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

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

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

Powered by Google App Engine
This is Rietveld 408576698