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" |
| 12 #include "media/base/data_buffer.h" |
11 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
12 #include "media/base/decrypt_config.h" | 14 #include "media/base/decrypt_config.h" |
13 #include "media/base/mock_callback.h" | 15 #include "media/base/mock_callback.h" |
14 #include "media/base/mock_filters.h" | 16 #include "media/base/mock_filters.h" |
15 #include "media/base/video_frame.h" | 17 #include "media/filters/decrypting_audio_decoder.h" |
16 #include "media/filters/decrypting_video_decoder.h" | |
17 #include "media/filters/ffmpeg_decoder_unittest.h" | 18 #include "media/filters/ffmpeg_decoder_unittest.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 | 20 |
20 using ::testing::_; | 21 using ::testing::_; |
21 using ::testing::AtMost; | 22 using ::testing::AtMost; |
22 using ::testing::Invoke; | 23 using ::testing::Invoke; |
23 using ::testing::IsNull; | 24 using ::testing::IsNull; |
24 using ::testing::ReturnRef; | 25 using ::testing::ReturnRef; |
25 using ::testing::SaveArg; | 26 using ::testing::SaveArg; |
26 using ::testing::StrictMock; | 27 using ::testing::StrictMock; |
27 | 28 |
28 namespace media { | 29 namespace media { |
29 | 30 |
30 static const VideoFrame::Format kVideoFormat = VideoFrame::YV12; | |
31 static const gfx::Size kCodedSize(320, 240); | 31 static const gfx::Size kCodedSize(320, 240); |
32 static const gfx::Rect kVisibleRect(320, 240); | 32 static const gfx::Rect kVisibleRect(320, 240); |
33 static const gfx::Size kNaturalSize(320, 240); | 33 static const gfx::Size kNaturalSize(320, 240); |
34 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; | 34 static const uint8 kFakeKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; |
35 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; | 35 static const uint8 kFakeIv[DecryptConfig::kDecryptionKeySize] = { 0 }; |
| 36 static const int kFakeAudioFrameSize = 16; |
36 | 37 |
37 // Create a fake non-empty encrypted buffer. | 38 // Create a fake non-empty encrypted buffer. |
38 static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() { | 39 static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() { |
39 const int buffer_size = 16; // Need a non-empty buffer; | 40 const int buffer_size = 16; // Need a non-empty buffer; |
40 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(buffer_size)); | 41 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(buffer_size)); |
41 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( | 42 buffer->SetDecryptConfig(scoped_ptr<DecryptConfig>(new DecryptConfig( |
42 std::string(reinterpret_cast<const char*>(kFakeKeyId), | 43 std::string(reinterpret_cast<const char*>(kFakeKeyId), |
43 arraysize(kFakeKeyId)), | 44 arraysize(kFakeKeyId)), |
44 std::string(reinterpret_cast<const char*>(kFakeIv), arraysize(kFakeIv)), | 45 std::string(reinterpret_cast<const char*>(kFakeIv), arraysize(kFakeIv)), |
45 0, | 46 0, |
(...skipping 22 matching lines...) Expand all Loading... |
68 } | 69 } |
69 | 70 |
70 ACTION_P2(ResetAndRunCallback, callback, param) { | 71 ACTION_P2(ResetAndRunCallback, callback, param) { |
71 base::ResetAndReturn(callback).Run(param); | 72 base::ResetAndReturn(callback).Run(param); |
72 } | 73 } |
73 | 74 |
74 MATCHER(IsNullCallback, "") { | 75 MATCHER(IsNullCallback, "") { |
75 return (arg.is_null()); | 76 return (arg.is_null()); |
76 } | 77 } |
77 | 78 |
78 class DecryptingVideoDecoderTest : public testing::Test { | 79 class DecryptingAudioDecoderTest : public testing::Test { |
79 public: | 80 public: |
80 DecryptingVideoDecoderTest() | 81 DecryptingAudioDecoderTest() |
81 : decoder_(new StrictMock<DecryptingVideoDecoder>( | 82 : decoder_(new StrictMock<DecryptingAudioDecoder>( |
82 base::Bind(&Identity<scoped_refptr<base::MessageLoopProxy> >, | 83 base::Bind(&Identity<scoped_refptr<base::MessageLoopProxy> >, |
83 message_loop_.message_loop_proxy()), | 84 message_loop_.message_loop_proxy()), |
84 base::Bind( | 85 base::Bind( |
85 &DecryptingVideoDecoderTest::RequestDecryptorNotification, | 86 &DecryptingAudioDecoderTest::RequestDecryptorNotification, |
86 base::Unretained(this)))), | 87 base::Unretained(this)))), |
87 decryptor_(new StrictMock<MockDecryptor>()), | 88 decryptor_(new StrictMock<MockDecryptor>()), |
88 demuxer_(new StrictMock<MockDemuxerStream>()), | 89 demuxer_(new StrictMock<MockDemuxerStream>()), |
89 encrypted_buffer_(CreateFakeEncryptedBuffer()), | 90 encrypted_buffer_(CreateFakeEncryptedBuffer()), |
90 decoded_video_frame_(VideoFrame::CreateBlackFrame(kCodedSize)), | 91 default_audio_frame_(new DataBuffer(kFakeAudioFrameSize)), |
91 null_video_frame_(scoped_refptr<VideoFrame>()), | 92 end_of_stream_frame_(new DataBuffer(0)), |
92 end_of_stream_video_frame_(VideoFrame::CreateEmptyFrame()) { | 93 decoded_frames_(1, default_audio_frame_) { |
93 } | 94 } |
94 | 95 |
95 virtual ~DecryptingVideoDecoderTest() { | 96 virtual ~DecryptingAudioDecoderTest() { |
96 Stop(); | 97 Stop(); |
97 } | 98 } |
98 | 99 |
99 void InitializeAndExpectStatus(const VideoDecoderConfig& config, | 100 void InitializeAndExpectStatus(const AudioDecoderConfig& config, |
100 PipelineStatus status) { | 101 PipelineStatus status) { |
101 EXPECT_CALL(*demuxer_, video_decoder_config()) | 102 EXPECT_CALL(*demuxer_, audio_decoder_config()) |
102 .WillRepeatedly(ReturnRef(config)); | 103 .WillRepeatedly(ReturnRef(config)); |
103 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 104 EXPECT_CALL(*this, RequestDecryptorNotification(_)) |
104 .WillRepeatedly(RunCallback0(decryptor_.get())); | 105 .WillRepeatedly(RunCallback0(decryptor_.get())); |
105 | 106 |
106 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status), | 107 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status), |
107 base::Bind(&MockStatisticsCB::OnStatistics, | 108 base::Bind(&MockStatisticsCB::OnStatistics, |
108 base::Unretained(&statistics_cb_))); | 109 base::Unretained(&statistics_cb_))); |
109 message_loop_.RunAllPending(); | 110 message_loop_.RunAllPending(); |
110 } | 111 } |
111 | 112 |
112 void Initialize() { | 113 void Initialize() { |
113 EXPECT_CALL(*decryptor_, InitializeVideoDecoderMock(_, _, _)) | 114 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _, _)) |
114 .Times(AtMost(1)) | 115 .Times(AtMost(1)) |
115 .WillOnce(DoAll(RunCallback1(true), SaveArg<2>(&key_added_cb_))); | 116 .WillOnce(DoAll(RunCallback1(true), SaveArg<2>(&key_added_cb_))); |
116 | 117 |
117 config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, kVideoFormat, | 118 config_.Initialize(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, |
118 kCodedSize, kVisibleRect, kNaturalSize, | |
119 NULL, 0, true, true); | 119 NULL, 0, true, true); |
120 | 120 |
121 InitializeAndExpectStatus(config_, PIPELINE_OK); | 121 InitializeAndExpectStatus(config_, PIPELINE_OK); |
122 } | 122 } |
123 | 123 |
124 void ReadAndExpectFrameReadyWith( | 124 void ReadAndExpectFrameReadyWith( |
125 VideoDecoder::Status status, | 125 AudioDecoder::Status status, |
126 const scoped_refptr<VideoFrame>& video_frame) { | 126 const scoped_refptr<Buffer>& audio_frame) { |
127 EXPECT_CALL(*this, FrameReady(status, video_frame)); | 127 if (status != AudioDecoder::kOk) |
| 128 EXPECT_CALL(*this, FrameReady(status, IsNull())); |
| 129 else |
| 130 EXPECT_CALL(*this, FrameReady(status, audio_frame)); |
128 | 131 |
129 decoder_->Read(base::Bind(&DecryptingVideoDecoderTest::FrameReady, | 132 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, |
130 base::Unretained(this))); | 133 base::Unretained(this))); |
131 message_loop_.RunAllPending(); | 134 message_loop_.RunAllPending(); |
132 } | 135 } |
133 | 136 |
134 // Sets up expectations and actions to put DecryptingVideoDecoder in an | 137 // Sets up expectations and actions to put DecryptingAudioDecoder in an |
135 // active normal decoding state. | 138 // active normal decoding state. |
136 void EnterNormalDecodingState() { | 139 void EnterNormalDecodingState() { |
| 140 Decryptor::AudioBuffers end_of_stream_frames_(1, |
| 141 end_of_stream_frame_); |
| 142 |
137 EXPECT_CALL(*demuxer_, Read(_)) | 143 EXPECT_CALL(*demuxer_, Read(_)) |
138 .WillOnce(ReturnBuffer(encrypted_buffer_)) | 144 .WillOnce(ReturnBuffer(encrypted_buffer_)) |
139 .WillRepeatedly(ReturnBuffer(DecoderBuffer::CreateEOSBuffer())); | 145 .WillRepeatedly(ReturnBuffer(DecoderBuffer::CreateEOSBuffer())); |
140 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) | 146 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
141 .WillOnce(RunCallback2(Decryptor::kSuccess, decoded_video_frame_)) | 147 .WillOnce(RunCallback2(Decryptor::kSuccess, |
| 148 decoded_frames_)) |
142 .WillRepeatedly(RunCallback2(Decryptor::kSuccess, | 149 .WillRepeatedly(RunCallback2(Decryptor::kSuccess, |
143 end_of_stream_video_frame_)); | 150 end_of_stream_frames_)); |
144 EXPECT_CALL(statistics_cb_, OnStatistics(_)); | 151 EXPECT_CALL(statistics_cb_, OnStatistics(_)); |
145 | 152 |
146 ReadAndExpectFrameReadyWith(VideoDecoder::kOk, decoded_video_frame_); | 153 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, default_audio_frame_); |
147 } | 154 } |
148 | 155 |
149 // Sets up expectations and actions to put DecryptingVideoDecoder in an end | 156 // Sets up expectations and actions to put DecryptingAudioDecoder in an end |
150 // of stream state. This function must be called after | 157 // of stream state. This function must be called after |
151 // EnterNormalDecodingState() to work. | 158 // EnterNormalDecodingState() to work. |
152 void EnterEndOfStreamState() { | 159 void EnterEndOfStreamState() { |
153 ReadAndExpectFrameReadyWith(VideoDecoder::kOk, end_of_stream_video_frame_); | 160 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, end_of_stream_frame_); |
154 } | 161 } |
155 | 162 |
156 // Make the read callback pending by saving and not firing it. | 163 // Make the read callback pending by saving and not firing it. |
157 void EnterPendingReadState() { | 164 void EnterPendingReadState() { |
158 EXPECT_TRUE(pending_demuxer_read_cb_.is_null()); | 165 EXPECT_TRUE(pending_demuxer_read_cb_.is_null()); |
159 EXPECT_CALL(*demuxer_, Read(_)) | 166 EXPECT_CALL(*demuxer_, Read(_)) |
160 .WillOnce(SaveArg<0>(&pending_demuxer_read_cb_)); | 167 .WillOnce(SaveArg<0>(&pending_demuxer_read_cb_)); |
161 decoder_->Read(base::Bind(&DecryptingVideoDecoderTest::FrameReady, | 168 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, |
162 base::Unretained(this))); | 169 base::Unretained(this))); |
163 message_loop_.RunAllPending(); | 170 message_loop_.RunAllPending(); |
164 // Make sure the Read() on the decoder triggers a Read() on the demuxer. | 171 // Make sure the Read() on the decoder triggers a Read() on the demuxer. |
165 EXPECT_FALSE(pending_demuxer_read_cb_.is_null()); | 172 EXPECT_FALSE(pending_demuxer_read_cb_.is_null()); |
166 } | 173 } |
167 | 174 |
168 // Make the video decode callback pending by saving and not firing it. | 175 // Make the audio decode callback pending by saving and not firing it. |
169 void EnterPendingDecodeState() { | 176 void EnterPendingDecodeState() { |
170 EXPECT_TRUE(pending_video_decode_cb_.is_null()); | 177 EXPECT_TRUE(pending_audio_decode_cb_.is_null()); |
171 EXPECT_CALL(*demuxer_, Read(_)) | 178 EXPECT_CALL(*demuxer_, Read(_)) |
172 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); | 179 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); |
173 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(encrypted_buffer_, _)) | 180 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _)) |
174 .WillOnce(SaveArg<1>(&pending_video_decode_cb_)); | 181 .WillOnce(SaveArg<1>(&pending_audio_decode_cb_)); |
175 | 182 |
176 decoder_->Read(base::Bind(&DecryptingVideoDecoderTest::FrameReady, | 183 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, |
177 base::Unretained(this))); | 184 base::Unretained(this))); |
178 message_loop_.RunAllPending(); | 185 message_loop_.RunAllPending(); |
179 // Make sure the Read() on the decoder triggers a DecryptAndDecode() on the | 186 // Make sure the Read() on the decoder triggers a DecryptAndDecode() on the |
180 // decryptor. | 187 // decryptor. |
181 EXPECT_FALSE(pending_video_decode_cb_.is_null()); | 188 EXPECT_FALSE(pending_audio_decode_cb_.is_null()); |
182 } | 189 } |
183 | 190 |
184 void EnterWaitingForKeyState() { | 191 void EnterWaitingForKeyState() { |
185 EXPECT_CALL(*demuxer_, Read(_)) | 192 EXPECT_CALL(*demuxer_, Read(_)) |
186 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); | 193 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); |
187 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) | 194 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
188 .WillRepeatedly(RunCallback2(Decryptor::kNoKey, null_video_frame_)); | 195 .WillRepeatedly(RunCallback2(Decryptor::kNoKey, |
189 decoder_->Read(base::Bind(&DecryptingVideoDecoderTest::FrameReady, | 196 Decryptor::AudioBuffers())); |
| 197 decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, |
190 base::Unretained(this))); | 198 base::Unretained(this))); |
191 message_loop_.RunAllPending(); | 199 message_loop_.RunAllPending(); |
192 } | 200 } |
193 | 201 |
194 void AbortPendingVideoDecodeCB() { | 202 void AbortPendingAudioDecodeCB() { |
195 if (!pending_video_decode_cb_.is_null()) { | 203 if (!pending_audio_decode_cb_.is_null()) { |
196 base::ResetAndReturn(&pending_video_decode_cb_).Run( | 204 base::ResetAndReturn(&pending_audio_decode_cb_).Run( |
197 Decryptor::kSuccess, scoped_refptr<VideoFrame>(NULL)); | 205 Decryptor::kSuccess, Decryptor::AudioBuffers()); |
198 } | 206 } |
199 } | 207 } |
200 | 208 |
201 void AbortAllPendingCBs() { | 209 void AbortAllPendingCBs() { |
202 if (!pending_init_cb_.is_null()) { | 210 if (!pending_init_cb_.is_null()) { |
203 ASSERT_TRUE(pending_video_decode_cb_.is_null()); | 211 ASSERT_TRUE(pending_audio_decode_cb_.is_null()); |
204 base::ResetAndReturn(&pending_init_cb_).Run(false); | 212 base::ResetAndReturn(&pending_init_cb_).Run(false); |
205 return; | 213 return; |
206 } | 214 } |
207 | 215 |
208 AbortPendingVideoDecodeCB(); | 216 AbortPendingAudioDecodeCB(); |
209 } | 217 } |
210 | 218 |
211 void Reset() { | 219 void Reset() { |
212 EXPECT_CALL(*decryptor_, ResetDecoder(Decryptor::kVideo)) | 220 EXPECT_CALL(*decryptor_, ResetDecoder(Decryptor::kAudio)) |
213 .WillRepeatedly(InvokeWithoutArgs( | 221 .WillRepeatedly(InvokeWithoutArgs( |
214 this, &DecryptingVideoDecoderTest::AbortPendingVideoDecodeCB)); | 222 this, &DecryptingAudioDecoderTest::AbortPendingAudioDecodeCB)); |
215 | 223 |
216 decoder_->Reset(NewExpectedClosure()); | 224 decoder_->Reset(NewExpectedClosure()); |
217 message_loop_.RunAllPending(); | 225 message_loop_.RunAllPending(); |
218 } | 226 } |
219 | 227 |
220 void Stop() { | 228 void Stop() { |
221 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kVideo)) | 229 EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)) |
222 .WillRepeatedly(InvokeWithoutArgs( | 230 .WillRepeatedly(InvokeWithoutArgs( |
223 this, &DecryptingVideoDecoderTest::AbortAllPendingCBs)); | 231 this, &DecryptingAudioDecoderTest::AbortAllPendingCBs)); |
224 | 232 |
225 decoder_->Stop(NewExpectedClosure()); | 233 decoder_->Stop(NewExpectedClosure()); |
226 message_loop_.RunAllPending(); | 234 message_loop_.RunAllPending(); |
227 } | 235 } |
228 | 236 |
229 MOCK_METHOD1(RequestDecryptorNotification, | 237 MOCK_METHOD1(RequestDecryptorNotification, |
230 void(const DecryptingVideoDecoder::DecryptorNotificationCB&)); | 238 void(const DecryptingAudioDecoder::DecryptorNotificationCB&)); |
231 | 239 |
232 MOCK_METHOD2(FrameReady, void(VideoDecoder::Status, | 240 MOCK_METHOD2(FrameReady, void(AudioDecoder::Status, |
233 const scoped_refptr<VideoFrame>&)); | 241 const scoped_refptr<Buffer>&)); |
234 | 242 |
235 MessageLoop message_loop_; | 243 MessageLoop message_loop_; |
236 scoped_refptr<StrictMock<DecryptingVideoDecoder> > decoder_; | 244 scoped_refptr<StrictMock<DecryptingAudioDecoder> > decoder_; |
237 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; | 245 scoped_ptr<StrictMock<MockDecryptor> > decryptor_; |
238 scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_; | 246 scoped_refptr<StrictMock<MockDemuxerStream> > demuxer_; |
239 MockStatisticsCB statistics_cb_; | 247 MockStatisticsCB statistics_cb_; |
240 VideoDecoderConfig config_; | 248 AudioDecoderConfig config_; |
241 | 249 |
242 DemuxerStream::ReadCB pending_demuxer_read_cb_; | 250 DemuxerStream::ReadCB pending_demuxer_read_cb_; |
243 Decryptor::DecoderInitCB pending_init_cb_; | 251 Decryptor::DecoderInitCB pending_init_cb_; |
244 Decryptor::KeyAddedCB key_added_cb_; | 252 Decryptor::KeyAddedCB key_added_cb_; |
245 Decryptor::VideoDecodeCB pending_video_decode_cb_; | 253 Decryptor::AudioDecodeCB pending_audio_decode_cb_; |
246 | 254 |
247 // Constant buffer/frames to be returned by the |demuxer_| and |decryptor_|. | 255 // Constant buffer/frames to be returned by the |demuxer_| and |decryptor_|. |
248 scoped_refptr<DecoderBuffer> encrypted_buffer_; | 256 scoped_refptr<DecoderBuffer> encrypted_buffer_; |
249 scoped_refptr<VideoFrame> decoded_video_frame_; | 257 scoped_refptr<Buffer> default_audio_frame_; |
250 scoped_refptr<VideoFrame> null_video_frame_; | 258 scoped_refptr<Buffer> end_of_stream_frame_; |
251 scoped_refptr<VideoFrame> end_of_stream_video_frame_; | 259 Decryptor::AudioBuffers decoded_frames_; |
252 | 260 |
253 private: | 261 private: |
254 DISALLOW_COPY_AND_ASSIGN(DecryptingVideoDecoderTest); | 262 DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoderTest); |
255 }; | 263 }; |
256 | 264 |
257 TEST_F(DecryptingVideoDecoderTest, Initialize_Normal) { | 265 TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) { |
258 Initialize(); | 266 Initialize(); |
259 } | 267 } |
260 | 268 |
261 // Ensure that DecryptingVideoDecoder only accepts encrypted video. | 269 // Ensure that DecryptingAudioDecoder only accepts encrypted audio. |
262 TEST_F(DecryptingVideoDecoderTest, Initialize_UnencryptedVideoConfig) { | 270 TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) { |
263 VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, | 271 AudioDecoderConfig config(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, |
264 kVideoFormat, | |
265 kCodedSize, kVisibleRect, kNaturalSize, | |
266 NULL, 0, false); | 272 NULL, 0, false); |
267 | 273 |
268 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); | 274 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); |
269 } | 275 } |
270 | 276 |
271 // Ensure decoder handles invalid video configs without crashing. | 277 // Ensure decoder handles invalid audio configs without crashing. |
272 TEST_F(DecryptingVideoDecoderTest, Initialize_InvalidVideoConfig) { | 278 TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) { |
273 VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, | 279 AudioDecoderConfig config(kUnknownAudioCodec, 0, CHANNEL_LAYOUT_STEREO, 0, |
274 VideoFrame::INVALID, | |
275 kCodedSize, kVisibleRect, kNaturalSize, | |
276 NULL, 0, true); | 280 NULL, 0, true); |
277 | 281 |
278 InitializeAndExpectStatus(config, PIPELINE_ERROR_DECODE); | 282 InitializeAndExpectStatus(config, PIPELINE_ERROR_DECODE); |
279 } | 283 } |
280 | 284 |
281 // Ensure decoder handles unsupported video configs without crashing. | 285 // Ensure decoder handles unsupported audio configs without crashing. |
282 TEST_F(DecryptingVideoDecoderTest, Initialize_UnsupportedVideoConfig) { | 286 TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { |
283 EXPECT_CALL(*decryptor_, InitializeVideoDecoderMock(_, _, _)) | 287 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _, _)) |
284 .WillOnce(RunCallback1(false)); | 288 .WillOnce(RunCallback1(false)); |
285 | 289 |
286 VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, | 290 AudioDecoderConfig config(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, |
287 kVideoFormat, | |
288 kCodedSize, kVisibleRect, kNaturalSize, | |
289 NULL, 0, true); | 291 NULL, 0, true); |
290 | |
291 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); | 292 InitializeAndExpectStatus(config, DECODER_ERROR_NOT_SUPPORTED); |
292 } | 293 } |
293 | 294 |
294 // Test normal decrypt and decode case. | 295 // Test normal decrypt and decode case. |
295 TEST_F(DecryptingVideoDecoderTest, DecryptAndDecode_Normal) { | 296 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { |
296 Initialize(); | 297 Initialize(); |
297 EnterNormalDecodingState(); | 298 EnterNormalDecodingState(); |
298 } | 299 } |
299 | 300 |
300 // Test the case where the decryptor returns error when doing decrypt and | 301 // Test the case where the decryptor returns error when doing decrypt and |
301 // decode. | 302 // decode. |
302 TEST_F(DecryptingVideoDecoderTest, DecryptAndDecode_DecodeError) { | 303 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_DecodeError) { |
303 Initialize(); | 304 Initialize(); |
304 | 305 |
305 EXPECT_CALL(*demuxer_, Read(_)) | 306 EXPECT_CALL(*demuxer_, Read(_)) |
306 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); | 307 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); |
307 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) | 308 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
308 .WillRepeatedly(RunCallback2(Decryptor::kError, | 309 .WillRepeatedly(RunCallback2(Decryptor::kError, |
309 scoped_refptr<VideoFrame>(NULL))); | 310 Decryptor::AudioBuffers())); |
310 | 311 |
311 ReadAndExpectFrameReadyWith(VideoDecoder::kDecodeError, null_video_frame_); | 312 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL); |
312 } | 313 } |
313 | 314 |
314 // Test the case where the decryptor returns kNeedMoreData to ask for more | 315 // Test the case where the decryptor returns kNeedMoreData to ask for more |
315 // buffers before it can produce a frame. | 316 // buffers before it can produce a frame. |
316 TEST_F(DecryptingVideoDecoderTest, DecryptAndDecode_NeedMoreData) { | 317 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_NeedMoreData) { |
317 Initialize(); | 318 Initialize(); |
318 | 319 |
319 EXPECT_CALL(*demuxer_, Read(_)) | 320 EXPECT_CALL(*demuxer_, Read(_)) |
320 .Times(2) | 321 .Times(2) |
321 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); | 322 .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); |
322 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) | 323 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
323 .WillOnce(RunCallback2(Decryptor::kNeedMoreData, | 324 .WillOnce(RunCallback2(Decryptor::kNeedMoreData, |
324 scoped_refptr<VideoFrame>())) | 325 Decryptor::AudioBuffers())) |
325 .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_video_frame_)); | 326 .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_frames_)); |
326 EXPECT_CALL(statistics_cb_, OnStatistics(_)) | 327 EXPECT_CALL(statistics_cb_, OnStatistics(_)) |
327 .Times(2); | 328 .Times(2); |
328 | 329 |
329 ReadAndExpectFrameReadyWith(VideoDecoder::kOk, decoded_video_frame_); | 330 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, default_audio_frame_); |
| 331 } |
| 332 |
| 333 // Test the case where the decryptor returns multiple decoded frames. |
| 334 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFrames) { |
| 335 Initialize(); |
| 336 |
| 337 scoped_refptr<Buffer> audio_frame_a(new DataBuffer(kFakeAudioFrameSize)); |
| 338 scoped_refptr<Buffer> audio_frame_b(new DataBuffer(kFakeAudioFrameSize)); |
| 339 decoded_frames_.push_back(audio_frame_a); |
| 340 decoded_frames_.push_back(audio_frame_b); |
| 341 |
| 342 EXPECT_CALL(*demuxer_, Read(_)) |
| 343 .WillOnce(ReturnBuffer(encrypted_buffer_)); |
| 344 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
| 345 .WillOnce(RunCallback2(Decryptor::kSuccess, decoded_frames_)); |
| 346 EXPECT_CALL(statistics_cb_, OnStatistics(_)); |
| 347 |
| 348 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, default_audio_frame_); |
| 349 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, audio_frame_a); |
| 350 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, audio_frame_b); |
330 } | 351 } |
331 | 352 |
332 // Test the case where the decryptor receives end-of-stream buffer. | 353 // Test the case where the decryptor receives end-of-stream buffer. |
333 TEST_F(DecryptingVideoDecoderTest, DecryptAndDecode_EndOfStream) { | 354 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_EndOfStream) { |
334 Initialize(); | 355 Initialize(); |
335 EnterNormalDecodingState(); | 356 EnterNormalDecodingState(); |
336 EnterEndOfStreamState(); | 357 EnterEndOfStreamState(); |
337 } | 358 } |
338 | 359 |
| 360 // Test the case where the decryptor returns multiple decoded frames, the last |
| 361 // of which is end-of-stream frame. |
| 362 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFramesWithEos) { |
| 363 Initialize(); |
| 364 |
| 365 scoped_refptr<Buffer> audio_frame_a(new DataBuffer(kFakeAudioFrameSize)); |
| 366 scoped_refptr<Buffer> audio_frame_b(new DataBuffer(kFakeAudioFrameSize)); |
| 367 Decryptor::AudioBuffers decoded_frames_a; |
| 368 decoded_frames_a.push_back(audio_frame_a); |
| 369 decoded_frames_a.push_back(audio_frame_b); |
| 370 decoded_frames_a.push_back(end_of_stream_frame_); |
| 371 |
| 372 EXPECT_CALL(*demuxer_, Read(_)) |
| 373 .WillOnce(ReturnBuffer(encrypted_buffer_)) |
| 374 .WillOnce(ReturnBuffer(DecoderBuffer::CreateEOSBuffer())); |
| 375 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
| 376 .WillOnce(RunCallback2(Decryptor::kSuccess, decoded_frames_)) |
| 377 .WillOnce(RunCallback2(Decryptor::kSuccess, decoded_frames_a)); |
| 378 // Expect only one OnStatistics() here because EOS input buffer doesn't |
| 379 // trigger statistics reporting. |
| 380 EXPECT_CALL(statistics_cb_, OnStatistics(_)); |
| 381 |
| 382 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, default_audio_frame_); |
| 383 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, audio_frame_a); |
| 384 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, audio_frame_b); |
| 385 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, end_of_stream_frame_); |
| 386 } |
| 387 |
339 // Test the case where the a key is added when the decryptor is in | 388 // Test the case where the a key is added when the decryptor is in |
340 // kWaitingForKey state. | 389 // kWaitingForKey state. |
341 TEST_F(DecryptingVideoDecoderTest, KeyAdded_DuringWaitingForKey) { | 390 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DuringWaitingForKey) { |
342 Initialize(); | 391 Initialize(); |
343 EnterWaitingForKeyState(); | 392 EnterWaitingForKeyState(); |
344 | 393 |
345 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) | 394 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
346 .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_video_frame_)); | 395 .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_frames_)); |
347 EXPECT_CALL(statistics_cb_, OnStatistics(_)); | 396 EXPECT_CALL(statistics_cb_, OnStatistics(_)); |
348 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, decoded_video_frame_)); | 397 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, default_audio_frame_)); |
349 key_added_cb_.Run(); | 398 key_added_cb_.Run(); |
350 message_loop_.RunAllPending(); | 399 message_loop_.RunAllPending(); |
351 } | 400 } |
352 | 401 |
353 // Test the case where the a key is added when the decryptor is in | 402 // Test the case where the a key is added when the decryptor is in |
354 // kPendingDecode state. | 403 // kPendingDecode state. |
355 TEST_F(DecryptingVideoDecoderTest, KeyAdded_DruingPendingDecode) { | 404 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DruingPendingDecode) { |
356 Initialize(); | 405 Initialize(); |
357 EnterPendingDecodeState(); | 406 EnterPendingDecodeState(); |
358 | 407 |
359 EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) | 408 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
360 .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_video_frame_)); | 409 .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_frames_)); |
361 EXPECT_CALL(statistics_cb_, OnStatistics(_)); | 410 EXPECT_CALL(statistics_cb_, OnStatistics(_)); |
362 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, decoded_video_frame_)); | 411 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, default_audio_frame_)); |
363 // The video decode callback is returned after the correct decryption key is | 412 // The audio decode callback is returned after the correct decryption key is |
364 // added. | 413 // added. |
365 key_added_cb_.Run(); | 414 key_added_cb_.Run(); |
366 base::ResetAndReturn(&pending_video_decode_cb_).Run(Decryptor::kNoKey, | 415 base::ResetAndReturn(&pending_audio_decode_cb_) |
367 null_video_frame_); | 416 .Run(Decryptor::kNoKey, Decryptor::AudioBuffers()); |
368 message_loop_.RunAllPending(); | 417 message_loop_.RunAllPending(); |
369 } | 418 } |
370 | 419 |
371 // Test resetting when the decoder is in kIdle state but has not decoded any | 420 // Test resetting when the decoder is in kIdle state but has not decoded any |
372 // frame. | 421 // frame. |
373 TEST_F(DecryptingVideoDecoderTest, Reset_DuringIdleAfterInitialization) { | 422 TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterInitialization) { |
374 Initialize(); | 423 Initialize(); |
375 Reset(); | 424 Reset(); |
376 } | 425 } |
377 | 426 |
378 // Test resetting when the decoder is in kIdle state after it has decoded one | 427 // Test resetting when the decoder is in kIdle state after it has decoded one |
379 // frame. | 428 // frame. |
380 TEST_F(DecryptingVideoDecoderTest, Reset_DuringIdleAfterDecodedOneFrame) { | 429 TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterDecodedOneFrame) { |
381 Initialize(); | 430 Initialize(); |
382 EnterNormalDecodingState(); | 431 EnterNormalDecodingState(); |
383 Reset(); | 432 Reset(); |
384 } | 433 } |
385 | 434 |
386 // Test resetting when the decoder is in kPendingDemuxerRead state. | 435 // Test resetting when the decoder is in kPendingDemuxerRead state. |
387 TEST_F(DecryptingVideoDecoderTest, Reset_DuringPendingDemuxerRead) { | 436 TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingDemuxerRead) { |
388 Initialize(); | 437 Initialize(); |
389 EnterPendingReadState(); | 438 EnterPendingReadState(); |
390 | 439 |
391 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); | 440 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, IsNull())); |
392 | 441 |
393 Reset(); | 442 Reset(); |
394 base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kOk, | 443 base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kOk, |
395 encrypted_buffer_); | 444 encrypted_buffer_); |
396 message_loop_.RunAllPending(); | 445 message_loop_.RunAllPending(); |
397 } | 446 } |
398 | 447 |
399 // Test resetting when the decoder is in kPendingDecode state. | 448 // Test resetting when the decoder is in kPendingDecode state. |
400 TEST_F(DecryptingVideoDecoderTest, Reset_DuringPendingDecode) { | 449 TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingDecode) { |
401 Initialize(); | 450 Initialize(); |
402 EnterPendingDecodeState(); | 451 EnterPendingDecodeState(); |
403 | 452 |
404 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); | 453 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, IsNull())); |
405 | 454 |
406 Reset(); | 455 Reset(); |
407 } | 456 } |
408 | 457 |
409 // Test resetting when the decoder is in kWaitingForKey state. | 458 // Test resetting when the decoder is in kWaitingForKey state. |
410 TEST_F(DecryptingVideoDecoderTest, Reset_DuringWaitingForKey) { | 459 TEST_F(DecryptingAudioDecoderTest, Reset_DuringWaitingForKey) { |
411 Initialize(); | 460 Initialize(); |
412 EnterWaitingForKeyState(); | 461 EnterWaitingForKeyState(); |
413 | 462 |
414 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); | 463 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, IsNull())); |
415 | 464 |
416 Reset(); | 465 Reset(); |
417 } | 466 } |
418 | 467 |
419 // Test resetting when the decoder has hit end of stream and is in | 468 // Test resetting when the decoder has hit end of stream and is in |
420 // kDecodeFinished state. | 469 // kDecodeFinished state. |
421 TEST_F(DecryptingVideoDecoderTest, Reset_AfterDecodeFinished) { | 470 TEST_F(DecryptingAudioDecoderTest, Reset_AfterDecodeFinished) { |
422 Initialize(); | 471 Initialize(); |
423 EnterNormalDecodingState(); | 472 EnterNormalDecodingState(); |
424 EnterEndOfStreamState(); | 473 EnterEndOfStreamState(); |
425 Reset(); | 474 Reset(); |
426 } | 475 } |
427 | 476 |
428 // Test resetting after the decoder has been reset. | 477 // Test resetting after the decoder has been reset. |
429 TEST_F(DecryptingVideoDecoderTest, Reset_AfterReset) { | 478 TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { |
430 Initialize(); | 479 Initialize(); |
431 EnterNormalDecodingState(); | 480 EnterNormalDecodingState(); |
432 Reset(); | 481 Reset(); |
433 Reset(); | 482 Reset(); |
434 } | 483 } |
435 | 484 |
436 // Test stopping when the decoder is in kDecryptorRequested state. | 485 // Test stopping when the decoder is in kDecryptorRequested state. |
437 TEST_F(DecryptingVideoDecoderTest, Stop_DuringDecryptorRequested) { | 486 TEST_F(DecryptingAudioDecoderTest, Stop_DuringDecryptorRequested) { |
438 config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, kVideoFormat, | 487 config_.Initialize(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, |
439 kCodedSize, kVisibleRect, kNaturalSize, | |
440 NULL, 0, true, true); | 488 NULL, 0, true, true); |
441 EXPECT_CALL(*demuxer_, video_decoder_config()) | 489 EXPECT_CALL(*demuxer_, audio_decoder_config()) |
442 .WillRepeatedly(ReturnRef(config_)); | 490 .WillRepeatedly(ReturnRef(config_)); |
443 DecryptingVideoDecoder::DecryptorNotificationCB decryptor_notification_cb; | 491 DecryptingAudioDecoder::DecryptorNotificationCB decryptor_notification_cb; |
444 EXPECT_CALL(*this, RequestDecryptorNotification(_)) | 492 EXPECT_CALL(*this, RequestDecryptorNotification(_)) |
445 .WillOnce(SaveArg<0>(&decryptor_notification_cb)); | 493 .WillOnce(SaveArg<0>(&decryptor_notification_cb)); |
446 decoder_->Initialize(demuxer_, | 494 decoder_->Initialize(demuxer_, |
447 NewExpectedStatusCB(DECODER_ERROR_NOT_SUPPORTED), | 495 NewExpectedStatusCB(DECODER_ERROR_NOT_SUPPORTED), |
448 base::Bind(&MockStatisticsCB::OnStatistics, | 496 base::Bind(&MockStatisticsCB::OnStatistics, |
449 base::Unretained(&statistics_cb_))); | 497 base::Unretained(&statistics_cb_))); |
450 message_loop_.RunAllPending(); | 498 message_loop_.RunAllPending(); |
451 // |decryptor_notification_cb| is saved but not called here. | 499 // |decryptor_notification_cb| is saved but not called here. |
452 EXPECT_FALSE(decryptor_notification_cb.is_null()); | 500 EXPECT_FALSE(decryptor_notification_cb.is_null()); |
453 | 501 |
454 // During stop, RequestDecryptorNotification() should be called with a NULL | 502 // During stop, RequestDecryptorNotification() should be called with a NULL |
455 // callback to cancel the |decryptor_notification_cb|. | 503 // callback to cancel the |decryptor_notification_cb|. |
456 EXPECT_CALL(*this, RequestDecryptorNotification(IsNullCallback())) | 504 EXPECT_CALL(*this, RequestDecryptorNotification(IsNullCallback())) |
457 .WillOnce(ResetAndRunCallback(&decryptor_notification_cb, | 505 .WillOnce(ResetAndRunCallback(&decryptor_notification_cb, |
458 reinterpret_cast<Decryptor*>(NULL))); | 506 reinterpret_cast<Decryptor*>(NULL))); |
459 Stop(); | 507 Stop(); |
460 } | 508 } |
461 | 509 |
462 // Test stopping when the decoder is in kPendingDecoderInit state. | 510 // Test stopping when the decoder is in kPendingDecoderInit state. |
463 TEST_F(DecryptingVideoDecoderTest, Stop_DuringPendingDecoderInit) { | 511 TEST_F(DecryptingAudioDecoderTest, Stop_DuringPendingDecoderInit) { |
464 EXPECT_CALL(*decryptor_, InitializeVideoDecoderMock(_, _, _)) | 512 EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _, _)) |
465 .WillOnce(SaveArg<1>(&pending_init_cb_)); | 513 .WillOnce(SaveArg<1>(&pending_init_cb_)); |
466 | 514 |
467 config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, kVideoFormat, | 515 config_.Initialize(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, |
468 kCodedSize, kVisibleRect, kNaturalSize, NULL, 0, true, | 516 NULL, 0, true, true); |
469 true); | |
470 InitializeAndExpectStatus(config_, DECODER_ERROR_NOT_SUPPORTED); | 517 InitializeAndExpectStatus(config_, DECODER_ERROR_NOT_SUPPORTED); |
471 EXPECT_FALSE(pending_init_cb_.is_null()); | 518 EXPECT_FALSE(pending_init_cb_.is_null()); |
472 | 519 |
473 Stop(); | 520 Stop(); |
474 } | 521 } |
475 | 522 |
476 // Test stopping when the decoder is in kIdle state but has not decoded any | 523 // Test stopping when the decoder is in kIdle state but has not decoded any |
477 // frame. | 524 // frame. |
478 TEST_F(DecryptingVideoDecoderTest, Stop_DuringIdleAfterInitialization) { | 525 TEST_F(DecryptingAudioDecoderTest, Stop_DuringIdleAfterInitialization) { |
479 Initialize(); | 526 Initialize(); |
480 Stop(); | 527 Stop(); |
481 } | 528 } |
482 | 529 |
483 // Test stopping when the decoder is in kIdle state after it has decoded one | 530 // Test stopping when the decoder is in kIdle state after it has decoded one |
484 // frame. | 531 // frame. |
485 TEST_F(DecryptingVideoDecoderTest, Stop_DuringIdleAfterDecodedOneFrame) { | 532 TEST_F(DecryptingAudioDecoderTest, Stop_DuringIdleAfterDecodedOneFrame) { |
486 Initialize(); | 533 Initialize(); |
487 EnterNormalDecodingState(); | 534 EnterNormalDecodingState(); |
488 Stop(); | 535 Stop(); |
489 } | 536 } |
490 | 537 |
491 // Test stopping when the decoder is in kPendingDemuxerRead state. | 538 // Test stopping when the decoder is in kPendingDemuxerRead state. |
492 TEST_F(DecryptingVideoDecoderTest, Stop_DuringPendingDemuxerRead) { | 539 TEST_F(DecryptingAudioDecoderTest, Stop_DuringPendingDemuxerRead) { |
493 Initialize(); | 540 Initialize(); |
494 EnterPendingReadState(); | 541 EnterPendingReadState(); |
495 | 542 |
496 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); | 543 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, IsNull())); |
497 | 544 |
498 Stop(); | 545 Stop(); |
499 base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kOk, | 546 base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kOk, |
500 encrypted_buffer_); | 547 encrypted_buffer_); |
501 message_loop_.RunAllPending(); | 548 message_loop_.RunAllPending(); |
502 } | 549 } |
503 | 550 |
504 // Test stopping when the decoder is in kPendingDecode state. | 551 // Test stopping when the decoder is in kPendingDecode state. |
505 TEST_F(DecryptingVideoDecoderTest, Stop_DuringPendingDecode) { | 552 TEST_F(DecryptingAudioDecoderTest, Stop_DuringPendingDecode) { |
506 Initialize(); | 553 Initialize(); |
507 EnterPendingDecodeState(); | 554 EnterPendingDecodeState(); |
508 | 555 |
509 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); | 556 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, IsNull())); |
510 | 557 |
511 Stop(); | 558 Stop(); |
512 } | 559 } |
513 | 560 |
514 // Test stopping when the decoder is in kWaitingForKey state. | 561 // Test stopping when the decoder is in kWaitingForKey state. |
515 TEST_F(DecryptingVideoDecoderTest, Stop_DuringWaitingForKey) { | 562 TEST_F(DecryptingAudioDecoderTest, Stop_DuringWaitingForKey) { |
516 Initialize(); | 563 Initialize(); |
517 EnterWaitingForKeyState(); | 564 EnterWaitingForKeyState(); |
518 | 565 |
519 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); | 566 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, IsNull())); |
520 | 567 |
521 Stop(); | 568 Stop(); |
522 } | 569 } |
523 | 570 |
524 // Test stopping when the decoder has hit end of stream and is in | 571 // Test stopping when the decoder has hit end of stream and is in |
525 // kDecodeFinished state. | 572 // kDecodeFinished state. |
526 TEST_F(DecryptingVideoDecoderTest, Stop_AfterDecodeFinished) { | 573 TEST_F(DecryptingAudioDecoderTest, Stop_AfterDecodeFinished) { |
527 Initialize(); | 574 Initialize(); |
528 EnterNormalDecodingState(); | 575 EnterNormalDecodingState(); |
529 EnterEndOfStreamState(); | 576 EnterEndOfStreamState(); |
530 Stop(); | 577 Stop(); |
531 } | 578 } |
532 | 579 |
533 // Test stopping when there is a pending reset on the decoder. | 580 // Test stopping when there is a pending reset on the decoder. |
534 // Reset is pending because it cannot complete when the video decode callback | 581 // Reset is pending because it cannot complete when the audio decode callback |
535 // is pending. | 582 // is pending. |
536 TEST_F(DecryptingVideoDecoderTest, Stop_DuringPendingReset) { | 583 TEST_F(DecryptingAudioDecoderTest, Stop_DuringPendingReset) { |
537 Initialize(); | 584 Initialize(); |
538 EnterPendingDecodeState(); | 585 EnterPendingDecodeState(); |
539 | 586 |
540 EXPECT_CALL(*decryptor_, ResetDecoder(Decryptor::kVideo)); | 587 EXPECT_CALL(*decryptor_, ResetDecoder(Decryptor::kAudio)); |
541 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); | 588 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, IsNull())); |
542 | 589 |
543 decoder_->Reset(NewExpectedClosure()); | 590 decoder_->Reset(NewExpectedClosure()); |
544 Stop(); | 591 Stop(); |
545 } | 592 } |
546 | 593 |
547 // Test stopping after the decoder has been reset. | 594 // Test stopping after the decoder has been reset. |
548 TEST_F(DecryptingVideoDecoderTest, Stop_AfterReset) { | 595 TEST_F(DecryptingAudioDecoderTest, Stop_AfterReset) { |
549 Initialize(); | 596 Initialize(); |
550 EnterNormalDecodingState(); | 597 EnterNormalDecodingState(); |
551 Reset(); | 598 Reset(); |
552 Stop(); | 599 Stop(); |
553 } | 600 } |
554 | 601 |
555 // Test stopping after the decoder has been stopped. | 602 // Test stopping after the decoder has been stopped. |
556 TEST_F(DecryptingVideoDecoderTest, Stop_AfterStop) { | 603 TEST_F(DecryptingAudioDecoderTest, Stop_AfterStop) { |
557 Initialize(); | 604 Initialize(); |
558 EnterNormalDecodingState(); | 605 EnterNormalDecodingState(); |
559 Stop(); | 606 Stop(); |
560 Stop(); | 607 Stop(); |
561 } | 608 } |
562 | 609 |
563 // Test aborted read on the demuxer stream. | 610 // Test aborted read on the demuxer stream. |
564 TEST_F(DecryptingVideoDecoderTest, DemuxerRead_Aborted) { | 611 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_Aborted) { |
565 Initialize(); | 612 Initialize(); |
566 | 613 |
567 // ReturnBuffer() with NULL triggers aborted demuxer read. | 614 // ReturnBuffer() with NULL triggers aborted demuxer read. |
568 EXPECT_CALL(*demuxer_, Read(_)) | 615 EXPECT_CALL(*demuxer_, Read(_)) |
569 .WillOnce(ReturnBuffer(scoped_refptr<DecoderBuffer>())); | 616 .WillOnce(ReturnBuffer(scoped_refptr<DecoderBuffer>())); |
570 | 617 |
571 ReadAndExpectFrameReadyWith(VideoDecoder::kOk, null_video_frame_); | 618 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, NULL); |
572 } | 619 } |
573 | 620 |
574 // Test aborted read on the demuxer stream when the decoder is being reset. | 621 // Test aborted read on the demuxer stream when the decoder is being reset. |
575 TEST_F(DecryptingVideoDecoderTest, DemuxerRead_AbortedDuringReset) { | 622 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_AbortedDuringReset) { |
576 Initialize(); | 623 Initialize(); |
577 EnterPendingReadState(); | 624 EnterPendingReadState(); |
578 | 625 |
579 // Make sure we get a NULL video frame returned. | 626 // Make sure we get a NULL audio frame returned. |
580 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); | 627 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, IsNull())); |
581 | 628 |
582 Reset(); | 629 Reset(); |
583 base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kAborted, | 630 base::ResetAndReturn(&pending_demuxer_read_cb_).Run(DemuxerStream::kAborted, |
584 NULL); | 631 NULL); |
585 message_loop_.RunAllPending(); | 632 message_loop_.RunAllPending(); |
586 } | 633 } |
587 | 634 |
588 // Test config change on the demuxer stream. | 635 // Test config change on the demuxer stream. |
589 TEST_F(DecryptingVideoDecoderTest, DemuxerRead_ConfigChanged) { | 636 TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChanged) { |
590 Initialize(); | 637 Initialize(); |
591 | 638 |
592 EXPECT_CALL(*demuxer_, Read(_)) | 639 EXPECT_CALL(*demuxer_, Read(_)) |
593 .WillOnce(ReturnConfigChanged()); | 640 .WillOnce(ReturnConfigChanged()); |
594 | 641 |
595 // TODO(xhwang): Update this test when kConfigChanged is supported in | 642 // TODO(xhwang): Update this test when kConfigChanged is supported in |
596 // DecryptingVideoDecoder. | 643 // DecryptingAudioDecoder. |
597 ReadAndExpectFrameReadyWith(VideoDecoder::kDecodeError, null_video_frame_); | 644 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL); |
598 } | 645 } |
599 | 646 |
600 } // namespace media | 647 } // namespace media |
OLD | NEW |