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

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

Issue 2584493002: Added first layer of the echo canceller 3 functionality (Closed)
Patch Set: Disabled the BlockProcessor DEATH tests due to false alarms on the trybots 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/audio_processing/aec3/echo_canceller3.h"
12
13 #include <deque>
14 #include <memory>
15 #include <sstream>
16 #include <string>
17 #include <utility>
18 #include <vector>
19
20 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h"
21 #include "webrtc/modules/audio_processing/aec3/block_processor.h"
22 #include "webrtc/modules/audio_processing/aec3/frame_blocker.h"
23 #include "webrtc/modules/audio_processing/aec3/mock/mock_block_processor.h"
24 #include "webrtc/modules/audio_processing/audio_buffer.h"
25 #include "webrtc/test/gmock.h"
26 #include "webrtc/test/gtest.h"
27
28 namespace webrtc {
29 namespace {
30
31 using testing::StrictMock;
32 using testing::_;
33
34 // Populates the frame with linearly increasing sample values for each band,
35 // with a band-specific offset, in order to allow simple bitexactness
36 // verification for each band.
37 void PopulateInputFrame(size_t frame_length,
38 size_t num_bands,
39 size_t frame_index,
40 float* const* frame,
41 int offset) {
42 for (size_t k = 0; k < num_bands; ++k) {
43 for (size_t i = 0; i < frame_length; ++i) {
44 float value = static_cast<int>(frame_index * frame_length + i) + offset;
45 frame[k][i] = (value > 0 ? 5000 * k + value : 0);
46 }
47 }
48 }
49
50 // Verifies the that samples in the output frame are identical to the samples
51 // that were produced for the input frame, with an offset in order to compensate
52 // for buffering delays.
53 bool VerifyOutputFrameBitexactness(size_t frame_length,
54 size_t num_bands,
55 size_t frame_index,
56 const float* const* frame,
57 int offset) {
58 float reference_frame_data[kMaxNumBands][2 * kSubFrameLength];
59 float* reference_frame[kMaxNumBands];
60 for (size_t k = 0; k < num_bands; ++k) {
61 reference_frame[k] = &reference_frame_data[k][0];
62 }
63
64 PopulateInputFrame(frame_length, num_bands, frame_index, reference_frame,
65 offset);
66 for (size_t k = 0; k < num_bands; ++k) {
67 for (size_t i = 0; i < frame_length; ++i) {
68 if (reference_frame[k][i] != frame[k][i]) {
69 return false;
70 }
71 }
72 }
73
74 return true;
75 }
76
77 // Class for testing that the capture data is properly received by the block
78 // processor and that the processor data is properly passed to the
79 // EchoCanceller3 output.
80 class CaptureTransportVerificationProcessor : public BlockProcessor {
81 public:
82 explicit CaptureTransportVerificationProcessor(size_t num_bands) {}
83 ~CaptureTransportVerificationProcessor() override = default;
84
85 void ProcessCapture(bool known_echo_path_change,
86 bool saturated_microphone_signal,
87 std::vector<std::vector<float>>* capture_block) override {
88 }
89
90 bool BufferRender(std::vector<std::vector<float>>* block) override {
91 return false;
92 }
93
94 void ReportEchoLeakage(bool leakage_detected) override {}
95
96 private:
97 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CaptureTransportVerificationProcessor);
98 };
99
100 // Class for testing that the render data is properly received by the block
101 // processor.
102 class RenderTransportVerificationProcessor : public BlockProcessor {
103 public:
104 explicit RenderTransportVerificationProcessor(size_t num_bands) {}
105 ~RenderTransportVerificationProcessor() override = default;
106
107 void ProcessCapture(bool known_echo_path_change,
108 bool saturated_microphone_signal,
109 std::vector<std::vector<float>>* capture_block) override {
110 std::vector<std::vector<float>> render_block =
111 received_render_blocks_.front();
112 received_render_blocks_.pop_front();
113 capture_block->swap(render_block);
114 }
115
116 bool BufferRender(std::vector<std::vector<float>>* block) override {
117 received_render_blocks_.push_back(*block);
118 return false;
119 }
120
121 void ReportEchoLeakage(bool leakage_detected) override {}
122
123 private:
124 std::deque<std::vector<std::vector<float>>> received_render_blocks_;
125 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderTransportVerificationProcessor);
126 };
127
128 class EchoCanceller3Tester {
129 public:
130 explicit EchoCanceller3Tester(int sample_rate_hz)
131 : sample_rate_hz_(sample_rate_hz),
132 num_bands_(NumBandsForRate(sample_rate_hz_)),
133 frame_length_(sample_rate_hz_ == 8000 ? 80 : 160),
134 fullband_frame_length_(rtc::CheckedDivExact(sample_rate_hz_, 100)),
135 capture_buffer_(fullband_frame_length_,
136 1,
137 fullband_frame_length_,
138 1,
139 fullband_frame_length_),
140 render_buffer_(fullband_frame_length_,
141 1,
142 fullband_frame_length_,
143 1,
144 fullband_frame_length_) {}
145
146 // Verifies that the capture data is properly received by the block processor
147 // and that the processor data is properly passed to the EchoCanceller3
148 // output.
149 void RunCaptureTransportVerificationTest() {
150 EchoCanceller3 aec3(
151 sample_rate_hz_, false,
152 std::unique_ptr<BlockProcessor>(
153 new CaptureTransportVerificationProcessor(num_bands_)));
154
155 for (size_t frame_index = 0; frame_index < kNumFramesToProcess;
156 ++frame_index) {
157 aec3.AnalyzeCapture(&capture_buffer_);
158 OptionalBandSplit();
159 PopulateInputFrame(frame_length_, num_bands_, frame_index,
160 &capture_buffer_.split_bands_f(0)[0], 0);
161 PopulateInputFrame(frame_length_, num_bands_, frame_index,
162 &render_buffer_.split_bands_f(0)[0], 100);
163
164 EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_));
165 aec3.ProcessCapture(&capture_buffer_, false);
166 EXPECT_TRUE(VerifyOutputFrameBitexactness(
167 frame_length_, num_bands_, frame_index,
168 &capture_buffer_.split_bands_f(0)[0], -64));
169 }
170 }
171
172 // Test method for testing that the render data is properly received by the
173 // block processor.
174 void RunRenderTransportVerificationTest() {
175 EchoCanceller3 aec3(
176 sample_rate_hz_, false,
177 std::unique_ptr<BlockProcessor>(
178 new RenderTransportVerificationProcessor(num_bands_)));
179
180 for (size_t frame_index = 0; frame_index < kNumFramesToProcess;
181 ++frame_index) {
182 aec3.AnalyzeCapture(&capture_buffer_);
183 OptionalBandSplit();
184 PopulateInputFrame(frame_length_, num_bands_, frame_index,
185 &capture_buffer_.split_bands_f(0)[0], 100);
186 PopulateInputFrame(frame_length_, num_bands_, frame_index,
187 &render_buffer_.split_bands_f(0)[0], 0);
188
189 EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_));
190 aec3.ProcessCapture(&capture_buffer_, false);
191 EXPECT_TRUE(VerifyOutputFrameBitexactness(
192 frame_length_, num_bands_, frame_index,
193 &capture_buffer_.split_bands_f(0)[0], -64));
194 }
195 }
196
197 // Verifies that information about echo path changes are properly propagated
198 // to the block processor.
199 // The cases tested are:
200 // -That no set echo path change flags are received when there is no echo path
201 // change.
202 // -That set echo path change flags are received and continues to be received
203 // as long as echo path changes are flagged.
204 // -That set echo path change flags are no longer received when echo path
205 // change events stop being flagged.
206 enum class EchoPathChangeTestVariant { kNone, kOneSticky, kOneNonSticky };
207
208 void RunEchoPathChangeVerificationTest(
209 EchoPathChangeTestVariant echo_path_change_test_variant) {
210 const size_t num_full_blocks_per_frame =
211 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100) / kBlockSize;
212 const size_t expected_num_block_to_process =
213 (kNumFramesToProcess *
214 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) /
215 kBlockSize;
216 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>>
217 block_processor_mock(
218 new StrictMock<webrtc::test::MockBlockProcessor>());
219 EXPECT_CALL(*block_processor_mock, BufferRender(_))
220 .Times(expected_num_block_to_process);
221 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(_)).Times(0);
222
223 switch (echo_path_change_test_variant) {
224 case EchoPathChangeTestVariant::kNone:
225 EXPECT_CALL(*block_processor_mock, ProcessCapture(false, _, _))
226 .Times(expected_num_block_to_process);
227 break;
228 case EchoPathChangeTestVariant::kOneSticky:
229 EXPECT_CALL(*block_processor_mock, ProcessCapture(true, _, _))
230 .Times(expected_num_block_to_process);
231 break;
232 case EchoPathChangeTestVariant::kOneNonSticky:
233 EXPECT_CALL(*block_processor_mock, ProcessCapture(true, _, _))
234 .Times(num_full_blocks_per_frame);
235 EXPECT_CALL(*block_processor_mock, ProcessCapture(false, _, _))
236 .Times(expected_num_block_to_process - num_full_blocks_per_frame);
237 break;
238 }
239
240 EchoCanceller3 aec3(sample_rate_hz_, false,
241 std::move(block_processor_mock));
242
243 for (size_t frame_index = 0; frame_index < kNumFramesToProcess;
244 ++frame_index) {
245 bool echo_path_change = false;
246 switch (echo_path_change_test_variant) {
247 case EchoPathChangeTestVariant::kNone:
248 break;
249 case EchoPathChangeTestVariant::kOneSticky:
250 echo_path_change = true;
251 break;
252 case EchoPathChangeTestVariant::kOneNonSticky:
253 if (frame_index == 0) {
254 echo_path_change = true;
255 }
256 break;
257 }
258
259 aec3.AnalyzeCapture(&capture_buffer_);
260 OptionalBandSplit();
261
262 PopulateInputFrame(frame_length_, num_bands_, frame_index,
263 &capture_buffer_.split_bands_f(0)[0], 0);
264 PopulateInputFrame(frame_length_, num_bands_, frame_index,
265 &render_buffer_.split_bands_f(0)[0], 0);
266
267 EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_));
268 aec3.ProcessCapture(&capture_buffer_, echo_path_change);
269 }
270 }
271
272 // Test for verifying that echo leakage information is being properly passed
273 // to the processor.
274 // The cases tested are:
275 // -That no method calls are received when they should not.
276 // -That false values are received each time they are flagged.
277 // -That true values are received each time they are flagged.
278 // -That a false value is received when flagged after a true value has been
279 // flagged.
280 enum class EchoLeakageTestVariant {
281 kNone,
282 kFalseSticky,
283 kTrueSticky,
284 kTrueNonSticky
285 };
286
287 void RunEchoLeakageVerificationTest(
288 EchoLeakageTestVariant leakage_report_variant) {
289 const size_t expected_num_block_to_process =
290 (kNumFramesToProcess *
291 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) /
292 kBlockSize;
293 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>>
294 block_processor_mock(
295 new StrictMock<webrtc::test::MockBlockProcessor>());
296 EXPECT_CALL(*block_processor_mock, BufferRender(_))
297 .Times(expected_num_block_to_process);
298 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, _, _))
299 .Times(expected_num_block_to_process);
300
301 switch (leakage_report_variant) {
302 case EchoLeakageTestVariant::kNone:
303 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(_)).Times(0);
304 break;
305 case EchoLeakageTestVariant::kFalseSticky:
306 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(false)).Times(1);
307 break;
308 case EchoLeakageTestVariant::kTrueSticky:
309 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(true)).Times(1);
310 break;
311 case EchoLeakageTestVariant::kTrueNonSticky: {
312 testing::InSequence s;
313 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(true)).Times(1);
314 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(false))
315 .Times(kNumFramesToProcess - 1);
316 } break;
317 }
318
319 EchoCanceller3 aec3(sample_rate_hz_, false,
320 std::move(block_processor_mock));
321
322 for (size_t frame_index = 0; frame_index < kNumFramesToProcess;
323 ++frame_index) {
324 switch (leakage_report_variant) {
325 case EchoLeakageTestVariant::kNone:
326 break;
327 case EchoLeakageTestVariant::kFalseSticky:
328 if (frame_index == 0) {
329 aec3.ReportEchoLeakage(false);
330 }
331 break;
332 case EchoLeakageTestVariant::kTrueSticky:
333 if (frame_index == 0) {
334 aec3.ReportEchoLeakage(true);
335 }
336 break;
337 case EchoLeakageTestVariant::kTrueNonSticky:
338 if (frame_index == 0) {
339 aec3.ReportEchoLeakage(true);
340 } else {
341 aec3.ReportEchoLeakage(false);
342 }
343 break;
344 }
345
346 aec3.AnalyzeCapture(&capture_buffer_);
347 OptionalBandSplit();
348
349 PopulateInputFrame(frame_length_, num_bands_, frame_index,
350 &capture_buffer_.split_bands_f(0)[0], 0);
351 PopulateInputFrame(frame_length_, num_bands_, frame_index,
352 &render_buffer_.split_bands_f(0)[0], 0);
353
354 EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_));
355 aec3.ProcessCapture(&capture_buffer_, false);
356 }
357 }
358
359 // This verifies that saturation information is properly passed to the
360 // BlockProcessor.
361 // The cases tested are:
362 // -That no saturation event is passed to the processor if there is no
363 // saturation.
364 // -That one frame with one negative saturated sample value is reported to be
365 // saturated and that following non-saturated frames are properly reported as
366 // not being saturated.
367 // -That one frame with one positive saturated sample value is reported to be
368 // saturated and that following non-saturated frames are properly reported as
369 // not being saturated.
370 enum class SaturationTestVariant { kNone, kOneNegative, kOnePositive };
371
372 void RunCaptureSaturationVerificationTest(
373 SaturationTestVariant saturation_variant) {
374 const size_t num_full_blocks_per_frame =
375 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100) / kBlockSize;
376 const size_t expected_num_block_to_process =
377 (kNumFramesToProcess *
378 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) /
379 kBlockSize;
380 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>>
381 block_processor_mock(
382 new StrictMock<webrtc::test::MockBlockProcessor>());
383 EXPECT_CALL(*block_processor_mock, BufferRender(_))
384 .Times(expected_num_block_to_process);
385 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(_)).Times(0);
386
387 switch (saturation_variant) {
388 case SaturationTestVariant::kNone:
389 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, false, _))
390 .Times(expected_num_block_to_process);
391 break;
392 case SaturationTestVariant::kOneNegative: {
393 testing::InSequence s;
394 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, true, _))
395 .Times(num_full_blocks_per_frame);
396 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, false, _))
397 .Times(expected_num_block_to_process - num_full_blocks_per_frame);
398 } break;
399 case SaturationTestVariant::kOnePositive: {
400 testing::InSequence s;
401 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, true, _))
402 .Times(num_full_blocks_per_frame);
403 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, false, _))
404 .Times(expected_num_block_to_process - num_full_blocks_per_frame);
405 } break;
406 }
407
408 EchoCanceller3 aec3(sample_rate_hz_, false,
409 std::move(block_processor_mock));
410
411 for (size_t frame_index = 0; frame_index < kNumFramesToProcess;
412 ++frame_index) {
413 for (int k = 0; k < fullband_frame_length_; ++k) {
414 capture_buffer_.channels_f()[0][k] = 0.f;
415 }
416 switch (saturation_variant) {
417 case SaturationTestVariant::kNone:
418 break;
419 case SaturationTestVariant::kOneNegative:
420 if (frame_index == 0) {
421 capture_buffer_.channels_f()[0][10] = -32768.f;
422 }
423 break;
424 case SaturationTestVariant::kOnePositive:
425 if (frame_index == 0) {
426 capture_buffer_.channels_f()[0][10] = 32767.f;
427 }
428 break;
429 }
430
431 aec3.AnalyzeCapture(&capture_buffer_);
432 OptionalBandSplit();
433
434 PopulateInputFrame(frame_length_, num_bands_, frame_index,
435 &capture_buffer_.split_bands_f(0)[0], 0);
436 PopulateInputFrame(frame_length_, num_bands_, frame_index,
437 &render_buffer_.split_bands_f(0)[0], 0);
438
439 EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_));
440 aec3.ProcessCapture(&capture_buffer_, false);
441 }
442 }
443
444 // This test verifies that the swapqueue is able to handle jitter in the
445 // capture and render API calls.
446 void RunRenderSwapQueueVerificationTest() {
447 EchoCanceller3 aec3(
448 sample_rate_hz_, false,
449 std::unique_ptr<BlockProcessor>(
450 new RenderTransportVerificationProcessor(num_bands_)));
451
452 constexpr size_t kSwapQueueLength = 30;
453 for (size_t frame_index = 0; frame_index < kSwapQueueLength;
454 ++frame_index) {
455 if (sample_rate_hz_ > 16000) {
456 render_buffer_.SplitIntoFrequencyBands();
457 }
458 PopulateInputFrame(frame_length_, num_bands_, frame_index,
459 &render_buffer_.split_bands_f(0)[0], 0);
460
461 EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_));
462 }
463
464 for (size_t frame_index = 0; frame_index < kSwapQueueLength;
465 ++frame_index) {
466 aec3.AnalyzeCapture(&capture_buffer_);
467 if (sample_rate_hz_ > 16000) {
468 capture_buffer_.SplitIntoFrequencyBands();
469 }
470
471 PopulateInputFrame(frame_length_, num_bands_, frame_index,
472 &capture_buffer_.split_bands_f(0)[0], 0);
473
474 aec3.ProcessCapture(&capture_buffer_, false);
475 EXPECT_TRUE(VerifyOutputFrameBitexactness(
476 frame_length_, num_bands_, frame_index,
477 &capture_buffer_.split_bands_f(0)[0], -64));
478 }
479 }
480
481 // This test verifies that a buffer overrun in the render swapqueue is
482 // properly reported.
483 void RunRenderPipelineSwapQueueOverrunReturnValueTest() {
484 EchoCanceller3 aec3(sample_rate_hz_, false);
485
486 constexpr size_t kSwapQueueLength = 30;
487 for (size_t k = 0; k < 2; ++k) {
488 for (size_t frame_index = 0; frame_index < kSwapQueueLength;
489 ++frame_index) {
490 if (sample_rate_hz_ > 16000) {
491 render_buffer_.SplitIntoFrequencyBands();
492 }
493 PopulateInputFrame(frame_length_, num_bands_, frame_index,
494 &render_buffer_.split_bands_f(0)[0], 0);
495
496 if (k == 0) {
497 EXPECT_TRUE(aec3.AnalyzeRender(&render_buffer_));
498 } else {
499 EXPECT_FALSE(aec3.AnalyzeRender(&render_buffer_));
500 }
501 }
502 }
503 }
504
505 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
506 // Verifies the that the check for the number of bands in the AnalyzeRender
507 // input is correct by adjusting the sample rates of EchoCanceller3 and the
508 // input AudioBuffer to have a different number of bands.
509 void RunAnalyzeRenderNumBandsCheckVerification() {
510 // Set aec3_sample_rate_hz to be different from sample_rate_hz_ in such a
511 // way that the number of bands for the rates are different.
512 const int aec3_sample_rate_hz = sample_rate_hz_ == 48000 ? 32000 : 48000;
513 EchoCanceller3 aec3(aec3_sample_rate_hz, false);
514 PopulateInputFrame(frame_length_, num_bands_, 0,
515 &render_buffer_.split_bands_f(0)[0], 0);
516
517 EXPECT_DEATH(aec3.AnalyzeRender(&render_buffer_), "");
518 }
519
520 // Verifies the that the check for the number of bands in the ProcessCapture
521 // input is correct by adjusting the sample rates of EchoCanceller3 and the
522 // input AudioBuffer to have a different number of bands.
523 void RunProcessCaptureNumBandsCheckVerification() {
524 // Set aec3_sample_rate_hz to be different from sample_rate_hz_ in such a
525 // way that the number of bands for the rates are different.
526 const int aec3_sample_rate_hz = sample_rate_hz_ == 48000 ? 32000 : 48000;
527 EchoCanceller3 aec3(aec3_sample_rate_hz, false);
528 PopulateInputFrame(frame_length_, num_bands_, 0,
529 &capture_buffer_.split_bands_f(0)[0], 100);
530 EXPECT_DEATH(aec3.ProcessCapture(&capture_buffer_, false), "");
531 }
532
533 // Verifies the that the check for the frame length in the AnalyzeRender input
534 // is correct by adjusting the sample rates of EchoCanceller3 and the input
535 // AudioBuffer to have a different frame lengths.
536 void RunAnalyzeRenderFrameLengthCheckVerification() {
537 // Set aec3_sample_rate_hz to be different from sample_rate_hz_ in such a
538 // way that the band frame lengths are different.
539 const int aec3_sample_rate_hz = sample_rate_hz_ == 8000 ? 16000 : 8000;
540 EchoCanceller3 aec3(aec3_sample_rate_hz, false);
541
542 OptionalBandSplit();
543 PopulateInputFrame(frame_length_, num_bands_, 0,
544 &render_buffer_.split_bands_f(0)[0], 0);
545
546 EXPECT_DEATH(aec3.AnalyzeRender(&render_buffer_), "");
547 }
548
549 // Verifies the that the check for the frame length in the AnalyzeRender input
550 // is correct by adjusting the sample rates of EchoCanceller3 and the input
551 // AudioBuffer to have a different frame lengths.
552 void RunProcessCaptureFrameLengthCheckVerification() {
553 // Set aec3_sample_rate_hz to be different from sample_rate_hz_ in such a
554 // way that the band frame lengths are different.
555 const int aec3_sample_rate_hz = sample_rate_hz_ == 8000 ? 16000 : 8000;
556 EchoCanceller3 aec3(aec3_sample_rate_hz, false);
557
558 OptionalBandSplit();
559 PopulateInputFrame(frame_length_, num_bands_, 0,
560 &capture_buffer_.split_bands_f(0)[0], 100);
561
562 EXPECT_DEATH(aec3.ProcessCapture(&capture_buffer_, false), "");
563 }
564
565 #endif
566
567 private:
568 void OptionalBandSplit() {
569 if (sample_rate_hz_ > 16000) {
570 capture_buffer_.SplitIntoFrequencyBands();
571 render_buffer_.SplitIntoFrequencyBands();
572 }
573 }
574
575 static constexpr size_t kNumFramesToProcess = 20;
576 const int sample_rate_hz_;
577 const size_t num_bands_;
578 const size_t frame_length_;
579 const int fullband_frame_length_;
580 AudioBuffer capture_buffer_;
581 AudioBuffer render_buffer_;
582
583 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(EchoCanceller3Tester);
584 };
585
586 std::string ProduceDebugText(int sample_rate_hz) {
587 std::ostringstream ss;
588 ss << "Sample rate: " << sample_rate_hz;
589 return ss.str();
590 }
591
592 std::string ProduceDebugText(int sample_rate_hz, int variant) {
593 std::ostringstream ss;
594 ss << "Sample rate: " << sample_rate_hz << ", variant: " << variant;
595 return ss.str();
596 }
597
598 } // namespace
599
600 TEST(EchoCanceller3Buffering, CaptureBitexactness) {
601 for (auto rate : {8000, 16000, 32000, 48000}) {
602 SCOPED_TRACE(ProduceDebugText(rate));
603 EchoCanceller3Tester(rate).RunCaptureTransportVerificationTest();
604 }
605 }
606
607 TEST(EchoCanceller3Buffering, RenderBitexactness) {
608 for (auto rate : {8000, 16000, 32000, 48000}) {
609 SCOPED_TRACE(ProduceDebugText(rate));
610 EchoCanceller3Tester(rate).RunRenderTransportVerificationTest();
611 }
612 }
613
614 TEST(EchoCanceller3Buffering, RenderSwapQueue) {
615 for (auto rate : {8000, 16000, 32000, 48000}) {
616 SCOPED_TRACE(ProduceDebugText(rate));
617 EchoCanceller3Tester(rate).RunRenderSwapQueueVerificationTest();
618 }
619 }
620
621 TEST(EchoCanceller3Buffering, RenderSwapQueueOverrunReturnValue) {
622 for (auto rate : {8000, 16000, 32000, 48000}) {
623 SCOPED_TRACE(ProduceDebugText(rate));
624 EchoCanceller3Tester(rate)
625 .RunRenderPipelineSwapQueueOverrunReturnValueTest();
626 }
627 }
628
629 TEST(EchoCanceller3Messaging, CaptureSaturation) {
630 auto variants = {EchoCanceller3Tester::SaturationTestVariant::kNone,
631 EchoCanceller3Tester::SaturationTestVariant::kOneNegative,
632 EchoCanceller3Tester::SaturationTestVariant::kOnePositive};
633 for (auto rate : {8000, 16000, 32000, 48000}) {
634 for (auto variant : variants) {
635 SCOPED_TRACE(ProduceDebugText(rate, static_cast<int>(variant)));
636 EchoCanceller3Tester(rate).RunCaptureSaturationVerificationTest(variant);
637 }
638 }
639 }
640
641 TEST(EchoCanceller3Messaging, EchoPathChange) {
642 auto variants = {
643 EchoCanceller3Tester::EchoPathChangeTestVariant::kNone,
644 EchoCanceller3Tester::EchoPathChangeTestVariant::kOneSticky,
645 EchoCanceller3Tester::EchoPathChangeTestVariant::kOneNonSticky};
646 for (auto rate : {8000, 16000, 32000, 48000}) {
647 for (auto variant : variants) {
648 SCOPED_TRACE(ProduceDebugText(rate, static_cast<int>(variant)));
649 EchoCanceller3Tester(rate).RunEchoPathChangeVerificationTest(variant);
650 }
651 }
652 }
653
654 TEST(EchoCanceller3Messaging, EchoLeakage) {
655 auto variants = {
656 EchoCanceller3Tester::EchoLeakageTestVariant::kNone,
657 EchoCanceller3Tester::EchoLeakageTestVariant::kFalseSticky,
658 EchoCanceller3Tester::EchoLeakageTestVariant::kTrueSticky,
659 EchoCanceller3Tester::EchoLeakageTestVariant::kTrueNonSticky};
660 for (auto rate : {8000, 16000, 32000, 48000}) {
661 for (auto variant : variants) {
662 SCOPED_TRACE(ProduceDebugText(rate, static_cast<int>(variant)));
663 EchoCanceller3Tester(rate).RunEchoLeakageVerificationTest(variant);
664 }
665 }
666 }
667
668 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
669 TEST(EchoCanceller3InputCheck, WrongRenderNumBandsCheckVerification) {
670 for (auto rate : {8000, 16000, 32000, 48000}) {
671 SCOPED_TRACE(ProduceDebugText(rate));
672 EchoCanceller3Tester(rate).RunAnalyzeRenderNumBandsCheckVerification();
673 }
674 }
675
676 TEST(EchoCanceller3InputCheck, WrongCaptureNumBandsCheckVerification) {
677 for (auto rate : {8000, 16000, 32000, 48000}) {
678 SCOPED_TRACE(ProduceDebugText(rate));
679 EchoCanceller3Tester(rate).RunProcessCaptureNumBandsCheckVerification();
680 }
681 }
682
683 TEST(EchoCanceller3InputCheck, WrongRenderFrameLengthCheckVerification) {
684 for (auto rate : {8000, 16000}) {
685 SCOPED_TRACE(ProduceDebugText(rate));
686 EchoCanceller3Tester(rate).RunAnalyzeRenderFrameLengthCheckVerification();
687 }
688 }
689
690 TEST(EchoCanceller3InputCheck, WrongCaptureFrameLengthCheckVerification) {
691 for (auto rate : {8000, 16000}) {
692 SCOPED_TRACE(ProduceDebugText(rate));
693 EchoCanceller3Tester(rate).RunProcessCaptureFrameLengthCheckVerification();
694 }
695 }
696
697 // Verifiers that the verification for null input to the render analysis api
698 // call works.
699 TEST(EchoCanceller3InputCheck, NullRenderAnalysisParameter) {
700 EXPECT_DEATH(EchoCanceller3(8000, false).AnalyzeRender(nullptr), "");
701 }
702
703 // Verifiers that the verification for null input to the capture analysis api
704 // call works.
705 TEST(EchoCanceller3InputCheck, NullCaptureAnalysisParameter) {
706 EXPECT_DEATH(EchoCanceller3(8000, false).AnalyzeCapture(nullptr), "");
707 }
708
709 // Verifiers that the verification for null input to the capture processing api
710 // call works.
711 TEST(EchoCanceller3InputCheck, NullCaptureProcessingParameter) {
712 EXPECT_DEATH(EchoCanceller3(8000, false).ProcessCapture(nullptr, false), "");
713 }
714
715 #endif
716
717 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/aec3/echo_canceller3.cc ('k') | webrtc/modules/audio_processing/aec3/frame_blocker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698