diff --git a/modules/audio_processing/aec3/echo_path_delay_estimator.cc b/modules/audio_processing/aec3/echo_path_delay_estimator.cc index 21c3d193f8..0026522d53 100644 --- a/modules/audio_processing/aec3/echo_path_delay_estimator.cc +++ b/modules/audio_processing/aec3/echo_path_delay_estimator.cc @@ -48,6 +48,8 @@ void EchoPathDelayEstimator::Reset(bool soft_reset) { matched_filter_lag_aggregator_.Reset(); } matched_filter_.Reset(); + old_aggregated_lag_ = rtc::nullopt; + consistent_estimate_counter_ = 0; } rtc::Optional EchoPathDelayEstimator::EstimateDelay( @@ -84,6 +86,19 @@ rtc::Optional EchoPathDelayEstimator::EstimateDelay( if (aggregated_matched_filter_lag) { aggregated_matched_filter_lag->delay *= down_sampling_factor_; } + + if (old_aggregated_lag_ && aggregated_matched_filter_lag && + old_aggregated_lag_->delay == aggregated_matched_filter_lag->delay) { + ++consistent_estimate_counter_; + } else { + consistent_estimate_counter_ = 0; + } + old_aggregated_lag_ = aggregated_matched_filter_lag; + constexpr size_t kNumBlocksPerSecondBy2 = kNumBlocksPerSecond / 2; + if (consistent_estimate_counter_ > kNumBlocksPerSecondBy2) { + Reset(true); + } + return aggregated_matched_filter_lag; } diff --git a/modules/audio_processing/aec3/echo_path_delay_estimator.h b/modules/audio_processing/aec3/echo_path_delay_estimator.h index 3277f198a1..6389098102 100644 --- a/modules/audio_processing/aec3/echo_path_delay_estimator.h +++ b/modules/audio_processing/aec3/echo_path_delay_estimator.h @@ -55,6 +55,8 @@ class EchoPathDelayEstimator { Decimator capture_decimator_; MatchedFilter matched_filter_; MatchedFilterLagAggregator matched_filter_lag_aggregator_; + rtc::Optional old_aggregated_lag_; + size_t consistent_estimate_counter_ = 0; RTC_DISALLOW_COPY_AND_ASSIGN(EchoPathDelayEstimator); }; diff --git a/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc b/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc index acd7993782..38f31c9ea6 100644 --- a/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc +++ b/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc @@ -84,8 +84,12 @@ TEST(EchoPathDelayEstimator, DelayEstimation) { render_delay_buffer->PrepareCaptureProcessing(); - estimated_delay_samples = estimator.EstimateDelay( + auto estimate = estimator.EstimateDelay( render_delay_buffer->GetDownsampledRenderBuffer(), capture); + + if (estimate) { + estimated_delay_samples = estimate; + } } if (estimated_delay_samples) {