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

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

Issue 2611223003: Adding second layer of the echo canceller 3 functionality. (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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 // Class for testing that the capture data is properly received by the block 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 78 // processor and that the processor data is properly passed to the
79 // EchoCanceller3 output. 79 // EchoCanceller3 output.
80 class CaptureTransportVerificationProcessor : public BlockProcessor { 80 class CaptureTransportVerificationProcessor : public BlockProcessor {
81 public: 81 public:
82 explicit CaptureTransportVerificationProcessor(size_t num_bands) {} 82 explicit CaptureTransportVerificationProcessor(size_t num_bands) {}
83 ~CaptureTransportVerificationProcessor() override = default; 83 ~CaptureTransportVerificationProcessor() override = default;
84 84
85 void ProcessCapture(bool known_echo_path_change, 85 void ProcessCapture(bool level_change,
86 bool saturated_microphone_signal, 86 bool saturated_microphone_signal,
87 std::vector<std::vector<float>>* capture_block) override { 87 std::vector<std::vector<float>>* capture_block) override {
88 } 88 }
89 89
90 bool BufferRender(std::vector<std::vector<float>>* block) override { 90 bool BufferRender(std::vector<std::vector<float>>* block) override {
91 return false; 91 return false;
92 } 92 }
93 93
94 void ReportEchoLeakage(bool leakage_detected) override {} 94 void UpdateEchoLeakageStatus(bool leakage_detected) override {}
95 95
96 private: 96 private:
97 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CaptureTransportVerificationProcessor); 97 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CaptureTransportVerificationProcessor);
98 }; 98 };
99 99
100 // Class for testing that the render data is properly received by the block 100 // Class for testing that the render data is properly received by the block
101 // processor. 101 // processor.
102 class RenderTransportVerificationProcessor : public BlockProcessor { 102 class RenderTransportVerificationProcessor : public BlockProcessor {
103 public: 103 public:
104 explicit RenderTransportVerificationProcessor(size_t num_bands) {} 104 explicit RenderTransportVerificationProcessor(size_t num_bands) {}
105 ~RenderTransportVerificationProcessor() override = default; 105 ~RenderTransportVerificationProcessor() override = default;
106 106
107 void ProcessCapture(bool known_echo_path_change, 107 void ProcessCapture(bool level_change,
108 bool saturated_microphone_signal, 108 bool saturated_microphone_signal,
109 std::vector<std::vector<float>>* capture_block) override { 109 std::vector<std::vector<float>>* capture_block) override {
110 std::vector<std::vector<float>> render_block = 110 std::vector<std::vector<float>> render_block =
111 received_render_blocks_.front(); 111 received_render_blocks_.front();
112 received_render_blocks_.pop_front(); 112 received_render_blocks_.pop_front();
113 capture_block->swap(render_block); 113 capture_block->swap(render_block);
114 } 114 }
115 115
116 bool BufferRender(std::vector<std::vector<float>>* block) override { 116 bool BufferRender(std::vector<std::vector<float>>* block) override {
117 received_render_blocks_.push_back(*block); 117 received_render_blocks_.push_back(*block);
118 return false; 118 return false;
119 } 119 }
120 120
121 void ReportEchoLeakage(bool leakage_detected) override {} 121 void UpdateEchoLeakageStatus(bool leakage_detected) override {}
122 122
123 private: 123 private:
124 std::deque<std::vector<std::vector<float>>> received_render_blocks_; 124 std::deque<std::vector<std::vector<float>>> received_render_blocks_;
125 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderTransportVerificationProcessor); 125 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderTransportVerificationProcessor);
126 }; 126 };
127 127
128 class EchoCanceller3Tester { 128 class EchoCanceller3Tester {
129 public: 129 public:
130 explicit EchoCanceller3Tester(int sample_rate_hz) 130 explicit EchoCanceller3Tester(int sample_rate_hz)
131 : sample_rate_hz_(sample_rate_hz), 131 : sample_rate_hz_(sample_rate_hz),
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100) / kBlockSize; 211 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100) / kBlockSize;
212 const size_t expected_num_block_to_process = 212 const size_t expected_num_block_to_process =
213 (kNumFramesToProcess * 213 (kNumFramesToProcess *
214 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) / 214 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) /
215 kBlockSize; 215 kBlockSize;
216 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>> 216 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>>
217 block_processor_mock( 217 block_processor_mock(
218 new StrictMock<webrtc::test::MockBlockProcessor>()); 218 new StrictMock<webrtc::test::MockBlockProcessor>());
219 EXPECT_CALL(*block_processor_mock, BufferRender(_)) 219 EXPECT_CALL(*block_processor_mock, BufferRender(_))
220 .Times(expected_num_block_to_process); 220 .Times(expected_num_block_to_process);
221 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(_)).Times(0); 221 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(_)).Times(0);
222 222
223 switch (echo_path_change_test_variant) { 223 switch (echo_path_change_test_variant) {
224 case EchoPathChangeTestVariant::kNone: 224 case EchoPathChangeTestVariant::kNone:
225 EXPECT_CALL(*block_processor_mock, ProcessCapture(false, _, _)) 225 EXPECT_CALL(*block_processor_mock, ProcessCapture(false, _, _))
226 .Times(expected_num_block_to_process); 226 .Times(expected_num_block_to_process);
227 break; 227 break;
228 case EchoPathChangeTestVariant::kOneSticky: 228 case EchoPathChangeTestVariant::kOneSticky:
229 EXPECT_CALL(*block_processor_mock, ProcessCapture(true, _, _)) 229 EXPECT_CALL(*block_processor_mock, ProcessCapture(true, _, _))
230 .Times(expected_num_block_to_process); 230 .Times(expected_num_block_to_process);
231 break; 231 break;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>> 293 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>>
294 block_processor_mock( 294 block_processor_mock(
295 new StrictMock<webrtc::test::MockBlockProcessor>()); 295 new StrictMock<webrtc::test::MockBlockProcessor>());
296 EXPECT_CALL(*block_processor_mock, BufferRender(_)) 296 EXPECT_CALL(*block_processor_mock, BufferRender(_))
297 .Times(expected_num_block_to_process); 297 .Times(expected_num_block_to_process);
298 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, _, _)) 298 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, _, _))
299 .Times(expected_num_block_to_process); 299 .Times(expected_num_block_to_process);
300 300
301 switch (leakage_report_variant) { 301 switch (leakage_report_variant) {
302 case EchoLeakageTestVariant::kNone: 302 case EchoLeakageTestVariant::kNone:
303 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(_)).Times(0); 303 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(_)).Times(0);
304 break; 304 break;
305 case EchoLeakageTestVariant::kFalseSticky: 305 case EchoLeakageTestVariant::kFalseSticky:
306 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(false)).Times(1); 306 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(false))
307 .Times(1);
307 break; 308 break;
308 case EchoLeakageTestVariant::kTrueSticky: 309 case EchoLeakageTestVariant::kTrueSticky:
309 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(true)).Times(1); 310 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(true))
311 .Times(1);
310 break; 312 break;
311 case EchoLeakageTestVariant::kTrueNonSticky: { 313 case EchoLeakageTestVariant::kTrueNonSticky: {
312 testing::InSequence s; 314 testing::InSequence s;
313 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(true)).Times(1); 315 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(true))
314 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(false)) 316 .Times(1);
317 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(false))
315 .Times(kNumFramesToProcess - 1); 318 .Times(kNumFramesToProcess - 1);
316 } break; 319 } break;
317 } 320 }
318 321
319 EchoCanceller3 aec3(sample_rate_hz_, false, 322 EchoCanceller3 aec3(sample_rate_hz_, false,
320 std::move(block_processor_mock)); 323 std::move(block_processor_mock));
321 324
322 for (size_t frame_index = 0; frame_index < kNumFramesToProcess; 325 for (size_t frame_index = 0; frame_index < kNumFramesToProcess;
323 ++frame_index) { 326 ++frame_index) {
324 switch (leakage_report_variant) { 327 switch (leakage_report_variant) {
325 case EchoLeakageTestVariant::kNone: 328 case EchoLeakageTestVariant::kNone:
326 break; 329 break;
327 case EchoLeakageTestVariant::kFalseSticky: 330 case EchoLeakageTestVariant::kFalseSticky:
328 if (frame_index == 0) { 331 if (frame_index == 0) {
329 aec3.ReportEchoLeakage(false); 332 aec3.UpdateEchoLeakageStatus(false);
330 } 333 }
331 break; 334 break;
332 case EchoLeakageTestVariant::kTrueSticky: 335 case EchoLeakageTestVariant::kTrueSticky:
333 if (frame_index == 0) { 336 if (frame_index == 0) {
334 aec3.ReportEchoLeakage(true); 337 aec3.UpdateEchoLeakageStatus(true);
335 } 338 }
336 break; 339 break;
337 case EchoLeakageTestVariant::kTrueNonSticky: 340 case EchoLeakageTestVariant::kTrueNonSticky:
338 if (frame_index == 0) { 341 if (frame_index == 0) {
339 aec3.ReportEchoLeakage(true); 342 aec3.UpdateEchoLeakageStatus(true);
340 } else { 343 } else {
341 aec3.ReportEchoLeakage(false); 344 aec3.UpdateEchoLeakageStatus(false);
342 } 345 }
343 break; 346 break;
344 } 347 }
345 348
346 aec3.AnalyzeCapture(&capture_buffer_); 349 aec3.AnalyzeCapture(&capture_buffer_);
347 OptionalBandSplit(); 350 OptionalBandSplit();
348 351
349 PopulateInputFrame(frame_length_, num_bands_, frame_index, 352 PopulateInputFrame(frame_length_, num_bands_, frame_index,
350 &capture_buffer_.split_bands_f(0)[0], 0); 353 &capture_buffer_.split_bands_f(0)[0], 0);
351 PopulateInputFrame(frame_length_, num_bands_, frame_index, 354 PopulateInputFrame(frame_length_, num_bands_, frame_index,
(...skipping 23 matching lines...) Expand all
375 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100) / kBlockSize; 378 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100) / kBlockSize;
376 const size_t expected_num_block_to_process = 379 const size_t expected_num_block_to_process =
377 (kNumFramesToProcess * 380 (kNumFramesToProcess *
378 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) / 381 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) /
379 kBlockSize; 382 kBlockSize;
380 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>> 383 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>>
381 block_processor_mock( 384 block_processor_mock(
382 new StrictMock<webrtc::test::MockBlockProcessor>()); 385 new StrictMock<webrtc::test::MockBlockProcessor>());
383 EXPECT_CALL(*block_processor_mock, BufferRender(_)) 386 EXPECT_CALL(*block_processor_mock, BufferRender(_))
384 .Times(expected_num_block_to_process); 387 .Times(expected_num_block_to_process);
385 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(_)).Times(0); 388 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(_)).Times(0);
386 389
387 switch (saturation_variant) { 390 switch (saturation_variant) {
388 case SaturationTestVariant::kNone: 391 case SaturationTestVariant::kNone:
389 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, false, _)) 392 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, false, _))
390 .Times(expected_num_block_to_process); 393 .Times(expected_num_block_to_process);
391 break; 394 break;
392 case SaturationTestVariant::kOneNegative: { 395 case SaturationTestVariant::kOneNegative: {
393 testing::InSequence s; 396 testing::InSequence s;
394 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, true, _)) 397 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, true, _))
395 .Times(num_full_blocks_per_frame); 398 .Times(num_full_blocks_per_frame);
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 711
709 // Verifiers that the verification for null input to the capture processing api 712 // Verifiers that the verification for null input to the capture processing api
710 // call works. 713 // call works.
711 TEST(EchoCanceller3InputCheck, NullCaptureProcessingParameter) { 714 TEST(EchoCanceller3InputCheck, NullCaptureProcessingParameter) {
712 EXPECT_DEATH(EchoCanceller3(8000, false).ProcessCapture(nullptr, false), ""); 715 EXPECT_DEATH(EchoCanceller3(8000, false).ProcessCapture(nullptr, false), "");
713 } 716 }
714 717
715 #endif 718 #endif
716 719
717 } // namespace webrtc 720 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698