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 Random random_generator(42U); | |
107 for (auto rate : {8000, 16000, 32000, 48000}) { | |
108 SCOPED_TRACE(ProduceDebugText(rate)); | |
109 std::unique_ptr<testing::StrictMock<webrtc::test::MockRenderDelayBuffer>> | |
110 render_delay_buffer_mock( | |
111 new StrictMock<webrtc::test::MockRenderDelayBuffer>(rate)); | |
112 EXPECT_CALL(*render_delay_buffer_mock, Insert(_)) | |
113 .Times(kNumBlocks) | |
114 .WillRepeatedly(Return(true)); | |
115 EXPECT_CALL(*render_delay_buffer_mock, IsBlockAvailable()) | |
116 .Times(kNumBlocks) | |
117 .WillRepeatedly(Return(true)); | |
118 EXPECT_CALL(*render_delay_buffer_mock, SetDelay(9)).Times(AtLeast(1)); | |
aleloi
2017/01/20 14:45:37
Is it obvious that the correct delay is 9 blocks?
peah-webrtc
2017/01/23 14:16:40
I agree. I tried to make it more clear by using co
| |
119 EXPECT_CALL(*render_delay_buffer_mock, MaxDelay()).WillOnce(Return(30)); | |
120 EXPECT_CALL(*render_delay_buffer_mock, MaxApiJitter()).WillOnce(Return(30)); | |
121 EXPECT_CALL(*render_delay_buffer_mock, Delay()) | |
122 .Times(kNumBlocks + 1) | |
123 .WillRepeatedly(Return(0)); | |
124 std::unique_ptr<BlockProcessor> block_processor( | |
125 BlockProcessor::Create(rate, std::move(render_delay_buffer_mock))); | |
126 | |
127 std::vector<std::vector<float>> render_block( | |
128 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
129 std::vector<std::vector<float>> capture_block( | |
130 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
131 DelayBuffer<float> signal_delay_buffer(640); | |
aleloi
2017/01/20 14:45:37
Related comment about correct delay above.
peah-webrtc
2017/01/23 14:16:40
Done.
| |
132 for (size_t k = 0; k < kNumBlocks; ++k) { | |
133 RandomizeSampleVector(&random_generator, render_block[0]); | |
134 signal_delay_buffer.Delay(render_block[0], capture_block[0]); | |
135 EXPECT_TRUE(block_processor->BufferRender(&render_block)); | |
136 block_processor->ProcessCapture(false, false, &capture_block); | |
137 } | |
138 } | |
139 } | |
140 | |
141 // Verifies that BlockProcessor submodules are called in a proper manner. | |
142 TEST(BlockProcessor, SubmoduleIntegration) { | |
143 constexpr size_t kNumBlocks = 310; | |
144 Random random_generator(42U); | |
145 for (auto rate : {8000, 16000, 32000, 48000}) { | |
146 SCOPED_TRACE(ProduceDebugText(rate)); | |
147 std::unique_ptr<testing::StrictMock<webrtc::test::MockRenderDelayBuffer>> | |
148 render_delay_buffer_mock( | |
149 new StrictMock<webrtc::test::MockRenderDelayBuffer>(rate)); | |
150 std::unique_ptr< | |
151 testing::StrictMock<webrtc::test::MockRenderDelayController>> | |
152 render_delay_controller_mock( | |
153 new StrictMock<webrtc::test::MockRenderDelayController>()); | |
154 std::unique_ptr<testing::StrictMock<webrtc::test::MockEchoRemover>> | |
155 echo_remover_mock(new StrictMock<webrtc::test::MockEchoRemover>()); | |
156 | |
157 EXPECT_CALL(*render_delay_buffer_mock, Insert(_)) | |
158 .Times(kNumBlocks) | |
159 .WillRepeatedly(Return(true)); | |
160 EXPECT_CALL(*render_delay_buffer_mock, IsBlockAvailable()) | |
161 .Times(kNumBlocks) | |
162 .WillRepeatedly(Return(true)); | |
163 EXPECT_CALL(*render_delay_buffer_mock, GetNext()).Times(kNumBlocks); | |
164 EXPECT_CALL(*render_delay_buffer_mock, SetDelay(9)).Times(AtLeast(1)); | |
165 EXPECT_CALL(*render_delay_buffer_mock, Delay()) | |
166 .Times(kNumBlocks) | |
167 .WillRepeatedly(Return(0)); | |
168 EXPECT_CALL(*render_delay_controller_mock, GetDelay(_)) | |
169 .Times(kNumBlocks) | |
170 .WillRepeatedly(Return(9)); | |
171 EXPECT_CALL(*render_delay_controller_mock, AnalyzeRender(_)) | |
172 .Times(kNumBlocks) | |
173 .WillRepeatedly(Return(true)); | |
174 EXPECT_CALL(*render_delay_controller_mock, AlignmentHeadroom()) | |
175 .Times(kNumBlocks); | |
176 EXPECT_CALL(*echo_remover_mock, ProcessBlock(_, _, _, _, _)) | |
177 .Times(kNumBlocks); | |
178 EXPECT_CALL(*echo_remover_mock, UpdateEchoLeakageStatus(_)) | |
179 .Times(kNumBlocks); | |
180 | |
181 std::unique_ptr<BlockProcessor> block_processor(BlockProcessor::Create( | |
182 rate, std::move(render_delay_buffer_mock), | |
183 std::move(render_delay_controller_mock), std::move(echo_remover_mock))); | |
184 | |
185 std::vector<std::vector<float>> render_block( | |
186 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
187 std::vector<std::vector<float>> capture_block( | |
188 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
189 DelayBuffer<float> signal_delay_buffer(640); | |
190 for (size_t k = 0; k < kNumBlocks; ++k) { | |
191 RandomizeSampleVector(&random_generator, render_block[0]); | |
192 signal_delay_buffer.Delay(render_block[0], capture_block[0]); | |
193 EXPECT_TRUE(block_processor->BufferRender(&render_block)); | |
194 block_processor->ProcessCapture(false, false, &capture_block); | |
195 block_processor->UpdateEchoLeakageStatus(false); | |
196 } | |
197 } | |
198 } | |
199 | |
89 TEST(BlockProcessor, BasicSetupAndApiCalls) { | 200 TEST(BlockProcessor, BasicSetupAndApiCalls) { |
90 for (auto rate : {8000, 16000, 32000, 48000}) { | 201 for (auto rate : {8000, 16000, 32000, 48000}) { |
91 SCOPED_TRACE(ProduceDebugText(rate)); | 202 SCOPED_TRACE(ProduceDebugText(rate)); |
92 RunBasicSetupAndApiCallTest(rate); | 203 RunBasicSetupAndApiCallTest(rate); |
93 } | 204 } |
94 } | 205 } |
95 | 206 |
96 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 207 #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 | 208 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}) { | 209 for (auto rate : {8000, 16000, 32000, 48000}) { |
101 SCOPED_TRACE(ProduceDebugText(rate)); | 210 SCOPED_TRACE(ProduceDebugText(rate)); |
102 RunRenderBlockSizeVerificationTest(rate); | 211 RunRenderBlockSizeVerificationTest(rate); |
103 } | 212 } |
104 } | 213 } |
105 | 214 |
106 TEST(BlockProcessor, DISABLED_VerifyCaptureBlockSizeCheck) { | 215 TEST(BlockProcessor, VerifyCaptureBlockSizeCheck) { |
107 for (auto rate : {8000, 16000, 32000, 48000}) { | 216 for (auto rate : {8000, 16000, 32000, 48000}) { |
108 SCOPED_TRACE(ProduceDebugText(rate)); | 217 SCOPED_TRACE(ProduceDebugText(rate)); |
109 RunCaptureBlockSizeVerificationTest(rate); | 218 RunCaptureBlockSizeVerificationTest(rate); |
110 } | 219 } |
111 } | 220 } |
112 | 221 |
113 TEST(BlockProcessor, DISABLED_VerifyRenderNumBandsCheck) { | 222 TEST(BlockProcessor, VerifyRenderNumBandsCheck) { |
114 for (auto rate : {8000, 16000, 32000, 48000}) { | 223 for (auto rate : {8000, 16000, 32000, 48000}) { |
115 SCOPED_TRACE(ProduceDebugText(rate)); | 224 SCOPED_TRACE(ProduceDebugText(rate)); |
116 RunRenderNumBandsVerificationTest(rate); | 225 RunRenderNumBandsVerificationTest(rate); |
117 } | 226 } |
118 } | 227 } |
119 | 228 |
120 TEST(BlockProcessor, DISABLED_VerifyCaptureNumBandsCheck) { | 229 TEST(BlockProcessor, VerifyCaptureNumBandsCheck) { |
121 for (auto rate : {8000, 16000, 32000, 48000}) { | 230 for (auto rate : {8000, 16000, 32000, 48000}) { |
122 SCOPED_TRACE(ProduceDebugText(rate)); | 231 SCOPED_TRACE(ProduceDebugText(rate)); |
123 RunCaptureNumBandsVerificationTest(rate); | 232 RunCaptureNumBandsVerificationTest(rate); |
124 } | 233 } |
125 } | 234 } |
126 | 235 |
127 // Verifiers that the verification for null ProcessCapture input works. | 236 // Verifiers that the verification for null ProcessCapture input works. |
128 TEST(BlockProcessor, DISABLED_NullProcessCaptureParameter) { | 237 TEST(BlockProcessor, NullProcessCaptureParameter) { |
129 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) | 238 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) |
130 ->ProcessCapture(false, false, nullptr), | 239 ->ProcessCapture(false, false, nullptr), |
131 ""); | 240 ""); |
132 } | 241 } |
133 | 242 |
134 // Verifiers that the verification for null BufferRender input works. | 243 // Verifiers that the verification for null BufferRender input works. |
135 TEST(BlockProcessor, DISABLED_NullBufferRenderParameter) { | 244 TEST(BlockProcessor, NullBufferRenderParameter) { |
136 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) | 245 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) |
137 ->BufferRender(nullptr), | 246 ->BufferRender(nullptr), |
138 ""); | 247 ""); |
139 } | 248 } |
140 | 249 |
141 #endif | 250 #endif |
142 | 251 |
143 } // namespace webrtc | 252 } // namespace webrtc |
OLD | NEW |