From 8be2f201ba8790501f6f3fa39f00017f02fca46d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Wed, 12 Aug 2020 08:46:47 +0200 Subject: [PATCH] Add ability to state whether the APM output will be used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL adds the ability for the surrounding code to state that the APM output will not be used. The intended usecase for this is to allow APM to run at a lower complexity when the endpoint is muted. When APM has been informed that the output will not be used, it can turn off code that is needed only for ensuring that the output audio will sound good. Bug: b/154437967,b/163802450 Change-Id: I8e22989e35354372e96191d15da44beb9d1b26ae Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/181200 Reviewed-by: Alessio Bazzica Commit-Queue: Per Ã…hgren Cr-Commit-Position: refs/heads/master@{#31949} --- modules/audio_processing/aec_dump/aec_dump_impl.cc | 6 ++++++ modules/audio_processing/audio_processing_impl.cc | 6 ++++++ modules/audio_processing/debug.proto | 1 + modules/audio_processing/include/audio_processing.h | 12 +++++++++++- .../test/aec_dump_based_simulator.cc | 4 ++++ .../audio_processing/test/runtime_setting_util.cc | 4 ++++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/modules/audio_processing/aec_dump/aec_dump_impl.cc b/modules/audio_processing/aec_dump/aec_dump_impl.cc index 12997388f0..18f85721b1 100644 --- a/modules/audio_processing/aec_dump/aec_dump_impl.cc +++ b/modules/audio_processing/aec_dump/aec_dump_impl.cc @@ -203,6 +203,12 @@ void AecDumpImpl::WriteRuntimeSetting( setting->set_capture_fixed_post_gain(x); break; } + case AudioProcessing::RuntimeSetting::Type::kCaptureOutputUsed: { + bool x; + runtime_setting.GetBool(&x); + setting->set_capture_output_used(x); + break; + } case AudioProcessing::RuntimeSetting::Type::kPlayoutVolumeChange: { int x; runtime_setting.GetInt(&x); diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc index b155bdbadb..485022accf 100644 --- a/modules/audio_processing/audio_processing_impl.cc +++ b/modules/audio_processing/audio_processing_impl.cc @@ -705,6 +705,7 @@ void AudioProcessingImpl::SetRuntimeSetting(RuntimeSetting setting) { case RuntimeSetting::Type::kCapturePreGain: case RuntimeSetting::Type::kCaptureCompressionGain: case RuntimeSetting::Type::kCaptureFixedPostGain: + case RuntimeSetting::Type::kCaptureOutputUsed: capture_runtime_settings_enqueuer_.Enqueue(setting); return; case RuntimeSetting::Type::kPlayoutVolumeChange: @@ -865,6 +866,10 @@ void AudioProcessingImpl::HandleCaptureRuntimeSettings() { case RuntimeSetting::Type::kNotSpecified: RTC_NOTREACHED(); break; + case RuntimeSetting::Type::kCaptureOutputUsed: + // TODO(b/154437967): Add support for reducing complexity when it is + // known that the capture output will not be used. + break; } } } @@ -886,6 +891,7 @@ void AudioProcessingImpl::HandleRenderRuntimeSettings() { case RuntimeSetting::Type::kCapturePreGain: // fall-through case RuntimeSetting::Type::kCaptureCompressionGain: // fall-through case RuntimeSetting::Type::kCaptureFixedPostGain: // fall-through + case RuntimeSetting::Type::kCaptureOutputUsed: // fall-through case RuntimeSetting::Type::kNotSpecified: RTC_NOTREACHED(); break; diff --git a/modules/audio_processing/debug.proto b/modules/audio_processing/debug.proto index af5e22ce72..07cce23ba3 100644 --- a/modules/audio_processing/debug.proto +++ b/modules/audio_processing/debug.proto @@ -91,6 +91,7 @@ message RuntimeSetting { optional float capture_fixed_post_gain = 3; optional int32 playout_volume_change = 4; optional PlayoutAudioDeviceInfo playout_audio_device_change = 5; + optional bool capture_output_used = 6; } message Event { diff --git a/modules/audio_processing/include/audio_processing.h b/modules/audio_processing/include/audio_processing.h index d84318f2a0..9e2d6dcb4a 100644 --- a/modules/audio_processing/include/audio_processing.h +++ b/modules/audio_processing/include/audio_processing.h @@ -384,7 +384,8 @@ class RTC_EXPORT AudioProcessing : public rtc::RefCountInterface { kCaptureFixedPostGain, kPlayoutVolumeChange, kCustomRenderProcessingRuntimeSetting, - kPlayoutAudioDeviceChange + kPlayoutAudioDeviceChange, + kCaptureOutputUsed }; // Play-out audio device properties. @@ -434,6 +435,10 @@ class RTC_EXPORT AudioProcessing : public rtc::RefCountInterface { return {Type::kCustomRenderProcessingRuntimeSetting, payload}; } + static RuntimeSetting CreateCaptureOutputUsedSetting(bool payload) { + return {Type::kCaptureOutputUsed, payload}; + } + Type type() const { return type_; } // Getters do not return a value but instead modify the argument to protect // from implicit casting. @@ -445,6 +450,10 @@ class RTC_EXPORT AudioProcessing : public rtc::RefCountInterface { RTC_DCHECK(value); *value = value_.int_value; } + void GetBool(bool* value) const { + RTC_DCHECK(value); + *value = value_.bool_value; + } void GetPlayoutAudioDeviceInfo(PlayoutAudioDeviceInfo* value) const { RTC_DCHECK(value); *value = value_.playout_audio_device_info; @@ -463,6 +472,7 @@ class RTC_EXPORT AudioProcessing : public rtc::RefCountInterface { U(PlayoutAudioDeviceInfo value) : playout_audio_device_info(value) {} float float_value; int int_value; + bool bool_value; PlayoutAudioDeviceInfo playout_audio_device_info; } value_; }; diff --git a/modules/audio_processing/test/aec_dump_based_simulator.cc b/modules/audio_processing/test/aec_dump_based_simulator.cc index f5bd6452e3..49372a9c28 100644 --- a/modules/audio_processing/test/aec_dump_based_simulator.cc +++ b/modules/audio_processing/test/aec_dump_based_simulator.cc @@ -544,6 +544,10 @@ void AecDumpBasedSimulator::HandleMessage( AudioProcessing::RuntimeSetting::CreatePlayoutAudioDeviceChange( {msg.playout_audio_device_change().id(), msg.playout_audio_device_change().max_volume()})); + } else if (msg.has_capture_output_used()) { + ap_->SetRuntimeSetting( + AudioProcessing::RuntimeSetting::CreateCaptureOutputUsedSetting( + msg.capture_output_used())); } } diff --git a/modules/audio_processing/test/runtime_setting_util.cc b/modules/audio_processing/test/runtime_setting_util.cc index 88761870fd..4899d2d459 100644 --- a/modules/audio_processing/test/runtime_setting_util.cc +++ b/modules/audio_processing/test/runtime_setting_util.cc @@ -41,6 +41,10 @@ void ReplayRuntimeSetting(AudioProcessing* apm, AudioProcessing::RuntimeSetting::CreatePlayoutAudioDeviceChange( {setting.playout_audio_device_change().id(), setting.playout_audio_device_change().max_volume()})); + } else if (setting.has_capture_output_used()) { + apm->SetRuntimeSetting( + AudioProcessing::RuntimeSetting::CreateCaptureOutputUsedSetting( + setting.capture_output_used())); } } } // namespace webrtc