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/mock_callback.h" | 15 #include "media/base/mock_callback.h" |
16 #include "media/base/mock_filters.h" | 16 #include "media/base/mock_filters.h" |
17 #include "media/filters/decrypting_audio_decoder.h" | 17 #include "media/filters/decrypting_audio_decoder.h" |
18 #include "media/filters/ffmpeg_decoder_unittest.h" | 18 #include "media/filters/ffmpeg_decoder_unittest.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::Invoke; | |
24 using ::testing::IsNull; | 23 using ::testing::IsNull; |
25 using ::testing::ReturnRef; | 24 using ::testing::ReturnRef; |
26 using ::testing::SaveArg; | 25 using ::testing::SaveArg; |
27 using ::testing::StrictMock; | 26 using ::testing::StrictMock; |
28 | 27 |
29 namespace media { | 28 namespace media { |
30 | 29 |
31 static const int kFakeAudioFrameSize = 16; | 30 static const int kFakeAudioFrameSize = 16; |
32 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; | 31 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; |
33 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; | 32 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 | 79 |
81 MATCHER(IsEndOfStream, "") { | 80 MATCHER(IsEndOfStream, "") { |
82 return (arg->IsEndOfStream()); | 81 return (arg->IsEndOfStream()); |
83 } | 82 } |
84 | 83 |
85 } // namespace | 84 } // namespace |
86 | 85 |
87 class DecryptingAudioDecoderTest : public testing::Test { | 86 class DecryptingAudioDecoderTest : public testing::Test { |
88 public: | 87 public: |
89 DecryptingAudioDecoderTest() | 88 DecryptingAudioDecoderTest() |
90 : decoder_(new StrictMock<DecryptingAudioDecoder>( | 89 : decoder_(new DecryptingAudioDecoder( |
ddorwin
2012/11/13 01:08:49
Just curious, why did you drop StrictMock?
xhwang
2012/11/13 21:10:21
DecryptingAudioDecoder is a concrete class, not a
| |
91 base::Bind(&Identity<scoped_refptr<base::MessageLoopProxy> >, | 90 base::Bind(&Identity<scoped_refptr<base::MessageLoopProxy> >, |
92 message_loop_.message_loop_proxy()), | 91 message_loop_.message_loop_proxy()), |
93 base::Bind( | 92 base::Bind( |
94 &DecryptingAudioDecoderTest::RequestDecryptorNotification, | 93 &DecryptingAudioDecoderTest::RequestDecryptorNotification, |
95 base::Unretained(this)))), | 94 base::Unretained(this)))), |
96 decryptor_(new StrictMock<MockDecryptor>()), | 95 decryptor_(new StrictMock<MockDecryptor>()), |
97 demuxer_(new StrictMock<MockDemuxerStream>()), | 96 demuxer_(new StrictMock<MockDemuxerStream>()), |
98 encrypted_buffer_(CreateFakeEncryptedBuffer()), | 97 encrypted_buffer_(CreateFakeEncryptedBuffer()), |
99 decoded_frame_(NULL), | 98 decoded_frame_(NULL), |
100 end_of_stream_frame_(new DataBuffer(0)), | 99 end_of_stream_frame_(new DataBuffer(0)), |
101 decoded_frame_list_() { | 100 decoded_frame_list_() { |
102 // TODO(xhwang): Fix this after DataBuffer(data, size) is public. | |
103 scoped_refptr<DataBuffer> buffer = new DataBuffer(kFakeAudioFrameSize); | 101 scoped_refptr<DataBuffer> buffer = new DataBuffer(kFakeAudioFrameSize); |
104 buffer->SetDataSize(kFakeAudioFrameSize); | 102 buffer->SetDataSize(kFakeAudioFrameSize); |
ddorwin
2012/11/13 01:08:49
// Frame contains random data.
xhwang
2012/11/13 21:10:21
Done.
| |
105 decoded_frame_ = buffer; | 103 decoded_frame_ = buffer; |
ddorwin
2012/11/13 01:08:49
Do we even need the local variable |buffer|?
xhwang
2012/11/13 21:10:21
We can only call SetDataSize() on a DataBuffer, no
| |
106 decoded_frame_list_.push_back(decoded_frame_); | 104 decoded_frame_list_.push_back(decoded_frame_); |
107 } | 105 } |
108 | 106 |
109 void InitializeAndExpectStatus(const AudioDecoderConfig& config, | 107 void InitializeAndExpectStatus(const AudioDecoderConfig& config, |
110 PipelineStatus status) { | 108 PipelineStatus status) { |
111 EXPECT_CALL(*demuxer_, audio_decoder_config()) | 109 EXPECT_CALL(*demuxer_, audio_decoder_config()) |
112 .WillRepeatedly(ReturnRef(config)); | 110 .WillRepeatedly(ReturnRef(config)); |
113 | 111 |
114 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status), | 112 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status), |
115 base::Bind(&MockStatisticsCB::OnStatistics, | 113 base::Bind(&MockStatisticsCB::OnStatistics, |
116 base::Unretained(&statistics_cb_))); | 114 base::Unretained(&statistics_cb_))); |
117 message_loop_.RunAllPending(); | 115 message_loop_.RunAllPending(); |
118 } | 116 } |
119 | 117 |
120 void Initialize() { | 118 void Initialize() { |
121 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _, _)) | 119 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _, _)) |
122 .Times(AtMost(1)) | 120 .Times(AtMost(1)) |
123 .WillOnce(DoAll(RunCallback1(true), SaveArg<2>(&key_added_cb_))); | 121 .WillOnce(DoAll(RunCallback1(true), SaveArg<2>(&key_added_cb_))); |
124 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 122 EXPECT_CALL(*this, RequestDecryptorNotification(_)) |
125 .WillOnce(RunCallback0(decryptor_.get())); | 123 .WillOnce(RunCallback0(decryptor_.get())); |
126 | 124 |
127 config_.Initialize(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, | 125 AudioDecoderConfig config(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, |
128 NULL, 0, true, true); | 126 NULL, 0, true); |
127 InitializeAndExpectStatus(config, PIPELINE_OK); | |
129 | 128 |
130 InitializeAndExpectStatus(config_, PIPELINE_OK); | |
131 EXPECT_EQ(16, decoder_->bits_per_channel()); | 129 EXPECT_EQ(16, decoder_->bits_per_channel()); |
132 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, decoder_->channel_layout()); | 130 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, decoder_->channel_layout()); |
133 EXPECT_EQ(44100, decoder_->samples_per_second()); | 131 EXPECT_EQ(44100, decoder_->samples_per_second()); |
134 } | 132 } |
135 | 133 |
136 void ReadAndExpectFrameReadyWith( | 134 void ReadAndExpectFrameReadyWith( |
137 AudioDecoder::Status status, | 135 AudioDecoder::Status status, |
138 const scoped_refptr<Buffer>& audio_frame) { | 136 const scoped_refptr<Buffer>& audio_frame) { |
139 if (status != AudioDecoder::kOk) | 137 if (status != AudioDecoder::kOk) |
140 EXPECT_CALL(*this, FrameReady(status, IsNull())); | 138 EXPECT_CALL(*this, FrameReady(status, IsNull())); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 base::Unretained(this))); | 195 base::Unretained(this))); |
198 message_loop_.RunAllPending(); | 196 message_loop_.RunAllPending(); |
199 // Make sure the Read() on the decoder triggers a DecryptAndDecode() on the | 197 // Make sure the Read() on the decoder triggers a DecryptAndDecode() on the |
200 // decryptor. | 198 // decryptor. |
201 EXPECT_FALSE(pending_audio_decode_cb_.is_null()); | 199 EXPECT_FALSE(pending_audio_decode_cb_.is_null()); |
202 } | 200 } |
203 | 201 |
204 void EnterWaitingForKeyState() { | 202 void EnterWaitingForKeyState() { |
205 EXPECT_CALL(*demuxer_, Read(_)) | 203 EXPECT_CALL(*demuxer_, Read(_)) |
206 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); | 204 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); |
207 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) | 205 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _)) |
208 .WillRepeatedly(RunCallback2(Decryptor::kNoKey, | 206 .WillRepeatedly(RunCallback2(Decryptor::kNoKey, |
209 Decryptor::AudioBuffers())); | 207 Decryptor::AudioBuffers())); |
210 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, | 208 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, |
211 base::Unretained(this))); | 209 base::Unretained(this))); |
212 message_loop_.RunAllPending(); | 210 message_loop_.RunAllPending(); |
213 } | 211 } |
214 | 212 |
215 void AbortPendingAudioDecodeCB() { | 213 void AbortPendingAudioDecodeCB() { |
216 if (!pending_audio_decode_cb_.is_null()) { | 214 if (!pending_audio_decode_cb_.is_null()) { |
217 base::ResetAndReturn(&pending_audio_decode_cb_).Run( | 215 base::ResetAndReturn(&pending_audio_decode_cb_).Run( |
(...skipping 10 matching lines...) Expand all Loading... | |
228 message_loop_.RunAllPending(); | 226 message_loop_.RunAllPending(); |
229 } | 227 } |
230 | 228 |
231 MOCK_METHOD1(RequestDecryptorNotification, | 229 MOCK_METHOD1(RequestDecryptorNotification, |
232 void(const DecryptingAudioDecoder::DecryptorNotificationCB&)); | 230 void(const DecryptingAudioDecoder::DecryptorNotificationCB&)); |
233 | 231 |
234 MOCK_METHOD2(FrameReady, void(AudioDecoder::Status, | 232 MOCK_METHOD2(FrameReady, void(AudioDecoder::Status, |
235 const scoped_refptr<Buffer>&)); | 233 const scoped_refptr<Buffer>&)); |
236 | 234 |
237 MessageLoop message_loop_; | 235 MessageLoop message_loop_; |
238 scoped_refptr<StrictMock<DecryptingAudioDecoder> > decoder_; | 236 scoped_refptr<DecryptingAudioDecoder> decoder_; |
239 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; | 237 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; |
240 scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_; | 238 scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_; |
241 MockStatisticsCB statistics_cb_; | 239 MockStatisticsCB statistics_cb_; |
242 AudioDecoderConfig config_; | |
243 | 240 |
244 DemuxerStream::ReadCB pending_demuxer_read_cb_; | 241 DemuxerStream::ReadCB pending_demuxer_read_cb_; |
245 Decryptor::DecoderInitCB pending_init_cb_; | 242 Decryptor::DecoderInitCB pending_init_cb_; |
246 Decryptor::KeyAddedCB key_added_cb_; | 243 Decryptor::KeyAddedCB key_added_cb_; |
247 Decryptor::AudioDecodeCB pending_audio_decode_cb_; | 244 Decryptor::AudioDecodeCB pending_audio_decode_cb_; |
248 | 245 |
249 // Constant buffer/frames to be returned by the |demuxer_| and |decryptor_|. | 246 // Constant buffer/frames to be returned by the |demuxer_| and |decryptor_|. |
250 scoped_refptr<DecoderBuffer> encrypted_buffer_; | 247 scoped_refptr<DecoderBuffer> encrypted_buffer_; |
251 scoped_refptr<Buffer> decoded_frame_; | 248 scoped_refptr<Buffer> decoded_frame_; |
252 scoped_refptr<Buffer> end_of_stream_frame_; | 249 scoped_refptr<Buffer> end_of_stream_frame_; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 | 480 |
484 EXPECT_CALL(*demuxer_, Read(_)) | 481 EXPECT_CALL(*demuxer_, Read(_)) |
485 .WillOnce(ReturnConfigChanged()); | 482 .WillOnce(ReturnConfigChanged()); |
486 | 483 |
487 // TODO(xhwang): Update this test when kConfigChanged is supported in | 484 // TODO(xhwang): Update this test when kConfigChanged is supported in |
488 // DecryptingAudioDecoder. | 485 // DecryptingAudioDecoder. |
489 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL); | 486 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL); |
490 } | 487 } |
491 | 488 |
492 } // namespace media | 489 } // namespace media |
OLD | NEW |