Add AEC proxies for simple deprecation of AEC configurability.
Some changes need access to both the APM interface and the AECs,
hence we can't make the changes inside the AECs themselves.
The proxies also make it easy to drop support for individual parts of the
interfaces one at a time.
Bug: webrtc:9535
Change-Id: I3398e1182157f7d8b1e4c455060b830b61c20dd9
Reviewed-on: https://webrtc-review.googlesource.com/94500
Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org>
Commit-Queue: Sam Zackrisson <saza@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24317}
diff --git a/modules/audio_processing/BUILD.gn b/modules/audio_processing/BUILD.gn
index 71fbcf6..9e71446 100644
--- a/modules/audio_processing/BUILD.gn
+++ b/modules/audio_processing/BUILD.gn
@@ -37,8 +37,12 @@
"common.h",
"echo_cancellation_impl.cc",
"echo_cancellation_impl.h",
+ "echo_cancellation_proxy.cc",
+ "echo_cancellation_proxy.h",
"echo_control_mobile_impl.cc",
"echo_control_mobile_impl.h",
+ "echo_control_mobile_proxy.cc",
+ "echo_control_mobile_proxy.h",
"echo_detector/circular_buffer.cc",
"echo_detector/circular_buffer.h",
"echo_detector/mean_variance_estimator.cc",
diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc
index 3711375..5269385 100644
--- a/modules/audio_processing/audio_processing_impl.cc
+++ b/modules/audio_processing/audio_processing_impl.cc
@@ -24,7 +24,9 @@
#include "modules/audio_processing/audio_buffer.h"
#include "modules/audio_processing/common.h"
#include "modules/audio_processing/echo_cancellation_impl.h"
+#include "modules/audio_processing/echo_cancellation_proxy.h"
#include "modules/audio_processing/echo_control_mobile_impl.h"
+#include "modules/audio_processing/echo_control_mobile_proxy.h"
#include "modules/audio_processing/gain_control_for_experimental_agc.h"
#include "modules/audio_processing/gain_control_impl.h"
#include "modules/audio_processing/gain_controller2.h"
@@ -264,6 +266,8 @@
// Accessed externally of APM without any lock acquired.
std::unique_ptr<EchoCancellationImpl> echo_cancellation;
std::unique_ptr<EchoControlMobileImpl> echo_control_mobile;
+ std::unique_ptr<EchoCancellationProxy> echo_cancellation_proxy;
+ std::unique_ptr<EchoControlMobileProxy> echo_control_mobile_proxy;
std::unique_ptr<GainControlImpl> gain_control;
std::unique_ptr<LevelEstimatorImpl> level_estimator;
std::unique_ptr<NoiseSuppressionImpl> noise_suppression;
@@ -394,6 +398,11 @@
new EchoCancellationImpl(&crit_render_, &crit_capture_));
public_submodules_->echo_control_mobile.reset(
new EchoControlMobileImpl(&crit_render_, &crit_capture_));
+ public_submodules_->echo_cancellation_proxy.reset(new EchoCancellationProxy(
+ this, public_submodules_->echo_cancellation.get()));
+ public_submodules_->echo_control_mobile_proxy.reset(
+ new EchoControlMobileProxy(
+ this, public_submodules_->echo_control_mobile.get()));
public_submodules_->gain_control.reset(
new GainControlImpl(&crit_render_, &crit_capture_));
public_submodules_->level_estimator.reset(
@@ -1714,11 +1723,11 @@
}
EchoCancellation* AudioProcessingImpl::echo_cancellation() const {
- return public_submodules_->echo_cancellation.get();
+ return public_submodules_->echo_cancellation_proxy.get();
}
EchoControlMobile* AudioProcessingImpl::echo_control_mobile() const {
- return public_submodules_->echo_control_mobile.get();
+ return public_submodules_->echo_control_mobile_proxy.get();
}
GainControl* AudioProcessingImpl::gain_control() const {
diff --git a/modules/audio_processing/echo_cancellation_proxy.cc b/modules/audio_processing/echo_cancellation_proxy.cc
new file mode 100644
index 0000000..e8b1fbd
--- /dev/null
+++ b/modules/audio_processing/echo_cancellation_proxy.cc
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "modules/audio_processing/echo_cancellation_proxy.h"
+
+namespace webrtc {
+
+EchoCancellationProxy::EchoCancellationProxy(
+ AudioProcessing* audio_processing,
+ EchoCancellation* echo_cancellation)
+ : audio_processing_(audio_processing),
+ echo_cancellation_(echo_cancellation) {}
+
+EchoCancellationProxy::~EchoCancellationProxy() = default;
+
+int EchoCancellationProxy::Enable(bool enable) {
+ // Change the config in APM to mirror the applied settings.
+ // TODO(bugs.webrtc.org/9535): Remove the call to EchoCancellation::Enable
+ // when APM starts taking the config into account.
+ AudioProcessing::Config apm_config = audio_processing_->GetConfig();
+ bool aec2_enabled = apm_config.echo_canceller.enabled &&
+ !apm_config.echo_canceller.mobile_mode;
+ if ((aec2_enabled && !enable) || (!aec2_enabled && enable)) {
+ apm_config.echo_canceller.enabled = enable;
+ apm_config.echo_canceller.mobile_mode = false;
+ audio_processing_->ApplyConfig(apm_config);
+ }
+ echo_cancellation_->Enable(enable);
+ return AudioProcessing::kNoError;
+}
+
+bool EchoCancellationProxy::is_enabled() const {
+ return echo_cancellation_->is_enabled();
+}
+
+int EchoCancellationProxy::enable_drift_compensation(bool enable) {
+ return echo_cancellation_->enable_drift_compensation(enable);
+}
+
+bool EchoCancellationProxy::is_drift_compensation_enabled() const {
+ return echo_cancellation_->is_drift_compensation_enabled();
+}
+
+void EchoCancellationProxy::set_stream_drift_samples(int drift) {
+ echo_cancellation_->set_stream_drift_samples(drift);
+}
+
+int EchoCancellationProxy::stream_drift_samples() const {
+ return echo_cancellation_->stream_drift_samples();
+}
+
+int EchoCancellationProxy::set_suppression_level(
+ EchoCancellation::SuppressionLevel level) {
+ return echo_cancellation_->set_suppression_level(level);
+}
+
+EchoCancellation::SuppressionLevel EchoCancellationProxy::suppression_level()
+ const {
+ return echo_cancellation_->suppression_level();
+}
+
+bool EchoCancellationProxy::stream_has_echo() const {
+ return echo_cancellation_->stream_has_echo();
+}
+int EchoCancellationProxy::enable_metrics(bool enable) {
+ return echo_cancellation_->enable_metrics(enable);
+}
+bool EchoCancellationProxy::are_metrics_enabled() const {
+ return echo_cancellation_->are_metrics_enabled();
+}
+int EchoCancellationProxy::GetMetrics(Metrics* metrics) {
+ return echo_cancellation_->GetMetrics(metrics);
+}
+int EchoCancellationProxy::enable_delay_logging(bool enable) {
+ return echo_cancellation_->enable_delay_logging(enable);
+}
+bool EchoCancellationProxy::is_delay_logging_enabled() const {
+ return echo_cancellation_->is_delay_logging_enabled();
+}
+int EchoCancellationProxy::GetDelayMetrics(int* median, int* std) {
+ return echo_cancellation_->GetDelayMetrics(median, std);
+}
+int EchoCancellationProxy::GetDelayMetrics(int* median,
+ int* std,
+ float* fraction_poor_delays) {
+ return echo_cancellation_->GetDelayMetrics(median, std, fraction_poor_delays);
+}
+
+struct AecCore* EchoCancellationProxy::aec_core() const {
+ return echo_cancellation_->aec_core();
+}
+
+} // namespace webrtc
diff --git a/modules/audio_processing/echo_cancellation_proxy.h b/modules/audio_processing/echo_cancellation_proxy.h
new file mode 100644
index 0000000..f2d3017
--- /dev/null
+++ b/modules/audio_processing/echo_cancellation_proxy.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_PROXY_H_
+#define MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_PROXY_H_
+
+#include "modules/audio_processing/include/audio_processing.h"
+#include "rtc_base/constructormagic.h"
+#include "rtc_base/scoped_ref_ptr.h"
+
+namespace webrtc {
+
+// Class for temporarily redirecting AEC2 configuration to a new API.
+class EchoCancellationProxy : public EchoCancellation {
+ public:
+ EchoCancellationProxy(AudioProcessing* audio_processing,
+ EchoCancellation* echo_cancellation);
+ ~EchoCancellationProxy() override;
+
+ int Enable(bool enable) override;
+ bool is_enabled() const override;
+ int enable_drift_compensation(bool enable) override;
+ bool is_drift_compensation_enabled() const override;
+ void set_stream_drift_samples(int drift) override;
+ int stream_drift_samples() const override;
+ int set_suppression_level(SuppressionLevel level) override;
+ SuppressionLevel suppression_level() const override;
+ bool stream_has_echo() const override;
+ int enable_metrics(bool enable) override;
+ bool are_metrics_enabled() const override;
+ int GetMetrics(Metrics* metrics) override;
+ int enable_delay_logging(bool enable) override;
+ bool is_delay_logging_enabled() const override;
+ int GetDelayMetrics(int* median, int* std) override;
+ int GetDelayMetrics(int* median,
+ int* std,
+ float* fraction_poor_delays) override;
+ struct AecCore* aec_core() const override;
+
+ private:
+ AudioProcessing* audio_processing_;
+ EchoCancellation* echo_cancellation_;
+
+ RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoCancellationProxy);
+};
+} // namespace webrtc
+
+#endif // MODULES_AUDIO_PROCESSING_ECHO_CANCELLATION_PROXY_H_
diff --git a/modules/audio_processing/echo_control_mobile_proxy.cc b/modules/audio_processing/echo_control_mobile_proxy.cc
new file mode 100644
index 0000000..fd29834
--- /dev/null
+++ b/modules/audio_processing/echo_control_mobile_proxy.cc
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "modules/audio_processing/echo_control_mobile_proxy.h"
+
+namespace webrtc {
+
+EchoControlMobileProxy::EchoControlMobileProxy(
+ AudioProcessing* audio_processing,
+ EchoControlMobile* echo_control_mobile)
+ : audio_processing_(audio_processing),
+ echo_control_mobile_(echo_control_mobile) {}
+
+EchoControlMobileProxy::~EchoControlMobileProxy() = default;
+
+int EchoControlMobileProxy::Enable(bool enable) {
+ // Change the config in APM to mirror the applied settings.
+ // TODO(bugs.webrtc.org/9535): Remove the call to EchoControlMobile::Enable
+ // when APM starts taking the config into account.
+ AudioProcessing::Config apm_config = audio_processing_->GetConfig();
+ bool aecm_enabled = apm_config.echo_canceller.enabled &&
+ apm_config.echo_canceller.mobile_mode;
+ if ((aecm_enabled && !enable) || (!aecm_enabled && enable)) {
+ apm_config.echo_canceller.enabled = enable;
+ apm_config.echo_canceller.mobile_mode = true;
+ audio_processing_->ApplyConfig(apm_config);
+ }
+ echo_control_mobile_->Enable(enable);
+ return AudioProcessing::kNoError;
+}
+
+bool EchoControlMobileProxy::is_enabled() const {
+ return echo_control_mobile_->is_enabled();
+}
+
+int EchoControlMobileProxy::set_routing_mode(RoutingMode mode) {
+ return echo_control_mobile_->set_routing_mode(mode);
+}
+
+EchoControlMobile::RoutingMode EchoControlMobileProxy::routing_mode() const {
+ return echo_control_mobile_->routing_mode();
+}
+
+int EchoControlMobileProxy::enable_comfort_noise(bool enable) {
+ return echo_control_mobile_->enable_comfort_noise(enable);
+}
+
+bool EchoControlMobileProxy::is_comfort_noise_enabled() const {
+ return echo_control_mobile_->is_comfort_noise_enabled();
+}
+
+int EchoControlMobileProxy::SetEchoPath(const void* echo_path,
+ size_t size_bytes) {
+ return echo_control_mobile_->SetEchoPath(echo_path, size_bytes);
+}
+
+int EchoControlMobileProxy::GetEchoPath(void* echo_path,
+ size_t size_bytes) const {
+ return echo_control_mobile_->GetEchoPath(echo_path, size_bytes);
+}
+
+} // namespace webrtc
diff --git a/modules/audio_processing/echo_control_mobile_proxy.h b/modules/audio_processing/echo_control_mobile_proxy.h
new file mode 100644
index 0000000..eb5908a
--- /dev/null
+++ b/modules/audio_processing/echo_control_mobile_proxy.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_PROXY_H_
+#define MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_PROXY_H_
+
+#include "modules/audio_processing/include/audio_processing.h"
+#include "rtc_base/constructormagic.h"
+#include "rtc_base/scoped_ref_ptr.h"
+
+namespace webrtc {
+
+// Class for temporarily redirecting AECM configuration to a new API.
+class EchoControlMobileProxy : public EchoControlMobile {
+ public:
+ EchoControlMobileProxy(AudioProcessing* audio_processing,
+ EchoControlMobile* echo_control_mobile);
+ ~EchoControlMobileProxy() override;
+
+ bool is_enabled() const override;
+ RoutingMode routing_mode() const override;
+ bool is_comfort_noise_enabled() const override;
+ int Enable(bool enable) override;
+ int set_routing_mode(RoutingMode mode) override;
+ int enable_comfort_noise(bool enable) override;
+ int SetEchoPath(const void* echo_path, size_t size_bytes) override;
+ int GetEchoPath(void* echo_path, size_t size_bytes) const override;
+
+ private:
+ AudioProcessing* audio_processing_;
+ EchoControlMobile* echo_control_mobile_;
+
+ RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoControlMobileProxy);
+};
+} // namespace webrtc
+
+#endif // MODULES_AUDIO_PROCESSING_ECHO_CONTROL_MOBILE_PROXY_H_