Open up for do the noise suppressor analysis on the linear AEC output

This CL allows the noise suppressor to use the linear AEC output
for analysis whenever that is available. This will potentially
lower the risk that the noise suppressor estimates the noise
based on echo.
The feature is off by default.

Bug: webrtc:5298,b:132164318
Change-Id: Idc6c8e197d96209d213819d87a8fb2533b7303ec
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/162900
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Per Åhgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30116}
diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc
index 6d8b209..cffbfbe 100644
--- a/modules/audio_processing/audio_processing_impl.cc
+++ b/modules/audio_processing/audio_processing_impl.cc
@@ -1206,6 +1206,7 @@
                 1);
 
   AudioBuffer* capture_buffer = capture_.capture_audio.get();  // For brevity.
+  AudioBuffer* linear_aec_buffer = capture_.linear_aec_output.get();
 
   if (submodules_.high_pass_filter &&
       config_.high_pass_filter.apply_in_full_band &&
@@ -1292,10 +1293,14 @@
   RETURN_ON_ERR(submodules_.gain_control->AnalyzeCaptureAudio(*capture_buffer));
   RTC_DCHECK(
       !(submodules_.legacy_noise_suppressor && submodules_.noise_suppressor));
-  if (submodules_.noise_suppressor) {
-    submodules_.noise_suppressor->Analyze(*capture_buffer);
-  } else if (submodules_.legacy_noise_suppressor) {
-    submodules_.legacy_noise_suppressor->AnalyzeCaptureAudio(capture_buffer);
+
+  if (!config_.noise_suppression.analyze_linear_aec_output_when_available ||
+      !linear_aec_buffer || submodules_.echo_control_mobile) {
+    if (submodules_.noise_suppressor) {
+      submodules_.noise_suppressor->Analyze(*capture_buffer);
+    } else if (submodules_.legacy_noise_suppressor) {
+      submodules_.legacy_noise_suppressor->AnalyzeCaptureAudio(capture_buffer);
+    }
   }
 
   if (submodules_.echo_control_mobile) {
@@ -1322,11 +1327,20 @@
         submodules_.echo_controller->SetAudioBufferDelay(stream_delay_ms());
       }
 
-      AudioBuffer* linear_aec_buffer = capture_.linear_aec_output.get();
       submodules_.echo_controller->ProcessCapture(
           capture_buffer, linear_aec_buffer, capture_.echo_path_gain_change);
     }
 
+    if (config_.noise_suppression.analyze_linear_aec_output_when_available &&
+        linear_aec_buffer) {
+      if (submodules_.noise_suppressor) {
+        submodules_.noise_suppressor->Analyze(*linear_aec_buffer);
+      } else if (submodules_.legacy_noise_suppressor) {
+        submodules_.legacy_noise_suppressor->AnalyzeCaptureAudio(
+            linear_aec_buffer);
+      }
+    }
+
     if (submodules_.noise_suppressor) {
       submodules_.noise_suppressor->Process(capture_buffer);
     } else if (submodules_.legacy_noise_suppressor) {