OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 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 std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); |
| 37 |
| 38 std::vector<std::vector<float>> render(NumBandsForRate(rate), |
| 39 std::vector<float>(kBlockSize, 0.f)); |
| 40 std::vector<std::vector<float>> capture( |
| 41 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); |
| 42 for (size_t k = 0; k < 100; ++k) { |
| 43 EchoPathVariability echo_path_variability(k % 3 == 0 ? true : false, |
| 44 k % 5 == 0 ? true : false); |
| 45 rtc::Optional<size_t> echo_path_delay_samples = |
| 46 (k % 6 == 0 ? rtc::Optional<size_t>(k * 10) |
| 47 : rtc::Optional<size_t>()); |
| 48 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, |
| 49 k % 2 == 0 ? true : false, render, &capture); |
| 50 remover->UpdateEchoLeakageStatus(k % 7 == 0 ? true : false); |
| 51 } |
| 52 } |
| 53 } |
| 54 |
| 55 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 56 |
| 57 // Verifies the check for the samplerate. |
| 58 // TODO(peah): Re-enable the test once the issue with memory leaks during DEATH |
| 59 // tests on test bots has been fixed. |
| 60 TEST(EchoRemover, DISABLED_WrongSampleRate) { |
| 61 EXPECT_DEATH(std::unique_ptr<EchoRemover>(EchoRemover::Create(8001)), ""); |
| 62 } |
| 63 |
| 64 // Verifies the check for the render block size. |
| 65 TEST(EchoRemover, WrongRenderBlockSize) { |
| 66 for (auto rate : {8000, 16000, 32000, 48000}) { |
| 67 ProduceDebugText(rate); |
| 68 std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); |
| 69 |
| 70 std::vector<std::vector<float>> render( |
| 71 NumBandsForRate(rate), std::vector<float>(kBlockSize - 1, 0.f)); |
| 72 std::vector<std::vector<float>> capture( |
| 73 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); |
| 74 EchoPathVariability echo_path_variability(false, false); |
| 75 rtc::Optional<size_t> echo_path_delay_samples; |
| 76 EXPECT_DEATH( |
| 77 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, |
| 78 false, render, &capture), |
| 79 ""); |
| 80 } |
| 81 } |
| 82 |
| 83 // Verifies the check for the capture block size. |
| 84 TEST(EchoRemover, WrongCaptureBlockSize) { |
| 85 for (auto rate : {8000, 16000, 32000, 48000}) { |
| 86 ProduceDebugText(rate); |
| 87 std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); |
| 88 |
| 89 std::vector<std::vector<float>> render(NumBandsForRate(rate), |
| 90 std::vector<float>(kBlockSize, 0.f)); |
| 91 std::vector<std::vector<float>> capture( |
| 92 NumBandsForRate(rate), std::vector<float>(kBlockSize - 1, 0.f)); |
| 93 EchoPathVariability echo_path_variability(false, false); |
| 94 rtc::Optional<size_t> echo_path_delay_samples; |
| 95 EXPECT_DEATH( |
| 96 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, |
| 97 false, render, &capture), |
| 98 ""); |
| 99 } |
| 100 } |
| 101 |
| 102 // Verifies the check for the number of render bands. |
| 103 TEST(EchoRemover, WrongRenderNumBands) { |
| 104 for (auto rate : {16000, 32000, 48000}) { |
| 105 ProduceDebugText(rate); |
| 106 std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); |
| 107 |
| 108 std::vector<std::vector<float>> render( |
| 109 NumBandsForRate(rate == 48000 ? 16000 : rate + 16000), |
| 110 std::vector<float>(kBlockSize, 0.f)); |
| 111 std::vector<std::vector<float>> capture( |
| 112 NumBandsForRate(rate), std::vector<float>(kBlockSize, 0.f)); |
| 113 EchoPathVariability echo_path_variability(false, false); |
| 114 rtc::Optional<size_t> echo_path_delay_samples; |
| 115 EXPECT_DEATH( |
| 116 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, |
| 117 false, render, &capture), |
| 118 ""); |
| 119 } |
| 120 } |
| 121 |
| 122 // Verifies the check for the number of capture bands. |
| 123 TEST(EchoRemover, WrongCaptureNumBands) { |
| 124 for (auto rate : {16000, 32000, 48000}) { |
| 125 ProduceDebugText(rate); |
| 126 std::unique_ptr<EchoRemover> remover(EchoRemover::Create(rate)); |
| 127 |
| 128 std::vector<std::vector<float>> render(NumBandsForRate(rate), |
| 129 std::vector<float>(kBlockSize, 0.f)); |
| 130 std::vector<std::vector<float>> capture( |
| 131 NumBandsForRate(rate == 48000 ? 16000 : rate + 16000), |
| 132 std::vector<float>(kBlockSize, 0.f)); |
| 133 EchoPathVariability echo_path_variability(false, false); |
| 134 rtc::Optional<size_t> echo_path_delay_samples; |
| 135 EXPECT_DEATH( |
| 136 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, |
| 137 false, render, &capture), |
| 138 ""); |
| 139 } |
| 140 } |
| 141 |
| 142 // Verifies the check for non-null capture block. |
| 143 TEST(EchoRemover, NullCapture) { |
| 144 std::unique_ptr<EchoRemover> remover(EchoRemover::Create(8000)); |
| 145 |
| 146 std::vector<std::vector<float>> render(NumBandsForRate(8000), |
| 147 std::vector<float>(kBlockSize, 0.f)); |
| 148 EchoPathVariability echo_path_variability(false, false); |
| 149 rtc::Optional<size_t> echo_path_delay_samples; |
| 150 EXPECT_DEATH( |
| 151 remover->ProcessBlock(echo_path_delay_samples, echo_path_variability, |
| 152 false, render, nullptr), |
| 153 ""); |
| 154 } |
| 155 |
| 156 #endif |
| 157 |
| 158 } // namespace webrtc |
OLD | NEW |