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

Side by Side Diff: webrtc/modules/audio_processing/aec3/echo_path_delay_estimator_unittest.cc

Issue 2784023002: Major AEC3 render pipeline changes (Closed)
Patch Set: Disabled one more DEATH test that caused issues due to bug on bots Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h" 11 #include "webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <sstream> 14 #include <sstream>
15 #include <string> 15 #include <string>
16 16
17 #include "webrtc/base/random.h" 17 #include "webrtc/base/random.h"
18 #include "webrtc/modules/audio_processing/aec3/aec3_common.h" 18 #include "webrtc/modules/audio_processing/aec3/aec3_common.h"
19 #include "webrtc/modules/audio_processing/aec3/render_delay_buffer.h"
19 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" 20 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h"
20 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" 21 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h"
21 #include "webrtc/test/gtest.h" 22 #include "webrtc/test/gtest.h"
22 23
23 namespace webrtc { 24 namespace webrtc {
24 namespace { 25 namespace {
25 26
26 std::string ProduceDebugText(size_t delay) { 27 std::string ProduceDebugText(size_t delay) {
27 std::ostringstream ss; 28 std::ostringstream ss;
28 ss << "Delay: " << delay; 29 ss << "Delay: " << delay;
29 return ss.str(); 30 return ss.str();
30 } 31 }
31 32
32 } // namespace 33 } // namespace
33 34
34 // Verifies that the basic API calls work. 35 // Verifies that the basic API calls work.
35 TEST(EchoPathDelayEstimator, BasicApiCalls) { 36 TEST(EchoPathDelayEstimator, BasicApiCalls) {
36 ApmDataDumper data_dumper(0); 37 ApmDataDumper data_dumper(0);
38 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
39 RenderDelayBuffer::Create(3));
37 EchoPathDelayEstimator estimator(&data_dumper); 40 EchoPathDelayEstimator estimator(&data_dumper);
38 std::vector<float> render(kBlockSize, 0.f); 41 std::vector<std::vector<float>> render(3, std::vector<float>(kBlockSize));
39 std::vector<float> capture(kBlockSize, 0.f); 42 std::vector<float> capture(kBlockSize);
40 for (size_t k = 0; k < 100; ++k) { 43 for (size_t k = 0; k < 100; ++k) {
41 estimator.EstimateDelay(render, capture); 44 render_delay_buffer->Insert(render);
45 estimator.EstimateDelay(render_delay_buffer->GetDownsampledRenderBuffer(),
46 capture);
42 } 47 }
43 } 48 }
44 49
45 // Verifies that the delay estimator produces correct delay for artificially 50 // Verifies that the delay estimator produces correct delay for artificially
46 // delayed signals. 51 // delayed signals.
47 TEST(EchoPathDelayEstimator, DelayEstimation) { 52 TEST(EchoPathDelayEstimator, DelayEstimation) {
48 Random random_generator(42U); 53 Random random_generator(42U);
49 std::vector<float> render(kBlockSize, 0.f); 54 std::vector<std::vector<float>> render(3, std::vector<float>(kBlockSize));
50 std::vector<float> capture(kBlockSize, 0.f); 55 std::vector<float> capture(kBlockSize);
51 ApmDataDumper data_dumper(0); 56 ApmDataDumper data_dumper(0);
52 for (size_t delay_samples : {15, 64, 150, 200, 800, 4000}) { 57 for (size_t delay_samples : {15, 64, 150, 200, 800, 4000}) {
53 SCOPED_TRACE(ProduceDebugText(delay_samples)); 58 SCOPED_TRACE(ProduceDebugText(delay_samples));
59 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
60 RenderDelayBuffer::Create(3));
54 DelayBuffer<float> signal_delay_buffer(delay_samples); 61 DelayBuffer<float> signal_delay_buffer(delay_samples);
55 EchoPathDelayEstimator estimator(&data_dumper); 62 EchoPathDelayEstimator estimator(&data_dumper);
56 63
57 rtc::Optional<size_t> estimated_delay_samples; 64 rtc::Optional<size_t> estimated_delay_samples;
58 for (size_t k = 0; k < (100 + delay_samples / kBlockSize); ++k) { 65 for (size_t k = 0; k < (100 + delay_samples / kBlockSize); ++k) {
59 RandomizeSampleVector(&random_generator, render); 66 RandomizeSampleVector(&random_generator, render[0]);
60 signal_delay_buffer.Delay(render, capture); 67 signal_delay_buffer.Delay(render[0], capture);
61 estimated_delay_samples = estimator.EstimateDelay(render, capture); 68 render_delay_buffer->Insert(render);
69 render_delay_buffer->UpdateBuffers();
70 estimated_delay_samples = estimator.EstimateDelay(
71 render_delay_buffer->GetDownsampledRenderBuffer(), capture);
62 } 72 }
63 if (estimated_delay_samples) { 73 if (estimated_delay_samples) {
64 // Due to the internal down-sampling by 4 done inside the delay estimator 74 // Due to the internal down-sampling by 4 done inside the delay estimator
65 // the estimated delay cannot be expected to be closer than 4 samples to 75 // the estimated delay cannot be expected to be closer than 4 samples to
66 // the true delay. 76 // the true delay.
67 EXPECT_NEAR(delay_samples, *estimated_delay_samples, 4); 77 EXPECT_NEAR(delay_samples, *estimated_delay_samples, 4);
68 } else { 78 } else {
69 ADD_FAILURE(); 79 ADD_FAILURE();
70 } 80 }
71 } 81 }
72 } 82 }
73 83
74 // Verifies that the delay estimator does not produce delay estimates too 84 // Verifies that the delay estimator does not produce delay estimates too
75 // quickly. 85 // quickly.
76 TEST(EchoPathDelayEstimator, NoInitialDelayestimates) { 86 TEST(EchoPathDelayEstimator, NoInitialDelayestimates) {
77 Random random_generator(42U); 87 Random random_generator(42U);
78 std::vector<float> render(kBlockSize, 0.f); 88 std::vector<std::vector<float>> render(3, std::vector<float>(kBlockSize));
79 std::vector<float> capture(kBlockSize, 0.f); 89 std::vector<float> capture(kBlockSize);
80 ApmDataDumper data_dumper(0); 90 ApmDataDumper data_dumper(0);
91 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
92 RenderDelayBuffer::Create(3));
81 93
82 EchoPathDelayEstimator estimator(&data_dumper); 94 EchoPathDelayEstimator estimator(&data_dumper);
83 for (size_t k = 0; k < 19; ++k) { 95 for (size_t k = 0; k < 19; ++k) {
84 RandomizeSampleVector(&random_generator, render); 96 RandomizeSampleVector(&random_generator, render[0]);
85 std::copy(render.begin(), render.end(), capture.begin()); 97 std::copy(render[0].begin(), render[0].end(), capture.begin());
86 EXPECT_FALSE(estimator.EstimateDelay(render, capture)); 98 render_delay_buffer->Insert(render);
99 render_delay_buffer->UpdateBuffers();
100 EXPECT_FALSE(estimator.EstimateDelay(
101 render_delay_buffer->GetDownsampledRenderBuffer(), capture));
87 } 102 }
88 } 103 }
89 104
90 // Verifies that the delay estimator does not produce delay estimates for render 105 // Verifies that the delay estimator does not produce delay estimates for render
91 // signals of low level. 106 // signals of low level.
92 TEST(EchoPathDelayEstimator, NoDelayEstimatesForLowLevelRenderSignals) { 107 TEST(EchoPathDelayEstimator, NoDelayEstimatesForLowLevelRenderSignals) {
93 Random random_generator(42U); 108 Random random_generator(42U);
94 std::vector<float> render(kBlockSize, 0.f); 109 std::vector<std::vector<float>> render(3, std::vector<float>(kBlockSize));
95 std::vector<float> capture(kBlockSize, 0.f); 110 std::vector<float> capture(kBlockSize);
96 ApmDataDumper data_dumper(0); 111 ApmDataDumper data_dumper(0);
97 EchoPathDelayEstimator estimator(&data_dumper); 112 EchoPathDelayEstimator estimator(&data_dumper);
113 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
114 RenderDelayBuffer::Create(3));
98 for (size_t k = 0; k < 100; ++k) { 115 for (size_t k = 0; k < 100; ++k) {
99 RandomizeSampleVector(&random_generator, render); 116 RandomizeSampleVector(&random_generator, render[0]);
100 for (auto& render_k : render) { 117 for (auto& render_k : render[0]) {
101 render_k *= 100.f / 32767.f; 118 render_k *= 100.f / 32767.f;
102 } 119 }
103 std::copy(render.begin(), render.end(), capture.begin()); 120 std::copy(render[0].begin(), render[0].end(), capture.begin());
104 EXPECT_FALSE(estimator.EstimateDelay(render, capture)); 121 render_delay_buffer->Insert(render);
122 render_delay_buffer->UpdateBuffers();
123 EXPECT_FALSE(estimator.EstimateDelay(
124 render_delay_buffer->GetDownsampledRenderBuffer(), capture));
105 } 125 }
106 } 126 }
107 127
108 // Verifies that the delay estimator does not produce delay estimates for 128 // Verifies that the delay estimator does not produce delay estimates for
109 // uncorrelated signals. 129 // uncorrelated signals.
110 TEST(EchoPathDelayEstimator, NoDelayEstimatesForUncorrelatedSignals) { 130 TEST(EchoPathDelayEstimator, NoDelayEstimatesForUncorrelatedSignals) {
111 Random random_generator(42U); 131 Random random_generator(42U);
112 std::vector<float> render(kBlockSize, 0.f); 132 std::vector<std::vector<float>> render(3, std::vector<float>(kBlockSize));
113 std::vector<float> capture(kBlockSize, 0.f); 133 std::vector<float> capture(kBlockSize);
114 ApmDataDumper data_dumper(0); 134 ApmDataDumper data_dumper(0);
115 EchoPathDelayEstimator estimator(&data_dumper); 135 EchoPathDelayEstimator estimator(&data_dumper);
136 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
137 RenderDelayBuffer::Create(3));
116 for (size_t k = 0; k < 100; ++k) { 138 for (size_t k = 0; k < 100; ++k) {
117 RandomizeSampleVector(&random_generator, render); 139 RandomizeSampleVector(&random_generator, render[0]);
118 RandomizeSampleVector(&random_generator, capture); 140 RandomizeSampleVector(&random_generator, capture);
119 EXPECT_FALSE(estimator.EstimateDelay(render, capture)); 141 render_delay_buffer->Insert(render);
142 render_delay_buffer->UpdateBuffers();
143 EXPECT_FALSE(estimator.EstimateDelay(
144 render_delay_buffer->GetDownsampledRenderBuffer(), capture));
120 } 145 }
121 } 146 }
122 147
123 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 148 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
124 149
125 // Verifies the check for the render blocksize. 150 // Verifies the check for the render blocksize.
126 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH 151 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH
127 // tests on test bots has been fixed. 152 // tests on test bots has been fixed.
128 TEST(EchoPathDelayEstimator, DISABLED_WrongRenderBlockSize) { 153 TEST(EchoPathDelayEstimator, DISABLED_WrongRenderBlockSize) {
129 ApmDataDumper data_dumper(0); 154 ApmDataDumper data_dumper(0);
130 EchoPathDelayEstimator estimator(&data_dumper); 155 EchoPathDelayEstimator estimator(&data_dumper);
131 std::vector<float> render(std::vector<float>(kBlockSize - 1, 0.f)); 156 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
132 std::vector<float> capture(std::vector<float>(kBlockSize, 0.f)); 157 RenderDelayBuffer::Create(3));
133 EXPECT_DEATH(estimator.EstimateDelay(render, capture), ""); 158 std::vector<float> capture(kBlockSize);
159 EXPECT_DEATH(estimator.EstimateDelay(
160 render_delay_buffer->GetDownsampledRenderBuffer(), capture),
161 "");
134 } 162 }
135 163
136 // Verifies the check for the capture blocksize. 164 // Verifies the check for the capture blocksize.
137 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH 165 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH
138 // tests on test bots has been fixed. 166 // tests on test bots has been fixed.
139 TEST(EchoPathDelayEstimator, WrongCaptureBlockSize) { 167 TEST(EchoPathDelayEstimator, WrongCaptureBlockSize) {
140 ApmDataDumper data_dumper(0); 168 ApmDataDumper data_dumper(0);
141 EchoPathDelayEstimator estimator(&data_dumper); 169 EchoPathDelayEstimator estimator(&data_dumper);
142 std::vector<float> render(std::vector<float>(kBlockSize, 0.f)); 170 std::unique_ptr<RenderDelayBuffer> render_delay_buffer(
143 std::vector<float> capture(std::vector<float>(kBlockSize - 1, 0.f)); 171 RenderDelayBuffer::Create(3));
144 EXPECT_DEATH(estimator.EstimateDelay(render, capture), ""); 172 std::vector<float> capture(std::vector<float>(kBlockSize - 1));
173 EXPECT_DEATH(estimator.EstimateDelay(
174 render_delay_buffer->GetDownsampledRenderBuffer(), capture),
175 "");
145 } 176 }
146 177
147 // Verifies the check for non-null data dumper. 178 // Verifies the check for non-null data dumper.
148 TEST(EchoPathDelayEstimator, NullDataDumper) { 179 TEST(EchoPathDelayEstimator, NullDataDumper) {
149 EXPECT_DEATH(EchoPathDelayEstimator(nullptr), ""); 180 EXPECT_DEATH(EchoPathDelayEstimator(nullptr), "");
150 } 181 }
151 182
152 #endif 183 #endif
153 184
154 } // namespace webrtc 185 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/aec3/echo_path_delay_estimator.cc ('k') | webrtc/modules/audio_processing/aec3/echo_remover.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698