modules/audio_processing: Adds a config for reported delays

There are platforms and devices where the reported delays are untrusted and we currently solve that with an extended filter length and a slightly more conservative delay handling.
With this change we give the user the possibility to turn off reported system delay values completely.

- Includes new unit tests.

TESTED=trybots and manual testing
R=aluebs@webrtc.org, kwiberg@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/13629004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6391 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl.cc b/webrtc/modules/audio_processing/echo_cancellation_impl.cc
index 8cf3410..e770f9f 100644
--- a/webrtc/modules/audio_processing/echo_cancellation_impl.cc
+++ b/webrtc/modules/audio_processing/echo_cancellation_impl.cc
@@ -323,6 +323,7 @@
 
 void EchoCancellationImpl::SetExtraOptions(const Config& config) {
   delay_correction_enabled_ = config.Get<DelayCorrection>().enabled;
+  reported_delay_enabled_ = config.Get<ReportedDelay>().enabled;
   Configure();
 }
 
diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc b/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc
index eeea258..49bcf94 100644
--- a/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc
+++ b/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc
@@ -48,4 +48,34 @@
   EXPECT_EQ(0, WebRtcAec_delay_correction_enabled(aec_core));
 }
 
+TEST(EchoCancellationInternalTest, ReportedDelay) {
+  scoped_ptr<AudioProcessing> ap(AudioProcessing::Create(0));
+  EXPECT_TRUE(ap->echo_cancellation()->aec_core() == NULL);
+
+  EXPECT_EQ(ap->kNoError, ap->echo_cancellation()->Enable(true));
+  EXPECT_TRUE(ap->echo_cancellation()->is_enabled());
+
+  AecCore* aec_core = ap->echo_cancellation()->aec_core();
+  ASSERT_TRUE(aec_core != NULL);
+  // Enabled by default.
+  EXPECT_EQ(1, WebRtcAec_reported_delay_enabled(aec_core));
+
+  Config config;
+  config.Set<ReportedDelay>(new ReportedDelay(false));
+  ap->SetExtraOptions(config);
+  EXPECT_EQ(0, WebRtcAec_reported_delay_enabled(aec_core));
+
+  // Retains setting after initialization.
+  EXPECT_EQ(ap->kNoError, ap->Initialize());
+  EXPECT_EQ(0, WebRtcAec_reported_delay_enabled(aec_core));
+
+  config.Set<ReportedDelay>(new ReportedDelay(true));
+  ap->SetExtraOptions(config);
+  EXPECT_EQ(1, WebRtcAec_reported_delay_enabled(aec_core));
+
+  // Retains setting after initialization.
+  EXPECT_EQ(ap->kNoError, ap->Initialize());
+  EXPECT_EQ(1, WebRtcAec_reported_delay_enabled(aec_core));
+}
+
 }  // namespace webrtc
diff --git a/webrtc/modules/audio_processing/include/audio_processing.h b/webrtc/modules/audio_processing/include/audio_processing.h
index 15e01b9..77c3f3a 100644
--- a/webrtc/modules/audio_processing/include/audio_processing.h
+++ b/webrtc/modules/audio_processing/include/audio_processing.h
@@ -53,6 +53,18 @@
   bool enabled;
 };
 
+// Use to disable the reported system delays. By disabling the reported system
+// delays the echo cancellation algorithm assumes the process and reverse
+// streams to be aligned. This configuration only applies to EchoCancellation
+// and not EchoControlMobile and is set with AudioProcessing::SetExtraOptions().
+// Note that by disabling reported system delays the EchoCancellation may
+// regress in performance.
+struct ReportedDelay {
+  ReportedDelay() : enabled(true) {}
+  explicit ReportedDelay(bool enabled) : enabled(enabled) {}
+  bool enabled;
+};
+
 // Must be provided through AudioProcessing::Create(Confg&). It will have no
 // impact if used with AudioProcessing::SetExtraOptions().
 struct ExperimentalAgc {