| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 Play(); | 462 Play(); |
| 463 Flush(false); | 463 Flush(false); |
| 464 } | 464 } |
| 465 | 465 |
| 466 TEST_F(RendererImplTest, FlushAfterUnderflow) { | 466 TEST_F(RendererImplTest, FlushAfterUnderflow) { |
| 467 InitializeWithAudioAndVideo(); | 467 InitializeWithAudioAndVideo(); |
| 468 Play(); | 468 Play(); |
| 469 | 469 |
| 470 // Simulate underflow. | 470 // Simulate underflow. |
| 471 EXPECT_CALL(time_source_, StopTicking()); | 471 EXPECT_CALL(time_source_, StopTicking()); |
| 472 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); |
| 472 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); | 473 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
| 473 | 474 |
| 474 // Flush while underflowed. We shouldn't call StopTicking() again. | 475 // Flush while underflowed. We shouldn't call StopTicking() again. |
| 475 Flush(true); | 476 Flush(true); |
| 476 } | 477 } |
| 477 | 478 |
| 478 TEST_F(RendererImplTest, SetPlaybackRate) { | 479 TEST_F(RendererImplTest, SetPlaybackRate) { |
| 479 InitializeWithAudioAndVideo(); | 480 InitializeWithAudioAndVideo(); |
| 480 SetPlaybackRate(1.0); | 481 SetPlaybackRate(1.0); |
| 481 SetPlaybackRate(2.0); | 482 SetPlaybackRate(2.0); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 581 |
| 581 InitializeAndExpect(PIPELINE_ERROR_DECODE); | 582 InitializeAndExpect(PIPELINE_ERROR_DECODE); |
| 582 } | 583 } |
| 583 | 584 |
| 584 TEST_F(RendererImplTest, AudioUnderflow) { | 585 TEST_F(RendererImplTest, AudioUnderflow) { |
| 585 InitializeWithAudio(); | 586 InitializeWithAudio(); |
| 586 Play(); | 587 Play(); |
| 587 | 588 |
| 588 // Underflow should occur immediately with a single audio track. | 589 // Underflow should occur immediately with a single audio track. |
| 589 EXPECT_CALL(time_source_, StopTicking()); | 590 EXPECT_CALL(time_source_, StopTicking()); |
| 591 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); |
| 590 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); | 592 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
| 591 } | 593 } |
| 592 | 594 |
| 593 TEST_F(RendererImplTest, AudioUnderflowWithVideo) { | 595 TEST_F(RendererImplTest, AudioUnderflowWithVideo) { |
| 594 InitializeWithAudioAndVideo(); | 596 InitializeWithAudioAndVideo(); |
| 595 Play(); | 597 Play(); |
| 596 | 598 |
| 597 // Underflow should be immediate when both audio and video are present and | 599 // Underflow should be immediate when both audio and video are present and |
| 598 // audio underflows. | 600 // audio underflows. |
| 599 EXPECT_CALL(time_source_, StopTicking()); | 601 EXPECT_CALL(time_source_, StopTicking()); |
| 602 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); |
| 600 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); | 603 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
| 601 } | 604 } |
| 602 | 605 |
| 603 TEST_F(RendererImplTest, VideoUnderflow) { | 606 TEST_F(RendererImplTest, VideoUnderflow) { |
| 604 InitializeWithVideo(); | 607 InitializeWithVideo(); |
| 605 Play(); | 608 Play(); |
| 606 | 609 |
| 607 // Underflow should occur immediately with a single video track. | 610 // Underflow should occur immediately with a single video track. |
| 608 EXPECT_CALL(time_source_, StopTicking()); | 611 EXPECT_CALL(time_source_, StopTicking()); |
| 612 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); |
| 609 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); | 613 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
| 610 } | 614 } |
| 611 | 615 |
| 612 TEST_F(RendererImplTest, VideoUnderflowWithAudio) { | 616 TEST_F(RendererImplTest, VideoUnderflowWithAudio) { |
| 613 InitializeWithAudioAndVideo(); | 617 InitializeWithAudioAndVideo(); |
| 614 Play(); | 618 Play(); |
| 615 | 619 |
| 616 // Set a zero threshold such that the underflow will be executed on the next | 620 // Set a zero threshold such that the underflow will be executed on the next |
| 617 // run of the message loop. | 621 // run of the message loop. |
| 618 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); | 622 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); |
| 619 | 623 |
| 620 // Underflow should be delayed when both audio and video are present and video | 624 // Underflow should be delayed when both audio and video are present and video |
| 621 // underflows. | 625 // underflows. |
| 626 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); |
| 622 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); | 627 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
| 623 Mock::VerifyAndClearExpectations(&time_source_); | 628 Mock::VerifyAndClearExpectations(&time_source_); |
| 624 | 629 |
| 625 EXPECT_CALL(time_source_, StopTicking()); | 630 EXPECT_CALL(time_source_, StopTicking()); |
| 626 base::RunLoop().RunUntilIdle(); | 631 base::RunLoop().RunUntilIdle(); |
| 627 } | 632 } |
| 628 | 633 |
| 629 TEST_F(RendererImplTest, VideoUnderflowWithAudioVideoRecovers) { | 634 TEST_F(RendererImplTest, VideoUnderflowWithAudioVideoRecovers) { |
| 630 InitializeWithAudioAndVideo(); | 635 InitializeWithAudioAndVideo(); |
| 631 Play(); | 636 Play(); |
| 632 | 637 |
| 633 // Set a zero threshold such that the underflow will be executed on the next | 638 // Set a zero threshold such that the underflow will be executed on the next |
| 634 // run of the message loop. | 639 // run of the message loop. |
| 635 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); | 640 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); |
| 636 | 641 |
| 637 // Underflow should be delayed when both audio and video are present and video | 642 // Underflow should be delayed when both audio and video are present and video |
| 638 // underflows. | 643 // underflows. |
| 644 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) |
| 645 .Times(0); |
| 639 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); | 646 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
| 640 Mock::VerifyAndClearExpectations(&time_source_); | 647 Mock::VerifyAndClearExpectations(&time_source_); |
| 641 | 648 |
| 642 // If video recovers, the underflow should never occur. | 649 // If video recovers, the underflow should never occur. |
| 643 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_ENOUGH); | 650 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_ENOUGH); |
| 644 base::RunLoop().RunUntilIdle(); | 651 base::RunLoop().RunUntilIdle(); |
| 645 } | 652 } |
| 646 | 653 |
| 647 TEST_F(RendererImplTest, VideoAndAudioUnderflow) { | 654 TEST_F(RendererImplTest, VideoAndAudioUnderflow) { |
| 648 InitializeWithAudioAndVideo(); | 655 InitializeWithAudioAndVideo(); |
| 649 Play(); | 656 Play(); |
| 650 | 657 |
| 651 // Set a zero threshold such that the underflow will be executed on the next | 658 // Set a zero threshold such that the underflow will be executed on the next |
| 652 // run of the message loop. | 659 // run of the message loop. |
| 653 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); | 660 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); |
| 654 | 661 |
| 655 // Underflow should be delayed when both audio and video are present and video | 662 // Underflow should be delayed when both audio and video are present and video |
| 656 // underflows. | 663 // underflows. |
| 664 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) |
| 665 .Times(0); |
| 657 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); | 666 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
| 658 Mock::VerifyAndClearExpectations(&time_source_); | 667 Mock::VerifyAndClearExpectations(&time_source_); |
| 659 | 668 |
| 669 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); |
| 660 EXPECT_CALL(time_source_, StopTicking()); | 670 EXPECT_CALL(time_source_, StopTicking()); |
| 661 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); | 671 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
| 662 | 672 |
| 663 // Nothing else should primed on the message loop. | 673 // Nothing else should primed on the message loop. |
| 664 base::RunLoop().RunUntilIdle(); | 674 base::RunLoop().RunUntilIdle(); |
| 665 } | 675 } |
| 666 | 676 |
| 667 TEST_F(RendererImplTest, VideoUnderflowWithAudioFlush) { | 677 TEST_F(RendererImplTest, VideoUnderflowWithAudioFlush) { |
| 668 InitializeWithAudioAndVideo(); | 678 InitializeWithAudioAndVideo(); |
| 669 Play(); | 679 Play(); |
| 670 | 680 |
| 671 // Set a massive threshold such that it shouldn't fire within this test. | 681 // Set a massive threshold such that it shouldn't fire within this test. |
| 672 renderer_impl_->set_video_underflow_threshold_for_testing( | 682 renderer_impl_->set_video_underflow_threshold_for_testing( |
| 673 base::TimeDelta::FromSeconds(100)); | 683 base::TimeDelta::FromSeconds(100)); |
| 674 | 684 |
| 675 // Simulate the cases where audio underflows and then video underflows. | 685 // Simulate the cases where audio underflows and then video underflows. |
| 676 EXPECT_CALL(time_source_, StopTicking()); | 686 EXPECT_CALL(time_source_, StopTicking()); |
| 687 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); |
| 677 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); | 688 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
| 678 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); | 689 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
| 679 Mock::VerifyAndClearExpectations(&time_source_); | 690 Mock::VerifyAndClearExpectations(&time_source_); |
| 680 | 691 |
| 681 // Flush the audio and video renderers, both think they're in an underflow | 692 // Flush the audio and video renderers, both think they're in an underflow |
| 682 // state, but if the video renderer underflow was deferred, RendererImpl would | 693 // state, but if the video renderer underflow was deferred, RendererImpl would |
| 683 // think it still has enough data. | 694 // think it still has enough data. |
| 684 EXPECT_CALL(*audio_renderer_, Flush(_)).WillOnce(RunClosure<0>()); | 695 EXPECT_CALL(*audio_renderer_, Flush(_)).WillOnce(RunClosure<0>()); |
| 685 EXPECT_CALL(*video_renderer_, Flush(_)).WillOnce(RunClosure<0>()); | 696 EXPECT_CALL(*video_renderer_, Flush(_)).WillOnce(RunClosure<0>()); |
| 686 EXPECT_CALL(callbacks_, OnFlushed()); | 697 EXPECT_CALL(callbacks_, OnFlushed()); |
| 687 renderer_impl_->Flush( | 698 renderer_impl_->Flush( |
| 688 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); | 699 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); |
| 689 base::RunLoop().RunUntilIdle(); | 700 base::RunLoop().RunUntilIdle(); |
| 690 | 701 |
| 691 // Start playback after the flush, but never return BUFFERING_HAVE_ENOUGH from | 702 // Start playback after the flush, but never return BUFFERING_HAVE_ENOUGH from |
| 692 // the video renderer (which simulates spool up time for the video renderer). | 703 // the video renderer (which simulates spool up time for the video renderer). |
| 693 const base::TimeDelta kStartTime; | 704 const base::TimeDelta kStartTime; |
| 694 EXPECT_CALL(time_source_, SetMediaTime(kStartTime)); | 705 EXPECT_CALL(time_source_, SetMediaTime(kStartTime)); |
| 695 EXPECT_CALL(*audio_renderer_, StartPlaying()) | 706 EXPECT_CALL(*audio_renderer_, StartPlaying()) |
| 696 .WillOnce( | 707 .WillOnce( |
| 697 SetBufferingState(&audio_renderer_client_, BUFFERING_HAVE_ENOUGH)); | 708 SetBufferingState(&audio_renderer_client_, BUFFERING_HAVE_ENOUGH)); |
| 698 EXPECT_CALL(*video_renderer_, StartPlayingFrom(kStartTime)); | 709 EXPECT_CALL(*video_renderer_, StartPlayingFrom(kStartTime)); |
| 699 renderer_impl_->StartPlayingFrom(kStartTime); | 710 renderer_impl_->StartPlayingFrom(kStartTime); |
| 700 | 711 |
| 701 // Nothing else should primed on the message loop. | 712 // Nothing else should primed on the message loop. |
| 702 base::RunLoop().RunUntilIdle(); | 713 base::RunLoop().RunUntilIdle(); |
| 703 } | 714 } |
| 704 | 715 |
| 705 } // namespace media | 716 } // namespace media |
| OLD | NEW |