Chromium Code Reviews| 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" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 message_loop_.RunAllPending(); | 124 message_loop_.RunAllPending(); |
| 125 | 125 |
| 126 pipeline_ = NULL; | 126 pipeline_ = NULL; |
| 127 mocks_.reset(); | 127 mocks_.reset(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 protected: | 130 protected: |
| 131 // Sets up expectations to allow the demuxer to initialize. | 131 // Sets up expectations to allow the demuxer to initialize. |
| 132 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 132 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
| 133 void InitializeDemuxer(MockDemuxerStreamVector* streams, | 133 void InitializeDemuxer(MockDemuxerStreamVector* streams, |
| 134 const base::TimeDelta& duration) { | 134 const base::TimeDelta& duration, |
| 135 bool expect_set_playback_rate) { | |
| 135 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | 136 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) |
| 136 .WillOnce(DoAll(SetDemuxerProperties(duration), | 137 .WillOnce(DoAll(SetDemuxerProperties(duration), |
| 137 RunPipelineStatusCB1())); | 138 RunPipelineStatusCB1())); |
| 138 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 139 if (expect_set_playback_rate) |
|
scherkus (not reviewing)
2012/08/08 21:15:02
instead of a bool, can this block can get moves to
acolwell GONE FROM CHROMIUM
2012/08/08 21:40:59
Yes it can. Done.
| |
| 140 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | |
| 139 | 141 |
| 140 // Configure the demuxer to return the streams. | 142 // Configure the demuxer to return the streams. |
| 141 for (size_t i = 0; i < streams->size(); ++i) { | 143 for (size_t i = 0; i < streams->size(); ++i) { |
| 142 scoped_refptr<DemuxerStream> stream((*streams)[i]); | 144 scoped_refptr<DemuxerStream> stream((*streams)[i]); |
| 143 EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) | 145 EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) |
| 144 .WillRepeatedly(Return(stream)); | 146 .WillRepeatedly(Return(stream)); |
| 145 } | 147 } |
| 146 } | 148 } |
| 147 | 149 |
| 148 void InitializeDemuxer(MockDemuxerStreamVector* streams) { | 150 void InitializeDemuxer(MockDemuxerStreamVector* streams) { |
| 149 // Initialize with a default non-zero duration. | 151 // Initialize with a default non-zero duration. |
| 150 InitializeDemuxer(streams, base::TimeDelta::FromSeconds(10)); | 152 InitializeDemuxer(streams, base::TimeDelta::FromSeconds(10), true); |
| 153 } | |
| 154 | |
| 155 void InitializeDemuxer(MockDemuxerStreamVector* streams, | |
| 156 bool expect_set_playback_rate) { | |
| 157 // Initialize with a default non-zero duration. | |
| 158 InitializeDemuxer(streams, base::TimeDelta::FromSeconds(10), | |
| 159 expect_set_playback_rate); | |
| 151 } | 160 } |
| 152 | 161 |
| 153 StrictMock<MockDemuxerStream>* CreateStream(DemuxerStream::Type type) { | 162 StrictMock<MockDemuxerStream>* CreateStream(DemuxerStream::Type type) { |
| 154 StrictMock<MockDemuxerStream>* stream = | 163 StrictMock<MockDemuxerStream>* stream = |
| 155 new StrictMock<MockDemuxerStream>(); | 164 new StrictMock<MockDemuxerStream>(); |
| 156 EXPECT_CALL(*stream, type()) | 165 EXPECT_CALL(*stream, type()) |
| 157 .WillRepeatedly(Return(type)); | 166 .WillRepeatedly(Return(type)); |
| 158 return stream; | 167 return stream; |
| 159 } | 168 } |
| 160 | 169 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 181 | 190 |
| 182 // Startup sequence. | 191 // Startup sequence. |
| 183 EXPECT_CALL(*mocks_->video_renderer(), | 192 EXPECT_CALL(*mocks_->video_renderer(), |
| 184 Preroll(mocks_->demuxer()->GetStartTime(), _)) | 193 Preroll(mocks_->demuxer()->GetStartTime(), _)) |
| 185 .WillOnce(RunPipelineStatusCB1()); | 194 .WillOnce(RunPipelineStatusCB1()); |
| 186 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) | 195 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) |
| 187 .WillOnce(RunClosure()); | 196 .WillOnce(RunClosure()); |
| 188 } | 197 } |
| 189 | 198 |
| 190 // Sets up expectations to allow the audio renderer to initialize. | 199 // Sets up expectations to allow the audio renderer to initialize. |
| 191 void InitializeAudioRenderer(bool disable_after_init_cb = false) { | 200 void InitializeAudioRenderer() { |
| 201 InitializeAudioRenderer(false, true); | |
| 202 } | |
| 203 | |
| 204 void InitializeAudioRenderer(bool disable_after_init_cb, | |
| 205 bool expect_to_play) { | |
| 192 if (disable_after_init_cb) { | 206 if (disable_after_init_cb) { |
| 193 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( | 207 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( |
| 194 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), | 208 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), |
| 195 _, _, _, _, _, _)) | 209 _, _, _, _, _, _)) |
| 196 .WillOnce(DoAll(RunPipelineStatusCB1(), | 210 .WillOnce(DoAll(RunPipelineStatusCB1(), |
| 197 WithArg<5>(RunClosure()))); // |disabled_cb|. | 211 WithArg<5>(RunClosure()))); // |disabled_cb|. |
| 198 } else { | 212 } else { |
| 199 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( | 213 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( |
| 200 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), | 214 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), |
| 201 _, _, _, _, _, _)) | 215 _, _, _, _, _, _)) |
| 202 .WillOnce(DoAll(SaveArg<3>(&audio_time_cb_), | 216 .WillOnce(DoAll(SaveArg<3>(&audio_time_cb_), |
| 203 RunPipelineStatusCB1())); | 217 RunPipelineStatusCB1())); |
| 204 } | 218 } |
| 205 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); | |
| 206 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); | |
| 207 | 219 |
| 208 // Startup sequence. | 220 if (expect_to_play) { |
| 209 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) | 221 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); |
|
scherkus (not reviewing)
2012/08/08 21:15:02
ditto (move to InitializePipeline when start_statu
acolwell GONE FROM CHROMIUM
2012/08/08 21:40:59
Done.
| |
| 210 .WillOnce(RunPipelineStatusCB1()); | 222 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); |
| 211 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 223 |
| 212 .WillOnce(RunClosure()); | 224 // Startup sequence. |
| 225 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) | |
| 226 .WillOnce(RunPipelineStatusCB1()); | |
| 227 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | |
| 228 .WillOnce(RunClosure()); | |
| 229 } | |
| 213 } | 230 } |
| 214 | 231 |
| 215 // Sets up expectations on the callback and initializes the pipeline. Called | 232 // Sets up expectations on the callback and initializes the pipeline. Called |
| 216 // after tests have set expectations any filters they wish to use. | 233 // after tests have set expectations any filters they wish to use. |
| 217 void InitializePipeline(PipelineStatus start_status) { | 234 void InitializePipeline(PipelineStatus start_status) { |
| 218 EXPECT_CALL(callbacks_, OnStart(start_status)); | 235 EXPECT_CALL(callbacks_, OnStart(start_status)); |
| 219 | 236 |
| 220 pipeline_->Start( | 237 pipeline_->Start( |
| 221 mocks_->Create().Pass(), | 238 mocks_->Create().Pass(), |
| 222 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 239 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 EXPECT_TRUE(pipeline_->HasVideo()); | 459 EXPECT_TRUE(pipeline_->HasVideo()); |
| 443 } | 460 } |
| 444 | 461 |
| 445 TEST_F(PipelineTest, Seek) { | 462 TEST_F(PipelineTest, Seek) { |
| 446 CreateAudioStream(); | 463 CreateAudioStream(); |
| 447 CreateVideoStream(); | 464 CreateVideoStream(); |
| 448 MockDemuxerStreamVector streams; | 465 MockDemuxerStreamVector streams; |
| 449 streams.push_back(audio_stream()); | 466 streams.push_back(audio_stream()); |
| 450 streams.push_back(video_stream()); | 467 streams.push_back(video_stream()); |
| 451 | 468 |
| 452 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); | 469 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000), true); |
| 453 InitializeAudioDecoder(audio_stream()); | 470 InitializeAudioDecoder(audio_stream()); |
| 454 InitializeAudioRenderer(); | 471 InitializeAudioRenderer(); |
| 455 InitializeVideoDecoder(video_stream()); | 472 InitializeVideoDecoder(video_stream()); |
| 456 InitializeVideoRenderer(); | 473 InitializeVideoRenderer(); |
| 457 | 474 |
| 458 // Initialize then seek! | 475 // Initialize then seek! |
| 459 InitializePipeline(PIPELINE_OK); | 476 InitializePipeline(PIPELINE_OK); |
| 460 | 477 |
| 461 // Every filter should receive a call to Seek(). | 478 // Every filter should receive a call to Seek(). |
| 462 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); | 479 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 481 InitializePipeline(PIPELINE_OK); | 498 InitializePipeline(PIPELINE_OK); |
| 482 pipeline_->SetVolume(expected); | 499 pipeline_->SetVolume(expected); |
| 483 } | 500 } |
| 484 | 501 |
| 485 TEST_F(PipelineTest, Properties) { | 502 TEST_F(PipelineTest, Properties) { |
| 486 CreateVideoStream(); | 503 CreateVideoStream(); |
| 487 MockDemuxerStreamVector streams; | 504 MockDemuxerStreamVector streams; |
| 488 streams.push_back(video_stream()); | 505 streams.push_back(video_stream()); |
| 489 | 506 |
| 490 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 507 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 491 InitializeDemuxer(&streams, kDuration); | 508 InitializeDemuxer(&streams, kDuration, true); |
| 492 InitializeVideoDecoder(video_stream()); | 509 InitializeVideoDecoder(video_stream()); |
| 493 InitializeVideoRenderer(); | 510 InitializeVideoRenderer(); |
| 494 | 511 |
| 495 InitializePipeline(PIPELINE_OK); | 512 InitializePipeline(PIPELINE_OK); |
| 496 EXPECT_TRUE(pipeline_->IsInitialized()); | 513 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 497 EXPECT_EQ(kDuration.ToInternalValue(), | 514 EXPECT_EQ(kDuration.ToInternalValue(), |
| 498 pipeline_->GetMediaDuration().ToInternalValue()); | 515 pipeline_->GetMediaDuration().ToInternalValue()); |
| 499 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); | 516 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); |
| 500 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 517 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 501 } | 518 } |
| 502 | 519 |
| 503 TEST_F(PipelineTest, GetBufferedTimeRanges) { | 520 TEST_F(PipelineTest, GetBufferedTimeRanges) { |
| 504 CreateVideoStream(); | 521 CreateVideoStream(); |
| 505 MockDemuxerStreamVector streams; | 522 MockDemuxerStreamVector streams; |
| 506 streams.push_back(video_stream()); | 523 streams.push_back(video_stream()); |
| 507 | 524 |
| 508 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 525 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 509 InitializeDemuxer(&streams, kDuration); | 526 InitializeDemuxer(&streams, kDuration, true); |
| 510 InitializeVideoDecoder(video_stream()); | 527 InitializeVideoDecoder(video_stream()); |
| 511 InitializeVideoRenderer(); | 528 InitializeVideoRenderer(); |
| 512 | 529 |
| 513 InitializePipeline(PIPELINE_OK); | 530 InitializePipeline(PIPELINE_OK); |
| 514 EXPECT_TRUE(pipeline_->IsInitialized()); | 531 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 515 | 532 |
| 516 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); | 533 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); |
| 517 | 534 |
| 518 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 535 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 519 pipeline_->AddBufferedByteRange(0, kTotalBytes / 8); | 536 pipeline_->AddBufferedByteRange(0, kTotalBytes / 8); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 | 600 |
| 584 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { | 601 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { |
| 585 CreateAudioStream(); | 602 CreateAudioStream(); |
| 586 CreateVideoStream(); | 603 CreateVideoStream(); |
| 587 MockDemuxerStreamVector streams; | 604 MockDemuxerStreamVector streams; |
| 588 streams.push_back(audio_stream()); | 605 streams.push_back(audio_stream()); |
| 589 streams.push_back(video_stream()); | 606 streams.push_back(video_stream()); |
| 590 | 607 |
| 591 InitializeDemuxer(&streams); | 608 InitializeDemuxer(&streams); |
| 592 InitializeAudioDecoder(audio_stream()); | 609 InitializeAudioDecoder(audio_stream()); |
| 593 InitializeAudioRenderer(true); | 610 InitializeAudioRenderer(true, true); |
| 594 InitializeVideoDecoder(video_stream()); | 611 InitializeVideoDecoder(video_stream()); |
| 595 InitializeVideoRenderer(); | 612 InitializeVideoRenderer(); |
| 596 | 613 |
| 597 EXPECT_CALL(*mocks_->demuxer(), | 614 EXPECT_CALL(*mocks_->demuxer(), |
| 598 OnAudioRendererDisabled()); | 615 OnAudioRendererDisabled()); |
| 599 | 616 |
| 600 InitializePipeline(PIPELINE_OK); | 617 InitializePipeline(PIPELINE_OK); |
| 601 EXPECT_TRUE(pipeline_->IsInitialized()); | 618 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 602 EXPECT_FALSE(pipeline_->HasAudio()); | 619 EXPECT_FALSE(pipeline_->HasAudio()); |
| 603 EXPECT_TRUE(pipeline_->HasVideo()); | 620 EXPECT_TRUE(pipeline_->HasVideo()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 CreateAudioStream(); | 672 CreateAudioStream(); |
| 656 CreateVideoStream(); | 673 CreateVideoStream(); |
| 657 MockDemuxerStreamVector streams; | 674 MockDemuxerStreamVector streams; |
| 658 streams.push_back(audio_stream()); | 675 streams.push_back(audio_stream()); |
| 659 streams.push_back(video_stream()); | 676 streams.push_back(video_stream()); |
| 660 | 677 |
| 661 // Replace the clock so we can simulate wallclock time advancing w/o using | 678 // Replace the clock so we can simulate wallclock time advancing w/o using |
| 662 // Sleep(). | 679 // Sleep(). |
| 663 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); | 680 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); |
| 664 | 681 |
| 665 InitializeDemuxer(&streams, duration); | 682 InitializeDemuxer(&streams, duration, true); |
| 666 InitializeAudioDecoder(audio_stream()); | 683 InitializeAudioDecoder(audio_stream()); |
| 667 InitializeAudioRenderer(); | 684 InitializeAudioRenderer(); |
| 668 InitializeVideoDecoder(video_stream()); | 685 InitializeVideoDecoder(video_stream()); |
| 669 InitializeVideoRenderer(); | 686 InitializeVideoRenderer(); |
| 670 InitializePipeline(PIPELINE_OK); | 687 InitializePipeline(PIPELINE_OK); |
| 671 | 688 |
| 672 EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue()); | 689 EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue()); |
| 673 | 690 |
| 674 float playback_rate = 1.0f; | 691 float playback_rate = 1.0f; |
| 675 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 692 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 .WillOnce(Return(true)); | 725 .WillOnce(Return(true)); |
| 709 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 726 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 710 pipeline_->OnRendererEnded(); | 727 pipeline_->OnRendererEnded(); |
| 711 } | 728 } |
| 712 | 729 |
| 713 TEST_F(PipelineTest, ErrorDuringSeek) { | 730 TEST_F(PipelineTest, ErrorDuringSeek) { |
| 714 CreateAudioStream(); | 731 CreateAudioStream(); |
| 715 MockDemuxerStreamVector streams; | 732 MockDemuxerStreamVector streams; |
| 716 streams.push_back(audio_stream()); | 733 streams.push_back(audio_stream()); |
| 717 | 734 |
| 718 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); | 735 InitializeDemuxer(&streams); |
| 719 InitializeAudioDecoder(audio_stream()); | 736 InitializeAudioDecoder(audio_stream()); |
| 720 InitializeAudioRenderer(); | 737 InitializeAudioRenderer(); |
| 721 InitializePipeline(PIPELINE_OK); | 738 InitializePipeline(PIPELINE_OK); |
| 722 | 739 |
| 723 float playback_rate = 1.0f; | 740 float playback_rate = 1.0f; |
| 724 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 741 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
| 725 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 742 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
| 726 pipeline_->SetPlaybackRate(playback_rate); | 743 pipeline_->SetPlaybackRate(playback_rate); |
| 727 message_loop_.RunAllPending(); | 744 message_loop_.RunAllPending(); |
| 728 | 745 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 | 781 |
| 765 // No additional tasks should be queued as a result of these calls. | 782 // No additional tasks should be queued as a result of these calls. |
| 766 message_loop->AssertIdle(); | 783 message_loop->AssertIdle(); |
| 767 } | 784 } |
| 768 | 785 |
| 769 TEST_F(PipelineTest, NoMessageDuringTearDownFromError) { | 786 TEST_F(PipelineTest, NoMessageDuringTearDownFromError) { |
| 770 CreateAudioStream(); | 787 CreateAudioStream(); |
| 771 MockDemuxerStreamVector streams; | 788 MockDemuxerStreamVector streams; |
| 772 streams.push_back(audio_stream()); | 789 streams.push_back(audio_stream()); |
| 773 | 790 |
| 774 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); | 791 InitializeDemuxer(&streams); |
| 775 InitializeAudioDecoder(audio_stream()); | 792 InitializeAudioDecoder(audio_stream()); |
| 776 InitializeAudioRenderer(); | 793 InitializeAudioRenderer(); |
| 777 InitializePipeline(PIPELINE_OK); | 794 InitializePipeline(PIPELINE_OK); |
| 778 | 795 |
| 779 // Trigger additional requests on the pipeline during tear down from error. | 796 // Trigger additional requests on the pipeline during tear down from error. |
| 780 base::Callback<void(PipelineStatus)> cb = base::Bind( | 797 base::Callback<void(PipelineStatus)> cb = base::Bind( |
| 781 &TestNoCallsAfterError, pipeline_, &message_loop_); | 798 &TestNoCallsAfterError, pipeline_, &message_loop_); |
| 782 ON_CALL(callbacks_, OnError(_)) | 799 ON_CALL(callbacks_, OnError(_)) |
| 783 .WillByDefault(Invoke(&cb, &base::Callback<void(PipelineStatus)>::Run)); | 800 .WillByDefault(Invoke(&cb, &base::Callback<void(PipelineStatus)>::Run)); |
| 784 | 801 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 802 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); | 819 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); |
| 803 message_loop_.RunAllPending(); | 820 message_loop_.RunAllPending(); |
| 804 } | 821 } |
| 805 | 822 |
| 806 TEST_F(PipelineTest, StartTimeIsZero) { | 823 TEST_F(PipelineTest, StartTimeIsZero) { |
| 807 CreateVideoStream(); | 824 CreateVideoStream(); |
| 808 MockDemuxerStreamVector streams; | 825 MockDemuxerStreamVector streams; |
| 809 streams.push_back(video_stream()); | 826 streams.push_back(video_stream()); |
| 810 | 827 |
| 811 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 828 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 812 InitializeDemuxer(&streams, kDuration); | 829 InitializeDemuxer(&streams, kDuration, true); |
| 813 InitializeVideoDecoder(video_stream()); | 830 InitializeVideoDecoder(video_stream()); |
| 814 InitializeVideoRenderer(); | 831 InitializeVideoRenderer(); |
| 815 | 832 |
| 816 InitializePipeline(PIPELINE_OK); | 833 InitializePipeline(PIPELINE_OK); |
| 817 EXPECT_TRUE(pipeline_->IsInitialized()); | 834 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 818 EXPECT_FALSE(pipeline_->HasAudio()); | 835 EXPECT_FALSE(pipeline_->HasAudio()); |
| 819 EXPECT_TRUE(pipeline_->HasVideo()); | 836 EXPECT_TRUE(pipeline_->HasVideo()); |
| 820 | 837 |
| 821 EXPECT_EQ(base::TimeDelta(), pipeline_->GetMediaTime()); | 838 EXPECT_EQ(base::TimeDelta(), pipeline_->GetMediaTime()); |
| 822 } | 839 } |
| 823 | 840 |
| 824 TEST_F(PipelineTest, StartTimeIsNonZero) { | 841 TEST_F(PipelineTest, StartTimeIsNonZero) { |
| 825 const base::TimeDelta kStartTime = base::TimeDelta::FromSeconds(4); | 842 const base::TimeDelta kStartTime = base::TimeDelta::FromSeconds(4); |
| 826 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 843 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 827 | 844 |
| 828 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) | 845 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) |
| 829 .WillRepeatedly(Return(kStartTime)); | 846 .WillRepeatedly(Return(kStartTime)); |
| 830 | 847 |
| 831 CreateVideoStream(); | 848 CreateVideoStream(); |
| 832 MockDemuxerStreamVector streams; | 849 MockDemuxerStreamVector streams; |
| 833 streams.push_back(video_stream()); | 850 streams.push_back(video_stream()); |
| 834 | 851 |
| 835 InitializeDemuxer(&streams, kDuration); | 852 InitializeDemuxer(&streams, kDuration, true); |
| 836 InitializeVideoDecoder(video_stream()); | 853 InitializeVideoDecoder(video_stream()); |
| 837 InitializeVideoRenderer(); | 854 InitializeVideoRenderer(); |
| 838 | 855 |
| 839 InitializePipeline(PIPELINE_OK); | 856 InitializePipeline(PIPELINE_OK); |
| 840 EXPECT_TRUE(pipeline_->IsInitialized()); | 857 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 841 EXPECT_FALSE(pipeline_->HasAudio()); | 858 EXPECT_FALSE(pipeline_->HasAudio()); |
| 842 EXPECT_TRUE(pipeline_->HasVideo()); | 859 EXPECT_TRUE(pipeline_->HasVideo()); |
| 843 | 860 |
| 844 EXPECT_EQ(kStartTime, pipeline_->GetMediaTime()); | 861 EXPECT_EQ(kStartTime, pipeline_->GetMediaTime()); |
| 845 } | 862 } |
| 846 | 863 |
| 847 static void RunTimeCB(const AudioRenderer::TimeCB& time_cb, | 864 static void RunTimeCB(const AudioRenderer::TimeCB& time_cb, |
| 848 int time_in_ms, | 865 int time_in_ms, |
| 849 int max_time_in_ms) { | 866 int max_time_in_ms) { |
| 850 time_cb.Run(base::TimeDelta::FromMilliseconds(time_in_ms), | 867 time_cb.Run(base::TimeDelta::FromMilliseconds(time_in_ms), |
| 851 base::TimeDelta::FromMilliseconds(max_time_in_ms)); | 868 base::TimeDelta::FromMilliseconds(max_time_in_ms)); |
| 852 } | 869 } |
| 853 | 870 |
| 854 TEST_F(PipelineTest, AudioTimeUpdateDuringSeek) { | 871 TEST_F(PipelineTest, AudioTimeUpdateDuringSeek) { |
| 855 CreateAudioStream(); | 872 CreateAudioStream(); |
| 856 MockDemuxerStreamVector streams; | 873 MockDemuxerStreamVector streams; |
| 857 streams.push_back(audio_stream()); | 874 streams.push_back(audio_stream()); |
| 858 | 875 |
| 859 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); | 876 InitializeDemuxer(&streams); |
| 860 InitializeAudioDecoder(audio_stream()); | 877 InitializeAudioDecoder(audio_stream()); |
| 861 InitializeAudioRenderer(); | 878 InitializeAudioRenderer(); |
| 862 InitializePipeline(PIPELINE_OK); | 879 InitializePipeline(PIPELINE_OK); |
| 863 | 880 |
| 864 float playback_rate = 1.0f; | 881 float playback_rate = 1.0f; |
| 865 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 882 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
| 866 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 883 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
| 867 pipeline_->SetPlaybackRate(playback_rate); | 884 pipeline_->SetPlaybackRate(playback_rate); |
| 868 message_loop_.RunAllPending(); | 885 message_loop_.RunAllPending(); |
| 869 | 886 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 897 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time); | 914 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time); |
| 898 | 915 |
| 899 // Now that the seek is complete, verify that time updates advance the current | 916 // Now that the seek is complete, verify that time updates advance the current |
| 900 // time. | 917 // time. |
| 901 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100); | 918 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100); |
| 902 audio_time_cb_.Run(new_time, new_time); | 919 audio_time_cb_.Run(new_time, new_time); |
| 903 | 920 |
| 904 EXPECT_EQ(pipeline_->GetMediaTime(), new_time); | 921 EXPECT_EQ(pipeline_->GetMediaTime(), new_time); |
| 905 } | 922 } |
| 906 | 923 |
| 924 TEST_F(PipelineTest, InitFailure_Demuxer) { | |
| 925 PipelineStatus expected_status = DEMUXER_ERROR_COULD_NOT_OPEN; | |
| 926 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | |
| 927 .WillOnce(RunPipelineStatusCB1WithStatus(expected_status)); | |
| 928 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | |
| 929 .WillOnce(RunClosure()); | |
| 930 InitializePipeline(expected_status); | |
| 931 EXPECT_FALSE(pipeline_->IsInitialized()); | |
| 932 } | |
| 933 | |
| 934 TEST_F(PipelineTest, InitFailure_AudioDecoder) { | |
| 935 CreateAudioStream(); | |
| 936 MockDemuxerStreamVector streams; | |
| 937 streams.push_back(audio_stream()); | |
| 938 | |
| 939 InitializeDemuxer(&streams, false); | |
| 940 | |
| 941 PipelineStatus expected_status = PIPELINE_ERROR_DECODE; | |
| 942 scoped_refptr<DemuxerStream> stream = streams[0]; | |
| 943 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) | |
| 944 .WillOnce(RunPipelineStatusCB1WithStatus(expected_status)); | |
| 945 | |
| 946 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | |
| 947 .WillOnce(RunClosure()); | |
| 948 | |
| 949 InitializePipeline(expected_status); | |
| 950 EXPECT_FALSE(pipeline_->IsInitialized()); | |
| 951 EXPECT_FALSE(pipeline_->HasAudio()); | |
| 952 } | |
| 953 | |
| 954 TEST_F(PipelineTest, InitFailure_AudioRenderer) { | |
| 955 CreateAudioStream(); | |
| 956 MockDemuxerStreamVector streams; | |
| 957 streams.push_back(audio_stream()); | |
| 958 | |
| 959 InitializeDemuxer(&streams, false); | |
| 960 InitializeAudioDecoder(audio_stream()); | |
| 961 | |
| 962 PipelineStatus expected_status = PIPELINE_ERROR_INITIALIZATION_FAILED; | |
| 963 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( | |
| 964 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), | |
| 965 _, _, _, _, _, _)) | |
| 966 .WillOnce(RunPipelineStatusCB1WithStatus(expected_status)); | |
| 967 | |
| 968 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | |
| 969 .WillOnce(RunClosure()); | |
| 970 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | |
| 971 .WillOnce(RunClosure()); | |
| 972 | |
| 973 InitializePipeline(expected_status); | |
| 974 EXPECT_FALSE(pipeline_->IsInitialized()); | |
| 975 EXPECT_TRUE(pipeline_->HasAudio()); | |
| 976 } | |
| 977 | |
| 978 TEST_F(PipelineTest, InitFailure_VideoDecoder) { | |
| 979 CreateAudioStream(); | |
| 980 CreateVideoStream(); | |
| 981 MockDemuxerStreamVector streams; | |
| 982 streams.push_back(audio_stream()); | |
| 983 streams.push_back(video_stream()); | |
| 984 | |
| 985 InitializeDemuxer(&streams, false); | |
| 986 InitializeAudioDecoder(audio_stream()); | |
| 987 InitializeAudioRenderer(false, false); | |
| 988 | |
| 989 PipelineStatus expected_status = PIPELINE_ERROR_DECODE; | |
| 990 scoped_refptr<DemuxerStream> stream = streams[1]; | |
| 991 EXPECT_CALL(*mocks_->video_decoder(), | |
| 992 Initialize(stream, _, _)) | |
| 993 .WillOnce(RunPipelineStatusCB1WithStatus(expected_status)); | |
| 994 | |
| 995 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | |
| 996 .WillOnce(RunClosure()); | |
| 997 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | |
| 998 .WillOnce(RunClosure()); | |
| 999 | |
| 1000 InitializePipeline(expected_status); | |
| 1001 EXPECT_FALSE(pipeline_->IsInitialized()); | |
| 1002 EXPECT_TRUE(pipeline_->HasAudio()); | |
| 1003 EXPECT_FALSE(pipeline_->HasVideo()); | |
| 1004 } | |
| 1005 | |
|
scherkus (not reviewing)
2012/08/08 21:15:02
remove extra blank line
acolwell GONE FROM CHROMIUM
2012/08/08 21:40:59
Done.
| |
| 1006 | |
| 1007 TEST_F(PipelineTest, InitFailure_VideoRenderer) { | |
| 1008 CreateAudioStream(); | |
| 1009 CreateVideoStream(); | |
| 1010 MockDemuxerStreamVector streams; | |
| 1011 streams.push_back(audio_stream()); | |
| 1012 streams.push_back(video_stream()); | |
| 1013 | |
| 1014 InitializeDemuxer(&streams, false); | |
| 1015 InitializeAudioDecoder(audio_stream()); | |
| 1016 InitializeAudioRenderer(false, false); | |
| 1017 InitializeVideoDecoder(video_stream()); | |
| 1018 | |
| 1019 PipelineStatus expected_status = PIPELINE_ERROR_INITIALIZATION_FAILED; | |
| 1020 EXPECT_CALL(*mocks_->video_renderer(), Initialize( | |
| 1021 scoped_refptr<VideoDecoder>(mocks_->video_decoder()), | |
| 1022 _, _, _, _, _, _, _, _)) | |
| 1023 .WillOnce(RunPipelineStatusCB1WithStatus(expected_status)); | |
| 1024 | |
| 1025 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | |
| 1026 .WillOnce(RunClosure()); | |
| 1027 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | |
| 1028 .WillOnce(RunClosure()); | |
| 1029 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)) | |
| 1030 .WillOnce(RunClosure()); | |
| 1031 | |
| 1032 InitializePipeline(expected_status); | |
| 1033 EXPECT_FALSE(pipeline_->IsInitialized()); | |
| 1034 EXPECT_TRUE(pipeline_->HasAudio()); | |
| 1035 EXPECT_TRUE(pipeline_->HasVideo()); | |
| 1036 } | |
| 1037 | |
| 907 class FlexibleCallbackRunner : public base::DelegateSimpleThread::Delegate { | 1038 class FlexibleCallbackRunner : public base::DelegateSimpleThread::Delegate { |
| 908 public: | 1039 public: |
| 909 FlexibleCallbackRunner(base::TimeDelta delay, PipelineStatus status, | 1040 FlexibleCallbackRunner(base::TimeDelta delay, PipelineStatus status, |
| 910 const PipelineStatusCB& status_cb) | 1041 const PipelineStatusCB& status_cb) |
| 911 : delay_(delay), | 1042 : delay_(delay), |
| 912 status_(status), | 1043 status_(status), |
| 913 status_cb_(status_cb) { | 1044 status_cb_(status_cb) { |
| 914 if (delay_ < base::TimeDelta()) { | 1045 if (delay_ < base::TimeDelta()) { |
| 915 status_cb_.Run(status_); | 1046 status_cb_.Run(status_); |
| 916 return; | 1047 return; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); | 1082 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); |
| 952 } | 1083 } |
| 953 | 1084 |
| 954 // Test that different-thread, some-delay callback (the expected common case) | 1085 // Test that different-thread, some-delay callback (the expected common case) |
| 955 // works correctly. | 1086 // works correctly. |
| 956 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 1087 TEST(PipelineStatusNotificationTest, DelayedCallback) { |
| 957 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); | 1088 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); |
| 958 } | 1089 } |
| 959 | 1090 |
| 960 } // namespace media | 1091 } // namespace media |
| OLD | NEW |