Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
|
hlundin-webrtc
2017/01/18 13:08:49
2017
peah-webrtc
2017/01/19 15:33:05
Done.
| |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/modules/audio_processing/aec3/echo_remover.h" | |
| 12 | |
| 13 #include <memory> | |
| 14 #include <sstream> | |
| 15 #include <string> | |
| 16 | |
| 17 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" | |
| 18 #include "webrtc/modules/audio_processing/logging/apm_data_dumper.h" | |
| 19 #include "webrtc/test/gtest.h" | |
| 20 | |
| 21 namespace webrtc { | |
| 22 namespace { | |
| 23 | |
| 24 std::string ProduceDebugText(int sample_rate_hz) { | |
| 25 std::ostringstream ss; | |
| 26 ss << "Sample rate: " << sample_rate_hz; | |
| 27 return ss.str(); | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 // Verifies the basic API call sequence | |
| 33 TEST(EchoRemover, BasicApiCalls) { | |
| 34 for (auto rate : {8000, 16000, 32000, 48000}) { | |
| 35 ProduceDebugText(rate); | |
| 36 ApmDataDumper data_dumper(0); | |
| 37 std::unique_ptr<EchoRemover> remover( | |
| 38 EchoRemover::Create(&data_dumper, rate)); | |
| 39 | |
| 40 std::vector<std::vector<float>> render(NumBandsForRate(rate), | |
| 41 std::vector<float>(kBlockSize, 0.f)); | |
| 42 std::vector<std::vector<float>> capture( | |
| 43 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
| 44 for (size_t k = 0; k < 100; ++k) { | |
| 45 EchoPathVariability echo_path_variability(k % 3 == 0 ? true : false, | |
| 46 k % 5 == 0 ? true : false); | |
| 47 rtc::Optional<size_t> echo_path_delay_samples = | |
| 48 (k % 6 == 0 ? rtc::Optional<size_t>(k * 10) | |
| 49 : rtc::Optional<size_t>()); | |
| 50 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, | |
| 51 k % 2 == 0 ? true : false, render, &capture); | |
| 52 remover->UpdateEchoLeakageStatus(k % 7 == 0 ? true : false); | |
| 53 } | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | |
| 58 | |
| 59 // Verifies the check for the samplerate. | |
| 60 TEST(EchoRemover, WrongSampleRate) { | |
| 61 ApmDataDumper data_dumper(0); | |
| 62 EXPECT_DEATH( | |
| 63 std::unique_ptr<EchoRemover>(EchoRemover::Create(&data_dumper, 8001)), | |
| 64 ""); | |
| 65 } | |
| 66 | |
| 67 // Verifies the check for the render block size. | |
| 68 TEST(EchoRemover, WrongRenderBlockSize) { | |
| 69 for (auto rate : {8000, 16000, 32000, 48000}) { | |
| 70 ProduceDebugText(rate); | |
| 71 ApmDataDumper data_dumper(0); | |
| 72 std::unique_ptr<EchoRemover> remover( | |
| 73 EchoRemover::Create(&data_dumper, rate)); | |
| 74 | |
| 75 std::vector<std::vector<float>> render( | |
| 76 NumBandsForRate(rate), std::vector<float>(kBlockSize - 1, 0.f)); | |
| 77 std::vector<std::vector<float>> capture( | |
| 78 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
| 79 EchoPathVariability echo_path_variability(false, false); | |
| 80 rtc::Optional<size_t> echo_path_delay_samples; | |
| 81 EXPECT_DEATH( | |
| 82 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, | |
| 83 false, render, &capture), | |
| 84 ""); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 // Verifies the check for the capture block size. | |
| 89 TEST(EchoRemover, WrongCaptureBlockSize) { | |
| 90 for (auto rate : {8000, 16000, 32000, 48000}) { | |
| 91 ProduceDebugText(rate); | |
| 92 ApmDataDumper data_dumper(0); | |
| 93 std::unique_ptr<EchoRemover> remover( | |
| 94 EchoRemover::Create(&data_dumper, rate)); | |
| 95 | |
| 96 std::vector<std::vector<float>> render(NumBandsForRate(rate), | |
| 97 std::vector<float>(kBlockSize, 0.f)); | |
| 98 std::vector<std::vector<float>> capture( | |
| 99 NumBandsForRate(rate), std::vector<float>(kBlockSize - 1, 0.f)); | |
| 100 EchoPathVariability echo_path_variability(false, false); | |
| 101 rtc::Optional<size_t> echo_path_delay_samples; | |
| 102 EXPECT_DEATH( | |
| 103 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, | |
| 104 false, render, &capture), | |
| 105 ""); | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 // Verifies the check for the number of render bands. | |
| 110 TEST(EchoRemover, WrongRenderNumBands) { | |
| 111 for (auto rate : {16000, 32000, 48000}) { | |
| 112 ProduceDebugText(rate); | |
| 113 ApmDataDumper data_dumper(0); | |
| 114 std::unique_ptr<EchoRemover> remover( | |
| 115 EchoRemover::Create(&data_dumper, rate)); | |
| 116 | |
| 117 std::vector<std::vector<float>> render( | |
| 118 NumBandsForRate(rate == 48000 ? 16000 : rate + 16000), | |
| 119 std::vector<float>(kBlockSize, 0.f)); | |
| 120 std::vector<std::vector<float>> capture( | |
| 121 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); | |
| 122 EchoPathVariability echo_path_variability(false, false); | |
| 123 rtc::Optional<size_t> echo_path_delay_samples; | |
| 124 EXPECT_DEATH( | |
| 125 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, | |
| 126 false, render, &capture), | |
| 127 ""); | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 // Verifies the check for the number of capture bands. | |
| 132 TEST(EchoRemover, WrongCaptureNumBands) { | |
| 133 for (auto rate : {16000, 32000, 48000}) { | |
| 134 ProduceDebugText(rate); | |
| 135 ApmDataDumper data_dumper(0); | |
| 136 std::unique_ptr<EchoRemover> remover( | |
| 137 EchoRemover::Create(&data_dumper, rate)); | |
| 138 | |
| 139 std::vector<std::vector<float>> render(NumBandsForRate(rate), | |
| 140 std::vector<float>(kBlockSize, 0.f)); | |
| 141 std::vector<std::vector<float>> capture( | |
| 142 NumBandsForRate(rate == 48000 ? 16000 : rate + 16000), | |
| 143 std::vector<float>(kBlockSize, 0.f)); | |
| 144 EchoPathVariability echo_path_variability(false, false); | |
| 145 rtc::Optional<size_t> echo_path_delay_samples; | |
| 146 EXPECT_DEATH( | |
| 147 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, | |
| 148 false, render, &capture), | |
| 149 ""); | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 // Verifies the check for non-null capture block. | |
| 154 TEST(EchoRemover, NullCapture) { | |
| 155 for (auto rate : {16000, 32000, 48000}) { | |
|
hlundin-webrtc
2017/01/18 13:08:49
Do you have to test all rates?
peah-webrtc
2017/01/19 15:33:05
Done.
| |
| 156 ProduceDebugText(rate); | |
| 157 ApmDataDumper data_dumper(0); | |
| 158 std::unique_ptr<EchoRemover> remover( | |
| 159 EchoRemover::Create(&data_dumper, rate)); | |
| 160 | |
| 161 std::vector<std::vector<float>> render(NumBandsForRate(rate), | |
| 162 std::vector<float>(kBlockSize, 0.f)); | |
| 163 EchoPathVariability echo_path_variability(false, false); | |
| 164 rtc::Optional<size_t> echo_path_delay_samples; | |
| 165 EXPECT_DEATH( | |
| 166 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, | |
| 167 false, render, nullptr), | |
| 168 ""); | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 // Verifies the check for non-null data dumper. | |
| 173 TEST(EchoRemover, NullDataDumper) { | |
| 174 for (auto rate : {16000, 32000, 48000}) { | |
|
hlundin-webrtc
2017/01/18 13:08:49
Do you have to test all rates?
peah-webrtc
2017/01/19 15:33:05
This test is now removed.
Done.
| |
| 175 ProduceDebugText(rate); | |
| 176 EXPECT_DEATH( | |
| 177 std::unique_ptr<EchoRemover>(EchoRemover::Create(nullptr, rate)), ""); | |
| 178 } | |
| 179 } | |
| 180 | |
| 181 #endif | |
| 182 | |
| 183 } // namespace webrtc | |
| OLD | NEW |