OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "media/base/buffers.h" | 11 #include "media/base/buffers.h" |
12 #include "media/base/data_buffer.h" | 12 #include "media/base/data_buffer.h" |
13 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
14 #include "media/base/decrypt_config.h" | 14 #include "media/base/decrypt_config.h" |
15 #include "media/base/gmock_callback_support.h" | 15 #include "media/base/gmock_callback_support.h" |
16 #include "media/base/mock_filters.h" | 16 #include "media/base/mock_filters.h" |
17 #include "media/base/test_helpers.h" | 17 #include "media/base/test_helpers.h" |
18 #include "media/filters/decrypting_audio_decoder.h" | 18 #include "media/filters/decrypting_audio_decoder.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 | 20 |
21 using ::testing::_; | 21 using ::testing::_; |
22 using ::testing::AtMost; | 22 using ::testing::AtMost; |
23 using ::testing::IsNull; | 23 using ::testing::IsNull; |
24 using ::testing::ReturnRef; | 24 using ::testing::ReturnRef; |
25 using ::testing::SaveArg; | 25 using ::testing::SaveArg; |
26 using ::testing::StrictMock; | 26 using ::testing::StrictMock; |
27 | 27 |
28 namespace media { | 28 namespace media { |
29 | 29 |
30 static const int kFakeAudioFrameSize = 16; | 30 // Make sure the kFakeAudioFrameSize is a valid frame size for all audio decoder |
| 31 // configs used in this test. |
| 32 static const int kFakeAudioFrameSize = 48; |
31 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; | 33 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; |
32 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; | 34 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; |
33 | 35 |
34 // Create a fake non-empty encrypted buffer. | 36 // Create a fake non-empty encrypted buffer. |
35 static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() { | 37 static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() { |
36 const int buffer_size = 16; // Need a non-empty buffer; | 38 const int buffer_size = 16; // Need a non-empty buffer; |
37 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(buffer_size)); | 39 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(buffer_size)); |
38 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( | 40 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( |
39 std::string(reinterpret_cast<const char*>(kFakeKeyId), | 41 std::string(reinterpret_cast<const char*>(kFakeKeyId), |
40 arraysize(kFakeKeyId)), | 42 arraysize(kFakeKeyId)), |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 EXPECT_CALL(*demuxer_, Read(_)) | 347 EXPECT_CALL(*demuxer_, Read(_)) |
346 .WillOnce(ReturnBuffer(scoped_refptr<DecoderBuffer>())); | 348 .WillOnce(ReturnBuffer(scoped_refptr<DecoderBuffer>())); |
347 | 349 |
348 ReadAndExpectFrameReadyWith(AudioDecoder::kAborted, NULL); | 350 ReadAndExpectFrameReadyWith(AudioDecoder::kAborted, NULL); |
349 } | 351 } |
350 | 352 |
351 // Test config change on the demuxer stream. | 353 // Test config change on the demuxer stream. |
352 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChange) { | 354 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChange) { |
353 Initialize(); | 355 Initialize(); |
354 | 356 |
| 357 // The new config is different from the initial config in bits-per-channel, |
| 358 // channel layout and samples_per_second. |
| 359 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16, |
| 360 CHANNEL_LAYOUT_5_1, 88200, NULL, 0, false); |
| 361 EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel()); |
| 362 EXPECT_NE(new_config.channel_layout(), config_.channel_layout()); |
| 363 EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second()); |
| 364 |
| 365 EXPECT_CALL(*demuxer_, audio_decoder_config()) |
| 366 .WillRepeatedly(ReturnRef(new_config)); |
355 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); | 367 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); |
356 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) | 368 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) |
357 .WillOnce(RunCallback<1>(true)); | 369 .WillOnce(RunCallback<1>(true)); |
358 EXPECT_CALL(*demuxer_, Read(_)) | 370 EXPECT_CALL(*demuxer_, Read(_)) |
359 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, | 371 .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, |
360 scoped_refptr<DecoderBuffer>())) | 372 scoped_refptr<DecoderBuffer>())) |
361 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); | 373 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); |
362 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) | 374 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
363 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); | 375 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); |
364 EXPECT_CALL(statistics_cb_, OnStatistics(_)); | 376 EXPECT_CALL(statistics_cb_, OnStatistics(_)); |
365 | 377 |
366 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_); | 378 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_); |
| 379 |
| 380 EXPECT_EQ(new_config.bits_per_channel(), decoder_->bits_per_channel()); |
| 381 EXPECT_EQ(new_config.channel_layout(), decoder_->channel_layout()); |
| 382 EXPECT_EQ(new_config.samples_per_second(), decoder_->samples_per_second()); |
367 } | 383 } |
368 | 384 |
369 // Test config change failure. | 385 // Test config change failure. |
370 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChangeFailed) { | 386 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChangeFailed) { |
371 Initialize(); | 387 Initialize(); |
372 | 388 |
373 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); | 389 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); |
374 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) | 390 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) |
375 .WillOnce(RunCallback<1>(false)); | 391 .WillOnce(RunCallback<1>(false)); |
376 EXPECT_CALL(*demuxer_, Read(_)) | 392 EXPECT_CALL(*demuxer_, Read(_)) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 } | 474 } |
459 | 475 |
460 // Test resetting when the decoder is in kPendingDemuxerRead state and the read | 476 // Test resetting when the decoder is in kPendingDemuxerRead state and the read |
461 // callback is returned with kConfigChanged. | 477 // callback is returned with kConfigChanged. |
462 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_ConfigChange) { | 478 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_ConfigChange) { |
463 Initialize(); | 479 Initialize(); |
464 EnterPendingReadState(); | 480 EnterPendingReadState(); |
465 | 481 |
466 Reset(); | 482 Reset(); |
467 | 483 |
| 484 // The new config is different from the initial config in bits-per-channel, |
| 485 // channel layout and samples_per_second. |
| 486 AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16, |
| 487 CHANNEL_LAYOUT_5_1, 88200, NULL, 0, false); |
| 488 EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel()); |
| 489 EXPECT_NE(new_config.channel_layout(), config_.channel_layout()); |
| 490 EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second()); |
| 491 |
468 // Even during pending reset, the decoder still needs to be initialized with | 492 // Even during pending reset, the decoder still needs to be initialized with |
469 // the new config. | 493 // the new config. |
| 494 EXPECT_CALL(*demuxer_, audio_decoder_config()) |
| 495 .WillRepeatedly(ReturnRef(new_config)); |
470 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); | 496 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); |
471 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) | 497 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) |
472 .WillOnce(RunCallback<1>(true)); | 498 .WillOnce(RunCallback<1>(true)); |
473 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull())); | 499 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull())); |
474 | 500 |
475 base::ResetAndReturn(&pending_demuxer_read_cb_) | 501 base::ResetAndReturn(&pending_demuxer_read_cb_) |
476 .Run(DemuxerStream::kConfigChanged, NULL); | 502 .Run(DemuxerStream::kConfigChanged, NULL); |
477 message_loop_.RunUntilIdle(); | 503 message_loop_.RunUntilIdle(); |
| 504 |
| 505 EXPECT_EQ(new_config.bits_per_channel(), decoder_->bits_per_channel()); |
| 506 EXPECT_EQ(new_config.channel_layout(), decoder_->channel_layout()); |
| 507 EXPECT_EQ(new_config.samples_per_second(), decoder_->samples_per_second()); |
478 } | 508 } |
479 | 509 |
480 // Test resetting when the decoder is in kPendingDemuxerRead state, the read | 510 // Test resetting when the decoder is in kPendingDemuxerRead state, the read |
481 // callback is returned with kConfigChanged and the config change fails. | 511 // callback is returned with kConfigChanged and the config change fails. |
482 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_ConfigChangeFailed) { | 512 TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_ConfigChangeFailed) { |
483 Initialize(); | 513 Initialize(); |
484 EnterPendingReadState(); | 514 EnterPendingReadState(); |
485 | 515 |
486 Reset(); | 516 Reset(); |
487 | 517 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 | 582 |
553 // Test resetting after the decoder has been reset. | 583 // Test resetting after the decoder has been reset. |
554 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { | 584 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { |
555 Initialize(); | 585 Initialize(); |
556 EnterNormalDecodingState(); | 586 EnterNormalDecodingState(); |
557 Reset(); | 587 Reset(); |
558 Reset(); | 588 Reset(); |
559 } | 589 } |
560 | 590 |
561 } // namespace media | 591 } // namespace media |
OLD | NEW |