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" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 EXPECT_TRUE(buffer->GetData()); | 51 EXPECT_TRUE(buffer->GetData()); |
52 EXPECT_GT(buffer->GetDataSize(), 0); | 52 EXPECT_GT(buffer->GetDataSize(), 0); |
53 *got_eos_buffer = false; | 53 *got_eos_buffer = false; |
54 }; | 54 }; |
55 | 55 |
56 | 56 |
57 // Fixture class to facilitate writing tests. Takes care of setting up the | 57 // Fixture class to facilitate writing tests. Takes care of setting up the |
58 // FFmpeg, pipeline and filter host mocks. | 58 // FFmpeg, pipeline and filter host mocks. |
59 class FFmpegDemuxerTest : public testing::Test { | 59 class FFmpegDemuxerTest : public testing::Test { |
60 protected: | 60 protected: |
61 FFmpegDemuxerTest() {} | 61 FFmpegDemuxerTest() : need_key_called_(0) {} |
62 | 62 |
63 virtual ~FFmpegDemuxerTest() { | 63 virtual ~FFmpegDemuxerTest() { |
64 if (demuxer_) { | 64 if (demuxer_) { |
65 demuxer_->Stop(MessageLoop::QuitWhenIdleClosure()); | 65 demuxer_->Stop(MessageLoop::QuitWhenIdleClosure()); |
66 message_loop_.Run(); | 66 message_loop_.Run(); |
67 } | 67 } |
68 | 68 |
69 demuxer_ = NULL; | 69 demuxer_ = NULL; |
70 } | 70 } |
71 | 71 |
72 void CreateDemuxer(const std::string& name) { | 72 void CreateDemuxer(const std::string& name) { |
73 CHECK(!demuxer_); | 73 CHECK(!demuxer_); |
74 | 74 |
75 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber()); | 75 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber()); |
76 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber()); | 76 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber()); |
77 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); | 77 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); |
78 | 78 |
79 CreateDataSource(name); | 79 CreateDataSource(name); |
80 | |
81 media::FFmpegNeedKeyCB need_key_cb = | |
82 base::Bind(&FFmpegDemuxerTest::NeedKeyCB, base::Unretained(this)); | |
80 demuxer_ = new FFmpegDemuxer(message_loop_.message_loop_proxy(), | 83 demuxer_ = new FFmpegDemuxer(message_loop_.message_loop_proxy(), |
81 data_source_); | 84 data_source_, |
85 need_key_cb); | |
82 } | 86 } |
83 | 87 |
84 MOCK_METHOD1(CheckPoint, void(int v)); | 88 MOCK_METHOD1(CheckPoint, void(int v)); |
85 | 89 |
86 void InitializeDemuxer() { | 90 void InitializeDemuxer() { |
87 EXPECT_CALL(host_, SetDuration(_)); | 91 EXPECT_CALL(host_, SetDuration(_)); |
88 WaitableMessageLoopEvent event; | 92 WaitableMessageLoopEvent event; |
89 demuxer_->Initialize(&host_, event.GetPipelineStatusCB()); | 93 demuxer_->Initialize(&host_, event.GetPipelineStatusCB()); |
90 event.RunAndWaitForStatus(PIPELINE_OK); | 94 event.RunAndWaitForStatus(PIPELINE_OK); |
91 } | 95 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 DemuxerStream* stream = demuxer_->GetStream(type); | 134 DemuxerStream* stream = demuxer_->GetStream(type); |
131 CHECK(stream); | 135 CHECK(stream); |
132 return static_cast<FFmpegDemuxerStream*>(stream)->stopped_; | 136 return static_cast<FFmpegDemuxerStream*>(stream)->stopped_; |
133 } | 137 } |
134 | 138 |
135 // Fixture members. | 139 // Fixture members. |
136 scoped_refptr<FileDataSource> data_source_; | 140 scoped_refptr<FileDataSource> data_source_; |
137 scoped_refptr<FFmpegDemuxer> demuxer_; | 141 scoped_refptr<FFmpegDemuxer> demuxer_; |
138 StrictMock<MockDemuxerHost> host_; | 142 StrictMock<MockDemuxerHost> host_; |
139 MessageLoop message_loop_; | 143 MessageLoop message_loop_; |
144 int need_key_called_; | |
140 | 145 |
141 AVFormatContext* format_context() { | 146 AVFormatContext* format_context() { |
142 return demuxer_->glue_->format_context(); | 147 return demuxer_->glue_->format_context(); |
143 } | 148 } |
144 | 149 |
145 void ReadUntilEndOfStream() { | 150 void ReadUntilEndOfStream() { |
146 // We should expect an end of stream buffer. | 151 // We should expect an end of stream buffer. |
147 scoped_refptr<DemuxerStream> audio = | 152 scoped_refptr<DemuxerStream> audio = |
148 demuxer_->GetStream(DemuxerStream::AUDIO); | 153 demuxer_->GetStream(DemuxerStream::AUDIO); |
149 | 154 |
(...skipping 16 matching lines...) Expand all Loading... | |
166 | 171 |
167 file_path = file_path.Append(FILE_PATH_LITERAL("media")) | 172 file_path = file_path.Append(FILE_PATH_LITERAL("media")) |
168 .Append(FILE_PATH_LITERAL("test")) | 173 .Append(FILE_PATH_LITERAL("test")) |
169 .Append(FILE_PATH_LITERAL("data")) | 174 .Append(FILE_PATH_LITERAL("data")) |
170 .AppendASCII(name); | 175 .AppendASCII(name); |
171 | 176 |
172 data_source_ = new FileDataSource(); | 177 data_source_ = new FileDataSource(); |
173 EXPECT_TRUE(data_source_->Initialize(file_path)); | 178 EXPECT_TRUE(data_source_->Initialize(file_path)); |
174 } | 179 } |
175 | 180 |
181 void NeedKeyCB(const std::string& type, | |
ddorwin
2013/03/13 18:07:24
MOCK_METHOD...
fgalligan1
2013/03/13 19:05:26
Done.
| |
182 scoped_array<uint8> init_data, int init_data_size) { | |
183 need_key_called_++; | |
184 } | |
185 | |
176 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest); | 186 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest); |
177 }; | 187 }; |
178 | 188 |
179 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { | 189 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { |
180 // Simulate avformat_open_input() failing. | 190 // Simulate avformat_open_input() failing. |
181 CreateDemuxer("ten_byte_file"); | 191 CreateDemuxer("ten_byte_file"); |
182 WaitableMessageLoopEvent event; | 192 WaitableMessageLoopEvent event; |
183 demuxer_->Initialize(&host_, event.GetPipelineStatusCB()); | 193 demuxer_->Initialize(&host_, event.GetPipelineStatusCB()); |
184 event.RunAndWaitForStatus(DEMUXER_ERROR_COULD_NOT_OPEN); | 194 event.RunAndWaitForStatus(DEMUXER_ERROR_COULD_NOT_OPEN); |
185 } | 195 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 // Audio stream should be Vorbis. | 284 // Audio stream should be Vorbis. |
275 stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 285 stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
276 ASSERT_TRUE(stream); | 286 ASSERT_TRUE(stream); |
277 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); | 287 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); |
278 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); | 288 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); |
279 | 289 |
280 // Unknown stream should never be present. | 290 // Unknown stream should never be present. |
281 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); | 291 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); |
282 } | 292 } |
283 | 293 |
294 // TODO(fgalligan): Enable test when code to parse encrypted WebM files lands | |
295 // in Chromium's FFmpeg. crbug.com/189221 | |
296 TEST_F(FFmpegDemuxerTest, DISABLED_Initialize_Encrypted) { | |
297 CreateDemuxer("bear-320x240-av_enc-av.webm"); | |
298 InitializeDemuxer(); | |
299 | |
300 // NeedKey callback should have been called twice. Once for each encrypted | |
301 // stream. | |
302 EXPECT_EQ(2, need_key_called_); | |
ddorwin
2013/03/13 18:07:24
This is what mocks do well. Since this tests alrea
fgalligan1
2013/03/13 19:05:26
Done.
| |
303 } | |
304 | |
284 TEST_F(FFmpegDemuxerTest, Read_Audio) { | 305 TEST_F(FFmpegDemuxerTest, Read_Audio) { |
285 // We test that on a successful audio packet read. | 306 // We test that on a successful audio packet read. |
286 CreateDemuxer("bear-320x240.webm"); | 307 CreateDemuxer("bear-320x240.webm"); |
287 InitializeDemuxer(); | 308 InitializeDemuxer(); |
288 | 309 |
289 // Attempt a read from the audio stream and run the message loop until done. | 310 // Attempt a read from the audio stream and run the message loop until done. |
290 scoped_refptr<DemuxerStream> audio = | 311 scoped_refptr<DemuxerStream> audio = |
291 demuxer_->GetStream(DemuxerStream::AUDIO); | 312 demuxer_->GetStream(DemuxerStream::AUDIO); |
292 | 313 |
293 audio->Read(NewReadCB(FROM_HERE, 29, 0)); | 314 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) { | 642 TEST_F(FFmpegDemuxerTest, MP4_ZeroStszEntry) { |
622 #if !defined(USE_PROPRIETARY_CODECS) | 643 #if !defined(USE_PROPRIETARY_CODECS) |
623 return; | 644 return; |
624 #endif | 645 #endif |
625 CreateDemuxer("bear-1280x720-zero-stsz-entry.mp4"); | 646 CreateDemuxer("bear-1280x720-zero-stsz-entry.mp4"); |
626 InitializeDemuxer(); | 647 InitializeDemuxer(); |
627 ReadUntilEndOfStream(); | 648 ReadUntilEndOfStream(); |
628 } | 649 } |
629 | 650 |
630 } // namespace media | 651 } // namespace media |
OLD | NEW |