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 |
27 namespace media { | 29 namespace media { |
28 | 30 |
29 struct VideoFrameStreamTestParams { | 31 struct VideoFrameStreamTestParams { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 decoder_ = NULL; | 86 decoder_ = NULL; |
85 video_frame_stream_.reset(); | 87 video_frame_stream_.reset(); |
86 message_loop_.RunUntilIdle(); | 88 message_loop_.RunUntilIdle(); |
87 | 89 |
88 DCHECK(!pending_initialize_); | 90 DCHECK(!pending_initialize_); |
89 DCHECK(!pending_read_); | 91 DCHECK(!pending_read_); |
90 DCHECK(!pending_reset_); | 92 DCHECK(!pending_reset_); |
91 DCHECK(!pending_stop_); | 93 DCHECK(!pending_stop_); |
92 } | 94 } |
93 | 95 |
96 // Used to verify that the number of calls to SetDecryptorReadyCallback() | |
ddorwin
2014/08/04 18:59:08
ditto - skipped this file.
Since we now have 3 co
jrummell
2014/08/07 01:54:25
Done.
| |
97 // match the number of calls to DecryptorSet() and that the calls happen in | |
98 // pairs (e.g. DecryptorSet() called after every SetDecryptorReadyCallback() | |
99 // call). There may be any number of pairs (including 0). | |
100 class CallbackVerifier { | |
101 public: | |
102 CallbackVerifier() : ready_called_(0), set_called_(0) {} | |
103 ~CallbackVerifier() { Verify(); } | |
104 void SetDecryptorReadyCallbackCalled() { ++ready_called_; } | |
105 void DecryptorSetCalled() { | |
106 ++set_called_; | |
107 Verify(); | |
108 } | |
109 void Verify() { EXPECT_EQ(set_called_, ready_called_); } | |
110 | |
111 private: | |
112 int ready_called_; | |
113 int set_called_; | |
114 }; | |
115 | |
94 MOCK_METHOD1(OnNewSpliceBuffer, void(base::TimeDelta)); | 116 MOCK_METHOD1(OnNewSpliceBuffer, void(base::TimeDelta)); |
95 MOCK_METHOD1(SetDecryptorReadyCallback, void(const media::DecryptorReadyCB&)); | 117 MOCK_METHOD1(SetDecryptorReadyCallback, void(const media::DecryptorReadyCB&)); |
118 MOCK_METHOD1(DecryptorSet, void(bool)); | |
96 | 119 |
97 void OnStatistics(const PipelineStatistics& statistics) { | 120 void OnStatistics(const PipelineStatistics& statistics) { |
98 total_bytes_decoded_ += statistics.video_bytes_decoded; | 121 total_bytes_decoded_ += statistics.video_bytes_decoded; |
99 } | 122 } |
100 | 123 |
101 void OnInitialized(bool success) { | 124 void OnInitialized(bool success) { |
102 DCHECK(!pending_read_); | 125 DCHECK(!pending_read_); |
103 DCHECK(!pending_reset_); | 126 DCHECK(!pending_reset_); |
104 DCHECK(pending_initialize_); | 127 DCHECK(pending_initialize_); |
105 pending_initialize_ = false; | 128 pending_initialize_ = false; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 | 235 |
213 case SET_DECRYPTOR: | 236 case SET_DECRYPTOR: |
214 // Hold DecryptorReadyCB. | 237 // Hold DecryptorReadyCB. |
215 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) | 238 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) |
216 .Times(2); | 239 .Times(2); |
217 // Initialize will fail because no decryptor is available. | 240 // Initialize will fail because no decryptor is available. |
218 InitializeVideoFrameStream(); | 241 InitializeVideoFrameStream(); |
219 break; | 242 break; |
220 | 243 |
221 case DECRYPTOR_NO_KEY: | 244 case DECRYPTOR_NO_KEY: |
222 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) | 245 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)).WillRepeatedly(DoAll( |
223 .WillRepeatedly(RunCallback<0>(decryptor_.get())); | 246 InvokeWithoutArgs( |
247 &verifier_, &CallbackVerifier::SetDecryptorReadyCallbackCalled), | |
248 RunCallback<0>(decryptor_.get(), | |
249 base::Bind(&VideoFrameStreamTest::DecryptorSet, | |
250 base::Unretained(this))))); | |
251 EXPECT_CALL(*this, DecryptorSet(Eq(true))) | |
252 .WillRepeatedly(InvokeWithoutArgs( | |
253 &verifier_, &CallbackVerifier::DecryptorSetCalled)); | |
224 has_no_key_ = true; | 254 has_no_key_ = true; |
225 ReadOneFrame(); | 255 ReadOneFrame(); |
226 break; | 256 break; |
227 | 257 |
228 case DECODER_INIT: | 258 case DECODER_INIT: |
229 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)) | 259 EXPECT_CALL(*this, SetDecryptorReadyCallback(_)).WillRepeatedly(DoAll( |
230 .WillRepeatedly(RunCallback<0>(decryptor_.get())); | 260 InvokeWithoutArgs( |
261 &verifier_, &CallbackVerifier::SetDecryptorReadyCallbackCalled), | |
262 RunCallback<0>(decryptor_.get(), | |
263 base::Bind(&VideoFrameStreamTest::DecryptorSet, | |
264 base::Unretained(this))))); | |
265 EXPECT_CALL(*this, DecryptorSet(Eq(true))) | |
266 .WillRepeatedly(InvokeWithoutArgs( | |
267 &verifier_, &CallbackVerifier::DecryptorSetCalled)); | |
231 decoder_->HoldNextInit(); | 268 decoder_->HoldNextInit(); |
232 InitializeVideoFrameStream(); | 269 InitializeVideoFrameStream(); |
233 break; | 270 break; |
234 | 271 |
235 case DECODER_REINIT: | 272 case DECODER_REINIT: |
236 decoder_->HoldNextInit(); | 273 decoder_->HoldNextInit(); |
237 ReadUntilPending(); | 274 ReadUntilPending(); |
238 break; | 275 break; |
239 | 276 |
240 case DECODER_DECODE: | 277 case DECODER_DECODE: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 bool pending_read_; | 362 bool pending_read_; |
326 bool pending_reset_; | 363 bool pending_reset_; |
327 bool pending_stop_; | 364 bool pending_stop_; |
328 int total_bytes_decoded_; | 365 int total_bytes_decoded_; |
329 scoped_refptr<VideoFrame> frame_read_; | 366 scoped_refptr<VideoFrame> frame_read_; |
330 VideoFrameStream::Status last_read_status_; | 367 VideoFrameStream::Status last_read_status_; |
331 | 368 |
332 // Decryptor has no key to decrypt a frame. | 369 // Decryptor has no key to decrypt a frame. |
333 bool has_no_key_; | 370 bool has_no_key_; |
334 | 371 |
372 CallbackVerifier verifier_; | |
373 | |
335 private: | 374 private: |
336 DISALLOW_COPY_AND_ASSIGN(VideoFrameStreamTest); | 375 DISALLOW_COPY_AND_ASSIGN(VideoFrameStreamTest); |
337 }; | 376 }; |
338 | 377 |
339 INSTANTIATE_TEST_CASE_P( | 378 INSTANTIATE_TEST_CASE_P( |
340 Clear, | 379 Clear, |
341 VideoFrameStreamTest, | 380 VideoFrameStreamTest, |
342 ::testing::Values( | 381 ::testing::Values( |
343 VideoFrameStreamTestParams(false, 0, 1), | 382 VideoFrameStreamTestParams(false, 0, 1), |
344 VideoFrameStreamTestParams(false, 3, 1), | 383 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. | 724 // The error must surface from Read() as DECODE_ERROR. |
686 while (last_read_status_ == VideoFrameStream::OK) { | 725 while (last_read_status_ == VideoFrameStream::OK) { |
687 ReadOneFrame(); | 726 ReadOneFrame(); |
688 message_loop_.RunUntilIdle(); | 727 message_loop_.RunUntilIdle(); |
689 EXPECT_FALSE(pending_read_); | 728 EXPECT_FALSE(pending_read_); |
690 } | 729 } |
691 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); | 730 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); |
692 } | 731 } |
693 | 732 |
694 } // namespace media | 733 } // namespace media |
OLD | NEW |