| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 153 } |
| 154 | 154 |
| 155 StrictMock<MockDemuxerStream>* CreateStream(DemuxerStream::Type type) { | 155 StrictMock<MockDemuxerStream>* CreateStream(DemuxerStream::Type type) { |
| 156 StrictMock<MockDemuxerStream>* stream = | 156 StrictMock<MockDemuxerStream>* stream = |
| 157 new StrictMock<MockDemuxerStream>(); | 157 new StrictMock<MockDemuxerStream>(); |
| 158 EXPECT_CALL(*stream, type()) | 158 EXPECT_CALL(*stream, type()) |
| 159 .WillRepeatedly(Return(type)); | 159 .WillRepeatedly(Return(type)); |
| 160 return stream; | 160 return stream; |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Sets up expectations to allow the audio decoder to initialize. | |
| 164 void InitializeAudioDecoder(const scoped_refptr<DemuxerStream>& stream) { | |
| 165 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) | |
| 166 .WillOnce(RunPipelineStatusCB()); | |
| 167 } | |
| 168 | |
| 169 // Sets up expectations to allow the video renderer to initialize. | 163 // Sets up expectations to allow the video renderer to initialize. |
| 170 void InitializeVideoRenderer(const scoped_refptr<DemuxerStream>& stream) { | 164 void InitializeVideoRenderer(const scoped_refptr<DemuxerStream>& stream) { |
| 171 EXPECT_CALL(*mocks_->video_renderer(), Initialize( | 165 EXPECT_CALL(*mocks_->video_renderer(), |
| 172 stream, _, _, _, _, _, _, _, _, _)) | 166 Initialize(stream, _, _, _, _, _, _, _, _, _)) |
| 173 .WillOnce(RunPipelineStatusCB2()); | 167 .WillOnce(RunPipelineStatusCB2()); |
| 174 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | 168 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); |
| 175 | 169 |
| 176 // Startup sequence. | 170 // Startup sequence. |
| 177 EXPECT_CALL(*mocks_->video_renderer(), | 171 EXPECT_CALL(*mocks_->video_renderer(), |
| 178 Preroll(mocks_->demuxer()->GetStartTime(), _)) | 172 Preroll(mocks_->demuxer()->GetStartTime(), _)) |
| 179 .WillOnce(RunPipelineStatusCB()); | 173 .WillOnce(RunPipelineStatusCB()); |
| 180 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) | 174 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) |
| 181 .WillOnce(RunClosure()); | 175 .WillOnce(RunClosure()); |
| 182 } | 176 } |
| 183 | 177 |
| 184 // Sets up expectations to allow the audio renderer to initialize. | 178 // Sets up expectations to allow the audio renderer to initialize. |
| 185 void InitializeAudioRenderer(bool disable_after_init_cb = false) { | 179 void InitializeAudioRenderer(const scoped_refptr<DemuxerStream>& stream, |
| 180 bool disable_after_init_cb) { |
| 186 if (disable_after_init_cb) { | 181 if (disable_after_init_cb) { |
| 187 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( | 182 EXPECT_CALL(*mocks_->audio_renderer(), |
| 188 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), | 183 Initialize(stream, _, _, _, _, _, _, _, _)) |
| 189 _, _, _, _, _, _)) | 184 .WillOnce(DoAll(RunPipelineStatusCB2(), |
| 190 .WillOnce(DoAll(RunPipelineStatusCB(), | 185 WithArg<7>(RunClosure()))); // |disabled_cb|. |
| 191 WithArg<5>(RunClosure()))); // |disabled_cb|. | |
| 192 } else { | 186 } else { |
| 193 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( | 187 EXPECT_CALL(*mocks_->audio_renderer(), |
| 194 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), | 188 Initialize(stream, _, _, _, _, _, _, _, _)) |
| 195 _, _, _, _, _, _)) | 189 .WillOnce(DoAll(SaveArg<5>(&audio_time_cb_), |
| 196 .WillOnce(DoAll(SaveArg<3>(&audio_time_cb_), | 190 RunPipelineStatusCB2())); |
| 197 RunPipelineStatusCB())); | |
| 198 } | 191 } |
| 199 } | 192 } |
| 200 | 193 |
| 201 // Sets up expectations on the callback and initializes the pipeline. Called | 194 // Sets up expectations on the callback and initializes the pipeline. Called |
| 202 // after tests have set expectations any filters they wish to use. | 195 // after tests have set expectations any filters they wish to use. |
| 203 void InitializePipeline(PipelineStatus start_status) { | 196 void InitializePipeline(PipelineStatus start_status) { |
| 204 EXPECT_CALL(callbacks_, OnStart(start_status)); | 197 EXPECT_CALL(callbacks_, OnStart(start_status)); |
| 205 | 198 |
| 206 if (start_status == PIPELINE_OK) { | 199 if (start_status == PIPELINE_OK) { |
| 207 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kHaveMetadata)); | 200 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kHaveMetadata)); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 380 |
| 388 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); | 381 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); |
| 389 } | 382 } |
| 390 | 383 |
| 391 TEST_F(PipelineTest, AudioStream) { | 384 TEST_F(PipelineTest, AudioStream) { |
| 392 CreateAudioStream(); | 385 CreateAudioStream(); |
| 393 MockDemuxerStreamVector streams; | 386 MockDemuxerStreamVector streams; |
| 394 streams.push_back(audio_stream()); | 387 streams.push_back(audio_stream()); |
| 395 | 388 |
| 396 InitializeDemuxer(&streams); | 389 InitializeDemuxer(&streams); |
| 397 InitializeAudioDecoder(audio_stream()); | 390 InitializeAudioRenderer(audio_stream(), false); |
| 398 InitializeAudioRenderer(); | |
| 399 | 391 |
| 400 InitializePipeline(PIPELINE_OK); | 392 InitializePipeline(PIPELINE_OK); |
| 401 EXPECT_TRUE(pipeline_->HasAudio()); | 393 EXPECT_TRUE(pipeline_->HasAudio()); |
| 402 EXPECT_FALSE(pipeline_->HasVideo()); | 394 EXPECT_FALSE(pipeline_->HasVideo()); |
| 403 } | 395 } |
| 404 | 396 |
| 405 TEST_F(PipelineTest, VideoStream) { | 397 TEST_F(PipelineTest, VideoStream) { |
| 406 CreateVideoStream(); | 398 CreateVideoStream(); |
| 407 MockDemuxerStreamVector streams; | 399 MockDemuxerStreamVector streams; |
| 408 streams.push_back(video_stream()); | 400 streams.push_back(video_stream()); |
| 409 | 401 |
| 410 InitializeDemuxer(&streams); | 402 InitializeDemuxer(&streams); |
| 411 InitializeVideoRenderer(video_stream()); | 403 InitializeVideoRenderer(video_stream()); |
| 412 | 404 |
| 413 InitializePipeline(PIPELINE_OK); | 405 InitializePipeline(PIPELINE_OK); |
| 414 EXPECT_FALSE(pipeline_->HasAudio()); | 406 EXPECT_FALSE(pipeline_->HasAudio()); |
| 415 EXPECT_TRUE(pipeline_->HasVideo()); | 407 EXPECT_TRUE(pipeline_->HasVideo()); |
| 416 } | 408 } |
| 417 | 409 |
| 418 TEST_F(PipelineTest, AudioVideoStream) { | 410 TEST_F(PipelineTest, AudioVideoStream) { |
| 419 CreateAudioStream(); | 411 CreateAudioStream(); |
| 420 CreateVideoStream(); | 412 CreateVideoStream(); |
| 421 MockDemuxerStreamVector streams; | 413 MockDemuxerStreamVector streams; |
| 422 streams.push_back(audio_stream()); | 414 streams.push_back(audio_stream()); |
| 423 streams.push_back(video_stream()); | 415 streams.push_back(video_stream()); |
| 424 | 416 |
| 425 InitializeDemuxer(&streams); | 417 InitializeDemuxer(&streams); |
| 426 InitializeAudioDecoder(audio_stream()); | 418 InitializeAudioRenderer(audio_stream(), false); |
| 427 InitializeAudioRenderer(); | |
| 428 InitializeVideoRenderer(video_stream()); | 419 InitializeVideoRenderer(video_stream()); |
| 429 | 420 |
| 430 InitializePipeline(PIPELINE_OK); | 421 InitializePipeline(PIPELINE_OK); |
| 431 EXPECT_TRUE(pipeline_->HasAudio()); | 422 EXPECT_TRUE(pipeline_->HasAudio()); |
| 432 EXPECT_TRUE(pipeline_->HasVideo()); | 423 EXPECT_TRUE(pipeline_->HasVideo()); |
| 433 } | 424 } |
| 434 | 425 |
| 435 TEST_F(PipelineTest, Seek) { | 426 TEST_F(PipelineTest, Seek) { |
| 436 CreateAudioStream(); | 427 CreateAudioStream(); |
| 437 CreateVideoStream(); | 428 CreateVideoStream(); |
| 438 MockDemuxerStreamVector streams; | 429 MockDemuxerStreamVector streams; |
| 439 streams.push_back(audio_stream()); | 430 streams.push_back(audio_stream()); |
| 440 streams.push_back(video_stream()); | 431 streams.push_back(video_stream()); |
| 441 | 432 |
| 442 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); | 433 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); |
| 443 InitializeAudioDecoder(audio_stream()); | 434 InitializeAudioRenderer(audio_stream(), false); |
| 444 InitializeAudioRenderer(); | |
| 445 InitializeVideoRenderer(video_stream()); | 435 InitializeVideoRenderer(video_stream()); |
| 446 | 436 |
| 447 // Initialize then seek! | 437 // Initialize then seek! |
| 448 InitializePipeline(PIPELINE_OK); | 438 InitializePipeline(PIPELINE_OK); |
| 449 | 439 |
| 450 // Every filter should receive a call to Seek(). | 440 // Every filter should receive a call to Seek(). |
| 451 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); | 441 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); |
| 452 ExpectSeek(expected); | 442 ExpectSeek(expected); |
| 453 DoSeek(expected); | 443 DoSeek(expected); |
| 454 } | 444 } |
| 455 | 445 |
| 456 TEST_F(PipelineTest, SetVolume) { | 446 TEST_F(PipelineTest, SetVolume) { |
| 457 CreateAudioStream(); | 447 CreateAudioStream(); |
| 458 MockDemuxerStreamVector streams; | 448 MockDemuxerStreamVector streams; |
| 459 streams.push_back(audio_stream()); | 449 streams.push_back(audio_stream()); |
| 460 | 450 |
| 461 InitializeDemuxer(&streams); | 451 InitializeDemuxer(&streams); |
| 462 InitializeAudioDecoder(audio_stream()); | 452 InitializeAudioRenderer(audio_stream(), false); |
| 463 InitializeAudioRenderer(); | |
| 464 | 453 |
| 465 // The audio renderer should receive a call to SetVolume(). | 454 // The audio renderer should receive a call to SetVolume(). |
| 466 float expected = 0.5f; | 455 float expected = 0.5f; |
| 467 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); | 456 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); |
| 468 | 457 |
| 469 // Initialize then set volume! | 458 // Initialize then set volume! |
| 470 InitializePipeline(PIPELINE_OK); | 459 InitializePipeline(PIPELINE_OK); |
| 471 pipeline_->SetVolume(expected); | 460 pipeline_->SetVolume(expected); |
| 472 } | 461 } |
| 473 | 462 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 } | 528 } |
| 540 | 529 |
| 541 TEST_F(PipelineTest, DisableAudioRenderer) { | 530 TEST_F(PipelineTest, DisableAudioRenderer) { |
| 542 CreateAudioStream(); | 531 CreateAudioStream(); |
| 543 CreateVideoStream(); | 532 CreateVideoStream(); |
| 544 MockDemuxerStreamVector streams; | 533 MockDemuxerStreamVector streams; |
| 545 streams.push_back(audio_stream()); | 534 streams.push_back(audio_stream()); |
| 546 streams.push_back(video_stream()); | 535 streams.push_back(video_stream()); |
| 547 | 536 |
| 548 InitializeDemuxer(&streams); | 537 InitializeDemuxer(&streams); |
| 549 InitializeAudioDecoder(audio_stream()); | 538 InitializeAudioRenderer(audio_stream(), false); |
| 550 InitializeAudioRenderer(); | |
| 551 InitializeVideoRenderer(video_stream()); | 539 InitializeVideoRenderer(video_stream()); |
| 552 | 540 |
| 553 InitializePipeline(PIPELINE_OK); | 541 InitializePipeline(PIPELINE_OK); |
| 554 EXPECT_TRUE(pipeline_->HasAudio()); | 542 EXPECT_TRUE(pipeline_->HasAudio()); |
| 555 EXPECT_TRUE(pipeline_->HasVideo()); | 543 EXPECT_TRUE(pipeline_->HasVideo()); |
| 556 | 544 |
| 557 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); | 545 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); |
| 558 pipeline_->OnAudioDisabled(); | 546 pipeline_->OnAudioDisabled(); |
| 559 | 547 |
| 560 // Verify that ended event is fired when video ends. | 548 // Verify that ended event is fired when video ends. |
| 561 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 549 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 562 pipeline_->OnVideoRendererEnded(); | 550 pipeline_->OnVideoRendererEnded(); |
| 563 } | 551 } |
| 564 | 552 |
| 565 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { | 553 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { |
| 566 CreateAudioStream(); | 554 CreateAudioStream(); |
| 567 CreateVideoStream(); | 555 CreateVideoStream(); |
| 568 MockDemuxerStreamVector streams; | 556 MockDemuxerStreamVector streams; |
| 569 streams.push_back(audio_stream()); | 557 streams.push_back(audio_stream()); |
| 570 streams.push_back(video_stream()); | 558 streams.push_back(video_stream()); |
| 571 | 559 |
| 572 InitializeDemuxer(&streams); | 560 InitializeDemuxer(&streams); |
| 573 InitializeAudioDecoder(audio_stream()); | 561 InitializeAudioRenderer(audio_stream(), true); |
| 574 InitializeAudioRenderer(true); | |
| 575 InitializeVideoRenderer(video_stream()); | 562 InitializeVideoRenderer(video_stream()); |
| 576 | 563 |
| 577 EXPECT_CALL(*mocks_->demuxer(), | 564 EXPECT_CALL(*mocks_->demuxer(), |
| 578 OnAudioRendererDisabled()); | 565 OnAudioRendererDisabled()); |
| 579 | 566 |
| 580 InitializePipeline(PIPELINE_OK); | 567 InitializePipeline(PIPELINE_OK); |
| 581 EXPECT_FALSE(pipeline_->HasAudio()); | 568 EXPECT_FALSE(pipeline_->HasAudio()); |
| 582 EXPECT_TRUE(pipeline_->HasVideo()); | 569 EXPECT_TRUE(pipeline_->HasVideo()); |
| 583 | 570 |
| 584 // Verify that ended event is fired when video ends. | 571 // Verify that ended event is fired when video ends. |
| 585 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 572 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 586 pipeline_->OnVideoRendererEnded(); | 573 pipeline_->OnVideoRendererEnded(); |
| 587 } | 574 } |
| 588 | 575 |
| 589 TEST_F(PipelineTest, EndedCallback) { | 576 TEST_F(PipelineTest, EndedCallback) { |
| 590 CreateAudioStream(); | 577 CreateAudioStream(); |
| 591 CreateVideoStream(); | 578 CreateVideoStream(); |
| 592 MockDemuxerStreamVector streams; | 579 MockDemuxerStreamVector streams; |
| 593 streams.push_back(audio_stream()); | 580 streams.push_back(audio_stream()); |
| 594 streams.push_back(video_stream()); | 581 streams.push_back(video_stream()); |
| 595 | 582 |
| 596 InitializeDemuxer(&streams); | 583 InitializeDemuxer(&streams); |
| 597 InitializeAudioDecoder(audio_stream()); | 584 InitializeAudioRenderer(audio_stream(), false); |
| 598 InitializeAudioRenderer(); | |
| 599 InitializeVideoRenderer(video_stream()); | 585 InitializeVideoRenderer(video_stream()); |
| 600 InitializePipeline(PIPELINE_OK); | 586 InitializePipeline(PIPELINE_OK); |
| 601 | 587 |
| 602 // The ended callback shouldn't run until both renderers have ended. | 588 // The ended callback shouldn't run until both renderers have ended. |
| 603 pipeline_->OnAudioRendererEnded(); | 589 pipeline_->OnAudioRendererEnded(); |
| 604 message_loop_.RunAllPending(); | 590 message_loop_.RunAllPending(); |
| 605 | 591 |
| 606 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 592 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 607 pipeline_->OnVideoRendererEnded(); | 593 pipeline_->OnVideoRendererEnded(); |
| 608 message_loop_.RunAllPending(); | 594 message_loop_.RunAllPending(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 621 CreateVideoStream(); | 607 CreateVideoStream(); |
| 622 MockDemuxerStreamVector streams; | 608 MockDemuxerStreamVector streams; |
| 623 streams.push_back(audio_stream()); | 609 streams.push_back(audio_stream()); |
| 624 streams.push_back(video_stream()); | 610 streams.push_back(video_stream()); |
| 625 | 611 |
| 626 // Replace the clock so we can simulate wallclock time advancing w/o using | 612 // Replace the clock so we can simulate wallclock time advancing w/o using |
| 627 // Sleep(). | 613 // Sleep(). |
| 628 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); | 614 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); |
| 629 | 615 |
| 630 InitializeDemuxer(&streams, duration); | 616 InitializeDemuxer(&streams, duration); |
| 631 InitializeAudioDecoder(audio_stream()); | 617 InitializeAudioRenderer(audio_stream(), false); |
| 632 InitializeAudioRenderer(); | |
| 633 InitializeVideoRenderer(video_stream()); | 618 InitializeVideoRenderer(video_stream()); |
| 634 InitializePipeline(PIPELINE_OK); | 619 InitializePipeline(PIPELINE_OK); |
| 635 | 620 |
| 636 EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue()); | 621 EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue()); |
| 637 | 622 |
| 638 float playback_rate = 1.0f; | 623 float playback_rate = 1.0f; |
| 639 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 624 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
| 640 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(playback_rate)); | 625 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(playback_rate)); |
| 641 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 626 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
| 642 pipeline_->SetPlaybackRate(playback_rate); | 627 pipeline_->SetPlaybackRate(playback_rate); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 665 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 650 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 666 pipeline_->OnVideoRendererEnded(); | 651 pipeline_->OnVideoRendererEnded(); |
| 667 } | 652 } |
| 668 | 653 |
| 669 TEST_F(PipelineTest, ErrorDuringSeek) { | 654 TEST_F(PipelineTest, ErrorDuringSeek) { |
| 670 CreateAudioStream(); | 655 CreateAudioStream(); |
| 671 MockDemuxerStreamVector streams; | 656 MockDemuxerStreamVector streams; |
| 672 streams.push_back(audio_stream()); | 657 streams.push_back(audio_stream()); |
| 673 | 658 |
| 674 InitializeDemuxer(&streams); | 659 InitializeDemuxer(&streams); |
| 675 InitializeAudioDecoder(audio_stream()); | 660 InitializeAudioRenderer(audio_stream(), false); |
| 676 InitializeAudioRenderer(); | |
| 677 InitializePipeline(PIPELINE_OK); | 661 InitializePipeline(PIPELINE_OK); |
| 678 | 662 |
| 679 float playback_rate = 1.0f; | 663 float playback_rate = 1.0f; |
| 680 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 664 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
| 681 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 665 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
| 682 pipeline_->SetPlaybackRate(playback_rate); | 666 pipeline_->SetPlaybackRate(playback_rate); |
| 683 message_loop_.RunAllPending(); | 667 message_loop_.RunAllPending(); |
| 684 | 668 |
| 685 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | 669 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); |
| 686 | 670 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 // No additional tasks should be queued as a result of these calls. | 705 // No additional tasks should be queued as a result of these calls. |
| 722 message_loop->AssertIdle(); | 706 message_loop->AssertIdle(); |
| 723 } | 707 } |
| 724 | 708 |
| 725 TEST_F(PipelineTest, NoMessageDuringTearDownFromError) { | 709 TEST_F(PipelineTest, NoMessageDuringTearDownFromError) { |
| 726 CreateAudioStream(); | 710 CreateAudioStream(); |
| 727 MockDemuxerStreamVector streams; | 711 MockDemuxerStreamVector streams; |
| 728 streams.push_back(audio_stream()); | 712 streams.push_back(audio_stream()); |
| 729 | 713 |
| 730 InitializeDemuxer(&streams); | 714 InitializeDemuxer(&streams); |
| 731 InitializeAudioDecoder(audio_stream()); | 715 InitializeAudioRenderer(audio_stream(), false); |
| 732 InitializeAudioRenderer(); | |
| 733 InitializePipeline(PIPELINE_OK); | 716 InitializePipeline(PIPELINE_OK); |
| 734 | 717 |
| 735 // Trigger additional requests on the pipeline during tear down from error. | 718 // Trigger additional requests on the pipeline during tear down from error. |
| 736 base::Callback<void(PipelineStatus)> cb = base::Bind( | 719 base::Callback<void(PipelineStatus)> cb = base::Bind( |
| 737 &TestNoCallsAfterError, pipeline_, &message_loop_); | 720 &TestNoCallsAfterError, pipeline_, &message_loop_); |
| 738 ON_CALL(callbacks_, OnError(_)) | 721 ON_CALL(callbacks_, OnError(_)) |
| 739 .WillByDefault(Invoke(&cb, &base::Callback<void(PipelineStatus)>::Run)); | 722 .WillByDefault(Invoke(&cb, &base::Callback<void(PipelineStatus)>::Run)); |
| 740 | 723 |
| 741 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | 724 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); |
| 742 | 725 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 time_cb.Run(base::TimeDelta::FromMilliseconds(time_in_ms), | 785 time_cb.Run(base::TimeDelta::FromMilliseconds(time_in_ms), |
| 803 base::TimeDelta::FromMilliseconds(max_time_in_ms)); | 786 base::TimeDelta::FromMilliseconds(max_time_in_ms)); |
| 804 } | 787 } |
| 805 | 788 |
| 806 TEST_F(PipelineTest, AudioTimeUpdateDuringSeek) { | 789 TEST_F(PipelineTest, AudioTimeUpdateDuringSeek) { |
| 807 CreateAudioStream(); | 790 CreateAudioStream(); |
| 808 MockDemuxerStreamVector streams; | 791 MockDemuxerStreamVector streams; |
| 809 streams.push_back(audio_stream()); | 792 streams.push_back(audio_stream()); |
| 810 | 793 |
| 811 InitializeDemuxer(&streams); | 794 InitializeDemuxer(&streams); |
| 812 InitializeAudioDecoder(audio_stream()); | 795 InitializeAudioRenderer(audio_stream(), false); |
| 813 InitializeAudioRenderer(); | |
| 814 InitializePipeline(PIPELINE_OK); | 796 InitializePipeline(PIPELINE_OK); |
| 815 | 797 |
| 816 float playback_rate = 1.0f; | 798 float playback_rate = 1.0f; |
| 817 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 799 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
| 818 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 800 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
| 819 pipeline_->SetPlaybackRate(playback_rate); | 801 pipeline_->SetPlaybackRate(playback_rate); |
| 820 message_loop_.RunAllPending(); | 802 message_loop_.RunAllPending(); |
| 821 | 803 |
| 822 // Provide an initial time update so that the pipeline transitions out of the | 804 // Provide an initial time update so that the pipeline transitions out of the |
| 823 // "waiting for time update" state. | 805 // "waiting for time update" state. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 // Test that different-thread, some-delay callback (the expected common case) | 892 // Test that different-thread, some-delay callback (the expected common case) |
| 911 // works correctly. | 893 // works correctly. |
| 912 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 894 TEST(PipelineStatusNotificationTest, DelayedCallback) { |
| 913 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); | 895 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); |
| 914 } | 896 } |
| 915 | 897 |
| 916 class PipelineTeardownTest : public PipelineTest { | 898 class PipelineTeardownTest : public PipelineTest { |
| 917 public: | 899 public: |
| 918 enum TeardownState { | 900 enum TeardownState { |
| 919 kInitDemuxer, | 901 kInitDemuxer, |
| 920 kInitAudioDecoder, | |
| 921 kInitAudioRenderer, | 902 kInitAudioRenderer, |
| 922 kInitVideoRenderer, | 903 kInitVideoRenderer, |
| 923 kPausing, | 904 kPausing, |
| 924 kFlushing, | 905 kFlushing, |
| 925 kSeeking, | 906 kSeeking, |
| 926 kPrerolling, | 907 kPrerolling, |
| 927 kStarting, | 908 kStarting, |
| 928 kPlaying, | 909 kPlaying, |
| 929 }; | 910 }; |
| 930 | 911 |
| 931 enum StopOrError { | 912 enum StopOrError { |
| 932 kStop, | 913 kStop, |
| 933 kError, | 914 kError, |
| 934 }; | 915 }; |
| 935 | 916 |
| 936 PipelineTeardownTest() {} | 917 PipelineTeardownTest() {} |
| 937 virtual ~PipelineTeardownTest() {} | 918 virtual ~PipelineTeardownTest() {} |
| 938 | 919 |
| 939 void RunTest(TeardownState state, StopOrError stop_or_error) { | 920 void RunTest(TeardownState state, StopOrError stop_or_error) { |
| 940 switch (state) { | 921 switch (state) { |
| 941 case kInitDemuxer: | 922 case kInitDemuxer: |
| 942 case kInitAudioDecoder: | |
| 943 case kInitAudioRenderer: | 923 case kInitAudioRenderer: |
| 944 case kInitVideoRenderer: | 924 case kInitVideoRenderer: |
| 945 DoInitialize(state, stop_or_error); | 925 DoInitialize(state, stop_or_error); |
| 946 break; | 926 break; |
| 947 | 927 |
| 948 case kPausing: | 928 case kPausing: |
| 949 case kFlushing: | 929 case kFlushing: |
| 950 case kSeeking: | 930 case kSeeking: |
| 951 case kPrerolling: | 931 case kPrerolling: |
| 952 case kStarting: | 932 case kStarting: |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 return status; | 981 return status; |
| 1002 } | 982 } |
| 1003 | 983 |
| 1004 CreateAudioStream(); | 984 CreateAudioStream(); |
| 1005 CreateVideoStream(); | 985 CreateVideoStream(); |
| 1006 MockDemuxerStreamVector streams; | 986 MockDemuxerStreamVector streams; |
| 1007 streams.push_back(audio_stream()); | 987 streams.push_back(audio_stream()); |
| 1008 streams.push_back(video_stream()); | 988 streams.push_back(video_stream()); |
| 1009 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); | 989 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); |
| 1010 | 990 |
| 1011 if (state == kInitAudioDecoder) { | 991 if (state == kInitAudioRenderer) { |
| 1012 if (stop_or_error == kStop) { | 992 if (stop_or_error == kStop) { |
| 1013 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(_, _, _)) | 993 EXPECT_CALL(*mocks_->audio_renderer(), |
| 1014 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); | 994 Initialize(_, _, _, _, _, _, _, _, _)) |
| 995 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB2())); |
| 1015 EXPECT_CALL(callbacks_, OnStop()); | 996 EXPECT_CALL(callbacks_, OnStop()); |
| 1016 } else { | 997 } else { |
| 1017 status = PIPELINE_ERROR_DECODE; | 998 status = PIPELINE_ERROR_INITIALIZATION_FAILED; |
| 1018 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(_, _, _)) | 999 EXPECT_CALL(*mocks_->audio_renderer(), |
| 1019 .WillOnce(RunPipelineStatusCBWithStatus(status)); | 1000 Initialize(_, _, _, _, _, _, _, _, _)) |
| 1001 .WillOnce(RunPipelineStatusCB2WithStatus(status)); |
| 1020 } | 1002 } |
| 1021 | 1003 |
| 1022 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | 1004 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| 1023 return status; | |
| 1024 } | |
| 1025 | |
| 1026 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(_, _, _)) | |
| 1027 .WillOnce(RunPipelineStatusCB()); | |
| 1028 | |
| 1029 if (state == kInitAudioRenderer) { | |
| 1030 if (stop_or_error == kStop) { | |
| 1031 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(_, _, _, _, _, _, _)) | |
| 1032 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); | |
| 1033 EXPECT_CALL(callbacks_, OnStop()); | |
| 1034 } else { | |
| 1035 status = PIPELINE_ERROR_INITIALIZATION_FAILED; | |
| 1036 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(_, _, _, _, _, _, _)) | |
| 1037 .WillOnce(RunPipelineStatusCBWithStatus(status)); | |
| 1038 } | |
| 1039 | |
| 1040 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 1041 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | 1005 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| 1042 return status; | 1006 return status; |
| 1043 } | 1007 } |
| 1044 | 1008 |
| 1045 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(_, _, _, _, _, _, _)) | 1009 EXPECT_CALL(*mocks_->audio_renderer(), |
| 1046 .WillOnce(RunPipelineStatusCB()); | 1010 Initialize(_, _, _, _, _, _, _, _, _)) |
| 1011 .WillOnce(RunPipelineStatusCB2()); |
| 1047 | 1012 |
| 1048 if (state == kInitVideoRenderer) { | 1013 if (state == kInitVideoRenderer) { |
| 1049 if (stop_or_error == kStop) { | 1014 if (stop_or_error == kStop) { |
| 1050 EXPECT_CALL(*mocks_->video_renderer(), | 1015 EXPECT_CALL(*mocks_->video_renderer(), |
| 1051 Initialize(_, _, _, _, _, _, _, _, _, _)) | 1016 Initialize(_, _, _, _, _, _, _, _, _, _)) |
| 1052 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB2())); | 1017 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB2())); |
| 1053 EXPECT_CALL(callbacks_, OnStop()); | 1018 EXPECT_CALL(callbacks_, OnStop()); |
| 1054 } else { | 1019 } else { |
| 1055 status = PIPELINE_ERROR_INITIALIZATION_FAILED; | 1020 status = PIPELINE_ERROR_INITIALIZATION_FAILED; |
| 1056 EXPECT_CALL(*mocks_->video_renderer(), | 1021 EXPECT_CALL(*mocks_->video_renderer(), |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1225 | 1190 |
| 1226 DISALLOW_COPY_AND_ASSIGN(PipelineTeardownTest); | 1191 DISALLOW_COPY_AND_ASSIGN(PipelineTeardownTest); |
| 1227 }; | 1192 }; |
| 1228 | 1193 |
| 1229 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \ | 1194 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \ |
| 1230 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \ | 1195 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \ |
| 1231 RunTest(k##state, k##stop_or_error); \ | 1196 RunTest(k##state, k##stop_or_error); \ |
| 1232 } | 1197 } |
| 1233 | 1198 |
| 1234 INSTANTIATE_TEARDOWN_TEST(Stop, InitDemuxer); | 1199 INSTANTIATE_TEARDOWN_TEST(Stop, InitDemuxer); |
| 1235 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioDecoder); | |
| 1236 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioRenderer); | 1200 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioRenderer); |
| 1237 INSTANTIATE_TEARDOWN_TEST(Stop, InitVideoRenderer); | 1201 INSTANTIATE_TEARDOWN_TEST(Stop, InitVideoRenderer); |
| 1238 INSTANTIATE_TEARDOWN_TEST(Stop, Pausing); | 1202 INSTANTIATE_TEARDOWN_TEST(Stop, Pausing); |
| 1239 INSTANTIATE_TEARDOWN_TEST(Stop, Flushing); | 1203 INSTANTIATE_TEARDOWN_TEST(Stop, Flushing); |
| 1240 INSTANTIATE_TEARDOWN_TEST(Stop, Seeking); | 1204 INSTANTIATE_TEARDOWN_TEST(Stop, Seeking); |
| 1241 INSTANTIATE_TEARDOWN_TEST(Stop, Prerolling); | 1205 INSTANTIATE_TEARDOWN_TEST(Stop, Prerolling); |
| 1242 INSTANTIATE_TEARDOWN_TEST(Stop, Starting); | 1206 INSTANTIATE_TEARDOWN_TEST(Stop, Starting); |
| 1243 INSTANTIATE_TEARDOWN_TEST(Stop, Playing); | 1207 INSTANTIATE_TEARDOWN_TEST(Stop, Playing); |
| 1244 | 1208 |
| 1245 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer); | 1209 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer); |
| 1246 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioDecoder); | |
| 1247 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); | 1210 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); |
| 1248 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); | 1211 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); |
| 1249 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); | 1212 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); |
| 1250 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); | 1213 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); |
| 1251 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); | 1214 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); |
| 1252 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); | 1215 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); |
| 1253 INSTANTIATE_TEARDOWN_TEST(Error, Starting); | 1216 INSTANTIATE_TEARDOWN_TEST(Error, Starting); |
| 1254 INSTANTIATE_TEARDOWN_TEST(Error, Playing); | 1217 INSTANTIATE_TEARDOWN_TEST(Error, Playing); |
| 1255 | 1218 |
| 1256 } // namespace media | 1219 } // namespace media |
| OLD | NEW |