OLD | NEW |
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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/threading/simple_thread.h" | 10 #include "base/threading/simple_thread.h" |
11 #include "media/base/clock.h" | 11 #include "media/base/clock.h" |
12 #include "media/base/filter_host.h" | |
13 #include "media/base/filters.h" | |
14 #include "media/base/media_log.h" | 12 #include "media/base/media_log.h" |
15 #include "media/base/pipeline.h" | 13 #include "media/base/pipeline.h" |
16 #include "media/base/mock_callback.h" | 14 #include "media/base/mock_callback.h" |
17 #include "media/base/mock_filters.h" | 15 #include "media/base/mock_filters.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
20 | 18 |
21 using ::testing::_; | 19 using ::testing::_; |
22 using ::testing::DeleteArg; | 20 using ::testing::DeleteArg; |
23 using ::testing::DoAll; | 21 using ::testing::DoAll; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 171 } |
174 | 172 |
175 // Sets up expectations to allow the audio decoder to initialize. | 173 // Sets up expectations to allow the audio decoder to initialize. |
176 void InitializeAudioDecoder(const scoped_refptr<DemuxerStream>& stream) { | 174 void InitializeAudioDecoder(const scoped_refptr<DemuxerStream>& stream) { |
177 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) | 175 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) |
178 .WillOnce(RunPipelineStatusCB1()); | 176 .WillOnce(RunPipelineStatusCB1()); |
179 } | 177 } |
180 | 178 |
181 // Sets up expectations to allow the video renderer to initialize. | 179 // Sets up expectations to allow the video renderer to initialize. |
182 void InitializeVideoRenderer() { | 180 void InitializeVideoRenderer() { |
183 EXPECT_CALL(*mocks_->video_renderer(), SetHost(NotNull())); | |
184 EXPECT_CALL(*mocks_->video_renderer(), Initialize( | 181 EXPECT_CALL(*mocks_->video_renderer(), Initialize( |
185 scoped_refptr<VideoDecoder>(mocks_->video_decoder()), _, _, _)) | 182 scoped_refptr<VideoDecoder>(mocks_->video_decoder()), |
| 183 _, _, _, _, _, _, _, _)) |
186 .WillOnce(RunPipelineStatusCB1()); | 184 .WillOnce(RunPipelineStatusCB1()); |
187 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | 185 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); |
188 | 186 |
189 // Startup sequence. | 187 // Startup sequence. |
190 EXPECT_CALL(*mocks_->video_renderer(), | 188 EXPECT_CALL(*mocks_->video_renderer(), |
191 Seek(mocks_->demuxer()->GetStartTime(), _)) | 189 Seek(mocks_->demuxer()->GetStartTime(), _)) |
192 .WillOnce(RunPipelineStatusCB1()); | 190 .WillOnce(RunPipelineStatusCB1()); |
193 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) | 191 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) |
194 .WillOnce(RunClosure()); | 192 .WillOnce(RunClosure()); |
195 } | 193 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // We expect a successful seek callback. | 276 // We expect a successful seek callback. |
279 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | 277 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
280 } | 278 } |
281 | 279 |
282 void DoSeek(const base::TimeDelta& seek_time) { | 280 void DoSeek(const base::TimeDelta& seek_time) { |
283 pipeline_->Seek(seek_time, | 281 pipeline_->Seek(seek_time, |
284 base::Bind(&CallbackHelper::OnSeek, | 282 base::Bind(&CallbackHelper::OnSeek, |
285 base::Unretained(&callbacks_))); | 283 base::Unretained(&callbacks_))); |
286 | 284 |
287 // We expect the time to be updated only after the seek has completed. | 285 // We expect the time to be updated only after the seek has completed. |
288 EXPECT_NE(seek_time, pipeline_->GetCurrentTime()); | 286 EXPECT_NE(seek_time, pipeline_->GetMediaTime()); |
289 message_loop_.RunAllPending(); | 287 message_loop_.RunAllPending(); |
290 EXPECT_EQ(seek_time, pipeline_->GetCurrentTime()); | 288 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); |
291 } | 289 } |
292 | 290 |
293 // Fixture members. | 291 // Fixture members. |
294 StrictMock<CallbackHelper> callbacks_; | 292 StrictMock<CallbackHelper> callbacks_; |
295 MessageLoop message_loop_; | 293 MessageLoop message_loop_; |
296 scoped_refptr<Pipeline> pipeline_; | 294 scoped_refptr<Pipeline> pipeline_; |
297 scoped_ptr<media::MockFilterCollection> mocks_; | 295 scoped_ptr<media::MockFilterCollection> mocks_; |
298 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; | 296 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; |
299 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream_; | 297 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream_; |
300 AudioRenderer::TimeCB audio_time_cb_; | 298 AudioRenderer::TimeCB audio_time_cb_; |
(...skipping 19 matching lines...) Expand all Loading... |
320 pipeline_->SetPlaybackRate(1.0f); | 318 pipeline_->SetPlaybackRate(1.0f); |
321 EXPECT_EQ(1.0f, pipeline_->GetPlaybackRate()); | 319 EXPECT_EQ(1.0f, pipeline_->GetPlaybackRate()); |
322 | 320 |
323 // Setting should still work. | 321 // Setting should still work. |
324 EXPECT_EQ(1.0f, pipeline_->GetVolume()); | 322 EXPECT_EQ(1.0f, pipeline_->GetVolume()); |
325 pipeline_->SetVolume(-1.0f); | 323 pipeline_->SetVolume(-1.0f); |
326 EXPECT_EQ(1.0f, pipeline_->GetVolume()); | 324 EXPECT_EQ(1.0f, pipeline_->GetVolume()); |
327 pipeline_->SetVolume(0.0f); | 325 pipeline_->SetVolume(0.0f); |
328 EXPECT_EQ(0.0f, pipeline_->GetVolume()); | 326 EXPECT_EQ(0.0f, pipeline_->GetVolume()); |
329 | 327 |
330 EXPECT_TRUE(kZero == pipeline_->GetCurrentTime()); | 328 EXPECT_TRUE(kZero == pipeline_->GetMediaTime()); |
331 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); | 329 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); |
332 EXPECT_TRUE(kZero == pipeline_->GetMediaDuration()); | 330 EXPECT_TRUE(kZero == pipeline_->GetMediaDuration()); |
333 | 331 |
334 EXPECT_EQ(0, pipeline_->GetTotalBytes()); | 332 EXPECT_EQ(0, pipeline_->GetTotalBytes()); |
335 | 333 |
336 // Should always get set to zero. | 334 // Should always get set to zero. |
337 gfx::Size size(1, 1); | 335 gfx::Size size(1, 1); |
338 pipeline_->GetNaturalVideoSize(&size); | 336 pipeline_->GetNaturalVideoSize(&size); |
339 EXPECT_EQ(0, size.width()); | 337 EXPECT_EQ(0, size.width()); |
340 EXPECT_EQ(0, size.height()); | 338 EXPECT_EQ(0, size.height()); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 EXPECT_TRUE(pipeline_->HasAudio()); | 576 EXPECT_TRUE(pipeline_->HasAudio()); |
579 EXPECT_TRUE(pipeline_->HasVideo()); | 577 EXPECT_TRUE(pipeline_->HasVideo()); |
580 | 578 |
581 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); | 579 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); |
582 pipeline_->OnAudioDisabled(); | 580 pipeline_->OnAudioDisabled(); |
583 | 581 |
584 // Verify that ended event is fired when video ends. | 582 // Verify that ended event is fired when video ends. |
585 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 583 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
586 .WillOnce(Return(true)); | 584 .WillOnce(Return(true)); |
587 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 585 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
588 FilterHost* host = pipeline_; | 586 pipeline_->OnRendererEnded(); |
589 host->NotifyEnded(); | |
590 } | 587 } |
591 | 588 |
592 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { | 589 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { |
593 CreateAudioStream(); | 590 CreateAudioStream(); |
594 CreateVideoStream(); | 591 CreateVideoStream(); |
595 MockDemuxerStreamVector streams; | 592 MockDemuxerStreamVector streams; |
596 streams.push_back(audio_stream()); | 593 streams.push_back(audio_stream()); |
597 streams.push_back(video_stream()); | 594 streams.push_back(video_stream()); |
598 | 595 |
599 InitializeDemuxer(&streams); | 596 InitializeDemuxer(&streams); |
600 InitializeAudioDecoder(audio_stream()); | 597 InitializeAudioDecoder(audio_stream()); |
601 InitializeAudioRenderer(true); | 598 InitializeAudioRenderer(true); |
602 InitializeVideoDecoder(video_stream()); | 599 InitializeVideoDecoder(video_stream()); |
603 InitializeVideoRenderer(); | 600 InitializeVideoRenderer(); |
604 | 601 |
605 EXPECT_CALL(*mocks_->demuxer(), | 602 EXPECT_CALL(*mocks_->demuxer(), |
606 OnAudioRendererDisabled()); | 603 OnAudioRendererDisabled()); |
607 | 604 |
608 InitializePipeline(PIPELINE_OK); | 605 InitializePipeline(PIPELINE_OK); |
609 EXPECT_TRUE(pipeline_->IsInitialized()); | 606 EXPECT_TRUE(pipeline_->IsInitialized()); |
610 EXPECT_FALSE(pipeline_->HasAudio()); | 607 EXPECT_FALSE(pipeline_->HasAudio()); |
611 EXPECT_TRUE(pipeline_->HasVideo()); | 608 EXPECT_TRUE(pipeline_->HasVideo()); |
612 | 609 |
613 // Verify that ended event is fired when video ends. | 610 // Verify that ended event is fired when video ends. |
614 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 611 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
615 .WillOnce(Return(true)); | 612 .WillOnce(Return(true)); |
616 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 613 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
617 FilterHost* host = pipeline_; | 614 pipeline_->OnRendererEnded(); |
618 host->NotifyEnded(); | |
619 } | 615 } |
620 | 616 |
621 TEST_F(PipelineTest, EndedCallback) { | 617 TEST_F(PipelineTest, EndedCallback) { |
622 CreateAudioStream(); | 618 CreateAudioStream(); |
623 CreateVideoStream(); | 619 CreateVideoStream(); |
624 MockDemuxerStreamVector streams; | 620 MockDemuxerStreamVector streams; |
625 streams.push_back(audio_stream()); | 621 streams.push_back(audio_stream()); |
626 streams.push_back(video_stream()); | 622 streams.push_back(video_stream()); |
627 | 623 |
628 InitializeDemuxer(&streams); | 624 InitializeDemuxer(&streams); |
629 InitializeAudioDecoder(audio_stream()); | 625 InitializeAudioDecoder(audio_stream()); |
630 InitializeAudioRenderer(); | 626 InitializeAudioRenderer(); |
631 InitializeVideoDecoder(video_stream()); | 627 InitializeVideoDecoder(video_stream()); |
632 InitializeVideoRenderer(); | 628 InitializeVideoRenderer(); |
633 InitializePipeline(PIPELINE_OK); | 629 InitializePipeline(PIPELINE_OK); |
634 | 630 |
635 // For convenience to simulate filters calling the methods. | |
636 FilterHost* host = pipeline_; | |
637 | |
638 // Due to short circuit evaluation we only need to test a subset of cases. | 631 // Due to short circuit evaluation we only need to test a subset of cases. |
639 InSequence s; | 632 InSequence s; |
640 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | 633 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
641 .WillOnce(Return(false)); | 634 .WillOnce(Return(false)); |
642 host->NotifyEnded(); | 635 pipeline_->OnRendererEnded(); |
643 | 636 |
644 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | 637 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
645 .WillOnce(Return(true)); | 638 .WillOnce(Return(true)); |
646 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 639 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
647 .WillOnce(Return(false)); | 640 .WillOnce(Return(false)); |
648 host->NotifyEnded(); | 641 pipeline_->OnRendererEnded(); |
649 | 642 |
650 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | 643 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
651 .WillOnce(Return(true)); | 644 .WillOnce(Return(true)); |
652 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 645 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
653 .WillOnce(Return(true)); | 646 .WillOnce(Return(true)); |
654 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 647 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
655 host->NotifyEnded(); | 648 pipeline_->OnRendererEnded(); |
656 } | 649 } |
657 | 650 |
658 // Static function & time variable used to simulate changes in wallclock time. | 651 // Static function & time variable used to simulate changes in wallclock time. |
659 static int64 g_static_clock_time; | 652 static int64 g_static_clock_time; |
660 static base::Time StaticClockFunction() { | 653 static base::Time StaticClockFunction() { |
661 return base::Time::FromInternalValue(g_static_clock_time); | 654 return base::Time::FromInternalValue(g_static_clock_time); |
662 } | 655 } |
663 | 656 |
664 TEST_F(PipelineTest, AudioStreamShorterThanVideo) { | 657 TEST_F(PipelineTest, AudioStreamShorterThanVideo) { |
665 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); | 658 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); |
666 | 659 |
667 CreateAudioStream(); | 660 CreateAudioStream(); |
668 CreateVideoStream(); | 661 CreateVideoStream(); |
669 MockDemuxerStreamVector streams; | 662 MockDemuxerStreamVector streams; |
670 streams.push_back(audio_stream()); | 663 streams.push_back(audio_stream()); |
671 streams.push_back(video_stream()); | 664 streams.push_back(video_stream()); |
672 | 665 |
673 // Replace the clock so we can simulate wallclock time advancing w/o using | 666 // Replace the clock so we can simulate wallclock time advancing w/o using |
674 // Sleep(). | 667 // Sleep(). |
675 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); | 668 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); |
676 | 669 |
677 InitializeDemuxer(&streams, duration); | 670 InitializeDemuxer(&streams, duration); |
678 InitializeAudioDecoder(audio_stream()); | 671 InitializeAudioDecoder(audio_stream()); |
679 InitializeAudioRenderer(); | 672 InitializeAudioRenderer(); |
680 InitializeVideoDecoder(video_stream()); | 673 InitializeVideoDecoder(video_stream()); |
681 InitializeVideoRenderer(); | 674 InitializeVideoRenderer(); |
682 InitializePipeline(PIPELINE_OK); | 675 InitializePipeline(PIPELINE_OK); |
683 | 676 |
684 // For convenience to simulate filters calling the methods. | 677 EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue()); |
685 FilterHost* host = pipeline_; | |
686 | |
687 EXPECT_EQ(0, host->GetTime().ToInternalValue()); | |
688 | 678 |
689 float playback_rate = 1.0f; | 679 float playback_rate = 1.0f; |
690 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 680 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
691 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(playback_rate)); | 681 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(playback_rate)); |
692 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 682 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
693 pipeline_->SetPlaybackRate(playback_rate); | 683 pipeline_->SetPlaybackRate(playback_rate); |
694 message_loop_.RunAllPending(); | 684 message_loop_.RunAllPending(); |
695 | 685 |
696 InSequence s; | 686 InSequence s; |
697 | 687 |
698 // Verify that the clock doesn't advance since it hasn't been started by | 688 // Verify that the clock doesn't advance since it hasn't been started by |
699 // a time update from the audio stream. | 689 // a time update from the audio stream. |
700 int64 start_time = host->GetTime().ToInternalValue(); | 690 int64 start_time = pipeline_->GetMediaTime().ToInternalValue(); |
701 g_static_clock_time += | 691 g_static_clock_time += |
702 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); | 692 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); |
703 EXPECT_EQ(host->GetTime().ToInternalValue(), start_time); | 693 EXPECT_EQ(pipeline_->GetMediaTime().ToInternalValue(), start_time); |
704 | 694 |
705 // Signal end of audio stream. | 695 // Signal end of audio stream. |
706 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | 696 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
707 .WillOnce(Return(true)); | 697 .WillOnce(Return(true)); |
708 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 698 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
709 .WillOnce(Return(false)); | 699 .WillOnce(Return(false)); |
710 host->NotifyEnded(); | 700 pipeline_->OnRendererEnded(); |
711 message_loop_.RunAllPending(); | 701 message_loop_.RunAllPending(); |
712 | 702 |
713 // Verify that the clock advances. | 703 // Verify that the clock advances. |
714 start_time = host->GetTime().ToInternalValue(); | 704 start_time = pipeline_->GetMediaTime().ToInternalValue(); |
715 g_static_clock_time += | 705 g_static_clock_time += |
716 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); | 706 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); |
717 EXPECT_GT(host->GetTime().ToInternalValue(), start_time); | 707 EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time); |
718 | 708 |
719 // Signal end of video stream and make sure OnEnded() callback occurs. | 709 // Signal end of video stream and make sure OnEnded() callback occurs. |
720 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | 710 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
721 .WillOnce(Return(true)); | 711 .WillOnce(Return(true)); |
722 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 712 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
723 .WillOnce(Return(true)); | 713 .WillOnce(Return(true)); |
724 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 714 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
725 host->NotifyEnded(); | 715 pipeline_->OnRendererEnded(); |
726 } | 716 } |
727 | 717 |
728 TEST_F(PipelineTest, ErrorDuringSeek) { | 718 TEST_F(PipelineTest, ErrorDuringSeek) { |
729 CreateAudioStream(); | 719 CreateAudioStream(); |
730 MockDemuxerStreamVector streams; | 720 MockDemuxerStreamVector streams; |
731 streams.push_back(audio_stream()); | 721 streams.push_back(audio_stream()); |
732 | 722 |
733 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); | 723 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); |
734 InitializeAudioDecoder(audio_stream()); | 724 InitializeAudioDecoder(audio_stream()); |
735 InitializeAudioRenderer(); | 725 InitializeAudioRenderer(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 816 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
827 InitializeDemuxer(&streams, kDuration); | 817 InitializeDemuxer(&streams, kDuration); |
828 InitializeVideoDecoder(video_stream()); | 818 InitializeVideoDecoder(video_stream()); |
829 InitializeVideoRenderer(); | 819 InitializeVideoRenderer(); |
830 | 820 |
831 InitializePipeline(PIPELINE_OK); | 821 InitializePipeline(PIPELINE_OK); |
832 EXPECT_TRUE(pipeline_->IsInitialized()); | 822 EXPECT_TRUE(pipeline_->IsInitialized()); |
833 EXPECT_FALSE(pipeline_->HasAudio()); | 823 EXPECT_FALSE(pipeline_->HasAudio()); |
834 EXPECT_TRUE(pipeline_->HasVideo()); | 824 EXPECT_TRUE(pipeline_->HasVideo()); |
835 | 825 |
836 EXPECT_EQ(base::TimeDelta(), pipeline_->GetCurrentTime()); | 826 EXPECT_EQ(base::TimeDelta(), pipeline_->GetMediaTime()); |
837 } | 827 } |
838 | 828 |
839 TEST_F(PipelineTest, StartTimeIsNonZero) { | 829 TEST_F(PipelineTest, StartTimeIsNonZero) { |
840 const base::TimeDelta kStartTime = base::TimeDelta::FromSeconds(4); | 830 const base::TimeDelta kStartTime = base::TimeDelta::FromSeconds(4); |
841 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 831 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
842 | 832 |
843 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) | 833 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) |
844 .WillRepeatedly(Return(kStartTime)); | 834 .WillRepeatedly(Return(kStartTime)); |
845 | 835 |
846 CreateVideoStream(); | 836 CreateVideoStream(); |
847 MockDemuxerStreamVector streams; | 837 MockDemuxerStreamVector streams; |
848 streams.push_back(video_stream()); | 838 streams.push_back(video_stream()); |
849 | 839 |
850 InitializeDemuxer(&streams, kDuration); | 840 InitializeDemuxer(&streams, kDuration); |
851 InitializeVideoDecoder(video_stream()); | 841 InitializeVideoDecoder(video_stream()); |
852 InitializeVideoRenderer(); | 842 InitializeVideoRenderer(); |
853 | 843 |
854 InitializePipeline(PIPELINE_OK); | 844 InitializePipeline(PIPELINE_OK); |
855 EXPECT_TRUE(pipeline_->IsInitialized()); | 845 EXPECT_TRUE(pipeline_->IsInitialized()); |
856 EXPECT_FALSE(pipeline_->HasAudio()); | 846 EXPECT_FALSE(pipeline_->HasAudio()); |
857 EXPECT_TRUE(pipeline_->HasVideo()); | 847 EXPECT_TRUE(pipeline_->HasVideo()); |
858 | 848 |
859 EXPECT_EQ(kStartTime, pipeline_->GetCurrentTime()); | 849 EXPECT_EQ(kStartTime, pipeline_->GetMediaTime()); |
860 } | 850 } |
861 | 851 |
862 static void RunTimeCB(const AudioRenderer::TimeCB& time_cb, | 852 static void RunTimeCB(const AudioRenderer::TimeCB& time_cb, |
863 int time_in_ms, | 853 int time_in_ms, |
864 int max_time_in_ms) { | 854 int max_time_in_ms) { |
865 time_cb.Run(base::TimeDelta::FromMilliseconds(time_in_ms), | 855 time_cb.Run(base::TimeDelta::FromMilliseconds(time_in_ms), |
866 base::TimeDelta::FromMilliseconds(max_time_in_ms)); | 856 base::TimeDelta::FromMilliseconds(max_time_in_ms)); |
867 } | 857 } |
868 | 858 |
869 TEST_F(PipelineTest, AudioTimeUpdateDuringSeek) { | 859 TEST_F(PipelineTest, AudioTimeUpdateDuringSeek) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 892 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
903 .WillOnce(RunClosure()); | 893 .WillOnce(RunClosure()); |
904 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _)) | 894 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _)) |
905 .WillOnce(RunPipelineStatusCB1()); | 895 .WillOnce(RunPipelineStatusCB1()); |
906 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 896 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
907 .WillOnce(RunClosure()); | 897 .WillOnce(RunClosure()); |
908 | 898 |
909 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | 899 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
910 DoSeek(seek_time); | 900 DoSeek(seek_time); |
911 | 901 |
912 EXPECT_EQ(pipeline_->GetCurrentTime(), seek_time); | 902 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time); |
913 | 903 |
914 // Now that the seek is complete, verify that time updates advance the current | 904 // Now that the seek is complete, verify that time updates advance the current |
915 // time. | 905 // time. |
916 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100); | 906 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100); |
917 audio_time_cb_.Run(new_time, new_time); | 907 audio_time_cb_.Run(new_time, new_time); |
918 | 908 |
919 EXPECT_EQ(pipeline_->GetCurrentTime(), new_time); | 909 EXPECT_EQ(pipeline_->GetMediaTime(), new_time); |
920 } | 910 } |
921 | 911 |
922 class FlexibleCallbackRunner : public base::DelegateSimpleThread::Delegate { | 912 class FlexibleCallbackRunner : public base::DelegateSimpleThread::Delegate { |
923 public: | 913 public: |
924 FlexibleCallbackRunner(base::TimeDelta delay, PipelineStatus status, | 914 FlexibleCallbackRunner(base::TimeDelta delay, PipelineStatus status, |
925 const PipelineStatusCB& status_cb) | 915 const PipelineStatusCB& status_cb) |
926 : delay_(delay), | 916 : delay_(delay), |
927 status_(status), | 917 status_(status), |
928 status_cb_(status_cb) { | 918 status_cb_(status_cb) { |
929 if (delay_ < base::TimeDelta()) { | 919 if (delay_ < base::TimeDelta()) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); | 956 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); |
967 } | 957 } |
968 | 958 |
969 // Test that different-thread, some-delay callback (the expected common case) | 959 // Test that different-thread, some-delay callback (the expected common case) |
970 // works correctly. | 960 // works correctly. |
971 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 961 TEST(PipelineStatusNotificationTest, DelayedCallback) { |
972 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); | 962 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); |
973 } | 963 } |
974 | 964 |
975 } // namespace media | 965 } // namespace media |
OLD | NEW |