blob: 92e393023a5913781918b318e5713294899cd3ba [file] [log] [blame]
peahd0263542017-01-03 04:20:34 -08001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/aec3/frame_blocker.h"
peahd0263542017-01-03 04:20:34 -080012
peahd0263542017-01-03 04:20:34 -080013#include <string>
14#include <vector>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/audio_processing/aec3/aec3_common.h"
17#include "modules/audio_processing/aec3/block_framer.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020018#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "test/gtest.h"
peahd0263542017-01-03 04:20:34 -080020
21namespace webrtc {
22namespace {
23
24float ComputeSampleValue(size_t chunk_counter,
25 size_t chunk_size,
26 size_t band,
Per Åhgrence202a02019-09-02 17:01:19 +020027 size_t channel,
peahd0263542017-01-03 04:20:34 -080028 size_t sample_index,
29 int offset) {
30 float value =
Per Åhgrence202a02019-09-02 17:01:19 +020031 static_cast<int>(chunk_counter * chunk_size + sample_index + channel) +
32 offset;
peahd0263542017-01-03 04:20:34 -080033 return value > 0 ? 5000 * band + value : 0;
34}
35
36void FillSubFrame(size_t sub_frame_counter,
37 int offset,
Per Åhgrence202a02019-09-02 17:01:19 +020038 std::vector<std::vector<std::vector<float>>>* sub_frame) {
39 for (size_t band = 0; band < sub_frame->size(); ++band) {
40 for (size_t channel = 0; channel < (*sub_frame)[band].size(); ++channel) {
41 for (size_t sample = 0; sample < (*sub_frame)[band][channel].size();
42 ++sample) {
43 (*sub_frame)[band][channel][sample] = ComputeSampleValue(
44 sub_frame_counter, kSubFrameLength, band, channel, sample, offset);
45 }
peahd0263542017-01-03 04:20:34 -080046 }
47 }
48}
49
Per Åhgrence202a02019-09-02 17:01:19 +020050void FillSubFrameView(
51 size_t sub_frame_counter,
52 int offset,
53 std::vector<std::vector<std::vector<float>>>* sub_frame,
54 std::vector<std::vector<rtc::ArrayView<float>>>* sub_frame_view) {
peahd0263542017-01-03 04:20:34 -080055 FillSubFrame(sub_frame_counter, offset, sub_frame);
Per Åhgrence202a02019-09-02 17:01:19 +020056 for (size_t band = 0; band < sub_frame_view->size(); ++band) {
57 for (size_t channel = 0; channel < (*sub_frame_view)[band].size();
58 ++channel) {
59 (*sub_frame_view)[band][channel] = rtc::ArrayView<float>(
60 &(*sub_frame)[band][channel][0], (*sub_frame)[band][channel].size());
61 }
peahd0263542017-01-03 04:20:34 -080062 }
63}
64
Per Åhgrence202a02019-09-02 17:01:19 +020065bool VerifySubFrame(
66 size_t sub_frame_counter,
67 int offset,
68 const std::vector<std::vector<rtc::ArrayView<float>>>& sub_frame_view) {
69 std::vector<std::vector<std::vector<float>>> reference_sub_frame(
70 sub_frame_view.size(),
71 std::vector<std::vector<float>>(
72 sub_frame_view[0].size(),
73 std::vector<float>(sub_frame_view[0][0].size(), 0.f)));
peahd0263542017-01-03 04:20:34 -080074 FillSubFrame(sub_frame_counter, offset, &reference_sub_frame);
Per Åhgrence202a02019-09-02 17:01:19 +020075 for (size_t band = 0; band < sub_frame_view.size(); ++band) {
76 for (size_t channel = 0; channel < sub_frame_view[band].size(); ++channel) {
77 for (size_t sample = 0; sample < sub_frame_view[band][channel].size();
78 ++sample) {
79 if (reference_sub_frame[band][channel][sample] !=
80 sub_frame_view[band][channel][sample]) {
81 return false;
82 }
peahd0263542017-01-03 04:20:34 -080083 }
84 }
85 }
86 return true;
87}
88
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +020089bool VerifyBlock(size_t block_counter, int offset, const Block& block) {
90 for (int band = 0; band < block.NumBands(); ++band) {
91 for (int channel = 0; channel < block.NumChannels(); ++channel) {
92 for (size_t sample = 0; sample < kBlockSize; ++sample) {
93 auto it = block.begin(band, channel) + sample;
Per Åhgrence202a02019-09-02 17:01:19 +020094 const float reference_value = ComputeSampleValue(
95 block_counter, kBlockSize, band, channel, sample, offset);
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +020096 if (reference_value != *it) {
Per Åhgrence202a02019-09-02 17:01:19 +020097 return false;
98 }
peahd0263542017-01-03 04:20:34 -080099 }
100 }
101 }
102 return true;
103}
104
105// Verifies that the FrameBlocker properly forms blocks out of the frames.
Per Åhgrence202a02019-09-02 17:01:19 +0200106void RunBlockerTest(int sample_rate_hz, size_t num_channels) {
peahd0263542017-01-03 04:20:34 -0800107 constexpr size_t kNumSubFramesToProcess = 20;
108 const size_t num_bands = NumBandsForRate(sample_rate_hz);
109
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200110 Block block(num_bands, num_channels);
Per Åhgrence202a02019-09-02 17:01:19 +0200111 std::vector<std::vector<std::vector<float>>> input_sub_frame(
112 num_bands, std::vector<std::vector<float>>(
113 num_channels, std::vector<float>(kSubFrameLength, 0.f)));
114 std::vector<std::vector<rtc::ArrayView<float>>> input_sub_frame_view(
115 num_bands, std::vector<rtc::ArrayView<float>>(num_channels));
116 FrameBlocker blocker(num_bands, num_channels);
peahd0263542017-01-03 04:20:34 -0800117
118 size_t block_counter = 0;
119 for (size_t sub_frame_index = 0; sub_frame_index < kNumSubFramesToProcess;
120 ++sub_frame_index) {
121 FillSubFrameView(sub_frame_index, 0, &input_sub_frame,
122 &input_sub_frame_view);
123
124 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &block);
125 VerifyBlock(block_counter++, 0, block);
126
127 if ((sub_frame_index + 1) % 4 == 0) {
128 EXPECT_TRUE(blocker.IsBlockAvailable());
129 } else {
130 EXPECT_FALSE(blocker.IsBlockAvailable());
131 }
132 if (blocker.IsBlockAvailable()) {
133 blocker.ExtractBlock(&block);
134 VerifyBlock(block_counter++, 0, block);
135 }
136 }
137}
138
139// Verifies that the FrameBlocker and BlockFramer work well together and produce
140// the expected output.
Per Åhgrence202a02019-09-02 17:01:19 +0200141void RunBlockerAndFramerTest(int sample_rate_hz, size_t num_channels) {
peahd0263542017-01-03 04:20:34 -0800142 const size_t kNumSubFramesToProcess = 20;
143 const size_t num_bands = NumBandsForRate(sample_rate_hz);
144
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200145 Block block(num_bands, num_channels);
Per Åhgrence202a02019-09-02 17:01:19 +0200146 std::vector<std::vector<std::vector<float>>> input_sub_frame(
147 num_bands, std::vector<std::vector<float>>(
148 num_channels, std::vector<float>(kSubFrameLength, 0.f)));
149 std::vector<std::vector<std::vector<float>>> output_sub_frame(
150 num_bands, std::vector<std::vector<float>>(
151 num_channels, std::vector<float>(kSubFrameLength, 0.f)));
152 std::vector<std::vector<rtc::ArrayView<float>>> output_sub_frame_view(
153 num_bands, std::vector<rtc::ArrayView<float>>(num_channels));
154 std::vector<std::vector<rtc::ArrayView<float>>> input_sub_frame_view(
155 num_bands, std::vector<rtc::ArrayView<float>>(num_channels));
156 FrameBlocker blocker(num_bands, num_channels);
157 BlockFramer framer(num_bands, num_channels);
peahd0263542017-01-03 04:20:34 -0800158
159 for (size_t sub_frame_index = 0; sub_frame_index < kNumSubFramesToProcess;
160 ++sub_frame_index) {
161 FillSubFrameView(sub_frame_index, 0, &input_sub_frame,
162 &input_sub_frame_view);
163 FillSubFrameView(sub_frame_index, 0, &output_sub_frame,
164 &output_sub_frame_view);
165
166 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &block);
167 framer.InsertBlockAndExtractSubFrame(block, &output_sub_frame_view);
168
169 if ((sub_frame_index + 1) % 4 == 0) {
170 EXPECT_TRUE(blocker.IsBlockAvailable());
171 } else {
172 EXPECT_FALSE(blocker.IsBlockAvailable());
173 }
174 if (blocker.IsBlockAvailable()) {
175 blocker.ExtractBlock(&block);
176 framer.InsertBlock(block);
177 }
Per Åhgrence202a02019-09-02 17:01:19 +0200178 if (sub_frame_index > 1) {
179 EXPECT_TRUE(VerifySubFrame(sub_frame_index, -64, output_sub_frame_view));
180 }
peahd0263542017-01-03 04:20:34 -0800181 }
182}
183
184#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
185// Verifies that the FrameBlocker crashes if the InsertSubFrameAndExtractBlock
186// method is called for inputs with the wrong number of bands or band lengths.
Per Åhgrence202a02019-09-02 17:01:19 +0200187void RunWronglySizedInsertAndExtractParametersTest(
188 int sample_rate_hz,
189 size_t correct_num_channels,
190 size_t num_block_bands,
191 size_t num_block_channels,
Per Åhgrence202a02019-09-02 17:01:19 +0200192 size_t num_sub_frame_bands,
193 size_t num_sub_frame_channels,
194 size_t sub_frame_length) {
peahd0263542017-01-03 04:20:34 -0800195 const size_t correct_num_bands = NumBandsForRate(sample_rate_hz);
196
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200197 Block block(num_block_bands, num_block_channels);
Per Åhgrence202a02019-09-02 17:01:19 +0200198 std::vector<std::vector<std::vector<float>>> input_sub_frame(
199 num_sub_frame_bands,
200 std::vector<std::vector<float>>(
201 num_sub_frame_channels, std::vector<float>(sub_frame_length, 0.f)));
202 std::vector<std::vector<rtc::ArrayView<float>>> input_sub_frame_view(
203 input_sub_frame.size(),
204 std::vector<rtc::ArrayView<float>>(num_sub_frame_channels));
peahd0263542017-01-03 04:20:34 -0800205 FillSubFrameView(0, 0, &input_sub_frame, &input_sub_frame_view);
Per Åhgrence202a02019-09-02 17:01:19 +0200206 FrameBlocker blocker(correct_num_bands, correct_num_channels);
peahd0263542017-01-03 04:20:34 -0800207 EXPECT_DEATH(
208 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &block), "");
209}
210
211// Verifies that the FrameBlocker crashes if the ExtractBlock method is called
212// for inputs with the wrong number of bands or band lengths.
213void RunWronglySizedExtractParameterTest(int sample_rate_hz,
Per Åhgrence202a02019-09-02 17:01:19 +0200214 size_t correct_num_channels,
peahd0263542017-01-03 04:20:34 -0800215 size_t num_block_bands,
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200216 size_t num_block_channels) {
peahd0263542017-01-03 04:20:34 -0800217 const size_t correct_num_bands = NumBandsForRate(sample_rate_hz);
218
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200219 Block correct_block(correct_num_bands, correct_num_channels);
220 Block wrong_block(num_block_bands, num_block_channels);
Per Åhgrence202a02019-09-02 17:01:19 +0200221 std::vector<std::vector<std::vector<float>>> input_sub_frame(
222 correct_num_bands,
223 std::vector<std::vector<float>>(
224 correct_num_channels, std::vector<float>(kSubFrameLength, 0.f)));
225 std::vector<std::vector<rtc::ArrayView<float>>> input_sub_frame_view(
226 input_sub_frame.size(),
227 std::vector<rtc::ArrayView<float>>(correct_num_channels));
peahd0263542017-01-03 04:20:34 -0800228 FillSubFrameView(0, 0, &input_sub_frame, &input_sub_frame_view);
Per Åhgrence202a02019-09-02 17:01:19 +0200229 FrameBlocker blocker(correct_num_bands, correct_num_channels);
peahd0263542017-01-03 04:20:34 -0800230 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &correct_block);
231 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &correct_block);
232 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &correct_block);
233 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &correct_block);
234
235 EXPECT_DEATH(blocker.ExtractBlock(&wrong_block), "");
236}
237
238// Verifies that the FrameBlocker crashes if the ExtractBlock method is called
239// after a wrong number of previous InsertSubFrameAndExtractBlock method calls
240// have been made.
241void RunWrongExtractOrderTest(int sample_rate_hz,
Per Åhgrence202a02019-09-02 17:01:19 +0200242 size_t num_channels,
peahd0263542017-01-03 04:20:34 -0800243 size_t num_preceeding_api_calls) {
Per Åhgrence202a02019-09-02 17:01:19 +0200244 const size_t num_bands = NumBandsForRate(sample_rate_hz);
peahd0263542017-01-03 04:20:34 -0800245
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200246 Block block(num_bands, num_channels);
Per Åhgrence202a02019-09-02 17:01:19 +0200247 std::vector<std::vector<std::vector<float>>> input_sub_frame(
248 num_bands, std::vector<std::vector<float>>(
249 num_channels, std::vector<float>(kSubFrameLength, 0.f)));
250 std::vector<std::vector<rtc::ArrayView<float>>> input_sub_frame_view(
251 input_sub_frame.size(), std::vector<rtc::ArrayView<float>>(num_channels));
peahd0263542017-01-03 04:20:34 -0800252 FillSubFrameView(0, 0, &input_sub_frame, &input_sub_frame_view);
Per Åhgrence202a02019-09-02 17:01:19 +0200253 FrameBlocker blocker(num_bands, num_channels);
peahd0263542017-01-03 04:20:34 -0800254 for (size_t k = 0; k < num_preceeding_api_calls; ++k) {
255 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &block);
256 }
257
258 EXPECT_DEATH(blocker.ExtractBlock(&block), "");
259}
260#endif
261
Per Åhgrence202a02019-09-02 17:01:19 +0200262std::string ProduceDebugText(int sample_rate_hz, size_t num_channels) {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200263 rtc::StringBuilder ss;
peahd0263542017-01-03 04:20:34 -0800264 ss << "Sample rate: " << sample_rate_hz;
Per Åhgrence202a02019-09-02 17:01:19 +0200265 ss << ", number of channels: " << num_channels;
Jonas Olsson84df1c72018-09-14 16:59:32 +0200266 return ss.Release();
peahd0263542017-01-03 04:20:34 -0800267}
268
269} // namespace
270
271#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
Tommi909f3a52020-05-18 16:47:56 +0200272TEST(FrameBlockerDeathTest,
273 WrongNumberOfBandsInBlockForInsertSubFrameAndExtractBlock) {
Per Åhgrence202a02019-09-02 17:01:19 +0200274 for (auto rate : {16000, 32000, 48000}) {
275 for (size_t correct_num_channels : {1, 2, 4, 8}) {
276 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
277 const size_t correct_num_bands = NumBandsForRate(rate);
278 const size_t wrong_num_bands = (correct_num_bands % 3) + 1;
279 RunWronglySizedInsertAndExtractParametersTest(
280 rate, correct_num_channels, wrong_num_bands, correct_num_channels,
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200281 correct_num_bands, correct_num_channels, kSubFrameLength);
Per Åhgrence202a02019-09-02 17:01:19 +0200282 }
283 }
284}
285
Tommi909f3a52020-05-18 16:47:56 +0200286TEST(FrameBlockerDeathTest,
Per Åhgrence202a02019-09-02 17:01:19 +0200287 WrongNumberOfChannelsInBlockForInsertSubFrameAndExtractBlock) {
288 for (auto rate : {16000, 32000, 48000}) {
289 for (size_t correct_num_channels : {1, 2, 4, 8}) {
290 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
291 const size_t correct_num_bands = NumBandsForRate(rate);
292 const size_t wrong_num_channels = correct_num_channels + 1;
293 RunWronglySizedInsertAndExtractParametersTest(
294 rate, correct_num_channels, correct_num_bands, wrong_num_channels,
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200295 correct_num_bands, correct_num_channels, kSubFrameLength);
Per Åhgrence202a02019-09-02 17:01:19 +0200296 }
peahd0263542017-01-03 04:20:34 -0800297 }
298}
299
Tommi909f3a52020-05-18 16:47:56 +0200300TEST(FrameBlockerDeathTest,
peahd0263542017-01-03 04:20:34 -0800301 WrongNumberOfBandsInSubFrameForInsertSubFrameAndExtractBlock) {
Per Åhgrence202a02019-09-02 17:01:19 +0200302 for (auto rate : {16000, 32000, 48000}) {
303 for (size_t correct_num_channels : {1, 2, 4, 8}) {
304 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
305 const size_t correct_num_bands = NumBandsForRate(rate);
306 const size_t wrong_num_bands = (correct_num_bands % 3) + 1;
307 RunWronglySizedInsertAndExtractParametersTest(
308 rate, correct_num_channels, correct_num_bands, correct_num_channels,
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200309 wrong_num_bands, correct_num_channels, kSubFrameLength);
Per Åhgrence202a02019-09-02 17:01:19 +0200310 }
311 }
312}
313
Tommi909f3a52020-05-18 16:47:56 +0200314TEST(FrameBlockerDeathTest,
Per Åhgrence202a02019-09-02 17:01:19 +0200315 WrongNumberOfChannelsInSubFrameForInsertSubFrameAndExtractBlock) {
316 for (auto rate : {16000, 32000, 48000}) {
317 for (size_t correct_num_channels : {1, 2, 4, 8}) {
318 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
319 const size_t correct_num_bands = NumBandsForRate(rate);
320 const size_t wrong_num_channels = correct_num_channels + 1;
321 RunWronglySizedInsertAndExtractParametersTest(
322 rate, correct_num_channels, correct_num_bands, wrong_num_channels,
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200323 correct_num_bands, wrong_num_channels, kSubFrameLength);
Per Åhgrence202a02019-09-02 17:01:19 +0200324 }
peahd0263542017-01-03 04:20:34 -0800325 }
326}
327
Tommi909f3a52020-05-18 16:47:56 +0200328TEST(FrameBlockerDeathTest,
peahd0263542017-01-03 04:20:34 -0800329 WrongNumberOfSamplesInSubFrameForInsertSubFrameAndExtractBlock) {
Per Åhgrence202a02019-09-02 17:01:19 +0200330 for (auto rate : {16000, 32000, 48000}) {
331 for (size_t correct_num_channels : {1, 2, 4, 8}) {
332 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
333 const size_t correct_num_bands = NumBandsForRate(rate);
334 RunWronglySizedInsertAndExtractParametersTest(
335 rate, correct_num_channels, correct_num_bands, correct_num_channels,
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200336 correct_num_bands, correct_num_channels, kSubFrameLength - 1);
Per Åhgrena66395e2019-08-30 08:54:09 +0200337 }
338 }
339}
340
Tommi909f3a52020-05-18 16:47:56 +0200341TEST(FrameBlockerDeathTest, WrongNumberOfBandsInBlockForExtractBlock) {
Per Åhgrence202a02019-09-02 17:01:19 +0200342 for (auto rate : {16000, 32000, 48000}) {
343 for (size_t correct_num_channels : {1, 2, 4, 8}) {
344 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
345 const size_t correct_num_bands = NumBandsForRate(rate);
346 const size_t wrong_num_bands = (correct_num_bands % 3) + 1;
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200347 RunWronglySizedExtractParameterTest(
348 rate, correct_num_channels, wrong_num_bands, correct_num_channels);
Per Åhgrence202a02019-09-02 17:01:19 +0200349 }
350 }
351}
352
Tommi909f3a52020-05-18 16:47:56 +0200353TEST(FrameBlockerDeathTest, WrongNumberOfChannelsInBlockForExtractBlock) {
Per Åhgrence202a02019-09-02 17:01:19 +0200354 for (auto rate : {16000, 32000, 48000}) {
355 for (size_t correct_num_channels : {1, 2, 4, 8}) {
356 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
357 const size_t correct_num_bands = NumBandsForRate(rate);
358 const size_t wrong_num_channels = correct_num_channels + 1;
Gustaf Ullbergd3ead1a2022-05-23 10:39:53 +0200359 RunWronglySizedExtractParameterTest(
360 rate, correct_num_channels, correct_num_bands, wrong_num_channels);
Per Åhgrence202a02019-09-02 17:01:19 +0200361 }
362 }
363}
364
Tommi909f3a52020-05-18 16:47:56 +0200365TEST(FrameBlockerDeathTest, WrongNumberOfPreceedingApiCallsForExtractBlock) {
Per Åhgrence202a02019-09-02 17:01:19 +0200366 for (auto rate : {16000, 32000, 48000}) {
367 for (size_t num_channels : {1, 2, 4, 8}) {
368 for (size_t num_calls = 0; num_calls < 4; ++num_calls) {
369 rtc::StringBuilder ss;
370 ss << "Sample rate: " << rate;
371 ss << "Num channels: " << num_channels;
372 ss << ", Num preceeding InsertSubFrameAndExtractBlock calls: "
373 << num_calls;
374
375 SCOPED_TRACE(ss.str());
376 RunWrongExtractOrderTest(rate, num_channels, num_calls);
377 }
378 }
379 }
380}
381
382// Verifies that the verification for 0 number of channels works.
Tommi909f3a52020-05-18 16:47:56 +0200383TEST(FrameBlockerDeathTest, ZeroNumberOfChannelsParameter) {
Per Åhgrence202a02019-09-02 17:01:19 +0200384 EXPECT_DEATH(FrameBlocker(16000, 0), "");
385}
386
387// Verifies that the verification for 0 number of bands works.
Tommi909f3a52020-05-18 16:47:56 +0200388TEST(FrameBlockerDeathTest, ZeroNumberOfBandsParameter) {
Per Åhgrence202a02019-09-02 17:01:19 +0200389 EXPECT_DEATH(FrameBlocker(0, 1), "");
390}
391
peahd0263542017-01-03 04:20:34 -0800392// Verifiers that the verification for null sub_frame pointer works.
Tommi909f3a52020-05-18 16:47:56 +0200393TEST(FrameBlockerDeathTest, NullBlockParameter) {
Per Åhgrence202a02019-09-02 17:01:19 +0200394 std::vector<std::vector<std::vector<float>>> sub_frame(
395 1, std::vector<std::vector<float>>(
396 1, std::vector<float>(kSubFrameLength, 0.f)));
397 std::vector<std::vector<rtc::ArrayView<float>>> sub_frame_view(
398 sub_frame.size());
peahd0263542017-01-03 04:20:34 -0800399 FillSubFrameView(0, 0, &sub_frame, &sub_frame_view);
400 EXPECT_DEATH(
Per Åhgrence202a02019-09-02 17:01:19 +0200401 FrameBlocker(1, 1).InsertSubFrameAndExtractBlock(sub_frame_view, nullptr),
peahd0263542017-01-03 04:20:34 -0800402 "");
403}
404
405#endif
406
407TEST(FrameBlocker, BlockBitexactness) {
Per Åhgrence202a02019-09-02 17:01:19 +0200408 for (auto rate : {16000, 32000, 48000}) {
409 for (size_t num_channels : {1, 2, 4, 8}) {
410 SCOPED_TRACE(ProduceDebugText(rate, num_channels));
411 RunBlockerTest(rate, num_channels);
412 }
peahd0263542017-01-03 04:20:34 -0800413 }
414}
415
416TEST(FrameBlocker, BlockerAndFramer) {
Per Åhgrence202a02019-09-02 17:01:19 +0200417 for (auto rate : {16000, 32000, 48000}) {
418 for (size_t num_channels : {1, 2, 4, 8}) {
419 SCOPED_TRACE(ProduceDebugText(rate, num_channels));
420 RunBlockerAndFramerTest(rate, num_channels);
421 }
peahd0263542017-01-03 04:20:34 -0800422 }
423}
424
425} // namespace webrtc