OLD | NEW |
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 Loading... |
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 Loading... |
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 ×tamp_offset_map_[source_id]); | 579 ×tamp_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) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 int stream_flags, bool is_audio_encrypted, bool is_video_encrypted) { | 661 int stream_flags, bool is_audio_encrypted, bool is_video_encrypted) { |
658 | 662 |
659 PipelineStatus expected_status = | 663 PipelineStatus expected_status = |
660 (stream_flags != 0) ? PIPELINE_OK : DEMUXER_ERROR_COULD_NOT_OPEN; | 664 (stream_flags != 0) ? PIPELINE_OK : DEMUXER_ERROR_COULD_NOT_OPEN; |
661 | 665 |
662 base::TimeDelta expected_duration = kNoTimestamp(); | 666 base::TimeDelta expected_duration = kNoTimestamp(); |
663 if (expected_status == PIPELINE_OK) | 667 if (expected_status == PIPELINE_OK) |
664 expected_duration = kDefaultDuration(); | 668 expected_duration = kDefaultDuration(); |
665 | 669 |
666 EXPECT_CALL(*this, DemuxerOpened()); | 670 EXPECT_CALL(*this, DemuxerOpened()); |
| 671 |
| 672 // Adding expectation prior to CreateInitDoneCB() here because InSequence |
| 673 // tests require init segment received before duration set. Also, only |
| 674 // expect an init segment received callback if there is actually a track in |
| 675 // it. |
| 676 if (stream_flags != 0) |
| 677 EXPECT_CALL(*this, InitSegmentReceived()); |
| 678 |
667 demuxer_->Initialize( | 679 demuxer_->Initialize( |
668 &host_, CreateInitDoneCB(expected_duration, expected_status), true); | 680 &host_, CreateInitDoneCB(expected_duration, expected_status), true); |
669 | 681 |
670 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk) | 682 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk) |
671 return false; | 683 return false; |
672 | 684 |
673 AppendInitSegmentWithEncryptedInfo( | 685 AppendInitSegmentWithEncryptedInfo( |
674 kSourceId, stream_flags, | 686 kSourceId, stream_flags, |
675 is_audio_encrypted, is_video_encrypted); | 687 is_audio_encrypted, is_video_encrypted); |
676 return true; | 688 return true; |
(...skipping 12 matching lines...) Expand all Loading... |
689 return false; | 701 return false; |
690 | 702 |
691 int audio_flags = HAS_AUDIO; | 703 int audio_flags = HAS_AUDIO; |
692 int video_flags = HAS_VIDEO; | 704 int video_flags = HAS_VIDEO; |
693 | 705 |
694 if (has_text) { | 706 if (has_text) { |
695 audio_flags |= HAS_TEXT; | 707 audio_flags |= HAS_TEXT; |
696 video_flags |= HAS_TEXT; | 708 video_flags |= HAS_TEXT; |
697 } | 709 } |
698 | 710 |
| 711 EXPECT_CALL(*this, InitSegmentReceived()); |
699 AppendInitSegmentWithSourceId(audio_id, audio_flags); | 712 AppendInitSegmentWithSourceId(audio_id, audio_flags); |
| 713 EXPECT_CALL(*this, InitSegmentReceived()); |
700 AppendInitSegmentWithSourceId(video_id, video_flags); | 714 AppendInitSegmentWithSourceId(video_id, video_flags); |
701 return true; | 715 return true; |
702 } | 716 } |
703 | 717 |
704 bool InitDemuxerAudioAndVideoSources(const std::string& audio_id, | 718 bool InitDemuxerAudioAndVideoSources(const std::string& audio_id, |
705 const std::string& video_id) { | 719 const std::string& video_id) { |
706 return InitDemuxerAudioAndVideoSourcesText(audio_id, video_id, false); | 720 return InitDemuxerAudioAndVideoSourcesText(audio_id, video_id, false); |
707 } | 721 } |
708 | 722 |
709 // Initializes the demuxer with data from 2 files with different | 723 // Initializes the demuxer with data from 2 files with different |
(...skipping 12 matching lines...) Expand all Loading... |
722 // The resulting audio stream returns data from each file for the following | 736 // The resulting audio stream returns data from each file for the following |
723 // time ranges. | 737 // time ranges. |
724 // bear-320x240.webm : [0-524) [779-2736) | 738 // bear-320x240.webm : [0-524) [779-2736) |
725 // bear-640x360.webm : [527-759) | 739 // bear-640x360.webm : [527-759) |
726 bool InitDemuxerWithConfigChangeData() { | 740 bool InitDemuxerWithConfigChangeData() { |
727 scoped_refptr<DecoderBuffer> bear1 = ReadTestDataFile("bear-320x240.webm"); | 741 scoped_refptr<DecoderBuffer> bear1 = ReadTestDataFile("bear-320x240.webm"); |
728 scoped_refptr<DecoderBuffer> bear2 = ReadTestDataFile("bear-640x360.webm"); | 742 scoped_refptr<DecoderBuffer> bear2 = ReadTestDataFile("bear-640x360.webm"); |
729 | 743 |
730 EXPECT_CALL(*this, DemuxerOpened()); | 744 EXPECT_CALL(*this, DemuxerOpened()); |
731 | 745 |
| 746 // Adding expectation prior to CreateInitDoneCB() here because InSequence |
| 747 // tests require init segment received before duration set. |
| 748 EXPECT_CALL(*this, InitSegmentReceived()); |
732 demuxer_->Initialize( | 749 demuxer_->Initialize( |
733 &host_, CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), | 750 &host_, CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), |
734 PIPELINE_OK), true); | 751 PIPELINE_OK), true); |
735 | 752 |
736 if (AddId(kSourceId, HAS_AUDIO | HAS_VIDEO) != ChunkDemuxer::kOk) | 753 if (AddId(kSourceId, HAS_AUDIO | HAS_VIDEO) != ChunkDemuxer::kOk) |
737 return false; | 754 return false; |
738 | 755 |
739 // Append the whole bear1 file. | 756 // Append the whole bear1 file. |
740 // TODO(wolenetz/acolwell): Remove this extra SetDuration expectation once | 757 // TODO(wolenetz/acolwell): Remove this extra SetDuration expectation once |
741 // the files are fixed to have the correct duration in their init segments, | 758 // 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. | 759 // and the CreateInitDoneCB() call, above, is fixed to used that duration. |
743 // See http://crbug.com/354284. | 760 // See http://crbug.com/354284. |
744 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746))); | 761 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746))); |
745 AppendData(bear1->data(), bear1->data_size()); | 762 AppendData(bear1->data(), bear1->data_size()); |
746 // Last audio frame has timestamp 2721 and duration 24 (estimated from max | 763 // Last audio frame has timestamp 2721 and duration 24 (estimated from max |
747 // seen so far for audio track). | 764 // seen so far for audio track). |
748 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry | 765 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry |
749 // DefaultDuration for video track). | 766 // DefaultDuration for video track). |
750 CheckExpectedRanges(kSourceId, "{ [0,2736) }"); | 767 CheckExpectedRanges(kSourceId, "{ [0,2736) }"); |
751 | 768 |
752 // Append initialization segment for bear2. | 769 // Append initialization segment for bear2. |
753 // Note: Offsets here and below are derived from | 770 // Note: Offsets here and below are derived from |
754 // media/test/data/bear-640x360-manifest.js and | 771 // media/test/data/bear-640x360-manifest.js and |
755 // media/test/data/bear-320x240-manifest.js which were | 772 // media/test/data/bear-320x240-manifest.js which were |
756 // generated from media/test/data/bear-640x360.webm and | 773 // generated from media/test/data/bear-640x360.webm and |
757 // media/test/data/bear-320x240.webm respectively. | 774 // media/test/data/bear-320x240.webm respectively. |
| 775 EXPECT_CALL(*this, InitSegmentReceived()); |
758 AppendData(bear2->data(), 4340); | 776 AppendData(bear2->data(), 4340); |
759 | 777 |
760 // Append a media segment that goes from [0.527000, 1.014000). | 778 // Append a media segment that goes from [0.527000, 1.014000). |
761 AppendData(bear2->data() + 55290, 18785); | 779 AppendData(bear2->data() + 55290, 18785); |
762 CheckExpectedRanges(kSourceId, "{ [0,1027) [1201,2736) }"); | 780 CheckExpectedRanges(kSourceId, "{ [0,1027) [1201,2736) }"); |
763 | 781 |
764 // Append initialization segment for bear1 & fill gap with [779-1197) | 782 // Append initialization segment for bear1 & fill gap with [779-1197) |
765 // segment. | 783 // segment. |
| 784 EXPECT_CALL(*this, InitSegmentReceived()); |
766 AppendData(bear1->data(), 4370); | 785 AppendData(bear1->data(), 4370); |
767 AppendData(bear1->data() + 72737, 28183); | 786 AppendData(bear1->data() + 72737, 28183); |
768 CheckExpectedRanges(kSourceId, "{ [0,2736) }"); | 787 CheckExpectedRanges(kSourceId, "{ [0,2736) }"); |
769 | 788 |
770 MarkEndOfStream(PIPELINE_OK); | 789 MarkEndOfStream(PIPELINE_OK); |
771 return true; | 790 return true; |
772 } | 791 } |
773 | 792 |
774 void ShutdownDemuxer() { | 793 void ShutdownDemuxer() { |
775 if (demuxer_) { | 794 if (demuxer_) { |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 int stream_flags) { | 1110 int stream_flags) { |
1092 EXPECT_CALL(*this, DemuxerOpened()); | 1111 EXPECT_CALL(*this, DemuxerOpened()); |
1093 demuxer_->Initialize( | 1112 demuxer_->Initialize( |
1094 &host_, CreateInitDoneCB(duration, PIPELINE_OK), true); | 1113 &host_, CreateInitDoneCB(duration, PIPELINE_OK), true); |
1095 | 1114 |
1096 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk) | 1115 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk) |
1097 return false; | 1116 return false; |
1098 | 1117 |
1099 // Read a WebM file into memory and send the data to the demuxer. | 1118 // Read a WebM file into memory and send the data to the demuxer. |
1100 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); | 1119 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); |
| 1120 EXPECT_CALL(*this, InitSegmentReceived()); |
1101 AppendDataInPieces(buffer->data(), buffer->data_size(), 512); | 1121 AppendDataInPieces(buffer->data(), buffer->data_size(), 512); |
1102 | 1122 |
1103 // Verify that the timestamps on the first few packets match what we | 1123 // Verify that the timestamps on the first few packets match what we |
1104 // expect. | 1124 // expect. |
1105 for (size_t i = 0; | 1125 for (size_t i = 0; |
1106 (timestamps[i].audio_time_ms != kSkip || | 1126 (timestamps[i].audio_time_ms != kSkip || |
1107 timestamps[i].video_time_ms != kSkip); | 1127 timestamps[i].video_time_ms != kSkip); |
1108 i++) { | 1128 i++) { |
1109 bool audio_read_done = false; | 1129 bool audio_read_done = false; |
1110 bool video_read_done = false; | 1130 bool video_read_done = false; |
(...skipping 24 matching lines...) Expand all Loading... |
1135 // (http://code.google.com/p/googletest/issues/detail?id=395) or when we use | 1155 // (http://code.google.com/p/googletest/issues/detail?id=395) or when we use |
1136 // std::string instead of scoped_ptr<uint8[]> (http://crbug.com/130689). | 1156 // std::string instead of scoped_ptr<uint8[]> (http://crbug.com/130689). |
1137 MOCK_METHOD3(NeedKeyMock, void(const std::string& type, | 1157 MOCK_METHOD3(NeedKeyMock, void(const std::string& type, |
1138 const uint8* init_data, int init_data_size)); | 1158 const uint8* init_data, int init_data_size)); |
1139 void DemuxerNeedKey(const std::string& type, | 1159 void DemuxerNeedKey(const std::string& type, |
1140 const std::vector<uint8>& init_data) { | 1160 const std::vector<uint8>& init_data) { |
1141 const uint8* init_data_ptr = init_data.empty() ? NULL : &init_data[0]; | 1161 const uint8* init_data_ptr = init_data.empty() ? NULL : &init_data[0]; |
1142 NeedKeyMock(type, init_data_ptr, init_data.size()); | 1162 NeedKeyMock(type, init_data_ptr, init_data.size()); |
1143 } | 1163 } |
1144 | 1164 |
| 1165 MOCK_METHOD0(InitSegmentReceived, void(void)); |
| 1166 |
1145 void Seek(base::TimeDelta seek_time) { | 1167 void Seek(base::TimeDelta seek_time) { |
1146 demuxer_->StartWaitingForSeek(seek_time); | 1168 demuxer_->StartWaitingForSeek(seek_time); |
1147 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); | 1169 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); |
1148 message_loop_.RunUntilIdle(); | 1170 message_loop_.RunUntilIdle(); |
1149 } | 1171 } |
1150 | 1172 |
1151 void MarkEndOfStream(PipelineStatus status) { | 1173 void MarkEndOfStream(PipelineStatus status) { |
1152 demuxer_->MarkEndOfStream(status); | 1174 demuxer_->MarkEndOfStream(status); |
1153 message_loop_.RunUntilIdle(); | 1175 message_loop_.RunUntilIdle(); |
1154 } | 1176 } |
1155 | 1177 |
1156 bool SetTimestampOffset(const std::string& id, | 1178 bool SetTimestampOffset(const std::string& id, |
1157 base::TimeDelta timestamp_offset) { | 1179 base::TimeDelta timestamp_offset) { |
1158 if (demuxer_->IsParsingMediaSegment(id)) | 1180 if (demuxer_->IsParsingMediaSegment(id)) |
1159 return false; | 1181 return false; |
1160 | 1182 |
1161 timestamp_offset_map_[id] = timestamp_offset; | 1183 timestamp_offset_map_[id] = timestamp_offset; |
1162 return true; | 1184 return true; |
1163 } | 1185 } |
1164 | 1186 |
1165 base::MessageLoop message_loop_; | 1187 base::MessageLoop message_loop_; |
1166 MockDemuxerHost host_; | 1188 MockDemuxerHost host_; |
1167 | 1189 |
1168 scoped_ptr<ChunkDemuxer> demuxer_; | 1190 scoped_ptr<ChunkDemuxer> demuxer_; |
| 1191 ChunkDemuxer::InitSegmentReceivedCB init_segment_received_cb_; |
1169 | 1192 |
1170 base::TimeDelta append_window_start_for_next_append_; | 1193 base::TimeDelta append_window_start_for_next_append_; |
1171 base::TimeDelta append_window_end_for_next_append_; | 1194 base::TimeDelta append_window_end_for_next_append_; |
1172 | 1195 |
1173 // Map of source id to timestamp offset to use for the next AppendData() | 1196 // Map of source id to timestamp offset to use for the next AppendData() |
1174 // operation for that source id. | 1197 // operation for that source id. |
1175 std::map<std::string, base::TimeDelta> timestamp_offset_map_; | 1198 std::map<std::string, base::TimeDelta> timestamp_offset_map_; |
1176 | 1199 |
1177 private: | 1200 private: |
1178 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); | 1201 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 MuxedStreamInfo(kAudioTrackNum, "0K 23K"), | 1364 MuxedStreamInfo(kAudioTrackNum, "0K 23K"), |
1342 MuxedStreamInfo(kVideoTrackNum, "0K 30"), | 1365 MuxedStreamInfo(kVideoTrackNum, "0K 30"), |
1343 MuxedStreamInfo(kTextTrackNum, "10K")); | 1366 MuxedStreamInfo(kTextTrackNum, "10K")); |
1344 CheckExpectedRanges(kSourceId, "{ [0,46) }"); | 1367 CheckExpectedRanges(kSourceId, "{ [0,46) }"); |
1345 | 1368 |
1346 scoped_ptr<uint8[]> info_tracks; | 1369 scoped_ptr<uint8[]> info_tracks; |
1347 int info_tracks_size = 0; | 1370 int info_tracks_size = 0; |
1348 CreateInitSegmentWithAlternateTextTrackNum(HAS_TEXT | HAS_AUDIO | HAS_VIDEO, | 1371 CreateInitSegmentWithAlternateTextTrackNum(HAS_TEXT | HAS_AUDIO | HAS_VIDEO, |
1349 false, false, | 1372 false, false, |
1350 &info_tracks, &info_tracks_size); | 1373 &info_tracks, &info_tracks_size); |
| 1374 EXPECT_CALL(*this, InitSegmentReceived()); |
1351 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, | 1375 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, |
1352 append_window_start_for_next_append_, | 1376 append_window_start_for_next_append_, |
1353 append_window_end_for_next_append_, | 1377 append_window_end_for_next_append_, |
1354 ×tamp_offset_map_[kSourceId]); | 1378 ×tamp_offset_map_[kSourceId], |
| 1379 init_segment_received_cb_); |
1355 | 1380 |
1356 AppendMuxedCluster( | 1381 AppendMuxedCluster( |
1357 MuxedStreamInfo(kAudioTrackNum, "46K 69K"), | 1382 MuxedStreamInfo(kAudioTrackNum, "46K 69K"), |
1358 MuxedStreamInfo(kVideoTrackNum, "60K"), | 1383 MuxedStreamInfo(kVideoTrackNum, "60K"), |
1359 MuxedStreamInfo(kAlternateTextTrackNum, "45K")); | 1384 MuxedStreamInfo(kAlternateTextTrackNum, "45K")); |
1360 | 1385 |
1361 CheckExpectedRanges(kSourceId, "{ [0,92) }"); | 1386 CheckExpectedRanges(kSourceId, "{ [0,92) }"); |
1362 CheckExpectedBuffers(audio_stream, "0 23 46 69"); | 1387 CheckExpectedBuffers(audio_stream, "0 23 46 69"); |
1363 CheckExpectedBuffers(video_stream, "0 30 60"); | 1388 CheckExpectedBuffers(video_stream, "0 30 60"); |
1364 CheckExpectedBuffers(text_stream, "10 45"); | 1389 CheckExpectedBuffers(text_stream, "10 45"); |
(...skipping 17 matching lines...) Expand all Loading... |
1382 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1407 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
1383 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1408 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
1384 ASSERT_TRUE(audio_stream && video_stream && text_stream); | 1409 ASSERT_TRUE(audio_stream && video_stream && text_stream); |
1385 | 1410 |
1386 AppendMuxedCluster( | 1411 AppendMuxedCluster( |
1387 MuxedStreamInfo(kAudioTrackNum, "23K"), | 1412 MuxedStreamInfo(kAudioTrackNum, "23K"), |
1388 MuxedStreamInfo(kVideoTrackNum, "0 30K"), | 1413 MuxedStreamInfo(kVideoTrackNum, "0 30K"), |
1389 MuxedStreamInfo(kTextTrackNum, "25K 40K")); | 1414 MuxedStreamInfo(kTextTrackNum, "25K 40K")); |
1390 CheckExpectedRanges(kSourceId, "{ [23,46) }"); | 1415 CheckExpectedRanges(kSourceId, "{ [23,46) }"); |
1391 | 1416 |
| 1417 EXPECT_CALL(*this, InitSegmentReceived()); |
1392 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); | 1418 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); |
1393 AppendMuxedCluster( | 1419 AppendMuxedCluster( |
1394 MuxedStreamInfo(kAudioTrackNum, "46K 69K"), | 1420 MuxedStreamInfo(kAudioTrackNum, "46K 69K"), |
1395 MuxedStreamInfo(kVideoTrackNum, "60 90K"), | 1421 MuxedStreamInfo(kVideoTrackNum, "60 90K"), |
1396 MuxedStreamInfo(kTextTrackNum, "80K 90K")); | 1422 MuxedStreamInfo(kTextTrackNum, "80K 90K")); |
1397 CheckExpectedRanges(kSourceId, "{ [23,92) }"); | 1423 CheckExpectedRanges(kSourceId, "{ [23,92) }"); |
1398 | 1424 |
1399 CheckExpectedBuffers(audio_stream, "23 46 69"); | 1425 CheckExpectedBuffers(audio_stream, "23 46 69"); |
1400 CheckExpectedBuffers(video_stream, "30 90"); | 1426 CheckExpectedBuffers(video_stream, "30 90"); |
1401 CheckExpectedBuffers(text_stream, "25 40 80 90"); | 1427 CheckExpectedBuffers(text_stream, "25 40 80 90"); |
1402 } | 1428 } |
1403 | 1429 |
1404 // Make sure that the demuxer reports an error if Shutdown() | 1430 // Make sure that the demuxer reports an error if Shutdown() |
1405 // is called before all the initialization segments are appended. | 1431 // is called before all the initialization segments are appended. |
1406 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { | 1432 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { |
1407 EXPECT_CALL(*this, DemuxerOpened()); | 1433 EXPECT_CALL(*this, DemuxerOpened()); |
1408 demuxer_->Initialize( | 1434 demuxer_->Initialize( |
1409 &host_, CreateInitDoneCB( | 1435 &host_, CreateInitDoneCB( |
1410 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1436 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); |
1411 | 1437 |
1412 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); | 1438 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); |
1413 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); | 1439 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); |
1414 | 1440 |
| 1441 EXPECT_CALL(*this, InitSegmentReceived()); |
1415 AppendInitSegmentWithSourceId("audio", HAS_AUDIO); | 1442 AppendInitSegmentWithSourceId("audio", HAS_AUDIO); |
1416 | 1443 |
1417 ShutdownDemuxer(); | 1444 ShutdownDemuxer(); |
1418 } | 1445 } |
1419 | 1446 |
1420 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) { | 1447 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) { |
1421 EXPECT_CALL(*this, DemuxerOpened()); | 1448 EXPECT_CALL(*this, DemuxerOpened()); |
1422 demuxer_->Initialize( | 1449 demuxer_->Initialize( |
1423 &host_, CreateInitDoneCB( | 1450 &host_, CreateInitDoneCB( |
1424 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); | 1451 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); |
1425 | 1452 |
1426 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); | 1453 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); |
1427 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); | 1454 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); |
1428 | 1455 |
1429 EXPECT_CALL(host_, AddTextStream(_, _)) | 1456 EXPECT_CALL(host_, AddTextStream(_, _)) |
1430 .Times(Exactly(1)); | 1457 .Times(Exactly(1)); |
1431 | 1458 |
| 1459 EXPECT_CALL(*this, InitSegmentReceived()); |
1432 AppendInitSegmentWithSourceId("video_and_text", HAS_VIDEO | HAS_TEXT); | 1460 AppendInitSegmentWithSourceId("video_and_text", HAS_VIDEO | HAS_TEXT); |
1433 | 1461 |
1434 ShutdownDemuxer(); | 1462 ShutdownDemuxer(); |
1435 } | 1463 } |
1436 | 1464 |
1437 // Verifies that all streams waiting for data receive an end of stream | 1465 // Verifies that all streams waiting for data receive an end of stream |
1438 // buffer when Shutdown() is called. | 1466 // buffer when Shutdown() is called. |
1439 TEST_F(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) { | 1467 TEST_F(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) { |
1440 DemuxerStream* text_stream = NULL; | 1468 DemuxerStream* text_stream = NULL; |
1441 EXPECT_CALL(host_, AddTextStream(_, _)) | 1469 EXPECT_CALL(host_, AddTextStream(_, _)) |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 | 1558 |
1531 // Test the case where AppendData() is called before Init(). | 1559 // Test the case where AppendData() is called before Init(). |
1532 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) { | 1560 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) { |
1533 scoped_ptr<uint8[]> info_tracks; | 1561 scoped_ptr<uint8[]> info_tracks; |
1534 int info_tracks_size = 0; | 1562 int info_tracks_size = 0; |
1535 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, | 1563 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, |
1536 false, false, &info_tracks, &info_tracks_size); | 1564 false, false, &info_tracks, &info_tracks_size); |
1537 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, | 1565 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, |
1538 append_window_start_for_next_append_, | 1566 append_window_start_for_next_append_, |
1539 append_window_end_for_next_append_, | 1567 append_window_end_for_next_append_, |
1540 ×tamp_offset_map_[kSourceId]); | 1568 ×tamp_offset_map_[kSourceId], |
| 1569 init_segment_received_cb_); |
1541 } | 1570 } |
1542 | 1571 |
1543 // Make sure Read() callbacks are dispatched with the proper data. | 1572 // Make sure Read() callbacks are dispatched with the proper data. |
1544 TEST_F(ChunkDemuxerTest, Read) { | 1573 TEST_F(ChunkDemuxerTest, Read) { |
1545 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1574 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
1546 | 1575 |
1547 AppendCluster(kDefaultFirstCluster()); | 1576 AppendCluster(kDefaultFirstCluster()); |
1548 | 1577 |
1549 bool audio_read_done = false; | 1578 bool audio_read_done = false; |
1550 bool video_read_done = false; | 1579 bool video_read_done = false; |
(...skipping 15 matching lines...) Expand all Loading... |
1566 | 1595 |
1567 // Make sure that AppendCluster() does not fail with a cluster that has | 1596 // Make sure that AppendCluster() does not fail with a cluster that has |
1568 // overlaps with the previously appended cluster. | 1597 // overlaps with the previously appended cluster. |
1569 AppendCluster(GenerateCluster(5, 4)); | 1598 AppendCluster(GenerateCluster(5, 4)); |
1570 | 1599 |
1571 // Verify that AppendData() can still accept more data. | 1600 // Verify that AppendData() can still accept more data. |
1572 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); | 1601 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); |
1573 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(), | 1602 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(), |
1574 append_window_start_for_next_append_, | 1603 append_window_start_for_next_append_, |
1575 append_window_end_for_next_append_, | 1604 append_window_end_for_next_append_, |
1576 ×tamp_offset_map_[kSourceId]); | 1605 ×tamp_offset_map_[kSourceId], |
| 1606 init_segment_received_cb_); |
1577 } | 1607 } |
1578 | 1608 |
1579 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) { | 1609 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) { |
1580 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1610 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
1581 AppendCluster(kDefaultFirstCluster()); | 1611 AppendCluster(kDefaultFirstCluster()); |
1582 | 1612 |
1583 ClusterBuilder cb; | 1613 ClusterBuilder cb; |
1584 | 1614 |
1585 // Test the case where block timecodes are not monotonically | 1615 // Test the case where block timecodes are not monotonically |
1586 // increasing but stay above the cluster timecode. | 1616 // increasing but stay above the cluster timecode. |
1587 cb.SetClusterTimecode(5); | 1617 cb.SetClusterTimecode(5); |
1588 AddSimpleBlock(&cb, kAudioTrackNum, 5); | 1618 AddSimpleBlock(&cb, kAudioTrackNum, 5); |
1589 AddSimpleBlock(&cb, kVideoTrackNum, 10); | 1619 AddSimpleBlock(&cb, kVideoTrackNum, 10); |
1590 AddSimpleBlock(&cb, kAudioTrackNum, 7); | 1620 AddSimpleBlock(&cb, kAudioTrackNum, 7); |
1591 AddSimpleBlock(&cb, kVideoTrackNum, 15); | 1621 AddSimpleBlock(&cb, kVideoTrackNum, 15); |
1592 | 1622 |
1593 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 1623 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
1594 AppendCluster(cb.Finish()); | 1624 AppendCluster(cb.Finish()); |
1595 | 1625 |
1596 // Verify that AppendData() ignores data after the error. | 1626 // Verify that AppendData() ignores data after the error. |
1597 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); | 1627 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); |
1598 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), | 1628 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), |
1599 append_window_start_for_next_append_, | 1629 append_window_start_for_next_append_, |
1600 append_window_end_for_next_append_, | 1630 append_window_end_for_next_append_, |
1601 ×tamp_offset_map_[kSourceId]); | 1631 ×tamp_offset_map_[kSourceId], |
| 1632 init_segment_received_cb_); |
1602 } | 1633 } |
1603 | 1634 |
1604 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) { | 1635 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) { |
1605 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1636 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
1606 AppendCluster(kDefaultFirstCluster()); | 1637 AppendCluster(kDefaultFirstCluster()); |
1607 | 1638 |
1608 ClusterBuilder cb; | 1639 ClusterBuilder cb; |
1609 | 1640 |
1610 // Test timecodes going backwards and including values less than the cluster | 1641 // Test timecodes going backwards and including values less than the cluster |
1611 // timecode. | 1642 // timecode. |
1612 cb.SetClusterTimecode(5); | 1643 cb.SetClusterTimecode(5); |
1613 AddSimpleBlock(&cb, kAudioTrackNum, 5); | 1644 AddSimpleBlock(&cb, kAudioTrackNum, 5); |
1614 AddSimpleBlock(&cb, kVideoTrackNum, 5); | 1645 AddSimpleBlock(&cb, kVideoTrackNum, 5); |
1615 AddSimpleBlock(&cb, kAudioTrackNum, 3); | 1646 AddSimpleBlock(&cb, kAudioTrackNum, 3); |
1616 AddSimpleBlock(&cb, kVideoTrackNum, 3); | 1647 AddSimpleBlock(&cb, kVideoTrackNum, 3); |
1617 | 1648 |
1618 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 1649 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
1619 AppendCluster(cb.Finish()); | 1650 AppendCluster(cb.Finish()); |
1620 | 1651 |
1621 // Verify that AppendData() ignores data after the error. | 1652 // Verify that AppendData() ignores data after the error. |
1622 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); | 1653 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); |
1623 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), | 1654 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), |
1624 append_window_start_for_next_append_, | 1655 append_window_start_for_next_append_, |
1625 append_window_end_for_next_append_, | 1656 append_window_end_for_next_append_, |
1626 ×tamp_offset_map_[kSourceId]); | 1657 ×tamp_offset_map_[kSourceId], |
| 1658 init_segment_received_cb_); |
1627 } | 1659 } |
1628 | 1660 |
1629 | 1661 |
1630 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) { | 1662 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) { |
1631 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1663 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
1632 AppendCluster(kDefaultFirstCluster()); | 1664 AppendCluster(kDefaultFirstCluster()); |
1633 | 1665 |
1634 ClusterBuilder cb; | 1666 ClusterBuilder cb; |
1635 | 1667 |
1636 // Test monotonic increasing timestamps on a per stream | 1668 // Test monotonic increasing timestamps on a per stream |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 uint8* dst = buffer.get(); | 1959 uint8* dst = buffer.get(); |
1928 memcpy(dst, info_tracks.get(), info_tracks_size); | 1960 memcpy(dst, info_tracks.get(), info_tracks_size); |
1929 dst += info_tracks_size; | 1961 dst += info_tracks_size; |
1930 | 1962 |
1931 memcpy(dst, cluster_a->data(), cluster_a->size()); | 1963 memcpy(dst, cluster_a->data(), cluster_a->size()); |
1932 dst += cluster_a->size(); | 1964 dst += cluster_a->size(); |
1933 | 1965 |
1934 memcpy(dst, cluster_b->data(), cluster_b->size()); | 1966 memcpy(dst, cluster_b->data(), cluster_b->size()); |
1935 dst += cluster_b->size(); | 1967 dst += cluster_b->size(); |
1936 | 1968 |
| 1969 EXPECT_CALL(*this, InitSegmentReceived()); |
1937 AppendDataInPieces(buffer.get(), buffer_size); | 1970 AppendDataInPieces(buffer.get(), buffer_size); |
1938 | 1971 |
1939 GenerateExpectedReads(0, 9); | 1972 GenerateExpectedReads(0, 9); |
1940 } | 1973 } |
1941 | 1974 |
1942 TEST_F(ChunkDemuxerTest, WebMFile_AudioAndVideo) { | 1975 TEST_F(ChunkDemuxerTest, WebMFile_AudioAndVideo) { |
1943 struct BufferTimestamps buffer_timestamps[] = { | 1976 struct BufferTimestamps buffer_timestamps[] = { |
1944 {0, 0}, | 1977 {0, 0}, |
1945 {33, 3}, | 1978 {33, 3}, |
1946 {67, 6}, | 1979 {67, 6}, |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2085 demuxer_->Initialize( | 2118 demuxer_->Initialize( |
2086 &host_, CreateInitDoneCB( | 2119 &host_, CreateInitDoneCB( |
2087 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true); | 2120 kNoTimestamp(), DEMUXER_ERROR_COULD_NOT_OPEN), true); |
2088 | 2121 |
2089 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); | 2122 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); |
2090 | 2123 |
2091 uint8 tmp = 0; | 2124 uint8 tmp = 0; |
2092 demuxer_->AppendData(kSourceId, &tmp, 1, | 2125 demuxer_->AppendData(kSourceId, &tmp, 1, |
2093 append_window_start_for_next_append_, | 2126 append_window_start_for_next_append_, |
2094 append_window_end_for_next_append_, | 2127 append_window_end_for_next_append_, |
2095 ×tamp_offset_map_[kSourceId]); | 2128 ×tamp_offset_map_[kSourceId], |
| 2129 init_segment_received_cb_); |
2096 } | 2130 } |
2097 | 2131 |
2098 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) { | 2132 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) { |
2099 EXPECT_CALL(*this, DemuxerOpened()); | 2133 EXPECT_CALL(*this, DemuxerOpened()); |
2100 demuxer_->Initialize( | 2134 demuxer_->Initialize( |
2101 &host_, CreateInitDoneCB(kNoTimestamp(), | 2135 &host_, CreateInitDoneCB(kNoTimestamp(), |
2102 DEMUXER_ERROR_COULD_NOT_OPEN), true); | 2136 DEMUXER_ERROR_COULD_NOT_OPEN), true); |
2103 | 2137 |
2104 std::vector<std::string> codecs(1); | 2138 std::vector<std::string> codecs(1); |
2105 codecs[0] = "vorbis"; | 2139 codecs[0] = "vorbis"; |
(...skipping 16 matching lines...) Expand all Loading... |
2122 | 2156 |
2123 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); | 2157 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); |
2124 } | 2158 } |
2125 | 2159 |
2126 TEST_F(ChunkDemuxerTest, MultipleHeaders) { | 2160 TEST_F(ChunkDemuxerTest, MultipleHeaders) { |
2127 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2161 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
2128 | 2162 |
2129 AppendCluster(kDefaultFirstCluster()); | 2163 AppendCluster(kDefaultFirstCluster()); |
2130 | 2164 |
2131 // Append another identical initialization segment. | 2165 // Append another identical initialization segment. |
| 2166 EXPECT_CALL(*this, InitSegmentReceived()); |
2132 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); | 2167 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); |
2133 | 2168 |
2134 AppendCluster(kDefaultSecondCluster()); | 2169 AppendCluster(kDefaultSecondCluster()); |
2135 | 2170 |
2136 GenerateExpectedReads(0, 9); | 2171 GenerateExpectedReads(0, 9); |
2137 } | 2172 } |
2138 | 2173 |
2139 TEST_F(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideo) { | 2174 TEST_F(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideo) { |
2140 std::string audio_id = "audio1"; | 2175 std::string audio_id = "audio1"; |
2141 std::string video_id = "video1"; | 2176 std::string video_id = "video1"; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2176 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); | 2211 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); |
2177 | 2212 |
2178 std::string audio_id = "audio1"; | 2213 std::string audio_id = "audio1"; |
2179 std::string video_id = "video1"; | 2214 std::string video_id = "video1"; |
2180 | 2215 |
2181 ASSERT_EQ(AddId(audio_id, HAS_AUDIO), ChunkDemuxer::kOk); | 2216 ASSERT_EQ(AddId(audio_id, HAS_AUDIO), ChunkDemuxer::kOk); |
2182 | 2217 |
2183 // Adding an id with audio/video should fail because we already added audio. | 2218 // Adding an id with audio/video should fail because we already added audio. |
2184 ASSERT_EQ(AddId(), ChunkDemuxer::kReachedIdLimit); | 2219 ASSERT_EQ(AddId(), ChunkDemuxer::kReachedIdLimit); |
2185 | 2220 |
| 2221 EXPECT_CALL(*this, InitSegmentReceived()); |
2186 AppendInitSegmentWithSourceId(audio_id, HAS_AUDIO); | 2222 AppendInitSegmentWithSourceId(audio_id, HAS_AUDIO); |
2187 | 2223 |
2188 // Adding an id after append should fail. | 2224 // Adding an id after append should fail. |
2189 ASSERT_EQ(AddId(video_id, HAS_VIDEO), ChunkDemuxer::kReachedIdLimit); | 2225 ASSERT_EQ(AddId(video_id, HAS_VIDEO), ChunkDemuxer::kReachedIdLimit); |
2190 } | 2226 } |
2191 | 2227 |
2192 // Test that Read() calls after a RemoveId() return "end of stream" buffers. | 2228 // Test that Read() calls after a RemoveId() return "end of stream" buffers. |
2193 TEST_F(ChunkDemuxerTest, RemoveId) { | 2229 TEST_F(ChunkDemuxerTest, RemoveId) { |
2194 std::string audio_id = "audio1"; | 2230 std::string audio_id = "audio1"; |
2195 std::string video_id = "video1"; | 2231 std::string video_id = "video1"; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2408 ShutdownDemuxer(); | 2444 ShutdownDemuxer(); |
2409 } | 2445 } |
2410 | 2446 |
2411 // Test ranges in an audio-only stream. | 2447 // Test ranges in an audio-only stream. |
2412 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) { | 2448 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) { |
2413 EXPECT_CALL(*this, DemuxerOpened()); | 2449 EXPECT_CALL(*this, DemuxerOpened()); |
2414 demuxer_->Initialize( | 2450 demuxer_->Initialize( |
2415 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); | 2451 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); |
2416 | 2452 |
2417 ASSERT_EQ(AddId(kSourceId, HAS_AUDIO), ChunkDemuxer::kOk); | 2453 ASSERT_EQ(AddId(kSourceId, HAS_AUDIO), ChunkDemuxer::kOk); |
| 2454 EXPECT_CALL(*this, InitSegmentReceived()); |
2418 AppendInitSegment(HAS_AUDIO); | 2455 AppendInitSegment(HAS_AUDIO); |
2419 | 2456 |
2420 // Test a simple cluster. | 2457 // Test a simple cluster. |
2421 AppendCluster( | 2458 AppendCluster( |
2422 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); | 2459 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); |
2423 | 2460 |
2424 CheckExpectedRanges("{ [0,92) }"); | 2461 CheckExpectedRanges("{ [0,92) }"); |
2425 | 2462 |
2426 // Append a disjoint cluster to check for two separate ranges. | 2463 // Append a disjoint cluster to check for two separate ranges. |
2427 AppendCluster(GenerateSingleStreamCluster( | 2464 AppendCluster(GenerateSingleStreamCluster( |
2428 150, 219, kAudioTrackNum, kAudioBlockDuration)); | 2465 150, 219, kAudioTrackNum, kAudioBlockDuration)); |
2429 | 2466 |
2430 CheckExpectedRanges("{ [0,92) [150,219) }"); | 2467 CheckExpectedRanges("{ [0,92) [150,219) }"); |
2431 } | 2468 } |
2432 | 2469 |
2433 // Test ranges in a video-only stream. | 2470 // Test ranges in a video-only stream. |
2434 TEST_F(ChunkDemuxerTest, GetBufferedRanges_VideoIdOnly) { | 2471 TEST_F(ChunkDemuxerTest, GetBufferedRanges_VideoIdOnly) { |
2435 EXPECT_CALL(*this, DemuxerOpened()); | 2472 EXPECT_CALL(*this, DemuxerOpened()); |
2436 demuxer_->Initialize( | 2473 demuxer_->Initialize( |
2437 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); | 2474 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); |
2438 | 2475 |
2439 ASSERT_EQ(AddId(kSourceId, HAS_VIDEO), ChunkDemuxer::kOk); | 2476 ASSERT_EQ(AddId(kSourceId, HAS_VIDEO), ChunkDemuxer::kOk); |
| 2477 EXPECT_CALL(*this, InitSegmentReceived()); |
2440 AppendInitSegment(HAS_VIDEO); | 2478 AppendInitSegment(HAS_VIDEO); |
2441 | 2479 |
2442 // Test a simple cluster. | 2480 // Test a simple cluster. |
2443 AppendCluster( | 2481 AppendCluster( |
2444 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); | 2482 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); |
2445 | 2483 |
2446 CheckExpectedRanges("{ [0,132) }"); | 2484 CheckExpectedRanges("{ [0,132) }"); |
2447 | 2485 |
2448 // Append a disjoint cluster to check for two separate ranges. | 2486 // Append a disjoint cluster to check for two separate ranges. |
2449 AppendCluster(GenerateSingleStreamCluster( | 2487 AppendCluster(GenerateSingleStreamCluster( |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3008 // Audio: first PES: | 3046 // Audio: first PES: |
3009 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000] | 3047 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000] |
3010 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767] | 3048 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767] |
3011 // Video: last PES: | 3049 // Video: last PES: |
3012 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128] | 3050 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128] |
3013 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794] | 3051 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794] |
3014 // Audio: last PES: | 3052 // Audio: last PES: |
3015 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309] | 3053 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309] |
3016 | 3054 |
3017 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts"); | 3055 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts"); |
| 3056 EXPECT_CALL(*this, InitSegmentReceived()); |
3018 AppendData(kSourceId, buffer->data(), buffer->data_size()); | 3057 AppendData(kSourceId, buffer->data(), buffer->data_size()); |
3019 | 3058 |
3020 // Confirm we're in the middle of parsing a media segment. | 3059 // Confirm we're in the middle of parsing a media segment. |
3021 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); | 3060 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); |
3022 | 3061 |
3023 // Abort on the Mpeg2 TS parser triggers the emission of the last video | 3062 // Abort on the Mpeg2 TS parser triggers the emission of the last video |
3024 // buffer which is pending in the stream parser. | 3063 // buffer which is pending in the stream parser. |
3025 Ranges<base::TimeDelta> range_before_abort = | 3064 Ranges<base::TimeDelta> range_before_abort = |
3026 demuxer_->GetBufferedRanges(kSourceId); | 3065 demuxer_->GetBufferedRanges(kSourceId); |
3027 demuxer_->Abort(kSourceId, | 3066 demuxer_->Abort(kSourceId, |
(...skipping 23 matching lines...) Expand all Loading... |
3051 // Audio: first PES: | 3090 // Audio: first PES: |
3052 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000] | 3091 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000] |
3053 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767] | 3092 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767] |
3054 // Video: last PES: | 3093 // Video: last PES: |
3055 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128] | 3094 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128] |
3056 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794] | 3095 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794] |
3057 // Audio: last PES: | 3096 // Audio: last PES: |
3058 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309] | 3097 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309] |
3059 | 3098 |
3060 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts"); | 3099 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts"); |
| 3100 EXPECT_CALL(*this, InitSegmentReceived()); |
3061 AppendData(kSourceId, buffer->data(), buffer->data_size()); | 3101 AppendData(kSourceId, buffer->data(), buffer->data_size()); |
3062 | 3102 |
3063 // Confirm we're in the middle of parsing a media segment. | 3103 // Confirm we're in the middle of parsing a media segment. |
3064 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); | 3104 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); |
3065 | 3105 |
3066 // Seek to a time corresponding to buffers that will be emitted during the | 3106 // Seek to a time corresponding to buffers that will be emitted during the |
3067 // abort. | 3107 // abort. |
3068 Seek(base::TimeDelta::FromMilliseconds(4110)); | 3108 Seek(base::TimeDelta::FromMilliseconds(4110)); |
3069 | 3109 |
3070 // Abort on the Mpeg2 TS parser triggers the emission of the last video | 3110 // Abort on the Mpeg2 TS parser triggers the emission of the last video |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3440 | 3480 |
3441 // Set the append window to [50,150). | 3481 // Set the append window to [50,150). |
3442 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); | 3482 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); |
3443 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(150); | 3483 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(150); |
3444 | 3484 |
3445 // Read a WebM file into memory and send the data to the demuxer. The chunk | 3485 // Read a WebM file into memory and send the data to the demuxer. The chunk |
3446 // size has been chosen carefully to ensure the preroll buffer used by the | 3486 // size has been chosen carefully to ensure the preroll buffer used by the |
3447 // partial append window trim must come from a previous Append() call. | 3487 // partial append window trim must come from a previous Append() call. |
3448 scoped_refptr<DecoderBuffer> buffer = | 3488 scoped_refptr<DecoderBuffer> buffer = |
3449 ReadTestDataFile("bear-320x240-audio-only.webm"); | 3489 ReadTestDataFile("bear-320x240-audio-only.webm"); |
| 3490 EXPECT_CALL(*this, InitSegmentReceived()); |
3450 AppendDataInPieces(buffer->data(), buffer->data_size(), 128); | 3491 AppendDataInPieces(buffer->data(), buffer->data_size(), 128); |
3451 | 3492 |
3452 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 3493 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
3453 CheckExpectedBuffers(stream, "50P 50 62 86 109 122 125 128"); | 3494 CheckExpectedBuffers(stream, "50P 50 62 86 109 122 125 128"); |
3454 } | 3495 } |
3455 | 3496 |
3456 TEST_F(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) { | 3497 TEST_F(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) { |
3457 EXPECT_CALL(*this, DemuxerOpened()); | 3498 EXPECT_CALL(*this, DemuxerOpened()); |
3458 demuxer_->Initialize( | 3499 demuxer_->Initialize( |
3459 &host_, | 3500 &host_, |
3460 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), | 3501 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), |
3461 true); | 3502 true); |
3462 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); | 3503 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); |
3463 | 3504 |
3464 // Set the append window such that the first file is completely before the | 3505 // Set the append window such that the first file is completely before the |
3465 // append window. | 3506 // append window. |
3466 // TODO(wolenetz/acolwell): Update this duration once the files are fixed to | 3507 // TODO(wolenetz/acolwell): Update this duration once the files are fixed to |
3467 // have the correct duration in their init segments, and the | 3508 // have the correct duration in their init segments, and the |
3468 // CreateInitDoneCB() call, above, is fixed to used that duration. See | 3509 // CreateInitDoneCB() call, above, is fixed to used that duration. See |
3469 // http://crbug.com/354284. | 3510 // http://crbug.com/354284. |
3470 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746); | 3511 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746); |
3471 append_window_start_for_next_append_ = duration_1; | 3512 append_window_start_for_next_append_ = duration_1; |
3472 | 3513 |
3473 // Read a WebM file into memory and append the data. | 3514 // Read a WebM file into memory and append the data. |
3474 scoped_refptr<DecoderBuffer> buffer = | 3515 scoped_refptr<DecoderBuffer> buffer = |
3475 ReadTestDataFile("bear-320x240-audio-only.webm"); | 3516 ReadTestDataFile("bear-320x240-audio-only.webm"); |
| 3517 EXPECT_CALL(*this, InitSegmentReceived()); |
3476 AppendDataInPieces(buffer->data(), buffer->data_size(), 512); | 3518 AppendDataInPieces(buffer->data(), buffer->data_size(), 512); |
3477 CheckExpectedRanges(kSourceId, "{ }"); | 3519 CheckExpectedRanges(kSourceId, "{ }"); |
3478 | 3520 |
3479 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 3521 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
3480 AudioDecoderConfig config_1 = stream->audio_decoder_config(); | 3522 AudioDecoderConfig config_1 = stream->audio_decoder_config(); |
3481 | 3523 |
3482 // Read a second WebM with a different config in and append the data. | 3524 // Read a second WebM with a different config in and append the data. |
3483 scoped_refptr<DecoderBuffer> buffer2 = | 3525 scoped_refptr<DecoderBuffer> buffer2 = |
3484 ReadTestDataFile("bear-320x240-audio-only-48khz.webm"); | 3526 ReadTestDataFile("bear-320x240-audio-only-48khz.webm"); |
| 3527 EXPECT_CALL(*this, InitSegmentReceived()); |
3485 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber()); | 3528 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber()); |
3486 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1)); | 3529 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1)); |
3487 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512); | 3530 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512); |
3488 CheckExpectedRanges(kSourceId, "{ [2746,5519) }"); | 3531 CheckExpectedRanges(kSourceId, "{ [2746,5519) }"); |
3489 | 3532 |
3490 Seek(duration_1); | 3533 Seek(duration_1); |
3491 ExpectConfigChanged(DemuxerStream::AUDIO); | 3534 ExpectConfigChanged(DemuxerStream::AUDIO); |
3492 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config())); | 3535 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config())); |
3493 CheckExpectedBuffers(stream, "2746 2767 2789 2810"); | 3536 CheckExpectedBuffers(stream, "2746 2767 2789 2810"); |
3494 } | 3537 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3696 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { | 3739 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { |
3697 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 3740 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
3698 | 3741 |
3699 AppendCluster(GenerateCluster(0, 0, 4)); | 3742 AppendCluster(GenerateCluster(0, 0, 4)); |
3700 AppendData(kCuesHeader, sizeof(kCuesHeader)); | 3743 AppendData(kCuesHeader, sizeof(kCuesHeader)); |
3701 AppendCluster(GenerateCluster(46, 66, 5)); | 3744 AppendCluster(GenerateCluster(46, 66, 5)); |
3702 CheckExpectedRanges(kSourceId, "{ [0,115) }"); | 3745 CheckExpectedRanges(kSourceId, "{ [0,115) }"); |
3703 } | 3746 } |
3704 | 3747 |
3705 } // namespace media | 3748 } // namespace media |
OLD | NEW |