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 |
11 #include "webrtc/modules/audio_processing/aec3/block_processor.h" | 11 #include "webrtc/modules/audio_processing/aec3/block_processor.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 #include <sstream> | 14 #include <sstream> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/base/checks.h" | |
19 #include "webrtc/base/random.h" | |
18 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" | 20 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" |
21 #include "webrtc/modules/audio_processing/aec3/mock/mock_echo_remover.h" | |
22 #include "webrtc/modules/audio_processing/aec3/mock/mock_render_delay_buffer.h" | |
23 #include "webrtc/modules/audio_processing/aec3/mock/mock_render_delay_controller .h" | |
24 #include "webrtc/modules/audio_processing/test/echo_canceller_test_tools.h" | |
25 #include "webrtc/test/gmock.h" | |
19 #include "webrtc/test/gtest.h" | 26 #include "webrtc/test/gtest.h" |
20 | 27 |
21 namespace webrtc { | 28 namespace webrtc { |
22 namespace { | 29 namespace { |
23 | 30 |
31 using testing::AtLeast; | |
32 using testing::Return; | |
33 using testing::StrictMock; | |
34 using testing::_; | |
35 | |
24 // Verifies that the basic BlockProcessor functionality works and that the API | 36 // Verifies that the basic BlockProcessor functionality works and that the API |
25 // methods are callable. | 37 // methods are callable. |
26 void RunBasicSetupAndApiCallTest(int sample_rate_hz) { | 38 void RunBasicSetupAndApiCallTest(int sample_rate_hz) { |
27 std::unique_ptr<BlockProcessor> block_processor( | 39 std::unique_ptr<BlockProcessor> block_processor( |
28 BlockProcessor::Create(sample_rate_hz)); | 40 BlockProcessor::Create(sample_rate_hz)); |
29 std::vector<std::vector<float>> block(NumBandsForRate(sample_rate_hz), | 41 std::vector<std::vector<float>> block(NumBandsForRate(sample_rate_hz), |
30 std::vector<float>(kBlockSize, 0.f)); | 42 std::vector<float>(kBlockSize, 0.f)); |
31 | 43 |
32 EXPECT_FALSE(block_processor->BufferRender(&block)); | 44 EXPECT_TRUE(block_processor->BufferRender(&block)); |
33 block_processor->ProcessCapture(false, false, &block); | 45 block_processor->ProcessCapture(false, false, &block); |
34 block_processor->ReportEchoLeakage(false); | 46 block_processor->UpdateEchoLeakageStatus(false); |
35 } | 47 } |
36 | 48 |
37 #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) |
38 void RunRenderBlockSizeVerificationTest(int sample_rate_hz) { | 50 void RunRenderBlockSizeVerificationTest(int sample_rate_hz) { |
39 std::unique_ptr<BlockProcessor> block_processor( | 51 std::unique_ptr<BlockProcessor> block_processor( |
40 BlockProcessor::Create(sample_rate_hz)); | 52 BlockProcessor::Create(sample_rate_hz)); |
41 std::vector<std::vector<float>> block( | 53 std::vector<std::vector<float>> block( |
42 NumBandsForRate(sample_rate_hz), std::vector<float>(kBlockSize - 1, 0.f)); | 54 NumBandsForRate(sample_rate_hz), std::vector<float>(kBlockSize - 1, 0.f)); |
43 | 55 |
44 EXPECT_DEATH(block_processor->BufferRender(&block), ""); | 56 EXPECT_DEATH(block_processor->BufferRender(&block), ""); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 #endif | 91 #endif |
80 | 92 |
81 std::string ProduceDebugText(int sample_rate_hz) { | 93 std::string ProduceDebugText(int sample_rate_hz) { |
82 std::ostringstream ss; | 94 std::ostringstream ss; |
83 ss << "Sample rate: " << sample_rate_hz; | 95 ss << "Sample rate: " << sample_rate_hz; |
84 return ss.str(); | 96 return ss.str(); |
85 } | 97 } |
86 | 98 |
87 } // namespace | 99 } // namespace |
88 | 100 |
101 // Verifies that the delay controller functionality is properly integrated with | |
102 // the render delay buffer inside block processor. | |
103 // TODO(peah): Activate the unittest once the required code has been landed. | |
104 TEST(BlockProcessor, DISABLED_DelayControllerIntegration) { | |
105 constexpr size_t kNumBlocks = 310; | |
106 constexpr size_t kDelayInSamples = 640; | |
107 constexpr size_t kDelayHeadroom = 1; | |
108 constexpr size_t kDelayInBlocks = | |
hlundin-webrtc
2017/01/23 19:48:28
Is this division supposed to be exact? If so, you
peah-webrtc
2017/01/23 21:38:22
Thanks for the suggestion! The division is not req
| |
109 kDelayInSamples / kBlockSize - kDelayHeadroom; | |
110 Random random_generator(42U); | |
111 for (auto rate : {8000, 16000, 32000, 48000}) { | |
112 SCOPED_TRACE(ProduceDebugText(rate)); | |
113 std::unique_ptr<testing::StrictMock<webrtc::test::MockRenderDelayBuffer>> | |
114 render_delay_buffer_mock( | |
115 new StrictMock<webrtc::test::MockRenderDelayBuffer>(rate)); | |
116 EXPECT_CALL(*render_delay_buffer_mock, Insert(_)) | |
117 .Times(kNumBlocks) | |
118 .WillRepeatedly(Return(true)); | |
119 EXPECT_CALL(*render_delay_buffer_mock, IsBlockAvailable()) | |
120 .Times(kNumBlocks) | |
121 .WillRepeatedly(Return(true)); | |
122 EXPECT_CALL(*render_delay_buffer_mock, SetDelay(kDelayInBlocks)) | |
123 .Times(AtLeast(1)); | |
124 EXPECT_CALL(*render_delay_buffer_mock, MaxDelay()).WillOnce(Return(30)); | |
125 EXPECT_CALL(*render_delay_buffer_mock, MaxApiJitter()).WillOnce(Return(30)); | |
126 EXPECT_CALL(*render_delay_buffer_mock, Delay()) | |
127 .Times(kNumBlocks + 1) | |
128 .WillRepeatedly(Return(0)); | |
129 std::unique_ptr<BlockProcessor> block_processor( | |
130 BlockProcessor::Create(rate, std::move(render_delay_buffer_mock))); | |
131 | |
132 std::vector<std::vector<float>> render_block( | |
133 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
134 std::vector<std::vector<float>> capture_block( | |
135 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
136 DelayBuffer<float> signal_delay_buffer(kDelayInSamples); | |
137 for (size_t k = 0; k < kNumBlocks; ++k) { | |
138 RandomizeSampleVector(&random_generator, render_block[0]); | |
139 signal_delay_buffer.Delay(render_block[0], capture_block[0]); | |
140 EXPECT_TRUE(block_processor->BufferRender(&render_block)); | |
141 block_processor->ProcessCapture(false, false, &capture_block); | |
142 } | |
143 } | |
144 } | |
145 | |
146 // Verifies that BlockProcessor submodules are called in a proper manner. | |
147 TEST(BlockProcessor, SubmoduleIntegration) { | |
148 constexpr size_t kNumBlocks = 310; | |
149 Random random_generator(42U); | |
150 for (auto rate : {8000, 16000, 32000, 48000}) { | |
151 SCOPED_TRACE(ProduceDebugText(rate)); | |
152 std::unique_ptr<testing::StrictMock<webrtc::test::MockRenderDelayBuffer>> | |
153 render_delay_buffer_mock( | |
154 new StrictMock<webrtc::test::MockRenderDelayBuffer>(rate)); | |
155 std::unique_ptr< | |
156 testing::StrictMock<webrtc::test::MockRenderDelayController>> | |
157 render_delay_controller_mock( | |
158 new StrictMock<webrtc::test::MockRenderDelayController>()); | |
159 std::unique_ptr<testing::StrictMock<webrtc::test::MockEchoRemover>> | |
160 echo_remover_mock(new StrictMock<webrtc::test::MockEchoRemover>()); | |
161 | |
162 EXPECT_CALL(*render_delay_buffer_mock, Insert(_)) | |
163 .Times(kNumBlocks) | |
164 .WillRepeatedly(Return(true)); | |
165 EXPECT_CALL(*render_delay_buffer_mock, IsBlockAvailable()) | |
166 .Times(kNumBlocks) | |
167 .WillRepeatedly(Return(true)); | |
168 EXPECT_CALL(*render_delay_buffer_mock, GetNext()).Times(kNumBlocks); | |
169 EXPECT_CALL(*render_delay_buffer_mock, SetDelay(9)).Times(AtLeast(1)); | |
170 EXPECT_CALL(*render_delay_buffer_mock, Delay()) | |
171 .Times(kNumBlocks) | |
172 .WillRepeatedly(Return(0)); | |
173 EXPECT_CALL(*render_delay_controller_mock, GetDelay(_)) | |
174 .Times(kNumBlocks) | |
175 .WillRepeatedly(Return(9)); | |
176 EXPECT_CALL(*render_delay_controller_mock, AnalyzeRender(_)) | |
177 .Times(kNumBlocks) | |
178 .WillRepeatedly(Return(true)); | |
179 EXPECT_CALL(*render_delay_controller_mock, AlignmentHeadroomSamples()) | |
180 .Times(kNumBlocks); | |
181 EXPECT_CALL(*echo_remover_mock, ProcessBlock(_, _, _, _, _)) | |
182 .Times(kNumBlocks); | |
183 EXPECT_CALL(*echo_remover_mock, UpdateEchoLeakageStatus(_)) | |
184 .Times(kNumBlocks); | |
185 | |
186 std::unique_ptr<BlockProcessor> block_processor(BlockProcessor::Create( | |
187 rate, std::move(render_delay_buffer_mock), | |
188 std::move(render_delay_controller_mock), std::move(echo_remover_mock))); | |
189 | |
190 std::vector<std::vector<float>> render_block( | |
191 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
192 std::vector<std::vector<float>> capture_block( | |
193 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
194 DelayBuffer<float> signal_delay_buffer(640); | |
195 for (size_t k = 0; k < kNumBlocks; ++k) { | |
196 RandomizeSampleVector(&random_generator, render_block[0]); | |
197 signal_delay_buffer.Delay(render_block[0], capture_block[0]); | |
198 EXPECT_TRUE(block_processor->BufferRender(&render_block)); | |
199 block_processor->ProcessCapture(false, false, &capture_block); | |
200 block_processor->UpdateEchoLeakageStatus(false); | |
201 } | |
202 } | |
203 } | |
204 | |
89 TEST(BlockProcessor, BasicSetupAndApiCalls) { | 205 TEST(BlockProcessor, BasicSetupAndApiCalls) { |
90 for (auto rate : {8000, 16000, 32000, 48000}) { | 206 for (auto rate : {8000, 16000, 32000, 48000}) { |
91 SCOPED_TRACE(ProduceDebugText(rate)); | 207 SCOPED_TRACE(ProduceDebugText(rate)); |
92 RunBasicSetupAndApiCallTest(rate); | 208 RunBasicSetupAndApiCallTest(rate); |
93 } | 209 } |
94 } | 210 } |
95 | 211 |
96 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 212 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
97 // TODO(peah): Enable all DEATH tests below, or add suppressions, once clarity | 213 TEST(BlockProcessor, VerifyRenderBlockSizeCheck) { |
98 // has been reached on why they fail on the trybots. | |
99 TEST(BlockProcessor, DISABLED_VerifyRenderBlockSizeCheck) { | |
100 for (auto rate : {8000, 16000, 32000, 48000}) { | 214 for (auto rate : {8000, 16000, 32000, 48000}) { |
101 SCOPED_TRACE(ProduceDebugText(rate)); | 215 SCOPED_TRACE(ProduceDebugText(rate)); |
102 RunRenderBlockSizeVerificationTest(rate); | 216 RunRenderBlockSizeVerificationTest(rate); |
103 } | 217 } |
104 } | 218 } |
105 | 219 |
106 TEST(BlockProcessor, DISABLED_VerifyCaptureBlockSizeCheck) { | 220 TEST(BlockProcessor, VerifyCaptureBlockSizeCheck) { |
107 for (auto rate : {8000, 16000, 32000, 48000}) { | 221 for (auto rate : {8000, 16000, 32000, 48000}) { |
108 SCOPED_TRACE(ProduceDebugText(rate)); | 222 SCOPED_TRACE(ProduceDebugText(rate)); |
109 RunCaptureBlockSizeVerificationTest(rate); | 223 RunCaptureBlockSizeVerificationTest(rate); |
110 } | 224 } |
111 } | 225 } |
112 | 226 |
113 TEST(BlockProcessor, DISABLED_VerifyRenderNumBandsCheck) { | 227 TEST(BlockProcessor, VerifyRenderNumBandsCheck) { |
114 for (auto rate : {8000, 16000, 32000, 48000}) { | 228 for (auto rate : {8000, 16000, 32000, 48000}) { |
115 SCOPED_TRACE(ProduceDebugText(rate)); | 229 SCOPED_TRACE(ProduceDebugText(rate)); |
116 RunRenderNumBandsVerificationTest(rate); | 230 RunRenderNumBandsVerificationTest(rate); |
117 } | 231 } |
118 } | 232 } |
119 | 233 |
120 TEST(BlockProcessor, DISABLED_VerifyCaptureNumBandsCheck) { | 234 TEST(BlockProcessor, VerifyCaptureNumBandsCheck) { |
121 for (auto rate : {8000, 16000, 32000, 48000}) { | 235 for (auto rate : {8000, 16000, 32000, 48000}) { |
122 SCOPED_TRACE(ProduceDebugText(rate)); | 236 SCOPED_TRACE(ProduceDebugText(rate)); |
123 RunCaptureNumBandsVerificationTest(rate); | 237 RunCaptureNumBandsVerificationTest(rate); |
124 } | 238 } |
125 } | 239 } |
126 | 240 |
127 // Verifiers that the verification for null ProcessCapture input works. | 241 // Verifiers that the verification for null ProcessCapture input works. |
128 TEST(BlockProcessor, DISABLED_NullProcessCaptureParameter) { | 242 TEST(BlockProcessor, NullProcessCaptureParameter) { |
129 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) | 243 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) |
130 ->ProcessCapture(false, false, nullptr), | 244 ->ProcessCapture(false, false, nullptr), |
131 ""); | 245 ""); |
132 } | 246 } |
133 | 247 |
134 // Verifiers that the verification for null BufferRender input works. | 248 // Verifiers that the verification for null BufferRender input works. |
135 TEST(BlockProcessor, DISABLED_NullBufferRenderParameter) { | 249 TEST(BlockProcessor, NullBufferRenderParameter) { |
136 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) | 250 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) |
137 ->BufferRender(nullptr), | 251 ->BufferRender(nullptr), |
138 ""); | 252 ""); |
139 } | 253 } |
140 | 254 |
141 #endif | 255 #endif |
142 | 256 |
143 } // namespace webrtc | 257 } // namespace webrtc |
OLD | NEW |