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 18 matching lines...) Expand all Loading... |
29 namespace { | 29 namespace { |
30 | 30 |
31 using testing::AtLeast; | 31 using testing::AtLeast; |
32 using testing::Return; | 32 using testing::Return; |
33 using testing::StrictMock; | 33 using testing::StrictMock; |
34 using testing::_; | 34 using testing::_; |
35 | 35 |
36 // Verifies that the basic BlockProcessor functionality works and that the API | 36 // Verifies that the basic BlockProcessor functionality works and that the API |
37 // methods are callable. | 37 // methods are callable. |
38 void RunBasicSetupAndApiCallTest(int sample_rate_hz) { | 38 void RunBasicSetupAndApiCallTest(int sample_rate_hz) { |
39 std::unique_ptr<BlockProcessor> block_processor( | 39 std::unique_ptr<BlockProcessor> block_processor(BlockProcessor::Create( |
40 BlockProcessor::Create(sample_rate_hz)); | 40 AudioProcessing::Config::EchoCanceller3(), sample_rate_hz)); |
41 std::vector<std::vector<float>> block(NumBandsForRate(sample_rate_hz), | 41 std::vector<std::vector<float>> block(NumBandsForRate(sample_rate_hz), |
42 std::vector<float>(kBlockSize, 0.f)); | 42 std::vector<float>(kBlockSize, 0.f)); |
43 | 43 |
44 block_processor->BufferRender(block); | 44 block_processor->BufferRender(block); |
45 block_processor->ProcessCapture(false, false, &block); | 45 block_processor->ProcessCapture(false, false, &block); |
46 block_processor->UpdateEchoLeakageStatus(false); | 46 block_processor->UpdateEchoLeakageStatus(false); |
47 } | 47 } |
48 | 48 |
49 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 49 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
50 void RunRenderBlockSizeVerificationTest(int sample_rate_hz) { | 50 void RunRenderBlockSizeVerificationTest(int sample_rate_hz) { |
51 std::unique_ptr<BlockProcessor> block_processor( | 51 std::unique_ptr<BlockProcessor> block_processor(BlockProcessor::Create( |
52 BlockProcessor::Create(sample_rate_hz)); | 52 AudioProcessing::Config::EchoCanceller3(), sample_rate_hz)); |
53 std::vector<std::vector<float>> block( | 53 std::vector<std::vector<float>> block( |
54 NumBandsForRate(sample_rate_hz), std::vector<float>(kBlockSize - 1, 0.f)); | 54 NumBandsForRate(sample_rate_hz), std::vector<float>(kBlockSize - 1, 0.f)); |
55 | 55 |
56 EXPECT_DEATH(block_processor->BufferRender(block), ""); | 56 EXPECT_DEATH(block_processor->BufferRender(block), ""); |
57 } | 57 } |
58 | 58 |
59 void RunCaptureBlockSizeVerificationTest(int sample_rate_hz) { | 59 void RunCaptureBlockSizeVerificationTest(int sample_rate_hz) { |
60 std::unique_ptr<BlockProcessor> block_processor( | 60 std::unique_ptr<BlockProcessor> block_processor(BlockProcessor::Create( |
61 BlockProcessor::Create(sample_rate_hz)); | 61 AudioProcessing::Config::EchoCanceller3(), sample_rate_hz)); |
62 std::vector<std::vector<float>> block( | 62 std::vector<std::vector<float>> block( |
63 NumBandsForRate(sample_rate_hz), std::vector<float>(kBlockSize - 1, 0.f)); | 63 NumBandsForRate(sample_rate_hz), std::vector<float>(kBlockSize - 1, 0.f)); |
64 | 64 |
65 EXPECT_DEATH(block_processor->ProcessCapture(false, false, &block), ""); | 65 EXPECT_DEATH(block_processor->ProcessCapture(false, false, &block), ""); |
66 } | 66 } |
67 | 67 |
68 void RunRenderNumBandsVerificationTest(int sample_rate_hz) { | 68 void RunRenderNumBandsVerificationTest(int sample_rate_hz) { |
69 const size_t wrong_num_bands = NumBandsForRate(sample_rate_hz) < 3 | 69 const size_t wrong_num_bands = NumBandsForRate(sample_rate_hz) < 3 |
70 ? NumBandsForRate(sample_rate_hz) + 1 | 70 ? NumBandsForRate(sample_rate_hz) + 1 |
71 : 1; | 71 : 1; |
72 std::unique_ptr<BlockProcessor> block_processor( | 72 std::unique_ptr<BlockProcessor> block_processor(BlockProcessor::Create( |
73 BlockProcessor::Create(sample_rate_hz)); | 73 AudioProcessing::Config::EchoCanceller3(), sample_rate_hz)); |
74 std::vector<std::vector<float>> block(wrong_num_bands, | 74 std::vector<std::vector<float>> block(wrong_num_bands, |
75 std::vector<float>(kBlockSize, 0.f)); | 75 std::vector<float>(kBlockSize, 0.f)); |
76 | 76 |
77 EXPECT_DEATH(block_processor->BufferRender(block), ""); | 77 EXPECT_DEATH(block_processor->BufferRender(block), ""); |
78 } | 78 } |
79 | 79 |
80 void RunCaptureNumBandsVerificationTest(int sample_rate_hz) { | 80 void RunCaptureNumBandsVerificationTest(int sample_rate_hz) { |
81 const size_t wrong_num_bands = NumBandsForRate(sample_rate_hz) < 3 | 81 const size_t wrong_num_bands = NumBandsForRate(sample_rate_hz) < 3 |
82 ? NumBandsForRate(sample_rate_hz) + 1 | 82 ? NumBandsForRate(sample_rate_hz) + 1 |
83 : 1; | 83 : 1; |
84 std::unique_ptr<BlockProcessor> block_processor( | 84 std::unique_ptr<BlockProcessor> block_processor(BlockProcessor::Create( |
85 BlockProcessor::Create(sample_rate_hz)); | 85 AudioProcessing::Config::EchoCanceller3(), sample_rate_hz)); |
86 std::vector<std::vector<float>> block(wrong_num_bands, | 86 std::vector<std::vector<float>> block(wrong_num_bands, |
87 std::vector<float>(kBlockSize, 0.f)); | 87 std::vector<float>(kBlockSize, 0.f)); |
88 | 88 |
89 EXPECT_DEATH(block_processor->ProcessCapture(false, false, &block), ""); | 89 EXPECT_DEATH(block_processor->ProcessCapture(false, false, &block), ""); |
90 } | 90 } |
91 #endif | 91 #endif |
92 | 92 |
93 std::string ProduceDebugText(int sample_rate_hz) { | 93 std::string ProduceDebugText(int sample_rate_hz) { |
94 std::ostringstream ss; | 94 std::ostringstream ss; |
95 ss << "Sample rate: " << sample_rate_hz; | 95 ss << "Sample rate: " << sample_rate_hz; |
(...skipping 23 matching lines...) Expand all Loading... |
119 EXPECT_CALL(*render_delay_buffer_mock, IsBlockAvailable()) | 119 EXPECT_CALL(*render_delay_buffer_mock, IsBlockAvailable()) |
120 .Times(kNumBlocks) | 120 .Times(kNumBlocks) |
121 .WillRepeatedly(Return(true)); | 121 .WillRepeatedly(Return(true)); |
122 EXPECT_CALL(*render_delay_buffer_mock, SetDelay(kDelayInBlocks)) | 122 EXPECT_CALL(*render_delay_buffer_mock, SetDelay(kDelayInBlocks)) |
123 .Times(AtLeast(1)); | 123 .Times(AtLeast(1)); |
124 EXPECT_CALL(*render_delay_buffer_mock, MaxDelay()).WillOnce(Return(30)); | 124 EXPECT_CALL(*render_delay_buffer_mock, MaxDelay()).WillOnce(Return(30)); |
125 EXPECT_CALL(*render_delay_buffer_mock, Delay()) | 125 EXPECT_CALL(*render_delay_buffer_mock, Delay()) |
126 .Times(kNumBlocks + 1) | 126 .Times(kNumBlocks + 1) |
127 .WillRepeatedly(Return(0)); | 127 .WillRepeatedly(Return(0)); |
128 std::unique_ptr<BlockProcessor> block_processor( | 128 std::unique_ptr<BlockProcessor> block_processor( |
129 BlockProcessor::Create(rate, std::move(render_delay_buffer_mock))); | 129 BlockProcessor::Create(AudioProcessing::Config::EchoCanceller3(), rate, |
| 130 std::move(render_delay_buffer_mock))); |
130 | 131 |
131 std::vector<std::vector<float>> render_block( | 132 std::vector<std::vector<float>> render_block( |
132 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | 133 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); |
133 std::vector<std::vector<float>> capture_block( | 134 std::vector<std::vector<float>> capture_block( |
134 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | 135 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); |
135 DelayBuffer<float> signal_delay_buffer(kDelayInSamples); | 136 DelayBuffer<float> signal_delay_buffer(kDelayInSamples); |
136 for (size_t k = 0; k < kNumBlocks; ++k) { | 137 for (size_t k = 0; k < kNumBlocks; ++k) { |
137 RandomizeSampleVector(&random_generator, render_block[0]); | 138 RandomizeSampleVector(&random_generator, render_block[0]); |
138 signal_delay_buffer.Delay(render_block[0], capture_block[0]); | 139 signal_delay_buffer.Delay(render_block[0], capture_block[0]); |
139 block_processor->BufferRender(render_block); | 140 block_processor->BufferRender(render_block); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 .Times(kNumBlocks) | 174 .Times(kNumBlocks) |
174 .WillRepeatedly(Return(9)); | 175 .WillRepeatedly(Return(9)); |
175 EXPECT_CALL(*render_delay_controller_mock, AlignmentHeadroomSamples()) | 176 EXPECT_CALL(*render_delay_controller_mock, AlignmentHeadroomSamples()) |
176 .Times(kNumBlocks); | 177 .Times(kNumBlocks); |
177 EXPECT_CALL(*echo_remover_mock, ProcessCapture(_, _, _, _, _)) | 178 EXPECT_CALL(*echo_remover_mock, ProcessCapture(_, _, _, _, _)) |
178 .Times(kNumBlocks); | 179 .Times(kNumBlocks); |
179 EXPECT_CALL(*echo_remover_mock, UpdateEchoLeakageStatus(_)) | 180 EXPECT_CALL(*echo_remover_mock, UpdateEchoLeakageStatus(_)) |
180 .Times(kNumBlocks); | 181 .Times(kNumBlocks); |
181 | 182 |
182 std::unique_ptr<BlockProcessor> block_processor(BlockProcessor::Create( | 183 std::unique_ptr<BlockProcessor> block_processor(BlockProcessor::Create( |
183 rate, std::move(render_delay_buffer_mock), | 184 AudioProcessing::Config::EchoCanceller3(), rate, |
| 185 std::move(render_delay_buffer_mock), |
184 std::move(render_delay_controller_mock), std::move(echo_remover_mock))); | 186 std::move(render_delay_controller_mock), std::move(echo_remover_mock))); |
185 | 187 |
186 std::vector<std::vector<float>> render_block( | 188 std::vector<std::vector<float>> render_block( |
187 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | 189 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); |
188 std::vector<std::vector<float>> capture_block( | 190 std::vector<std::vector<float>> capture_block( |
189 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | 191 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); |
190 DelayBuffer<float> signal_delay_buffer(640); | 192 DelayBuffer<float> signal_delay_buffer(640); |
191 for (size_t k = 0; k < kNumBlocks; ++k) { | 193 for (size_t k = 0; k < kNumBlocks; ++k) { |
192 RandomizeSampleVector(&random_generator, render_block[0]); | 194 RandomizeSampleVector(&random_generator, render_block[0]); |
193 signal_delay_buffer.Delay(render_block[0], capture_block[0]); | 195 signal_delay_buffer.Delay(render_block[0], capture_block[0]); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 // signal. | 233 // signal. |
232 TEST(BlockProcessor, VerifyCaptureNumBandsCheck) { | 234 TEST(BlockProcessor, VerifyCaptureNumBandsCheck) { |
233 for (auto rate : {8000, 16000, 32000, 48000}) { | 235 for (auto rate : {8000, 16000, 32000, 48000}) { |
234 SCOPED_TRACE(ProduceDebugText(rate)); | 236 SCOPED_TRACE(ProduceDebugText(rate)); |
235 RunCaptureNumBandsVerificationTest(rate); | 237 RunCaptureNumBandsVerificationTest(rate); |
236 } | 238 } |
237 } | 239 } |
238 | 240 |
239 // Verifiers that the verification for null ProcessCapture input works. | 241 // Verifiers that the verification for null ProcessCapture input works. |
240 TEST(BlockProcessor, NullProcessCaptureParameter) { | 242 TEST(BlockProcessor, NullProcessCaptureParameter) { |
241 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) | 243 EXPECT_DEATH(std::unique_ptr<BlockProcessor>( |
| 244 BlockProcessor::Create( |
| 245 AudioProcessing::Config::EchoCanceller3(), 8000)) |
242 ->ProcessCapture(false, false, nullptr), | 246 ->ProcessCapture(false, false, nullptr), |
243 ""); | 247 ""); |
244 } | 248 } |
245 | 249 |
246 // Verifies the check for correct sample rate. | 250 // Verifies the check for correct sample rate. |
247 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH | 251 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH |
248 // tests on test bots has been fixed. | 252 // tests on test bots has been fixed. |
249 TEST(BlockProcessor, DISABLED_WrongSampleRate) { | 253 TEST(BlockProcessor, DISABLED_WrongSampleRate) { |
250 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8001)), | 254 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create( |
| 255 AudioProcessing::Config::EchoCanceller3(), 8001)), |
251 ""); | 256 ""); |
252 } | 257 } |
253 | 258 |
254 #endif | 259 #endif |
255 | 260 |
256 } // namespace webrtc | 261 } // namespace webrtc |
OLD | NEW |