| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 ACTION_P2(SetError, pipeline, status) { | 49 ACTION_P2(SetError, pipeline, status) { |
| 50 pipeline->SetErrorForTesting(status); | 50 pipeline->SetErrorForTesting(status); |
| 51 } | 51 } |
| 52 | 52 |
| 53 ACTION(RunPipelineStatusCB) { | 53 ACTION(RunPipelineStatusCB) { |
| 54 arg1.Run(PIPELINE_OK); | 54 arg1.Run(PIPELINE_OK); |
| 55 } | 55 } |
| 56 | 56 |
| 57 ACTION(RunPipelineStatusCB2) { |
| 58 arg2.Run(PIPELINE_OK); |
| 59 } |
| 60 |
| 57 ACTION_P(RunPipelineStatusCBWithStatus, status) { | 61 ACTION_P(RunPipelineStatusCBWithStatus, status) { |
| 58 arg1.Run(status); | 62 arg1.Run(status); |
| 59 } | 63 } |
| 60 | 64 |
| 65 ACTION_P(RunPipelineStatusCB2WithStatus, status) { |
| 66 arg2.Run(status); |
| 67 } |
| 68 |
| 61 // Used for setting expectations on pipeline callbacks. Using a StrictMock | 69 // Used for setting expectations on pipeline callbacks. Using a StrictMock |
| 62 // also lets us test for missing callbacks. | 70 // also lets us test for missing callbacks. |
| 63 class CallbackHelper { | 71 class CallbackHelper { |
| 64 public: | 72 public: |
| 65 CallbackHelper() {} | 73 CallbackHelper() {} |
| 66 virtual ~CallbackHelper() {} | 74 virtual ~CallbackHelper() {} |
| 67 | 75 |
| 68 MOCK_METHOD1(OnStart, void(PipelineStatus)); | 76 MOCK_METHOD1(OnStart, void(PipelineStatus)); |
| 69 MOCK_METHOD1(OnSeek, void(PipelineStatus)); | 77 MOCK_METHOD1(OnSeek, void(PipelineStatus)); |
| 70 MOCK_METHOD0(OnStop, void()); | 78 MOCK_METHOD0(OnStop, void()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 165 } |
| 158 | 166 |
| 159 StrictMock<MockDemuxerStream>* CreateStream(DemuxerStream::Type type) { | 167 StrictMock<MockDemuxerStream>* CreateStream(DemuxerStream::Type type) { |
| 160 StrictMock<MockDemuxerStream>* stream = | 168 StrictMock<MockDemuxerStream>* stream = |
| 161 new StrictMock<MockDemuxerStream>(); | 169 new StrictMock<MockDemuxerStream>(); |
| 162 EXPECT_CALL(*stream, type()) | 170 EXPECT_CALL(*stream, type()) |
| 163 .WillRepeatedly(Return(type)); | 171 .WillRepeatedly(Return(type)); |
| 164 return stream; | 172 return stream; |
| 165 } | 173 } |
| 166 | 174 |
| 167 // Sets up expectations to allow the video decoder to initialize. | |
| 168 void InitializeVideoDecoder(const scoped_refptr<DemuxerStream>& stream) { | |
| 169 EXPECT_CALL(*mocks_->video_decoder(), | |
| 170 Initialize(stream, _, _)) | |
| 171 .WillOnce(RunPipelineStatusCB()); | |
| 172 } | |
| 173 | |
| 174 // Sets up expectations to allow the audio decoder to initialize. | 175 // Sets up expectations to allow the audio decoder to initialize. |
| 175 void InitializeAudioDecoder(const scoped_refptr<DemuxerStream>& stream) { | 176 void InitializeAudioDecoder(const scoped_refptr<DemuxerStream>& stream) { |
| 176 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) | 177 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) |
| 177 .WillOnce(RunPipelineStatusCB()); | 178 .WillOnce(RunPipelineStatusCB()); |
| 178 } | 179 } |
| 179 | 180 |
| 180 // Sets up expectations to allow the video renderer to initialize. | 181 // Sets up expectations to allow the video renderer to initialize. |
| 181 void InitializeVideoRenderer() { | 182 void InitializeVideoRenderer(const scoped_refptr<DemuxerStream>& stream) { |
| 182 EXPECT_CALL(*mocks_->video_renderer(), Initialize( | 183 EXPECT_CALL(*mocks_->video_renderer(), Initialize( |
| 183 scoped_refptr<VideoDecoder>(mocks_->video_decoder()), | 184 stream, _, _, _, _, _, _, _, _, _)) |
| 184 _, _, _, _, _, _, _, _)) | 185 .WillOnce(RunPipelineStatusCB2()); |
| 185 .WillOnce(RunPipelineStatusCB()); | |
| 186 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | 186 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); |
| 187 | 187 |
| 188 // Startup sequence. | 188 // Startup sequence. |
| 189 EXPECT_CALL(*mocks_->video_renderer(), | 189 EXPECT_CALL(*mocks_->video_renderer(), |
| 190 Preroll(mocks_->demuxer()->GetStartTime(), _)) | 190 Preroll(mocks_->demuxer()->GetStartTime(), _)) |
| 191 .WillOnce(RunPipelineStatusCB()); | 191 .WillOnce(RunPipelineStatusCB()); |
| 192 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) | 192 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) |
| 193 .WillOnce(RunClosure()); | 193 .WillOnce(RunClosure()); |
| 194 } | 194 } |
| 195 | 195 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 EXPECT_TRUE(pipeline_->HasAudio()); | 412 EXPECT_TRUE(pipeline_->HasAudio()); |
| 413 EXPECT_FALSE(pipeline_->HasVideo()); | 413 EXPECT_FALSE(pipeline_->HasVideo()); |
| 414 } | 414 } |
| 415 | 415 |
| 416 TEST_F(PipelineTest, VideoStream) { | 416 TEST_F(PipelineTest, VideoStream) { |
| 417 CreateVideoStream(); | 417 CreateVideoStream(); |
| 418 MockDemuxerStreamVector streams; | 418 MockDemuxerStreamVector streams; |
| 419 streams.push_back(video_stream()); | 419 streams.push_back(video_stream()); |
| 420 | 420 |
| 421 InitializeDemuxer(&streams); | 421 InitializeDemuxer(&streams); |
| 422 InitializeVideoDecoder(video_stream()); | 422 InitializeVideoRenderer(video_stream()); |
| 423 InitializeVideoRenderer(); | |
| 424 | 423 |
| 425 InitializePipeline(PIPELINE_OK); | 424 InitializePipeline(PIPELINE_OK); |
| 426 EXPECT_FALSE(pipeline_->HasAudio()); | 425 EXPECT_FALSE(pipeline_->HasAudio()); |
| 427 EXPECT_TRUE(pipeline_->HasVideo()); | 426 EXPECT_TRUE(pipeline_->HasVideo()); |
| 428 } | 427 } |
| 429 | 428 |
| 430 TEST_F(PipelineTest, AudioVideoStream) { | 429 TEST_F(PipelineTest, AudioVideoStream) { |
| 431 CreateAudioStream(); | 430 CreateAudioStream(); |
| 432 CreateVideoStream(); | 431 CreateVideoStream(); |
| 433 MockDemuxerStreamVector streams; | 432 MockDemuxerStreamVector streams; |
| 434 streams.push_back(audio_stream()); | 433 streams.push_back(audio_stream()); |
| 435 streams.push_back(video_stream()); | 434 streams.push_back(video_stream()); |
| 436 | 435 |
| 437 InitializeDemuxer(&streams); | 436 InitializeDemuxer(&streams); |
| 438 InitializeAudioDecoder(audio_stream()); | 437 InitializeAudioDecoder(audio_stream()); |
| 439 InitializeAudioRenderer(); | 438 InitializeAudioRenderer(); |
| 440 InitializeVideoDecoder(video_stream()); | 439 InitializeVideoRenderer(video_stream()); |
| 441 InitializeVideoRenderer(); | |
| 442 | 440 |
| 443 InitializePipeline(PIPELINE_OK); | 441 InitializePipeline(PIPELINE_OK); |
| 444 EXPECT_TRUE(pipeline_->HasAudio()); | 442 EXPECT_TRUE(pipeline_->HasAudio()); |
| 445 EXPECT_TRUE(pipeline_->HasVideo()); | 443 EXPECT_TRUE(pipeline_->HasVideo()); |
| 446 } | 444 } |
| 447 | 445 |
| 448 TEST_F(PipelineTest, Seek) { | 446 TEST_F(PipelineTest, Seek) { |
| 449 CreateAudioStream(); | 447 CreateAudioStream(); |
| 450 CreateVideoStream(); | 448 CreateVideoStream(); |
| 451 MockDemuxerStreamVector streams; | 449 MockDemuxerStreamVector streams; |
| 452 streams.push_back(audio_stream()); | 450 streams.push_back(audio_stream()); |
| 453 streams.push_back(video_stream()); | 451 streams.push_back(video_stream()); |
| 454 | 452 |
| 455 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); | 453 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); |
| 456 InitializeAudioDecoder(audio_stream()); | 454 InitializeAudioDecoder(audio_stream()); |
| 457 InitializeAudioRenderer(); | 455 InitializeAudioRenderer(); |
| 458 InitializeVideoDecoder(video_stream()); | 456 InitializeVideoRenderer(video_stream()); |
| 459 InitializeVideoRenderer(); | |
| 460 | 457 |
| 461 // Initialize then seek! | 458 // Initialize then seek! |
| 462 InitializePipeline(PIPELINE_OK); | 459 InitializePipeline(PIPELINE_OK); |
| 463 | 460 |
| 464 // Every filter should receive a call to Seek(). | 461 // Every filter should receive a call to Seek(). |
| 465 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); | 462 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); |
| 466 ExpectSeek(expected); | 463 ExpectSeek(expected); |
| 467 DoSeek(expected); | 464 DoSeek(expected); |
| 468 } | 465 } |
| 469 | 466 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 485 pipeline_->SetVolume(expected); | 482 pipeline_->SetVolume(expected); |
| 486 } | 483 } |
| 487 | 484 |
| 488 TEST_F(PipelineTest, Properties) { | 485 TEST_F(PipelineTest, Properties) { |
| 489 CreateVideoStream(); | 486 CreateVideoStream(); |
| 490 MockDemuxerStreamVector streams; | 487 MockDemuxerStreamVector streams; |
| 491 streams.push_back(video_stream()); | 488 streams.push_back(video_stream()); |
| 492 | 489 |
| 493 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 490 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 494 InitializeDemuxer(&streams, kDuration); | 491 InitializeDemuxer(&streams, kDuration); |
| 495 InitializeVideoDecoder(video_stream()); | 492 InitializeVideoRenderer(video_stream()); |
| 496 InitializeVideoRenderer(); | |
| 497 | 493 |
| 498 InitializePipeline(PIPELINE_OK); | 494 InitializePipeline(PIPELINE_OK); |
| 499 EXPECT_EQ(kDuration.ToInternalValue(), | 495 EXPECT_EQ(kDuration.ToInternalValue(), |
| 500 pipeline_->GetMediaDuration().ToInternalValue()); | 496 pipeline_->GetMediaDuration().ToInternalValue()); |
| 501 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); | 497 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); |
| 502 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 498 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 503 } | 499 } |
| 504 | 500 |
| 505 TEST_F(PipelineTest, GetBufferedTimeRanges) { | 501 TEST_F(PipelineTest, GetBufferedTimeRanges) { |
| 506 CreateVideoStream(); | 502 CreateVideoStream(); |
| 507 MockDemuxerStreamVector streams; | 503 MockDemuxerStreamVector streams; |
| 508 streams.push_back(video_stream()); | 504 streams.push_back(video_stream()); |
| 509 | 505 |
| 510 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 506 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 511 InitializeDemuxer(&streams, kDuration); | 507 InitializeDemuxer(&streams, kDuration); |
| 512 InitializeVideoDecoder(video_stream()); | 508 InitializeVideoRenderer(video_stream()); |
| 513 InitializeVideoRenderer(); | |
| 514 | 509 |
| 515 InitializePipeline(PIPELINE_OK); | 510 InitializePipeline(PIPELINE_OK); |
| 516 | 511 |
| 517 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); | 512 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); |
| 518 | 513 |
| 519 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 514 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 520 pipeline_->AddBufferedByteRange(0, kTotalBytes / 8); | 515 pipeline_->AddBufferedByteRange(0, kTotalBytes / 8); |
| 521 EXPECT_TRUE(pipeline_->DidLoadingProgress()); | 516 EXPECT_TRUE(pipeline_->DidLoadingProgress()); |
| 522 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 517 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 523 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); | 518 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 TEST_F(PipelineTest, DisableAudioRenderer) { | 552 TEST_F(PipelineTest, DisableAudioRenderer) { |
| 558 CreateAudioStream(); | 553 CreateAudioStream(); |
| 559 CreateVideoStream(); | 554 CreateVideoStream(); |
| 560 MockDemuxerStreamVector streams; | 555 MockDemuxerStreamVector streams; |
| 561 streams.push_back(audio_stream()); | 556 streams.push_back(audio_stream()); |
| 562 streams.push_back(video_stream()); | 557 streams.push_back(video_stream()); |
| 563 | 558 |
| 564 InitializeDemuxer(&streams); | 559 InitializeDemuxer(&streams); |
| 565 InitializeAudioDecoder(audio_stream()); | 560 InitializeAudioDecoder(audio_stream()); |
| 566 InitializeAudioRenderer(); | 561 InitializeAudioRenderer(); |
| 567 InitializeVideoDecoder(video_stream()); | 562 InitializeVideoRenderer(video_stream()); |
| 568 InitializeVideoRenderer(); | |
| 569 | 563 |
| 570 InitializePipeline(PIPELINE_OK); | 564 InitializePipeline(PIPELINE_OK); |
| 571 EXPECT_TRUE(pipeline_->HasAudio()); | 565 EXPECT_TRUE(pipeline_->HasAudio()); |
| 572 EXPECT_TRUE(pipeline_->HasVideo()); | 566 EXPECT_TRUE(pipeline_->HasVideo()); |
| 573 | 567 |
| 574 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); | 568 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); |
| 575 pipeline_->OnAudioDisabled(); | 569 pipeline_->OnAudioDisabled(); |
| 576 | 570 |
| 577 // Verify that ended event is fired when video ends. | 571 // Verify that ended event is fired when video ends. |
| 578 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 572 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 579 pipeline_->OnVideoRendererEnded(); | 573 pipeline_->OnVideoRendererEnded(); |
| 580 } | 574 } |
| 581 | 575 |
| 582 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { | 576 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { |
| 583 CreateAudioStream(); | 577 CreateAudioStream(); |
| 584 CreateVideoStream(); | 578 CreateVideoStream(); |
| 585 MockDemuxerStreamVector streams; | 579 MockDemuxerStreamVector streams; |
| 586 streams.push_back(audio_stream()); | 580 streams.push_back(audio_stream()); |
| 587 streams.push_back(video_stream()); | 581 streams.push_back(video_stream()); |
| 588 | 582 |
| 589 InitializeDemuxer(&streams); | 583 InitializeDemuxer(&streams); |
| 590 InitializeAudioDecoder(audio_stream()); | 584 InitializeAudioDecoder(audio_stream()); |
| 591 InitializeAudioRenderer(true); | 585 InitializeAudioRenderer(true); |
| 592 InitializeVideoDecoder(video_stream()); | 586 InitializeVideoRenderer(video_stream()); |
| 593 InitializeVideoRenderer(); | |
| 594 | 587 |
| 595 EXPECT_CALL(*mocks_->demuxer(), | 588 EXPECT_CALL(*mocks_->demuxer(), |
| 596 OnAudioRendererDisabled()); | 589 OnAudioRendererDisabled()); |
| 597 | 590 |
| 598 InitializePipeline(PIPELINE_OK); | 591 InitializePipeline(PIPELINE_OK); |
| 599 EXPECT_FALSE(pipeline_->HasAudio()); | 592 EXPECT_FALSE(pipeline_->HasAudio()); |
| 600 EXPECT_TRUE(pipeline_->HasVideo()); | 593 EXPECT_TRUE(pipeline_->HasVideo()); |
| 601 | 594 |
| 602 // Verify that ended event is fired when video ends. | 595 // Verify that ended event is fired when video ends. |
| 603 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 596 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 604 pipeline_->OnVideoRendererEnded(); | 597 pipeline_->OnVideoRendererEnded(); |
| 605 } | 598 } |
| 606 | 599 |
| 607 TEST_F(PipelineTest, EndedCallback) { | 600 TEST_F(PipelineTest, EndedCallback) { |
| 608 CreateAudioStream(); | 601 CreateAudioStream(); |
| 609 CreateVideoStream(); | 602 CreateVideoStream(); |
| 610 MockDemuxerStreamVector streams; | 603 MockDemuxerStreamVector streams; |
| 611 streams.push_back(audio_stream()); | 604 streams.push_back(audio_stream()); |
| 612 streams.push_back(video_stream()); | 605 streams.push_back(video_stream()); |
| 613 | 606 |
| 614 InitializeDemuxer(&streams); | 607 InitializeDemuxer(&streams); |
| 615 InitializeAudioDecoder(audio_stream()); | 608 InitializeAudioDecoder(audio_stream()); |
| 616 InitializeAudioRenderer(); | 609 InitializeAudioRenderer(); |
| 617 InitializeVideoDecoder(video_stream()); | 610 InitializeVideoRenderer(video_stream()); |
| 618 InitializeVideoRenderer(); | |
| 619 InitializePipeline(PIPELINE_OK); | 611 InitializePipeline(PIPELINE_OK); |
| 620 | 612 |
| 621 // The ended callback shouldn't run until both renderers have ended. | 613 // The ended callback shouldn't run until both renderers have ended. |
| 622 pipeline_->OnAudioRendererEnded(); | 614 pipeline_->OnAudioRendererEnded(); |
| 623 message_loop_.RunAllPending(); | 615 message_loop_.RunAllPending(); |
| 624 | 616 |
| 625 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 617 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 626 pipeline_->OnVideoRendererEnded(); | 618 pipeline_->OnVideoRendererEnded(); |
| 627 message_loop_.RunAllPending(); | 619 message_loop_.RunAllPending(); |
| 628 } | 620 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 642 streams.push_back(audio_stream()); | 634 streams.push_back(audio_stream()); |
| 643 streams.push_back(video_stream()); | 635 streams.push_back(video_stream()); |
| 644 | 636 |
| 645 // Replace the clock so we can simulate wallclock time advancing w/o using | 637 // Replace the clock so we can simulate wallclock time advancing w/o using |
| 646 // Sleep(). | 638 // Sleep(). |
| 647 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); | 639 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); |
| 648 | 640 |
| 649 InitializeDemuxer(&streams, duration); | 641 InitializeDemuxer(&streams, duration); |
| 650 InitializeAudioDecoder(audio_stream()); | 642 InitializeAudioDecoder(audio_stream()); |
| 651 InitializeAudioRenderer(); | 643 InitializeAudioRenderer(); |
| 652 InitializeVideoDecoder(video_stream()); | 644 InitializeVideoRenderer(video_stream()); |
| 653 InitializeVideoRenderer(); | |
| 654 InitializePipeline(PIPELINE_OK); | 645 InitializePipeline(PIPELINE_OK); |
| 655 | 646 |
| 656 EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue()); | 647 EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue()); |
| 657 | 648 |
| 658 float playback_rate = 1.0f; | 649 float playback_rate = 1.0f; |
| 659 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 650 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
| 660 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(playback_rate)); | 651 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(playback_rate)); |
| 661 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 652 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
| 662 pipeline_->SetPlaybackRate(playback_rate); | 653 pipeline_->SetPlaybackRate(playback_rate); |
| 663 message_loop_.RunAllPending(); | 654 message_loop_.RunAllPending(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 message_loop_.RunAllPending(); | 770 message_loop_.RunAllPending(); |
| 780 } | 771 } |
| 781 | 772 |
| 782 TEST_F(PipelineTest, StartTimeIsZero) { | 773 TEST_F(PipelineTest, StartTimeIsZero) { |
| 783 CreateVideoStream(); | 774 CreateVideoStream(); |
| 784 MockDemuxerStreamVector streams; | 775 MockDemuxerStreamVector streams; |
| 785 streams.push_back(video_stream()); | 776 streams.push_back(video_stream()); |
| 786 | 777 |
| 787 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 778 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 788 InitializeDemuxer(&streams, kDuration); | 779 InitializeDemuxer(&streams, kDuration); |
| 789 InitializeVideoDecoder(video_stream()); | 780 InitializeVideoRenderer(video_stream()); |
| 790 InitializeVideoRenderer(); | |
| 791 | 781 |
| 792 InitializePipeline(PIPELINE_OK); | 782 InitializePipeline(PIPELINE_OK); |
| 793 EXPECT_FALSE(pipeline_->HasAudio()); | 783 EXPECT_FALSE(pipeline_->HasAudio()); |
| 794 EXPECT_TRUE(pipeline_->HasVideo()); | 784 EXPECT_TRUE(pipeline_->HasVideo()); |
| 795 | 785 |
| 796 EXPECT_EQ(base::TimeDelta(), pipeline_->GetMediaTime()); | 786 EXPECT_EQ(base::TimeDelta(), pipeline_->GetMediaTime()); |
| 797 } | 787 } |
| 798 | 788 |
| 799 TEST_F(PipelineTest, StartTimeIsNonZero) { | 789 TEST_F(PipelineTest, StartTimeIsNonZero) { |
| 800 const base::TimeDelta kStartTime = base::TimeDelta::FromSeconds(4); | 790 const base::TimeDelta kStartTime = base::TimeDelta::FromSeconds(4); |
| 801 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 791 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 802 | 792 |
| 803 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) | 793 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) |
| 804 .WillRepeatedly(Return(kStartTime)); | 794 .WillRepeatedly(Return(kStartTime)); |
| 805 | 795 |
| 806 CreateVideoStream(); | 796 CreateVideoStream(); |
| 807 MockDemuxerStreamVector streams; | 797 MockDemuxerStreamVector streams; |
| 808 streams.push_back(video_stream()); | 798 streams.push_back(video_stream()); |
| 809 | 799 |
| 810 InitializeDemuxer(&streams, kDuration); | 800 InitializeDemuxer(&streams, kDuration); |
| 811 InitializeVideoDecoder(video_stream()); | 801 InitializeVideoRenderer(video_stream()); |
| 812 InitializeVideoRenderer(); | |
| 813 | 802 |
| 814 InitializePipeline(PIPELINE_OK); | 803 InitializePipeline(PIPELINE_OK); |
| 815 EXPECT_FALSE(pipeline_->HasAudio()); | 804 EXPECT_FALSE(pipeline_->HasAudio()); |
| 816 EXPECT_TRUE(pipeline_->HasVideo()); | 805 EXPECT_TRUE(pipeline_->HasVideo()); |
| 817 | 806 |
| 818 EXPECT_EQ(kStartTime, pipeline_->GetMediaTime()); | 807 EXPECT_EQ(kStartTime, pipeline_->GetMediaTime()); |
| 819 } | 808 } |
| 820 | 809 |
| 821 static void RunTimeCB(const AudioRenderer::TimeCB& time_cb, | 810 static void RunTimeCB(const AudioRenderer::TimeCB& time_cb, |
| 822 int time_in_ms, | 811 int time_in_ms, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 919 TEST(PipelineStatusNotificationTest, DelayedCallback) { |
| 931 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); | 920 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); |
| 932 } | 921 } |
| 933 | 922 |
| 934 class PipelineTeardownTest : public PipelineTest { | 923 class PipelineTeardownTest : public PipelineTest { |
| 935 public: | 924 public: |
| 936 enum TeardownState { | 925 enum TeardownState { |
| 937 kInitDemuxer, | 926 kInitDemuxer, |
| 938 kInitAudioDecoder, | 927 kInitAudioDecoder, |
| 939 kInitAudioRenderer, | 928 kInitAudioRenderer, |
| 940 kInitVideoDecoder, | |
| 941 kInitVideoRenderer, | 929 kInitVideoRenderer, |
| 942 kPausing, | 930 kPausing, |
| 943 kFlushing, | 931 kFlushing, |
| 944 kSeeking, | 932 kSeeking, |
| 945 kPrerolling, | 933 kPrerolling, |
| 946 kStarting, | 934 kStarting, |
| 947 kPlaying, | 935 kPlaying, |
| 948 }; | 936 }; |
| 949 | 937 |
| 950 enum StopOrError { | 938 enum StopOrError { |
| 951 kStop, | 939 kStop, |
| 952 kError, | 940 kError, |
| 953 }; | 941 }; |
| 954 | 942 |
| 955 PipelineTeardownTest() {} | 943 PipelineTeardownTest() {} |
| 956 virtual ~PipelineTeardownTest() {} | 944 virtual ~PipelineTeardownTest() {} |
| 957 | 945 |
| 958 void RunTest(TeardownState state, StopOrError stop_or_error) { | 946 void RunTest(TeardownState state, StopOrError stop_or_error) { |
| 959 switch (state) { | 947 switch (state) { |
| 960 case kInitDemuxer: | 948 case kInitDemuxer: |
| 961 case kInitAudioDecoder: | 949 case kInitAudioDecoder: |
| 962 case kInitAudioRenderer: | 950 case kInitAudioRenderer: |
| 963 case kInitVideoDecoder: | |
| 964 case kInitVideoRenderer: | 951 case kInitVideoRenderer: |
| 965 DoInitialize(state, stop_or_error); | 952 DoInitialize(state, stop_or_error); |
| 966 break; | 953 break; |
| 967 | 954 |
| 968 case kPausing: | 955 case kPausing: |
| 969 case kFlushing: | 956 case kFlushing: |
| 970 case kSeeking: | 957 case kSeeking: |
| 971 case kPrerolling: | 958 case kPrerolling: |
| 972 case kStarting: { | 959 case kStarting: { |
| 973 DoInitialize(state, stop_or_error); | 960 DoInitialize(state, stop_or_error); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 } | 1060 } |
| 1074 | 1061 |
| 1075 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | 1062 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| 1076 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | 1063 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| 1077 return status; | 1064 return status; |
| 1078 } | 1065 } |
| 1079 | 1066 |
| 1080 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(_, _, _, _, _, _, _)) | 1067 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(_, _, _, _, _, _, _)) |
| 1081 .WillOnce(RunPipelineStatusCB()); | 1068 .WillOnce(RunPipelineStatusCB()); |
| 1082 | 1069 |
| 1083 if (state == kInitVideoDecoder) { | |
| 1084 if (stop_or_error == kStop) { | |
| 1085 EXPECT_CALL(*mocks_->video_decoder(), Initialize(_, _, _)) | |
| 1086 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); | |
| 1087 EXPECT_CALL(callbacks_, OnStop()); | |
| 1088 } else { | |
| 1089 status = PIPELINE_ERROR_DECODE; | |
| 1090 EXPECT_CALL(*mocks_->video_decoder(), Initialize(_, _, _)) | |
| 1091 .WillOnce(RunPipelineStatusCBWithStatus(status)); | |
| 1092 } | |
| 1093 | |
| 1094 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 1095 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 1096 return status; | |
| 1097 } | |
| 1098 | |
| 1099 EXPECT_CALL(*mocks_->video_decoder(), Initialize(_, _, _)) | |
| 1100 .WillOnce(RunPipelineStatusCB()); | |
| 1101 | |
| 1102 if (state == kInitVideoRenderer) { | 1070 if (state == kInitVideoRenderer) { |
| 1103 if (stop_or_error == kStop) { | 1071 if (stop_or_error == kStop) { |
| 1104 EXPECT_CALL(*mocks_->video_renderer(), | 1072 EXPECT_CALL(*mocks_->video_renderer(), |
| 1105 Initialize(_, _, _, _, _, _, _, _, _)) | 1073 Initialize(_, _, _, _, _, _, _, _, _, _)) |
| 1106 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); | 1074 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB2())); |
| 1107 EXPECT_CALL(callbacks_, OnStop()); | 1075 EXPECT_CALL(callbacks_, OnStop()); |
| 1108 } else { | 1076 } else { |
| 1109 status = PIPELINE_ERROR_INITIALIZATION_FAILED; | 1077 status = PIPELINE_ERROR_INITIALIZATION_FAILED; |
| 1110 EXPECT_CALL(*mocks_->video_renderer(), | 1078 EXPECT_CALL(*mocks_->video_renderer(), |
| 1111 Initialize(_, _, _, _, _, _, _, _, _)) | 1079 Initialize(_, _, _, _, _, _, _, _, _, _)) |
| 1112 .WillOnce(RunPipelineStatusCBWithStatus(status)); | 1080 .WillOnce(RunPipelineStatusCB2WithStatus(status)); |
| 1113 } | 1081 } |
| 1114 | 1082 |
| 1115 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | 1083 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| 1116 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | 1084 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| 1117 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); | 1085 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); |
| 1118 return status; | 1086 return status; |
| 1119 } | 1087 } |
| 1120 | 1088 |
| 1121 EXPECT_CALL(*mocks_->video_renderer(), | 1089 EXPECT_CALL(*mocks_->video_renderer(), |
| 1122 Initialize(_, _, _, _, _, _, _, _, _)) | 1090 Initialize(_, _, _, _, _, _, _, _, _, _)) |
| 1123 .WillOnce(RunPipelineStatusCB()); | 1091 .WillOnce(RunPipelineStatusCB2()); |
| 1124 | 1092 |
| 1125 // If we get here it's a successful initialization. | 1093 // If we get here it's a successful initialization. |
| 1126 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 1094 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); |
| 1127 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); | 1095 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); |
| 1128 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | 1096 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); |
| 1129 | 1097 |
| 1130 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); | 1098 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); |
| 1131 | 1099 |
| 1132 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) | 1100 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) |
| 1133 .WillOnce(RunPipelineStatusCB()); | 1101 .WillOnce(RunPipelineStatusCB()); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1307 }; | 1275 }; |
| 1308 | 1276 |
| 1309 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \ | 1277 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \ |
| 1310 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \ | 1278 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \ |
| 1311 RunTest(k##state, k##stop_or_error); \ | 1279 RunTest(k##state, k##stop_or_error); \ |
| 1312 } | 1280 } |
| 1313 | 1281 |
| 1314 INSTANTIATE_TEARDOWN_TEST(Stop, InitDemuxer); | 1282 INSTANTIATE_TEARDOWN_TEST(Stop, InitDemuxer); |
| 1315 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioDecoder); | 1283 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioDecoder); |
| 1316 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioRenderer); | 1284 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioRenderer); |
| 1317 INSTANTIATE_TEARDOWN_TEST(Stop, InitVideoDecoder); | |
| 1318 INSTANTIATE_TEARDOWN_TEST(Stop, InitVideoRenderer); | 1285 INSTANTIATE_TEARDOWN_TEST(Stop, InitVideoRenderer); |
| 1319 INSTANTIATE_TEARDOWN_TEST(Stop, Pausing); | 1286 INSTANTIATE_TEARDOWN_TEST(Stop, Pausing); |
| 1320 INSTANTIATE_TEARDOWN_TEST(Stop, Flushing); | 1287 INSTANTIATE_TEARDOWN_TEST(Stop, Flushing); |
| 1321 INSTANTIATE_TEARDOWN_TEST(Stop, Seeking); | 1288 INSTANTIATE_TEARDOWN_TEST(Stop, Seeking); |
| 1322 INSTANTIATE_TEARDOWN_TEST(Stop, Prerolling); | 1289 INSTANTIATE_TEARDOWN_TEST(Stop, Prerolling); |
| 1323 INSTANTIATE_TEARDOWN_TEST(Stop, Starting); | 1290 INSTANTIATE_TEARDOWN_TEST(Stop, Starting); |
| 1324 INSTANTIATE_TEARDOWN_TEST(Stop, Playing); | 1291 INSTANTIATE_TEARDOWN_TEST(Stop, Playing); |
| 1325 | 1292 |
| 1326 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer); | 1293 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer); |
| 1327 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioDecoder); | 1294 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioDecoder); |
| 1328 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); | 1295 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); |
| 1329 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoDecoder); | |
| 1330 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); | 1296 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); |
| 1331 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); | 1297 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); |
| 1332 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); | 1298 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); |
| 1333 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); | 1299 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); |
| 1334 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); | 1300 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); |
| 1335 INSTANTIATE_TEARDOWN_TEST(Error, Starting); | 1301 INSTANTIATE_TEARDOWN_TEST(Error, Starting); |
| 1336 INSTANTIATE_TEARDOWN_TEST(Error, Playing); | 1302 INSTANTIATE_TEARDOWN_TEST(Error, Playing); |
| 1337 | 1303 |
| 1338 } // namespace media | 1304 } // namespace media |
| OLD | NEW |