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

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

Issue 1564983003: MSE: Log a warning if muxed AV media segment has no A or has no V block (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed previous CR comments Created 4 years, 11 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
« no previous file with comments | « media/base/stream_parser.h ('k') | media/filters/media_source_state.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 "media/filters/chunk_demuxer.h" 5 #include "media/filters/chunk_demuxer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 112 }
113 } 113 }
114 114
115 MATCHER_P(HasTimestamp, timestamp_in_ms, "") { 115 MATCHER_P(HasTimestamp, timestamp_in_ms, "") {
116 return arg.get() && !arg->end_of_stream() && 116 return arg.get() && !arg->end_of_stream() &&
117 arg->timestamp().InMilliseconds() == timestamp_in_ms; 117 arg->timestamp().InMilliseconds() == timestamp_in_ms;
118 } 118 }
119 119
120 MATCHER(IsEndOfStream, "") { return arg.get() && arg->end_of_stream(); } 120 MATCHER(IsEndOfStream, "") { return arg.get() && arg->end_of_stream(); }
121 121
122 MATCHER_P(SegmentMissingFrames, frame_types_string, "") {
123 return CONTAINS_STRING(arg, "Media segment did not contain any " +
124 std::string(frame_types_string) +
125 " coded frames, mismatching initialization "
126 "segment. Therefore, MSE coded frame "
127 "processing may not interoperably detect "
128 "discontinuities in appended media.");
129 }
130
122 MATCHER(StreamParsingFailed, "") { 131 MATCHER(StreamParsingFailed, "") {
123 return CONTAINS_STRING(arg, "Append: stream parsing failed."); 132 return CONTAINS_STRING(arg, "Append: stream parsing failed.");
124 } 133 }
125 134
126 MATCHER_P(FoundStream, stream_type_string, "") { 135 MATCHER_P(FoundStream, stream_type_string, "") {
127 return CONTAINS_STRING( 136 return CONTAINS_STRING(
128 arg, "found_" + std::string(stream_type_string) + "_stream") && 137 arg, "found_" + std::string(stream_type_string) + "_stream") &&
129 CONTAINS_STRING(arg, "true"); 138 CONTAINS_STRING(arg, "true");
130 } 139 }
131 140
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 for (int i = 0; i < garbage_cluster_size; ++i) 762 for (int i = 0; i < garbage_cluster_size; ++i)
754 garbage_cluster[i] = i; 763 garbage_cluster[i] = i;
755 AppendData(garbage_cluster.get(), garbage_cluster_size); 764 AppendData(garbage_cluster.get(), garbage_cluster_size);
756 } 765 }
757 766
758 void InitDoneCalled(PipelineStatus expected_status, 767 void InitDoneCalled(PipelineStatus expected_status,
759 PipelineStatus status) { 768 PipelineStatus status) {
760 EXPECT_EQ(status, expected_status); 769 EXPECT_EQ(status, expected_status);
761 } 770 }
762 771
763 void AppendEmptyCluster(int timecode) {
764 AppendCluster(GenerateEmptyCluster(timecode));
765 }
766
767 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration, 772 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration,
768 PipelineStatus expected_status) { 773 PipelineStatus expected_status) {
769 if (expected_duration != kNoTimestamp()) 774 if (expected_duration != kNoTimestamp())
770 EXPECT_CALL(host_, SetDuration(expected_duration)); 775 EXPECT_CALL(host_, SetDuration(expected_duration));
771 return CreateInitDoneCB(expected_status); 776 return CreateInitDoneCB(expected_status);
772 } 777 }
773 778
774 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) { 779 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) {
775 return base::Bind(&ChunkDemuxerTest::InitDoneCalled, 780 return base::Bind(&ChunkDemuxerTest::InitDoneCalled,
776 base::Unretained(this), 781 base::Unretained(this),
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 // Append the whole bear1 file. 930 // Append the whole bear1 file.
926 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)).Times(7); 931 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)).Times(7);
927 // Expect duration adjustment since actual duration differs slightly from 932 // Expect duration adjustment since actual duration differs slightly from
928 // duration in the init segment. 933 // duration in the init segment.
929 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746))); 934 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746)));
930 AppendData(bear1->data(), bear1->data_size()); 935 AppendData(bear1->data(), bear1->data_size());
931 // Last audio frame has timestamp 2721 and duration 24 (estimated from max 936 // Last audio frame has timestamp 2721 and duration 24 (estimated from max
932 // seen so far for audio track). 937 // seen so far for audio track).
933 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry 938 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry
934 // DefaultDuration for video track). 939 // DefaultDuration for video track).
935 CheckExpectedRanges(kSourceId, "{ [0,2736) }"); 940 CheckExpectedRanges("{ [0,2736) }");
936 941
937 // Append initialization segment for bear2. 942 // Append initialization segment for bear2.
938 // Note: Offsets here and below are derived from 943 // Note: Offsets here and below are derived from
939 // media/test/data/bear-640x360-manifest.js and 944 // media/test/data/bear-640x360-manifest.js and
940 // media/test/data/bear-320x240-manifest.js which were 945 // media/test/data/bear-320x240-manifest.js which were
941 // generated from media/test/data/bear-640x360.webm and 946 // generated from media/test/data/bear-640x360.webm and
942 // media/test/data/bear-320x240.webm respectively. 947 // media/test/data/bear-320x240.webm respectively.
943 EXPECT_CALL(*this, InitSegmentReceived()); 948 EXPECT_CALL(*this, InitSegmentReceived());
944 AppendData(bear2->data(), 4340); 949 AppendData(bear2->data(), 4340);
945 950
946 // Append a media segment that goes from [0.527000, 1.014000). 951 // Append a media segment that goes from [0.527000, 1.014000).
947 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)); 952 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2));
948 EXPECT_MEDIA_LOG(GeneratedSplice(20000, 527000)); 953 EXPECT_MEDIA_LOG(GeneratedSplice(20000, 527000));
949 AppendData(bear2->data() + 55290, 18785); 954 AppendData(bear2->data() + 55290, 18785);
950 CheckExpectedRanges(kSourceId, "{ [0,1027) [1201,2736) }"); 955 CheckExpectedRanges("{ [0,1027) [1201,2736) }");
951 956
952 // Append initialization segment for bear1 & fill gap with [779-1197) 957 // Append initialization segment for bear1 & fill gap with [779-1197)
953 // segment. 958 // segment.
954 EXPECT_CALL(*this, InitSegmentReceived()); 959 EXPECT_CALL(*this, InitSegmentReceived());
955 AppendData(bear1->data(), 4370); 960 AppendData(bear1->data(), 4370);
956 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23)); 961 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23));
957 EXPECT_MEDIA_LOG(GeneratedSplice(26000, 779000)); 962 EXPECT_MEDIA_LOG(GeneratedSplice(26000, 779000));
958 AppendData(bear1->data() + 72737, 28183); 963 AppendData(bear1->data() + 72737, 28183);
959 CheckExpectedRanges(kSourceId, "{ [0,2736) }"); 964 CheckExpectedRanges("{ [0,2736) }");
960 965
961 MarkEndOfStream(PIPELINE_OK); 966 MarkEndOfStream(PIPELINE_OK);
962 return true; 967 return true;
963 } 968 }
964 969
965 void ShutdownDemuxer() { 970 void ShutdownDemuxer() {
966 if (demuxer_) { 971 if (demuxer_) {
967 demuxer_->Shutdown(); 972 demuxer_->Shutdown();
968 message_loop_.RunUntilIdle(); 973 message_loop_.RunUntilIdle();
969 } 974 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 GenerateSingleStreamExpectedReads( 1148 GenerateSingleStreamExpectedReads(
1144 timecode, block_count, DemuxerStream::VIDEO, kVideoBlockDuration); 1149 timecode, block_count, DemuxerStream::VIDEO, kVideoBlockDuration);
1145 } 1150 }
1146 1151
1147 scoped_ptr<Cluster> GenerateEmptyCluster(int timecode) { 1152 scoped_ptr<Cluster> GenerateEmptyCluster(int timecode) {
1148 ClusterBuilder cb; 1153 ClusterBuilder cb;
1149 cb.SetClusterTimecode(timecode); 1154 cb.SetClusterTimecode(timecode);
1150 return cb.Finish(); 1155 return cb.Finish();
1151 } 1156 }
1152 1157
1158 void CheckExpectedRangesForMediaSource(const std::string& expected) {
1159 CheckExpectedRanges(demuxer_->GetBufferedRanges(), expected);
1160 }
1161
1153 void CheckExpectedRanges(const std::string& expected) { 1162 void CheckExpectedRanges(const std::string& expected) {
1154 CheckExpectedRanges(kSourceId, expected); 1163 CheckExpectedRanges(kSourceId, expected);
1164 CheckExpectedRangesForMediaSource(expected);
1155 } 1165 }
1156 1166
1157 void CheckExpectedRanges(const std::string& id, 1167 void CheckExpectedRanges(const std::string& id, const std::string& expected) {
1158 const std::string& expected) {
1159 CheckExpectedRanges(demuxer_->GetBufferedRanges(id), expected); 1168 CheckExpectedRanges(demuxer_->GetBufferedRanges(id), expected);
1160 } 1169 }
1161 1170
1162 void CheckExpectedRanges(DemuxerStream::Type type, 1171 void CheckExpectedRanges(DemuxerStream::Type type,
1163 const std::string& expected) { 1172 const std::string& expected) {
1164 ChunkDemuxerStream* stream = 1173 ChunkDemuxerStream* stream =
1165 static_cast<ChunkDemuxerStream*>(demuxer_->GetStream(type)); 1174 static_cast<ChunkDemuxerStream*>(demuxer_->GetStream(type));
1166 CheckExpectedRanges(stream->GetBufferedRanges(kDefaultDuration()), 1175 CheckExpectedRanges(stream->GetBufferedRanges(kDefaultDuration()),
1167 expected); 1176 expected);
1168 } 1177 }
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 append_window_end_for_next_append_, 1549 append_window_end_for_next_append_,
1541 &timestamp_offset_map_[kSourceId], 1550 &timestamp_offset_map_[kSourceId],
1542 init_segment_received_cb_); 1551 init_segment_received_cb_);
1543 1552
1544 AppendMuxedCluster( 1553 AppendMuxedCluster(
1545 MuxedStreamInfo(kAudioTrackNum, "46K 69K", 23), 1554 MuxedStreamInfo(kAudioTrackNum, "46K 69K", 23),
1546 MuxedStreamInfo(kVideoTrackNum, "60K", 1555 MuxedStreamInfo(kVideoTrackNum, "60K",
1547 WebMClusterParser::kDefaultVideoBufferDurationInMs), 1556 WebMClusterParser::kDefaultVideoBufferDurationInMs),
1548 MuxedStreamInfo(kAlternateTextTrackNum, "45K")); 1557 MuxedStreamInfo(kAlternateTextTrackNum, "45K"));
1549 1558
1550 CheckExpectedRanges(kSourceId, "{ [0,92) }"); 1559 CheckExpectedRanges("{ [0,92) }");
1551 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K"); 1560 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K");
1552 CheckExpectedBuffers(video_stream, "0K 30 60K"); 1561 CheckExpectedBuffers(video_stream, "0K 30 60K");
1553 CheckExpectedBuffers(text_stream, "10K 45K"); 1562 CheckExpectedBuffers(text_stream, "10K 45K");
1554 1563
1555 ShutdownDemuxer(); 1564 ShutdownDemuxer();
1556 } 1565 }
1557 1566
1558 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) { 1567 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) {
1559 // Tests that non-key-frames following an init segment are allowed 1568 // Tests that non-key-frames following an init segment are allowed
1560 // and dropped, as expected if the initialization segment received 1569 // and dropped, as expected if the initialization segment received
1561 // algorithm correctly sets the needs random access point flag to true for all 1570 // algorithm correctly sets the needs random access point flag to true for all
1562 // track buffers. Note that the first initialization segment is insufficient 1571 // track buffers. Note that the first initialization segment is insufficient
1563 // to fully test this since needs random access point flag initializes to 1572 // to fully test this since needs random access point flag initializes to
1564 // true. 1573 // true.
1565 CreateNewDemuxer(); 1574 CreateNewDemuxer();
1566 DemuxerStream* text_stream = NULL; 1575 DemuxerStream* text_stream = NULL;
1567 EXPECT_CALL(host_, AddTextStream(_, _)) 1576 EXPECT_CALL(host_, AddTextStream(_, _))
1568 .WillOnce(SaveArg<0>(&text_stream)); 1577 .WillOnce(SaveArg<0>(&text_stream));
1569 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( 1578 ASSERT_TRUE(InitDemuxerWithEncryptionInfo(
1570 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); 1579 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false));
1571 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 1580 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
1572 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 1581 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
1573 ASSERT_TRUE(audio_stream && video_stream && text_stream); 1582 ASSERT_TRUE(audio_stream && video_stream && text_stream);
1574 1583
1575 AppendMuxedCluster( 1584 AppendMuxedCluster(
1576 MuxedStreamInfo(kAudioTrackNum, "23K", 1585 MuxedStreamInfo(kAudioTrackNum, "23K",
1577 WebMClusterParser::kDefaultAudioBufferDurationInMs), 1586 WebMClusterParser::kDefaultAudioBufferDurationInMs),
1578 MuxedStreamInfo(kVideoTrackNum, "0 30K", 30), 1587 MuxedStreamInfo(kVideoTrackNum, "0 30K", 30),
1579 MuxedStreamInfo(kTextTrackNum, "25K 40K")); 1588 MuxedStreamInfo(kTextTrackNum, "25K 40K"));
1580 CheckExpectedRanges(kSourceId, "{ [23,46) }"); 1589 CheckExpectedRanges("{ [23,46) }");
1581 1590
1582 EXPECT_CALL(*this, InitSegmentReceived()); 1591 EXPECT_CALL(*this, InitSegmentReceived());
1583 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); 1592 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO);
1584 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "46K 69K", 23), 1593 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "46K 69K", 23),
1585 MuxedStreamInfo(kVideoTrackNum, "60 90K", 30), 1594 MuxedStreamInfo(kVideoTrackNum, "60 90K", 30),
1586 MuxedStreamInfo(kTextTrackNum, "80K 90K")); 1595 MuxedStreamInfo(kTextTrackNum, "80K 90K"));
1587 CheckExpectedRanges("{ [23,92) }"); 1596 CheckExpectedRanges("{ [23,92) }");
1588 1597
1589 CheckExpectedBuffers(audio_stream, "23K 46K 69K"); 1598 CheckExpectedBuffers(audio_stream, "23K 46K 69K");
1590 CheckExpectedBuffers(video_stream, "30K 90K"); 1599 CheckExpectedBuffers(video_stream, "30K 90K");
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 2088
2080 EXPECT_CALL(host_, AddTextStream(_, _)) 2089 EXPECT_CALL(host_, AddTextStream(_, _))
2081 .WillOnce(SaveArg<0>(&text_stream)); 2090 .WillOnce(SaveArg<0>(&text_stream));
2082 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 2091 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
2083 2092
2084 AppendMuxedCluster(MuxedStreamInfo(kVideoTrackNum, "0K 33", 33), 2093 AppendMuxedCluster(MuxedStreamInfo(kVideoTrackNum, "0K 33", 33),
2085 MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23)); 2094 MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23));
2086 2095
2087 // Check expected ranges and verify that an empty text track does not 2096 // Check expected ranges and verify that an empty text track does not
2088 // affect the expected ranges. 2097 // affect the expected ranges.
2089 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 2098 CheckExpectedRanges("{ [0,46) }");
2090 2099
2091 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66))); 2100 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66)));
2092 MarkEndOfStream(PIPELINE_OK); 2101 MarkEndOfStream(PIPELINE_OK);
2093 2102
2094 // Check expected ranges and verify that an empty text track does not 2103 // Check expected ranges and verify that an empty text track does not
2095 // affect the expected ranges. 2104 // affect the expected ranges.
2096 CheckExpectedRanges(kSourceId, "{ [0,66) }"); 2105 CheckExpectedRanges("{ [0,66) }");
2097 2106
2098 // Unmark end of stream state and verify that the ranges return to 2107 // Unmark end of stream state and verify that the ranges return to
2099 // their pre-"end of stream" values. 2108 // their pre-"end of stream" values.
2100 demuxer_->UnmarkEndOfStream(); 2109 demuxer_->UnmarkEndOfStream();
2101 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 2110 CheckExpectedRanges("{ [0,46) }");
2102 2111
2103 // Add text track data and verify that the buffered ranges don't change 2112 // Add text track data and verify that the buffered ranges don't change
2104 // since the intersection of all the tracks doesn't change. 2113 // since the intersection of all the tracks doesn't change.
2105 EXPECT_MEDIA_LOG(SkippingSpliceAtOrBefore(0, 0)); 2114 EXPECT_MEDIA_LOG(SkippingSpliceAtOrBefore(0, 0));
2106 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(200))); 2115 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(200)));
2107 AppendMuxedCluster(MuxedStreamInfo(kVideoTrackNum, "0K 33", 33), 2116 AppendMuxedCluster(MuxedStreamInfo(kVideoTrackNum, "0K 33", 33),
2108 MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), 2117 MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23),
2109 MuxedStreamInfo(kTextTrackNum, "0K 100K")); 2118 MuxedStreamInfo(kTextTrackNum, "0K 100K"));
2110 CheckExpectedRanges("{ [0,46) }"); 2119 CheckExpectedRanges("{ [0,46) }");
2111 2120
2112 // Mark end of stream and verify that text track data is reflected in 2121 // Mark end of stream and verify that text track data is reflected in
2113 // the new range. 2122 // the new range.
2114 MarkEndOfStream(PIPELINE_OK); 2123 MarkEndOfStream(PIPELINE_OK);
2115 CheckExpectedRanges(kSourceId, "{ [0,200) }"); 2124 CheckExpectedRanges("{ [0,200) }");
2116 } 2125 }
2117 2126
2118 // Make sure AppendData() will accept elements that span multiple calls. 2127 // Make sure AppendData() will accept elements that span multiple calls.
2119 TEST_F(ChunkDemuxerTest, AppendingInPieces) { 2128 TEST_F(ChunkDemuxerTest, AppendingInPieces) {
2120 EXPECT_CALL(*this, DemuxerOpened()); 2129 EXPECT_CALL(*this, DemuxerOpened());
2121 demuxer_->Initialize( 2130 demuxer_->Initialize(
2122 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 2131 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
2123 2132
2124 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); 2133 ASSERT_EQ(AddId(), ChunkDemuxer::kOk);
2125 2134
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2251 2260
2252 ExpectInitMediaLogs(HAS_AUDIO | HAS_VIDEO); 2261 ExpectInitMediaLogs(HAS_AUDIO | HAS_VIDEO);
2253 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)); 2262 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2));
2254 ASSERT_TRUE(ParseWebMFile("bear-320x240-altref.webm", buffer_timestamps, 2263 ASSERT_TRUE(ParseWebMFile("bear-320x240-altref.webm", buffer_timestamps,
2255 base::TimeDelta::FromMilliseconds(2767))); 2264 base::TimeDelta::FromMilliseconds(2767)));
2256 } 2265 }
2257 2266
2258 // Verify that we output buffers before the entire cluster has been parsed. 2267 // Verify that we output buffers before the entire cluster has been parsed.
2259 TEST_F(ChunkDemuxerTest, IncrementalClusterParsing) { 2268 TEST_F(ChunkDemuxerTest, IncrementalClusterParsing) {
2260 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2269 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2261 AppendEmptyCluster(0);
2262 2270
2263 scoped_ptr<Cluster> cluster(GenerateCluster(0, 6)); 2271 scoped_ptr<Cluster> cluster(GenerateCluster(0, 6));
2264 2272
2265 bool audio_read_done = false; 2273 bool audio_read_done = false;
2266 bool video_read_done = false; 2274 bool video_read_done = false;
2267 ReadAudio(base::Bind(&OnReadDone, 2275 ReadAudio(base::Bind(&OnReadDone,
2268 base::TimeDelta::FromMilliseconds(0), 2276 base::TimeDelta::FromMilliseconds(0),
2269 &audio_read_done)); 2277 &audio_read_done));
2270 ReadVideo(base::Bind(&OnReadDone, 2278 ReadVideo(base::Bind(&OnReadDone,
2271 base::TimeDelta::FromMilliseconds(0), 2279 base::TimeDelta::FromMilliseconds(0),
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 demuxer_->StartWaitingForSeek(seek_time); 2642 demuxer_->StartWaitingForSeek(seek_time);
2635 demuxer_->Seek(seek_time, 2643 demuxer_->Seek(seek_time,
2636 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); 2644 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called));
2637 message_loop_.RunUntilIdle(); 2645 message_loop_.RunUntilIdle();
2638 2646
2639 EXPECT_FALSE(seek_cb_was_called); 2647 EXPECT_FALSE(seek_cb_was_called);
2640 2648
2641 EXPECT_CALL(host_, SetDuration( 2649 EXPECT_CALL(host_, SetDuration(
2642 base::TimeDelta::FromMilliseconds(120))); 2650 base::TimeDelta::FromMilliseconds(120)));
2643 MarkEndOfStream(PIPELINE_OK); 2651 MarkEndOfStream(PIPELINE_OK);
2652 CheckExpectedRanges("{ [0,120) }");
2644 message_loop_.RunUntilIdle(); 2653 message_loop_.RunUntilIdle();
2645 2654
2646 EXPECT_TRUE(seek_cb_was_called); 2655 EXPECT_TRUE(seek_cb_was_called);
2647 2656
2648 ShutdownDemuxer(); 2657 ShutdownDemuxer();
2649 } 2658 }
2650 2659
2651 // Test that EndOfStream is ignored if coming during a pending seek 2660 // Test that EndOfStream is ignored if coming during a pending seek
2652 // whose seek time is before some existing ranges. 2661 // whose seek time is before some existing ranges.
2653 TEST_F(ChunkDemuxerTest, EndOfStreamDuringPendingSeek) { 2662 TEST_F(ChunkDemuxerTest, EndOfStreamDuringPendingSeek) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2732 2741
2733 CheckExpectedRanges("{ [0,132) }"); 2742 CheckExpectedRanges("{ [0,132) }");
2734 2743
2735 // Append a disjoint cluster to check for two separate ranges. 2744 // Append a disjoint cluster to check for two separate ranges.
2736 AppendCluster(GenerateSingleStreamCluster( 2745 AppendCluster(GenerateSingleStreamCluster(
2737 200, 299, kVideoTrackNum, kVideoBlockDuration)); 2746 200, 299, kVideoTrackNum, kVideoBlockDuration));
2738 2747
2739 CheckExpectedRanges("{ [0,132) [200,299) }"); 2748 CheckExpectedRanges("{ [0,132) [200,299) }");
2740 } 2749 }
2741 2750
2751 TEST_F(ChunkDemuxerTest, GetBufferedRanges_SeparateStreams) {
2752 std::string audio_id = "audio1";
2753 std::string video_id = "video1";
2754 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
2755
2756 // Append audio and video data into separate source ids.
2757
2758 // Audio block: 0 -> 23
2759 // Video block: 0 -> 33
2760 // Buffered Range: 0 -> 23
2761 // Audio block duration is smaller than video block duration,
2762 // so the buffered ranges should correspond to the audio blocks.
2763 AppendCluster(audio_id,
2764 GenerateSingleStreamCluster(0, 23, kAudioTrackNum, 23));
2765 AppendCluster(video_id,
2766 GenerateSingleStreamCluster(0, 33, kVideoTrackNum, 33));
2767 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [0,23) }");
2768 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,33) }");
2769 CheckExpectedRangesForMediaSource("{ [0,23) }");
2770
2771 // Audio blocks: 300 -> 400
2772 // Video blocks: 320 -> 420
2773 // Buffered Range: 320 -> 400 (jagged start and end across SourceBuffers)
2774 AppendCluster(audio_id,
2775 GenerateSingleStreamCluster(300, 400, kAudioTrackNum, 50));
2776 AppendCluster(video_id,
2777 GenerateSingleStreamCluster(320, 420, kVideoTrackNum, 50));
2778 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [0,23) [300,400) }");
2779 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,33) [320,420) }");
2780 CheckExpectedRangesForMediaSource("{ [0,23) [320,400) }");
2781
2782 // Audio block: 520 -> 590
2783 // Video block: 500 -> 570
2784 // Buffered Range: 520 -> 570 (jagged start and end across SourceBuffers)
2785 AppendCluster(audio_id,
2786 GenerateSingleStreamCluster(520, 590, kAudioTrackNum, 70));
2787 AppendCluster(video_id,
2788 GenerateSingleStreamCluster(500, 570, kVideoTrackNum, 70));
2789 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [0,23) [300,400) [520,590) }");
2790 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,33) [320,420) [500,570) }");
2791 CheckExpectedRangesForMediaSource("{ [0,23) [320,400) [520,570) }");
2792
2793 // Audio block: 720 -> 750
2794 // Video block: 700 -> 770
2795 // Buffered Range: 720 -> 750 (complete overlap of audio)
2796 AppendCluster(audio_id,
2797 GenerateSingleStreamCluster(720, 750, kAudioTrackNum, 30));
2798 AppendCluster(video_id,
2799 GenerateSingleStreamCluster(700, 770, kVideoTrackNum, 70));
2800 CheckExpectedRanges(DemuxerStream::AUDIO,
2801 "{ [0,23) [300,400) [520,590) [720,750) }");
2802 CheckExpectedRanges(DemuxerStream::VIDEO,
2803 "{ [0,33) [320,420) [500,570) [700,770) }");
2804 CheckExpectedRangesForMediaSource("{ [0,23) [320,400) [520,570) [720,750) }");
2805
2806 // Audio block: 900 -> 970
2807 // Video block: 920 -> 950
2808 // Buffered Range: 920 -> 950 (complete overlap of video)
2809 AppendCluster(audio_id,
2810 GenerateSingleStreamCluster(900, 970, kAudioTrackNum, 70));
2811 AppendCluster(video_id,
2812 GenerateSingleStreamCluster(920, 950, kVideoTrackNum, 30));
2813 CheckExpectedRanges(DemuxerStream::AUDIO,
2814 "{ [0,23) [300,400) [520,590) [720,750) [900,970) }");
2815 CheckExpectedRanges(DemuxerStream::VIDEO,
2816 "{ [0,33) [320,420) [500,570) [700,770) [920,950) }");
2817 CheckExpectedRangesForMediaSource(
2818 "{ [0,23) [320,400) [520,570) [720,750) [920,950) }");
2819
2820 // Appending within buffered range should not affect buffered ranges.
2821 EXPECT_MEDIA_LOG(GeneratedSplice(40000, 930000));
2822 AppendCluster(audio_id,
2823 GenerateSingleStreamCluster(930, 950, kAudioTrackNum, 20));
2824 AppendCluster(video_id,
2825 GenerateSingleStreamCluster(930, 950, kVideoTrackNum, 20));
2826 CheckExpectedRanges(DemuxerStream::AUDIO,
2827 "{ [0,23) [300,400) [520,590) [720,750) [900,970) }");
2828 CheckExpectedRanges(DemuxerStream::VIDEO,
2829 "{ [0,33) [320,420) [500,570) [700,770) [920,950) }");
2830 CheckExpectedRangesForMediaSource(
2831 "{ [0,23) [320,400) [520,570) [720,750) [920,950) }");
2832 }
2833
2742 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideo) { 2834 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideo) {
2743 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2835 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2744 2836
2745 // Audio: 0 -> 23 2837 // Audio block: 0 -> 23
2746 // Video: 0 -> 33 2838 // Video block: 0 -> 33
2747 // Buffered Range: 0 -> 23 2839 // Buffered Range: 0 -> 23
2748 // Audio block duration is smaller than video block duration, 2840 // Audio block duration is smaller than video block duration,
2749 // so the buffered ranges should correspond to the audio blocks. 2841 // so the buffered ranges should correspond to the audio blocks.
2750 AppendCluster(GenerateSingleStreamCluster( 2842 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0D23K"),
2751 0, kAudioBlockDuration, kAudioTrackNum, kAudioBlockDuration)); 2843 MuxedStreamInfo(kVideoTrackNum, "0D33K"));
2752 AppendCluster(GenerateSingleStreamCluster(
2753 0, kVideoBlockDuration, kVideoTrackNum, kVideoBlockDuration));
2754 2844
2845 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [0,23) }");
2846 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,33) }");
2755 CheckExpectedRanges("{ [0,23) }"); 2847 CheckExpectedRanges("{ [0,23) }");
2756 2848
2757 // Audio: 300 -> 400 2849 // Audio blocks: 300 -> 400
2758 // Video: 320 -> 420 2850 // Video blocks: 320 -> 420
2759 // Buffered Range: 320 -> 400 (end overlap) 2851 // Naive Buffered Range: 320 -> 400 (end overlap) **
2760 AppendCluster(GenerateSingleStreamCluster(300, 400, kAudioTrackNum, 50)); 2852 // **Except these are in the same cluster, with same segment start time of
2761 AppendCluster(GenerateSingleStreamCluster(320, 420, kVideoTrackNum, 50)); 2853 // 300, so the added buffered range is 300 -> 400 (still with end overlap)
2854 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "300K 350D50K"),
2855 MuxedStreamInfo(kVideoTrackNum, "320K 370D50K"));
2762 2856
2763 CheckExpectedRanges("{ [0,23) [320,400) }"); 2857 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [0,23) [300,400) }");
2858 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,33) [300,420) }");
2859 CheckExpectedRanges("{ [0,23) [300,400) }");
2764 2860
2765 // Audio: 520 -> 590 2861 // Audio block: 520 -> 590
2766 // Video: 500 -> 570 2862 // Video block: 500 -> 570
2767 // Buffered Range: 520 -> 570 (front overlap) 2863 // Naive Buffered Range: 520 -> 570 (front overlap) **
2768 AppendCluster(GenerateSingleStreamCluster(520, 590, kAudioTrackNum, 70)); 2864 // **Except these are in the same cluster, with same segment start time of
2769 AppendCluster(GenerateSingleStreamCluster(500, 570, kVideoTrackNum, 70)); 2865 // 500, so the added buffered range is 500 -> 570
2866 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "520D70K"),
2867 MuxedStreamInfo(kVideoTrackNum, "500D70K"));
2770 2868
2771 CheckExpectedRanges("{ [0,23) [320,400) [520,570) }"); 2869 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [0,23) [300,400) [500,590) }");
2870 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,33) [300,420) [500,570) }");
2871 CheckExpectedRanges("{ [0,23) [300,400) [500,570) }");
2772 2872
2773 // Audio: 720 -> 750 2873 // Audio block: 720 -> 750
2774 // Video: 700 -> 770 2874 // Video block: 700 -> 770
2775 // Buffered Range: 720 -> 750 (complete overlap, audio) 2875 // Naive Buffered Range: 720 -> 750 (complete overlap, audio) **
2776 AppendCluster(GenerateSingleStreamCluster(720, 750, kAudioTrackNum, 30)); 2876 // **Except these are in the same cluster, with same segment start time of
2777 AppendCluster(GenerateSingleStreamCluster(700, 770, kVideoTrackNum, 70)); 2877 // 700, so the added buffered range is 700 -> 750
2878 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "720D30K"),
2879 MuxedStreamInfo(kVideoTrackNum, "700D70K"));
2778 2880
2779 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) }"); 2881 CheckExpectedRanges(DemuxerStream::AUDIO,
2882 "{ [0,23) [300,400) [500,590) [700,750) }");
2883 CheckExpectedRanges(DemuxerStream::VIDEO,
2884 "{ [0,33) [300,420) [500,570) [700,770) }");
2885 CheckExpectedRanges("{ [0,23) [300,400) [500,570) [700,750) }");
2780 2886
2781 // Audio: 900 -> 970 2887 // Audio block: 900 -> 970
2782 // Video: 920 -> 950 2888 // Video block: 920 -> 950
2783 // Buffered Range: 920 -> 950 (complete overlap, video) 2889 // Naive Buffered Range: 920 -> 950 (complete overlap, video) **
2784 AppendCluster(GenerateSingleStreamCluster(900, 970, kAudioTrackNum, 70)); 2890 // **Except these are in the same cluster, with same segment start time of
2785 AppendCluster(GenerateSingleStreamCluster(920, 950, kVideoTrackNum, 30)); 2891 // 900, so the added buffered range is 900 -> 950
2892 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "900D70K"),
2893 MuxedStreamInfo(kVideoTrackNum, "920D30K"));
2786 2894
2787 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); 2895 CheckExpectedRanges(DemuxerStream::AUDIO,
2896 "{ [0,23) [300,400) [500,590) [700,750) [900,970) }");
2897 CheckExpectedRanges(DemuxerStream::VIDEO,
2898 "{ [0,33) [300,420) [500,570) [700,770) [900,950) }");
2899 CheckExpectedRanges("{ [0,23) [300,400) [500,570) [700,750) [900,950) }");
2788 2900
2789 // Appending within buffered range should not affect buffered ranges. 2901 // Appending within buffered range should not affect buffered ranges.
2790 EXPECT_MEDIA_LOG(GeneratedSplice(40000, 930000)); 2902 EXPECT_MEDIA_LOG(GeneratedSplice(40000, 930000));
2791 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "930D20K"), 2903 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "930D20K"),
2792 MuxedStreamInfo(kVideoTrackNum, "930D20K")); 2904 MuxedStreamInfo(kVideoTrackNum, "930D20K"));
2793 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); 2905 CheckExpectedRanges(DemuxerStream::AUDIO,
2794 2906 "{ [0,23) [300,400) [500,590) [700,750) [900,970) }");
2795 // Appending to single stream outside buffered ranges should not affect 2907 CheckExpectedRanges(DemuxerStream::VIDEO,
2796 // buffered ranges. 2908 "{ [0,33) [300,420) [500,570) [700,770) [900,950) }");
2797 AppendCluster(GenerateSingleStreamCluster(1230, 1240, kVideoTrackNum, 10)); 2909 CheckExpectedRanges("{ [0,23) [300,400) [500,570) [700,750) [900,950) }");
2798 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }");
2799 } 2910 }
2800 2911
2801 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) { 2912 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) {
2802 EXPECT_CALL(host_, AddTextStream(_, _)); 2913 EXPECT_CALL(host_, AddTextStream(_, _));
2803 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 2914 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
2804 2915
2805 // Append audio & video data 2916 // Append audio & video data
2806 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), 2917 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23),
2807 MuxedStreamInfo(kVideoTrackNum, "0K 33", 33)); 2918 MuxedStreamInfo(kVideoTrackNum, "0K 33", 33));
2808 2919
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2933 3044
2934 // Should not be able to fulfill a seek to 0. 3045 // Should not be able to fulfill a seek to 0.
2935 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(0); 3046 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(0);
2936 demuxer_->StartWaitingForSeek(seek_time); 3047 demuxer_->StartWaitingForSeek(seek_time);
2937 demuxer_->Seek(seek_time, 3048 demuxer_->Seek(seek_time,
2938 NewExpectedStatusCB(PIPELINE_ERROR_ABORT)); 3049 NewExpectedStatusCB(PIPELINE_ERROR_ABORT));
2939 ExpectRead(DemuxerStream::AUDIO, 0); 3050 ExpectRead(DemuxerStream::AUDIO, 0);
2940 ExpectEndOfStream(DemuxerStream::VIDEO); 3051 ExpectEndOfStream(DemuxerStream::VIDEO);
2941 } 3052 }
2942 3053
2943 TEST_F(ChunkDemuxerTest, ClusterWithNoBuffers) {
2944 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2945
2946 // Generate and append an empty cluster beginning at 0.
2947 AppendEmptyCluster(0);
2948
2949 // Sanity check that data can be appended after this cluster correctly.
2950 AppendCluster(GenerateCluster(0, 2));
2951 ExpectRead(DemuxerStream::AUDIO, 0);
2952 ExpectRead(DemuxerStream::VIDEO, 0);
2953 }
2954
2955 TEST_F(ChunkDemuxerTest, CodecPrefixMatching) { 3054 TEST_F(ChunkDemuxerTest, CodecPrefixMatching) {
2956 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported; 3055 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported;
2957 3056
2958 #if defined(USE_PROPRIETARY_CODECS) 3057 #if defined(USE_PROPRIETARY_CODECS)
2959 expected = ChunkDemuxer::kOk; 3058 expected = ChunkDemuxer::kOk;
2960 #endif 3059 #endif
2961 3060
2962 std::vector<std::string> codecs; 3061 std::vector<std::string> codecs;
2963 codecs.push_back("avc1.4D4041"); 3062 codecs.push_back("avc1.4D4041");
2964 3063
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
3367 append_window_start_for_next_append_, 3466 append_window_start_for_next_append_,
3368 append_window_end_for_next_append_, 3467 append_window_end_for_next_append_,
3369 &timestamp_offset_map_[kSourceId]); 3468 &timestamp_offset_map_[kSourceId]);
3370 } 3469 }
3371 3470
3372 #endif 3471 #endif
3373 #endif 3472 #endif
3374 3473
3375 TEST_F(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { 3474 TEST_F(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) {
3376 const uint8_t kBuffer[] = { 3475 const uint8_t kBuffer[] = {
3377 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) 3476 // CLUSTER (size = 10)
3378 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) 3477 0x1F, 0x43, 0xB6, 0x75, 0x8A,
3379 3478
3380 0x1F, 0x43, 0xB6, 0x75, 3479 // Cluster TIMECODE (value = 1)
3381 0xFF, // CLUSTER (size = unknown; really 3 due to:) 3480 0xE7, 0x81, 0x01,
3382 0xE7, 0x81, 0x02, // Cluster TIMECODE (value = 2) 3481
3383 /* e.g. put some blocks here... */ 3482 // SIMPLEBLOCK (size = 5)
3384 0x1A, 0x45, 0xDF, 0xA3, 3483 0xA3, 0x85,
3385 0x8A, // EBMLHEADER (size = 10, not fully appended) 3484
3485 // Audio Track Number
3486 0x80 | (kAudioTrackNum & 0x7F),
3487
3488 // Timecode (relative to cluster) (value = 0)
3489 0x00, 0x00,
3490
3491 // Keyframe flag
3492 0x80,
3493
3494 // Fake block data
3495 0x00,
3496
3497 // CLUSTER (size = unknown; really 10)
3498 0x1F, 0x43, 0xB6, 0x75, 0xFF,
3499
3500 // Cluster TIMECODE (value = 2)
3501 0xE7, 0x81, 0x02,
3502
3503 // SIMPLEBLOCK (size = 5)
3504 0xA3, 0x85,
3505
3506 // Audio Track Number
3507 0x80 | (kAudioTrackNum & 0x7F),
3508
3509 // Timecode (relative to cluster) (value = 0)
3510 0x00, 0x00,
3511
3512 // Keyframe flag
3513 0x80,
3514
3515 // Fake block data
3516 0x00,
3517
3518 // EBMLHEADER (size = 10, not fully appended)
3519 0x1A, 0x45, 0xDF, 0xA3, 0x8A,
chcunningham 2016/01/20 00:40:59 Is this part needed?
wolenetz 2016/01/20 00:45:48 Indeed it is. The termination of an "unknown"-size
3386 }; 3520 };
3387 3521
3388 // This array indicates expected return value of IsParsingMediaSegment() 3522 // This array indicates expected return value of IsParsingMediaSegment()
3389 // following each incrementally appended byte in |kBuffer|. 3523 // following each incrementally appended byte in |kBuffer|.
3390 const bool kExpectedReturnValues[] = { 3524 const bool kExpectedReturnValues[] = {
3391 false, false, false, false, true, 3525 // First Cluster, explicit size
3392 true, true, false, 3526 false, false, false, false, true, true, true, true, true, true, true,
3527 true, true, true, false,
3393 3528
3394 false, false, false, false, true, 3529 // Second Cluster, unknown size
3395 true, true, true, 3530 false, false, false, false, true, true, true, true, true, true, true,
3531 true, true, true, true,
3396 3532
3397 true, true, true, true, false, 3533 // EBMLHEADER
3534 true, true, true, true, false,
3398 }; 3535 };
3399 3536
3400 static_assert(arraysize(kBuffer) == arraysize(kExpectedReturnValues), 3537 static_assert(arraysize(kBuffer) == arraysize(kExpectedReturnValues),
3401 "test arrays out of sync"); 3538 "test arrays out of sync");
3402 static_assert(arraysize(kBuffer) == sizeof(kBuffer), 3539 static_assert(arraysize(kBuffer) == sizeof(kBuffer),
3403 "there should be one byte per index"); 3540 "there should be one byte per index");
3404 3541
3405 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3542 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3406 3543 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23)).Times(2);
3544 EXPECT_MEDIA_LOG(GeneratedSplice(22000, 2000));
3407 for (size_t i = 0; i < sizeof(kBuffer); i++) { 3545 for (size_t i = 0; i < sizeof(kBuffer); i++) {
3408 DVLOG(3) << "Appending and testing index " << i; 3546 DVLOG(3) << "Appending and testing index " << i;
3409 AppendData(kBuffer + i, 1); 3547 AppendData(kBuffer + i, 1);
3410 bool expected_return_value = kExpectedReturnValues[i]; 3548 bool expected_return_value = kExpectedReturnValues[i];
3411 EXPECT_EQ(expected_return_value, 3549 EXPECT_EQ(expected_return_value,
3412 demuxer_->IsParsingMediaSegment(kSourceId)); 3550 demuxer_->IsParsingMediaSegment(kSourceId));
3413 } 3551 }
3414 } 3552 }
3415 3553
3416 TEST_F(ChunkDemuxerTest, DurationChange) { 3554 TEST_F(ChunkDemuxerTest, DurationChange) {
3417 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3555 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3418 const int kStreamDuration = kDefaultDuration().InMilliseconds(); 3556 const int kStreamDuration = kDefaultDuration().InMilliseconds();
3419 3557
3420 // Add data leading up to the currently set duration. 3558 // Add data leading up to the currently set duration.
3421 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration, 3559 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration,
3422 kStreamDuration - kVideoBlockDuration, 3560 kStreamDuration - kVideoBlockDuration,
3423 2)); 3561 2));
3424 3562
3425 CheckExpectedRanges(kSourceId, "{ [201191,201224) }"); 3563 CheckExpectedRanges("{ [201191,201224) }");
3426 3564
3427 // Add data beginning at the currently set duration and expect a new duration 3565 // Add data beginning at the currently set duration and expect a new duration
3428 // to be signaled. Note that the last video block will have a higher end 3566 // to be signaled. Note that the last video block will have a higher end
3429 // timestamp than the last audio block. 3567 // timestamp than the last audio block.
3430 const int kNewStreamDurationVideo = kStreamDuration + kVideoBlockDuration; 3568 const int kNewStreamDurationVideo = kStreamDuration + kVideoBlockDuration;
3431 EXPECT_CALL(host_, SetDuration( 3569 EXPECT_CALL(host_, SetDuration(
3432 base::TimeDelta::FromMilliseconds(kNewStreamDurationVideo))); 3570 base::TimeDelta::FromMilliseconds(kNewStreamDurationVideo)));
3433 AppendCluster(GenerateCluster(kDefaultDuration().InMilliseconds(), 2)); 3571 AppendCluster(GenerateCluster(kDefaultDuration().InMilliseconds(), 2));
3434 3572
3435 CheckExpectedRanges(kSourceId, "{ [201191,201247) }"); 3573 CheckExpectedRanges("{ [201191,201247) }");
3436 3574
3437 // Add more data to the end of each media type. Note that the last audio block 3575 // Add more data to the end of each media type. Note that the last audio block
3438 // will have a higher end timestamp than the last video block. 3576 // will have a higher end timestamp than the last video block.
3439 const int kFinalStreamDuration = kStreamDuration + kAudioBlockDuration * 3; 3577 const int kFinalStreamDuration = kStreamDuration + kAudioBlockDuration * 3;
3440 EXPECT_CALL(host_, SetDuration( 3578 EXPECT_CALL(host_, SetDuration(
3441 base::TimeDelta::FromMilliseconds(kFinalStreamDuration))); 3579 base::TimeDelta::FromMilliseconds(kFinalStreamDuration)));
3442 AppendCluster(GenerateCluster(kStreamDuration + kAudioBlockDuration, 3580 AppendCluster(GenerateCluster(kStreamDuration + kAudioBlockDuration,
3443 kStreamDuration + kVideoBlockDuration, 3581 kStreamDuration + kVideoBlockDuration,
3444 3)); 3582 3));
3445 3583
3446 // See that the range has increased appropriately (but not to the full 3584 // See that the range has increased appropriately (but not to the full
3447 // duration of 201293, since there is not enough video appended for that). 3585 // duration of 201293, since there is not enough video appended for that).
3448 CheckExpectedRanges(kSourceId, "{ [201191,201290) }"); 3586 CheckExpectedRanges("{ [201191,201290) }");
3449 } 3587 }
3450 3588
3451 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) { 3589 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) {
3452 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3590 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3453 ASSERT_TRUE(SetTimestampOffset(kSourceId, kDefaultDuration())); 3591 ASSERT_TRUE(SetTimestampOffset(kSourceId, kDefaultDuration()));
3454 EXPECT_CALL(host_, SetDuration( 3592 EXPECT_CALL(host_, SetDuration(
3455 kDefaultDuration() + base::TimeDelta::FromMilliseconds( 3593 kDefaultDuration() + base::TimeDelta::FromMilliseconds(
3456 kVideoBlockDuration * 2))); 3594 kVideoBlockDuration * 2)));
3457 AppendCluster(GenerateCluster(0, 4)); 3595 AppendCluster(GenerateCluster(0, 4));
3458 } 3596 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3498 message_loop_.RunUntilIdle(); 3636 message_loop_.RunUntilIdle();
3499 } 3637 }
3500 3638
3501 // Verifies that signaling end of stream while stalled at a gap 3639 // Verifies that signaling end of stream while stalled at a gap
3502 // boundary does not trigger end of stream buffers to be returned. 3640 // boundary does not trigger end of stream buffers to be returned.
3503 TEST_F(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) { 3641 TEST_F(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) {
3504 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3642 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3505 3643
3506 AppendCluster(0, 10); 3644 AppendCluster(0, 10);
3507 AppendCluster(300, 10); 3645 AppendCluster(300, 10);
3508 CheckExpectedRanges(kSourceId, "{ [0,132) [300,432) }"); 3646 CheckExpectedRanges("{ [0,132) [300,432) }");
3509 3647
3510 GenerateExpectedReads(0, 10); 3648 GenerateExpectedReads(0, 10);
3511 3649
3512 bool audio_read_done = false; 3650 bool audio_read_done = false;
3513 bool video_read_done = false; 3651 bool video_read_done = false;
3514 ReadAudio(base::Bind(&OnReadDone, 3652 ReadAudio(base::Bind(&OnReadDone,
3515 base::TimeDelta::FromMilliseconds(138), 3653 base::TimeDelta::FromMilliseconds(138),
3516 &audio_read_done)); 3654 &audio_read_done));
3517 ReadVideo(base::Bind(&OnReadDone, 3655 ReadVideo(base::Bind(&OnReadDone,
3518 base::TimeDelta::FromMilliseconds(138), 3656 base::TimeDelta::FromMilliseconds(138),
3519 &video_read_done)); 3657 &video_read_done));
3520 3658
3521 // Verify that the reads didn't complete 3659 // Verify that the reads didn't complete
3522 EXPECT_FALSE(audio_read_done); 3660 EXPECT_FALSE(audio_read_done);
3523 EXPECT_FALSE(video_read_done); 3661 EXPECT_FALSE(video_read_done);
3524 3662
3525 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(438))); 3663 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(438)));
3526 MarkEndOfStream(PIPELINE_OK); 3664 MarkEndOfStream(PIPELINE_OK);
3527 3665
3528 // Verify that the reads still haven't completed. 3666 // Verify that the reads still haven't completed.
3529 EXPECT_FALSE(audio_read_done); 3667 EXPECT_FALSE(audio_read_done);
3530 EXPECT_FALSE(video_read_done); 3668 EXPECT_FALSE(video_read_done);
3531 3669
3532 demuxer_->UnmarkEndOfStream(); 3670 demuxer_->UnmarkEndOfStream();
3533 3671
3534 AppendCluster(138, 22); 3672 AppendCluster(138, 22);
3535 3673
3536 message_loop_.RunUntilIdle(); 3674 message_loop_.RunUntilIdle();
3537 3675
3538 CheckExpectedRanges(kSourceId, "{ [0,435) }"); 3676 CheckExpectedRanges("{ [0,435) }");
3539 3677
3540 // Verify that the reads have completed. 3678 // Verify that the reads have completed.
3541 EXPECT_TRUE(audio_read_done); 3679 EXPECT_TRUE(audio_read_done);
3542 EXPECT_TRUE(video_read_done); 3680 EXPECT_TRUE(video_read_done);
3543 3681
3544 // Read the rest of the buffers. 3682 // Read the rest of the buffers.
3545 GenerateExpectedReads(161, 171, 20); 3683 GenerateExpectedReads(161, 171, 20);
3546 3684
3547 // Verify that reads block because the append cleared the end of stream state. 3685 // Verify that reads block because the append cleared the end of stream state.
3548 audio_read_done = false; 3686 audio_read_done = false;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3615 // Verify that the old data, and nothing more, has been garbage collected. 3753 // Verify that the old data, and nothing more, has been garbage collected.
3616 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [1000,1230) }"); 3754 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [1000,1230) }");
3617 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [1000,1165) }"); 3755 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [1000,1165) }");
3618 } 3756 }
3619 3757
3620 TEST_F(ChunkDemuxerTest, GCDuringSeek_SingleRange_SeekForward) { 3758 TEST_F(ChunkDemuxerTest, GCDuringSeek_SingleRange_SeekForward) {
3621 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3759 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3622 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3760 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3623 // Append some data at position 1000ms 3761 // Append some data at position 1000ms
3624 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 10); 3762 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 10);
3625 CheckExpectedRanges(kSourceId, "{ [1000,1230) }"); 3763 CheckExpectedRanges("{ [1000,1230) }");
3626 3764
3627 // GC should be able to evict frames in the currently buffered range, since 3765 // GC should be able to evict frames in the currently buffered range, since
3628 // those frames are earlier than the seek target position. 3766 // those frames are earlier than the seek target position.
3629 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000); 3767 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000);
3630 Seek(seek_time); 3768 Seek(seek_time);
3631 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize)); 3769 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize));
3632 3770
3633 // Append data to complete seek operation 3771 // Append data to complete seek operation
3634 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); 3772 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5);
3635 CheckExpectedRanges(kSourceId, "{ [1115,1230) [2000,2115) }"); 3773 CheckExpectedRanges("{ [1115,1230) [2000,2115) }");
3636 } 3774 }
3637 3775
3638 TEST_F(ChunkDemuxerTest, GCDuringSeek_SingleRange_SeekBack) { 3776 TEST_F(ChunkDemuxerTest, GCDuringSeek_SingleRange_SeekBack) {
3639 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3777 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3640 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3778 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3641 // Append some data at position 1000ms 3779 // Append some data at position 1000ms
3642 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 10); 3780 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 10);
3643 CheckExpectedRanges(kSourceId, "{ [1000,1230) }"); 3781 CheckExpectedRanges("{ [1000,1230) }");
3644 3782
3645 // GC should be able to evict frames in the currently buffered range, since 3783 // GC should be able to evict frames in the currently buffered range, since
3646 // seek target position has no data and so we should allow some frames to be 3784 // seek target position has no data and so we should allow some frames to be
3647 // evicted to make space for the upcoming append at seek target position. 3785 // evicted to make space for the upcoming append at seek target position.
3648 base::TimeDelta seek_time = base::TimeDelta(); 3786 base::TimeDelta seek_time = base::TimeDelta();
3649 Seek(seek_time); 3787 Seek(seek_time);
3650 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize)); 3788 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize));
3651 3789
3652 // Append data to complete seek operation 3790 // Append data to complete seek operation
3653 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 5); 3791 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 5);
3654 CheckExpectedRanges(kSourceId, "{ [0,115) [1115,1230) }"); 3792 CheckExpectedRanges("{ [0,115) [1115,1230) }");
3655 } 3793 }
3656 3794
3657 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekForward) { 3795 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekForward) {
3658 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3796 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3659 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3797 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3660 // Append some data at position 1000ms then at 2000ms 3798 // Append some data at position 1000ms then at 2000ms
3661 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); 3799 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5);
3662 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); 3800 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5);
3663 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); 3801 CheckExpectedRanges("{ [1000,1115) [2000,2115) }");
3664 3802
3665 // GC should be able to evict frames in the currently buffered ranges, since 3803 // GC should be able to evict frames in the currently buffered ranges, since
3666 // those frames are earlier than the seek target position. 3804 // those frames are earlier than the seek target position.
3667 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(3000); 3805 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(3000);
3668 Seek(seek_time); 3806 Seek(seek_time);
3669 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize)); 3807 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize));
3670 3808
3671 // Append data to complete seek operation 3809 // Append data to complete seek operation
3672 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3000, 5); 3810 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3000, 5);
3673 CheckExpectedRanges(kSourceId, "{ [2069,2115) [3000,3115) }"); 3811 CheckExpectedRanges("{ [2069,2115) [3000,3115) }");
3674 } 3812 }
3675 3813
3676 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekInbetween1) { 3814 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekInbetween1) {
3677 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3815 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3678 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3816 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3679 // Append some data at position 1000ms then at 2000ms 3817 // Append some data at position 1000ms then at 2000ms
3680 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); 3818 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5);
3681 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); 3819 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5);
3682 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); 3820 CheckExpectedRanges("{ [1000,1115) [2000,2115) }");
3683 3821
3684 // GC should be able to evict all frames from the first buffered range, since 3822 // GC should be able to evict all frames from the first buffered range, since
3685 // those frames are earlier than the seek target position. But there's only 5 3823 // those frames are earlier than the seek target position. But there's only 5
3686 // blocks worth of data in the first range and seek target position has no 3824 // blocks worth of data in the first range and seek target position has no
3687 // data, so GC proceeds with trying to delete some frames from the back of 3825 // data, so GC proceeds with trying to delete some frames from the back of
3688 // buffered ranges, that doesn't yield anything, since that's the most 3826 // buffered ranges, that doesn't yield anything, since that's the most
3689 // recently appended data, so then GC starts removing data from the front of 3827 // recently appended data, so then GC starts removing data from the front of
3690 // the remaining buffered range (2000ms) to ensure we free up enough space for 3828 // the remaining buffered range (2000ms) to ensure we free up enough space for
3691 // the upcoming append and allow seek to proceed. 3829 // the upcoming append and allow seek to proceed.
3692 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(1500); 3830 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(1500);
3693 Seek(seek_time); 3831 Seek(seek_time);
3694 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize)); 3832 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize));
3695 3833
3696 // Append data to complete seek operation 3834 // Append data to complete seek operation
3697 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1500, 5); 3835 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1500, 5);
3698 CheckExpectedRanges(kSourceId, "{ [1500,1615) [2069,2115) }"); 3836 CheckExpectedRanges("{ [1500,1615) [2069,2115) }");
3699 } 3837 }
3700 3838
3701 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekInbetween2) { 3839 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekInbetween2) {
3702 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3840 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3703 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3841 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3704 3842
3705 // Append some data at position 2000ms first, then at 1000ms, so that the last 3843 // Append some data at position 2000ms first, then at 1000ms, so that the last
3706 // appended data position is in the first buffered range (that matters to the 3844 // appended data position is in the first buffered range (that matters to the
3707 // GC algorithm since it tries to preserve more recently appended data). 3845 // GC algorithm since it tries to preserve more recently appended data).
3708 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); 3846 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5);
3709 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); 3847 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5);
3710 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); 3848 CheckExpectedRanges("{ [1000,1115) [2000,2115) }");
3711 3849
3712 // Now try performing garbage collection without announcing seek first, i.e. 3850 // Now try performing garbage collection without announcing seek first, i.e.
3713 // without calling Seek(), the GC algorithm should try to preserve data in the 3851 // without calling Seek(), the GC algorithm should try to preserve data in the
3714 // first range, since that is most recently appended data. 3852 // first range, since that is most recently appended data.
3715 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2030); 3853 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2030);
3716 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize)); 3854 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize));
3717 3855
3718 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1500, 5); 3856 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1500, 5);
3719 CheckExpectedRanges(kSourceId, "{ [1000,1115) [1500,1615) }"); 3857 CheckExpectedRanges("{ [1000,1115) [1500,1615) }");
3720 } 3858 }
3721 3859
3722 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekBack) { 3860 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekBack) {
3723 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3861 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3724 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3862 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3725 // Append some data at position 1000ms then at 2000ms 3863 // Append some data at position 1000ms then at 2000ms
3726 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); 3864 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5);
3727 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); 3865 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5);
3728 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); 3866 CheckExpectedRanges("{ [1000,1115) [2000,2115) }");
3729 3867
3730 // GC should be able to evict frames in the currently buffered ranges, since 3868 // GC should be able to evict frames in the currently buffered ranges, since
3731 // those frames are earlier than the seek target position. 3869 // those frames are earlier than the seek target position.
3732 base::TimeDelta seek_time = base::TimeDelta(); 3870 base::TimeDelta seek_time = base::TimeDelta();
3733 Seek(seek_time); 3871 Seek(seek_time);
3734 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize)); 3872 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize));
3735 3873
3736 // Append data to complete seek operation 3874 // Append data to complete seek operation
3737 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 5); 3875 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 5);
3738 CheckExpectedRanges(kSourceId, "{ [0,115) [2069,2115) }"); 3876 CheckExpectedRanges("{ [0,115) [2069,2115) }");
3739 } 3877 }
3740 3878
3741 TEST_F(ChunkDemuxerTest, GCDuringSeek) { 3879 TEST_F(ChunkDemuxerTest, GCDuringSeek) {
3742 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3880 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3743 3881
3744 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 5 * kBlockSize); 3882 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 5 * kBlockSize);
3745 3883
3746 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(1000); 3884 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(1000);
3747 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(500); 3885 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(500);
3748 3886
3749 // Initiate a seek to |seek_time1|. 3887 // Initiate a seek to |seek_time1|.
3750 Seek(seek_time1); 3888 Seek(seek_time1);
3751 3889
3752 // Append data to satisfy the first seek request. 3890 // Append data to satisfy the first seek request.
3753 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3891 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
3754 seek_time1.InMilliseconds(), 5); 3892 seek_time1.InMilliseconds(), 5);
3755 CheckExpectedRanges(kSourceId, "{ [1000,1115) }"); 3893 CheckExpectedRanges("{ [1000,1115) }");
3756 3894
3757 // We are under memory limit, so Evict should be a no-op. 3895 // We are under memory limit, so Evict should be a no-op.
3758 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time1, 0)); 3896 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time1, 0));
3759 CheckExpectedRanges(kSourceId, "{ [1000,1115) }"); 3897 CheckExpectedRanges("{ [1000,1115) }");
3760 3898
3761 // Signal that the second seek is starting. 3899 // Signal that the second seek is starting.
3762 demuxer_->StartWaitingForSeek(seek_time2); 3900 demuxer_->StartWaitingForSeek(seek_time2);
3763 3901
3764 // Append data to satisfy the second seek. 3902 // Append data to satisfy the second seek.
3765 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3903 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
3766 seek_time2.InMilliseconds(), 5); 3904 seek_time2.InMilliseconds(), 5);
3767 CheckExpectedRanges(kSourceId, "{ [500,615) [1000,1115) }"); 3905 CheckExpectedRanges("{ [500,615) [1000,1115) }");
3768 3906
3769 // We are now over our memory usage limit. We have just seeked to |seek_time2| 3907 // We are now over our memory usage limit. We have just seeked to |seek_time2|
3770 // so data around 500ms position should be preserved, while the previous 3908 // so data around 500ms position should be preserved, while the previous
3771 // append at 1000ms should be removed. 3909 // append at 1000ms should be removed.
3772 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0)); 3910 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0));
3773 CheckExpectedRanges(kSourceId, "{ [500,615) }"); 3911 CheckExpectedRanges("{ [500,615) }");
3774 3912
3775 // Complete the seek. 3913 // Complete the seek.
3776 demuxer_->Seek(seek_time2, NewExpectedStatusCB(PIPELINE_OK)); 3914 demuxer_->Seek(seek_time2, NewExpectedStatusCB(PIPELINE_OK));
3777 3915
3778 // Append more data and make sure that we preserve both the buffered range 3916 // Append more data and make sure that we preserve both the buffered range
3779 // around |seek_time2|, because that's the current playback position, 3917 // around |seek_time2|, because that's the current playback position,
3780 // and the newly appended range, since this is the most recent append. 3918 // and the newly appended range, since this is the most recent append.
3781 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 700, 5); 3919 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 700, 5);
3782 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0)); 3920 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0));
3783 CheckExpectedRanges(kSourceId, "{ [500,615) [700,815) }"); 3921 CheckExpectedRanges("{ [500,615) [700,815) }");
3784 } 3922 }
3785 3923
3786 TEST_F(ChunkDemuxerTest, GCKeepPlayhead) { 3924 TEST_F(ChunkDemuxerTest, GCKeepPlayhead) {
3787 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3925 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3788 3926
3789 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 5 * kBlockSize); 3927 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 5 * kBlockSize);
3790 3928
3791 // Append data at the start that can be garbage collected: 3929 // Append data at the start that can be garbage collected:
3792 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 10); 3930 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 10);
3793 CheckExpectedRanges(kSourceId, "{ [0,230) }"); 3931 CheckExpectedRanges("{ [0,230) }");
3794 3932
3795 // We expect garbage collection to fail, as we don't want to spontaneously 3933 // We expect garbage collection to fail, as we don't want to spontaneously
3796 // create gaps in source buffer stream. Gaps could break playback for many 3934 // create gaps in source buffer stream. Gaps could break playback for many
3797 // clients, who don't bother to check ranges after append. 3935 // clients, who don't bother to check ranges after append.
3798 EXPECT_FALSE(demuxer_->EvictCodedFrames( 3936 EXPECT_FALSE(demuxer_->EvictCodedFrames(
3799 kSourceId, base::TimeDelta::FromMilliseconds(0), 0)); 3937 kSourceId, base::TimeDelta::FromMilliseconds(0), 0));
3800 CheckExpectedRanges(kSourceId, "{ [0,230) }"); 3938 CheckExpectedRanges("{ [0,230) }");
3801 3939
3802 // Increase media_time a bit, this will allow some data to be collected, but 3940 // Increase media_time a bit, this will allow some data to be collected, but
3803 // we are still over memory usage limit. 3941 // we are still over memory usage limit.
3804 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(23*2); 3942 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(23*2);
3805 Seek(seek_time1); 3943 Seek(seek_time1);
3806 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time1, 0)); 3944 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time1, 0));
3807 CheckExpectedRanges(kSourceId, "{ [46,230) }"); 3945 CheckExpectedRanges("{ [46,230) }");
3808 3946
3809 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(23*4); 3947 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(23*4);
3810 Seek(seek_time2); 3948 Seek(seek_time2);
3811 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0)); 3949 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0));
3812 CheckExpectedRanges(kSourceId, "{ [92,230) }"); 3950 CheckExpectedRanges("{ [92,230) }");
3813 3951
3814 // media_time has progressed to a point where we can collect enough data to 3952 // media_time has progressed to a point where we can collect enough data to
3815 // be under memory limit, so Evict should return true. 3953 // be under memory limit, so Evict should return true.
3816 base::TimeDelta seek_time3 = base::TimeDelta::FromMilliseconds(23*6); 3954 base::TimeDelta seek_time3 = base::TimeDelta::FromMilliseconds(23*6);
3817 Seek(seek_time3); 3955 Seek(seek_time3);
3818 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time3, 0)); 3956 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time3, 0));
3819 // Strictly speaking the current playback time is 23*6==138ms, so we could 3957 // Strictly speaking the current playback time is 23*6==138ms, so we could
3820 // release data up to 138ms, but we only release as much data as necessary 3958 // release data up to 138ms, but we only release as much data as necessary
3821 // to bring memory usage under the limit, so we release only up to 115ms. 3959 // to bring memory usage under the limit, so we release only up to 115ms.
3822 CheckExpectedRanges(kSourceId, "{ [115,230) }"); 3960 CheckExpectedRanges("{ [115,230) }");
3823 } 3961 }
3824 3962
3825 TEST_F(ChunkDemuxerTest, AppendWindow_Video) { 3963 TEST_F(ChunkDemuxerTest, AppendWindow_Video) {
3826 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); 3964 ASSERT_TRUE(InitDemuxer(HAS_VIDEO));
3827 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3965 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3828 3966
3829 // Set the append window to [50,280). 3967 // Set the append window to [50,280).
3830 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); 3968 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50);
3831 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3969 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3832 3970
3833 // Append a cluster that starts before and ends after the append window. 3971 // Append a cluster that starts before and ends after the append window.
3834 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30)); 3972 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30));
3835 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3973 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3836 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); 3974 "0K 30 60 90 120K 150 180 210 240K 270 300 330K");
3837 3975
3838 // Verify that GOPs that start outside the window are not included 3976 // Verify that GOPs that start outside the window are not included
3839 // in the buffer. Also verify that buffers that start inside the 3977 // in the buffer. Also verify that buffers that start inside the
3840 // window and extend beyond the end of the window are not included. 3978 // window and extend beyond the end of the window are not included.
3841 CheckExpectedRanges(kSourceId, "{ [120,270) }"); 3979 CheckExpectedRanges("{ [120,270) }");
3842 CheckExpectedBuffers(stream, "120K 150 180 210 240K"); 3980 CheckExpectedBuffers(stream, "120K 150 180 210 240K");
3843 3981
3844 // Extend the append window to [50,650). 3982 // Extend the append window to [50,650).
3845 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3983 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3846 3984
3847 // Append more data and verify that adding buffers start at the next 3985 // Append more data and verify that adding buffers start at the next
3848 // key frame. 3986 // key frame.
3849 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30)); 3987 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30));
3850 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3988 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3851 "360 390 420K 450 480 510 540K 570 600 630K"); 3989 "360 390 420K 450 480 510 540K 570 600 630K");
3852 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); 3990 CheckExpectedRanges("{ [120,270) [420,630) }");
3853 } 3991 }
3854 3992
3855 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) { 3993 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) {
3856 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3994 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3857 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3995 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3858 3996
3859 // Set the append window to [50,280). 3997 // Set the append window to [50,280).
3860 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); 3998 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50);
3861 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3999 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3862 4000
3863 // Append a cluster that starts before and ends after the append window. 4001 // Append a cluster that starts before and ends after the append window.
3864 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30)); 4002 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30));
3865 AppendSingleStreamCluster( 4003 AppendSingleStreamCluster(
3866 kSourceId, kAudioTrackNum, 4004 kSourceId, kAudioTrackNum,
3867 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); 4005 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K");
3868 4006
3869 // Verify that frames that end outside the window are not included 4007 // Verify that frames that end outside the window are not included
3870 // in the buffer. Also verify that buffers that start inside the 4008 // in the buffer. Also verify that buffers that start inside the
3871 // window and extend beyond the end of the window are not included. 4009 // window and extend beyond the end of the window are not included.
3872 // 4010 //
3873 // The first 50ms of the range should be truncated since it overlaps 4011 // The first 50ms of the range should be truncated since it overlaps
3874 // the start of the append window. 4012 // the start of the append window.
3875 CheckExpectedRanges(kSourceId, "{ [50,280) }"); 4013 CheckExpectedRanges("{ [50,280) }");
3876 4014
3877 // The "50P" buffer is the "0" buffer marked for complete discard. The next 4015 // The "50P" buffer is the "0" buffer marked for complete discard. The next
3878 // "50" buffer is the "30" buffer marked with 20ms of start discard. 4016 // "50" buffer is the "30" buffer marked with 20ms of start discard.
3879 CheckExpectedBuffers(stream, "50KP 50K 60K 90K 120K 150K 180K 210K 240K"); 4017 CheckExpectedBuffers(stream, "50KP 50K 60K 90K 120K 150K 180K 210K 240K");
3880 4018
3881 // Extend the append window to [50,650). 4019 // Extend the append window to [50,650).
3882 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 4020 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3883 4021
3884 // Append more data and verify that a new range is created. 4022 // Append more data and verify that a new range is created.
3885 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30)); 4023 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30));
3886 AppendSingleStreamCluster( 4024 AppendSingleStreamCluster(
3887 kSourceId, kAudioTrackNum, 4025 kSourceId, kAudioTrackNum,
3888 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); 4026 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K");
3889 CheckExpectedRanges(kSourceId, "{ [50,280) [360,650) }"); 4027 CheckExpectedRanges("{ [50,280) [360,650) }");
3890 } 4028 }
3891 4029
3892 TEST_F(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) { 4030 TEST_F(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) {
3893 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 4031 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3894 4032
3895 // Set the append window to [10,20). 4033 // Set the append window to [10,20).
3896 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10); 4034 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10);
3897 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20); 4035 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
3898 4036
3899 // Append a cluster that starts before and ends after the append window. 4037 // Append a cluster that starts before and ends after the append window.
3900 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated( 4038 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(
3901 WebMClusterParser::kDefaultAudioBufferDurationInMs)); 4039 WebMClusterParser::kDefaultAudioBufferDurationInMs));
3902 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K"); 4040 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K");
3903 4041
3904 // Verify the append is clipped to the append window. 4042 // Verify the append is clipped to the append window.
3905 CheckExpectedRanges(kSourceId, "{ [10,20) }"); 4043 CheckExpectedRanges("{ [10,20) }");
3906 } 4044 }
3907 4045
3908 TEST_F(ChunkDemuxerTest, AppendWindow_WebMFile_AudioOnly) { 4046 TEST_F(ChunkDemuxerTest, AppendWindow_WebMFile_AudioOnly) {
3909 EXPECT_CALL(*this, DemuxerOpened()); 4047 EXPECT_CALL(*this, DemuxerOpened());
3910 demuxer_->Initialize( 4048 demuxer_->Initialize(
3911 &host_, 4049 &host_,
3912 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), 4050 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK),
3913 true); 4051 true);
3914 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); 4052 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO));
3915 4053
(...skipping 30 matching lines...) Expand all
3946 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746); 4084 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746);
3947 append_window_start_for_next_append_ = duration_1; 4085 append_window_start_for_next_append_ = duration_1;
3948 4086
3949 // Read a WebM file into memory and append the data. 4087 // Read a WebM file into memory and append the data.
3950 scoped_refptr<DecoderBuffer> buffer = 4088 scoped_refptr<DecoderBuffer> buffer =
3951 ReadTestDataFile("bear-320x240-audio-only.webm"); 4089 ReadTestDataFile("bear-320x240-audio-only.webm");
3952 ExpectInitMediaLogs(HAS_AUDIO); 4090 ExpectInitMediaLogs(HAS_AUDIO);
3953 EXPECT_CALL(*this, InitSegmentReceived()); 4091 EXPECT_CALL(*this, InitSegmentReceived());
3954 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)); 4092 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2));
3955 AppendDataInPieces(buffer->data(), buffer->data_size(), 512); 4093 AppendDataInPieces(buffer->data(), buffer->data_size(), 512);
3956 CheckExpectedRanges(kSourceId, "{ }"); 4094 CheckExpectedRanges("{ }");
3957 4095
3958 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 4096 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3959 AudioDecoderConfig config_1 = stream->audio_decoder_config(); 4097 AudioDecoderConfig config_1 = stream->audio_decoder_config();
3960 4098
3961 // Read a second WebM with a different config in and append the data. 4099 // Read a second WebM with a different config in and append the data.
3962 scoped_refptr<DecoderBuffer> buffer2 = 4100 scoped_refptr<DecoderBuffer> buffer2 =
3963 ReadTestDataFile("bear-320x240-audio-only-48khz.webm"); 4101 ReadTestDataFile("bear-320x240-audio-only-48khz.webm");
3964 EXPECT_CALL(*this, InitSegmentReceived()); 4102 EXPECT_CALL(*this, InitSegmentReceived());
3965 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(21)); 4103 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(21));
3966 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber()); 4104 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber());
3967 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1)); 4105 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1));
3968 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512); 4106 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512);
3969 CheckExpectedRanges(kSourceId, "{ [2746,5519) }"); 4107 CheckExpectedRanges("{ [2746,5519) }");
3970 4108
3971 Seek(duration_1); 4109 Seek(duration_1);
3972 ExpectConfigChanged(DemuxerStream::AUDIO); 4110 ExpectConfigChanged(DemuxerStream::AUDIO);
3973 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config())); 4111 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config()));
3974 CheckExpectedBuffers(stream, "2746K 2767K 2789K 2810K"); 4112 CheckExpectedBuffers(stream, "2746K 2767K 2789K 2810K");
3975 } 4113 }
3976 4114
3977 TEST_F(ChunkDemuxerTest, AppendWindow_Text) { 4115 TEST_F(ChunkDemuxerTest, AppendWindow_Text) {
3978 DemuxerStream* text_stream = NULL; 4116 DemuxerStream* text_stream = NULL;
3979 EXPECT_CALL(host_, AddTextStream(_, _)) 4117 EXPECT_CALL(host_, AddTextStream(_, _))
3980 .WillOnce(SaveArg<0>(&text_stream)); 4118 .WillOnce(SaveArg<0>(&text_stream));
3981 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); 4119 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT));
3982 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 4120 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3983 4121
3984 // Set the append window to [20,280). 4122 // Set the append window to [20,280).
3985 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); 4123 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
3986 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 4124 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3987 4125
3988 // Append a cluster that starts before and ends after the append 4126 // Append a cluster that starts before and ends after the append
3989 // window. 4127 // window.
3990 AppendMuxedCluster( 4128 AppendMuxedCluster(
3991 MuxedStreamInfo(kVideoTrackNum, 4129 MuxedStreamInfo(kVideoTrackNum,
3992 "0K 30 60 90 120K 150 180 210 240K 270 300 330K", 30), 4130 "0K 30 60 90 120K 150 180 210 240K 270 300 330K", 30),
3993 MuxedStreamInfo(kTextTrackNum, "0K 100K 200K 300K")); 4131 MuxedStreamInfo(kTextTrackNum, "0K 100K 200K 300K"));
3994 4132
3995 // Verify that text cues that start outside the window are not included 4133 // Verify that text cues that start outside the window are not included
3996 // in the buffer. Also verify that cues that extend beyond the 4134 // in the buffer. Also verify that cues that extend beyond the
3997 // window are not included. 4135 // window are not included.
3998 CheckExpectedRanges(kSourceId, "{ [100,270) }"); 4136 CheckExpectedRanges("{ [100,270) }");
3999 CheckExpectedBuffers(video_stream, "120K 150 180 210 240K"); 4137 CheckExpectedBuffers(video_stream, "120K 150 180 210 240K");
4000 CheckExpectedBuffers(text_stream, "100K"); 4138 CheckExpectedBuffers(text_stream, "100K");
4001 4139
4002 // Extend the append window to [20,650). 4140 // Extend the append window to [20,650).
4003 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 4141 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
4004 4142
4005 // Append more data and verify that a new range is created. 4143 // Append more data and verify that a new range is created.
4006 AppendMuxedCluster( 4144 AppendMuxedCluster(
4007 MuxedStreamInfo(kVideoTrackNum, 4145 MuxedStreamInfo(kVideoTrackNum,
4008 "360 390 420K 450 480 510 540K 570 600 630K", 30), 4146 "360 390 420K 450 480 510 540K 570 600 630K", 30),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4040 4178
4041 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K"); 4179 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K");
4042 CheckExpectedBuffers(video_stream, "0K 30 60 90 120K 150 180"); 4180 CheckExpectedBuffers(video_stream, "0K 30 60 90 120K 150 180");
4043 CheckExpectedBuffers(text_stream, "0K 100K 200K"); 4181 CheckExpectedBuffers(text_stream, "0K 100K 200K");
4044 4182
4045 // Remove the buffers that were added. 4183 // Remove the buffers that were added.
4046 demuxer_->Remove(kSourceId, base::TimeDelta(), 4184 demuxer_->Remove(kSourceId, base::TimeDelta(),
4047 base::TimeDelta::FromMilliseconds(300)); 4185 base::TimeDelta::FromMilliseconds(300));
4048 4186
4049 // Verify that all the appended data has been removed. 4187 // Verify that all the appended data has been removed.
4050 CheckExpectedRanges(kSourceId, "{ }"); 4188 CheckExpectedRanges("{ }");
4051 4189
4052 // Append new buffers that are clearly different than the original 4190 // Append new buffers that are clearly different than the original
4053 // ones and verify that only the new buffers are returned. 4191 // ones and verify that only the new buffers are returned.
4054 AppendMuxedCluster( 4192 AppendMuxedCluster(
4055 MuxedStreamInfo(kAudioTrackNum, "1K 21K 41K 61K 81K 101K 121K 141K", 20), 4193 MuxedStreamInfo(kAudioTrackNum, "1K 21K 41K 61K 81K 101K 121K 141K", 20),
4056 MuxedStreamInfo(kVideoTrackNum, "1K 31 61 91 121K 151 181", 30), 4194 MuxedStreamInfo(kVideoTrackNum, "1K 31 61 91 121K 151 181", 30),
4057 MuxedStreamInfo(kTextTrackNum, "1K 101K 201K")); 4195 MuxedStreamInfo(kTextTrackNum, "1K 101K 201K"));
4058 4196
4059 Seek(base::TimeDelta()); 4197 Seek(base::TimeDelta());
4060 CheckExpectedBuffers(audio_stream, "1K 21K 41K 61K 81K 101K 121K 141K"); 4198 CheckExpectedBuffers(audio_stream, "1K 21K 41K 61K 81K 101K 121K 141K");
4061 CheckExpectedBuffers(video_stream, "1K 31 61 91 121K 151 181"); 4199 CheckExpectedBuffers(video_stream, "1K 31 61 91 121K 151 181");
4062 CheckExpectedBuffers(text_stream, "1K 101K 201K"); 4200 CheckExpectedBuffers(text_stream, "1K 101K 201K");
4063 } 4201 }
4064 4202
4065 TEST_F(ChunkDemuxerTest, Remove_StartAtDuration) { 4203 TEST_F(ChunkDemuxerTest, Remove_StartAtDuration) {
4066 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 4204 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
4067 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 4205 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
4068 4206
4069 // Set the duration to something small so that the append that 4207 // Set the duration to something small so that the append that
4070 // follows updates the duration to reflect the end of the appended data. 4208 // follows updates the duration to reflect the end of the appended data.
4071 EXPECT_CALL(host_, SetDuration( 4209 EXPECT_CALL(host_, SetDuration(
4072 base::TimeDelta::FromMilliseconds(1))); 4210 base::TimeDelta::FromMilliseconds(1)));
4073 demuxer_->SetDuration(0.001); 4211 demuxer_->SetDuration(0.001);
4074 4212
4075 EXPECT_CALL(host_, SetDuration( 4213 EXPECT_CALL(host_, SetDuration(
4076 base::TimeDelta::FromMilliseconds(160))); 4214 base::TimeDelta::FromMilliseconds(160)));
4077 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 4215 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
4078 "0K 20K 40K 60K 80K 100K 120K 140D20K"); 4216 "0K 20K 40K 60K 80K 100K 120K 140D20K");
4079 4217
4080 CheckExpectedRanges(kSourceId, "{ [0,160) }"); 4218 CheckExpectedRanges("{ [0,160) }");
4081 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K"); 4219 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K");
4082 4220
4083 demuxer_->Remove(kSourceId, 4221 demuxer_->Remove(kSourceId,
4084 base::TimeDelta::FromSecondsD(demuxer_->GetDuration()), 4222 base::TimeDelta::FromSecondsD(demuxer_->GetDuration()),
4085 kInfiniteDuration()); 4223 kInfiniteDuration());
4086 4224
4087 Seek(base::TimeDelta()); 4225 Seek(base::TimeDelta());
4088 CheckExpectedRanges(kSourceId, "{ [0,160) }"); 4226 CheckExpectedRanges("{ [0,160) }");
4089 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K"); 4227 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K");
4090 } 4228 }
4091 4229
4092 // Verifies that a Seek() will complete without text cues for 4230 // Verifies that a Seek() will complete without text cues for
4093 // the seek point and will return cues after the seek position 4231 // the seek point and will return cues after the seek position
4094 // when they are eventually appended. 4232 // when they are eventually appended.
4095 TEST_F(ChunkDemuxerTest, SeekCompletesWithoutTextCues) { 4233 TEST_F(ChunkDemuxerTest, SeekCompletesWithoutTextCues) {
4096 DemuxerStream* text_stream = NULL; 4234 DemuxerStream* text_stream = NULL;
4097 EXPECT_CALL(host_, AddTextStream(_, _)) 4235 EXPECT_CALL(host_, AddTextStream(_, _))
4098 .WillOnce(SaveArg<0>(&text_stream)); 4236 .WillOnce(SaveArg<0>(&text_stream));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4146 4284
4147 // Verify that audio & video streams continue to return expected values. 4285 // Verify that audio & video streams continue to return expected values.
4148 CheckExpectedBuffers(audio_stream, "160K 180K"); 4286 CheckExpectedBuffers(audio_stream, "160K 180K");
4149 CheckExpectedBuffers(video_stream, "180 210"); 4287 CheckExpectedBuffers(video_stream, "180 210");
4150 } 4288 }
4151 4289
4152 TEST_F(ChunkDemuxerTest, ClusterWithUnknownSize) { 4290 TEST_F(ChunkDemuxerTest, ClusterWithUnknownSize) {
4153 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 4291 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
4154 4292
4155 AppendCluster(GenerateCluster(0, 0, 4, true)); 4293 AppendCluster(GenerateCluster(0, 0, 4, true));
4156 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 4294 CheckExpectedRanges("{ [0,46) }");
4157 4295
4158 // A new cluster indicates end of the previous cluster with unknown size. 4296 // A new cluster indicates end of the previous cluster with unknown size.
4159 AppendCluster(GenerateCluster(46, 66, 5, true)); 4297 AppendCluster(GenerateCluster(46, 66, 5, true));
4160 CheckExpectedRanges(kSourceId, "{ [0,115) }"); 4298 CheckExpectedRanges("{ [0,115) }");
4161 } 4299 }
4162 4300
4163 TEST_F(ChunkDemuxerTest, CuesBetweenClustersWithUnknownSize) { 4301 TEST_F(ChunkDemuxerTest, CuesBetweenClustersWithUnknownSize) {
4164 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 4302 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
4165 4303
4166 // Add two clusters separated by Cues in a single Append() call. 4304 // Add two clusters separated by Cues in a single Append() call.
4167 scoped_ptr<Cluster> cluster = GenerateCluster(0, 0, 4, true); 4305 scoped_ptr<Cluster> cluster = GenerateCluster(0, 0, 4, true);
4168 std::vector<uint8_t> data(cluster->data(), cluster->data() + cluster->size()); 4306 std::vector<uint8_t> data(cluster->data(), cluster->data() + cluster->size());
4169 data.insert(data.end(), kCuesHeader, kCuesHeader + sizeof(kCuesHeader)); 4307 data.insert(data.end(), kCuesHeader, kCuesHeader + sizeof(kCuesHeader));
4170 cluster = GenerateCluster(46, 66, 5, true); 4308 cluster = GenerateCluster(46, 66, 5, true);
4171 data.insert(data.end(), cluster->data(), cluster->data() + cluster->size()); 4309 data.insert(data.end(), cluster->data(), cluster->data() + cluster->size());
4172 AppendData(&*data.begin(), data.size()); 4310 AppendData(&*data.begin(), data.size());
4173 4311
4174 CheckExpectedRanges(kSourceId, "{ [0,115) }"); 4312 CheckExpectedRanges("{ [0,115) }");
4175 } 4313 }
4176 4314
4177 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { 4315 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) {
4178 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 4316 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
4179 4317
4180 AppendCluster(GenerateCluster(0, 0, 4)); 4318 AppendCluster(GenerateCluster(0, 0, 4));
4181 AppendData(kCuesHeader, sizeof(kCuesHeader)); 4319 AppendData(kCuesHeader, sizeof(kCuesHeader));
4182 AppendCluster(GenerateCluster(46, 66, 5)); 4320 AppendCluster(GenerateCluster(46, 66, 5));
4183 CheckExpectedRanges(kSourceId, "{ [0,115) }"); 4321 CheckExpectedRanges("{ [0,115) }");
4184 } 4322 }
4185 4323
4186 TEST_F(ChunkDemuxerTest, EvictCodedFramesTest) { 4324 TEST_F(ChunkDemuxerTest, EvictCodedFramesTest) {
4187 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 4325 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
4188 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 4326 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
4189 demuxer_->SetMemoryLimits(DemuxerStream::VIDEO, 15 * kBlockSize); 4327 demuxer_->SetMemoryLimits(DemuxerStream::VIDEO, 15 * kBlockSize);
4190 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 4328 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
4191 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 4329 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
4192 4330
4193 const char* kAudioStreamInfo = "0K 40K 80K 120K 160K 200K 240K 280K"; 4331 const char* kAudioStreamInfo = "0K 40K 80K 120K 160K 200K 240K 280K";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4226 // Given these numbers MSE GC will remove just one audio block (since current 4364 // Given these numbers MSE GC will remove just one audio block (since current
4227 // audio size is 80 bytes, new data is 28 bytes, we need to remove just one 10 4365 // audio size is 80 bytes, new data is 28 bytes, we need to remove just one 10
4228 // byte block to stay under 100 bytes memory limit after append 4366 // byte block to stay under 100 bytes memory limit after append
4229 // 80 - 10 + 28 = 98). 4367 // 80 - 10 + 28 = 98).
4230 // For video stream 150 + 52 = 202. Video limit is 150 bytes. We need to 4368 // For video stream 150 + 52 = 202. Video limit is 150 bytes. We need to
4231 // remove at least 6 blocks to stay under limit. 4369 // remove at least 6 blocks to stay under limit.
4232 CheckExpectedBuffers(audio_stream, "40K 80K 120K 160K 200K 240K 280K"); 4370 CheckExpectedBuffers(audio_stream, "40K 80K 120K 160K 200K 240K 280K");
4233 CheckExpectedBuffers(video_stream, "60K 70 80K 90 100K 110 120K 130 140K"); 4371 CheckExpectedBuffers(video_stream, "60K 70 80K 90 100K 110 120K 130 140K");
4234 } 4372 }
4235 4373
4374 TEST_F(ChunkDemuxerTest, SegmentMissingAudioFrame_AudioOnly) {
4375 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
4376 EXPECT_MEDIA_LOG(SegmentMissingFrames("audio"));
4377 AppendCluster(GenerateEmptyCluster(0));
4378 }
4379
4380 TEST_F(ChunkDemuxerTest, SegmentMissingVideoFrame_VideoOnly) {
4381 ASSERT_TRUE(InitDemuxer(HAS_VIDEO));
4382 EXPECT_MEDIA_LOG(SegmentMissingFrames("video"));
4383 AppendCluster(GenerateEmptyCluster(0));
4384 }
4385
4386 TEST_F(ChunkDemuxerTest, SegmentMissingAudioFrame_AudioVideo) {
4387 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
4388 EXPECT_MEDIA_LOG(SegmentMissingFrames("audio"));
4389 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 0, 10);
4390 }
4391
4392 TEST_F(ChunkDemuxerTest, SegmentMissingVideoFrame_AudioVideo) {
4393 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
4394 EXPECT_MEDIA_LOG(SegmentMissingFrames("video"));
4395 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 10);
4396 }
4397
4398 TEST_F(ChunkDemuxerTest, SegmentMissingAudioVideoFrames) {
4399 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
4400 EXPECT_MEDIA_LOG(SegmentMissingFrames("audio or video"));
4401 AppendCluster(GenerateEmptyCluster(0));
4402 }
4403
4236 } // namespace media 4404 } // namespace media
OLDNEW
« no previous file with comments | « media/base/stream_parser.h ('k') | media/filters/media_source_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698