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 <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/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "media/base/decrypt_config.h" | |
| 14 #include "media/base/mock_demuxer_host.h" | 15 #include "media/base/mock_demuxer_host.h" |
| 15 #include "media/base/test_helpers.h" | 16 #include "media/base/test_helpers.h" |
| 16 #include "media/ffmpeg/ffmpeg_common.h" | 17 #include "media/ffmpeg/ffmpeg_common.h" |
| 17 #include "media/filters/ffmpeg_demuxer.h" | 18 #include "media/filters/ffmpeg_demuxer.h" |
| 18 #include "media/filters/file_data_source.h" | 19 #include "media/filters/file_data_source.h" |
| 20 #include "media/webm/webm_crypto_helpers.h" | |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 22 |
| 21 using ::testing::AnyNumber; | 23 using ::testing::AnyNumber; |
| 22 using ::testing::DoAll; | 24 using ::testing::DoAll; |
| 25 using ::testing::Exactly; | |
| 23 using ::testing::InSequence; | 26 using ::testing::InSequence; |
| 24 using ::testing::Invoke; | 27 using ::testing::Invoke; |
| 28 using ::testing::NotNull; | |
| 25 using ::testing::Return; | 29 using ::testing::Return; |
| 26 using ::testing::SaveArg; | 30 using ::testing::SaveArg; |
| 27 using ::testing::SetArgPointee; | 31 using ::testing::SetArgPointee; |
| 28 using ::testing::StrictMock; | 32 using ::testing::StrictMock; |
| 29 using ::testing::WithArgs; | 33 using ::testing::WithArgs; |
| 30 using ::testing::_; | 34 using ::testing::_; |
| 31 | 35 |
| 32 namespace media { | 36 namespace media { |
| 33 | 37 |
| 34 MATCHER(IsEndOfStreamBuffer, | 38 MATCHER(IsEndOfStreamBuffer, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 } | 74 } |
| 71 | 75 |
| 72 void CreateDemuxer(const std::string& name) { | 76 void CreateDemuxer(const std::string& name) { |
| 73 CHECK(!demuxer_); | 77 CHECK(!demuxer_); |
| 74 | 78 |
| 75 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber()); | 79 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber()); |
| 76 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber()); | 80 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber()); |
| 77 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); | 81 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); |
| 78 | 82 |
| 79 CreateDataSource(name); | 83 CreateDataSource(name); |
| 84 | |
| 85 media::FFmpegNeedKeyCB need_key_cb = | |
| 86 base::Bind(&FFmpegDemuxerTest::NeedKeyCB, base::Unretained(this)); | |
| 80 demuxer_ = new FFmpegDemuxer(message_loop_.message_loop_proxy(), | 87 demuxer_ = new FFmpegDemuxer(message_loop_.message_loop_proxy(), |
| 81 data_source_); | 88 data_source_, |
| 89 need_key_cb); | |
| 82 } | 90 } |
| 83 | 91 |
| 84 MOCK_METHOD1(CheckPoint, void(int v)); | 92 MOCK_METHOD1(CheckPoint, void(int v)); |
| 85 | 93 |
| 86 void InitializeDemuxer() { | 94 void InitializeDemuxer() { |
| 87 EXPECT_CALL(host_, SetDuration(_)); | 95 EXPECT_CALL(host_, SetDuration(_)); |
| 88 WaitableMessageLoopEvent event; | 96 WaitableMessageLoopEvent event; |
| 89 demuxer_->Initialize(&host_, event.GetPipelineStatusCB()); | 97 demuxer_->Initialize(&host_, event.GetPipelineStatusCB()); |
| 90 event.RunAndWaitForStatus(PIPELINE_OK); | 98 event.RunAndWaitForStatus(PIPELINE_OK); |
| 91 } | 99 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 114 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure()); | 122 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure()); |
| 115 } | 123 } |
| 116 | 124 |
| 117 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location, | 125 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location, |
| 118 int size, int64 timestampInMicroseconds) { | 126 int size, int64 timestampInMicroseconds) { |
| 119 EXPECT_CALL(*this, OnReadDoneCalled(size, timestampInMicroseconds)); | 127 EXPECT_CALL(*this, OnReadDoneCalled(size, timestampInMicroseconds)); |
| 120 return base::Bind(&FFmpegDemuxerTest::OnReadDone, base::Unretained(this), | 128 return base::Bind(&FFmpegDemuxerTest::OnReadDone, base::Unretained(this), |
| 121 location, size, timestampInMicroseconds); | 129 location, size, timestampInMicroseconds); |
| 122 } | 130 } |
| 123 | 131 |
| 132 MOCK_METHOD3(NeedKeyCBMock, void(const std::string& type, | |
| 133 const uint8* init_data, int init_data_size)); | |
| 134 void NeedKeyCB(const std::string& type, | |
|
ddorwin
2013/03/13 19:16:09
Why can't we use the mock method directly? For the
fgalligan1
2013/03/13 19:36:52
I added xhwang's todo and comment on why we can't
xhwang
2013/03/13 20:15:20
Yeah, it's unfortunate that mock method doesn't wo
| |
| 135 scoped_array<uint8> init_data, int init_data_size) { | |
| 136 NeedKeyCBMock(type, init_data.get(), init_data_size); | |
| 137 } | |
| 138 | |
| 124 // Accessor to demuxer internals. | 139 // Accessor to demuxer internals. |
| 125 void set_duration_known(bool duration_known) { | 140 void set_duration_known(bool duration_known) { |
| 126 demuxer_->duration_known_ = duration_known; | 141 demuxer_->duration_known_ = duration_known; |
| 127 } | 142 } |
| 128 | 143 |
| 129 bool IsStreamStopped(DemuxerStream::Type type) { | 144 bool IsStreamStopped(DemuxerStream::Type type) { |
| 130 DemuxerStream* stream = demuxer_->GetStream(type); | 145 DemuxerStream* stream = demuxer_->GetStream(type); |
| 131 CHECK(stream); | 146 CHECK(stream); |
| 132 return static_cast<FFmpegDemuxerStream*>(stream)->stopped_; | 147 return static_cast<FFmpegDemuxerStream*>(stream)->stopped_; |
| 133 } | 148 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 // Audio stream should be Vorbis. | 289 // Audio stream should be Vorbis. |
| 275 stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 290 stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 276 ASSERT_TRUE(stream); | 291 ASSERT_TRUE(stream); |
| 277 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); | 292 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); |
| 278 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); | 293 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); |
| 279 | 294 |
| 280 // Unknown stream should never be present. | 295 // Unknown stream should never be present. |
| 281 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); | 296 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); |
| 282 } | 297 } |
| 283 | 298 |
| 299 // TODO(fgalligan): Enable test when code to parse encrypted WebM files lands | |
| 300 // in Chromium's FFmpeg. crbug.com/189221 | |
| 301 TEST_F(FFmpegDemuxerTest, DISABLED_Initialize_Encrypted) { | |
| 302 EXPECT_CALL(*this, NeedKeyCBMock(kWebMEncryptInitDataType, NotNull(), | |
| 303 DecryptConfig::kDecryptionKeySize)) | |
| 304 .Times(Exactly(2)); | |
| 305 | |
| 306 CreateDemuxer("bear-320x240-av_enc-av.webm"); | |
| 307 InitializeDemuxer(); | |
| 308 } | |
| 309 | |
| 284 TEST_F(FFmpegDemuxerTest, Read_Audio) { | 310 TEST_F(FFmpegDemuxerTest, Read_Audio) { |
| 285 // We test that on a successful audio packet read. | 311 // We test that on a successful audio packet read. |
| 286 CreateDemuxer("bear-320x240.webm"); | 312 CreateDemuxer("bear-320x240.webm"); |
| 287 InitializeDemuxer(); | 313 InitializeDemuxer(); |
| 288 | 314 |
| 289 // Attempt a read from the audio stream and run the message loop until done. | 315 // Attempt a read from the audio stream and run the message loop until done. |
| 290 scoped_refptr<DemuxerStream> audio = | 316 scoped_refptr<DemuxerStream> audio = |
| 291 demuxer_->GetStream(DemuxerStream::AUDIO); | 317 demuxer_->GetStream(DemuxerStream::AUDIO); |
| 292 | 318 |
| 293 audio->Read(NewReadCB(FROM_HERE, 29, 0)); | 319 audio->Read(NewReadCB(FROM_HERE, 29, 0)); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 621 TEST_F(FFmpegDemuxerTest, MP4_ZeroStszEntry) { | 647 TEST_F(FFmpegDemuxerTest, MP4_ZeroStszEntry) { |
| 622 #if !defined(USE_PROPRIETARY_CODECS) | 648 #if !defined(USE_PROPRIETARY_CODECS) |
| 623 return; | 649 return; |
| 624 #endif | 650 #endif |
| 625 CreateDemuxer("bear-1280x720-zero-stsz-entry.mp4"); | 651 CreateDemuxer("bear-1280x720-zero-stsz-entry.mp4"); |
| 626 InitializeDemuxer(); | 652 InitializeDemuxer(); |
| 627 ReadUntilEndOfStream(); | 653 ReadUntilEndOfStream(); |
| 628 } | 654 } |
| 629 | 655 |
| 630 } // namespace media | 656 } // namespace media |
| OLD | NEW |