OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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/block_processor.h" |
| 12 |
| 13 #include <memory> |
| 14 #include <sstream> |
| 15 #include <string> |
| 16 #include <vector> |
| 17 |
| 18 #include "webrtc/modules/audio_processing/aec3/aec3_constants.h" |
| 19 #include "webrtc/test/gtest.h" |
| 20 |
| 21 namespace webrtc { |
| 22 namespace { |
| 23 |
| 24 // Verifies that the basic BlockProcessor functionality works and that the API |
| 25 // methods are callable. |
| 26 void RunBasicSetupAndApiCallTest(int sample_rate_hz) { |
| 27 std::unique_ptr<BlockProcessor> block_processor( |
| 28 BlockProcessor::Create(sample_rate_hz)); |
| 29 std::vector<std::vector<float>> block(NumBandsForRate(sample_rate_hz), |
| 30 std::vector<float>(kBlockSize, 0.f)); |
| 31 |
| 32 EXPECT_FALSE(block_processor->BufferRender(&block)); |
| 33 block_processor->ProcessCapture(false, false, &block); |
| 34 block_processor->ReportEchoLeakage(false); |
| 35 } |
| 36 |
| 37 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 38 void RunRenderBlockSizeVerificationTest(int sample_rate_hz) { |
| 39 std::unique_ptr<BlockProcessor> block_processor( |
| 40 BlockProcessor::Create(sample_rate_hz)); |
| 41 std::vector<std::vector<float>> block( |
| 42 NumBandsForRate(sample_rate_hz), std::vector<float>(kBlockSize - 1, 0.f)); |
| 43 |
| 44 EXPECT_DEATH(block_processor->BufferRender(&block), ""); |
| 45 } |
| 46 |
| 47 void RunCaptureBlockSizeVerificationTest(int sample_rate_hz) { |
| 48 std::unique_ptr<BlockProcessor> block_processor( |
| 49 BlockProcessor::Create(sample_rate_hz)); |
| 50 std::vector<std::vector<float>> block( |
| 51 NumBandsForRate(sample_rate_hz), std::vector<float>(kBlockSize - 1, 0.f)); |
| 52 |
| 53 EXPECT_DEATH(block_processor->ProcessCapture(false, false, &block), ""); |
| 54 } |
| 55 |
| 56 void RunRenderNumBandsVerificationTest(int sample_rate_hz) { |
| 57 const size_t wrong_num_bands = NumBandsForRate(sample_rate_hz) < 3 |
| 58 ? NumBandsForRate(sample_rate_hz) + 1 |
| 59 : 1; |
| 60 std::unique_ptr<BlockProcessor> block_processor( |
| 61 BlockProcessor::Create(sample_rate_hz)); |
| 62 std::vector<std::vector<float>> block(wrong_num_bands, |
| 63 std::vector<float>(kBlockSize, 0.f)); |
| 64 |
| 65 EXPECT_DEATH(block_processor->BufferRender(&block), ""); |
| 66 } |
| 67 |
| 68 void RunCaptureNumBandsVerificationTest(int sample_rate_hz) { |
| 69 const size_t wrong_num_bands = NumBandsForRate(sample_rate_hz) < 3 |
| 70 ? NumBandsForRate(sample_rate_hz) + 1 |
| 71 : 1; |
| 72 std::unique_ptr<BlockProcessor> block_processor( |
| 73 BlockProcessor::Create(sample_rate_hz)); |
| 74 std::vector<std::vector<float>> block(wrong_num_bands, |
| 75 std::vector<float>(kBlockSize, 0.f)); |
| 76 |
| 77 EXPECT_DEATH(block_processor->ProcessCapture(false, false, &block), ""); |
| 78 } |
| 79 #endif |
| 80 |
| 81 std::string ProduceDebugText(int sample_rate_hz) { |
| 82 std::ostringstream ss; |
| 83 ss << "Sample rate: " << sample_rate_hz; |
| 84 return ss.str(); |
| 85 } |
| 86 |
| 87 } // namespace |
| 88 |
| 89 TEST(BlockProcessor, BasicSetupAndApiCalls) { |
| 90 for (auto rate : {8000, 16000, 32000, 48000}) { |
| 91 SCOPED_TRACE(ProduceDebugText(rate)); |
| 92 RunBasicSetupAndApiCallTest(rate); |
| 93 } |
| 94 } |
| 95 |
| 96 #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 |
| 98 // has been reached on why they fail on the trybots. |
| 99 TEST(BlockProcessor, DISABLED_VerifyRenderBlockSizeCheck) { |
| 100 for (auto rate : {8000, 16000, 32000, 48000}) { |
| 101 SCOPED_TRACE(ProduceDebugText(rate)); |
| 102 RunRenderBlockSizeVerificationTest(rate); |
| 103 } |
| 104 } |
| 105 |
| 106 TEST(BlockProcessor, DISABLED_VerifyCaptureBlockSizeCheck) { |
| 107 for (auto rate : {8000, 16000, 32000, 48000}) { |
| 108 SCOPED_TRACE(ProduceDebugText(rate)); |
| 109 RunCaptureBlockSizeVerificationTest(rate); |
| 110 } |
| 111 } |
| 112 |
| 113 TEST(BlockProcessor, DISABLED_VerifyRenderNumBandsCheck) { |
| 114 for (auto rate : {8000, 16000, 32000, 48000}) { |
| 115 SCOPED_TRACE(ProduceDebugText(rate)); |
| 116 RunRenderNumBandsVerificationTest(rate); |
| 117 } |
| 118 } |
| 119 |
| 120 TEST(BlockProcessor, DISABLED_VerifyCaptureNumBandsCheck) { |
| 121 for (auto rate : {8000, 16000, 32000, 48000}) { |
| 122 SCOPED_TRACE(ProduceDebugText(rate)); |
| 123 RunCaptureNumBandsVerificationTest(rate); |
| 124 } |
| 125 } |
| 126 |
| 127 // Verifiers that the verification for null ProcessCapture input works. |
| 128 TEST(BlockProcessor, DISABLED_NullProcessCaptureParameter) { |
| 129 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) |
| 130 ->ProcessCapture(false, false, nullptr), |
| 131 ""); |
| 132 } |
| 133 |
| 134 // Verifiers that the verification for null BufferRender input works. |
| 135 TEST(BlockProcessor, DISABLED_NullBufferRenderParameter) { |
| 136 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) |
| 137 ->BufferRender(nullptr), |
| 138 ""); |
| 139 } |
| 140 |
| 141 #endif |
| 142 |
| 143 } // namespace webrtc |
OLD | NEW |