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

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

Issue 547223003: MSE: Notify Blink SourceBuffer on init segment received (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits. Plan is to depend on blink-side CL landing first (https://codereview.chromium.org/55294… Created 6 years, 3 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // has been appended. This cluster starts with blocks that 155 // has been appended. This cluster starts with blocks that
156 // have timestamps consistent with the end times of the blocks 156 // have timestamps consistent with the end times of the blocks
157 // in kDefaultFirstCluster() so that these two clusters represent 157 // in kDefaultFirstCluster() so that these two clusters represent
158 // a continuous region. 158 // a continuous region.
159 scoped_ptr<Cluster> kDefaultSecondCluster() { 159 scoped_ptr<Cluster> kDefaultSecondCluster() {
160 return GenerateCluster(46, 66, 5); 160 return GenerateCluster(46, 66, 5);
161 } 161 }
162 162
163 ChunkDemuxerTest() 163 ChunkDemuxerTest()
164 : append_window_end_for_next_append_(kInfiniteDuration()) { 164 : append_window_end_for_next_append_(kInfiniteDuration()) {
165 init_segment_received_cb_ =
166 base::Bind(&ChunkDemuxerTest::InitSegmentReceived,
167 base::Unretained(this));
165 CreateNewDemuxer(); 168 CreateNewDemuxer();
166 } 169 }
167 170
168 void CreateNewDemuxer() { 171 void CreateNewDemuxer() {
169 base::Closure open_cb = 172 base::Closure open_cb =
170 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this)); 173 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this));
171 Demuxer::NeedKeyCB need_key_cb = 174 Demuxer::NeedKeyCB need_key_cb =
172 base::Bind(&ChunkDemuxerTest::DemuxerNeedKey, base::Unretained(this)); 175 base::Bind(&ChunkDemuxerTest::DemuxerNeedKey, base::Unretained(this));
173 demuxer_.reset( 176 demuxer_.reset(
174 new ChunkDemuxer(open_cb, need_key_cb, base::Bind(&LogFunc), true)); 177 new ChunkDemuxer(open_cb, need_key_cb, base::Bind(&LogFunc), true));
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 AppendCluster(kSourceId, GenerateCluster(block_queue, false)); 569 AppendCluster(kSourceId, GenerateCluster(block_queue, false));
567 } 570 }
568 571
569 void AppendData(const std::string& source_id, 572 void AppendData(const std::string& source_id,
570 const uint8* data, size_t length) { 573 const uint8* data, size_t length) {
571 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); 574 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber());
572 575
573 demuxer_->AppendData(source_id, data, length, 576 demuxer_->AppendData(source_id, data, length,
574 append_window_start_for_next_append_, 577 append_window_start_for_next_append_,
575 append_window_end_for_next_append_, 578 append_window_end_for_next_append_,
576 &timestamp_offset_map_[source_id]); 579 &timestamp_offset_map_[source_id],
580 init_segment_received_cb_);
577 } 581 }
578 582
579 void AppendDataInPieces(const uint8* data, size_t length) { 583 void AppendDataInPieces(const uint8* data, size_t length) {
580 AppendDataInPieces(data, length, 7); 584 AppendDataInPieces(data, length, 7);
581 } 585 }
582 586
583 void AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { 587 void AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) {
584 const uint8* start = data; 588 const uint8* start = data;
585 const uint8* end = data + length; 589 const uint8* end = data + length;
586 while (start < end) { 590 while (start < end) {
587 size_t append_size = std::min(piece_size, 591 size_t append_size = std::min(piece_size,
588 static_cast<size_t>(end - start)); 592 static_cast<size_t>(end - start));
589 AppendData(start, append_size); 593 AppendData(start, append_size);
590 start += append_size; 594 start += append_size;
591 } 595 }
592 } 596 }
593 597
594 void AppendInitSegment(int stream_flags) { 598 void AppendInitSegment(int stream_flags, bool expect_init_segment_received) {
595 AppendInitSegmentWithSourceId(kSourceId, stream_flags); 599 AppendInitSegmentWithSourceId(kSourceId, stream_flags,
600 expect_init_segment_received);
596 } 601 }
597 602
598 void AppendInitSegmentWithSourceId(const std::string& source_id, 603 void AppendInitSegmentWithSourceId(const std::string& source_id,
599 int stream_flags) { 604 int stream_flags,
600 AppendInitSegmentWithEncryptedInfo(source_id, stream_flags, false, false); 605 bool expect_init_segment_received) {
606 AppendInitSegmentWithEncryptedInfo(source_id, stream_flags,
607 expect_init_segment_received,
608 false, false);
601 } 609 }
602 610
603 void AppendInitSegmentWithEncryptedInfo(const std::string& source_id, 611 void AppendInitSegmentWithEncryptedInfo(const std::string& source_id,
604 int stream_flags, 612 int stream_flags,
613 bool expect_init_segment_received,
605 bool is_audio_encrypted, 614 bool is_audio_encrypted,
606 bool is_video_encrypted) { 615 bool is_video_encrypted) {
616 DCHECK(!expect_init_segment_received || stream_flags > 0)
617 << "Do not expect an init segment received when there are no tracks";
607 scoped_ptr<uint8[]> info_tracks; 618 scoped_ptr<uint8[]> info_tracks;
608 int info_tracks_size = 0; 619 int info_tracks_size = 0;
609 CreateInitSegment(stream_flags, 620 CreateInitSegment(stream_flags,
610 is_audio_encrypted, is_video_encrypted, 621 is_audio_encrypted, is_video_encrypted,
611 &info_tracks, &info_tracks_size); 622 &info_tracks, &info_tracks_size);
623 if (expect_init_segment_received)
624 EXPECT_CALL(*this, InitSegmentReceived());
612 AppendData(source_id, info_tracks.get(), info_tracks_size); 625 AppendData(source_id, info_tracks.get(), info_tracks_size);
613 } 626 }
614 627
615 void AppendGarbage() { 628 void AppendGarbage() {
616 // Fill up an array with gibberish. 629 // Fill up an array with gibberish.
617 int garbage_cluster_size = 10; 630 int garbage_cluster_size = 10;
618 scoped_ptr<uint8[]> garbage_cluster(new uint8[garbage_cluster_size]); 631 scoped_ptr<uint8[]> garbage_cluster(new uint8[garbage_cluster_size]);
619 for (int i = 0; i < garbage_cluster_size; ++i) 632 for (int i = 0; i < garbage_cluster_size; ++i)
620 garbage_cluster[i] = i; 633 garbage_cluster[i] = i;
621 AppendData(garbage_cluster.get(), garbage_cluster_size); 634 AppendData(garbage_cluster.get(), garbage_cluster_size);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 int stream_flags, bool is_audio_encrypted, bool is_video_encrypted) { 670 int stream_flags, bool is_audio_encrypted, bool is_video_encrypted) {
658 671
659 PipelineStatus expected_status = 672 PipelineStatus expected_status =
660 (stream_flags != 0) ? PIPELINE_OK : DEMUXER_ERROR_COULD_NOT_OPEN; 673 (stream_flags != 0) ? PIPELINE_OK : DEMUXER_ERROR_COULD_NOT_OPEN;
661 674
662 base::TimeDelta expected_duration = kNoTimestamp(); 675 base::TimeDelta expected_duration = kNoTimestamp();
663 if (expected_status == PIPELINE_OK) 676 if (expected_status == PIPELINE_OK)
664 expected_duration = kDefaultDuration(); 677 expected_duration = kDefaultDuration();
665 678
666 EXPECT_CALL(*this, DemuxerOpened()); 679 EXPECT_CALL(*this, DemuxerOpened());
680
681 // Adding expectation prior to CreateInitDoneCB() here because InSequence
682 // tests require init segment received before duration set. Also, only
683 // expect an init segment received callback if there is actually a track in
684 // it.
685 if (stream_flags != 0)
686 EXPECT_CALL(*this, InitSegmentReceived());
687
667 demuxer_->Initialize( 688 demuxer_->Initialize(
668 &host_, CreateInitDoneCB(expected_duration, expected_status), true); 689 &host_, CreateInitDoneCB(expected_duration, expected_status), true);
669 690
670 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk) 691 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk)
671 return false; 692 return false;
672 693
673 AppendInitSegmentWithEncryptedInfo( 694 AppendInitSegmentWithEncryptedInfo(
674 kSourceId, stream_flags, 695 kSourceId, stream_flags, false,
675 is_audio_encrypted, is_video_encrypted); 696 is_audio_encrypted, is_video_encrypted);
676 return true; 697 return true;
677 } 698 }
678 699
679 bool InitDemuxerAudioAndVideoSourcesText(const std::string& audio_id, 700 bool InitDemuxerAudioAndVideoSourcesText(const std::string& audio_id,
680 const std::string& video_id, 701 const std::string& video_id,
681 bool has_text) { 702 bool has_text) {
682 EXPECT_CALL(*this, DemuxerOpened()); 703 EXPECT_CALL(*this, DemuxerOpened());
683 demuxer_->Initialize( 704 demuxer_->Initialize(
684 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 705 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
685 706
686 if (AddId(audio_id, HAS_AUDIO) != ChunkDemuxer::kOk) 707 if (AddId(audio_id, HAS_AUDIO) != ChunkDemuxer::kOk)
687 return false; 708 return false;
688 if (AddId(video_id, HAS_VIDEO) != ChunkDemuxer::kOk) 709 if (AddId(video_id, HAS_VIDEO) != ChunkDemuxer::kOk)
689 return false; 710 return false;
690 711
691 int audio_flags = HAS_AUDIO; 712 int audio_flags = HAS_AUDIO;
692 int video_flags = HAS_VIDEO; 713 int video_flags = HAS_VIDEO;
693 714
694 if (has_text) { 715 if (has_text) {
695 audio_flags |= HAS_TEXT; 716 audio_flags |= HAS_TEXT;
696 video_flags |= HAS_TEXT; 717 video_flags |= HAS_TEXT;
697 } 718 }
698 719
699 AppendInitSegmentWithSourceId(audio_id, audio_flags); 720 AppendInitSegmentWithSourceId(audio_id, audio_flags, true);
700 AppendInitSegmentWithSourceId(video_id, video_flags); 721 AppendInitSegmentWithSourceId(video_id, video_flags, true);
701 return true; 722 return true;
702 } 723 }
703 724
704 bool InitDemuxerAudioAndVideoSources(const std::string& audio_id, 725 bool InitDemuxerAudioAndVideoSources(const std::string& audio_id,
705 const std::string& video_id) { 726 const std::string& video_id) {
706 return InitDemuxerAudioAndVideoSourcesText(audio_id, video_id, false); 727 return InitDemuxerAudioAndVideoSourcesText(audio_id, video_id, false);
707 } 728 }
708 729
709 // Initializes the demuxer with data from 2 files with different 730 // Initializes the demuxer with data from 2 files with different
710 // decoder configurations. This is used to test the decoder config change 731 // decoder configurations. This is used to test the decoder config change
(...skipping 11 matching lines...) Expand all
722 // The resulting audio stream returns data from each file for the following 743 // The resulting audio stream returns data from each file for the following
723 // time ranges. 744 // time ranges.
724 // bear-320x240.webm : [0-524) [779-2736) 745 // bear-320x240.webm : [0-524) [779-2736)
725 // bear-640x360.webm : [527-759) 746 // bear-640x360.webm : [527-759)
726 bool InitDemuxerWithConfigChangeData() { 747 bool InitDemuxerWithConfigChangeData() {
727 scoped_refptr<DecoderBuffer> bear1 = ReadTestDataFile("bear-320x240.webm"); 748 scoped_refptr<DecoderBuffer> bear1 = ReadTestDataFile("bear-320x240.webm");
728 scoped_refptr<DecoderBuffer> bear2 = ReadTestDataFile("bear-640x360.webm"); 749 scoped_refptr<DecoderBuffer> bear2 = ReadTestDataFile("bear-640x360.webm");
729 750
730 EXPECT_CALL(*this, DemuxerOpened()); 751 EXPECT_CALL(*this, DemuxerOpened());
731 752
753 // Adding expectation prior to CreateInitDoneCB() here because InSequence
754 // tests require init segment received before duration set.
755 EXPECT_CALL(*this, InitSegmentReceived());
732 demuxer_->Initialize( 756 demuxer_->Initialize(
733 &host_, CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), 757 &host_, CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744),
734 PIPELINE_OK), true); 758 PIPELINE_OK), true);
735 759
736 if (AddId(kSourceId, HAS_AUDIO | HAS_VIDEO) != ChunkDemuxer::kOk) 760 if (AddId(kSourceId, HAS_AUDIO | HAS_VIDEO) != ChunkDemuxer::kOk)
737 return false; 761 return false;
738 762
739 // Append the whole bear1 file. 763 // Append the whole bear1 file.
740 // TODO(wolenetz/acolwell): Remove this extra SetDuration expectation once 764 // TODO(wolenetz/acolwell): Remove this extra SetDuration expectation once
741 // the files are fixed to have the correct duration in their init segments, 765 // the files are fixed to have the correct duration in their init segments,
742 // and the CreateInitDoneCB() call, above, is fixed to used that duration. 766 // and the CreateInitDoneCB() call, above, is fixed to used that duration.
743 // See http://crbug.com/354284. 767 // See http://crbug.com/354284.
744 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746))); 768 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746)));
745 AppendData(bear1->data(), bear1->data_size()); 769 AppendData(bear1->data(), bear1->data_size());
746 // Last audio frame has timestamp 2721 and duration 24 (estimated from max 770 // Last audio frame has timestamp 2721 and duration 24 (estimated from max
747 // seen so far for audio track). 771 // seen so far for audio track).
748 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry 772 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry
749 // DefaultDuration for video track). 773 // DefaultDuration for video track).
750 CheckExpectedRanges(kSourceId, "{ [0,2736) }"); 774 CheckExpectedRanges(kSourceId, "{ [0,2736) }");
751 775
752 // Append initialization segment for bear2. 776 // Append initialization segment for bear2.
753 // Note: Offsets here and below are derived from 777 // Note: Offsets here and below are derived from
754 // media/test/data/bear-640x360-manifest.js and 778 // media/test/data/bear-640x360-manifest.js and
755 // media/test/data/bear-320x240-manifest.js which were 779 // media/test/data/bear-320x240-manifest.js which were
756 // generated from media/test/data/bear-640x360.webm and 780 // generated from media/test/data/bear-640x360.webm and
757 // media/test/data/bear-320x240.webm respectively. 781 // media/test/data/bear-320x240.webm respectively.
782 EXPECT_CALL(*this, InitSegmentReceived());
758 AppendData(bear2->data(), 4340); 783 AppendData(bear2->data(), 4340);
759 784
760 // Append a media segment that goes from [0.527000, 1.014000). 785 // Append a media segment that goes from [0.527000, 1.014000).
761 AppendData(bear2->data() + 55290, 18785); 786 AppendData(bear2->data() + 55290, 18785);
762 CheckExpectedRanges(kSourceId, "{ [0,1027) [1201,2736) }"); 787 CheckExpectedRanges(kSourceId, "{ [0,1027) [1201,2736) }");
763 788
764 // Append initialization segment for bear1 & fill gap with [779-1197) 789 // Append initialization segment for bear1 & fill gap with [779-1197)
765 // segment. 790 // segment.
791 EXPECT_CALL(*this, InitSegmentReceived());
766 AppendData(bear1->data(), 4370); 792 AppendData(bear1->data(), 4370);
767 AppendData(bear1->data() + 72737, 28183); 793 AppendData(bear1->data() + 72737, 28183);
768 CheckExpectedRanges(kSourceId, "{ [0,2736) }"); 794 CheckExpectedRanges(kSourceId, "{ [0,2736) }");
769 795
770 MarkEndOfStream(PIPELINE_OK); 796 MarkEndOfStream(PIPELINE_OK);
771 return true; 797 return true;
772 } 798 }
773 799
774 void ShutdownDemuxer() { 800 void ShutdownDemuxer() {
775 if (demuxer_) { 801 if (demuxer_) {
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 int stream_flags) { 1106 int stream_flags) {
1081 EXPECT_CALL(*this, DemuxerOpened()); 1107 EXPECT_CALL(*this, DemuxerOpened());
1082 demuxer_->Initialize( 1108 demuxer_->Initialize(
1083 &host_, CreateInitDoneCB(duration, PIPELINE_OK), true); 1109 &host_, CreateInitDoneCB(duration, PIPELINE_OK), true);
1084 1110
1085 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk) 1111 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk)
1086 return false; 1112 return false;
1087 1113
1088 // Read a WebM file into memory and send the data to the demuxer. 1114 // Read a WebM file into memory and send the data to the demuxer.
1089 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); 1115 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename);
1116 EXPECT_CALL(*this, InitSegmentReceived());
1090 AppendDataInPieces(buffer->data(), buffer->data_size(), 512); 1117 AppendDataInPieces(buffer->data(), buffer->data_size(), 512);
1091 1118
1092 // Verify that the timestamps on the first few packets match what we 1119 // Verify that the timestamps on the first few packets match what we
1093 // expect. 1120 // expect.
1094 for (size_t i = 0; 1121 for (size_t i = 0;
1095 (timestamps[i].audio_time_ms != kSkip || 1122 (timestamps[i].audio_time_ms != kSkip ||
1096 timestamps[i].video_time_ms != kSkip); 1123 timestamps[i].video_time_ms != kSkip);
1097 i++) { 1124 i++) {
1098 bool audio_read_done = false; 1125 bool audio_read_done = false;
1099 bool video_read_done = false; 1126 bool video_read_done = false;
(...skipping 24 matching lines...) Expand all
1124 // (http://code.google.com/p/googletest/issues/detail?id=395) or when we use 1151 // (http://code.google.com/p/googletest/issues/detail?id=395) or when we use
1125 // std::string instead of scoped_ptr<uint8[]> (http://crbug.com/130689). 1152 // std::string instead of scoped_ptr<uint8[]> (http://crbug.com/130689).
1126 MOCK_METHOD3(NeedKeyMock, void(const std::string& type, 1153 MOCK_METHOD3(NeedKeyMock, void(const std::string& type,
1127 const uint8* init_data, int init_data_size)); 1154 const uint8* init_data, int init_data_size));
1128 void DemuxerNeedKey(const std::string& type, 1155 void DemuxerNeedKey(const std::string& type,
1129 const std::vector<uint8>& init_data) { 1156 const std::vector<uint8>& init_data) {
1130 const uint8* init_data_ptr = init_data.empty() ? NULL : &init_data[0]; 1157 const uint8* init_data_ptr = init_data.empty() ? NULL : &init_data[0];
1131 NeedKeyMock(type, init_data_ptr, init_data.size()); 1158 NeedKeyMock(type, init_data_ptr, init_data.size());
1132 } 1159 }
1133 1160
1161 MOCK_METHOD0(InitSegmentReceived, void(void));
1162
1134 void Seek(base::TimeDelta seek_time) { 1163 void Seek(base::TimeDelta seek_time) {
1135 demuxer_->StartWaitingForSeek(seek_time); 1164 demuxer_->StartWaitingForSeek(seek_time);
1136 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); 1165 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK));
1137 message_loop_.RunUntilIdle(); 1166 message_loop_.RunUntilIdle();
1138 } 1167 }
1139 1168
1140 void MarkEndOfStream(PipelineStatus status) { 1169 void MarkEndOfStream(PipelineStatus status) {
1141 demuxer_->MarkEndOfStream(status); 1170 demuxer_->MarkEndOfStream(status);
1142 message_loop_.RunUntilIdle(); 1171 message_loop_.RunUntilIdle();
1143 } 1172 }
1144 1173
1145 bool SetTimestampOffset(const std::string& id, 1174 bool SetTimestampOffset(const std::string& id,
1146 base::TimeDelta timestamp_offset) { 1175 base::TimeDelta timestamp_offset) {
1147 if (demuxer_->IsParsingMediaSegment(id)) 1176 if (demuxer_->IsParsingMediaSegment(id))
1148 return false; 1177 return false;
1149 1178
1150 timestamp_offset_map_[id] = timestamp_offset; 1179 timestamp_offset_map_[id] = timestamp_offset;
1151 return true; 1180 return true;
1152 } 1181 }
1153 1182
1154 base::MessageLoop message_loop_; 1183 base::MessageLoop message_loop_;
1155 MockDemuxerHost host_; 1184 MockDemuxerHost host_;
1156 1185
1157 scoped_ptr<ChunkDemuxer> demuxer_; 1186 scoped_ptr<ChunkDemuxer> demuxer_;
1187 ChunkDemuxer::InitSegmentReceivedCB init_segment_received_cb_;
1158 1188
1159 base::TimeDelta append_window_start_for_next_append_; 1189 base::TimeDelta append_window_start_for_next_append_;
1160 base::TimeDelta append_window_end_for_next_append_; 1190 base::TimeDelta append_window_end_for_next_append_;
1161 1191
1162 // Map of source id to timestamp offset to use for the next AppendData() 1192 // Map of source id to timestamp offset to use for the next AppendData()
1163 // operation for that source id. 1193 // operation for that source id.
1164 std::map<std::string, base::TimeDelta> timestamp_offset_map_; 1194 std::map<std::string, base::TimeDelta> timestamp_offset_map_;
1165 1195
1166 private: 1196 private:
1167 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); 1197 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 MuxedStreamInfo(kAudioTrackNum, "0K 23K"), 1360 MuxedStreamInfo(kAudioTrackNum, "0K 23K"),
1331 MuxedStreamInfo(kVideoTrackNum, "0K 30"), 1361 MuxedStreamInfo(kVideoTrackNum, "0K 30"),
1332 MuxedStreamInfo(kTextTrackNum, "10K")); 1362 MuxedStreamInfo(kTextTrackNum, "10K"));
1333 CheckExpectedRanges(kSourceId, "{ [0,46) }"); 1363 CheckExpectedRanges(kSourceId, "{ [0,46) }");
1334 1364
1335 scoped_ptr<uint8[]> info_tracks; 1365 scoped_ptr<uint8[]> info_tracks;
1336 int info_tracks_size = 0; 1366 int info_tracks_size = 0;
1337 CreateInitSegmentWithAlternateTextTrackNum(HAS_TEXT | HAS_AUDIO | HAS_VIDEO, 1367 CreateInitSegmentWithAlternateTextTrackNum(HAS_TEXT | HAS_AUDIO | HAS_VIDEO,
1338 false, false, 1368 false, false,
1339 &info_tracks, &info_tracks_size); 1369 &info_tracks, &info_tracks_size);
1370 EXPECT_CALL(*this, InitSegmentReceived());
1340 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, 1371 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size,
1341 append_window_start_for_next_append_, 1372 append_window_start_for_next_append_,
1342 append_window_end_for_next_append_, 1373 append_window_end_for_next_append_,
1343 &timestamp_offset_map_[kSourceId]); 1374 &timestamp_offset_map_[kSourceId],
1375 init_segment_received_cb_);
1344 1376
1345 AppendMuxedCluster( 1377 AppendMuxedCluster(
1346 MuxedStreamInfo(kAudioTrackNum, "46K 69K"), 1378 MuxedStreamInfo(kAudioTrackNum, "46K 69K"),
1347 MuxedStreamInfo(kVideoTrackNum, "60K"), 1379 MuxedStreamInfo(kVideoTrackNum, "60K"),
1348 MuxedStreamInfo(kAlternateTextTrackNum, "45K")); 1380 MuxedStreamInfo(kAlternateTextTrackNum, "45K"));
1349 1381
1350 CheckExpectedRanges(kSourceId, "{ [0,92) }"); 1382 CheckExpectedRanges(kSourceId, "{ [0,92) }");
1351 CheckExpectedBuffers(audio_stream, "0 23 46 69"); 1383 CheckExpectedBuffers(audio_stream, "0 23 46 69");
1352 CheckExpectedBuffers(video_stream, "0 30 60"); 1384 CheckExpectedBuffers(video_stream, "0 30 60");
1353 CheckExpectedBuffers(text_stream, "10 45"); 1385 CheckExpectedBuffers(text_stream, "10 45");
(...skipping 17 matching lines...) Expand all
1371 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); 1403 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
1372 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 1404 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
1373 ASSERT_TRUE(audio_stream && video_stream && text_stream); 1405 ASSERT_TRUE(audio_stream && video_stream && text_stream);
1374 1406
1375 AppendMuxedCluster( 1407 AppendMuxedCluster(
1376 MuxedStreamInfo(kAudioTrackNum, "23K"), 1408 MuxedStreamInfo(kAudioTrackNum, "23K"),
1377 MuxedStreamInfo(kVideoTrackNum, "0 30K"), 1409 MuxedStreamInfo(kVideoTrackNum, "0 30K"),
1378 MuxedStreamInfo(kTextTrackNum, "25K 40K")); 1410 MuxedStreamInfo(kTextTrackNum, "25K 40K"));
1379 CheckExpectedRanges(kSourceId, "{ [23,46) }"); 1411 CheckExpectedRanges(kSourceId, "{ [23,46) }");
1380 1412
1381 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); 1413 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO, true);
1382 AppendMuxedCluster( 1414 AppendMuxedCluster(
1383 MuxedStreamInfo(kAudioTrackNum, "46K 69K"), 1415 MuxedStreamInfo(kAudioTrackNum, "46K 69K"),
1384 MuxedStreamInfo(kVideoTrackNum, "60 90K"), 1416 MuxedStreamInfo(kVideoTrackNum, "60 90K"),
1385 MuxedStreamInfo(kTextTrackNum, "80K 90K")); 1417 MuxedStreamInfo(kTextTrackNum, "80K 90K"));
1386 CheckExpectedRanges(kSourceId, "{ [23,92) }"); 1418 CheckExpectedRanges(kSourceId, "{ [23,92) }");
1387 1419
1388 CheckExpectedBuffers(audio_stream, "23 46 69"); 1420 CheckExpectedBuffers(audio_stream, "23 46 69");
1389 CheckExpectedBuffers(video_stream, "30 90"); 1421 CheckExpectedBuffers(video_stream, "30 90");
1390 CheckExpectedBuffers(text_stream, "25 40 80 90"); 1422 CheckExpectedBuffers(text_stream, "25 40 80 90");
1391 } 1423 }
1392 1424
1393 // Make sure that the demuxer reports an error if Shutdown() 1425 // Make sure that the demuxer reports an error if Shutdown()
1394 // is called before all the initialization segments are appended. 1426 // is called before all the initialization segments are appended.
1395 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { 1427 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) {
1396 EXPECT_CALL(*this, DemuxerOpened()); 1428 EXPECT_CALL(*this, DemuxerOpened());
1397 demuxer_->Initialize( 1429 demuxer_->Initialize(
1398 &host_, CreateInitDoneCB( 1430 &host_, CreateInitDoneCB(
1399 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1431 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1400 1432
1401 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); 1433 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk);
1402 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); 1434 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk);
1403 1435
1404 AppendInitSegmentWithSourceId("audio", HAS_AUDIO); 1436 AppendInitSegmentWithSourceId("audio", HAS_AUDIO, true);
1405 1437
1406 ShutdownDemuxer(); 1438 ShutdownDemuxer();
1407 } 1439 }
1408 1440
1409 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) { 1441 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) {
1410 EXPECT_CALL(*this, DemuxerOpened()); 1442 EXPECT_CALL(*this, DemuxerOpened());
1411 demuxer_->Initialize( 1443 demuxer_->Initialize(
1412 &host_, CreateInitDoneCB( 1444 &host_, CreateInitDoneCB(
1413 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1445 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1414 1446
1415 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); 1447 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk);
1416 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); 1448 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk);
1417 1449
1418 EXPECT_CALL(host_, AddTextStream(_, _)) 1450 EXPECT_CALL(host_, AddTextStream(_, _))
1419 .Times(Exactly(1)); 1451 .Times(Exactly(1));
1420 1452
1421 AppendInitSegmentWithSourceId("video_and_text", HAS_VIDEO | HAS_TEXT); 1453 AppendInitSegmentWithSourceId("video_and_text", HAS_VIDEO | HAS_TEXT, true);
1422 1454
1423 ShutdownDemuxer(); 1455 ShutdownDemuxer();
1424 } 1456 }
1425 1457
1426 // Verifies that all streams waiting for data receive an end of stream 1458 // Verifies that all streams waiting for data receive an end of stream
1427 // buffer when Shutdown() is called. 1459 // buffer when Shutdown() is called.
1428 TEST_F(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) { 1460 TEST_F(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) {
1429 DemuxerStream* text_stream = NULL; 1461 DemuxerStream* text_stream = NULL;
1430 EXPECT_CALL(host_, AddTextStream(_, _)) 1462 EXPECT_CALL(host_, AddTextStream(_, _))
1431 .WillOnce(SaveArg<0>(&text_stream)); 1463 .WillOnce(SaveArg<0>(&text_stream));
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 1551
1520 // Test the case where AppendData() is called before Init(). 1552 // Test the case where AppendData() is called before Init().
1521 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) { 1553 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) {
1522 scoped_ptr<uint8[]> info_tracks; 1554 scoped_ptr<uint8[]> info_tracks;
1523 int info_tracks_size = 0; 1555 int info_tracks_size = 0;
1524 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, 1556 CreateInitSegment(HAS_AUDIO | HAS_VIDEO,
1525 false, false, &info_tracks, &info_tracks_size); 1557 false, false, &info_tracks, &info_tracks_size);
1526 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, 1558 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size,
1527 append_window_start_for_next_append_, 1559 append_window_start_for_next_append_,
1528 append_window_end_for_next_append_, 1560 append_window_end_for_next_append_,
1529 &timestamp_offset_map_[kSourceId]); 1561 &timestamp_offset_map_[kSourceId],
1562 init_segment_received_cb_);
1530 } 1563 }
1531 1564
1532 // Make sure Read() callbacks are dispatched with the proper data. 1565 // Make sure Read() callbacks are dispatched with the proper data.
1533 TEST_F(ChunkDemuxerTest, Read) { 1566 TEST_F(ChunkDemuxerTest, Read) {
1534 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1567 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1535 1568
1536 AppendCluster(kDefaultFirstCluster()); 1569 AppendCluster(kDefaultFirstCluster());
1537 1570
1538 bool audio_read_done = false; 1571 bool audio_read_done = false;
1539 bool video_read_done = false; 1572 bool video_read_done = false;
(...skipping 15 matching lines...) Expand all
1555 1588
1556 // Make sure that AppendCluster() does not fail with a cluster that has 1589 // Make sure that AppendCluster() does not fail with a cluster that has
1557 // overlaps with the previously appended cluster. 1590 // overlaps with the previously appended cluster.
1558 AppendCluster(GenerateCluster(5, 4)); 1591 AppendCluster(GenerateCluster(5, 4));
1559 1592
1560 // Verify that AppendData() can still accept more data. 1593 // Verify that AppendData() can still accept more data.
1561 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); 1594 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2));
1562 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(), 1595 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(),
1563 append_window_start_for_next_append_, 1596 append_window_start_for_next_append_,
1564 append_window_end_for_next_append_, 1597 append_window_end_for_next_append_,
1565 &timestamp_offset_map_[kSourceId]); 1598 &timestamp_offset_map_[kSourceId],
1599 init_segment_received_cb_);
1566 } 1600 }
1567 1601
1568 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) { 1602 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) {
1569 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1603 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1570 AppendCluster(kDefaultFirstCluster()); 1604 AppendCluster(kDefaultFirstCluster());
1571 1605
1572 ClusterBuilder cb; 1606 ClusterBuilder cb;
1573 1607
1574 // Test the case where block timecodes are not monotonically 1608 // Test the case where block timecodes are not monotonically
1575 // increasing but stay above the cluster timecode. 1609 // increasing but stay above the cluster timecode.
1576 cb.SetClusterTimecode(5); 1610 cb.SetClusterTimecode(5);
1577 AddSimpleBlock(&cb, kAudioTrackNum, 5); 1611 AddSimpleBlock(&cb, kAudioTrackNum, 5);
1578 AddSimpleBlock(&cb, kVideoTrackNum, 10); 1612 AddSimpleBlock(&cb, kVideoTrackNum, 10);
1579 AddSimpleBlock(&cb, kAudioTrackNum, 7); 1613 AddSimpleBlock(&cb, kAudioTrackNum, 7);
1580 AddSimpleBlock(&cb, kVideoTrackNum, 15); 1614 AddSimpleBlock(&cb, kVideoTrackNum, 15);
1581 1615
1582 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1616 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1583 AppendCluster(cb.Finish()); 1617 AppendCluster(cb.Finish());
1584 1618
1585 // Verify that AppendData() ignores data after the error. 1619 // Verify that AppendData() ignores data after the error.
1586 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); 1620 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2));
1587 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), 1621 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(),
1588 append_window_start_for_next_append_, 1622 append_window_start_for_next_append_,
1589 append_window_end_for_next_append_, 1623 append_window_end_for_next_append_,
1590 &timestamp_offset_map_[kSourceId]); 1624 &timestamp_offset_map_[kSourceId],
1625 init_segment_received_cb_);
1591 } 1626 }
1592 1627
1593 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) { 1628 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) {
1594 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1629 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1595 AppendCluster(kDefaultFirstCluster()); 1630 AppendCluster(kDefaultFirstCluster());
1596 1631
1597 ClusterBuilder cb; 1632 ClusterBuilder cb;
1598 1633
1599 // Test timecodes going backwards and including values less than the cluster 1634 // Test timecodes going backwards and including values less than the cluster
1600 // timecode. 1635 // timecode.
1601 cb.SetClusterTimecode(5); 1636 cb.SetClusterTimecode(5);
1602 AddSimpleBlock(&cb, kAudioTrackNum, 5); 1637 AddSimpleBlock(&cb, kAudioTrackNum, 5);
1603 AddSimpleBlock(&cb, kVideoTrackNum, 5); 1638 AddSimpleBlock(&cb, kVideoTrackNum, 5);
1604 AddSimpleBlock(&cb, kAudioTrackNum, 3); 1639 AddSimpleBlock(&cb, kAudioTrackNum, 3);
1605 AddSimpleBlock(&cb, kVideoTrackNum, 3); 1640 AddSimpleBlock(&cb, kVideoTrackNum, 3);
1606 1641
1607 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1642 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1608 AppendCluster(cb.Finish()); 1643 AppendCluster(cb.Finish());
1609 1644
1610 // Verify that AppendData() ignores data after the error. 1645 // Verify that AppendData() ignores data after the error.
1611 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); 1646 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2));
1612 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), 1647 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(),
1613 append_window_start_for_next_append_, 1648 append_window_start_for_next_append_,
1614 append_window_end_for_next_append_, 1649 append_window_end_for_next_append_,
1615 &timestamp_offset_map_[kSourceId]); 1650 &timestamp_offset_map_[kSourceId],
1651 init_segment_received_cb_);
1616 } 1652 }
1617 1653
1618 1654
1619 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) { 1655 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) {
1620 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1656 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1621 AppendCluster(kDefaultFirstCluster()); 1657 AppendCluster(kDefaultFirstCluster());
1622 1658
1623 ClusterBuilder cb; 1659 ClusterBuilder cb;
1624 1660
1625 // Test monotonic increasing timestamps on a per stream 1661 // Test monotonic increasing timestamps on a per stream
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 uint8* dst = buffer.get(); 1952 uint8* dst = buffer.get();
1917 memcpy(dst, info_tracks.get(), info_tracks_size); 1953 memcpy(dst, info_tracks.get(), info_tracks_size);
1918 dst += info_tracks_size; 1954 dst += info_tracks_size;
1919 1955
1920 memcpy(dst, cluster_a->data(), cluster_a->size()); 1956 memcpy(dst, cluster_a->data(), cluster_a->size());
1921 dst += cluster_a->size(); 1957 dst += cluster_a->size();
1922 1958
1923 memcpy(dst, cluster_b->data(), cluster_b->size()); 1959 memcpy(dst, cluster_b->data(), cluster_b->size());
1924 dst += cluster_b->size(); 1960 dst += cluster_b->size();
1925 1961
1962 EXPECT_CALL(*this, InitSegmentReceived());
1926 AppendDataInPieces(buffer.get(), buffer_size); 1963 AppendDataInPieces(buffer.get(), buffer_size);
1927 1964
1928 GenerateExpectedReads(0, 9); 1965 GenerateExpectedReads(0, 9);
1929 } 1966 }
1930 1967
1931 TEST_F(ChunkDemuxerTest, WebMFile_AudioAndVideo) { 1968 TEST_F(ChunkDemuxerTest, WebMFile_AudioAndVideo) {
1932 struct BufferTimestamps buffer_timestamps[] = { 1969 struct BufferTimestamps buffer_timestamps[] = {
1933 {0, 0}, 1970 {0, 0},
1934 {33, 3}, 1971 {33, 3},
1935 {67, 6}, 1972 {67, 6},
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 demuxer_->Initialize( 2111 demuxer_->Initialize(
2075 &host_, CreateInitDoneCB( 2112 &host_, CreateInitDoneCB(
2076 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 2113 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
2077 2114
2078 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); 2115 ASSERT_EQ(AddId(), ChunkDemuxer::kOk);
2079 2116
2080 uint8 tmp = 0; 2117 uint8 tmp = 0;
2081 demuxer_->AppendData(kSourceId, &tmp, 1, 2118 demuxer_->AppendData(kSourceId, &tmp, 1,
2082 append_window_start_for_next_append_, 2119 append_window_start_for_next_append_,
2083 append_window_end_for_next_append_, 2120 append_window_end_for_next_append_,
2084 &timestamp_offset_map_[kSourceId]); 2121 &timestamp_offset_map_[kSourceId],
2122 init_segment_received_cb_);
2085 } 2123 }
2086 2124
2087 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) { 2125 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) {
2088 EXPECT_CALL(*this, DemuxerOpened()); 2126 EXPECT_CALL(*this, DemuxerOpened());
2089 demuxer_->Initialize( 2127 demuxer_->Initialize(
2090 &host_, CreateInitDoneCB(kNoTimestamp(), 2128 &host_, CreateInitDoneCB(kNoTimestamp(),
2091 DEMUXER_ERROR_COULD_NOT_OPEN), true); 2129 DEMUXER_ERROR_COULD_NOT_OPEN), true);
2092 2130
2093 std::vector<std::string> codecs(1); 2131 std::vector<std::string> codecs(1);
2094 codecs[0] = "vorbis"; 2132 codecs[0] = "vorbis";
2095 ASSERT_EQ(demuxer_->AddId(kSourceId, "audio/webm", codecs), 2133 ASSERT_EQ(demuxer_->AddId(kSourceId, "audio/webm", codecs),
2096 ChunkDemuxer::kOk); 2134 ChunkDemuxer::kOk);
2097 2135
2098 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); 2136 AppendInitSegment(HAS_AUDIO | HAS_VIDEO, false);
2099 } 2137 }
2100 2138
2101 TEST_F(ChunkDemuxerTest, AVHeadersWithVideoOnlyType) { 2139 TEST_F(ChunkDemuxerTest, AVHeadersWithVideoOnlyType) {
2102 EXPECT_CALL(*this, DemuxerOpened()); 2140 EXPECT_CALL(*this, DemuxerOpened());
2103 demuxer_->Initialize( 2141 demuxer_->Initialize(
2104 &host_, CreateInitDoneCB(kNoTimestamp(), 2142 &host_, CreateInitDoneCB(kNoTimestamp(),
2105 DEMUXER_ERROR_COULD_NOT_OPEN), true); 2143 DEMUXER_ERROR_COULD_NOT_OPEN), true);
2106 2144
2107 std::vector<std::string> codecs(1); 2145 std::vector<std::string> codecs(1);
2108 codecs[0] = "vp8"; 2146 codecs[0] = "vp8";
2109 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs), 2147 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs),
2110 ChunkDemuxer::kOk); 2148 ChunkDemuxer::kOk);
2111 2149
2112 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); 2150 AppendInitSegment(HAS_AUDIO | HAS_VIDEO, false);
2113 } 2151 }
2114 2152
2115 TEST_F(ChunkDemuxerTest, MultipleHeaders) { 2153 TEST_F(ChunkDemuxerTest, MultipleHeaders) {
2116 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2154 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2117 2155
2118 AppendCluster(kDefaultFirstCluster()); 2156 AppendCluster(kDefaultFirstCluster());
2119 2157
2120 // Append another identical initialization segment. 2158 // Append another identical initialization segment.
2121 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); 2159 AppendInitSegment(HAS_AUDIO | HAS_VIDEO, true);
acolwell GONE FROM CHROMIUM 2014/09/10 18:02:38 nit: I'm not sure this bool param is helping all t
wolenetz 2014/09/11 22:40:37 Done.
2122 2160
2123 AppendCluster(kDefaultSecondCluster()); 2161 AppendCluster(kDefaultSecondCluster());
2124 2162
2125 GenerateExpectedReads(0, 9); 2163 GenerateExpectedReads(0, 9);
2126 } 2164 }
2127 2165
2128 TEST_F(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideo) { 2166 TEST_F(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideo) {
2129 std::string audio_id = "audio1"; 2167 std::string audio_id = "audio1";
2130 std::string video_id = "video1"; 2168 std::string video_id = "video1";
2131 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); 2169 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2165 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 2203 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
2166 2204
2167 std::string audio_id = "audio1"; 2205 std::string audio_id = "audio1";
2168 std::string video_id = "video1"; 2206 std::string video_id = "video1";
2169 2207
2170 ASSERT_EQ(AddId(audio_id, HAS_AUDIO), ChunkDemuxer::kOk); 2208 ASSERT_EQ(AddId(audio_id, HAS_AUDIO), ChunkDemuxer::kOk);
2171 2209
2172 // Adding an id with audio/video should fail because we already added audio. 2210 // Adding an id with audio/video should fail because we already added audio.
2173 ASSERT_EQ(AddId(), ChunkDemuxer::kReachedIdLimit); 2211 ASSERT_EQ(AddId(), ChunkDemuxer::kReachedIdLimit);
2174 2212
2175 AppendInitSegmentWithSourceId(audio_id, HAS_AUDIO); 2213 AppendInitSegmentWithSourceId(audio_id, HAS_AUDIO, true);
2176 2214
2177 // Adding an id after append should fail. 2215 // Adding an id after append should fail.
2178 ASSERT_EQ(AddId(video_id, HAS_VIDEO), ChunkDemuxer::kReachedIdLimit); 2216 ASSERT_EQ(AddId(video_id, HAS_VIDEO), ChunkDemuxer::kReachedIdLimit);
2179 } 2217 }
2180 2218
2181 // Test that Read() calls after a RemoveId() return "end of stream" buffers. 2219 // Test that Read() calls after a RemoveId() return "end of stream" buffers.
2182 TEST_F(ChunkDemuxerTest, RemoveId) { 2220 TEST_F(ChunkDemuxerTest, RemoveId) {
2183 std::string audio_id = "audio1"; 2221 std::string audio_id = "audio1";
2184 std::string video_id = "video1"; 2222 std::string video_id = "video1";
2185 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id)); 2223 ASSERT_TRUE(InitDemuxerAudioAndVideoSources(audio_id, video_id));
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
2397 ShutdownDemuxer(); 2435 ShutdownDemuxer();
2398 } 2436 }
2399 2437
2400 // Test ranges in an audio-only stream. 2438 // Test ranges in an audio-only stream.
2401 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) { 2439 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) {
2402 EXPECT_CALL(*this, DemuxerOpened()); 2440 EXPECT_CALL(*this, DemuxerOpened());
2403 demuxer_->Initialize( 2441 demuxer_->Initialize(
2404 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 2442 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
2405 2443
2406 ASSERT_EQ(AddId(kSourceId, HAS_AUDIO), ChunkDemuxer::kOk); 2444 ASSERT_EQ(AddId(kSourceId, HAS_AUDIO), ChunkDemuxer::kOk);
2407 AppendInitSegment(HAS_AUDIO); 2445 AppendInitSegment(HAS_AUDIO, true);
2408 2446
2409 // Test a simple cluster. 2447 // Test a simple cluster.
2410 AppendCluster( 2448 AppendCluster(
2411 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); 2449 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration));
2412 2450
2413 CheckExpectedRanges("{ [0,92) }"); 2451 CheckExpectedRanges("{ [0,92) }");
2414 2452
2415 // Append a disjoint cluster to check for two separate ranges. 2453 // Append a disjoint cluster to check for two separate ranges.
2416 AppendCluster(GenerateSingleStreamCluster( 2454 AppendCluster(GenerateSingleStreamCluster(
2417 150, 219, kAudioTrackNum, kAudioBlockDuration)); 2455 150, 219, kAudioTrackNum, kAudioBlockDuration));
2418 2456
2419 CheckExpectedRanges("{ [0,92) [150,219) }"); 2457 CheckExpectedRanges("{ [0,92) [150,219) }");
2420 } 2458 }
2421 2459
2422 // Test ranges in a video-only stream. 2460 // Test ranges in a video-only stream.
2423 TEST_F(ChunkDemuxerTest, GetBufferedRanges_VideoIdOnly) { 2461 TEST_F(ChunkDemuxerTest, GetBufferedRanges_VideoIdOnly) {
2424 EXPECT_CALL(*this, DemuxerOpened()); 2462 EXPECT_CALL(*this, DemuxerOpened());
2425 demuxer_->Initialize( 2463 demuxer_->Initialize(
2426 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 2464 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
2427 2465
2428 ASSERT_EQ(AddId(kSourceId, HAS_VIDEO), ChunkDemuxer::kOk); 2466 ASSERT_EQ(AddId(kSourceId, HAS_VIDEO), ChunkDemuxer::kOk);
2429 AppendInitSegment(HAS_VIDEO); 2467 AppendInitSegment(HAS_VIDEO, true);
2430 2468
2431 // Test a simple cluster. 2469 // Test a simple cluster.
2432 AppendCluster( 2470 AppendCluster(
2433 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); 2471 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration));
2434 2472
2435 CheckExpectedRanges("{ [0,132) }"); 2473 CheckExpectedRanges("{ [0,132) }");
2436 2474
2437 // Append a disjoint cluster to check for two separate ranges. 2475 // Append a disjoint cluster to check for two separate ranges.
2438 AppendCluster(GenerateSingleStreamCluster( 2476 AppendCluster(GenerateSingleStreamCluster(
2439 200, 299, kVideoTrackNum, kVideoBlockDuration)); 2477 200, 299, kVideoTrackNum, kVideoBlockDuration));
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
2997 // Audio: first PES: 3035 // Audio: first PES:
2998 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000] 3036 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000]
2999 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767] 3037 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767]
3000 // Video: last PES: 3038 // Video: last PES:
3001 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128] 3039 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128]
3002 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794] 3040 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794]
3003 // Audio: last PES: 3041 // Audio: last PES:
3004 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309] 3042 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309]
3005 3043
3006 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts"); 3044 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts");
3045 EXPECT_CALL(*this, InitSegmentReceived());
3007 AppendData(kSourceId, buffer->data(), buffer->data_size()); 3046 AppendData(kSourceId, buffer->data(), buffer->data_size());
3008 3047
3009 // Confirm we're in the middle of parsing a media segment. 3048 // Confirm we're in the middle of parsing a media segment.
3010 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); 3049 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId));
3011 3050
3012 // Abort on the Mpeg2 TS parser triggers the emission of the last video 3051 // Abort on the Mpeg2 TS parser triggers the emission of the last video
3013 // buffer which is pending in the stream parser. 3052 // buffer which is pending in the stream parser.
3014 Ranges<base::TimeDelta> range_before_abort = 3053 Ranges<base::TimeDelta> range_before_abort =
3015 demuxer_->GetBufferedRanges(kSourceId); 3054 demuxer_->GetBufferedRanges(kSourceId);
3016 demuxer_->Abort(kSourceId, 3055 demuxer_->Abort(kSourceId,
(...skipping 23 matching lines...) Expand all
3040 // Audio: first PES: 3079 // Audio: first PES:
3041 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000] 3080 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000]
3042 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767] 3081 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767]
3043 // Video: last PES: 3082 // Video: last PES:
3044 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128] 3083 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128]
3045 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794] 3084 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794]
3046 // Audio: last PES: 3085 // Audio: last PES:
3047 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309] 3086 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309]
3048 3087
3049 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts"); 3088 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts");
3089 EXPECT_CALL(*this, InitSegmentReceived());
3050 AppendData(kSourceId, buffer->data(), buffer->data_size()); 3090 AppendData(kSourceId, buffer->data(), buffer->data_size());
3051 3091
3052 // Confirm we're in the middle of parsing a media segment. 3092 // Confirm we're in the middle of parsing a media segment.
3053 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); 3093 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId));
3054 3094
3055 // Seek to a time corresponding to buffers that will be emitted during the 3095 // Seek to a time corresponding to buffers that will be emitted during the
3056 // abort. 3096 // abort.
3057 Seek(base::TimeDelta::FromMilliseconds(4110)); 3097 Seek(base::TimeDelta::FromMilliseconds(4110));
3058 3098
3059 // Abort on the Mpeg2 TS parser triggers the emission of the last video 3099 // Abort on the Mpeg2 TS parser triggers the emission of the last video
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
3399 3439
3400 // Set the append window to [50,150). 3440 // Set the append window to [50,150).
3401 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); 3441 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50);
3402 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(150); 3442 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(150);
3403 3443
3404 // Read a WebM file into memory and send the data to the demuxer. The chunk 3444 // Read a WebM file into memory and send the data to the demuxer. The chunk
3405 // size has been chosen carefully to ensure the preroll buffer used by the 3445 // size has been chosen carefully to ensure the preroll buffer used by the
3406 // partial append window trim must come from a previous Append() call. 3446 // partial append window trim must come from a previous Append() call.
3407 scoped_refptr<DecoderBuffer> buffer = 3447 scoped_refptr<DecoderBuffer> buffer =
3408 ReadTestDataFile("bear-320x240-audio-only.webm"); 3448 ReadTestDataFile("bear-320x240-audio-only.webm");
3449 EXPECT_CALL(*this, InitSegmentReceived());
3409 AppendDataInPieces(buffer->data(), buffer->data_size(), 128); 3450 AppendDataInPieces(buffer->data(), buffer->data_size(), 128);
3410 3451
3411 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3452 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3412 CheckExpectedBuffers(stream, "50P 50 62 86 109 122 125 128"); 3453 CheckExpectedBuffers(stream, "50P 50 62 86 109 122 125 128");
3413 } 3454 }
3414 3455
3415 TEST_F(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) { 3456 TEST_F(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) {
3416 EXPECT_CALL(*this, DemuxerOpened()); 3457 EXPECT_CALL(*this, DemuxerOpened());
3417 demuxer_->Initialize( 3458 demuxer_->Initialize(
3418 &host_, 3459 &host_,
3419 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), 3460 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK),
3420 true); 3461 true);
3421 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); 3462 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO));
3422 3463
3423 // Set the append window such that the first file is completely before the 3464 // Set the append window such that the first file is completely before the
3424 // append window. 3465 // append window.
3425 // TODO(wolenetz/acolwell): Update this duration once the files are fixed to 3466 // TODO(wolenetz/acolwell): Update this duration once the files are fixed to
3426 // have the correct duration in their init segments, and the 3467 // have the correct duration in their init segments, and the
3427 // CreateInitDoneCB() call, above, is fixed to used that duration. See 3468 // CreateInitDoneCB() call, above, is fixed to used that duration. See
3428 // http://crbug.com/354284. 3469 // http://crbug.com/354284.
3429 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746); 3470 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746);
3430 append_window_start_for_next_append_ = duration_1; 3471 append_window_start_for_next_append_ = duration_1;
3431 3472
3432 // Read a WebM file into memory and append the data. 3473 // Read a WebM file into memory and append the data.
3433 scoped_refptr<DecoderBuffer> buffer = 3474 scoped_refptr<DecoderBuffer> buffer =
3434 ReadTestDataFile("bear-320x240-audio-only.webm"); 3475 ReadTestDataFile("bear-320x240-audio-only.webm");
3476 EXPECT_CALL(*this, InitSegmentReceived());
3435 AppendDataInPieces(buffer->data(), buffer->data_size(), 512); 3477 AppendDataInPieces(buffer->data(), buffer->data_size(), 512);
3436 CheckExpectedRanges(kSourceId, "{ }"); 3478 CheckExpectedRanges(kSourceId, "{ }");
3437 3479
3438 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 3480 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
3439 AudioDecoderConfig config_1 = stream->audio_decoder_config(); 3481 AudioDecoderConfig config_1 = stream->audio_decoder_config();
3440 3482
3441 // Read a second WebM with a different config in and append the data. 3483 // Read a second WebM with a different config in and append the data.
3442 scoped_refptr<DecoderBuffer> buffer2 = 3484 scoped_refptr<DecoderBuffer> buffer2 =
3443 ReadTestDataFile("bear-320x240-audio-only-48khz.webm"); 3485 ReadTestDataFile("bear-320x240-audio-only-48khz.webm");
3486 EXPECT_CALL(*this, InitSegmentReceived());
3444 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber()); 3487 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber());
3445 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1)); 3488 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1));
3446 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512); 3489 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512);
3447 CheckExpectedRanges(kSourceId, "{ [2746,5519) }"); 3490 CheckExpectedRanges(kSourceId, "{ [2746,5519) }");
3448 3491
3449 Seek(duration_1); 3492 Seek(duration_1);
3450 ExpectConfigChanged(DemuxerStream::AUDIO); 3493 ExpectConfigChanged(DemuxerStream::AUDIO);
3451 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config())); 3494 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config()));
3452 CheckExpectedBuffers(stream, "2746 2767 2789 2810"); 3495 CheckExpectedBuffers(stream, "2746 2767 2789 2810");
3453 } 3496 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
3655 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { 3698 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) {
3656 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 3699 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
3657 3700
3658 AppendCluster(GenerateCluster(0, 0, 4)); 3701 AppendCluster(GenerateCluster(0, 0, 4));
3659 AppendData(kCuesHeader, sizeof(kCuesHeader)); 3702 AppendData(kCuesHeader, sizeof(kCuesHeader));
3660 AppendCluster(GenerateCluster(46, 66, 5)); 3703 AppendCluster(GenerateCluster(46, 66, 5));
3661 CheckExpectedRanges(kSourceId, "{ [0,115) }"); 3704 CheckExpectedRanges(kSourceId, "{ [0,115) }");
3662 } 3705 }
3663 3706
3664 } // namespace media 3707 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698