| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <deque> | 6 #include <deque> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 using ::testing::WithArgs; | 35 using ::testing::WithArgs; |
| 36 using ::testing::_; | 36 using ::testing::_; |
| 37 | 37 |
| 38 namespace media { | 38 namespace media { |
| 39 | 39 |
| 40 MATCHER(IsEndOfStreamBuffer, | 40 MATCHER(IsEndOfStreamBuffer, |
| 41 std::string(negation ? "isn't" : "is") + " end of stream") { | 41 std::string(negation ? "isn't" : "is") + " end of stream") { |
| 42 return arg->end_of_stream(); | 42 return arg->end_of_stream(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 const uint8 kEncryptedMediaInitData[] = { |
| 46 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, |
| 47 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, |
| 48 }; |
| 49 |
| 45 static void EosOnReadDone(bool* got_eos_buffer, | 50 static void EosOnReadDone(bool* got_eos_buffer, |
| 46 DemuxerStream::Status status, | 51 DemuxerStream::Status status, |
| 47 const scoped_refptr<DecoderBuffer>& buffer) { | 52 const scoped_refptr<DecoderBuffer>& buffer) { |
| 48 base::MessageLoop::current()->PostTask( | 53 base::MessageLoop::current()->PostTask( |
| 49 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 54 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 50 | 55 |
| 51 EXPECT_EQ(status, DemuxerStream::kOk); | 56 EXPECT_EQ(status, DemuxerStream::kOk); |
| 52 if (buffer->end_of_stream()) { | 57 if (buffer->end_of_stream()) { |
| 53 *got_eos_buffer = true; | 58 *got_eos_buffer = true; |
| 54 return; | 59 return; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 71 demuxer_->Stop(); | 76 demuxer_->Stop(); |
| 72 } | 77 } |
| 73 | 78 |
| 74 void CreateDemuxer(const std::string& name) { | 79 void CreateDemuxer(const std::string& name) { |
| 75 CHECK(!demuxer_); | 80 CHECK(!demuxer_); |
| 76 | 81 |
| 77 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); | 82 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); |
| 78 | 83 |
| 79 CreateDataSource(name); | 84 CreateDataSource(name); |
| 80 | 85 |
| 81 Demuxer::NeedKeyCB need_key_cb = | 86 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind( |
| 82 base::Bind(&FFmpegDemuxerTest::NeedKeyCB, base::Unretained(this)); | 87 &FFmpegDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this)); |
| 83 | 88 |
| 84 demuxer_.reset(new FFmpegDemuxer(message_loop_.message_loop_proxy(), | 89 demuxer_.reset(new FFmpegDemuxer( |
| 85 data_source_.get(), | 90 message_loop_.message_loop_proxy(), data_source_.get(), |
| 86 need_key_cb, | 91 encrypted_media_init_data_cb, new MediaLog())); |
| 87 new MediaLog())); | |
| 88 } | 92 } |
| 89 | 93 |
| 90 MOCK_METHOD1(CheckPoint, void(int v)); | 94 MOCK_METHOD1(CheckPoint, void(int v)); |
| 91 | 95 |
| 92 void InitializeDemuxerWithTimelineOffset(bool enable_text, | 96 void InitializeDemuxerWithTimelineOffset(bool enable_text, |
| 93 base::Time timeline_offset) { | 97 base::Time timeline_offset) { |
| 94 EXPECT_CALL(host_, SetDuration(_)); | 98 EXPECT_CALL(host_, SetDuration(_)); |
| 95 WaitableMessageLoopEvent event; | 99 WaitableMessageLoopEvent event; |
| 96 demuxer_->Initialize(&host_, event.GetPipelineStatusCB(), enable_text); | 100 demuxer_->Initialize(&host_, event.GetPipelineStatusCB(), enable_text); |
| 97 demuxer_->timeline_offset_ = timeline_offset; | 101 demuxer_->timeline_offset_ = timeline_offset; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 timestamp_us, | 176 timestamp_us, |
| 173 discard_front_padding, | 177 discard_front_padding, |
| 174 is_key_frame); | 178 is_key_frame); |
| 175 | 179 |
| 176 return base::Bind(&FFmpegDemuxerTest::OnReadDone, | 180 return base::Bind(&FFmpegDemuxerTest::OnReadDone, |
| 177 base::Unretained(this), | 181 base::Unretained(this), |
| 178 location, | 182 location, |
| 179 read_expectation); | 183 read_expectation); |
| 180 } | 184 } |
| 181 | 185 |
| 182 // TODO(xhwang): This is a workaround of the issue that move-only parameters | 186 MOCK_METHOD2(OnEncryptedMediaInitData, |
| 183 // are not supported in mocked methods. Remove this when the issue is fixed | 187 void(const std::string& init_data_type, |
| 184 // (http://code.google.com/p/googletest/issues/detail?id=395) or when we use | 188 const std::vector<uint8>& init_data)); |
| 185 // std::string instead of scoped_ptr<uint8[]> (http://crbug.com/130689). | |
| 186 MOCK_METHOD3(NeedKeyCBMock, void(const std::string& type, | |
| 187 const uint8* init_data, int init_data_size)); | |
| 188 void NeedKeyCB(const std::string& type, | |
| 189 const std::vector<uint8>& init_data) { | |
| 190 const uint8* init_data_ptr = init_data.empty() ? NULL : &init_data[0]; | |
| 191 NeedKeyCBMock(type, init_data_ptr, init_data.size()); | |
| 192 } | |
| 193 | 189 |
| 194 // Accessor to demuxer internals. | 190 // Accessor to demuxer internals. |
| 195 void set_duration_known(bool duration_known) { | 191 void set_duration_known(bool duration_known) { |
| 196 demuxer_->duration_known_ = duration_known; | 192 demuxer_->duration_known_ = duration_known; |
| 197 } | 193 } |
| 198 | 194 |
| 199 bool IsStreamStopped(DemuxerStream::Type type) { | 195 bool IsStreamStopped(DemuxerStream::Type type) { |
| 200 DemuxerStream* stream = demuxer_->GetStream(type); | 196 DemuxerStream* stream = demuxer_->GetStream(type); |
| 201 CHECK(stream); | 197 CHECK(stream); |
| 202 return !static_cast<FFmpegDemuxerStream*>(stream)->demuxer_; | 198 return !static_cast<FFmpegDemuxerStream*>(stream)->demuxer_; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 369 stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 374 ASSERT_TRUE(stream); | 370 ASSERT_TRUE(stream); |
| 375 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); | 371 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); |
| 376 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); | 372 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); |
| 377 | 373 |
| 378 // Unknown stream should never be present. | 374 // Unknown stream should never be present. |
| 379 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); | 375 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); |
| 380 } | 376 } |
| 381 | 377 |
| 382 TEST_F(FFmpegDemuxerTest, Initialize_Encrypted) { | 378 TEST_F(FFmpegDemuxerTest, Initialize_Encrypted) { |
| 383 EXPECT_CALL(*this, NeedKeyCBMock(kWebMInitDataType, NotNull(), | 379 EXPECT_CALL(*this, |
| 384 DecryptConfig::kDecryptionKeySize)) | 380 OnEncryptedMediaInitData( |
| 381 kWebMInitDataType, |
| 382 std::vector<uint8>(kEncryptedMediaInitData, |
| 383 kEncryptedMediaInitData + |
| 384 arraysize(kEncryptedMediaInitData)))) |
| 385 .Times(Exactly(2)); | 385 .Times(Exactly(2)); |
| 386 | 386 |
| 387 CreateDemuxer("bear-320x240-av_enc-av.webm"); | 387 CreateDemuxer("bear-320x240-av_enc-av.webm"); |
| 388 InitializeDemuxer(); | 388 InitializeDemuxer(); |
| 389 } | 389 } |
| 390 | 390 |
| 391 TEST_F(FFmpegDemuxerTest, Read_Audio) { | 391 TEST_F(FFmpegDemuxerTest, Read_Audio) { |
| 392 // We test that on a successful audio packet read. | 392 // We test that on a successful audio packet read. |
| 393 CreateDemuxer("bear-320x240.webm"); | 393 CreateDemuxer("bear-320x240.webm"); |
| 394 InitializeDemuxer(); | 394 InitializeDemuxer(); |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 InitializeDemuxer(); | 969 InitializeDemuxer(); |
| 970 | 970 |
| 971 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 971 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 972 ASSERT_TRUE(stream); | 972 ASSERT_TRUE(stream); |
| 973 ASSERT_EQ(VIDEO_ROTATION_270, stream->video_rotation()); | 973 ASSERT_EQ(VIDEO_ROTATION_270, stream->video_rotation()); |
| 974 } | 974 } |
| 975 | 975 |
| 976 #endif | 976 #endif |
| 977 | 977 |
| 978 } // namespace media | 978 } // namespace media |
| OLD | NEW |