AEC3: Added a mode to properly utilize highly linear setups

Bug: webrtc:9321
Change-Id: I9c1abbd6b1daa1ecff041633318edfb8a011e9c0
Reviewed-on: https://webrtc-review.googlesource.com/79480
Reviewed-by: Jesus de Vicente Pena <devicentepena@webrtc.org>
Commit-Queue: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23423}
diff --git a/api/audio/echo_canceller3_config.h b/api/audio/echo_canceller3_config.h
index b82760d..cce04d4 100644
--- a/api/audio/echo_canceller3_config.h
+++ b/api/audio/echo_canceller3_config.h
@@ -134,6 +134,7 @@
       int full_gain_blocks = 312;
     } gain_rampup;
     bool has_clock_drift = false;
+    bool linear_and_stable_echo_path = false;
   } echo_removal_control;
 
   struct EchoModel {
diff --git a/modules/audio_processing/aec3/aec_state.cc b/modules/audio_processing/aec3/aec_state.cc
index 1f91777..f358185 100644
--- a/modules/audio_processing/aec3/aec_state.cc
+++ b/modules/audio_processing/aec3/aec_state.cc
@@ -245,10 +245,13 @@
   usable_linear_estimate_ = !echo_saturation_;
   usable_linear_estimate_ =
       usable_linear_estimate_ && filter_has_had_time_to_converge;
-  usable_linear_estimate_ =
-      usable_linear_estimate_ && recently_converged_filter;
-  usable_linear_estimate_ = usable_linear_estimate_ && !diverged_filter;
+
   usable_linear_estimate_ = usable_linear_estimate_ && external_delay;
+  if (!config_.echo_removal_control.linear_and_stable_echo_path) {
+    usable_linear_estimate_ =
+        usable_linear_estimate_ && recently_converged_filter;
+    usable_linear_estimate_ = usable_linear_estimate_ && !diverged_filter;
+  }
 
   use_linear_filter_output_ = usable_linear_estimate_ && !TransparentMode();
 
diff --git a/modules/audio_processing/test/audio_processing_simulator.cc b/modules/audio_processing/test/audio_processing_simulator.cc
index 7e19194..577274f 100644
--- a/modules/audio_processing/test/audio_processing_simulator.cc
+++ b/modules/audio_processing/test/audio_processing_simulator.cc
@@ -266,6 +266,8 @@
     }
     ReadParam(section, "has_clock_drift",
               &cfg.echo_removal_control.has_clock_drift);
+    ReadParam(section, "linear_and_stable_echo_path",
+              &cfg.echo_removal_control.linear_and_stable_echo_path);
   }
 
   if (rtc::GetValueFromJsonObject(root, "echo_model", &section)) {