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

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

Issue 2835203006: media: Refactor VideoFrameStreamTest (Closed)
Patch Set: Created 3 years, 7 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
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"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/string_number_conversions.h"
12 #include "media/base/fake_demuxer_stream.h" 13 #include "media/base/fake_demuxer_stream.h"
13 #include "media/base/gmock_callback_support.h" 14 #include "media/base/gmock_callback_support.h"
14 #include "media/base/mock_filters.h" 15 #include "media/base/mock_filters.h"
15 #include "media/base/test_helpers.h" 16 #include "media/base/test_helpers.h"
16 #include "media/base/timestamp_constants.h" 17 #include "media/base/timestamp_constants.h"
17 #include "media/filters/decoder_stream.h" 18 #include "media/filters/decoder_stream.h"
18 #include "media/filters/fake_video_decoder.h" 19 #include "media/filters/fake_video_decoder.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 using ::testing::_; 22 using ::testing::_;
22 using ::testing::AnyNumber; 23 using ::testing::AnyNumber;
23 using ::testing::Assign; 24 using ::testing::Assign;
24 using ::testing::Invoke; 25 using ::testing::Invoke;
25 using ::testing::InvokeWithoutArgs; 26 using ::testing::InvokeWithoutArgs;
26 using ::testing::NiceMock; 27 using ::testing::NiceMock;
27 using ::testing::Return; 28 using ::testing::Return;
28 using ::testing::SaveArg; 29 using ::testing::SaveArg;
29 using ::testing::StrictMock; 30 using ::testing::StrictMock;
30 31
31 static const int kNumConfigs = 4; 32 namespace media {
32 static const int kNumBuffersInOneConfig = 5;
33 33
34 namespace media { 34 namespace {
DaleCurtis 2017/04/26 19:41:14 no anonymous namespace in media generally. use sta
xhwang 2017/04/27 21:11:14 Done.
35
36 const int kNumConfigs = 4;
37 const int kNumBuffersInOneConfig = 5;
38
39 std::string GetDecoderName(int i) {
40 return std::string("VideoDecoder") + base::IntToString(i);
41 }
42
43 } // namespace
35 44
36 struct VideoFrameStreamTestParams { 45 struct VideoFrameStreamTestParams {
37 VideoFrameStreamTestParams(bool is_encrypted, 46 VideoFrameStreamTestParams(bool is_encrypted,
38 bool has_decryptor, 47 bool has_decryptor,
39 int decoding_delay, 48 int decoding_delay,
40 int parallel_decoding) 49 int parallel_decoding)
41 : is_encrypted(is_encrypted), 50 : is_encrypted(is_encrypted),
42 has_decryptor(has_decryptor), 51 has_decryptor(has_decryptor),
43 decoding_delay(decoding_delay), 52 decoding_delay(decoding_delay),
44 parallel_decoding(parallel_decoding) {} 53 parallel_decoding(parallel_decoding) {}
(...skipping 18 matching lines...) Expand all
63 pending_read_(false), 72 pending_read_(false),
64 pending_reset_(false), 73 pending_reset_(false),
65 pending_stop_(false), 74 pending_stop_(false),
66 num_decoded_bytes_unreported_(0), 75 num_decoded_bytes_unreported_(0),
67 has_no_key_(false) { 76 has_no_key_(false) {
68 int decoding_delay = GetParam().decoding_delay; 77 int decoding_delay = GetParam().decoding_delay;
69 int parallel_decoding = GetParam().parallel_decoding; 78 int parallel_decoding = GetParam().parallel_decoding;
70 BytesDecodedCB bytes_decoded_cb = base::Bind( 79 BytesDecodedCB bytes_decoded_cb = base::Bind(
71 &VideoFrameStreamTest::OnBytesDecoded, base::Unretained(this)); 80 &VideoFrameStreamTest::OnBytesDecoded, base::Unretained(this));
72 81
73 decoder1_ = new FakeVideoDecoder(decoding_delay, parallel_decoding, 82 // Provide 3 decoders to test fallback cases.
74 bytes_decoded_cb);
75 decoder2_ = new FakeVideoDecoder(decoding_delay, parallel_decoding,
76 bytes_decoded_cb);
77 decoder3_ = new FakeVideoDecoder(decoding_delay, parallel_decoding,
78 bytes_decoded_cb);
79
80 // TODO(xhwang): We should test the case where only certain decoder 83 // TODO(xhwang): We should test the case where only certain decoder
81 // supports encrypted streams. Currently this is hard to test because we use 84 // supports encrypted streams. Currently this is hard to test because we use
82 // parameterized tests which need to pass in all combinations. 85 // parameterized tests which need to pass in all combinations.
83 if (GetParam().is_encrypted && !GetParam().has_decryptor) { 86 ScopedVector<VideoDecoder> decoders;
84 decoder1_->EnableEncryptedConfigSupport(); 87 for (int i = 0; i < 3; ++i) {
85 decoder2_->EnableEncryptedConfigSupport(); 88 FakeVideoDecoder* decoder =
86 decoder3_->EnableEncryptedConfigSupport(); 89 new FakeVideoDecoder(GetDecoderName(i), decoding_delay,
90 parallel_decoding, bytes_decoded_cb);
91
92 if (GetParam().is_encrypted && !GetParam().has_decryptor)
93 decoder->EnableEncryptedConfigSupport();
94
95 decoders.push_back(decoder);
96
97 // Keep a copy of the raw pointers so we can change the behavior of each
98 // decoder.
99 decoders_.push_back(decoder);
87 } 100 }
88 101
89 ScopedVector<VideoDecoder> decoders;
90 decoders.push_back(decoder1_);
91 decoders.push_back(decoder2_);
92 decoders.push_back(decoder3_);
93
94 video_frame_stream_.reset(new VideoFrameStream( 102 video_frame_stream_.reset(new VideoFrameStream(
95 message_loop_.task_runner(), std::move(decoders), &media_log_)); 103 message_loop_.task_runner(), std::move(decoders), &media_log_));
96 104
105 video_frame_stream_->set_decoder_change_observer_for_testing(base::Bind(
106 &VideoFrameStreamTest::OnDecoderChanged, base::Unretained(this)));
107
97 if (GetParam().is_encrypted && GetParam().has_decryptor) { 108 if (GetParam().is_encrypted && GetParam().has_decryptor) {
98 decryptor_.reset(new NiceMock<MockDecryptor>()); 109 decryptor_.reset(new NiceMock<MockDecryptor>());
99 110
100 // Decryptor can only decrypt (not decrypt-and-decode) so that 111 // Decryptor can only decrypt (not decrypt-and-decode) so that
101 // DecryptingDemuxerStream will be used. 112 // DecryptingDemuxerStream will be used.
102 EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _)) 113 EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _))
103 .WillRepeatedly(RunCallback<1>(false)); 114 .WillRepeatedly(RunCallback<1>(false));
104 EXPECT_CALL(*decryptor_, Decrypt(_, _, _)) 115 EXPECT_CALL(*decryptor_, Decrypt(_, _, _))
105 .WillRepeatedly(Invoke(this, &VideoFrameStreamTest::Decrypt)); 116 .WillRepeatedly(Invoke(this, &VideoFrameStreamTest::Decrypt));
106 } 117 }
107 118
108 if (GetParam().is_encrypted) { 119 if (GetParam().is_encrypted) {
109 cdm_context_.reset(new StrictMock<MockCdmContext>()); 120 cdm_context_.reset(new StrictMock<MockCdmContext>());
110 121
111 EXPECT_CALL(*cdm_context_, GetDecryptor()) 122 EXPECT_CALL(*cdm_context_, GetDecryptor())
112 .WillRepeatedly(Return(decryptor_.get())); 123 .WillRepeatedly(Return(decryptor_.get()));
113 } 124 }
114 } 125 }
115 126
116 ~VideoFrameStreamTest() { 127 ~VideoFrameStreamTest() {
117 // Check that the pipeline statistics callback was fired correctly. 128 // Check that the pipeline statistics callback was fired correctly.
118 EXPECT_EQ(num_decoded_bytes_unreported_, 0); 129 EXPECT_EQ(num_decoded_bytes_unreported_, 0);
119 130
120 is_initialized_ = false; 131 is_initialized_ = false;
121 decoder1_ = NULL; 132 decoders_.clear();
122 decoder2_ = NULL;
123 decoder3_ = NULL;
124 video_frame_stream_.reset(); 133 video_frame_stream_.reset();
125 base::RunLoop().RunUntilIdle(); 134 base::RunLoop().RunUntilIdle();
126 135
127 DCHECK(!pending_initialize_); 136 DCHECK(!pending_initialize_);
128 DCHECK(!pending_read_); 137 DCHECK(!pending_read_);
129 DCHECK(!pending_reset_); 138 DCHECK(!pending_reset_);
130 DCHECK(!pending_stop_); 139 DCHECK(!pending_stop_);
131 } 140 }
132 141
133 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); 142 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void));
134 143
135 void OnStatistics(const PipelineStatistics& statistics) { 144 void OnStatistics(const PipelineStatistics& statistics) {
136 num_decoded_bytes_unreported_ -= statistics.video_bytes_decoded; 145 num_decoded_bytes_unreported_ -= statistics.video_bytes_decoded;
137 } 146 }
138 147
139 void OnBytesDecoded(int count) { 148 void OnBytesDecoded(int count) {
140 num_decoded_bytes_unreported_ += count; 149 num_decoded_bytes_unreported_ += count;
141 } 150 }
142 151
152 void SimulateDecoderInitFailure(const std::vector<int>& decoder_indices) {
153 for (const auto& i : decoder_indices)
154 decoders_[i]->SimulateFailureToInit();
155 }
156
143 void OnInitialized(bool success) { 157 void OnInitialized(bool success) {
144 DCHECK(!pending_read_); 158 DCHECK(!pending_read_);
145 DCHECK(!pending_reset_); 159 DCHECK(!pending_reset_);
146 DCHECK(pending_initialize_); 160 DCHECK(pending_initialize_);
147 pending_initialize_ = false; 161 pending_initialize_ = false;
148 162
149 is_initialized_ = success; 163 is_initialized_ = success;
150 if (!success) { 164 if (!success)
151 decoder1_ = NULL; 165 decoders_.clear();
152 decoder2_ = NULL;
153 decoder3_ = NULL;
154 }
155 } 166 }
156 167
157 void InitializeVideoFrameStream() { 168 void Initialize() {
158 pending_initialize_ = true; 169 pending_initialize_ = true;
159 video_frame_stream_->Initialize( 170 video_frame_stream_->Initialize(
160 demuxer_stream_.get(), base::Bind(&VideoFrameStreamTest::OnInitialized, 171 demuxer_stream_.get(), base::Bind(&VideoFrameStreamTest::OnInitialized,
161 base::Unretained(this)), 172 base::Unretained(this)),
162 cdm_context_.get(), 173 cdm_context_.get(),
163 base::Bind(&VideoFrameStreamTest::OnStatistics, base::Unretained(this)), 174 base::Bind(&VideoFrameStreamTest::OnStatistics, base::Unretained(this)),
164 base::Bind(&VideoFrameStreamTest::OnWaitingForDecryptionKey, 175 base::Bind(&VideoFrameStreamTest::OnWaitingForDecryptionKey,
165 base::Unretained(this))); 176 base::Unretained(this)));
166 base::RunLoop().RunUntilIdle(); 177 base::RunLoop().RunUntilIdle();
167 } 178 }
168 179
180 void OnDecoderChanged(VideoDecoder* decoder) {
181 if (!decoder) {
182 decoder_ = nullptr;
183 return;
184 }
185
186 std::string name = decoder->GetDisplayName();
187 ASSERT_TRUE(GetDecoderName(0) == name || GetDecoderName(1) == name ||
188 GetDecoderName(2) == name);
189 decoder_ = static_cast<FakeVideoDecoder*>(decoder);
190 }
191
169 // Fake Decrypt() function used by DecryptingDemuxerStream. It does nothing 192 // Fake Decrypt() function used by DecryptingDemuxerStream. It does nothing
170 // but removes the DecryptConfig to make the buffer unencrypted. 193 // but removes the DecryptConfig to make the buffer unencrypted.
171 void Decrypt(Decryptor::StreamType stream_type, 194 void Decrypt(Decryptor::StreamType stream_type,
172 const scoped_refptr<DecoderBuffer>& encrypted, 195 const scoped_refptr<DecoderBuffer>& encrypted,
173 const Decryptor::DecryptCB& decrypt_cb) { 196 const Decryptor::DecryptCB& decrypt_cb) {
174 DCHECK(encrypted->decrypt_config()); 197 DCHECK(encrypted->decrypt_config());
175 if (has_no_key_) { 198 if (has_no_key_) {
176 decrypt_cb.Run(Decryptor::kNoKey, NULL); 199 decrypt_cb.Run(Decryptor::kNoKey, NULL);
177 return; 200 return;
178 } 201 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 void ReadAllFrames() { 256 void ReadAllFrames() {
234 // No frames should have been dropped. 257 // No frames should have been dropped.
235 ReadAllFrames(kNumConfigs * kNumBuffersInOneConfig); 258 ReadAllFrames(kNumConfigs * kNumBuffersInOneConfig);
236 } 259 }
237 260
238 enum PendingState { 261 enum PendingState {
239 NOT_PENDING, 262 NOT_PENDING,
240 DEMUXER_READ_NORMAL, 263 DEMUXER_READ_NORMAL,
241 DEMUXER_READ_CONFIG_CHANGE, 264 DEMUXER_READ_CONFIG_CHANGE,
242 DECRYPTOR_NO_KEY, 265 DECRYPTOR_NO_KEY,
243 DECODER_INIT,
244 DECODER_REINIT, 266 DECODER_REINIT,
245 DECODER_DECODE, 267 DECODER_DECODE,
246 DECODER_RESET 268 DECODER_RESET
247 }; 269 };
248 270
249 void EnterPendingState(PendingState state) { 271 void EnterPendingState(PendingState state) {
250 EnterPendingState(state, decoder1_);
251 }
252
253 void EnterPendingState(PendingState state, FakeVideoDecoder* decoder) {
254 DCHECK_NE(state, NOT_PENDING); 272 DCHECK_NE(state, NOT_PENDING);
255 switch (state) { 273 switch (state) {
256 case DEMUXER_READ_NORMAL: 274 case DEMUXER_READ_NORMAL:
257 demuxer_stream_->HoldNextRead(); 275 demuxer_stream_->HoldNextRead();
258 ReadUntilPending(); 276 ReadUntilPending();
259 break; 277 break;
260 278
261 case DEMUXER_READ_CONFIG_CHANGE: 279 case DEMUXER_READ_CONFIG_CHANGE:
262 demuxer_stream_->HoldNextConfigChangeRead(); 280 demuxer_stream_->HoldNextConfigChangeRead();
263 ReadUntilPending(); 281 ReadUntilPending();
264 break; 282 break;
265 283
266 case DECRYPTOR_NO_KEY: 284 case DECRYPTOR_NO_KEY:
267 if (GetParam().is_encrypted && GetParam().has_decryptor) { 285 if (GetParam().is_encrypted && GetParam().has_decryptor) {
268 EXPECT_CALL(*this, OnWaitingForDecryptionKey()); 286 EXPECT_CALL(*this, OnWaitingForDecryptionKey());
269 has_no_key_ = true; 287 has_no_key_ = true;
270 } 288 }
271 ReadOneFrame(); 289 ReadOneFrame();
272 break; 290 break;
273 291
274 case DECODER_INIT:
275 decoder->HoldNextInit();
276 InitializeVideoFrameStream();
277 break;
278
279 case DECODER_REINIT: 292 case DECODER_REINIT:
280 decoder->HoldNextInit(); 293 decoder_->HoldNextInit();
281 ReadUntilPending(); 294 ReadUntilPending();
282 break; 295 break;
283 296
284 case DECODER_DECODE: 297 case DECODER_DECODE:
285 decoder->HoldDecode(); 298 decoder_->HoldDecode();
286 ReadUntilPending(); 299 ReadUntilPending();
287 break; 300 break;
288 301
289 case DECODER_RESET: 302 case DECODER_RESET:
290 decoder->HoldNextReset(); 303 decoder_->HoldNextReset();
291 pending_reset_ = true; 304 pending_reset_ = true;
292 video_frame_stream_->Reset(base::Bind(&VideoFrameStreamTest::OnReset, 305 video_frame_stream_->Reset(base::Bind(&VideoFrameStreamTest::OnReset,
293 base::Unretained(this))); 306 base::Unretained(this)));
294 base::RunLoop().RunUntilIdle(); 307 base::RunLoop().RunUntilIdle();
295 break; 308 break;
296 309
297 case NOT_PENDING: 310 case NOT_PENDING:
298 NOTREACHED(); 311 NOTREACHED();
299 break; 312 break;
300 } 313 }
301 } 314 }
302 315
303 void SatisfyPendingCallback(PendingState state) { 316 void SatisfyPendingCallback(PendingState state) {
304 SatisfyPendingCallback(state, decoder1_);
305 }
306
307 void SatisfyPendingCallback(PendingState state, FakeVideoDecoder* decoder) {
308 DCHECK_NE(state, NOT_PENDING); 317 DCHECK_NE(state, NOT_PENDING);
309 switch (state) { 318 switch (state) {
310 case DEMUXER_READ_NORMAL: 319 case DEMUXER_READ_NORMAL:
311 case DEMUXER_READ_CONFIG_CHANGE: 320 case DEMUXER_READ_CONFIG_CHANGE:
312 demuxer_stream_->SatisfyRead(); 321 demuxer_stream_->SatisfyRead();
313 break; 322 break;
314 323
315 // This is only interesting to test during VideoFrameStream destruction. 324 // This is only interesting to test during VideoFrameStream destruction.
316 // There's no need to satisfy a callback. 325 // There's no need to satisfy a callback.
317 case DECRYPTOR_NO_KEY: 326 case DECRYPTOR_NO_KEY:
318 NOTREACHED(); 327 NOTREACHED();
319 break; 328 break;
320 329
321 case DECODER_INIT:
322 decoder->SatisfyInit();
323 break;
324
325 case DECODER_REINIT: 330 case DECODER_REINIT:
326 decoder->SatisfyInit(); 331 decoder_->SatisfyInit();
327 break; 332 break;
328 333
329 case DECODER_DECODE: 334 case DECODER_DECODE:
330 decoder->SatisfyDecode(); 335 decoder_->SatisfyDecode();
331 break; 336 break;
332 337
333 case DECODER_RESET: 338 case DECODER_RESET:
334 decoder->SatisfyReset(); 339 decoder_->SatisfyReset();
335 break; 340 break;
336 341
337 case NOT_PENDING: 342 case NOT_PENDING:
338 NOTREACHED(); 343 NOTREACHED();
339 break; 344 break;
340 } 345 }
341 346
342 base::RunLoop().RunUntilIdle(); 347 base::RunLoop().RunUntilIdle();
343 } 348 }
344 349
345 void Initialize() {
346 EnterPendingState(DECODER_INIT);
347 SatisfyPendingCallback(DECODER_INIT);
348 }
349
350 void Read() { 350 void Read() {
351 EnterPendingState(DECODER_DECODE); 351 EnterPendingState(DECODER_DECODE);
352 SatisfyPendingCallback(DECODER_DECODE); 352 SatisfyPendingCallback(DECODER_DECODE);
353 } 353 }
354 354
355 void Reset() { 355 void Reset() {
356 EnterPendingState(DECODER_RESET); 356 EnterPendingState(DECODER_RESET);
357 SatisfyPendingCallback(DECODER_RESET); 357 SatisfyPendingCallback(DECODER_RESET);
358 } 358 }
359 359
360 void ReadUntilDecoderReinitialized(FakeVideoDecoder* decoder) { 360 void ReadUntilDecoderReinitialized() {
361 EnterPendingState(DECODER_REINIT, decoder); 361 EnterPendingState(DECODER_REINIT);
362 SatisfyPendingCallback(DECODER_REINIT, decoder); 362 SatisfyPendingCallback(DECODER_REINIT);
363 } 363 }
364 364
365 base::MessageLoop message_loop_; 365 base::MessageLoop message_loop_;
366 366
367 MediaLog media_log_; 367 MediaLog media_log_;
368 std::unique_ptr<VideoFrameStream> video_frame_stream_; 368 std::unique_ptr<VideoFrameStream> video_frame_stream_;
369 std::unique_ptr<FakeDemuxerStream> demuxer_stream_; 369 std::unique_ptr<FakeDemuxerStream> demuxer_stream_;
370 std::unique_ptr<StrictMock<MockCdmContext>> cdm_context_; 370 std::unique_ptr<StrictMock<MockCdmContext>> cdm_context_;
371 371
372 // Use NiceMock since we don't care about most of calls on the decryptor, 372 // Use NiceMock since we don't care about most of calls on the decryptor,
373 // e.g. RegisterNewKeyCB(). 373 // e.g. RegisterNewKeyCB().
374 std::unique_ptr<NiceMock<MockDecryptor>> decryptor_; 374 std::unique_ptr<NiceMock<MockDecryptor>> decryptor_;
375 375
376 // Raw pointers to the list of decoders to be select from by DecoderSelector.
376 // Three decoders are needed to test that decoder fallback can occur more than 377 // Three decoders are needed to test that decoder fallback can occur more than
377 // once on a config change. They are owned by |video_frame_stream_|. 378 // once on a config change. They are owned by |video_frame_stream_|.
378 FakeVideoDecoder* decoder1_; 379 std::vector<FakeVideoDecoder*> decoders_;
379 FakeVideoDecoder* decoder2_; 380
380 FakeVideoDecoder* decoder3_; 381 // The current decoder used by |video_frame_stream_|.
382 FakeVideoDecoder* decoder_;
381 383
382 bool is_initialized_; 384 bool is_initialized_;
383 int num_decoded_frames_; 385 int num_decoded_frames_;
384 bool pending_initialize_; 386 bool pending_initialize_;
385 bool pending_read_; 387 bool pending_read_;
386 bool pending_reset_; 388 bool pending_reset_;
387 bool pending_stop_; 389 bool pending_stop_;
388 int num_decoded_bytes_unreported_; 390 int num_decoded_bytes_unreported_;
389 scoped_refptr<VideoFrame> frame_read_; 391 scoped_refptr<VideoFrame> frame_read_;
390 VideoFrameStream::Status last_read_status_; 392 VideoFrameStream::Status last_read_status_;
(...skipping 27 matching lines...) Expand all
418 VideoFrameStreamTest, 420 VideoFrameStreamTest,
419 ::testing::Values(VideoFrameStreamTestParams(false, false, 0, 3), 421 ::testing::Values(VideoFrameStreamTestParams(false, false, 0, 3),
420 VideoFrameStreamTestParams(false, false, 2, 3))); 422 VideoFrameStreamTestParams(false, false, 2, 3)));
421 423
422 TEST_P(VideoFrameStreamTest, Initialization) { 424 TEST_P(VideoFrameStreamTest, Initialization) {
423 Initialize(); 425 Initialize();
424 EXPECT_TRUE(is_initialized_); 426 EXPECT_TRUE(is_initialized_);
425 } 427 }
426 428
427 TEST_P(VideoFrameStreamTest, AllDecoderInitializationFails) { 429 TEST_P(VideoFrameStreamTest, AllDecoderInitializationFails) {
428 decoder1_->SimulateFailureToInit(); 430 SimulateDecoderInitFailure({0, 1, 2});
429 decoder2_->SimulateFailureToInit();
430 decoder3_->SimulateFailureToInit();
431 Initialize(); 431 Initialize();
432 EXPECT_FALSE(is_initialized_); 432 EXPECT_FALSE(is_initialized_);
433 } 433 }
434 434
435 TEST_P(VideoFrameStreamTest, PartialDecoderInitializationFails) { 435 TEST_P(VideoFrameStreamTest, PartialDecoderInitializationFails) {
436 decoder1_->SimulateFailureToInit(); 436 SimulateDecoderInitFailure({0, 1});
437 decoder2_->SimulateFailureToInit();
438 Initialize(); 437 Initialize();
439 EXPECT_TRUE(is_initialized_); 438 EXPECT_TRUE(is_initialized_);
440 } 439 }
441 440
442 TEST_P(VideoFrameStreamTest, ReadOneFrame) { 441 TEST_P(VideoFrameStreamTest, ReadOneFrame) {
443 Initialize(); 442 Initialize();
444 Read(); 443 Read();
445 } 444 }
446 445
447 TEST_P(VideoFrameStreamTest, ReadAllFrames) { 446 TEST_P(VideoFrameStreamTest, ReadAllFrames) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 EXPECT_FALSE(pending_read_); 485 EXPECT_FALSE(pending_read_);
487 } 486 }
488 487
489 TEST_P(VideoFrameStreamTest, Read_BlockedDemuxerAndDecoder) { 488 TEST_P(VideoFrameStreamTest, Read_BlockedDemuxerAndDecoder) {
490 // Test applies only when the decoder allows multiple parallel requests. 489 // Test applies only when the decoder allows multiple parallel requests.
491 if (GetParam().parallel_decoding == 1) 490 if (GetParam().parallel_decoding == 1)
492 return; 491 return;
493 492
494 Initialize(); 493 Initialize();
495 demuxer_stream_->HoldNextRead(); 494 demuxer_stream_->HoldNextRead();
496 decoder1_->HoldDecode(); 495 decoder_->HoldDecode();
497 ReadOneFrame(); 496 ReadOneFrame();
498 EXPECT_TRUE(pending_read_); 497 EXPECT_TRUE(pending_read_);
499 498
500 int demuxed_buffers = 0; 499 int demuxed_buffers = 0;
501 500
502 // Pass frames from the demuxer to the VideoFrameStream until the first read 501 // Pass frames from the demuxer to the VideoFrameStream until the first read
503 // request is satisfied, while always keeping one decode request pending. 502 // request is satisfied, while always keeping one decode request pending.
504 while (pending_read_) { 503 while (pending_read_) {
505 ++demuxed_buffers; 504 ++demuxed_buffers;
506 demuxer_stream_->SatisfyReadAndHoldNext(); 505 demuxer_stream_->SatisfyReadAndHoldNext();
507 base::RunLoop().RunUntilIdle(); 506 base::RunLoop().RunUntilIdle();
508 507
509 // Always keep one decode request pending. 508 // Always keep one decode request pending.
510 if (demuxed_buffers > 1) { 509 if (demuxed_buffers > 1) {
511 decoder1_->SatisfySingleDecode(); 510 decoder_->SatisfySingleDecode();
512 base::RunLoop().RunUntilIdle(); 511 base::RunLoop().RunUntilIdle();
513 } 512 }
514 } 513 }
515 514
516 ReadUntilPending(); 515 ReadUntilPending();
517 EXPECT_TRUE(pending_read_); 516 EXPECT_TRUE(pending_read_);
518 517
519 // Unblocking one decode request should unblock read even when demuxer is 518 // Unblocking one decode request should unblock read even when demuxer is
520 // still blocked. 519 // still blocked.
521 decoder1_->SatisfySingleDecode(); 520 decoder_->SatisfySingleDecode();
522 base::RunLoop().RunUntilIdle(); 521 base::RunLoop().RunUntilIdle();
523 EXPECT_FALSE(pending_read_); 522 EXPECT_FALSE(pending_read_);
524 523
525 // Stream should still be blocked on the demuxer after unblocking the decoder. 524 // Stream should still be blocked on the demuxer after unblocking the decoder.
526 decoder1_->SatisfyDecode(); 525 decoder_->SatisfyDecode();
527 ReadUntilPending(); 526 ReadUntilPending();
528 EXPECT_TRUE(pending_read_); 527 EXPECT_TRUE(pending_read_);
529 528
530 // Verify that the stream has returned all frames that have been demuxed, 529 // Verify that the stream has returned all frames that have been demuxed,
531 // accounting for the decoder delay. 530 // accounting for the decoder delay.
532 EXPECT_EQ(demuxed_buffers - GetParam().decoding_delay, num_decoded_frames_); 531 EXPECT_EQ(demuxed_buffers - GetParam().decoding_delay, num_decoded_frames_);
533 532
534 // Unblocking the demuxer will unblock the stream. 533 // Unblocking the demuxer will unblock the stream.
535 demuxer_stream_->SatisfyRead(); 534 demuxer_stream_->SatisfyRead();
536 base::RunLoop().RunUntilIdle(); 535 base::RunLoop().RunUntilIdle();
537 EXPECT_FALSE(pending_read_); 536 EXPECT_FALSE(pending_read_);
538 } 537 }
539 538
540 TEST_P(VideoFrameStreamTest, Read_DuringEndOfStreamDecode) { 539 TEST_P(VideoFrameStreamTest, Read_DuringEndOfStreamDecode) {
541 // Test applies only when the decoder allows multiple parallel requests, and 540 // Test applies only when the decoder allows multiple parallel requests, and
542 // they are not satisfied in a single batch. 541 // they are not satisfied in a single batch.
543 if (GetParam().parallel_decoding == 1 || GetParam().decoding_delay != 0) 542 if (GetParam().parallel_decoding == 1 || GetParam().decoding_delay != 0)
544 return; 543 return;
545 544
546 Initialize(); 545 Initialize();
547 decoder1_->HoldDecode(); 546 decoder_->HoldDecode();
548 547
549 // Read all of the frames up to end of stream. Since parallel decoding is 548 // Read all of the frames up to end of stream. Since parallel decoding is
550 // enabled, the end of stream buffer will be sent to the decoder immediately, 549 // enabled, the end of stream buffer will be sent to the decoder immediately,
551 // but we don't satisfy it yet. 550 // but we don't satisfy it yet.
552 for (int configuration = 0; configuration < kNumConfigs; configuration++) { 551 for (int configuration = 0; configuration < kNumConfigs; configuration++) {
553 for (int frame = 0; frame < kNumBuffersInOneConfig; frame++) { 552 for (int frame = 0; frame < kNumBuffersInOneConfig; frame++) {
554 ReadOneFrame(); 553 ReadOneFrame();
555 while (pending_read_) { 554 while (pending_read_) {
556 decoder1_->SatisfySingleDecode(); 555 decoder_->SatisfySingleDecode();
557 base::RunLoop().RunUntilIdle(); 556 base::RunLoop().RunUntilIdle();
558 } 557 }
559 } 558 }
560 } 559 }
561 560
562 // Read() again. The callback must be delayed until the decode completes. 561 // Read() again. The callback must be delayed until the decode completes.
563 ReadOneFrame(); 562 ReadOneFrame();
564 ASSERT_TRUE(pending_read_); 563 ASSERT_TRUE(pending_read_);
565 564
566 // Satisfy decoding of the end of stream buffer. The read should complete. 565 // Satisfy decoding of the end of stream buffer. The read should complete.
567 decoder1_->SatisfySingleDecode(); 566 decoder_->SatisfySingleDecode();
568 base::RunLoop().RunUntilIdle(); 567 base::RunLoop().RunUntilIdle();
569 ASSERT_FALSE(pending_read_); 568 ASSERT_FALSE(pending_read_);
570 EXPECT_EQ(last_read_status_, VideoFrameStream::OK); 569 EXPECT_EQ(last_read_status_, VideoFrameStream::OK);
571 570
572 // The read output should indicate end of stream. 571 // The read output should indicate end of stream.
573 ASSERT_TRUE(frame_read_.get()); 572 ASSERT_TRUE(frame_read_.get());
574 EXPECT_TRUE( 573 EXPECT_TRUE(
575 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); 574 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM));
576 } 575 }
577 576
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 Reset(); 657 Reset();
659 } 658 }
660 659
661 // In the following Destroy_* tests, |video_frame_stream_| is destroyed in 660 // In the following Destroy_* tests, |video_frame_stream_| is destroyed in
662 // VideoFrameStreamTest dtor. 661 // VideoFrameStreamTest dtor.
663 662
664 TEST_P(VideoFrameStreamTest, Destroy_BeforeInitialization) { 663 TEST_P(VideoFrameStreamTest, Destroy_BeforeInitialization) {
665 } 664 }
666 665
667 TEST_P(VideoFrameStreamTest, Destroy_DuringInitialization) { 666 TEST_P(VideoFrameStreamTest, Destroy_DuringInitialization) {
668 EnterPendingState(DECODER_INIT); 667 decoders_[0]->HoldNextInit();
668 Initialize();
669 } 669 }
670 670
671 TEST_P(VideoFrameStreamTest, Destroy_AfterInitialization) { 671 TEST_P(VideoFrameStreamTest, Destroy_AfterInitialization) {
672 Initialize(); 672 Initialize();
673 } 673 }
674 674
675 TEST_P(VideoFrameStreamTest, Destroy_DuringReinitialization) { 675 TEST_P(VideoFrameStreamTest, Destroy_DuringReinitialization) {
676 Initialize(); 676 Initialize();
677 EnterPendingState(DECODER_REINIT); 677 EnterPendingState(DECODER_REINIT);
678 } 678 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 EnterPendingState(DECODER_RESET); 741 EnterPendingState(DECODER_RESET);
742 SatisfyPendingCallback(DECODER_DECODE); 742 SatisfyPendingCallback(DECODER_DECODE);
743 } 743 }
744 744
745 TEST_P(VideoFrameStreamTest, Destroy_AfterRead_AfterReset) { 745 TEST_P(VideoFrameStreamTest, Destroy_AfterRead_AfterReset) {
746 Initialize(); 746 Initialize();
747 Read(); 747 Read();
748 Reset(); 748 Reset();
749 } 749 }
750 750
751 // The following tests cover the fallback logic.
752
751 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitialDecodeError) { 753 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitialDecodeError) {
752 Initialize(); 754 Initialize();
753 decoder1_->SimulateError(); 755 decoder_->SimulateError();
754 ReadOneFrame(); 756 ReadOneFrame();
755 757
756 // |video_frame_stream_| should have fallen back to |decoder2_|. 758 // |video_frame_stream_| should have fallen back to a new decoder.
759 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName());
757 ASSERT_FALSE(pending_read_); 760 ASSERT_FALSE(pending_read_);
758 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); 761 ASSERT_EQ(VideoFrameStream::OK, last_read_status_);
759 762
760 // Can't check |decoder1_| right now, it might have been destroyed already. 763 // Check that we fallbacked to Decoder2.
761 ASSERT_GT(decoder2_->total_bytes_decoded(), 0); 764 ASSERT_GT(decoder_->total_bytes_decoded(), 0);
762 765
763 // Verify no frame was dropped. 766 // Verify no frame was dropped.
764 ReadAllFrames(); 767 ReadAllFrames();
765 } 768 }
766 769
767 TEST_P(VideoFrameStreamTest, FallbackDecoder_EndOfStreamReachedBeforeFallback) { 770 TEST_P(VideoFrameStreamTest, FallbackDecoder_EndOfStreamReachedBeforeFallback) {
768 // Only consider cases where there is a decoder delay. For test simplicity, 771 // Only consider cases where there is a decoder delay. For test simplicity,
769 // omit the parallel case. 772 // omit the parallel case.
770 if (GetParam().decoding_delay == 0 || GetParam().parallel_decoding > 1) 773 if (GetParam().decoding_delay == 0 || GetParam().parallel_decoding > 1)
771 return; 774 return;
772 775
773 Initialize(); 776 Initialize();
774 decoder1_->HoldDecode(); 777 decoder_->HoldDecode();
775 ReadOneFrame(); 778 ReadOneFrame();
776 779
777 // One buffer should have already pulled from the demuxer stream. Set the next 780 // One buffer should have already pulled from the demuxer stream. Set the next
778 // one to be an EOS. 781 // one to be an EOS.
779 demuxer_stream_->SeekToEndOfStream(); 782 demuxer_stream_->SeekToEndOfStream();
780 783
781 decoder1_->SatisfySingleDecode(); 784 decoder_->SatisfySingleDecode();
782 base::RunLoop().RunUntilIdle(); 785 base::RunLoop().RunUntilIdle();
783 786
784 // |video_frame_stream_| should not have emited a frame. 787 // |video_frame_stream_| should not have emited a frame.
785 EXPECT_TRUE(pending_read_); 788 EXPECT_TRUE(pending_read_);
786 789
787 // Pending buffers should contain a regular buffer and an EOS buffer. 790 // Pending buffers should contain a regular buffer and an EOS buffer.
788 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 2); 791 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 2);
789 792
790 decoder1_->SimulateError(); 793 decoder_->SimulateError();
791 base::RunLoop().RunUntilIdle(); 794 base::RunLoop().RunUntilIdle();
792 795
793 // A frame should have been emited 796 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName());
797
798 // A frame should have been emitted.
794 EXPECT_FALSE(pending_read_); 799 EXPECT_FALSE(pending_read_);
795 EXPECT_EQ(last_read_status_, VideoFrameStream::OK); 800 EXPECT_EQ(last_read_status_, VideoFrameStream::OK);
796 EXPECT_FALSE( 801 EXPECT_FALSE(
797 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); 802 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM));
798 EXPECT_GT(decoder2_->total_bytes_decoded(), 0); 803 EXPECT_GT(decoder_->total_bytes_decoded(), 0);
799 804
800 ReadOneFrame(); 805 ReadOneFrame();
801 806
802 EXPECT_FALSE(pending_read_); 807 EXPECT_FALSE(pending_read_);
803 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); 808 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing());
804 EXPECT_TRUE( 809 EXPECT_TRUE(
805 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM)); 810 frame_read_->metadata()->IsTrue(VideoFrameMetadata::END_OF_STREAM));
806 } 811 }
807 812
808 TEST_P(VideoFrameStreamTest, FallbackDecoder_DoesReinitializeStompPendingRead) { 813 TEST_P(VideoFrameStreamTest, FallbackDecoder_DoesReinitializeStompPendingRead) {
809 // Test only the case where there is no decoding delay and parallel decoding. 814 // Test only the case where there is no decoding delay and parallel decoding.
810 if (GetParam().decoding_delay != 0 || GetParam().parallel_decoding <= 1) 815 if (GetParam().decoding_delay != 0 || GetParam().parallel_decoding <= 1)
811 return; 816 return;
812 817
813 Initialize(); 818 Initialize();
814 decoder1_->HoldDecode(); 819 decoder_->HoldDecode();
815 820
816 // Queue one read, defer the second. 821 // Queue one read, defer the second.
817 frame_read_ = nullptr; 822 frame_read_ = nullptr;
818 pending_read_ = true; 823 pending_read_ = true;
819 video_frame_stream_->Read( 824 video_frame_stream_->Read(
820 base::Bind(&VideoFrameStreamTest::FrameReady, base::Unretained(this))); 825 base::Bind(&VideoFrameStreamTest::FrameReady, base::Unretained(this)));
821 demuxer_stream_->HoldNextRead(); 826 demuxer_stream_->HoldNextRead();
822 827
823 // Force an error to occur on the first decode, but ensure it isn't propagated 828 // Force an error to occur on the first decode, but ensure it isn't propagated
824 // until after the next read has been started. 829 // until after the next read has been started.
825 decoder1_->SimulateError(); 830 decoder_->SimulateError();
826 decoder2_->HoldDecode(); 831 decoders_[1]->HoldDecode();
827 832
828 // Complete the fallback to the second decoder with the read still pending. 833 // Complete the fallback to the second decoder with the read still pending.
829 base::RunLoop().RunUntilIdle(); 834 base::RunLoop().RunUntilIdle();
830 835
831 // Can't check |decoder1_| right now, it might have been destroyed already. 836 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName());
832 // Verify that there was nothing decoded until we kicked the decoder. 837
833 EXPECT_EQ(decoder2_->total_bytes_decoded(), 0); 838 // Can't check the original decoder right now, it might have been destroyed
834 decoder2_->SatisfyDecode(); 839 // already. Verify that there was nothing decoded until we kicked the decoder.
835 const int first_decoded_bytes = decoder2_->total_bytes_decoded(); 840 EXPECT_EQ(decoder_->total_bytes_decoded(), 0);
841 decoder_->SatisfyDecode();
842 const int first_decoded_bytes = decoder_->total_bytes_decoded();
836 ASSERT_GT(first_decoded_bytes, 0); 843 ASSERT_GT(first_decoded_bytes, 0);
837 844
838 // Satisfy the previously pending read and ensure it is decoded. 845 // Satisfy the previously pending read and ensure it is decoded.
839 demuxer_stream_->SatisfyRead(); 846 demuxer_stream_->SatisfyRead();
840 base::RunLoop().RunUntilIdle(); 847 base::RunLoop().RunUntilIdle();
841 ASSERT_GT(decoder2_->total_bytes_decoded(), first_decoded_bytes); 848 ASSERT_GT(decoder_->total_bytes_decoded(), first_decoded_bytes);
842 } 849 }
843 850
844 TEST_P(VideoFrameStreamTest, 851 TEST_P(VideoFrameStreamTest,
845 FallbackDecoder_SelectedOnInitialDecodeError_Twice) { 852 FallbackDecoder_SelectedOnInitialDecodeError_Twice) {
846 Initialize(); 853 Initialize();
847 decoder1_->SimulateError(); 854 decoder_->SimulateError();
848 decoder2_->HoldNextInit(); 855
856 decoders_[1]->HoldNextInit();
849 ReadOneFrame(); 857 ReadOneFrame();
850 858
851 decoder2_->SatisfyInit(); 859 decoders_[1]->SatisfyInit();
852 decoder2_->SimulateError(); 860 decoders_[1]->SimulateError();
853 base::RunLoop().RunUntilIdle(); 861 base::RunLoop().RunUntilIdle();
854 862
855 // |video_frame_stream_| should have fallen back to |decoder3_|. 863 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName());
864
865 // |video_frame_stream_| should have fallen back to |decoders_[2]|.
856 ASSERT_FALSE(pending_read_); 866 ASSERT_FALSE(pending_read_);
857 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); 867 ASSERT_EQ(VideoFrameStream::OK, last_read_status_);
858 868
859 // Can't check |decoder1_| or |decoder2_| right now, they might have been 869 // Can't check previously selected decoder(s) right now, they might have been
860 // destroyed already. 870 // destroyed already.
861 ASSERT_GT(decoder3_->total_bytes_decoded(), 0); 871 ASSERT_GT(decoder_->total_bytes_decoded(), 0);
862 872
863 // Verify no frame was dropped. 873 // Verify no frame was dropped.
864 ReadAllFrames(); 874 ReadAllFrames();
865 } 875 }
866 876
867 TEST_P(VideoFrameStreamTest, FallbackDecoder_ConfigChangeClearsPendingBuffers) { 877 TEST_P(VideoFrameStreamTest, FallbackDecoder_ConfigChangeClearsPendingBuffers) {
868 // Test case is only interesting if the decoder can receive a config change 878 // Test case is only interesting if the decoder can receive a config change
869 // before returning its first frame. 879 // before returning its first frame.
870 if (GetParam().decoding_delay < kNumBuffersInOneConfig) 880 if (GetParam().decoding_delay < kNumBuffersInOneConfig)
871 return; 881 return;
(...skipping 12 matching lines...) Expand all
884 TEST_P(VideoFrameStreamTest, FallbackDecoder_ErrorDuringConfigChangeFlushing) { 894 TEST_P(VideoFrameStreamTest, FallbackDecoder_ErrorDuringConfigChangeFlushing) {
885 // Test case is only interesting if the decoder can receive a config change 895 // Test case is only interesting if the decoder can receive a config change
886 // before returning its first frame. 896 // before returning its first frame.
887 if (GetParam().decoding_delay < kNumBuffersInOneConfig) 897 if (GetParam().decoding_delay < kNumBuffersInOneConfig)
888 return; 898 return;
889 899
890 Initialize(); 900 Initialize();
891 EnterPendingState(DEMUXER_READ_CONFIG_CHANGE); 901 EnterPendingState(DEMUXER_READ_CONFIG_CHANGE);
892 EXPECT_GT(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); 902 EXPECT_GT(video_frame_stream_->get_pending_buffers_size_for_testing(), 0);
893 903
894 decoder1_->HoldDecode(); 904 decoder_->HoldDecode();
895 SatisfyPendingCallback(DEMUXER_READ_CONFIG_CHANGE); 905 SatisfyPendingCallback(DEMUXER_READ_CONFIG_CHANGE);
896 906
897 // The flush request should have been sent and held. 907 // The flush request should have been sent and held.
898 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); 908 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0);
899 EXPECT_TRUE(pending_read_); 909 EXPECT_TRUE(pending_read_);
900 910
901 // Triggering an error here will cause the frames in |decoder1_| to be lost. 911 // Triggering an error here will cause the frames in selected decoder to be
902 // There are no pending buffers buffers to give to give to |decoder2_| due to 912 // lost. There are no pending buffers to give to |decoders_[1]| due to
903 // crbug.com/603713. 913 // http://crbug.com/603713
904 decoder1_->SimulateError(); 914 decoder_->SimulateError();
905 base::RunLoop().RunUntilIdle(); 915 base::RunLoop().RunUntilIdle();
906 916
907 // We want to make sure that |decoder2_| can decode the rest of the frames 917 // We want to make sure the fallback decoder can decode the rest of the frames
908 // in the demuxer stream. 918 // in the demuxer stream.
909 ReadAllFrames(kNumBuffersInOneConfig * (kNumConfigs - 1)); 919 ReadAllFrames(kNumBuffersInOneConfig * (kNumConfigs - 1));
910 } 920 }
911 921
912 TEST_P(VideoFrameStreamTest, FallbackDecoder_PendingBuffersIsFilledAndCleared) { 922 TEST_P(VideoFrameStreamTest, FallbackDecoder_PendingBuffersIsFilledAndCleared) {
913 // Test applies only when there is a decoder delay, and the decoder will not 923 // Test applies only when there is a decoder delay, and the decoder will not
914 // receive a config change before outputing its first frame. Parallel decoding 924 // receive a config change before outputing its first frame. Parallel decoding
915 // is also disabled in this test case, for readability and simplicity of the 925 // is also disabled in this test case, for readability and simplicity of the
916 // unit test. 926 // unit test.
917 if (GetParam().decoding_delay == 0 || 927 if (GetParam().decoding_delay == 0 ||
918 GetParam().decoding_delay > kNumBuffersInOneConfig || 928 GetParam().decoding_delay > kNumBuffersInOneConfig ||
919 GetParam().parallel_decoding > 1) { 929 GetParam().parallel_decoding > 1) {
920 return; 930 return;
921 } 931 }
922 Initialize(); 932 Initialize();
923 933
924 // Block on demuxer read and decoder decode so we can step through. 934 // Block on demuxer read and decoder decode so we can step through.
925 demuxer_stream_->HoldNextRead(); 935 demuxer_stream_->HoldNextRead();
926 decoder1_->HoldDecode(); 936 decoder_->HoldDecode();
927 ReadOneFrame(); 937 ReadOneFrame();
928 938
929 int demuxer_reads_satisfied = 0; 939 int demuxer_reads_satisfied = 0;
930 // Send back and requests buffers until the next one would fill the decoder 940 // Send back and requests buffers until the next one would fill the decoder
931 // delay. 941 // delay.
932 while (demuxer_reads_satisfied < GetParam().decoding_delay - 1) { 942 while (demuxer_reads_satisfied < GetParam().decoding_delay - 1) {
933 // Send a buffer back. 943 // Send a buffer back.
934 demuxer_stream_->SatisfyReadAndHoldNext(); 944 demuxer_stream_->SatisfyReadAndHoldNext();
935 base::RunLoop().RunUntilIdle(); 945 base::RunLoop().RunUntilIdle();
936 ++demuxer_reads_satisfied; 946 ++demuxer_reads_satisfied;
937 947
938 // Decode one buffer. 948 // Decode one buffer.
939 decoder1_->SatisfySingleDecode(); 949 decoder_->SatisfySingleDecode();
940 base::RunLoop().RunUntilIdle(); 950 base::RunLoop().RunUntilIdle();
941 EXPECT_TRUE(pending_read_); 951 EXPECT_TRUE(pending_read_);
942 EXPECT_EQ(demuxer_reads_satisfied, 952 EXPECT_EQ(demuxer_reads_satisfied,
943 video_frame_stream_->get_pending_buffers_size_for_testing()); 953 video_frame_stream_->get_pending_buffers_size_for_testing());
944 // No fallback buffers should be queued up yet. 954 // No fallback buffers should be queued up yet.
945 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); 955 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing());
946 } 956 }
947 957
948 // Hold the init before triggering the error, to verify internal state. 958 // Hold the init before triggering the error, to verify internal state.
949 demuxer_stream_->SatisfyReadAndHoldNext(); 959 demuxer_stream_->SatisfyReadAndHoldNext();
950 ++demuxer_reads_satisfied; 960 ++demuxer_reads_satisfied;
951 decoder2_->HoldNextInit(); 961
952 decoder1_->SimulateError(); 962 decoder_->SimulateError();
963 decoders_[1]->HoldNextInit();
953 base::RunLoop().RunUntilIdle(); 964 base::RunLoop().RunUntilIdle();
954 965
955 EXPECT_TRUE(pending_read_); 966 EXPECT_TRUE(pending_read_);
956 EXPECT_EQ(demuxer_reads_satisfied, 967 EXPECT_EQ(demuxer_reads_satisfied,
957 video_frame_stream_->get_pending_buffers_size_for_testing()); 968 video_frame_stream_->get_pending_buffers_size_for_testing());
958 969
959 decoder2_->SatisfyInit(); 970 decoders_[1]->SatisfyInit();
960 decoder2_->HoldDecode(); 971 decoders_[1]->HoldDecode();
961 base::RunLoop().RunUntilIdle(); 972 base::RunLoop().RunUntilIdle();
962 973
974 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName());
975
963 // Make sure the pending buffers have been transfered to fallback buffers. 976 // Make sure the pending buffers have been transfered to fallback buffers.
964 // One call to Decode() during the initialization process, so we expect one 977 // One call to Decode() during the initialization process, so we expect one
965 // buffer to already have been consumed from the fallback buffers. 978 // buffer to already have been consumed from the fallback buffers.
966 // Pending buffers should never go down (unless we encounter a config change) 979 // Pending buffers should never go down (unless we encounter a config change)
967 EXPECT_EQ(demuxer_reads_satisfied - 1, 980 EXPECT_EQ(demuxer_reads_satisfied - 1,
968 video_frame_stream_->get_fallback_buffers_size_for_testing()); 981 video_frame_stream_->get_fallback_buffers_size_for_testing());
969 EXPECT_EQ(demuxer_reads_satisfied, 982 EXPECT_EQ(demuxer_reads_satisfied,
970 video_frame_stream_->get_pending_buffers_size_for_testing()); 983 video_frame_stream_->get_pending_buffers_size_for_testing());
971 984
972 decoder2_->SatisfyDecode(); 985 decoder_->SatisfyDecode();
973 base::RunLoop().RunUntilIdle(); 986 base::RunLoop().RunUntilIdle();
974 987
975 // Make sure all buffers consumed by |decoder2_| have come from the fallback. 988 // Make sure all buffers consumed by |decoders_[1]| have come from the
976 // Pending buffers should not have been cleared yet. 989 // fallback. Pending buffers should not have been cleared yet.
977 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing()); 990 EXPECT_EQ(0, video_frame_stream_->get_fallback_buffers_size_for_testing());
978 EXPECT_EQ(demuxer_reads_satisfied, 991 EXPECT_EQ(demuxer_reads_satisfied,
979 video_frame_stream_->get_pending_buffers_size_for_testing()); 992 video_frame_stream_->get_pending_buffers_size_for_testing());
980 EXPECT_TRUE(pending_read_); 993 EXPECT_TRUE(pending_read_);
981 994
982 // Give the decoder one more buffer, enough to release a frame. 995 // Give the decoder one more buffer, enough to release a frame.
983 demuxer_stream_->SatisfyReadAndHoldNext(); 996 demuxer_stream_->SatisfyReadAndHoldNext();
984 base::RunLoop().RunUntilIdle(); 997 base::RunLoop().RunUntilIdle();
985 998
986 // New buffers should not have been added after the frame was released. 999 // New buffers should not have been added after the frame was released.
987 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0); 1000 EXPECT_EQ(video_frame_stream_->get_pending_buffers_size_for_testing(), 0);
988 EXPECT_FALSE(pending_read_); 1001 EXPECT_FALSE(pending_read_);
989 1002
990 demuxer_stream_->SatisfyRead(); 1003 demuxer_stream_->SatisfyRead();
991 1004
992 // Confirm no frames were dropped. 1005 // Confirm no frames were dropped.
993 ReadAllFrames(); 1006 ReadAllFrames();
994 } 1007 }
995 1008
996 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnDecodeThenInitErrors) { 1009 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnDecodeThenInitErrors) {
997 Initialize(); 1010 Initialize();
998 decoder1_->SimulateError(); 1011 decoder_->SimulateError();
999 decoder2_->SimulateFailureToInit(); 1012 SimulateDecoderInitFailure({1});
1000 ReadOneFrame(); 1013 ReadOneFrame();
1001 1014
1002 // |video_frame_stream_| should have fallen back to |decoder3_| 1015 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName());
1016
1017 // |video_frame_stream_| should have fallen back to |decoders_[2]|
1003 ASSERT_FALSE(pending_read_); 1018 ASSERT_FALSE(pending_read_);
1004 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); 1019 ASSERT_EQ(VideoFrameStream::OK, last_read_status_);
1005 1020
1006 // Can't check |decoder1_| or |decoder2_| right now, they might have been 1021 // Can't check previously selected decoder(s) right now, they might have been
1007 // destroyed already. 1022 // destroyed already.
1008 ASSERT_GT(decoder3_->total_bytes_decoded(), 0); 1023 ASSERT_GT(decoder_->total_bytes_decoded(), 0);
1009 1024
1010 // Verify no frame was dropped. 1025 // Verify no frame was dropped.
1011 ReadAllFrames(); 1026 ReadAllFrames();
1012 } 1027 }
1013 1028
1014 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitThenDecodeErrors) { 1029 TEST_P(VideoFrameStreamTest, FallbackDecoder_SelectedOnInitThenDecodeErrors) {
1015 decoder1_->SimulateFailureToInit(); 1030 SimulateDecoderInitFailure({0});
1016 decoder2_->HoldDecode();
1017 Initialize(); 1031 Initialize();
1032 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName());
1033
1034 decoder_->HoldDecode();
1018 ReadOneFrame(); 1035 ReadOneFrame();
1019 decoder2_->SimulateError(); 1036 decoder_->SimulateError();
1020 base::RunLoop().RunUntilIdle(); 1037 base::RunLoop().RunUntilIdle();
1021 1038
1022 // |video_frame_stream_| should have fallen back to |decoder3_| 1039 // |video_frame_stream_| should have fallen back to |decoders_[2]|
1040 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName());
1041
1023 ASSERT_FALSE(pending_read_); 1042 ASSERT_FALSE(pending_read_);
1024 ASSERT_EQ(VideoFrameStream::OK, last_read_status_); 1043 ASSERT_EQ(VideoFrameStream::OK, last_read_status_);
1025 1044
1026 // Can't check |decoder1_| or |decoder2_| right now, they might have been 1045 // Can't check previously selected decoder(s) right now, they might have been
1027 // destroyed already. 1046 // destroyed already.
1028 ASSERT_GT(decoder3_->total_bytes_decoded(), 0); 1047 ASSERT_GT(decoder_->total_bytes_decoded(), 0);
1029 1048
1030 // Verify no frame was dropped. 1049 // Verify no frame was dropped.
1031 ReadAllFrames(); 1050 ReadAllFrames();
1032 } 1051 }
1033 1052
1034 TEST_P(VideoFrameStreamTest, 1053 TEST_P(VideoFrameStreamTest,
1035 FallbackDecoder_NotSelectedOnMidstreamDecodeError) { 1054 FallbackDecoder_NotSelectedOnMidstreamDecodeError) {
1036 Initialize(); 1055 Initialize();
1037 ReadOneFrame(); 1056 ReadOneFrame();
1038 1057
1039 // Successfully received a frame. 1058 // Successfully received a frame.
1040 EXPECT_FALSE(pending_read_); 1059 EXPECT_FALSE(pending_read_);
1041 ASSERT_GT(decoder1_->total_bytes_decoded(), 0); 1060 ASSERT_GT(decoder_->total_bytes_decoded(), 0);
1042 1061
1043 decoder1_->SimulateError(); 1062 decoder_->SimulateError();
1044 1063
1045 // The error must surface from Read() as DECODE_ERROR. 1064 // The error must surface from Read() as DECODE_ERROR.
1046 while (last_read_status_ == VideoFrameStream::OK) { 1065 while (last_read_status_ == VideoFrameStream::OK) {
1047 ReadOneFrame(); 1066 ReadOneFrame();
1048 base::RunLoop().RunUntilIdle(); 1067 base::RunLoop().RunUntilIdle();
1049 EXPECT_FALSE(pending_read_); 1068 EXPECT_FALSE(pending_read_);
1050 } 1069 }
1051 1070
1052 // Verify the error was surfaced, rather than falling back to |decoder2_|. 1071 // Verify the error was surfaced, rather than falling back to other decoders.
1072 ASSERT_EQ(GetDecoderName(0), decoder_->GetDisplayName());
1053 EXPECT_FALSE(pending_read_); 1073 EXPECT_FALSE(pending_read_);
1054 ASSERT_EQ(decoder2_->total_bytes_decoded(), 0);
1055 ASSERT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); 1074 ASSERT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_);
1056 } 1075 }
1057 1076
1058 TEST_P(VideoFrameStreamTest, DecoderErrorWhenNotReading) { 1077 TEST_P(VideoFrameStreamTest, DecoderErrorWhenNotReading) {
1059 Initialize(); 1078 Initialize();
1060 decoder1_->HoldDecode(); 1079 decoder_->HoldDecode();
1061 ReadOneFrame(); 1080 ReadOneFrame();
1062 EXPECT_TRUE(pending_read_); 1081 EXPECT_TRUE(pending_read_);
1063 1082
1064 // Satisfy decode requests until we get the first frame out. 1083 // Satisfy decode requests until we get the first frame out.
1065 while (pending_read_) { 1084 while (pending_read_) {
1066 decoder1_->SatisfySingleDecode(); 1085 decoder_->SatisfySingleDecode();
1067 base::RunLoop().RunUntilIdle(); 1086 base::RunLoop().RunUntilIdle();
1068 } 1087 }
1069 1088
1070 // Trigger an error in the decoding. 1089 // Trigger an error in the decoding.
1071 decoder1_->SimulateError(); 1090 decoder_->SimulateError();
1072 1091
1073 // The error must surface from Read() as DECODE_ERROR. 1092 // The error must surface from Read() as DECODE_ERROR.
1074 while (last_read_status_ == VideoFrameStream::OK) { 1093 while (last_read_status_ == VideoFrameStream::OK) {
1075 ReadOneFrame(); 1094 ReadOneFrame();
1076 base::RunLoop().RunUntilIdle(); 1095 base::RunLoop().RunUntilIdle();
1077 EXPECT_FALSE(pending_read_); 1096 EXPECT_FALSE(pending_read_);
1078 } 1097 }
1079 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); 1098 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_);
1080 } 1099 }
1081 1100
1082 TEST_P(VideoFrameStreamTest, FallbackDecoderSelectedOnFailureToReinitialize) { 1101 TEST_P(VideoFrameStreamTest, FallbackDecoderSelectedOnFailureToReinitialize) {
1083 Initialize(); 1102 Initialize();
1084 decoder1_->SimulateFailureToInit(); 1103 decoder_->SimulateFailureToInit();
1085 ReadUntilDecoderReinitialized(decoder1_); 1104 ReadUntilDecoderReinitialized();
1105 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName());
1086 ReadAllFrames(); 1106 ReadAllFrames();
1087 ASSERT_GT(decoder2_->total_bytes_decoded(), 0); 1107 ASSERT_GT(decoder_->total_bytes_decoded(), 0);
1088 } 1108 }
1089 1109
1090 TEST_P(VideoFrameStreamTest, 1110 TEST_P(VideoFrameStreamTest,
1091 FallbackDecoderSelectedOnFailureToReinitialize_Twice) { 1111 FallbackDecoderSelectedOnFailureToReinitialize_Twice) {
1092 Initialize(); 1112 Initialize();
1093 decoder1_->SimulateFailureToInit(); 1113 decoder_->SimulateFailureToInit();
1094 ReadUntilDecoderReinitialized(decoder1_); 1114 ReadUntilDecoderReinitialized();
1115 ASSERT_EQ(GetDecoderName(1), decoder_->GetDisplayName());
1095 ReadOneFrame(); 1116 ReadOneFrame();
1096 decoder2_->SimulateFailureToInit(); 1117 decoder_->SimulateFailureToInit();
1097 ReadUntilDecoderReinitialized(decoder2_); 1118 ReadUntilDecoderReinitialized();
1119 ASSERT_EQ(GetDecoderName(2), decoder_->GetDisplayName());
1098 ReadAllFrames(); 1120 ReadAllFrames();
1099 } 1121 }
1100 1122
1101 TEST_P(VideoFrameStreamTest, DecodeErrorAfterFallbackDecoderSelectionFails) { 1123 TEST_P(VideoFrameStreamTest, DecodeErrorAfterFallbackDecoderSelectionFails) {
1102 Initialize(); 1124 Initialize();
1103 decoder1_->SimulateFailureToInit(); 1125 decoder_->SimulateFailureToInit();
1104 decoder2_->SimulateFailureToInit(); 1126 SimulateDecoderInitFailure({1, 2});
1105 decoder3_->SimulateFailureToInit(); 1127 ReadUntilDecoderReinitialized();
1106 ReadUntilDecoderReinitialized(decoder1_);
1107 // The error will surface from Read() as DECODE_ERROR. 1128 // The error will surface from Read() as DECODE_ERROR.
1108 while (last_read_status_ == VideoFrameStream::OK) { 1129 while (last_read_status_ == VideoFrameStream::OK) {
1109 ReadOneFrame(); 1130 ReadOneFrame();
1110 base::RunLoop().RunUntilIdle(); 1131 base::RunLoop().RunUntilIdle();
1111 EXPECT_FALSE(pending_read_); 1132 EXPECT_FALSE(pending_read_);
1112 } 1133 }
1113 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_); 1134 EXPECT_EQ(VideoFrameStream::DECODE_ERROR, last_read_status_);
1114 } 1135 }
1115 1136
1116 TEST_P(VideoFrameStreamTest, Destroy_DuringFallbackDecoderSelection) { 1137 TEST_P(VideoFrameStreamTest, Destroy_DuringFallbackDecoderSelection) {
1117 Initialize(); 1138 Initialize();
1118 decoder1_->SimulateFailureToInit(); 1139 decoder_->SimulateFailureToInit();
1119 EnterPendingState(DECODER_REINIT); 1140 EnterPendingState(DECODER_REINIT);
1120 decoder2_->HoldNextInit(); 1141 decoders_[1]->HoldNextInit();
1121 SatisfyPendingCallback(DECODER_REINIT); 1142 SatisfyPendingCallback(DECODER_REINIT);
1122 } 1143 }
1123 1144
1124 } // namespace media 1145 } // namespace media
OLDNEW
« media/filters/fake_video_decoder.h ('K') | « media/filters/fake_video_decoder_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698