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

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

Issue 205703003: MSE: Use frame duration, if available, in LegacyFrameProcessor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to pull in WebM frame duration estimation, undid the CD tests' conversion to just BlockGrou… Created 6 years, 8 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/chunk_demuxer.cc ('k') | media/filters/legacy_frame_processor.h » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 // bear-640x360.webm AudioDecoderConfig returns 3935 for its extra_data_size() 549 // bear-640x360.webm AudioDecoderConfig returns 3935 for its extra_data_size()
550 // The resulting audio stream returns data from each file for the following 550 // The resulting audio stream returns data from each file for the following
551 // time ranges. 551 // time ranges.
552 // bear-320x240.webm : [0-524) [779-2736) 552 // bear-320x240.webm : [0-524) [779-2736)
553 // bear-640x360.webm : [527-759) 553 // bear-640x360.webm : [527-759)
554 bool InitDemuxerWithConfigChangeData() { 554 bool InitDemuxerWithConfigChangeData() {
555 scoped_refptr<DecoderBuffer> bear1 = ReadTestDataFile("bear-320x240.webm"); 555 scoped_refptr<DecoderBuffer> bear1 = ReadTestDataFile("bear-320x240.webm");
556 scoped_refptr<DecoderBuffer> bear2 = ReadTestDataFile("bear-640x360.webm"); 556 scoped_refptr<DecoderBuffer> bear2 = ReadTestDataFile("bear-640x360.webm");
557 557
558 EXPECT_CALL(*this, DemuxerOpened()); 558 EXPECT_CALL(*this, DemuxerOpened());
559
559 demuxer_->Initialize( 560 demuxer_->Initialize(
560 &host_, CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), 561 &host_, CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744),
561 PIPELINE_OK), true); 562 PIPELINE_OK), true);
562 563
563 if (AddId(kSourceId, HAS_AUDIO | HAS_VIDEO) != ChunkDemuxer::kOk) 564 if (AddId(kSourceId, HAS_AUDIO | HAS_VIDEO) != ChunkDemuxer::kOk)
564 return false; 565 return false;
565 566
566 // Append the whole bear1 file. 567 // Append the whole bear1 file.
568 // TODO(wolenetz/acolwell): Remove this extra SetDuration expectation once
569 // the files are fixed to have the correct duration in their init segments,
570 // and the CreateInitDoneCB() call, above, is fixed to used that duration.
571 // See http://crbug.com/354284.
572 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2768)));
567 AppendData(bear1->data(), bear1->data_size()); 573 AppendData(bear1->data(), bear1->data_size());
568 // Last audio frame has timestamp 2721 and duration 24 (estimated from max 574 // Last audio frame has timestamp 2721 and duration 24 (estimated from max
569 // seen so far for audio track). 575 // seen so far for audio track).
570 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry 576 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry
571 // DefaultDuration for video track). 577 // DefaultDuration for video track).
572 CheckExpectedRanges(kSourceId, "{ [0,2736) }"); 578 CheckExpectedRanges(kSourceId, "{ [0,2736) }");
573 579
574 // Append initialization segment for bear2. 580 // Append initialization segment for bear2.
575 // Note: Offsets here and below are derived from 581 // Note: Offsets here and below are derived from
576 // media/test/data/bear-640x360-manifest.js and 582 // media/test/data/bear-640x360-manifest.js and
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 int track_number, 684 int track_number,
679 int block_duration) { 685 int block_duration) {
680 CHECK_GT(end_timecode, timecode); 686 CHECK_GT(end_timecode, timecode);
681 687
682 std::vector<uint8> data(kBlockSize); 688 std::vector<uint8> data(kBlockSize);
683 689
684 ClusterBuilder cb; 690 ClusterBuilder cb;
685 cb.SetClusterTimecode(timecode); 691 cb.SetClusterTimecode(timecode);
686 692
687 // Create simple blocks for everything except the last block. 693 // Create simple blocks for everything except the last block.
688 for (int i = 0; timecode < (end_timecode - block_duration); i++) { 694 while (timecode < (end_timecode - block_duration)) {
689 cb.AddSimpleBlock(track_number, timecode, kWebMFlagKeyframe, 695 cb.AddSimpleBlock(track_number, timecode, kWebMFlagKeyframe,
690 &data[0], data.size()); 696 &data[0], data.size());
691 timecode += block_duration; 697 timecode += block_duration;
692 } 698 }
693 699
694 // Make the last block a BlockGroup so that it doesn't get delayed by the
695 // block duration calculation logic.
696 if (track_number == kVideoTrackNum) { 700 if (track_number == kVideoTrackNum) {
697 AddVideoBlockGroup(&cb, track_number, timecode, block_duration, 701 AddVideoBlockGroup(&cb, track_number, timecode, block_duration,
698 kWebMFlagKeyframe); 702 kWebMFlagKeyframe);
699 } else { 703 } else {
700 cb.AddBlockGroup(track_number, timecode, block_duration, 704 cb.AddBlockGroup(track_number, timecode, block_duration,
701 kWebMFlagKeyframe, &data[0], data.size()); 705 kWebMFlagKeyframe, &data[0], data.size());
702 } 706 }
707
703 return cb.Finish(); 708 return cb.Finish();
704 } 709 }
705 710
706 void Read(DemuxerStream::Type type, const DemuxerStream::ReadCB& read_cb) { 711 void Read(DemuxerStream::Type type, const DemuxerStream::ReadCB& read_cb) {
707 demuxer_->GetStream(type)->Read(read_cb); 712 demuxer_->GetStream(type)->Read(read_cb);
708 message_loop_.RunUntilIdle(); 713 message_loop_.RunUntilIdle();
709 } 714 }
710 715
711 void ReadAudio(const DemuxerStream::ReadCB& read_cb) { 716 void ReadAudio(const DemuxerStream::ReadCB& read_cb) {
712 Read(DemuxerStream::AUDIO, read_cb); 717 Read(DemuxerStream::AUDIO, read_cb);
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 } 1578 }
1574 1579
1575 // Verify buffered range change behavior for audio/video/text tracks. 1580 // Verify buffered range change behavior for audio/video/text tracks.
1576 TEST_F(ChunkDemuxerTest, EndOfStreamRangeChanges) { 1581 TEST_F(ChunkDemuxerTest, EndOfStreamRangeChanges) {
1577 DemuxerStream* text_stream = NULL; 1582 DemuxerStream* text_stream = NULL;
1578 1583
1579 EXPECT_CALL(host_, AddTextStream(_, _)) 1584 EXPECT_CALL(host_, AddTextStream(_, _))
1580 .WillOnce(SaveArg<0>(&text_stream)); 1585 .WillOnce(SaveArg<0>(&text_stream));
1581 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 1586 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
1582 1587
1583 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 30"); 1588 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33");
1584 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K"); 1589 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K");
1585 1590
1586 // Check expected ranges and verify that an empty text track does not 1591 // Check expected ranges and verify that an empty text track does not
1587 // affect the expected ranges. 1592 // affect the expected ranges.
1588 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 1593 CheckExpectedRanges(kSourceId, "{ [0,46) }");
1589 1594
1590 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(60))); 1595 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66)));
1591 MarkEndOfStream(PIPELINE_OK); 1596 MarkEndOfStream(PIPELINE_OK);
1592 1597
1593 // Check expected ranges and verify that an empty text track does not 1598 // Check expected ranges and verify that an empty text track does not
1594 // affect the expected ranges. 1599 // affect the expected ranges.
1595 CheckExpectedRanges(kSourceId, "{ [0,60) }"); 1600 CheckExpectedRanges(kSourceId, "{ [0,66) }");
1596 1601
1597 // Unmark end of stream state and verify that the ranges return to 1602 // Unmark end of stream state and verify that the ranges return to
1598 // their pre-"end of stream" values. 1603 // their pre-"end of stream" values.
1599 demuxer_->UnmarkEndOfStream(); 1604 demuxer_->UnmarkEndOfStream();
1600 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 1605 CheckExpectedRanges(kSourceId, "{ [0,46) }");
1601 1606
1602 // Add text track data and verify that the buffered ranges don't change 1607 // Add text track data and verify that the buffered ranges don't change
1603 // since the intersection of all the tracks doesn't change. 1608 // since the intersection of all the tracks doesn't change.
1604 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(200))); 1609 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(200)));
1605 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K"); 1610 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K");
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 TEST_F(ChunkDemuxerTest, WebMFile_AudioAndVideo) { 1652 TEST_F(ChunkDemuxerTest, WebMFile_AudioAndVideo) {
1648 struct BufferTimestamps buffer_timestamps[] = { 1653 struct BufferTimestamps buffer_timestamps[] = {
1649 {0, 0}, 1654 {0, 0},
1650 {33, 3}, 1655 {33, 3},
1651 {67, 6}, 1656 {67, 6},
1652 {100, 9}, 1657 {100, 9},
1653 {133, 12}, 1658 {133, 12},
1654 {kSkip, kSkip}, 1659 {kSkip, kSkip},
1655 }; 1660 };
1656 1661
1662 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the
1663 // ParseWebMFile() call's expected duration, below, once the file is fixed to
1664 // have the correct duration in the init segment. See http://crbug.com/354284.
1665 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2768)));
1666
1657 ASSERT_TRUE(ParseWebMFile("bear-320x240.webm", buffer_timestamps, 1667 ASSERT_TRUE(ParseWebMFile("bear-320x240.webm", buffer_timestamps,
1658 base::TimeDelta::FromMilliseconds(2744))); 1668 base::TimeDelta::FromMilliseconds(2744)));
1659 } 1669 }
1660 1670
1661 TEST_F(ChunkDemuxerTest, WebMFile_LiveAudioAndVideo) { 1671 TEST_F(ChunkDemuxerTest, WebMFile_LiveAudioAndVideo) {
1662 struct BufferTimestamps buffer_timestamps[] = { 1672 struct BufferTimestamps buffer_timestamps[] = {
1663 {0, 0}, 1673 {0, 0},
1664 {33, 3}, 1674 {33, 3},
1665 {67, 6}, 1675 {67, 6},
1666 {100, 9}, 1676 {100, 9},
1667 {133, 12}, 1677 {133, 12},
1668 {kSkip, kSkip}, 1678 {kSkip, kSkip},
1669 }; 1679 };
1670 1680
1671 ASSERT_TRUE(ParseWebMFile("bear-320x240-live.webm", buffer_timestamps, 1681 ASSERT_TRUE(ParseWebMFile("bear-320x240-live.webm", buffer_timestamps,
1672 kInfiniteDuration())); 1682 kInfiniteDuration()));
1673 } 1683 }
1674 1684
1675 TEST_F(ChunkDemuxerTest, WebMFile_AudioOnly) { 1685 TEST_F(ChunkDemuxerTest, WebMFile_AudioOnly) {
1676 struct BufferTimestamps buffer_timestamps[] = { 1686 struct BufferTimestamps buffer_timestamps[] = {
1677 {kSkip, 0}, 1687 {kSkip, 0},
1678 {kSkip, 3}, 1688 {kSkip, 3},
1679 {kSkip, 6}, 1689 {kSkip, 6},
1680 {kSkip, 9}, 1690 {kSkip, 9},
1681 {kSkip, 12}, 1691 {kSkip, 12},
1682 {kSkip, kSkip}, 1692 {kSkip, kSkip},
1683 }; 1693 };
1684 1694
1695 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the
1696 // ParseWebMFile() call's expected duration, below, once the file is fixed to
1697 // have the correct duration in the init segment. See http://crbug.com/354284.
1698 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2768)));
1699
1685 ASSERT_TRUE(ParseWebMFile("bear-320x240-audio-only.webm", buffer_timestamps, 1700 ASSERT_TRUE(ParseWebMFile("bear-320x240-audio-only.webm", buffer_timestamps,
1686 base::TimeDelta::FromMilliseconds(2744), 1701 base::TimeDelta::FromMilliseconds(2744),
1687 HAS_AUDIO)); 1702 HAS_AUDIO));
1688 } 1703 }
1689 1704
1690 TEST_F(ChunkDemuxerTest, WebMFile_VideoOnly) { 1705 TEST_F(ChunkDemuxerTest, WebMFile_VideoOnly) {
1691 struct BufferTimestamps buffer_timestamps[] = { 1706 struct BufferTimestamps buffer_timestamps[] = {
1692 {0, kSkip}, 1707 {0, kSkip},
1693 {33, kSkip}, 1708 {33, kSkip},
1694 {67, kSkip}, 1709 {67, kSkip},
1695 {100, kSkip}, 1710 {100, kSkip},
1696 {133, kSkip}, 1711 {133, kSkip},
1697 {kSkip, kSkip}, 1712 {kSkip, kSkip},
1698 }; 1713 };
1699 1714
1715 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the
1716 // ParseWebMFile() call's expected duration, below, once the file is fixed to
1717 // have the correct duration in the init segment. See http://crbug.com/354284.
1718 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2736)));
1719
1700 ASSERT_TRUE(ParseWebMFile("bear-320x240-video-only.webm", buffer_timestamps, 1720 ASSERT_TRUE(ParseWebMFile("bear-320x240-video-only.webm", buffer_timestamps,
1701 base::TimeDelta::FromMilliseconds(2703), 1721 base::TimeDelta::FromMilliseconds(2703),
1702 HAS_VIDEO)); 1722 HAS_VIDEO));
1703 } 1723 }
1704 1724
1705 TEST_F(ChunkDemuxerTest, WebMFile_AltRefFrames) { 1725 TEST_F(ChunkDemuxerTest, WebMFile_AltRefFrames) {
1706 struct BufferTimestamps buffer_timestamps[] = { 1726 struct BufferTimestamps buffer_timestamps[] = {
1707 {0, 0}, 1727 {0, 0},
1708 {33, 3}, 1728 {33, 3},
1709 {33, 6}, 1729 {33, 6},
1710 {67, 9}, 1730 {67, 9},
1711 {100, 12}, 1731 {100, 12},
1712 {kSkip, kSkip}, 1732 {kSkip, kSkip},
1713 }; 1733 };
1714 1734
1735 // TODO(wolenetz/acolwell): Remove this SetDuration expectation and update the
1736 // ParseWebMFile() call's expected duration, below, once the file is fixed to
1737 // have the correct duration in the init segment. See http://crbug.com/354284.
1738 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2768)));
1739
1715 ASSERT_TRUE(ParseWebMFile("bear-320x240-altref.webm", buffer_timestamps, 1740 ASSERT_TRUE(ParseWebMFile("bear-320x240-altref.webm", buffer_timestamps,
1716 base::TimeDelta::FromMilliseconds(2767))); 1741 base::TimeDelta::FromMilliseconds(2767)));
1717 } 1742 }
1718 1743
1719 // Verify that we output buffers before the entire cluster has been parsed. 1744 // Verify that we output buffers before the entire cluster has been parsed.
1720 TEST_F(ChunkDemuxerTest, IncrementalClusterParsing) { 1745 TEST_F(ChunkDemuxerTest, IncrementalClusterParsing) {
1721 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1746 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1722 AppendEmptyCluster(0); 1747 AppendEmptyCluster(0);
1723 1748
1724 scoped_ptr<Cluster> cluster(GenerateCluster(0, 6)); 1749 scoped_ptr<Cluster> cluster(GenerateCluster(0, 6));
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
2720 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2745 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2721 const int kStreamDuration = kDefaultDuration().InMilliseconds(); 2746 const int kStreamDuration = kDefaultDuration().InMilliseconds();
2722 2747
2723 // Add data leading up to the currently set duration. 2748 // Add data leading up to the currently set duration.
2724 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration, 2749 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration,
2725 kStreamDuration - kVideoBlockDuration, 2750 kStreamDuration - kVideoBlockDuration,
2726 2)); 2751 2));
2727 2752
2728 CheckExpectedRanges(kSourceId, "{ [201191,201224) }"); 2753 CheckExpectedRanges(kSourceId, "{ [201191,201224) }");
2729 2754
2730 // Add data at the currently set duration. The duration should not increase. 2755 // Add data beginning at the currently set duration and expect a new duration
2756 // to be signaled. Note that the last video block will have a higher end
2757 // timestamp than the last audio block.
2758 // TODO(wolenetz): Compliant coded frame processor will emit a max of one
2759 // duration change per each ProcessFrames(). Remove the first expectation here
2760 // once compliant coded frame processor is used. See http://crbug.com/249422.
2761 const int kNewStreamDurationAudio = kStreamDuration + kAudioBlockDuration;
2762 EXPECT_CALL(host_, SetDuration(
2763 base::TimeDelta::FromMilliseconds(kNewStreamDurationAudio)));
2764 const int kNewStreamDurationVideo = kStreamDuration + kVideoBlockDuration;
2765 EXPECT_CALL(host_, SetDuration(
2766 base::TimeDelta::FromMilliseconds(kNewStreamDurationVideo)));
2731 AppendCluster(GenerateCluster(kDefaultDuration().InMilliseconds(), 2)); 2767 AppendCluster(GenerateCluster(kDefaultDuration().InMilliseconds(), 2));
2732 2768
2733 // Range should not be affected. 2769 CheckExpectedRanges(kSourceId, "{ [201191,201247) }");
2734 CheckExpectedRanges(kSourceId, "{ [201191,201224) }");
2735 2770
2736 // Now add data past the duration and expect a new duration to be signalled. 2771 // Add more data to the end of each media type. Note that the last audio block
2737 const int kNewStreamDuration = kStreamDuration + kAudioBlockDuration * 2; 2772 // will have a higher end timestamp than the last video block.
2773 const int kFinalStreamDuration = kStreamDuration + kAudioBlockDuration * 3;
2738 EXPECT_CALL(host_, SetDuration( 2774 EXPECT_CALL(host_, SetDuration(
2739 base::TimeDelta::FromMilliseconds(kNewStreamDuration))); 2775 base::TimeDelta::FromMilliseconds(kFinalStreamDuration)));
2740 AppendCluster(GenerateCluster(kStreamDuration + kAudioBlockDuration, 2776 AppendCluster(GenerateCluster(kStreamDuration + kAudioBlockDuration,
2741 kStreamDuration + kVideoBlockDuration, 2777 kStreamDuration + kVideoBlockDuration,
2742 2)); 2778 3));
2743 2779
2744 // See that the range has increased appropriately. 2780 // See that the range has increased appropriately (but not to the full
2745 CheckExpectedRanges(kSourceId, "{ [201191,201270) }"); 2781 // duration of 201293, since there is not enough video appended for that).
2782 CheckExpectedRanges(kSourceId, "{ [201191,201290) }");
2746 } 2783 }
2747 2784
2748 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) { 2785 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) {
2749 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2786 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2750 2787
2751 ASSERT_TRUE(SetTimestampOffset(kSourceId, kDefaultDuration())); 2788 ASSERT_TRUE(SetTimestampOffset(kSourceId, kDefaultDuration()));
2752 2789
2790 // TODO(wolenetz): Compliant coded frame processor will emit a max of one
2791 // duration change per each ProcessFrames(). Remove the first expectation here
2792 // once compliant coded frame processor is used. See http://crbug.com/249422.
2753 EXPECT_CALL(host_, SetDuration( 2793 EXPECT_CALL(host_, SetDuration(
2754 kDefaultDuration() + base::TimeDelta::FromMilliseconds( 2794 kDefaultDuration() + base::TimeDelta::FromMilliseconds(
2755 kAudioBlockDuration * 2))); 2795 kAudioBlockDuration * 2)));
2796 EXPECT_CALL(host_, SetDuration(
2797 kDefaultDuration() + base::TimeDelta::FromMilliseconds(
2798 kVideoBlockDuration * 2)));
2756 AppendCluster(GenerateCluster(0, 4)); 2799 AppendCluster(GenerateCluster(0, 4));
2757 } 2800 }
2758 2801
2759 TEST_F(ChunkDemuxerTest, EndOfStreamTruncateDuration) { 2802 TEST_F(ChunkDemuxerTest, EndOfStreamTruncateDuration) {
2760 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2803 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2761 2804
2762 AppendCluster(kDefaultFirstCluster()); 2805 AppendCluster(kDefaultFirstCluster());
2763 2806
2764 EXPECT_CALL(host_, SetDuration( 2807 EXPECT_CALL(host_, SetDuration(
2765 base::TimeDelta::FromMilliseconds(kDefaultFirstClusterEndTimestamp))); 2808 base::TimeDelta::FromMilliseconds(kDefaultFirstClusterEndTimestamp)));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2810 2853
2811 // Normally this would return an audio buffer at timestamp zero, but 2854 // Normally this would return an audio buffer at timestamp zero, but
2812 // all reads should return EOS buffers when disabled. 2855 // all reads should return EOS buffers when disabled.
2813 bool audio_read_done = false; 2856 bool audio_read_done = false;
2814 stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); 2857 stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done));
2815 message_loop_.RunUntilIdle(); 2858 message_loop_.RunUntilIdle();
2816 2859
2817 EXPECT_TRUE(audio_read_done); 2860 EXPECT_TRUE(audio_read_done);
2818 } 2861 }
2819 2862
2820 // Verifies that signalling end of stream while stalled at a gap 2863 // Verifies that signaling end of stream while stalled at a gap
2821 // boundary does not trigger end of stream buffers to be returned. 2864 // boundary does not trigger end of stream buffers to be returned.
2822 TEST_F(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) { 2865 TEST_F(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) {
2823 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2866 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2824 2867
2825 AppendCluster(0, 10); 2868 AppendCluster(0, 10);
2826 AppendCluster(300, 10); 2869 AppendCluster(300, 10);
2827 CheckExpectedRanges(kSourceId, "{ [0,132) [300,432) }"); 2870 CheckExpectedRanges(kSourceId, "{ [0,132) [300,432) }");
2828 2871
2829
2830 GenerateExpectedReads(0, 10); 2872 GenerateExpectedReads(0, 10);
2831 2873
2832 bool audio_read_done = false; 2874 bool audio_read_done = false;
2833 bool video_read_done = false; 2875 bool video_read_done = false;
2834 ReadAudio(base::Bind(&OnReadDone, 2876 ReadAudio(base::Bind(&OnReadDone,
2835 base::TimeDelta::FromMilliseconds(138), 2877 base::TimeDelta::FromMilliseconds(138),
2836 &audio_read_done)); 2878 &audio_read_done));
2837 ReadVideo(base::Bind(&OnReadDone, 2879 ReadVideo(base::Bind(&OnReadDone,
2838 base::TimeDelta::FromMilliseconds(138), 2880 base::TimeDelta::FromMilliseconds(138),
2839 &video_read_done)); 2881 &video_read_done));
2840 2882
2841 // Verify that the reads didn't complete 2883 // Verify that the reads didn't complete
2842 EXPECT_FALSE(audio_read_done); 2884 EXPECT_FALSE(audio_read_done);
2843 EXPECT_FALSE(video_read_done); 2885 EXPECT_FALSE(video_read_done);
2844 2886
2845 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(438))); 2887 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(438)));
2846 MarkEndOfStream(PIPELINE_OK); 2888 MarkEndOfStream(PIPELINE_OK);
2847 2889
2848 // Verify that the reads still haven't completed. 2890 // Verify that the reads still haven't completed.
2849 EXPECT_FALSE(audio_read_done); 2891 EXPECT_FALSE(audio_read_done);
2850 EXPECT_FALSE(video_read_done); 2892 EXPECT_FALSE(video_read_done);
2851 2893
2852 demuxer_->UnmarkEndOfStream(); 2894 demuxer_->UnmarkEndOfStream();
2853 2895
2854 AppendCluster(138, 24); 2896 AppendCluster(138, 22);
2855 2897
2856 message_loop_.RunUntilIdle(); 2898 message_loop_.RunUntilIdle();
2857 2899
2858 CheckExpectedRanges(kSourceId, "{ [0,438) }"); 2900 CheckExpectedRanges(kSourceId, "{ [0,435) }");
2859 2901
2860 // Verify that the reads have completed. 2902 // Verify that the reads have completed.
2861 EXPECT_TRUE(audio_read_done); 2903 EXPECT_TRUE(audio_read_done);
2862 EXPECT_TRUE(video_read_done); 2904 EXPECT_TRUE(video_read_done);
2863 2905
2864 // Read the rest of the buffers. 2906 // Read the rest of the buffers.
2865 GenerateExpectedReads(161, 171, 22); 2907 GenerateExpectedReads(161, 171, 20);
2866 2908
2867 // Verify that reads block because the append cleared the end of stream state. 2909 // Verify that reads block because the append cleared the end of stream state.
2868 audio_read_done = false; 2910 audio_read_done = false;
2869 video_read_done = false; 2911 video_read_done = false;
2870 ReadAudio(base::Bind(&OnReadDone_EOSExpected, 2912 ReadAudio(base::Bind(&OnReadDone_EOSExpected,
2871 &audio_read_done)); 2913 &audio_read_done));
2872 ReadVideo(base::Bind(&OnReadDone_EOSExpected, 2914 ReadVideo(base::Bind(&OnReadDone_EOSExpected,
2873 &video_read_done)); 2915 &video_read_done));
2874 2916
2875 // Verify that the reads don't complete. 2917 // Verify that the reads don't complete.
2876 EXPECT_FALSE(audio_read_done); 2918 EXPECT_FALSE(audio_read_done);
2877 EXPECT_FALSE(video_read_done); 2919 EXPECT_FALSE(video_read_done);
2878 2920
2921 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(437)));
2879 MarkEndOfStream(PIPELINE_OK); 2922 MarkEndOfStream(PIPELINE_OK);
2880 2923
2881 EXPECT_TRUE(audio_read_done); 2924 EXPECT_TRUE(audio_read_done);
2882 EXPECT_TRUE(video_read_done); 2925 EXPECT_TRUE(video_read_done);
2883 } 2926 }
2884 2927
2885 TEST_F(ChunkDemuxerTest, CanceledSeekDuringInitialPreroll) { 2928 TEST_F(ChunkDemuxerTest, CanceledSeekDuringInitialPreroll) {
2886 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2929 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2887 2930
2888 // Cancel preroll. 2931 // Cancel preroll.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2957 // Set the append window to [20,280). 3000 // Set the append window to [20,280).
2958 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); 3001 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
2959 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3002 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
2960 3003
2961 // Append a cluster that starts before and ends after the append window. 3004 // Append a cluster that starts before and ends after the append window.
2962 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3005 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
2963 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); 3006 "0K 30 60 90 120K 150 180 210 240K 270 300 330K");
2964 3007
2965 // Verify that GOPs that start outside the window are not included 3008 // Verify that GOPs that start outside the window are not included
2966 // in the buffer. Also verify that buffers that start inside the 3009 // in the buffer. Also verify that buffers that start inside the
2967 // window and extend beyond the end of the window are included. 3010 // window and extend beyond the end of the window are not included.
2968 CheckExpectedRanges(kSourceId, "{ [120,300) }"); 3011 CheckExpectedRanges(kSourceId, "{ [120,270) }");
2969 CheckExpectedBuffers(stream, "120 150 180 210 240 270"); 3012 CheckExpectedBuffers(stream, "120 150 180 210 240");
2970 3013
2971 // Extend the append window to [20,650). 3014 // Extend the append window to [20,650).
2972 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3015 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
2973 3016
2974 // Append more data and verify that adding buffers start at the next 3017 // Append more data and verify that adding buffers start at the next
2975 // keyframe. 3018 // keyframe.
2976 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3019 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
2977 "360 390 420K 450 480 510 540K 570 600 630K"); 3020 "360 390 420K 450 480 510 540K 570 600 630K");
2978 CheckExpectedRanges(kSourceId, "{ [120,300) [420,660) }"); 3021 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }");
2979 } 3022 }
2980 3023
2981 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) { 3024 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) {
2982 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3025 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
2983 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3026 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
2984 3027
2985 // Set the append window to [20,280). 3028 // Set the append window to [20,280).
2986 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); 3029 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
2987 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3030 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
2988 3031
2989 // Append a cluster that starts before and ends after the append window. 3032 // Append a cluster that starts before and ends after the append window.
2990 AppendSingleStreamCluster( 3033 AppendSingleStreamCluster(
2991 kSourceId, kAudioTrackNum, 3034 kSourceId, kAudioTrackNum,
2992 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); 3035 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K");
2993 3036
2994 // Verify that frames that start outside the window are not included 3037 // Verify that frames that start outside the window are not included
2995 // in the buffer. Also verify that buffers that start inside the 3038 // in the buffer. Also verify that buffers that start inside the
2996 // window and extend beyond the end of the window are included. 3039 // window and extend beyond the end of the window are not included.
2997 CheckExpectedRanges(kSourceId, "{ [30,300) }"); 3040 CheckExpectedRanges(kSourceId, "{ [30,270) }");
2998 CheckExpectedBuffers(stream, "30 60 90 120 150 180 210 240 270"); 3041 CheckExpectedBuffers(stream, "30 60 90 120 150 180 210 240");
2999 3042
3000 // Extend the append window to [20,650). 3043 // Extend the append window to [20,650).
3001 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3044 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3002 3045
3003 // Append more data and verify that a new range is created. 3046 // Append more data and verify that a new range is created.
3004 AppendSingleStreamCluster( 3047 AppendSingleStreamCluster(
3005 kSourceId, kAudioTrackNum, 3048 kSourceId, kAudioTrackNum,
3006 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); 3049 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K");
3007 CheckExpectedRanges(kSourceId, "{ [30,300) [360,660) }"); 3050 CheckExpectedRanges(kSourceId, "{ [30,270) [360,630) }");
3008 } 3051 }
3009 3052
3010 TEST_F(ChunkDemuxerTest, AppendWindow_Text) { 3053 TEST_F(ChunkDemuxerTest, AppendWindow_Text) {
3011 DemuxerStream* text_stream = NULL; 3054 DemuxerStream* text_stream = NULL;
3012 EXPECT_CALL(host_, AddTextStream(_, _)) 3055 EXPECT_CALL(host_, AddTextStream(_, _))
3013 .WillOnce(SaveArg<0>(&text_stream)); 3056 .WillOnce(SaveArg<0>(&text_stream));
3014 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); 3057 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT));
3015 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3058 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3016 3059
3017 // Set the append window to [20,280). 3060 // Set the append window to [20,280).
3018 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); 3061 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
3019 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3062 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3020 3063
3021 // Append a cluster that starts before and ends after the append 3064 // Append a cluster that starts before and ends after the append
3022 // window. 3065 // window.
3023 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3066 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3024 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); 3067 "0K 30 60 90 120K 150 180 210 240K 270 300 330K");
3025 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K 200K 300K"); 3068 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K 200K 300K");
3026 3069
3027 // Verify that text cues that start outside the window are not included 3070 // Verify that text cues that start outside the window are not included
3028 // in the buffer. Also verify that cues that extend beyond the 3071 // in the buffer. Also verify that cues that extend beyond the
3029 // window are included. 3072 // window are not included.
3030 CheckExpectedRanges(kSourceId, "{ [120,300) }"); 3073 CheckExpectedRanges(kSourceId, "{ [120,270) }");
3031 CheckExpectedBuffers(video_stream, "120 150 180 210 240 270"); 3074 CheckExpectedBuffers(video_stream, "120 150 180 210 240");
3032 CheckExpectedBuffers(text_stream, "100 200"); 3075 CheckExpectedBuffers(text_stream, "100");
3033 3076
3034 // Extend the append window to [20,650). 3077 // Extend the append window to [20,650).
3035 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3078 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3036 3079
3037 // Append more data and verify that a new range is created. 3080 // Append more data and verify that a new range is created.
3038 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3081 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3039 "360 390 420K 450 480 510 540K 570 600 630K"); 3082 "360 390 420K 450 480 510 540K 570 600 630K");
3040 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "400K 500K 600K 700K"); 3083 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "400K 500K 600K 700K");
3041 CheckExpectedRanges(kSourceId, "{ [120,300) [420,660) }"); 3084 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }");
3042 3085
3043 // Seek to the new range and verify that the expected buffers are returned. 3086 // Seek to the new range and verify that the expected buffers are returned.
3044 Seek(base::TimeDelta::FromMilliseconds(420)); 3087 Seek(base::TimeDelta::FromMilliseconds(420));
3045 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600 630"); 3088 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600");
3046 CheckExpectedBuffers(text_stream, "400 500 600"); 3089 CheckExpectedBuffers(text_stream, "400 500");
3047 } 3090 }
3048 3091
3049 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) { 3092 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) {
3050 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3093 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3051 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 3094 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
3052 AppendGarbage(); 3095 AppendGarbage();
3053 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50); 3096 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50);
3054 demuxer_->StartWaitingForSeek(seek_time); 3097 demuxer_->StartWaitingForSeek(seek_time);
3055 } 3098 }
3056 3099
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3117 3160
3118 bool text_read_done = false; 3161 bool text_read_done = false;
3119 text_stream->Read(base::Bind(&OnReadDone, 3162 text_stream->Read(base::Bind(&OnReadDone,
3120 base::TimeDelta::FromMilliseconds(125), 3163 base::TimeDelta::FromMilliseconds(125),
3121 &text_read_done)); 3164 &text_read_done));
3122 3165
3123 // Append audio & video data so the seek completes. 3166 // Append audio & video data so the seek completes.
3124 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3167 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
3125 "0K 20K 40K 60K 80K 100K 120K 140K 160K 180K"); 3168 "0K 20K 40K 60K 80K 100K 120K 140K 160K 180K");
3126 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3169 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3127 "0K 30 60 90 120K 150 180 210"); 3170 "0K 30 60 90K 120K 150 180 210");
acolwell GONE FROM CHROMIUM 2014/03/28 21:01:34 Why did this become a keyframe?
wolenetz 2014/03/28 22:17:43 Thanks for catching that. It slipped through the r
3128 3171
3129 message_loop_.RunUntilIdle(); 3172 message_loop_.RunUntilIdle();
3130 EXPECT_TRUE(seek_cb_was_called); 3173 EXPECT_TRUE(seek_cb_was_called);
3131 EXPECT_FALSE(text_read_done); 3174 EXPECT_FALSE(text_read_done);
3132 3175
3133 // Read some audio & video buffers to further verify seek completion. 3176 // Read some audio & video buffers to further verify seek completion.
3134 CheckExpectedBuffers(audio_stream, "120 140"); 3177 CheckExpectedBuffers(audio_stream, "120 140");
3135 CheckExpectedBuffers(video_stream, "120 150"); 3178 CheckExpectedBuffers(video_stream, "120 150");
3136 3179
3137 EXPECT_FALSE(text_read_done); 3180 EXPECT_FALSE(text_read_done);
3138 3181
3139 // Append text cues that start after the seek point and verify that 3182 // Append text cues that start after the seek point and verify that
3140 // they are returned by Read() calls. 3183 // they are returned by Read() calls.
3141 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "125K 175K 225K"); 3184 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "125K 175K 225K");
3142 3185
3143 message_loop_.RunUntilIdle(); 3186 message_loop_.RunUntilIdle();
3144 EXPECT_TRUE(text_read_done); 3187 EXPECT_TRUE(text_read_done);
3145 3188
3146 // NOTE: we start at 175 here because the buffer at 125 was returned 3189 // NOTE: we start at 175 here because the buffer at 125 was returned
3147 // to the pending read initiated above. 3190 // to the pending read initiated above.
3148 CheckExpectedBuffers(text_stream, "175 225"); 3191 CheckExpectedBuffers(text_stream, "175 225");
3149 3192
3150 // Verify that audio & video streams contiue to return expected values. 3193 // Verify that audio & video streams continue to return expected values.
3151 CheckExpectedBuffers(audio_stream, "160 180"); 3194 CheckExpectedBuffers(audio_stream, "160 180");
3152 CheckExpectedBuffers(video_stream, "180 210"); 3195 CheckExpectedBuffers(video_stream, "180 210");
3153 } 3196 }
3154 3197
3155 } // namespace media 3198 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/chunk_demuxer.cc ('k') | media/filters/legacy_frame_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698