OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <deque> | 5 #include <deque> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/md5.h" | 9 #include "base/md5.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 message_loop_.message_loop_proxy(), LogCB())); | 103 message_loop_.message_loop_proxy(), LogCB())); |
104 break; | 104 break; |
105 case OPUS: | 105 case OPUS: |
106 decoder_.reset( | 106 decoder_.reset( |
107 new OpusAudioDecoder(message_loop_.message_loop_proxy())); | 107 new OpusAudioDecoder(message_loop_.message_loop_proxy())); |
108 break; | 108 break; |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 virtual ~AudioDecoderTest() { | 112 virtual ~AudioDecoderTest() { |
113 // Always issue a Stop() even if it's already been sent to avoid assertion | |
114 // failures causing crashes. | |
115 Stop(); | |
116 EXPECT_FALSE(pending_decode_); | 113 EXPECT_FALSE(pending_decode_); |
117 EXPECT_FALSE(pending_reset_); | 114 EXPECT_FALSE(pending_reset_); |
118 } | 115 } |
119 | 116 |
120 protected: | 117 protected: |
121 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer) { | 118 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer) { |
122 ASSERT_FALSE(pending_decode_); | 119 ASSERT_FALSE(pending_decode_); |
123 pending_decode_ = true; | 120 pending_decode_ = true; |
124 last_decode_status_ = AudioDecoder::kDecodeError; | 121 last_decode_status_ = AudioDecoder::kDecodeError; |
125 decoder_->Decode( | 122 decoder_->Decode( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 199 |
203 void Reset() { | 200 void Reset() { |
204 ASSERT_FALSE(pending_reset_); | 201 ASSERT_FALSE(pending_reset_); |
205 pending_reset_ = true; | 202 pending_reset_ = true; |
206 decoder_->Reset( | 203 decoder_->Reset( |
207 base::Bind(&AudioDecoderTest::ResetFinished, base::Unretained(this))); | 204 base::Bind(&AudioDecoderTest::ResetFinished, base::Unretained(this))); |
208 base::RunLoop().RunUntilIdle(); | 205 base::RunLoop().RunUntilIdle(); |
209 ASSERT_FALSE(pending_reset_); | 206 ASSERT_FALSE(pending_reset_); |
210 } | 207 } |
211 | 208 |
212 void Stop() { | |
213 decoder_->Stop(); | |
214 } | |
215 | |
216 void Seek(base::TimeDelta seek_time) { | 209 void Seek(base::TimeDelta seek_time) { |
217 Reset(); | 210 Reset(); |
218 decoded_audio_.clear(); | 211 decoded_audio_.clear(); |
219 ASSERT_TRUE(reader_->SeekForTesting(seek_time)); | 212 ASSERT_TRUE(reader_->SeekForTesting(seek_time)); |
220 } | 213 } |
221 | 214 |
222 void OnDecoderOutput(const scoped_refptr<AudioBuffer>& buffer) { | 215 void OnDecoderOutput(const scoped_refptr<AudioBuffer>& buffer) { |
223 EXPECT_FALSE(buffer->end_of_stream()); | 216 EXPECT_FALSE(buffer->end_of_stream()); |
224 decoded_audio_.push_back(buffer); | 217 decoded_audio_.push_back(buffer); |
225 } | 218 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 base::TimeDelta start_timestamp_; | 305 base::TimeDelta start_timestamp_; |
313 | 306 |
314 DISALLOW_COPY_AND_ASSIGN(AudioDecoderTest); | 307 DISALLOW_COPY_AND_ASSIGN(AudioDecoderTest); |
315 }; | 308 }; |
316 | 309 |
317 class OpusAudioDecoderBehavioralTest : public AudioDecoderTest {}; | 310 class OpusAudioDecoderBehavioralTest : public AudioDecoderTest {}; |
318 class FFmpegAudioDecoderBehavioralTest : public AudioDecoderTest {}; | 311 class FFmpegAudioDecoderBehavioralTest : public AudioDecoderTest {}; |
319 | 312 |
320 TEST_P(AudioDecoderTest, Initialize) { | 313 TEST_P(AudioDecoderTest, Initialize) { |
321 ASSERT_NO_FATAL_FAILURE(Initialize()); | 314 ASSERT_NO_FATAL_FAILURE(Initialize()); |
322 Stop(); | |
323 } | 315 } |
324 | 316 |
325 // Verifies decode audio as well as the Decode() -> Reset() -> Stop() sequence. | 317 // Verifies decode audio as well as the Decode() -> Reset() sequence. |
326 TEST_P(AudioDecoderTest, ProduceAudioSamples) { | 318 TEST_P(AudioDecoderTest, ProduceAudioSamples) { |
327 ASSERT_NO_FATAL_FAILURE(Initialize()); | 319 ASSERT_NO_FATAL_FAILURE(Initialize()); |
328 | 320 |
329 // Run the test multiple times with a seek back to the beginning in between. | 321 // Run the test multiple times with a seek back to the beginning in between. |
330 std::vector<std::string> decoded_audio_md5_hashes; | 322 std::vector<std::string> decoded_audio_md5_hashes; |
331 for (int i = 0; i < 2; ++i) { | 323 for (int i = 0; i < 2; ++i) { |
332 for (size_t j = 0; j < kDecodeRuns; ++j) { | 324 for (size_t j = 0; j < kDecodeRuns; ++j) { |
333 do { | 325 do { |
334 Decode(); | 326 Decode(); |
335 ASSERT_EQ(last_decode_status(), AudioDecoder::kOk); | 327 ASSERT_EQ(last_decode_status(), AudioDecoder::kOk); |
(...skipping 14 matching lines...) Expand all Loading... |
350 SCOPED_TRACE(base::StringPrintf("i = %d, j = %" PRIuS, i, j)); | 342 SCOPED_TRACE(base::StringPrintf("i = %d, j = %" PRIuS, i, j)); |
351 ExpectDecodedAudio(j, i == 0 ? "" : decoded_audio_md5_hashes[j]); | 343 ExpectDecodedAudio(j, i == 0 ? "" : decoded_audio_md5_hashes[j]); |
352 } | 344 } |
353 | 345 |
354 SendEndOfStream(); | 346 SendEndOfStream(); |
355 ASSERT_EQ(kDecodeRuns, decoded_audio_size()); | 347 ASSERT_EQ(kDecodeRuns, decoded_audio_size()); |
356 | 348 |
357 // Seek back to the beginning. Calls Reset() on the decoder. | 349 // Seek back to the beginning. Calls Reset() on the decoder. |
358 Seek(start_timestamp()); | 350 Seek(start_timestamp()); |
359 } | 351 } |
360 | |
361 Stop(); | |
362 } | 352 } |
363 | 353 |
364 TEST_P(AudioDecoderTest, DecodeStop) { | 354 TEST_P(AudioDecoderTest, Decode) { |
365 ASSERT_NO_FATAL_FAILURE(Initialize()); | 355 ASSERT_NO_FATAL_FAILURE(Initialize()); |
366 Decode(); | 356 Decode(); |
367 EXPECT_EQ(AudioDecoder::kOk, last_decode_status()); | 357 EXPECT_EQ(AudioDecoder::kOk, last_decode_status()); |
368 Stop(); | |
369 } | 358 } |
370 | 359 |
371 TEST_P(AudioDecoderTest, ResetStop) { | 360 TEST_P(AudioDecoderTest, Reset) { |
372 ASSERT_NO_FATAL_FAILURE(Initialize()); | 361 ASSERT_NO_FATAL_FAILURE(Initialize()); |
373 Reset(); | 362 Reset(); |
374 Stop(); | |
375 } | 363 } |
376 | 364 |
377 TEST_P(AudioDecoderTest, NoTimestamp) { | 365 TEST_P(AudioDecoderTest, NoTimestamp) { |
378 ASSERT_NO_FATAL_FAILURE(Initialize()); | 366 ASSERT_NO_FATAL_FAILURE(Initialize()); |
379 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); | 367 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); |
380 buffer->set_timestamp(kNoTimestamp()); | 368 buffer->set_timestamp(kNoTimestamp()); |
381 DecodeBuffer(buffer); | 369 DecodeBuffer(buffer); |
382 EXPECT_EQ(AudioDecoder::kDecodeError, last_decode_status()); | 370 EXPECT_EQ(AudioDecoder::kDecodeError, last_decode_status()); |
383 Stop(); | |
384 } | 371 } |
385 | 372 |
386 TEST_P(OpusAudioDecoderBehavioralTest, InitializeWithNoCodecDelay) { | 373 TEST_P(OpusAudioDecoderBehavioralTest, InitializeWithNoCodecDelay) { |
387 ASSERT_EQ(GetParam().decoder_type, OPUS); | 374 ASSERT_EQ(GetParam().decoder_type, OPUS); |
388 AudioDecoderConfig decoder_config; | 375 AudioDecoderConfig decoder_config; |
389 decoder_config.Initialize(kCodecOpus, | 376 decoder_config.Initialize(kCodecOpus, |
390 kSampleFormatF32, | 377 kSampleFormatF32, |
391 CHANNEL_LAYOUT_STEREO, | 378 CHANNEL_LAYOUT_STEREO, |
392 48000, | 379 48000, |
393 kOpusExtraData, | 380 kOpusExtraData, |
394 ARRAYSIZE_UNSAFE(kOpusExtraData), | 381 ARRAYSIZE_UNSAFE(kOpusExtraData), |
395 false, | 382 false, |
396 false, | 383 false, |
397 base::TimeDelta::FromMilliseconds(80), | 384 base::TimeDelta::FromMilliseconds(80), |
398 0); | 385 0); |
399 InitializeDecoder(decoder_config); | 386 InitializeDecoder(decoder_config); |
400 Stop(); | |
401 } | 387 } |
402 | 388 |
403 TEST_P(OpusAudioDecoderBehavioralTest, InitializeWithBadCodecDelay) { | 389 TEST_P(OpusAudioDecoderBehavioralTest, InitializeWithBadCodecDelay) { |
404 ASSERT_EQ(GetParam().decoder_type, OPUS); | 390 ASSERT_EQ(GetParam().decoder_type, OPUS); |
405 AudioDecoderConfig decoder_config; | 391 AudioDecoderConfig decoder_config; |
406 decoder_config.Initialize( | 392 decoder_config.Initialize( |
407 kCodecOpus, | 393 kCodecOpus, |
408 kSampleFormatF32, | 394 kSampleFormatF32, |
409 CHANNEL_LAYOUT_STEREO, | 395 CHANNEL_LAYOUT_STEREO, |
410 48000, | 396 48000, |
411 kOpusExtraData, | 397 kOpusExtraData, |
412 ARRAYSIZE_UNSAFE(kOpusExtraData), | 398 ARRAYSIZE_UNSAFE(kOpusExtraData), |
413 false, | 399 false, |
414 false, | 400 false, |
415 base::TimeDelta::FromMilliseconds(80), | 401 base::TimeDelta::FromMilliseconds(80), |
416 // Use a different codec delay than in the extradata. | 402 // Use a different codec delay than in the extradata. |
417 100); | 403 100); |
418 InitializeDecoderWithStatus(decoder_config, DECODER_ERROR_NOT_SUPPORTED); | 404 InitializeDecoderWithStatus(decoder_config, DECODER_ERROR_NOT_SUPPORTED); |
419 Stop(); | |
420 } | 405 } |
421 | 406 |
422 TEST_P(FFmpegAudioDecoderBehavioralTest, InitializeWithBadConfig) { | 407 TEST_P(FFmpegAudioDecoderBehavioralTest, InitializeWithBadConfig) { |
423 const AudioDecoderConfig decoder_config(kCodecVorbis, | 408 const AudioDecoderConfig decoder_config(kCodecVorbis, |
424 kSampleFormatF32, | 409 kSampleFormatF32, |
425 CHANNEL_LAYOUT_STEREO, | 410 CHANNEL_LAYOUT_STEREO, |
426 // Invalid sample rate of zero. | 411 // Invalid sample rate of zero. |
427 0, | 412 0, |
428 NULL, | 413 NULL, |
429 0, | 414 0, |
430 false); | 415 false); |
431 InitializeDecoderWithStatus(decoder_config, DECODER_ERROR_NOT_SUPPORTED); | 416 InitializeDecoderWithStatus(decoder_config, DECODER_ERROR_NOT_SUPPORTED); |
432 Stop(); | |
433 } | 417 } |
434 | 418 |
435 const DecodedBufferExpectations kSfxOpusExpectations[] = { | 419 const DecodedBufferExpectations kSfxOpusExpectations[] = { |
436 {0, 13500, "-2.70,-1.41,-0.78,-1.27,-2.56,-3.73,"}, | 420 {0, 13500, "-2.70,-1.41,-0.78,-1.27,-2.56,-3.73,"}, |
437 {13500, 20000, "5.48,5.93,6.04,5.83,5.54,5.45,"}, | 421 {13500, 20000, "5.48,5.93,6.04,5.83,5.54,5.45,"}, |
438 {33500, 20000, "-3.45,-3.35,-3.57,-4.12,-4.74,-5.14,"}, | 422 {33500, 20000, "-3.45,-3.35,-3.57,-4.12,-4.74,-5.14,"}, |
439 }; | 423 }; |
440 | 424 |
441 const DecodedBufferExpectations kBearOpusExpectations[] = { | 425 const DecodedBufferExpectations kBearOpusExpectations[] = { |
442 {500, 3500, "-0.26,0.87,1.36,0.84,-0.30,-1.22,"}, | 426 {500, 3500, "-0.26,0.87,1.36,0.84,-0.30,-1.22,"}, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 }; | 522 }; |
539 | 523 |
540 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderTest, | 524 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderTest, |
541 AudioDecoderTest, | 525 AudioDecoderTest, |
542 testing::ValuesIn(kFFmpegTests)); | 526 testing::ValuesIn(kFFmpegTests)); |
543 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderBehavioralTest, | 527 INSTANTIATE_TEST_CASE_P(FFmpegAudioDecoderBehavioralTest, |
544 FFmpegAudioDecoderBehavioralTest, | 528 FFmpegAudioDecoderBehavioralTest, |
545 testing::ValuesIn(kFFmpegBehavioralTest)); | 529 testing::ValuesIn(kFFmpegBehavioralTest)); |
546 | 530 |
547 } // namespace media | 531 } // namespace media |
OLD | NEW |