APM: fix TS initialization bugs with `WebRTC-Audio-GainController2`
When the `WebRTC-Audio-GainController2` field trial is used, the
initial APM configuration is adjusted depending on its original
values and the field trial parameters.
This CL fixes two cases when the code crashes:
1. when, in the initial APM config, AGC1 is enabled, AGC2 is
disabled and TS is enabled
2. when the initial APM sample rate is different from the
capture one and the VAD APM sub-module is not re-initialized
This CL also improves the unit tests coverage and it has been
tested offline to check that the VAD sub-module is created only
when expected and that AGC2 uses its internal VAD when expected.
The tests ran on a few Wav files with different sample rates and
one AEC dump and on 16 different APM and field trial
configurations.
Bug: chromium:1407341, b/265112132
Change-Id: I7cc267ea81cb02be92c1f37f273b7ae93b6e4634
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/290988
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Olga Sharonova <olka@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39118}
diff --git a/modules/audio_processing/audio_processing_impl.h b/modules/audio_processing/audio_processing_impl.h
index b4b3de2..fe80e0d 100644
--- a/modules/audio_processing/audio_processing_impl.h
+++ b/modules/audio_processing/audio_processing_impl.h
@@ -227,10 +227,12 @@
static AudioProcessing::Config AdjustConfig(
const AudioProcessing::Config& config,
const absl::optional<GainController2ExperimentParams>& experiment_params);
- static TransientSuppressor::VadMode GetTransientSuppressorVadMode(
+ // Returns true if the APM VAD sub-module should be used.
+ static bool UseApmVadSubModule(
+ const AudioProcessing::Config& config,
const absl::optional<GainController2ExperimentParams>& experiment_params);
- const TransientSuppressor::VadMode transient_suppressor_vad_mode_;
+ TransientSuppressor::VadMode transient_suppressor_vad_mode_;
SwapQueue<RuntimeSetting> capture_runtime_settings_;
SwapQueue<RuntimeSetting> render_runtime_settings_;
@@ -317,14 +319,15 @@
void InitializeGainController1() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
void InitializeTransientSuppressor()
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
- // Initializes the `GainController2` sub-module. If the sub-module is enabled
- // and `config_has_changed` is true, recreates the sub-module.
- void InitializeGainController2(bool config_has_changed)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
+ // Initializes the `GainController2` sub-module. If the sub-module is enabled,
+ // recreates it.
+ void InitializeGainController2() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
// Initializes the `VoiceActivityDetectorWrapper` sub-module. If the
- // sub-module is enabled and `config_has_changed` is true, recreates the
- // sub-module.
- void InitializeVoiceActivityDetector(bool config_has_changed)
+ // sub-module is enabled, recreates it. Call `InitializeGainController2()`
+ // first.
+ // TODO(bugs.webrtc.org/13663): Remove if TS is removed otherwise remove call
+ // order requirement - i.e., decouple from `InitializeGainController2()`.
+ void InitializeVoiceActivityDetector()
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
void InitializeNoiseSuppressor() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_capture_);
void InitializeCaptureLevelsAdjuster()