Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: media/filters/video_frame_stream_unittest.cc

Issue 2650823006: media: Pass CdmContext in decoder reinitialization (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/filters/fake_video_decoder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 5 #include <utility>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 17 matching lines...) Expand all
28 using ::testing::SaveArg; 28 using ::testing::SaveArg;
29 using ::testing::StrictMock; 29 using ::testing::StrictMock;
30 30
31 static const int kNumConfigs = 4; 31 static const int kNumConfigs = 4;
32 static const int kNumBuffersInOneConfig = 5; 32 static const int kNumBuffersInOneConfig = 5;
33 33
34 namespace media { 34 namespace media {
35 35
36 struct VideoFrameStreamTestParams { 36 struct VideoFrameStreamTestParams {
37 VideoFrameStreamTestParams(bool is_encrypted, 37 VideoFrameStreamTestParams(bool is_encrypted,
38 bool has_decryptor,
38 int decoding_delay, 39 int decoding_delay,
39 int parallel_decoding) 40 int parallel_decoding)
40 : is_encrypted(is_encrypted), 41 : is_encrypted(is_encrypted),
42 has_decryptor(has_decryptor),
41 decoding_delay(decoding_delay), 43 decoding_delay(decoding_delay),
42 parallel_decoding(parallel_decoding) {} 44 parallel_decoding(parallel_decoding) {}
43 45
44 bool is_encrypted; 46 bool is_encrypted;
47 bool has_decryptor;
45 int decoding_delay; 48 int decoding_delay;
46 int parallel_decoding; 49 int parallel_decoding;
47 }; 50 };
48 51
49 class VideoFrameStreamTest 52 class VideoFrameStreamTest
50 : public testing::Test, 53 : public testing::Test,
51 public testing::WithParamInterface<VideoFrameStreamTestParams> { 54 public testing::WithParamInterface<VideoFrameStreamTestParams> {
52 public: 55 public:
53 VideoFrameStreamTest() 56 VideoFrameStreamTest()
54 : demuxer_stream_(new FakeDemuxerStream(kNumConfigs, 57 : demuxer_stream_(new FakeDemuxerStream(kNumConfigs,
55 kNumBuffersInOneConfig, 58 kNumBuffersInOneConfig,
56 GetParam().is_encrypted)), 59 GetParam().is_encrypted)),
57 cdm_context_(new StrictMock<MockCdmContext>()), 60 cdm_context_(new StrictMock<MockCdmContext>()),
58 decryptor_(new NiceMock<MockDecryptor>()),
59 decoder1_(
60 new FakeVideoDecoder(GetParam().decoding_delay,
61 GetParam().parallel_decoding,
62 base::Bind(
63 &VideoFrameStreamTest::OnBytesDecoded,
64 base::Unretained(this)))),
65 decoder2_(
66 new FakeVideoDecoder(GetParam().decoding_delay,
67 GetParam().parallel_decoding,
68 base::Bind(
69 &VideoFrameStreamTest::OnBytesDecoded,
70 base::Unretained(this)))),
71 decoder3_(
72 new FakeVideoDecoder(GetParam().decoding_delay,
73 GetParam().parallel_decoding,
74 base::Bind(
75 &VideoFrameStreamTest::OnBytesDecoded,
76 base::Unretained(this)))),
77 is_initialized_(false), 61 is_initialized_(false),
78 num_decoded_frames_(0), 62 num_decoded_frames_(0),
79 pending_initialize_(false), 63 pending_initialize_(false),
80 pending_read_(false), 64 pending_read_(false),
81 pending_reset_(false), 65 pending_reset_(false),
82 pending_stop_(false), 66 pending_stop_(false),
83 num_decoded_bytes_unreported_(0), 67 num_decoded_bytes_unreported_(0),
84 has_no_key_(false) { 68 has_no_key_(false) {
69 int decoding_delay = GetParam().decoding_delay;
70 int parallel_decoding = GetParam().parallel_decoding;
71 BytesDecodedCB bytes_decoded_cb = base::Bind(
72 &VideoFrameStreamTest::OnBytesDecoded, base::Unretained(this));
73
74 decoder1_ = new FakeVideoDecoder(decoding_delay, parallel_decoding,
75 bytes_decoded_cb);
76 decoder2_ = new FakeVideoDecoder(decoding_delay, parallel_decoding,
77 bytes_decoded_cb);
78 decoder3_ = new FakeVideoDecoder(decoding_delay, parallel_decoding,
79 bytes_decoded_cb);
80
81 // TODO(xhwang): We should test the case where only certain decoder
82 // supports encrypted streams. Currently this is hard to test becasue we use
83 // parameterized tests which need to pass in all combinations.
84 if (GetParam().is_encrypted && !GetParam().has_decryptor) {
85 decoder1_->EnableEncryptedConfigSupport();
86 decoder2_->EnableEncryptedConfigSupport();
87 decoder3_->EnableEncryptedConfigSupport();
88 }
89
85 ScopedVector<VideoDecoder> decoders; 90 ScopedVector<VideoDecoder> decoders;
86 decoders.push_back(decoder1_); 91 decoders.push_back(decoder1_);
87 decoders.push_back(decoder2_); 92 decoders.push_back(decoder2_);
88 decoders.push_back(decoder3_); 93 decoders.push_back(decoder3_);
89 94
90 video_frame_stream_.reset(new VideoFrameStream( 95 video_frame_stream_.reset(new VideoFrameStream(
91 message_loop_.task_runner(), std::move(decoders), new MediaLog())); 96 message_loop_.task_runner(), std::move(decoders), new MediaLog()));
92 97
98 if (GetParam().has_decryptor) {
99 decryptor_.reset(new NiceMock<MockDecryptor>());
100
101 // Decryptor can only decrypt (not decrypt-and-decode) so that
102 // DecryptingDemuxerStream will be used.
103 EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _))
104 .WillRepeatedly(RunCallback<1>(false));
105 EXPECT_CALL(*decryptor_, Decrypt(_, _, _))
106 .WillRepeatedly(Invoke(this, &VideoFrameStreamTest::Decrypt));
107 }
108
93 EXPECT_CALL(*cdm_context_, GetDecryptor()) 109 EXPECT_CALL(*cdm_context_, GetDecryptor())
94 .WillRepeatedly(Return(decryptor_.get())); 110 .WillRepeatedly(Return(decryptor_.get()));
95
96 // Decryptor can only decrypt (not decrypt-and-decode) so that
97 // DecryptingDemuxerStream will be used.
98 EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _))
99 .WillRepeatedly(RunCallback<1>(false));
100 EXPECT_CALL(*decryptor_, Decrypt(_, _, _))
101 .WillRepeatedly(Invoke(this, &VideoFrameStreamTest::Decrypt));
102 } 111 }
103 112
104 ~VideoFrameStreamTest() { 113 ~VideoFrameStreamTest() {
105 // Check that the pipeline statistics callback was fired correctly. 114 // Check that the pipeline statistics callback was fired correctly.
106 EXPECT_EQ(num_decoded_bytes_unreported_, 0); 115 EXPECT_EQ(num_decoded_bytes_unreported_, 0);
107 116
108 is_initialized_ = false; 117 is_initialized_ = false;
109 decoder1_ = NULL; 118 decoder1_ = NULL;
110 decoder2_ = NULL; 119 decoder2_ = NULL;
111 decoder3_ = NULL; 120 decoder3_ = NULL;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 demuxer_stream_->HoldNextRead(); 254 demuxer_stream_->HoldNextRead();
246 ReadUntilPending(); 255 ReadUntilPending();
247 break; 256 break;
248 257
249 case DEMUXER_READ_CONFIG_CHANGE: 258 case DEMUXER_READ_CONFIG_CHANGE:
250 demuxer_stream_->HoldNextConfigChangeRead(); 259 demuxer_stream_->HoldNextConfigChangeRead();
251 ReadUntilPending(); 260 ReadUntilPending();
252 break; 261 break;
253 262
254 case DECRYPTOR_NO_KEY: 263 case DECRYPTOR_NO_KEY:
255 if (GetParam().is_encrypted) 264 if (GetParam().is_encrypted && GetParam().has_decryptor) {
256 EXPECT_CALL(*this, OnWaitingForDecryptionKey()); 265 EXPECT_CALL(*this, OnWaitingForDecryptionKey());
257 has_no_key_ = true; 266 has_no_key_ = true;
267 }
258 ReadOneFrame(); 268 ReadOneFrame();
259 break; 269 break;
260 270
261 case DECODER_INIT: 271 case DECODER_INIT:
262 decoder->HoldNextInit(); 272 decoder->HoldNextInit();
263 InitializeVideoFrameStream(); 273 InitializeVideoFrameStream();
264 break; 274 break;
265 275
266 case DECODER_REINIT: 276 case DECODER_REINIT:
267 decoder->HoldNextInit(); 277 decoder->HoldNextInit();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 // Decryptor has no key to decrypt a frame. 388 // Decryptor has no key to decrypt a frame.
379 bool has_no_key_; 389 bool has_no_key_;
380 390
381 private: 391 private:
382 DISALLOW_COPY_AND_ASSIGN(VideoFrameStreamTest); 392 DISALLOW_COPY_AND_ASSIGN(VideoFrameStreamTest);
383 }; 393 };
384 394
385 INSTANTIATE_TEST_CASE_P( 395 INSTANTIATE_TEST_CASE_P(
386 Clear, 396 Clear,
387 VideoFrameStreamTest, 397 VideoFrameStreamTest,
388 ::testing::Values( 398 ::testing::Values(VideoFrameStreamTestParams(false, false, 0, 1),
389 VideoFrameStreamTestParams(false, 0, 1), 399 VideoFrameStreamTestParams(false, false, 3, 1),
390 VideoFrameStreamTestParams(false, 3, 1), 400 VideoFrameStreamTestParams(false, false, 7, 1)));
391 VideoFrameStreamTestParams(false, 7, 1)));
392 401
393 INSTANTIATE_TEST_CASE_P( 402 INSTANTIATE_TEST_CASE_P(
394 Encrypted, 403 EncryptedWithDecryptor,
395 VideoFrameStreamTest, 404 VideoFrameStreamTest,
396 ::testing::Values( 405 ::testing::Values(VideoFrameStreamTestParams(true, true, 7, 1)));
397 VideoFrameStreamTestParams(true, 7, 1))); 406
407 INSTANTIATE_TEST_CASE_P(
408 EncryptedWithoutDecryptor,
409 VideoFrameStreamTest,
410 ::testing::Values(VideoFrameStreamTestParams(true, false, 7, 1)));
398 411
399 INSTANTIATE_TEST_CASE_P( 412 INSTANTIATE_TEST_CASE_P(
400 Clear_Parallel, 413 Clear_Parallel,
401 VideoFrameStreamTest, 414 VideoFrameStreamTest,
402 ::testing::Values( 415 ::testing::Values(VideoFrameStreamTestParams(false, false, 0, 3),
403 VideoFrameStreamTestParams(false, 0, 3), 416 VideoFrameStreamTestParams(false, false, 2, 3)));
404 VideoFrameStreamTestParams(false, 2, 3)));
405
406 417
407 TEST_P(VideoFrameStreamTest, Initialization) { 418 TEST_P(VideoFrameStreamTest, Initialization) {
408 Initialize(); 419 Initialize();
420 EXPECT_TRUE(is_initialized_);
409 } 421 }
410 422
411 TEST_P(VideoFrameStreamTest, AllDecoderInitializationFails) { 423 TEST_P(VideoFrameStreamTest, AllDecoderInitializationFails) {
412 decoder1_->SimulateFailureToInit(); 424 decoder1_->SimulateFailureToInit();
413 decoder2_->SimulateFailureToInit(); 425 decoder2_->SimulateFailureToInit();
414 decoder3_->SimulateFailureToInit(); 426 decoder3_->SimulateFailureToInit();
415 Initialize(); 427 Initialize();
416 EXPECT_FALSE(is_initialized_); 428 EXPECT_FALSE(is_initialized_);
417 } 429 }
418 430
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 1118
1107 TEST_P(VideoFrameStreamTest, Destroy_DuringFallbackDecoderSelection) { 1119 TEST_P(VideoFrameStreamTest, Destroy_DuringFallbackDecoderSelection) {
1108 Initialize(); 1120 Initialize();
1109 decoder1_->SimulateFailureToInit(); 1121 decoder1_->SimulateFailureToInit();
1110 EnterPendingState(DECODER_REINIT); 1122 EnterPendingState(DECODER_REINIT);
1111 decoder2_->HoldNextInit(); 1123 decoder2_->HoldNextInit();
1112 SatisfyPendingCallback(DECODER_REINIT); 1124 SatisfyPendingCallback(DECODER_REINIT);
1113 } 1125 }
1114 1126
1115 } // namespace media 1127 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/fake_video_decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698