OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.h" | 8 #include "base/callback.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/debug/stack_trace.h" | 10 #include "base/debug/stack_trace.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 using ::testing::AnyNumber; | 29 using ::testing::AnyNumber; |
30 using ::testing::Invoke; | 30 using ::testing::Invoke; |
31 using ::testing::Mock; | 31 using ::testing::Mock; |
32 using ::testing::NiceMock; | 32 using ::testing::NiceMock; |
33 using ::testing::Return; | 33 using ::testing::Return; |
34 using ::testing::SaveArg; | 34 using ::testing::SaveArg; |
35 using ::testing::StrictMock; | 35 using ::testing::StrictMock; |
36 | 36 |
37 namespace media { | 37 namespace media { |
38 | 38 |
| 39 // Threshold for Render() callbacks used for testing; should not be zero. |
| 40 static const int kTestBackgroundRenderTimeoutMs = 25; |
| 41 |
39 ACTION_P(RunClosure, closure) { | 42 ACTION_P(RunClosure, closure) { |
40 closure.Run(); | 43 closure.Run(); |
41 } | 44 } |
42 | 45 |
43 MATCHER_P(HasTimestamp, ms, "") { | 46 MATCHER_P(HasTimestamp, ms, "") { |
44 *result_listener << "has timestamp " << arg->timestamp().InMilliseconds(); | 47 *result_listener << "has timestamp " << arg->timestamp().InMilliseconds(); |
45 return arg->timestamp().InMilliseconds() == ms; | 48 return arg->timestamp().InMilliseconds() == ms; |
46 } | 49 } |
47 | 50 |
48 class VideoRendererImplTest : public ::testing::Test { | 51 class VideoRendererImplTest : public testing::TestWithParam<bool> { |
49 public: | 52 public: |
50 VideoRendererImplTest() | 53 VideoRendererImplTest() |
51 : tick_clock_(new base::SimpleTestTickClock()), | 54 : tick_clock_(new base::SimpleTestTickClock()), |
52 decoder_(new MockVideoDecoder()), | 55 decoder_(new MockVideoDecoder()), |
53 demuxer_stream_(DemuxerStream::VIDEO) { | 56 demuxer_stream_(DemuxerStream::VIDEO) { |
54 ScopedVector<VideoDecoder> decoders; | 57 ScopedVector<VideoDecoder> decoders; |
55 decoders.push_back(decoder_); | 58 decoders.push_back(decoder_); |
56 | 59 |
57 // Since the Underflow test needs a render interval shorter than the frame | 60 // Since the Underflow test needs a render interval shorter than the frame |
58 // duration, use 120Hz (which makes each interval is < 10ms; ~9.9ms). | 61 // duration, use 120Hz (which makes each interval is < 10ms; ~9.9ms). |
59 null_video_sink_.reset(new NullVideoSink( | 62 null_video_sink_.reset(new NullVideoSink( |
60 false, base::TimeDelta::FromSecondsD(1.0 / 120), | 63 false, base::TimeDelta::FromSecondsD(1.0 / 120), |
61 base::Bind(&MockCB::FrameReceived, base::Unretained(&mock_cb_)), | 64 base::Bind(&MockCB::FrameReceived, base::Unretained(&mock_cb_)), |
62 message_loop_.task_runner())); | 65 message_loop_.task_runner())); |
63 | 66 |
64 renderer_.reset(new VideoRendererImpl( | 67 renderer_.reset(new VideoRendererImpl( |
65 message_loop_.message_loop_proxy(), null_video_sink_.get(), | 68 message_loop_.message_loop_proxy(), null_video_sink_.get(), |
66 decoders.Pass(), true, new MediaLog())); | 69 decoders.Pass(), true, new MediaLog())); |
67 | 70 if (GetParam()) |
| 71 renderer_->enable_new_video_renderer_for_testing(); |
68 renderer_->SetTickClockForTesting(scoped_ptr<base::TickClock>(tick_clock_)); | 72 renderer_->SetTickClockForTesting(scoped_ptr<base::TickClock>(tick_clock_)); |
69 null_video_sink_->set_tick_clock_for_testing(tick_clock_); | 73 null_video_sink_->set_tick_clock_for_testing(tick_clock_); |
70 | 74 |
| 75 // Disable background rendering for tests by default. |
| 76 renderer_->SetBackgroundRenderingForTesting(false, base::TimeDelta()); |
| 77 |
71 // Start wallclock time at a non-zero value. | 78 // Start wallclock time at a non-zero value. |
72 AdvanceWallclockTimeInMs(12345); | 79 AdvanceWallclockTimeInMs(12345); |
73 | 80 |
74 demuxer_stream_.set_video_decoder_config(TestVideoConfig::Normal()); | 81 demuxer_stream_.set_video_decoder_config(TestVideoConfig::Normal()); |
75 | 82 |
76 // We expect these to be called but we don't care how/when. | 83 // We expect these to be called but we don't care how/when. |
77 EXPECT_CALL(demuxer_stream_, Read(_)).WillRepeatedly( | 84 EXPECT_CALL(demuxer_stream_, Read(_)).WillRepeatedly( |
78 RunCallback<0>(DemuxerStream::kOk, | 85 RunCallback<0>(DemuxerStream::kOk, |
79 scoped_refptr<DecoderBuffer>(new DecoderBuffer(0)))); | 86 scoped_refptr<DecoderBuffer>(new DecoderBuffer(0)))); |
80 } | 87 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 renderer_->Flush(event.GetClosure()); | 145 renderer_->Flush(event.GetClosure()); |
139 event.RunAndWait(); | 146 event.RunAndWait(); |
140 } | 147 } |
141 | 148 |
142 void Destroy() { | 149 void Destroy() { |
143 SCOPED_TRACE("Destroy()"); | 150 SCOPED_TRACE("Destroy()"); |
144 renderer_.reset(); | 151 renderer_.reset(); |
145 message_loop_.RunUntilIdle(); | 152 message_loop_.RunUntilIdle(); |
146 } | 153 } |
147 | 154 |
| 155 void SuspendRenderCallbacks() { |
| 156 null_video_sink_->PauseRenderCallbacks(base::TimeTicks() + |
| 157 base::TimeDelta::Max()); |
| 158 } |
| 159 |
148 // Parses a string representation of video frames and generates corresponding | 160 // Parses a string representation of video frames and generates corresponding |
149 // VideoFrame objects in |decode_results_|. | 161 // VideoFrame objects in |decode_results_|. |
150 // | 162 // |
151 // Syntax: | 163 // Syntax: |
152 // nn - Queue a decoder buffer with timestamp nn * 1000us | 164 // nn - Queue a decoder buffer with timestamp nn * 1000us |
153 // abort - Queue an aborted read | 165 // abort - Queue an aborted read |
154 // error - Queue a decoder error | 166 // error - Queue a decoder error |
155 // | 167 // |
156 // Examples: | 168 // Examples: |
157 // A clip that is four frames long: "0 10 20 30" | 169 // A clip that is four frames long: "0 10 20 30" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 base::AutoLock l(lock_); | 271 base::AutoLock l(lock_); |
260 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(time_ms)); | 272 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(time_ms)); |
261 } | 273 } |
262 | 274 |
263 void AdvanceTimeInMs(int time_ms) { | 275 void AdvanceTimeInMs(int time_ms) { |
264 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); | 276 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); |
265 base::AutoLock l(lock_); | 277 base::AutoLock l(lock_); |
266 time_ += base::TimeDelta::FromMilliseconds(time_ms); | 278 time_ += base::TimeDelta::FromMilliseconds(time_ms); |
267 } | 279 } |
268 | 280 |
| 281 bool has_ended() const { |
| 282 return ended_event_.is_signaled(); |
| 283 } |
| 284 |
269 protected: | 285 protected: |
270 // Fixture members. | 286 // Fixture members. |
271 scoped_ptr<VideoRendererImpl> renderer_; | 287 scoped_ptr<VideoRendererImpl> renderer_; |
272 base::SimpleTestTickClock* tick_clock_; // Owned by |renderer_|. | 288 base::SimpleTestTickClock* tick_clock_; // Owned by |renderer_|. |
273 MockVideoDecoder* decoder_; // Owned by |renderer_|. | 289 MockVideoDecoder* decoder_; // Owned by |renderer_|. |
274 NiceMock<MockDemuxerStream> demuxer_stream_; | 290 NiceMock<MockDemuxerStream> demuxer_stream_; |
275 | 291 |
276 // Use StrictMock<T> to catch missing/extra callbacks. | 292 // Use StrictMock<T> to catch missing/extra callbacks. |
277 class MockCB { | 293 class MockCB { |
278 public: | 294 public: |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 353 |
338 // Run during DecodeRequested() to unblock WaitForPendingRead(). | 354 // Run during DecodeRequested() to unblock WaitForPendingRead(). |
339 base::Closure wait_for_pending_decode_cb_; | 355 base::Closure wait_for_pending_decode_cb_; |
340 | 356 |
341 std::deque<std::pair< | 357 std::deque<std::pair< |
342 VideoDecoder::Status, scoped_refptr<VideoFrame> > > decode_results_; | 358 VideoDecoder::Status, scoped_refptr<VideoFrame> > > decode_results_; |
343 | 359 |
344 DISALLOW_COPY_AND_ASSIGN(VideoRendererImplTest); | 360 DISALLOW_COPY_AND_ASSIGN(VideoRendererImplTest); |
345 }; | 361 }; |
346 | 362 |
347 TEST_F(VideoRendererImplTest, DoNothing) { | 363 TEST_P(VideoRendererImplTest, DoNothing) { |
348 // Test that creation and deletion doesn't depend on calls to Initialize() | 364 // Test that creation and deletion doesn't depend on calls to Initialize() |
349 // and/or Destroy(). | 365 // and/or Destroy(). |
350 } | 366 } |
351 | 367 |
352 TEST_F(VideoRendererImplTest, DestroyWithoutInitialize) { | 368 TEST_P(VideoRendererImplTest, DestroyWithoutInitialize) { |
353 Destroy(); | 369 Destroy(); |
354 } | 370 } |
355 | 371 |
356 TEST_F(VideoRendererImplTest, Initialize) { | 372 TEST_P(VideoRendererImplTest, Initialize) { |
357 Initialize(); | 373 Initialize(); |
358 Destroy(); | 374 Destroy(); |
359 } | 375 } |
360 | 376 |
361 TEST_F(VideoRendererImplTest, InitializeAndStartPlayingFrom) { | 377 TEST_P(VideoRendererImplTest, InitializeAndStartPlayingFrom) { |
362 Initialize(); | 378 Initialize(); |
363 QueueFrames("0 10 20 30"); | 379 QueueFrames("0 10 20 30"); |
364 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); | 380 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); |
365 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 381 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
366 StartPlayingFrom(0); | 382 StartPlayingFrom(0); |
367 Destroy(); | 383 Destroy(); |
368 } | 384 } |
369 | 385 |
370 TEST_F(VideoRendererImplTest, DestroyWhileInitializing) { | 386 TEST_P(VideoRendererImplTest, InitializeAndEndOfStream) { |
| 387 Initialize(); |
| 388 StartPlayingFrom(0); |
| 389 WaitForPendingRead(); |
| 390 { |
| 391 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); |
| 392 WaitableMessageLoopEvent event; |
| 393 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 394 .WillOnce(RunClosure(event.GetClosure())); |
| 395 SatisfyPendingReadWithEndOfStream(); |
| 396 event.RunAndWait(); |
| 397 } |
| 398 EXPECT_FALSE(null_video_sink_->is_started()); |
| 399 Destroy(); |
| 400 } |
| 401 |
| 402 TEST_P(VideoRendererImplTest, DestroyWhileInitializing) { |
371 CallInitialize(NewExpectedStatusCB(PIPELINE_ERROR_ABORT), false, PIPELINE_OK); | 403 CallInitialize(NewExpectedStatusCB(PIPELINE_ERROR_ABORT), false, PIPELINE_OK); |
372 Destroy(); | 404 Destroy(); |
373 } | 405 } |
374 | 406 |
375 TEST_F(VideoRendererImplTest, DestroyWhileFlushing) { | 407 TEST_P(VideoRendererImplTest, DestroyWhileFlushing) { |
376 Initialize(); | 408 Initialize(); |
377 QueueFrames("0 10 20 30"); | 409 QueueFrames("0 10 20 30"); |
378 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); | 410 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); |
379 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 411 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
380 StartPlayingFrom(0); | 412 StartPlayingFrom(0); |
381 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_NOTHING)); | 413 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_NOTHING)); |
382 renderer_->Flush(NewExpectedClosure()); | 414 renderer_->Flush(NewExpectedClosure()); |
383 Destroy(); | 415 Destroy(); |
384 } | 416 } |
385 | 417 |
386 TEST_F(VideoRendererImplTest, Play) { | 418 TEST_P(VideoRendererImplTest, Play) { |
387 Initialize(); | 419 Initialize(); |
388 QueueFrames("0 10 20 30"); | 420 QueueFrames("0 10 20 30"); |
389 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); | 421 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); |
390 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 422 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
391 StartPlayingFrom(0); | 423 StartPlayingFrom(0); |
392 Destroy(); | 424 Destroy(); |
393 } | 425 } |
394 | 426 |
395 TEST_F(VideoRendererImplTest, FlushWithNothingBuffered) { | 427 TEST_P(VideoRendererImplTest, FlushWithNothingBuffered) { |
396 Initialize(); | 428 Initialize(); |
397 StartPlayingFrom(0); | 429 StartPlayingFrom(0); |
398 | 430 |
399 // We shouldn't expect a buffering state change since we never reached | 431 // We shouldn't expect a buffering state change since we never reached |
400 // BUFFERING_HAVE_ENOUGH. | 432 // BUFFERING_HAVE_ENOUGH. |
401 Flush(); | 433 Flush(); |
402 Destroy(); | 434 Destroy(); |
403 } | 435 } |
404 | 436 |
405 TEST_F(VideoRendererImplTest, DecodeError_Playing) { | 437 TEST_P(VideoRendererImplTest, DecodeError_Playing) { |
406 Initialize(); | 438 Initialize(); |
407 QueueFrames("0 10 20 30"); | 439 QueueFrames("0 10 20 30"); |
408 EXPECT_CALL(mock_cb_, FrameReceived(_)).Times(testing::AtLeast(1)); | 440 EXPECT_CALL(mock_cb_, FrameReceived(_)).Times(testing::AtLeast(1)); |
409 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 441 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
410 StartPlayingFrom(0); | 442 StartPlayingFrom(0); |
411 | 443 renderer_->OnTimeStateChanged(true); |
412 WaitForPendingRead(); | |
413 | 444 |
414 QueueFrames("error"); | 445 QueueFrames("error"); |
415 SatisfyPendingRead(); | 446 SatisfyPendingRead(); |
416 WaitForError(PIPELINE_ERROR_DECODE); | 447 WaitForError(PIPELINE_ERROR_DECODE); |
417 Destroy(); | 448 Destroy(); |
418 } | 449 } |
419 | 450 |
420 TEST_F(VideoRendererImplTest, DecodeError_DuringStartPlayingFrom) { | 451 TEST_P(VideoRendererImplTest, DecodeError_DuringStartPlayingFrom) { |
421 Initialize(); | 452 Initialize(); |
422 QueueFrames("error"); | 453 QueueFrames("error"); |
423 StartPlayingFrom(0); | 454 StartPlayingFrom(0); |
424 Destroy(); | 455 Destroy(); |
425 } | 456 } |
426 | 457 |
427 TEST_F(VideoRendererImplTest, StartPlayingFrom_Exact) { | 458 TEST_P(VideoRendererImplTest, StartPlayingFrom_Exact) { |
428 Initialize(); | 459 Initialize(); |
429 QueueFrames("50 60 70 80 90"); | 460 QueueFrames("50 60 70 80 90"); |
430 | 461 |
431 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(60))); | 462 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(60))); |
432 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 463 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
433 StartPlayingFrom(60); | 464 StartPlayingFrom(60); |
434 Destroy(); | 465 Destroy(); |
435 } | 466 } |
436 | 467 |
437 TEST_F(VideoRendererImplTest, StartPlayingFrom_RightBefore) { | 468 TEST_P(VideoRendererImplTest, StartPlayingFrom_RightBefore) { |
438 Initialize(); | 469 Initialize(); |
439 QueueFrames("50 60 70 80 90"); | 470 QueueFrames("50 60 70 80 90"); |
440 | 471 |
441 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(50))); | 472 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(50))); |
442 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 473 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
443 StartPlayingFrom(59); | 474 StartPlayingFrom(59); |
444 Destroy(); | 475 Destroy(); |
445 } | 476 } |
446 | 477 |
447 TEST_F(VideoRendererImplTest, StartPlayingFrom_RightAfter) { | 478 TEST_P(VideoRendererImplTest, StartPlayingFrom_RightAfter) { |
448 Initialize(); | 479 Initialize(); |
449 QueueFrames("50 60 70 80 90"); | 480 QueueFrames("50 60 70 80 90"); |
450 | 481 |
451 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(60))); | 482 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(60))); |
452 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 483 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
453 StartPlayingFrom(61); | 484 StartPlayingFrom(61); |
454 Destroy(); | 485 Destroy(); |
455 } | 486 } |
456 | 487 |
457 TEST_F(VideoRendererImplTest, StartPlayingFrom_LowDelay) { | 488 TEST_P(VideoRendererImplTest, StartPlayingFrom_LowDelay) { |
458 // In low-delay mode only one frame is required to finish preroll. | 489 // In low-delay mode only one frame is required to finish preroll. |
459 InitializeWithLowDelay(true); | 490 InitializeWithLowDelay(true); |
460 QueueFrames("0"); | 491 QueueFrames("0"); |
461 | 492 |
462 // Expect some amount of have enough/nothing due to only requiring one frame. | 493 // Expect some amount of have enough/nothing due to only requiring one frame. |
463 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); | 494 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); |
464 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 495 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
465 .Times(AnyNumber()); | 496 .Times(AnyNumber()); |
466 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_NOTHING)) | 497 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_NOTHING)) |
467 .Times(AnyNumber()); | 498 .Times(AnyNumber()); |
468 StartPlayingFrom(0); | 499 StartPlayingFrom(0); |
469 | 500 |
470 QueueFrames("10"); | 501 QueueFrames("10"); |
471 SatisfyPendingRead(); | 502 SatisfyPendingRead(); |
472 | 503 |
| 504 renderer_->OnTimeStateChanged(true); |
473 WaitableMessageLoopEvent event; | 505 WaitableMessageLoopEvent event; |
474 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(10))) | 506 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(10))) |
475 .WillOnce(RunClosure(event.GetClosure())); | 507 .WillOnce(RunClosure(event.GetClosure())); |
476 AdvanceTimeInMs(10); | 508 AdvanceTimeInMs(10); |
477 event.RunAndWait(); | 509 event.RunAndWait(); |
478 | 510 |
479 Destroy(); | 511 Destroy(); |
480 } | 512 } |
481 | 513 |
482 // Verify that a late decoder response doesn't break invariants in the renderer. | 514 // Verify that a late decoder response doesn't break invariants in the renderer. |
483 TEST_F(VideoRendererImplTest, DestroyDuringOutstandingRead) { | 515 TEST_P(VideoRendererImplTest, DestroyDuringOutstandingRead) { |
484 Initialize(); | 516 Initialize(); |
485 QueueFrames("0 10 20 30"); | 517 QueueFrames("0 10 20 30"); |
486 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); | 518 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); |
487 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 519 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
488 StartPlayingFrom(0); | 520 StartPlayingFrom(0); |
489 | 521 |
490 // Check that there is an outstanding Read() request. | 522 // Check that there is an outstanding Read() request. |
491 EXPECT_TRUE(IsReadPending()); | 523 EXPECT_TRUE(IsReadPending()); |
492 | 524 |
493 Destroy(); | 525 Destroy(); |
494 } | 526 } |
495 | 527 |
496 TEST_F(VideoRendererImplTest, VideoDecoder_InitFailure) { | 528 TEST_P(VideoRendererImplTest, VideoDecoder_InitFailure) { |
497 InitializeRenderer(DECODER_ERROR_NOT_SUPPORTED, false); | 529 InitializeRenderer(DECODER_ERROR_NOT_SUPPORTED, false); |
498 Destroy(); | 530 Destroy(); |
499 } | 531 } |
500 | 532 |
501 TEST_F(VideoRendererImplTest, Underflow) { | 533 TEST_P(VideoRendererImplTest, Underflow) { |
502 Initialize(); | 534 Initialize(); |
503 QueueFrames("0 10 20 30"); | 535 QueueFrames("0 10 20 30"); |
504 | 536 |
505 { | 537 { |
506 WaitableMessageLoopEvent event; | 538 WaitableMessageLoopEvent event; |
507 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); | 539 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); |
508 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 540 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
509 .WillOnce(RunClosure(event.GetClosure())); | 541 .WillOnce(RunClosure(event.GetClosure())); |
510 StartPlayingFrom(0); | 542 StartPlayingFrom(0); |
511 event.RunAndWait(); | 543 event.RunAndWait(); |
512 Mock::VerifyAndClearExpectations(&mock_cb_); | 544 Mock::VerifyAndClearExpectations(&mock_cb_); |
513 } | 545 } |
514 | 546 |
| 547 renderer_->OnTimeStateChanged(true); |
| 548 |
515 // Advance time slightly, but enough to exceed the duration of the last frame. | 549 // Advance time slightly, but enough to exceed the duration of the last frame. |
516 // Frames should be dropped and we should NOT signal having nothing. | 550 // Frames should be dropped and we should NOT signal having nothing. |
517 { | 551 { |
518 SCOPED_TRACE("Waiting for frame drops"); | 552 SCOPED_TRACE("Waiting for frame drops"); |
519 WaitableMessageLoopEvent event; | 553 WaitableMessageLoopEvent event; |
520 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(10))) | 554 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(10))) |
521 .Times(0); | 555 .Times(0); |
522 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(20))) | 556 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(20))) |
523 .Times(0); | 557 .Times(0); |
524 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(30))) | 558 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(30))) |
(...skipping 22 matching lines...) Expand all Loading... |
547 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 581 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
548 .WillOnce(RunClosure(event.GetClosure())); | 582 .WillOnce(RunClosure(event.GetClosure())); |
549 SatisfyPendingReadWithEndOfStream(); | 583 SatisfyPendingReadWithEndOfStream(); |
550 event.RunAndWait(); | 584 event.RunAndWait(); |
551 } | 585 } |
552 | 586 |
553 WaitForEnded(); | 587 WaitForEnded(); |
554 Destroy(); | 588 Destroy(); |
555 } | 589 } |
556 | 590 |
| 591 // Tests the case where the video started in the background and never received |
| 592 // any Render() calls and time never started progressing (so the sink should be |
| 593 // stopped immediately). |
| 594 TEST_P(VideoRendererImplTest, BackgroundRenderingStopsAfterFirstFrame) { |
| 595 // This test is only for the new rendering path. |
| 596 if (!GetParam()) |
| 597 return; |
| 598 |
| 599 // By default, tests disable background rendering, so enable it now and give |
| 600 // a short, but non-zero, timeout. |
| 601 renderer_->SetBackgroundRenderingForTesting( |
| 602 true, base::TimeDelta::FromMilliseconds(kTestBackgroundRenderTimeoutMs)); |
| 603 |
| 604 InitializeWithLowDelay(true); |
| 605 QueueFrames("0"); |
| 606 |
| 607 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
| 608 |
| 609 // Pause callbacks forever, but don't start the sink. Ended should not fire. |
| 610 SuspendRenderCallbacks(); |
| 611 StartPlayingFrom(0); |
| 612 EXPECT_TRUE(IsReadPending()); |
| 613 SatisfyPendingReadWithEndOfStream(); |
| 614 |
| 615 { |
| 616 SCOPED_TRACE("Waiting for sink to stop."); |
| 617 WaitableMessageLoopEvent event; |
| 618 null_video_sink_->set_stop_cb(event.GetClosure()); |
| 619 event.RunAndWait(); |
| 620 } |
| 621 |
| 622 EXPECT_FALSE(has_ended()); |
| 623 Destroy(); |
| 624 } |
| 625 |
| 626 // Tests the case where the video started in the background and never received |
| 627 // any Render() calls, but time is progressing. |
| 628 TEST_P(VideoRendererImplTest, BackgroundRenderingNeverStarted) { |
| 629 // This test is only for the new rendering path. |
| 630 if (!GetParam()) |
| 631 return; |
| 632 |
| 633 // By default, tests disable background rendering, so enable it now and give |
| 634 // a short, but non-zero, timeout. |
| 635 renderer_->SetBackgroundRenderingForTesting( |
| 636 true, base::TimeDelta::FromMilliseconds(kTestBackgroundRenderTimeoutMs)); |
| 637 |
| 638 Initialize(); |
| 639 QueueFrames("0 10 20 30"); |
| 640 |
| 641 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
| 642 |
| 643 // Start the sink and pause callbacks forever. |
| 644 renderer_->OnTimeStateChanged(true); |
| 645 SuspendRenderCallbacks(); |
| 646 StartPlayingFrom(0); |
| 647 AdvanceTimeInMs(41); |
| 648 AdvanceWallclockTimeInMs(kTestBackgroundRenderTimeoutMs); |
| 649 |
| 650 // Eventually background rendering should request new buffers and at that |
| 651 // point fire the ended event if rendering has completed. |
| 652 WaitForPendingRead(); |
| 653 SatisfyPendingReadWithEndOfStream(); |
| 654 WaitForEnded(); |
| 655 Destroy(); |
| 656 } |
| 657 |
| 658 // Tests the case where the video started in the background and never received |
| 659 // any Render() calls, but time is progressing and there's only a single frame |
| 660 // in the video. |
| 661 TEST_P(VideoRendererImplTest, BackgroundRenderingNeverStartedSingleFrame) { |
| 662 // This test is only for the new rendering path. |
| 663 if (!GetParam()) |
| 664 return; |
| 665 |
| 666 // By default, tests disable background rendering, so enable it now and give |
| 667 // a short, but non-zero, timeout. |
| 668 renderer_->SetBackgroundRenderingForTesting( |
| 669 true, base::TimeDelta::FromMilliseconds(kTestBackgroundRenderTimeoutMs)); |
| 670 |
| 671 Initialize(); |
| 672 QueueFrames("0"); |
| 673 |
| 674 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
| 675 |
| 676 // Start the sink and pause callbacks forever. |
| 677 renderer_->OnTimeStateChanged(true); |
| 678 SuspendRenderCallbacks(); |
| 679 StartPlayingFrom(0); |
| 680 |
| 681 AdvanceWallclockTimeInMs(kTestBackgroundRenderTimeoutMs); |
| 682 |
| 683 // Eventually background rendering should request new buffers and at that |
| 684 // point fire the ended event if rendering has completed. |
| 685 WaitForPendingRead(); |
| 686 SatisfyPendingReadWithEndOfStream(); |
| 687 WaitForEnded(); |
| 688 Destroy(); |
| 689 } |
| 690 |
| 691 // Tests the case where the video started and received a single Render() call, |
| 692 // then the video was put into the background. |
| 693 TEST_P(VideoRendererImplTest, BackgroundRenderingRenderStartedThenStopped) { |
| 694 // This test is only for the new rendering path. |
| 695 if (!GetParam()) |
| 696 return; |
| 697 |
| 698 // By default, tests disable background rendering, so enable it now and give |
| 699 // a short, but non-zero, timeout. |
| 700 renderer_->SetBackgroundRenderingForTesting( |
| 701 true, base::TimeDelta::FromMilliseconds(kTestBackgroundRenderTimeoutMs)); |
| 702 |
| 703 Initialize(); |
| 704 QueueFrames("0 10 20 30"); |
| 705 |
| 706 // Start the sink and wait for the first callback. |
| 707 { |
| 708 WaitableMessageLoopEvent event; |
| 709 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); |
| 710 EXPECT_CALL(mock_cb_, BufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 711 .WillOnce(RunClosure(event.GetClosure())); |
| 712 StartPlayingFrom(0); |
| 713 event.RunAndWait(); |
| 714 Mock::VerifyAndClearExpectations(&mock_cb_); |
| 715 } |
| 716 |
| 717 renderer_->OnTimeStateChanged(true); |
| 718 |
| 719 // Suspend all future callbacks and synthetically advance the media time. |
| 720 SuspendRenderCallbacks(); |
| 721 AdvanceTimeInMs(41); |
| 722 AdvanceWallclockTimeInMs(kTestBackgroundRenderTimeoutMs); |
| 723 |
| 724 // Eventually background rendering should request new buffers and at that |
| 725 // point fire the ended event if rendering has completed. |
| 726 WaitForPendingRead(); |
| 727 SatisfyPendingReadWithEndOfStream(); |
| 728 WaitForEnded(); |
| 729 Destroy(); |
| 730 } |
| 731 |
| 732 INSTANTIATE_TEST_CASE_P(OldVideoRenderer, |
| 733 VideoRendererImplTest, |
| 734 testing::Values(false)); |
| 735 INSTANTIATE_TEST_CASE_P(NewVideoRenderer, |
| 736 VideoRendererImplTest, |
| 737 testing::Values(true)); |
| 738 |
557 } // namespace media | 739 } // namespace media |
OLD | NEW |