From e9d3760d5cd0f4bb1821897dc995dcbe3cfdccaa Mon Sep 17 00:00:00 2001 From: "bjornv@webrtc.org" Date: Wed, 23 Apr 2014 13:20:07 +0000 Subject: [PATCH] AEC: Adds a reported_delay_enabled_ flag Adds a feature to completely turn on or off buffer handling based on reported delay values. During startup, reported delays are controlled differently through, e.g., WEBRTC_UNTRUSTED_DELAY. By default, the feature is enabled giving the same output as before this change. TESTED=trybots, modules_unittest R=aluebs@webrtc.org, andrew@webrtc.org, kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/12349005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5965 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/audio_processing/aec/aec_core.c | 9 +++++++++ webrtc/modules/audio_processing/aec/aec_core.h | 6 ++++++ webrtc/modules/audio_processing/aec/aec_core_internal.h | 1 + webrtc/modules/audio_processing/aec/echo_cancellation.c | 8 ++++++-- .../modules/audio_processing/echo_cancellation_impl.cc | 5 ++++- webrtc/modules/audio_processing/echo_cancellation_impl.h | 1 + 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/webrtc/modules/audio_processing/aec/aec_core.c b/webrtc/modules/audio_processing/aec/aec_core.c index 3f3d2c088..b1b0e11a1 100644 --- a/webrtc/modules/audio_processing/aec/aec_core.c +++ b/webrtc/modules/audio_processing/aec/aec_core.c @@ -473,6 +473,7 @@ int WebRtcAec_InitAec(AecCore* aec, int sampFreq) { aec->delay_logging_enabled = 0; memset(aec->delay_histogram, 0, sizeof(aec->delay_histogram)); + aec->reported_delay_enabled = 1; aec->extended_filter_enabled = 0; aec->num_partitions = kNormalNumPartitions; @@ -785,6 +786,14 @@ void WebRtcAec_SetConfigCore(AecCore* self, } } +void WebRtcAec_enable_reported_delay(AecCore* self, int enable) { + self->reported_delay_enabled = enable; +} + +int WebRtcAec_reported_delay_enabled(AecCore* self) { + return self->reported_delay_enabled; +} + void WebRtcAec_enable_delay_correction(AecCore* self, int enable) { self->extended_filter_enabled = enable; self->num_partitions = enable ? kExtendedNumPartitions : kNormalNumPartitions; diff --git a/webrtc/modules/audio_processing/aec/aec_core.h b/webrtc/modules/audio_processing/aec/aec_core.h index e1f6f903d..9f302b79f 100644 --- a/webrtc/modules/audio_processing/aec/aec_core.h +++ b/webrtc/modules/audio_processing/aec/aec_core.h @@ -104,6 +104,12 @@ void WebRtcAec_SetConfigCore(AecCore* self, int metrics_mode, int delay_logging); +// Non-zero enables, zero disables. +void WebRtcAec_enable_reported_delay(AecCore* self, int enable); + +// 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 diff --git a/webrtc/modules/audio_processing/aec/aec_core_internal.h b/webrtc/modules/audio_processing/aec/aec_core_internal.h index c6b762ab1..ba7cd347f 100644 --- a/webrtc/modules/audio_processing/aec/aec_core_internal.h +++ b/webrtc/modules/audio_processing/aec/aec_core_internal.h @@ -122,6 +122,7 @@ struct AecCore { void* delay_estimator_farend; void* delay_estimator; + int reported_delay_enabled; // 0 = disabled, otherwise enabled. // 1 = extended filter mode enabled, 0 = disabled. int extended_filter_enabled; // Runtime selection of number of filter partitions. diff --git a/webrtc/modules/audio_processing/aec/echo_cancellation.c b/webrtc/modules/audio_processing/aec/echo_cancellation.c index bbdd5f628..d8b443018 100644 --- a/webrtc/modules/audio_processing/aec/echo_cancellation.c +++ b/webrtc/modules/audio_processing/aec/echo_cancellation.c @@ -766,7 +766,9 @@ static int ProcessNormal(aecpc_t* aecpc, } } else { // AEC is enabled. - EstBufDelayNormal(aecpc); + if (WebRtcAec_reported_delay_enabled(aecpc->aec)) { + EstBufDelayNormal(aecpc); + } // Note that 1 frame is supported for NB and 2 frames for WB. for (i = 0; i < nFrames; i++) { @@ -842,7 +844,9 @@ static void ProcessExtended(aecpc_t* self, self->startup_phase = 0; } - EstBufDelayExtended(self); + if (WebRtcAec_reported_delay_enabled(self->aec)) { + EstBufDelayExtended(self); + } { // |delay_diff_offset| gives us the option to manually rewind the delay on diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl.cc b/webrtc/modules/audio_processing/echo_cancellation_impl.cc index f0bd95ec0..d4bd781bc 100644 --- a/webrtc/modules/audio_processing/echo_cancellation_impl.cc +++ b/webrtc/modules/audio_processing/echo_cancellation_impl.cc @@ -67,7 +67,8 @@ EchoCancellationImpl::EchoCancellationImpl(const AudioProcessing* apm, was_stream_drift_set_(false), stream_has_echo_(false), delay_logging_enabled_(false), - delay_correction_enabled_(false) {} + delay_correction_enabled_(false), + reported_delay_enabled_(true) {} EchoCancellationImpl::~EchoCancellationImpl() {} @@ -361,6 +362,8 @@ int EchoCancellationImpl::ConfigureHandle(void* handle) const { WebRtcAec_enable_delay_correction(WebRtcAec_aec_core( static_cast(handle)), delay_correction_enabled_ ? 1 : 0); + WebRtcAec_enable_reported_delay(WebRtcAec_aec_core( + static_cast(handle)), reported_delay_enabled_ ? 1 : 0); return WebRtcAec_set_config(static_cast(handle), config); } diff --git a/webrtc/modules/audio_processing/echo_cancellation_impl.h b/webrtc/modules/audio_processing/echo_cancellation_impl.h index b36419303..b9c116a06 100644 --- a/webrtc/modules/audio_processing/echo_cancellation_impl.h +++ b/webrtc/modules/audio_processing/echo_cancellation_impl.h @@ -72,6 +72,7 @@ class EchoCancellationImpl : public EchoCancellation, bool stream_has_echo_; bool delay_logging_enabled_; bool delay_correction_enabled_; + bool reported_delay_enabled_; }; } // namespace webrtc