Chromium Code Reviews| 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_FALSE(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}) { | |
|
hlundin-webrtc
2017/01/18 13:08:48
Are any of the tested code paths dependent on the
peah-webrtc
2017/01/19 15:33:04
I agree that it is probably sufficient to only tes
hlundin-webrtc
2017/01/20 09:31:44
Acknowledged.
peah-webrtc
2017/01/23 14:16:39
Acknowledged.
| |
| 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)); | |
| 119 EXPECT_CALL(*render_delay_buffer_mock, MaxDelay()) | |
| 120 .Times(1) | |
|
hlundin-webrtc
2017/01/18 13:08:48
Use .WillOnce(Return(x)) instead of .Times(1).Will
peah-webrtc
2017/01/19 15:33:04
Done.
| |
| 121 .WillRepeatedly(Return(30)); | |
| 122 EXPECT_CALL(*render_delay_buffer_mock, MaxApiJitter()) | |
| 123 .Times(1) | |
|
hlundin-webrtc
2017/01/18 13:08:48
WillOnce
peah-webrtc
2017/01/19 15:33:04
Done.
| |
| 124 .WillRepeatedly(Return(30)); | |
| 125 EXPECT_CALL(*render_delay_buffer_mock, Delay()) | |
| 126 .Times(kNumBlocks + 1) | |
| 127 .WillRepeatedly(Return(0)); | |
| 128 std::unique_ptr<BlockProcessor> block_processor( | |
| 129 BlockProcessor::Create(rate, std::move(render_delay_buffer_mock))); | |
| 130 | |
| 131 std::vector<std::vector<float>> render_block( | |
| 132 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
| 133 std::vector<std::vector<float>> capture_block( | |
| 134 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
| 135 DelayBuffer<float> signal_delay_buffer(640); | |
| 136 for (size_t k = 0; k < kNumBlocks; ++k) { | |
| 137 RandomizeSampleVector(&random_generator, render_block[0]); | |
| 138 signal_delay_buffer.Delay(render_block[0], capture_block[0]); | |
| 139 EXPECT_FALSE(block_processor->BufferRender(&render_block)); | |
| 140 block_processor->ProcessCapture(false, false, &capture_block); | |
| 141 } | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 // Verifies that BlockProcessor submodules are called in a proper manner. | |
| 146 TEST(BlockProcessor, SubmoduleIntegration) { | |
| 147 constexpr size_t kNumBlocks = 310; | |
| 148 Random random_generator(42U); | |
| 149 for (auto rate : {8000, 16000, 32000, 48000}) { | |
|
hlundin-webrtc
2017/01/18 13:08:48
Same here; would testing one rate suffice?
peah-webrtc
2017/01/19 15:33:04
Probably yes, but for the same arguments as above,
hlundin-webrtc
2017/01/20 09:31:44
Acknowledged.
peah-webrtc
2017/01/23 14:16:39
Acknowledged.
| |
| 150 SCOPED_TRACE(ProduceDebugText(rate)); | |
| 151 std::unique_ptr<testing::StrictMock<webrtc::test::MockRenderDelayBuffer>> | |
| 152 render_delay_buffer_mock( | |
| 153 new StrictMock<webrtc::test::MockRenderDelayBuffer>(rate)); | |
| 154 std::unique_ptr< | |
| 155 testing::StrictMock<webrtc::test::MockRenderDelayController>> | |
| 156 render_delay_controller_mock( | |
| 157 new StrictMock<webrtc::test::MockRenderDelayController>()); | |
| 158 std::unique_ptr<testing::StrictMock<webrtc::test::MockEchoRemover>> | |
| 159 echo_remover_mock(new StrictMock<webrtc::test::MockEchoRemover>()); | |
| 160 | |
| 161 EXPECT_CALL(*render_delay_buffer_mock, Insert(_)) | |
| 162 .Times(kNumBlocks) | |
| 163 .WillRepeatedly(Return(true)); | |
| 164 EXPECT_CALL(*render_delay_buffer_mock, IsBlockAvailable()) | |
| 165 .Times(kNumBlocks) | |
| 166 .WillRepeatedly(Return(true)); | |
| 167 EXPECT_CALL(*render_delay_buffer_mock, SetDelay(9)).Times(AtLeast(1)); | |
| 168 EXPECT_CALL(*render_delay_buffer_mock, MaxDelay()).Times(0); | |
|
hlundin-webrtc
2017/01/18 13:08:48
You don't need this when you have a StrictMock.
peah-webrtc
2017/01/19 15:33:04
Done.
| |
| 169 EXPECT_CALL(*render_delay_buffer_mock, MaxApiJitter()).Times(0); | |
|
hlundin-webrtc
2017/01/18 13:08:48
You don't need this when you have a StrictMock.
peah-webrtc
2017/01/19 15:33:04
Done.
| |
| 170 EXPECT_CALL(*render_delay_buffer_mock, Delay()) | |
| 171 .Times(kNumBlocks) | |
| 172 .WillRepeatedly(Return(0)); | |
| 173 EXPECT_CALL(*render_delay_controller_mock, SelectDelay(_)) | |
| 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, AlignmentHeadroom()) | |
| 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_FALSE(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 |