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

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

Issue 196173002: MSE: Lift timestampOffset and appendWindow[Start,End] storage to WebSourceBufferImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 // Default cluster to append after kDefaultFirstCluster() 148 // Default cluster to append after kDefaultFirstCluster()
149 // has been appended. This cluster starts with blocks that 149 // has been appended. This cluster starts with blocks that
150 // have timestamps consistent with the end times of the blocks 150 // have timestamps consistent with the end times of the blocks
151 // in kDefaultFirstCluster() so that these two clusters represent 151 // in kDefaultFirstCluster() so that these two clusters represent
152 // a continuous region. 152 // a continuous region.
153 scoped_ptr<Cluster> kDefaultSecondCluster() { 153 scoped_ptr<Cluster> kDefaultSecondCluster() {
154 return GenerateCluster(46, 66, 5); 154 return GenerateCluster(46, 66, 5);
155 } 155 }
156 156
157 ChunkDemuxerTest() { 157 ChunkDemuxerTest()
158 : append_window_end_for_next_append_(kInfiniteDuration()) {
158 CreateNewDemuxer(); 159 CreateNewDemuxer();
159 } 160 }
160 161
161 void CreateNewDemuxer() { 162 void CreateNewDemuxer() {
162 base::Closure open_cb = 163 base::Closure open_cb =
163 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this)); 164 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this));
164 Demuxer::NeedKeyCB need_key_cb = 165 Demuxer::NeedKeyCB need_key_cb =
165 base::Bind(&ChunkDemuxerTest::DemuxerNeedKey, base::Unretained(this)); 166 base::Bind(&ChunkDemuxerTest::DemuxerNeedKey, base::Unretained(this));
166 demuxer_.reset(new ChunkDemuxer(open_cb, need_key_cb, 167 demuxer_.reset(new ChunkDemuxer(open_cb, need_key_cb,
167 base::Bind(&LogFunc))); 168 base::Bind(&LogFunc)));
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 } 391 }
391 AppendCluster(source_id, cb.Finish()); 392 AppendCluster(source_id, cb.Finish());
392 } 393 }
393 394
394 void AppendData(const std::string& source_id, 395 void AppendData(const std::string& source_id,
395 const uint8* data, size_t length) { 396 const uint8* data, size_t length) {
396 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); 397 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber());
397 398
398 // TODO(wolenetz): Test timestamp offset updating once "sequence" append 399 // TODO(wolenetz): Test timestamp offset updating once "sequence" append
399 // mode processing is implemented. See http://crbug.com/249422. 400 // mode processing is implemented. See http://crbug.com/249422.
400 demuxer_->AppendData(source_id, data, length, NULL); 401 demuxer_->AppendData(source_id, data, length,
402 append_window_start_for_next_append_,
403 append_window_end_for_next_append_,
404 &timestamp_offset_map_[source_id]);
401 } 405 }
402 406
403 void AppendDataInPieces(const uint8* data, size_t length) { 407 void AppendDataInPieces(const uint8* data, size_t length) {
404 AppendDataInPieces(data, length, 7); 408 AppendDataInPieces(data, length, 7);
405 } 409 }
406 410
407 void AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { 411 void AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) {
408 const uint8* start = data; 412 const uint8* start = data;
409 const uint8* end = data + length; 413 const uint8* end = data + length;
410 while (start < end) { 414 while (start < end) {
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 demuxer_->StartWaitingForSeek(seek_time); 939 demuxer_->StartWaitingForSeek(seek_time);
936 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); 940 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK));
937 message_loop_.RunUntilIdle(); 941 message_loop_.RunUntilIdle();
938 } 942 }
939 943
940 void MarkEndOfStream(PipelineStatus status) { 944 void MarkEndOfStream(PipelineStatus status) {
941 demuxer_->MarkEndOfStream(status); 945 demuxer_->MarkEndOfStream(status);
942 message_loop_.RunUntilIdle(); 946 message_loop_.RunUntilIdle();
943 } 947 }
944 948
949 bool SetTimestampOffset(const std::string& id,
950 base::TimeDelta timestamp_offset) {
951 if (demuxer_->IsParsingMediaSegment(id))
952 return false;
953
954 timestamp_offset_map_[id] = timestamp_offset;
955 return true;
956 }
957
945 base::MessageLoop message_loop_; 958 base::MessageLoop message_loop_;
946 MockDemuxerHost host_; 959 MockDemuxerHost host_;
947 960
948 scoped_ptr<ChunkDemuxer> demuxer_; 961 scoped_ptr<ChunkDemuxer> demuxer_;
949 962
963 base::TimeDelta append_window_start_for_next_append_;
964 base::TimeDelta append_window_end_for_next_append_;
wolenetz 2014/03/11 23:21:34 Note, I didn't see much gain by adding similar map
965
966 // Map of source id to timestamp offset to use for the next AppendData()
967 // operation for that source id.
968 std::map<std::string, base::TimeDelta> timestamp_offset_map_;
969
950 private: 970 private:
951 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); 971 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest);
952 }; 972 };
953 973
954 TEST_F(ChunkDemuxerTest, Init) { 974 TEST_F(ChunkDemuxerTest, Init) {
955 // Test no streams, audio-only, video-only, and audio & video scenarios. 975 // Test no streams, audio-only, video-only, and audio & video scenarios.
956 // Audio and video streams can be encrypted or not encrypted. 976 // Audio and video streams can be encrypted or not encrypted.
957 for (int i = 0; i < 16; i++) { 977 for (int i = 0; i < 16; i++) {
958 bool has_audio = (i & 0x1) != 0; 978 bool has_audio = (i & 0x1) != 0;
959 bool has_video = (i & 0x2) != 0; 979 bool has_video = (i & 0x2) != 0;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 AppendCluster(GenerateCluster(5000, 6)); 1232 AppendCluster(GenerateCluster(5000, 6));
1213 GenerateExpectedReads(5000, 6); 1233 GenerateExpectedReads(5000, 6);
1214 } 1234 }
1215 1235
1216 // Test the case where AppendData() is called before Init(). 1236 // Test the case where AppendData() is called before Init().
1217 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) { 1237 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) {
1218 scoped_ptr<uint8[]> info_tracks; 1238 scoped_ptr<uint8[]> info_tracks;
1219 int info_tracks_size = 0; 1239 int info_tracks_size = 0;
1220 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, 1240 CreateInitSegment(HAS_AUDIO | HAS_VIDEO,
1221 false, false, &info_tracks, &info_tracks_size); 1241 false, false, &info_tracks, &info_tracks_size);
1222 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, NULL); 1242 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size,
1243 append_window_start_for_next_append_,
1244 append_window_end_for_next_append_,
1245 &timestamp_offset_map_[kSourceId]);
1223 } 1246 }
1224 1247
1225 // Make sure Read() callbacks are dispatched with the proper data. 1248 // Make sure Read() callbacks are dispatched with the proper data.
1226 TEST_F(ChunkDemuxerTest, Read) { 1249 TEST_F(ChunkDemuxerTest, Read) {
1227 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1250 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1228 1251
1229 AppendCluster(kDefaultFirstCluster()); 1252 AppendCluster(kDefaultFirstCluster());
1230 1253
1231 bool audio_read_done = false; 1254 bool audio_read_done = false;
1232 bool video_read_done = false; 1255 bool video_read_done = false;
(...skipping 12 matching lines...) Expand all
1245 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1268 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1246 AppendCluster(kDefaultFirstCluster()); 1269 AppendCluster(kDefaultFirstCluster());
1247 AppendCluster(GenerateCluster(10, 4)); 1270 AppendCluster(GenerateCluster(10, 4));
1248 1271
1249 // Make sure that AppendCluster() does not fail with a cluster that has 1272 // Make sure that AppendCluster() does not fail with a cluster that has
1250 // overlaps with the previously appended cluster. 1273 // overlaps with the previously appended cluster.
1251 AppendCluster(GenerateCluster(5, 4)); 1274 AppendCluster(GenerateCluster(5, 4));
1252 1275
1253 // Verify that AppendData() can still accept more data. 1276 // Verify that AppendData() can still accept more data.
1254 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); 1277 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2));
1255 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(), NULL); 1278 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(),
1279 append_window_start_for_next_append_,
1280 append_window_end_for_next_append_,
1281 &timestamp_offset_map_[kSourceId]);
1256 } 1282 }
1257 1283
1258 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) { 1284 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) {
1259 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1285 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1260 AppendCluster(kDefaultFirstCluster()); 1286 AppendCluster(kDefaultFirstCluster());
1261 1287
1262 ClusterBuilder cb; 1288 ClusterBuilder cb;
1263 1289
1264 // Test the case where block timecodes are not monotonically 1290 // Test the case where block timecodes are not monotonically
1265 // increasing but stay above the cluster timecode. 1291 // increasing but stay above the cluster timecode.
1266 cb.SetClusterTimecode(5); 1292 cb.SetClusterTimecode(5);
1267 AddSimpleBlock(&cb, kAudioTrackNum, 5); 1293 AddSimpleBlock(&cb, kAudioTrackNum, 5);
1268 AddSimpleBlock(&cb, kVideoTrackNum, 10); 1294 AddSimpleBlock(&cb, kVideoTrackNum, 10);
1269 AddSimpleBlock(&cb, kAudioTrackNum, 7); 1295 AddSimpleBlock(&cb, kAudioTrackNum, 7);
1270 AddSimpleBlock(&cb, kVideoTrackNum, 15); 1296 AddSimpleBlock(&cb, kVideoTrackNum, 15);
1271 1297
1272 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1298 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1273 AppendCluster(cb.Finish()); 1299 AppendCluster(cb.Finish());
1274 1300
1275 // Verify that AppendData() ignores data after the error. 1301 // Verify that AppendData() ignores data after the error.
1276 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); 1302 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2));
1277 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), NULL); 1303 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(),
1304 append_window_start_for_next_append_,
1305 append_window_end_for_next_append_,
1306 &timestamp_offset_map_[kSourceId]);
1278 } 1307 }
1279 1308
1280 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) { 1309 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) {
1281 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1310 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1282 AppendCluster(kDefaultFirstCluster()); 1311 AppendCluster(kDefaultFirstCluster());
1283 1312
1284 ClusterBuilder cb; 1313 ClusterBuilder cb;
1285 1314
1286 // Test timecodes going backwards and including values less than the cluster 1315 // Test timecodes going backwards and including values less than the cluster
1287 // timecode. 1316 // timecode.
1288 cb.SetClusterTimecode(5); 1317 cb.SetClusterTimecode(5);
1289 AddSimpleBlock(&cb, kAudioTrackNum, 5); 1318 AddSimpleBlock(&cb, kAudioTrackNum, 5);
1290 AddSimpleBlock(&cb, kVideoTrackNum, 5); 1319 AddSimpleBlock(&cb, kVideoTrackNum, 5);
1291 AddSimpleBlock(&cb, kAudioTrackNum, 3); 1320 AddSimpleBlock(&cb, kAudioTrackNum, 3);
1292 AddSimpleBlock(&cb, kVideoTrackNum, 3); 1321 AddSimpleBlock(&cb, kVideoTrackNum, 3);
1293 1322
1294 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1323 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1295 AppendCluster(cb.Finish()); 1324 AppendCluster(cb.Finish());
1296 1325
1297 // Verify that AppendData() ignores data after the error. 1326 // Verify that AppendData() ignores data after the error.
1298 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); 1327 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2));
1299 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), NULL); 1328 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(),
1329 append_window_start_for_next_append_,
1330 append_window_end_for_next_append_,
1331 &timestamp_offset_map_[kSourceId]);
1300 } 1332 }
1301 1333
1302 1334
1303 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) { 1335 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) {
1304 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1336 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1305 AppendCluster(kDefaultFirstCluster()); 1337 AppendCluster(kDefaultFirstCluster());
1306 1338
1307 ClusterBuilder cb; 1339 ClusterBuilder cb;
1308 1340
1309 // Test monotonic increasing timestamps on a per stream 1341 // Test monotonic increasing timestamps on a per stream
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 1778
1747 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) { 1779 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) {
1748 EXPECT_CALL(*this, DemuxerOpened()); 1780 EXPECT_CALL(*this, DemuxerOpened());
1749 demuxer_->Initialize( 1781 demuxer_->Initialize(
1750 &host_, CreateInitDoneCB( 1782 &host_, CreateInitDoneCB(
1751 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1783 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1752 1784
1753 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); 1785 ASSERT_EQ(AddId(), ChunkDemuxer::kOk);
1754 1786
1755 uint8 tmp = 0; 1787 uint8 tmp = 0;
1756 demuxer_->AppendData(kSourceId, &tmp, 1, NULL); 1788 demuxer_->AppendData(kSourceId, &tmp, 1,
1789 append_window_start_for_next_append_,
1790 append_window_end_for_next_append_,
1791 &timestamp_offset_map_[kSourceId]);
1757 } 1792 }
1758 1793
1759 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) { 1794 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) {
1760 EXPECT_CALL(*this, DemuxerOpened()); 1795 EXPECT_CALL(*this, DemuxerOpened());
1761 demuxer_->Initialize( 1796 demuxer_->Initialize(
1762 &host_, CreateInitDoneCB(kNoTimestamp(), 1797 &host_, CreateInitDoneCB(kNoTimestamp(),
1763 DEMUXER_ERROR_COULD_NOT_OPEN), true); 1798 DEMUXER_ERROR_COULD_NOT_OPEN), true);
1764 1799
1765 std::vector<std::string> codecs(1); 1800 std::vector<std::string> codecs(1);
1766 codecs[0] = "vorbis"; 1801 codecs[0] = "vorbis";
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
2577 Seek(base::TimeDelta::FromMilliseconds(801)); 2612 Seek(base::TimeDelta::FromMilliseconds(801));
2578 2613
2579 // Verify that no config change is signalled. 2614 // Verify that no config change is signalled.
2580 ExpectRead(DemuxerStream::VIDEO, 801); 2615 ExpectRead(DemuxerStream::VIDEO, 801);
2581 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config())); 2616 ASSERT_TRUE(video_config_1.Matches(video->video_decoder_config()));
2582 } 2617 }
2583 2618
2584 TEST_F(ChunkDemuxerTest, TimestampPositiveOffset) { 2619 TEST_F(ChunkDemuxerTest, TimestampPositiveOffset) {
2585 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2620 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2586 2621
2587 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2622 ASSERT_TRUE(SetTimestampOffset(kSourceId, base::TimeDelta::FromSeconds(30)));
2588 kSourceId, base::TimeDelta::FromSeconds(30)));
2589 AppendCluster(GenerateCluster(0, 2)); 2623 AppendCluster(GenerateCluster(0, 2));
2590 2624
2591 Seek(base::TimeDelta::FromMilliseconds(30000)); 2625 Seek(base::TimeDelta::FromMilliseconds(30000));
2592 2626
2593 GenerateExpectedReads(30000, 2); 2627 GenerateExpectedReads(30000, 2);
2594 } 2628 }
2595 2629
2596 TEST_F(ChunkDemuxerTest, TimestampNegativeOffset) { 2630 TEST_F(ChunkDemuxerTest, TimestampNegativeOffset) {
2597 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2631 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2598 2632
2599 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2633 ASSERT_TRUE(SetTimestampOffset(kSourceId, base::TimeDelta::FromSeconds(-1)));
2600 kSourceId, base::TimeDelta::FromSeconds(-1)));
2601 AppendCluster(GenerateCluster(1000, 2)); 2634 AppendCluster(GenerateCluster(1000, 2));
2602 2635
2603 GenerateExpectedReads(0, 2); 2636 GenerateExpectedReads(0, 2);
2604 } 2637 }
2605 2638
2606 TEST_F(ChunkDemuxerTest, TimestampOffsetSeparateStreams) { 2639 TEST_F(ChunkDemuxerTest, TimestampOffsetSeparateStreams) {
2607 std::string audio_id = "audio1"; 2640 std::string audio_id = "audio1";
2608 std::string video_id = "video1"; 2641 std::string video_id = "video1";
2609 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); 2642 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
2610 2643
2611 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2644 ASSERT_TRUE(SetTimestampOffset(
2612 audio_id, base::TimeDelta::FromMilliseconds(-2500))); 2645 audio_id, base::TimeDelta::FromMilliseconds(-2500)));
2613 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2646 ASSERT_TRUE(SetTimestampOffset(
2614 video_id, base::TimeDelta::FromMilliseconds(-2500))); 2647 video_id, base::TimeDelta::FromMilliseconds(-2500)));
2615 AppendCluster(audio_id, GenerateSingleStreamCluster(2500, 2648 AppendCluster(audio_id, GenerateSingleStreamCluster(2500,
2616 2500 + kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); 2649 2500 + kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration));
2617 AppendCluster(video_id, GenerateSingleStreamCluster(2500, 2650 AppendCluster(video_id, GenerateSingleStreamCluster(2500,
2618 2500 + kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); 2651 2500 + kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration));
2619 GenerateAudioStreamExpectedReads(0, 4); 2652 GenerateAudioStreamExpectedReads(0, 4);
2620 GenerateVideoStreamExpectedReads(0, 4); 2653 GenerateVideoStreamExpectedReads(0, 4);
2621 2654
2622 Seek(base::TimeDelta::FromMilliseconds(27300)); 2655 Seek(base::TimeDelta::FromMilliseconds(27300));
2623 2656
2624 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2657 ASSERT_TRUE(SetTimestampOffset(
2625 audio_id, base::TimeDelta::FromMilliseconds(27300))); 2658 audio_id, base::TimeDelta::FromMilliseconds(27300)));
2626 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2659 ASSERT_TRUE(SetTimestampOffset(
2627 video_id, base::TimeDelta::FromMilliseconds(27300))); 2660 video_id, base::TimeDelta::FromMilliseconds(27300)));
2628 AppendCluster(audio_id, GenerateSingleStreamCluster( 2661 AppendCluster(audio_id, GenerateSingleStreamCluster(
2629 0, kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration)); 2662 0, kAudioBlockDuration * 4, kAudioTrackNum, kAudioBlockDuration));
2630 AppendCluster(video_id, GenerateSingleStreamCluster( 2663 AppendCluster(video_id, GenerateSingleStreamCluster(
2631 0, kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration)); 2664 0, kVideoBlockDuration * 4, kVideoTrackNum, kVideoBlockDuration));
2632 GenerateVideoStreamExpectedReads(27300, 4); 2665 GenerateVideoStreamExpectedReads(27300, 4);
2633 GenerateAudioStreamExpectedReads(27300, 4); 2666 GenerateAudioStreamExpectedReads(27300, 4);
2634 } 2667 }
2635 2668
2636 TEST_F(ChunkDemuxerTest, TimestampOffsetMidMediaSegment) { 2669 TEST_F(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) {
2637 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2670 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2638 2671
2639 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); 2672 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2);
2640 // Append only part of the cluster data. 2673 // Append only part of the cluster data.
2641 AppendData(cluster->data(), cluster->size() - 13); 2674 AppendData(cluster->data(), cluster->size() - 13);
2642 2675
2643 // Setting a timestamp should fail because we're in the middle of a cluster. 2676 // Confirm we're in the middle of parsing a media segment.
2644 ASSERT_FALSE(demuxer_->SetTimestampOffset( 2677 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId));
2645 kSourceId, base::TimeDelta::FromSeconds(25)));
2646 2678
2647 demuxer_->Abort(kSourceId); 2679 demuxer_->Abort(kSourceId);
2648 // After Abort(), setting a timestamp should succeed since we're no longer 2680 // After Abort(), parsing should no longer be in the middle of a media
2649 // in the middle of a cluster 2681 // segment.
2650 ASSERT_TRUE(demuxer_->SetTimestampOffset( 2682 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId));
2651 kSourceId, base::TimeDelta::FromSeconds(25)));
2652 } 2683 }
2653 2684
2654 TEST_F(ChunkDemuxerTest, WebMParsingMediaSegmentDetection) { 2685 TEST_F(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) {
2655 // TODO(wolenetz): Also test 'unknown' sized clusters. 2686 // TODO(wolenetz): Also test 'unknown' sized clusters.
2656 // See http://crbug.com/335676. 2687 // See http://crbug.com/335676.
2657 const uint8 kBuffer[] = { 2688 const uint8 kBuffer[] = {
2658 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) 2689 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3)
2659 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) 2690 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1)
2660 }; 2691 };
2661 2692
2662 // Setting timestamp offset or append mode is allowed only while not 2693 // This array indicates expected return value of IsParsingMediaSegment()
2663 // parsing a media segment. This array indicates whether or not these 2694 // following each incrementally appended byte in |kBuffer|.
2664 // operations are allowed following each incrementally appended byte in
2665 // |kBuffer|.
2666 const bool kExpectedReturnValues[] = { 2695 const bool kExpectedReturnValues[] = {
2667 true, true, true, true, false, 2696 false, false, false, false, true,
2668 false, false, true, 2697 true, true, false,
2669 }; 2698 };
2670 2699
2671 COMPILE_ASSERT(arraysize(kBuffer) == arraysize(kExpectedReturnValues), 2700 COMPILE_ASSERT(arraysize(kBuffer) == arraysize(kExpectedReturnValues),
2672 test_arrays_out_of_sync); 2701 test_arrays_out_of_sync);
2673 COMPILE_ASSERT(arraysize(kBuffer) == sizeof(kBuffer), not_one_byte_per_index); 2702 COMPILE_ASSERT(arraysize(kBuffer) == sizeof(kBuffer), not_one_byte_per_index);
2674 2703
2675 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2704 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2676 2705
2677 for (size_t i = 0; i < sizeof(kBuffer); i++) { 2706 for (size_t i = 0; i < sizeof(kBuffer); i++) {
2678 DVLOG(3) << "Appending and testing index " << i; 2707 DVLOG(3) << "Appending and testing index " << i;
2679 AppendData(kBuffer + i, 1); 2708 AppendData(kBuffer + i, 1);
2680 bool expected_return_value = kExpectedReturnValues[i]; 2709 bool expected_return_value = kExpectedReturnValues[i];
2681 EXPECT_EQ(expected_return_value, demuxer_->SetTimestampOffset( 2710 EXPECT_EQ(expected_return_value,
2682 kSourceId, base::TimeDelta::FromSeconds(25))); 2711 demuxer_->IsParsingMediaSegment(kSourceId));
2683 EXPECT_EQ(expected_return_value, demuxer_->SetSequenceMode(
2684 kSourceId, true));
2685 EXPECT_EQ(expected_return_value, demuxer_->SetSequenceMode(
2686 kSourceId, false));
2687 } 2712 }
2688 } 2713 }
2689 2714
2690 TEST_F(ChunkDemuxerTest, SetSequenceModeMidMediaSegment) {
2691 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2692
2693 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2);
2694 // Append only part of the cluster data.
2695 AppendData(cluster->data(), cluster->size() - 13);
2696
2697 // Setting append mode should fail because we're in the middle of a cluster.
2698 ASSERT_FALSE(demuxer_->SetSequenceMode(kSourceId, true));
2699 ASSERT_FALSE(demuxer_->SetSequenceMode(kSourceId, false));
2700
2701 demuxer_->Abort(kSourceId);
2702 // After Abort(), setting append mode should succeed since we're no longer
2703 // in the middle of a cluster.
2704 ASSERT_TRUE(demuxer_->SetSequenceMode(kSourceId, true));
2705 ASSERT_TRUE(demuxer_->SetSequenceMode(kSourceId, false));
2706 }
2707
2708 TEST_F(ChunkDemuxerTest, DurationChange) { 2715 TEST_F(ChunkDemuxerTest, DurationChange) {
2709 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2716 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2710 const int kStreamDuration = kDefaultDuration().InMilliseconds(); 2717 const int kStreamDuration = kDefaultDuration().InMilliseconds();
2711 2718
2712 // Add data leading up to the currently set duration. 2719 // Add data leading up to the currently set duration.
2713 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration, 2720 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration,
2714 kStreamDuration - kVideoBlockDuration, 2721 kStreamDuration - kVideoBlockDuration,
2715 2)); 2722 2));
2716 2723
2717 CheckExpectedRanges(kSourceId, "{ [201191,201224) }"); 2724 CheckExpectedRanges(kSourceId, "{ [201191,201224) }");
(...skipping 12 matching lines...) Expand all
2730 kStreamDuration + kVideoBlockDuration, 2737 kStreamDuration + kVideoBlockDuration,
2731 2)); 2738 2));
2732 2739
2733 // See that the range has increased appropriately. 2740 // See that the range has increased appropriately.
2734 CheckExpectedRanges(kSourceId, "{ [201191,201270) }"); 2741 CheckExpectedRanges(kSourceId, "{ [201191,201270) }");
2735 } 2742 }
2736 2743
2737 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) { 2744 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) {
2738 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2745 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2739 2746
2740 ASSERT_TRUE(demuxer_->SetTimestampOffset(kSourceId, kDefaultDuration())); 2747 ASSERT_TRUE(SetTimestampOffset(kSourceId, kDefaultDuration()));
2741 2748
2742 EXPECT_CALL(host_, SetDuration( 2749 EXPECT_CALL(host_, SetDuration(
2743 kDefaultDuration() + base::TimeDelta::FromMilliseconds( 2750 kDefaultDuration() + base::TimeDelta::FromMilliseconds(
2744 kAudioBlockDuration * 2))); 2751 kAudioBlockDuration * 2)));
2745 AppendCluster(GenerateCluster(0, 4)); 2752 AppendCluster(GenerateCluster(0, 4));
2746 } 2753 }
2747 2754
2748 TEST_F(ChunkDemuxerTest, EndOfStreamTruncateDuration) { 2755 TEST_F(ChunkDemuxerTest, EndOfStreamTruncateDuration) {
2749 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2756 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2750 2757
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
2937 2944
2938 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(0), 2945 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(0),
2939 base::TimeDelta::FromMilliseconds(1)); 2946 base::TimeDelta::FromMilliseconds(1));
2940 } 2947 }
2941 2948
2942 TEST_F(ChunkDemuxerTest, AppendWindow_Video) { 2949 TEST_F(ChunkDemuxerTest, AppendWindow_Video) {
2943 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); 2950 ASSERT_TRUE(InitDemuxer(HAS_VIDEO));
2944 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); 2951 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO);
2945 2952
2946 // Set the append window to [20,280). 2953 // Set the append window to [20,280).
2947 demuxer_->SetAppendWindowStart(kSourceId, 2954 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
2948 base::TimeDelta::FromMilliseconds(20)); 2955 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
2949 demuxer_->SetAppendWindowEnd(kSourceId,
2950 base::TimeDelta::FromMilliseconds(280));
2951 2956
2952 // Append a cluster that starts before and ends after the append window. 2957 // Append a cluster that starts before and ends after the append window.
2953 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 2958 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
2954 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); 2959 "0K 30 60 90 120K 150 180 210 240K 270 300 330K");
2955 2960
2956 // Verify that GOPs that start outside the window are not included 2961 // Verify that GOPs that start outside the window are not included
2957 // in the buffer. Also verify that buffers that start inside the 2962 // in the buffer. Also verify that buffers that start inside the
2958 // window and extend beyond the end of the window are included. 2963 // window and extend beyond the end of the window are included.
2959 CheckExpectedRanges(kSourceId, "{ [120,300) }"); 2964 CheckExpectedRanges(kSourceId, "{ [120,300) }");
2960 CheckExpectedBuffers(stream, "120 150 180 210 240 270"); 2965 CheckExpectedBuffers(stream, "120 150 180 210 240 270");
2961 2966
2962 // Extend the append window to [20,650). 2967 // Extend the append window to [20,650).
2963 demuxer_->SetAppendWindowEnd(kSourceId, 2968 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
2964 base::TimeDelta::FromMilliseconds(650));
2965 2969
2966 // Append more data and verify that adding buffers start at the next 2970 // Append more data and verify that adding buffers start at the next
2967 // keyframe. 2971 // keyframe.
2968 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 2972 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
2969 "360 390 420K 450 480 510 540K 570 600 630K"); 2973 "360 390 420K 450 480 510 540K 570 600 630K");
2970 CheckExpectedRanges(kSourceId, "{ [120,300) [420,660) }"); 2974 CheckExpectedRanges(kSourceId, "{ [120,300) [420,660) }");
2971 } 2975 }
2972 2976
2973 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) { 2977 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) {
2974 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 2978 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
2975 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 2979 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
2976 2980
2977 // Set the append window to [20,280). 2981 // Set the append window to [20,280).
2978 demuxer_->SetAppendWindowStart(kSourceId, 2982 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
2979 base::TimeDelta::FromMilliseconds(20)); 2983 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
2980 demuxer_->SetAppendWindowEnd(kSourceId,
2981 base::TimeDelta::FromMilliseconds(280));
2982 2984
2983 // Append a cluster that starts before and ends after the append window. 2985 // Append a cluster that starts before and ends after the append window.
2984 AppendSingleStreamCluster( 2986 AppendSingleStreamCluster(
2985 kSourceId, kAudioTrackNum, 2987 kSourceId, kAudioTrackNum,
2986 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); 2988 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K");
2987 2989
2988 // Verify that frames that start outside the window are not included 2990 // Verify that frames that start outside the window are not included
2989 // in the buffer. Also verify that buffers that start inside the 2991 // in the buffer. Also verify that buffers that start inside the
2990 // window and extend beyond the end of the window are included. 2992 // window and extend beyond the end of the window are included.
2991 CheckExpectedRanges(kSourceId, "{ [30,300) }"); 2993 CheckExpectedRanges(kSourceId, "{ [30,300) }");
2992 CheckExpectedBuffers(stream, "30 60 90 120 150 180 210 240 270"); 2994 CheckExpectedBuffers(stream, "30 60 90 120 150 180 210 240 270");
2993 2995
2994 // Extend the append window to [20,650). 2996 // Extend the append window to [20,650).
2995 demuxer_->SetAppendWindowEnd(kSourceId, 2997 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
2996 base::TimeDelta::FromMilliseconds(650));
2997 2998
2998 // Append more data and verify that a new range is created. 2999 // Append more data and verify that a new range is created.
2999 AppendSingleStreamCluster( 3000 AppendSingleStreamCluster(
3000 kSourceId, kAudioTrackNum, 3001 kSourceId, kAudioTrackNum,
3001 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); 3002 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K");
3002 CheckExpectedRanges(kSourceId, "{ [30,300) [360,660) }"); 3003 CheckExpectedRanges(kSourceId, "{ [30,300) [360,660) }");
3003 } 3004 }
3004 3005
3005 TEST_F(ChunkDemuxerTest, AppendWindow_Text) { 3006 TEST_F(ChunkDemuxerTest, AppendWindow_Text) {
3006 DemuxerStream* text_stream = NULL; 3007 DemuxerStream* text_stream = NULL;
3007 EXPECT_CALL(host_, AddTextStream(_, _)) 3008 EXPECT_CALL(host_, AddTextStream(_, _))
3008 .WillOnce(SaveArg<0>(&text_stream)); 3009 .WillOnce(SaveArg<0>(&text_stream));
3009 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); 3010 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT));
3010 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3011 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3011 3012
3012 // Set the append window to [20,280). 3013 // Set the append window to [20,280).
3013 demuxer_->SetAppendWindowStart(kSourceId, 3014 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
3014 base::TimeDelta::FromMilliseconds(20)); 3015 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3015 demuxer_->SetAppendWindowEnd(kSourceId,
3016 base::TimeDelta::FromMilliseconds(280));
3017 3016
3018 // Append a cluster that starts before and ends after the append 3017 // Append a cluster that starts before and ends after the append
3019 // window. 3018 // window.
3020 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3019 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3021 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); 3020 "0K 30 60 90 120K 150 180 210 240K 270 300 330K");
3022 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K 200K 300K"); 3021 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K 200K 300K");
3023 3022
3024 // Verify that text cues that start outside the window are not included 3023 // Verify that text cues that start outside the window are not included
3025 // in the buffer. Also verify that cues that extend beyond the 3024 // in the buffer. Also verify that cues that extend beyond the
3026 // window are included. 3025 // window are included.
3027 CheckExpectedRanges(kSourceId, "{ [120,300) }"); 3026 CheckExpectedRanges(kSourceId, "{ [120,300) }");
3028 CheckExpectedBuffers(video_stream, "120 150 180 210 240 270"); 3027 CheckExpectedBuffers(video_stream, "120 150 180 210 240 270");
3029 CheckExpectedBuffers(text_stream, "100 200"); 3028 CheckExpectedBuffers(text_stream, "100 200");
3030 3029
3031 // Extend the append window to [20,650). 3030 // Extend the append window to [20,650).
3032 demuxer_->SetAppendWindowEnd(kSourceId, 3031 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3033 base::TimeDelta::FromMilliseconds(650));
3034 3032
3035 // Append more data and verify that a new range is created. 3033 // Append more data and verify that a new range is created.
3036 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3034 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3037 "360 390 420K 450 480 510 540K 570 600 630K"); 3035 "360 390 420K 450 480 510 540K 570 600 630K");
3038 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "400K 500K 600K 700K"); 3036 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "400K 500K 600K 700K");
3039 CheckExpectedRanges(kSourceId, "{ [120,300) [420,660) }"); 3037 CheckExpectedRanges(kSourceId, "{ [120,300) [420,660) }");
3040 3038
3041 // Seek to the new range and verify that the expected buffers are returned. 3039 // Seek to the new range and verify that the expected buffers are returned.
3042 Seek(base::TimeDelta::FromMilliseconds(420)); 3040 Seek(base::TimeDelta::FromMilliseconds(420));
3043 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600 630"); 3041 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600 630");
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
3144 // NOTE: we start at 175 here because the buffer at 125 was returned 3142 // NOTE: we start at 175 here because the buffer at 125 was returned
3145 // to the pending read initiated above. 3143 // to the pending read initiated above.
3146 CheckExpectedBuffers(text_stream, "175 225"); 3144 CheckExpectedBuffers(text_stream, "175 225");
3147 3145
3148 // Verify that audio & video streams contiue to return expected values. 3146 // Verify that audio & video streams contiue to return expected values.
3149 CheckExpectedBuffers(audio_stream, "160 180"); 3147 CheckExpectedBuffers(audio_stream, "160 180");
3150 CheckExpectedBuffers(video_stream, "180 210"); 3148 CheckExpectedBuffers(video_stream, "180 210");
3151 } 3149 }
3152 3150
3153 } // namespace media 3151 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698