Commit e0ca18b5 authored by Kehuang Li's avatar Kehuang Li Committed by Commit Bot

Do not start AGC timer if getting max volume is not supported by stream

When audio stream do not support GetMaxVolume(), it will be spam to
query and update normalized volume every second, especially making
unsupported GetMaxVolume() print out warning msg. In this change, if the
first try to get |max_volume_| fails, |normalized_volume_| won't be set
and timer will not be started. This CL assumes that if GetMaxVolume()
doesn't work at first, it will not work all the time during the stream;
and user may StartAgc() again once the GetMaxVolume() start to work
after a while. Other behavior should have no difference.

Google Home, no longer have spamming warning msg, and work well.

Bug: NONE
Test: Build on desktop and test on appr.tc, no crash; built and run on
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ic4af961df08cb4f1940604c44108ca08e80190c8
Reviewed-on: https://chromium-review.googlesource.com/954584Reviewed-by: default avatarOlga Sharonova <olka@chromium.org>
Reviewed-by: default avatarMax Morin <maxmorin@chromium.org>
Commit-Queue: Olga Sharonova <olka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548041}
parent faf41677
...@@ -89,6 +89,13 @@ class MEDIA_EXPORT AgcAudioStream : public AudioInterface { ...@@ -89,6 +89,13 @@ class MEDIA_EXPORT AgcAudioStream : public AudioInterface {
if (!agc_is_enabled_ || timer_.IsRunning()) if (!agc_is_enabled_ || timer_.IsRunning())
return; return;
max_volume_ = static_cast<AudioInterface*>(this)->GetMaxVolume();
if (max_volume_ <= 0) {
DLOG(WARNING) << "Failed to get max volume from hardware. Won't provide "
<< "normalized volume.";
return;
}
// Query and cache the volume to avoid sending 0 as volume to AGC at the // Query and cache the volume to avoid sending 0 as volume to AGC at the
// beginning of the audio stream, otherwise AGC will try to raise the // beginning of the audio stream, otherwise AGC will try to raise the
// volume from 0. // volume from 0.
...@@ -159,19 +166,14 @@ class MEDIA_EXPORT AgcAudioStream : public AudioInterface { ...@@ -159,19 +166,14 @@ class MEDIA_EXPORT AgcAudioStream : public AudioInterface {
// thread and it leads to a more stable capture performance. // thread and it leads to a more stable capture performance.
void QueryAndStoreNewMicrophoneVolume() { void QueryAndStoreNewMicrophoneVolume() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_GT(max_volume_, 0.0);
// Cach the maximum volume if this is the first time we ask for it.
if (max_volume_ == 0.0)
max_volume_ = static_cast<AudioInterface*>(this)->GetMaxVolume();
// Retrieve the current volume level by asking the audio hardware. // Retrieve the current volume level by asking the audio hardware.
// Range is normalized to [0.0,1.0] or [0.0, 1.5] on Linux. // Range is normalized to [0.0,1.0] or [0.0, 1.5] on Linux.
if (max_volume_ != 0.0) {
double normalized_volume = double normalized_volume =
static_cast<AudioInterface*>(this)->GetVolume() / max_volume_; static_cast<AudioInterface*>(this)->GetVolume() / max_volume_;
normalized_volume_.store(normalized_volume, std::memory_order_relaxed); normalized_volume_.store(normalized_volume, std::memory_order_relaxed);
} }
}
// Ensures that this class is created and destroyed on the same thread. // Ensures that this class is created and destroyed on the same thread.
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment