[go: nahoru, domu]

Use buildflag for sample rate in cast_audio_manager_alsa

Instead of hard-coding the number to 48kHz, we will need the correct
value of the platform/device.

correct sample rate when run web application.

Bug: b/130197895
Test: Remove the similar flag in chromecat/internal and build and got
Change-Id: Ib350b48080cb75de6e94e61cecec9ca2d89d0848
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1560443
Reviewed-by: Luke Halliwell <halliwell@chromium.org>
Reviewed-by: Kenneth MacKay <kmackay@chromium.org>
Commit-Queue: Kehuang Li <kehuangli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650847}
diff --git a/chromecast/chromecast.gni b/chromecast/chromecast.gni
index c6ac9e5a..f82aea2 100644
--- a/chromecast/chromecast.gni
+++ b/chromecast/chromecast.gni
@@ -116,6 +116,9 @@
   # within cast_shell. Enable for desktop builds to ensure that Chromium CQ
   # builds the external Mojo broker code.
   enable_external_mojo_services = is_cast_desktop_build
+
+  # Recording happens at this sample rate. Must be 16000, 48000 or 96000 Hz.
+  audio_input_sample_rate = 16000
 }
 
 declare_args() {
diff --git a/chromecast/media/audio/BUILD.gn b/chromecast/media/audio/BUILD.gn
index efa3ccc..2e000eb 100644
--- a/chromecast/media/audio/BUILD.gn
+++ b/chromecast/media/audio/BUILD.gn
@@ -80,4 +80,9 @@
     "MAXIMUM_OUTPUT_BUFFER_SIZE_IN_FRAMES=$maximum_output_buffer_size_in_frames",
     "DEFAULT_OUTPUT_BUFFER_SIZE_IN_FRAMES=$default_output_buffer_size_in_frames",
   ]
+
+  if (use_alsa) {
+    # Currently, this flag will only be used in cast_audio_manager_alsa.cc
+    flags += [ "AUDIO_INPUT_SAMPLE_RATE=$audio_input_sample_rate" ]
+  }
 }
diff --git a/chromecast/media/audio/cast_audio_manager_alsa.cc b/chromecast/media/audio/cast_audio_manager_alsa.cc
index bc4af57..6112900 100644
--- a/chromecast/media/audio/cast_audio_manager_alsa.cc
+++ b/chromecast/media/audio/cast_audio_manager_alsa.cc
@@ -9,6 +9,7 @@
 
 #include "base/memory/free_deleter.h"
 #include "base/stl_util.h"
+#include "chromecast/media/audio/audio_buildflags.h"
 #include "chromecast/media/cma/backend/cma_backend_factory.h"
 #include "media/audio/alsa/alsa_input.h"
 #include "media/audio/alsa/alsa_wrapper.h"
@@ -18,7 +19,7 @@
 
 namespace {
 // TODO(alokp): Query the preferred value from media backend.
-const int kDefaultSampleRate = 48000;
+const int kDefaultSampleRate = BUILDFLAG(AUDIO_INPUT_SAMPLE_RATE);
 
 // TODO(jyw): Query the preferred value from media backend.
 static const int kDefaultInputBufferSize = 1024;