peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/aec3/frame_blocker.h" |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 12 | |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "modules/audio_processing/aec3/aec3_common.h" |
| 17 | #include "modules/audio_processing/aec3/block_framer.h" |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 18 | #include "rtc_base/strings/string_builder.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "test/gtest.h" |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | namespace { |
| 23 | |
| 24 | float ComputeSampleValue(size_t chunk_counter, |
| 25 | size_t chunk_size, |
| 26 | size_t band, |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 27 | size_t channel, |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 28 | size_t sample_index, |
| 29 | int offset) { |
| 30 | float value = |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 31 | static_cast<int>(chunk_counter * chunk_size + sample_index + channel) + |
| 32 | offset; |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 33 | return value > 0 ? 5000 * band + value : 0; |
| 34 | } |
| 35 | |
| 36 | void FillSubFrame(size_t sub_frame_counter, |
| 37 | int offset, |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 38 | 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 | } |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 50 | void 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) { |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 55 | FillSubFrame(sub_frame_counter, offset, sub_frame); |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 56 | 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 | } |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 65 | bool 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))); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 74 | FillSubFrame(sub_frame_counter, offset, &reference_sub_frame); |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 75 | 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 | } |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | } |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | bool VerifyBlock(size_t block_counter, |
| 90 | int offset, |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 91 | 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 | } |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | } |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | // Verifies that the FrameBlocker properly forms blocks out of the frames. |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 107 | void RunBlockerTest(int sample_rate_hz, size_t num_channels) { |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 108 | constexpr size_t kNumSubFramesToProcess = 20; |
| 109 | const size_t num_bands = NumBandsForRate(sample_rate_hz); |
| 110 | |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 111 | 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); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 120 | |
| 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 Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 144 | void RunBlockerAndFramerTest(int sample_rate_hz, size_t num_channels) { |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 145 | const size_t kNumSubFramesToProcess = 20; |
| 146 | const size_t num_bands = NumBandsForRate(sample_rate_hz); |
| 147 | |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 148 | 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); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 163 | |
| 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 Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 183 | if (sub_frame_index > 1) { |
| 184 | EXPECT_TRUE(VerifySubFrame(sub_frame_index, -64, output_sub_frame_view)); |
| 185 | } |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 186 | } |
| 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 Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 192 | void 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) { |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 201 | const size_t correct_num_bands = NumBandsForRate(sample_rate_hz); |
| 202 | |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 203 | 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)); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 214 | FillSubFrameView(0, 0, &input_sub_frame, &input_sub_frame_view); |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 215 | FrameBlocker blocker(correct_num_bands, correct_num_channels); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 216 | 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. |
| 222 | void RunWronglySizedExtractParameterTest(int sample_rate_hz, |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 223 | size_t correct_num_channels, |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 224 | size_t num_block_bands, |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 225 | size_t num_block_channels, |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 226 | size_t block_length) { |
| 227 | const size_t correct_num_bands = NumBandsForRate(sample_rate_hz); |
| 228 | |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 229 | 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)); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 244 | FillSubFrameView(0, 0, &input_sub_frame, &input_sub_frame_view); |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 245 | FrameBlocker blocker(correct_num_bands, correct_num_channels); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 246 | 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. |
| 257 | void RunWrongExtractOrderTest(int sample_rate_hz, |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 258 | size_t num_channels, |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 259 | size_t num_preceeding_api_calls) { |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 260 | const size_t num_bands = NumBandsForRate(sample_rate_hz); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 261 | |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 262 | 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)); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 270 | FillSubFrameView(0, 0, &input_sub_frame, &input_sub_frame_view); |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 271 | FrameBlocker blocker(num_bands, num_channels); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 272 | 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 Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 280 | std::string ProduceDebugText(int sample_rate_hz, size_t num_channels) { |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame] | 281 | rtc::StringBuilder ss; |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 282 | ss << "Sample rate: " << sample_rate_hz; |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 283 | ss << ", number of channels: " << num_channels; |
Jonas Olsson | 84df1c7 | 2018-09-14 16:59:32 +0200 | [diff] [blame] | 284 | return ss.Release(); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | } // namespace |
| 288 | |
| 289 | #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 290 | TEST(FrameBlocker, WrongNumberOfBandsInBlockForInsertSubFrameAndExtractBlock) { |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 291 | 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 | |
| 303 | TEST(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 | } |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
| 317 | TEST(FrameBlocker, |
| 318 | WrongNumberOfBandsInSubFrameForInsertSubFrameAndExtractBlock) { |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 319 | 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 | |
| 331 | TEST(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 | } |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
| 345 | TEST(FrameBlocker, |
| 346 | WrongNumberOfSamplesInBlockForInsertSubFrameAndExtractBlock) { |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 347 | 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 | } |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
| 359 | TEST(FrameBlocker, |
| 360 | WrongNumberOfSamplesInSubFrameForInsertSubFrameAndExtractBlock) { |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 361 | 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 Åhgren | a66395e | 2019-08-30 08:54:09 +0200 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 373 | TEST(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 | |
| 386 | TEST(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 | |
| 399 | TEST(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 | |
| 411 | TEST(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. |
| 429 | TEST(FrameBlocker, ZeroNumberOfChannelsParameter) { |
| 430 | EXPECT_DEATH(FrameBlocker(16000, 0), ""); |
| 431 | } |
| 432 | |
| 433 | // Verifies that the verification for 0 number of bands works. |
| 434 | TEST(FrameBlocker, ZeroNumberOfBandsParameter) { |
| 435 | EXPECT_DEATH(FrameBlocker(0, 1), ""); |
| 436 | } |
| 437 | |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 438 | // Verifiers that the verification for null sub_frame pointer works. |
| 439 | TEST(FrameBlocker, NullBlockParameter) { |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 440 | 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()); |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 445 | FillSubFrameView(0, 0, &sub_frame, &sub_frame_view); |
| 446 | EXPECT_DEATH( |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 447 | FrameBlocker(1, 1).InsertSubFrameAndExtractBlock(sub_frame_view, nullptr), |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 448 | ""); |
| 449 | } |
| 450 | |
| 451 | #endif |
| 452 | |
| 453 | TEST(FrameBlocker, BlockBitexactness) { |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 454 | 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 | } |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | TEST(FrameBlocker, BlockerAndFramer) { |
Per Åhgren | ce202a0 | 2019-09-02 17:01:19 +0200 | [diff] [blame^] | 463 | 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 | } |
peah | d026354 | 2017-01-03 04:20:34 -0800 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
| 471 | } // namespace webrtc |