blob: e907608d95f566442b58f59fd7d9751bf4901fd5 [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
89bool VerifyBlock(size_t block_counter,
90 int offset,
Per Åhgrence202a02019-09-02 17:01:19 +020091 const std::vector<std::vector<std::vector<float>>>& block) {
92 for (size_t band = 0; band < block.size(); ++band) {
93 for (size_t channel = 0; channel < block[band].size(); ++channel) {
94 for (size_t sample = 0; sample < block[band][channel].size(); ++sample) {
95 const float reference_value = ComputeSampleValue(
96 block_counter, kBlockSize, band, channel, sample, offset);
97 if (reference_value != block[band][channel][sample]) {
98 return false;
99 }
peahd0263542017-01-03 04:20:34 -0800100 }
101 }
102 }
103 return true;
104}
105
106// Verifies that the FrameBlocker properly forms blocks out of the frames.
Per Åhgrence202a02019-09-02 17:01:19 +0200107void RunBlockerTest(int sample_rate_hz, size_t num_channels) {
peahd0263542017-01-03 04:20:34 -0800108 constexpr size_t kNumSubFramesToProcess = 20;
109 const size_t num_bands = NumBandsForRate(sample_rate_hz);
110
Per Åhgrence202a02019-09-02 17:01:19 +0200111 std::vector<std::vector<std::vector<float>>> block(
112 num_bands, std::vector<std::vector<float>>(
113 num_channels, std::vector<float>(kBlockSize, 0.f)));
114 std::vector<std::vector<std::vector<float>>> input_sub_frame(
115 num_bands, std::vector<std::vector<float>>(
116 num_channels, std::vector<float>(kSubFrameLength, 0.f)));
117 std::vector<std::vector<rtc::ArrayView<float>>> input_sub_frame_view(
118 num_bands, std::vector<rtc::ArrayView<float>>(num_channels));
119 FrameBlocker blocker(num_bands, num_channels);
peahd0263542017-01-03 04:20:34 -0800120
121 size_t block_counter = 0;
122 for (size_t sub_frame_index = 0; sub_frame_index < kNumSubFramesToProcess;
123 ++sub_frame_index) {
124 FillSubFrameView(sub_frame_index, 0, &input_sub_frame,
125 &input_sub_frame_view);
126
127 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &block);
128 VerifyBlock(block_counter++, 0, block);
129
130 if ((sub_frame_index + 1) % 4 == 0) {
131 EXPECT_TRUE(blocker.IsBlockAvailable());
132 } else {
133 EXPECT_FALSE(blocker.IsBlockAvailable());
134 }
135 if (blocker.IsBlockAvailable()) {
136 blocker.ExtractBlock(&block);
137 VerifyBlock(block_counter++, 0, block);
138 }
139 }
140}
141
142// Verifies that the FrameBlocker and BlockFramer work well together and produce
143// the expected output.
Per Åhgrence202a02019-09-02 17:01:19 +0200144void RunBlockerAndFramerTest(int sample_rate_hz, size_t num_channels) {
peahd0263542017-01-03 04:20:34 -0800145 const size_t kNumSubFramesToProcess = 20;
146 const size_t num_bands = NumBandsForRate(sample_rate_hz);
147
Per Åhgrence202a02019-09-02 17:01:19 +0200148 std::vector<std::vector<std::vector<float>>> block(
149 num_bands, std::vector<std::vector<float>>(
150 num_channels, std::vector<float>(kBlockSize, 0.f)));
151 std::vector<std::vector<std::vector<float>>> input_sub_frame(
152 num_bands, std::vector<std::vector<float>>(
153 num_channels, std::vector<float>(kSubFrameLength, 0.f)));
154 std::vector<std::vector<std::vector<float>>> output_sub_frame(
155 num_bands, std::vector<std::vector<float>>(
156 num_channels, std::vector<float>(kSubFrameLength, 0.f)));
157 std::vector<std::vector<rtc::ArrayView<float>>> output_sub_frame_view(
158 num_bands, std::vector<rtc::ArrayView<float>>(num_channels));
159 std::vector<std::vector<rtc::ArrayView<float>>> input_sub_frame_view(
160 num_bands, std::vector<rtc::ArrayView<float>>(num_channels));
161 FrameBlocker blocker(num_bands, num_channels);
162 BlockFramer framer(num_bands, num_channels);
peahd0263542017-01-03 04:20:34 -0800163
164 for (size_t sub_frame_index = 0; sub_frame_index < kNumSubFramesToProcess;
165 ++sub_frame_index) {
166 FillSubFrameView(sub_frame_index, 0, &input_sub_frame,
167 &input_sub_frame_view);
168 FillSubFrameView(sub_frame_index, 0, &output_sub_frame,
169 &output_sub_frame_view);
170
171 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &block);
172 framer.InsertBlockAndExtractSubFrame(block, &output_sub_frame_view);
173
174 if ((sub_frame_index + 1) % 4 == 0) {
175 EXPECT_TRUE(blocker.IsBlockAvailable());
176 } else {
177 EXPECT_FALSE(blocker.IsBlockAvailable());
178 }
179 if (blocker.IsBlockAvailable()) {
180 blocker.ExtractBlock(&block);
181 framer.InsertBlock(block);
182 }
Per Åhgrence202a02019-09-02 17:01:19 +0200183 if (sub_frame_index > 1) {
184 EXPECT_TRUE(VerifySubFrame(sub_frame_index, -64, output_sub_frame_view));
185 }
peahd0263542017-01-03 04:20:34 -0800186 }
187}
188
189#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
190// Verifies that the FrameBlocker crashes if the InsertSubFrameAndExtractBlock
191// method is called for inputs with the wrong number of bands or band lengths.
Per Åhgrence202a02019-09-02 17:01:19 +0200192void RunWronglySizedInsertAndExtractParametersTest(
193 int sample_rate_hz,
194 size_t correct_num_channels,
195 size_t num_block_bands,
196 size_t num_block_channels,
197 size_t block_length,
198 size_t num_sub_frame_bands,
199 size_t num_sub_frame_channels,
200 size_t sub_frame_length) {
peahd0263542017-01-03 04:20:34 -0800201 const size_t correct_num_bands = NumBandsForRate(sample_rate_hz);
202
Per Åhgrence202a02019-09-02 17:01:19 +0200203 std::vector<std::vector<std::vector<float>>> block(
204 num_block_bands,
205 std::vector<std::vector<float>>(num_block_channels,
206 std::vector<float>(block_length, 0.f)));
207 std::vector<std::vector<std::vector<float>>> input_sub_frame(
208 num_sub_frame_bands,
209 std::vector<std::vector<float>>(
210 num_sub_frame_channels, std::vector<float>(sub_frame_length, 0.f)));
211 std::vector<std::vector<rtc::ArrayView<float>>> input_sub_frame_view(
212 input_sub_frame.size(),
213 std::vector<rtc::ArrayView<float>>(num_sub_frame_channels));
peahd0263542017-01-03 04:20:34 -0800214 FillSubFrameView(0, 0, &input_sub_frame, &input_sub_frame_view);
Per Åhgrence202a02019-09-02 17:01:19 +0200215 FrameBlocker blocker(correct_num_bands, correct_num_channels);
peahd0263542017-01-03 04:20:34 -0800216 EXPECT_DEATH(
217 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &block), "");
218}
219
220// Verifies that the FrameBlocker crashes if the ExtractBlock method is called
221// for inputs with the wrong number of bands or band lengths.
222void RunWronglySizedExtractParameterTest(int sample_rate_hz,
Per Åhgrence202a02019-09-02 17:01:19 +0200223 size_t correct_num_channels,
peahd0263542017-01-03 04:20:34 -0800224 size_t num_block_bands,
Per Åhgrence202a02019-09-02 17:01:19 +0200225 size_t num_block_channels,
peahd0263542017-01-03 04:20:34 -0800226 size_t block_length) {
227 const size_t correct_num_bands = NumBandsForRate(sample_rate_hz);
228
Per Åhgrence202a02019-09-02 17:01:19 +0200229 std::vector<std::vector<std::vector<float>>> correct_block(
230 correct_num_bands,
231 std::vector<std::vector<float>>(correct_num_channels,
232 std::vector<float>(kBlockSize, 0.f)));
233 std::vector<std::vector<std::vector<float>>> wrong_block(
234 num_block_bands,
235 std::vector<std::vector<float>>(num_block_channels,
236 std::vector<float>(block_length, 0.f)));
237 std::vector<std::vector<std::vector<float>>> input_sub_frame(
238 correct_num_bands,
239 std::vector<std::vector<float>>(
240 correct_num_channels, std::vector<float>(kSubFrameLength, 0.f)));
241 std::vector<std::vector<rtc::ArrayView<float>>> input_sub_frame_view(
242 input_sub_frame.size(),
243 std::vector<rtc::ArrayView<float>>(correct_num_channels));
peahd0263542017-01-03 04:20:34 -0800244 FillSubFrameView(0, 0, &input_sub_frame, &input_sub_frame_view);
Per Åhgrence202a02019-09-02 17:01:19 +0200245 FrameBlocker blocker(correct_num_bands, correct_num_channels);
peahd0263542017-01-03 04:20:34 -0800246 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &correct_block);
247 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &correct_block);
248 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &correct_block);
249 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &correct_block);
250
251 EXPECT_DEATH(blocker.ExtractBlock(&wrong_block), "");
252}
253
254// Verifies that the FrameBlocker crashes if the ExtractBlock method is called
255// after a wrong number of previous InsertSubFrameAndExtractBlock method calls
256// have been made.
257void RunWrongExtractOrderTest(int sample_rate_hz,
Per Åhgrence202a02019-09-02 17:01:19 +0200258 size_t num_channels,
peahd0263542017-01-03 04:20:34 -0800259 size_t num_preceeding_api_calls) {
Per Åhgrence202a02019-09-02 17:01:19 +0200260 const size_t num_bands = NumBandsForRate(sample_rate_hz);
peahd0263542017-01-03 04:20:34 -0800261
Per Åhgrence202a02019-09-02 17:01:19 +0200262 std::vector<std::vector<std::vector<float>>> block(
263 num_bands, std::vector<std::vector<float>>(
264 num_channels, std::vector<float>(kBlockSize, 0.f)));
265 std::vector<std::vector<std::vector<float>>> input_sub_frame(
266 num_bands, std::vector<std::vector<float>>(
267 num_channels, std::vector<float>(kSubFrameLength, 0.f)));
268 std::vector<std::vector<rtc::ArrayView<float>>> input_sub_frame_view(
269 input_sub_frame.size(), std::vector<rtc::ArrayView<float>>(num_channels));
peahd0263542017-01-03 04:20:34 -0800270 FillSubFrameView(0, 0, &input_sub_frame, &input_sub_frame_view);
Per Åhgrence202a02019-09-02 17:01:19 +0200271 FrameBlocker blocker(num_bands, num_channels);
peahd0263542017-01-03 04:20:34 -0800272 for (size_t k = 0; k < num_preceeding_api_calls; ++k) {
273 blocker.InsertSubFrameAndExtractBlock(input_sub_frame_view, &block);
274 }
275
276 EXPECT_DEATH(blocker.ExtractBlock(&block), "");
277}
278#endif
279
Per Åhgrence202a02019-09-02 17:01:19 +0200280std::string ProduceDebugText(int sample_rate_hz, size_t num_channels) {
Jonas Olsson366a50c2018-09-06 13:41:30 +0200281 rtc::StringBuilder ss;
peahd0263542017-01-03 04:20:34 -0800282 ss << "Sample rate: " << sample_rate_hz;
Per Åhgrence202a02019-09-02 17:01:19 +0200283 ss << ", number of channels: " << num_channels;
Jonas Olsson84df1c72018-09-14 16:59:32 +0200284 return ss.Release();
peahd0263542017-01-03 04:20:34 -0800285}
286
287} // namespace
288
289#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
290TEST(FrameBlocker, WrongNumberOfBandsInBlockForInsertSubFrameAndExtractBlock) {
Per Åhgrence202a02019-09-02 17:01:19 +0200291 for (auto rate : {16000, 32000, 48000}) {
292 for (size_t correct_num_channels : {1, 2, 4, 8}) {
293 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
294 const size_t correct_num_bands = NumBandsForRate(rate);
295 const size_t wrong_num_bands = (correct_num_bands % 3) + 1;
296 RunWronglySizedInsertAndExtractParametersTest(
297 rate, correct_num_channels, wrong_num_bands, correct_num_channels,
298 kBlockSize, correct_num_bands, correct_num_channels, kSubFrameLength);
299 }
300 }
301}
302
303TEST(FrameBlocker,
304 WrongNumberOfChannelsInBlockForInsertSubFrameAndExtractBlock) {
305 for (auto rate : {16000, 32000, 48000}) {
306 for (size_t correct_num_channels : {1, 2, 4, 8}) {
307 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
308 const size_t correct_num_bands = NumBandsForRate(rate);
309 const size_t wrong_num_channels = correct_num_channels + 1;
310 RunWronglySizedInsertAndExtractParametersTest(
311 rate, correct_num_channels, correct_num_bands, wrong_num_channels,
312 kBlockSize, correct_num_bands, correct_num_channels, kSubFrameLength);
313 }
peahd0263542017-01-03 04:20:34 -0800314 }
315}
316
317TEST(FrameBlocker,
318 WrongNumberOfBandsInSubFrameForInsertSubFrameAndExtractBlock) {
Per Åhgrence202a02019-09-02 17:01:19 +0200319 for (auto rate : {16000, 32000, 48000}) {
320 for (size_t correct_num_channels : {1, 2, 4, 8}) {
321 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
322 const size_t correct_num_bands = NumBandsForRate(rate);
323 const size_t wrong_num_bands = (correct_num_bands % 3) + 1;
324 RunWronglySizedInsertAndExtractParametersTest(
325 rate, correct_num_channels, correct_num_bands, correct_num_channels,
326 kBlockSize, wrong_num_bands, correct_num_channels, kSubFrameLength);
327 }
328 }
329}
330
331TEST(FrameBlocker,
332 WrongNumberOfChannelsInSubFrameForInsertSubFrameAndExtractBlock) {
333 for (auto rate : {16000, 32000, 48000}) {
334 for (size_t correct_num_channels : {1, 2, 4, 8}) {
335 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
336 const size_t correct_num_bands = NumBandsForRate(rate);
337 const size_t wrong_num_channels = correct_num_channels + 1;
338 RunWronglySizedInsertAndExtractParametersTest(
339 rate, correct_num_channels, correct_num_bands, wrong_num_channels,
340 kBlockSize, correct_num_bands, wrong_num_channels, kSubFrameLength);
341 }
peahd0263542017-01-03 04:20:34 -0800342 }
343}
344
345TEST(FrameBlocker,
346 WrongNumberOfSamplesInBlockForInsertSubFrameAndExtractBlock) {
Per Åhgrence202a02019-09-02 17:01:19 +0200347 for (auto rate : {16000, 32000, 48000}) {
348 for (size_t correct_num_channels : {1, 2, 4, 8}) {
349 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
350 const size_t correct_num_bands = NumBandsForRate(rate);
351 RunWronglySizedInsertAndExtractParametersTest(
352 rate, correct_num_channels, correct_num_bands, correct_num_channels,
353 kBlockSize - 1, correct_num_bands, correct_num_channels,
354 kSubFrameLength);
355 }
peahd0263542017-01-03 04:20:34 -0800356 }
357}
358
359TEST(FrameBlocker,
360 WrongNumberOfSamplesInSubFrameForInsertSubFrameAndExtractBlock) {
Per Åhgrence202a02019-09-02 17:01:19 +0200361 for (auto rate : {16000, 32000, 48000}) {
362 for (size_t correct_num_channels : {1, 2, 4, 8}) {
363 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
364 const size_t correct_num_bands = NumBandsForRate(rate);
365 RunWronglySizedInsertAndExtractParametersTest(
366 rate, correct_num_channels, correct_num_bands, correct_num_channels,
367 kBlockSize, correct_num_bands, correct_num_channels,
368 kSubFrameLength - 1);
Per Åhgrena66395e2019-08-30 08:54:09 +0200369 }
370 }
371}
372
Per Åhgrence202a02019-09-02 17:01:19 +0200373TEST(FrameBlocker, WrongNumberOfBandsInBlockForExtractBlock) {
374 for (auto rate : {16000, 32000, 48000}) {
375 for (size_t correct_num_channels : {1, 2, 4, 8}) {
376 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
377 const size_t correct_num_bands = NumBandsForRate(rate);
378 const size_t wrong_num_bands = (correct_num_bands % 3) + 1;
379 RunWronglySizedExtractParameterTest(rate, correct_num_channels,
380 wrong_num_bands, correct_num_channels,
381 kBlockSize);
382 }
383 }
384}
385
386TEST(FrameBlocker, WrongNumberOfChannelsInBlockForExtractBlock) {
387 for (auto rate : {16000, 32000, 48000}) {
388 for (size_t correct_num_channels : {1, 2, 4, 8}) {
389 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
390 const size_t correct_num_bands = NumBandsForRate(rate);
391 const size_t wrong_num_channels = correct_num_channels + 1;
392 RunWronglySizedExtractParameterTest(rate, correct_num_channels,
393 correct_num_bands, wrong_num_channels,
394 kBlockSize);
395 }
396 }
397}
398
399TEST(FrameBlocker, WrongNumberOfSamplesInBlockForExtractBlock) {
400 for (auto rate : {16000, 32000, 48000}) {
401 for (size_t correct_num_channels : {1, 2, 4, 8}) {
402 SCOPED_TRACE(ProduceDebugText(rate, correct_num_channels));
403 const size_t correct_num_bands = NumBandsForRate(rate);
404 RunWronglySizedExtractParameterTest(rate, correct_num_channels,
405 correct_num_bands,
406 correct_num_channels, kBlockSize - 1);
407 }
408 }
409}
410
411TEST(FrameBlocker, WrongNumberOfPreceedingApiCallsForExtractBlock) {
412 for (auto rate : {16000, 32000, 48000}) {
413 for (size_t num_channels : {1, 2, 4, 8}) {
414 for (size_t num_calls = 0; num_calls < 4; ++num_calls) {
415 rtc::StringBuilder ss;
416 ss << "Sample rate: " << rate;
417 ss << "Num channels: " << num_channels;
418 ss << ", Num preceeding InsertSubFrameAndExtractBlock calls: "
419 << num_calls;
420
421 SCOPED_TRACE(ss.str());
422 RunWrongExtractOrderTest(rate, num_channels, num_calls);
423 }
424 }
425 }
426}
427
428// Verifies that the verification for 0 number of channels works.
429TEST(FrameBlocker, ZeroNumberOfChannelsParameter) {
430 EXPECT_DEATH(FrameBlocker(16000, 0), "");
431}
432
433// Verifies that the verification for 0 number of bands works.
434TEST(FrameBlocker, ZeroNumberOfBandsParameter) {
435 EXPECT_DEATH(FrameBlocker(0, 1), "");
436}
437
peahd0263542017-01-03 04:20:34 -0800438// Verifiers that the verification for null sub_frame pointer works.
439TEST(FrameBlocker, NullBlockParameter) {
Per Åhgrence202a02019-09-02 17:01:19 +0200440 std::vector<std::vector<std::vector<float>>> sub_frame(
441 1, std::vector<std::vector<float>>(
442 1, std::vector<float>(kSubFrameLength, 0.f)));
443 std::vector<std::vector<rtc::ArrayView<float>>> sub_frame_view(
444 sub_frame.size());
peahd0263542017-01-03 04:20:34 -0800445 FillSubFrameView(0, 0, &sub_frame, &sub_frame_view);
446 EXPECT_DEATH(
Per Åhgrence202a02019-09-02 17:01:19 +0200447 FrameBlocker(1, 1).InsertSubFrameAndExtractBlock(sub_frame_view, nullptr),
peahd0263542017-01-03 04:20:34 -0800448 "");
449}
450
451#endif
452
453TEST(FrameBlocker, BlockBitexactness) {
Per Åhgrence202a02019-09-02 17:01:19 +0200454 for (auto rate : {16000, 32000, 48000}) {
455 for (size_t num_channels : {1, 2, 4, 8}) {
456 SCOPED_TRACE(ProduceDebugText(rate, num_channels));
457 RunBlockerTest(rate, num_channels);
458 }
peahd0263542017-01-03 04:20:34 -0800459 }
460}
461
462TEST(FrameBlocker, BlockerAndFramer) {
Per Åhgrence202a02019-09-02 17:01:19 +0200463 for (auto rate : {16000, 32000, 48000}) {
464 for (size_t num_channels : {1, 2, 4, 8}) {
465 SCOPED_TRACE(ProduceDebugText(rate, num_channels));
466 RunBlockerAndFramerTest(rate, num_channels);
467 }
peahd0263542017-01-03 04:20:34 -0800468 }
469}
470
471} // namespace webrtc