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

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

Issue 2086353002: Remove calls to deprecated MessageLoop methods in media. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/run_loop.h"
18 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
19 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
20 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
21 #include "media/base/decrypt_config.h" 22 #include "media/base/decrypt_config.h"
22 #include "media/base/media_log.h" 23 #include "media/base/media_log.h"
23 #include "media/base/media_tracks.h" 24 #include "media/base/media_tracks.h"
24 #include "media/base/mock_demuxer_host.h" 25 #include "media/base/mock_demuxer_host.h"
25 #include "media/base/test_helpers.h" 26 #include "media/base/test_helpers.h"
26 #include "media/base/timestamp_constants.h" 27 #include "media/base/timestamp_constants.h"
27 #include "media/ffmpeg/ffmpeg_common.h" 28 #include "media/ffmpeg/ffmpeg_common.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 EXPECT_EQ(status, DemuxerStream::kOk); 168 EXPECT_EQ(status, DemuxerStream::kOk);
168 EXPECT_TRUE(buffer.get() != NULL); 169 EXPECT_TRUE(buffer.get() != NULL);
169 EXPECT_EQ(read_expectation.size, buffer->data_size()); 170 EXPECT_EQ(read_expectation.size, buffer->data_size());
170 EXPECT_EQ(read_expectation.timestamp_us, 171 EXPECT_EQ(read_expectation.timestamp_us,
171 buffer->timestamp().InMicroseconds()); 172 buffer->timestamp().InMicroseconds());
172 EXPECT_EQ(read_expectation.discard_front_padding, 173 EXPECT_EQ(read_expectation.discard_front_padding,
173 buffer->discard_padding().first); 174 buffer->discard_padding().first);
174 EXPECT_EQ(read_expectation.is_key_frame, buffer->is_key_frame()); 175 EXPECT_EQ(read_expectation.is_key_frame, buffer->is_key_frame());
175 DCHECK_EQ(&message_loop_, base::MessageLoop::current()); 176 DCHECK_EQ(&message_loop_, base::MessageLoop::current());
176 OnReadDoneCalled(read_expectation.size, read_expectation.timestamp_us); 177 OnReadDoneCalled(read_expectation.size, read_expectation.timestamp_us);
177 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 178 message_loop_.task_runner()->PostTask(
179 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
178 } 180 }
179 181
180 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location, 182 DemuxerStream::ReadCB NewReadCB(const tracked_objects::Location& location,
181 int size, 183 int size,
182 int64_t timestamp_us, 184 int64_t timestamp_us,
183 bool is_key_frame) { 185 bool is_key_frame) {
184 return NewReadCBWithCheckedDiscard(location, 186 return NewReadCBWithCheckedDiscard(location,
185 size, 187 size,
186 timestamp_us, 188 timestamp_us,
187 base::TimeDelta(), 189 base::TimeDelta(),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 242
241 int preferred_seeking_stream_index() const { 243 int preferred_seeking_stream_index() const {
242 return demuxer_->preferred_stream_for_seeking_.first; 244 return demuxer_->preferred_stream_for_seeking_.first;
243 } 245 }
244 246
245 void ReadUntilEndOfStream(DemuxerStream* stream) { 247 void ReadUntilEndOfStream(DemuxerStream* stream) {
246 bool got_eos_buffer = false; 248 bool got_eos_buffer = false;
247 const int kMaxBuffers = 170; 249 const int kMaxBuffers = 170;
248 for (int i = 0; !got_eos_buffer && i < kMaxBuffers; i++) { 250 for (int i = 0; !got_eos_buffer && i < kMaxBuffers; i++) {
249 stream->Read(base::Bind(&EosOnReadDone, &got_eos_buffer)); 251 stream->Read(base::Bind(&EosOnReadDone, &got_eos_buffer));
250 message_loop_.Run(); 252 base::RunLoop().Run();
251 } 253 }
252 254
253 EXPECT_TRUE(got_eos_buffer); 255 EXPECT_TRUE(got_eos_buffer);
254 } 256 }
255 257
256 private: 258 private:
257 void CreateDataSource(const std::string& name) { 259 void CreateDataSource(const std::string& name) {
258 CHECK(!data_source_); 260 CHECK(!data_source_);
259 261
260 base::FilePath file_path; 262 base::FilePath file_path;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 420
419 TEST_F(FFmpegDemuxerTest, Read_Audio) { 421 TEST_F(FFmpegDemuxerTest, Read_Audio) {
420 // We test that on a successful audio packet read. 422 // We test that on a successful audio packet read.
421 CreateDemuxer("bear-320x240.webm"); 423 CreateDemuxer("bear-320x240.webm");
422 InitializeDemuxer(); 424 InitializeDemuxer();
423 425
424 // Attempt a read from the audio stream and run the message loop until done. 426 // Attempt a read from the audio stream and run the message loop until done.
425 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); 427 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
426 428
427 audio->Read(NewReadCB(FROM_HERE, 29, 0, true)); 429 audio->Read(NewReadCB(FROM_HERE, 29, 0, true));
428 message_loop_.Run(); 430 base::RunLoop().Run();
429 431
430 audio->Read(NewReadCB(FROM_HERE, 27, 3000, true)); 432 audio->Read(NewReadCB(FROM_HERE, 27, 3000, true));
431 message_loop_.Run(); 433 base::RunLoop().Run();
432 434
433 EXPECT_EQ(22084, demuxer_->GetMemoryUsage()); 435 EXPECT_EQ(22084, demuxer_->GetMemoryUsage());
434 } 436 }
435 437
436 TEST_F(FFmpegDemuxerTest, Read_Video) { 438 TEST_F(FFmpegDemuxerTest, Read_Video) {
437 // We test that on a successful video packet read. 439 // We test that on a successful video packet read.
438 CreateDemuxer("bear-320x240.webm"); 440 CreateDemuxer("bear-320x240.webm");
439 InitializeDemuxer(); 441 InitializeDemuxer();
440 442
441 // Attempt a read from the video stream and run the message loop until done. 443 // Attempt a read from the video stream and run the message loop until done.
442 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); 444 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
443 445
444 video->Read(NewReadCB(FROM_HERE, 22084, 0, true)); 446 video->Read(NewReadCB(FROM_HERE, 22084, 0, true));
445 message_loop_.Run(); 447 base::RunLoop().Run();
446 448
447 video->Read(NewReadCB(FROM_HERE, 1057, 33000, false)); 449 video->Read(NewReadCB(FROM_HERE, 1057, 33000, false));
448 message_loop_.Run(); 450 base::RunLoop().Run();
449 451
450 EXPECT_EQ(323, demuxer_->GetMemoryUsage()); 452 EXPECT_EQ(323, demuxer_->GetMemoryUsage());
451 } 453 }
452 454
453 TEST_F(FFmpegDemuxerTest, Read_Text) { 455 TEST_F(FFmpegDemuxerTest, Read_Text) {
454 // We test that on a successful text packet read. 456 // We test that on a successful text packet read.
455 CreateDemuxer("bear-vp8-webvtt.webm"); 457 CreateDemuxer("bear-vp8-webvtt.webm");
456 DemuxerStream* text_stream = NULL; 458 DemuxerStream* text_stream = NULL;
457 EXPECT_CALL(host_, AddTextStream(_, _)) 459 EXPECT_CALL(host_, AddTextStream(_, _))
458 .WillOnce(SaveArg<0>(&text_stream)); 460 .WillOnce(SaveArg<0>(&text_stream));
459 InitializeDemuxerWithText(); 461 InitializeDemuxerWithText();
460 ASSERT_TRUE(text_stream); 462 ASSERT_TRUE(text_stream);
461 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type()); 463 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type());
462 464
463 text_stream->Read(NewReadCB(FROM_HERE, 31, 0, true)); 465 text_stream->Read(NewReadCB(FROM_HERE, 31, 0, true));
464 message_loop_.Run(); 466 base::RunLoop().Run();
465 467
466 text_stream->Read(NewReadCB(FROM_HERE, 19, 500000, true)); 468 text_stream->Read(NewReadCB(FROM_HERE, 19, 500000, true));
467 message_loop_.Run(); 469 base::RunLoop().Run();
468 } 470 }
469 471
470 TEST_F(FFmpegDemuxerTest, SeekInitialized_NoVideoStartTime) { 472 TEST_F(FFmpegDemuxerTest, SeekInitialized_NoVideoStartTime) {
471 CreateDemuxer("audio-start-time-only.webm"); 473 CreateDemuxer("audio-start-time-only.webm");
472 InitializeDemuxer(); 474 InitializeDemuxer();
473 EXPECT_EQ(0, preferred_seeking_stream_index()); 475 EXPECT_EQ(0, preferred_seeking_stream_index());
474 } 476 }
475 477
476 TEST_F(FFmpegDemuxerTest, Read_VideoPositiveStartTime) { 478 TEST_F(FFmpegDemuxerTest, Read_VideoPositiveStartTime) {
477 const int64_t kTimelineOffsetMs = 1352550896000LL; 479 const int64_t kTimelineOffsetMs = 1352550896000LL;
478 480
479 // Test the start time is the first timestamp of the video and audio stream. 481 // Test the start time is the first timestamp of the video and audio stream.
480 CreateDemuxer("nonzero-start-time.webm"); 482 CreateDemuxer("nonzero-start-time.webm");
481 InitializeDemuxerWithTimelineOffset( 483 InitializeDemuxerWithTimelineOffset(
482 base::Time::FromJsTime(kTimelineOffsetMs)); 484 base::Time::FromJsTime(kTimelineOffsetMs));
483 485
484 // Attempt a read from the video stream and run the message loop until done. 486 // Attempt a read from the video stream and run the message loop until done.
485 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); 487 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
486 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); 488 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
487 489
488 const base::TimeDelta video_start_time = 490 const base::TimeDelta video_start_time =
489 base::TimeDelta::FromMicroseconds(400000); 491 base::TimeDelta::FromMicroseconds(400000);
490 const base::TimeDelta audio_start_time = 492 const base::TimeDelta audio_start_time =
491 base::TimeDelta::FromMicroseconds(396000); 493 base::TimeDelta::FromMicroseconds(396000);
492 494
493 // Run the test twice with a seek in between. 495 // Run the test twice with a seek in between.
494 for (int i = 0; i < 2; ++i) { 496 for (int i = 0; i < 2; ++i) {
495 video->Read(NewReadCB(FROM_HERE, 5636, video_start_time.InMicroseconds(), 497 video->Read(NewReadCB(FROM_HERE, 5636, video_start_time.InMicroseconds(),
496 true)); 498 true));
497 message_loop_.Run(); 499 base::RunLoop().Run();
498 audio->Read(NewReadCB(FROM_HERE, 165, audio_start_time.InMicroseconds(), 500 audio->Read(NewReadCB(FROM_HERE, 165, audio_start_time.InMicroseconds(),
499 true)); 501 true));
500 message_loop_.Run(); 502 base::RunLoop().Run();
501 503
502 // Verify that the start time is equal to the lowest timestamp (ie the 504 // Verify that the start time is equal to the lowest timestamp (ie the
503 // audio). 505 // audio).
504 EXPECT_EQ(audio_start_time, demuxer_->start_time()); 506 EXPECT_EQ(audio_start_time, demuxer_->start_time());
505 507
506 // Verify that the timeline offset has not been adjusted by the start time. 508 // Verify that the timeline offset has not been adjusted by the start time.
507 EXPECT_EQ(kTimelineOffsetMs, demuxer_->GetTimelineOffset().ToJavaTime()); 509 EXPECT_EQ(kTimelineOffsetMs, demuxer_->GetTimelineOffset().ToJavaTime());
508 510
509 // Seek back to the beginning and repeat the test. 511 // Seek back to the beginning and repeat the test.
510 WaitableMessageLoopEvent event; 512 WaitableMessageLoopEvent event;
511 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB()); 513 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB());
512 event.RunAndWaitForStatus(PIPELINE_OK); 514 event.RunAndWaitForStatus(PIPELINE_OK);
513 } 515 }
514 } 516 }
515 517
516 TEST_F(FFmpegDemuxerTest, Read_AudioNoStartTime) { 518 TEST_F(FFmpegDemuxerTest, Read_AudioNoStartTime) {
517 // FFmpeg does not set timestamps when demuxing wave files. Ensure that the 519 // FFmpeg does not set timestamps when demuxing wave files. Ensure that the
518 // demuxer sets a start time of zero in this case. 520 // demuxer sets a start time of zero in this case.
519 CreateDemuxer("sfx_s24le.wav"); 521 CreateDemuxer("sfx_s24le.wav");
520 InitializeDemuxer(); 522 InitializeDemuxer();
521 523
522 // Run the test twice with a seek in between. 524 // Run the test twice with a seek in between.
523 for (int i = 0; i < 2; ++i) { 525 for (int i = 0; i < 2; ++i) {
524 demuxer_->GetStream(DemuxerStream::AUDIO) 526 demuxer_->GetStream(DemuxerStream::AUDIO)
525 ->Read(NewReadCB(FROM_HERE, 4095, 0, true)); 527 ->Read(NewReadCB(FROM_HERE, 4095, 0, true));
526 message_loop_.Run(); 528 base::RunLoop().Run();
527 EXPECT_EQ(base::TimeDelta(), demuxer_->start_time()); 529 EXPECT_EQ(base::TimeDelta(), demuxer_->start_time());
528 530
529 // Seek back to the beginning and repeat the test. 531 // Seek back to the beginning and repeat the test.
530 WaitableMessageLoopEvent event; 532 WaitableMessageLoopEvent event;
531 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB()); 533 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB());
532 event.RunAndWaitForStatus(PIPELINE_OK); 534 event.RunAndWaitForStatus(PIPELINE_OK);
533 } 535 }
534 } 536 }
535 537
536 // TODO(dalecurtis): Test is disabled since FFmpeg does not currently guarantee 538 // TODO(dalecurtis): Test is disabled since FFmpeg does not currently guarantee
537 // the order of demuxed packets in OGG containers. Re-enable and fix key frame 539 // the order of demuxed packets in OGG containers. Re-enable and fix key frame
538 // expectations once we decide to either workaround it or attempt a fix 540 // expectations once we decide to either workaround it or attempt a fix
539 // upstream. See http://crbug.com/387996. 541 // upstream. See http://crbug.com/387996.
540 TEST_F(FFmpegDemuxerTest, 542 TEST_F(FFmpegDemuxerTest,
541 DISABLED_Read_AudioNegativeStartTimeAndOggDiscard_Bear) { 543 DISABLED_Read_AudioNegativeStartTimeAndOggDiscard_Bear) {
542 // Many ogg files have negative starting timestamps, so ensure demuxing and 544 // Many ogg files have negative starting timestamps, so ensure demuxing and
543 // seeking work correctly with a negative start time. 545 // seeking work correctly with a negative start time.
544 CreateDemuxer("bear.ogv"); 546 CreateDemuxer("bear.ogv");
545 InitializeDemuxer(); 547 InitializeDemuxer();
546 548
547 // Attempt a read from the video stream and run the message loop until done. 549 // Attempt a read from the video stream and run the message loop until done.
548 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); 550 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
549 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); 551 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
550 552
551 // Run the test twice with a seek in between. 553 // Run the test twice with a seek in between.
552 for (int i = 0; i < 2; ++i) { 554 for (int i = 0; i < 2; ++i) {
553 audio->Read( 555 audio->Read(
554 NewReadCBWithCheckedDiscard(FROM_HERE, 40, 0, kInfiniteDuration(), 556 NewReadCBWithCheckedDiscard(FROM_HERE, 40, 0, kInfiniteDuration(),
555 true)); 557 true));
556 message_loop_.Run(); 558 base::RunLoop().Run();
557 audio->Read( 559 audio->Read(
558 NewReadCBWithCheckedDiscard(FROM_HERE, 41, 2903, kInfiniteDuration(), 560 NewReadCBWithCheckedDiscard(FROM_HERE, 41, 2903, kInfiniteDuration(),
559 true)); 561 true));
560 message_loop_.Run(); 562 base::RunLoop().Run();
561 audio->Read(NewReadCBWithCheckedDiscard( 563 audio->Read(NewReadCBWithCheckedDiscard(
562 FROM_HERE, 173, 5805, base::TimeDelta::FromMicroseconds(10159), true)); 564 FROM_HERE, 173, 5805, base::TimeDelta::FromMicroseconds(10159), true));
563 message_loop_.Run(); 565 base::RunLoop().Run();
564 566
565 audio->Read(NewReadCB(FROM_HERE, 148, 18866, true)); 567 audio->Read(NewReadCB(FROM_HERE, 148, 18866, true));
566 message_loop_.Run(); 568 base::RunLoop().Run();
567 EXPECT_EQ(base::TimeDelta::FromMicroseconds(-15964), 569 EXPECT_EQ(base::TimeDelta::FromMicroseconds(-15964),
568 demuxer_->start_time()); 570 demuxer_->start_time());
569 571
570 video->Read(NewReadCB(FROM_HERE, 5751, 0, true)); 572 video->Read(NewReadCB(FROM_HERE, 5751, 0, true));
571 message_loop_.Run(); 573 base::RunLoop().Run();
572 574
573 video->Read(NewReadCB(FROM_HERE, 846, 33367, true)); 575 video->Read(NewReadCB(FROM_HERE, 846, 33367, true));
574 message_loop_.Run(); 576 base::RunLoop().Run();
575 577
576 video->Read(NewReadCB(FROM_HERE, 1255, 66733, true)); 578 video->Read(NewReadCB(FROM_HERE, 1255, 66733, true));
577 message_loop_.Run(); 579 base::RunLoop().Run();
578 580
579 // Seek back to the beginning and repeat the test. 581 // Seek back to the beginning and repeat the test.
580 WaitableMessageLoopEvent event; 582 WaitableMessageLoopEvent event;
581 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB()); 583 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB());
582 event.RunAndWaitForStatus(PIPELINE_OK); 584 event.RunAndWaitForStatus(PIPELINE_OK);
583 } 585 }
584 } 586 }
585 587
586 // Same test above, but using sync2.ogv which has video stream muxed before the 588 // Same test above, but using sync2.ogv which has video stream muxed before the
587 // audio stream, so seeking based only on start time will fail since ffmpeg is 589 // audio stream, so seeking based only on start time will fail since ffmpeg is
588 // essentially just seeking based on file position. 590 // essentially just seeking based on file position.
589 TEST_F(FFmpegDemuxerTest, Read_AudioNegativeStartTimeAndOggDiscard_Sync) { 591 TEST_F(FFmpegDemuxerTest, Read_AudioNegativeStartTimeAndOggDiscard_Sync) {
590 // Many ogg files have negative starting timestamps, so ensure demuxing and 592 // Many ogg files have negative starting timestamps, so ensure demuxing and
591 // seeking work correctly with a negative start time. 593 // seeking work correctly with a negative start time.
592 CreateDemuxer("sync2.ogv"); 594 CreateDemuxer("sync2.ogv");
593 InitializeDemuxer(); 595 InitializeDemuxer();
594 596
595 // Attempt a read from the video stream and run the message loop until done. 597 // Attempt a read from the video stream and run the message loop until done.
596 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); 598 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
597 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); 599 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
598 600
599 // Run the test twice with a seek in between. 601 // Run the test twice with a seek in between.
600 for (int i = 0; i < 2; ++i) { 602 for (int i = 0; i < 2; ++i) {
601 audio->Read(NewReadCBWithCheckedDiscard( 603 audio->Read(NewReadCBWithCheckedDiscard(
602 FROM_HERE, 1, 0, base::TimeDelta::FromMicroseconds(2902), true)); 604 FROM_HERE, 1, 0, base::TimeDelta::FromMicroseconds(2902), true));
603 message_loop_.Run(); 605 base::RunLoop().Run();
604 606
605 audio->Read(NewReadCB(FROM_HERE, 1, 2902, true)); 607 audio->Read(NewReadCB(FROM_HERE, 1, 2902, true));
606 message_loop_.Run(); 608 base::RunLoop().Run();
607 EXPECT_EQ(base::TimeDelta::FromMicroseconds(-2902), 609 EXPECT_EQ(base::TimeDelta::FromMicroseconds(-2902),
608 demuxer_->start_time()); 610 demuxer_->start_time());
609 611
610 // Though the internal start time may be below zero, the exposed media time 612 // Though the internal start time may be below zero, the exposed media time
611 // must always be greater than zero. 613 // must always be greater than zero.
612 EXPECT_EQ(base::TimeDelta(), demuxer_->GetStartTime()); 614 EXPECT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
613 615
614 video->Read(NewReadCB(FROM_HERE, 9997, 0, true)); 616 video->Read(NewReadCB(FROM_HERE, 9997, 0, true));
615 message_loop_.Run(); 617 base::RunLoop().Run();
616 618
617 video->Read(NewReadCB(FROM_HERE, 16, 33241, false)); 619 video->Read(NewReadCB(FROM_HERE, 16, 33241, false));
618 message_loop_.Run(); 620 base::RunLoop().Run();
619 621
620 video->Read(NewReadCB(FROM_HERE, 631, 66482, false)); 622 video->Read(NewReadCB(FROM_HERE, 631, 66482, false));
621 message_loop_.Run(); 623 base::RunLoop().Run();
622 624
623 // Seek back to the beginning and repeat the test. 625 // Seek back to the beginning and repeat the test.
624 WaitableMessageLoopEvent event; 626 WaitableMessageLoopEvent event;
625 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB()); 627 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB());
626 event.RunAndWaitForStatus(PIPELINE_OK); 628 event.RunAndWaitForStatus(PIPELINE_OK);
627 } 629 }
628 } 630 }
629 631
630 // Similar to the test above, but using an opus clip with a large amount of 632 // Similar to the test above, but using an opus clip with a large amount of
631 // pre-skip, which ffmpeg encodes as negative timestamps. 633 // pre-skip, which ffmpeg encodes as negative timestamps.
(...skipping 11 matching lines...) Expand all
643 static const int kTestExpectations[][2] = { 645 static const int kTestExpectations[][2] = {
644 {635, 0}, {594, 120000}, {597, 240000}, {591, 360000}, 646 {635, 0}, {594, 120000}, {597, 240000}, {591, 360000},
645 {582, 480000}, {583, 600000}, {592, 720000}, {567, 840000}, 647 {582, 480000}, {583, 600000}, {592, 720000}, {567, 840000},
646 {579, 960000}, {572, 1080000}, {583, 1200000}}; 648 {579, 960000}, {572, 1080000}, {583, 1200000}};
647 649
648 // Run the test twice with a seek in between. 650 // Run the test twice with a seek in between.
649 for (int i = 0; i < 2; ++i) { 651 for (int i = 0; i < 2; ++i) {
650 for (size_t j = 0; j < arraysize(kTestExpectations); ++j) { 652 for (size_t j = 0; j < arraysize(kTestExpectations); ++j) {
651 audio->Read(NewReadCB(FROM_HERE, kTestExpectations[j][0], 653 audio->Read(NewReadCB(FROM_HERE, kTestExpectations[j][0],
652 kTestExpectations[j][1], true)); 654 kTestExpectations[j][1], true));
653 message_loop_.Run(); 655 base::RunLoop().Run();
654 } 656 }
655 657
656 // Though the internal start time may be below zero, the exposed media time 658 // Though the internal start time may be below zero, the exposed media time
657 // must always be greater than zero. 659 // must always be greater than zero.
658 EXPECT_EQ(base::TimeDelta(), demuxer_->GetStartTime()); 660 EXPECT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
659 661
660 video->Read(NewReadCB(FROM_HERE, 16009, 0, true)); 662 video->Read(NewReadCB(FROM_HERE, 16009, 0, true));
661 message_loop_.Run(); 663 base::RunLoop().Run();
662 664
663 video->Read(NewReadCB(FROM_HERE, 2715, 1000, false)); 665 video->Read(NewReadCB(FROM_HERE, 2715, 1000, false));
664 message_loop_.Run(); 666 base::RunLoop().Run();
665 667
666 video->Read(NewReadCB(FROM_HERE, 427, 33000, false)); 668 video->Read(NewReadCB(FROM_HERE, 427, 33000, false));
667 message_loop_.Run(); 669 base::RunLoop().Run();
668 670
669 // Seek back to the beginning and repeat the test. 671 // Seek back to the beginning and repeat the test.
670 WaitableMessageLoopEvent event; 672 WaitableMessageLoopEvent event;
671 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB()); 673 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB());
672 event.RunAndWaitForStatus(PIPELINE_OK); 674 event.RunAndWaitForStatus(PIPELINE_OK);
673 } 675 }
674 } 676 }
675 677
676 // Similar to the test above, but using sfx-opus.ogg, which has a much smaller 678 // Similar to the test above, but using sfx-opus.ogg, which has a much smaller
677 // amount of discard padding and no |start_time| set on the AVStream. 679 // amount of discard padding and no |start_time| set on the AVStream.
678 TEST_F(FFmpegDemuxerTest, Read_AudioNegativeStartTimeAndOpusSfxDiscard_Sync) { 680 TEST_F(FFmpegDemuxerTest, Read_AudioNegativeStartTimeAndOpusSfxDiscard_Sync) {
679 CreateDemuxer("sfx-opus.ogg"); 681 CreateDemuxer("sfx-opus.ogg");
680 InitializeDemuxer(); 682 InitializeDemuxer();
681 683
682 // 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.
683 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); 685 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
684 EXPECT_EQ(audio->audio_decoder_config().codec_delay(), 312); 686 EXPECT_EQ(audio->audio_decoder_config().codec_delay(), 312);
685 687
686 // Run the test twice with a seek in between. 688 // Run the test twice with a seek in between.
687 for (int i = 0; i < 2; ++i) { 689 for (int i = 0; i < 2; ++i) {
688 audio->Read(NewReadCB(FROM_HERE, 314, 0, true)); 690 audio->Read(NewReadCB(FROM_HERE, 314, 0, true));
689 message_loop_.Run(); 691 base::RunLoop().Run();
690 692
691 audio->Read(NewReadCB(FROM_HERE, 244, 20000, true)); 693 audio->Read(NewReadCB(FROM_HERE, 244, 20000, true));
692 message_loop_.Run(); 694 base::RunLoop().Run();
693 695
694 // Though the internal start time may be below zero, the exposed media time 696 // Though the internal start time may be below zero, the exposed media time
695 // must always be greater than zero. 697 // must always be greater than zero.
696 EXPECT_EQ(base::TimeDelta(), demuxer_->GetStartTime()); 698 EXPECT_EQ(base::TimeDelta(), demuxer_->GetStartTime());
697 699
698 // Seek back to the beginning and repeat the test. 700 // Seek back to the beginning and repeat the test.
699 WaitableMessageLoopEvent event; 701 WaitableMessageLoopEvent event;
700 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB()); 702 demuxer_->Seek(base::TimeDelta(), event.GetPipelineStatusCB());
701 event.RunAndWaitForStatus(PIPELINE_OK); 703 event.RunAndWaitForStatus(PIPELINE_OK);
702 } 704 }
(...skipping 13 matching lines...) Expand all
716 EXPECT_CALL(host_, AddTextStream(_, _)) 718 EXPECT_CALL(host_, AddTextStream(_, _))
717 .WillOnce(SaveArg<0>(&text_stream)); 719 .WillOnce(SaveArg<0>(&text_stream));
718 InitializeDemuxerWithText(); 720 InitializeDemuxerWithText();
719 ASSERT_TRUE(text_stream); 721 ASSERT_TRUE(text_stream);
720 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type()); 722 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type());
721 723
722 bool got_eos_buffer = false; 724 bool got_eos_buffer = false;
723 const int kMaxBuffers = 10; 725 const int kMaxBuffers = 10;
724 for (int i = 0; !got_eos_buffer && i < kMaxBuffers; i++) { 726 for (int i = 0; !got_eos_buffer && i < kMaxBuffers; i++) {
725 text_stream->Read(base::Bind(&EosOnReadDone, &got_eos_buffer)); 727 text_stream->Read(base::Bind(&EosOnReadDone, &got_eos_buffer));
726 message_loop_.Run(); 728 base::RunLoop().Run();
727 } 729 }
728 730
729 EXPECT_TRUE(got_eos_buffer); 731 EXPECT_TRUE(got_eos_buffer);
730 } 732 }
731 733
732 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration) { 734 TEST_F(FFmpegDemuxerTest, Read_EndOfStream_NoDuration) {
733 // Verify that end of stream buffers are created. 735 // Verify that end of stream buffers are created.
734 CreateDemuxer("bear-320x240.webm"); 736 CreateDemuxer("bear-320x240.webm");
735 InitializeDemuxer(); 737 InitializeDemuxer();
736 set_duration_known(false); 738 set_duration_known(false);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 InitializeDemuxer(); 776 InitializeDemuxer();
775 777
776 // Get our streams. 778 // Get our streams.
777 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); 779 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
778 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); 780 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
779 ASSERT_TRUE(video); 781 ASSERT_TRUE(video);
780 ASSERT_TRUE(audio); 782 ASSERT_TRUE(audio);
781 783
782 // Read a video packet and release it. 784 // Read a video packet and release it.
783 video->Read(NewReadCB(FROM_HERE, 22084, 0, true)); 785 video->Read(NewReadCB(FROM_HERE, 22084, 0, true));
784 message_loop_.Run(); 786 base::RunLoop().Run();
785 787
786 // Issue a simple forward seek, which should discard queued packets. 788 // Issue a simple forward seek, which should discard queued packets.
787 WaitableMessageLoopEvent event; 789 WaitableMessageLoopEvent event;
788 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000), 790 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000),
789 event.GetPipelineStatusCB()); 791 event.GetPipelineStatusCB());
790 event.RunAndWaitForStatus(PIPELINE_OK); 792 event.RunAndWaitForStatus(PIPELINE_OK);
791 793
792 // Audio read #1. 794 // Audio read #1.
793 audio->Read(NewReadCB(FROM_HERE, 145, 803000, true)); 795 audio->Read(NewReadCB(FROM_HERE, 145, 803000, true));
794 message_loop_.Run(); 796 base::RunLoop().Run();
795 797
796 // Audio read #2. 798 // Audio read #2.
797 audio->Read(NewReadCB(FROM_HERE, 148, 826000, true)); 799 audio->Read(NewReadCB(FROM_HERE, 148, 826000, true));
798 message_loop_.Run(); 800 base::RunLoop().Run();
799 801
800 // Video read #1. 802 // Video read #1.
801 video->Read(NewReadCB(FROM_HERE, 5425, 801000, true)); 803 video->Read(NewReadCB(FROM_HERE, 5425, 801000, true));
802 message_loop_.Run(); 804 base::RunLoop().Run();
803 805
804 // Video read #2. 806 // Video read #2.
805 video->Read(NewReadCB(FROM_HERE, 1906, 834000, false)); 807 video->Read(NewReadCB(FROM_HERE, 1906, 834000, false));
806 message_loop_.Run(); 808 base::RunLoop().Run();
807 } 809 }
808 810
809 TEST_F(FFmpegDemuxerTest, SeekText) { 811 TEST_F(FFmpegDemuxerTest, SeekText) {
810 // We're testing that the demuxer frees all queued packets when it receives 812 // We're testing that the demuxer frees all queued packets when it receives
811 // a Seek(). 813 // a Seek().
812 CreateDemuxer("bear-vp8-webvtt.webm"); 814 CreateDemuxer("bear-vp8-webvtt.webm");
813 DemuxerStream* text_stream = NULL; 815 DemuxerStream* text_stream = NULL;
814 EXPECT_CALL(host_, AddTextStream(_, _)) 816 EXPECT_CALL(host_, AddTextStream(_, _))
815 .WillOnce(SaveArg<0>(&text_stream)); 817 .WillOnce(SaveArg<0>(&text_stream));
816 InitializeDemuxerWithText(); 818 InitializeDemuxerWithText();
817 ASSERT_TRUE(text_stream); 819 ASSERT_TRUE(text_stream);
818 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type()); 820 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type());
819 821
820 // Get our streams. 822 // Get our streams.
821 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); 823 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
822 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); 824 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
823 ASSERT_TRUE(video); 825 ASSERT_TRUE(video);
824 ASSERT_TRUE(audio); 826 ASSERT_TRUE(audio);
825 827
826 // Read a text packet and release it. 828 // Read a text packet and release it.
827 text_stream->Read(NewReadCB(FROM_HERE, 31, 0, true)); 829 text_stream->Read(NewReadCB(FROM_HERE, 31, 0, true));
828 message_loop_.Run(); 830 base::RunLoop().Run();
829 831
830 // Issue a simple forward seek, which should discard queued packets. 832 // Issue a simple forward seek, which should discard queued packets.
831 WaitableMessageLoopEvent event; 833 WaitableMessageLoopEvent event;
832 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000), 834 demuxer_->Seek(base::TimeDelta::FromMicroseconds(1000000),
833 event.GetPipelineStatusCB()); 835 event.GetPipelineStatusCB());
834 event.RunAndWaitForStatus(PIPELINE_OK); 836 event.RunAndWaitForStatus(PIPELINE_OK);
835 837
836 // Audio read #1. 838 // Audio read #1.
837 audio->Read(NewReadCB(FROM_HERE, 145, 803000, true)); 839 audio->Read(NewReadCB(FROM_HERE, 145, 803000, true));
838 message_loop_.Run(); 840 base::RunLoop().Run();
839 841
840 // Audio read #2. 842 // Audio read #2.
841 audio->Read(NewReadCB(FROM_HERE, 148, 826000, true)); 843 audio->Read(NewReadCB(FROM_HERE, 148, 826000, true));
842 message_loop_.Run(); 844 base::RunLoop().Run();
843 845
844 // Video read #1. 846 // Video read #1.
845 video->Read(NewReadCB(FROM_HERE, 5425, 801000, true)); 847 video->Read(NewReadCB(FROM_HERE, 5425, 801000, true));
846 message_loop_.Run(); 848 base::RunLoop().Run();
847 849
848 // Video read #2. 850 // Video read #2.
849 video->Read(NewReadCB(FROM_HERE, 1906, 834000, false)); 851 video->Read(NewReadCB(FROM_HERE, 1906, 834000, false));
850 message_loop_.Run(); 852 base::RunLoop().Run();
851 853
852 // Text read #1. 854 // Text read #1.
853 text_stream->Read(NewReadCB(FROM_HERE, 19, 500000, true)); 855 text_stream->Read(NewReadCB(FROM_HERE, 19, 500000, true));
854 message_loop_.Run(); 856 base::RunLoop().Run();
855 857
856 // Text read #2. 858 // Text read #2.
857 text_stream->Read(NewReadCB(FROM_HERE, 19, 1000000, true)); 859 text_stream->Read(NewReadCB(FROM_HERE, 19, 1000000, true));
858 message_loop_.Run(); 860 base::RunLoop().Run();
859 } 861 }
860 862
861 class MockReadCB { 863 class MockReadCB {
862 public: 864 public:
863 MockReadCB() {} 865 MockReadCB() {}
864 ~MockReadCB() {} 866 ~MockReadCB() {}
865 867
866 MOCK_METHOD2(Run, void(DemuxerStream::Status status, 868 MOCK_METHOD2(Run, void(DemuxerStream::Status status,
867 const scoped_refptr<DecoderBuffer>& buffer)); 869 const scoped_refptr<DecoderBuffer>& buffer));
868 private: 870 private:
(...skipping 11 matching lines...) Expand all
880 ASSERT_TRUE(audio); 882 ASSERT_TRUE(audio);
881 883
882 demuxer_->Stop(); 884 demuxer_->Stop();
883 885
884 // Reads after being stopped are all EOS buffers. 886 // Reads after being stopped are all EOS buffers.
885 StrictMock<MockReadCB> callback; 887 StrictMock<MockReadCB> callback;
886 EXPECT_CALL(callback, Run(DemuxerStream::kOk, IsEndOfStreamBuffer())); 888 EXPECT_CALL(callback, Run(DemuxerStream::kOk, IsEndOfStreamBuffer()));
887 889
888 // Attempt the read... 890 // Attempt the read...
889 audio->Read(base::Bind(&MockReadCB::Run, base::Unretained(&callback))); 891 audio->Read(base::Bind(&MockReadCB::Run, base::Unretained(&callback)));
890 message_loop_.RunUntilIdle(); 892 base::RunLoop().RunUntilIdle();
891 893
892 // Don't let the test call Stop() again. 894 // Don't let the test call Stop() again.
893 demuxer_.reset(); 895 demuxer_.reset();
894 } 896 }
895 897
896 // Verify that seek works properly when the WebM cues data is at the start of 898 // Verify that seek works properly when the WebM cues data is at the start of
897 // the file instead of at the end. 899 // the file instead of at the end.
898 TEST_F(FFmpegDemuxerTest, SeekWithCuesBeforeFirstCluster) { 900 TEST_F(FFmpegDemuxerTest, SeekWithCuesBeforeFirstCluster) {
899 CreateDemuxer("bear-320x240-cues-in-front.webm"); 901 CreateDemuxer("bear-320x240-cues-in-front.webm");
900 InitializeDemuxer(); 902 InitializeDemuxer();
901 903
902 // Get our streams. 904 // Get our streams.
903 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); 905 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
904 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); 906 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
905 ASSERT_TRUE(video); 907 ASSERT_TRUE(video);
906 ASSERT_TRUE(audio); 908 ASSERT_TRUE(audio);
907 909
908 // Read a video packet and release it. 910 // Read a video packet and release it.
909 video->Read(NewReadCB(FROM_HERE, 22084, 0, true)); 911 video->Read(NewReadCB(FROM_HERE, 22084, 0, true));
910 message_loop_.Run(); 912 base::RunLoop().Run();
911 913
912 // Issue a simple forward seek, which should discard queued packets. 914 // Issue a simple forward seek, which should discard queued packets.
913 WaitableMessageLoopEvent event; 915 WaitableMessageLoopEvent event;
914 demuxer_->Seek(base::TimeDelta::FromMicroseconds(2500000), 916 demuxer_->Seek(base::TimeDelta::FromMicroseconds(2500000),
915 event.GetPipelineStatusCB()); 917 event.GetPipelineStatusCB());
916 event.RunAndWaitForStatus(PIPELINE_OK); 918 event.RunAndWaitForStatus(PIPELINE_OK);
917 919
918 // Audio read #1. 920 // Audio read #1.
919 audio->Read(NewReadCB(FROM_HERE, 40, 2403000, true)); 921 audio->Read(NewReadCB(FROM_HERE, 40, 2403000, true));
920 message_loop_.Run(); 922 base::RunLoop().Run();
921 923
922 // Audio read #2. 924 // Audio read #2.
923 audio->Read(NewReadCB(FROM_HERE, 42, 2406000, true)); 925 audio->Read(NewReadCB(FROM_HERE, 42, 2406000, true));
924 message_loop_.Run(); 926 base::RunLoop().Run();
925 927
926 // Video read #1. 928 // Video read #1.
927 video->Read(NewReadCB(FROM_HERE, 5276, 2402000, true)); 929 video->Read(NewReadCB(FROM_HERE, 5276, 2402000, true));
928 message_loop_.Run(); 930 base::RunLoop().Run();
929 931
930 // Video read #2. 932 // Video read #2.
931 video->Read(NewReadCB(FROM_HERE, 1740, 2436000, false)); 933 video->Read(NewReadCB(FROM_HERE, 1740, 2436000, false));
932 message_loop_.Run(); 934 base::RunLoop().Run();
933 } 935 }
934 936
935 #if defined(USE_PROPRIETARY_CODECS) 937 #if defined(USE_PROPRIETARY_CODECS)
936 // Ensure ID3v1 tag reading is disabled. id3_test.mp3 has an ID3v1 tag with the 938 // Ensure ID3v1 tag reading is disabled. id3_test.mp3 has an ID3v1 tag with the
937 // field "title" set to "sample for id3 test". 939 // field "title" set to "sample for id3 test".
938 TEST_F(FFmpegDemuxerTest, NoID3TagData) { 940 TEST_F(FFmpegDemuxerTest, NoID3TagData) {
939 CreateDemuxer("id3_test.mp3"); 941 CreateDemuxer("id3_test.mp3");
940 InitializeDemuxer(); 942 InitializeDemuxer();
941 EXPECT_FALSE(av_dict_get(format_context()->metadata, "title", NULL, 0)); 943 EXPECT_FALSE(av_dict_get(format_context()->metadata, "title", NULL, 0));
942 } 944 }
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 1237
1236 const MediaTrack& audio_track = *(media_tracks_->tracks()[1]); 1238 const MediaTrack& audio_track = *(media_tracks_->tracks()[1]);
1237 EXPECT_EQ(audio_track.type(), MediaTrack::Audio); 1239 EXPECT_EQ(audio_track.type(), MediaTrack::Audio);
1238 EXPECT_EQ(audio_track.bytestream_track_id(), 2); 1240 EXPECT_EQ(audio_track.bytestream_track_id(), 2);
1239 EXPECT_EQ(audio_track.kind(), "main"); 1241 EXPECT_EQ(audio_track.kind(), "main");
1240 EXPECT_EQ(audio_track.label(), ""); 1242 EXPECT_EQ(audio_track.label(), "");
1241 EXPECT_EQ(audio_track.language(), ""); 1243 EXPECT_EQ(audio_track.language(), "");
1242 } 1244 }
1243 1245
1244 } // namespace media 1246 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/fake_video_decoder_unittest.cc ('k') | media/filters/ffmpeg_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698