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 TEST(BlockProcessor, VerifyRenderBlockSizeCheck) { | |
98 for (auto rate : {8000, 16000, 32000, 48000}) { | |
99 SCOPED_TRACE(ProduceDebugText(rate)); | |
100 RunRenderBlockSizeVerificationTest(rate); | |
101 } | |
102 } | |
103 | |
104 TEST(BlockProcessor, VerifyCaptureBlockSizeCheck) { | |
105 for (auto rate : {8000, 16000, 32000, 48000}) { | |
106 SCOPED_TRACE(ProduceDebugText(rate)); | |
107 RunCaptureBlockSizeVerificationTest(rate); | |
108 } | |
109 } | |
110 | |
111 TEST(BlockProcessor, VerifyRenderNumBandsCheck) { | |
112 for (auto rate : {8000, 16000, 32000, 48000}) { | |
113 SCOPED_TRACE(ProduceDebugText(rate)); | |
114 RunRenderNumBandsVerificationTest(rate); | |
115 } | |
116 } | |
117 | |
118 TEST(BlockProcessor, VerifyCaptureNumBandsCheck) { | |
119 for (auto rate : {8000, 16000, 32000, 48000}) { | |
120 SCOPED_TRACE(ProduceDebugText(rate)); | |
121 RunCaptureNumBandsVerificationTest(rate); | |
122 } | |
123 } | |
124 | |
125 // Verifiers that the verification for null ProcessCapture input works. | |
126 TEST(BlockProcessor, NullProcessCaptureParameter) { | |
127 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) | |
128 ->ProcessCapture(false, false, nullptr), | |
129 ""); | |
130 } | |
131 | |
132 // Verifiers that the verification for null BufferRender input works. | |
133 TEST(BlockProcessor, NullBufferRenderParameter) { | |
134 EXPECT_DEATH(std::unique_ptr<BlockProcessor>(BlockProcessor::Create(8000)) | |
135 ->BufferRender(nullptr), | |
136 ""); | |
137 } | |
138 | |
139 #endif | |
140 | |
141 } // namespace webrtc | |
OLD | NEW |