Chromium Code Reviews| 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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "media/base/audio_buffer.h" | 11 #include "media/base/audio_buffer.h" |
| 12 #include "media/base/buffers.h" | 12 #include "media/base/buffers.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::Assign; | |
| 22 using ::testing::AtMost; | 23 using ::testing::AtMost; |
| 23 using ::testing::IsNull; | 24 using ::testing::IsNull; |
| 24 using ::testing::SaveArg; | 25 using ::testing::SaveArg; |
| 25 using ::testing::StrictMock; | 26 using ::testing::StrictMock; |
| 26 | 27 |
| 27 namespace media { | 28 namespace media { |
| 28 | 29 |
| 29 static const int kSampleRate = 44100; | 30 static const int kSampleRate = 44100; |
| 30 | 31 |
| 31 // Make sure the kFakeAudioFrameSize is a valid frame size for all audio decoder | 32 // Make sure the kFakeAudioFrameSize is a valid frame size for all audio decoder |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 52 | 53 |
| 53 ACTION_P(ReturnBuffer, buffer) { | 54 ACTION_P(ReturnBuffer, buffer) { |
| 54 return buffer; | 55 return buffer; |
| 55 } | 56 } |
| 56 | 57 |
| 57 ACTION_P(RunCallbackIfNotNull, param) { | 58 ACTION_P(RunCallbackIfNotNull, param) { |
| 58 if (!arg0.is_null()) | 59 if (!arg0.is_null()) |
| 59 arg0.Run(param); | 60 arg0.Run(param); |
| 60 } | 61 } |
| 61 | 62 |
| 62 // Mock action which we use to repeatedly call ReadAndExpectFrameReadyWith() if | |
| 63 // we get kNotEnoughData from a Decode() call to |decoder_|. | |
| 64 ACTION_P2(CallExpectFrameReadyMoreData, test, buffer) { | |
| 65 test->ReadAndExpectFrameReadyWith( | |
| 66 CreateFakeEncryptedBuffer(), AudioDecoder::kNotEnoughData, buffer); | |
| 67 } | |
| 68 | |
| 69 MATCHER(IsEndOfStream, "end of stream") { | 63 MATCHER(IsEndOfStream, "end of stream") { |
| 70 return (arg->end_of_stream()); | 64 return (arg->end_of_stream()); |
| 71 } | 65 } |
| 72 | 66 |
| 73 } // namespace | 67 } // namespace |
| 74 | 68 |
| 75 class DecryptingAudioDecoderTest : public testing::Test { | 69 class DecryptingAudioDecoderTest : public testing::Test { |
| 76 public: | 70 public: |
| 77 DecryptingAudioDecoderTest() | 71 DecryptingAudioDecoderTest() |
| 78 : decoder_(new DecryptingAudioDecoder( | 72 : decoder_(new DecryptingAudioDecoder( |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 100 int channels = ChannelLayoutToChannelCount(config.channel_layout()); | 94 int channels = ChannelLayoutToChannelCount(config.channel_layout()); |
| 101 if (channels < 0) | 95 if (channels < 0) |
| 102 channels = 0; | 96 channels = 0; |
| 103 decoded_frame_ = AudioBuffer::CreateEmptyBuffer(config.channel_layout(), | 97 decoded_frame_ = AudioBuffer::CreateEmptyBuffer(config.channel_layout(), |
| 104 channels, | 98 channels, |
| 105 kSampleRate, | 99 kSampleRate, |
| 106 kFakeAudioFrameSize, | 100 kFakeAudioFrameSize, |
| 107 kNoTimestamp()); | 101 kNoTimestamp()); |
| 108 decoded_frame_list_.push_back(decoded_frame_); | 102 decoded_frame_list_.push_back(decoded_frame_); |
| 109 | 103 |
| 110 decoder_->Initialize(config, NewExpectedStatusCB(status)); | 104 decoder_->Initialize(config, NewExpectedStatusCB(status), |
| 105 base::Bind(&DecryptingAudioDecoderTest::FrameReady, | |
| 106 base::Unretained(this))); | |
| 111 message_loop_.RunUntilIdle(); | 107 message_loop_.RunUntilIdle(); |
| 112 } | 108 } |
| 113 | 109 |
| 114 void Initialize() { | 110 void Initialize() { |
| 115 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 111 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
| 116 .Times(AtMost(1)) | 112 .Times(AtMost(1)) |
| 117 .WillOnce(RunCallback<1>(true)); | 113 .WillOnce(RunCallback<1>(true)); |
| 118 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 114 EXPECT_CALL(*this, RequestDecryptorNotification(_)) |
| 119 .WillOnce(RunCallbackIfNotNull(decryptor_.get())); | 115 .WillOnce(RunCallbackIfNotNull(decryptor_.get())); |
| 120 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) | 116 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) |
| 121 .WillOnce(SaveArg<1>(&key_added_cb_)); | 117 .WillOnce(SaveArg<1>(&key_added_cb_)); |
| 122 | 118 |
| 123 config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32, | 119 config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32, |
| 124 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true, true, | 120 CHANNEL_LAYOUT_STEREO, kSampleRate, NULL, 0, true, true, |
| 125 base::TimeDelta(), 0); | 121 base::TimeDelta(), 0); |
| 126 InitializeAndExpectStatus(config_, PIPELINE_OK); | 122 InitializeAndExpectStatus(config_, PIPELINE_OK); |
| 127 } | 123 } |
| 128 | 124 |
| 129 void Reinitialize() { | 125 void Reinitialize() { |
| 130 ReinitializeConfigChange(config_); | 126 ReinitializeConfigChange(config_); |
| 131 } | 127 } |
| 132 | 128 |
| 133 void ReinitializeConfigChange(const AudioDecoderConfig& new_config) { | 129 void ReinitializeConfigChange(const AudioDecoderConfig& new_config) { |
| 134 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); | 130 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); |
| 135 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) | 131 EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
| 136 .WillOnce(RunCallback<1>(true)); | 132 .WillOnce(RunCallback<1>(true)); |
| 137 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) | 133 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) |
| 138 .WillOnce(SaveArg<1>(&key_added_cb_)); | 134 .WillOnce(SaveArg<1>(&key_added_cb_)); |
| 139 decoder_->Initialize(new_config, NewExpectedStatusCB(PIPELINE_OK)); | 135 decoder_->Initialize(new_config, NewExpectedStatusCB(PIPELINE_OK), |
| 136 base::Bind(&DecryptingAudioDecoderTest::FrameReady, | |
| 137 base::Unretained(this))); | |
| 140 } | 138 } |
| 141 | 139 |
| 142 void ReadAndExpectFrameReadyWith( | 140 void ReadAndExpectFrameReadyWith( |
|
xhwang
2014/06/05 21:53:49
This should really be renamed to DecodeAndExpect..
Sergey Ulanov
2014/06/06 22:49:40
Done.
| |
| 143 scoped_refptr<DecoderBuffer> input, | 141 scoped_refptr<DecoderBuffer> input, |
| 144 AudioDecoder::Status status, | 142 AudioDecoder::Status status, |
| 145 const scoped_refptr<AudioBuffer>& audio_frame) { | 143 const Decryptor::AudioBuffers& audio_frames) { |
| 146 | 144 for (Decryptor::AudioBuffers::const_iterator it = audio_frames.begin(); |
| 147 const scoped_refptr<AudioBuffer>& buffer = decoder_->GetDecodeOutput(); | 145 it != audio_frames.end(); ++it) { |
| 148 | 146 if ((*it)->end_of_stream()) { |
| 149 if (buffer) { | 147 EXPECT_CALL(*this, FrameReady(IsEndOfStream())); |
| 150 EXPECT_EQ(audio_frame, buffer); | 148 } else { |
| 151 EXPECT_EQ(status, AudioDecoder::kOk); | 149 EXPECT_CALL(*this, FrameReady(*it)); |
| 152 return; | 150 } |
| 153 } | 151 } |
| 154 | 152 EXPECT_CALL(*this, DecodeDone(status)); |
| 155 if (status == AudioDecoder::kNotEnoughData) | |
| 156 // Keep calling again to give it more data if we get kNotEnoughData. | |
| 157 EXPECT_CALL(*this, FrameReady(status, scoped_refptr<AudioBuffer>(NULL))). | |
| 158 WillRepeatedly(CallExpectFrameReadyMoreData(this, audio_frame)); | |
| 159 else if (status != AudioDecoder::kOk) | |
| 160 EXPECT_CALL(*this, FrameReady(status, IsNull())); | |
| 161 else if (audio_frame->end_of_stream()) | |
| 162 EXPECT_CALL(*this, FrameReady(status, IsEndOfStream())); | |
| 163 else | |
| 164 EXPECT_CALL(*this, FrameReady(status, audio_frame)); | |
| 165 | 153 |
| 166 decoder_->Decode(input, | 154 decoder_->Decode(input, |
| 167 base::Bind(&DecryptingAudioDecoderTest::FrameReady, | 155 base::Bind(&DecryptingAudioDecoderTest::DecodeDone, |
| 168 base::Unretained(this))); | 156 base::Unretained(this))); |
| 169 message_loop_.RunUntilIdle(); | 157 message_loop_.RunUntilIdle(); |
| 170 } | 158 } |
| 171 | 159 |
| 172 // Sets up expectations and actions to put DecryptingAudioDecoder in an | 160 // Sets up expectations and actions to put DecryptingAudioDecoder in an |
| 173 // active normal decoding state. | 161 // active normal decoding state. |
| 174 void EnterNormalDecodingState() { | 162 void EnterNormalDecodingState() { |
| 175 Decryptor::AudioBuffers end_of_stream_frames_(1, end_of_stream_frame_); | 163 Decryptor::AudioBuffers end_of_stream_frames_(1, end_of_stream_frame_); |
| 176 | 164 |
| 177 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) | 165 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
| 178 .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)) | 166 .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)) |
| 179 .WillRepeatedly(RunCallback<1>(Decryptor::kNeedMoreData, | 167 .WillRepeatedly(RunCallback<1>(Decryptor::kNeedMoreData, |
| 180 Decryptor::AudioBuffers())); | 168 Decryptor::AudioBuffers())); |
| 181 | 169 |
| 182 ReadAndExpectFrameReadyWith( | 170 ReadAndExpectFrameReadyWith(encrypted_buffer_, AudioDecoder::kOk, |
| 183 encrypted_buffer_, AudioDecoder::kOk, decoded_frame_); | 171 Decryptor::AudioBuffers(1, decoded_frame_)); |
| 184 } | 172 } |
| 185 | 173 |
| 186 // Sets up expectations and actions to put DecryptingAudioDecoder in an end | 174 // Sets up expectations and actions to put DecryptingAudioDecoder in an end |
| 187 // of stream state. This function must be called after | 175 // of stream state. This function must be called after |
| 188 // EnterNormalDecodingState() to work. | 176 // EnterNormalDecodingState() to work. |
| 189 void EnterEndOfStreamState() { | 177 void EnterEndOfStreamState() { |
| 190 ReadAndExpectFrameReadyWith(DecoderBuffer::CreateEOSBuffer(), | 178 ReadAndExpectFrameReadyWith( |
| 191 AudioDecoder::kOk, | 179 DecoderBuffer::CreateEOSBuffer(), AudioDecoder::kOk, |
| 192 end_of_stream_frame_); | 180 Decryptor::AudioBuffers(1, end_of_stream_frame_)); |
| 193 } | 181 } |
| 194 | 182 |
| 195 // Make the audio decode callback pending by saving and not firing it. | 183 // Make the audio decode callback pending by saving and not firing it. |
| 196 void EnterPendingDecodeState() { | 184 void EnterPendingDecodeState() { |
| 197 EXPECT_TRUE(pending_audio_decode_cb_.is_null()); | 185 EXPECT_TRUE(pending_audio_decode_cb_.is_null()); |
| 198 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _)) | 186 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _)) |
| 199 .WillOnce(SaveArg<1>(&pending_audio_decode_cb_)); | 187 .WillOnce(SaveArg<1>(&pending_audio_decode_cb_)); |
| 200 | 188 |
| 201 decoder_->Decode(encrypted_buffer_, | 189 decoder_->Decode(encrypted_buffer_, |
| 202 base::Bind(&DecryptingAudioDecoderTest::FrameReady, | 190 base::Bind(&DecryptingAudioDecoderTest::DecodeDone, |
| 203 base::Unretained(this))); | 191 base::Unretained(this))); |
| 204 message_loop_.RunUntilIdle(); | 192 message_loop_.RunUntilIdle(); |
| 205 // Make sure the Decode() on the decoder triggers a DecryptAndDecode() on | 193 // Make sure the Decode() on the decoder triggers a DecryptAndDecode() on |
| 206 // the decryptor. | 194 // the decryptor. |
| 207 EXPECT_FALSE(pending_audio_decode_cb_.is_null()); | 195 EXPECT_FALSE(pending_audio_decode_cb_.is_null()); |
| 208 } | 196 } |
| 209 | 197 |
| 210 void EnterWaitingForKeyState() { | 198 void EnterWaitingForKeyState() { |
| 211 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _)) | 199 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _)) |
| 212 .WillRepeatedly(RunCallback<1>(Decryptor::kNoKey, | 200 .WillRepeatedly(RunCallback<1>(Decryptor::kNoKey, |
| 213 Decryptor::AudioBuffers())); | 201 Decryptor::AudioBuffers())); |
| 214 decoder_->Decode(encrypted_buffer_, | 202 decoder_->Decode(encrypted_buffer_, |
| 215 base::Bind(&DecryptingAudioDecoderTest::FrameReady, | 203 base::Bind(&DecryptingAudioDecoderTest::DecodeDone, |
| 216 base::Unretained(this))); | 204 base::Unretained(this))); |
| 217 message_loop_.RunUntilIdle(); | 205 message_loop_.RunUntilIdle(); |
| 218 } | 206 } |
| 219 | 207 |
| 220 void AbortPendingAudioDecodeCB() { | 208 void AbortPendingAudioDecodeCB() { |
| 221 if (!pending_audio_decode_cb_.is_null()) { | 209 if (!pending_audio_decode_cb_.is_null()) { |
| 222 base::ResetAndReturn(&pending_audio_decode_cb_).Run( | 210 base::ResetAndReturn(&pending_audio_decode_cb_).Run( |
| 223 Decryptor::kSuccess, Decryptor::AudioBuffers()); | 211 Decryptor::kSuccess, Decryptor::AudioBuffers()); |
| 224 } | 212 } |
| 225 } | 213 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 247 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)) | 235 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)) |
| 248 .WillRepeatedly(InvokeWithoutArgs( | 236 .WillRepeatedly(InvokeWithoutArgs( |
| 249 this, &DecryptingAudioDecoderTest::AbortAllPendingCBs)); | 237 this, &DecryptingAudioDecoderTest::AbortAllPendingCBs)); |
| 250 | 238 |
| 251 decoder_->Stop(); | 239 decoder_->Stop(); |
| 252 message_loop_.RunUntilIdle(); | 240 message_loop_.RunUntilIdle(); |
| 253 } | 241 } |
| 254 | 242 |
| 255 MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&)); | 243 MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&)); |
| 256 | 244 |
| 257 MOCK_METHOD2(FrameReady, | 245 MOCK_METHOD1(FrameReady, void(const scoped_refptr<AudioBuffer>&)); |
| 258 void(AudioDecoder::Status, const scoped_refptr<AudioBuffer>&)); | 246 MOCK_METHOD1(DecodeDone, void(AudioDecoder::Status)); |
| 259 | 247 |
| 260 base::MessageLoop message_loop_; | 248 base::MessageLoop message_loop_; |
| 261 scoped_ptr<DecryptingAudioDecoder> decoder_; | 249 scoped_ptr<DecryptingAudioDecoder> decoder_; |
| 262 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; | 250 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; |
| 263 AudioDecoderConfig config_; | 251 AudioDecoderConfig config_; |
| 264 | 252 |
| 265 Decryptor::DecoderInitCB pending_init_cb_; | 253 Decryptor::DecoderInitCB pending_init_cb_; |
| 266 Decryptor::NewKeyCB key_added_cb_; | 254 Decryptor::NewKeyCB key_added_cb_; |
| 267 Decryptor::AudioDecodeCB pending_audio_decode_cb_; | 255 Decryptor::AudioDecodeCB pending_audio_decode_cb_; |
| 268 | 256 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 // Test the case where the decryptor returns error when doing decrypt and | 314 // Test the case where the decryptor returns error when doing decrypt and |
| 327 // decode. | 315 // decode. |
| 328 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_DecodeError) { | 316 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_DecodeError) { |
| 329 Initialize(); | 317 Initialize(); |
| 330 | 318 |
| 331 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) | 319 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
| 332 .WillRepeatedly(RunCallback<1>(Decryptor::kError, | 320 .WillRepeatedly(RunCallback<1>(Decryptor::kError, |
| 333 Decryptor::AudioBuffers())); | 321 Decryptor::AudioBuffers())); |
| 334 | 322 |
| 335 ReadAndExpectFrameReadyWith( | 323 ReadAndExpectFrameReadyWith( |
| 336 encrypted_buffer_, AudioDecoder::kDecodeError, NULL); | 324 encrypted_buffer_, AudioDecoder::kDecodeError, Decryptor::AudioBuffers()); |
| 337 } | 325 } |
| 338 | 326 |
| 339 // Test the case where the decryptor returns kNeedMoreData to ask for more | 327 // Test the case where the decryptor returns kNeedMoreData to ask for more |
| 340 // buffers before it can produce a frame. | 328 // buffers before it can produce a frame. |
| 341 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_NeedMoreData) { | 329 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_NeedMoreData) { |
| 342 Initialize(); | 330 Initialize(); |
| 343 | 331 |
| 344 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) | 332 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
| 345 .WillOnce(RunCallback<1>(Decryptor::kNeedMoreData, | 333 .WillOnce(RunCallback<1>(Decryptor::kNeedMoreData, |
| 346 Decryptor::AudioBuffers())) | 334 Decryptor::AudioBuffers())) |
| 347 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); | 335 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); |
| 348 | 336 |
| 349 // We expect it to eventually return kOk, with any number of returns of | 337 // We expect it to eventually return kOk, with any number of returns of |
| 350 // kNotEnoughData beforehand. | 338 // kNotEnoughData beforehand. |
| 351 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_)); | 339 bool frame_delivered = false; |
| 352 ReadAndExpectFrameReadyWith( | 340 EXPECT_CALL(*this, FrameReady(decoded_frame_)) |
| 353 encrypted_buffer_, AudioDecoder::kNotEnoughData, decoded_frame_); | 341 .WillOnce(Assign(&frame_delivered, true)); |
| 342 | |
| 343 while (!frame_delivered) { | |
| 344 ASSERT_NO_FATAL_FAILURE(ReadAndExpectFrameReadyWith( | |
| 345 encrypted_buffer_, AudioDecoder::kOk, Decryptor::AudioBuffers())); | |
| 346 } | |
| 354 } | 347 } |
| 355 | 348 |
| 356 // Test the case where the decryptor returns multiple decoded frames. | 349 // Test the case where the decryptor returns multiple decoded frames. |
| 357 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFrames) { | 350 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFrames) { |
| 358 Initialize(); | 351 Initialize(); |
| 359 | 352 |
| 360 scoped_refptr<AudioBuffer> frame_a = AudioBuffer::CreateEmptyBuffer( | 353 scoped_refptr<AudioBuffer> frame_a = AudioBuffer::CreateEmptyBuffer( |
| 361 config_.channel_layout(), | 354 config_.channel_layout(), |
| 362 ChannelLayoutToChannelCount(config_.channel_layout()), | 355 ChannelLayoutToChannelCount(config_.channel_layout()), |
| 363 kSampleRate, | 356 kSampleRate, |
| 364 kFakeAudioFrameSize, | 357 kFakeAudioFrameSize, |
| 365 kNoTimestamp()); | 358 kNoTimestamp()); |
| 366 scoped_refptr<AudioBuffer> frame_b = AudioBuffer::CreateEmptyBuffer( | 359 scoped_refptr<AudioBuffer> frame_b = AudioBuffer::CreateEmptyBuffer( |
| 367 config_.channel_layout(), | 360 config_.channel_layout(), |
| 368 ChannelLayoutToChannelCount(config_.channel_layout()), | 361 ChannelLayoutToChannelCount(config_.channel_layout()), |
| 369 kSampleRate, | 362 kSampleRate, |
| 370 kFakeAudioFrameSize, | 363 kFakeAudioFrameSize, |
| 371 kNoTimestamp()); | 364 kNoTimestamp()); |
| 372 decoded_frame_list_.push_back(frame_a); | 365 decoded_frame_list_.push_back(frame_a); |
| 373 decoded_frame_list_.push_back(frame_b); | 366 decoded_frame_list_.push_back(frame_b); |
| 374 | 367 |
| 375 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) | 368 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
| 376 .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); | 369 .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); |
| 377 | 370 |
| 378 ReadAndExpectFrameReadyWith( | 371 Decryptor::AudioBuffers buffers; |
| 379 encrypted_buffer_, AudioDecoder::kOk, decoded_frame_); | 372 buffers.push_back(decoded_frame_); |
| 380 ReadAndExpectFrameReadyWith(encrypted_buffer_, AudioDecoder::kOk, frame_a); | 373 buffers.push_back(frame_a); |
| 381 ReadAndExpectFrameReadyWith(encrypted_buffer_, AudioDecoder::kOk, frame_b); | 374 buffers.push_back(frame_b); |
| 375 ReadAndExpectFrameReadyWith(encrypted_buffer_, AudioDecoder::kOk, buffers); | |
| 382 } | 376 } |
| 383 | 377 |
| 384 // Test the case where the decryptor receives end-of-stream buffer. | 378 // Test the case where the decryptor receives end-of-stream buffer. |
| 385 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_EndOfStream) { | 379 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_EndOfStream) { |
| 386 Initialize(); | 380 Initialize(); |
| 387 EnterNormalDecodingState(); | 381 EnterNormalDecodingState(); |
| 388 EnterEndOfStreamState(); | 382 EnterEndOfStreamState(); |
| 389 } | 383 } |
| 390 | 384 |
| 391 // Test reinitializing decode with a new config | 385 // Test reinitializing decode with a new config |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 409 } | 403 } |
| 410 | 404 |
| 411 // Test the case where the a key is added when the decryptor is in | 405 // Test the case where the a key is added when the decryptor is in |
| 412 // kWaitingForKey state. | 406 // kWaitingForKey state. |
| 413 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DuringWaitingForKey) { | 407 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DuringWaitingForKey) { |
| 414 Initialize(); | 408 Initialize(); |
| 415 EnterWaitingForKeyState(); | 409 EnterWaitingForKeyState(); |
| 416 | 410 |
| 417 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) | 411 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
| 418 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); | 412 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); |
| 419 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_)); | 413 EXPECT_CALL(*this, FrameReady(decoded_frame_)); |
| 414 EXPECT_CALL(*this, DecodeDone(AudioDecoder::kOk)); | |
| 420 key_added_cb_.Run(); | 415 key_added_cb_.Run(); |
| 421 message_loop_.RunUntilIdle(); | 416 message_loop_.RunUntilIdle(); |
| 422 } | 417 } |
| 423 | 418 |
| 424 // Test the case where the a key is added when the decryptor is in | 419 // Test the case where the a key is added when the decryptor is in |
| 425 // kPendingDecode state. | 420 // kPendingDecode state. |
| 426 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DruingPendingDecode) { | 421 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DruingPendingDecode) { |
| 427 Initialize(); | 422 Initialize(); |
| 428 EnterPendingDecodeState(); | 423 EnterPendingDecodeState(); |
| 429 | 424 |
| 430 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) | 425 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
| 431 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); | 426 .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); |
| 432 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_)); | 427 EXPECT_CALL(*this, FrameReady(decoded_frame_)); |
| 428 EXPECT_CALL(*this, DecodeDone(AudioDecoder::kOk)); | |
| 433 // The audio decode callback is returned after the correct decryption key is | 429 // The audio decode callback is returned after the correct decryption key is |
| 434 // added. | 430 // added. |
| 435 key_added_cb_.Run(); | 431 key_added_cb_.Run(); |
| 436 base::ResetAndReturn(&pending_audio_decode_cb_).Run( | 432 base::ResetAndReturn(&pending_audio_decode_cb_).Run( |
| 437 Decryptor::kNoKey, Decryptor::AudioBuffers()); | 433 Decryptor::kNoKey, Decryptor::AudioBuffers()); |
| 438 message_loop_.RunUntilIdle(); | 434 message_loop_.RunUntilIdle(); |
| 439 } | 435 } |
| 440 | 436 |
| 441 // Test resetting when the decoder is in kIdle state but has not decoded any | 437 // Test resetting when the decoder is in kIdle state but has not decoded any |
| 442 // frame. | 438 // frame. |
| 443 TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterInitialization) { | 439 TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterInitialization) { |
| 444 Initialize(); | 440 Initialize(); |
| 445 Reset(); | 441 Reset(); |
| 446 } | 442 } |
| 447 | 443 |
| 448 // Test resetting when the decoder is in kIdle state after it has decoded one | 444 // Test resetting when the decoder is in kIdle state after it has decoded one |
| 449 // frame. | 445 // frame. |
| 450 TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterDecodedOneFrame) { | 446 TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterDecodedOneFrame) { |
| 451 Initialize(); | 447 Initialize(); |
| 452 EnterNormalDecodingState(); | 448 EnterNormalDecodingState(); |
| 453 Reset(); | 449 Reset(); |
| 454 } | 450 } |
| 455 | 451 |
| 456 // Test resetting when the decoder is in kPendingDecode state. | 452 // Test resetting when the decoder is in kPendingDecode state. |
| 457 TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingDecode) { | 453 TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingDecode) { |
| 458 Initialize(); | 454 Initialize(); |
| 459 EnterPendingDecodeState(); | 455 EnterPendingDecodeState(); |
| 460 | 456 |
| 461 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull())); | 457 EXPECT_CALL(*this, DecodeDone(AudioDecoder::kAborted)); |
| 462 | 458 |
| 463 Reset(); | 459 Reset(); |
| 464 } | 460 } |
| 465 | 461 |
| 466 // Test resetting when the decoder is in kWaitingForKey state. | 462 // Test resetting when the decoder is in kWaitingForKey state. |
| 467 TEST_F(DecryptingAudioDecoderTest, Reset_DuringWaitingForKey) { | 463 TEST_F(DecryptingAudioDecoderTest, Reset_DuringWaitingForKey) { |
| 468 Initialize(); | 464 Initialize(); |
| 469 EnterWaitingForKeyState(); | 465 EnterWaitingForKeyState(); |
| 470 | 466 |
| 471 EXPECT_CALL(*this, FrameReady(AudioDecoder::kAborted, IsNull())); | 467 EXPECT_CALL(*this, DecodeDone(AudioDecoder::kAborted)); |
| 472 | 468 |
| 473 Reset(); | 469 Reset(); |
| 474 } | 470 } |
| 475 | 471 |
| 476 // Test resetting when the decoder has hit end of stream and is in | 472 // Test resetting when the decoder has hit end of stream and is in |
| 477 // kDecodeFinished state. | 473 // kDecodeFinished state. |
| 478 TEST_F(DecryptingAudioDecoderTest, Reset_AfterDecodeFinished) { | 474 TEST_F(DecryptingAudioDecoderTest, Reset_AfterDecodeFinished) { |
| 479 Initialize(); | 475 Initialize(); |
| 480 EnterNormalDecodingState(); | 476 EnterNormalDecodingState(); |
| 481 EnterEndOfStreamState(); | 477 EnterEndOfStreamState(); |
| 482 Reset(); | 478 Reset(); |
| 483 } | 479 } |
| 484 | 480 |
| 485 // Test resetting after the decoder has been reset. | 481 // Test resetting after the decoder has been reset. |
| 486 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { | 482 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { |
| 487 Initialize(); | 483 Initialize(); |
| 488 EnterNormalDecodingState(); | 484 EnterNormalDecodingState(); |
| 489 Reset(); | 485 Reset(); |
| 490 Reset(); | 486 Reset(); |
| 491 } | 487 } |
| 492 | 488 |
| 493 } // namespace media | 489 } // namespace media |
| OLD | NEW |