diff options
Diffstat (limited to 'chromium/media/filters/decrypting_audio_decoder_unittest.cc')
-rw-r--r-- | chromium/media/filters/decrypting_audio_decoder_unittest.cc | 411 |
1 files changed, 137 insertions, 274 deletions
diff --git a/chromium/media/filters/decrypting_audio_decoder_unittest.cc b/chromium/media/filters/decrypting_audio_decoder_unittest.cc index 2f07e231c03..8f187e1ae75 100644 --- a/chromium/media/filters/decrypting_audio_decoder_unittest.cc +++ b/chromium/media/filters/decrypting_audio_decoder_unittest.cc @@ -20,17 +20,19 @@ using ::testing::_; using ::testing::AtMost; -using ::testing::IsNull; using ::testing::SaveArg; using ::testing::StrictMock; namespace media { +const int kSampleRate = 44100; + // Make sure the kFakeAudioFrameSize is a valid frame size for all audio decoder // configs used in this test. -static const int kFakeAudioFrameSize = 48; -static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; -static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; +const int kFakeAudioFrameSize = 48; +const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; +const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; +const int kDecodingDelay = 3; // Create a fake non-empty encrypted buffer. static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() { @@ -40,7 +42,6 @@ static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() { std::string(reinterpret_cast<const char*>(kFakeKeyId), arraysize(kFakeKeyId)), std::string(reinterpret_cast<const char*>(kFakeIv), arraysize(kFakeIv)), - 0, std::vector<SubsampleEntry>()))); return buffer; } @@ -50,7 +51,7 @@ static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() { namespace { ACTION_P(ReturnBuffer, buffer) { - arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); + return buffer; } ACTION_P(RunCallbackIfNotNull, param) { @@ -58,14 +59,6 @@ ACTION_P(RunCallbackIfNotNull, param) { arg0.Run(param); } -ACTION_P2(ResetAndRunCallback, callback, param) { - base::ResetAndReturn(callback).Run(param); -} - -MATCHER(IsEndOfStream, "end of stream") { - return (arg->end_of_stream()); -} - } // namespace class DecryptingAudioDecoderTest : public testing::Test { @@ -77,11 +70,16 @@ class DecryptingAudioDecoderTest : public testing::Test { &DecryptingAudioDecoderTest::RequestDecryptorNotification, base::Unretained(this)))), decryptor_(new StrictMock<MockDecryptor>()), - demuxer_(new StrictMock<MockDemuxerStream>(DemuxerStream::AUDIO)), + num_decrypt_and_decode_calls_(0), + num_frames_in_decryptor_(0), encrypted_buffer_(CreateFakeEncryptedBuffer()), decoded_frame_(NULL), - end_of_stream_frame_(AudioBuffer::CreateEOSBuffer()), - decoded_frame_list_() { + decoded_frame_list_() {} + + virtual ~DecryptingAudioDecoderTest() { + EXPECT_CALL(*this, RequestDecryptorNotification(_)) + .Times(testing::AnyNumber()); + Stop(); } void InitializeAndExpectStatus(const AudioDecoderConfig& config, @@ -90,16 +88,18 @@ class DecryptingAudioDecoderTest : public testing::Test { // invalid values (that CreateEmptyBuffer() doesn't support), tweak them // just for CreateEmptyBuffer(). int channels = ChannelLayoutToChannelCount(config.channel_layout()); - if (channels < 1) - channels = 1; - decoded_frame_ = AudioBuffer::CreateEmptyBuffer( - channels, kFakeAudioFrameSize, kNoTimestamp(), kNoTimestamp()); + if (channels < 0) + channels = 0; + decoded_frame_ = AudioBuffer::CreateEmptyBuffer(config.channel_layout(), + channels, + kSampleRate, + kFakeAudioFrameSize, + kNoTimestamp()); decoded_frame_list_.push_back(decoded_frame_); - demuxer_->set_audio_decoder_config(config); - decoder_->Initialize(demuxer_.get(), NewExpectedStatusCB(status), - base::Bind(&MockStatisticsCB::OnStatistics, - base::Unretained(&statistics_cb_))); + decoder_->Initialize(config, NewExpectedStatusCB(status), + base::Bind(&DecryptingAudioDecoderTest::FrameReady, + base::Unretained(this))); message_loop_.RunUntilIdle(); } @@ -113,91 +113,98 @@ class DecryptingAudioDecoderTest : public testing::Test { .WillOnce(SaveArg<1>(&key_added_cb_)); config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32, - CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true, true, - base::TimeDelta(), base::TimeDelta()); + CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true, true, + base::TimeDelta(), 0); InitializeAndExpectStatus(config_, PIPELINE_OK); + } - EXPECT_EQ(DecryptingAudioDecoder::kSupportedBitsPerChannel, - decoder_->bits_per_channel()); - EXPECT_EQ(config_.channel_layout(), decoder_->channel_layout()); - EXPECT_EQ(config_.samples_per_second(), decoder_->samples_per_second()); + void Reinitialize() { + ReinitializeConfigChange(config_); } - void ReadAndExpectFrameReadyWith( - AudioDecoder::Status status, - const scoped_refptr<AudioBuffer>& audio_frame) { - if (status != AudioDecoder::kOk) - EXPECT_CALL(*this, FrameReady(status, IsNull())); - else if (audio_frame->end_of_stream()) - EXPECT_CALL(*this, FrameReady(status, IsEndOfStream())); - else - EXPECT_CALL(*this, FrameReady(status, audio_frame)); - - decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, - base::Unretained(this))); + void ReinitializeConfigChange(const AudioDecoderConfig& new_config) { + EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); + EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) + .WillOnce(RunCallback<1>(true)); + EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) + .WillOnce(SaveArg<1>(&key_added_cb_)); + decoder_->Initialize(new_config, NewExpectedStatusCB(PIPELINE_OK), + base::Bind(&DecryptingAudioDecoderTest::FrameReady, + base::Unretained(this))); + } + + // Decode |buffer| and expect DecodeDone to get called with |status|. + void DecodeAndExpect(const scoped_refptr<DecoderBuffer>& buffer, + AudioDecoder::Status status) { + EXPECT_CALL(*this, DecodeDone(status)); + decoder_->Decode(buffer, + base::Bind(&DecryptingAudioDecoderTest::DecodeDone, + base::Unretained(this))); message_loop_.RunUntilIdle(); } + // Helper function to simulate the decrypting and decoding process in the + // |decryptor_| with a decoding delay of kDecodingDelay buffers. + void DecryptAndDecodeAudio(const scoped_refptr<DecoderBuffer>& encrypted, + const Decryptor::AudioDecodeCB& audio_decode_cb) { + num_decrypt_and_decode_calls_++; + if (!encrypted->end_of_stream()) + num_frames_in_decryptor_++; + + if (num_decrypt_and_decode_calls_ <= kDecodingDelay || + num_frames_in_decryptor_ == 0) { + audio_decode_cb.Run(Decryptor::kNeedMoreData, Decryptor::AudioBuffers()); + return; + } + + num_frames_in_decryptor_--; + audio_decode_cb.Run(Decryptor::kSuccess, + Decryptor::AudioBuffers(1, decoded_frame_)); + } + // Sets up expectations and actions to put DecryptingAudioDecoder in an // active normal decoding state. void EnterNormalDecodingState() { - Decryptor::AudioBuffers end_of_stream_frames_(1, end_of_stream_frame_); - - EXPECT_CALL(*demuxer_, Read(_)) - .WillOnce(ReturnBuffer(encrypted_buffer_)) - .WillRepeatedly(ReturnBuffer(DecoderBuffer::CreateEOSBuffer())); - EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) - .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)) - .WillRepeatedly(RunCallback<1>(Decryptor::kNeedMoreData, - Decryptor::AudioBuffers())); - EXPECT_CALL(statistics_cb_, OnStatistics(_)); - - ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_); + EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)).WillRepeatedly( + Invoke(this, &DecryptingAudioDecoderTest::DecryptAndDecodeAudio)); + EXPECT_CALL(*this, FrameReady(decoded_frame_)); + for (int i = 0; i < kDecodingDelay + 1; ++i) + DecodeAndExpect(encrypted_buffer_, AudioDecoder::kOk); } // Sets up expectations and actions to put DecryptingAudioDecoder in an end // of stream state. This function must be called after // EnterNormalDecodingState() to work. void EnterEndOfStreamState() { - ReadAndExpectFrameReadyWith(AudioDecoder::kOk, end_of_stream_frame_); - } - - // Make the read callback pending by saving and not firing it. - void EnterPendingReadState() { - EXPECT_TRUE(pending_demuxer_read_cb_.is_null()); - EXPECT_CALL(*demuxer_, Read(_)) - .WillOnce(SaveArg<0>(&pending_demuxer_read_cb_)); - decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, - base::Unretained(this))); - message_loop_.RunUntilIdle(); - // Make sure the Read() on the decoder triggers a Read() on the demuxer. - EXPECT_FALSE(pending_demuxer_read_cb_.is_null()); + // The codec in the |decryptor_| will be flushed. + EXPECT_CALL(*this, FrameReady(decoded_frame_)) + .Times(kDecodingDelay); + DecodeAndExpect(DecoderBuffer::CreateEOSBuffer(), AudioDecoder::kOk); + EXPECT_EQ(0, num_frames_in_decryptor_); } // Make the audio decode callback pending by saving and not firing it. void EnterPendingDecodeState() { EXPECT_TRUE(pending_audio_decode_cb_.is_null()); - EXPECT_CALL(*demuxer_, Read(_)) - .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _)) .WillOnce(SaveArg<1>(&pending_audio_decode_cb_)); - decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, - base::Unretained(this))); + decoder_->Decode(encrypted_buffer_, + base::Bind(&DecryptingAudioDecoderTest::DecodeDone, + base::Unretained(this))); message_loop_.RunUntilIdle(); - // Make sure the Read() on the decoder triggers a DecryptAndDecode() on the - // decryptor. + // Make sure the Decode() on the decoder triggers a DecryptAndDecode() on + // the decryptor. EXPECT_FALSE(pending_audio_decode_cb_.is_null()); } void EnterWaitingForKeyState() { - EXPECT_CALL(*demuxer_, Read(_)) - .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _)) .WillRepeatedly(RunCallback<1>(Decryptor::kNoKey, Decryptor::AudioBuffers())); - decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, - base::Unretained(this))); + decoder_->Decode(encrypted_buffer_, + base::Bind(&DecryptingAudioDecoderTest::DecodeDone, + base::Unretained(this))); message_loop_.RunUntilIdle(); } @@ -208,6 +215,16 @@ class DecryptingAudioDecoderTest : public testing::Test { } } + void AbortAllPendingCBs() { + if (!pending_init_cb_.is_null()) { + ASSERT_TRUE(pending_audio_decode_cb_.is_null()); + base::ResetAndReturn(&pending_init_cb_).Run(false); + return; + } + + AbortPendingAudioDecodeCB(); + } + void Reset() { EXPECT_CALL(*decryptor_, ResetDecoder(Decryptor::kAudio)) .WillRepeatedly(InvokeWithoutArgs( @@ -217,27 +234,36 @@ class DecryptingAudioDecoderTest : public testing::Test { message_loop_.RunUntilIdle(); } + void Stop() { + EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)) + .WillRepeatedly(InvokeWithoutArgs( + this, &DecryptingAudioDecoderTest::AbortAllPendingCBs)); + + decoder_->Stop(); + message_loop_.RunUntilIdle(); + } + MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&)); - MOCK_METHOD2(FrameReady, - void(AudioDecoder::Status, const scoped_refptr<AudioBuffer>&)); + MOCK_METHOD1(FrameReady, void(const scoped_refptr<AudioBuffer>&)); + MOCK_METHOD1(DecodeDone, void(AudioDecoder::Status)); base::MessageLoop message_loop_; scoped_ptr<DecryptingAudioDecoder> decoder_; scoped_ptr<StrictMock<MockDecryptor> > decryptor_; - scoped_ptr<StrictMock<MockDemuxerStream> > demuxer_; - MockStatisticsCB statistics_cb_; AudioDecoderConfig config_; - DemuxerStream::ReadCB pending_demuxer_read_cb_; + // Variables to help the |decryptor_| to simulate decoding delay and flushing. + int num_decrypt_and_decode_calls_; + int num_frames_in_decryptor_; + Decryptor::DecoderInitCB pending_init_cb_; Decryptor::NewKeyCB key_added_cb_; Decryptor::AudioDecodeCB pending_audio_decode_cb_; - // Constant buffer/frames to be returned by the |demuxer_| and |decryptor_|. + // Constant buffer/frames, to be used/returned by |decoder_| and |decryptor_|. scoped_refptr<DecoderBuffer> encrypted_buffer_; scoped_refptr<AudioBuffer> decoded_frame_; - scoped_refptr<AudioBuffer> end_of_stream_frame_; Decryptor::AudioBuffers decoded_frame_list_; private: @@ -251,7 +277,7 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) { // Ensure that DecryptingAudioDecoder only accepts encrypted audio. TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) { AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, - CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, false); + CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, false); InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); } @@ -272,7 +298,7 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { .WillOnce(RunCallbackIfNotNull(decryptor_.get())); AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, - CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true); + CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true); InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); } @@ -281,7 +307,7 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_NullDecryptor) { .WillRepeatedly(RunCallbackIfNotNull(static_cast<Decryptor*>(NULL))); AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32, - CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true); + CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true); InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); } @@ -296,31 +322,11 @@ TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_DecodeError) { Initialize(); - EXPECT_CALL(*demuxer_, Read(_)) - .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) .WillRepeatedly(RunCallback<1>(Decryptor::kError, Decryptor::AudioBuffers())); - ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL); -} - -// Test the case where the decryptor returns kNeedMoreData to ask for more -// buffers before it can produce a frame. -TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_NeedMoreData) { - Initialize(); - - EXPECT_CALL(*demuxer_, Read(_)) - .Times(2) - .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); - EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) - .WillOnce(RunCallback<1>(Decryptor::kNeedMoreData, - Decryptor::AudioBuffers())) - .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); - EXPECT_CALL(statistics_cb_, OnStatistics(_)) - .Times(2); - - ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_); + DecodeAndExpect(encrypted_buffer_, AudioDecoder::kDecodeError); } // Test the case where the decryptor returns multiple decoded frames. @@ -328,27 +334,27 @@ TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFrames) { Initialize(); scoped_refptr<AudioBuffer> frame_a = AudioBuffer::CreateEmptyBuffer( + config_.channel_layout(), ChannelLayoutToChannelCount(config_.channel_layout()), + kSampleRate, kFakeAudioFrameSize, - kNoTimestamp(), kNoTimestamp()); scoped_refptr<AudioBuffer> frame_b = AudioBuffer::CreateEmptyBuffer( + config_.channel_layout(), ChannelLayoutToChannelCount(config_.channel_layout()), + kSampleRate, kFakeAudioFrameSize, - kNoTimestamp(), kNoTimestamp()); decoded_frame_list_.push_back(frame_a); decoded_frame_list_.push_back(frame_b); - EXPECT_CALL(*demuxer_, Read(_)) - .WillOnce(ReturnBuffer(encrypted_buffer_)); EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); - EXPECT_CALL(statistics_cb_, OnStatistics(_)); - ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_); - ReadAndExpectFrameReadyWith(AudioDecoder::kOk, frame_a); - ReadAndExpectFrameReadyWith(AudioDecoder::kOk, frame_b); + EXPECT_CALL(*this, FrameReady(decoded_frame_)); + EXPECT_CALL(*this, FrameReady(frame_a)); + EXPECT_CALL(*this, FrameReady(frame_b)); + DecodeAndExpect(encrypted_buffer_, AudioDecoder::kOk); } // Test the case where the decryptor receives end-of-stream buffer. @@ -358,61 +364,24 @@ TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_EndOfStream) { EnterEndOfStreamState(); } -// Test aborted read on the demuxer stream. -TEST_F(DecryptingAudioDecoderTest, DemuxerRead_Aborted) { +// Test reinitializing decode with a new config +TEST_F(DecryptingAudioDecoderTest, Reinitialize_ConfigChange) { Initialize(); - // ReturnBuffer() with NULL triggers aborted demuxer read. - EXPECT_CALL(*demuxer_, Read(_)) - .WillOnce(ReturnBuffer(scoped_refptr<DecoderBuffer>())); - - ReadAndExpectFrameReadyWith(AudioDecoder::kAborted, NULL); -} - -// Test config change on the demuxer stream. -TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChange) { - Initialize(); + EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) + .Times(AtMost(1)) + .WillOnce(RunCallback<1>(true)); // The new config is different from the initial config in bits-per-channel, // channel layout and samples_per_second. AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16, - CHANNEL_LAYOUT_5_1, 88200, NULL, 0, false); + CHANNEL_LAYOUT_5_1, 88200, NULL, 0, true); EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel()); EXPECT_NE(new_config.channel_layout(), config_.channel_layout()); EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second()); - demuxer_->set_audio_decoder_config(new_config); - EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); - EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) - .WillOnce(RunCallback<1>(true)); - EXPECT_CALL(*demuxer_, Read(_)) - .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, - scoped_refptr<DecoderBuffer>())) - .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); - EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) - .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); - EXPECT_CALL(statistics_cb_, OnStatistics(_)); - - ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_); - - EXPECT_EQ(new_config.bits_per_channel(), decoder_->bits_per_channel()); - EXPECT_EQ(new_config.channel_layout(), decoder_->channel_layout()); - EXPECT_EQ(new_config.samples_per_second(), decoder_->samples_per_second()); -} - -// Test config change failure. -TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChangeFailed) { - Initialize(); - - EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); - EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) - .WillOnce(RunCallback<1>(false)); - EXPECT_CALL(*demuxer_, Read(_)) - .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, - scoped_refptr<DecoderBuffer>())) - .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); - - ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL); + ReinitializeConfigChange(new_config); + message_loop_.RunUntilIdle(); } // Test the case where the a key is added when the decryptor is in @@ -423,8 +392,8 @@ TEST_F(DecryptingAudioDecoderTest, KeyAdded_DuringWaitingForKey) { EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); - EXPECT_CALL(statistics_cb_, OnStatistics(_)); - EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_)); + EXPECT_CALL(*this, FrameReady(decoded_frame_)); + EXPECT_CALL(*this, DecodeDone(AudioDecoder::kOk)); key_added_cb_.Run(); message_loop_.RunUntilIdle(); } @@ -437,8 +406,8 @@ TEST_F(DecryptingAudioDecoderTest, KeyAdded_DruingPendingDecode) { EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); - EXPECT_CALL(statistics_cb_, OnStatistics(_)); - EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_)); + EXPECT_CALL(*this, FrameReady(decoded_frame_)); + EXPECT_CALL(*this, DecodeDone(AudioDecoder::kOk)); // The audio decode callback is returned after the correct decryption key is // added. key_added_cb_.Run(); @@ -462,118 +431,12 @@ TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterDecodedOneFrame) { Reset(); } -// Test resetting when the decoder is in kPendingDemuxerRead state and the read -// callback is returned with kOk. -TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_Ok) { - Initialize(); - EnterPendingReadState(); - - EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull())); - - Reset(); - base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kOk, - encrypted_buffer_); - message_loop_.RunUntilIdle(); -} - -// Test resetting when the decoder is in kPendingDemuxerRead state and the read -// callback is returned with kAborted. -TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_Aborted) { - Initialize(); - EnterPendingReadState(); - - // Make sure we get a NULL audio frame returned. - EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull())); - - Reset(); - base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kAborted, - NULL); - message_loop_.RunUntilIdle(); -} - -// Test resetting when the decoder is in kPendingDemuxerRead state and the read -// callback is returned with kConfigChanged. -TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_ConfigChange) { - Initialize(); - EnterPendingReadState(); - - Reset(); - - // The new config is different from the initial config in bits-per-channel, - // channel layout and samples_per_second. - AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16, - CHANNEL_LAYOUT_5_1, 88200, NULL, 0, false); - EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel()); - EXPECT_NE(new_config.channel_layout(), config_.channel_layout()); - EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second()); - - // Even during pending reset, the decoder still needs to be initialized with - // the new config. - demuxer_->set_audio_decoder_config(new_config); - EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); - EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) - .WillOnce(RunCallback<1>(true)); - EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull())); - - base::ResetAndReturn(&pending_demuxer_read_cb_) - .Run(DemuxerStream::kConfigChanged, NULL); - message_loop_.RunUntilIdle(); - - EXPECT_EQ(new_config.bits_per_channel(), decoder_->bits_per_channel()); - EXPECT_EQ(new_config.channel_layout(), decoder_->channel_layout()); - EXPECT_EQ(new_config.samples_per_second(), decoder_->samples_per_second()); -} - -// Test resetting when the decoder is in kPendingDemuxerRead state, the read -// callback is returned with kConfigChanged and the config change fails. -TEST_F(DecryptingAudioDecoderTest, Reset_DuringDemuxerRead_ConfigChangeFailed) { - Initialize(); - EnterPendingReadState(); - - Reset(); - - // Even during pending reset, the decoder still needs to be initialized with - // the new config. - EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); - EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) - .WillOnce(RunCallback<1>(false)); - EXPECT_CALL(*this, FrameReady(AudioDecoder::kDecodeError, IsNull())); - - base::ResetAndReturn(&pending_demuxer_read_cb_) - .Run(DemuxerStream::kConfigChanged, NULL); - message_loop_.RunUntilIdle(); -} - -// Test resetting when the decoder is in kPendingConfigChange state. -TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingConfigChange) { - Initialize(); - EnterNormalDecodingState(); - - EXPECT_CALL(*demuxer_, Read(_)) - .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, - scoped_refptr<DecoderBuffer>())); - EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); - EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) - .WillOnce(SaveArg<1>(&pending_init_cb_)); - - decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, - base::Unretained(this))); - message_loop_.RunUntilIdle(); - EXPECT_FALSE(pending_init_cb_.is_null()); - - EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull())); - - Reset(); - base::ResetAndReturn(&pending_init_cb_).Run(true); - message_loop_.RunUntilIdle(); -} - // Test resetting when the decoder is in kPendingDecode state. TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingDecode) { Initialize(); EnterPendingDecodeState(); - EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull())); + EXPECT_CALL(*this, DecodeDone(AudioDecoder::kAborted)); Reset(); } @@ -583,7 +446,7 @@ TEST_F(DecryptingAudioDecoderTest, Reset_DuringWaitingForKey) { Initialize(); EnterWaitingForKeyState(); - EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull())); + EXPECT_CALL(*this, DecodeDone(AudioDecoder::kAborted)); Reset(); } |