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

Side by Side Diff: media/base/pipeline_unittest.cc

Issue 10796074: Move VideoRenderer out of Filter heirarchy. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <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
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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_->GetCurrentTime().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_->GetCurrentTime().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_->GetCurrentTime().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_->GetCurrentTime().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_->GetCurrentTime().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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698