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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 CHECK_NE(codecs_param_end, std::string::npos); | 610 CHECK_NE(codecs_param_end, std::string::npos); |
611 | 611 |
612 std::string codecs_param = mimetype_.substr( | 612 std::string codecs_param = mimetype_.substr( |
613 codecs_param_start, codecs_param_end - codecs_param_start); | 613 codecs_param_start, codecs_param_end - codecs_param_start); |
614 codecs = base::SplitString(codecs_param, ",", base::KEEP_WHITESPACE, | 614 codecs = base::SplitString(codecs_param, ",", base::KEEP_WHITESPACE, |
615 base::SPLIT_WANT_NONEMPTY); | 615 base::SPLIT_WANT_NONEMPTY); |
616 } | 616 } |
617 | 617 |
618 CHECK_EQ(chunk_demuxer_->AddId(kSourceId, type, codecs), ChunkDemuxer::kOk); | 618 CHECK_EQ(chunk_demuxer_->AddId(kSourceId, type, codecs), ChunkDemuxer::kOk); |
619 chunk_demuxer_->SetTracksWatcher( | 619 chunk_demuxer_->SetTracksWatcher( |
620 kSourceId, base::Bind(&MockMediaSource::InitSegmentReceivedWrapper, | 620 kSourceId, base::Bind(&MockMediaSource::InitSegmentReceived, |
621 base::Unretained(this))); | 621 base::Unretained(this))); |
622 | 622 |
623 AppendData(initial_append_size_); | 623 AppendData(initial_append_size_); |
624 } | 624 } |
625 | 625 |
626 void OnEncryptedMediaInitData(EmeInitDataType init_data_type, | 626 void OnEncryptedMediaInitData(EmeInitDataType init_data_type, |
627 const std::vector<uint8_t>& init_data) { | 627 const std::vector<uint8_t>& init_data) { |
628 DCHECK(!init_data.empty()); | 628 DCHECK(!init_data.empty()); |
629 CHECK(!encrypted_media_init_data_cb_.is_null()); | 629 CHECK(!encrypted_media_init_data_cb_.is_null()); |
630 encrypted_media_init_data_cb_.Run(init_data_type, init_data); | 630 encrypted_media_init_data_cb_.Run(init_data_type, init_data); |
631 } | 631 } |
632 | 632 |
633 base::TimeDelta last_timestamp_offset() const { | 633 base::TimeDelta last_timestamp_offset() const { |
634 return last_timestamp_offset_; | 634 return last_timestamp_offset_; |
635 } | 635 } |
636 | 636 |
637 // A workaround for gtest mocks not allowing moving scoped_ptrs. | 637 void InitSegmentReceived(scoped_ptr<MediaTracks> tracks) { |
638 void InitSegmentReceivedWrapper(scoped_ptr<MediaTracks> tracks) { | 638 CHECK(tracks.get()); |
639 InitSegmentReceived(tracks); | 639 EXPECT_GT(tracks->tracks().size(), 0u); |
| 640 CHECK(chunk_demuxer_); |
| 641 // Generate track ids. |
| 642 std::vector<unsigned> track_ids; |
| 643 for (size_t track_id = 1; track_id <= tracks->tracks().size(); ++track_id) { |
| 644 track_ids.push_back(track_id); |
| 645 } |
| 646 |
| 647 chunk_demuxer_->OnTrackIdsAssigned(*tracks.get(), track_ids); |
| 648 InitSegmentReceivedMock(tracks); |
640 } | 649 } |
641 | 650 |
642 MOCK_METHOD1(InitSegmentReceived, void(scoped_ptr<MediaTracks>&)); | 651 MOCK_METHOD1(InitSegmentReceivedMock, void(scoped_ptr<MediaTracks>&)); |
643 | 652 |
644 private: | 653 private: |
645 scoped_refptr<DecoderBuffer> file_data_; | 654 scoped_refptr<DecoderBuffer> file_data_; |
646 size_t current_position_; | 655 size_t current_position_; |
647 size_t initial_append_size_; | 656 size_t initial_append_size_; |
648 std::string mimetype_; | 657 std::string mimetype_; |
649 ChunkDemuxer* chunk_demuxer_; | 658 ChunkDemuxer* chunk_demuxer_; |
650 scoped_ptr<Demuxer> owned_chunk_demuxer_; | 659 scoped_ptr<Demuxer> owned_chunk_demuxer_; |
651 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_; | 660 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_; |
652 base::TimeDelta last_timestamp_offset_; | 661 base::TimeDelta last_timestamp_offset_; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 public: | 695 public: |
687 PipelineStatus StartPipelineWithMediaSource(MockMediaSource* source) { | 696 PipelineStatus StartPipelineWithMediaSource(MockMediaSource* source) { |
688 return StartPipelineWithMediaSource(source, kNormal); | 697 return StartPipelineWithMediaSource(source, kNormal); |
689 } | 698 } |
690 | 699 |
691 PipelineStatus StartPipelineWithMediaSource(MockMediaSource* source, | 700 PipelineStatus StartPipelineWithMediaSource(MockMediaSource* source, |
692 uint8_t test_type) { | 701 uint8_t test_type) { |
693 hashing_enabled_ = test_type & kHashed; | 702 hashing_enabled_ = test_type & kHashed; |
694 clockless_playback_ = test_type & kClockless; | 703 clockless_playback_ = test_type & kClockless; |
695 | 704 |
696 EXPECT_CALL(*source, InitSegmentReceived(_)).Times(AtLeast(1)); | 705 EXPECT_CALL(*source, InitSegmentReceivedMock(_)).Times(AtLeast(1)); |
697 EXPECT_CALL(*this, OnMetadata(_)) | 706 EXPECT_CALL(*this, OnMetadata(_)) |
698 .Times(AtMost(1)) | 707 .Times(AtMost(1)) |
699 .WillRepeatedly(SaveArg<0>(&metadata_)); | 708 .WillRepeatedly(SaveArg<0>(&metadata_)); |
700 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) | 709 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) |
701 .Times(AnyNumber()); | 710 .Times(AnyNumber()); |
702 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) | 711 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) |
703 .Times(AnyNumber()); | 712 .Times(AnyNumber()); |
704 | 713 |
705 // Encrypted content not used, so this is never called. | 714 // Encrypted content not used, so this is never called. |
706 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); | 715 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); |
(...skipping 13 matching lines...) Expand all Loading... |
720 base::Unretained(this)), | 729 base::Unretained(this)), |
721 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey, | 730 base::Bind(&PipelineIntegrationTest::OnWaitingForDecryptionKey, |
722 base::Unretained(this))); | 731 base::Unretained(this))); |
723 message_loop_.Run(); | 732 message_loop_.Run(); |
724 EXPECT_EQ(PIPELINE_OK, pipeline_status_); | 733 EXPECT_EQ(PIPELINE_OK, pipeline_status_); |
725 return pipeline_status_; | 734 return pipeline_status_; |
726 } | 735 } |
727 | 736 |
728 void StartPipelineWithEncryptedMedia(MockMediaSource* source, | 737 void StartPipelineWithEncryptedMedia(MockMediaSource* source, |
729 FakeEncryptedMedia* encrypted_media) { | 738 FakeEncryptedMedia* encrypted_media) { |
730 EXPECT_CALL(*source, InitSegmentReceived(_)).Times(AtLeast(1)); | 739 EXPECT_CALL(*source, InitSegmentReceivedMock(_)).Times(AtLeast(1)); |
731 EXPECT_CALL(*this, OnMetadata(_)) | 740 EXPECT_CALL(*this, OnMetadata(_)) |
732 .Times(AtMost(1)) | 741 .Times(AtMost(1)) |
733 .WillRepeatedly(SaveArg<0>(&metadata_)); | 742 .WillRepeatedly(SaveArg<0>(&metadata_)); |
734 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) | 743 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) |
735 .Times(AnyNumber()); | 744 .Times(AnyNumber()); |
736 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) | 745 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) |
737 .Times(AnyNumber()); | 746 .Times(AnyNumber()); |
738 EXPECT_CALL(*this, DecryptorAttached(true)); | 747 EXPECT_CALL(*this, DecryptorAttached(true)); |
739 | 748 |
740 // Encrypted content used but keys provided in advance, so this is | 749 // Encrypted content used but keys provided in advance, so this is |
(...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2128 } | 2137 } |
2129 | 2138 |
2130 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { | 2139 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { |
2131 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); | 2140 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); |
2132 Play(); | 2141 Play(); |
2133 ASSERT_TRUE(WaitUntilOnEnded()); | 2142 ASSERT_TRUE(WaitUntilOnEnded()); |
2134 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), | 2143 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), |
2135 demuxer_->GetStartTime()); | 2144 demuxer_->GetStartTime()); |
2136 } | 2145 } |
2137 | 2146 |
| 2147 TEST_F(PipelineIntegrationTest, AudioTrackMuteUnmute) { |
| 2148 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm")); |
| 2149 |
| 2150 // Start playback and play a little, to ensure demuxer streams are created. |
| 2151 Play(); |
| 2152 ASSERT_TRUE( |
| 2153 WaitUntilCurrentTimeIsAfter(base::TimeDelta::FromMilliseconds(200))); |
| 2154 Pause(); |
| 2155 |
| 2156 const DemuxerStream* demux_stream = demuxer_->GetDemuxerStreamByTrackId(2); |
| 2157 EXPECT_NE(demux_stream, nullptr); |
| 2158 EXPECT_EQ(demux_stream->type(), DemuxerStream::AUDIO); |
| 2159 |
| 2160 // TODO(servolk): Find a way to verify that audio is really muted/unmuted. |
| 2161 // This should mute the audio stream. |
| 2162 std::vector<const DemuxerStream*> enabledAudioStreams; |
| 2163 pipeline_->OnEnabledAudioStreamsChanged(enabledAudioStreams); |
| 2164 |
| 2165 Play(); |
| 2166 ASSERT_TRUE( |
| 2167 WaitUntilCurrentTimeIsAfter(base::TimeDelta::FromMilliseconds(500))); |
| 2168 Pause(); |
| 2169 |
| 2170 // This should unmute the audio stream. |
| 2171 enabledAudioStreams.push_back(demux_stream); |
| 2172 pipeline_->OnEnabledAudioStreamsChanged(enabledAudioStreams); |
| 2173 |
| 2174 Play(); |
| 2175 ASSERT_TRUE(WaitUntilOnEnded()); |
| 2176 } |
| 2177 |
| 2178 TEST_F(PipelineIntegrationTest, VideoTrackSelectDeselect) { |
| 2179 ASSERT_EQ(PIPELINE_OK, Start("bear-320x240.webm")); |
| 2180 |
| 2181 // Start playback and play a little, to ensure demuxer streams are created. |
| 2182 Play(); |
| 2183 ASSERT_TRUE( |
| 2184 WaitUntilCurrentTimeIsAfter(base::TimeDelta::FromMilliseconds(200))); |
| 2185 Pause(); |
| 2186 |
| 2187 const DemuxerStream* demux_stream = demuxer_->GetDemuxerStreamByTrackId(1); |
| 2188 EXPECT_NE(demux_stream, nullptr); |
| 2189 EXPECT_EQ(demux_stream->type(), DemuxerStream::VIDEO); |
| 2190 |
| 2191 // Deselect video stream. |
| 2192 pipeline_->OnSelectedVideoStreamChanged(nullptr); |
| 2193 |
| 2194 Play(); |
| 2195 ASSERT_TRUE( |
| 2196 WaitUntilCurrentTimeIsAfter(base::TimeDelta::FromMilliseconds(500))); |
| 2197 Pause(); |
| 2198 |
| 2199 // Select video stream. |
| 2200 pipeline_->OnSelectedVideoStreamChanged(demux_stream); |
| 2201 |
| 2202 Play(); |
| 2203 ASSERT_TRUE(WaitUntilOnEnded()); |
| 2204 } |
| 2205 |
2138 } // namespace media | 2206 } // namespace media |
OLD | NEW |