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

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: 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
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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "media/base/audio_decoder_config.h" 18 #include "media/base/audio_decoder_config.h"
19 #include "media/base/decoder_buffer.h" 19 #include "media/base/decoder_buffer.h"
20 #include "media/base/decrypt_config.h" 20 #include "media/base/decrypt_config.h"
21 #include "media/base/media_log.h"
22 #include "media/base/mock_demuxer_host.h" 21 #include "media/base/mock_demuxer_host.h"
22 #include "media/base/mock_media_log.h"
23 #include "media/base/test_data_util.h" 23 #include "media/base/test_data_util.h"
24 #include "media/base/test_helpers.h" 24 #include "media/base/test_helpers.h"
25 #include "media/base/timestamp_constants.h" 25 #include "media/base/timestamp_constants.h"
26 #include "media/formats/webm/cluster_builder.h" 26 #include "media/formats/webm/cluster_builder.h"
27 #include "media/formats/webm/webm_constants.h" 27 #include "media/formats/webm/webm_constants.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 29
30 using ::testing::AnyNumber; 30 using ::testing::AnyNumber;
31 using ::testing::Exactly; 31 using ::testing::Exactly;
32 using ::testing::InSequence; 32 using ::testing::InSequence;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 } 110 }
111 111
112 MATCHER_P(HasTimestamp, timestamp_in_ms, "") { 112 MATCHER_P(HasTimestamp, timestamp_in_ms, "") {
113 return arg.get() && !arg->end_of_stream() && 113 return arg.get() && !arg->end_of_stream() &&
114 arg->timestamp().InMilliseconds() == timestamp_in_ms; 114 arg->timestamp().InMilliseconds() == timestamp_in_ms;
115 } 115 }
116 116
117 MATCHER(IsEndOfStream, "") { return arg.get() && arg->end_of_stream(); } 117 MATCHER(IsEndOfStream, "") { return arg.get() && arg->end_of_stream(); }
118 118
119 MATCHER_P(SegmentMissingFrames, frame_types_string, "") {
120 return CONTAINS_STRING(
121 arg, "Media segment did not contain any " +
122 std::string(frame_types_string) +
123 " coded frames, mismatching initialization segment");
124 }
125
119 static void OnReadDone(const base::TimeDelta& expected_time, 126 static void OnReadDone(const base::TimeDelta& expected_time,
120 bool* called, 127 bool* called,
121 DemuxerStream::Status status, 128 DemuxerStream::Status status,
122 const scoped_refptr<DecoderBuffer>& buffer) { 129 const scoped_refptr<DecoderBuffer>& buffer) {
123 EXPECT_EQ(status, DemuxerStream::kOk); 130 EXPECT_EQ(status, DemuxerStream::kOk);
124 EXPECT_EQ(expected_time, buffer->timestamp()); 131 EXPECT_EQ(expected_time, buffer->timestamp());
125 *called = true; 132 *called = true;
126 } 133 }
127 134
128 static void OnReadDone_AbortExpected( 135 static void OnReadDone_AbortExpected(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 base::Bind(&ChunkDemuxerTest::InitSegmentReceived, 181 base::Bind(&ChunkDemuxerTest::InitSegmentReceived,
175 base::Unretained(this)); 182 base::Unretained(this));
176 CreateNewDemuxer(); 183 CreateNewDemuxer();
177 } 184 }
178 185
179 void CreateNewDemuxer() { 186 void CreateNewDemuxer() {
180 base::Closure open_cb = 187 base::Closure open_cb =
181 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this)); 188 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this));
182 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind( 189 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind(
183 &ChunkDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this)); 190 &ChunkDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this));
184 demuxer_.reset(new ChunkDemuxer(open_cb, encrypted_media_init_data_cb, 191 demuxer_.reset(new ChunkDemuxer(
185 scoped_refptr<MediaLog>(new MediaLog()), 192 open_cb, encrypted_media_init_data_cb,
186 true)); 193 scoped_refptr<MockMediaLog>(new MockMediaLog()), true));
194
195 // BIG TODO start here: use strick mock media log and verify the new media
196 // logs (and any pre-existing ones...)
187 } 197 }
188 198
189 virtual ~ChunkDemuxerTest() { 199 virtual ~ChunkDemuxerTest() {
190 ShutdownDemuxer(); 200 ShutdownDemuxer();
191 } 201 }
192 202
193 void CreateInitSegment(int stream_flags, 203 void CreateInitSegment(int stream_flags,
194 bool is_audio_encrypted, 204 bool is_audio_encrypted,
195 bool is_video_encrypted, 205 bool is_video_encrypted,
196 scoped_ptr<uint8_t[]>* buffer, 206 scoped_ptr<uint8_t[]>* buffer,
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 444 }
435 }; 445 };
436 446
437 // |track_number| - The track number to place in 447 // |track_number| - The track number to place in
438 // |block_descriptions| - A space delimited string of block info that 448 // |block_descriptions| - A space delimited string of block info that
439 // is used to populate |blocks|. Each block info has a timestamp in 449 // is used to populate |blocks|. Each block info has a timestamp in
440 // milliseconds and optionally followed by a 'K' to indicate that a block 450 // milliseconds and optionally followed by a 'K' to indicate that a block
441 // should be marked as a key frame. For example "0K 30 60" should populate 451 // should be marked as a key frame. For example "0K 30 60" should populate
442 // |blocks| with 3 BlockInfo objects: a key frame with timestamp 0 and 2 452 // |blocks| with 3 BlockInfo objects: a key frame with timestamp 0 and 2
443 // non-key-frames at 30ms and 60ms. 453 // non-key-frames at 30ms and 60ms.
454 // Every block will be a SimpleBlock, with the exception that the last block
455 // may have an optional duration delimited with a 'D' and appended to the
456 // block info timestamp, prior to the optional keyframe 'K'. For example "0K
457 // 30 60D10K" indicates that the last block will be a keyframe BlockGroup
458 // with duration 10ms.
444 void ParseBlockDescriptions(int track_number, 459 void ParseBlockDescriptions(int track_number,
445 const std::string block_descriptions, 460 const std::string block_descriptions,
446 std::vector<BlockInfo>* blocks) { 461 std::vector<BlockInfo>* blocks) {
447 std::vector<std::string> timestamps = base::SplitString( 462 std::vector<std::string> timestamps = base::SplitString(
448 block_descriptions, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 463 block_descriptions, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
449 464
450 for (size_t i = 0; i < timestamps.size(); ++i) { 465 for (size_t i = 0; i < timestamps.size(); ++i) {
451 std::string timestamp_str = timestamps[i]; 466 std::string timestamp_str = timestamps[i];
452 BlockInfo block_info; 467 BlockInfo block_info;
453 block_info.track_number = track_number; 468 block_info.track_number = track_number;
454 block_info.flags = 0; 469 block_info.flags = 0;
455 block_info.duration = 0; 470 block_info.duration = 0;
456 471
457 if (base::EndsWith(timestamp_str, "K", base::CompareCase::SENSITIVE)) { 472 if (base::EndsWith(timestamp_str, "K", base::CompareCase::SENSITIVE)) {
458 block_info.flags = kWebMFlagKeyframe; 473 block_info.flags = kWebMFlagKeyframe;
459 // Remove the "K" off of the token. 474 // Remove the "K" off of the token.
460 timestamp_str = timestamp_str.substr(0, timestamps[i].length() - 1); 475 timestamp_str = timestamp_str.substr(0, timestamps[i].length() - 1);
461 } 476 }
477
478 size_t duration_pos = timestamp_str.find('D');
479 const bool explicit_duration = duration_pos != std::string::npos;
480 const bool is_last_block = i == timestamps.size() - 1;
481 CHECK((!explicit_duration && !is_last_block) || is_last_block);
chcunningham 2016/01/07 22:23:56 I *think* you're trying to assert that (explicit
wolenetz 2016/01/07 22:37:09 Correct.
wolenetz 2016/01/16 01:23:35 Fixed already in landed prereq CL https://coderevi
482 if (explicit_duration) {
483 CHECK(base::StringToInt(timestamp_str.substr(duration_pos + 1),
484 &block_info.duration));
485 timestamp_str = timestamp_str.substr(0, duration_pos);
486 }
487
462 CHECK(base::StringToInt(timestamp_str, &block_info.timestamp_in_ms)); 488 CHECK(base::StringToInt(timestamp_str, &block_info.timestamp_in_ms));
463 489
464 if (track_number == kTextTrackNum || 490 if (track_number == kTextTrackNum ||
465 track_number == kAlternateTextTrackNum) { 491 track_number == kAlternateTextTrackNum) {
466 block_info.duration = kTextBlockDuration; 492 block_info.duration = kTextBlockDuration;
467 ASSERT_EQ(kWebMFlagKeyframe, block_info.flags) 493 ASSERT_EQ(kWebMFlagKeyframe, block_info.flags)
468 << "Text block with timestamp " << block_info.timestamp_in_ms 494 << "Text block with timestamp " << block_info.timestamp_in_ms
469 << " was not marked as a key frame." 495 << " was not marked as a key frame."
470 << " All text blocks must be key frames"; 496 << " All text blocks must be key frames";
471 } 497 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 for (int i = 0; i < garbage_cluster_size; ++i) 661 for (int i = 0; i < garbage_cluster_size; ++i)
636 garbage_cluster[i] = i; 662 garbage_cluster[i] = i;
637 AppendData(garbage_cluster.get(), garbage_cluster_size); 663 AppendData(garbage_cluster.get(), garbage_cluster_size);
638 } 664 }
639 665
640 void InitDoneCalled(PipelineStatus expected_status, 666 void InitDoneCalled(PipelineStatus expected_status,
641 PipelineStatus status) { 667 PipelineStatus status) {
642 EXPECT_EQ(status, expected_status); 668 EXPECT_EQ(status, expected_status);
643 } 669 }
644 670
645 void AppendEmptyCluster(int timecode) {
646 AppendCluster(GenerateEmptyCluster(timecode));
647 }
648
649 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration, 671 PipelineStatusCB CreateInitDoneCB(const base::TimeDelta& expected_duration,
650 PipelineStatus expected_status) { 672 PipelineStatus expected_status) {
651 if (expected_duration != kNoTimestamp()) 673 if (expected_duration != kNoTimestamp())
652 EXPECT_CALL(host_, SetDuration(expected_duration)); 674 EXPECT_CALL(host_, SetDuration(expected_duration));
653 return CreateInitDoneCB(expected_status); 675 return CreateInitDoneCB(expected_status);
654 } 676 }
655 677
656 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) { 678 PipelineStatusCB CreateInitDoneCB(PipelineStatus expected_status) {
657 return base::Bind(&ChunkDemuxerTest::InitDoneCalled, 679 return base::Bind(&ChunkDemuxerTest::InitDoneCalled,
658 base::Unretained(this), 680 base::Unretained(this),
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 789
768 // Append the whole bear1 file. 790 // Append the whole bear1 file.
769 // Expect duration adjustment since actual duration differs slightly from 791 // Expect duration adjustment since actual duration differs slightly from
770 // duration in the init segment. 792 // duration in the init segment.
771 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746))); 793 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746)));
772 AppendData(bear1->data(), bear1->data_size()); 794 AppendData(bear1->data(), bear1->data_size());
773 // Last audio frame has timestamp 2721 and duration 24 (estimated from max 795 // Last audio frame has timestamp 2721 and duration 24 (estimated from max
774 // seen so far for audio track). 796 // seen so far for audio track).
775 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry 797 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry
776 // DefaultDuration for video track). 798 // DefaultDuration for video track).
777 CheckExpectedRanges(kSourceId, "{ [0,2736) }"); 799 CheckExpectedRanges("{ [0,2736) }");
778 800
779 // Append initialization segment for bear2. 801 // Append initialization segment for bear2.
780 // Note: Offsets here and below are derived from 802 // Note: Offsets here and below are derived from
781 // media/test/data/bear-640x360-manifest.js and 803 // media/test/data/bear-640x360-manifest.js and
782 // media/test/data/bear-320x240-manifest.js which were 804 // media/test/data/bear-320x240-manifest.js which were
783 // generated from media/test/data/bear-640x360.webm and 805 // generated from media/test/data/bear-640x360.webm and
784 // media/test/data/bear-320x240.webm respectively. 806 // media/test/data/bear-320x240.webm respectively.
785 EXPECT_CALL(*this, InitSegmentReceived()); 807 EXPECT_CALL(*this, InitSegmentReceived());
786 AppendData(bear2->data(), 4340); 808 AppendData(bear2->data(), 4340);
787 809
788 // Append a media segment that goes from [0.527000, 1.014000). 810 // Append a media segment that goes from [0.527000, 1.014000).
789 AppendData(bear2->data() + 55290, 18785); 811 AppendData(bear2->data() + 55290, 18785);
790 CheckExpectedRanges(kSourceId, "{ [0,1027) [1201,2736) }"); 812 CheckExpectedRanges("{ [0,1027) [1201,2736) }");
791 813
792 // Append initialization segment for bear1 & fill gap with [779-1197) 814 // Append initialization segment for bear1 & fill gap with [779-1197)
793 // segment. 815 // segment.
794 EXPECT_CALL(*this, InitSegmentReceived()); 816 EXPECT_CALL(*this, InitSegmentReceived());
795 AppendData(bear1->data(), 4370); 817 AppendData(bear1->data(), 4370);
796 AppendData(bear1->data() + 72737, 28183); 818 AppendData(bear1->data() + 72737, 28183);
797 CheckExpectedRanges(kSourceId, "{ [0,2736) }"); 819 CheckExpectedRanges("{ [0,2736) }");
798 820
799 MarkEndOfStream(PIPELINE_OK); 821 MarkEndOfStream(PIPELINE_OK);
800 return true; 822 return true;
801 } 823 }
802 824
803 void ShutdownDemuxer() { 825 void ShutdownDemuxer() {
804 if (demuxer_) { 826 if (demuxer_) {
805 demuxer_->Shutdown(); 827 demuxer_->Shutdown();
806 message_loop_.RunUntilIdle(); 828 message_loop_.RunUntilIdle();
807 } 829 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 scoped_ptr<Cluster> GenerateEmptyCluster(int timecode) { 1007 scoped_ptr<Cluster> GenerateEmptyCluster(int timecode) {
986 ClusterBuilder cb; 1008 ClusterBuilder cb;
987 cb.SetClusterTimecode(timecode); 1009 cb.SetClusterTimecode(timecode);
988 return cb.Finish(); 1010 return cb.Finish();
989 } 1011 }
990 1012
991 void CheckExpectedRanges(const std::string& expected) { 1013 void CheckExpectedRanges(const std::string& expected) {
992 CheckExpectedRanges(kSourceId, expected); 1014 CheckExpectedRanges(kSourceId, expected);
993 } 1015 }
994 1016
995 void CheckExpectedRanges(const std::string& id, 1017 void CheckExpectedRanges(const std::string& id, const std::string& expected) {
996 const std::string& expected) {
997 CheckExpectedRanges(demuxer_->GetBufferedRanges(id), expected); 1018 CheckExpectedRanges(demuxer_->GetBufferedRanges(id), expected);
998 } 1019 }
999 1020
1000 void CheckExpectedRanges(DemuxerStream::Type type, 1021 void CheckExpectedRanges(DemuxerStream::Type type,
1001 const std::string& expected) { 1022 const std::string& expected) {
1002 ChunkDemuxerStream* stream = 1023 ChunkDemuxerStream* stream =
1003 static_cast<ChunkDemuxerStream*>(demuxer_->GetStream(type)); 1024 static_cast<ChunkDemuxerStream*>(demuxer_->GetStream(type));
1004 CheckExpectedRanges(stream->GetBufferedRanges(kDefaultDuration()), 1025 CheckExpectedRanges(stream->GetBufferedRanges(kDefaultDuration()),
1005 expected); 1026 expected);
1006 } 1027 }
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 1388 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
1368 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 1389 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
1369 ASSERT_TRUE(audio_stream); 1390 ASSERT_TRUE(audio_stream);
1370 ASSERT_TRUE(video_stream); 1391 ASSERT_TRUE(video_stream);
1371 ASSERT_TRUE(text_stream); 1392 ASSERT_TRUE(text_stream);
1372 1393
1373 AppendMuxedCluster( 1394 AppendMuxedCluster(
1374 MuxedStreamInfo(kAudioTrackNum, "0K 23K"), 1395 MuxedStreamInfo(kAudioTrackNum, "0K 23K"),
1375 MuxedStreamInfo(kVideoTrackNum, "0K 30"), 1396 MuxedStreamInfo(kVideoTrackNum, "0K 30"),
1376 MuxedStreamInfo(kTextTrackNum, "10K")); 1397 MuxedStreamInfo(kTextTrackNum, "10K"));
1377 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 1398 CheckExpectedRanges("{ [0,46) }");
1378 1399
1379 scoped_ptr<uint8_t[]> info_tracks; 1400 scoped_ptr<uint8_t[]> info_tracks;
1380 int info_tracks_size = 0; 1401 int info_tracks_size = 0;
1381 CreateInitSegmentWithAlternateTextTrackNum(HAS_TEXT | HAS_AUDIO | HAS_VIDEO, 1402 CreateInitSegmentWithAlternateTextTrackNum(HAS_TEXT | HAS_AUDIO | HAS_VIDEO,
1382 false, false, 1403 false, false,
1383 &info_tracks, &info_tracks_size); 1404 &info_tracks, &info_tracks_size);
1384 EXPECT_CALL(*this, InitSegmentReceived()); 1405 EXPECT_CALL(*this, InitSegmentReceived());
1385 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, 1406 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size,
1386 append_window_start_for_next_append_, 1407 append_window_start_for_next_append_,
1387 append_window_end_for_next_append_, 1408 append_window_end_for_next_append_,
1388 &timestamp_offset_map_[kSourceId], 1409 &timestamp_offset_map_[kSourceId],
1389 init_segment_received_cb_); 1410 init_segment_received_cb_);
1390 1411
1391 AppendMuxedCluster( 1412 AppendMuxedCluster(
1392 MuxedStreamInfo(kAudioTrackNum, "46K 69K"), 1413 MuxedStreamInfo(kAudioTrackNum, "46K 69K"),
1393 MuxedStreamInfo(kVideoTrackNum, "60K"), 1414 MuxedStreamInfo(kVideoTrackNum, "60K"),
1394 MuxedStreamInfo(kAlternateTextTrackNum, "45K")); 1415 MuxedStreamInfo(kAlternateTextTrackNum, "45K"));
1395 1416
1396 CheckExpectedRanges(kSourceId, "{ [0,92) }"); 1417 CheckExpectedRanges("{ [0,92) }");
1397 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K"); 1418 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K");
1398 CheckExpectedBuffers(video_stream, "0K 30 60K"); 1419 CheckExpectedBuffers(video_stream, "0K 30 60K");
1399 CheckExpectedBuffers(text_stream, "10K 45K"); 1420 CheckExpectedBuffers(text_stream, "10K 45K");
1400 1421
1401 ShutdownDemuxer(); 1422 ShutdownDemuxer();
1402 } 1423 }
1403 1424
1404 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) { 1425 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) {
1405 // Tests that non-key-frames following an init segment are allowed 1426 // Tests that non-key-frames following an init segment are allowed
1406 // and dropped, as expected if the initialization segment received 1427 // and dropped, as expected if the initialization segment received
1407 // algorithm correctly sets the needs random access point flag to true for all 1428 // algorithm correctly sets the needs random access point flag to true for all
1408 // track buffers. Note that the first initialization segment is insufficient 1429 // track buffers. Note that the first initialization segment is insufficient
1409 // to fully test this since needs random access point flag initializes to 1430 // to fully test this since needs random access point flag initializes to
1410 // true. 1431 // true.
1411 CreateNewDemuxer(); 1432 CreateNewDemuxer();
1412 DemuxerStream* text_stream = NULL; 1433 DemuxerStream* text_stream = NULL;
1413 EXPECT_CALL(host_, AddTextStream(_, _)) 1434 EXPECT_CALL(host_, AddTextStream(_, _))
1414 .WillOnce(SaveArg<0>(&text_stream)); 1435 .WillOnce(SaveArg<0>(&text_stream));
1415 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( 1436 ASSERT_TRUE(InitDemuxerWithEncryptionInfo(
1416 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); 1437 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false));
1417 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 1438 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
1418 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 1439 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
1419 ASSERT_TRUE(audio_stream && video_stream && text_stream); 1440 ASSERT_TRUE(audio_stream && video_stream && text_stream);
1420 1441
1421 AppendMuxedCluster( 1442 AppendMuxedCluster(
1422 MuxedStreamInfo(kAudioTrackNum, "23K"), 1443 MuxedStreamInfo(kAudioTrackNum, "23K"),
1423 MuxedStreamInfo(kVideoTrackNum, "0 30K"), 1444 MuxedStreamInfo(kVideoTrackNum, "0 30K"),
1424 MuxedStreamInfo(kTextTrackNum, "25K 40K")); 1445 MuxedStreamInfo(kTextTrackNum, "25K 40K"));
1425 CheckExpectedRanges(kSourceId, "{ [23,46) }"); 1446 CheckExpectedRanges("{ [23,46) }");
1426 1447
1427 EXPECT_CALL(*this, InitSegmentReceived()); 1448 EXPECT_CALL(*this, InitSegmentReceived());
1428 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); 1449 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO);
1429 AppendMuxedCluster( 1450 AppendMuxedCluster(
1430 MuxedStreamInfo(kAudioTrackNum, "46K 69K"), 1451 MuxedStreamInfo(kAudioTrackNum, "46K 69K"),
1431 MuxedStreamInfo(kVideoTrackNum, "60 90K"), 1452 MuxedStreamInfo(kVideoTrackNum, "60 90K"),
1432 MuxedStreamInfo(kTextTrackNum, "80K 90K")); 1453 MuxedStreamInfo(kTextTrackNum, "80K 90K"));
1433 CheckExpectedRanges(kSourceId, "{ [23,92) }"); 1454 CheckExpectedRanges("{ [23,92) }");
1434 1455
1435 CheckExpectedBuffers(audio_stream, "23K 46K 69K"); 1456 CheckExpectedBuffers(audio_stream, "23K 46K 69K");
1436 CheckExpectedBuffers(video_stream, "30K 90K"); 1457 CheckExpectedBuffers(video_stream, "30K 90K");
1437 CheckExpectedBuffers(text_stream, "25K 40K 80K 90K"); 1458 CheckExpectedBuffers(text_stream, "25K 40K 80K 90K");
1438 } 1459 }
1439 1460
1440 // Make sure that the demuxer reports an error if Shutdown() 1461 // Make sure that the demuxer reports an error if Shutdown()
1441 // is called before all the initialization segments are appended. 1462 // is called before all the initialization segments are appended.
1442 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { 1463 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) {
1443 EXPECT_CALL(*this, DemuxerOpened()); 1464 EXPECT_CALL(*this, DemuxerOpened());
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 EXPECT_CALL(host_, AddTextStream(_, _)) 1933 EXPECT_CALL(host_, AddTextStream(_, _))
1913 .WillOnce(SaveArg<0>(&text_stream)); 1934 .WillOnce(SaveArg<0>(&text_stream));
1914 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 1935 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
1915 1936
1916 AppendMuxedCluster( 1937 AppendMuxedCluster(
1917 MuxedStreamInfo(kVideoTrackNum, "0K 33"), 1938 MuxedStreamInfo(kVideoTrackNum, "0K 33"),
1918 MuxedStreamInfo(kAudioTrackNum, "0K 23K")); 1939 MuxedStreamInfo(kAudioTrackNum, "0K 23K"));
1919 1940
1920 // Check expected ranges and verify that an empty text track does not 1941 // Check expected ranges and verify that an empty text track does not
1921 // affect the expected ranges. 1942 // affect the expected ranges.
1922 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 1943 CheckExpectedRanges("{ [0,46) }");
1923 1944
1924 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66))); 1945 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66)));
1925 MarkEndOfStream(PIPELINE_OK); 1946 MarkEndOfStream(PIPELINE_OK);
1926 1947
1927 // Check expected ranges and verify that an empty text track does not 1948 // Check expected ranges and verify that an empty text track does not
1928 // affect the expected ranges. 1949 // affect the expected ranges.
1929 CheckExpectedRanges(kSourceId, "{ [0,66) }"); 1950 CheckExpectedRanges("{ [0,66) }");
1930 1951
1931 // Unmark end of stream state and verify that the ranges return to 1952 // Unmark end of stream state and verify that the ranges return to
1932 // their pre-"end of stream" values. 1953 // their pre-"end of stream" values.
1933 demuxer_->UnmarkEndOfStream(); 1954 demuxer_->UnmarkEndOfStream();
1934 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 1955 CheckExpectedRanges("{ [0,46) }");
1935 1956
1936 // Add text track data and verify that the buffered ranges don't change 1957 // Add text track data and verify that the buffered ranges don't change
1937 // since the intersection of all the tracks doesn't change. 1958 // since the intersection of all the tracks doesn't change.
1938 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(200))); 1959 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(200)));
1939 AppendMuxedCluster( 1960 AppendMuxedCluster(
1940 MuxedStreamInfo(kVideoTrackNum, "0K 33"), 1961 MuxedStreamInfo(kVideoTrackNum, "0K 33"),
1941 MuxedStreamInfo(kAudioTrackNum, "0K 23K"), 1962 MuxedStreamInfo(kAudioTrackNum, "0K 23K"),
1942 MuxedStreamInfo(kTextTrackNum, "0K 100K")); 1963 MuxedStreamInfo(kTextTrackNum, "0K 100K"));
1943 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 1964 CheckExpectedRanges("{ [0,46) }");
1944 1965
1945 // Mark end of stream and verify that text track data is reflected in 1966 // Mark end of stream and verify that text track data is reflected in
1946 // the new range. 1967 // the new range.
1947 MarkEndOfStream(PIPELINE_OK); 1968 MarkEndOfStream(PIPELINE_OK);
1948 CheckExpectedRanges(kSourceId, "{ [0,200) }"); 1969 CheckExpectedRanges("{ [0,200) }");
1949 } 1970 }
1950 1971
1951 // Make sure AppendData() will accept elements that span multiple calls. 1972 // Make sure AppendData() will accept elements that span multiple calls.
1952 TEST_F(ChunkDemuxerTest, AppendingInPieces) { 1973 TEST_F(ChunkDemuxerTest, AppendingInPieces) {
1953 EXPECT_CALL(*this, DemuxerOpened()); 1974 EXPECT_CALL(*this, DemuxerOpened());
1954 demuxer_->Initialize( 1975 demuxer_->Initialize(
1955 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 1976 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
1956 1977
1957 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); 1978 ASSERT_EQ(AddId(), ChunkDemuxer::kOk);
1958 1979
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 {kSkip, kSkip}, 2092 {kSkip, kSkip},
2072 }; 2093 };
2073 2094
2074 ASSERT_TRUE(ParseWebMFile("bear-320x240-altref.webm", buffer_timestamps, 2095 ASSERT_TRUE(ParseWebMFile("bear-320x240-altref.webm", buffer_timestamps,
2075 base::TimeDelta::FromMilliseconds(2767))); 2096 base::TimeDelta::FromMilliseconds(2767)));
2076 } 2097 }
2077 2098
2078 // Verify that we output buffers before the entire cluster has been parsed. 2099 // Verify that we output buffers before the entire cluster has been parsed.
2079 TEST_F(ChunkDemuxerTest, IncrementalClusterParsing) { 2100 TEST_F(ChunkDemuxerTest, IncrementalClusterParsing) {
2080 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2101 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2081 AppendEmptyCluster(0);
2082 2102
2083 scoped_ptr<Cluster> cluster(GenerateCluster(0, 6)); 2103 scoped_ptr<Cluster> cluster(GenerateCluster(0, 6));
2084 2104
2085 bool audio_read_done = false; 2105 bool audio_read_done = false;
2086 bool video_read_done = false; 2106 bool video_read_done = false;
2087 ReadAudio(base::Bind(&OnReadDone, 2107 ReadAudio(base::Bind(&OnReadDone,
2088 base::TimeDelta::FromMilliseconds(0), 2108 base::TimeDelta::FromMilliseconds(0),
2089 &audio_read_done)); 2109 &audio_read_done));
2090 ReadVideo(base::Bind(&OnReadDone, 2110 ReadVideo(base::Bind(&OnReadDone,
2091 base::TimeDelta::FromMilliseconds(0), 2111 base::TimeDelta::FromMilliseconds(0),
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2392 EXPECT_TRUE(video_read_done); 2412 EXPECT_TRUE(video_read_done);
2393 } 2413 }
2394 2414
2395 // Test that Seek() completes successfully when EndOfStream 2415 // Test that Seek() completes successfully when EndOfStream
2396 // is called before data is available for that seek point. 2416 // is called before data is available for that seek point.
2397 // This scenario might be useful if seeking past the end of stream 2417 // This scenario might be useful if seeking past the end of stream
2398 // of either audio or video (or both). 2418 // of either audio or video (or both).
2399 TEST_F(ChunkDemuxerTest, EndOfStreamAfterPastEosSeek) { 2419 TEST_F(ChunkDemuxerTest, EndOfStreamAfterPastEosSeek) {
2400 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2420 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2401 2421
2402 AppendCluster(GenerateSingleStreamCluster(0, 120, kAudioTrackNum, 10)); 2422 AppendMuxedCluster(
2403 AppendCluster(GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 5)); 2423 MuxedStreamInfo(kAudioTrackNum,
2424 "0K 10K 20K 30K 40K 50K 60K 70K 80K 90K 100K 110K"),
2425 MuxedStreamInfo(kVideoTrackNum, "0K 20K 40K 60K 80K"));
2426 CheckExpectedRanges("{ [0,100) }");
2404 2427
2405 // Seeking past the end of video. 2428 // Seeking past the end of video.
2406 // Note: audio data is available for that seek point. 2429 // Note: audio data is available for that seek point.
2407 bool seek_cb_was_called = false; 2430 bool seek_cb_was_called = false;
2408 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(110); 2431 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(110);
2409 demuxer_->StartWaitingForSeek(seek_time); 2432 demuxer_->StartWaitingForSeek(seek_time);
2410 demuxer_->Seek(seek_time, 2433 demuxer_->Seek(seek_time,
2411 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); 2434 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called));
2412 message_loop_.RunUntilIdle(); 2435 message_loop_.RunUntilIdle();
2413 2436
2414 EXPECT_FALSE(seek_cb_was_called); 2437 EXPECT_FALSE(seek_cb_was_called);
2415 2438
2416 EXPECT_CALL(host_, SetDuration( 2439 EXPECT_CALL(host_, SetDuration(
2417 base::TimeDelta::FromMilliseconds(120))); 2440 base::TimeDelta::FromMilliseconds(120)));
2418 MarkEndOfStream(PIPELINE_OK); 2441 MarkEndOfStream(PIPELINE_OK);
2442 CheckExpectedRanges("{ [0,120) }");
2419 message_loop_.RunUntilIdle(); 2443 message_loop_.RunUntilIdle();
2420 2444
2421 EXPECT_TRUE(seek_cb_was_called); 2445 EXPECT_TRUE(seek_cb_was_called);
2422 2446
2423 ShutdownDemuxer(); 2447 ShutdownDemuxer();
2424 } 2448 }
2425 2449
2426 // Test that EndOfStream is ignored if coming during a pending seek 2450 // Test that EndOfStream is ignored if coming during a pending seek
2427 // whose seek time is before some existing ranges. 2451 // whose seek time is before some existing ranges.
2428 TEST_F(ChunkDemuxerTest, EndOfStreamDuringPendingSeek) { 2452 TEST_F(ChunkDemuxerTest, EndOfStreamDuringPendingSeek) {
2429 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2453 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2430 2454
2431 AppendCluster(GenerateSingleStreamCluster(0, 120, kAudioTrackNum, 10)); 2455 AppendMuxedCluster(
2432 AppendCluster(GenerateSingleStreamCluster(0, 100, kVideoTrackNum, 5)); 2456 MuxedStreamInfo(kAudioTrackNum,
2433 AppendCluster(GenerateSingleStreamCluster(200, 300, kAudioTrackNum, 10)); 2457 "0K 10K 20K 30K 40K 50K 60K 70K 80K 90K 100K 110K"),
2434 AppendCluster(GenerateSingleStreamCluster(200, 300, kVideoTrackNum, 5)); 2458 MuxedStreamInfo(kVideoTrackNum, "0K 20K 40K 60K 80K"));
2459 AppendMuxedCluster(
2460 MuxedStreamInfo(kAudioTrackNum,
2461 "200K 210K 220K 230K 240K 250K 260K 270K 280K 290K"),
2462 MuxedStreamInfo(kVideoTrackNum, "200K 220K 240K 260K 280K"));
2435 2463
2436 bool seek_cb_was_called = false; 2464 bool seek_cb_was_called = false;
2437 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(160); 2465 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(160);
2438 demuxer_->StartWaitingForSeek(seek_time); 2466 demuxer_->StartWaitingForSeek(seek_time);
2439 demuxer_->Seek(seek_time, 2467 demuxer_->Seek(seek_time,
2440 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); 2468 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called));
2441 message_loop_.RunUntilIdle(); 2469 message_loop_.RunUntilIdle();
2442 2470
2443 EXPECT_FALSE(seek_cb_was_called); 2471 EXPECT_FALSE(seek_cb_was_called);
2444 2472
2445 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(300))); 2473 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(300)));
2446 MarkEndOfStream(PIPELINE_OK); 2474 MarkEndOfStream(PIPELINE_OK);
2447 message_loop_.RunUntilIdle(); 2475 message_loop_.RunUntilIdle();
2448 2476
2449 EXPECT_FALSE(seek_cb_was_called); 2477 EXPECT_FALSE(seek_cb_was_called);
2450 2478
2451 demuxer_->UnmarkEndOfStream(); 2479 demuxer_->UnmarkEndOfStream();
2452 2480
2453 AppendCluster(GenerateSingleStreamCluster(140, 180, kAudioTrackNum, 10)); 2481 AppendMuxedCluster(
2454 AppendCluster(GenerateSingleStreamCluster(140, 180, kVideoTrackNum, 5)); 2482 MuxedStreamInfo(kAudioTrackNum, "140K 150K 160K 170K"),
2483 MuxedStreamInfo(kVideoTrackNum,
2484 "140K 145K 150K 155K 160K 165K 170K 175K"));
2455 2485
2456 message_loop_.RunUntilIdle(); 2486 message_loop_.RunUntilIdle();
2457 2487
2458 EXPECT_TRUE(seek_cb_was_called); 2488 EXPECT_TRUE(seek_cb_was_called);
2459 2489
2460 ShutdownDemuxer(); 2490 ShutdownDemuxer();
2461 } 2491 }
2462 2492
2463 // Test ranges in an audio-only stream. 2493 // Test ranges in an audio-only stream.
2464 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) { 2494 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2507 } 2537 }
2508 2538
2509 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideo) { 2539 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideo) {
2510 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2540 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2511 2541
2512 // Audio: 0 -> 23 2542 // Audio: 0 -> 23
2513 // Video: 0 -> 33 2543 // Video: 0 -> 33
2514 // Buffered Range: 0 -> 23 2544 // Buffered Range: 0 -> 23
2515 // Audio block duration is smaller than video block duration, 2545 // Audio block duration is smaller than video block duration,
2516 // so the buffered ranges should correspond to the audio blocks. 2546 // so the buffered ranges should correspond to the audio blocks.
2517 AppendCluster(GenerateSingleStreamCluster( 2547 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0D23K"),
2518 0, kAudioBlockDuration, kAudioTrackNum, kAudioBlockDuration)); 2548 MuxedStreamInfo(kVideoTrackNum, "0D33K"));
2519 AppendCluster(GenerateSingleStreamCluster(
2520 0, kVideoBlockDuration, kVideoTrackNum, kVideoBlockDuration));
2521 2549
2550 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [0,23) }");
2551 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,33) }");
2522 CheckExpectedRanges("{ [0,23) }"); 2552 CheckExpectedRanges("{ [0,23) }");
2523 2553
2524 // Audio: 300 -> 400 2554 // Audio: 300 -> 400
2525 // Video: 320 -> 420 2555 // Video: 320 -> 420
chcunningham 2016/01/07 22:23:57 This is Video: 300 -> 420 now.
wolenetz 2016/01/07 22:37:09 I suppose the comment format isn't clear. The A/V
wolenetz 2016/01/16 01:23:35 Done.
2526 // Buffered Range: 320 -> 400 (end overlap) 2556 // Naive Buffered Range: 320 -> 400 (end overlap) **
2527 AppendCluster(GenerateSingleStreamCluster(300, 400, kAudioTrackNum, 50)); 2557 // **Except these are in the same cluster, with same segment start time of
2528 AppendCluster(GenerateSingleStreamCluster(320, 420, kVideoTrackNum, 50)); 2558 // 300, so the added buffered range is 300 -> 400 (still with end overlap)
2559 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "300K 350D50K"),
2560 MuxedStreamInfo(kVideoTrackNum, "320K 370D50K"));
2529 2561
2530 CheckExpectedRanges("{ [0,23) [320,400) }"); 2562 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [0,23) [300,400) }");
2563 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,33) [300,420) }");
2564 CheckExpectedRanges("{ [0,23) [300,400) }");
2531 2565
2532 // Audio: 520 -> 590 2566 // Audio: 520 -> 590
2533 // Video: 500 -> 570 2567 // Video: 500 -> 570
2534 // Buffered Range: 520 -> 570 (front overlap) 2568 // Naive Buffered Range: 520 -> 570 (front overlap) **
2535 AppendCluster(GenerateSingleStreamCluster(520, 590, kAudioTrackNum, 70)); 2569 // **Except these are in the same cluster, with same segment start time of
2536 AppendCluster(GenerateSingleStreamCluster(500, 570, kVideoTrackNum, 70)); 2570 // 500, so the added buffered range is 500 -> 570
chcunningham 2016/01/07 22:23:57 Is this due to the fudgy start stuff?
wolenetz 2016/01/07 22:37:09 While it seems similar, the fudgy start stuff is m
2571 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "520D70K"),
2572 MuxedStreamInfo(kVideoTrackNum, "500D70K"));
2537 2573
2538 CheckExpectedRanges("{ [0,23) [320,400) [520,570) }"); 2574 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [0,23) [300,400) [500,590) }");
2575 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,33) [300,420) [500,570) }");
2576 CheckExpectedRanges("{ [0,23) [300,400) [500,570) }");
2539 2577
2540 // Audio: 720 -> 750 2578 // Audio: 720 -> 750
2541 // Video: 700 -> 770 2579 // Video: 700 -> 770
2542 // Buffered Range: 720 -> 750 (complete overlap, audio) 2580 // Naive Buffered Range: 720 -> 750 (complete overlap, audio) **
2543 AppendCluster(GenerateSingleStreamCluster(720, 750, kAudioTrackNum, 30)); 2581 // **Except these are in the same cluster, with same segment start time of
2544 AppendCluster(GenerateSingleStreamCluster(700, 770, kVideoTrackNum, 70)); 2582 // 700, so the added buffered range is 700 -> 750
chcunningham 2016/01/07 22:23:57 Do we now need to add a test where we have 2 Sourc
wolenetz 2016/01/07 22:37:09 SGTM.
wolenetz 2016/01/16 01:23:35 Done.
2583 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "720D30K"),
2584 MuxedStreamInfo(kVideoTrackNum, "700D70K"));
2545 2585
2546 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) }"); 2586 CheckExpectedRanges(DemuxerStream::AUDIO,
2587 "{ [0,23) [300,400) [500,590) [700,750) }");
2588 CheckExpectedRanges(DemuxerStream::VIDEO,
2589 "{ [0,33) [300,420) [500,570) [700,770) }");
2590 CheckExpectedRanges("{ [0,23) [300,400) [500,570) [700,750) }");
2547 2591
2548 // Audio: 900 -> 970 2592 // Audio: 900 -> 970
2549 // Video: 920 -> 950 2593 // Video: 920 -> 950
2550 // Buffered Range: 920 -> 950 (complete overlap, video) 2594 // Naive Buffered Range: 920 -> 950 (complete overlap, video) **
2551 AppendCluster(GenerateSingleStreamCluster(900, 970, kAudioTrackNum, 70)); 2595 // **Except these are in the same cluster, with same segment start time of
2552 AppendCluster(GenerateSingleStreamCluster(920, 950, kVideoTrackNum, 30)); 2596 // 900, so the added buffered range is 900 -> 950
2597 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "900D70K"),
2598 MuxedStreamInfo(kVideoTrackNum, "920D30K"));
2553 2599
2554 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); 2600 CheckExpectedRanges(DemuxerStream::AUDIO,
2601 "{ [0,23) [300,400) [500,590) [700,750) [900,970) }");
2602 CheckExpectedRanges(DemuxerStream::VIDEO,
2603 "{ [0,33) [300,420) [500,570) [700,770) [900,950) }");
2604 CheckExpectedRanges("{ [0,23) [300,400) [500,570) [700,750) [900,950) }");
2555 2605
2556 // Appending within buffered range should not affect buffered ranges. 2606 // Appending within buffered range should not affect buffered ranges.
2557 AppendCluster(GenerateSingleStreamCluster(930, 950, kAudioTrackNum, 20)); 2607 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "930D20K"),
2558 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); 2608 MuxedStreamInfo(kVideoTrackNum, "930D20K"));
2559 2609
2560 // Appending to single stream outside buffered ranges should not affect 2610 CheckExpectedRanges(DemuxerStream::AUDIO,
2561 // buffered ranges. 2611 "{ [0,23) [300,400) [500,590) [700,750) [900,970) }");
2562 AppendCluster(GenerateSingleStreamCluster(1230, 1240, kVideoTrackNum, 10)); 2612 CheckExpectedRanges(DemuxerStream::VIDEO,
2563 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); 2613 "{ [0,33) [300,420) [500,570) [700,770) [900,950) }");
2614 CheckExpectedRanges("{ [0,23) [300,400) [500,570) [700,750) [900,950) }");
2564 } 2615 }
2565 2616
2566 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) { 2617 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) {
2567 EXPECT_CALL(host_, AddTextStream(_, _)); 2618 EXPECT_CALL(host_, AddTextStream(_, _));
2568 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); 2619 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT));
2569 2620
2570 // Append audio & video data 2621 // Append audio & video data
2571 AppendMuxedCluster( 2622 AppendMuxedCluster(
2572 MuxedStreamInfo(kAudioTrackNum, "0K 23K"), 2623 MuxedStreamInfo(kAudioTrackNum, "0K 23K"),
2573 MuxedStreamInfo(kVideoTrackNum, "0K 33")); 2624 MuxedStreamInfo(kVideoTrackNum, "0K 33"));
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2707 demuxer_->Seek(seek_time, 2758 demuxer_->Seek(seek_time,
2708 NewExpectedStatusCB(PIPELINE_ERROR_ABORT)); 2759 NewExpectedStatusCB(PIPELINE_ERROR_ABORT));
2709 ExpectRead(DemuxerStream::AUDIO, 0); 2760 ExpectRead(DemuxerStream::AUDIO, 0);
2710 ExpectEndOfStream(DemuxerStream::VIDEO); 2761 ExpectEndOfStream(DemuxerStream::VIDEO);
2711 } 2762 }
2712 2763
2713 TEST_F(ChunkDemuxerTest, ClusterWithNoBuffers) { 2764 TEST_F(ChunkDemuxerTest, ClusterWithNoBuffers) {
2714 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2765 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2715 2766
2716 // Generate and append an empty cluster beginning at 0. 2767 // Generate and append an empty cluster beginning at 0.
2717 AppendEmptyCluster(0); 2768 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
2718 2769 AppendCluster(GenerateEmptyCluster(0));
2719 // Sanity check that data can be appended after this cluster correctly.
2720 AppendCluster(GenerateCluster(0, 2));
2721 ExpectRead(DemuxerStream::AUDIO, 0);
2722 ExpectRead(DemuxerStream::VIDEO, 0);
2723 } 2770 }
2724 2771
2725 TEST_F(ChunkDemuxerTest, CodecPrefixMatching) { 2772 TEST_F(ChunkDemuxerTest, CodecPrefixMatching) {
2726 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported; 2773 ChunkDemuxer::Status expected = ChunkDemuxer::kNotSupported;
2727 2774
2728 #if defined(USE_PROPRIETARY_CODECS) 2775 #if defined(USE_PROPRIETARY_CODECS)
2729 expected = ChunkDemuxer::kOk; 2776 expected = ChunkDemuxer::kOk;
2730 #endif 2777 #endif
2731 2778
2732 std::vector<std::string> codecs; 2779 std::vector<std::string> codecs;
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
3129 append_window_start_for_next_append_, 3176 append_window_start_for_next_append_,
3130 append_window_end_for_next_append_, 3177 append_window_end_for_next_append_,
3131 &timestamp_offset_map_[kSourceId]); 3178 &timestamp_offset_map_[kSourceId]);
3132 } 3179 }
3133 3180
3134 #endif 3181 #endif
3135 #endif 3182 #endif
3136 3183
3137 TEST_F(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { 3184 TEST_F(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) {
3138 const uint8_t kBuffer[] = { 3185 const uint8_t kBuffer[] = {
3139 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) 3186 0x1F,
3140 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) 3187 0x43,
3188 0xB6,
3189 0x75,
3190 0x8A, // CLUSTER (size = 10)
3191 0xE7,
3192 0x81,
3193 0x01, // Cluster TIMECODE (value = 1)
3141 3194
chcunningham 2016/01/07 22:23:56 This space seems kinda random?
wolenetz 2016/01/07 22:37:09 Yep. Per my PTAL PS1 comment, git cl format did ba
wolenetz 2016/01/16 01:23:35 Done.
3142 0x1F, 0x43, 0xB6, 0x75, 3195 0xA3,
3143 0xFF, // CLUSTER (size = unknown; really 3 due to:) 3196 0x85, // SIMPLEBLOCK (size = 5)
3144 0xE7, 0x81, 0x02, // Cluster TIMECODE (value = 2) 3197 0x80 | (kAudioTrackNum & 0x7F), // Audio Track Number
3145 /* e.g. put some blocks here... */ 3198 0x00,
3146 0x1A, 0x45, 0xDF, 0xA3, 3199 0x00, // Timecode (relative to cluster) (value = 0)
3200 0x80, // Keyframe flag
3201 0x00, // Fake block data
3202
3203 0x1F,
3204 0x43,
3205 0xB6,
3206 0x75,
3207 0xFF, // CLUSTER (size = unknown; really 10 due to:)
3208 0xE7,
3209 0x81,
3210 0x02, // Cluster TIMECODE (value = 2)
3211
chcunningham 2016/01/07 22:23:56 ditto
wolenetz 2016/01/07 22:37:09 ditto
wolenetz 2016/01/16 01:23:35 Done.
3212 0xA3,
3213 0x85, // SIMPLEBLOCK (size = 5)
3214 0x80 | (kAudioTrackNum & 0x7F), // Audio Track Number
3215 0x00,
3216 0x00, // Timecode (relative to cluster) (value = 0)
3217 0x80, // Keyframe flag
3218 0x00, // Fake block data
3219
chcunningham 2016/01/07 22:23:57 ditto
wolenetz 2016/01/07 22:37:09 ditto
wolenetz 2016/01/16 01:23:35 Done.
3220 0x1A,
3221 0x45,
3222 0xDF,
3223 0xA3,
3147 0x8A, // EBMLHEADER (size = 10, not fully appended) 3224 0x8A, // EBMLHEADER (size = 10, not fully appended)
3148 }; 3225 };
3149 3226
3150 // This array indicates expected return value of IsParsingMediaSegment() 3227 // This array indicates expected return value of IsParsingMediaSegment()
3151 // following each incrementally appended byte in |kBuffer|. 3228 // following each incrementally appended byte in |kBuffer|.
3152 const bool kExpectedReturnValues[] = { 3229 const bool kExpectedReturnValues[] = {
3153 false, false, false, false, true, 3230 false, false, false, false, true, true, true, true,
3154 true, true, false,
3155 3231
3156 false, false, false, false, true, 3232 true, true, true, true, true, true, false,
3157 true, true, true,
3158 3233
3159 true, true, true, true, false, 3234 false, false, false, false, true, true, true, true,
3235
3236 true, true, true, true, true, true, true,
3237
3238 true, true, true, true, false,
3160 }; 3239 };
3161 3240
3162 static_assert(arraysize(kBuffer) == arraysize(kExpectedReturnValues), 3241 static_assert(arraysize(kBuffer) == arraysize(kExpectedReturnValues),
3163 "test arrays out of sync"); 3242 "test arrays out of sync");
3164 static_assert(arraysize(kBuffer) == sizeof(kBuffer), 3243 static_assert(arraysize(kBuffer) == sizeof(kBuffer),
3165 "there should be one byte per index"); 3244 "there should be one byte per index");
3166 3245
3167 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3246 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3168 3247
3169 for (size_t i = 0; i < sizeof(kBuffer); i++) { 3248 for (size_t i = 0; i < sizeof(kBuffer); i++) {
3170 DVLOG(3) << "Appending and testing index " << i; 3249 DVLOG(3) << "Appending and testing index " << i;
3171 AppendData(kBuffer + i, 1); 3250 AppendData(kBuffer + i, 1);
3172 bool expected_return_value = kExpectedReturnValues[i]; 3251 bool expected_return_value = kExpectedReturnValues[i];
3173 EXPECT_EQ(expected_return_value, 3252 EXPECT_EQ(expected_return_value,
3174 demuxer_->IsParsingMediaSegment(kSourceId)); 3253 demuxer_->IsParsingMediaSegment(kSourceId));
3175 } 3254 }
3176 } 3255 }
3177 3256
3178 TEST_F(ChunkDemuxerTest, DurationChange) { 3257 TEST_F(ChunkDemuxerTest, DurationChange) {
3179 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3258 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3180 const int kStreamDuration = kDefaultDuration().InMilliseconds(); 3259 const int kStreamDuration = kDefaultDuration().InMilliseconds();
3181 3260
3182 // Add data leading up to the currently set duration. 3261 // Add data leading up to the currently set duration.
3183 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration, 3262 AppendCluster(GenerateCluster(kStreamDuration - kAudioBlockDuration,
3184 kStreamDuration - kVideoBlockDuration, 3263 kStreamDuration - kVideoBlockDuration,
3185 2)); 3264 2));
3186 3265
3187 CheckExpectedRanges(kSourceId, "{ [201191,201224) }"); 3266 CheckExpectedRanges("{ [201191,201224) }");
3188 3267
3189 // Add data beginning at the currently set duration and expect a new duration 3268 // Add data beginning at the currently set duration and expect a new duration
3190 // to be signaled. Note that the last video block will have a higher end 3269 // to be signaled. Note that the last video block will have a higher end
3191 // timestamp than the last audio block. 3270 // timestamp than the last audio block.
3192 const int kNewStreamDurationVideo = kStreamDuration + kVideoBlockDuration; 3271 const int kNewStreamDurationVideo = kStreamDuration + kVideoBlockDuration;
3193 EXPECT_CALL(host_, SetDuration( 3272 EXPECT_CALL(host_, SetDuration(
3194 base::TimeDelta::FromMilliseconds(kNewStreamDurationVideo))); 3273 base::TimeDelta::FromMilliseconds(kNewStreamDurationVideo)));
3195 AppendCluster(GenerateCluster(kDefaultDuration().InMilliseconds(), 2)); 3274 AppendCluster(GenerateCluster(kDefaultDuration().InMilliseconds(), 2));
3196 3275
3197 CheckExpectedRanges(kSourceId, "{ [201191,201247) }"); 3276 CheckExpectedRanges("{ [201191,201247) }");
3198 3277
3199 // Add more data to the end of each media type. Note that the last audio block 3278 // Add more data to the end of each media type. Note that the last audio block
3200 // will have a higher end timestamp than the last video block. 3279 // will have a higher end timestamp than the last video block.
3201 const int kFinalStreamDuration = kStreamDuration + kAudioBlockDuration * 3; 3280 const int kFinalStreamDuration = kStreamDuration + kAudioBlockDuration * 3;
3202 EXPECT_CALL(host_, SetDuration( 3281 EXPECT_CALL(host_, SetDuration(
3203 base::TimeDelta::FromMilliseconds(kFinalStreamDuration))); 3282 base::TimeDelta::FromMilliseconds(kFinalStreamDuration)));
3204 AppendCluster(GenerateCluster(kStreamDuration + kAudioBlockDuration, 3283 AppendCluster(GenerateCluster(kStreamDuration + kAudioBlockDuration,
3205 kStreamDuration + kVideoBlockDuration, 3284 kStreamDuration + kVideoBlockDuration,
3206 3)); 3285 3));
3207 3286
3208 // See that the range has increased appropriately (but not to the full 3287 // See that the range has increased appropriately (but not to the full
3209 // duration of 201293, since there is not enough video appended for that). 3288 // duration of 201293, since there is not enough video appended for that).
3210 CheckExpectedRanges(kSourceId, "{ [201191,201290) }"); 3289 CheckExpectedRanges("{ [201191,201290) }");
3211 } 3290 }
3212 3291
3213 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) { 3292 TEST_F(ChunkDemuxerTest, DurationChangeTimestampOffset) {
3214 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3293 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3215 ASSERT_TRUE(SetTimestampOffset(kSourceId, kDefaultDuration())); 3294 ASSERT_TRUE(SetTimestampOffset(kSourceId, kDefaultDuration()));
3216 EXPECT_CALL(host_, SetDuration( 3295 EXPECT_CALL(host_, SetDuration(
3217 kDefaultDuration() + base::TimeDelta::FromMilliseconds( 3296 kDefaultDuration() + base::TimeDelta::FromMilliseconds(
3218 kVideoBlockDuration * 2))); 3297 kVideoBlockDuration * 2)));
3219 AppendCluster(GenerateCluster(0, 4)); 3298 AppendCluster(GenerateCluster(0, 4));
3220 } 3299 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3260 message_loop_.RunUntilIdle(); 3339 message_loop_.RunUntilIdle();
3261 } 3340 }
3262 3341
3263 // Verifies that signaling end of stream while stalled at a gap 3342 // Verifies that signaling end of stream while stalled at a gap
3264 // boundary does not trigger end of stream buffers to be returned. 3343 // boundary does not trigger end of stream buffers to be returned.
3265 TEST_F(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) { 3344 TEST_F(ChunkDemuxerTest, EndOfStreamWhileWaitingForGapToBeFilled) {
3266 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3345 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3267 3346
3268 AppendCluster(0, 10); 3347 AppendCluster(0, 10);
3269 AppendCluster(300, 10); 3348 AppendCluster(300, 10);
3270 CheckExpectedRanges(kSourceId, "{ [0,132) [300,432) }"); 3349 CheckExpectedRanges("{ [0,132) [300,432) }");
3271 3350
3272 GenerateExpectedReads(0, 10); 3351 GenerateExpectedReads(0, 10);
3273 3352
3274 bool audio_read_done = false; 3353 bool audio_read_done = false;
3275 bool video_read_done = false; 3354 bool video_read_done = false;
3276 ReadAudio(base::Bind(&OnReadDone, 3355 ReadAudio(base::Bind(&OnReadDone,
3277 base::TimeDelta::FromMilliseconds(138), 3356 base::TimeDelta::FromMilliseconds(138),
3278 &audio_read_done)); 3357 &audio_read_done));
3279 ReadVideo(base::Bind(&OnReadDone, 3358 ReadVideo(base::Bind(&OnReadDone,
3280 base::TimeDelta::FromMilliseconds(138), 3359 base::TimeDelta::FromMilliseconds(138),
3281 &video_read_done)); 3360 &video_read_done));
3282 3361
3283 // Verify that the reads didn't complete 3362 // Verify that the reads didn't complete
3284 EXPECT_FALSE(audio_read_done); 3363 EXPECT_FALSE(audio_read_done);
3285 EXPECT_FALSE(video_read_done); 3364 EXPECT_FALSE(video_read_done);
3286 3365
3287 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(438))); 3366 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(438)));
3288 MarkEndOfStream(PIPELINE_OK); 3367 MarkEndOfStream(PIPELINE_OK);
3289 3368
3290 // Verify that the reads still haven't completed. 3369 // Verify that the reads still haven't completed.
3291 EXPECT_FALSE(audio_read_done); 3370 EXPECT_FALSE(audio_read_done);
3292 EXPECT_FALSE(video_read_done); 3371 EXPECT_FALSE(video_read_done);
3293 3372
3294 demuxer_->UnmarkEndOfStream(); 3373 demuxer_->UnmarkEndOfStream();
3295 3374
3296 AppendCluster(138, 22); 3375 AppendCluster(138, 22);
3297 3376
3298 message_loop_.RunUntilIdle(); 3377 message_loop_.RunUntilIdle();
3299 3378
3300 CheckExpectedRanges(kSourceId, "{ [0,435) }"); 3379 CheckExpectedRanges("{ [0,435) }");
3301 3380
3302 // Verify that the reads have completed. 3381 // Verify that the reads have completed.
3303 EXPECT_TRUE(audio_read_done); 3382 EXPECT_TRUE(audio_read_done);
3304 EXPECT_TRUE(video_read_done); 3383 EXPECT_TRUE(video_read_done);
3305 3384
3306 // Read the rest of the buffers. 3385 // Read the rest of the buffers.
3307 GenerateExpectedReads(161, 171, 20); 3386 GenerateExpectedReads(161, 171, 20);
3308 3387
3309 // Verify that reads block because the append cleared the end of stream state. 3388 // Verify that reads block because the append cleared the end of stream state.
3310 audio_read_done = false; 3389 audio_read_done = false;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3342 TEST_F(ChunkDemuxerTest, SetMemoryLimitType) { 3421 TEST_F(ChunkDemuxerTest, SetMemoryLimitType) {
3343 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3422 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3344 3423
3345 // Set different memory limits for audio and video. 3424 // Set different memory limits for audio and video.
3346 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3425 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3347 demuxer_->SetMemoryLimits(DemuxerStream::VIDEO, 5 * kBlockSize + 1); 3426 demuxer_->SetMemoryLimits(DemuxerStream::VIDEO, 5 * kBlockSize + 1);
3348 3427
3349 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(1000); 3428 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(1000);
3350 3429
3351 // Append data at the start that can be garbage collected: 3430 // Append data at the start that can be garbage collected:
3352 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 10); 3431 AppendMuxedCluster(
3353 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 0, 5); 3432 MuxedStreamInfo(kAudioTrackNum,
3433 "0K 23K 46K 69K 92K 115K 138K 161K 184K 207K"),
3434 MuxedStreamInfo(kVideoTrackNum, "0K 33K 66K 99K 132K"));
3354 3435
3355 // We should be right at buffer limit, should pass 3436 // We should be right at buffer limit, should pass
3356 EXPECT_TRUE(demuxer_->EvictCodedFrames( 3437 EXPECT_TRUE(demuxer_->EvictCodedFrames(
3357 kSourceId, base::TimeDelta::FromMilliseconds(0), 0)); 3438 kSourceId, base::TimeDelta::FromMilliseconds(0), 0));
3358 3439
3359 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [0,230) }"); 3440 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [0,230) }");
3360 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,165) }"); 3441 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,165) }");
3361 3442
3362 // Seek so we can garbage collect the data appended above. 3443 // Seek so we can garbage collect the data appended above.
3363 Seek(seek_time); 3444 Seek(seek_time);
3364 3445
3365 // Append data at seek_time. 3446 // Append data at seek_time.
3366 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3447 AppendMuxedCluster(
3367 seek_time.InMilliseconds(), 10); 3448 MuxedStreamInfo(
3368 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3449 kAudioTrackNum,
3369 seek_time.InMilliseconds(), 5); 3450 "1000K 1023K 1046K 1069K 1092K 1115K 1138K 1161K 1184K 1207K"),
3451 MuxedStreamInfo(kVideoTrackNum, "1000K 1033K 1066K 1099K 1132K"));
3370 3452
3371 // We should delete first append, and be exactly at buffer limit 3453 // We should delete first append, and be exactly at buffer limit
3372 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 0)); 3454 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 0));
3373 3455
3374 // Verify that the old data, and nothing more, has been garbage collected. 3456 // Verify that the old data, and nothing more, has been garbage collected.
3375 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [1000,1230) }"); 3457 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [1000,1230) }");
3376 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [1000,1165) }"); 3458 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [1000,1165) }");
3377 } 3459 }
3378 3460
3379 TEST_F(ChunkDemuxerTest, GCDuringSeek_SingleRange_SeekForward) { 3461 TEST_F(ChunkDemuxerTest, GCDuringSeek_SingleRange_SeekForward) {
3380 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3462 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3381 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3463 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3382 // Append some data at position 1000ms 3464 // Append some data at position 1000ms
3383 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 10); 3465 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 10);
3384 CheckExpectedRanges(kSourceId, "{ [1000,1230) }"); 3466 CheckExpectedRanges("{ [1000,1230) }");
3385 3467
3386 // GC should be able to evict frames in the currently buffered range, since 3468 // GC should be able to evict frames in the currently buffered range, since
3387 // those frames are earlier than the seek target position. 3469 // those frames are earlier than the seek target position.
3388 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000); 3470 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2000);
3389 Seek(seek_time); 3471 Seek(seek_time);
3390 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize)); 3472 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize));
3391 3473
3392 // Append data to complete seek operation 3474 // Append data to complete seek operation
3393 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); 3475 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5);
3394 CheckExpectedRanges(kSourceId, "{ [1115,1230) [2000,2115) }"); 3476 CheckExpectedRanges("{ [1115,1230) [2000,2115) }");
3395 } 3477 }
3396 3478
3397 TEST_F(ChunkDemuxerTest, GCDuringSeek_SingleRange_SeekBack) { 3479 TEST_F(ChunkDemuxerTest, GCDuringSeek_SingleRange_SeekBack) {
3398 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3480 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3399 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3481 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3400 // Append some data at position 1000ms 3482 // Append some data at position 1000ms
3401 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 10); 3483 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 10);
3402 CheckExpectedRanges(kSourceId, "{ [1000,1230) }"); 3484 CheckExpectedRanges("{ [1000,1230) }");
3403 3485
3404 // GC should be able to evict frames in the currently buffered range, since 3486 // GC should be able to evict frames in the currently buffered range, since
3405 // seek target position has no data and so we should allow some frames to be 3487 // seek target position has no data and so we should allow some frames to be
3406 // evicted to make space for the upcoming append at seek target position. 3488 // evicted to make space for the upcoming append at seek target position.
3407 base::TimeDelta seek_time = base::TimeDelta(); 3489 base::TimeDelta seek_time = base::TimeDelta();
3408 Seek(seek_time); 3490 Seek(seek_time);
3409 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize)); 3491 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize));
3410 3492
3411 // Append data to complete seek operation 3493 // Append data to complete seek operation
3412 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 5); 3494 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 5);
3413 CheckExpectedRanges(kSourceId, "{ [0,115) [1115,1230) }"); 3495 CheckExpectedRanges("{ [0,115) [1115,1230) }");
3414 } 3496 }
3415 3497
3416 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekForward) { 3498 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekForward) {
3417 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3499 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3418 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3500 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3419 // Append some data at position 1000ms then at 2000ms 3501 // Append some data at position 1000ms then at 2000ms
3420 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); 3502 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5);
3421 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); 3503 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5);
3422 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); 3504 CheckExpectedRanges("{ [1000,1115) [2000,2115) }");
3423 3505
3424 // GC should be able to evict frames in the currently buffered ranges, since 3506 // GC should be able to evict frames in the currently buffered ranges, since
3425 // those frames are earlier than the seek target position. 3507 // those frames are earlier than the seek target position.
3426 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(3000); 3508 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(3000);
3427 Seek(seek_time); 3509 Seek(seek_time);
3428 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize)); 3510 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize));
3429 3511
3430 // Append data to complete seek operation 3512 // Append data to complete seek operation
3431 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3000, 5); 3513 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3000, 5);
3432 CheckExpectedRanges(kSourceId, "{ [2069,2115) [3000,3115) }"); 3514 CheckExpectedRanges("{ [2069,2115) [3000,3115) }");
3433 } 3515 }
3434 3516
3435 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekInbetween1) { 3517 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekInbetween1) {
3436 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3518 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3437 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3519 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3438 // Append some data at position 1000ms then at 2000ms 3520 // Append some data at position 1000ms then at 2000ms
3439 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); 3521 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5);
3440 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); 3522 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5);
3441 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); 3523 CheckExpectedRanges("{ [1000,1115) [2000,2115) }");
3442 3524
3443 // GC should be able to evict all frames from the first buffered range, since 3525 // GC should be able to evict all frames from the first buffered range, since
3444 // those frames are earlier than the seek target position. But there's only 5 3526 // those frames are earlier than the seek target position. But there's only 5
3445 // blocks worth of data in the first range and seek target position has no 3527 // blocks worth of data in the first range and seek target position has no
3446 // data, so GC proceeds with trying to delete some frames from the back of 3528 // data, so GC proceeds with trying to delete some frames from the back of
3447 // buffered ranges, that doesn't yield anything, since that's the most 3529 // buffered ranges, that doesn't yield anything, since that's the most
3448 // recently appended data, so then GC starts removing data from the front of 3530 // recently appended data, so then GC starts removing data from the front of
3449 // the remaining buffered range (2000ms) to ensure we free up enough space for 3531 // the remaining buffered range (2000ms) to ensure we free up enough space for
3450 // the upcoming append and allow seek to proceed. 3532 // the upcoming append and allow seek to proceed.
3451 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(1500); 3533 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(1500);
3452 Seek(seek_time); 3534 Seek(seek_time);
3453 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize)); 3535 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize));
3454 3536
3455 // Append data to complete seek operation 3537 // Append data to complete seek operation
3456 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1500, 5); 3538 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1500, 5);
3457 CheckExpectedRanges(kSourceId, "{ [1500,1615) [2069,2115) }"); 3539 CheckExpectedRanges("{ [1500,1615) [2069,2115) }");
3458 } 3540 }
3459 3541
3460 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekInbetween2) { 3542 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekInbetween2) {
3461 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3543 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3462 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3544 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3463 3545
3464 // Append some data at position 2000ms first, then at 1000ms, so that the last 3546 // Append some data at position 2000ms first, then at 1000ms, so that the last
3465 // appended data position is in the first buffered range (that matters to the 3547 // appended data position is in the first buffered range (that matters to the
3466 // GC algorithm since it tries to preserve more recently appended data). 3548 // GC algorithm since it tries to preserve more recently appended data).
3467 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); 3549 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5);
3468 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); 3550 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5);
3469 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); 3551 CheckExpectedRanges("{ [1000,1115) [2000,2115) }");
3470 3552
3471 // Now try performing garbage collection without announcing seek first, i.e. 3553 // Now try performing garbage collection without announcing seek first, i.e.
3472 // without calling Seek(), the GC algorithm should try to preserve data in the 3554 // without calling Seek(), the GC algorithm should try to preserve data in the
3473 // first range, since that is most recently appended data. 3555 // first range, since that is most recently appended data.
3474 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2030); 3556 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(2030);
3475 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize)); 3557 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 5 * kBlockSize));
3476 3558
3477 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1500, 5); 3559 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1500, 5);
3478 CheckExpectedRanges(kSourceId, "{ [1000,1115) [1500,1615) }"); 3560 CheckExpectedRanges("{ [1000,1115) [1500,1615) }");
3479 } 3561 }
3480 3562
3481 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekBack) { 3563 TEST_F(ChunkDemuxerTest, GCDuringSeek_MultipleRanges_SeekBack) {
3482 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3564 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3483 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 3565 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3484 // Append some data at position 1000ms then at 2000ms 3566 // Append some data at position 1000ms then at 2000ms
3485 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5); 3567 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 1000, 5);
3486 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5); 3568 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 2000, 5);
3487 CheckExpectedRanges(kSourceId, "{ [1000,1115) [2000,2115) }"); 3569 CheckExpectedRanges("{ [1000,1115) [2000,2115) }");
3488 3570
3489 // GC should be able to evict frames in the currently buffered ranges, since 3571 // GC should be able to evict frames in the currently buffered ranges, since
3490 // those frames are earlier than the seek target position. 3572 // those frames are earlier than the seek target position.
3491 base::TimeDelta seek_time = base::TimeDelta(); 3573 base::TimeDelta seek_time = base::TimeDelta();
3492 Seek(seek_time); 3574 Seek(seek_time);
3493 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize)); 3575 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time, 8 * kBlockSize));
3494 3576
3495 // Append data to complete seek operation 3577 // Append data to complete seek operation
3496 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 5); 3578 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 5);
3497 CheckExpectedRanges(kSourceId, "{ [0,115) [2069,2115) }"); 3579 CheckExpectedRanges("{ [0,115) [2069,2115) }");
3498 } 3580 }
3499 3581
3500 TEST_F(ChunkDemuxerTest, GCDuringSeek) { 3582 TEST_F(ChunkDemuxerTest, GCDuringSeek) {
3501 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3583 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3502 3584
3503 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 5 * kBlockSize); 3585 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 5 * kBlockSize);
3504 3586
3505 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(1000); 3587 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(1000);
3506 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(500); 3588 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(500);
3507 3589
3508 // Initiate a seek to |seek_time1|. 3590 // Initiate a seek to |seek_time1|.
3509 Seek(seek_time1); 3591 Seek(seek_time1);
3510 3592
3511 // Append data to satisfy the first seek request. 3593 // Append data to satisfy the first seek request.
3512 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3594 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
3513 seek_time1.InMilliseconds(), 5); 3595 seek_time1.InMilliseconds(), 5);
3514 CheckExpectedRanges(kSourceId, "{ [1000,1115) }"); 3596 CheckExpectedRanges("{ [1000,1115) }");
3515 3597
3516 // We are under memory limit, so Evict should be a no-op. 3598 // We are under memory limit, so Evict should be a no-op.
3517 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time1, 0)); 3599 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time1, 0));
3518 CheckExpectedRanges(kSourceId, "{ [1000,1115) }"); 3600 CheckExpectedRanges("{ [1000,1115) }");
3519 3601
3520 // Signal that the second seek is starting. 3602 // Signal that the second seek is starting.
3521 demuxer_->StartWaitingForSeek(seek_time2); 3603 demuxer_->StartWaitingForSeek(seek_time2);
3522 3604
3523 // Append data to satisfy the second seek. 3605 // Append data to satisfy the second seek.
3524 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3606 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
3525 seek_time2.InMilliseconds(), 5); 3607 seek_time2.InMilliseconds(), 5);
3526 CheckExpectedRanges(kSourceId, "{ [500,615) [1000,1115) }"); 3608 CheckExpectedRanges("{ [500,615) [1000,1115) }");
3527 3609
3528 // We are now over our memory usage limit. We have just seeked to |seek_time2| 3610 // We are now over our memory usage limit. We have just seeked to |seek_time2|
3529 // so data around 500ms position should be preserved, while the previous 3611 // so data around 500ms position should be preserved, while the previous
3530 // append at 1000ms should be removed. 3612 // append at 1000ms should be removed.
3531 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0)); 3613 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0));
3532 CheckExpectedRanges(kSourceId, "{ [500,615) }"); 3614 CheckExpectedRanges("{ [500,615) }");
3533 3615
3534 // Complete the seek. 3616 // Complete the seek.
3535 demuxer_->Seek(seek_time2, NewExpectedStatusCB(PIPELINE_OK)); 3617 demuxer_->Seek(seek_time2, NewExpectedStatusCB(PIPELINE_OK));
3536 3618
3537 // Append more data and make sure that we preserve both the buffered range 3619 // Append more data and make sure that we preserve both the buffered range
3538 // around |seek_time2|, because that's the current playback position, 3620 // around |seek_time2|, because that's the current playback position,
3539 // and the newly appended range, since this is the most recent append. 3621 // and the newly appended range, since this is the most recent append.
3540 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 700, 5); 3622 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 700, 5);
3541 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0)); 3623 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0));
3542 CheckExpectedRanges(kSourceId, "{ [500,615) [700,815) }"); 3624 CheckExpectedRanges("{ [500,615) [700,815) }");
3543 } 3625 }
3544 3626
3545 TEST_F(ChunkDemuxerTest, GCKeepPlayhead) { 3627 TEST_F(ChunkDemuxerTest, GCKeepPlayhead) {
3546 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3628 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3547 3629
3548 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 5 * kBlockSize); 3630 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 5 * kBlockSize);
3549 3631
3550 // Append data at the start that can be garbage collected: 3632 // Append data at the start that can be garbage collected:
3551 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 10); 3633 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 10);
3552 CheckExpectedRanges(kSourceId, "{ [0,230) }"); 3634 CheckExpectedRanges("{ [0,230) }");
3553 3635
3554 // We expect garbage collection to fail, as we don't want to spontaneously 3636 // We expect garbage collection to fail, as we don't want to spontaneously
3555 // create gaps in source buffer stream. Gaps could break playback for many 3637 // create gaps in source buffer stream. Gaps could break playback for many
3556 // clients, who don't bother to check ranges after append. 3638 // clients, who don't bother to check ranges after append.
3557 EXPECT_FALSE(demuxer_->EvictCodedFrames( 3639 EXPECT_FALSE(demuxer_->EvictCodedFrames(
3558 kSourceId, base::TimeDelta::FromMilliseconds(0), 0)); 3640 kSourceId, base::TimeDelta::FromMilliseconds(0), 0));
3559 CheckExpectedRanges(kSourceId, "{ [0,230) }"); 3641 CheckExpectedRanges("{ [0,230) }");
3560 3642
3561 // Increase media_time a bit, this will allow some data to be collected, but 3643 // Increase media_time a bit, this will allow some data to be collected, but
3562 // we are still over memory usage limit. 3644 // we are still over memory usage limit.
3563 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(23*2); 3645 base::TimeDelta seek_time1 = base::TimeDelta::FromMilliseconds(23*2);
3564 Seek(seek_time1); 3646 Seek(seek_time1);
3565 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time1, 0)); 3647 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time1, 0));
3566 CheckExpectedRanges(kSourceId, "{ [46,230) }"); 3648 CheckExpectedRanges("{ [46,230) }");
3567 3649
3568 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(23*4); 3650 base::TimeDelta seek_time2 = base::TimeDelta::FromMilliseconds(23*4);
3569 Seek(seek_time2); 3651 Seek(seek_time2);
3570 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0)); 3652 EXPECT_FALSE(demuxer_->EvictCodedFrames(kSourceId, seek_time2, 0));
3571 CheckExpectedRanges(kSourceId, "{ [92,230) }"); 3653 CheckExpectedRanges("{ [92,230) }");
3572 3654
3573 // media_time has progressed to a point where we can collect enough data to 3655 // media_time has progressed to a point where we can collect enough data to
3574 // be under memory limit, so Evict should return true. 3656 // be under memory limit, so Evict should return true.
3575 base::TimeDelta seek_time3 = base::TimeDelta::FromMilliseconds(23*6); 3657 base::TimeDelta seek_time3 = base::TimeDelta::FromMilliseconds(23*6);
3576 Seek(seek_time3); 3658 Seek(seek_time3);
3577 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time3, 0)); 3659 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time3, 0));
3578 // Strictly speaking the current playback time is 23*6==138ms, so we could 3660 // Strictly speaking the current playback time is 23*6==138ms, so we could
3579 // release data up to 138ms, but we only release as much data as necessary 3661 // release data up to 138ms, but we only release as much data as necessary
3580 // to bring memory usage under the limit, so we release only up to 115ms. 3662 // to bring memory usage under the limit, so we release only up to 115ms.
3581 CheckExpectedRanges(kSourceId, "{ [115,230) }"); 3663 CheckExpectedRanges("{ [115,230) }");
3582 } 3664 }
3583 3665
3584 TEST_F(ChunkDemuxerTest, AppendWindow_Video) { 3666 TEST_F(ChunkDemuxerTest, AppendWindow_Video) {
3585 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); 3667 ASSERT_TRUE(InitDemuxer(HAS_VIDEO));
3586 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3668 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3587 3669
3588 // Set the append window to [50,280). 3670 // Set the append window to [50,280).
3589 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); 3671 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50);
3590 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3672 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3591 3673
3592 // Append a cluster that starts before and ends after the append window. 3674 // Append a cluster that starts before and ends after the append window.
3593 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3675 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3594 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); 3676 "0K 30 60 90 120K 150 180 210 240K 270 300 330K");
3595 3677
3596 // Verify that GOPs that start outside the window are not included 3678 // Verify that GOPs that start outside the window are not included
3597 // in the buffer. Also verify that buffers that start inside the 3679 // in the buffer. Also verify that buffers that start inside the
3598 // window and extend beyond the end of the window are not included. 3680 // window and extend beyond the end of the window are not included.
3599 CheckExpectedRanges(kSourceId, "{ [120,270) }"); 3681 CheckExpectedRanges("{ [120,270) }");
3600 CheckExpectedBuffers(stream, "120K 150 180 210 240K"); 3682 CheckExpectedBuffers(stream, "120K 150 180 210 240K");
3601 3683
3602 // Extend the append window to [50,650). 3684 // Extend the append window to [50,650).
3603 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3685 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3604 3686
3605 // Append more data and verify that adding buffers start at the next 3687 // Append more data and verify that adding buffers start at the next
3606 // key frame. 3688 // key frame.
3607 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 3689 AppendSingleStreamCluster(kSourceId, kVideoTrackNum,
3608 "360 390 420K 450 480 510 540K 570 600 630K"); 3690 "360 390 420K 450 480 510 540K 570 600 630K");
3609 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); 3691 CheckExpectedRanges("{ [120,270) [420,630) }");
3610 } 3692 }
3611 3693
3612 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) { 3694 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) {
3613 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3695 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3614 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3696 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3615 3697
3616 // Set the append window to [50,280). 3698 // Set the append window to [50,280).
3617 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); 3699 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50);
3618 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3700 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3619 3701
3620 // Append a cluster that starts before and ends after the append window. 3702 // Append a cluster that starts before and ends after the append window.
3621 AppendSingleStreamCluster( 3703 AppendSingleStreamCluster(
3622 kSourceId, kAudioTrackNum, 3704 kSourceId, kAudioTrackNum,
3623 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); 3705 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K");
3624 3706
3625 // Verify that frames that end outside the window are not included 3707 // Verify that frames that end outside the window are not included
3626 // in the buffer. Also verify that buffers that start inside the 3708 // in the buffer. Also verify that buffers that start inside the
3627 // window and extend beyond the end of the window are not included. 3709 // window and extend beyond the end of the window are not included.
3628 // 3710 //
3629 // The first 50ms of the range should be truncated since it overlaps 3711 // The first 50ms of the range should be truncated since it overlaps
3630 // the start of the append window. 3712 // the start of the append window.
3631 CheckExpectedRanges(kSourceId, "{ [50,280) }"); 3713 CheckExpectedRanges("{ [50,280) }");
3632 3714
3633 // The "50P" buffer is the "0" buffer marked for complete discard. The next 3715 // The "50P" buffer is the "0" buffer marked for complete discard. The next
3634 // "50" buffer is the "30" buffer marked with 20ms of start discard. 3716 // "50" buffer is the "30" buffer marked with 20ms of start discard.
3635 CheckExpectedBuffers(stream, "50KP 50K 60K 90K 120K 150K 180K 210K 240K"); 3717 CheckExpectedBuffers(stream, "50KP 50K 60K 90K 120K 150K 180K 210K 240K");
3636 3718
3637 // Extend the append window to [50,650). 3719 // Extend the append window to [50,650).
3638 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3720 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3639 3721
3640 // Append more data and verify that a new range is created. 3722 // Append more data and verify that a new range is created.
3641 AppendSingleStreamCluster( 3723 AppendSingleStreamCluster(
3642 kSourceId, kAudioTrackNum, 3724 kSourceId, kAudioTrackNum,
3643 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); 3725 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K");
3644 CheckExpectedRanges(kSourceId, "{ [50,280) [360,650) }"); 3726 CheckExpectedRanges("{ [50,280) [360,650) }");
3645 } 3727 }
3646 3728
3647 TEST_F(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) { 3729 TEST_F(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) {
3648 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3730 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3649 3731
3650 // Set the append window to [10,20). 3732 // Set the append window to [10,20).
3651 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10); 3733 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10);
3652 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20); 3734 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
3653 3735
3654 // Append a cluster that starts before and ends after the append window. 3736 // Append a cluster that starts before and ends after the append window.
3655 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K"); 3737 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K");
3656 3738
3657 // Verify the append is clipped to the append window. 3739 // Verify the append is clipped to the append window.
3658 CheckExpectedRanges(kSourceId, "{ [10,20) }"); 3740 CheckExpectedRanges("{ [10,20) }");
3659 } 3741 }
3660 3742
3661 TEST_F(ChunkDemuxerTest, AppendWindow_WebMFile_AudioOnly) { 3743 TEST_F(ChunkDemuxerTest, AppendWindow_WebMFile_AudioOnly) {
3662 EXPECT_CALL(*this, DemuxerOpened()); 3744 EXPECT_CALL(*this, DemuxerOpened());
3663 demuxer_->Initialize( 3745 demuxer_->Initialize(
3664 &host_, 3746 &host_,
3665 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), 3747 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK),
3666 true); 3748 true);
3667 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); 3749 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO));
3668 3750
(...skipping 26 matching lines...) Expand all
3695 // Expect duration adjustment since actual duration differs slightly from 3777 // Expect duration adjustment since actual duration differs slightly from
3696 // duration in the init segment. 3778 // duration in the init segment.
3697 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746); 3779 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746);
3698 append_window_start_for_next_append_ = duration_1; 3780 append_window_start_for_next_append_ = duration_1;
3699 3781
3700 // Read a WebM file into memory and append the data. 3782 // Read a WebM file into memory and append the data.
3701 scoped_refptr<DecoderBuffer> buffer = 3783 scoped_refptr<DecoderBuffer> buffer =
3702 ReadTestDataFile("bear-320x240-audio-only.webm"); 3784 ReadTestDataFile("bear-320x240-audio-only.webm");
3703 EXPECT_CALL(*this, InitSegmentReceived()); 3785 EXPECT_CALL(*this, InitSegmentReceived());
3704 AppendDataInPieces(buffer->data(), buffer->data_size(), 512); 3786 AppendDataInPieces(buffer->data(), buffer->data_size(), 512);
3705 CheckExpectedRanges(kSourceId, "{ }"); 3787 CheckExpectedRanges("{ }");
3706 3788
3707 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3789 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3708 AudioDecoderConfig config_1 = stream->audio_decoder_config(); 3790 AudioDecoderConfig config_1 = stream->audio_decoder_config();
3709 3791
3710 // Read a second WebM with a different config in and append the data. 3792 // Read a second WebM with a different config in and append the data.
3711 scoped_refptr<DecoderBuffer> buffer2 = 3793 scoped_refptr<DecoderBuffer> buffer2 =
3712 ReadTestDataFile("bear-320x240-audio-only-48khz.webm"); 3794 ReadTestDataFile("bear-320x240-audio-only-48khz.webm");
3713 EXPECT_CALL(*this, InitSegmentReceived()); 3795 EXPECT_CALL(*this, InitSegmentReceived());
3714 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber()); 3796 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber());
3715 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1)); 3797 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1));
3716 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512); 3798 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512);
3717 CheckExpectedRanges(kSourceId, "{ [2746,5519) }"); 3799 CheckExpectedRanges("{ [2746,5519) }");
3718 3800
3719 Seek(duration_1); 3801 Seek(duration_1);
3720 ExpectConfigChanged(DemuxerStream::AUDIO); 3802 ExpectConfigChanged(DemuxerStream::AUDIO);
3721 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config())); 3803 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config()));
3722 CheckExpectedBuffers(stream, "2746K 2767K 2789K 2810K"); 3804 CheckExpectedBuffers(stream, "2746K 2767K 2789K 2810K");
3723 } 3805 }
3724 3806
3725 TEST_F(ChunkDemuxerTest, AppendWindow_Text) { 3807 TEST_F(ChunkDemuxerTest, AppendWindow_Text) {
3726 DemuxerStream* text_stream = NULL; 3808 DemuxerStream* text_stream = NULL;
3727 EXPECT_CALL(host_, AddTextStream(_, _)) 3809 EXPECT_CALL(host_, AddTextStream(_, _))
3728 .WillOnce(SaveArg<0>(&text_stream)); 3810 .WillOnce(SaveArg<0>(&text_stream));
3729 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); 3811 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT));
3730 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 3812 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3731 3813
3732 // Set the append window to [20,280). 3814 // Set the append window to [20,280).
3733 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); 3815 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20);
3734 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); 3816 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280);
3735 3817
3736 // Append a cluster that starts before and ends after the append 3818 // Append a cluster that starts before and ends after the append
3737 // window. 3819 // window.
3738 AppendMuxedCluster( 3820 AppendMuxedCluster(
3739 MuxedStreamInfo(kVideoTrackNum, 3821 MuxedStreamInfo(kVideoTrackNum,
3740 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"), 3822 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"),
3741 MuxedStreamInfo(kTextTrackNum, "0K 100K 200K 300K" )); 3823 MuxedStreamInfo(kTextTrackNum, "0K 100K 200K 300K" ));
3742 3824
3743 // Verify that text cues that start outside the window are not included 3825 // Verify that text cues that start outside the window are not included
3744 // in the buffer. Also verify that cues that extend beyond the 3826 // in the buffer. Also verify that cues that extend beyond the
3745 // window are not included. 3827 // window are not included.
3746 CheckExpectedRanges(kSourceId, "{ [100,270) }"); 3828 CheckExpectedRanges("{ [100,270) }");
3747 CheckExpectedBuffers(video_stream, "120K 150 180 210 240K"); 3829 CheckExpectedBuffers(video_stream, "120K 150 180 210 240K");
3748 CheckExpectedBuffers(text_stream, "100K"); 3830 CheckExpectedBuffers(text_stream, "100K");
3749 3831
3750 // Extend the append window to [20,650). 3832 // Extend the append window to [20,650).
3751 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); 3833 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650);
3752 3834
3753 // Append more data and verify that a new range is created. 3835 // Append more data and verify that a new range is created.
3754 AppendMuxedCluster( 3836 AppendMuxedCluster(
3755 MuxedStreamInfo(kVideoTrackNum, 3837 MuxedStreamInfo(kVideoTrackNum,
3756 "360 390 420K 450 480 510 540K 570 600 630K"), 3838 "360 390 420K 450 480 510 540K 570 600 630K"),
3757 MuxedStreamInfo(kTextTrackNum, "400K 500K 600K 700K" )); 3839 MuxedStreamInfo(kTextTrackNum, "400K 500K 600K 700K" ));
3758 CheckExpectedRanges(kSourceId, "{ [100,270) [400,630) }"); 3840 CheckExpectedRanges("{ [100,270) [400,630) }");
3759 3841
3760 // Seek to the new range and verify that the expected buffers are returned. 3842 // Seek to the new range and verify that the expected buffers are returned.
3761 Seek(base::TimeDelta::FromMilliseconds(420)); 3843 Seek(base::TimeDelta::FromMilliseconds(420));
3762 CheckExpectedBuffers(video_stream, "420K 450 480 510 540K 570 600"); 3844 CheckExpectedBuffers(video_stream, "420K 450 480 510 540K 570 600");
3763 CheckExpectedBuffers(text_stream, "400K 500K"); 3845 CheckExpectedBuffers(text_stream, "400K 500K");
3764 } 3846 }
3765 3847
3766 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) { 3848 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) {
3767 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3849 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3768 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 3850 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
(...skipping 18 matching lines...) Expand all
3787 3869
3788 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K"); 3870 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K");
3789 CheckExpectedBuffers(video_stream, "0K 30 60 90 120K 150 180"); 3871 CheckExpectedBuffers(video_stream, "0K 30 60 90 120K 150 180");
3790 CheckExpectedBuffers(text_stream, "0K 100K 200K"); 3872 CheckExpectedBuffers(text_stream, "0K 100K 200K");
3791 3873
3792 // Remove the buffers that were added. 3874 // Remove the buffers that were added.
3793 demuxer_->Remove(kSourceId, base::TimeDelta(), 3875 demuxer_->Remove(kSourceId, base::TimeDelta(),
3794 base::TimeDelta::FromMilliseconds(300)); 3876 base::TimeDelta::FromMilliseconds(300));
3795 3877
3796 // Verify that all the appended data has been removed. 3878 // Verify that all the appended data has been removed.
3797 CheckExpectedRanges(kSourceId, "{ }"); 3879 CheckExpectedRanges("{ }");
3798 3880
3799 // Append new buffers that are clearly different than the original 3881 // Append new buffers that are clearly different than the original
3800 // ones and verify that only the new buffers are returned. 3882 // ones and verify that only the new buffers are returned.
3801 AppendMuxedCluster( 3883 AppendMuxedCluster(
3802 MuxedStreamInfo(kAudioTrackNum, "1K 21K 41K 61K 81K 101K 121K 141K"), 3884 MuxedStreamInfo(kAudioTrackNum, "1K 21K 41K 61K 81K 101K 121K 141K"),
3803 MuxedStreamInfo(kVideoTrackNum, "1K 31 61 91 121K 151 181"), 3885 MuxedStreamInfo(kVideoTrackNum, "1K 31 61 91 121K 151 181"),
3804 MuxedStreamInfo(kTextTrackNum, "1K 101K 201K")); 3886 MuxedStreamInfo(kTextTrackNum, "1K 101K 201K"));
3805 3887
3806 Seek(base::TimeDelta()); 3888 Seek(base::TimeDelta());
3807 CheckExpectedBuffers(audio_stream, "1K 21K 41K 61K 81K 101K 121K 141K"); 3889 CheckExpectedBuffers(audio_stream, "1K 21K 41K 61K 81K 101K 121K 141K");
3808 CheckExpectedBuffers(video_stream, "1K 31 61 91 121K 151 181"); 3890 CheckExpectedBuffers(video_stream, "1K 31 61 91 121K 151 181");
3809 CheckExpectedBuffers(text_stream, "1K 101K 201K"); 3891 CheckExpectedBuffers(text_stream, "1K 101K 201K");
3810 } 3892 }
3811 3893
3812 TEST_F(ChunkDemuxerTest, Remove_StartAtDuration) { 3894 TEST_F(ChunkDemuxerTest, Remove_StartAtDuration) {
3813 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); 3895 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
3814 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3896 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3815 3897
3816 // Set the duration to something small so that the append that 3898 // Set the duration to something small so that the append that
3817 // follows updates the duration to reflect the end of the appended data. 3899 // follows updates the duration to reflect the end of the appended data.
3818 EXPECT_CALL(host_, SetDuration( 3900 EXPECT_CALL(host_, SetDuration(
3819 base::TimeDelta::FromMilliseconds(1))); 3901 base::TimeDelta::FromMilliseconds(1)));
3820 demuxer_->SetDuration(0.001); 3902 demuxer_->SetDuration(0.001);
3821 3903
3822 EXPECT_CALL(host_, SetDuration( 3904 EXPECT_CALL(host_, SetDuration(
3823 base::TimeDelta::FromMilliseconds(160))); 3905 base::TimeDelta::FromMilliseconds(160)));
3824 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 3906 AppendSingleStreamCluster(kSourceId, kAudioTrackNum,
3825 "0K 20K 40K 60K 80K 100K 120K 140K"); 3907 "0K 20K 40K 60K 80K 100K 120K 140K");
3826 3908
3827 CheckExpectedRanges(kSourceId, "{ [0,160) }"); 3909 CheckExpectedRanges("{ [0,160) }");
3828 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K"); 3910 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K");
3829 3911
3830 demuxer_->Remove(kSourceId, 3912 demuxer_->Remove(kSourceId,
3831 base::TimeDelta::FromSecondsD(demuxer_->GetDuration()), 3913 base::TimeDelta::FromSecondsD(demuxer_->GetDuration()),
3832 kInfiniteDuration()); 3914 kInfiniteDuration());
3833 3915
3834 Seek(base::TimeDelta()); 3916 Seek(base::TimeDelta());
3835 CheckExpectedRanges(kSourceId, "{ [0,160) }"); 3917 CheckExpectedRanges("{ [0,160) }");
3836 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K"); 3918 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K");
3837 } 3919 }
3838 3920
3839 // Verifies that a Seek() will complete without text cues for 3921 // Verifies that a Seek() will complete without text cues for
3840 // the seek point and will return cues after the seek position 3922 // the seek point and will return cues after the seek position
3841 // when they are eventually appended. 3923 // when they are eventually appended.
3842 TEST_F(ChunkDemuxerTest, SeekCompletesWithoutTextCues) { 3924 TEST_F(ChunkDemuxerTest, SeekCompletesWithoutTextCues) {
3843 DemuxerStream* text_stream = NULL; 3925 DemuxerStream* text_stream = NULL;
3844 EXPECT_CALL(host_, AddTextStream(_, _)) 3926 EXPECT_CALL(host_, AddTextStream(_, _))
3845 .WillOnce(SaveArg<0>(&text_stream)); 3927 .WillOnce(SaveArg<0>(&text_stream));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3894 3976
3895 // Verify that audio & video streams continue to return expected values. 3977 // Verify that audio & video streams continue to return expected values.
3896 CheckExpectedBuffers(audio_stream, "160K 180K"); 3978 CheckExpectedBuffers(audio_stream, "160K 180K");
3897 CheckExpectedBuffers(video_stream, "180 210"); 3979 CheckExpectedBuffers(video_stream, "180 210");
3898 } 3980 }
3899 3981
3900 TEST_F(ChunkDemuxerTest, ClusterWithUnknownSize) { 3982 TEST_F(ChunkDemuxerTest, ClusterWithUnknownSize) {
3901 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3983 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3902 3984
3903 AppendCluster(GenerateCluster(0, 0, 4, true)); 3985 AppendCluster(GenerateCluster(0, 0, 4, true));
3904 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 3986 CheckExpectedRanges("{ [0,46) }");
3905 3987
3906 // A new cluster indicates end of the previous cluster with unknown size. 3988 // A new cluster indicates end of the previous cluster with unknown size.
3907 AppendCluster(GenerateCluster(46, 66, 5, true)); 3989 AppendCluster(GenerateCluster(46, 66, 5, true));
3908 CheckExpectedRanges(kSourceId, "{ [0,115) }"); 3990 CheckExpectedRanges("{ [0,115) }");
3909 } 3991 }
3910 3992
3911 TEST_F(ChunkDemuxerTest, CuesBetweenClustersWithUnknownSize) { 3993 TEST_F(ChunkDemuxerTest, CuesBetweenClustersWithUnknownSize) {
3912 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3994 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3913 3995
3914 // Add two clusters separated by Cues in a single Append() call. 3996 // Add two clusters separated by Cues in a single Append() call.
3915 scoped_ptr<Cluster> cluster = GenerateCluster(0, 0, 4, true); 3997 scoped_ptr<Cluster> cluster = GenerateCluster(0, 0, 4, true);
3916 std::vector<uint8_t> data(cluster->data(), cluster->data() + cluster->size()); 3998 std::vector<uint8_t> data(cluster->data(), cluster->data() + cluster->size());
3917 data.insert(data.end(), kCuesHeader, kCuesHeader + sizeof(kCuesHeader)); 3999 data.insert(data.end(), kCuesHeader, kCuesHeader + sizeof(kCuesHeader));
3918 cluster = GenerateCluster(46, 66, 5, true); 4000 cluster = GenerateCluster(46, 66, 5, true);
3919 data.insert(data.end(), cluster->data(), cluster->data() + cluster->size()); 4001 data.insert(data.end(), cluster->data(), cluster->data() + cluster->size());
3920 AppendData(&*data.begin(), data.size()); 4002 AppendData(&*data.begin(), data.size());
3921 4003
3922 CheckExpectedRanges(kSourceId, "{ [0,115) }"); 4004 CheckExpectedRanges("{ [0,115) }");
3923 } 4005 }
3924 4006
3925 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { 4007 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) {
3926 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 4008 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3927 4009
3928 AppendCluster(GenerateCluster(0, 0, 4)); 4010 AppendCluster(GenerateCluster(0, 0, 4));
3929 AppendData(kCuesHeader, sizeof(kCuesHeader)); 4011 AppendData(kCuesHeader, sizeof(kCuesHeader));
3930 AppendCluster(GenerateCluster(46, 66, 5)); 4012 AppendCluster(GenerateCluster(46, 66, 5));
3931 CheckExpectedRanges(kSourceId, "{ [0,115) }"); 4013 CheckExpectedRanges("{ [0,115) }");
3932 } 4014 }
3933 4015
3934 TEST_F(ChunkDemuxerTest, EvictCodedFramesTest) { 4016 TEST_F(ChunkDemuxerTest, EvictCodedFramesTest) {
3935 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 4017 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3936 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize); 4018 demuxer_->SetMemoryLimits(DemuxerStream::AUDIO, 10 * kBlockSize);
3937 demuxer_->SetMemoryLimits(DemuxerStream::VIDEO, 15 * kBlockSize); 4019 demuxer_->SetMemoryLimits(DemuxerStream::VIDEO, 15 * kBlockSize);
3938 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 4020 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3939 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 4021 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
3940 4022
3941 const char* kAudioStreamInfo = "0K 40K 80K 120K 160K 200K 240K 280K"; 4023 const char* kAudioStreamInfo = "0K 40K 80K 120K 160K 200K 240K 280K";
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3975 // Given these numbers MSE GC will remove just one audio block (since current 4057 // Given these numbers MSE GC will remove just one audio block (since current
3976 // audio size is 80 bytes, new data is 28 bytes, we need to remove just one 10 4058 // audio size is 80 bytes, new data is 28 bytes, we need to remove just one 10
3977 // byte block to stay under 100 bytes memory limit after append 4059 // byte block to stay under 100 bytes memory limit after append
3978 // 80 - 10 + 28 = 98). 4060 // 80 - 10 + 28 = 98).
3979 // For video stream 150 + 52 = 202. Video limit is 150 bytes. We need to 4061 // For video stream 150 + 52 = 202. Video limit is 150 bytes. We need to
3980 // remove at least 6 blocks to stay under limit. 4062 // remove at least 6 blocks to stay under limit.
3981 CheckExpectedBuffers(audio_stream, "40K 80K 120K 160K 200K 240K 280K"); 4063 CheckExpectedBuffers(audio_stream, "40K 80K 120K 160K 200K 240K 280K");
3982 CheckExpectedBuffers(video_stream, "60K 70 80K 90 100K 110 120K 130 140K"); 4064 CheckExpectedBuffers(video_stream, "60K 70 80K 90 100K 110 120K 130 140K");
3983 } 4065 }
3984 4066
4067 TEST_F(ChunkDemuxerTest, SegmentMissingAudioFrame_AudioOnly) {
chcunningham 2016/01/07 22:23:57 These are work-in-progress I think?
wolenetz 2016/01/07 22:37:09 Correct. I need to add strict medialog expectation
wolenetz 2016/01/16 01:23:35 Done.
4068 ASSERT_TRUE(InitDemuxer(HAS_AUDIO));
4069 AppendCluster(GenerateEmptyCluster(0));
4070 }
4071
4072 TEST_F(ChunkDemuxerTest, SegmentMissingVideoFrame_VideoOnly) {
4073 ASSERT_TRUE(InitDemuxer(HAS_VIDEO));
4074 AppendCluster(GenerateEmptyCluster(0));
4075 }
4076
4077 TEST_F(ChunkDemuxerTest, SegmentMissingAudioFrame_AudioVideo) {
4078 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
4079 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, 0, 10);
4080 }
4081
4082 TEST_F(ChunkDemuxerTest, SegmentMissingVideoFrame_AudioVideo) {
4083 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
4084 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, 0, 10);
4085 }
4086
4087 TEST_F(ChunkDemuxerTest, SegmentMissingAudioVideoFrames) {
4088 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
4089 AppendCluster(GenerateEmptyCluster(0));
4090 }
4091
3985 } // namespace media 4092 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698