From bb826c9142e370574335a0529d45cd4a6b3a0c19 Mon Sep 17 00:00:00 2001 From: Ivo Creusen Date: Wed, 29 Apr 2020 14:34:48 +0200 Subject: [PATCH] Make echo metrics optional This makes it optional for an echo detector to report metrics through the getStats interface. Bug: webrtc:11539 Change-Id: I1fef93b7bf534637b69c16971d38709b3e849a08 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174100 Commit-Queue: Ivo Creusen Reviewed-by: Sam Zackrisson Cr-Commit-Position: refs/heads/master@{#31146} --- modules/audio_processing/include/audio_processing.h | 4 ++-- .../residual_echo_detector_unittest.cc | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/audio_processing/include/audio_processing.h b/modules/audio_processing/include/audio_processing.h index 9c2b09f2f4..5f90d7d5e1 100644 --- a/modules/audio_processing/include/audio_processing.h +++ b/modules/audio_processing/include/audio_processing.h @@ -884,8 +884,8 @@ class EchoDetector : public rtc::RefCountInterface { std::vector* packed_buffer); struct Metrics { - double echo_likelihood; - double echo_likelihood_recent_max; + absl::optional echo_likelihood; + absl::optional echo_likelihood_recent_max; }; // Collect current metrics from the echo detector. diff --git a/modules/audio_processing/residual_echo_detector_unittest.cc b/modules/audio_processing/residual_echo_detector_unittest.cc index 84065cdd3f..6697cf009d 100644 --- a/modules/audio_processing/residual_echo_detector_unittest.cc +++ b/modules/audio_processing/residual_echo_detector_unittest.cc @@ -41,7 +41,8 @@ TEST(ResidualEchoDetectorTests, Echo) { } // We expect to detect echo with near certain likelihood. auto ed_metrics = echo_detector->GetMetrics(); - EXPECT_NEAR(1.f, ed_metrics.echo_likelihood, 0.01f); + ASSERT_TRUE(ed_metrics.echo_likelihood); + EXPECT_NEAR(1.f, ed_metrics.echo_likelihood.value(), 0.01f); } TEST(ResidualEchoDetectorTests, NoEcho) { @@ -63,7 +64,8 @@ TEST(ResidualEchoDetectorTests, NoEcho) { } // We expect to not detect any echo. auto ed_metrics = echo_detector->GetMetrics(); - EXPECT_NEAR(0.f, ed_metrics.echo_likelihood, 0.01f); + ASSERT_TRUE(ed_metrics.echo_likelihood); + EXPECT_NEAR(0.f, ed_metrics.echo_likelihood.value(), 0.01f); } TEST(ResidualEchoDetectorTests, EchoWithRenderClockDrift) { @@ -100,7 +102,8 @@ TEST(ResidualEchoDetectorTests, EchoWithRenderClockDrift) { // possible to make this decision right away. For this reason we only expect // an echo likelihood of 75% in this test. auto ed_metrics = echo_detector->GetMetrics(); - EXPECT_GT(ed_metrics.echo_likelihood, 0.75f); + ASSERT_TRUE(ed_metrics.echo_likelihood); + EXPECT_GT(ed_metrics.echo_likelihood.value(), 0.75f); } TEST(ResidualEchoDetectorTests, EchoWithCaptureClockDrift) { @@ -132,7 +135,8 @@ TEST(ResidualEchoDetectorTests, EchoWithCaptureClockDrift) { } // We expect to detect echo with near certain likelihood. auto ed_metrics = echo_detector->GetMetrics(); - EXPECT_NEAR(1.f, ed_metrics.echo_likelihood, 0.01f); + ASSERT_TRUE(ed_metrics.echo_likelihood); + EXPECT_NEAR(1.f, ed_metrics.echo_likelihood.value(), 0.01f); } } // namespace webrtc