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 "media/filters/pipeline_integration_test_base.h" | 5 #include "media/filters/pipeline_integration_test_base.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "media/base/cdm_callback_promise.h" | 12 #include "media/base/cdm_callback_promise.h" |
| 13 #include "media/base/cdm_context.h" | 13 #include "media/base/cdm_context.h" |
| 14 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
| 15 #include "media/base/media.h" | |
| 15 #include "media/base/media_keys.h" | 16 #include "media/base/media_keys.h" |
| 16 #include "media/base/media_switches.h" | 17 #include "media/base/media_switches.h" |
| 17 #include "media/base/test_data_util.h" | 18 #include "media/base/test_data_util.h" |
| 18 #include "media/cdm/aes_decryptor.h" | 19 #include "media/cdm/aes_decryptor.h" |
| 19 #include "media/cdm/json_web_key.h" | 20 #include "media/cdm/json_web_key.h" |
| 20 #include "media/filters/chunk_demuxer.h" | 21 #include "media/filters/chunk_demuxer.h" |
| 21 #include "media/filters/renderer_impl.h" | 22 #include "media/filters/renderer_impl.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 23 | 24 |
| 25 #if defined(MOJO_RENDERER) | |
| 26 #include "media/mojo/services/mojo_renderer_impl.h" | |
| 27 #include "mojo/public/cpp/application/application_impl.h" | |
| 28 #include "mojo/public/cpp/application/application_test_base.h" | |
| 29 #include "mojo/public/cpp/application/connect.h" | |
| 30 #endif | |
| 31 | |
| 24 using testing::_; | 32 using testing::_; |
| 25 using testing::AnyNumber; | 33 using testing::AnyNumber; |
| 26 using testing::AtLeast; | 34 using testing::AtLeast; |
| 27 using testing::AtMost; | 35 using testing::AtMost; |
| 28 using testing::SaveArg; | 36 using testing::SaveArg; |
| 29 | 37 |
| 30 namespace media { | 38 namespace media { |
| 31 | 39 |
| 32 const char kSourceId[] = "SourceId"; | 40 const char kSourceId[] = "SourceId"; |
| 33 const char kCencInitDataType[] = "cenc"; | 41 const char kCencInitDataType[] = "cenc"; |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 550 scoped_refptr<DecoderBuffer> file_data_; | 558 scoped_refptr<DecoderBuffer> file_data_; |
| 551 int current_position_; | 559 int current_position_; |
| 552 int initial_append_size_; | 560 int initial_append_size_; |
| 553 std::string mimetype_; | 561 std::string mimetype_; |
| 554 ChunkDemuxer* chunk_demuxer_; | 562 ChunkDemuxer* chunk_demuxer_; |
| 555 scoped_ptr<Demuxer> owned_chunk_demuxer_; | 563 scoped_ptr<Demuxer> owned_chunk_demuxer_; |
| 556 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_; | 564 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_; |
| 557 base::TimeDelta last_timestamp_offset_; | 565 base::TimeDelta last_timestamp_offset_; |
| 558 }; | 566 }; |
| 559 | 567 |
| 560 class PipelineIntegrationTest | 568 #if defined(MOJO_RENDERER) |
| 561 : public testing::Test, | 569 class PipelineIntegrationTestHost : public mojo::test::ApplicationTestBase, |
| 562 public PipelineIntegrationTestBase { | 570 public PipelineIntegrationTestBase { |
| 571 public: | |
| 572 virtual ~PipelineIntegrationTestHost() { | |
| 573 // MessageLoop is already dead here... so we can't Stop() the pipeline here. | |
| 574 CHECK(!pipeline_->IsRunning()); | |
| 575 }; | |
| 576 | |
| 577 virtual void SetUp() override { | |
| 578 ApplicationTestBase::SetUp(); | |
| 579 | |
| 580 // TODO(dalecurtis): For some reason this isn't done... | |
| 581 if (!CommandLine::InitializedForCurrentProcess()) { | |
| 582 CommandLine::Init(0, NULL); | |
| 583 media::InitializeMediaLibraryForTesting(); | |
| 584 } | |
| 585 | |
| 586 // Creating the service provider will create a message loop which we need | |
| 587 // to share... | |
| 588 service_provider_ = application_impl() | |
| 589 ->ConnectToApplication("mojo:media") | |
| 590 ->GetServiceProvider(); | |
| 591 | |
| 592 CHECK(base::MessageLoop::current()); | |
| 593 Initialize(base::MessageLoop::current()); | |
| 594 } | |
| 595 | |
| 596 protected: | |
| 597 scoped_ptr<Renderer> CreateRenderer() override { | |
| 598 mojo::MediaRendererPtr mojo_media_renderer; | |
| 599 mojo::ConnectToService(service_provider_, &mojo_media_renderer); | |
| 600 return make_scoped_ptr(new MojoRendererImpl(message_loop_->task_runner(), | |
| 601 mojo_media_renderer.Pass())); | |
| 602 } | |
| 603 | |
| 604 private: | |
| 605 mojo::ServiceProvider* service_provider_; | |
| 606 }; | |
| 607 #else | |
| 608 class PipelineIntegrationTestHost : public testing::Test, | |
| 609 public PipelineIntegrationTestBase { | |
| 610 public: | |
| 611 virtual ~PipelineIntegrationTestHost() { | |
| 612 if (pipeline_->IsRunning()) | |
| 613 Stop(); | |
| 614 }; | |
| 615 | |
| 616 virtual void SetUp() override { Initialize(&test_message_loop_); } | |
| 617 | |
| 618 private: | |
| 619 base::MessageLoop test_message_loop_; | |
| 620 }; | |
| 621 #endif | |
|
xhwang
2014/12/15 22:22:39
Neat!
I thought about putting mojo related code
| |
| 622 | |
| 623 class PipelineIntegrationTest : public PipelineIntegrationTestHost { | |
| 563 public: | 624 public: |
| 564 void StartPipelineWithMediaSource(MockMediaSource* source) { | 625 void StartPipelineWithMediaSource(MockMediaSource* source) { |
| 565 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1)); | 626 EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1)); |
| 566 EXPECT_CALL(*this, OnMetadata(_)) | 627 EXPECT_CALL(*this, OnMetadata(_)) |
| 567 .Times(AtMost(1)) | 628 .Times(AtMost(1)) |
| 568 .WillRepeatedly(SaveArg<0>(&metadata_)); | 629 .WillRepeatedly(SaveArg<0>(&metadata_)); |
| 569 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) | 630 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) |
| 570 .Times(AtMost(1)); | 631 .Times(AtMost(1)); |
| 571 demuxer_ = source->GetDemuxer().Pass(); | 632 demuxer_ = source->GetDemuxer().Pass(); |
| 572 pipeline_->Start( | 633 pipeline_->Start( |
| 573 demuxer_.get(), CreateRenderer(), | 634 demuxer_.get(), CreateRenderer(), |
| 574 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), | 635 base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), |
| 575 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), | 636 base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), |
| 576 base::Bind(&PipelineIntegrationTest::OnStatusCallback, | 637 base::Bind(&PipelineIntegrationTest::OnStatusCallback, |
| 577 base::Unretained(this)), | 638 base::Unretained(this)), |
| 578 base::Bind(&PipelineIntegrationTest::OnMetadata, | 639 base::Bind(&PipelineIntegrationTest::OnMetadata, |
| 579 base::Unretained(this)), | 640 base::Unretained(this)), |
| 580 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged, | 641 base::Bind(&PipelineIntegrationTest::OnBufferingStateChanged, |
| 581 base::Unretained(this)), | 642 base::Unretained(this)), |
| 582 base::Bind(&PipelineIntegrationTest::OnVideoFramePaint, | 643 base::Bind(&PipelineIntegrationTest::OnVideoFramePaint, |
| 583 base::Unretained(this)), | 644 base::Unretained(this)), |
| 584 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack, | 645 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack, |
| 585 base::Unretained(this))); | 646 base::Unretained(this))); |
| 586 message_loop_.Run(); | 647 message_loop_->Run(); |
| 587 EXPECT_EQ(PIPELINE_OK, pipeline_status_); | 648 EXPECT_EQ(PIPELINE_OK, pipeline_status_); |
| 588 } | 649 } |
| 589 | 650 |
| 590 void StartHashedPipelineWithMediaSource(MockMediaSource* source) { | 651 void StartHashedPipelineWithMediaSource(MockMediaSource* source) { |
| 591 hashing_enabled_ = true; | 652 hashing_enabled_ = true; |
| 592 StartPipelineWithMediaSource(source); | 653 StartPipelineWithMediaSource(source); |
| 593 } | 654 } |
| 594 | 655 |
| 595 void StartPipelineWithEncryptedMedia( | 656 void StartPipelineWithEncryptedMedia( |
| 596 MockMediaSource* source, | 657 MockMediaSource* source, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 621 base::Unretained(this)), | 682 base::Unretained(this)), |
| 622 base::Bind(&PipelineIntegrationTest::OnVideoFramePaint, | 683 base::Bind(&PipelineIntegrationTest::OnVideoFramePaint, |
| 623 base::Unretained(this)), | 684 base::Unretained(this)), |
| 624 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack, | 685 base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack, |
| 625 base::Unretained(this))); | 686 base::Unretained(this))); |
| 626 | 687 |
| 627 source->set_encrypted_media_init_data_cb( | 688 source->set_encrypted_media_init_data_cb( |
| 628 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData, | 689 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData, |
| 629 base::Unretained(encrypted_media))); | 690 base::Unretained(encrypted_media))); |
| 630 | 691 |
| 631 message_loop_.Run(); | 692 message_loop_->Run(); |
| 632 EXPECT_EQ(PIPELINE_OK, pipeline_status_); | 693 EXPECT_EQ(PIPELINE_OK, pipeline_status_); |
| 633 } | 694 } |
| 634 | 695 |
| 635 // Verifies that seeking works properly for ChunkDemuxer when the | 696 // Verifies that seeking works properly for ChunkDemuxer when the |
| 636 // seek happens while there is a pending read on the ChunkDemuxer | 697 // seek happens while there is a pending read on the ChunkDemuxer |
| 637 // and no data is available. | 698 // and no data is available. |
| 638 bool TestSeekDuringRead(const std::string& filename, | 699 bool TestSeekDuringRead(const std::string& filename, |
| 639 const std::string& mimetype, | 700 const std::string& mimetype, |
| 640 int initial_append_size, | 701 int initial_append_size, |
| 641 base::TimeDelta start_seek_time, | 702 base::TimeDelta start_seek_time, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 663 return true; | 724 return true; |
| 664 } | 725 } |
| 665 }; | 726 }; |
| 666 | 727 |
| 667 TEST_F(PipelineIntegrationTest, BasicPlayback) { | 728 TEST_F(PipelineIntegrationTest, BasicPlayback) { |
| 668 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm")); | 729 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm")); |
| 669 | 730 |
| 670 Play(); | 731 Play(); |
| 671 | 732 |
| 672 ASSERT_TRUE(WaitUntilOnEnded()); | 733 ASSERT_TRUE(WaitUntilOnEnded()); |
| 734 | |
| 735 // TODO(dalecurtis): Have to add this to every test since the MessageLoop dies | |
| 736 // before ~PipelineIntegrationTest(Base|Host|Etc). | |
| 737 Stop(); | |
| 673 } | 738 } |
| 674 | 739 |
| 675 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOgg) { | 740 TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOgg) { |
| 676 ASSERT_EQ(PIPELINE_OK, Start("bear-opus.ogg")); | 741 ASSERT_EQ(PIPELINE_OK, Start("bear-opus.ogg")); |
| 677 | 742 |
| 678 Play(); | 743 Play(); |
| 679 | 744 |
| 680 ASSERT_TRUE(WaitUntilOnEnded()); | 745 ASSERT_TRUE(WaitUntilOnEnded()); |
| 681 } | 746 } |
| 682 | 747 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 909 StartPipelineWithEncryptedMedia(&source, &encrypted_media); | 974 StartPipelineWithEncryptedMedia(&source, &encrypted_media); |
| 910 | 975 |
| 911 scoped_refptr<DecoderBuffer> second_file = | 976 scoped_refptr<DecoderBuffer> second_file = |
| 912 ReadTestDataFile("bear-640x360-av_enc-av.webm"); | 977 ReadTestDataFile("bear-640x360-av_enc-av.webm"); |
| 913 | 978 |
| 914 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec), | 979 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec), |
| 915 second_file->data(), second_file->data_size()); | 980 second_file->data(), second_file->data_size()); |
| 916 | 981 |
| 917 source.EndOfStream(); | 982 source.EndOfStream(); |
| 918 | 983 |
| 919 message_loop_.Run(); | 984 message_loop_->Run(); |
| 920 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_); | 985 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_); |
| 921 | 986 |
| 922 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); | 987 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); |
| 923 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); | 988 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); |
| 924 // The second video was not added, so its time has not been added. | 989 // The second video was not added, so its time has not been added. |
| 925 EXPECT_EQ(k320WebMFileDurationMs, | 990 EXPECT_EQ(k320WebMFileDurationMs, |
| 926 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); | 991 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); |
| 927 | 992 |
| 928 Play(); | 993 Play(); |
| 929 | 994 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1163 StartPipelineWithEncryptedMedia(&source, &encrypted_media); | 1228 StartPipelineWithEncryptedMedia(&source, &encrypted_media); |
| 1164 | 1229 |
| 1165 scoped_refptr<DecoderBuffer> second_file = | 1230 scoped_refptr<DecoderBuffer> second_file = |
| 1166 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4"); | 1231 ReadTestDataFile("bear-1280x720-v_frag-cenc.mp4"); |
| 1167 | 1232 |
| 1168 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec), | 1233 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec), |
| 1169 second_file->data(), second_file->data_size()); | 1234 second_file->data(), second_file->data_size()); |
| 1170 | 1235 |
| 1171 source.EndOfStream(); | 1236 source.EndOfStream(); |
| 1172 | 1237 |
| 1173 message_loop_.Run(); | 1238 message_loop_->Run(); |
| 1174 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_); | 1239 EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_); |
| 1175 | 1240 |
| 1176 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); | 1241 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); |
| 1177 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); | 1242 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds()); |
| 1178 // The second video was not added, so its time has not been added. | 1243 // The second video was not added, so its time has not been added. |
| 1179 EXPECT_EQ(k640IsoFileDurationMs, | 1244 EXPECT_EQ(k640IsoFileDurationMs, |
| 1180 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); | 1245 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); |
| 1181 | 1246 |
| 1182 Play(); | 1247 Play(); |
| 1183 | 1248 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1611 | 1676 |
| 1612 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { | 1677 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { |
| 1613 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); | 1678 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); |
| 1614 Play(); | 1679 Play(); |
| 1615 ASSERT_TRUE(WaitUntilOnEnded()); | 1680 ASSERT_TRUE(WaitUntilOnEnded()); |
| 1616 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), | 1681 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), |
| 1617 demuxer_->GetStartTime()); | 1682 demuxer_->GetStartTime()); |
| 1618 } | 1683 } |
| 1619 | 1684 |
| 1620 } // namespace media | 1685 } // namespace media |
| OLD | NEW |