Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: webrtc/modules/audio_coding/neteq/neteq_external_decoder_unittest.cc

Issue 1230503003: Update a ton of audio code to use size_t more correctly and in general reduce (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 }; 162 };
163 163
164 // This test encodes a few packets of PCM16b 32 kHz data and inserts it into two 164 // This test encodes a few packets of PCM16b 32 kHz data and inserts it into two
165 // different NetEq instances. The first instance uses the internal version of 165 // different NetEq instances. The first instance uses the internal version of
166 // the decoder object, while the second one uses an externally created decoder 166 // the decoder object, while the second one uses an externally created decoder
167 // object (ExternalPcm16B wrapped in MockExternalPcm16B, both defined above). 167 // object (ExternalPcm16B wrapped in MockExternalPcm16B, both defined above).
168 // The test verifies that the output from both instances match. 168 // The test verifies that the output from both instances match.
169 class NetEqExternalVsInternalDecoderTest : public NetEqExternalDecoderUnitTest, 169 class NetEqExternalVsInternalDecoderTest : public NetEqExternalDecoderUnitTest,
170 public ::testing::Test { 170 public ::testing::Test {
171 protected: 171 protected:
172 static const int kMaxBlockSize = 480; // 10 ms @ 48 kHz. 172 static const size_t kMaxBlockSize = 480; // 10 ms @ 48 kHz.
173 173
174 NetEqExternalVsInternalDecoderTest() 174 NetEqExternalVsInternalDecoderTest()
175 : NetEqExternalDecoderUnitTest(kDecoderPCM16Bswb32kHz, 175 : NetEqExternalDecoderUnitTest(kDecoderPCM16Bswb32kHz,
176 new MockExternalPcm16B), 176 new MockExternalPcm16B),
177 sample_rate_hz_(CodecSampleRateHz(kDecoderPCM16Bswb32kHz)) { 177 sample_rate_hz_(CodecSampleRateHz(kDecoderPCM16Bswb32kHz)) {
178 NetEq::Config config; 178 NetEq::Config config;
179 config.sample_rate_hz = CodecSampleRateHz(kDecoderPCM16Bswb32kHz); 179 config.sample_rate_hz = CodecSampleRateHz(kDecoderPCM16Bswb32kHz);
180 neteq_internal_.reset(NetEq::Create(config)); 180 neteq_internal_.reset(NetEq::Create(config));
181 } 181 }
182 182
183 void SetUp() override { 183 void SetUp() override {
184 ASSERT_EQ(NetEq::kOK, 184 ASSERT_EQ(NetEq::kOK,
185 neteq_internal_->RegisterPayloadType(kDecoderPCM16Bswb32kHz, 185 neteq_internal_->RegisterPayloadType(kDecoderPCM16Bswb32kHz,
186 kPayloadType)); 186 kPayloadType));
187 } 187 }
188 188
189 void GetAndVerifyOutput() override { 189 void GetAndVerifyOutput() override {
190 NetEqOutputType output_type; 190 NetEqOutputType output_type;
191 int samples_per_channel; 191 size_t samples_per_channel;
192 int num_channels; 192 int num_channels;
193 // Get audio from internal decoder instance. 193 // Get audio from internal decoder instance.
194 EXPECT_EQ(NetEq::kOK, 194 EXPECT_EQ(NetEq::kOK,
195 neteq_internal_->GetAudio(kMaxBlockSize, 195 neteq_internal_->GetAudio(kMaxBlockSize,
196 output_internal_, 196 output_internal_,
197 &samples_per_channel, 197 &samples_per_channel,
198 &num_channels, 198 &num_channels,
199 &output_type)); 199 &output_type));
200 EXPECT_EQ(1, num_channels); 200 EXPECT_EQ(1, num_channels);
201 EXPECT_EQ(kOutputLengthMs * sample_rate_hz_ / 1000, samples_per_channel); 201 EXPECT_EQ(static_cast<size_t>(kOutputLengthMs * sample_rate_hz_ / 1000),
202 samples_per_channel);
202 203
203 // Get audio from external decoder instance. 204 // Get audio from external decoder instance.
204 samples_per_channel = GetOutputAudio(kMaxBlockSize, output_, &output_type); 205 samples_per_channel = GetOutputAudio(kMaxBlockSize, output_, &output_type);
205 206
206 for (int i = 0; i < samples_per_channel; ++i) { 207 for (size_t i = 0; i < samples_per_channel; ++i) {
207 ASSERT_EQ(output_[i], output_internal_[i]) << 208 ASSERT_EQ(output_[i], output_internal_[i]) <<
208 "Diff in sample " << i << "."; 209 "Diff in sample " << i << ".";
209 } 210 }
210 } 211 }
211 212
212 void InsertPacket(WebRtcRTPHeader rtp_header, const uint8_t* payload, 213 void InsertPacket(WebRtcRTPHeader rtp_header, const uint8_t* payload,
213 size_t payload_size_bytes, 214 size_t payload_size_bytes,
214 uint32_t receive_timestamp) override { 215 uint32_t receive_timestamp) override {
215 // Insert packet in internal decoder. 216 // Insert packet in internal decoder.
216 ASSERT_EQ( 217 ASSERT_EQ(
(...skipping 16 matching lines...) Expand all
233 int16_t output_[kMaxBlockSize]; 234 int16_t output_[kMaxBlockSize];
234 }; 235 };
235 236
236 TEST_F(NetEqExternalVsInternalDecoderTest, RunTest) { 237 TEST_F(NetEqExternalVsInternalDecoderTest, RunTest) {
237 RunTest(100); // Run 100 laps @ 10 ms each in the test loop. 238 RunTest(100); // Run 100 laps @ 10 ms each in the test loop.
238 } 239 }
239 240
240 class LargeTimestampJumpTest : public NetEqExternalDecoderUnitTest, 241 class LargeTimestampJumpTest : public NetEqExternalDecoderUnitTest,
241 public ::testing::Test { 242 public ::testing::Test {
242 protected: 243 protected:
243 static const int kMaxBlockSize = 480; // 10 ms @ 48 kHz. 244 static const size_t kMaxBlockSize = 480; // 10 ms @ 48 kHz.
244 245
245 enum TestStates { 246 enum TestStates {
246 kInitialPhase, 247 kInitialPhase,
247 kNormalPhase, 248 kNormalPhase,
248 kExpandPhase, 249 kExpandPhase,
249 kFadedExpandPhase, 250 kFadedExpandPhase,
250 kRecovered 251 kRecovered
251 }; 252 };
252 253
253 LargeTimestampJumpTest() 254 LargeTimestampJumpTest()
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 287 }
287 break; 288 break;
288 } 289 }
289 case kRecovered: { 290 case kRecovered: {
290 break; 291 break;
291 } 292 }
292 } 293 }
293 } 294 }
294 295
295 void GetAndVerifyOutput() override { 296 void GetAndVerifyOutput() override {
296 int num_samples; 297 size_t num_samples;
297 NetEqOutputType output_type; 298 NetEqOutputType output_type;
298 num_samples = GetOutputAudio(kMaxBlockSize, output_, &output_type); 299 num_samples = GetOutputAudio(kMaxBlockSize, output_, &output_type);
299 UpdateState(output_type); 300 UpdateState(output_type);
300 301
301 if (test_state_ == kExpandPhase || test_state_ == kFadedExpandPhase) { 302 if (test_state_ == kExpandPhase || test_state_ == kFadedExpandPhase) {
302 // Don't verify the output in this phase of the test. 303 // Don't verify the output in this phase of the test.
303 return; 304 return;
304 } 305 }
305 306
306 for (int i = 0; i < num_samples; ++i) { 307 for (size_t i = 0; i < num_samples; ++i) {
307 if (output_[i] != 0) 308 if (output_[i] != 0)
308 return; 309 return;
309 } 310 }
310 EXPECT_TRUE(false) 311 EXPECT_TRUE(false)
311 << "Expected at least one non-zero sample in each output block."; 312 << "Expected at least one non-zero sample in each output block.";
312 } 313 }
313 314
314 int NumExpectedDecodeCalls(int num_loops) override { 315 int NumExpectedDecodeCalls(int num_loops) override {
315 // Some packets at the end of the stream won't be decoded. When the jump in 316 // Some packets at the end of the stream won't be decoded. When the jump in
316 // timestamp happens, NetEq will do Expand during one GetAudio call. In the 317 // timestamp happens, NetEq will do Expand during one GetAudio call. In the
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 kStartSeqeunceNumber, 454 kStartSeqeunceNumber,
454 kStartTimestamp, 455 kStartTimestamp,
455 kJumpFromTimestamp, 456 kJumpFromTimestamp,
456 kJumpToTimestamp)); 457 kJumpToTimestamp));
457 458
458 RunTest(130); // Run 130 laps @ 10 ms each in the test loop. 459 RunTest(130); // Run 130 laps @ 10 ms each in the test loop.
459 EXPECT_EQ(kRecovered, test_state_); 460 EXPECT_EQ(kRecovered, test_state_);
460 } 461 }
461 462
462 } // namespace webrtc 463 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/mock/mock_packet_buffer.h ('k') | webrtc/modules/audio_coding/neteq/neteq_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698