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 "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> |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1003 kWebMFlagKeyframe); | 1003 kWebMFlagKeyframe); |
1004 } else { | 1004 } else { |
1005 cb.AddBlockGroup(track_number, timecode, block_duration, | 1005 cb.AddBlockGroup(track_number, timecode, block_duration, |
1006 kWebMFlagKeyframe, static_cast<bool>(kWebMFlagKeyframe), | 1006 kWebMFlagKeyframe, static_cast<bool>(kWebMFlagKeyframe), |
1007 &data[0], data.size()); | 1007 &data[0], data.size()); |
1008 } | 1008 } |
1009 | 1009 |
1010 return cb.Finish(); | 1010 return cb.Finish(); |
1011 } | 1011 } |
1012 | 1012 |
1013 DemuxerStream* GetStream(DemuxerStream::Type type) { | |
xhwang
2017/02/01 18:26:04
ditto about TODO
Do we have tests for multiple st
servolk
2017/02/01 22:29:17
In this CL I have modified a FFmpegDemuxerTest::In
| |
1014 std::vector<DemuxerStream*> streams = demuxer_->GetStreams(); | |
1015 for (const auto& s : streams) { | |
1016 if (s->type() == type) | |
1017 return s; | |
1018 } | |
1019 return nullptr; | |
1020 } | |
1021 | |
1013 void Read(DemuxerStream::Type type, const DemuxerStream::ReadCB& read_cb) { | 1022 void Read(DemuxerStream::Type type, const DemuxerStream::ReadCB& read_cb) { |
1014 demuxer_->GetStream(type)->Read(read_cb); | 1023 GetStream(type)->Read(read_cb); |
1015 base::RunLoop().RunUntilIdle(); | 1024 base::RunLoop().RunUntilIdle(); |
1016 } | 1025 } |
1017 | 1026 |
1018 void ReadAudio(const DemuxerStream::ReadCB& read_cb) { | 1027 void ReadAudio(const DemuxerStream::ReadCB& read_cb) { |
1019 Read(DemuxerStream::AUDIO, read_cb); | 1028 Read(DemuxerStream::AUDIO, read_cb); |
1020 } | 1029 } |
1021 | 1030 |
1022 void ReadVideo(const DemuxerStream::ReadCB& read_cb) { | 1031 void ReadVideo(const DemuxerStream::ReadCB& read_cb) { |
1023 Read(DemuxerStream::VIDEO, read_cb); | 1032 Read(DemuxerStream::VIDEO, read_cb); |
1024 } | 1033 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1090 CheckExpectedRangesForMediaSource(expected); | 1099 CheckExpectedRangesForMediaSource(expected); |
1091 } | 1100 } |
1092 | 1101 |
1093 void CheckExpectedRanges(const std::string& id, const std::string& expected) { | 1102 void CheckExpectedRanges(const std::string& id, const std::string& expected) { |
1094 CheckExpectedRanges(demuxer_->GetBufferedRanges(id), expected); | 1103 CheckExpectedRanges(demuxer_->GetBufferedRanges(id), expected); |
1095 } | 1104 } |
1096 | 1105 |
1097 void CheckExpectedRanges(DemuxerStream::Type type, | 1106 void CheckExpectedRanges(DemuxerStream::Type type, |
1098 const std::string& expected) { | 1107 const std::string& expected) { |
1099 ChunkDemuxerStream* stream = | 1108 ChunkDemuxerStream* stream = |
1100 static_cast<ChunkDemuxerStream*>(demuxer_->GetStream(type)); | 1109 static_cast<ChunkDemuxerStream*>(GetStream(type)); |
1101 CheckExpectedRanges(stream->GetBufferedRanges(kDefaultDuration()), | 1110 CheckExpectedRanges(stream->GetBufferedRanges(kDefaultDuration()), |
1102 expected); | 1111 expected); |
1103 } | 1112 } |
1104 | 1113 |
1105 void CheckExpectedRanges(const Ranges<base::TimeDelta>& r, | 1114 void CheckExpectedRanges(const Ranges<base::TimeDelta>& r, |
1106 const std::string& expected) { | 1115 const std::string& expected) { |
1107 std::stringstream ss; | 1116 std::stringstream ss; |
1108 ss << "{ "; | 1117 ss << "{ "; |
1109 for (size_t i = 0; i < r.size(); ++i) { | 1118 for (size_t i = 0; i < r.size(); ++i) { |
1110 ss << "[" << r.start(i).InMilliseconds() << "," | 1119 ss << "[" << r.start(i).InMilliseconds() << "," |
(...skipping 10 matching lines...) Expand all Loading... | |
1121 scoped_refptr<DecoderBuffer>* buffer_out, | 1130 scoped_refptr<DecoderBuffer>* buffer_out, |
1122 DemuxerStream::Status status, | 1131 DemuxerStream::Status status, |
1123 const scoped_refptr<DecoderBuffer>& buffer) { | 1132 const scoped_refptr<DecoderBuffer>& buffer) { |
1124 *status_out = status; | 1133 *status_out = status; |
1125 *buffer_out = buffer; | 1134 *buffer_out = buffer; |
1126 } | 1135 } |
1127 | 1136 |
1128 void ReadUntilNotOkOrEndOfStream(DemuxerStream::Type type, | 1137 void ReadUntilNotOkOrEndOfStream(DemuxerStream::Type type, |
1129 DemuxerStream::Status* status, | 1138 DemuxerStream::Status* status, |
1130 base::TimeDelta* last_timestamp) { | 1139 base::TimeDelta* last_timestamp) { |
1131 DemuxerStream* stream = demuxer_->GetStream(type); | 1140 DemuxerStream* stream = GetStream(type); |
1132 scoped_refptr<DecoderBuffer> buffer; | 1141 scoped_refptr<DecoderBuffer> buffer; |
1133 | 1142 |
1134 *last_timestamp = kNoTimestamp; | 1143 *last_timestamp = kNoTimestamp; |
1135 do { | 1144 do { |
1136 stream->Read(base::Bind(&ChunkDemuxerTest::StoreStatusAndBuffer, | 1145 stream->Read(base::Bind(&ChunkDemuxerTest::StoreStatusAndBuffer, |
1137 base::Unretained(this), status, &buffer)); | 1146 base::Unretained(this), status, &buffer)); |
1138 base::RunLoop().RunUntilIdle(); | 1147 base::RunLoop().RunUntilIdle(); |
1139 if (*status == DemuxerStream::kOk && !buffer->end_of_stream()) | 1148 if (*status == DemuxerStream::kOk && !buffer->end_of_stream()) |
1140 *last_timestamp = buffer->timestamp(); | 1149 *last_timestamp = buffer->timestamp(); |
1141 } while (*status == DemuxerStream::kOk && !buffer->end_of_stream()); | 1150 } while (*status == DemuxerStream::kOk && !buffer->end_of_stream()); |
1142 } | 1151 } |
1143 | 1152 |
1144 void ExpectEndOfStream(DemuxerStream::Type type) { | 1153 void ExpectEndOfStream(DemuxerStream::Type type) { |
1145 EXPECT_CALL(*this, ReadDone(DemuxerStream::kOk, IsEndOfStream())); | 1154 EXPECT_CALL(*this, ReadDone(DemuxerStream::kOk, IsEndOfStream())); |
1146 demuxer_->GetStream(type)->Read(base::Bind( | 1155 GetStream(type)->Read( |
1147 &ChunkDemuxerTest::ReadDone, base::Unretained(this))); | 1156 base::Bind(&ChunkDemuxerTest::ReadDone, base::Unretained(this))); |
1148 base::RunLoop().RunUntilIdle(); | 1157 base::RunLoop().RunUntilIdle(); |
1149 } | 1158 } |
1150 | 1159 |
1151 void ExpectRead(DemuxerStream::Type type, int64_t timestamp_in_ms) { | 1160 void ExpectRead(DemuxerStream::Type type, int64_t timestamp_in_ms) { |
1152 EXPECT_CALL(*this, ReadDone(DemuxerStream::kOk, | 1161 EXPECT_CALL(*this, ReadDone(DemuxerStream::kOk, |
1153 HasTimestamp(timestamp_in_ms))); | 1162 HasTimestamp(timestamp_in_ms))); |
1154 demuxer_->GetStream(type)->Read(base::Bind( | 1163 GetStream(type)->Read( |
1155 &ChunkDemuxerTest::ReadDone, base::Unretained(this))); | 1164 base::Bind(&ChunkDemuxerTest::ReadDone, base::Unretained(this))); |
1156 base::RunLoop().RunUntilIdle(); | 1165 base::RunLoop().RunUntilIdle(); |
1157 } | 1166 } |
1158 | 1167 |
1159 void ExpectConfigChanged(DemuxerStream::Type type) { | 1168 void ExpectConfigChanged(DemuxerStream::Type type) { |
1160 EXPECT_CALL(*this, ReadDone(DemuxerStream::kConfigChanged, _)); | 1169 EXPECT_CALL(*this, ReadDone(DemuxerStream::kConfigChanged, _)); |
1161 demuxer_->GetStream(type)->Read(base::Bind( | 1170 GetStream(type)->Read( |
1162 &ChunkDemuxerTest::ReadDone, base::Unretained(this))); | 1171 base::Bind(&ChunkDemuxerTest::ReadDone, base::Unretained(this))); |
1163 base::RunLoop().RunUntilIdle(); | 1172 base::RunLoop().RunUntilIdle(); |
1164 } | 1173 } |
1165 | 1174 |
1166 void CheckExpectedBuffers(DemuxerStream* stream, | 1175 void CheckExpectedBuffers(DemuxerStream* stream, |
1167 const std::string& expected) { | 1176 const std::string& expected) { |
1168 std::vector<std::string> timestamps = base::SplitString( | 1177 std::vector<std::string> timestamps = base::SplitString( |
1169 expected, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 1178 expected, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
1170 std::stringstream ss; | 1179 std::stringstream ss; |
1171 for (size_t i = 0; i < timestamps.size(); ++i) { | 1180 for (size_t i = 0; i < timestamps.size(); ++i) { |
1172 // Initialize status to kAborted since it's possible for Read() to return | 1181 // Initialize status to kAborted since it's possible for Read() to return |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1350 stream_flags |= HAS_VIDEO; | 1359 stream_flags |= HAS_VIDEO; |
1351 | 1360 |
1352 if (has_audio || has_video) { | 1361 if (has_audio || has_video) { |
1353 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( | 1362 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( |
1354 stream_flags, is_audio_encrypted, is_video_encrypted)); | 1363 stream_flags, is_audio_encrypted, is_video_encrypted)); |
1355 } else { | 1364 } else { |
1356 ASSERT_FALSE(InitDemuxerWithEncryptionInfo( | 1365 ASSERT_FALSE(InitDemuxerWithEncryptionInfo( |
1357 stream_flags, is_audio_encrypted, is_video_encrypted)); | 1366 stream_flags, is_audio_encrypted, is_video_encrypted)); |
1358 } | 1367 } |
1359 | 1368 |
1360 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1369 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
1361 if (has_audio) { | 1370 if (has_audio) { |
1362 ASSERT_TRUE(audio_stream); | 1371 ASSERT_TRUE(audio_stream); |
1363 | 1372 |
1364 const AudioDecoderConfig& config = audio_stream->audio_decoder_config(); | 1373 const AudioDecoderConfig& config = audio_stream->audio_decoder_config(); |
1365 EXPECT_EQ(kCodecVorbis, config.codec()); | 1374 EXPECT_EQ(kCodecVorbis, config.codec()); |
1366 EXPECT_EQ(32, config.bits_per_channel()); | 1375 EXPECT_EQ(32, config.bits_per_channel()); |
1367 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, config.channel_layout()); | 1376 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, config.channel_layout()); |
1368 EXPECT_EQ(44100, config.samples_per_second()); | 1377 EXPECT_EQ(44100, config.samples_per_second()); |
1369 EXPECT_GT(config.extra_data().size(), 0u); | 1378 EXPECT_GT(config.extra_data().size(), 0u); |
1370 EXPECT_EQ(kSampleFormatPlanarF32, config.sample_format()); | 1379 EXPECT_EQ(kSampleFormatPlanarF32, config.sample_format()); |
1371 EXPECT_EQ(is_audio_encrypted, | 1380 EXPECT_EQ(is_audio_encrypted, |
1372 audio_stream->audio_decoder_config().is_encrypted()); | 1381 audio_stream->audio_decoder_config().is_encrypted()); |
1373 EXPECT_TRUE(static_cast<ChunkDemuxerStream*>(audio_stream) | 1382 EXPECT_TRUE(static_cast<ChunkDemuxerStream*>(audio_stream) |
1374 ->supports_partial_append_window_trimming()); | 1383 ->supports_partial_append_window_trimming()); |
1375 } else { | 1384 } else { |
1376 EXPECT_FALSE(audio_stream); | 1385 EXPECT_FALSE(audio_stream); |
1377 } | 1386 } |
1378 | 1387 |
1379 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1388 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
1380 if (has_video) { | 1389 if (has_video) { |
1381 EXPECT_TRUE(video_stream); | 1390 EXPECT_TRUE(video_stream); |
1382 EXPECT_EQ(is_video_encrypted, | 1391 EXPECT_EQ(is_video_encrypted, |
1383 video_stream->video_decoder_config().is_encrypted()); | 1392 video_stream->video_decoder_config().is_encrypted()); |
1384 EXPECT_FALSE(static_cast<ChunkDemuxerStream*>(video_stream) | 1393 EXPECT_FALSE(static_cast<ChunkDemuxerStream*>(video_stream) |
1385 ->supports_partial_append_window_trimming()); | 1394 ->supports_partial_append_window_trimming()); |
1386 } else { | 1395 } else { |
1387 EXPECT_FALSE(video_stream); | 1396 EXPECT_FALSE(video_stream); |
1388 } | 1397 } |
1389 | 1398 |
(...skipping 29 matching lines...) Expand all Loading... | |
1419 stream_flags |= HAS_VIDEO; | 1428 stream_flags |= HAS_VIDEO; |
1420 | 1429 |
1421 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( | 1430 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( |
1422 stream_flags, is_audio_encrypted, is_video_encrypted)); | 1431 stream_flags, is_audio_encrypted, is_video_encrypted)); |
1423 ASSERT_TRUE(text_stream); | 1432 ASSERT_TRUE(text_stream); |
1424 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type()); | 1433 EXPECT_EQ(DemuxerStream::TEXT, text_stream->type()); |
1425 EXPECT_EQ(kTextSubtitles, text_config.kind()); | 1434 EXPECT_EQ(kTextSubtitles, text_config.kind()); |
1426 EXPECT_FALSE(static_cast<ChunkDemuxerStream*>(text_stream) | 1435 EXPECT_FALSE(static_cast<ChunkDemuxerStream*>(text_stream) |
1427 ->supports_partial_append_window_trimming()); | 1436 ->supports_partial_append_window_trimming()); |
1428 | 1437 |
1429 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1438 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
1430 if (has_audio) { | 1439 if (has_audio) { |
1431 ASSERT_TRUE(audio_stream); | 1440 ASSERT_TRUE(audio_stream); |
1432 | 1441 |
1433 const AudioDecoderConfig& config = audio_stream->audio_decoder_config(); | 1442 const AudioDecoderConfig& config = audio_stream->audio_decoder_config(); |
1434 EXPECT_EQ(kCodecVorbis, config.codec()); | 1443 EXPECT_EQ(kCodecVorbis, config.codec()); |
1435 EXPECT_EQ(32, config.bits_per_channel()); | 1444 EXPECT_EQ(32, config.bits_per_channel()); |
1436 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, config.channel_layout()); | 1445 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, config.channel_layout()); |
1437 EXPECT_EQ(44100, config.samples_per_second()); | 1446 EXPECT_EQ(44100, config.samples_per_second()); |
1438 EXPECT_GT(config.extra_data().size(), 0u); | 1447 EXPECT_GT(config.extra_data().size(), 0u); |
1439 EXPECT_EQ(kSampleFormatPlanarF32, config.sample_format()); | 1448 EXPECT_EQ(kSampleFormatPlanarF32, config.sample_format()); |
1440 EXPECT_EQ(is_audio_encrypted, | 1449 EXPECT_EQ(is_audio_encrypted, |
1441 audio_stream->audio_decoder_config().is_encrypted()); | 1450 audio_stream->audio_decoder_config().is_encrypted()); |
1442 EXPECT_TRUE(static_cast<ChunkDemuxerStream*>(audio_stream) | 1451 EXPECT_TRUE(static_cast<ChunkDemuxerStream*>(audio_stream) |
1443 ->supports_partial_append_window_trimming()); | 1452 ->supports_partial_append_window_trimming()); |
1444 } else { | 1453 } else { |
1445 EXPECT_FALSE(audio_stream); | 1454 EXPECT_FALSE(audio_stream); |
1446 } | 1455 } |
1447 | 1456 |
1448 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1457 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
1449 if (has_video) { | 1458 if (has_video) { |
1450 EXPECT_TRUE(video_stream); | 1459 EXPECT_TRUE(video_stream); |
1451 EXPECT_EQ(is_video_encrypted, | 1460 EXPECT_EQ(is_video_encrypted, |
1452 video_stream->video_decoder_config().is_encrypted()); | 1461 video_stream->video_decoder_config().is_encrypted()); |
1453 EXPECT_FALSE(static_cast<ChunkDemuxerStream*>(video_stream) | 1462 EXPECT_FALSE(static_cast<ChunkDemuxerStream*>(video_stream) |
1454 ->supports_partial_append_window_trimming()); | 1463 ->supports_partial_append_window_trimming()); |
1455 } else { | 1464 } else { |
1456 EXPECT_FALSE(video_stream); | 1465 EXPECT_FALSE(video_stream); |
1457 } | 1466 } |
1458 | 1467 |
1459 ShutdownDemuxer(); | 1468 ShutdownDemuxer(); |
1460 demuxer_.reset(); | 1469 demuxer_.reset(); |
1461 } | 1470 } |
1462 } | 1471 } |
1463 | 1472 |
1464 TEST_F(ChunkDemuxerTest, SingleTextTrackIdChange) { | 1473 TEST_F(ChunkDemuxerTest, SingleTextTrackIdChange) { |
1465 // Test with 1 video stream, 1 audio, and 1 text stream. Send a second init | 1474 // Test with 1 video stream, 1 audio, and 1 text stream. Send a second init |
1466 // segment in which the text track ID changes. Verify appended buffers before | 1475 // segment in which the text track ID changes. Verify appended buffers before |
1467 // and after the second init segment map to the same underlying track buffers. | 1476 // and after the second init segment map to the same underlying track buffers. |
1468 CreateNewDemuxer(); | 1477 CreateNewDemuxer(); |
1469 DemuxerStream* text_stream = NULL; | 1478 DemuxerStream* text_stream = NULL; |
1470 TextTrackConfig text_config; | 1479 TextTrackConfig text_config; |
1471 EXPECT_CALL(host_, AddTextStream(_, _)) | 1480 EXPECT_CALL(host_, AddTextStream(_, _)) |
1472 .WillOnce(DoAll(SaveArg<0>(&text_stream), | 1481 .WillOnce(DoAll(SaveArg<0>(&text_stream), |
1473 SaveArg<1>(&text_config))); | 1482 SaveArg<1>(&text_config))); |
1474 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( | 1483 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( |
1475 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); | 1484 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); |
1476 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1485 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
1477 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1486 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
1478 ASSERT_TRUE(audio_stream); | 1487 ASSERT_TRUE(audio_stream); |
1479 ASSERT_TRUE(video_stream); | 1488 ASSERT_TRUE(video_stream); |
1480 ASSERT_TRUE(text_stream); | 1489 ASSERT_TRUE(text_stream); |
1481 | 1490 |
1482 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), | 1491 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), |
1483 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30), | 1492 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30), |
1484 MuxedStreamInfo(kTextTrackNum, "10K")); | 1493 MuxedStreamInfo(kTextTrackNum, "10K")); |
1485 CheckExpectedRanges("{ [0,46) }"); | 1494 CheckExpectedRanges("{ [0,46) }"); |
1486 | 1495 |
1487 std::unique_ptr<uint8_t[]> info_tracks; | 1496 std::unique_ptr<uint8_t[]> info_tracks; |
(...skipping 21 matching lines...) Expand all Loading... | |
1509 ShutdownDemuxer(); | 1518 ShutdownDemuxer(); |
1510 } | 1519 } |
1511 | 1520 |
1512 TEST_F(ChunkDemuxerTest, AudioVideoTrackIdsChange) { | 1521 TEST_F(ChunkDemuxerTest, AudioVideoTrackIdsChange) { |
1513 // Test with 1 audio and 1 video stream. Send a second init segment in which | 1522 // Test with 1 audio and 1 video stream. Send a second init segment in which |
1514 // the audio and video track IDs change. Verify that appended buffers before | 1523 // the audio and video track IDs change. Verify that appended buffers before |
1515 // and after the second init segment map to the same underlying track buffers. | 1524 // and after the second init segment map to the same underlying track buffers. |
1516 CreateNewDemuxer(); | 1525 CreateNewDemuxer(); |
1517 ASSERT_TRUE( | 1526 ASSERT_TRUE( |
1518 InitDemuxerWithEncryptionInfo(HAS_AUDIO | HAS_VIDEO, false, false)); | 1527 InitDemuxerWithEncryptionInfo(HAS_AUDIO | HAS_VIDEO, false, false)); |
1519 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1528 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
1520 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1529 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
1521 ASSERT_TRUE(audio_stream); | 1530 ASSERT_TRUE(audio_stream); |
1522 ASSERT_TRUE(video_stream); | 1531 ASSERT_TRUE(video_stream); |
1523 | 1532 |
1524 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), | 1533 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 23K", 23), |
1525 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30)); | 1534 MuxedStreamInfo(kVideoTrackNum, "0K 30", 30)); |
1526 CheckExpectedRanges("{ [0,46) }"); | 1535 CheckExpectedRanges("{ [0,46) }"); |
1527 | 1536 |
1528 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); | 1537 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); |
1529 ASSERT_TRUE(AppendInitSegment(HAS_AUDIO | HAS_VIDEO | | 1538 ASSERT_TRUE(AppendInitSegment(HAS_AUDIO | HAS_VIDEO | |
1530 USE_ALTERNATE_AUDIO_TRACK_ID | | 1539 USE_ALTERNATE_AUDIO_TRACK_ID | |
(...skipping 13 matching lines...) Expand all Loading... | |
1544 // algorithm correctly sets the needs random access point flag to true for all | 1553 // algorithm correctly sets the needs random access point flag to true for all |
1545 // track buffers. Note that the first initialization segment is insufficient | 1554 // track buffers. Note that the first initialization segment is insufficient |
1546 // to fully test this since needs random access point flag initializes to | 1555 // to fully test this since needs random access point flag initializes to |
1547 // true. | 1556 // true. |
1548 CreateNewDemuxer(); | 1557 CreateNewDemuxer(); |
1549 DemuxerStream* text_stream = NULL; | 1558 DemuxerStream* text_stream = NULL; |
1550 EXPECT_CALL(host_, AddTextStream(_, _)) | 1559 EXPECT_CALL(host_, AddTextStream(_, _)) |
1551 .WillOnce(SaveArg<0>(&text_stream)); | 1560 .WillOnce(SaveArg<0>(&text_stream)); |
1552 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( | 1561 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( |
1553 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); | 1562 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); |
1554 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1563 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
1555 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1564 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
1556 ASSERT_TRUE(audio_stream && video_stream && text_stream); | 1565 ASSERT_TRUE(audio_stream && video_stream && text_stream); |
1557 | 1566 |
1558 AppendMuxedCluster( | 1567 AppendMuxedCluster( |
1559 MuxedStreamInfo(kAudioTrackNum, "23K", | 1568 MuxedStreamInfo(kAudioTrackNum, "23K", |
1560 WebMClusterParser::kDefaultAudioBufferDurationInMs), | 1569 WebMClusterParser::kDefaultAudioBufferDurationInMs), |
1561 MuxedStreamInfo(kVideoTrackNum, "0 30K", 30), | 1570 MuxedStreamInfo(kVideoTrackNum, "0 30K", 30), |
1562 MuxedStreamInfo(kTextTrackNum, "25K 40K")); | 1571 MuxedStreamInfo(kTextTrackNum, "25K 40K")); |
1563 CheckExpectedRanges("{ [23,46) }"); | 1572 CheckExpectedRanges("{ [23,46) }"); |
1564 | 1573 |
1565 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); | 1574 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1611 } | 1620 } |
1612 | 1621 |
1613 // Verifies that all streams waiting for data receive an end of stream | 1622 // Verifies that all streams waiting for data receive an end of stream |
1614 // buffer when Shutdown() is called. | 1623 // buffer when Shutdown() is called. |
1615 TEST_F(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) { | 1624 TEST_F(ChunkDemuxerTest, Shutdown_EndOfStreamWhileWaitingForData) { |
1616 DemuxerStream* text_stream = NULL; | 1625 DemuxerStream* text_stream = NULL; |
1617 EXPECT_CALL(host_, AddTextStream(_, _)) | 1626 EXPECT_CALL(host_, AddTextStream(_, _)) |
1618 .WillOnce(SaveArg<0>(&text_stream)); | 1627 .WillOnce(SaveArg<0>(&text_stream)); |
1619 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 1628 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
1620 | 1629 |
1621 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1630 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
1622 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1631 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
1623 | 1632 |
1624 bool audio_read_done = false; | 1633 bool audio_read_done = false; |
1625 bool video_read_done = false; | 1634 bool video_read_done = false; |
1626 bool text_read_done = false; | 1635 bool text_read_done = false; |
1627 audio_stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); | 1636 audio_stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); |
1628 video_stream->Read(base::Bind(&OnReadDone_EOSExpected, &video_read_done)); | 1637 video_stream->Read(base::Bind(&OnReadDone_EOSExpected, &video_read_done)); |
1629 text_stream->Read(base::Bind(&OnReadDone_EOSExpected, &text_read_done)); | 1638 text_stream->Read(base::Bind(&OnReadDone_EOSExpected, &text_read_done)); |
1630 base::RunLoop().RunUntilIdle(); | 1639 base::RunLoop().RunUntilIdle(); |
1631 | 1640 |
1632 EXPECT_FALSE(audio_read_done); | 1641 EXPECT_FALSE(audio_read_done); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1732 ReadVideo(base::Bind(&OnReadDone, | 1741 ReadVideo(base::Bind(&OnReadDone, |
1733 base::TimeDelta::FromMilliseconds(0), | 1742 base::TimeDelta::FromMilliseconds(0), |
1734 &video_read_done)); | 1743 &video_read_done)); |
1735 | 1744 |
1736 EXPECT_TRUE(audio_read_done); | 1745 EXPECT_TRUE(audio_read_done); |
1737 EXPECT_TRUE(video_read_done); | 1746 EXPECT_TRUE(video_read_done); |
1738 } | 1747 } |
1739 | 1748 |
1740 TEST_F(ChunkDemuxerTest, OutOfOrderClusters) { | 1749 TEST_F(ChunkDemuxerTest, OutOfOrderClusters) { |
1741 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1750 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
1742 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1751 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
1743 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1752 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
1744 | 1753 |
1745 ASSERT_TRUE(AppendCluster(kDefaultFirstCluster())); | 1754 ASSERT_TRUE(AppendCluster(kDefaultFirstCluster())); |
1746 CheckExpectedBuffers(audio_stream, "0K 23K"); | 1755 CheckExpectedBuffers(audio_stream, "0K 23K"); |
1747 CheckExpectedBuffers(video_stream, "0K 33"); | 1756 CheckExpectedBuffers(video_stream, "0K 33"); |
1748 // Note: splice trimming changes durations. These are verified in lower level | 1757 // Note: splice trimming changes durations. These are verified in lower level |
1749 // tests. See SourceBufferStreamTest.Audio_SpliceTrimmingForOverlap. | 1758 // tests. See SourceBufferStreamTest.Audio_SpliceTrimmingForOverlap. |
1750 EXPECT_MEDIA_LOG(TrimmedSpliceOverlap(10000, 0, 13000)); | 1759 EXPECT_MEDIA_LOG(TrimmedSpliceOverlap(10000, 0, 13000)); |
1751 ASSERT_TRUE(AppendCluster(GenerateCluster(10, 4))); | 1760 ASSERT_TRUE(AppendCluster(GenerateCluster(10, 4))); |
1752 Seek(base::TimeDelta()); | 1761 Seek(base::TimeDelta()); |
1753 CheckExpectedBuffers(audio_stream, "0K 10K 33K"); | 1762 CheckExpectedBuffers(audio_stream, "0K 10K 33K"); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1913 | 1922 |
1914 EXPECT_CALL(host_, | 1923 EXPECT_CALL(host_, |
1915 OnDemuxerError(CHUNK_DEMUXER_ERROR_EOS_STATUS_NETWORK_ERROR)); | 1924 OnDemuxerError(CHUNK_DEMUXER_ERROR_EOS_STATUS_NETWORK_ERROR)); |
1916 MarkEndOfStream(CHUNK_DEMUXER_ERROR_EOS_STATUS_NETWORK_ERROR); | 1925 MarkEndOfStream(CHUNK_DEMUXER_ERROR_EOS_STATUS_NETWORK_ERROR); |
1917 } | 1926 } |
1918 | 1927 |
1919 // Helper class to reduce duplicate code when testing end of stream | 1928 // Helper class to reduce duplicate code when testing end of stream |
1920 // Read() behavior. | 1929 // Read() behavior. |
1921 class EndOfStreamHelper { | 1930 class EndOfStreamHelper { |
1922 public: | 1931 public: |
1923 explicit EndOfStreamHelper(Demuxer* demuxer) | 1932 explicit EndOfStreamHelper(DemuxerStream* audio, DemuxerStream* video) |
1924 : demuxer_(demuxer), | 1933 : audio_stream_(audio), |
1934 video_stream_(video), | |
1925 audio_read_done_(false), | 1935 audio_read_done_(false), |
1926 video_read_done_(false) { | 1936 video_read_done_(false) {} |
1927 } | |
1928 | 1937 |
1929 // Request a read on the audio and video streams. | 1938 // Request a read on the audio and video streams. |
1930 void RequestReads() { | 1939 void RequestReads() { |
1931 EXPECT_FALSE(audio_read_done_); | 1940 EXPECT_FALSE(audio_read_done_); |
1932 EXPECT_FALSE(video_read_done_); | 1941 EXPECT_FALSE(video_read_done_); |
1933 | 1942 |
1934 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 1943 audio_stream_->Read(base::Bind(&OnEndOfStreamReadDone, &audio_read_done_)); |
1935 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 1944 video_stream_->Read(base::Bind(&OnEndOfStreamReadDone, &video_read_done_)); |
1936 | |
1937 audio->Read(base::Bind(&OnEndOfStreamReadDone, &audio_read_done_)); | |
1938 video->Read(base::Bind(&OnEndOfStreamReadDone, &video_read_done_)); | |
1939 base::RunLoop().RunUntilIdle(); | 1945 base::RunLoop().RunUntilIdle(); |
1940 } | 1946 } |
1941 | 1947 |
1942 // Check to see if |audio_read_done_| and |video_read_done_| variables | 1948 // Check to see if |audio_read_done_| and |video_read_done_| variables |
1943 // match |expected|. | 1949 // match |expected|. |
1944 void CheckIfReadDonesWereCalled(bool expected) { | 1950 void CheckIfReadDonesWereCalled(bool expected) { |
1945 base::RunLoop().RunUntilIdle(); | 1951 base::RunLoop().RunUntilIdle(); |
1946 EXPECT_EQ(expected, audio_read_done_); | 1952 EXPECT_EQ(expected, audio_read_done_); |
1947 EXPECT_EQ(expected, video_read_done_); | 1953 EXPECT_EQ(expected, video_read_done_); |
1948 } | 1954 } |
1949 | 1955 |
1950 private: | 1956 private: |
1951 static void OnEndOfStreamReadDone( | 1957 static void OnEndOfStreamReadDone( |
1952 bool* called, | 1958 bool* called, |
1953 DemuxerStream::Status status, | 1959 DemuxerStream::Status status, |
1954 const scoped_refptr<DecoderBuffer>& buffer) { | 1960 const scoped_refptr<DecoderBuffer>& buffer) { |
1955 EXPECT_EQ(status, DemuxerStream::kOk); | 1961 EXPECT_EQ(status, DemuxerStream::kOk); |
1956 EXPECT_TRUE(buffer->end_of_stream()); | 1962 EXPECT_TRUE(buffer->end_of_stream()); |
1957 *called = true; | 1963 *called = true; |
1958 } | 1964 } |
1959 | 1965 |
1960 Demuxer* demuxer_; | 1966 DemuxerStream* audio_stream_; |
1967 DemuxerStream* video_stream_; | |
1961 bool audio_read_done_; | 1968 bool audio_read_done_; |
1962 bool video_read_done_; | 1969 bool video_read_done_; |
1963 | 1970 |
1964 DISALLOW_COPY_AND_ASSIGN(EndOfStreamHelper); | 1971 DISALLOW_COPY_AND_ASSIGN(EndOfStreamHelper); |
1965 }; | 1972 }; |
1966 | 1973 |
1967 // Make sure that all pending reads that we don't have media data for get an | 1974 // Make sure that all pending reads that we don't have media data for get an |
1968 // "end of stream" buffer when MarkEndOfStream() is called. | 1975 // "end of stream" buffer when MarkEndOfStream() is called. |
1969 TEST_F(ChunkDemuxerTest, EndOfStreamWithPendingReads) { | 1976 TEST_F(ChunkDemuxerTest, EndOfStreamWithPendingReads) { |
1970 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 1977 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
1971 | 1978 |
1972 ASSERT_TRUE(AppendCluster(GenerateCluster(0, 2))); | 1979 ASSERT_TRUE(AppendCluster(GenerateCluster(0, 2))); |
1973 | 1980 |
1974 bool audio_read_done_1 = false; | 1981 bool audio_read_done_1 = false; |
1975 bool video_read_done_1 = false; | 1982 bool video_read_done_1 = false; |
1976 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get()); | 1983 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
1977 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get()); | 1984 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
1985 EndOfStreamHelper end_of_stream_helper_1(audio_stream, video_stream); | |
1986 EndOfStreamHelper end_of_stream_helper_2(audio_stream, video_stream); | |
1978 | 1987 |
1979 ReadAudio(base::Bind(&OnReadDone, | 1988 ReadAudio(base::Bind(&OnReadDone, |
1980 base::TimeDelta::FromMilliseconds(0), | 1989 base::TimeDelta::FromMilliseconds(0), |
1981 &audio_read_done_1)); | 1990 &audio_read_done_1)); |
1982 ReadVideo(base::Bind(&OnReadDone, | 1991 ReadVideo(base::Bind(&OnReadDone, |
1983 base::TimeDelta::FromMilliseconds(0), | 1992 base::TimeDelta::FromMilliseconds(0), |
1984 &video_read_done_1)); | 1993 &video_read_done_1)); |
1985 base::RunLoop().RunUntilIdle(); | 1994 base::RunLoop().RunUntilIdle(); |
1986 | 1995 |
1987 EXPECT_TRUE(audio_read_done_1); | 1996 EXPECT_TRUE(audio_read_done_1); |
(...skipping 13 matching lines...) Expand all Loading... | |
2001 | 2010 |
2002 // Make sure that all Read() calls after we get an MarkEndOfStream() | 2011 // Make sure that all Read() calls after we get an MarkEndOfStream() |
2003 // call return an "end of stream" buffer. | 2012 // call return an "end of stream" buffer. |
2004 TEST_F(ChunkDemuxerTest, ReadsAfterEndOfStream) { | 2013 TEST_F(ChunkDemuxerTest, ReadsAfterEndOfStream) { |
2005 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2014 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
2006 | 2015 |
2007 ASSERT_TRUE(AppendCluster(GenerateCluster(0, 2))); | 2016 ASSERT_TRUE(AppendCluster(GenerateCluster(0, 2))); |
2008 | 2017 |
2009 bool audio_read_done_1 = false; | 2018 bool audio_read_done_1 = false; |
2010 bool video_read_done_1 = false; | 2019 bool video_read_done_1 = false; |
2011 EndOfStreamHelper end_of_stream_helper_1(demuxer_.get()); | 2020 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
2012 EndOfStreamHelper end_of_stream_helper_2(demuxer_.get()); | 2021 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
2013 EndOfStreamHelper end_of_stream_helper_3(demuxer_.get()); | 2022 EndOfStreamHelper end_of_stream_helper_1(audio_stream, video_stream); |
2023 EndOfStreamHelper end_of_stream_helper_2(audio_stream, video_stream); | |
2024 EndOfStreamHelper end_of_stream_helper_3(audio_stream, video_stream); | |
2014 | 2025 |
2015 ReadAudio(base::Bind(&OnReadDone, | 2026 ReadAudio(base::Bind(&OnReadDone, |
2016 base::TimeDelta::FromMilliseconds(0), | 2027 base::TimeDelta::FromMilliseconds(0), |
2017 &audio_read_done_1)); | 2028 &audio_read_done_1)); |
2018 ReadVideo(base::Bind(&OnReadDone, | 2029 ReadVideo(base::Bind(&OnReadDone, |
2019 base::TimeDelta::FromMilliseconds(0), | 2030 base::TimeDelta::FromMilliseconds(0), |
2020 &video_read_done_1)); | 2031 &video_read_done_1)); |
2021 | 2032 |
2022 end_of_stream_helper_1.RequestReads(); | 2033 end_of_stream_helper_1.RequestReads(); |
2023 | 2034 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2176 {100, 9}, | 2187 {100, 9}, |
2177 {133, 12}, | 2188 {133, 12}, |
2178 {kSkip, kSkip}, | 2189 {kSkip, kSkip}, |
2179 }; | 2190 }; |
2180 | 2191 |
2181 ExpectInitMediaLogs(HAS_AUDIO | HAS_VIDEO); | 2192 ExpectInitMediaLogs(HAS_AUDIO | HAS_VIDEO); |
2182 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)).Times(7); | 2193 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)).Times(7); |
2183 ASSERT_TRUE(ParseWebMFile("bear-320x240-live.webm", buffer_timestamps, | 2194 ASSERT_TRUE(ParseWebMFile("bear-320x240-live.webm", buffer_timestamps, |
2184 kInfiniteDuration)); | 2195 kInfiniteDuration)); |
2185 | 2196 |
2186 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 2197 DemuxerStream* audio = GetStream(DemuxerStream::AUDIO); |
2187 EXPECT_EQ(DemuxerStream::LIVENESS_LIVE, audio->liveness()); | 2198 EXPECT_EQ(DemuxerStream::LIVENESS_LIVE, audio->liveness()); |
2188 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 2199 DemuxerStream* video = GetStream(DemuxerStream::VIDEO); |
2189 EXPECT_EQ(DemuxerStream::LIVENESS_LIVE, video->liveness()); | 2200 EXPECT_EQ(DemuxerStream::LIVENESS_LIVE, video->liveness()); |
2190 EXPECT_EQ(212949, demuxer_->GetMemoryUsage()); | 2201 EXPECT_EQ(212949, demuxer_->GetMemoryUsage()); |
2191 } | 2202 } |
2192 | 2203 |
2193 TEST_F(ChunkDemuxerTest, WebMFile_AudioOnly) { | 2204 TEST_F(ChunkDemuxerTest, WebMFile_AudioOnly) { |
2194 struct BufferTimestamps buffer_timestamps[] = { | 2205 struct BufferTimestamps buffer_timestamps[] = { |
2195 {kSkip, 0}, | 2206 {kSkip, 0}, |
2196 {kSkip, 3}, | 2207 {kSkip, 3}, |
2197 {kSkip, 6}, | 2208 {kSkip, 6}, |
2198 {kSkip, 9}, | 2209 {kSkip, 9}, |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2478 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration))); | 2489 GenerateSingleStreamCluster(0, 92, kAudioTrackNum, kAudioBlockDuration))); |
2479 ASSERT_TRUE(AppendCluster(video_id, | 2490 ASSERT_TRUE(AppendCluster(video_id, |
2480 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, | 2491 GenerateSingleStreamCluster(0, 132, kVideoTrackNum, |
2481 kVideoBlockDuration))); | 2492 kVideoBlockDuration))); |
2482 | 2493 |
2483 // Read() from audio should return normal buffers. | 2494 // Read() from audio should return normal buffers. |
2484 GenerateAudioStreamExpectedReads(0, 4); | 2495 GenerateAudioStreamExpectedReads(0, 4); |
2485 | 2496 |
2486 // Audio stream will become inaccessible after |audio_id| is removed, so save | 2497 // Audio stream will become inaccessible after |audio_id| is removed, so save |
2487 // it here to read from it after RemoveId. | 2498 // it here to read from it after RemoveId. |
2488 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 2499 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
2489 | 2500 |
2490 // Remove the audio id. | 2501 // Remove the audio id. |
2491 demuxer_->RemoveId(audio_id); | 2502 demuxer_->RemoveId(audio_id); |
2492 | 2503 |
2493 // Read() from audio should return "end of stream" buffers. | 2504 // Read() from audio should return "end of stream" buffers. |
2494 bool audio_read_done = false; | 2505 bool audio_read_done = false; |
2495 audio_stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); | 2506 audio_stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done)); |
2496 base::RunLoop().RunUntilIdle(); | 2507 base::RunLoop().RunUntilIdle(); |
2497 EXPECT_TRUE(audio_read_done); | 2508 EXPECT_TRUE(audio_read_done); |
2498 | 2509 |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3166 ASSERT_TRUE(AppendCluster(kDefaultSecondCluster())); | 3177 ASSERT_TRUE(AppendCluster(kDefaultSecondCluster())); |
3167 EXPECT_CALL(host_, SetDuration( | 3178 EXPECT_CALL(host_, SetDuration( |
3168 base::TimeDelta::FromMilliseconds(kDefaultSecondClusterEndTimestamp))); | 3179 base::TimeDelta::FromMilliseconds(kDefaultSecondClusterEndTimestamp))); |
3169 MarkEndOfStream(PIPELINE_OK); | 3180 MarkEndOfStream(PIPELINE_OK); |
3170 | 3181 |
3171 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); | 3182 demuxer_->Seek(seek_time, NewExpectedStatusCB(PIPELINE_OK)); |
3172 | 3183 |
3173 GenerateExpectedReads(0, 4); | 3184 GenerateExpectedReads(0, 4); |
3174 GenerateExpectedReads(46, 66, 5); | 3185 GenerateExpectedReads(46, 66, 5); |
3175 | 3186 |
3176 EndOfStreamHelper end_of_stream_helper(demuxer_.get()); | 3187 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
3188 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); | |
3189 EndOfStreamHelper end_of_stream_helper(audio_stream, video_stream); | |
3177 end_of_stream_helper.RequestReads(); | 3190 end_of_stream_helper.RequestReads(); |
3178 end_of_stream_helper.CheckIfReadDonesWereCalled(true); | 3191 end_of_stream_helper.CheckIfReadDonesWereCalled(true); |
3179 } | 3192 } |
3180 | 3193 |
3181 TEST_F(ChunkDemuxerTest, ConfigChange_Video) { | 3194 TEST_F(ChunkDemuxerTest, ConfigChange_Video) { |
3182 InSequence s; | 3195 InSequence s; |
3183 | 3196 |
3184 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); | 3197 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); |
3185 | 3198 |
3186 DemuxerStream::Status status; | 3199 DemuxerStream::Status status; |
3187 base::TimeDelta last_timestamp; | 3200 base::TimeDelta last_timestamp; |
3188 | 3201 |
3189 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 3202 DemuxerStream* video = GetStream(DemuxerStream::VIDEO); |
3190 | 3203 |
3191 // Fetch initial video config and verify it matches what we expect. | 3204 // Fetch initial video config and verify it matches what we expect. |
3192 const VideoDecoderConfig& video_config_1 = video->video_decoder_config(); | 3205 const VideoDecoderConfig& video_config_1 = video->video_decoder_config(); |
3193 ASSERT_TRUE(video_config_1.IsValidConfig()); | 3206 ASSERT_TRUE(video_config_1.IsValidConfig()); |
3194 EXPECT_EQ(video_config_1.natural_size().width(), 320); | 3207 EXPECT_EQ(video_config_1.natural_size().width(), 320); |
3195 EXPECT_EQ(video_config_1.natural_size().height(), 240); | 3208 EXPECT_EQ(video_config_1.natural_size().height(), 240); |
3196 | 3209 |
3197 ExpectRead(DemuxerStream::VIDEO, 0); | 3210 ExpectRead(DemuxerStream::VIDEO, 0); |
3198 | 3211 |
3199 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); | 3212 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); |
(...skipping 26 matching lines...) Expand all Loading... | |
3226 } | 3239 } |
3227 | 3240 |
3228 TEST_F(ChunkDemuxerTest, ConfigChange_Audio) { | 3241 TEST_F(ChunkDemuxerTest, ConfigChange_Audio) { |
3229 InSequence s; | 3242 InSequence s; |
3230 | 3243 |
3231 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); | 3244 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); |
3232 | 3245 |
3233 DemuxerStream::Status status; | 3246 DemuxerStream::Status status; |
3234 base::TimeDelta last_timestamp; | 3247 base::TimeDelta last_timestamp; |
3235 | 3248 |
3236 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO); | 3249 DemuxerStream* audio = GetStream(DemuxerStream::AUDIO); |
3237 | 3250 |
3238 // Fetch initial audio config and verify it matches what we expect. | 3251 // Fetch initial audio config and verify it matches what we expect. |
3239 const AudioDecoderConfig& audio_config_1 = audio->audio_decoder_config(); | 3252 const AudioDecoderConfig& audio_config_1 = audio->audio_decoder_config(); |
3240 ASSERT_TRUE(audio_config_1.IsValidConfig()); | 3253 ASSERT_TRUE(audio_config_1.IsValidConfig()); |
3241 EXPECT_EQ(audio_config_1.samples_per_second(), 44100); | 3254 EXPECT_EQ(audio_config_1.samples_per_second(), 44100); |
3242 EXPECT_EQ(audio_config_1.extra_data().size(), 3863u); | 3255 EXPECT_EQ(audio_config_1.extra_data().size(), 3863u); |
3243 | 3256 |
3244 ExpectRead(DemuxerStream::AUDIO, 0); | 3257 ExpectRead(DemuxerStream::AUDIO, 0); |
3245 | 3258 |
3246 // Read until we encounter config 2. | 3259 // Read until we encounter config 2. |
(...skipping 18 matching lines...) Expand all Loading... | |
3265 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); | 3278 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); |
3266 ASSERT_EQ(status, DemuxerStream::kOk); | 3279 ASSERT_EQ(status, DemuxerStream::kOk); |
3267 EXPECT_EQ(last_timestamp.InMilliseconds(), 2744); | 3280 EXPECT_EQ(last_timestamp.InMilliseconds(), 2744); |
3268 } | 3281 } |
3269 | 3282 |
3270 TEST_F(ChunkDemuxerTest, ConfigChange_Seek) { | 3283 TEST_F(ChunkDemuxerTest, ConfigChange_Seek) { |
3271 InSequence s; | 3284 InSequence s; |
3272 | 3285 |
3273 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); | 3286 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); |
3274 | 3287 |
3275 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO); | 3288 DemuxerStream* video = GetStream(DemuxerStream::VIDEO); |
3276 | 3289 |
3277 // Fetch initial video config and verify it matches what we expect. | 3290 // Fetch initial video config and verify it matches what we expect. |
3278 const VideoDecoderConfig& video_config_1 = video->video_decoder_config(); | 3291 const VideoDecoderConfig& video_config_1 = video->video_decoder_config(); |
3279 ASSERT_TRUE(video_config_1.IsValidConfig()); | 3292 ASSERT_TRUE(video_config_1.IsValidConfig()); |
3280 EXPECT_EQ(video_config_1.natural_size().width(), 320); | 3293 EXPECT_EQ(video_config_1.natural_size().width(), 320); |
3281 EXPECT_EQ(video_config_1.natural_size().height(), 240); | 3294 EXPECT_EQ(video_config_1.natural_size().height(), 240); |
3282 | 3295 |
3283 ExpectRead(DemuxerStream::VIDEO, 0); | 3296 ExpectRead(DemuxerStream::VIDEO, 0); |
3284 | 3297 |
3285 // Seek to a location with a different config. | 3298 // Seek to a location with a different config. |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3978 Seek(seek_time3); | 3991 Seek(seek_time3); |
3979 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time3, 0)); | 3992 EXPECT_TRUE(demuxer_->EvictCodedFrames(kSourceId, seek_time3, 0)); |
3980 // Strictly speaking the current playback time is 23*6==138ms, so we could | 3993 // Strictly speaking the current playback time is 23*6==138ms, so we could |
3981 // release data up to 138ms, but we only release as much data as necessary | 3994 // release data up to 138ms, but we only release as much data as necessary |
3982 // to bring memory usage under the limit, so we release only up to 115ms. | 3995 // to bring memory usage under the limit, so we release only up to 115ms. |
3983 CheckExpectedRanges("{ [115,230) }"); | 3996 CheckExpectedRanges("{ [115,230) }"); |
3984 } | 3997 } |
3985 | 3998 |
3986 TEST_F(ChunkDemuxerTest, AppendWindow_Video) { | 3999 TEST_F(ChunkDemuxerTest, AppendWindow_Video) { |
3987 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); | 4000 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); |
3988 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4001 DemuxerStream* stream = GetStream(DemuxerStream::VIDEO); |
3989 | 4002 |
3990 // Set the append window to [50,280). | 4003 // Set the append window to [50,280). |
3991 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); | 4004 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); |
3992 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); | 4005 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); |
3993 | 4006 |
3994 // Append a cluster that starts before and ends after the append window. | 4007 // Append a cluster that starts before and ends after the append window. |
3995 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30)); | 4008 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30)); |
3996 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 4009 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, |
3997 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); | 4010 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); |
3998 | 4011 |
3999 // Verify that GOPs that start outside the window are not included | 4012 // Verify that GOPs that start outside the window are not included |
4000 // in the buffer. Also verify that buffers that start inside the | 4013 // in the buffer. Also verify that buffers that start inside the |
4001 // window and extend beyond the end of the window are not included. | 4014 // window and extend beyond the end of the window are not included. |
4002 CheckExpectedRanges("{ [120,270) }"); | 4015 CheckExpectedRanges("{ [120,270) }"); |
4003 CheckExpectedBuffers(stream, "120K 150 180 210 240K"); | 4016 CheckExpectedBuffers(stream, "120K 150 180 210 240K"); |
4004 | 4017 |
4005 // Extend the append window to [50,650). | 4018 // Extend the append window to [50,650). |
4006 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); | 4019 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); |
4007 | 4020 |
4008 // Append more data and verify that adding buffers start at the next | 4021 // Append more data and verify that adding buffers start at the next |
4009 // key frame. | 4022 // key frame. |
4010 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30)); | 4023 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30)); |
4011 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 4024 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, |
4012 "360 390 420K 450 480 510 540K 570 600 630K"); | 4025 "360 390 420K 450 480 510 540K 570 600 630K"); |
4013 CheckExpectedRanges("{ [120,270) [420,630) }"); | 4026 CheckExpectedRanges("{ [120,270) [420,630) }"); |
4014 } | 4027 } |
4015 | 4028 |
4016 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) { | 4029 TEST_F(ChunkDemuxerTest, AppendWindow_Audio) { |
4017 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); | 4030 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
4018 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4031 DemuxerStream* stream = GetStream(DemuxerStream::AUDIO); |
4019 | 4032 |
4020 // Set the append window to [50,280). | 4033 // Set the append window to [50,280). |
4021 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); | 4034 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(50); |
4022 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); | 4035 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); |
4023 | 4036 |
4024 // Append a cluster that starts before and ends after the append window. | 4037 // Append a cluster that starts before and ends after the append window. |
4025 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30)); | 4038 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(30)); |
4026 AppendSingleStreamCluster( | 4039 AppendSingleStreamCluster( |
4027 kSourceId, kAudioTrackNum, | 4040 kSourceId, kAudioTrackNum, |
4028 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); | 4041 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4081 // Read a WebM file into memory and send the data to the demuxer. The chunk | 4094 // Read a WebM file into memory and send the data to the demuxer. The chunk |
4082 // size has been chosen carefully to ensure the preroll buffer used by the | 4095 // size has been chosen carefully to ensure the preroll buffer used by the |
4083 // partial append window trim must come from a previous Append() call. | 4096 // partial append window trim must come from a previous Append() call. |
4084 scoped_refptr<DecoderBuffer> buffer = | 4097 scoped_refptr<DecoderBuffer> buffer = |
4085 ReadTestDataFile("bear-320x240-audio-only.webm"); | 4098 ReadTestDataFile("bear-320x240-audio-only.webm"); |
4086 ExpectInitMediaLogs(HAS_AUDIO); | 4099 ExpectInitMediaLogs(HAS_AUDIO); |
4087 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); | 4100 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); |
4088 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)); | 4101 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)); |
4089 ASSERT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 128)); | 4102 ASSERT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 128)); |
4090 | 4103 |
4091 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4104 DemuxerStream* stream = GetStream(DemuxerStream::AUDIO); |
4092 CheckExpectedBuffers(stream, "50KP 50K 62K 86K 109K 122K 125K 128K"); | 4105 CheckExpectedBuffers(stream, "50KP 50K 62K 86K 109K 122K 125K 128K"); |
4093 } | 4106 } |
4094 | 4107 |
4095 TEST_F(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) { | 4108 TEST_F(ChunkDemuxerTest, AppendWindow_AudioConfigUpdateRemovesPreroll) { |
4096 EXPECT_CALL(*this, DemuxerOpened()); | 4109 EXPECT_CALL(*this, DemuxerOpened()); |
4097 demuxer_->Initialize( | 4110 demuxer_->Initialize( |
4098 &host_, | 4111 &host_, |
4099 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), | 4112 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), |
4100 true); | 4113 true); |
4101 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); | 4114 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); |
4102 | 4115 |
4103 // Set the append window such that the first file is completely before the | 4116 // Set the append window such that the first file is completely before the |
4104 // append window. | 4117 // append window. |
4105 // Expect duration adjustment since actual duration differs slightly from | 4118 // Expect duration adjustment since actual duration differs slightly from |
4106 // duration in the init segment. | 4119 // duration in the init segment. |
4107 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746); | 4120 const base::TimeDelta duration_1 = base::TimeDelta::FromMilliseconds(2746); |
4108 append_window_start_for_next_append_ = duration_1; | 4121 append_window_start_for_next_append_ = duration_1; |
4109 | 4122 |
4110 // Read a WebM file into memory and append the data. | 4123 // Read a WebM file into memory and append the data. |
4111 scoped_refptr<DecoderBuffer> buffer = | 4124 scoped_refptr<DecoderBuffer> buffer = |
4112 ReadTestDataFile("bear-320x240-audio-only.webm"); | 4125 ReadTestDataFile("bear-320x240-audio-only.webm"); |
4113 ExpectInitMediaLogs(HAS_AUDIO); | 4126 ExpectInitMediaLogs(HAS_AUDIO); |
4114 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); | 4127 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); |
4115 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)); | 4128 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(2)); |
4116 ASSERT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); | 4129 ASSERT_TRUE(AppendDataInPieces(buffer->data(), buffer->data_size(), 512)); |
4117 CheckExpectedRanges("{ }"); | 4130 CheckExpectedRanges("{ }"); |
4118 | 4131 |
4119 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4132 DemuxerStream* stream = GetStream(DemuxerStream::AUDIO); |
4120 AudioDecoderConfig config_1 = stream->audio_decoder_config(); | 4133 AudioDecoderConfig config_1 = stream->audio_decoder_config(); |
4121 | 4134 |
4122 // Read a second WebM with a different config in and append the data. | 4135 // Read a second WebM with a different config in and append the data. |
4123 scoped_refptr<DecoderBuffer> buffer2 = | 4136 scoped_refptr<DecoderBuffer> buffer2 = |
4124 ReadTestDataFile("bear-320x240-audio-only-48khz.webm"); | 4137 ReadTestDataFile("bear-320x240-audio-only-48khz.webm"); |
4125 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); | 4138 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); |
4126 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(21)); | 4139 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(21)); |
4127 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber()); | 4140 EXPECT_CALL(host_, SetDuration(_)).Times(AnyNumber()); |
4128 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1)); | 4141 ASSERT_TRUE(SetTimestampOffset(kSourceId, duration_1)); |
4129 ASSERT_TRUE(AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512)); | 4142 ASSERT_TRUE(AppendDataInPieces(buffer2->data(), buffer2->data_size(), 512)); |
4130 CheckExpectedRanges("{ [2746,5519) }"); | 4143 CheckExpectedRanges("{ [2746,5519) }"); |
4131 | 4144 |
4132 Seek(duration_1); | 4145 Seek(duration_1); |
4133 ExpectConfigChanged(DemuxerStream::AUDIO); | 4146 ExpectConfigChanged(DemuxerStream::AUDIO); |
4134 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config())); | 4147 ASSERT_FALSE(config_1.Matches(stream->audio_decoder_config())); |
4135 CheckExpectedBuffers(stream, "2746K 2767K 2789K 2810K"); | 4148 CheckExpectedBuffers(stream, "2746K 2767K 2789K 2810K"); |
4136 } | 4149 } |
4137 | 4150 |
4138 TEST_F(ChunkDemuxerTest, AppendWindow_Text) { | 4151 TEST_F(ChunkDemuxerTest, AppendWindow_Text) { |
4139 DemuxerStream* text_stream = NULL; | 4152 DemuxerStream* text_stream = NULL; |
4140 EXPECT_CALL(host_, AddTextStream(_, _)) | 4153 EXPECT_CALL(host_, AddTextStream(_, _)) |
4141 .WillOnce(SaveArg<0>(&text_stream)); | 4154 .WillOnce(SaveArg<0>(&text_stream)); |
4142 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); | 4155 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); |
4143 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4156 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4144 | 4157 |
4145 // Set the append window to [20,280). | 4158 // Set the append window to [20,280). |
4146 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); | 4159 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); |
4147 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); | 4160 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); |
4148 | 4161 |
4149 // Append a cluster that starts before and ends after the append | 4162 // Append a cluster that starts before and ends after the append |
4150 // window. | 4163 // window. |
4151 AppendMuxedCluster( | 4164 AppendMuxedCluster( |
4152 MuxedStreamInfo(kVideoTrackNum, | 4165 MuxedStreamInfo(kVideoTrackNum, |
4153 "0K 30 60 90 120K 150 180 210 240K 270 300 330K", 30), | 4166 "0K 30 60 90 120K 150 180 210 240K 270 300 330K", 30), |
(...skipping 30 matching lines...) Expand all Loading... | |
4184 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50); | 4197 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50); |
4185 demuxer_->StartWaitingForSeek(seek_time); | 4198 demuxer_->StartWaitingForSeek(seek_time); |
4186 } | 4199 } |
4187 | 4200 |
4188 TEST_F(ChunkDemuxerTest, Remove_AudioVideoText) { | 4201 TEST_F(ChunkDemuxerTest, Remove_AudioVideoText) { |
4189 DemuxerStream* text_stream = NULL; | 4202 DemuxerStream* text_stream = NULL; |
4190 EXPECT_CALL(host_, AddTextStream(_, _)) | 4203 EXPECT_CALL(host_, AddTextStream(_, _)) |
4191 .WillOnce(SaveArg<0>(&text_stream)); | 4204 .WillOnce(SaveArg<0>(&text_stream)); |
4192 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 4205 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
4193 | 4206 |
4194 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4207 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
4195 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4208 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4196 | 4209 |
4197 AppendMuxedCluster( | 4210 AppendMuxedCluster( |
4198 MuxedStreamInfo(kAudioTrackNum, "0K 20K 40K 60K 80K 100K 120K 140K", 20), | 4211 MuxedStreamInfo(kAudioTrackNum, "0K 20K 40K 60K 80K 100K 120K 140K", 20), |
4199 MuxedStreamInfo(kVideoTrackNum, "0K 30 60 90 120K 150 180", 30), | 4212 MuxedStreamInfo(kVideoTrackNum, "0K 30 60 90 120K 150 180", 30), |
4200 MuxedStreamInfo(kTextTrackNum, "0K 100K 200K")); | 4213 MuxedStreamInfo(kTextTrackNum, "0K 100K 200K")); |
4201 | 4214 |
4202 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K"); | 4215 CheckExpectedBuffers(audio_stream, "0K 20K 40K 60K 80K 100K 120K 140K"); |
4203 CheckExpectedBuffers(video_stream, "0K 30 60 90 120K 150 180"); | 4216 CheckExpectedBuffers(video_stream, "0K 30 60 90 120K 150 180"); |
4204 CheckExpectedBuffers(text_stream, "0K 100K 200K"); | 4217 CheckExpectedBuffers(text_stream, "0K 100K 200K"); |
4205 | 4218 |
(...skipping 12 matching lines...) Expand all Loading... | |
4218 MuxedStreamInfo(kTextTrackNum, "1K 101K 201K")); | 4231 MuxedStreamInfo(kTextTrackNum, "1K 101K 201K")); |
4219 | 4232 |
4220 Seek(base::TimeDelta()); | 4233 Seek(base::TimeDelta()); |
4221 CheckExpectedBuffers(audio_stream, "1K 21K 41K 61K 81K 101K 121K 141K"); | 4234 CheckExpectedBuffers(audio_stream, "1K 21K 41K 61K 81K 101K 121K 141K"); |
4222 CheckExpectedBuffers(video_stream, "1K 31 61 91 121K 151 181"); | 4235 CheckExpectedBuffers(video_stream, "1K 31 61 91 121K 151 181"); |
4223 CheckExpectedBuffers(text_stream, "1K 101K 201K"); | 4236 CheckExpectedBuffers(text_stream, "1K 101K 201K"); |
4224 } | 4237 } |
4225 | 4238 |
4226 TEST_F(ChunkDemuxerTest, Remove_StartAtDuration) { | 4239 TEST_F(ChunkDemuxerTest, Remove_StartAtDuration) { |
4227 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); | 4240 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
4228 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4241 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
4229 | 4242 |
4230 // Set the duration to something small so that the append that | 4243 // Set the duration to something small so that the append that |
4231 // follows updates the duration to reflect the end of the appended data. | 4244 // follows updates the duration to reflect the end of the appended data. |
4232 EXPECT_CALL(host_, SetDuration( | 4245 EXPECT_CALL(host_, SetDuration( |
4233 base::TimeDelta::FromMilliseconds(1))); | 4246 base::TimeDelta::FromMilliseconds(1))); |
4234 demuxer_->SetDuration(0.001); | 4247 demuxer_->SetDuration(0.001); |
4235 | 4248 |
4236 EXPECT_CALL(host_, SetDuration( | 4249 EXPECT_CALL(host_, SetDuration( |
4237 base::TimeDelta::FromMilliseconds(160))); | 4250 base::TimeDelta::FromMilliseconds(160))); |
4238 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, | 4251 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, |
(...skipping 13 matching lines...) Expand all Loading... | |
4252 | 4265 |
4253 // Verifies that a Seek() will complete without text cues for | 4266 // Verifies that a Seek() will complete without text cues for |
4254 // the seek point and will return cues after the seek position | 4267 // the seek point and will return cues after the seek position |
4255 // when they are eventually appended. | 4268 // when they are eventually appended. |
4256 TEST_F(ChunkDemuxerTest, SeekCompletesWithoutTextCues) { | 4269 TEST_F(ChunkDemuxerTest, SeekCompletesWithoutTextCues) { |
4257 DemuxerStream* text_stream = NULL; | 4270 DemuxerStream* text_stream = NULL; |
4258 EXPECT_CALL(host_, AddTextStream(_, _)) | 4271 EXPECT_CALL(host_, AddTextStream(_, _)) |
4259 .WillOnce(SaveArg<0>(&text_stream)); | 4272 .WillOnce(SaveArg<0>(&text_stream)); |
4260 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 4273 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
4261 | 4274 |
4262 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4275 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
4263 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4276 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4264 | 4277 |
4265 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(120); | 4278 base::TimeDelta seek_time = base::TimeDelta::FromMilliseconds(120); |
4266 bool seek_cb_was_called = false; | 4279 bool seek_cb_was_called = false; |
4267 demuxer_->StartWaitingForSeek(seek_time); | 4280 demuxer_->StartWaitingForSeek(seek_time); |
4268 demuxer_->Seek(seek_time, | 4281 demuxer_->Seek(seek_time, |
4269 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); | 4282 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); |
4270 base::RunLoop().RunUntilIdle(); | 4283 base::RunLoop().RunUntilIdle(); |
4271 | 4284 |
4272 EXPECT_FALSE(seek_cb_was_called); | 4285 EXPECT_FALSE(seek_cb_was_called); |
4273 | 4286 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4341 ASSERT_TRUE(AppendCluster(GenerateCluster(0, 0, 4))); | 4354 ASSERT_TRUE(AppendCluster(GenerateCluster(0, 0, 4))); |
4342 ASSERT_TRUE(AppendData(kCuesHeader, sizeof(kCuesHeader))); | 4355 ASSERT_TRUE(AppendData(kCuesHeader, sizeof(kCuesHeader))); |
4343 ASSERT_TRUE(AppendCluster(GenerateCluster(46, 66, 5))); | 4356 ASSERT_TRUE(AppendCluster(GenerateCluster(46, 66, 5))); |
4344 CheckExpectedRanges("{ [0,115) }"); | 4357 CheckExpectedRanges("{ [0,115) }"); |
4345 } | 4358 } |
4346 | 4359 |
4347 TEST_F(ChunkDemuxerTest, EvictCodedFramesTest) { | 4360 TEST_F(ChunkDemuxerTest, EvictCodedFramesTest) { |
4348 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 4361 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
4349 demuxer_->SetMemoryLimitsForTest(DemuxerStream::AUDIO, 10 * kBlockSize); | 4362 demuxer_->SetMemoryLimitsForTest(DemuxerStream::AUDIO, 10 * kBlockSize); |
4350 demuxer_->SetMemoryLimitsForTest(DemuxerStream::VIDEO, 15 * kBlockSize); | 4363 demuxer_->SetMemoryLimitsForTest(DemuxerStream::VIDEO, 15 * kBlockSize); |
4351 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4364 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
4352 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4365 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4353 | 4366 |
4354 const char* kAudioStreamInfo = "0K 40K 80K 120K 160K 200K 240K 280K"; | 4367 const char* kAudioStreamInfo = "0K 40K 80K 120K 160K 200K 240K 280K"; |
4355 const char* kVideoStreamInfo = "0K 10 20K 30 40K 50 60K 70 80K 90 100K " | 4368 const char* kVideoStreamInfo = "0K 10 20K 30 40K 50 60K 70 80K 90 100K " |
4356 "110 120K 130 140K"; | 4369 "110 120K 130 140K"; |
4357 // Append 8 blocks (80 bytes) of data to audio stream and 15 blocks (150 | 4370 // Append 8 blocks (80 bytes) of data to audio stream and 15 blocks (150 |
4358 // bytes) to video stream. | 4371 // bytes) to video stream. |
4359 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, kAudioStreamInfo, 40), | 4372 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, kAudioStreamInfo, 40), |
4360 MuxedStreamInfo(kVideoTrackNum, kVideoStreamInfo, 10)); | 4373 MuxedStreamInfo(kVideoTrackNum, kVideoStreamInfo, 10)); |
4361 CheckExpectedBuffers(audio_stream, kAudioStreamInfo); | 4374 CheckExpectedBuffers(audio_stream, kAudioStreamInfo); |
4362 CheckExpectedBuffers(video_stream, kVideoStreamInfo); | 4375 CheckExpectedBuffers(video_stream, kVideoStreamInfo); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4422 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 4435 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
4423 EXPECT_MEDIA_LOG(SegmentMissingFrames("1")); | 4436 EXPECT_MEDIA_LOG(SegmentMissingFrames("1")); |
4424 EXPECT_MEDIA_LOG(SegmentMissingFrames("2")); | 4437 EXPECT_MEDIA_LOG(SegmentMissingFrames("2")); |
4425 ASSERT_TRUE(AppendCluster(GenerateEmptyCluster(0))); | 4438 ASSERT_TRUE(AppendCluster(GenerateEmptyCluster(0))); |
4426 } | 4439 } |
4427 | 4440 |
4428 TEST_F(ChunkDemuxerTest, RelaxedKeyframe_FirstSegmentMissingKeyframe) { | 4441 TEST_F(ChunkDemuxerTest, RelaxedKeyframe_FirstSegmentMissingKeyframe) { |
4429 // Append V:[n n n][n n K] | 4442 // Append V:[n n n][n n K] |
4430 // Expect V: [K] | 4443 // Expect V: [K] |
4431 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); | 4444 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); |
4432 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4445 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4433 | 4446 |
4434 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(10)).Times(2); | 4447 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(10)).Times(2); |
4435 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0 10 20"); | 4448 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0 10 20"); |
4436 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "30 40 50K"); | 4449 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "30 40 50K"); |
4437 CheckExpectedRanges("{ [50,60) }"); | 4450 CheckExpectedRanges("{ [50,60) }"); |
4438 CheckExpectedBuffers(video_stream, "50K"); | 4451 CheckExpectedBuffers(video_stream, "50K"); |
4439 } | 4452 } |
4440 | 4453 |
4441 TEST_F(ChunkDemuxerTest, RelaxedKeyframe_SecondSegmentMissingKeyframe) { | 4454 TEST_F(ChunkDemuxerTest, RelaxedKeyframe_SecondSegmentMissingKeyframe) { |
4442 // Append V:[K n n][n n n] | 4455 // Append V:[K n n][n n n] |
4443 // Expect V:[K n n][n n n] | 4456 // Expect V:[K n n][n n n] |
4444 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); | 4457 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); |
4445 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4458 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4446 | 4459 |
4447 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(10)).Times(2); | 4460 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(10)).Times(2); |
4448 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 10 20"); | 4461 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 10 20"); |
4449 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "30 40 50"); | 4462 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "30 40 50"); |
4450 CheckExpectedRanges("{ [0,60) }"); | 4463 CheckExpectedRanges("{ [0,60) }"); |
4451 CheckExpectedBuffers(video_stream, "0K 10 20 30 40 50"); | 4464 CheckExpectedBuffers(video_stream, "0K 10 20 30 40 50"); |
4452 } | 4465 } |
4453 | 4466 |
4454 TEST_F(ChunkDemuxerTest, RelaxedKeyframe_RemoveInterruptsCodedFrameGroup_1) { | 4467 TEST_F(ChunkDemuxerTest, RelaxedKeyframe_RemoveInterruptsCodedFrameGroup_1) { |
4455 // Append V:[K n n] | 4468 // Append V:[K n n] |
4456 // Remove ***** | 4469 // Remove ***** |
4457 // Append V: [n n n][n K n] | 4470 // Append V: [n n n][n K n] |
4458 // Expect: [K n] | 4471 // Expect: [K n] |
4459 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); | 4472 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); |
4460 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4473 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4461 | 4474 |
4462 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(10)).Times(3); | 4475 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(10)).Times(3); |
4463 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 10 20"); | 4476 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 10 20"); |
4464 demuxer_->Remove(kSourceId, base::TimeDelta(), | 4477 demuxer_->Remove(kSourceId, base::TimeDelta(), |
4465 base::TimeDelta::FromMilliseconds(30)); | 4478 base::TimeDelta::FromMilliseconds(30)); |
4466 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "30 40 50"); | 4479 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "30 40 50"); |
4467 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "60 70K 80"); | 4480 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "60 70K 80"); |
4468 CheckExpectedRanges("{ [70,90) }"); | 4481 CheckExpectedRanges("{ [70,90) }"); |
4469 CheckExpectedBuffers(video_stream, "70K 80"); | 4482 CheckExpectedBuffers(video_stream, "70K 80"); |
4470 } | 4483 } |
4471 | 4484 |
4472 TEST_F(ChunkDemuxerTest, RelaxedKeyframe_RemoveInterruptsCodedFrameGroup_2) { | 4485 TEST_F(ChunkDemuxerTest, RelaxedKeyframe_RemoveInterruptsCodedFrameGroup_2) { |
4473 // Append V:[K n n][n n n][n K n] | 4486 // Append V:[K n n][n n n][n K n] |
4474 // Remove * | 4487 // Remove * |
4475 // Expect: [K n] | 4488 // Expect: [K n] |
4476 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); | 4489 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); |
4477 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4490 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4478 | 4491 |
4479 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(10)).Times(3); | 4492 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(10)).Times(3); |
4480 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 10 20"); | 4493 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 10 20"); |
4481 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "30 40 50"); | 4494 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "30 40 50"); |
4482 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "60 70K 80"); | 4495 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "60 70K 80"); |
4483 demuxer_->Remove(kSourceId, base::TimeDelta(), | 4496 demuxer_->Remove(kSourceId, base::TimeDelta(), |
4484 base::TimeDelta::FromMilliseconds(10)); | 4497 base::TimeDelta::FromMilliseconds(10)); |
4485 CheckExpectedRanges("{ [70,90) }"); | 4498 CheckExpectedRanges("{ [70,90) }"); |
4486 CheckExpectedBuffers(video_stream, "70K 80"); | 4499 CheckExpectedBuffers(video_stream, "70K 80"); |
4487 } | 4500 } |
4488 | 4501 |
4489 TEST_F(ChunkDemuxerTest, RelaxedKeyframe_RemoveInterruptsCodedFrameGroup_3) { | 4502 TEST_F(ChunkDemuxerTest, RelaxedKeyframe_RemoveInterruptsCodedFrameGroup_3) { |
4490 // Append V:[K n n][n n n][n K n] | 4503 // Append V:[K n n][n n n][n K n] |
4491 // Remove * | 4504 // Remove * |
4492 // Expect: [K n n..n n] [K n] | 4505 // Expect: [K n n..n n] [K n] |
4493 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); | 4506 ASSERT_TRUE(InitDemuxer(HAS_VIDEO)); |
4494 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4507 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4495 | 4508 |
4496 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(10)).Times(3); | 4509 EXPECT_MEDIA_LOG(WebMSimpleBlockDurationEstimated(10)).Times(3); |
4497 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 10 20"); | 4510 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 10 20"); |
4498 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "30 40 50"); | 4511 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "30 40 50"); |
4499 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "60 70K 80"); | 4512 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "60 70K 80"); |
4500 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(50), | 4513 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(50), |
4501 base::TimeDelta::FromMilliseconds(60)); | 4514 base::TimeDelta::FromMilliseconds(60)); |
4502 CheckExpectedRanges("{ [0,50) [70,90) }"); | 4515 CheckExpectedRanges("{ [0,50) [70,90) }"); |
4503 CheckExpectedBuffers(video_stream, "0K 10 20 30 40"); | 4516 CheckExpectedBuffers(video_stream, "0K 10 20 30 40"); |
4504 Seek(base::TimeDelta::FromMilliseconds(70)); | 4517 Seek(base::TimeDelta::FromMilliseconds(70)); |
4505 CheckExpectedBuffers(video_stream, "70K 80"); | 4518 CheckExpectedBuffers(video_stream, "70K 80"); |
4506 } | 4519 } |
4507 | 4520 |
4508 TEST_F(ChunkDemuxerTest, | 4521 TEST_F(ChunkDemuxerTest, |
4509 RelaxedKeyframe_RemoveInterruptsMuxedCodedFrameGroup_1) { | 4522 RelaxedKeyframe_RemoveInterruptsMuxedCodedFrameGroup_1) { |
4510 // Append muxed: | 4523 // Append muxed: |
4511 // A:[K K K] | 4524 // A:[K K K] |
4512 // V:[K n n] | 4525 // V:[K n n] |
4513 // Remove ***** | 4526 // Remove ***** |
4514 // Append muxed: | 4527 // Append muxed: |
4515 // A: [K K K][K K K] | 4528 // A: [K K K][K K K] |
4516 // V: [n n n][n K n] | 4529 // V: [n n n][n K n] |
4517 // Expect: | 4530 // Expect: |
4518 // A: [K K K][K K K] | 4531 // A: [K K K][K K K] |
4519 // V [K n] | 4532 // V [K n] |
4520 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 4533 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
4521 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4534 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
4522 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4535 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4523 | 4536 |
4524 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 10K 20D10K"), | 4537 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 10K 20D10K"), |
4525 MuxedStreamInfo(kVideoTrackNum, "0K 10 20", 10)); | 4538 MuxedStreamInfo(kVideoTrackNum, "0K 10 20", 10)); |
4526 demuxer_->Remove(kSourceId, base::TimeDelta(), | 4539 demuxer_->Remove(kSourceId, base::TimeDelta(), |
4527 base::TimeDelta::FromMilliseconds(30)); | 4540 base::TimeDelta::FromMilliseconds(30)); |
4528 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "30K 40K 50D10K"), | 4541 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "30K 40K 50D10K"), |
4529 MuxedStreamInfo(kVideoTrackNum, "30 40 50", 10)); | 4542 MuxedStreamInfo(kVideoTrackNum, "30 40 50", 10)); |
4530 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "60K 70K 80D10K"), | 4543 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "60K 70K 80D10K"), |
4531 MuxedStreamInfo(kVideoTrackNum, "60 70K 80", 10)); | 4544 MuxedStreamInfo(kVideoTrackNum, "60 70K 80", 10)); |
4532 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }"); | 4545 CheckExpectedRanges(DemuxerStream::AUDIO, "{ [30,90) }"); |
(...skipping 12 matching lines...) Expand all Loading... | |
4545 // Remove ***** | 4558 // Remove ***** |
4546 // Append muxed: | 4559 // Append muxed: |
4547 // A: [K K K][K K K] | 4560 // A: [K K K][K K K] |
4548 // V: [n n n][n K n] | 4561 // V: [n n n][n K n] |
4549 // Expect: | 4562 // Expect: |
4550 // A: [K K K][K K K] | 4563 // A: [K K K][K K K] |
4551 // V [................K n] (As would occur if there really were a | 4564 // V [................K n] (As would occur if there really were a |
4552 // jagged cluster start and not badly muxed clusters as used to | 4565 // jagged cluster start and not badly muxed clusters as used to |
4553 // simulate a jagged start in this test.) | 4566 // simulate a jagged start in this test.) |
4554 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 4567 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
4555 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4568 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
4556 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4569 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4557 | 4570 |
4558 EXPECT_MEDIA_LOG(SegmentMissingFrames("1")); | 4571 EXPECT_MEDIA_LOG(SegmentMissingFrames("1")); |
4559 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 10K 20D10K"), | 4572 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "0K 10K 20D10K"), |
4560 MuxedStreamInfo(kVideoTrackNum, "")); | 4573 MuxedStreamInfo(kVideoTrackNum, "")); |
4561 demuxer_->Remove(kSourceId, base::TimeDelta(), | 4574 demuxer_->Remove(kSourceId, base::TimeDelta(), |
4562 base::TimeDelta::FromMilliseconds(30)); | 4575 base::TimeDelta::FromMilliseconds(30)); |
4563 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "30K 40K 50D10K"), | 4576 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "30K 40K 50D10K"), |
4564 MuxedStreamInfo(kVideoTrackNum, "30 40 50", 10)); | 4577 MuxedStreamInfo(kVideoTrackNum, "30 40 50", 10)); |
4565 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "60K 70K 80D10K"), | 4578 AppendMuxedCluster(MuxedStreamInfo(kAudioTrackNum, "60K 70K 80D10K"), |
4566 MuxedStreamInfo(kVideoTrackNum, "60 70K 80", 10)); | 4579 MuxedStreamInfo(kVideoTrackNum, "60 70K 80", 10)); |
(...skipping 10 matching lines...) Expand all Loading... | |
4577 // A:[K K K | 4590 // A:[K K K |
4578 // V:(Nothing yet. This is a jagged start, not simulated.) | 4591 // V:(Nothing yet. This is a jagged start, not simulated.) |
4579 // Remove ***** | 4592 // Remove ***** |
4580 // Append muxed: | 4593 // Append muxed: |
4581 // A: K K K K K K] | 4594 // A: K K K K K K] |
4582 // V: n n n n K n] | 4595 // V: n n n n K n] |
4583 // Expect: | 4596 // Expect: |
4584 // A: [K K K K K K] | 4597 // A: [K K K K K K] |
4585 // V [..............K n] | 4598 // V [..............K n] |
4586 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 4599 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
4587 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4600 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
4588 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4601 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4589 | 4602 |
4590 std::vector<MuxedStreamInfo> msi(2); | 4603 std::vector<MuxedStreamInfo> msi(2); |
4591 msi[0] = | 4604 msi[0] = |
4592 MuxedStreamInfo(kAudioTrackNum, "0K 10K 20K 30K 40K 50K 60K 70K 80D10K"); | 4605 MuxedStreamInfo(kAudioTrackNum, "0K 10K 20K 30K 40K 50K 60K 70K 80D10K"); |
4593 msi[1] = MuxedStreamInfo(kVideoTrackNum, "31 41 51 61 71K 81", 10); | 4606 msi[1] = MuxedStreamInfo(kVideoTrackNum, "31 41 51 61 71K 81", 10); |
4594 std::unique_ptr<Cluster> cluster = GenerateMuxedCluster(msi); | 4607 std::unique_ptr<Cluster> cluster = GenerateMuxedCluster(msi); |
4595 | 4608 |
4596 // Append the first part of the cluster, up to the beginning of the first | 4609 // Append the first part of the cluster, up to the beginning of the first |
4597 // video simpleblock. The result should be just 4 audio blocks and no video | 4610 // video simpleblock. The result should be just 4 audio blocks and no video |
4598 // blocks are appended. Since the stream parser does not yet have a duration | 4611 // blocks are appended. Since the stream parser does not yet have a duration |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4634 } | 4647 } |
4635 | 4648 |
4636 void OnStreamStatusChanged(base::WaitableEvent* event, | 4649 void OnStreamStatusChanged(base::WaitableEvent* event, |
4637 DemuxerStream* stream, | 4650 DemuxerStream* stream, |
4638 bool enabled, | 4651 bool enabled, |
4639 base::TimeDelta) { | 4652 base::TimeDelta) { |
4640 EXPECT_EQ(enabled, stream->enabled()); | 4653 EXPECT_EQ(enabled, stream->enabled()); |
4641 event->Signal(); | 4654 event->Signal(); |
4642 } | 4655 } |
4643 | 4656 |
4644 void CheckStreamStatusNotifications(DemuxerStream* stream) { | 4657 void CheckStreamStatusNotifications(MediaResource* media_resource, |
4658 DemuxerStream* stream) { | |
4645 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 4659 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
4646 base::WaitableEvent::InitialState::NOT_SIGNALED); | 4660 base::WaitableEvent::InitialState::NOT_SIGNALED); |
4647 | 4661 |
4648 ASSERT_TRUE(stream->enabled()); | 4662 ASSERT_TRUE(stream->enabled()); |
4649 stream->SetStreamStatusChangeCB(base::Bind(&OnStreamStatusChanged, | 4663 media_resource->SetStreamStatusChangeCB( |
4650 base::Unretained(&event), | 4664 base::Bind(&OnStreamStatusChanged, base::Unretained(&event))); |
4651 base::Unretained(stream))); | |
4652 | 4665 |
4653 stream->set_enabled(false, base::TimeDelta()); | 4666 stream->set_enabled(false, base::TimeDelta()); |
4654 base::RunLoop().RunUntilIdle(); | 4667 base::RunLoop().RunUntilIdle(); |
4655 ASSERT_TRUE(event.IsSignaled()); | 4668 ASSERT_TRUE(event.IsSignaled()); |
4656 | 4669 |
4657 event.Reset(); | 4670 event.Reset(); |
4658 stream->set_enabled(true, base::TimeDelta()); | 4671 stream->set_enabled(true, base::TimeDelta()); |
4659 base::RunLoop().RunUntilIdle(); | 4672 base::RunLoop().RunUntilIdle(); |
4660 ASSERT_TRUE(event.IsSignaled()); | 4673 ASSERT_TRUE(event.IsSignaled()); |
4661 } | 4674 } |
4662 | 4675 |
4663 TEST_F(ChunkDemuxerTest, StreamStatusNotifications) { | 4676 TEST_F(ChunkDemuxerTest, StreamStatusNotifications) { |
4664 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 4677 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
4665 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 4678 DemuxerStream* audio_stream = GetStream(DemuxerStream::AUDIO); |
4666 EXPECT_NE(nullptr, audio_stream); | 4679 EXPECT_NE(nullptr, audio_stream); |
4667 CheckStreamStatusNotifications(audio_stream); | 4680 CheckStreamStatusNotifications(demuxer_.get(), audio_stream); |
4668 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 4681 DemuxerStream* video_stream = GetStream(DemuxerStream::VIDEO); |
4669 EXPECT_NE(nullptr, video_stream); | 4682 EXPECT_NE(nullptr, video_stream); |
4670 CheckStreamStatusNotifications(video_stream); | 4683 CheckStreamStatusNotifications(demuxer_.get(), video_stream); |
4671 } | 4684 } |
4672 | 4685 |
4673 TEST_F(ChunkDemuxerTest, MultipleIds) { | 4686 TEST_F(ChunkDemuxerTest, MultipleIds) { |
4674 CreateNewDemuxer(); | 4687 CreateNewDemuxer(); |
4675 EXPECT_CALL(*this, DemuxerOpened()); | 4688 EXPECT_CALL(*this, DemuxerOpened()); |
4676 EXPECT_CALL(host_, SetDuration(_)).Times(2); | 4689 EXPECT_CALL(host_, SetDuration(_)).Times(2); |
4677 demuxer_->Initialize(&host_, CreateInitDoneCB(kNoTimestamp, PIPELINE_OK), | 4690 demuxer_->Initialize(&host_, CreateInitDoneCB(kNoTimestamp, PIPELINE_OK), |
4678 true); | 4691 true); |
4679 | 4692 |
4680 const char* kId1 = "id1"; | 4693 const char* kId1 = "id1"; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4730 EXPECT_EQ(AddId(kId1, "video/webm", "vorbis,vp8"), ChunkDemuxer::kOk); | 4743 EXPECT_EQ(AddId(kId1, "video/webm", "vorbis,vp8"), ChunkDemuxer::kOk); |
4731 | 4744 |
4732 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); | 4745 EXPECT_CALL(*this, InitSegmentReceivedMock(_)); |
4733 EXPECT_MEDIA_LOG(FoundStream("video")); | 4746 EXPECT_MEDIA_LOG(FoundStream("video")); |
4734 EXPECT_MEDIA_LOG(CodecName("video", "vp8")); | 4747 EXPECT_MEDIA_LOG(CodecName("video", "vp8")); |
4735 EXPECT_MEDIA_LOG(FoundStream("audio")); | 4748 EXPECT_MEDIA_LOG(FoundStream("audio")); |
4736 EXPECT_MEDIA_LOG(CodecName("audio", "vorbis")); | 4749 EXPECT_MEDIA_LOG(CodecName("audio", "vorbis")); |
4737 | 4750 |
4738 // Append init segment to ensure demuxer streams get created. | 4751 // Append init segment to ensure demuxer streams get created. |
4739 ASSERT_TRUE(AppendInitSegmentWithSourceId(kId1, HAS_AUDIO | HAS_VIDEO)); | 4752 ASSERT_TRUE(AppendInitSegmentWithSourceId(kId1, HAS_AUDIO | HAS_VIDEO)); |
4740 EXPECT_NE(nullptr, demuxer_->GetStream(DemuxerStream::AUDIO)); | 4753 EXPECT_NE(nullptr, GetStream(DemuxerStream::AUDIO)); |
4741 EXPECT_NE(nullptr, demuxer_->GetStream(DemuxerStream::VIDEO)); | 4754 EXPECT_NE(nullptr, GetStream(DemuxerStream::VIDEO)); |
4742 | 4755 |
4743 // Removing the id should remove also the DemuxerStreams. | 4756 // Removing the id should remove also the DemuxerStreams. |
4744 demuxer_->RemoveId(kId1); | 4757 demuxer_->RemoveId(kId1); |
4745 EXPECT_EQ(nullptr, demuxer_->GetStream(DemuxerStream::AUDIO)); | 4758 EXPECT_EQ(nullptr, GetStream(DemuxerStream::AUDIO)); |
4746 EXPECT_EQ(nullptr, demuxer_->GetStream(DemuxerStream::VIDEO)); | 4759 EXPECT_EQ(nullptr, GetStream(DemuxerStream::VIDEO)); |
4747 } | 4760 } |
4748 | 4761 |
4749 // TODO(servolk): Add a unit test with multiple audio/video tracks using the | 4762 // TODO(servolk): Add a unit test with multiple audio/video tracks using the |
4750 // same codec type in a single SourceBufferState, when WebM parser supports | 4763 // same codec type in a single SourceBufferState, when WebM parser supports |
4751 // multiple tracks. crbug.com/646900 | 4764 // multiple tracks. crbug.com/646900 |
4752 | 4765 |
4753 class ChunkDemuxerMp4Vp9Test : public ChunkDemuxerTest, | 4766 class ChunkDemuxerMp4Vp9Test : public ChunkDemuxerTest, |
4754 public WithParamInterface<bool> { | 4767 public WithParamInterface<bool> { |
4755 public: | 4768 public: |
4756 void SetUp() override { | 4769 void SetUp() override { |
(...skipping 22 matching lines...) Expand all Loading... | |
4779 EXPECT_EQ( | 4792 EXPECT_EQ( |
4780 demuxer_->AddId("source_id", "video/mp4", "vp09.00.01.08.02.01.01.00"), | 4793 demuxer_->AddId("source_id", "video/mp4", "vp09.00.01.08.02.01.01.00"), |
4781 expected); | 4794 expected); |
4782 } | 4795 } |
4783 | 4796 |
4784 INSTANTIATE_TEST_CASE_P(EnableDisableMp4Vp9Demuxing, | 4797 INSTANTIATE_TEST_CASE_P(EnableDisableMp4Vp9Demuxing, |
4785 ChunkDemuxerMp4Vp9Test, | 4798 ChunkDemuxerMp4Vp9Test, |
4786 ::testing::Bool()); | 4799 ::testing::Bool()); |
4787 | 4800 |
4788 } // namespace media | 4801 } // namespace media |
OLD | NEW |