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

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

Issue 160529: demux duplicate data the same way as mp3 does. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <deque> 5 #include <deque>
6 6
7 #include "base/thread.h" 7 #include "base/thread.h"
8 #include "media/base/filters.h" 8 #include "media/base/filters.h"
9 #include "media/base/mock_ffmpeg.h" 9 #include "media/base/mock_ffmpeg.h"
10 #include "media/base/mock_filter_host.h" 10 #include "media/base/mock_filter_host.h"
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // Expect all calls in sequence. 313 // Expect all calls in sequence.
314 InSequence s; 314 InSequence s;
315 315
316 // The demuxer will read a data packet which will get immediately freed, 316 // The demuxer will read a data packet which will get immediately freed,
317 // followed by reading an audio packet... 317 // followed by reading an audio packet...
318 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) 318 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
319 .WillOnce(CreatePacket(AV_STREAM_DATA, kNullData, 0)); 319 .WillOnce(CreatePacket(AV_STREAM_DATA, kNullData, 0));
320 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket()); 320 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
321 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) 321 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
322 .WillOnce(CreatePacket(AV_STREAM_AUDIO, kAudioData, kDataSize)); 322 .WillOnce(CreatePacket(AV_STREAM_AUDIO, kAudioData, kDataSize));
323 EXPECT_CALL(*MockFFmpeg::get(), AVNewPacket(_, _)).WillOnce(NewPacket());
324 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
323 325
324 // ...then we'll free it with some sanity checkpoints... 326 // ...then we'll free it with some sanity checkpoints...
325 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(1)); 327 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(1));
326 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket()); 328 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
327 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(2)); 329 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(2));
328 330
329 // ...then we'll read a video packet... 331 // ...then we'll read a video packet...
330 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) 332 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
331 .WillOnce(CreatePacket(AV_STREAM_VIDEO, kVideoData, kDataSize)); 333 .WillOnce(CreatePacket(AV_STREAM_VIDEO, kVideoData, kDataSize));
334 EXPECT_CALL(*MockFFmpeg::get(), AVNewPacket(_, _)).WillOnce(NewPacket());
335 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
332 336
333 // ...then we'll free it with some sanity checkpoints... 337 // ...then we'll free it with some sanity checkpoints...
334 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(3)); 338 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(3));
335 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket()); 339 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
336 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(4)); 340 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(4));
337 341
338 // ...then we'll simulate end of stream. Note that a packet isn't "created" 342 // ...then we'll simulate end of stream. Note that a packet isn't "created"
339 // in this situation so there is no outstanding packet. However an end of 343 // in this situation so there is no outstanding packet. However an end of
340 // stream packet is created for each stream, which means av_free_packet() 344 // stream packet is created for each stream, which means av_free_packet()
341 // will still be called twice. 345 // will still be called twice.
342 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) 346 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
343 .WillOnce(Return(AVERROR_IO)); 347 .WillOnce(Return(AVERROR_IO));
344 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)); 348 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_));
345 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(5)); 349 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(5));
346 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)); 350 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_));
347 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(6)); 351 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(6));
348 352
349 // Attempt a read from the audio stream and run the message loop until done. 353 // Attempt a read from the audio stream and run the message loop until done.
350 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); 354 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader());
351 reader->Read(audio); 355 reader->Read(audio);
352 message_loop_.RunAllPending(); 356 message_loop_.RunAllPending();
353 EXPECT_TRUE(reader->called()); 357 EXPECT_TRUE(reader->called());
354 ASSERT_TRUE(reader->buffer()); 358 ASSERT_TRUE(reader->buffer());
355 EXPECT_FALSE(reader->buffer()->IsDiscontinuous()); 359 EXPECT_FALSE(reader->buffer()->IsDiscontinuous());
356 EXPECT_EQ(kAudioData, reader->buffer()->GetData()); 360 ASSERT_EQ(kDataSize, reader->buffer()->GetDataSize());
357 EXPECT_EQ(kDataSize, reader->buffer()->GetDataSize()); 361 EXPECT_EQ(0, memcmp(kAudioData, reader->buffer()->GetData(),
362 reader->buffer()->GetDataSize()));
358 363
359 // We shouldn't have freed the audio packet yet. 364 // We shouldn't have freed the audio packet yet.
360 MockFFmpeg::get()->CheckPoint(1); 365 MockFFmpeg::get()->CheckPoint(1);
361 366
362 // Manually release the last reference to the buffer. 367 // Manually release the last reference to the buffer.
363 reader->Reset(); 368 reader->Reset();
364 message_loop_.RunAllPending(); 369 message_loop_.RunAllPending();
365 MockFFmpeg::get()->CheckPoint(2); 370 MockFFmpeg::get()->CheckPoint(2);
366 371
367 // Attempt a read from the video stream and run the message loop until done. 372 // Attempt a read from the video stream and run the message loop until done.
368 reader->Read(video); 373 reader->Read(video);
369 message_loop_.RunAllPending(); 374 message_loop_.RunAllPending();
370 EXPECT_TRUE(reader->called()); 375 EXPECT_TRUE(reader->called());
371 ASSERT_TRUE(reader->buffer()); 376 ASSERT_TRUE(reader->buffer());
372 EXPECT_FALSE(reader->buffer()->IsDiscontinuous()); 377 EXPECT_FALSE(reader->buffer()->IsDiscontinuous());
373 EXPECT_EQ(kVideoData, reader->buffer()->GetData()); 378 ASSERT_EQ(kDataSize, reader->buffer()->GetDataSize());
374 EXPECT_EQ(kDataSize, reader->buffer()->GetDataSize()); 379 EXPECT_EQ(0, memcmp(kVideoData, reader->buffer()->GetData(),
380 reader->buffer()->GetDataSize()));
375 381
376 // We shouldn't have freed the video packet yet. 382 // We shouldn't have freed the video packet yet.
377 MockFFmpeg::get()->CheckPoint(3); 383 MockFFmpeg::get()->CheckPoint(3);
378 384
379 // Manually release the last reference to the buffer and verify it was freed. 385 // Manually release the last reference to the buffer and verify it was freed.
380 reader->Reset(); 386 reader->Reset();
381 message_loop_.RunAllPending(); 387 message_loop_.RunAllPending();
382 MockFFmpeg::get()->CheckPoint(4); 388 MockFFmpeg::get()->CheckPoint(4);
383 389
384 // We should now expect an end of stream buffer in both the audio and video 390 // We should now expect an end of stream buffer in both the audio and video
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 const int64 kExpectedTimestamp = 1234; 442 const int64 kExpectedTimestamp = 1234;
437 const int64 kExpectedFlags = 0; 443 const int64 kExpectedFlags = 0;
438 444
439 // Expect all calls in sequence. 445 // Expect all calls in sequence.
440 InSequence s; 446 InSequence s;
441 447
442 // First we'll read a video packet that causes two audio packets to be queued 448 // First we'll read a video packet that causes two audio packets to be queued
443 // inside FFmpegDemuxer... 449 // inside FFmpegDemuxer...
444 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) 450 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
445 .WillOnce(CreatePacket(AV_STREAM_AUDIO, kAudioData, kDataSize)); 451 .WillOnce(CreatePacket(AV_STREAM_AUDIO, kAudioData, kDataSize));
452 EXPECT_CALL(*MockFFmpeg::get(), AVNewPacket(_, _)).WillOnce(NewPacket());
453 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
446 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) 454 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
447 .WillOnce(CreatePacket(AV_STREAM_AUDIO, kAudioData, kDataSize)); 455 .WillOnce(CreatePacket(AV_STREAM_AUDIO, kAudioData, kDataSize));
456 EXPECT_CALL(*MockFFmpeg::get(), AVNewPacket(_, _)).WillOnce(NewPacket());
457 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
448 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) 458 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
449 .WillOnce(CreatePacket(AV_STREAM_VIDEO, kVideoData, kDataSize)); 459 .WillOnce(CreatePacket(AV_STREAM_VIDEO, kVideoData, kDataSize));
460 EXPECT_CALL(*MockFFmpeg::get(), AVNewPacket(_, _)).WillOnce(NewPacket());
461 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
450 462
451 // ...then we'll release our video packet... 463 // ...then we'll release our video packet...
452 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket()); 464 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
453 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(1)); 465 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(1));
454 466
455 // ...then we'll seek, which should release the previously queued packets... 467 // ...then we'll seek, which should release the previously queued packets...
456 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket()); 468 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
457 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket()); 469 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
458 470
459 // ... then we'll call Seek() to get around the first seek hack... 471 // ... then we'll call Seek() to get around the first seek hack...
(...skipping 10 matching lines...) Expand all
470 482
471 // ...then our callback will be executed... 483 // ...then our callback will be executed...
472 StrictMock<MockFilterCallback> seek_callback; 484 StrictMock<MockFilterCallback> seek_callback;
473 EXPECT_CALL(seek_callback, OnFilterCallback()); 485 EXPECT_CALL(seek_callback, OnFilterCallback());
474 EXPECT_CALL(seek_callback, OnCallbackDestroyed()); 486 EXPECT_CALL(seek_callback, OnCallbackDestroyed());
475 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(2)); 487 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(2));
476 488
477 // ...followed by two audio packet reads we'll trigger... 489 // ...followed by two audio packet reads we'll trigger...
478 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) 490 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
479 .WillOnce(CreatePacket(AV_STREAM_AUDIO, kAudioData, kDataSize)); 491 .WillOnce(CreatePacket(AV_STREAM_AUDIO, kAudioData, kDataSize));
492 EXPECT_CALL(*MockFFmpeg::get(), AVNewPacket(_, _)).WillOnce(NewPacket());
493 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
480 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket()); 494 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
481 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) 495 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
482 .WillOnce(CreatePacket(AV_STREAM_AUDIO, kAudioData, kDataSize)); 496 .WillOnce(CreatePacket(AV_STREAM_AUDIO, kAudioData, kDataSize));
497 EXPECT_CALL(*MockFFmpeg::get(), AVNewPacket(_, _)).WillOnce(NewPacket());
498 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
483 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket()); 499 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
484 500
485 // ...followed by two video packet reads... 501 // ...followed by two video packet reads...
486 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) 502 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
487 .WillOnce(CreatePacket(AV_STREAM_VIDEO, kVideoData, kDataSize)); 503 .WillOnce(CreatePacket(AV_STREAM_VIDEO, kVideoData, kDataSize));
504 EXPECT_CALL(*MockFFmpeg::get(), AVNewPacket(_, _)).WillOnce(NewPacket());
505 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
488 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket()); 506 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
489 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) 507 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
490 .WillOnce(CreatePacket(AV_STREAM_VIDEO, kVideoData, kDataSize)); 508 .WillOnce(CreatePacket(AV_STREAM_VIDEO, kVideoData, kDataSize));
509 EXPECT_CALL(*MockFFmpeg::get(), AVNewPacket(_, _)).WillOnce(NewPacket());
510 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
491 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket()); 511 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
492 512
493 // ...and finally a sanity checkpoint to make sure everything was released. 513 // ...and finally a sanity checkpoint to make sure everything was released.
494 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(3)); 514 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(3));
495 515
496 // Read a video packet and release it. 516 // Read a video packet and release it.
497 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); 517 scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader());
498 reader->Read(video); 518 reader->Read(video);
499 message_loop_.RunAllPending(); 519 message_loop_.RunAllPending();
500 EXPECT_TRUE(reader->called()); 520 EXPECT_TRUE(reader->called());
501 ASSERT_TRUE(reader->buffer()); 521 ASSERT_TRUE(reader->buffer());
502 EXPECT_FALSE(reader->buffer()->IsDiscontinuous()); 522 EXPECT_FALSE(reader->buffer()->IsDiscontinuous());
503 EXPECT_EQ(kVideoData, reader->buffer()->GetData()); 523 ASSERT_EQ(kDataSize, reader->buffer()->GetDataSize());
504 EXPECT_EQ(kDataSize, reader->buffer()->GetDataSize()); 524 EXPECT_EQ(0, memcmp(kVideoData, reader->buffer()->GetData(),
525 reader->buffer()->GetDataSize()));
505 526
506 // Release the video packet and verify the other packets are still queued. 527 // Release the video packet and verify the other packets are still queued.
507 reader->Reset(); 528 reader->Reset();
508 message_loop_.RunAllPending(); 529 message_loop_.RunAllPending();
509 MockFFmpeg::get()->CheckPoint(1); 530 MockFFmpeg::get()->CheckPoint(1);
510 531
511 // Issue a preliminary seek to get around the "first seek" hack. 532 // Issue a preliminary seek to get around the "first seek" hack.
512 // 533 //
513 // TODO(scherkus): fix the av_seek_frame() hackery! 534 // TODO(scherkus): fix the av_seek_frame() hackery!
514 demuxer_->Seek(base::TimeDelta(), hack_callback.NewCallback()); 535 demuxer_->Seek(base::TimeDelta(), hack_callback.NewCallback());
515 message_loop_.RunAllPending(); 536 message_loop_.RunAllPending();
516 537
517 // Now issue a simple forward seek, which should discard queued packets. 538 // Now issue a simple forward seek, which should discard queued packets.
518 demuxer_->Seek(base::TimeDelta::FromMicroseconds(kExpectedTimestamp), 539 demuxer_->Seek(base::TimeDelta::FromMicroseconds(kExpectedTimestamp),
519 seek_callback.NewCallback()); 540 seek_callback.NewCallback());
520 message_loop_.RunAllPending(); 541 message_loop_.RunAllPending();
521 MockFFmpeg::get()->CheckPoint(2); 542 MockFFmpeg::get()->CheckPoint(2);
522 543
523 // The next read from each stream should now be discontinuous, but subsequent 544 // The next read from each stream should now be discontinuous, but subsequent
524 // reads should not. 545 // reads should not.
525 546
526 // Audio read #1, should be discontinuous. 547 // Audio read #1, should be discontinuous.
527 reader->Read(audio); 548 reader->Read(audio);
528 message_loop_.RunAllPending(); 549 message_loop_.RunAllPending();
529 EXPECT_TRUE(reader->called()); 550 EXPECT_TRUE(reader->called());
530 ASSERT_TRUE(reader->buffer()); 551 ASSERT_TRUE(reader->buffer());
531 EXPECT_TRUE(reader->buffer()->IsDiscontinuous()); 552 EXPECT_TRUE(reader->buffer()->IsDiscontinuous());
532 EXPECT_EQ(kAudioData, reader->buffer()->GetData()); 553 ASSERT_EQ(kDataSize, reader->buffer()->GetDataSize());
533 EXPECT_EQ(kDataSize, reader->buffer()->GetDataSize()); 554 EXPECT_EQ(0, memcmp(kAudioData, reader->buffer()->GetData(),
555 reader->buffer()->GetDataSize()));
534 556
535 // Audio read #2, should not be discontinuous. 557 // Audio read #2, should not be discontinuous.
536 reader->Reset(); 558 reader->Reset();
537 reader->Read(audio); 559 reader->Read(audio);
538 message_loop_.RunAllPending(); 560 message_loop_.RunAllPending();
539 EXPECT_TRUE(reader->called()); 561 EXPECT_TRUE(reader->called());
540 ASSERT_TRUE(reader->buffer()); 562 ASSERT_TRUE(reader->buffer());
541 EXPECT_FALSE(reader->buffer()->IsDiscontinuous()); 563 EXPECT_FALSE(reader->buffer()->IsDiscontinuous());
542 EXPECT_EQ(kAudioData, reader->buffer()->GetData()); 564 ASSERT_EQ(kDataSize, reader->buffer()->GetDataSize());
543 EXPECT_EQ(kDataSize, reader->buffer()->GetDataSize()); 565 EXPECT_EQ(0, memcmp(kAudioData, reader->buffer()->GetData(),
566 reader->buffer()->GetDataSize()));
544 567
545 // Video read #1, should be discontinuous. 568 // Video read #1, should be discontinuous.
546 reader->Reset(); 569 reader->Reset();
547 reader->Read(video); 570 reader->Read(video);
548 message_loop_.RunAllPending(); 571 message_loop_.RunAllPending();
549 EXPECT_TRUE(reader->called()); 572 EXPECT_TRUE(reader->called());
550 ASSERT_TRUE(reader->buffer()); 573 ASSERT_TRUE(reader->buffer());
551 EXPECT_TRUE(reader->buffer()->IsDiscontinuous()); 574 EXPECT_TRUE(reader->buffer()->IsDiscontinuous());
552 EXPECT_EQ(kVideoData, reader->buffer()->GetData()); 575 ASSERT_EQ(kDataSize, reader->buffer()->GetDataSize());
553 EXPECT_EQ(kDataSize, reader->buffer()->GetDataSize()); 576 EXPECT_EQ(0, memcmp(kVideoData, reader->buffer()->GetData(),
577 reader->buffer()->GetDataSize()));
554 578
555 // Video read #2, should not be discontinuous. 579 // Video read #2, should not be discontinuous.
556 reader->Reset(); 580 reader->Reset();
557 reader->Read(video); 581 reader->Read(video);
558 message_loop_.RunAllPending(); 582 message_loop_.RunAllPending();
559 EXPECT_TRUE(reader->called()); 583 EXPECT_TRUE(reader->called());
560 ASSERT_TRUE(reader->buffer()); 584 ASSERT_TRUE(reader->buffer());
561 EXPECT_FALSE(reader->buffer()->IsDiscontinuous()); 585 EXPECT_FALSE(reader->buffer()->IsDiscontinuous());
562 EXPECT_EQ(kVideoData, reader->buffer()->GetData()); 586 ASSERT_EQ(kDataSize, reader->buffer()->GetDataSize());
563 EXPECT_EQ(kDataSize, reader->buffer()->GetDataSize()); 587 EXPECT_EQ(0, memcmp(kVideoData, reader->buffer()->GetData(),
588 reader->buffer()->GetDataSize()));
564 589
565 // Manually release the last reference to the buffer and verify it was freed. 590 // Manually release the last reference to the buffer and verify it was freed.
566 reader->Reset(); 591 reader->Reset();
567 message_loop_.RunAllPending(); 592 message_loop_.RunAllPending();
568 MockFFmpeg::get()->CheckPoint(3); 593 MockFFmpeg::get()->CheckPoint(3);
569 } 594 }
570 595
571 TEST_F(FFmpegDemuxerTest, MP3Hack) {
572 // This tests our deep-copying workaround for FFmpeg's MP3 demuxer. When we
573 // fix the root cause this test will fail and should be removed.
574 //
575 // TODO(scherkus): according to the documentation, deep-copying the packet is
576 // actually the correct action -- remove this test when we fix our demuxer.
577
578 // Simulate an MP3 stream.
579 codecs_[AV_STREAM_AUDIO].codec_id = CODEC_ID_MP3;
580 {
581 SCOPED_TRACE("");
582 InitializeDemuxer();
583 }
584
585 // Get our stream.
586 scoped_refptr<DemuxerStream> audio = demuxer_->GetStream(DS_STREAM_AUDIO);
587 ASSERT_TRUE(audio);
588
589 // Expect all calls in sequence.
590 InSequence s;
591
592 // We'll read an MP3 packet and allocate a new packet, then instantly free
593 // the original packet due to deep copying...
594 EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _))
595 .WillOnce(CreatePacket(AV_STREAM_AUDIO, kAudioData, kDataSize));
596 EXPECT_CALL(*MockFFmpeg::get(), AVNewPacket(_, _)).WillOnce(NewPacket());
597 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
598
599 // ...then we'll have a sanity checkpoint...
600 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(1));
601
602 // ...then we'll free the deep copied packet.
603 EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).WillOnce(FreePacket());
604 EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(2));
605
606 // Audio read should perform a deep copy on the packet and instantly release
607 // the original packet. The data pointers should not be the same, but the
608 // contents should match.
609 scoped_refptr<DemuxerStreamReader> reader = new DemuxerStreamReader();
610 reader->Read(audio);
611 message_loop_.RunAllPending();
612 EXPECT_TRUE(reader->called());
613 ASSERT_TRUE(reader->buffer());
614 EXPECT_FALSE(reader->buffer()->IsDiscontinuous());
615 EXPECT_NE(kAudioData, reader->buffer()->GetData());
616 EXPECT_EQ(kDataSize, reader->buffer()->GetDataSize());
617 EXPECT_EQ(0, memcmp(kAudioData, reader->buffer()->GetData(), kDataSize));
618
619 // We shouldn't have freed the MP3 packet yet.
620 MockFFmpeg::get()->CheckPoint(1);
621
622 // Manually release the last reference to the buffer and verify it was freed.
623 reader->Reset();
624 message_loop_.RunAllPending();
625 MockFFmpeg::get()->CheckPoint(2);
626 }
627
628 // A mocked callback specialization for calling Read(). Since RunWithParams() 596 // A mocked callback specialization for calling Read(). Since RunWithParams()
629 // is mocked we don't need to pass in object or method pointers. 597 // is mocked we don't need to pass in object or method pointers.
630 typedef CallbackImpl<FFmpegDemuxerTest, void (FFmpegDemuxerTest::*)(Buffer*), 598 typedef CallbackImpl<FFmpegDemuxerTest, void (FFmpegDemuxerTest::*)(Buffer*),
631 Tuple1<Buffer*> > ReadCallback; 599 Tuple1<Buffer*> > ReadCallback;
632 class MockReadCallback : public ReadCallback { 600 class MockReadCallback : public ReadCallback {
633 public: 601 public:
634 MockReadCallback() 602 MockReadCallback()
635 : ReadCallback(NULL, NULL) { 603 : ReadCallback(NULL, NULL) {
636 } 604 }
637 605
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 { 797 {
830 SCOPED_TRACE(""); 798 SCOPED_TRACE("");
831 InitializeDemuxer(); 799 InitializeDemuxer();
832 } 800 }
833 EXPECT_CALL(*data_source_, IsStreaming()) 801 EXPECT_CALL(*data_source_, IsStreaming())
834 .WillOnce(Return(false)); 802 .WillOnce(Return(false));
835 EXPECT_FALSE(demuxer_->IsStreaming()); 803 EXPECT_FALSE(demuxer_->IsStreaming());
836 } 804 }
837 805
838 } // namespace media 806 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_demuxer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698