Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: media/filters/ffmpeg_demuxer_unittest.cc

Issue 23702007: Render inband text tracks in the media pipeline (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: incorporate aaron's comments (11/04) Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 CHECK(!demuxer_); 76 CHECK(!demuxer_);
77 77
78 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber()); 78 EXPECT_CALL(host_, SetTotalBytes(_)).Times(AnyNumber());
79 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber()); 79 EXPECT_CALL(host_, AddBufferedByteRange(_, _)).Times(AnyNumber());
80 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); 80 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber());
81 81
82 CreateDataSource(name); 82 CreateDataSource(name);
83 83
84 Demuxer::NeedKeyCB need_key_cb = 84 Demuxer::NeedKeyCB need_key_cb =
85 base::Bind(&FFmpegDemuxerTest::NeedKeyCB, base::Unretained(this)); 85 base::Bind(&FFmpegDemuxerTest::NeedKeyCB, base::Unretained(this));
86
86 demuxer_.reset(new FFmpegDemuxer(message_loop_.message_loop_proxy(), 87 demuxer_.reset(new FFmpegDemuxer(message_loop_.message_loop_proxy(),
87 data_source_.get(), 88 data_source_.get(),
88 need_key_cb, 89 need_key_cb,
89 new MediaLog())); 90 new MediaLog()));
90 } 91 }
91 92
92 MOCK_METHOD1(CheckPoint, void(int v)); 93 MOCK_METHOD1(CheckPoint, void(int v));
93 94
94 void InitializeDemuxer() { 95 void InitializeDemuxerText(bool enable_text) {
95 EXPECT_CALL(host_, SetDuration(_)); 96 EXPECT_CALL(host_, SetDuration(_));
96 WaitableMessageLoopEvent event; 97 WaitableMessageLoopEvent event;
97 demuxer_->Initialize(&host_, event.GetPipelineStatusCB()); 98 demuxer_->Initialize(&host_, event.GetPipelineStatusCB(), enable_text);
98 event.RunAndWaitForStatus(PIPELINE_OK); 99 event.RunAndWaitForStatus(PIPELINE_OK);
99 } 100 }
100 101
102 void InitializeDemuxer() {
103 InitializeDemuxerText(false);
104 }
105
101 MOCK_METHOD2(OnReadDoneCalled, void(int, int64)); 106 MOCK_METHOD2(OnReadDoneCalled, void(int, int64));
102 107
103 // Verifies that |buffer| has a specific |size| and |timestamp|. 108 // Verifies that |buffer| has a specific |size| and |timestamp|.
104 // |location| simply indicates where the call to this function was made. 109 // |location| simply indicates where the call to this function was made.
105 // This makes it easier to track down where test failures occur. 110 // This makes it easier to track down where test failures occur.
106 void OnReadDone(const tracked_objects::Location& location, 111 void OnReadDone(const tracked_objects::Location& location,
107 int size, int64 timestampInMicroseconds, 112 int size, int64 timestampInMicroseconds,
108 DemuxerStream::Status status, 113 DemuxerStream::Status status,
109 const scoped_refptr<DecoderBuffer>& buffer) { 114 const scoped_refptr<DecoderBuffer>& buffer) {
110 std::string location_str; 115 std::string location_str;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 EXPECT_TRUE(data_source_->Initialize(file_path)); 197 EXPECT_TRUE(data_source_->Initialize(file_path));
193 } 198 }
194 199
195 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest); 200 DISALLOW_COPY_AND_ASSIGN(FFmpegDemuxerTest);
196 }; 201 };
197 202
198 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { 203 TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) {
199 // Simulate avformat_open_input() failing. 204 // Simulate avformat_open_input() failing.
200 CreateDemuxer("ten_byte_file"); 205 CreateDemuxer("ten_byte_file");
201 WaitableMessageLoopEvent event; 206 WaitableMessageLoopEvent event;
202 demuxer_->Initialize(&host_, event.GetPipelineStatusCB()); 207 demuxer_->Initialize(&host_, event.GetPipelineStatusCB(), true);
203 event.RunAndWaitForStatus(DEMUXER_ERROR_COULD_NOT_OPEN); 208 event.RunAndWaitForStatus(DEMUXER_ERROR_COULD_NOT_OPEN);
204 } 209 }
205 210
206 // TODO(acolwell): Uncomment this test when we discover a file that passes 211 // TODO(acolwell): Uncomment this test when we discover a file that passes
207 // avformat_open_input(), but has avformat_find_stream_info() fail. 212 // avformat_open_input(), but has avformat_find_stream_info() fail.
208 // 213 //
209 //TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { 214 //TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) {
210 // ("find_stream_info_fail.webm"); 215 // ("find_stream_info_fail.webm");
211 // demuxer_->Initialize( 216 // demuxer_->Initialize(
212 // &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_PARSE)); 217 // &host_, NewExpectedStatusCB(DEMUXER_ERROR_COULD_NOT_PARSE));
213 // message_loop_.RunUntilIdle(); 218 // message_loop_.RunUntilIdle();
214 //} 219 //}
215 220
216 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { 221 TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) {
217 // Open a file with no streams whatsoever. 222 // Open a file with no streams whatsoever.
218 CreateDemuxer("no_streams.webm"); 223 CreateDemuxer("no_streams.webm");
219 WaitableMessageLoopEvent event; 224 WaitableMessageLoopEvent event;
220 demuxer_->Initialize(&host_, event.GetPipelineStatusCB()); 225 demuxer_->Initialize(&host_, event.GetPipelineStatusCB(), true);
221 event.RunAndWaitForStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); 226 event.RunAndWaitForStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS);
222 } 227 }
223 228
224 TEST_F(FFmpegDemuxerTest, Initialize_NoAudioVideo) { 229 TEST_F(FFmpegDemuxerTest, Initialize_NoAudioVideo) {
225 // Open a file containing streams but none of which are audio/video streams. 230 // Open a file containing streams but none of which are audio/video streams.
226 CreateDemuxer("no_audio_video.webm"); 231 CreateDemuxer("no_audio_video.webm");
227 WaitableMessageLoopEvent event; 232 WaitableMessageLoopEvent event;
228 demuxer_->Initialize(&host_, event.GetPipelineStatusCB()); 233 demuxer_->Initialize(&host_, event.GetPipelineStatusCB(), true);
229 event.RunAndWaitForStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); 234 event.RunAndWaitForStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS);
230 } 235 }
231 236
232 TEST_F(FFmpegDemuxerTest, Initialize_Successful) { 237 TEST_F(FFmpegDemuxerTest, Initialize_Successful) {
233 CreateDemuxer("bear-320x240.webm"); 238 CreateDemuxer("bear-320x240.webm");
234 InitializeDemuxer(); 239 InitializeDemuxer();
235 240
236 // Video stream should be present. 241 // Video stream should be present.
237 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); 242 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO);
238 ASSERT_TRUE(stream); 243 ASSERT_TRUE(stream);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // Audio stream should be Vorbis. 296 // Audio stream should be Vorbis.
292 stream = demuxer_->GetStream(DemuxerStream::AUDIO); 297 stream = demuxer_->GetStream(DemuxerStream::AUDIO);
293 ASSERT_TRUE(stream); 298 ASSERT_TRUE(stream);
294 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); 299 EXPECT_EQ(DemuxerStream::AUDIO, stream->type());
295 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); 300 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec());
296 301
297 // Unknown stream should never be present. 302 // Unknown stream should never be present.
298 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); 303 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN));
299 } 304 }
300 305
306 TEST_F(FFmpegDemuxerTest, Initialize_MultitrackText) {
307 // Open a file containing the following streams:
308 // Stream #0: Video (VP8)
309 // Stream #1: Audio (Vorbis)
310 // Stream #2: Text (WebVTT)
311
312 CreateDemuxer("bear-vp8-webvtt.webm");
313 DemuxerStream* text_stream = NULL;
314 EXPECT_CALL(host_, AddTextStream(_, _))
315 .WillOnce(SaveArg<0>(&text_stream));
316 InitializeDemuxerText(true);
317 ASSERT_TRUE(text_stream);
318 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type());
319
320 // Video stream should be VP8.
321 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO);
322 ASSERT_TRUE(stream);
323 EXPECT_EQ(DemuxerStream::VIDEO, stream->type());
324 EXPECT_EQ(kCodecVP8, stream->video_decoder_config().codec());
325
326 // Audio stream should be Vorbis.
327 stream = demuxer_->GetStream(DemuxerStream::AUDIO);
328 ASSERT_TRUE(stream);
329 EXPECT_EQ(DemuxerStream::AUDIO, stream->type());
330 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec());
331
332 // Unknown stream should never be present.
333 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN));
334 }
335
301 TEST_F(FFmpegDemuxerTest, Initialize_Encrypted) { 336 TEST_F(FFmpegDemuxerTest, Initialize_Encrypted) {
302 EXPECT_CALL(*this, NeedKeyCBMock(kWebMEncryptInitDataType, NotNull(), 337 EXPECT_CALL(*this, NeedKeyCBMock(kWebMEncryptInitDataType, NotNull(),
303 DecryptConfig::kDecryptionKeySize)) 338 DecryptConfig::kDecryptionKeySize))
304 .Times(Exactly(2)); 339 .Times(Exactly(2));
305 340
306 CreateDemuxer("bear-320x240-av_enc-av.webm"); 341 CreateDemuxer("bear-320x240-av_enc-av.webm");
307 InitializeDemuxer(); 342 InitializeDemuxer();
308 } 343 }
309 344
310 TEST_F(FFmpegDemuxerTest, Read_Audio) { 345 TEST_F(FFmpegDemuxerTest, Read_Audio) {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 TEST_F(FFmpegDemuxerTest, MP4_ZeroStszEntry) { 611 TEST_F(FFmpegDemuxerTest, MP4_ZeroStszEntry) {
577 #if !defined(USE_PROPRIETARY_CODECS) 612 #if !defined(USE_PROPRIETARY_CODECS)
578 return; 613 return;
579 #endif 614 #endif
580 CreateDemuxer("bear-1280x720-zero-stsz-entry.mp4"); 615 CreateDemuxer("bear-1280x720-zero-stsz-entry.mp4");
581 InitializeDemuxer(); 616 InitializeDemuxer();
582 ReadUntilEndOfStream(); 617 ReadUntilEndOfStream();
583 } 618 }
584 619
585 } // namespace media 620 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698