| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 209 } |
| 210 | 210 |
| 211 void WaitForEnded() { | 211 void WaitForEnded() { |
| 212 SCOPED_TRACE("WaitForEnded()"); | 212 SCOPED_TRACE("WaitForEnded()"); |
| 213 | 213 |
| 214 WaitableMessageLoopEvent event; | 214 WaitableMessageLoopEvent event; |
| 215 EXPECT_CALL(mock_cb_, OnEnded()).WillOnce(RunClosure(event.GetClosure())); | 215 EXPECT_CALL(mock_cb_, OnEnded()).WillOnce(RunClosure(event.GetClosure())); |
| 216 event.RunAndWait(); | 216 event.RunAndWait(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void WaitForPendingRead() { | 219 void WaitForPendingDecode() { |
| 220 SCOPED_TRACE("WaitForPendingRead()"); | 220 SCOPED_TRACE("WaitForPendingDecode()"); |
| 221 if (!decode_cb_.is_null()) | 221 if (!decode_cb_.is_null()) |
| 222 return; | 222 return; |
| 223 | 223 |
| 224 DCHECK(wait_for_pending_decode_cb_.is_null()); | 224 DCHECK(wait_for_pending_decode_cb_.is_null()); |
| 225 | 225 |
| 226 WaitableMessageLoopEvent event; | 226 WaitableMessageLoopEvent event; |
| 227 wait_for_pending_decode_cb_ = event.GetClosure(); | 227 wait_for_pending_decode_cb_ = event.GetClosure(); |
| 228 event.RunAndWait(); | 228 event.RunAndWait(); |
| 229 | 229 |
| 230 DCHECK(!decode_cb_.is_null()); | 230 DCHECK(!decode_cb_.is_null()); |
| 231 DCHECK(wait_for_pending_decode_cb_.is_null()); | 231 DCHECK(wait_for_pending_decode_cb_.is_null()); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void SatisfyPendingRead() { | 234 void SatisfyPendingDecode() { |
| 235 CHECK(!decode_cb_.is_null()); | 235 CHECK(!decode_cb_.is_null()); |
| 236 CHECK(!decode_results_.empty()); | 236 CHECK(!decode_results_.empty()); |
| 237 | 237 |
| 238 // Post tasks for OutputCB and DecodeCB. | 238 // Post tasks for OutputCB and DecodeCB. |
| 239 scoped_refptr<VideoFrame> frame = decode_results_.front().second; | 239 scoped_refptr<VideoFrame> frame = decode_results_.front().second; |
| 240 if (frame.get()) | 240 if (frame.get()) |
| 241 message_loop_.PostTask(FROM_HERE, base::Bind(output_cb_, frame)); | 241 message_loop_.PostTask(FROM_HERE, base::Bind(output_cb_, frame)); |
| 242 message_loop_.PostTask( | 242 message_loop_.PostTask( |
| 243 FROM_HERE, base::Bind(base::ResetAndReturn(&decode_cb_), | 243 FROM_HERE, base::Bind(base::ResetAndReturn(&decode_cb_), |
| 244 decode_results_.front().first)); | 244 decode_results_.front().first)); |
| 245 decode_results_.pop_front(); | 245 decode_results_.pop_front(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void SatisfyPendingReadWithEndOfStream() { | 248 void SatisfyPendingDecodeWithEndOfStream() { |
| 249 DCHECK(!decode_cb_.is_null()); | 249 DCHECK(!decode_cb_.is_null()); |
| 250 | 250 |
| 251 // Return EOS buffer to trigger EOS frame. | 251 // Return EOS buffer to trigger EOS frame. |
| 252 EXPECT_CALL(demuxer_stream_, Read(_)) | 252 EXPECT_CALL(demuxer_stream_, Read(_)) |
| 253 .WillOnce(RunCallback<0>(DemuxerStream::kOk, | 253 .WillOnce(RunCallback<0>(DemuxerStream::kOk, |
| 254 DecoderBuffer::CreateEOSBuffer())); | 254 DecoderBuffer::CreateEOSBuffer())); |
| 255 | 255 |
| 256 // Satify pending |decode_cb_| to trigger a new DemuxerStream::Read(). | 256 // Satify pending |decode_cb_| to trigger a new DemuxerStream::Read(). |
| 257 message_loop_.PostTask( | 257 message_loop_.PostTask( |
| 258 FROM_HERE, | 258 FROM_HERE, |
| 259 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK)); | 259 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK)); |
| 260 | 260 |
| 261 WaitForPendingRead(); | 261 WaitForPendingDecode(); |
| 262 | 262 |
| 263 message_loop_.PostTask( | 263 message_loop_.PostTask( |
| 264 FROM_HERE, | 264 FROM_HERE, |
| 265 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK)); | 265 base::Bind(base::ResetAndReturn(&decode_cb_), DecodeStatus::OK)); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void AdvanceWallclockTimeInMs(int time_ms) { | 268 void AdvanceWallclockTimeInMs(int time_ms) { |
| 269 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); | 269 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); |
| 270 base::AutoLock l(lock_); | 270 base::AutoLock l(lock_); |
| 271 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(time_ms)); | 271 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(time_ms)); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 renderer_->OnTimeStateChanged(false); | 346 renderer_->OnTimeStateChanged(false); |
| 347 renderer_->OnTimeStateChanged(true); | 347 renderer_->OnTimeStateChanged(true); |
| 348 | 348 |
| 349 // Receiving end of stream should signal having enough. | 349 // Receiving end of stream should signal having enough. |
| 350 { | 350 { |
| 351 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); | 351 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); |
| 352 WaitableMessageLoopEvent event; | 352 WaitableMessageLoopEvent event; |
| 353 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 353 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 354 .WillOnce(RunClosure(event.GetClosure())); | 354 .WillOnce(RunClosure(event.GetClosure())); |
| 355 EXPECT_CALL(mock_cb_, OnEnded()); | 355 EXPECT_CALL(mock_cb_, OnEnded()); |
| 356 SatisfyPendingReadWithEndOfStream(); | 356 SatisfyPendingDecodeWithEndOfStream(); |
| 357 event.RunAndWait(); | 357 event.RunAndWait(); |
| 358 } | 358 } |
| 359 | 359 |
| 360 Destroy(); | 360 Destroy(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 void UnderflowRecoveryTest(UnderflowTestType type) { | 363 void UnderflowRecoveryTest(UnderflowTestType type) { |
| 364 InitializeWithLowDelay(type == UnderflowTestType::LOW_DELAY); | 364 InitializeWithLowDelay(type == UnderflowTestType::LOW_DELAY); |
| 365 if (type == UnderflowTestType::CANT_READ_WITHOUT_STALLING) | 365 if (type == UnderflowTestType::CANT_READ_WITHOUT_STALLING) |
| 366 ON_CALL(*decoder_, CanReadWithoutStalling()).WillByDefault(Return(false)); | 366 ON_CALL(*decoder_, CanReadWithoutStalling()).WillByDefault(Return(false)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 { | 407 { |
| 408 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); | 408 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); |
| 409 WaitableMessageLoopEvent event; | 409 WaitableMessageLoopEvent event; |
| 410 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(80))).Times(1); | 410 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(80))).Times(1); |
| 411 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 411 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 412 .WillOnce(RunClosure(event.GetClosure())); | 412 .WillOnce(RunClosure(event.GetClosure())); |
| 413 if (type == UnderflowTestType::NORMAL) | 413 if (type == UnderflowTestType::NORMAL) |
| 414 QueueFrames("80 100 120 140 160"); | 414 QueueFrames("80 100 120 140 160"); |
| 415 else | 415 else |
| 416 QueueFrames("40 60 80 90"); | 416 QueueFrames("40 60 80 90"); |
| 417 SatisfyPendingRead(); | 417 SatisfyPendingDecode(); |
| 418 event.RunAndWait(); | 418 event.RunAndWait(); |
| 419 } | 419 } |
| 420 | 420 |
| 421 Destroy(); | 421 Destroy(); |
| 422 } | 422 } |
| 423 | 423 |
| 424 protected: | 424 protected: |
| 425 // Fixture members. | 425 // Fixture members. |
| 426 std::unique_ptr<VideoRendererImpl> renderer_; | 426 std::unique_ptr<VideoRendererImpl> renderer_; |
| 427 base::SimpleTestTickClock* tick_clock_; // Owned by |renderer_|. | 427 base::SimpleTestTickClock* tick_clock_; // Owned by |renderer_|. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 442 | 442 |
| 443 base::MessageLoop message_loop_; | 443 base::MessageLoop message_loop_; |
| 444 | 444 |
| 445 private: | 445 private: |
| 446 void DecodeRequested(const scoped_refptr<DecoderBuffer>& buffer, | 446 void DecodeRequested(const scoped_refptr<DecoderBuffer>& buffer, |
| 447 const VideoDecoder::DecodeCB& decode_cb) { | 447 const VideoDecoder::DecodeCB& decode_cb) { |
| 448 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); | 448 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); |
| 449 CHECK(decode_cb_.is_null()); | 449 CHECK(decode_cb_.is_null()); |
| 450 decode_cb_ = decode_cb; | 450 decode_cb_ = decode_cb; |
| 451 | 451 |
| 452 // Wake up WaitForPendingRead() if needed. | 452 // Wake up WaitForPendingDecode() if needed. |
| 453 if (!wait_for_pending_decode_cb_.is_null()) | 453 if (!wait_for_pending_decode_cb_.is_null()) |
| 454 base::ResetAndReturn(&wait_for_pending_decode_cb_).Run(); | 454 base::ResetAndReturn(&wait_for_pending_decode_cb_).Run(); |
| 455 | 455 |
| 456 if (decode_results_.empty()) | 456 if (decode_results_.empty()) |
| 457 return; | 457 return; |
| 458 | 458 |
| 459 SatisfyPendingRead(); | 459 SatisfyPendingDecode(); |
| 460 } | 460 } |
| 461 | 461 |
| 462 void FlushRequested(const base::Closure& callback) { | 462 void FlushRequested(const base::Closure& callback) { |
| 463 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); | 463 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); |
| 464 decode_results_.clear(); | 464 decode_results_.clear(); |
| 465 if (!decode_cb_.is_null()) { | 465 if (!decode_cb_.is_null()) { |
| 466 QueueFrames("abort"); | 466 QueueFrames("abort"); |
| 467 SatisfyPendingRead(); | 467 SatisfyPendingDecode(); |
| 468 } | 468 } |
| 469 | 469 |
| 470 message_loop_.PostTask(FROM_HERE, callback); | 470 message_loop_.PostTask(FROM_HERE, callback); |
| 471 } | 471 } |
| 472 | 472 |
| 473 // Used to protect |time_|. | 473 // Used to protect |time_|. |
| 474 base::Lock lock_; | 474 base::Lock lock_; |
| 475 base::TimeDelta time_; | 475 base::TimeDelta time_; |
| 476 | 476 |
| 477 // Used for satisfying reads. | 477 // Used for satisfying reads. |
| 478 VideoDecoder::OutputCB output_cb_; | 478 VideoDecoder::OutputCB output_cb_; |
| 479 VideoDecoder::DecodeCB decode_cb_; | 479 VideoDecoder::DecodeCB decode_cb_; |
| 480 base::TimeDelta next_frame_timestamp_; | 480 base::TimeDelta next_frame_timestamp_; |
| 481 | 481 |
| 482 // Run during DecodeRequested() to unblock WaitForPendingRead(). | 482 // Run during DecodeRequested() to unblock WaitForPendingDecode(). |
| 483 base::Closure wait_for_pending_decode_cb_; | 483 base::Closure wait_for_pending_decode_cb_; |
| 484 | 484 |
| 485 std::deque<std::pair<DecodeStatus, scoped_refptr<VideoFrame>>> | 485 std::deque<std::pair<DecodeStatus, scoped_refptr<VideoFrame>>> |
| 486 decode_results_; | 486 decode_results_; |
| 487 | 487 |
| 488 DISALLOW_COPY_AND_ASSIGN(VideoRendererImplTest); | 488 DISALLOW_COPY_AND_ASSIGN(VideoRendererImplTest); |
| 489 }; | 489 }; |
| 490 | 490 |
| 491 TEST_F(VideoRendererImplTest, DoNothing) { | 491 TEST_F(VideoRendererImplTest, DoNothing) { |
| 492 // Test that creation and deletion doesn't depend on calls to Initialize() | 492 // Test that creation and deletion doesn't depend on calls to Initialize() |
| (...skipping 17 matching lines...) Expand all Loading... |
| 510 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); | 510 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); |
| 511 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); | 511 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); |
| 512 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); | 512 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); |
| 513 StartPlayingFrom(0); | 513 StartPlayingFrom(0); |
| 514 Destroy(); | 514 Destroy(); |
| 515 } | 515 } |
| 516 | 516 |
| 517 TEST_F(VideoRendererImplTest, InitializeAndEndOfStream) { | 517 TEST_F(VideoRendererImplTest, InitializeAndEndOfStream) { |
| 518 Initialize(); | 518 Initialize(); |
| 519 StartPlayingFrom(0); | 519 StartPlayingFrom(0); |
| 520 WaitForPendingRead(); | 520 WaitForPendingDecode(); |
| 521 { | 521 { |
| 522 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); | 522 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); |
| 523 WaitableMessageLoopEvent event; | 523 WaitableMessageLoopEvent event; |
| 524 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 524 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 525 .WillOnce(RunClosure(event.GetClosure())); | 525 .WillOnce(RunClosure(event.GetClosure())); |
| 526 EXPECT_CALL(mock_cb_, OnEnded()); | 526 EXPECT_CALL(mock_cb_, OnEnded()); |
| 527 SatisfyPendingReadWithEndOfStream(); | 527 SatisfyPendingDecodeWithEndOfStream(); |
| 528 event.RunAndWait(); | 528 event.RunAndWait(); |
| 529 } | 529 } |
| 530 // Firing a time state changed to true should be ignored... | 530 // Firing a time state changed to true should be ignored... |
| 531 renderer_->OnTimeStateChanged(true); | 531 renderer_->OnTimeStateChanged(true); |
| 532 EXPECT_FALSE(null_video_sink_->is_started()); | 532 EXPECT_FALSE(null_video_sink_->is_started()); |
| 533 Destroy(); | 533 Destroy(); |
| 534 } | 534 } |
| 535 | 535 |
| 536 TEST_F(VideoRendererImplTest, DestroyWhileInitializing) { | 536 TEST_F(VideoRendererImplTest, DestroyWhileInitializing) { |
| 537 CallInitialize(NewExpectedStatusCB(PIPELINE_ERROR_ABORT), false, PIPELINE_OK); | 537 CallInitialize(NewExpectedStatusCB(PIPELINE_ERROR_ABORT), false, PIPELINE_OK); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); | 587 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); |
| 588 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); | 588 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); |
| 589 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); | 589 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); |
| 590 | 590 |
| 591 StartPlayingFrom(0); | 591 StartPlayingFrom(0); |
| 592 renderer_->OnTimeStateChanged(true); | 592 renderer_->OnTimeStateChanged(true); |
| 593 time_source_.StartTicking(); | 593 time_source_.StartTicking(); |
| 594 AdvanceTimeInMs(10); | 594 AdvanceTimeInMs(10); |
| 595 | 595 |
| 596 QueueFrames("error"); | 596 QueueFrames("error"); |
| 597 SatisfyPendingRead(); | 597 SatisfyPendingDecode(); |
| 598 WaitForError(PIPELINE_ERROR_DECODE); | 598 WaitForError(PIPELINE_ERROR_DECODE); |
| 599 Destroy(); | 599 Destroy(); |
| 600 } | 600 } |
| 601 | 601 |
| 602 TEST_F(VideoRendererImplTest, DecodeError_DuringStartPlayingFrom) { | 602 TEST_F(VideoRendererImplTest, DecodeError_DuringStartPlayingFrom) { |
| 603 Initialize(); | 603 Initialize(); |
| 604 QueueFrames("error"); | 604 QueueFrames("error"); |
| 605 EXPECT_CALL(mock_cb_, OnError(PIPELINE_ERROR_DECODE)); | 605 EXPECT_CALL(mock_cb_, OnError(PIPELINE_ERROR_DECODE)); |
| 606 StartPlayingFrom(0); | 606 StartPlayingFrom(0); |
| 607 Destroy(); | 607 Destroy(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 657 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 658 .Times(AnyNumber()); | 658 .Times(AnyNumber()); |
| 659 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) | 659 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) |
| 660 .Times(AnyNumber()); | 660 .Times(AnyNumber()); |
| 661 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); | 661 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); |
| 662 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); | 662 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); |
| 663 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); | 663 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); |
| 664 StartPlayingFrom(10); | 664 StartPlayingFrom(10); |
| 665 | 665 |
| 666 QueueFrames("20"); | 666 QueueFrames("20"); |
| 667 SatisfyPendingRead(); | 667 SatisfyPendingDecode(); |
| 668 | 668 |
| 669 renderer_->OnTimeStateChanged(true); | 669 renderer_->OnTimeStateChanged(true); |
| 670 time_source_.StartTicking(); | 670 time_source_.StartTicking(); |
| 671 | 671 |
| 672 WaitableMessageLoopEvent event; | 672 WaitableMessageLoopEvent event; |
| 673 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(20))) | 673 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(20))) |
| 674 .WillOnce(RunClosure(event.GetClosure())); | 674 .WillOnce(RunClosure(event.GetClosure())); |
| 675 AdvanceTimeInMs(20); | 675 AdvanceTimeInMs(20); |
| 676 event.RunAndWait(); | 676 event.RunAndWait(); |
| 677 | 677 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 | 737 |
| 738 { | 738 { |
| 739 SCOPED_TRACE("Waiting for first frame to be painted."); | 739 SCOPED_TRACE("Waiting for first frame to be painted."); |
| 740 WaitableMessageLoopEvent event; | 740 WaitableMessageLoopEvent event; |
| 741 | 741 |
| 742 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))) | 742 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))) |
| 743 .WillOnce(RunClosure(event.GetClosure())); | 743 .WillOnce(RunClosure(event.GetClosure())); |
| 744 StartPlayingFrom(0); | 744 StartPlayingFrom(0); |
| 745 | 745 |
| 746 EXPECT_TRUE(IsReadPending()); | 746 EXPECT_TRUE(IsReadPending()); |
| 747 SatisfyPendingReadWithEndOfStream(); | 747 SatisfyPendingDecodeWithEndOfStream(); |
| 748 | 748 |
| 749 event.RunAndWait(); | 749 event.RunAndWait(); |
| 750 } | 750 } |
| 751 | 751 |
| 752 Destroy(); | 752 Destroy(); |
| 753 } | 753 } |
| 754 | 754 |
| 755 // Verifies that the sink is stopped after rendering the first frame if | 755 // Verifies that the sink is stopped after rendering the first frame if |
| 756 // playback has started. | 756 // playback has started. |
| 757 TEST_F(VideoRendererImplTest, RenderingStopsAfterOneFrameWithEOS) { | 757 TEST_F(VideoRendererImplTest, RenderingStopsAfterOneFrameWithEOS) { |
| 758 InitializeWithLowDelay(true); | 758 InitializeWithLowDelay(true); |
| 759 QueueFrames("0"); | 759 QueueFrames("0"); |
| 760 | 760 |
| 761 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))).Times(1); | 761 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))).Times(1); |
| 762 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 762 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
| 763 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); | 763 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); |
| 764 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); | 764 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); |
| 765 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); | 765 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); |
| 766 | 766 |
| 767 { | 767 { |
| 768 SCOPED_TRACE("Waiting for sink to stop."); | 768 SCOPED_TRACE("Waiting for sink to stop."); |
| 769 WaitableMessageLoopEvent event; | 769 WaitableMessageLoopEvent event; |
| 770 | 770 |
| 771 null_video_sink_->set_stop_cb(event.GetClosure()); | 771 null_video_sink_->set_stop_cb(event.GetClosure()); |
| 772 StartPlayingFrom(0); | 772 StartPlayingFrom(0); |
| 773 renderer_->OnTimeStateChanged(true); | 773 renderer_->OnTimeStateChanged(true); |
| 774 | 774 |
| 775 EXPECT_TRUE(IsReadPending()); | 775 EXPECT_TRUE(IsReadPending()); |
| 776 SatisfyPendingReadWithEndOfStream(); | 776 SatisfyPendingDecodeWithEndOfStream(); |
| 777 WaitForEnded(); | 777 WaitForEnded(); |
| 778 | 778 |
| 779 renderer_->OnTimeStateChanged(false); | 779 renderer_->OnTimeStateChanged(false); |
| 780 event.RunAndWait(); | 780 event.RunAndWait(); |
| 781 } | 781 } |
| 782 | 782 |
| 783 Destroy(); | 783 Destroy(); |
| 784 } | 784 } |
| 785 | 785 |
| 786 // Tests the case where the video started and received a single Render() call, | 786 // Tests the case where the video started and received a single Render() call, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 800 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); | 800 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); |
| 801 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); | 801 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); |
| 802 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); | 802 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); |
| 803 StartPlayingFrom(0); | 803 StartPlayingFrom(0); |
| 804 event.RunAndWait(); | 804 event.RunAndWait(); |
| 805 Mock::VerifyAndClearExpectations(&mock_cb_); | 805 Mock::VerifyAndClearExpectations(&mock_cb_); |
| 806 } | 806 } |
| 807 | 807 |
| 808 // Consider the case that rendering is faster than we setup the test event. | 808 // Consider the case that rendering is faster than we setup the test event. |
| 809 // In that case, when we run out of the frames, BUFFERING_HAVE_NOTHING will | 809 // In that case, when we run out of the frames, BUFFERING_HAVE_NOTHING will |
| 810 // be called. And then during SatisfyPendingReadWithEndOfStream, | 810 // be called. And then during SatisfyPendingDecodeWithEndOfStream, |
| 811 // BUFFER_HAVE_ENOUGH will be called again. | 811 // BUFFER_HAVE_ENOUGH will be called again. |
| 812 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 812 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 813 .Times(testing::AtMost(1)); | 813 .Times(testing::AtMost(1)); |
| 814 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) | 814 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) |
| 815 .Times(testing::AtMost(1)); | 815 .Times(testing::AtMost(1)); |
| 816 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)) | 816 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)) |
| 817 .WillRepeatedly(SaveArg<0>(&last_pipeline_statistics)); | 817 .WillRepeatedly(SaveArg<0>(&last_pipeline_statistics)); |
| 818 renderer_->OnTimeStateChanged(true); | 818 renderer_->OnTimeStateChanged(true); |
| 819 time_source_.StartTicking(); | 819 time_source_.StartTicking(); |
| 820 | 820 |
| 821 // Suspend all future callbacks and synthetically advance the media time, | 821 // Suspend all future callbacks and synthetically advance the media time, |
| 822 // because this is a background render, we won't underflow by waiting until | 822 // because this is a background render, we won't underflow by waiting until |
| 823 // a pending read is ready. | 823 // a pending read is ready. |
| 824 null_video_sink_->set_background_render(true); | 824 null_video_sink_->set_background_render(true); |
| 825 AdvanceTimeInMs(91); | 825 AdvanceTimeInMs(91); |
| 826 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(90))); | 826 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(90))); |
| 827 WaitForPendingRead(); | 827 WaitForPendingDecode(); |
| 828 SatisfyPendingReadWithEndOfStream(); | 828 SatisfyPendingDecodeWithEndOfStream(); |
| 829 | 829 |
| 830 // If this wasn't background rendering mode, this would result in two frames | 830 // If this wasn't background rendering mode, this would result in two frames |
| 831 // being dropped, but since we set background render to true, none should be | 831 // being dropped, but since we set background render to true, none should be |
| 832 // reported | 832 // reported |
| 833 EXPECT_EQ(0u, last_pipeline_statistics.video_frames_dropped); | 833 EXPECT_EQ(0u, last_pipeline_statistics.video_frames_dropped); |
| 834 EXPECT_EQ(4u, last_pipeline_statistics.video_frames_decoded); | 834 EXPECT_EQ(4u, last_pipeline_statistics.video_frames_decoded); |
| 835 EXPECT_EQ(115200, last_pipeline_statistics.video_memory_usage); | 835 EXPECT_EQ(115200, last_pipeline_statistics.video_memory_usage); |
| 836 | 836 |
| 837 AdvanceTimeInMs(30); | 837 AdvanceTimeInMs(30); |
| 838 WaitForEnded(); | 838 WaitForEnded(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 860 { | 860 { |
| 861 SCOPED_TRACE("Waiting for BUFFERING_HAVE_NOTHING"); | 861 SCOPED_TRACE("Waiting for BUFFERING_HAVE_NOTHING"); |
| 862 WaitableMessageLoopEvent event; | 862 WaitableMessageLoopEvent event; |
| 863 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) | 863 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) |
| 864 .WillOnce(RunClosure(event.GetClosure())); | 864 .WillOnce(RunClosure(event.GetClosure())); |
| 865 renderer_->OnTimeStateChanged(true); | 865 renderer_->OnTimeStateChanged(true); |
| 866 time_source_.StartTicking(); | 866 time_source_.StartTicking(); |
| 867 event.RunAndWait(); | 867 event.RunAndWait(); |
| 868 } | 868 } |
| 869 | 869 |
| 870 WaitForPendingRead(); | 870 WaitForPendingDecode(); |
| 871 | 871 |
| 872 // Jump time far enough forward that no frames are valid. | 872 // Jump time far enough forward that no frames are valid. |
| 873 renderer_->OnTimeStateChanged(false); | 873 renderer_->OnTimeStateChanged(false); |
| 874 AdvanceTimeInMs(1000); | 874 AdvanceTimeInMs(1000); |
| 875 time_source_.StopTicking(); | 875 time_source_.StopTicking(); |
| 876 | 876 |
| 877 // Providing the end of stream packet should remove all frames and exit. | 877 // Providing the end of stream packet should remove all frames and exit. |
| 878 SatisfyPendingReadWithEndOfStream(); | 878 SatisfyPendingDecodeWithEndOfStream(); |
| 879 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 879 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
| 880 WaitForEnded(); | 880 WaitForEnded(); |
| 881 Destroy(); | 881 Destroy(); |
| 882 } | 882 } |
| 883 | 883 |
| 884 TEST_F(VideoRendererImplTest, StartPlayingFromThenFlushThenEOS) { | 884 TEST_F(VideoRendererImplTest, StartPlayingFromThenFlushThenEOS) { |
| 885 Initialize(); | 885 Initialize(); |
| 886 QueueFrames("0 30 60 90"); | 886 QueueFrames("0 30 60 90"); |
| 887 | 887 |
| 888 WaitableMessageLoopEvent event; | 888 WaitableMessageLoopEvent event; |
| 889 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); | 889 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); |
| 890 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 890 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 891 .WillOnce(RunClosure(event.GetClosure())); | 891 .WillOnce(RunClosure(event.GetClosure())); |
| 892 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); | 892 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); |
| 893 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); | 893 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); |
| 894 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); | 894 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); |
| 895 StartPlayingFrom(0); | 895 StartPlayingFrom(0); |
| 896 event.RunAndWait(); | 896 event.RunAndWait(); |
| 897 | 897 |
| 898 // Cycle ticking so that we get a non-null reference time. | 898 // Cycle ticking so that we get a non-null reference time. |
| 899 time_source_.StartTicking(); | 899 time_source_.StartTicking(); |
| 900 time_source_.StopTicking(); | 900 time_source_.StopTicking(); |
| 901 | 901 |
| 902 // Flush and simulate a seek past EOS, where some error prevents the decoder | 902 // Flush and simulate a seek past EOS, where some error prevents the decoder |
| 903 // from returning any frames. | 903 // from returning any frames. |
| 904 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); | 904 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); |
| 905 Flush(); | 905 Flush(); |
| 906 | 906 |
| 907 StartPlayingFrom(200); | 907 StartPlayingFrom(200); |
| 908 WaitForPendingRead(); | 908 WaitForPendingDecode(); |
| 909 SatisfyPendingReadWithEndOfStream(); | 909 SatisfyPendingDecodeWithEndOfStream(); |
| 910 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 910 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
| 911 WaitForEnded(); | 911 WaitForEnded(); |
| 912 Destroy(); | 912 Destroy(); |
| 913 } | 913 } |
| 914 | 914 |
| 915 TEST_F(VideoRendererImplTest, FramesAreNotExpiredDuringPreroll) { | 915 TEST_F(VideoRendererImplTest, FramesAreNotExpiredDuringPreroll) { |
| 916 Initialize(); | 916 Initialize(); |
| 917 // !CanReadWithoutStalling() puts the renderer in state BUFFERING_HAVE_ENOUGH | 917 // !CanReadWithoutStalling() puts the renderer in state BUFFERING_HAVE_ENOUGH |
| 918 // after the first frame. | 918 // after the first frame. |
| 919 ON_CALL(*decoder_, CanReadWithoutStalling()).WillByDefault(Return(false)); | 919 ON_CALL(*decoder_, CanReadWithoutStalling()).WillByDefault(Return(false)); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 QueueFrames("0 10 20 30"); | 1109 QueueFrames("0 10 20 30"); |
| 1110 StartPlayingFrom(0); | 1110 StartPlayingFrom(0); |
| 1111 Flush(); | 1111 Flush(); |
| 1112 ASSERT_EQ(1u, frame_ready_cbs_.size()); | 1112 ASSERT_EQ(1u, frame_ready_cbs_.size()); |
| 1113 // This frame will be discarded. | 1113 // This frame will be discarded. |
| 1114 frame_ready_cbs_.front().Run(); | 1114 frame_ready_cbs_.front().Run(); |
| 1115 Destroy(); | 1115 Destroy(); |
| 1116 } | 1116 } |
| 1117 | 1117 |
| 1118 } // namespace media | 1118 } // namespace media |
| OLD | NEW |