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