OLD | NEW |
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 10 matching lines...) Expand all Loading... |
21 #include "webrtc/modules/audio_processing/aec3/block_processor.h" | 21 #include "webrtc/modules/audio_processing/aec3/block_processor.h" |
22 #include "webrtc/modules/audio_processing/aec3/frame_blocker.h" | 22 #include "webrtc/modules/audio_processing/aec3/frame_blocker.h" |
23 #include "webrtc/modules/audio_processing/aec3/mock/mock_block_processor.h" | 23 #include "webrtc/modules/audio_processing/aec3/mock/mock_block_processor.h" |
24 #include "webrtc/modules/audio_processing/audio_buffer.h" | 24 #include "webrtc/modules/audio_processing/audio_buffer.h" |
25 #include "webrtc/test/gmock.h" | 25 #include "webrtc/test/gmock.h" |
26 #include "webrtc/test/gtest.h" | 26 #include "webrtc/test/gtest.h" |
27 | 27 |
28 namespace webrtc { | 28 namespace webrtc { |
29 namespace { | 29 namespace { |
30 | 30 |
| 31 using testing::Return; |
31 using testing::StrictMock; | 32 using testing::StrictMock; |
32 using testing::_; | 33 using testing::_; |
33 | 34 |
34 // Populates the frame with linearly increasing sample values for each band, | 35 // Populates the frame with linearly increasing sample values for each band, |
35 // with a band-specific offset, in order to allow simple bitexactness | 36 // with a band-specific offset, in order to allow simple bitexactness |
36 // verification for each band. | 37 // verification for each band. |
37 void PopulateInputFrame(size_t frame_length, | 38 void PopulateInputFrame(size_t frame_length, |
38 size_t num_bands, | 39 size_t num_bands, |
39 size_t frame_index, | 40 size_t frame_index, |
40 float* const* frame, | 41 float* const* frame, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 76 } |
76 | 77 |
77 // Class for testing that the capture data is properly received by the block | 78 // 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 // processor and that the processor data is properly passed to the |
79 // EchoCanceller3 output. | 80 // EchoCanceller3 output. |
80 class CaptureTransportVerificationProcessor : public BlockProcessor { | 81 class CaptureTransportVerificationProcessor : public BlockProcessor { |
81 public: | 82 public: |
82 explicit CaptureTransportVerificationProcessor(size_t num_bands) {} | 83 explicit CaptureTransportVerificationProcessor(size_t num_bands) {} |
83 ~CaptureTransportVerificationProcessor() override = default; | 84 ~CaptureTransportVerificationProcessor() override = default; |
84 | 85 |
85 void ProcessCapture(bool known_echo_path_change, | 86 void ProcessCapture(bool level_change, |
86 bool saturated_microphone_signal, | 87 bool saturated_microphone_signal, |
87 std::vector<std::vector<float>>* capture_block) override { | 88 std::vector<std::vector<float>>* capture_block) override { |
88 } | 89 } |
89 | 90 |
90 bool BufferRender(std::vector<std::vector<float>>* block) override { | 91 bool BufferRender(std::vector<std::vector<float>>* block) override { |
91 return false; | 92 return true; |
92 } | 93 } |
93 | 94 |
94 void ReportEchoLeakage(bool leakage_detected) override {} | 95 void UpdateEchoLeakageStatus(bool leakage_detected) override {} |
95 | 96 |
96 private: | 97 private: |
97 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CaptureTransportVerificationProcessor); | 98 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CaptureTransportVerificationProcessor); |
98 }; | 99 }; |
99 | 100 |
100 // Class for testing that the render data is properly received by the block | 101 // Class for testing that the render data is properly received by the block |
101 // processor. | 102 // processor. |
102 class RenderTransportVerificationProcessor : public BlockProcessor { | 103 class RenderTransportVerificationProcessor : public BlockProcessor { |
103 public: | 104 public: |
104 explicit RenderTransportVerificationProcessor(size_t num_bands) {} | 105 explicit RenderTransportVerificationProcessor(size_t num_bands) {} |
105 ~RenderTransportVerificationProcessor() override = default; | 106 ~RenderTransportVerificationProcessor() override = default; |
106 | 107 |
107 void ProcessCapture(bool known_echo_path_change, | 108 void ProcessCapture(bool level_change, |
108 bool saturated_microphone_signal, | 109 bool saturated_microphone_signal, |
109 std::vector<std::vector<float>>* capture_block) override { | 110 std::vector<std::vector<float>>* capture_block) override { |
110 std::vector<std::vector<float>> render_block = | 111 std::vector<std::vector<float>> render_block = |
111 received_render_blocks_.front(); | 112 received_render_blocks_.front(); |
112 received_render_blocks_.pop_front(); | 113 received_render_blocks_.pop_front(); |
113 capture_block->swap(render_block); | 114 capture_block->swap(render_block); |
114 } | 115 } |
115 | 116 |
116 bool BufferRender(std::vector<std::vector<float>>* block) override { | 117 bool BufferRender(std::vector<std::vector<float>>* block) override { |
117 received_render_blocks_.push_back(*block); | 118 received_render_blocks_.push_back(*block); |
118 return false; | 119 return true; |
119 } | 120 } |
120 | 121 |
121 void ReportEchoLeakage(bool leakage_detected) override {} | 122 void UpdateEchoLeakageStatus(bool leakage_detected) override {} |
122 | 123 |
123 private: | 124 private: |
124 std::deque<std::vector<std::vector<float>>> received_render_blocks_; | 125 std::deque<std::vector<std::vector<float>>> received_render_blocks_; |
125 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderTransportVerificationProcessor); | 126 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RenderTransportVerificationProcessor); |
126 }; | 127 }; |
127 | 128 |
128 class EchoCanceller3Tester { | 129 class EchoCanceller3Tester { |
129 public: | 130 public: |
130 explicit EchoCanceller3Tester(int sample_rate_hz) | 131 explicit EchoCanceller3Tester(int sample_rate_hz) |
131 : sample_rate_hz_(sample_rate_hz), | 132 : sample_rate_hz_(sample_rate_hz), |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 const size_t num_full_blocks_per_frame = | 211 const size_t num_full_blocks_per_frame = |
211 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100) / kBlockSize; | 212 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100) / kBlockSize; |
212 const size_t expected_num_block_to_process = | 213 const size_t expected_num_block_to_process = |
213 (kNumFramesToProcess * | 214 (kNumFramesToProcess * |
214 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) / | 215 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) / |
215 kBlockSize; | 216 kBlockSize; |
216 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>> | 217 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>> |
217 block_processor_mock( | 218 block_processor_mock( |
218 new StrictMock<webrtc::test::MockBlockProcessor>()); | 219 new StrictMock<webrtc::test::MockBlockProcessor>()); |
219 EXPECT_CALL(*block_processor_mock, BufferRender(_)) | 220 EXPECT_CALL(*block_processor_mock, BufferRender(_)) |
220 .Times(expected_num_block_to_process); | 221 .Times(expected_num_block_to_process) |
221 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(_)).Times(0); | 222 .WillRepeatedly(Return(true)); |
| 223 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(_)).Times(0); |
222 | 224 |
223 switch (echo_path_change_test_variant) { | 225 switch (echo_path_change_test_variant) { |
224 case EchoPathChangeTestVariant::kNone: | 226 case EchoPathChangeTestVariant::kNone: |
225 EXPECT_CALL(*block_processor_mock, ProcessCapture(false, _, _)) | 227 EXPECT_CALL(*block_processor_mock, ProcessCapture(false, _, _)) |
226 .Times(expected_num_block_to_process); | 228 .Times(expected_num_block_to_process); |
227 break; | 229 break; |
228 case EchoPathChangeTestVariant::kOneSticky: | 230 case EchoPathChangeTestVariant::kOneSticky: |
229 EXPECT_CALL(*block_processor_mock, ProcessCapture(true, _, _)) | 231 EXPECT_CALL(*block_processor_mock, ProcessCapture(true, _, _)) |
230 .Times(expected_num_block_to_process); | 232 .Times(expected_num_block_to_process); |
231 break; | 233 break; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 void RunEchoLeakageVerificationTest( | 289 void RunEchoLeakageVerificationTest( |
288 EchoLeakageTestVariant leakage_report_variant) { | 290 EchoLeakageTestVariant leakage_report_variant) { |
289 const size_t expected_num_block_to_process = | 291 const size_t expected_num_block_to_process = |
290 (kNumFramesToProcess * | 292 (kNumFramesToProcess * |
291 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) / | 293 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) / |
292 kBlockSize; | 294 kBlockSize; |
293 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>> | 295 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>> |
294 block_processor_mock( | 296 block_processor_mock( |
295 new StrictMock<webrtc::test::MockBlockProcessor>()); | 297 new StrictMock<webrtc::test::MockBlockProcessor>()); |
296 EXPECT_CALL(*block_processor_mock, BufferRender(_)) | 298 EXPECT_CALL(*block_processor_mock, BufferRender(_)) |
297 .Times(expected_num_block_to_process); | 299 .Times(expected_num_block_to_process) |
| 300 .WillRepeatedly(Return(true)); |
298 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, _, _)) | 301 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, _, _)) |
299 .Times(expected_num_block_to_process); | 302 .Times(expected_num_block_to_process); |
300 | 303 |
301 switch (leakage_report_variant) { | 304 switch (leakage_report_variant) { |
302 case EchoLeakageTestVariant::kNone: | 305 case EchoLeakageTestVariant::kNone: |
303 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(_)).Times(0); | 306 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(_)).Times(0); |
304 break; | 307 break; |
305 case EchoLeakageTestVariant::kFalseSticky: | 308 case EchoLeakageTestVariant::kFalseSticky: |
306 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(false)).Times(1); | 309 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(false)) |
| 310 .Times(1); |
307 break; | 311 break; |
308 case EchoLeakageTestVariant::kTrueSticky: | 312 case EchoLeakageTestVariant::kTrueSticky: |
309 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(true)).Times(1); | 313 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(true)) |
| 314 .Times(1); |
310 break; | 315 break; |
311 case EchoLeakageTestVariant::kTrueNonSticky: { | 316 case EchoLeakageTestVariant::kTrueNonSticky: { |
312 testing::InSequence s; | 317 testing::InSequence s; |
313 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(true)).Times(1); | 318 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(true)) |
314 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(false)) | 319 .Times(1); |
| 320 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(false)) |
315 .Times(kNumFramesToProcess - 1); | 321 .Times(kNumFramesToProcess - 1); |
316 } break; | 322 } break; |
317 } | 323 } |
318 | 324 |
319 EchoCanceller3 aec3(sample_rate_hz_, false, | 325 EchoCanceller3 aec3(sample_rate_hz_, false, |
320 std::move(block_processor_mock)); | 326 std::move(block_processor_mock)); |
321 | 327 |
322 for (size_t frame_index = 0; frame_index < kNumFramesToProcess; | 328 for (size_t frame_index = 0; frame_index < kNumFramesToProcess; |
323 ++frame_index) { | 329 ++frame_index) { |
324 switch (leakage_report_variant) { | 330 switch (leakage_report_variant) { |
325 case EchoLeakageTestVariant::kNone: | 331 case EchoLeakageTestVariant::kNone: |
326 break; | 332 break; |
327 case EchoLeakageTestVariant::kFalseSticky: | 333 case EchoLeakageTestVariant::kFalseSticky: |
328 if (frame_index == 0) { | 334 if (frame_index == 0) { |
329 aec3.ReportEchoLeakage(false); | 335 aec3.UpdateEchoLeakageStatus(false); |
330 } | 336 } |
331 break; | 337 break; |
332 case EchoLeakageTestVariant::kTrueSticky: | 338 case EchoLeakageTestVariant::kTrueSticky: |
333 if (frame_index == 0) { | 339 if (frame_index == 0) { |
334 aec3.ReportEchoLeakage(true); | 340 aec3.UpdateEchoLeakageStatus(true); |
335 } | 341 } |
336 break; | 342 break; |
337 case EchoLeakageTestVariant::kTrueNonSticky: | 343 case EchoLeakageTestVariant::kTrueNonSticky: |
338 if (frame_index == 0) { | 344 if (frame_index == 0) { |
339 aec3.ReportEchoLeakage(true); | 345 aec3.UpdateEchoLeakageStatus(true); |
340 } else { | 346 } else { |
341 aec3.ReportEchoLeakage(false); | 347 aec3.UpdateEchoLeakageStatus(false); |
342 } | 348 } |
343 break; | 349 break; |
344 } | 350 } |
345 | 351 |
346 aec3.AnalyzeCapture(&capture_buffer_); | 352 aec3.AnalyzeCapture(&capture_buffer_); |
347 OptionalBandSplit(); | 353 OptionalBandSplit(); |
348 | 354 |
349 PopulateInputFrame(frame_length_, num_bands_, frame_index, | 355 PopulateInputFrame(frame_length_, num_bands_, frame_index, |
350 &capture_buffer_.split_bands_f(0)[0], 0); | 356 &capture_buffer_.split_bands_f(0)[0], 0); |
351 PopulateInputFrame(frame_length_, num_bands_, frame_index, | 357 PopulateInputFrame(frame_length_, num_bands_, frame_index, |
(...skipping 22 matching lines...) Expand all Loading... |
374 const size_t num_full_blocks_per_frame = | 380 const size_t num_full_blocks_per_frame = |
375 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100) / kBlockSize; | 381 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100) / kBlockSize; |
376 const size_t expected_num_block_to_process = | 382 const size_t expected_num_block_to_process = |
377 (kNumFramesToProcess * | 383 (kNumFramesToProcess * |
378 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) / | 384 rtc::CheckedDivExact(LowestBandRate(sample_rate_hz_), 100)) / |
379 kBlockSize; | 385 kBlockSize; |
380 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>> | 386 std::unique_ptr<testing::StrictMock<webrtc::test::MockBlockProcessor>> |
381 block_processor_mock( | 387 block_processor_mock( |
382 new StrictMock<webrtc::test::MockBlockProcessor>()); | 388 new StrictMock<webrtc::test::MockBlockProcessor>()); |
383 EXPECT_CALL(*block_processor_mock, BufferRender(_)) | 389 EXPECT_CALL(*block_processor_mock, BufferRender(_)) |
384 .Times(expected_num_block_to_process); | 390 .Times(expected_num_block_to_process) |
385 EXPECT_CALL(*block_processor_mock, ReportEchoLeakage(_)).Times(0); | 391 .WillRepeatedly(Return(true)); |
| 392 EXPECT_CALL(*block_processor_mock, UpdateEchoLeakageStatus(_)).Times(0); |
386 | 393 |
387 switch (saturation_variant) { | 394 switch (saturation_variant) { |
388 case SaturationTestVariant::kNone: | 395 case SaturationTestVariant::kNone: |
389 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, false, _)) | 396 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, false, _)) |
390 .Times(expected_num_block_to_process); | 397 .Times(expected_num_block_to_process); |
391 break; | 398 break; |
392 case SaturationTestVariant::kOneNegative: { | 399 case SaturationTestVariant::kOneNegative: { |
393 testing::InSequence s; | 400 testing::InSequence s; |
394 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, true, _)) | 401 EXPECT_CALL(*block_processor_mock, ProcessCapture(_, true, _)) |
395 .Times(num_full_blocks_per_frame); | 402 .Times(num_full_blocks_per_frame); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 | 715 |
709 // Verifiers that the verification for null input to the capture processing api | 716 // Verifiers that the verification for null input to the capture processing api |
710 // call works. | 717 // call works. |
711 TEST(EchoCanceller3InputCheck, NullCaptureProcessingParameter) { | 718 TEST(EchoCanceller3InputCheck, NullCaptureProcessingParameter) { |
712 EXPECT_DEATH(EchoCanceller3(8000, false).ProcessCapture(nullptr, false), ""); | 719 EXPECT_DEATH(EchoCanceller3(8000, false).ProcessCapture(nullptr, false), ""); |
713 } | 720 } |
714 | 721 |
715 #endif | 722 #endif |
716 | 723 |
717 } // namespace webrtc | 724 } // namespace webrtc |
OLD | NEW |