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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback_helpers.h" | 6 #include "base/callback_helpers.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "media/base/gmock_callback_support.h" | 8 #include "media/base/gmock_callback_support.h" |
9 #include "media/base/mock_filters.h" | 9 #include "media/base/mock_filters.h" |
10 #include "media/base/test_helpers.h" | 10 #include "media/base/test_helpers.h" |
11 #include "media/filters/decoder_stream.h" | 11 #include "media/filters/decoder_stream.h" |
12 #include "media/filters/fake_demuxer_stream.h" | 12 #include "media/filters/fake_demuxer_stream.h" |
13 #include "media/filters/fake_video_decoder.h" | 13 #include "media/filters/fake_video_decoder.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using ::testing::_; | 16 using ::testing::_; |
17 using ::testing::AnyNumber; | 17 using ::testing::AnyNumber; |
18 using ::testing::Assign; | 18 using ::testing::Assign; |
19 using ::testing::Invoke; | 19 using ::testing::Invoke; |
| 20 using ::testing::InvokeWithoutArgs; |
20 using ::testing::NiceMock; | 21 using ::testing::NiceMock; |
21 using ::testing::Return; | 22 using ::testing::Return; |
22 using ::testing::SaveArg; | 23 using ::testing::SaveArg; |
23 | 24 |
24 static const int kNumConfigs = 3; | 25 static const int kNumConfigs = 3; |
25 static const int kNumBuffersInOneConfig = 5; | 26 static const int kNumBuffersInOneConfig = 5; |
26 | 27 |
| 28 // Use anonymous namespace here to prevent the actions to be defined multiple |
| 29 // times across multiple test files. Sadly we can't use static for them. |
| 30 namespace { |
| 31 |
| 32 ACTION_P3(ExecuteCallbackWithVerifier, decryptor, done_cb, verifier) { |
| 33 // verifier must be called first since |done_cb| call will invoke it as well. |
| 34 verifier->RecordACalled(); |
| 35 arg0.Run(decryptor, done_cb); |
| 36 } |
| 37 |
| 38 ACTION_P(ReportCallback, verifier) { |
| 39 verifier->RecordBCalled(); |
| 40 } |
| 41 |
| 42 } // namespace |
| 43 |
27 namespace media { | 44 namespace media { |
28 | 45 |
29 struct VideoFrameStreamTestParams { | 46 struct VideoFrameStreamTestParams { |
30 VideoFrameStreamTestParams(bool is_encrypted, | 47 VideoFrameStreamTestParams(bool is_encrypted, |
31 int decoding_delay, | 48 int decoding_delay, |
32 int parallel_decoding) | 49 int parallel_decoding) |
33 : is_encrypted(is_encrypted), | 50 : is_encrypted(is_encrypted), |
34 decoding_delay(decoding_delay), | 51 decoding_delay(decoding_delay), |
35 parallel_decoding(parallel_decoding) {} | 52 parallel_decoding(parallel_decoding) {} |
36 | 53 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 message_loop_.RunUntilIdle(); | 103 message_loop_.RunUntilIdle(); |
87 | 104 |
88 DCHECK(!pending_initialize_); | 105 DCHECK(!pending_initialize_); |
89 DCHECK(!pending_read_); | 106 DCHECK(!pending_read_); |
90 DCHECK(!pending_reset_); | 107 DCHECK(!pending_reset_); |
91 DCHECK(!pending_stop_); | 108 DCHECK(!pending_stop_); |
92 } | 109 } |
93 | 110 |
94 MOCK_METHOD1(OnNewSpliceBuffer, void(base::TimeDelta)); | 111 MOCK_METHOD1(OnNewSpliceBuffer, void(base::TimeDelta)); |
95 MOCK_METHOD1(SetDecryptorReadyCallback, void(const media::DecryptorReadyCB&)); | 112 MOCK_METHOD1(SetDecryptorReadyCallback, void(const media::DecryptorReadyCB&)); |
| 113 MOCK_METHOD1(DecryptorSet, void(bool)); |
96 | 114 |
97 void OnStatistics(const PipelineStatistics& statistics) { | 115 void OnStatistics(const PipelineStatistics& statistics) { |
98 total_bytes_decoded_ += statistics.video_bytes_decoded; | 116 total_bytes_decoded_ += statistics.video_bytes_decoded; |
99 } | 117 } |
100 | 118 |
101 void OnInitialized(bool success) { | 119 void OnInitialized(bool success) { |
102 DCHECK(!pending_read_); | 120 DCHECK(!pending_read_); |
103 DCHECK(!pending_reset_); | 121 DCHECK(!pending_reset_); |
104 DCHECK(pending_initialize_); | 122 DCHECK(pending_initialize_); |
105 pending_initialize_ = false; | 123 pending_initialize_ = false; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 DEMUXER_READ_NORMAL, | 208 DEMUXER_READ_NORMAL, |
191 DEMUXER_READ_CONFIG_CHANGE, | 209 DEMUXER_READ_CONFIG_CHANGE, |
192 SET_DECRYPTOR, | 210 SET_DECRYPTOR, |
193 DECRYPTOR_NO_KEY, | 211 DECRYPTOR_NO_KEY, |
194 DECODER_INIT, | 212 DECODER_INIT, |
195 DECODER_REINIT, | 213 DECODER_REINIT, |
196 DECODER_DECODE, | 214 DECODER_DECODE, |
197 DECODER_RESET | 215 DECODER_RESET |
198 }; | 216 }; |
199 | 217 |
| 218 void ExpectDecryptorNotification() { |
| 219 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) |
| 220 .WillRepeatedly(ExecuteCallbackWithVerifier( |
| 221 decryptor_.get(), |
| 222 base::Bind(&VideoFrameStreamTest::DecryptorSet, |
| 223 base::Unretained(this)), |
| 224 &verifier_)); |
| 225 EXPECT_CALL(*this, DecryptorSet(true)) |
| 226 .WillRepeatedly(ReportCallback(&verifier_)); |
| 227 } |
| 228 |
200 void EnterPendingState(PendingState state) { | 229 void EnterPendingState(PendingState state) { |
201 DCHECK_NE(state, NOT_PENDING); | 230 DCHECK_NE(state, NOT_PENDING); |
202 switch (state) { | 231 switch (state) { |
203 case DEMUXER_READ_NORMAL: | 232 case DEMUXER_READ_NORMAL: |
204 demuxer_stream_->HoldNextRead(); | 233 demuxer_stream_->HoldNextRead(); |
205 ReadUntilPending(); | 234 ReadUntilPending(); |
206 break; | 235 break; |
207 | 236 |
208 case DEMUXER_READ_CONFIG_CHANGE: | 237 case DEMUXER_READ_CONFIG_CHANGE: |
209 demuxer_stream_->HoldNextConfigChangeRead(); | 238 demuxer_stream_->HoldNextConfigChangeRead(); |
210 ReadUntilPending(); | 239 ReadUntilPending(); |
211 break; | 240 break; |
212 | 241 |
213 case SET_DECRYPTOR: | 242 case SET_DECRYPTOR: |
214 // Hold DecryptorReadyCB. | 243 // Hold DecryptorReadyCB. |
215 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) | 244 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) |
216 .Times(2); | 245 .Times(2); |
217 // Initialize will fail because no decryptor is available. | 246 // Initialize will fail because no decryptor is available. |
218 InitializeVideoFrameStream(); | 247 InitializeVideoFrameStream(); |
219 break; | 248 break; |
220 | 249 |
221 case DECRYPTOR_NO_KEY: | 250 case DECRYPTOR_NO_KEY: |
222 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) | 251 ExpectDecryptorNotification(); |
223 .WillRepeatedly(RunCallback<0>(decryptor_.get())); | |
224 has_no_key_ = true; | 252 has_no_key_ = true; |
225 ReadOneFrame(); | 253 ReadOneFrame(); |
226 break; | 254 break; |
227 | 255 |
228 case DECODER_INIT: | 256 case DECODER_INIT: |
229 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) | 257 ExpectDecryptorNotification(); |
230 .WillRepeatedly(RunCallback<0>(decryptor_.get())); | |
231 decoder_->HoldNextInit(); | 258 decoder_->HoldNextInit(); |
232 InitializeVideoFrameStream(); | 259 InitializeVideoFrameStream(); |
233 break; | 260 break; |
234 | 261 |
235 case DECODER_REINIT: | 262 case DECODER_REINIT: |
236 decoder_->HoldNextInit(); | 263 decoder_->HoldNextInit(); |
237 ReadUntilPending(); | 264 ReadUntilPending(); |
238 break; | 265 break; |
239 | 266 |
240 case DECODER_DECODE: | 267 case DECODER_DECODE: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 bool pending_read_; | 352 bool pending_read_; |
326 bool pending_reset_; | 353 bool pending_reset_; |
327 bool pending_stop_; | 354 bool pending_stop_; |
328 int total_bytes_decoded_; | 355 int total_bytes_decoded_; |
329 scoped_refptr<VideoFrame> frame_read_; | 356 scoped_refptr<VideoFrame> frame_read_; |
330 VideoFrameStream::Status last_read_status_; | 357 VideoFrameStream::Status last_read_status_; |
331 | 358 |
332 // Decryptor has no key to decrypt a frame. | 359 // Decryptor has no key to decrypt a frame. |
333 bool has_no_key_; | 360 bool has_no_key_; |
334 | 361 |
| 362 CallbackPairChecker verifier_; |
| 363 |
335 private: | 364 private: |
336 DISALLOW_COPY_AND_ASSIGN(VideoFrameStreamTest); | 365 DISALLOW_COPY_AND_ASSIGN(VideoFrameStreamTest); |
337 }; | 366 }; |
338 | 367 |
339 INSTANTIATE_TEST_CASE_P( | 368 INSTANTIATE_TEST_CASE_P( |
340 Clear, | 369 Clear, |
341 VideoFrameStreamTest, | 370 VideoFrameStreamTest, |
342 ::testing::Values( | 371 ::testing::Values( |
343 VideoFrameStreamTestParams(false, 0, 1), | 372 VideoFrameStreamTestParams(false, 0, 1), |
344 VideoFrameStreamTestParams(false, 3, 1), | 373 VideoFrameStreamTestParams(false, 3, 1), |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 // The error must surface from Read() as DECODE_ERROR. | 714 // The error must surface from Read() as DECODE_ERROR. |
686 while (last_read_status_ == VideoFrameStream::OK) { | 715 while (last_read_status_ == VideoFrameStream::OK) { |
687 ReadOneFrame(); | 716 ReadOneFrame(); |
688 message_loop_.RunUntilIdle(); | 717 message_loop_.RunUntilIdle(); |
689 EXPECT_FALSE(pending_read_); | 718 EXPECT_FALSE(pending_read_); |
690 } | 719 } |
691 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); | 720 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
692 } | 721 } |
693 | 722 |
694 } // namespace media | 723 } // namespace media |
OLD | NEW |