Rename APM Config DelayCorrection to ExtendedFilter

We use this Config struct for enabling/disabling Extended filter mode
in AEC. This change renames it to ExtendedFilter for readability
reasons. The corresponding media constraint is also renamed to
kExtendedFilterEchoCancellation.

The old Config is kept in parallel with the new during a transition
period. This is to avoid problems with API breakages. During this
period, if any of the two Configs are enabled, the extended filter
mode is engaged in APM. That is, the two Configs are combined with an
"OR" operation.

This change also renames experimental_aec in AudioOptions to extended_filter_aec.

BUG=4696
R=bjornv@webrtc.org, tommi@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#9378}
diff --git a/talk/app/webrtc/localaudiosource.cc b/talk/app/webrtc/localaudiosource.cc
index b37d1e3..808e2cf 100644
--- a/talk/app/webrtc/localaudiosource.cc
+++ b/talk/app/webrtc/localaudiosource.cc
@@ -58,8 +58,8 @@
     if (iter->key == MediaConstraintsInterface::kEchoCancellation)
       options->echo_cancellation.Set(value);
     else if (iter->key ==
-        MediaConstraintsInterface::kExperimentalEchoCancellation)
-      options->experimental_aec.Set(value);
+             MediaConstraintsInterface::kExtendedFilterEchoCancellation)
+      options->extended_filter_aec.Set(value);
     else if (iter->key == MediaConstraintsInterface::kDAEchoCancellation)
       options->delay_agnostic_aec.Set(value);
     else if (iter->key == MediaConstraintsInterface::kAutoGainControl)
diff --git a/talk/app/webrtc/localaudiosource_unittest.cc b/talk/app/webrtc/localaudiosource_unittest.cc
index 569f814..43a132b 100644
--- a/talk/app/webrtc/localaudiosource_unittest.cc
+++ b/talk/app/webrtc/localaudiosource_unittest.cc
@@ -45,7 +45,7 @@
   webrtc::FakeConstraints constraints;
   constraints.AddMandatory(MediaConstraintsInterface::kEchoCancellation, false);
   constraints.AddOptional(
-      MediaConstraintsInterface::kExperimentalEchoCancellation, true);
+      MediaConstraintsInterface::kExtendedFilterEchoCancellation, true);
   constraints.AddOptional(MediaConstraintsInterface::kDAEchoCancellation, true);
   constraints.AddOptional(MediaConstraintsInterface::kAutoGainControl, true);
   constraints.AddOptional(
@@ -61,7 +61,7 @@
   bool value;
   EXPECT_TRUE(source->options().echo_cancellation.Get(&value));
   EXPECT_FALSE(value);
-  EXPECT_TRUE(source->options().experimental_aec.Get(&value));
+  EXPECT_TRUE(source->options().extended_filter_aec.Get(&value));
   EXPECT_TRUE(value);
   EXPECT_TRUE(source->options().delay_agnostic_aec.Get(&value));
   EXPECT_TRUE(value);
diff --git a/talk/app/webrtc/mediaconstraintsinterface.cc b/talk/app/webrtc/mediaconstraintsinterface.cc
index a84dde2..7fbc61d 100644
--- a/talk/app/webrtc/mediaconstraintsinterface.cc
+++ b/talk/app/webrtc/mediaconstraintsinterface.cc
@@ -48,7 +48,7 @@
 // Audio constraints.
 const char MediaConstraintsInterface::kEchoCancellation[] =
     "googEchoCancellation";
-const char MediaConstraintsInterface::kExperimentalEchoCancellation[] =
+const char MediaConstraintsInterface::kExtendedFilterEchoCancellation[] =
     "googEchoCancellation2";
 const char MediaConstraintsInterface::kDAEchoCancellation[] =
     "googDAEchoCancellation";
diff --git a/talk/app/webrtc/mediaconstraintsinterface.h b/talk/app/webrtc/mediaconstraintsinterface.h
index cc68209..1148d80 100644
--- a/talk/app/webrtc/mediaconstraintsinterface.h
+++ b/talk/app/webrtc/mediaconstraintsinterface.h
@@ -74,7 +74,7 @@
   // Constraint keys used by a local audio source.
   // These keys are google specific.
   static const char kEchoCancellation[];  // googEchoCancellation
-  static const char kExperimentalEchoCancellation[];  // googEchoCancellation2
+  static const char kExtendedFilterEchoCancellation[];  // googEchoCancellation2
   static const char kDAEchoCancellation[];  // googDAEchoCancellation
   static const char kAutoGainControl[];  // googAutoGainControl
   static const char kExperimentalAutoGainControl[];  // googAutoGainControl2
diff --git a/talk/media/base/mediachannel.h b/talk/media/base/mediachannel.h
index b5b2460..e7af7a7 100644
--- a/talk/media/base/mediachannel.h
+++ b/talk/media/base/mediachannel.h
@@ -159,7 +159,7 @@
     conference_mode.SetFrom(change.conference_mode);
     adjust_agc_delta.SetFrom(change.adjust_agc_delta);
     experimental_agc.SetFrom(change.experimental_agc);
-    experimental_aec.SetFrom(change.experimental_aec);
+    extended_filter_aec.SetFrom(change.extended_filter_aec);
     delay_agnostic_aec.SetFrom(change.delay_agnostic_aec);
     experimental_ns.SetFrom(change.experimental_ns);
     aec_dump.SetFrom(change.aec_dump);
@@ -191,7 +191,7 @@
         aecm_generate_comfort_noise == o.aecm_generate_comfort_noise &&
         conference_mode == o.conference_mode &&
         experimental_agc == o.experimental_agc &&
-        experimental_aec == o.experimental_aec &&
+        extended_filter_aec == o.extended_filter_aec &&
         delay_agnostic_aec == o.delay_agnostic_aec &&
         experimental_ns == o.experimental_ns &&
         adjust_agc_delta == o.adjust_agc_delta &&
@@ -226,7 +226,7 @@
     ost << ToStringIfSet("conference", conference_mode);
     ost << ToStringIfSet("agc_delta", adjust_agc_delta);
     ost << ToStringIfSet("experimental_agc", experimental_agc);
-    ost << ToStringIfSet("experimental_aec", experimental_aec);
+    ost << ToStringIfSet("extended_filter_aec", extended_filter_aec);
     ost << ToStringIfSet("delay_agnostic_aec", delay_agnostic_aec);
     ost << ToStringIfSet("experimental_ns", experimental_ns);
     ost << ToStringIfSet("aec_dump", aec_dump);
@@ -269,7 +269,7 @@
   Settable<bool> conference_mode;
   Settable<int> adjust_agc_delta;
   Settable<bool> experimental_agc;
-  Settable<bool> experimental_aec;
+  Settable<bool> extended_filter_aec;
   Settable<bool> delay_agnostic_aec;
   Settable<bool> experimental_ns;
   Settable<bool> aec_dump;
diff --git a/talk/media/webrtc/webrtcvoiceengine.cc b/talk/media/webrtc/webrtcvoiceengine.cc
index aad0d43..84a26c5 100644
--- a/talk/media/webrtc/webrtcvoiceengine.cc
+++ b/talk/media/webrtc/webrtcvoiceengine.cc
@@ -357,7 +357,7 @@
   options.conference_mode.Set(false);
   options.adjust_agc_delta.Set(0);
   options.experimental_agc.Set(false);
-  options.experimental_aec.Set(false);
+  options.extended_filter_aec.Set(false);
   options.delay_agnostic_aec.Set(false);
   options.experimental_ns.Set(false);
   options.aec_dump.Set(false);
@@ -661,7 +661,7 @@
   agc_mode = webrtc::kAgcFixedDigital;
   options.typing_detection.Set(false);
   options.experimental_agc.Set(false);
-  options.experimental_aec.Set(false);
+  options.extended_filter_aec.Set(false);
   options.experimental_ns.Set(false);
 #endif
 
@@ -672,7 +672,7 @@
   if (options.delay_agnostic_aec.Get(&use_delay_agnostic_aec)) {
     if (use_delay_agnostic_aec) {
       options.echo_cancellation.Set(true);
-      options.experimental_aec.Set(true);
+      options.extended_filter_aec.Set(true);
       ec_mode = webrtc::kEcConference;
     }
   }
@@ -848,12 +848,12 @@
         new webrtc::ReportedDelay(!delay_agnostic_aec));
   }
 
-  experimental_aec_.SetFrom(options.experimental_aec);
-  bool experimental_aec;
-  if (experimental_aec_.Get(&experimental_aec)) {
-    LOG(LS_INFO) << "Experimental aec is enabled? " << experimental_aec;
-    config.Set<webrtc::DelayCorrection>(
-        new webrtc::DelayCorrection(experimental_aec));
+  extended_filter_aec_.SetFrom(options.extended_filter_aec);
+  bool extended_filter;
+  if (extended_filter_aec_.Get(&extended_filter)) {
+    LOG(LS_INFO) << "Extended filter aec is enabled? " << extended_filter;
+    config.Set<webrtc::ExtendedFilter>(
+        new webrtc::ExtendedFilter(extended_filter));
   }
 
   experimental_ns_.SetFrom(options.experimental_ns);
diff --git a/talk/media/webrtc/webrtcvoiceengine.h b/talk/media/webrtc/webrtcvoiceengine.h
index 65dde08..35f2dbc 100644
--- a/talk/media/webrtc/webrtcvoiceengine.h
+++ b/talk/media/webrtc/webrtcvoiceengine.h
@@ -266,11 +266,11 @@
 
   rtc::CriticalSection signal_media_critical_;
 
-  // Cache received experimental_aec, delay_agnostic_aec and experimental_ns
+  // Cache received extended_filter_aec, delay_agnostic_aec and experimental_ns
   // values, and apply them in case they are missing in the audio options. We
   // need to do this because SetExtraOptions() will revert to defaults for
   // options which are not provided.
-  Settable<bool> experimental_aec_;
+  Settable<bool> extended_filter_aec_;
   Settable<bool> delay_agnostic_aec_;
   Settable<bool> experimental_ns_;
 };
diff --git a/talk/media/webrtc/webrtcvoiceengine_unittest.cc b/talk/media/webrtc/webrtcvoiceengine_unittest.cc
index cf8100b..0dc7b51 100644
--- a/talk/media/webrtc/webrtcvoiceengine_unittest.cc
+++ b/talk/media/webrtc/webrtcvoiceengine_unittest.cc
@@ -2895,7 +2895,7 @@
 
   // Turn off echo cancellation and delay agnostic aec.
   options.delay_agnostic_aec.Set(false);
-  options.experimental_aec.Set(false);
+  options.extended_filter_aec.Set(false);
   options.echo_cancellation.Set(false);
   ASSERT_TRUE(engine_.SetOptions(options));
   voe_.GetEcStatus(ec_enabled, ec_mode);
diff --git a/webrtc/modules/audio_processing/aec/aec_core.c b/webrtc/modules/audio_processing/aec/aec_core.c
index d4e11dc..32266f4 100644
--- a/webrtc/modules/audio_processing/aec/aec_core.c
+++ b/webrtc/modules/audio_processing/aec/aec_core.c
@@ -1934,14 +1934,14 @@
   return self->reported_delay_enabled;
 }
 
-void WebRtcAec_enable_delay_correction(AecCore* self, int enable) {
+void WebRtcAec_enable_extended_filter(AecCore* self, int enable) {
   self->extended_filter_enabled = enable;
   self->num_partitions = enable ? kExtendedNumPartitions : kNormalNumPartitions;
   // Update the delay estimator with filter length.  See InitAEC() for details.
   WebRtc_set_allowed_offset(self->delay_estimator, self->num_partitions / 2);
 }
 
-int WebRtcAec_delay_correction_enabled(AecCore* self) {
+int WebRtcAec_extended_filter_enabled(AecCore* self) {
   return self->extended_filter_enabled;
 }
 
diff --git a/webrtc/modules/audio_processing/aec/aec_core.h b/webrtc/modules/audio_processing/aec/aec_core.h
index d9335e3..aa5687a 100644
--- a/webrtc/modules/audio_processing/aec/aec_core.h
+++ b/webrtc/modules/audio_processing/aec/aec_core.h
@@ -108,14 +108,11 @@
 // Returns non-zero if reported delay is enabled and zero if disabled.
 int WebRtcAec_reported_delay_enabled(AecCore* self);
 
-// We now interpret delay correction to mean an extended filter length feature.
-// We reuse the delay correction infrastructure to avoid changes through to
-// libjingle. See details along with |DelayCorrection| in
-// echo_cancellation_impl.h. Non-zero enables, zero disables.
-void WebRtcAec_enable_delay_correction(AecCore* self, int enable);
+// Enables or disables extended filter mode. Non-zero enables, zero disables.
+void WebRtcAec_enable_extended_filter(AecCore* self, int enable);
 
-// Returns non-zero if delay correction is enabled and zero if disabled.
-int WebRtcAec_delay_correction_enabled(AecCore* self);
+// Returns non-zero if extended filter mode is enabled and zero if disabled.
+int WebRtcAec_extended_filter_enabled(AecCore* self);
 
 // Returns the current |system_delay|, i.e., the buffered difference between
 // far-end and near-end.
diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation.c b/webrtc/modules/audio_processing/aec/echo_cancellation.c
index 54ac24d..06d081d 100644
--- a/webrtc/modules/audio_processing/aec/echo_cancellation.c
+++ b/webrtc/modules/audio_processing/aec/echo_cancellation.c
@@ -373,7 +373,7 @@
   }
 
   // This returns the value of aec->extended_filter_enabled.
-  if (WebRtcAec_delay_correction_enabled(aecpc->aec)) {
+  if (WebRtcAec_extended_filter_enabled(aecpc->aec)) {
     ProcessExtended(aecpc,
                     nearend,
                     num_bands,
diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl.cc b/webrtc/modules/audio_processing/echo_cancellation_impl.cc
index 245941a..e28f127 100644
--- a/webrtc/modules/audio_processing/echo_cancellation_impl.cc
+++ b/webrtc/modules/audio_processing/echo_cancellation_impl.cc
@@ -57,18 +57,19 @@
 
 EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm,
                                            CriticalSectionWrapper* crit)
-  : ProcessingComponent(),
-    apm_(apm),
-    crit_(crit),
-    drift_compensation_enabled_(false),
-    metrics_enabled_(false),
-    suppression_level_(kModerateSuppression),
-    stream_drift_samples_(0),
-    was_stream_drift_set_(false),
-    stream_has_echo_(false),
-    delay_logging_enabled_(false),
-    delay_correction_enabled_(false),
-    reported_delay_enabled_(true) {}
+    : ProcessingComponent(),
+      apm_(apm),
+      crit_(crit),
+      drift_compensation_enabled_(false),
+      metrics_enabled_(false),
+      suppression_level_(kModerateSuppression),
+      stream_drift_samples_(0),
+      was_stream_drift_set_(false),
+      stream_has_echo_(false),
+      delay_logging_enabled_(false),
+      extended_filter_enabled_(false),
+      reported_delay_enabled_(true) {
+}
 
 EchoCancellationImpl::~EchoCancellationImpl() {}
 
@@ -327,7 +328,10 @@
 }
 
 void EchoCancellationImpl::SetExtraOptions(const Config& config) {
-  delay_correction_enabled_ = config.Get<DelayCorrection>().enabled;
+  // Both ExtendedFilter and DelayCorrection are diabled by default. If any one
+  // of them is true, then the extended filter mode is enabled.
+  extended_filter_enabled_ = config.Get<ExtendedFilter>().enabled ||
+                             config.Get<DelayCorrection>().enabled;
   reported_delay_enabled_ = config.Get<ReportedDelay>().enabled;
   Configure();
 }
@@ -366,8 +370,9 @@
   config.skewMode = drift_compensation_enabled_;
   config.delay_logging = delay_logging_enabled_;
 
-  WebRtcAec_enable_delay_correction(WebRtcAec_aec_core(
-      static_cast<Handle*>(handle)), delay_correction_enabled_ ? 1 : 0);
+  WebRtcAec_enable_extended_filter(
+      WebRtcAec_aec_core(static_cast<Handle*>(handle)),
+      extended_filter_enabled_ ? 1 : 0);
   WebRtcAec_enable_reported_delay(WebRtcAec_aec_core(
       static_cast<Handle*>(handle)), reported_delay_enabled_ ? 1 : 0);
   return WebRtcAec_set_config(static_cast<Handle*>(handle), config);
diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl.h b/webrtc/modules/audio_processing/echo_cancellation_impl.h
index ed3d7b5..cf3ebf6 100644
--- a/webrtc/modules/audio_processing/echo_cancellation_impl.h
+++ b/webrtc/modules/audio_processing/echo_cancellation_impl.h
@@ -74,7 +74,7 @@
   bool was_stream_drift_set_;
   bool stream_has_echo_;
   bool delay_logging_enabled_;
-  bool delay_correction_enabled_;
+  bool extended_filter_enabled_;
   bool reported_delay_enabled_;
 };
 
diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc b/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc
index aac9a1e..63b6db9 100644
--- a/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc
+++ b/webrtc/modules/audio_processing/echo_cancellation_impl_unittest.cc
@@ -18,7 +18,7 @@
 
 namespace webrtc {
 
-TEST(EchoCancellationInternalTest, DelayCorrection) {
+TEST(EchoCancellationInternalTest, ExtendedFilter) {
   rtc::scoped_ptr<AudioProcessing> ap(AudioProcessing::Create());
   EXPECT_TRUE(ap->echo_cancellation()->aec_core() == NULL);
 
@@ -28,24 +28,24 @@
   AecCore* aec_core = ap->echo_cancellation()->aec_core();
   ASSERT_TRUE(aec_core != NULL);
   // Disabled by default.
-  EXPECT_EQ(0, WebRtcAec_delay_correction_enabled(aec_core));
+  EXPECT_EQ(0, WebRtcAec_extended_filter_enabled(aec_core));
 
   Config config;
-  config.Set<DelayCorrection>(new DelayCorrection(true));
+  config.Set<ExtendedFilter>(new ExtendedFilter(true));
   ap->SetExtraOptions(config);
-  EXPECT_EQ(1, WebRtcAec_delay_correction_enabled(aec_core));
+  EXPECT_EQ(1, WebRtcAec_extended_filter_enabled(aec_core));
 
   // Retains setting after initialization.
   EXPECT_EQ(ap->kNoError, ap->Initialize());
-  EXPECT_EQ(1, WebRtcAec_delay_correction_enabled(aec_core));
+  EXPECT_EQ(1, WebRtcAec_extended_filter_enabled(aec_core));
 
-  config.Set<DelayCorrection>(new DelayCorrection(false));
+  config.Set<ExtendedFilter>(new ExtendedFilter(false));
   ap->SetExtraOptions(config);
-  EXPECT_EQ(0, WebRtcAec_delay_correction_enabled(aec_core));
+  EXPECT_EQ(0, WebRtcAec_extended_filter_enabled(aec_core));
 
   // Retains setting after initialization.
   EXPECT_EQ(ap->kNoError, ap->Initialize());
-  EXPECT_EQ(0, WebRtcAec_delay_correction_enabled(aec_core));
+  EXPECT_EQ(0, WebRtcAec_extended_filter_enabled(aec_core));
 }
 
 TEST(EchoCancellationInternalTest, ReportedDelay) {
diff --git a/webrtc/modules/audio_processing/include/audio_processing.h b/webrtc/modules/audio_processing/include/audio_processing.h
index 8c3436d..a4dd049 100644
--- a/webrtc/modules/audio_processing/include/audio_processing.h
+++ b/webrtc/modules/audio_processing/include/audio_processing.h
@@ -37,10 +37,10 @@
 class NoiseSuppression;
 class VoiceDetection;
 
-// Use to enable the delay correction feature. This now engages an extended
-// filter mode in the AEC, along with robustness measures around the reported
-// system delays. It comes with a significant increase in AEC complexity, but is
-// much more robust to unreliable reported delays.
+// Use to enable the extended filter mode in the AEC, along with robustness
+// measures around the reported system delays. It comes with a significant
+// increase in AEC complexity, but is much more robust to unreliable reported
+// delays.
 //
 // Detailed changes to the algorithm:
 // - The filter length is changed from 48 to 128 ms. This comes with tuning of
@@ -54,11 +54,19 @@
 //   the delay difference more heavily, and back off from the difference more.
 //   Adjustments force a readaptation of the filter, so they should be avoided
 //   except when really necessary.
+// TODO(henrik.lundin): Remove DelayCorrection once ExtendedFilter has
+// propagated through to all channels
+// (https://code.google.com/p/webrtc/issues/detail?id=4696).
 struct DelayCorrection {
   DelayCorrection() : enabled(false) {}
   explicit DelayCorrection(bool enabled) : enabled(enabled) {}
   bool enabled;
 };
+struct ExtendedFilter {
+  ExtendedFilter() : enabled(false) {}
+  explicit ExtendedFilter(bool enabled) : enabled(enabled) {}
+  bool enabled;
+};
 
 // Use to disable the reported system delays. By disabling the reported system
 // delays the echo cancellation algorithm assumes the process and reverse
diff --git a/webrtc/modules/audio_processing/test/audio_processing_unittest.cc b/webrtc/modules/audio_processing/test/audio_processing_unittest.cc
index d3c292a..c19449a 100644
--- a/webrtc/modules/audio_processing/test/audio_processing_unittest.cc
+++ b/webrtc/modules/audio_processing/test/audio_processing_unittest.cc
@@ -1587,7 +1587,7 @@
   // Make sure we have extended filter enabled. This makes sure nothing is
   // touched until we have a farend frame.
   Config config;
-  config.Set<DelayCorrection>(new DelayCorrection(true));
+  config.Set<ExtendedFilter>(new ExtendedFilter(true));
   apm_->SetExtraOptions(config);
   SetFrameTo(frame_, 1000);
   frame_copy.CopyFrom(*frame_);
@@ -1969,8 +1969,8 @@
 
     Config config;
     config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
-    config.Set<DelayCorrection>(
-        new DelayCorrection(test->use_aec_extended_filter()));
+    config.Set<ExtendedFilter>(
+        new ExtendedFilter(test->use_aec_extended_filter()));
     apm_.reset(AudioProcessing::Create(config));
 
     EnableAllComponents();
diff --git a/webrtc/modules/audio_processing/test/process_test.cc b/webrtc/modules/audio_processing/test/process_test.cc
index 23d4d18..0f28a44 100644
--- a/webrtc/modules/audio_processing/test/process_test.cc
+++ b/webrtc/modules/audio_processing/test/process_test.cc
@@ -258,7 +258,7 @@
                         suppression_level)));
 
     } else if (strcmp(argv[i], "--extended_filter") == 0) {
-      config.Set<DelayCorrection>(new DelayCorrection(true));
+      config.Set<ExtendedFilter>(new ExtendedFilter(true));
 
     } else if (strcmp(argv[i], "--no_reported_delay") == 0) {
       config.Set<ReportedDelay>(new ReportedDelay(false));