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

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

Issue 1735803002: Implemented passing media track info from ffmpeg into blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wolenetz@ CR feedback + better track info extraction in ffmpeg Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/filters/chunk_demuxer.cc ('k') | media/filters/ffmpeg_demuxer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/filters/chunk_demuxer.h" 5 #include "media/filters/chunk_demuxer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "media/base/audio_decoder_config.h" 18 #include "media/base/audio_decoder_config.h"
19 #include "media/base/decoder_buffer.h" 19 #include "media/base/decoder_buffer.h"
20 #include "media/base/decrypt_config.h" 20 #include "media/base/decrypt_config.h"
21 #include "media/base/media_tracks.h"
21 #include "media/base/mock_demuxer_host.h" 22 #include "media/base/mock_demuxer_host.h"
22 #include "media/base/mock_media_log.h" 23 #include "media/base/mock_media_log.h"
23 #include "media/base/test_data_util.h" 24 #include "media/base/test_data_util.h"
24 #include "media/base/test_helpers.h" 25 #include "media/base/test_helpers.h"
25 #include "media/base/timestamp_constants.h" 26 #include "media/base/timestamp_constants.h"
26 #include "media/formats/webm/cluster_builder.h" 27 #include "media/formats/webm/cluster_builder.h"
27 #include "media/formats/webm/webm_cluster_parser.h" 28 #include "media/formats/webm/webm_cluster_parser.h"
28 #include "media/formats/webm/webm_constants.h" 29 #include "media/formats/webm/webm_constants.h"
29 #include "media/media_features.h" 30 #include "media/media_features.h"
30 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // have timestamps consistent with the end times of the blocks 256 // have timestamps consistent with the end times of the blocks
256 // in kDefaultFirstCluster() so that these two clusters represent 257 // in kDefaultFirstCluster() so that these two clusters represent
257 // a continuous region. 258 // a continuous region.
258 scoped_ptr<Cluster> kDefaultSecondCluster() { 259 scoped_ptr<Cluster> kDefaultSecondCluster() {
259 return GenerateCluster(46, 66, 5); 260 return GenerateCluster(46, 66, 5);
260 } 261 }
261 262
262 ChunkDemuxerTest() 263 ChunkDemuxerTest()
263 : media_log_(new StrictMock<MockMediaLog>()), 264 : media_log_(new StrictMock<MockMediaLog>()),
264 append_window_end_for_next_append_(kInfiniteDuration()) { 265 append_window_end_for_next_append_(kInfiniteDuration()) {
265 init_segment_received_cb_ = 266 init_segment_received_cb_ = base::Bind(
266 base::Bind(&ChunkDemuxerTest::InitSegmentReceived, 267 &ChunkDemuxerTest::InitSegmentReceivedWrapper, base::Unretained(this));
267 base::Unretained(this));
268 CreateNewDemuxer(); 268 CreateNewDemuxer();
269 } 269 }
270 270
271 void CreateNewDemuxer() { 271 void CreateNewDemuxer() {
272 base::Closure open_cb = 272 base::Closure open_cb =
273 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this)); 273 base::Bind(&ChunkDemuxerTest::DemuxerOpened, base::Unretained(this));
274 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind( 274 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = base::Bind(
275 &ChunkDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this)); 275 &ChunkDemuxerTest::OnEncryptedMediaInitData, base::Unretained(this));
276 demuxer_.reset(new ChunkDemuxer(open_cb, encrypted_media_init_data_cb, 276 demuxer_.reset(new ChunkDemuxer(open_cb, encrypted_media_init_data_cb,
277 media_log_, true)); 277 media_log_, true));
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 443
444 if (has_video) { 444 if (has_video) {
445 codecs.push_back("vp8"); 445 codecs.push_back("vp8");
446 type = "video/webm"; 446 type = "video/webm";
447 } 447 }
448 448
449 if (!has_audio && !has_video) { 449 if (!has_audio && !has_video) {
450 return AddId(kSourceId, HAS_AUDIO | HAS_VIDEO); 450 return AddId(kSourceId, HAS_AUDIO | HAS_VIDEO);
451 } 451 }
452 452
453 return demuxer_->AddId(source_id, type, codecs); 453 ChunkDemuxer::Status status = demuxer_->AddId(source_id, type, codecs);
454 if (status == ChunkDemuxer::kOk)
455 demuxer_->SetTracksWatcher(
456 source_id, base::Bind(&ChunkDemuxerTest::InitSegmentReceivedWrapper,
457 base::Unretained(this)));
458 return status;
454 } 459 }
455 460
456 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) 461 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER)
457 ChunkDemuxer::Status AddIdForMp2tSource(const std::string& source_id) { 462 ChunkDemuxer::Status AddIdForMp2tSource(const std::string& source_id) {
458 std::vector<std::string> codecs; 463 std::vector<std::string> codecs;
459 std::string type = "video/mp2t"; 464 std::string type = "video/mp2t";
460 codecs.push_back("mp4a.40.2"); 465 codecs.push_back("mp4a.40.2");
461 codecs.push_back("avc1.640028"); 466 codecs.push_back("avc1.640028");
462 return demuxer_->AddId(source_id, type, codecs); 467 ChunkDemuxer::Status status = demuxer_->AddId(source_id, type, codecs);
468 if (status == ChunkDemuxer::kOk)
469 demuxer_->SetTracksWatcher(
470 source_id, base::Bind(&ChunkDemuxerTest::InitSegmentReceivedWrapper,
471 base::Unretained(this)));
472 return status;
463 } 473 }
464 #endif 474 #endif
465 475
466 void AppendData(const uint8_t* data, size_t length) { 476 void AppendData(const uint8_t* data, size_t length) {
467 AppendData(kSourceId, data, length); 477 AppendData(kSourceId, data, length);
468 } 478 }
469 479
470 void AppendCluster(const std::string& source_id, 480 void AppendCluster(const std::string& source_id,
471 scoped_ptr<Cluster> cluster) { 481 scoped_ptr<Cluster> cluster) {
472 AppendData(source_id, cluster->data(), cluster->size()); 482 AppendData(source_id, cluster->data(), cluster->size());
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 717
708 void AppendMuxedCluster(const std::vector<MuxedStreamInfo> msi) { 718 void AppendMuxedCluster(const std::vector<MuxedStreamInfo> msi) {
709 AppendCluster(kSourceId, GenerateMuxedCluster(msi)); 719 AppendCluster(kSourceId, GenerateMuxedCluster(msi));
710 } 720 }
711 721
712 void AppendData(const std::string& source_id, 722 void AppendData(const std::string& source_id,
713 const uint8_t* data, 723 const uint8_t* data,
714 size_t length) { 724 size_t length) {
715 EXPECT_CALL(host_, OnBufferedTimeRangesChanged(_)).Times(AnyNumber()); 725 EXPECT_CALL(host_, OnBufferedTimeRangesChanged(_)).Times(AnyNumber());
716 726
717 demuxer_->AppendData(source_id, data, length, 727 demuxer_->AppendData(
718 append_window_start_for_next_append_, 728 source_id, data, length, append_window_start_for_next_append_,
719 append_window_end_for_next_append_, 729 append_window_end_for_next_append_, &timestamp_offset_map_[source_id]);
720 &timestamp_offset_map_[source_id],
721 init_segment_received_cb_);
722 } 730 }
723 731
724 void AppendDataInPieces(const uint8_t* data, size_t length) { 732 void AppendDataInPieces(const uint8_t* data, size_t length) {
725 AppendDataInPieces(data, length, 7); 733 AppendDataInPieces(data, length, 7);
726 } 734 }
727 735
728 void AppendDataInPieces(const uint8_t* data, 736 void AppendDataInPieces(const uint8_t* data,
729 size_t length, 737 size_t length,
730 size_t piece_size) { 738 size_t piece_size) {
731 const uint8_t* start = data; 739 const uint8_t* start = data;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 arraysize(kEncryptedMediaInitData)))) 842 arraysize(kEncryptedMediaInitData))))
835 .Times(Exactly(need_key_count)); 843 .Times(Exactly(need_key_count));
836 } 844 }
837 845
838 // Adding expectations prior to CreateInitDoneCB() here because InSequence 846 // Adding expectations prior to CreateInitDoneCB() here because InSequence
839 // tests require init segment received before duration set. Also, only 847 // tests require init segment received before duration set. Also, only
840 // expect an init segment received callback if there is actually a track in 848 // expect an init segment received callback if there is actually a track in
841 // it. 849 // it.
842 if (stream_flags != 0) { 850 if (stream_flags != 0) {
843 ExpectInitMediaLogs(stream_flags); 851 ExpectInitMediaLogs(stream_flags);
844 EXPECT_CALL(*this, InitSegmentReceived()); 852 EXPECT_CALL(*this, InitSegmentReceived(_));
845 } else { 853 } else {
846 // OnNewConfigs() requires at least one audio, video, or text track. 854 // OnNewConfigs() requires at least one audio, video, or text track.
847 EXPECT_MEDIA_LOG(StreamParsingFailed()); 855 EXPECT_MEDIA_LOG(StreamParsingFailed());
848 } 856 }
849 857
850 demuxer_->Initialize( 858 demuxer_->Initialize(
851 &host_, CreateInitDoneCB(expected_duration, expected_status), true); 859 &host_, CreateInitDoneCB(expected_duration, expected_status), true);
852 860
853 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk) 861 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk)
854 return false; 862 return false;
(...skipping 21 matching lines...) Expand all
876 884
877 if (has_text) { 885 if (has_text) {
878 audio_flags |= HAS_TEXT; 886 audio_flags |= HAS_TEXT;
879 video_flags |= HAS_TEXT; 887 video_flags |= HAS_TEXT;
880 } 888 }
881 889
882 // Note: Unlike InitDemuxerWithEncryptionInfo, this method is currently 890 // Note: Unlike InitDemuxerWithEncryptionInfo, this method is currently
883 // incompatible with InSequence tests. Refactoring of the duration 891 // incompatible with InSequence tests. Refactoring of the duration
884 // set expectation to not be added during CreateInitDoneCB() could fix this. 892 // set expectation to not be added during CreateInitDoneCB() could fix this.
885 ExpectInitMediaLogs(audio_flags); 893 ExpectInitMediaLogs(audio_flags);
886 EXPECT_CALL(*this, InitSegmentReceived()); 894 EXPECT_CALL(*this, InitSegmentReceived(_));
887 AppendInitSegmentWithSourceId(audio_id, audio_flags); 895 AppendInitSegmentWithSourceId(audio_id, audio_flags);
888 896
889 ExpectInitMediaLogs(video_flags); 897 ExpectInitMediaLogs(video_flags);
890 EXPECT_CALL(*this, InitSegmentReceived()); 898 EXPECT_CALL(*this, InitSegmentReceived(_));
891 AppendInitSegmentWithSourceId(video_id, video_flags); 899 AppendInitSegmentWithSourceId(video_id, video_flags);
892 return true; 900 return true;
893 } 901 }
894 902
895 bool InitDemuxerAudioAndVideoSources(const std::string& audio_id, 903 bool InitDemuxerAudioAndVideoSources(const std::string& audio_id,
896 const std::string& video_id) { 904 const std::string& video_id) {
897 return InitDemuxerAudioAndVideoSourcesText(audio_id, video_id, false); 905 return InitDemuxerAudioAndVideoSourcesText(audio_id, video_id, false);
898 } 906 }
899 907
900 // Initializes the demuxer with data from 2 files with different 908 // Initializes the demuxer with data from 2 files with different
(...skipping 15 matching lines...) Expand all
916 // bear-640x360.webm : [527-759) 924 // bear-640x360.webm : [527-759)
917 bool InitDemuxerWithConfigChangeData() { 925 bool InitDemuxerWithConfigChangeData() {
918 scoped_refptr<DecoderBuffer> bear1 = ReadTestDataFile("bear-320x240.webm"); 926 scoped_refptr<DecoderBuffer> bear1 = ReadTestDataFile("bear-320x240.webm");
919 scoped_refptr<DecoderBuffer> bear2 = ReadTestDataFile("bear-640x360.webm"); 927 scoped_refptr<DecoderBuffer> bear2 = ReadTestDataFile("bear-640x360.webm");
920 928
921 EXPECT_CALL(*this, DemuxerOpened()); 929 EXPECT_CALL(*this, DemuxerOpened());
922 930
923 // Adding expectation prior to CreateInitDoneCB() here because InSequence 931 // Adding expectation prior to CreateInitDoneCB() here because InSequence
924 // tests require init segment received before duration set. 932 // tests require init segment received before duration set.
925 ExpectInitMediaLogs(HAS_AUDIO | HAS_VIDEO); 933 ExpectInitMediaLogs(HAS_AUDIO | HAS_VIDEO);
926 EXPECT_CALL(*this, InitSegmentReceived()); 934 EXPECT_CALL(*this, InitSegmentReceived(_));
927 demuxer_->Initialize( 935 demuxer_->Initialize(
928 &host_, CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), 936 &host_, CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744),
929 PIPELINE_OK), true); 937 PIPELINE_OK), true);
930 938
931 if (AddId(kSourceId, HAS_AUDIO | HAS_VIDEO) != ChunkDemuxer::kOk) 939 if (AddId(kSourceId, HAS_AUDIO | HAS_VIDEO) != ChunkDemuxer::kOk)
932 return false; 940 return false;
933 941
934 // Append the whole bear1 file. 942 // Append the whole bear1 file.
935 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)).Times(7); 943 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)).Times(7);
936 // Expect duration adjustment since actual duration differs slightly from 944 // Expect duration adjustment since actual duration differs slightly from
937 // duration in the init segment. 945 // duration in the init segment.
938 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746))); 946 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(2746)));
939 AppendData(bear1->data(), bear1->data_size()); 947 AppendData(bear1->data(), bear1->data_size());
940 // Last audio frame has timestamp 2721 and duration 24 (estimated from max 948 // Last audio frame has timestamp 2721 and duration 24 (estimated from max
941 // seen so far for audio track). 949 // seen so far for audio track).
942 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry 950 // Last video frame has timestamp 2703 and duration 33 (from TrackEntry
943 // DefaultDuration for video track). 951 // DefaultDuration for video track).
944 CheckExpectedRanges("{ [0,2736) }"); 952 CheckExpectedRanges("{ [0,2736) }");
945 953
946 // Append initialization segment for bear2. 954 // Append initialization segment for bear2.
947 // Note: Offsets here and below are derived from 955 // Note: Offsets here and below are derived from
948 // media/test/data/bear-640x360-manifest.js and 956 // media/test/data/bear-640x360-manifest.js and
949 // media/test/data/bear-320x240-manifest.js which were 957 // media/test/data/bear-320x240-manifest.js which were
950 // generated from media/test/data/bear-640x360.webm and 958 // generated from media/test/data/bear-640x360.webm and
951 // media/test/data/bear-320x240.webm respectively. 959 // media/test/data/bear-320x240.webm respectively.
952 EXPECT_CALL(*this, InitSegmentReceived()); 960 EXPECT_CALL(*this, InitSegmentReceived(_));
953 AppendData(bear2->data(), 4340); 961 AppendData(bear2->data(), 4340);
954 962
955 // Append a media segment that goes from [0.527000, 1.014000). 963 // Append a media segment that goes from [0.527000, 1.014000).
956 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)); 964 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2));
957 EXPECT_MEDIA_LOG(GeneratedSplice(20000, 527000)); 965 EXPECT_MEDIA_LOG(GeneratedSplice(20000, 527000));
958 AppendData(bear2->data() + 55290, 18785); 966 AppendData(bear2->data() + 55290, 18785);
959 CheckExpectedRanges("{ [0,1027) [1201,2736) }"); 967 CheckExpectedRanges("{ [0,1027) [1201,2736) }");
960 968
961 // Append initialization segment for bear1 & fill gap with [779-1197) 969 // Append initialization segment for bear1 & fill gap with [779-1197)
962 // segment. 970 // segment.
963 EXPECT_CALL(*this, InitSegmentReceived()); 971 EXPECT_CALL(*this, InitSegmentReceived(_));
964 AppendData(bear1->data(), 4370); 972 AppendData(bear1->data(), 4370);
965 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23)); 973 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(23));
966 EXPECT_MEDIA_LOG(GeneratedSplice(26000, 779000)); 974 EXPECT_MEDIA_LOG(GeneratedSplice(26000, 779000));
967 AppendData(bear1->data() + 72737, 28183); 975 AppendData(bear1->data() + 72737, 28183);
968 CheckExpectedRanges("{ [0,2736) }"); 976 CheckExpectedRanges("{ [0,2736) }");
969 977
970 MarkEndOfStream(PIPELINE_OK); 978 MarkEndOfStream(PIPELINE_OK);
971 return true; 979 return true;
972 } 980 }
973 981
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 int stream_flags) { 1309 int stream_flags) {
1302 EXPECT_CALL(*this, DemuxerOpened()); 1310 EXPECT_CALL(*this, DemuxerOpened());
1303 demuxer_->Initialize( 1311 demuxer_->Initialize(
1304 &host_, CreateInitDoneCB(duration, PIPELINE_OK), true); 1312 &host_, CreateInitDoneCB(duration, PIPELINE_OK), true);
1305 1313
1306 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk) 1314 if (AddId(kSourceId, stream_flags) != ChunkDemuxer::kOk)
1307 return false; 1315 return false;
1308 1316
1309 // Read a WebM file into memory and send the data to the demuxer. 1317 // Read a WebM file into memory and send the data to the demuxer.
1310 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); 1318 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename);
1311 EXPECT_CALL(*this, InitSegmentReceived()); 1319 EXPECT_CALL(*this, InitSegmentReceived(_));
1312 AppendDataInPieces(buffer->data(), buffer->data_size(), 512); 1320 AppendDataInPieces(buffer->data(), buffer->data_size(), 512);
1313 1321
1314 // Verify that the timestamps on the first few packets match what we 1322 // Verify that the timestamps on the first few packets match what we
1315 // expect. 1323 // expect.
1316 for (size_t i = 0; 1324 for (size_t i = 0;
1317 (timestamps[i].audio_time_ms != kSkip || 1325 (timestamps[i].audio_time_ms != kSkip ||
1318 timestamps[i].video_time_ms != kSkip); 1326 timestamps[i].video_time_ms != kSkip);
1319 i++) { 1327 i++) {
1320 bool audio_read_done = false; 1328 bool audio_read_done = false;
1321 bool video_read_done = false; 1329 bool video_read_done = false;
(...skipping 16 matching lines...) Expand all
1338 } 1346 }
1339 1347
1340 return true; 1348 return true;
1341 } 1349 }
1342 1350
1343 MOCK_METHOD0(DemuxerOpened, void()); 1351 MOCK_METHOD0(DemuxerOpened, void());
1344 MOCK_METHOD2(OnEncryptedMediaInitData, 1352 MOCK_METHOD2(OnEncryptedMediaInitData,
1345 void(EmeInitDataType init_data_type, 1353 void(EmeInitDataType init_data_type,
1346 const std::vector<uint8_t>& init_data)); 1354 const std::vector<uint8_t>& init_data));
1347 1355
1348 MOCK_METHOD0(InitSegmentReceived, void(void)); 1356 MOCK_METHOD1(InitSegmentReceived, void(scoped_ptr<MediaTracks>&));
1349 1357
1350 void Seek(base::TimeDelta seek_time) { 1358 void Seek(base::TimeDelta seek_time) {
1351 demuxer_->StartWaitingForSeek(seek_time); 1359 demuxer_->StartWaitingForSeek(seek_time);
1352 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); 1360 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK));
1353 message_loop_.RunUntilIdle(); 1361 message_loop_.RunUntilIdle();
1354 } 1362 }
1355 1363
1356 void MarkEndOfStream(PipelineStatus status) { 1364 void MarkEndOfStream(PipelineStatus status) {
1357 demuxer_->MarkEndOfStream(status); 1365 demuxer_->MarkEndOfStream(status);
1358 message_loop_.RunUntilIdle(); 1366 message_loop_.RunUntilIdle();
1359 } 1367 }
1360 1368
1361 bool SetTimestampOffset(const std::string& id, 1369 bool SetTimestampOffset(const std::string& id,
1362 base::TimeDelta timestamp_offset) { 1370 base::TimeDelta timestamp_offset) {
1363 if (demuxer_->IsParsingMediaSegment(id)) 1371 if (demuxer_->IsParsingMediaSegment(id))
1364 return false; 1372 return false;
1365 1373
1366 timestamp_offset_map_[id] = timestamp_offset; 1374 timestamp_offset_map_[id] = timestamp_offset;
1367 return true; 1375 return true;
1368 } 1376 }
1369 1377
1370 base::MessageLoop message_loop_; 1378 base::MessageLoop message_loop_;
1371 MockDemuxerHost host_; 1379 MockDemuxerHost host_;
1372 1380
1373 scoped_refptr<StrictMock<MockMediaLog>> media_log_; 1381 scoped_refptr<StrictMock<MockMediaLog>> media_log_;
1374 1382
1375 scoped_ptr<ChunkDemuxer> demuxer_; 1383 scoped_ptr<ChunkDemuxer> demuxer_;
1376 MediaSourceState::InitSegmentReceivedCB init_segment_received_cb_; 1384 Demuxer::MediaTracksUpdatedCB init_segment_received_cb_;
1377 1385
1378 base::TimeDelta append_window_start_for_next_append_; 1386 base::TimeDelta append_window_start_for_next_append_;
1379 base::TimeDelta append_window_end_for_next_append_; 1387 base::TimeDelta append_window_end_for_next_append_;
1380 1388
1381 // Map of source id to timestamp offset to use for the next AppendData() 1389 // Map of source id to timestamp offset to use for the next AppendData()
1382 // operation for that source id. 1390 // operation for that source id.
1383 std::map<std::string, base::TimeDelta> timestamp_offset_map_; 1391 std::map<std::string, base::TimeDelta> timestamp_offset_map_;
1384 1392
1393 public:
1394 // A workaround for gtest mocks not allowing moving scoped_ptrs.
1395 void InitSegmentReceivedWrapper(scoped_ptr<MediaTracks> tracks) {
1396 InitSegmentReceived(tracks);
1397 }
1398
1385 private: 1399 private:
1386 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); 1400 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest);
1387 }; 1401 };
1388 1402
1389 TEST_F(ChunkDemuxerTest, Init) { 1403 TEST_F(ChunkDemuxerTest, Init) {
1390 InSequence s; 1404 InSequence s;
1391 1405
1392 // Test no streams, audio-only, video-only, and audio & video scenarios. 1406 // Test no streams, audio-only, video-only, and audio & video scenarios.
1393 // Audio and video streams can be encrypted or not encrypted. 1407 // Audio and video streams can be encrypted or not encrypted.
1394 for (int i = 0; i < 16; i++) { 1408 for (int i = 0; i < 16; i++) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), 1554 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23),
1541 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30), 1555 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30),
1542 MuxedStreamInfo(kTextTrackNum, "10K")); 1556 MuxedStreamInfo(kTextTrackNum, "10K"));
1543 CheckExpectedRanges("{ [0,46) }"); 1557 CheckExpectedRanges("{ [0,46) }");
1544 1558
1545 scoped_ptr<uint8_t[]> info_tracks; 1559 scoped_ptr<uint8_t[]> info_tracks;
1546 int info_tracks_size = 0; 1560 int info_tracks_size = 0;
1547 CreateInitSegmentWithAlternateTextTrackNum(HAS_TEXT | HAS_AUDIO | HAS_VIDEO, 1561 CreateInitSegmentWithAlternateTextTrackNum(HAS_TEXT | HAS_AUDIO | HAS_VIDEO,
1548 false, false, 1562 false, false,
1549 &info_tracks, &info_tracks_size); 1563 &info_tracks, &info_tracks_size);
1550 EXPECT_CALL(*this, InitSegmentReceived()); 1564 EXPECT_CALL(*this, InitSegmentReceived(_));
1551 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, 1565 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size,
1552 append_window_start_for_next_append_, 1566 append_window_start_for_next_append_,
1553 append_window_end_for_next_append_, 1567 append_window_end_for_next_append_,
1554 &timestamp_offset_map_[kSourceId], 1568 &timestamp_offset_map_[kSourceId]);
1555 init_segment_received_cb_);
1556 1569
1557 AppendMuxedCluster( 1570 AppendMuxedCluster(
1558 MuxedStreamInfo(kAudioTrackNum, "46K 69K", 23), 1571 MuxedStreamInfo(kAudioTrackNum, "46K 69K", 23),
1559 MuxedStreamInfo(kVideoTrackNum, "60K", 1572 MuxedStreamInfo(kVideoTrackNum, "60K",
1560 WebMClusterParser::kDefaultVideoBufferDurationInMs), 1573 WebMClusterParser::kDefaultVideoBufferDurationInMs),
1561 MuxedStreamInfo(kAlternateTextTrackNum, "45K")); 1574 MuxedStreamInfo(kAlternateTextTrackNum, "45K"));
1562 1575
1563 CheckExpectedRanges("{ [0,92) }"); 1576 CheckExpectedRanges("{ [0,92) }");
1564 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K"); 1577 CheckExpectedBuffers(audio_stream, "0K 23K 46K 69K");
1565 CheckExpectedBuffers(video_stream, "0K 30 60K"); 1578 CheckExpectedBuffers(video_stream, "0K 30 60K");
(...skipping 19 matching lines...) Expand all
1585 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); 1598 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
1586 ASSERT_TRUE(audio_stream && video_stream && text_stream); 1599 ASSERT_TRUE(audio_stream && video_stream && text_stream);
1587 1600
1588 AppendMuxedCluster( 1601 AppendMuxedCluster(
1589 MuxedStreamInfo(kAudioTrackNum, "23K", 1602 MuxedStreamInfo(kAudioTrackNum, "23K",
1590 WebMClusterParser::kDefaultAudioBufferDurationInMs), 1603 WebMClusterParser::kDefaultAudioBufferDurationInMs),
1591 MuxedStreamInfo(kVideoTrackNum, "0 30K", 30), 1604 MuxedStreamInfo(kVideoTrackNum, "0 30K", 30),
1592 MuxedStreamInfo(kTextTrackNum, "25K 40K")); 1605 MuxedStreamInfo(kTextTrackNum, "25K 40K"));
1593 CheckExpectedRanges("{ [23,46) }"); 1606 CheckExpectedRanges("{ [23,46) }");
1594 1607
1595 EXPECT_CALL(*this, InitSegmentReceived()); 1608 EXPECT_CALL(*this, InitSegmentReceived(_));
1596 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); 1609 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO);
1597 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "46K 69K", 23), 1610 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "46K 69K", 23),
1598 MuxedStreamInfo(kVideoTrackNum, "60 90K", 30), 1611 MuxedStreamInfo(kVideoTrackNum, "60 90K", 30),
1599 MuxedStreamInfo(kTextTrackNum, "80K 90K")); 1612 MuxedStreamInfo(kTextTrackNum, "80K 90K"));
1600 CheckExpectedRanges("{ [23,92) }"); 1613 CheckExpectedRanges("{ [23,92) }");
1601 1614
1602 CheckExpectedBuffers(audio_stream, "23K 46K 69K"); 1615 CheckExpectedBuffers(audio_stream, "23K 46K 69K");
1603 CheckExpectedBuffers(video_stream, "30K 90K"); 1616 CheckExpectedBuffers(video_stream, "30K 90K");
1604 CheckExpectedBuffers(text_stream, "25K 40K 80K 90K"); 1617 CheckExpectedBuffers(text_stream, "25K 40K 80K 90K");
1605 } 1618 }
1606 1619
1607 // Make sure that the demuxer reports an error if Shutdown() 1620 // Make sure that the demuxer reports an error if Shutdown()
1608 // is called before all the initialization segments are appended. 1621 // is called before all the initialization segments are appended.
1609 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { 1622 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) {
1610 EXPECT_CALL(*this, DemuxerOpened()); 1623 EXPECT_CALL(*this, DemuxerOpened());
1611 demuxer_->Initialize( 1624 demuxer_->Initialize(
1612 &host_, CreateInitDoneCB( 1625 &host_, CreateInitDoneCB(
1613 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1626 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1614 1627
1615 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); 1628 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk);
1616 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk); 1629 EXPECT_EQ(AddId("video", HAS_VIDEO), ChunkDemuxer::kOk);
1617 1630
1618 ExpectInitMediaLogs(HAS_AUDIO); 1631 ExpectInitMediaLogs(HAS_AUDIO);
1619 EXPECT_CALL(*this, InitSegmentReceived()); 1632 EXPECT_CALL(*this, InitSegmentReceived(_));
1620 AppendInitSegmentWithSourceId("audio", HAS_AUDIO); 1633 AppendInitSegmentWithSourceId("audio", HAS_AUDIO);
1621 1634
1622 ShutdownDemuxer(); 1635 ShutdownDemuxer();
1623 } 1636 }
1624 1637
1625 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) { 1638 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppendedText) {
1626 EXPECT_CALL(*this, DemuxerOpened()); 1639 EXPECT_CALL(*this, DemuxerOpened());
1627 demuxer_->Initialize( 1640 demuxer_->Initialize(
1628 &host_, CreateInitDoneCB( 1641 &host_, CreateInitDoneCB(
1629 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true); 1642 kDefaultDuration(), DEMUXER_ERROR_COULD_NOT_OPEN), true);
1630 1643
1631 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk); 1644 EXPECT_EQ(AddId("audio", HAS_AUDIO), ChunkDemuxer::kOk);
1632 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk); 1645 EXPECT_EQ(AddId("video_and_text", HAS_VIDEO), ChunkDemuxer::kOk);
1633 1646
1634 EXPECT_CALL(host_, AddTextStream(_, _)) 1647 EXPECT_CALL(host_, AddTextStream(_, _))
1635 .Times(Exactly(1)); 1648 .Times(Exactly(1));
1636 1649
1637 ExpectInitMediaLogs(HAS_VIDEO); 1650 ExpectInitMediaLogs(HAS_VIDEO);
1638 EXPECT_CALL(*this, InitSegmentReceived()); 1651 EXPECT_CALL(*this, InitSegmentReceived(_));
1639 AppendInitSegmentWithSourceId("video_and_text", HAS_VIDEO | HAS_TEXT); 1652 AppendInitSegmentWithSourceId("video_and_text", HAS_VIDEO | HAS_TEXT);
1640 1653
1641 ShutdownDemuxer(); 1654 ShutdownDemuxer();
1642 } 1655 }
1643 1656
1644 // Verifies that all streams waiting for data receive an end of stream 1657 // Verifies that all streams waiting for data receive an end of stream
1645 // buffer when Shutdown() is called. 1658 // buffer when Shutdown() is called.
1646 TEST_F(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) { 1659 TEST_F(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) {
1647 DemuxerStream* text_stream = NULL; 1660 DemuxerStream* text_stream = NULL;
1648 EXPECT_CALL(host_, AddTextStream(_, _)) 1661 EXPECT_CALL(host_, AddTextStream(_, _))
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 1751
1739 // Test the case where AppendData() is called before Init(). 1752 // Test the case where AppendData() is called before Init().
1740 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) { 1753 TEST_F(ChunkDemuxerTest, AppendDataBeforeInit) {
1741 scoped_ptr<uint8_t[]> info_tracks; 1754 scoped_ptr<uint8_t[]> info_tracks;
1742 int info_tracks_size = 0; 1755 int info_tracks_size = 0;
1743 CreateInitSegment(HAS_AUDIO | HAS_VIDEO, 1756 CreateInitSegment(HAS_AUDIO | HAS_VIDEO,
1744 false, false, &info_tracks, &info_tracks_size); 1757 false, false, &info_tracks, &info_tracks_size);
1745 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, 1758 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size,
1746 append_window_start_for_next_append_, 1759 append_window_start_for_next_append_,
1747 append_window_end_for_next_append_, 1760 append_window_end_for_next_append_,
1748 &timestamp_offset_map_[kSourceId], 1761 &timestamp_offset_map_[kSourceId]);
1749 init_segment_received_cb_);
1750 } 1762 }
1751 1763
1752 // Make sure Read() callbacks are dispatched with the proper data. 1764 // Make sure Read() callbacks are dispatched with the proper data.
1753 TEST_F(ChunkDemuxerTest, Read) { 1765 TEST_F(ChunkDemuxerTest, Read) {
1754 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1766 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1755 1767
1756 AppendCluster(kDefaultFirstCluster()); 1768 AppendCluster(kDefaultFirstCluster());
1757 1769
1758 bool audio_read_done = false; 1770 bool audio_read_done = false;
1759 bool video_read_done = false; 1771 bool video_read_done = false;
(...skipping 18 matching lines...) Expand all
1778 // overlaps with the previously appended cluster. 1790 // overlaps with the previously appended cluster.
1779 EXPECT_MEDIA_LOG(SkippingSpliceAlreadySpliced(0)); 1791 EXPECT_MEDIA_LOG(SkippingSpliceAlreadySpliced(0));
1780 AppendCluster(GenerateCluster(5, 4)); 1792 AppendCluster(GenerateCluster(5, 4));
1781 1793
1782 // Verify that AppendData() can still accept more data. 1794 // Verify that AppendData() can still accept more data.
1783 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2)); 1795 scoped_ptr<Cluster> cluster_c(GenerateCluster(45, 2));
1784 EXPECT_MEDIA_LOG(GeneratedSplice(6000, 45000)); 1796 EXPECT_MEDIA_LOG(GeneratedSplice(6000, 45000));
1785 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(), 1797 demuxer_->AppendData(kSourceId, cluster_c->data(), cluster_c->size(),
1786 append_window_start_for_next_append_, 1798 append_window_start_for_next_append_,
1787 append_window_end_for_next_append_, 1799 append_window_end_for_next_append_,
1788 &timestamp_offset_map_[kSourceId], 1800 &timestamp_offset_map_[kSourceId]);
1789 init_segment_received_cb_);
1790 } 1801 }
1791 1802
1792 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) { 1803 TEST_F(ChunkDemuxerTest, NonMonotonicButAboveClusterTimecode) {
1793 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1804 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1794 AppendCluster(kDefaultFirstCluster()); 1805 AppendCluster(kDefaultFirstCluster());
1795 1806
1796 ClusterBuilder cb; 1807 ClusterBuilder cb;
1797 1808
1798 // Test the case where block timecodes are not monotonically 1809 // Test the case where block timecodes are not monotonically
1799 // increasing but stay above the cluster timecode. 1810 // increasing but stay above the cluster timecode.
1800 cb.SetClusterTimecode(5); 1811 cb.SetClusterTimecode(5);
1801 AddSimpleBlock(&cb, kAudioTrackNum, 5); 1812 AddSimpleBlock(&cb, kAudioTrackNum, 5);
1802 AddSimpleBlock(&cb, kVideoTrackNum, 10); 1813 AddSimpleBlock(&cb, kVideoTrackNum, 10);
1803 AddSimpleBlock(&cb, kAudioTrackNum, 7); 1814 AddSimpleBlock(&cb, kAudioTrackNum, 7);
1804 AddSimpleBlock(&cb, kVideoTrackNum, 15); 1815 AddSimpleBlock(&cb, kVideoTrackNum, 15);
1805 1816
1806 EXPECT_MEDIA_LOG(WebMOutOfOrderTimecode()); 1817 EXPECT_MEDIA_LOG(WebMOutOfOrderTimecode());
1807 EXPECT_MEDIA_LOG(StreamParsingFailed()); 1818 EXPECT_MEDIA_LOG(StreamParsingFailed());
1808 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1819 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1809 AppendCluster(cb.Finish()); 1820 AppendCluster(cb.Finish());
1810 1821
1811 // Verify that AppendData() ignores data after the error. 1822 // Verify that AppendData() ignores data after the error.
1812 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2)); 1823 scoped_ptr<Cluster> cluster_b(GenerateCluster(20, 2));
1813 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), 1824 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(),
1814 append_window_start_for_next_append_, 1825 append_window_start_for_next_append_,
1815 append_window_end_for_next_append_, 1826 append_window_end_for_next_append_,
1816 &timestamp_offset_map_[kSourceId], 1827 &timestamp_offset_map_[kSourceId]);
1817 init_segment_received_cb_);
1818 } 1828 }
1819 1829
1820 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) { 1830 TEST_F(ChunkDemuxerTest, BackwardsAndBeforeClusterTimecode) {
1821 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1831 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1822 AppendCluster(kDefaultFirstCluster()); 1832 AppendCluster(kDefaultFirstCluster());
1823 1833
1824 ClusterBuilder cb; 1834 ClusterBuilder cb;
1825 1835
1826 // Test timecodes going backwards and including values less than the cluster 1836 // Test timecodes going backwards and including values less than the cluster
1827 // timecode. 1837 // timecode.
1828 cb.SetClusterTimecode(5); 1838 cb.SetClusterTimecode(5);
1829 AddSimpleBlock(&cb, kAudioTrackNum, 5); 1839 AddSimpleBlock(&cb, kAudioTrackNum, 5);
1830 AddSimpleBlock(&cb, kVideoTrackNum, 5); 1840 AddSimpleBlock(&cb, kVideoTrackNum, 5);
1831 AddSimpleBlock(&cb, kAudioTrackNum, 3); 1841 AddSimpleBlock(&cb, kAudioTrackNum, 3);
1832 AddSimpleBlock(&cb, kVideoTrackNum, 3); 1842 AddSimpleBlock(&cb, kVideoTrackNum, 3);
1833 1843
1834 EXPECT_MEDIA_LOG(WebMNegativeTimecodeOffset("-2")); 1844 EXPECT_MEDIA_LOG(WebMNegativeTimecodeOffset("-2"));
1835 EXPECT_MEDIA_LOG(StreamParsingFailed()); 1845 EXPECT_MEDIA_LOG(StreamParsingFailed());
1836 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); 1846 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE));
1837 AppendCluster(cb.Finish()); 1847 AppendCluster(cb.Finish());
1838 1848
1839 // Verify that AppendData() ignores data after the error. 1849 // Verify that AppendData() ignores data after the error.
1840 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2)); 1850 scoped_ptr<Cluster> cluster_b(GenerateCluster(6, 2));
1841 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(), 1851 demuxer_->AppendData(kSourceId, cluster_b->data(), cluster_b->size(),
1842 append_window_start_for_next_append_, 1852 append_window_start_for_next_append_,
1843 append_window_end_for_next_append_, 1853 append_window_end_for_next_append_,
1844 &timestamp_offset_map_[kSourceId], 1854 &timestamp_offset_map_[kSourceId]);
1845 init_segment_received_cb_);
1846 } 1855 }
1847 1856
1848 1857
1849 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) { 1858 TEST_F(ChunkDemuxerTest, PerStreamMonotonicallyIncreasingTimestamps) {
1850 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 1859 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
1851 AppendCluster(kDefaultFirstCluster()); 1860 AppendCluster(kDefaultFirstCluster());
1852 1861
1853 ClusterBuilder cb; 1862 ClusterBuilder cb;
1854 1863
1855 // Test monotonic increasing timestamps on a per stream 1864 // Test monotonic increasing timestamps on a per stream
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2150 memcpy(dst, info_tracks.get(), info_tracks_size); 2159 memcpy(dst, info_tracks.get(), info_tracks_size);
2151 dst += info_tracks_size; 2160 dst += info_tracks_size;
2152 2161
2153 memcpy(dst, cluster_a->data(), cluster_a->size()); 2162 memcpy(dst, cluster_a->data(), cluster_a->size());
2154 dst += cluster_a->size(); 2163 dst += cluster_a->size();
2155 2164
2156 memcpy(dst, cluster_b->data(), cluster_b->size()); 2165 memcpy(dst, cluster_b->data(), cluster_b->size());
2157 dst += cluster_b->size(); 2166 dst += cluster_b->size();
2158 2167
2159 ExpectInitMediaLogs(HAS_AUDIO | HAS_VIDEO); 2168 ExpectInitMediaLogs(HAS_AUDIO | HAS_VIDEO);
2160 EXPECT_CALL(*this, InitSegmentReceived()); 2169 EXPECT_CALL(*this, InitSegmentReceived(_));
2161 AppendDataInPieces(buffer.get(), buffer_size); 2170 AppendDataInPieces(buffer.get(), buffer_size);
2162 2171
2163 GenerateExpectedReads(0, 9); 2172 GenerateExpectedReads(0, 9);
2164 } 2173 }
2165 2174
2166 TEST_F(ChunkDemuxerTest, WebMFile_AudioAndVideo) { 2175 TEST_F(ChunkDemuxerTest, WebMFile_AudioAndVideo) {
2167 struct BufferTimestamps buffer_timestamps[] = { 2176 struct BufferTimestamps buffer_timestamps[] = {
2168 {0, 0}, 2177 {0, 0},
2169 {33, 3}, 2178 {33, 3},
2170 {67, 6}, 2179 {67, 6},
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) { 2333 TEST_F(ChunkDemuxerTest, ParseErrorDuringInit) {
2325 EXPECT_CALL(*this, DemuxerOpened()); 2334 EXPECT_CALL(*this, DemuxerOpened());
2326 demuxer_->Initialize( 2335 demuxer_->Initialize(
2327 &host_, CreateInitDoneCB( 2336 &host_, CreateInitDoneCB(
2328 kNoTimestamp(), PIPELINE_ERROR_DECODE), true); 2337 kNoTimestamp(), PIPELINE_ERROR_DECODE), true);
2329 2338
2330 ASSERT_EQ(AddId(), ChunkDemuxer::kOk); 2339 ASSERT_EQ(AddId(), ChunkDemuxer::kOk);
2331 2340
2332 EXPECT_MEDIA_LOG(StreamParsingFailed()); 2341 EXPECT_MEDIA_LOG(StreamParsingFailed());
2333 uint8_t tmp = 0; 2342 uint8_t tmp = 0;
2334 demuxer_->AppendData(kSourceId, &tmp, 1, 2343 demuxer_->AppendData(kSourceId, &tmp, 1, append_window_start_for_next_append_,
2335 append_window_start_for_next_append_,
2336 append_window_end_for_next_append_, 2344 append_window_end_for_next_append_,
2337 &timestamp_offset_map_[kSourceId], 2345 &timestamp_offset_map_[kSourceId]);
2338 init_segment_received_cb_);
2339 } 2346 }
2340 2347
2341 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) { 2348 TEST_F(ChunkDemuxerTest, AVHeadersWithAudioOnlyType) {
2342 EXPECT_CALL(*this, DemuxerOpened()); 2349 EXPECT_CALL(*this, DemuxerOpened());
2343 demuxer_->Initialize( 2350 demuxer_->Initialize(
2344 &host_, CreateInitDoneCB(kNoTimestamp(), 2351 &host_, CreateInitDoneCB(kNoTimestamp(),
2345 PIPELINE_ERROR_DECODE), true); 2352 PIPELINE_ERROR_DECODE), true);
2346 2353
2347 std::vector<std::string> codecs(1); 2354 std::vector<std::string> codecs(1);
2348 codecs[0] = "vorbis"; 2355 codecs[0] = "vorbis";
2349 ASSERT_EQ(demuxer_->AddId(kSourceId, "audio/webm", codecs), 2356 ASSERT_EQ(demuxer_->AddId(kSourceId, "audio/webm", codecs),
2350 ChunkDemuxer::kOk); 2357 ChunkDemuxer::kOk);
2358 demuxer_->SetTracksWatcher(
2359 kSourceId, base::Bind(&ChunkDemuxerTest::InitSegmentReceivedWrapper,
2360 base::Unretained(this)));
2351 2361
2352 // Video track is unexpected per mimetype. 2362 // Video track is unexpected per mimetype.
2353 EXPECT_MEDIA_LOG(InitSegmentMismatchesMimeType("a video", true)); 2363 EXPECT_MEDIA_LOG(InitSegmentMismatchesMimeType("a video", true));
2354 EXPECT_MEDIA_LOG(StreamParsingFailed()); 2364 EXPECT_MEDIA_LOG(StreamParsingFailed());
2355 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); 2365 AppendInitSegment(HAS_AUDIO | HAS_VIDEO);
2356 } 2366 }
2357 2367
2358 TEST_F(ChunkDemuxerTest, AVHeadersWithVideoOnlyType) { 2368 TEST_F(ChunkDemuxerTest, AVHeadersWithVideoOnlyType) {
2359 EXPECT_CALL(*this, DemuxerOpened()); 2369 EXPECT_CALL(*this, DemuxerOpened());
2360 demuxer_->Initialize( 2370 demuxer_->Initialize(
2361 &host_, CreateInitDoneCB(kNoTimestamp(), 2371 &host_, CreateInitDoneCB(kNoTimestamp(),
2362 PIPELINE_ERROR_DECODE), true); 2372 PIPELINE_ERROR_DECODE), true);
2363 2373
2364 std::vector<std::string> codecs(1); 2374 std::vector<std::string> codecs(1);
2365 codecs[0] = "vp8"; 2375 codecs[0] = "vp8";
2366 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs), 2376 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs),
2367 ChunkDemuxer::kOk); 2377 ChunkDemuxer::kOk);
2378 demuxer_->SetTracksWatcher(
2379 kSourceId, base::Bind(&ChunkDemuxerTest::InitSegmentReceivedWrapper,
2380 base::Unretained(this)));
2368 2381
2369 // Audio track is unexpected per mimetype. 2382 // Audio track is unexpected per mimetype.
2370 EXPECT_MEDIA_LOG(InitSegmentMismatchesMimeType("an audio", true)); 2383 EXPECT_MEDIA_LOG(InitSegmentMismatchesMimeType("an audio", true));
2371 EXPECT_MEDIA_LOG(StreamParsingFailed()); 2384 EXPECT_MEDIA_LOG(StreamParsingFailed());
2372 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); 2385 AppendInitSegment(HAS_AUDIO | HAS_VIDEO);
2373 } 2386 }
2374 2387
2375 TEST_F(ChunkDemuxerTest, AudioOnlyHeaderWithAVType) { 2388 TEST_F(ChunkDemuxerTest, AudioOnlyHeaderWithAVType) {
2376 EXPECT_CALL(*this, DemuxerOpened()); 2389 EXPECT_CALL(*this, DemuxerOpened());
2377 demuxer_->Initialize( 2390 demuxer_->Initialize(
2378 &host_, CreateInitDoneCB(kNoTimestamp(), PIPELINE_ERROR_DECODE), true); 2391 &host_, CreateInitDoneCB(kNoTimestamp(), PIPELINE_ERROR_DECODE), true);
2379 2392
2380 std::vector<std::string> codecs(2); 2393 std::vector<std::string> codecs(2);
2381 codecs[0] = "vorbis"; 2394 codecs[0] = "vorbis";
2382 codecs[1] = "vp8"; 2395 codecs[1] = "vp8";
2383 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs), 2396 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs),
2384 ChunkDemuxer::kOk); 2397 ChunkDemuxer::kOk);
2398 demuxer_->SetTracksWatcher(
2399 kSourceId, base::Bind(&ChunkDemuxerTest::InitSegmentReceivedWrapper,
2400 base::Unretained(this)));
2385 2401
2386 // Video track is also expected per mimetype. 2402 // Video track is also expected per mimetype.
2387 EXPECT_MEDIA_LOG(InitSegmentMismatchesMimeType("a video", false)); 2403 EXPECT_MEDIA_LOG(InitSegmentMismatchesMimeType("a video", false));
2388 EXPECT_MEDIA_LOG(StreamParsingFailed()); 2404 EXPECT_MEDIA_LOG(StreamParsingFailed());
2389 AppendInitSegment(HAS_AUDIO); 2405 AppendInitSegment(HAS_AUDIO);
2390 } 2406 }
2391 2407
2392 TEST_F(ChunkDemuxerTest, VideoOnlyHeaderWithAVType) { 2408 TEST_F(ChunkDemuxerTest, VideoOnlyHeaderWithAVType) {
2393 EXPECT_CALL(*this, DemuxerOpened()); 2409 EXPECT_CALL(*this, DemuxerOpened());
2394 demuxer_->Initialize( 2410 demuxer_->Initialize(
2395 &host_, CreateInitDoneCB(kNoTimestamp(), PIPELINE_ERROR_DECODE), true); 2411 &host_, CreateInitDoneCB(kNoTimestamp(), PIPELINE_ERROR_DECODE), true);
2396 2412
2397 std::vector<std::string> codecs(2); 2413 std::vector<std::string> codecs(2);
2398 codecs[0] = "vorbis"; 2414 codecs[0] = "vorbis";
2399 codecs[1] = "vp8"; 2415 codecs[1] = "vp8";
2400 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs), 2416 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs),
2401 ChunkDemuxer::kOk); 2417 ChunkDemuxer::kOk);
2418 demuxer_->SetTracksWatcher(
2419 kSourceId, base::Bind(&ChunkDemuxerTest::InitSegmentReceivedWrapper,
2420 base::Unretained(this)));
2402 2421
2403 // Audio track is also expected per mimetype. 2422 // Audio track is also expected per mimetype.
2404 EXPECT_MEDIA_LOG(InitSegmentMismatchesMimeType("an audio", false)); 2423 EXPECT_MEDIA_LOG(InitSegmentMismatchesMimeType("an audio", false));
2405 EXPECT_MEDIA_LOG(StreamParsingFailed()); 2424 EXPECT_MEDIA_LOG(StreamParsingFailed());
2406 AppendInitSegment(HAS_VIDEO); 2425 AppendInitSegment(HAS_VIDEO);
2407 } 2426 }
2408 2427
2409 TEST_F(ChunkDemuxerTest, MultipleHeaders) { 2428 TEST_F(ChunkDemuxerTest, MultipleHeaders) {
2410 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); 2429 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO));
2411 2430
2412 AppendCluster(kDefaultFirstCluster()); 2431 AppendCluster(kDefaultFirstCluster());
2413 2432
2414 // Append another identical initialization segment. 2433 // Append another identical initialization segment.
2415 EXPECT_CALL(*this, InitSegmentReceived()); 2434 EXPECT_CALL(*this, InitSegmentReceived(_));
2416 AppendInitSegment(HAS_AUDIO | HAS_VIDEO); 2435 AppendInitSegment(HAS_AUDIO | HAS_VIDEO);
2417 2436
2418 AppendCluster(kDefaultSecondCluster()); 2437 AppendCluster(kDefaultSecondCluster());
2419 2438
2420 GenerateExpectedReads(0, 9); 2439 GenerateExpectedReads(0, 9);
2421 } 2440 }
2422 2441
2423 TEST_F(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideo) { 2442 TEST_F(ChunkDemuxerTest, AddSeparateSourcesForAudioAndVideo) {
2424 std::string audio_id = "audio1"; 2443 std::string audio_id = "audio1";
2425 std::string video_id = "video1"; 2444 std::string video_id = "video1";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2461 2480
2462 std::string audio_id = "audio1"; 2481 std::string audio_id = "audio1";
2463 std::string video_id = "video1"; 2482 std::string video_id = "video1";
2464 2483
2465 ASSERT_EQ(AddId(audio_id, HAS_AUDIO), ChunkDemuxer::kOk); 2484 ASSERT_EQ(AddId(audio_id, HAS_AUDIO), ChunkDemuxer::kOk);
2466 2485
2467 // Adding an id with audio/video should fail because we already added audio. 2486 // Adding an id with audio/video should fail because we already added audio.
2468 ASSERT_EQ(AddId(), ChunkDemuxer::kReachedIdLimit); 2487 ASSERT_EQ(AddId(), ChunkDemuxer::kReachedIdLimit);
2469 2488
2470 ExpectInitMediaLogs(HAS_AUDIO); 2489 ExpectInitMediaLogs(HAS_AUDIO);
2471 EXPECT_CALL(*this, InitSegmentReceived()); 2490 EXPECT_CALL(*this, InitSegmentReceived(_));
2472 AppendInitSegmentWithSourceId(audio_id, HAS_AUDIO); 2491 AppendInitSegmentWithSourceId(audio_id, HAS_AUDIO);
2473 2492
2474 // Adding an id after append should fail. 2493 // Adding an id after append should fail.
2475 ASSERT_EQ(AddId(video_id, HAS_VIDEO), ChunkDemuxer::kReachedIdLimit); 2494 ASSERT_EQ(AddId(video_id, HAS_VIDEO), ChunkDemuxer::kReachedIdLimit);
2476 } 2495 }
2477 2496
2478 // Test that Read() calls after a RemoveId() return "end of stream" buffers. 2497 // Test that Read() calls after a RemoveId() return "end of stream" buffers.
2479 TEST_F(ChunkDemuxerTest, RemoveId) { 2498 TEST_F(ChunkDemuxerTest, RemoveId) {
2480 std::string audio_id = "audio1"; 2499 std::string audio_id = "audio1";
2481 std::string video_id = "video1"; 2500 std::string video_id = "video1";
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
2705 } 2724 }
2706 2725
2707 // Test ranges in an audio-only stream. 2726 // Test ranges in an audio-only stream.
2708 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) { 2727 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioIdOnly) {
2709 EXPECT_CALL(*this, DemuxerOpened()); 2728 EXPECT_CALL(*this, DemuxerOpened());
2710 demuxer_->Initialize( 2729 demuxer_->Initialize(
2711 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 2730 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
2712 2731
2713 ASSERT_EQ(AddId(kSourceId, HAS_AUDIO), ChunkDemuxer::kOk); 2732 ASSERT_EQ(AddId(kSourceId, HAS_AUDIO), ChunkDemuxer::kOk);
2714 ExpectInitMediaLogs(HAS_AUDIO); 2733 ExpectInitMediaLogs(HAS_AUDIO);
2715 EXPECT_CALL(*this, InitSegmentReceived()); 2734 EXPECT_CALL(*this, InitSegmentReceived(_));
2716 AppendInitSegment(HAS_AUDIO); 2735 AppendInitSegment(HAS_AUDIO);
2717 2736
2718 // Test a simple cluster. 2737 // Test a simple cluster.
2719 AppendCluster( 2738 AppendCluster(
2720 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration)); 2739 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration));
2721 2740
2722 CheckExpectedRanges("{ [0,92) }"); 2741 CheckExpectedRanges("{ [0,92) }");
2723 2742
2724 // Append a disjoint cluster to check for two separate ranges. 2743 // Append a disjoint cluster to check for two separate ranges.
2725 AppendCluster(GenerateSingleStreamCluster( 2744 AppendCluster(GenerateSingleStreamCluster(
2726 150, 219, kAudioTrackNum, kAudioBlockDuration)); 2745 150, 219, kAudioTrackNum, kAudioBlockDuration));
2727 2746
2728 CheckExpectedRanges("{ [0,92) [150,219) }"); 2747 CheckExpectedRanges("{ [0,92) [150,219) }");
2729 } 2748 }
2730 2749
2731 // Test ranges in a video-only stream. 2750 // Test ranges in a video-only stream.
2732 TEST_F(ChunkDemuxerTest, GetBufferedRanges_VideoIdOnly) { 2751 TEST_F(ChunkDemuxerTest, GetBufferedRanges_VideoIdOnly) {
2733 EXPECT_CALL(*this, DemuxerOpened()); 2752 EXPECT_CALL(*this, DemuxerOpened());
2734 demuxer_->Initialize( 2753 demuxer_->Initialize(
2735 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true); 2754 &host_, CreateInitDoneCB(kDefaultDuration(), PIPELINE_OK), true);
2736 2755
2737 ASSERT_EQ(AddId(kSourceId, HAS_VIDEO), ChunkDemuxer::kOk); 2756 ASSERT_EQ(AddId(kSourceId, HAS_VIDEO), ChunkDemuxer::kOk);
2738 ExpectInitMediaLogs(HAS_VIDEO); 2757 ExpectInitMediaLogs(HAS_VIDEO);
2739 EXPECT_CALL(*this, InitSegmentReceived()); 2758 EXPECT_CALL(*this, InitSegmentReceived(_));
2740 AppendInitSegment(HAS_VIDEO); 2759 AppendInitSegment(HAS_VIDEO);
2741 2760
2742 // Test a simple cluster. 2761 // Test a simple cluster.
2743 AppendCluster( 2762 AppendCluster(
2744 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration)); 2763 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, kVideoBlockDuration));
2745 2764
2746 CheckExpectedRanges("{ [0,132) }"); 2765 CheckExpectedRanges("{ [0,132) }");
2747 2766
2748 // Append a disjoint cluster to check for two separate ranges. 2767 // Append a disjoint cluster to check for two separate ranges.
2749 AppendCluster(GenerateSingleStreamCluster( 2768 AppendCluster(GenerateSingleStreamCluster(
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
3399 // Audio: first PES: 3418 // Audio: first PES:
3400 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000] 3419 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000]
3401 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767] 3420 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767]
3402 // Video: last PES: 3421 // Video: last PES:
3403 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128] 3422 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128]
3404 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794] 3423 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794]
3405 // Audio: last PES: 3424 // Audio: last PES:
3406 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309] 3425 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309]
3407 3426
3408 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts"); 3427 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts");
3409 EXPECT_CALL(*this, InitSegmentReceived()); 3428 EXPECT_CALL(*this, InitSegmentReceived(_));
3410 AppendData(kSourceId, buffer->data(), buffer->data_size()); 3429 AppendData(kSourceId, buffer->data(), buffer->data_size());
3411 3430
3412 // Confirm we're in the middle of parsing a media segment. 3431 // Confirm we're in the middle of parsing a media segment.
3413 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); 3432 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId));
3414 3433
3415 // ResetParserState on the Mpeg2 TS parser triggers the emission of the last 3434 // ResetParserState on the Mpeg2 TS parser triggers the emission of the last
3416 // video buffer which is pending in the stream parser. 3435 // video buffer which is pending in the stream parser.
3417 Ranges<base::TimeDelta> range_before_abort = 3436 Ranges<base::TimeDelta> range_before_abort =
3418 demuxer_->GetBufferedRanges(kSourceId); 3437 demuxer_->GetBufferedRanges(kSourceId);
3419 demuxer_->ResetParserState(kSourceId, 3438 demuxer_->ResetParserState(kSourceId,
(...skipping 27 matching lines...) Expand all
3447 // Audio: first PES: 3466 // Audio: first PES:
3448 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000] 3467 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000]
3449 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767] 3468 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767]
3450 // Video: last PES: 3469 // Video: last PES:
3451 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128] 3470 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128]
3452 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794] 3471 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794]
3453 // Audio: last PES: 3472 // Audio: last PES:
3454 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309] 3473 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309]
3455 3474
3456 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts"); 3475 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts");
3457 EXPECT_CALL(*this, InitSegmentReceived()); 3476 EXPECT_CALL(*this, InitSegmentReceived(_));
3458 AppendData(kSourceId, buffer->data(), buffer->data_size()); 3477 AppendData(kSourceId, buffer->data(), buffer->data_size());
3459 3478
3460 // Confirm we're in the middle of parsing a media segment. 3479 // Confirm we're in the middle of parsing a media segment.
3461 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); 3480 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId));
3462 3481
3463 // Seek to a time corresponding to buffers that will be emitted during the 3482 // Seek to a time corresponding to buffers that will be emitted during the
3464 // abort. 3483 // abort.
3465 Seek(base::TimeDelta::FromMilliseconds(4110)); 3484 Seek(base::TimeDelta::FromMilliseconds(4110));
3466 3485
3467 // ResetParserState on the Mpeg2 TS parser triggers the emission of the last 3486 // ResetParserState on the Mpeg2 TS parser triggers the emission of the last
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
4058 // Set the append window to [50,150). 4077 // Set the append window to [50,150).
4059 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); 4078 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50);
4060 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(150); 4079 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(150);
4061 4080
4062 // Read a WebM file into memory and send the data to the demuxer. The chunk 4081 // Read a WebM file into memory and send the data to the demuxer. The chunk
4063 // size has been chosen carefully to ensure the preroll buffer used by the 4082 // size has been chosen carefully to ensure the preroll buffer used by the
4064 // partial append window trim must come from a previous Append() call. 4083 // partial append window trim must come from a previous Append() call.
4065 scoped_refptr<DecoderBuffer> buffer = 4084 scoped_refptr<DecoderBuffer> buffer =
4066 ReadTestDataFile("bear-320x240-audio-only.webm"); 4085 ReadTestDataFile("bear-320x240-audio-only.webm");
4067 ExpectInitMediaLogs(HAS_AUDIO); 4086 ExpectInitMediaLogs(HAS_AUDIO);
4068 EXPECT_CALL(*this, InitSegmentReceived()); 4087 EXPECT_CALL(*this, InitSegmentReceived(_));
4069 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)); 4088 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2));
4070 AppendDataInPieces(buffer->data(), buffer->data_size(), 128); 4089 AppendDataInPieces(buffer->data(), buffer->data_size(), 128);
4071 4090
4072 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 4091 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
4073 CheckExpectedBuffers(stream, "50KP 50K 62K 86K 109K 122K 125K 128K"); 4092 CheckExpectedBuffers(stream, "50KP 50K 62K 86K 109K 122K 125K 128K");
4074 } 4093 }
4075 4094
4076 TEST_F(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) { 4095 TEST_F(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) {
4077 EXPECT_CALL(*this, DemuxerOpened()); 4096 EXPECT_CALL(*this, DemuxerOpened());
4078 demuxer_->Initialize( 4097 demuxer_->Initialize(
4079 &host_, 4098 &host_,
4080 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), 4099 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK),
4081 true); 4100 true);
4082 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); 4101 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO));
4083 4102
4084 // Set the append window such that the first file is completely before the 4103 // Set the append window such that the first file is completely before the
4085 // append window. 4104 // append window.
4086 // Expect duration adjustment since actual duration differs slightly from 4105 // Expect duration adjustment since actual duration differs slightly from
4087 // duration in the init segment. 4106 // duration in the init segment.
4088 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746); 4107 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746);
4089 append_window_start_for_next_append_ = duration_1; 4108 append_window_start_for_next_append_ = duration_1;
4090 4109
4091 // Read a WebM file into memory and append the data. 4110 // Read a WebM file into memory and append the data.
4092 scoped_refptr<DecoderBuffer> buffer = 4111 scoped_refptr<DecoderBuffer> buffer =
4093 ReadTestDataFile("bear-320x240-audio-only.webm"); 4112 ReadTestDataFile("bear-320x240-audio-only.webm");
4094 ExpectInitMediaLogs(HAS_AUDIO); 4113 ExpectInitMediaLogs(HAS_AUDIO);
4095 EXPECT_CALL(*this, InitSegmentReceived()); 4114 EXPECT_CALL(*this, InitSegmentReceived(_));
4096 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)); 4115 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2));
4097 AppendDataInPieces(buffer->data(), buffer->data_size(), 512); 4116 AppendDataInPieces(buffer->data(), buffer->data_size(), 512);
4098 CheckExpectedRanges("{ }"); 4117 CheckExpectedRanges("{ }");
4099 4118
4100 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); 4119 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
4101 AudioDecoderConfig config_1 = stream->audio_decoder_config(); 4120 AudioDecoderConfig config_1 = stream->audio_decoder_config();
4102 4121
4103 // Read a second WebM with a different config in and append the data. 4122 // Read a second WebM with a different config in and append the data.
4104 scoped_refptr<DecoderBuffer> buffer2 = 4123 scoped_refptr<DecoderBuffer> buffer2 =
4105 ReadTestDataFile("bear-320x240-audio-only-48khz.webm"); 4124 ReadTestDataFile("bear-320x240-audio-only-48khz.webm");
4106 EXPECT_CALL(*this, InitSegmentReceived()); 4125 EXPECT_CALL(*this, InitSegmentReceived(_));
4107 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(21)); 4126 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(21));
4108 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber()); 4127 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber());
4109 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1)); 4128 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1));
4110 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512); 4129 AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512);
4111 CheckExpectedRanges("{ [2746,5519) }"); 4130 CheckExpectedRanges("{ [2746,5519) }");
4112 4131
4113 Seek(duration_1); 4132 Seek(duration_1);
4114 ExpectConfigChanged(DemuxerStream::AUDIO); 4133 ExpectConfigChanged(DemuxerStream::AUDIO);
4115 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config())); 4134 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config()));
4116 CheckExpectedBuffers(stream, "2746K 2767K 2789K 2810K"); 4135 CheckExpectedBuffers(stream, "2746K 2767K 2789K 2810K");
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
4607 cluster->size() - video_start); 4626 cluster->size() - video_start);
4608 4627
4609 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }"); 4628 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }");
4610 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,91) }"); 4629 CheckExpectedRanges(DemuxerStream::VIDEO, "{ [0,91) }");
4611 CheckExpectedRanges("{ [30,90) }"); 4630 CheckExpectedRanges("{ [30,90) }");
4612 CheckExpectedBuffers(audio_stream, "30K 40K 50K 60K 70K 80K"); 4631 CheckExpectedBuffers(audio_stream, "30K 40K 50K 60K 70K 80K");
4613 CheckExpectedBuffers(video_stream, "71K 81"); 4632 CheckExpectedBuffers(video_stream, "71K 81");
4614 } 4633 }
4615 4634
4616 } // namespace media 4635 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/chunk_demuxer.cc ('k') | media/filters/ffmpeg_demuxer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698