Added EchoCanceller3Factory.

Added EchoCanceller3Factory that implements EchoControlFactory and can
be used for injecting EchoCanceller3 into Audio Processing Module.

Renamed InitializeEchoCanceller3 to InitializeEchoController.

Bug: webrtc:8346
Change-Id: I47078da6a49aca1ee41f6a9d5b7b8e91bb5c11a3
Reviewed-on: https://webrtc-review.googlesource.com/9220
Commit-Queue: Gustaf Ullberg <gustaf@webrtc.org>
Reviewed-by: Per Ã…hgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20299}
diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc
index 9c13d1d..e82223f 100644
--- a/modules/audio_processing/audio_processing_impl.cc
+++ b/modules/audio_processing/audio_processing_impl.cc
@@ -553,7 +553,7 @@
   public_submodules_->level_estimator->Initialize();
   InitializeLevelController();
   InitializeResidualEchoDetector();
-  InitializeEchoCanceller3();
+  InitializeEchoController();
   InitializeGainController2();
   InitializePostProcessor();
 
@@ -688,23 +688,13 @@
   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<EchoControlFactory>(
+        new EchoCanceller3Factory(config.echo_canceller3));
+    InitializeEchoController();
     LOG(LS_INFO) << "Echo canceller 3 activated: "
                  << capture_nonlocked_.echo_canceller3_enabled;
   }
@@ -1702,14 +1692,10 @@
   }
 }
 
-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();
   }