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

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

Issue 10834236: Replace Pipeline::kEnded state and HasEnded() methods with renderer-specific bools. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « media/base/pipeline.cc ('k') | media/base/video_renderer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 568
569 InitializePipeline(PIPELINE_OK); 569 InitializePipeline(PIPELINE_OK);
570 EXPECT_TRUE(pipeline_->IsInitialized()); 570 EXPECT_TRUE(pipeline_->IsInitialized());
571 EXPECT_TRUE(pipeline_->HasAudio()); 571 EXPECT_TRUE(pipeline_->HasAudio());
572 EXPECT_TRUE(pipeline_->HasVideo()); 572 EXPECT_TRUE(pipeline_->HasVideo());
573 573
574 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); 574 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled());
575 pipeline_->OnAudioDisabled(); 575 pipeline_->OnAudioDisabled();
576 576
577 // Verify that ended event is fired when video ends. 577 // Verify that ended event is fired when video ends.
578 EXPECT_CALL(*mocks_->video_renderer(), HasEnded())
579 .WillOnce(Return(true));
580 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); 578 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK));
581 pipeline_->OnRendererEnded(); 579 pipeline_->OnVideoRendererEnded();
582 } 580 }
583 581
584 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { 582 TEST_F(PipelineTest, DisableAudioRendererDuringInit) {
585 CreateAudioStream(); 583 CreateAudioStream();
586 CreateVideoStream(); 584 CreateVideoStream();
587 MockDemuxerStreamVector streams; 585 MockDemuxerStreamVector streams;
588 streams.push_back(audio_stream()); 586 streams.push_back(audio_stream());
589 streams.push_back(video_stream()); 587 streams.push_back(video_stream());
590 588
591 InitializeDemuxer(&streams); 589 InitializeDemuxer(&streams);
592 InitializeAudioDecoder(audio_stream()); 590 InitializeAudioDecoder(audio_stream());
593 InitializeAudioRenderer(true); 591 InitializeAudioRenderer(true);
594 InitializeVideoDecoder(video_stream()); 592 InitializeVideoDecoder(video_stream());
595 InitializeVideoRenderer(); 593 InitializeVideoRenderer();
596 594
597 EXPECT_CALL(*mocks_->demuxer(), 595 EXPECT_CALL(*mocks_->demuxer(),
598 OnAudioRendererDisabled()); 596 OnAudioRendererDisabled());
599 597
600 InitializePipeline(PIPELINE_OK); 598 InitializePipeline(PIPELINE_OK);
601 EXPECT_TRUE(pipeline_->IsInitialized()); 599 EXPECT_TRUE(pipeline_->IsInitialized());
602 EXPECT_FALSE(pipeline_->HasAudio()); 600 EXPECT_FALSE(pipeline_->HasAudio());
603 EXPECT_TRUE(pipeline_->HasVideo()); 601 EXPECT_TRUE(pipeline_->HasVideo());
604 602
605 // Verify that ended event is fired when video ends. 603 // Verify that ended event is fired when video ends.
606 EXPECT_CALL(*mocks_->video_renderer(), HasEnded())
607 .WillOnce(Return(true));
608 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); 604 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK));
609 pipeline_->OnRendererEnded(); 605 pipeline_->OnVideoRendererEnded();
610 } 606 }
611 607
612 TEST_F(PipelineTest, EndedCallback) { 608 TEST_F(PipelineTest, EndedCallback) {
613 CreateAudioStream(); 609 CreateAudioStream();
614 CreateVideoStream(); 610 CreateVideoStream();
615 MockDemuxerStreamVector streams; 611 MockDemuxerStreamVector streams;
616 streams.push_back(audio_stream()); 612 streams.push_back(audio_stream());
617 streams.push_back(video_stream()); 613 streams.push_back(video_stream());
618 614
619 InitializeDemuxer(&streams); 615 InitializeDemuxer(&streams);
620 InitializeAudioDecoder(audio_stream()); 616 InitializeAudioDecoder(audio_stream());
621 InitializeAudioRenderer(); 617 InitializeAudioRenderer();
622 InitializeVideoDecoder(video_stream()); 618 InitializeVideoDecoder(video_stream());
623 InitializeVideoRenderer(); 619 InitializeVideoRenderer();
624 InitializePipeline(PIPELINE_OK); 620 InitializePipeline(PIPELINE_OK);
625 621
626 // Due to short circuit evaluation we only need to test a subset of cases. 622 // The ended callback shouldn't run until both renderers have ended.
627 InSequence s; 623 pipeline_->OnAudioRendererEnded();
628 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) 624 message_loop_.RunAllPending();
629 .WillOnce(Return(false));
630 pipeline_->OnRendererEnded();
631 625
632 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded())
633 .WillOnce(Return(true));
634 EXPECT_CALL(*mocks_->video_renderer(), HasEnded())
635 .WillOnce(Return(false));
636 pipeline_->OnRendererEnded();
637
638 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded())
639 .WillOnce(Return(true));
640 EXPECT_CALL(*mocks_->video_renderer(), HasEnded())
641 .WillOnce(Return(true));
642 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); 626 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK));
643 pipeline_->OnRendererEnded(); 627 pipeline_->OnVideoRendererEnded();
628 message_loop_.RunAllPending();
644 } 629 }
645 630
646 // Static function & time variable used to simulate changes in wallclock time. 631 // Static function & time variable used to simulate changes in wallclock time.
647 static int64 g_static_clock_time; 632 static int64 g_static_clock_time;
648 static base::Time StaticClockFunction() { 633 static base::Time StaticClockFunction() {
649 return base::Time::FromInternalValue(g_static_clock_time); 634 return base::Time::FromInternalValue(g_static_clock_time);
650 } 635 }
651 636
652 TEST_F(PipelineTest, AudioStreamShorterThanVideo) { 637 TEST_F(PipelineTest, AudioStreamShorterThanVideo) {
653 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); 638 base::TimeDelta duration = base::TimeDelta::FromSeconds(10);
(...skipping 27 matching lines...) Expand all
681 InSequence s; 666 InSequence s;
682 667
683 // Verify that the clock doesn't advance since it hasn't been started by 668 // Verify that the clock doesn't advance since it hasn't been started by
684 // a time update from the audio stream. 669 // a time update from the audio stream.
685 int64 start_time = pipeline_->GetMediaTime().ToInternalValue(); 670 int64 start_time = pipeline_->GetMediaTime().ToInternalValue();
686 g_static_clock_time += 671 g_static_clock_time +=
687 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); 672 base::TimeDelta::FromMilliseconds(100).ToInternalValue();
688 EXPECT_EQ(pipeline_->GetMediaTime().ToInternalValue(), start_time); 673 EXPECT_EQ(pipeline_->GetMediaTime().ToInternalValue(), start_time);
689 674
690 // Signal end of audio stream. 675 // Signal end of audio stream.
691 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) 676 pipeline_->OnAudioRendererEnded();
692 .WillOnce(Return(true));
693 EXPECT_CALL(*mocks_->video_renderer(), HasEnded())
694 .WillOnce(Return(false));
695 pipeline_->OnRendererEnded();
696 message_loop_.RunAllPending(); 677 message_loop_.RunAllPending();
697 678
698 // Verify that the clock advances. 679 // Verify that the clock advances.
699 start_time = pipeline_->GetMediaTime().ToInternalValue(); 680 start_time = pipeline_->GetMediaTime().ToInternalValue();
700 g_static_clock_time += 681 g_static_clock_time +=
701 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); 682 base::TimeDelta::FromMilliseconds(100).ToInternalValue();
702 EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time); 683 EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time);
703 684
704 // Signal end of video stream and make sure OnEnded() callback occurs. 685 // Signal end of video stream and make sure OnEnded() callback occurs.
705 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded())
706 .WillOnce(Return(true));
707 EXPECT_CALL(*mocks_->video_renderer(), HasEnded())
708 .WillOnce(Return(true));
709 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); 686 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK));
710 pipeline_->OnRendererEnded(); 687 pipeline_->OnVideoRendererEnded();
711 } 688 }
712 689
713 TEST_F(PipelineTest, ErrorDuringSeek) { 690 TEST_F(PipelineTest, ErrorDuringSeek) {
714 CreateAudioStream(); 691 CreateAudioStream();
715 MockDemuxerStreamVector streams; 692 MockDemuxerStreamVector streams;
716 streams.push_back(audio_stream()); 693 streams.push_back(audio_stream());
717 694
718 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); 695 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10));
719 InitializeAudioDecoder(audio_stream()); 696 InitializeAudioDecoder(audio_stream());
720 InitializeAudioRenderer(); 697 InitializeAudioRenderer();
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); 928 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0));
952 } 929 }
953 930
954 // Test that different-thread, some-delay callback (the expected common case) 931 // Test that different-thread, some-delay callback (the expected common case)
955 // works correctly. 932 // works correctly.
956 TEST(PipelineStatusNotificationTest, DelayedCallback) { 933 TEST(PipelineStatusNotificationTest, DelayedCallback) {
957 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); 934 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20));
958 } 935 }
959 936
960 } // namespace media 937 } // namespace media
OLDNEW
« no previous file with comments | « media/base/pipeline.cc ('k') | media/base/video_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698