Chromium Code Reviews| 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 } // namespace | |
| 82 | |
| 83 TEST(BlockProcessor, BasicSetupAndApiCalls) { | |
| 84 for (auto rate : {8000, 16000, 32000, 48000}) { | |
| 85 std::ostringstream ss; | |
| 86 ss << "Sample rate: " << rate; | |
| 87 SCOPED_TRACE(ss.str()); | |
| 88 RunBasicSetupAndApiCallTest(rate); | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | |
| 93 TEST(BlockProcessor, VerifyRenderBlockSizeCheck) { | |
| 94 for (auto rate : {8000, 16000, 32000, 48000}) { | |
| 95 std::ostringstream ss; | |
|
hlundin-webrtc
2016/12/23 13:38:12
Breaks out this too.
peah-webrtc
2017/01/02 08:45:10
Done.
| |
| 96 ss << "Sample rate: " << rate; | |
| 97 SCOPED_TRACE(ss.str()); | |
| 98 RunRenderBlockSizeVerificationTest(rate); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 TEST(BlockProcessor, VerifyCaptureBlockSizeCheck) { | |
| 103 for (auto rate : {8000, 16000, 32000, 48000}) { | |
| 104 std::ostringstream ss; | |
| 105 ss << "Sample rate: " << rate; | |
| 106 SCOPED_TRACE(ss.str()); | |
| 107 RunCaptureBlockSizeVerificationTest(rate); | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 TEST(BlockProcessor, VerifyRenderNumBandsCheck) { | |
| 112 for (auto rate : {8000, 16000, 32000, 48000}) { | |
| 113 std::ostringstream ss; | |
| 114 ss << "Sample rate: " << rate; | |
| 115 SCOPED_TRACE(ss.str()); | |
| 116 RunRenderNumBandsVerificationTest(rate); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 TEST(BlockProcessor, VerifyCaptureNumBandsCheck) { | |
| 121 for (auto rate : {8000, 16000, 32000, 48000}) { | |
| 122 std::ostringstream ss; | |
| 123 ss << "Sample rate: " << rate; | |
| 124 SCOPED_TRACE(ss.str()); | |
| 125 RunCaptureNumBandsVerificationTest(rate); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 #endif | |
| 130 | |
| 131 } // namespace webrtc | |
| OLD | NEW |