Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: webrtc/modules/audio_processing/aec3/correlator_lag_aggregator_unittest.cc

Issue 2644123002: Adding full initial version of delay estimation functionality in echo canceller 3 (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_processing/aec3/correlator_lag_aggregator_unittest.cc
diff --git a/webrtc/modules/audio_processing/aec3/correlator_lag_aggregator_unittest.cc b/webrtc/modules/audio_processing/aec3/correlator_lag_aggregator_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..23f9f6242a853fe4f86020e277712474483f2f37
--- /dev/null
+++ b/webrtc/modules/audio_processing/aec3/correlator_lag_aggregator_unittest.cc
@@ -0,0 +1,199 @@
+/*
+ * Copyright (c) 2017 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 "webrtc/modules/audio_processing/aec3/correlator_lag_aggregator.h"
+
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include "webrtc/base/array_view.h"
+#include "webrtc/modules/audio_processing/aec3/aec3_constants.h"
+#include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
+#include "webrtc/test/gtest.h"
+
+namespace webrtc {
+namespace {
+
+void VerifyNoAggregateOutputForRepeatedLagAggregation(
+ size_t num_repetitions,
+ rtc::ArrayView<const Correlator::LagEstimate> lag_estimates,
+ CorrelatorLagAggregator* aggregator) {
+ for (size_t k = 0; k < num_repetitions; ++k) {
+ EXPECT_FALSE(aggregator->Aggregate(lag_estimates));
+ }
+}
+
+constexpr size_t kThresholdForRequiredLagUpdatesInARow = 10;
+constexpr size_t kThresholdForRequiredIdenticalLagAggregates = 10;
+
+} // namespace
+
+// Verifies that the most accurate lag estimate is chosen.
+TEST(CorrelatorLagAggregator, MostAccurateLagChosen) {
+ constexpr size_t kArtificialLag1 = 5;
+ constexpr size_t kArtificialLag2 = 10;
+ ApmDataDumper data_dumper(0);
+ std::vector<Correlator::LagEstimate> lag_estimates(2);
+ CorrelatorLagAggregator aggregator(&data_dumper, lag_estimates.size());
+ lag_estimates[0].Set(1.f, true, kArtificialLag1, true);
+ lag_estimates[1].Set(0.5f, true, kArtificialLag2, true);
+
+ VerifyNoAggregateOutputForRepeatedLagAggregation(
+ kThresholdForRequiredLagUpdatesInARow +
+ kThresholdForRequiredIdenticalLagAggregates,
+ lag_estimates, &aggregator);
+ rtc::Optional<size_t> aggregated_lag = aggregator.Aggregate(lag_estimates);
+ EXPECT_TRUE(aggregated_lag);
+ EXPECT_EQ(kArtificialLag1, *aggregated_lag);
+
+ lag_estimates[0].Set(0.5f, true, kArtificialLag1, true);
+ lag_estimates[1].Set(1.f, true, kArtificialLag2, true);
+
+ VerifyNoAggregateOutputForRepeatedLagAggregation(
+ kThresholdForRequiredIdenticalLagAggregates, lag_estimates, &aggregator);
+ aggregated_lag = aggregator.Aggregate(lag_estimates);
+ EXPECT_TRUE(aggregated_lag);
+ EXPECT_EQ(kArtificialLag2, *aggregated_lag);
+}
+
+// Verifies that varying lag estimates causes lag estimates to not be deemed
+// reliable.
+TEST(CorrelatorLagAggregator, LagEstimateInvarianceRequiredForAggregatedLag) {
+ constexpr size_t kArtificialLag1 = 5;
+ constexpr size_t kArtificialLag2 = 10;
+ ApmDataDumper data_dumper(0);
+ std::vector<Correlator::LagEstimate> lag_estimates(1);
+ CorrelatorLagAggregator aggregator(&data_dumper, lag_estimates.size());
+ lag_estimates[0].Set(1.f, true, kArtificialLag1, true);
+ VerifyNoAggregateOutputForRepeatedLagAggregation(
+ kThresholdForRequiredLagUpdatesInARow +
+ kThresholdForRequiredIdenticalLagAggregates,
+ lag_estimates, &aggregator);
+ rtc::Optional<size_t> aggregated_lag = aggregator.Aggregate(lag_estimates);
+ EXPECT_TRUE(aggregated_lag);
+ EXPECT_EQ(kArtificialLag1, *aggregated_lag);
+
+ lag_estimates[0].Set(1.f, true, kArtificialLag2, true);
+
+ VerifyNoAggregateOutputForRepeatedLagAggregation(
+ kThresholdForRequiredIdenticalLagAggregates, lag_estimates, &aggregator);
+ aggregated_lag = aggregator.Aggregate(lag_estimates);
+ EXPECT_TRUE(aggregated_lag);
+ EXPECT_EQ(kArtificialLag2, *aggregated_lag);
+}
+
+// Verifies that lag estimate updates are required to produce an updated lag
+// aggregate.
+TEST(CorrelatorLagAggregator, LagEstimateUpdatesRequiredForAggregatedLag) {
+ constexpr size_t kArtificialLag1 = 5;
+ constexpr size_t kArtificialLag2 = 10;
+ ApmDataDumper data_dumper(0);
+ std::vector<Correlator::LagEstimate> lag_estimates(1);
+ CorrelatorLagAggregator aggregator(&data_dumper, lag_estimates.size());
+ lag_estimates[0].Set(1.f, true, kArtificialLag1, true);
+ VerifyNoAggregateOutputForRepeatedLagAggregation(
+ kThresholdForRequiredLagUpdatesInARow +
+ kThresholdForRequiredIdenticalLagAggregates,
+ lag_estimates, &aggregator);
+ rtc::Optional<size_t> aggregated_lag = aggregator.Aggregate(lag_estimates);
+ EXPECT_TRUE(aggregated_lag);
+ EXPECT_EQ(kArtificialLag1, *aggregated_lag);
+
+ lag_estimates[0].Set(1.f, true, kArtificialLag2, false);
+ EXPECT_TRUE(aggregated_lag);
hlundin-webrtc 2017/02/01 08:30:01 Nothing changed since last time you checked this.
peah-webrtc 2017/02/02 14:04:46 Done.
+ EXPECT_EQ(kArtificialLag1, *aggregated_lag);
hlundin-webrtc 2017/02/01 08:30:01 And this.
peah-webrtc 2017/02/02 14:04:46 Done.
+
+ for (size_t k = 0; k < kThresholdForRequiredLagUpdatesInARow +
+ kThresholdForRequiredIdenticalLagAggregates + 1;
hlundin-webrtc 2017/02/01 08:30:01 You should be able to break out this for loop into
peah-webrtc 2017/02/02 14:04:46 I added the SCOPED_TRACE. I don't think, however,
+ ++k) {
+ aggregated_lag = aggregator.Aggregate(lag_estimates);
+ EXPECT_TRUE(aggregated_lag);
+ EXPECT_EQ(kArtificialLag1, *aggregated_lag);
+ }
+
+ lag_estimates[0].Set(1.f, true, kArtificialLag2, true);
+ for (size_t k = 0; k < kThresholdForRequiredLagUpdatesInARow; ++k) {
+ aggregated_lag = aggregator.Aggregate(lag_estimates);
+ EXPECT_TRUE(aggregated_lag);
+ EXPECT_EQ(kArtificialLag1, *aggregated_lag);
+ }
+
+ VerifyNoAggregateOutputForRepeatedLagAggregation(
+ kThresholdForRequiredIdenticalLagAggregates, lag_estimates, &aggregator);
+
+ aggregated_lag = aggregator.Aggregate(lag_estimates);
+ EXPECT_TRUE(aggregated_lag);
+ EXPECT_EQ(kArtificialLag2, *aggregated_lag);
+}
+
+// Verifies that an aggregated lag is persistent if the lag estimates do not
+// change.
+TEST(CorrelatorLagAggregator, PersistentAggregatedLag) {
+ constexpr size_t kArtificialLag = 5;
+ ApmDataDumper data_dumper(0);
+ std::vector<Correlator::LagEstimate> lag_estimates(1);
+ CorrelatorLagAggregator aggregator(&data_dumper, lag_estimates.size());
+ lag_estimates[0].Set(1.f, true, kArtificialLag, true);
+ VerifyNoAggregateOutputForRepeatedLagAggregation(
+ kThresholdForRequiredLagUpdatesInARow +
+ kThresholdForRequiredIdenticalLagAggregates,
+ lag_estimates, &aggregator);
+ rtc::Optional<size_t> aggregated_lag = aggregator.Aggregate(lag_estimates);
+ EXPECT_TRUE(aggregated_lag);
+ EXPECT_EQ(kArtificialLag, *aggregated_lag);
+
+ aggregated_lag = aggregator.Aggregate(lag_estimates);
+ EXPECT_TRUE(aggregated_lag);
+ EXPECT_EQ(kArtificialLag, *aggregated_lag);
+}
+
+// Verifies that an aggregated lag is not produced without gaining lag estimate
+// confidence.
+TEST(CorrelatorLagAggregator, DelayBeforeReliableAggregatedLag) {
hlundin-webrtc 2017/02/01 08:30:01 This test is an exact subset of the test above. Re
peah-webrtc 2017/02/02 14:04:46 Done.
+ constexpr size_t kArtificialLag = 5;
+ ApmDataDumper data_dumper(0);
+ std::vector<Correlator::LagEstimate> lag_estimates(1);
+ CorrelatorLagAggregator aggregator(&data_dumper, lag_estimates.size());
+ lag_estimates[0].Set(1.f, true, kArtificialLag, true);
+ VerifyNoAggregateOutputForRepeatedLagAggregation(
+ kThresholdForRequiredLagUpdatesInARow +
+ kThresholdForRequiredIdenticalLagAggregates,
+ lag_estimates, &aggregator);
+ rtc::Optional<size_t> aggregated_lag = aggregator.Aggregate(lag_estimates);
+ EXPECT_TRUE(aggregated_lag);
+ EXPECT_EQ(kArtificialLag, *aggregated_lag);
+}
+
+#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
+
+// Verifies the check for correct number of lag estimates.
+TEST(CorrelatorLagAggregator, IncorrectNumberOfLagEstimates) {
+ ApmDataDumper data_dumper(0);
+ CorrelatorLagAggregator aggregator(&data_dumper, 1);
+ std::vector<Correlator::LagEstimate> lag_estimates(2);
+
+ EXPECT_DEATH(aggregator.Aggregate(lag_estimates), "");
+}
+
+// Verifies the check for non-zero number of lag estimates.
+TEST(CorrelatorLagAggregator, NonZeroLagEstimates) {
+ ApmDataDumper data_dumper(0);
+ EXPECT_DEATH(CorrelatorLagAggregator(&data_dumper, 0), "");
+}
+
+// Verifies the check for non-null data dumper.
+TEST(CorrelatorLagAggregator, NullDataDumper) {
+ EXPECT_DEATH(CorrelatorLagAggregator(nullptr, 1), "");
+}
+
+#endif
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698