From 11556464a62ea14db9eee5e6c2a79a40aa1700ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=85hgren?= Date: Fri, 22 Dec 2017 16:13:57 +0100 Subject: [PATCH] Enforcing a stream delay of 0 to be assumed in the AEC on Chrome OS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL forces the AEC2 to assume a stream delay of 0, thereby avoiding that the incorrect stream delays reported on Chrome OS causes echo issues. Bug: chromium:797274, chromium:797272 Change-Id: I10f295c9f1d735622c55fc56be99a14c6cdd88a2 Reviewed-on: https://webrtc-review.googlesource.com/36081 Reviewed-by: Per Åhgren Reviewed-by: Henrik Lundin Commit-Queue: Per Åhgren Cr-Commit-Position: refs/heads/master@{#21432} --- modules/audio_processing/BUILD.gn | 1 + .../echo_cancellation_impl.cc | 24 +++++++++++++++---- .../audio_processing/echo_cancellation_impl.h | 3 +++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/modules/audio_processing/BUILD.gn b/modules/audio_processing/BUILD.gn index 5ec09d59d4..49db002446 100644 --- a/modules/audio_processing/BUILD.gn +++ b/modules/audio_processing/BUILD.gn @@ -245,6 +245,7 @@ rtc_static_library("audio_processing") { "../../rtc_base:protobuf_utils", "../../rtc_base:sanitizer", "../../system_wrappers:cpu_features_api", + "../../system_wrappers:field_trial_api", "../../system_wrappers:metrics_api", "../audio_coding:isac", ] diff --git a/modules/audio_processing/echo_cancellation_impl.cc b/modules/audio_processing/echo_cancellation_impl.cc index 878d84f42a..99f676c562 100644 --- a/modules/audio_processing/echo_cancellation_impl.cc +++ b/modules/audio_processing/echo_cancellation_impl.cc @@ -16,6 +16,7 @@ #include "modules/audio_processing/aec/echo_cancellation.h" #include "modules/audio_processing/audio_buffer.h" #include "rtc_base/checks.h" +#include "system_wrappers/include/field_trial.h" namespace webrtc { @@ -49,6 +50,14 @@ AudioProcessing::Error MapError(int err) { } } +bool EnforceZeroStreamDelay() { +#if defined(CHROMEOS) + return !field_trial::IsEnabled("WebRTC-Aec2ZeroStreamDelayKillSwitch"); +#else + return false; +#endif +} + } // namespace struct EchoCancellationImpl::StreamProperties { @@ -106,7 +115,8 @@ EchoCancellationImpl::EchoCancellationImpl(rtc::CriticalSection* crit_render, stream_has_echo_(false), delay_logging_enabled_(false), extended_filter_enabled_(false), - delay_agnostic_enabled_(false) { + delay_agnostic_enabled_(false), + enforce_zero_stream_delay_(EnforceZeroStreamDelay()) { RTC_DCHECK(crit_render); RTC_DCHECK(crit_capture); } @@ -145,6 +155,9 @@ int EchoCancellationImpl::ProcessCaptureAudio(AudioBuffer* audio, return AudioProcessing::kNoError; } + const int stream_delay_ms_use = + enforce_zero_stream_delay_ ? 0 : stream_delay_ms; + if (drift_compensation_enabled_ && !was_stream_drift_set_) { return AudioProcessing::kStreamParameterNotSetError; } @@ -160,10 +173,11 @@ int EchoCancellationImpl::ProcessCaptureAudio(AudioBuffer* audio, stream_has_echo_ = false; for (size_t i = 0; i < audio->num_channels(); i++) { for (size_t j = 0; j < stream_properties_->num_reverse_channels; j++) { - err = WebRtcAec_Process( - cancellers_[handle_index]->state(), audio->split_bands_const_f(i), - audio->num_bands(), audio->split_bands_f(i), - audio->num_frames_per_band(), stream_delay_ms, stream_drift_samples_); + err = WebRtcAec_Process(cancellers_[handle_index]->state(), + audio->split_bands_const_f(i), audio->num_bands(), + audio->split_bands_f(i), + audio->num_frames_per_band(), stream_delay_ms_use, + stream_drift_samples_); if (err != AudioProcessing::kNoError) { err = MapError(err); diff --git a/modules/audio_processing/echo_cancellation_impl.h b/modules/audio_processing/echo_cancellation_impl.h index d410a11578..6700249da0 100644 --- a/modules/audio_processing/echo_cancellation_impl.h +++ b/modules/audio_processing/echo_cancellation_impl.h @@ -105,6 +105,9 @@ class EchoCancellationImpl : public EchoCancellation { bool delay_agnostic_enabled_ RTC_GUARDED_BY(crit_capture_); bool refined_adaptive_filter_enabled_ RTC_GUARDED_BY(crit_capture_) = false; + // Only active on Chrome OS devices. + const bool enforce_zero_stream_delay_ RTC_GUARDED_BY(crit_capture_); + std::vector> cancellers_; std::unique_ptr stream_properties_;