diff --git a/modules/audio_processing/aec3/echo_canceller3.cc b/modules/audio_processing/aec3/echo_canceller3.cc index de399ee28e..d34a98bc3e 100644 --- a/modules/audio_processing/aec3/echo_canceller3.cc +++ b/modules/audio_processing/aec3/echo_canceller3.cc @@ -359,4 +359,18 @@ void EchoCanceller3::EmptyRenderQueue() { } } +EchoCanceller3Factory::EchoCanceller3Factory( + const AudioProcessing::Config::EchoCanceller3& config) + : config_(config) { + // Revert to default configuration if needed. + if (!EchoCanceller3::Validate(config_)) { + config_ = AudioProcessing::Config::EchoCanceller3(); + } +} + +std::unique_ptr EchoCanceller3Factory::Create(int sample_rate_hz) { + return std::unique_ptr( + new EchoCanceller3(config_, sample_rate_hz, true)); +} + } // namespace webrtc diff --git a/modules/audio_processing/aec3/echo_canceller3.h b/modules/audio_processing/aec3/echo_canceller3.h index 68250255a9..07b0f7018f 100644 --- a/modules/audio_processing/aec3/echo_canceller3.h +++ b/modules/audio_processing/aec3/echo_canceller3.h @@ -133,6 +133,16 @@ class EchoCanceller3 : public EchoControl { RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoCanceller3); }; + +class EchoCanceller3Factory : public EchoControlFactory { + public: + EchoCanceller3Factory(); + EchoCanceller3Factory(const AudioProcessing::Config::EchoCanceller3& config); + std::unique_ptr Create(int sample_rate_hz) override; + + private: + AudioProcessing::Config::EchoCanceller3 config_; +}; } // namespace webrtc #endif // MODULES_AUDIO_PROCESSING_AEC3_ECHO_CANCELLER3_H_ diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc index 9c13d1d874..e82223fe82 100644 --- a/modules/audio_processing/audio_processing_impl.cc +++ b/modules/audio_processing/audio_processing_impl.cc @@ -553,7 +553,7 @@ int AudioProcessingImpl::InitializeLocked() { public_submodules_->level_estimator->Initialize(); InitializeLevelController(); InitializeResidualEchoDetector(); - InitializeEchoCanceller3(); + InitializeEchoController(); InitializeGainController2(); InitializePostProcessor(); @@ -688,23 +688,13 @@ void AudioProcessingImpl::ApplyConfig(const AudioProcessing::Config& config) { LOG(LS_INFO) << "Highpass filter activated: " << config_.high_pass_filter.enabled; - // TODO(gustaf): Do this outside of APM. - config_ok = EchoCanceller3::Validate(config_.echo_canceller3); - if (!config_ok) { - LOG(LS_ERROR) << "AudioProcessing module config error" << std::endl - << "echo canceller 3: " - << EchoCanceller3::ToString(config_.echo_canceller3) - << std::endl - << "Reverting to default parameter set"; - config_.echo_canceller3 = AudioProcessing::Config::EchoCanceller3(); - } - - // TODO(gustaf): Enable EchoCanceller3 by injection, not configuration. - if (config.echo_canceller3.enabled != - capture_nonlocked_.echo_canceller3_enabled) { + // Inject EchoCanceller3 if requested. + if (config.echo_canceller3.enabled && !echo_control_factory_) { capture_nonlocked_.echo_canceller3_enabled = config_.echo_canceller3.enabled; - InitializeEchoCanceller3(); + echo_control_factory_ = std::unique_ptr( + new EchoCanceller3Factory(config.echo_canceller3)); + InitializeEchoController(); LOG(LS_INFO) << "Echo canceller 3 activated: " << capture_nonlocked_.echo_canceller3_enabled; } @@ -1702,14 +1692,10 @@ void AudioProcessingImpl::InitializeLowCutFilter() { } } -void AudioProcessingImpl::InitializeEchoCanceller3() { +void AudioProcessingImpl::InitializeEchoController() { if (echo_control_factory_) { private_submodules_->echo_controller = echo_control_factory_->Create(proc_sample_rate_hz()); - } else if (capture_nonlocked_.echo_canceller3_enabled) { - // TODO(gustaf): Remove once injection is used. - private_submodules_->echo_controller.reset(new EchoCanceller3( - config_.echo_canceller3, proc_sample_rate_hz(), true)); } else { private_submodules_->echo_controller.reset(); } diff --git a/modules/audio_processing/audio_processing_impl.h b/modules/audio_processing/audio_processing_impl.h index 2becc9e26f..2aa5315b21 100644 --- a/modules/audio_processing/audio_processing_impl.h +++ b/modules/audio_processing/audio_processing_impl.h @@ -224,7 +224,7 @@ class AudioProcessingImpl : public AudioProcessing { void InitializeResidualEchoDetector() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_render_, crit_capture_); void InitializeLowCutFilter() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); - void InitializeEchoCanceller3() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); + void InitializeEchoController() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); void InitializeGainController2() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_); void InitializePostProcessor() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_capture_);