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 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <deque> | 9 #include <deque> |
10 #include <string> | 10 #include <string> |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 &FFmpegDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this)); | 98 &FFmpegDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this)); |
99 | 99 |
100 Demuxer::MediaTracksUpdatedCB tracks_updated_cb = base::Bind( | 100 Demuxer::MediaTracksUpdatedCB tracks_updated_cb = base::Bind( |
101 &FFmpegDemuxerTest::OnMediaTracksUpdated, base::Unretained(this)); | 101 &FFmpegDemuxerTest::OnMediaTracksUpdated, base::Unretained(this)); |
102 | 102 |
103 demuxer_.reset(new FFmpegDemuxer( | 103 demuxer_.reset(new FFmpegDemuxer( |
104 message_loop_.task_runner(), data_source_.get(), | 104 message_loop_.task_runner(), data_source_.get(), |
105 encrypted_media_init_data_cb, tracks_updated_cb, new MediaLog())); | 105 encrypted_media_init_data_cb, tracks_updated_cb, new MediaLog())); |
106 } | 106 } |
107 | 107 |
| 108 DemuxerStream* GetStream(DemuxerStream::Type type) { |
| 109 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
| 110 for (const auto& s : streams) { |
| 111 if (s->type() == type) |
| 112 return s; |
| 113 } |
| 114 return nullptr; |
| 115 } |
| 116 |
108 MOCK_METHOD1(CheckPoint, void(int v)); | 117 MOCK_METHOD1(CheckPoint, void(int v)); |
109 | 118 |
110 void InitializeDemuxerInternal(bool enable_text, | 119 void InitializeDemuxerInternal(bool enable_text, |
111 media::PipelineStatus expected_pipeline_status, | 120 media::PipelineStatus expected_pipeline_status, |
112 base::Time timeline_offset) { | 121 base::Time timeline_offset) { |
113 if (expected_pipeline_status == PIPELINE_OK) | 122 if (expected_pipeline_status == PIPELINE_OK) |
114 EXPECT_CALL(host_, SetDuration(_)); | 123 EXPECT_CALL(host_, SetDuration(_)); |
115 WaitableMessageLoopEvent event; | 124 WaitableMessageLoopEvent event; |
116 demuxer_->Initialize(&host_, event.GetPipelineStatusCB(), enable_text); | 125 demuxer_->Initialize(&host_, event.GetPipelineStatusCB(), enable_text); |
117 demuxer_->timeline_offset_ = timeline_offset; | 126 demuxer_->timeline_offset_ = timeline_offset; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 void OnMediaTracksUpdated(std::unique_ptr<MediaTracks> tracks) { | 229 void OnMediaTracksUpdated(std::unique_ptr<MediaTracks> tracks) { |
221 CHECK(tracks.get()); | 230 CHECK(tracks.get()); |
222 media_tracks_ = std::move(tracks); | 231 media_tracks_ = std::move(tracks); |
223 } | 232 } |
224 | 233 |
225 // Accessor to demuxer internals. | 234 // Accessor to demuxer internals. |
226 void set_duration_known(bool duration_known) { | 235 void set_duration_known(bool duration_known) { |
227 demuxer_->duration_known_ = duration_known; | 236 demuxer_->duration_known_ = duration_known; |
228 } | 237 } |
229 | 238 |
230 bool IsStreamStopped(DemuxerStream::Type type) { | |
231 DemuxerStream* stream = demuxer_->GetStream(type); | |
232 CHECK(stream); | |
233 return !static_cast<FFmpegDemuxerStream*>(stream)->demuxer_; | |
234 } | |
235 | |
236 // Fixture members. | 239 // Fixture members. |
237 std::unique_ptr<FileDataSource> data_source_; | 240 std::unique_ptr<FileDataSource> data_source_; |
238 std::unique_ptr<FFmpegDemuxer> demuxer_; | 241 std::unique_ptr<FFmpegDemuxer> demuxer_; |
239 StrictMock<MockDemuxerHost> host_; | 242 StrictMock<MockDemuxerHost> host_; |
240 std::unique_ptr<MediaTracks> media_tracks_; | 243 std::unique_ptr<MediaTracks> media_tracks_; |
241 base::MessageLoop message_loop_; | 244 base::MessageLoop message_loop_; |
242 | 245 |
243 AVFormatContext* format_context() { | 246 AVFormatContext* format_context() { |
244 return demuxer_->glue_->format_context(); | 247 return demuxer_->glue_->format_context(); |
245 } | 248 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 CreateDemuxer("no_audio_video.webm"); | 312 CreateDemuxer("no_audio_video.webm"); |
310 WaitableMessageLoopEvent event; | 313 WaitableMessageLoopEvent event; |
311 demuxer_->Initialize(&host_, event.GetPipelineStatusCB(), true); | 314 demuxer_->Initialize(&host_, event.GetPipelineStatusCB(), true); |
312 event.RunAndWaitForStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); | 315 event.RunAndWaitForStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); |
313 } | 316 } |
314 | 317 |
315 TEST_F(FFmpegDemuxerTest, Initialize_Successful) { | 318 TEST_F(FFmpegDemuxerTest, Initialize_Successful) { |
316 CreateDemuxer("bear-320x240.webm"); | 319 CreateDemuxer("bear-320x240.webm"); |
317 InitializeDemuxer(); | 320 InitializeDemuxer(); |
318 | 321 |
| 322 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
| 323 EXPECT_EQ(2u, streams.size()); |
| 324 |
319 // Video stream should be present. | 325 // Video stream should be present. |
320 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 326 DemuxerStream* stream = streams[0]; |
321 ASSERT_TRUE(stream); | 327 ASSERT_TRUE(stream); |
322 EXPECT_EQ(DemuxerStream::VIDEO, stream->type()); | 328 EXPECT_EQ(DemuxerStream::VIDEO, stream->type()); |
323 | 329 |
324 const VideoDecoderConfig& video_config = stream->video_decoder_config(); | 330 const VideoDecoderConfig& video_config = stream->video_decoder_config(); |
325 EXPECT_EQ(kCodecVP8, video_config.codec()); | 331 EXPECT_EQ(kCodecVP8, video_config.codec()); |
326 EXPECT_EQ(PIXEL_FORMAT_YV12, video_config.format()); | 332 EXPECT_EQ(PIXEL_FORMAT_YV12, video_config.format()); |
327 EXPECT_EQ(320, video_config.coded_size().width()); | 333 EXPECT_EQ(320, video_config.coded_size().width()); |
328 EXPECT_EQ(240, video_config.coded_size().height()); | 334 EXPECT_EQ(240, video_config.coded_size().height()); |
329 EXPECT_EQ(0, video_config.visible_rect().x()); | 335 EXPECT_EQ(0, video_config.visible_rect().x()); |
330 EXPECT_EQ(0, video_config.visible_rect().y()); | 336 EXPECT_EQ(0, video_config.visible_rect().y()); |
331 EXPECT_EQ(320, video_config.visible_rect().width()); | 337 EXPECT_EQ(320, video_config.visible_rect().width()); |
332 EXPECT_EQ(240, video_config.visible_rect().height()); | 338 EXPECT_EQ(240, video_config.visible_rect().height()); |
333 EXPECT_EQ(320, video_config.natural_size().width()); | 339 EXPECT_EQ(320, video_config.natural_size().width()); |
334 EXPECT_EQ(240, video_config.natural_size().height()); | 340 EXPECT_EQ(240, video_config.natural_size().height()); |
335 EXPECT_TRUE(video_config.extra_data().empty()); | 341 EXPECT_TRUE(video_config.extra_data().empty()); |
336 | 342 |
337 // Audio stream should be present. | 343 // Audio stream should be present. |
338 stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 344 stream = streams[1]; |
339 ASSERT_TRUE(stream); | 345 ASSERT_TRUE(stream); |
340 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); | 346 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); |
341 | 347 |
342 const AudioDecoderConfig& audio_config = stream->audio_decoder_config(); | 348 const AudioDecoderConfig& audio_config = stream->audio_decoder_config(); |
343 EXPECT_EQ(kCodecVorbis, audio_config.codec()); | 349 EXPECT_EQ(kCodecVorbis, audio_config.codec()); |
344 EXPECT_EQ(32, audio_config.bits_per_channel()); | 350 EXPECT_EQ(32, audio_config.bits_per_channel()); |
345 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, audio_config.channel_layout()); | 351 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, audio_config.channel_layout()); |
346 EXPECT_EQ(44100, audio_config.samples_per_second()); | 352 EXPECT_EQ(44100, audio_config.samples_per_second()); |
347 EXPECT_EQ(kSampleFormatPlanarF32, audio_config.sample_format()); | 353 EXPECT_EQ(kSampleFormatPlanarF32, audio_config.sample_format()); |
348 EXPECT_FALSE(audio_config.extra_data().empty()); | 354 EXPECT_FALSE(audio_config.extra_data().empty()); |
349 | |
350 // Unknown stream should never be present. | |
351 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); | |
352 } | 355 } |
353 | 356 |
354 TEST_F(FFmpegDemuxerTest, Initialize_Multitrack) { | 357 TEST_F(FFmpegDemuxerTest, Initialize_Multitrack) { |
355 // Open a file containing the following streams: | 358 // Open a file containing the following streams: |
356 // Stream #0: Video (VP8) | 359 // Stream #0: Video (VP8) |
357 // Stream #1: Audio (Vorbis) | 360 // Stream #1: Audio (Vorbis) |
358 // Stream #2: Subtitles (SRT) | 361 // Stream #2: Subtitles (SRT) |
359 // Stream #3: Video (Theora) | 362 // Stream #3: Video (Theora) |
360 // Stream #4: Audio (16-bit signed little endian PCM) | 363 // Stream #4: Audio (16-bit signed little endian PCM) |
361 // | 364 // |
362 // We should only pick the first audio/video streams we come across. | 365 // We should only pick the first audio/video streams we come across. |
363 CreateDemuxer("bear-320x240-multitrack.webm"); | 366 CreateDemuxer("bear-320x240-multitrack.webm"); |
364 InitializeDemuxer(); | 367 InitializeDemuxer(); |
365 | 368 |
| 369 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
| 370 EXPECT_EQ(4u, streams.size()); |
| 371 |
366 // Video stream should be VP8. | 372 // Video stream should be VP8. |
367 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 373 DemuxerStream* stream = streams[0]; |
368 ASSERT_TRUE(stream); | 374 ASSERT_TRUE(stream); |
369 EXPECT_EQ(DemuxerStream::VIDEO, stream->type()); | 375 EXPECT_EQ(DemuxerStream::VIDEO, stream->type()); |
370 EXPECT_EQ(kCodecVP8, stream->video_decoder_config().codec()); | 376 EXPECT_EQ(kCodecVP8, stream->video_decoder_config().codec()); |
371 | 377 |
372 // Audio stream should be Vorbis. | 378 // Audio stream should be Vorbis. |
373 stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 379 stream = streams[1]; |
374 ASSERT_TRUE(stream); | 380 ASSERT_TRUE(stream); |
375 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); | 381 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); |
376 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); | 382 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); |
377 | |
378 // Unknown stream should never be present. | |
379 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); | |
380 } | 383 } |
381 | 384 |
382 TEST_F(FFmpegDemuxerTest, Initialize_MultitrackText) { | 385 TEST_F(FFmpegDemuxerTest, Initialize_MultitrackText) { |
383 // Open a file containing the following streams: | 386 // Open a file containing the following streams: |
384 // Stream #0: Video (VP8) | 387 // Stream #0: Video (VP8) |
385 // Stream #1: Audio (Vorbis) | 388 // Stream #1: Audio (Vorbis) |
386 // Stream #2: Text (WebVTT) | 389 // Stream #2: Text (WebVTT) |
387 | 390 |
388 CreateDemuxer("bear-vp8-webvtt.webm"); | 391 CreateDemuxer("bear-vp8-webvtt.webm"); |
389 DemuxerStream* text_stream = NULL; | 392 DemuxerStream* text_stream = NULL; |
390 EXPECT_CALL(host_, AddTextStream(_, _)) | 393 EXPECT_CALL(host_, AddTextStream(_, _)) |
391 .WillOnce(SaveArg<0>(&text_stream)); | 394 .WillOnce(SaveArg<0>(&text_stream)); |
392 InitializeDemuxerWithText(); | 395 InitializeDemuxerWithText(); |
393 ASSERT_TRUE(text_stream); | 396 ASSERT_TRUE(text_stream); |
394 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type()); | 397 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type()); |
395 | 398 |
| 399 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
396 // Video stream should be VP8. | 400 // Video stream should be VP8. |
397 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 401 DemuxerStream* stream = streams[0]; |
398 ASSERT_TRUE(stream); | 402 ASSERT_TRUE(stream); |
399 EXPECT_EQ(DemuxerStream::VIDEO, stream->type()); | 403 EXPECT_EQ(DemuxerStream::VIDEO, stream->type()); |
400 EXPECT_EQ(kCodecVP8, stream->video_decoder_config().codec()); | 404 EXPECT_EQ(kCodecVP8, stream->video_decoder_config().codec()); |
401 | 405 |
402 // Audio stream should be Vorbis. | 406 // Audio stream should be Vorbis. |
403 stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 407 stream = streams[1]; |
404 ASSERT_TRUE(stream); | 408 ASSERT_TRUE(stream); |
405 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); | 409 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); |
406 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); | 410 EXPECT_EQ(kCodecVorbis, stream->audio_decoder_config().codec()); |
407 | |
408 // Unknown stream should never be present. | |
409 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::UNKNOWN)); | |
410 } | 411 } |
411 | 412 |
412 TEST_F(FFmpegDemuxerTest, Initialize_Encrypted) { | 413 TEST_F(FFmpegDemuxerTest, Initialize_Encrypted) { |
413 EXPECT_CALL(*this, | 414 EXPECT_CALL(*this, |
414 OnEncryptedMediaInitData( | 415 OnEncryptedMediaInitData( |
415 EmeInitDataType::WEBM, | 416 EmeInitDataType::WEBM, |
416 std::vector<uint8_t>(kEncryptedMediaInitData, | 417 std::vector<uint8_t>(kEncryptedMediaInitData, |
417 kEncryptedMediaInitData + | 418 kEncryptedMediaInitData + |
418 arraysize(kEncryptedMediaInitData)))) | 419 arraysize(kEncryptedMediaInitData)))) |
419 .Times(Exactly(2)); | 420 .Times(Exactly(2)); |
420 | 421 |
421 CreateDemuxer("bear-320x240-av_enc-av.webm"); | 422 CreateDemuxer("bear-320x240-av_enc-av.webm"); |
422 InitializeDemuxer(); | 423 InitializeDemuxer(); |
423 } | 424 } |
424 | 425 |
425 TEST_F(FFmpegDemuxerTest, AbortPendingReads) { | 426 TEST_F(FFmpegDemuxerTest, AbortPendingReads) { |
426 // We test that on a successful audio packet read. | 427 // We test that on a successful audio packet read. |
427 CreateDemuxer("bear-320x240.webm"); | 428 CreateDemuxer("bear-320x240.webm"); |
428 InitializeDemuxer(); | 429 InitializeDemuxer(); |
429 | 430 |
430 // Attempt a read from the audio stream and run the message loop until done. | 431 // Attempt a read from the audio stream and run the message loop until done. |
431 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 432 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
| 433 DemuxerStream* audio = streams[1]; |
432 | 434 |
433 // Depending on where in the reading process ffmpeg is, an error may cause the | 435 // Depending on where in the reading process ffmpeg is, an error may cause the |
434 // stream to be marked as EOF. Simulate this here to ensure it is properly | 436 // stream to be marked as EOF. Simulate this here to ensure it is properly |
435 // cleared by the AbortPendingReads() call. | 437 // cleared by the AbortPendingReads() call. |
436 format_context()->pb->eof_reached = 1; | 438 format_context()->pb->eof_reached = 1; |
437 audio->Read(NewReadCB(FROM_HERE, 29, 0, true, DemuxerStream::kAborted)); | 439 audio->Read(NewReadCB(FROM_HERE, 29, 0, true, DemuxerStream::kAborted)); |
438 demuxer_->AbortPendingReads(); | 440 demuxer_->AbortPendingReads(); |
439 base::RunLoop().Run(); | 441 base::RunLoop().Run(); |
440 | 442 |
441 // Additional reads should also be aborted (until a Seek()). | 443 // Additional reads should also be aborted (until a Seek()). |
442 audio->Read(NewReadCB(FROM_HERE, 29, 0, true, DemuxerStream::kAborted)); | 444 audio->Read(NewReadCB(FROM_HERE, 29, 0, true, DemuxerStream::kAborted)); |
443 base::RunLoop().Run(); | 445 base::RunLoop().Run(); |
444 | 446 |
445 // Ensure blocking thread has completed outstanding work. | 447 // Ensure blocking thread has completed outstanding work. |
446 demuxer_->Stop(); | 448 demuxer_->Stop(); |
447 EXPECT_EQ(format_context()->pb->eof_reached, 0); | 449 EXPECT_EQ(format_context()->pb->eof_reached, 0); |
448 | 450 |
449 // Calling abort after stop should not crash. | 451 // Calling abort after stop should not crash. |
450 demuxer_->AbortPendingReads(); | 452 demuxer_->AbortPendingReads(); |
451 demuxer_.reset(); | 453 demuxer_.reset(); |
452 } | 454 } |
453 | 455 |
454 TEST_F(FFmpegDemuxerTest, Read_Audio) { | 456 TEST_F(FFmpegDemuxerTest, Read_Audio) { |
455 // We test that on a successful audio packet read. | 457 // We test that on a successful audio packet read. |
456 CreateDemuxer("bear-320x240.webm"); | 458 CreateDemuxer("bear-320x240.webm"); |
457 InitializeDemuxer(); | 459 InitializeDemuxer(); |
458 | 460 |
459 // Attempt a read from the audio stream and run the message loop until done. | 461 // Attempt a read from the audio stream and run the message loop until done. |
460 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 462 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
| 463 DemuxerStream* audio = streams[1]; |
461 | 464 |
462 audio->Read(NewReadCB(FROM_HERE, 29, 0, true)); | 465 audio->Read(NewReadCB(FROM_HERE, 29, 0, true)); |
463 base::RunLoop().Run(); | 466 base::RunLoop().Run(); |
464 | 467 |
465 audio->Read(NewReadCB(FROM_HERE, 27, 3000, true)); | 468 audio->Read(NewReadCB(FROM_HERE, 27, 3000, true)); |
466 base::RunLoop().Run(); | 469 base::RunLoop().Run(); |
467 | 470 |
468 EXPECT_EQ(22084, demuxer_->GetMemoryUsage()); | 471 EXPECT_EQ(22084, demuxer_->GetMemoryUsage()); |
469 } | 472 } |
470 | 473 |
471 TEST_F(FFmpegDemuxerTest, Read_Video) { | 474 TEST_F(FFmpegDemuxerTest, Read_Video) { |
472 // We test that on a successful video packet read. | 475 // We test that on a successful video packet read. |
473 CreateDemuxer("bear-320x240.webm"); | 476 CreateDemuxer("bear-320x240.webm"); |
474 InitializeDemuxer(); | 477 InitializeDemuxer(); |
475 | 478 |
476 // Attempt a read from the video stream and run the message loop until done. | 479 // Attempt a read from the video stream and run the message loop until done. |
477 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 480 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
| 481 DemuxerStream* video = streams[0]; |
478 | 482 |
479 video->Read(NewReadCB(FROM_HERE, 22084, 0, true)); | 483 video->Read(NewReadCB(FROM_HERE, 22084, 0, true)); |
480 base::RunLoop().Run(); | 484 base::RunLoop().Run(); |
481 | 485 |
482 video->Read(NewReadCB(FROM_HERE, 1057, 33000, false)); | 486 video->Read(NewReadCB(FROM_HERE, 1057, 33000, false)); |
483 base::RunLoop().Run(); | 487 base::RunLoop().Run(); |
484 | 488 |
485 EXPECT_EQ(323, demuxer_->GetMemoryUsage()); | 489 EXPECT_EQ(323, demuxer_->GetMemoryUsage()); |
486 } | 490 } |
487 | 491 |
(...skipping 12 matching lines...) Expand all Loading... |
500 | 504 |
501 text_stream->Read(NewReadCB(FROM_HERE, 19, 500000, true)); | 505 text_stream->Read(NewReadCB(FROM_HERE, 19, 500000, true)); |
502 base::RunLoop().Run(); | 506 base::RunLoop().Run(); |
503 } | 507 } |
504 | 508 |
505 TEST_F(FFmpegDemuxerTest, SeekInitialized_NoVideoStartTime) { | 509 TEST_F(FFmpegDemuxerTest, SeekInitialized_NoVideoStartTime) { |
506 CreateDemuxer("audio-start-time-only.webm"); | 510 CreateDemuxer("audio-start-time-only.webm"); |
507 InitializeDemuxer(); | 511 InitializeDemuxer(); |
508 // Video stream should be preferred for seeking even if video start time is | 512 // Video stream should be preferred for seeking even if video start time is |
509 // unknown. | 513 // unknown. |
510 DemuxerStream* vstream = demuxer_->GetStream(DemuxerStream::VIDEO); | 514 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
| 515 DemuxerStream* vstream = streams[0]; |
511 EXPECT_EQ(vstream, preferred_seeking_stream(base::TimeDelta())); | 516 EXPECT_EQ(vstream, preferred_seeking_stream(base::TimeDelta())); |
512 } | 517 } |
513 | 518 |
514 TEST_F(FFmpegDemuxerTest, Seeking_PreferredStreamSelection) { | 519 TEST_F(FFmpegDemuxerTest, Seeking_PreferredStreamSelection) { |
515 const int64_t kTimelineOffsetMs = 1352550896000LL; | 520 const int64_t kTimelineOffsetMs = 1352550896000LL; |
516 | 521 |
517 // Test the start time is the first timestamp of the video and audio stream. | 522 // Test the start time is the first timestamp of the video and audio stream. |
518 CreateDemuxer("nonzero-start-time.webm"); | 523 CreateDemuxer("nonzero-start-time.webm"); |
519 InitializeDemuxerWithTimelineOffset( | 524 InitializeDemuxerWithTimelineOffset( |
520 base::Time::FromJsTime(kTimelineOffsetMs)); | 525 base::Time::FromJsTime(kTimelineOffsetMs)); |
521 | 526 |
522 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 527 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
523 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 528 DemuxerStream* video = streams[0]; |
| 529 DemuxerStream* audio = streams[1]; |
524 | 530 |
525 const base::TimeDelta video_start_time = | 531 const base::TimeDelta video_start_time = |
526 base::TimeDelta::FromMicroseconds(400000); | 532 base::TimeDelta::FromMicroseconds(400000); |
527 const base::TimeDelta audio_start_time = | 533 const base::TimeDelta audio_start_time = |
528 base::TimeDelta::FromMicroseconds(396000); | 534 base::TimeDelta::FromMicroseconds(396000); |
529 | 535 |
530 // Seeking to a position lower than the start time of either stream should | 536 // Seeking to a position lower than the start time of either stream should |
531 // prefer video stream for seeking. | 537 // prefer video stream for seeking. |
532 EXPECT_EQ(video, preferred_seeking_stream(base::TimeDelta())); | 538 EXPECT_EQ(video, preferred_seeking_stream(base::TimeDelta())); |
533 // Seeking to a position that has audio data, but not video, should prefer | 539 // Seeking to a position that has audio data, but not video, should prefer |
(...skipping 25 matching lines...) Expand all Loading... |
559 | 565 |
560 TEST_F(FFmpegDemuxerTest, Read_VideoPositiveStartTime) { | 566 TEST_F(FFmpegDemuxerTest, Read_VideoPositiveStartTime) { |
561 const int64_t kTimelineOffsetMs = 1352550896000LL; | 567 const int64_t kTimelineOffsetMs = 1352550896000LL; |
562 | 568 |
563 // Test the start time is the first timestamp of the video and audio stream. | 569 // Test the start time is the first timestamp of the video and audio stream. |
564 CreateDemuxer("nonzero-start-time.webm"); | 570 CreateDemuxer("nonzero-start-time.webm"); |
565 InitializeDemuxerWithTimelineOffset( | 571 InitializeDemuxerWithTimelineOffset( |
566 base::Time::FromJsTime(kTimelineOffsetMs)); | 572 base::Time::FromJsTime(kTimelineOffsetMs)); |
567 | 573 |
568 // Attempt a read from the video stream and run the message loop until done. | 574 // Attempt a read from the video stream and run the message loop until done. |
569 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 575 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
570 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 576 DemuxerStream* video = streams[0]; |
| 577 DemuxerStream* audio = streams[1]; |
571 | 578 |
572 const base::TimeDelta video_start_time = | 579 const base::TimeDelta video_start_time = |
573 base::TimeDelta::FromMicroseconds(400000); | 580 base::TimeDelta::FromMicroseconds(400000); |
574 const base::TimeDelta audio_start_time = | 581 const base::TimeDelta audio_start_time = |
575 base::TimeDelta::FromMicroseconds(396000); | 582 base::TimeDelta::FromMicroseconds(396000); |
576 | 583 |
577 // Run the test twice with a seek in between. | 584 // Run the test twice with a seek in between. |
578 for (int i = 0; i < 2; ++i) { | 585 for (int i = 0; i < 2; ++i) { |
579 video->Read(NewReadCB(FROM_HERE, 5636, video_start_time.InMicroseconds(), | 586 video->Read(NewReadCB(FROM_HERE, 5636, video_start_time.InMicroseconds(), |
580 true)); | 587 true)); |
(...skipping 17 matching lines...) Expand all Loading... |
598 } | 605 } |
599 | 606 |
600 TEST_F(FFmpegDemuxerTest, Read_AudioNoStartTime) { | 607 TEST_F(FFmpegDemuxerTest, Read_AudioNoStartTime) { |
601 // FFmpeg does not set timestamps when demuxing wave files. Ensure that the | 608 // FFmpeg does not set timestamps when demuxing wave files. Ensure that the |
602 // demuxer sets a start time of zero in this case. | 609 // demuxer sets a start time of zero in this case. |
603 CreateDemuxer("sfx_s24le.wav"); | 610 CreateDemuxer("sfx_s24le.wav"); |
604 InitializeDemuxer(); | 611 InitializeDemuxer(); |
605 | 612 |
606 // Run the test twice with a seek in between. | 613 // Run the test twice with a seek in between. |
607 for (int i = 0; i < 2; ++i) { | 614 for (int i = 0; i < 2; ++i) { |
608 demuxer_->GetStream(DemuxerStream::AUDIO) | 615 GetStream(DemuxerStream::AUDIO)->Read(NewReadCB(FROM_HERE, 4095, 0, true)); |
609 ->Read(NewReadCB(FROM_HERE, 4095, 0, true)); | |
610 base::RunLoop().Run(); | 616 base::RunLoop().Run(); |
611 EXPECT_EQ(base::TimeDelta(), demuxer_->start_time()); | 617 EXPECT_EQ(base::TimeDelta(), demuxer_->start_time()); |
612 | 618 |
613 // Seek back to the beginning and repeat the test. | 619 // Seek back to the beginning and repeat the test. |
614 WaitableMessageLoopEvent event; | 620 WaitableMessageLoopEvent event; |
615 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB()); | 621 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB()); |
616 event.RunAndWaitForStatus(PIPELINE_OK); | 622 event.RunAndWaitForStatus(PIPELINE_OK); |
617 } | 623 } |
618 } | 624 } |
619 | 625 |
620 // TODO(dalecurtis): Test is disabled since FFmpeg does not currently guarantee | 626 // TODO(dalecurtis): Test is disabled since FFmpeg does not currently guarantee |
621 // the order of demuxed packets in OGG containers. Re-enable and fix key frame | 627 // the order of demuxed packets in OGG containers. Re-enable and fix key frame |
622 // expectations once we decide to either workaround it or attempt a fix | 628 // expectations once we decide to either workaround it or attempt a fix |
623 // upstream. See http://crbug.com/387996. | 629 // upstream. See http://crbug.com/387996. |
624 TEST_F(FFmpegDemuxerTest, | 630 TEST_F(FFmpegDemuxerTest, |
625 DISABLED_Read_AudioNegativeStartTimeAndOggDiscard_Bear) { | 631 DISABLED_Read_AudioNegativeStartTimeAndOggDiscard_Bear) { |
626 // Many ogg files have negative starting timestamps, so ensure demuxing and | 632 // Many ogg files have negative starting timestamps, so ensure demuxing and |
627 // seeking work correctly with a negative start time. | 633 // seeking work correctly with a negative start time. |
628 CreateDemuxer("bear.ogv"); | 634 CreateDemuxer("bear.ogv"); |
629 InitializeDemuxer(); | 635 InitializeDemuxer(); |
630 | 636 |
631 // Attempt a read from the video stream and run the message loop until done. | 637 // Attempt a read from the video stream and run the message loop until done. |
632 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 638 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
633 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 639 DemuxerStream* video = streams[0]; |
| 640 DemuxerStream* audio = streams[1]; |
634 | 641 |
635 // Run the test twice with a seek in between. | 642 // Run the test twice with a seek in between. |
636 for (int i = 0; i < 2; ++i) { | 643 for (int i = 0; i < 2; ++i) { |
637 audio->Read( | 644 audio->Read( |
638 NewReadCBWithCheckedDiscard(FROM_HERE, 40, 0, kInfiniteDuration, true)); | 645 NewReadCBWithCheckedDiscard(FROM_HERE, 40, 0, kInfiniteDuration, true)); |
639 base::RunLoop().Run(); | 646 base::RunLoop().Run(); |
640 audio->Read(NewReadCBWithCheckedDiscard(FROM_HERE, 41, 2903, | 647 audio->Read(NewReadCBWithCheckedDiscard(FROM_HERE, 41, 2903, |
641 kInfiniteDuration, true)); | 648 kInfiniteDuration, true)); |
642 base::RunLoop().Run(); | 649 base::RunLoop().Run(); |
643 audio->Read(NewReadCBWithCheckedDiscard( | 650 audio->Read(NewReadCBWithCheckedDiscard( |
(...skipping 24 matching lines...) Expand all Loading... |
668 // Same test above, but using sync2.ogv which has video stream muxed before the | 675 // Same test above, but using sync2.ogv which has video stream muxed before the |
669 // audio stream, so seeking based only on start time will fail since ffmpeg is | 676 // audio stream, so seeking based only on start time will fail since ffmpeg is |
670 // essentially just seeking based on file position. | 677 // essentially just seeking based on file position. |
671 TEST_F(FFmpegDemuxerTest, Read_AudioNegativeStartTimeAndOggDiscard_Sync) { | 678 TEST_F(FFmpegDemuxerTest, Read_AudioNegativeStartTimeAndOggDiscard_Sync) { |
672 // Many ogg files have negative starting timestamps, so ensure demuxing and | 679 // Many ogg files have negative starting timestamps, so ensure demuxing and |
673 // seeking work correctly with a negative start time. | 680 // seeking work correctly with a negative start time. |
674 CreateDemuxer("sync2.ogv"); | 681 CreateDemuxer("sync2.ogv"); |
675 InitializeDemuxer(); | 682 InitializeDemuxer(); |
676 | 683 |
677 // Attempt a read from the video stream and run the message loop until done. | 684 // Attempt a read from the video stream and run the message loop until done. |
678 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 685 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
679 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 686 DemuxerStream* video = streams[0]; |
| 687 DemuxerStream* audio = streams[1]; |
680 | 688 |
681 // Run the test twice with a seek in between. | 689 // Run the test twice with a seek in between. |
682 for (int i = 0; i < 2; ++i) { | 690 for (int i = 0; i < 2; ++i) { |
683 audio->Read(NewReadCBWithCheckedDiscard( | 691 audio->Read(NewReadCBWithCheckedDiscard( |
684 FROM_HERE, 1, 0, base::TimeDelta::FromMicroseconds(2902), true)); | 692 FROM_HERE, 1, 0, base::TimeDelta::FromMicroseconds(2902), true)); |
685 base::RunLoop().Run(); | 693 base::RunLoop().Run(); |
686 | 694 |
687 audio->Read(NewReadCB(FROM_HERE, 1, 2902, true)); | 695 audio->Read(NewReadCB(FROM_HERE, 1, 2902, true)); |
688 base::RunLoop().Run(); | 696 base::RunLoop().Run(); |
689 EXPECT_EQ(base::TimeDelta::FromMicroseconds(-2902), | 697 EXPECT_EQ(base::TimeDelta::FromMicroseconds(-2902), |
(...skipping 19 matching lines...) Expand all Loading... |
709 } | 717 } |
710 } | 718 } |
711 | 719 |
712 // Similar to the test above, but using an opus clip with a large amount of | 720 // Similar to the test above, but using an opus clip with a large amount of |
713 // pre-skip, which ffmpeg encodes as negative timestamps. | 721 // pre-skip, which ffmpeg encodes as negative timestamps. |
714 TEST_F(FFmpegDemuxerTest, Read_AudioNegativeStartTimeAndOpusDiscard_Sync) { | 722 TEST_F(FFmpegDemuxerTest, Read_AudioNegativeStartTimeAndOpusDiscard_Sync) { |
715 CreateDemuxer("opus-trimming-video-test.webm"); | 723 CreateDemuxer("opus-trimming-video-test.webm"); |
716 InitializeDemuxer(); | 724 InitializeDemuxer(); |
717 | 725 |
718 // Attempt a read from the video stream and run the message loop until done. | 726 // Attempt a read from the video stream and run the message loop until done. |
719 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 727 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
720 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 728 DemuxerStream* video = streams[0]; |
| 729 DemuxerStream* audio = streams[1]; |
721 EXPECT_EQ(audio->audio_decoder_config().codec_delay(), 65535); | 730 EXPECT_EQ(audio->audio_decoder_config().codec_delay(), 65535); |
722 | 731 |
723 // Packet size to timestamp (in microseconds) mapping for the first N packets | 732 // Packet size to timestamp (in microseconds) mapping for the first N packets |
724 // which should be fully discarded. | 733 // which should be fully discarded. |
725 static const int kTestExpectations[][2] = { | 734 static const int kTestExpectations[][2] = { |
726 {635, 0}, {594, 120000}, {597, 240000}, {591, 360000}, | 735 {635, 0}, {594, 120000}, {597, 240000}, {591, 360000}, |
727 {582, 480000}, {583, 600000}, {592, 720000}, {567, 840000}, | 736 {582, 480000}, {583, 600000}, {592, 720000}, {567, 840000}, |
728 {579, 960000}, {572, 1080000}, {583, 1200000}}; | 737 {579, 960000}, {572, 1080000}, {583, 1200000}}; |
729 | 738 |
730 // Run the test twice with a seek in between. | 739 // Run the test twice with a seek in between. |
(...skipping 24 matching lines...) Expand all Loading... |
755 } | 764 } |
756 } | 765 } |
757 | 766 |
758 // Similar to the test above, but using sfx-opus.ogg, which has a much smaller | 767 // Similar to the test above, but using sfx-opus.ogg, which has a much smaller |
759 // amount of discard padding and no |start_time| set on the AVStream. | 768 // amount of discard padding and no |start_time| set on the AVStream. |
760 TEST_F(FFmpegDemuxerTest, Read_AudioNegativeStartTimeAndOpusSfxDiscard_Sync) { | 769 TEST_F(FFmpegDemuxerTest, Read_AudioNegativeStartTimeAndOpusSfxDiscard_Sync) { |
761 CreateDemuxer("sfx-opus.ogg"); | 770 CreateDemuxer("sfx-opus.ogg"); |
762 InitializeDemuxer(); | 771 InitializeDemuxer(); |
763 | 772 |
764 // Attempt a read from the video stream and run the message loop until done. | 773 // Attempt a read from the video stream and run the message loop until done. |
765 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 774 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
| 775 DemuxerStream* audio = streams[0]; |
766 EXPECT_EQ(audio->audio_decoder_config().codec_delay(), 312); | 776 EXPECT_EQ(audio->audio_decoder_config().codec_delay(), 312); |
767 | 777 |
768 // Run the test twice with a seek in between. | 778 // Run the test twice with a seek in between. |
769 for (int i = 0; i < 2; ++i) { | 779 for (int i = 0; i < 2; ++i) { |
770 audio->Read(NewReadCB(FROM_HERE, 314, 0, true)); | 780 audio->Read(NewReadCB(FROM_HERE, 314, 0, true)); |
771 base::RunLoop().Run(); | 781 base::RunLoop().Run(); |
772 | 782 |
773 audio->Read(NewReadCB(FROM_HERE, 244, 20000, true)); | 783 audio->Read(NewReadCB(FROM_HERE, 244, 20000, true)); |
774 base::RunLoop().Run(); | 784 base::RunLoop().Run(); |
775 | 785 |
776 // Though the internal start time may be below zero, the exposed media time | 786 // Though the internal start time may be below zero, the exposed media time |
777 // must always be greater than zero. | 787 // must always be greater than zero. |
778 EXPECT_EQ(base::TimeDelta(), demuxer_->GetStartTime()); | 788 EXPECT_EQ(base::TimeDelta(), demuxer_->GetStartTime()); |
779 | 789 |
780 // Seek back to the beginning and repeat the test. | 790 // Seek back to the beginning and repeat the test. |
781 WaitableMessageLoopEvent event; | 791 WaitableMessageLoopEvent event; |
782 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB()); | 792 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB()); |
783 event.RunAndWaitForStatus(PIPELINE_OK); | 793 event.RunAndWaitForStatus(PIPELINE_OK); |
784 } | 794 } |
785 } | 795 } |
786 | 796 |
787 TEST_F(FFmpegDemuxerTest, Read_EndOfStream) { | 797 TEST_F(FFmpegDemuxerTest, Read_EndOfStream) { |
788 // Verify that end of stream buffers are created. | 798 // Verify that end of stream buffers are created. |
789 CreateDemuxer("bear-320x240.webm"); | 799 CreateDemuxer("bear-320x240.webm"); |
790 InitializeDemuxer(); | 800 InitializeDemuxer(); |
791 ReadUntilEndOfStream(demuxer_->GetStream(DemuxerStream::AUDIO)); | 801 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); |
| 802 DemuxerStream* audio = streams[0]; |
| 803 ReadUntilEndOfStream(audio); |
792 } | 804 } |
793 | 805 |
794 TEST_F(FFmpegDemuxerTest, Read_EndOfStreamText) { | 806 TEST_F(FFmpegDemuxerTest, Read_EndOfStreamText) { |
795 // Verify that end of stream buffers are created. | 807 // Verify that end of stream buffers are created. |
796 CreateDemuxer("bear-vp8-webvtt.webm"); | 808 CreateDemuxer("bear-vp8-webvtt.webm"); |
797 DemuxerStream* text_stream = NULL; | 809 DemuxerStream* text_stream = NULL; |
798 EXPECT_CALL(host_, AddTextStream(_, _)) | 810 EXPECT_CALL(host_, AddTextStream(_, _)) |
799 .WillOnce(SaveArg<0>(&text_stream)); | 811 .WillOnce(SaveArg<0>(&text_stream)); |
800 InitializeDemuxerWithText(); | 812 InitializeDemuxerWithText(); |
801 ASSERT_TRUE(text_stream); | 813 ASSERT_TRUE(text_stream); |
802 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type()); | 814 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type()); |
803 | 815 |
804 bool got_eos_buffer = false; | 816 bool got_eos_buffer = false; |
805 const int kMaxBuffers = 10; | 817 const int kMaxBuffers = 10; |
806 for (int i = 0; !got_eos_buffer && i < kMaxBuffers; i++) { | 818 for (int i = 0; !got_eos_buffer && i < kMaxBuffers; i++) { |
807 text_stream->Read(base::Bind(&EosOnReadDone, &got_eos_buffer)); | 819 text_stream->Read(base::Bind(&EosOnReadDone, &got_eos_buffer)); |
808 base::RunLoop().Run(); | 820 base::RunLoop().Run(); |
809 } | 821 } |
810 | 822 |
811 EXPECT_TRUE(got_eos_buffer); | 823 EXPECT_TRUE(got_eos_buffer); |
812 } | 824 } |
813 | 825 |
814 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration) { | 826 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration) { |
815 // Verify that end of stream buffers are created. | 827 // Verify that end of stream buffers are created. |
816 CreateDemuxer("bear-320x240.webm"); | 828 CreateDemuxer("bear-320x240.webm"); |
817 InitializeDemuxer(); | 829 InitializeDemuxer(); |
818 set_duration_known(false); | 830 set_duration_known(false); |
819 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2767))); | 831 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2767))); |
820 ReadUntilEndOfStream(demuxer_->GetStream(DemuxerStream::AUDIO)); | 832 ReadUntilEndOfStream(GetStream(DemuxerStream::AUDIO)); |
821 ReadUntilEndOfStream(demuxer_->GetStream(DemuxerStream::VIDEO)); | 833 ReadUntilEndOfStream(GetStream(DemuxerStream::VIDEO)); |
822 } | 834 } |
823 | 835 |
824 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration_VideoOnly) { | 836 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration_VideoOnly) { |
825 // Verify that end of stream buffers are created. | 837 // Verify that end of stream buffers are created. |
826 CreateDemuxer("bear-320x240-video-only.webm"); | 838 CreateDemuxer("bear-320x240-video-only.webm"); |
827 InitializeDemuxer(); | 839 InitializeDemuxer(); |
828 set_duration_known(false); | 840 set_duration_known(false); |
829 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2736))); | 841 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2736))); |
830 ReadUntilEndOfStream(demuxer_->GetStream(DemuxerStream::VIDEO)); | 842 ReadUntilEndOfStream(GetStream(DemuxerStream::VIDEO)); |
831 } | 843 } |
832 | 844 |
833 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration_AudioOnly) { | 845 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration_AudioOnly) { |
834 // Verify that end of stream buffers are created. | 846 // Verify that end of stream buffers are created. |
835 CreateDemuxer("bear-320x240-audio-only.webm"); | 847 CreateDemuxer("bear-320x240-audio-only.webm"); |
836 InitializeDemuxer(); | 848 InitializeDemuxer(); |
837 set_duration_known(false); | 849 set_duration_known(false); |
838 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2767))); | 850 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2767))); |
839 ReadUntilEndOfStream(demuxer_->GetStream(DemuxerStream::AUDIO)); | 851 ReadUntilEndOfStream(GetStream(DemuxerStream::AUDIO)); |
840 } | 852 } |
841 | 853 |
842 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration_UnsupportedStream) { | 854 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration_UnsupportedStream) { |
843 // Verify that end of stream buffers are created and we don't crash | 855 // Verify that end of stream buffers are created and we don't crash |
844 // if there are streams in the file that we don't support. | 856 // if there are streams in the file that we don't support. |
845 CreateDemuxer("vorbis_audio_wmv_video.mkv"); | 857 CreateDemuxer("vorbis_audio_wmv_video.mkv"); |
846 InitializeDemuxer(); | 858 InitializeDemuxer(); |
847 set_duration_known(false); | 859 set_duration_known(false); |
848 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(1014))); | 860 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(1014))); |
849 ReadUntilEndOfStream(demuxer_->GetStream(DemuxerStream::AUDIO)); | 861 ReadUntilEndOfStream(GetStream(DemuxerStream::AUDIO)); |
850 } | 862 } |
851 | 863 |
852 TEST_F(FFmpegDemuxerTest, Seek) { | 864 TEST_F(FFmpegDemuxerTest, Seek) { |
853 // We're testing that the demuxer frees all queued packets when it receives | 865 // We're testing that the demuxer frees all queued packets when it receives |
854 // a Seek(). | 866 // a Seek(). |
855 CreateDemuxer("bear-320x240.webm"); | 867 CreateDemuxer("bear-320x240.webm"); |
856 InitializeDemuxer(); | 868 InitializeDemuxer(); |
857 | 869 |
858 // Get our streams. | 870 // Get our streams. |
859 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 871 DemuxerStream* video = GetStream(DemuxerStream::VIDEO); |
860 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 872 DemuxerStream* audio = GetStream(DemuxerStream::AUDIO); |
861 ASSERT_TRUE(video); | 873 ASSERT_TRUE(video); |
862 ASSERT_TRUE(audio); | 874 ASSERT_TRUE(audio); |
863 | 875 |
864 // Read a video packet and release it. | 876 // Read a video packet and release it. |
865 video->Read(NewReadCB(FROM_HERE, 22084, 0, true)); | 877 video->Read(NewReadCB(FROM_HERE, 22084, 0, true)); |
866 base::RunLoop().Run(); | 878 base::RunLoop().Run(); |
867 | 879 |
868 // Issue a simple forward seek, which should discard queued packets. | 880 // Issue a simple forward seek, which should discard queued packets. |
869 WaitableMessageLoopEvent event; | 881 WaitableMessageLoopEvent event; |
870 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000), | 882 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000), |
(...skipping 15 matching lines...) Expand all Loading... |
886 // Video read #2. | 898 // Video read #2. |
887 video->Read(NewReadCB(FROM_HERE, 1906, 834000, false)); | 899 video->Read(NewReadCB(FROM_HERE, 1906, 834000, false)); |
888 base::RunLoop().Run(); | 900 base::RunLoop().Run(); |
889 } | 901 } |
890 | 902 |
891 TEST_F(FFmpegDemuxerTest, CancelledSeek) { | 903 TEST_F(FFmpegDemuxerTest, CancelledSeek) { |
892 CreateDemuxer("bear-320x240.webm"); | 904 CreateDemuxer("bear-320x240.webm"); |
893 InitializeDemuxer(); | 905 InitializeDemuxer(); |
894 | 906 |
895 // Get our streams. | 907 // Get our streams. |
896 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 908 DemuxerStream* video = GetStream(DemuxerStream::VIDEO); |
897 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 909 DemuxerStream* audio = GetStream(DemuxerStream::AUDIO); |
898 ASSERT_TRUE(video); | 910 ASSERT_TRUE(video); |
899 ASSERT_TRUE(audio); | 911 ASSERT_TRUE(audio); |
900 | 912 |
901 // Read a video packet and release it. | 913 // Read a video packet and release it. |
902 video->Read(NewReadCB(FROM_HERE, 22084, 0, true)); | 914 video->Read(NewReadCB(FROM_HERE, 22084, 0, true)); |
903 base::RunLoop().Run(); | 915 base::RunLoop().Run(); |
904 | 916 |
905 // Issue a simple forward seek, which should discard queued packets. | 917 // Issue a simple forward seek, which should discard queued packets. |
906 WaitableMessageLoopEvent event; | 918 WaitableMessageLoopEvent event; |
907 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000), | 919 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000), |
908 event.GetPipelineStatusCB()); | 920 event.GetPipelineStatusCB()); |
909 // FFmpegDemuxer does not care what the previous seek time was when canceling. | 921 // FFmpegDemuxer does not care what the previous seek time was when canceling. |
910 demuxer_->CancelPendingSeek(base::TimeDelta::FromSeconds(12345)); | 922 demuxer_->CancelPendingSeek(base::TimeDelta::FromSeconds(12345)); |
911 event.RunAndWaitForStatus(PIPELINE_OK); | 923 event.RunAndWaitForStatus(PIPELINE_OK); |
912 } | 924 } |
913 | 925 |
914 TEST_F(FFmpegDemuxerTest, SeekText) { | 926 TEST_F(FFmpegDemuxerTest, SeekText) { |
915 // We're testing that the demuxer frees all queued packets when it receives | 927 // We're testing that the demuxer frees all queued packets when it receives |
916 // a Seek(). | 928 // a Seek(). |
917 CreateDemuxer("bear-vp8-webvtt.webm"); | 929 CreateDemuxer("bear-vp8-webvtt.webm"); |
918 DemuxerStream* text_stream = NULL; | 930 DemuxerStream* text_stream = NULL; |
919 EXPECT_CALL(host_, AddTextStream(_, _)) | 931 EXPECT_CALL(host_, AddTextStream(_, _)) |
920 .WillOnce(SaveArg<0>(&text_stream)); | 932 .WillOnce(SaveArg<0>(&text_stream)); |
921 InitializeDemuxerWithText(); | 933 InitializeDemuxerWithText(); |
922 ASSERT_TRUE(text_stream); | 934 ASSERT_TRUE(text_stream); |
923 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type()); | 935 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type()); |
924 | 936 |
925 // Get our streams. | 937 // Get our streams. |
926 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 938 DemuxerStream* video = GetStream(DemuxerStream::VIDEO); |
927 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 939 DemuxerStream* audio = GetStream(DemuxerStream::AUDIO); |
928 ASSERT_TRUE(video); | 940 ASSERT_TRUE(video); |
929 ASSERT_TRUE(audio); | 941 ASSERT_TRUE(audio); |
930 | 942 |
931 // Read a text packet and release it. | 943 // Read a text packet and release it. |
932 text_stream->Read(NewReadCB(FROM_HERE, 31, 0, true)); | 944 text_stream->Read(NewReadCB(FROM_HERE, 31, 0, true)); |
933 base::RunLoop().Run(); | 945 base::RunLoop().Run(); |
934 | 946 |
935 // Issue a simple forward seek, which should discard queued packets. | 947 // Issue a simple forward seek, which should discard queued packets. |
936 WaitableMessageLoopEvent event; | 948 WaitableMessageLoopEvent event; |
937 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000), | 949 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000), |
(...skipping 25 matching lines...) Expand all Loading... |
963 base::RunLoop().Run(); | 975 base::RunLoop().Run(); |
964 } | 976 } |
965 | 977 |
966 TEST_F(FFmpegDemuxerTest, Stop) { | 978 TEST_F(FFmpegDemuxerTest, Stop) { |
967 // Tests that calling Read() on a stopped demuxer stream immediately deletes | 979 // Tests that calling Read() on a stopped demuxer stream immediately deletes |
968 // the callback. | 980 // the callback. |
969 CreateDemuxer("bear-320x240.webm"); | 981 CreateDemuxer("bear-320x240.webm"); |
970 InitializeDemuxer(); | 982 InitializeDemuxer(); |
971 | 983 |
972 // Get our stream. | 984 // Get our stream. |
973 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 985 DemuxerStream* audio = GetStream(DemuxerStream::AUDIO); |
974 ASSERT_TRUE(audio); | 986 ASSERT_TRUE(audio); |
975 | 987 |
976 demuxer_->Stop(); | 988 demuxer_->Stop(); |
977 | 989 |
978 // Reads after being stopped are all EOS buffers. | 990 // Reads after being stopped are all EOS buffers. |
979 StrictMock<base::MockCallback<DemuxerStream::ReadCB>> callback; | 991 StrictMock<base::MockCallback<DemuxerStream::ReadCB>> callback; |
980 EXPECT_CALL(callback, Run(DemuxerStream::kOk, IsEndOfStreamBuffer())); | 992 EXPECT_CALL(callback, Run(DemuxerStream::kOk, IsEndOfStreamBuffer())); |
981 | 993 |
982 // Attempt the read... | 994 // Attempt the read... |
983 audio->Read(callback.Get()); | 995 audio->Read(callback.Get()); |
984 base::RunLoop().RunUntilIdle(); | 996 base::RunLoop().RunUntilIdle(); |
985 | 997 |
986 // Don't let the test call Stop() again. | 998 // Don't let the test call Stop() again. |
987 demuxer_.reset(); | 999 demuxer_.reset(); |
988 } | 1000 } |
989 | 1001 |
990 // Verify that seek works properly when the WebM cues data is at the start of | 1002 // Verify that seek works properly when the WebM cues data is at the start of |
991 // the file instead of at the end. | 1003 // the file instead of at the end. |
992 TEST_F(FFmpegDemuxerTest, SeekWithCuesBeforeFirstCluster) { | 1004 TEST_F(FFmpegDemuxerTest, SeekWithCuesBeforeFirstCluster) { |
993 CreateDemuxer("bear-320x240-cues-in-front.webm"); | 1005 CreateDemuxer("bear-320x240-cues-in-front.webm"); |
994 InitializeDemuxer(); | 1006 InitializeDemuxer(); |
995 | 1007 |
996 // Get our streams. | 1008 // Get our streams. |
997 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 1009 DemuxerStream* video = GetStream(DemuxerStream::VIDEO); |
998 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 1010 DemuxerStream* audio = GetStream(DemuxerStream::AUDIO); |
999 ASSERT_TRUE(video); | 1011 ASSERT_TRUE(video); |
1000 ASSERT_TRUE(audio); | 1012 ASSERT_TRUE(audio); |
1001 | 1013 |
1002 // Read a video packet and release it. | 1014 // Read a video packet and release it. |
1003 video->Read(NewReadCB(FROM_HERE, 22084, 0, true)); | 1015 video->Read(NewReadCB(FROM_HERE, 22084, 0, true)); |
1004 base::RunLoop().Run(); | 1016 base::RunLoop().Run(); |
1005 | 1017 |
1006 // Issue a simple forward seek, which should discard queued packets. | 1018 // Issue a simple forward seek, which should discard queued packets. |
1007 WaitableMessageLoopEvent event; | 1019 WaitableMessageLoopEvent event; |
1008 demuxer_->Seek(base::TimeDelta::FromMicroseconds(2500000), | 1020 demuxer_->Seek(base::TimeDelta::FromMicroseconds(2500000), |
(...skipping 29 matching lines...) Expand all Loading... |
1038 | 1050 |
1039 #if BUILDFLAG(USE_PROPRIETARY_CODECS) | 1051 #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
1040 // Ensure MP3 files with large image/video based ID3 tags demux okay. FFmpeg | 1052 // Ensure MP3 files with large image/video based ID3 tags demux okay. FFmpeg |
1041 // will hand us a video stream to the data which will likely be in a format we | 1053 // will hand us a video stream to the data which will likely be in a format we |
1042 // don't accept as video; e.g. PNG. | 1054 // don't accept as video; e.g. PNG. |
1043 TEST_F(FFmpegDemuxerTest, Mp3WithVideoStreamID3TagData) { | 1055 TEST_F(FFmpegDemuxerTest, Mp3WithVideoStreamID3TagData) { |
1044 CreateDemuxer("id3_png_test.mp3"); | 1056 CreateDemuxer("id3_png_test.mp3"); |
1045 InitializeDemuxer(); | 1057 InitializeDemuxer(); |
1046 | 1058 |
1047 // Ensure the expected streams are present. | 1059 // Ensure the expected streams are present. |
1048 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::VIDEO)); | 1060 EXPECT_FALSE(GetStream(DemuxerStream::VIDEO)); |
1049 EXPECT_TRUE(demuxer_->GetStream(DemuxerStream::AUDIO)); | 1061 EXPECT_TRUE(GetStream(DemuxerStream::AUDIO)); |
1050 } | 1062 } |
1051 #endif | 1063 #endif |
1052 | 1064 |
1053 // Ensure a video with an unsupported audio track still results in the video | 1065 // Ensure a video with an unsupported audio track still results in the video |
1054 // stream being demuxed. | 1066 // stream being demuxed. |
1055 TEST_F(FFmpegDemuxerTest, UnsupportedAudioSupportedVideoDemux) { | 1067 TEST_F(FFmpegDemuxerTest, UnsupportedAudioSupportedVideoDemux) { |
1056 CreateDemuxer("speex_audio_vorbis_video.ogv"); | 1068 CreateDemuxer("speex_audio_vorbis_video.ogv"); |
1057 InitializeDemuxer(); | 1069 InitializeDemuxer(); |
1058 | 1070 |
1059 // Ensure the expected streams are present. | 1071 // Ensure the expected streams are present. |
1060 EXPECT_TRUE(demuxer_->GetStream(DemuxerStream::VIDEO)); | 1072 EXPECT_TRUE(GetStream(DemuxerStream::VIDEO)); |
1061 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::AUDIO)); | 1073 EXPECT_FALSE(GetStream(DemuxerStream::AUDIO)); |
1062 } | 1074 } |
1063 | 1075 |
1064 // Ensure a video with an unsupported video track still results in the audio | 1076 // Ensure a video with an unsupported video track still results in the audio |
1065 // stream being demuxed. | 1077 // stream being demuxed. |
1066 TEST_F(FFmpegDemuxerTest, UnsupportedVideoSupportedAudioDemux) { | 1078 TEST_F(FFmpegDemuxerTest, UnsupportedVideoSupportedAudioDemux) { |
1067 CreateDemuxer("vorbis_audio_wmv_video.mkv"); | 1079 CreateDemuxer("vorbis_audio_wmv_video.mkv"); |
1068 InitializeDemuxer(); | 1080 InitializeDemuxer(); |
1069 | 1081 |
1070 // Ensure the expected streams are present. | 1082 // Ensure the expected streams are present. |
1071 EXPECT_FALSE(demuxer_->GetStream(DemuxerStream::VIDEO)); | 1083 EXPECT_FALSE(GetStream(DemuxerStream::VIDEO)); |
1072 EXPECT_TRUE(demuxer_->GetStream(DemuxerStream::AUDIO)); | 1084 EXPECT_TRUE(GetStream(DemuxerStream::AUDIO)); |
1073 } | 1085 } |
1074 | 1086 |
1075 #if BUILDFLAG(USE_PROPRIETARY_CODECS) | 1087 #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
1076 // FFmpeg returns null data pointers when samples have zero size, leading to | 1088 // FFmpeg returns null data pointers when samples have zero size, leading to |
1077 // mistakenly creating end of stream buffers http://crbug.com/169133 | 1089 // mistakenly creating end of stream buffers http://crbug.com/169133 |
1078 TEST_F(FFmpegDemuxerTest, MP4_ZeroStszEntry) { | 1090 TEST_F(FFmpegDemuxerTest, MP4_ZeroStszEntry) { |
1079 CreateDemuxer("bear-1280x720-zero-stsz-entry.mp4"); | 1091 CreateDemuxer("bear-1280x720-zero-stsz-entry.mp4"); |
1080 InitializeDemuxer(); | 1092 InitializeDemuxer(); |
1081 ReadUntilEndOfStream(demuxer_->GetStream(DemuxerStream::AUDIO)); | 1093 ReadUntilEndOfStream(GetStream(DemuxerStream::AUDIO)); |
1082 } | 1094 } |
1083 | 1095 |
1084 class Mp3SeekFFmpegDemuxerTest | 1096 class Mp3SeekFFmpegDemuxerTest |
1085 : public FFmpegDemuxerTest, | 1097 : public FFmpegDemuxerTest, |
1086 public testing::WithParamInterface<const char*> { | 1098 public testing::WithParamInterface<const char*> { |
1087 }; | 1099 }; |
1088 TEST_P(Mp3SeekFFmpegDemuxerTest, TestFastSeek) { | 1100 TEST_P(Mp3SeekFFmpegDemuxerTest, TestFastSeek) { |
1089 // Init demxuer with given MP3 file parameter. | 1101 // Init demxuer with given MP3 file parameter. |
1090 CreateDemuxer(GetParam()); | 1102 CreateDemuxer(GetParam()); |
1091 InitializeDemuxer(); | 1103 InitializeDemuxer(); |
1092 | 1104 |
1093 // We read a bunch of bytes when we first open the file. Reset the count | 1105 // We read a bunch of bytes when we first open the file. Reset the count |
1094 // here to just track the bytes read for the upcoming seek. This allows us | 1106 // here to just track the bytes read for the upcoming seek. This allows us |
1095 // to use a more narrow threshold for passing the test. | 1107 // to use a more narrow threshold for passing the test. |
1096 data_source_->reset_bytes_read_for_testing(); | 1108 data_source_->reset_bytes_read_for_testing(); |
1097 | 1109 |
1098 FFmpegDemuxerStream* audio = static_cast<FFmpegDemuxerStream*>( | 1110 FFmpegDemuxerStream* audio = |
1099 demuxer_->GetStream(DemuxerStream::AUDIO)); | 1111 static_cast<FFmpegDemuxerStream*>(GetStream(DemuxerStream::AUDIO)); |
1100 ASSERT_TRUE(audio); | 1112 ASSERT_TRUE(audio); |
1101 | 1113 |
1102 // Seek to near the end of the file | 1114 // Seek to near the end of the file |
1103 WaitableMessageLoopEvent event; | 1115 WaitableMessageLoopEvent event; |
1104 demuxer_->Seek(.9 * audio->duration(), event.GetPipelineStatusCB()); | 1116 demuxer_->Seek(.9 * audio->duration(), event.GetPipelineStatusCB()); |
1105 event.RunAndWaitForStatus(PIPELINE_OK); | 1117 event.RunAndWaitForStatus(PIPELINE_OK); |
1106 | 1118 |
1107 // Verify that seeking to the end read only a small portion of the file. | 1119 // Verify that seeking to the end read only a small portion of the file. |
1108 // Slow seeks that read sequentially up to the seek point will read too many | 1120 // Slow seeks that read sequentially up to the seek point will read too many |
1109 // bytes and fail this check. | 1121 // bytes and fail this check. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 "bear-1280x720-av_frag.mp4", | 1169 "bear-1280x720-av_frag.mp4", |
1158 "bear-1280x720-av_with-aud-nalus_frag.mp4" | 1170 "bear-1280x720-av_with-aud-nalus_frag.mp4" |
1159 }; | 1171 }; |
1160 | 1172 |
1161 for (size_t i = 0; i < arraysize(files); ++i) { | 1173 for (size_t i = 0; i < arraysize(files); ++i) { |
1162 DVLOG(1) << "Testing " << files[i]; | 1174 DVLOG(1) << "Testing " << files[i]; |
1163 CreateDemuxer(files[i]); | 1175 CreateDemuxer(files[i]); |
1164 InitializeDemuxer(); | 1176 InitializeDemuxer(); |
1165 | 1177 |
1166 // Ensure the expected streams are present. | 1178 // Ensure the expected streams are present. |
1167 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1179 DemuxerStream* stream = GetStream(DemuxerStream::VIDEO); |
1168 ASSERT_TRUE(stream); | 1180 ASSERT_TRUE(stream); |
1169 stream->EnableBitstreamConverter(); | 1181 stream->EnableBitstreamConverter(); |
1170 | 1182 |
1171 stream->Read(base::Bind(&ValidateAnnexB, stream)); | 1183 stream->Read(base::Bind(&ValidateAnnexB, stream)); |
1172 base::RunLoop().Run(); | 1184 base::RunLoop().Run(); |
1173 | 1185 |
1174 demuxer_->Stop(); | 1186 demuxer_->Stop(); |
1175 demuxer_.reset(); | 1187 demuxer_.reset(); |
1176 data_source_.reset(); | 1188 data_source_.reset(); |
1177 } | 1189 } |
1178 } | 1190 } |
1179 | 1191 |
1180 TEST_F(FFmpegDemuxerTest, Rotate_Metadata_0) { | 1192 TEST_F(FFmpegDemuxerTest, Rotate_Metadata_0) { |
1181 CreateDemuxer("bear_rotate_0.mp4"); | 1193 CreateDemuxer("bear_rotate_0.mp4"); |
1182 InitializeDemuxer(); | 1194 InitializeDemuxer(); |
1183 | 1195 |
1184 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1196 DemuxerStream* stream = GetStream(DemuxerStream::VIDEO); |
1185 ASSERT_TRUE(stream); | 1197 ASSERT_TRUE(stream); |
1186 ASSERT_EQ(VIDEO_ROTATION_0, stream->video_rotation()); | 1198 ASSERT_EQ(VIDEO_ROTATION_0, stream->video_rotation()); |
1187 } | 1199 } |
1188 | 1200 |
1189 TEST_F(FFmpegDemuxerTest, Rotate_Metadata_90) { | 1201 TEST_F(FFmpegDemuxerTest, Rotate_Metadata_90) { |
1190 CreateDemuxer("bear_rotate_90.mp4"); | 1202 CreateDemuxer("bear_rotate_90.mp4"); |
1191 InitializeDemuxer(); | 1203 InitializeDemuxer(); |
1192 | 1204 |
1193 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1205 DemuxerStream* stream = GetStream(DemuxerStream::VIDEO); |
1194 ASSERT_TRUE(stream); | 1206 ASSERT_TRUE(stream); |
1195 ASSERT_EQ(VIDEO_ROTATION_90, stream->video_rotation()); | 1207 ASSERT_EQ(VIDEO_ROTATION_90, stream->video_rotation()); |
1196 } | 1208 } |
1197 | 1209 |
1198 TEST_F(FFmpegDemuxerTest, Rotate_Metadata_180) { | 1210 TEST_F(FFmpegDemuxerTest, Rotate_Metadata_180) { |
1199 CreateDemuxer("bear_rotate_180.mp4"); | 1211 CreateDemuxer("bear_rotate_180.mp4"); |
1200 InitializeDemuxer(); | 1212 InitializeDemuxer(); |
1201 | 1213 |
1202 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1214 DemuxerStream* stream = GetStream(DemuxerStream::VIDEO); |
1203 ASSERT_TRUE(stream); | 1215 ASSERT_TRUE(stream); |
1204 ASSERT_EQ(VIDEO_ROTATION_180, stream->video_rotation()); | 1216 ASSERT_EQ(VIDEO_ROTATION_180, stream->video_rotation()); |
1205 } | 1217 } |
1206 | 1218 |
1207 TEST_F(FFmpegDemuxerTest, Rotate_Metadata_270) { | 1219 TEST_F(FFmpegDemuxerTest, Rotate_Metadata_270) { |
1208 CreateDemuxer("bear_rotate_270.mp4"); | 1220 CreateDemuxer("bear_rotate_270.mp4"); |
1209 InitializeDemuxer(); | 1221 InitializeDemuxer(); |
1210 | 1222 |
1211 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1223 DemuxerStream* stream = GetStream(DemuxerStream::VIDEO); |
1212 ASSERT_TRUE(stream); | 1224 ASSERT_TRUE(stream); |
1213 ASSERT_EQ(VIDEO_ROTATION_270, stream->video_rotation()); | 1225 ASSERT_EQ(VIDEO_ROTATION_270, stream->video_rotation()); |
1214 } | 1226 } |
1215 | 1227 |
1216 TEST_F(FFmpegDemuxerTest, NaturalSizeWithoutPASP) { | 1228 TEST_F(FFmpegDemuxerTest, NaturalSizeWithoutPASP) { |
1217 CreateDemuxer("bear-640x360-non_square_pixel-without_pasp.mp4"); | 1229 CreateDemuxer("bear-640x360-non_square_pixel-without_pasp.mp4"); |
1218 InitializeDemuxer(); | 1230 InitializeDemuxer(); |
1219 | 1231 |
1220 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1232 DemuxerStream* stream = GetStream(DemuxerStream::VIDEO); |
1221 ASSERT_TRUE(stream); | 1233 ASSERT_TRUE(stream); |
1222 | 1234 |
1223 const VideoDecoderConfig& video_config = stream->video_decoder_config(); | 1235 const VideoDecoderConfig& video_config = stream->video_decoder_config(); |
1224 EXPECT_EQ(gfx::Size(639, 360), video_config.natural_size()); | 1236 EXPECT_EQ(gfx::Size(639, 360), video_config.natural_size()); |
1225 } | 1237 } |
1226 | 1238 |
1227 TEST_F(FFmpegDemuxerTest, NaturalSizeWithPASP) { | 1239 TEST_F(FFmpegDemuxerTest, NaturalSizeWithPASP) { |
1228 CreateDemuxer("bear-640x360-non_square_pixel-with_pasp.mp4"); | 1240 CreateDemuxer("bear-640x360-non_square_pixel-with_pasp.mp4"); |
1229 InitializeDemuxer(); | 1241 InitializeDemuxer(); |
1230 | 1242 |
1231 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1243 DemuxerStream* stream = GetStream(DemuxerStream::VIDEO); |
1232 ASSERT_TRUE(stream); | 1244 ASSERT_TRUE(stream); |
1233 | 1245 |
1234 const VideoDecoderConfig& video_config = stream->video_decoder_config(); | 1246 const VideoDecoderConfig& video_config = stream->video_decoder_config(); |
1235 EXPECT_EQ(gfx::Size(639, 360), video_config.natural_size()); | 1247 EXPECT_EQ(gfx::Size(639, 360), video_config.natural_size()); |
1236 } | 1248 } |
1237 | 1249 |
1238 TEST_F(FFmpegDemuxerTest, HEVC_in_MP4_container) { | 1250 TEST_F(FFmpegDemuxerTest, HEVC_in_MP4_container) { |
1239 CreateDemuxer("bear-hevc-frag.mp4"); | 1251 CreateDemuxer("bear-hevc-frag.mp4"); |
1240 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 1252 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
1241 InitializeDemuxer(); | 1253 InitializeDemuxer(); |
1242 | 1254 |
1243 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 1255 DemuxerStream* video = GetStream(DemuxerStream::VIDEO); |
1244 ASSERT_TRUE(video); | 1256 ASSERT_TRUE(video); |
1245 | 1257 |
1246 video->Read(NewReadCB(FROM_HERE, 3569, 66733, true)); | 1258 video->Read(NewReadCB(FROM_HERE, 3569, 66733, true)); |
1247 base::RunLoop().Run(); | 1259 base::RunLoop().Run(); |
1248 | 1260 |
1249 video->Read(NewReadCB(FROM_HERE, 1042, 200200, false)); | 1261 video->Read(NewReadCB(FROM_HERE, 1042, 200200, false)); |
1250 base::RunLoop().Run(); | 1262 base::RunLoop().Run(); |
1251 #else | 1263 #else |
1252 InitializeDemuxerAndExpectPipelineStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); | 1264 InitializeDemuxerAndExpectPipelineStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); |
1253 #endif | 1265 #endif |
1254 } | 1266 } |
1255 | 1267 |
1256 TEST_F(FFmpegDemuxerTest, Read_AC3_Audio) { | 1268 TEST_F(FFmpegDemuxerTest, Read_AC3_Audio) { |
1257 CreateDemuxer("bear-ac3-only-frag.mp4"); | 1269 CreateDemuxer("bear-ac3-only-frag.mp4"); |
1258 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 1270 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
1259 InitializeDemuxer(); | 1271 InitializeDemuxer(); |
1260 | 1272 |
1261 // Attempt a read from the audio stream and run the message loop until done. | 1273 // Attempt a read from the audio stream and run the message loop until done. |
1262 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 1274 DemuxerStream* audio = GetStream(DemuxerStream::AUDIO); |
1263 | 1275 |
1264 // Read the first two frames and check that we are getting expected data | 1276 // Read the first two frames and check that we are getting expected data |
1265 audio->Read(NewReadCB(FROM_HERE, 834, 0, true)); | 1277 audio->Read(NewReadCB(FROM_HERE, 834, 0, true)); |
1266 base::RunLoop().Run(); | 1278 base::RunLoop().Run(); |
1267 | 1279 |
1268 audio->Read(NewReadCB(FROM_HERE, 836, 34830, true)); | 1280 audio->Read(NewReadCB(FROM_HERE, 836, 34830, true)); |
1269 base::RunLoop().Run(); | 1281 base::RunLoop().Run(); |
1270 #else | 1282 #else |
1271 InitializeDemuxerAndExpectPipelineStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); | 1283 InitializeDemuxerAndExpectPipelineStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); |
1272 #endif | 1284 #endif |
1273 } | 1285 } |
1274 | 1286 |
1275 TEST_F(FFmpegDemuxerTest, Read_EAC3_Audio) { | 1287 TEST_F(FFmpegDemuxerTest, Read_EAC3_Audio) { |
1276 CreateDemuxer("bear-eac3-only-frag.mp4"); | 1288 CreateDemuxer("bear-eac3-only-frag.mp4"); |
1277 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 1289 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
1278 InitializeDemuxer(); | 1290 InitializeDemuxer(); |
1279 | 1291 |
1280 // Attempt a read from the audio stream and run the message loop until done. | 1292 // Attempt a read from the audio stream and run the message loop until done. |
1281 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 1293 DemuxerStream* audio = GetStream(DemuxerStream::AUDIO); |
1282 | 1294 |
1283 // Read the first two frames and check that we are getting expected data | 1295 // Read the first two frames and check that we are getting expected data |
1284 audio->Read(NewReadCB(FROM_HERE, 870, 0, true)); | 1296 audio->Read(NewReadCB(FROM_HERE, 870, 0, true)); |
1285 base::RunLoop().Run(); | 1297 base::RunLoop().Run(); |
1286 | 1298 |
1287 audio->Read(NewReadCB(FROM_HERE, 872, 34830, true)); | 1299 audio->Read(NewReadCB(FROM_HERE, 872, 34830, true)); |
1288 base::RunLoop().Run(); | 1300 base::RunLoop().Run(); |
1289 #else | 1301 #else |
1290 InitializeDemuxerAndExpectPipelineStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); | 1302 InitializeDemuxerAndExpectPipelineStatus(DEMUXER_ERROR_NO_SUPPORTED_STREAMS); |
1291 #endif | 1303 #endif |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1450 EXPECT_FALSE(base::Time::FromUTCString(date_string, &result)) | 1462 EXPECT_FALSE(base::Time::FromUTCString(date_string, &result)) |
1451 << "date_string '" << date_string << "'"; | 1463 << "date_string '" << date_string << "'"; |
1452 } | 1464 } |
1453 } | 1465 } |
1454 | 1466 |
1455 TEST_F(FFmpegDemuxerTest, Read_Flac) { | 1467 TEST_F(FFmpegDemuxerTest, Read_Flac) { |
1456 CreateDemuxer("sfx.flac"); | 1468 CreateDemuxer("sfx.flac"); |
1457 InitializeDemuxer(); | 1469 InitializeDemuxer(); |
1458 | 1470 |
1459 // Video stream should not be present. | 1471 // Video stream should not be present. |
1460 EXPECT_EQ(nullptr, demuxer_->GetStream(DemuxerStream::VIDEO)); | 1472 EXPECT_EQ(nullptr, GetStream(DemuxerStream::VIDEO)); |
1461 | 1473 |
1462 // Audio stream should be present. | 1474 // Audio stream should be present. |
1463 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1475 DemuxerStream* stream = GetStream(DemuxerStream::AUDIO); |
1464 ASSERT_TRUE(stream); | 1476 ASSERT_TRUE(stream); |
1465 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); | 1477 EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); |
1466 | 1478 |
1467 const AudioDecoderConfig& audio_config = stream->audio_decoder_config(); | 1479 const AudioDecoderConfig& audio_config = stream->audio_decoder_config(); |
1468 EXPECT_EQ(kCodecFLAC, audio_config.codec()); | 1480 EXPECT_EQ(kCodecFLAC, audio_config.codec()); |
1469 EXPECT_EQ(32, audio_config.bits_per_channel()); | 1481 EXPECT_EQ(32, audio_config.bits_per_channel()); |
1470 EXPECT_EQ(CHANNEL_LAYOUT_MONO, audio_config.channel_layout()); | 1482 EXPECT_EQ(CHANNEL_LAYOUT_MONO, audio_config.channel_layout()); |
1471 EXPECT_EQ(44100, audio_config.samples_per_second()); | 1483 EXPECT_EQ(44100, audio_config.samples_per_second()); |
1472 EXPECT_EQ(kSampleFormatS32, audio_config.sample_format()); | 1484 EXPECT_EQ(kSampleFormatS32, audio_config.sample_format()); |
1473 } | 1485 } |
1474 | 1486 |
1475 // Verify that FFmpeg demuxer falls back to choosing disabled streams for | 1487 // Verify that FFmpeg demuxer falls back to choosing disabled streams for |
1476 // seeking if there's no suitable enabled stream found. | 1488 // seeking if there's no suitable enabled stream found. |
1477 TEST_F(FFmpegDemuxerTest, Seek_FallbackToDisabledVideoStream) { | 1489 TEST_F(FFmpegDemuxerTest, Seek_FallbackToDisabledVideoStream) { |
1478 // Input has only video stream, no audio. | 1490 // Input has only video stream, no audio. |
1479 CreateDemuxer("bear-320x240-video-only.webm"); | 1491 CreateDemuxer("bear-320x240-video-only.webm"); |
1480 InitializeDemuxer(); | 1492 InitializeDemuxer(); |
1481 EXPECT_EQ(nullptr, demuxer_->GetStream(DemuxerStream::AUDIO)); | 1493 EXPECT_EQ(nullptr, GetStream(DemuxerStream::AUDIO)); |
1482 DemuxerStream* vstream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1494 DemuxerStream* vstream = GetStream(DemuxerStream::VIDEO); |
1483 EXPECT_NE(nullptr, vstream); | 1495 EXPECT_NE(nullptr, vstream); |
1484 EXPECT_EQ(vstream, preferred_seeking_stream(base::TimeDelta())); | 1496 EXPECT_EQ(vstream, preferred_seeking_stream(base::TimeDelta())); |
1485 | 1497 |
1486 // Now pretend that video stream got disabled, e.g. due to current tab going | 1498 // Now pretend that video stream got disabled, e.g. due to current tab going |
1487 // into background. | 1499 // into background. |
1488 vstream->set_enabled(false, base::TimeDelta()); | 1500 vstream->set_enabled(false, base::TimeDelta()); |
1489 // Since there's no other enabled streams, the preferred seeking stream should | 1501 // Since there's no other enabled streams, the preferred seeking stream should |
1490 // still be the video stream. | 1502 // still be the video stream. |
1491 EXPECT_EQ(vstream, preferred_seeking_stream(base::TimeDelta())); | 1503 EXPECT_EQ(vstream, preferred_seeking_stream(base::TimeDelta())); |
1492 } | 1504 } |
1493 | 1505 |
1494 TEST_F(FFmpegDemuxerTest, Seek_FallbackToDisabledAudioStream) { | 1506 TEST_F(FFmpegDemuxerTest, Seek_FallbackToDisabledAudioStream) { |
1495 CreateDemuxer("bear-320x240-audio-only.webm"); | 1507 CreateDemuxer("bear-320x240-audio-only.webm"); |
1496 InitializeDemuxer(); | 1508 InitializeDemuxer(); |
1497 DemuxerStream* astream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1509 DemuxerStream* astream = GetStream(DemuxerStream::AUDIO); |
1498 EXPECT_NE(nullptr, astream); | 1510 EXPECT_NE(nullptr, astream); |
1499 EXPECT_EQ(nullptr, demuxer_->GetStream(DemuxerStream::VIDEO)); | 1511 EXPECT_EQ(nullptr, GetStream(DemuxerStream::VIDEO)); |
1500 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); | 1512 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); |
1501 | 1513 |
1502 // Now pretend that audio stream got disabled. | 1514 // Now pretend that audio stream got disabled. |
1503 astream->set_enabled(false, base::TimeDelta()); | 1515 astream->set_enabled(false, base::TimeDelta()); |
1504 // Since there's no other enabled streams, the preferred seeking stream should | 1516 // Since there's no other enabled streams, the preferred seeking stream should |
1505 // still be the audio stream. | 1517 // still be the audio stream. |
1506 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); | 1518 EXPECT_EQ(astream, preferred_seeking_stream(base::TimeDelta())); |
1507 } | 1519 } |
1508 | 1520 |
1509 } // namespace media | 1521 } // namespace media |
OLD | NEW |