Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 cb.AddBlockGroup(track_number, timestamp_in_ms, kTextBlockDuration, | 429 cb.AddBlockGroup(track_number, timestamp_in_ms, kTextBlockDuration, |
| 430 block_flags, &data[0], data.size()); | 430 block_flags, &data[0], data.size()); |
| 431 } else { | 431 } else { |
| 432 cb.AddSimpleBlock(track_number, timestamp_in_ms, block_flags, | 432 cb.AddSimpleBlock(track_number, timestamp_in_ms, block_flags, |
| 433 &data[0], data.size()); | 433 &data[0], data.size()); |
| 434 } | 434 } |
| 435 } | 435 } |
| 436 AppendCluster(source_id, cb.Finish()); | 436 AppendCluster(source_id, cb.Finish()); |
| 437 } | 437 } |
| 438 | 438 |
| 439 struct MuxedStreamInfo { | |
| 440 MuxedStreamInfo() | |
| 441 : track_number(0), | |
| 442 cluster_description("") | |
| 443 {} | |
| 444 | |
| 445 MuxedStreamInfo(int track_num, const char* cluster_desc) | |
| 446 : track_number(track_num), | |
| 447 cluster_description(cluster_desc) { | |
| 448 } | |
| 449 | |
| 450 int track_number; | |
| 451 // The cluster description paseed to AppendSingleStreamCluster(). | |
|
wolenetz
2014/07/08 00:47:33
nit: s/paseed/passed/
acolwell GONE FROM CHROMIUM
2014/07/08 03:45:13
Done.
| |
| 452 // See the documentation for that method for details on the string format. | |
| 453 const char* cluster_description; | |
| 454 }; | |
| 455 | |
| 456 void AppendMuxedCluster(const MuxedStreamInfo& msi_1, | |
| 457 const MuxedStreamInfo& msi_2) { | |
| 458 std::vector<MuxedStreamInfo> msi(2); | |
| 459 msi[0] = msi_1; | |
| 460 msi[1] = msi_2; | |
| 461 AppendMuxedCluster(msi); | |
| 462 } | |
| 463 | |
| 464 void AppendMuxedCluster(const MuxedStreamInfo& msi_1, | |
| 465 const MuxedStreamInfo& msi_2, | |
| 466 const MuxedStreamInfo& msi_3) { | |
| 467 std::vector<MuxedStreamInfo> msi(3); | |
| 468 msi[0] = msi_1; | |
| 469 msi[1] = msi_2; | |
| 470 msi[2] = msi_3; | |
| 471 AppendMuxedCluster(msi); | |
| 472 } | |
| 473 | |
| 474 void AppendMuxedCluster(const std::vector<MuxedStreamInfo> msi) { | |
| 475 for (size_t i = 0; i < msi.size(); ++i) { | |
| 476 AppendSingleStreamCluster(kSourceId, | |
| 477 msi[i].track_number, | |
| 478 msi[i].cluster_description); | |
| 479 } | |
| 480 } | |
| 481 | |
| 439 void AppendData(const std::string& source_id, | 482 void AppendData(const std::string& source_id, |
| 440 const uint8* data, size_t length) { | 483 const uint8* data, size_t length) { |
| 441 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); | 484 EXPECT_CALL(host_, AddBufferedTimeRange(_, _)).Times(AnyNumber()); |
| 442 | 485 |
| 443 demuxer_->AppendData(source_id, data, length, | 486 demuxer_->AppendData(source_id, data, length, |
| 444 append_window_start_for_next_append_, | 487 append_window_start_for_next_append_, |
| 445 append_window_end_for_next_append_, | 488 append_window_end_for_next_append_, |
| 446 ×tamp_offset_map_[source_id]); | 489 ×tamp_offset_map_[source_id]); |
| 447 } | 490 } |
| 448 | 491 |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 .WillOnce(DoAll(SaveArg<0>(&text_stream), | 1234 .WillOnce(DoAll(SaveArg<0>(&text_stream), |
| 1192 SaveArg<1>(&text_config))); | 1235 SaveArg<1>(&text_config))); |
| 1193 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( | 1236 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( |
| 1194 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); | 1237 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); |
| 1195 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1238 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 1196 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1239 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 1197 ASSERT_TRUE(audio_stream); | 1240 ASSERT_TRUE(audio_stream); |
| 1198 ASSERT_TRUE(video_stream); | 1241 ASSERT_TRUE(video_stream); |
| 1199 ASSERT_TRUE(text_stream); | 1242 ASSERT_TRUE(text_stream); |
| 1200 | 1243 |
| 1201 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K"); | 1244 AppendMuxedCluster( |
| 1202 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 30"); | 1245 { kAudioTrackNum, "0K 23K" }, |
|
wolenetz
2014/07/08 00:47:33
nit: linux*rel bots are still complaining about ex
acolwell GONE FROM CHROMIUM
2014/07/08 03:45:13
Done.
| |
| 1203 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "10K"); | 1246 { kVideoTrackNum, "0K 30" }, |
| 1247 { kTextTrackNum, "10K" }); | |
| 1204 CheckExpectedRanges(kSourceId, "{ [0,46) }"); | 1248 CheckExpectedRanges(kSourceId, "{ [0,46) }"); |
| 1205 | 1249 |
| 1206 scoped_ptr<uint8[]> info_tracks; | 1250 scoped_ptr<uint8[]> info_tracks; |
| 1207 int info_tracks_size = 0; | 1251 int info_tracks_size = 0; |
| 1208 CreateInitSegmentWithAlternateTextTrackNum(HAS_TEXT | HAS_AUDIO | HAS_VIDEO, | 1252 CreateInitSegmentWithAlternateTextTrackNum(HAS_TEXT | HAS_AUDIO | HAS_VIDEO, |
| 1209 false, false, | 1253 false, false, |
| 1210 &info_tracks, &info_tracks_size); | 1254 &info_tracks, &info_tracks_size); |
| 1211 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, | 1255 demuxer_->AppendData(kSourceId, info_tracks.get(), info_tracks_size, |
| 1212 append_window_start_for_next_append_, | 1256 append_window_start_for_next_append_, |
| 1213 append_window_end_for_next_append_, | 1257 append_window_end_for_next_append_, |
| 1214 ×tamp_offset_map_[kSourceId]); | 1258 ×tamp_offset_map_[kSourceId]); |
| 1215 | 1259 |
| 1216 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "46K 69K"); | 1260 AppendMuxedCluster( |
| 1217 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "60K"); | 1261 { kAudioTrackNum, "46K 69K" }, |
| 1218 AppendSingleStreamCluster(kSourceId, kAlternateTextTrackNum, "45K"); | 1262 { kVideoTrackNum, "60K" }, |
| 1263 { kAlternateTextTrackNum, "45K" }); | |
| 1219 | 1264 |
| 1220 CheckExpectedRanges(kSourceId, "{ [0,92) }"); | 1265 CheckExpectedRanges(kSourceId, "{ [0,92) }"); |
| 1221 CheckExpectedBuffers(audio_stream, "0 23 46 69"); | 1266 CheckExpectedBuffers(audio_stream, "0 23 46 69"); |
| 1222 CheckExpectedBuffers(video_stream, "0 30 60"); | 1267 CheckExpectedBuffers(video_stream, "0 30 60"); |
| 1223 CheckExpectedBuffers(text_stream, "10 45"); | 1268 CheckExpectedBuffers(text_stream, "10 45"); |
| 1224 | 1269 |
| 1225 ShutdownDemuxer(); | 1270 ShutdownDemuxer(); |
| 1226 } | 1271 } |
| 1227 | 1272 |
| 1228 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) { | 1273 TEST_F(ChunkDemuxerTest, InitSegmentSetsNeedRandomAccessPointFlag) { |
| 1229 // Tests that non-keyframes following an init segment are allowed | 1274 // Tests that non-keyframes following an init segment are allowed |
| 1230 // and dropped, as expected if the initialization segment received | 1275 // and dropped, as expected if the initialization segment received |
| 1231 // algorithm correctly sets the needs random access point flag to true for all | 1276 // algorithm correctly sets the needs random access point flag to true for all |
| 1232 // track buffers. Note that the first initialization segment is insufficient | 1277 // track buffers. Note that the first initialization segment is insufficient |
| 1233 // to fully test this since needs random access point flag initializes to | 1278 // to fully test this since needs random access point flag initializes to |
| 1234 // true. | 1279 // true. |
| 1235 CreateNewDemuxer(); | 1280 CreateNewDemuxer(); |
| 1236 DemuxerStream* text_stream = NULL; | 1281 DemuxerStream* text_stream = NULL; |
| 1237 EXPECT_CALL(host_, AddTextStream(_, _)) | 1282 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 1238 .WillOnce(SaveArg<0>(&text_stream)); | 1283 .WillOnce(SaveArg<0>(&text_stream)); |
| 1239 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( | 1284 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( |
| 1240 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); | 1285 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); |
| 1241 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1286 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 1242 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1287 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 1243 ASSERT_TRUE(audio_stream && video_stream && text_stream); | 1288 ASSERT_TRUE(audio_stream && video_stream && text_stream); |
| 1244 | 1289 |
| 1245 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0 23K"); | 1290 AppendMuxedCluster( |
| 1246 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0 30K"); | 1291 { kAudioTrackNum, "0 23K" }, |
| 1247 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0 40K"); | 1292 { kVideoTrackNum, "0 30K" }, |
| 1293 { kTextTrackNum, "0 40K" }); | |
| 1248 CheckExpectedRanges(kSourceId, "{ [30,46) }"); | 1294 CheckExpectedRanges(kSourceId, "{ [30,46) }"); |
| 1249 | 1295 |
| 1250 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); | 1296 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); |
| 1251 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "46 69K"); | 1297 AppendMuxedCluster( |
| 1252 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "60 90K"); | 1298 { kAudioTrackNum, "46 69K" }, |
| 1253 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "80 90K"); | 1299 { kVideoTrackNum, "60 90K" }, |
| 1300 { kTextTrackNum, "80 90K" }); | |
| 1254 CheckExpectedRanges(kSourceId, "{ [30,92) }"); | 1301 CheckExpectedRanges(kSourceId, "{ [30,92) }"); |
| 1255 | 1302 |
| 1256 CheckExpectedBuffers(audio_stream, "23 69"); | 1303 CheckExpectedBuffers(audio_stream, "23 69"); |
| 1257 CheckExpectedBuffers(video_stream, "30 90"); | 1304 CheckExpectedBuffers(video_stream, "30 90"); |
| 1258 | 1305 |
| 1259 // WebM parser marks all text buffers as keyframes. | 1306 // WebM parser marks all text buffers as keyframes. |
| 1260 CheckExpectedBuffers(text_stream, "0 40 80 90"); | 1307 CheckExpectedBuffers(text_stream, "0 40 80 90"); |
| 1261 } | 1308 } |
| 1262 | 1309 |
| 1263 // Make sure that the demuxer reports an error if Shutdown() | 1310 // Make sure that the demuxer reports an error if Shutdown() |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1723 } | 1770 } |
| 1724 | 1771 |
| 1725 // Verify buffered range change behavior for audio/video/text tracks. | 1772 // Verify buffered range change behavior for audio/video/text tracks. |
| 1726 TEST_F(ChunkDemuxerTest, EndOfStreamRangeChanges) { | 1773 TEST_F(ChunkDemuxerTest, EndOfStreamRangeChanges) { |
| 1727 DemuxerStream* text_stream = NULL; | 1774 DemuxerStream* text_stream = NULL; |
| 1728 | 1775 |
| 1729 EXPECT_CALL(host_, AddTextStream(_, _)) | 1776 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 1730 .WillOnce(SaveArg<0>(&text_stream)); | 1777 .WillOnce(SaveArg<0>(&text_stream)); |
| 1731 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 1778 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
| 1732 | 1779 |
| 1733 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); | 1780 AppendMuxedCluster( |
| 1734 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K"); | 1781 { kVideoTrackNum, "0K 33" }, |
| 1782 { kAudioTrackNum, "0K 23K" }); | |
| 1735 | 1783 |
| 1736 // Check expected ranges and verify that an empty text track does not | 1784 // Check expected ranges and verify that an empty text track does not |
| 1737 // affect the expected ranges. | 1785 // affect the expected ranges. |
| 1738 CheckExpectedRanges(kSourceId, "{ [0,46) }"); | 1786 CheckExpectedRanges(kSourceId, "{ [0,46) }"); |
| 1739 | 1787 |
| 1740 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66))); | 1788 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66))); |
| 1741 MarkEndOfStream(PIPELINE_OK); | 1789 MarkEndOfStream(PIPELINE_OK); |
| 1742 | 1790 |
| 1743 // Check expected ranges and verify that an empty text track does not | 1791 // Check expected ranges and verify that an empty text track does not |
| 1744 // affect the expected ranges. | 1792 // affect the expected ranges. |
| 1745 CheckExpectedRanges(kSourceId, "{ [0,66) }"); | 1793 CheckExpectedRanges(kSourceId, "{ [0,66) }"); |
| 1746 | 1794 |
| 1747 // Unmark end of stream state and verify that the ranges return to | 1795 // Unmark end of stream state and verify that the ranges return to |
| 1748 // their pre-"end of stream" values. | 1796 // their pre-"end of stream" values. |
| 1749 demuxer_->UnmarkEndOfStream(); | 1797 demuxer_->UnmarkEndOfStream(); |
| 1750 CheckExpectedRanges(kSourceId, "{ [0,46) }"); | 1798 CheckExpectedRanges(kSourceId, "{ [0,46) }"); |
| 1751 | 1799 |
| 1752 // Add text track data and verify that the buffered ranges don't change | 1800 // Add text track data and verify that the buffered ranges don't change |
| 1753 // since the intersection of all the tracks doesn't change. | 1801 // since the intersection of all the tracks doesn't change. |
| 1754 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(200))); | 1802 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(200))); |
| 1755 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K"); | 1803 AppendMuxedCluster( |
| 1804 { kVideoTrackNum, "0K 33" }, | |
| 1805 { kAudioTrackNum, "0K 23K" }, | |
| 1806 { kTextTrackNum, "0K 100K" }); | |
| 1756 CheckExpectedRanges(kSourceId, "{ [0,46) }"); | 1807 CheckExpectedRanges(kSourceId, "{ [0,46) }"); |
| 1757 | 1808 |
| 1758 // Mark end of stream and verify that text track data is reflected in | 1809 // Mark end of stream and verify that text track data is reflected in |
| 1759 // the new range. | 1810 // the new range. |
| 1760 MarkEndOfStream(PIPELINE_OK); | 1811 MarkEndOfStream(PIPELINE_OK); |
| 1761 CheckExpectedRanges(kSourceId, "{ [0,200) }"); | 1812 CheckExpectedRanges(kSourceId, "{ [0,200) }"); |
| 1762 } | 1813 } |
| 1763 | 1814 |
| 1764 // Make sure AppendData() will accept elements that span multiple calls. | 1815 // Make sure AppendData() will accept elements that span multiple calls. |
| 1765 TEST_F(ChunkDemuxerTest, AppendingInPieces) { | 1816 TEST_F(ChunkDemuxerTest, AppendingInPieces) { |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2362 // buffered ranges. | 2413 // buffered ranges. |
| 2363 AppendCluster(GenerateSingleStreamCluster(1230, 1240, kVideoTrackNum, 10)); | 2414 AppendCluster(GenerateSingleStreamCluster(1230, 1240, kVideoTrackNum, 10)); |
| 2364 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); | 2415 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); |
| 2365 } | 2416 } |
| 2366 | 2417 |
| 2367 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) { | 2418 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) { |
| 2368 EXPECT_CALL(host_, AddTextStream(_, _)); | 2419 EXPECT_CALL(host_, AddTextStream(_, _)); |
| 2369 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 2420 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
| 2370 | 2421 |
| 2371 // Append audio & video data | 2422 // Append audio & video data |
| 2372 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23"); | 2423 AppendMuxedCluster( |
| 2373 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); | 2424 { kAudioTrackNum, "0K 23" }, |
| 2425 { kVideoTrackNum, "0K 33" }); | |
| 2374 | 2426 |
| 2375 // Verify that a text track with no cues does not result in an empty buffered | 2427 // Verify that a text track with no cues does not result in an empty buffered |
| 2376 // range. | 2428 // range. |
| 2377 CheckExpectedRanges("{ [0,46) }"); | 2429 CheckExpectedRanges("{ [0,46) }"); |
| 2378 | 2430 |
| 2379 // Add some text cues. | 2431 // Add some text cues. |
| 2380 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K"); | 2432 AppendMuxedCluster( |
| 2433 { kAudioTrackNum, "100K 123" }, | |
| 2434 { kVideoTrackNum, "100K 133" }, | |
| 2435 { kTextTrackNum, "100K 200K" }); | |
| 2381 | 2436 |
| 2382 // Verify that the new cues did not affect the buffered ranges. | 2437 // Verify that the text cues are not reflected in the buffered ranges. |
| 2383 CheckExpectedRanges("{ [0,46) }"); | 2438 CheckExpectedRanges("{ [0,46) [100,146) }"); |
| 2384 | 2439 |
| 2385 // Remove the buffered range. | 2440 // Remove the buffered ranges. |
| 2386 demuxer_->Remove(kSourceId, base::TimeDelta(), | 2441 demuxer_->Remove(kSourceId, base::TimeDelta(), |
| 2387 base::TimeDelta::FromMilliseconds(46)); | 2442 base::TimeDelta::FromMilliseconds(250)); |
| 2388 CheckExpectedRanges("{ }"); | 2443 CheckExpectedRanges("{ }"); |
| 2389 } | 2444 } |
| 2390 | 2445 |
| 2391 // Once MarkEndOfStream() is called, GetBufferedRanges should not cut off any | 2446 // Once MarkEndOfStream() is called, GetBufferedRanges should not cut off any |
| 2392 // over-hanging tails at the end of the ranges as this is likely due to block | 2447 // over-hanging tails at the end of the ranges as this is likely due to block |
| 2393 // duration differences. | 2448 // duration differences. |
| 2394 TEST_F(ChunkDemuxerTest, GetBufferedRanges_EndOfStream) { | 2449 TEST_F(ChunkDemuxerTest, GetBufferedRanges_EndOfStream) { |
| 2395 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2450 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2396 | 2451 |
| 2397 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K 23K"); | 2452 AppendMuxedCluster( |
| 2398 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "0K 33"); | 2453 { kAudioTrackNum, "0K 23K" }, |
| 2454 { kVideoTrackNum, "0K 33" }); | |
| 2399 | 2455 |
| 2400 CheckExpectedRanges("{ [0,46) }"); | 2456 CheckExpectedRanges("{ [0,46) }"); |
| 2401 | 2457 |
| 2402 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66))); | 2458 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(66))); |
| 2403 MarkEndOfStream(PIPELINE_OK); | 2459 MarkEndOfStream(PIPELINE_OK); |
| 2404 | 2460 |
| 2405 // Verify that the range extends to the end of the video data. | 2461 // Verify that the range extends to the end of the video data. |
| 2406 CheckExpectedRanges("{ [0,66) }"); | 2462 CheckExpectedRanges("{ [0,66) }"); |
| 2407 | 2463 |
| 2408 // Verify that the range reverts to the intersection when end of stream | 2464 // Verify that the range reverts to the intersection when end of stream |
| 2409 // has been cancelled. | 2465 // has been cancelled. |
| 2410 demuxer_->UnmarkEndOfStream(); | 2466 demuxer_->UnmarkEndOfStream(); |
| 2411 CheckExpectedRanges("{ [0,46) }"); | 2467 CheckExpectedRanges("{ [0,46) }"); |
| 2412 | 2468 |
| 2413 // Append and remove data so that the 2 streams' end ranges do not overlap. | 2469 // Append and remove data so that the 2 streams' end ranges do not overlap. |
| 2414 | 2470 |
| 2415 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(246))); | 2471 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(246))); |
| 2416 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(398))); | 2472 EXPECT_CALL(host_, SetDuration(base::TimeDelta::FromMilliseconds(398))); |
| 2417 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "200K 223K"); | 2473 AppendMuxedCluster( |
| 2418 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 2474 { kAudioTrackNum, "200K 223K" }, |
| 2419 "200K 233 266 299 332K 365"); | 2475 { kVideoTrackNum, "200K 233 266 299 332K 365" }); |
| 2420 | 2476 |
| 2421 // At this point, the per-stream ranges are as follows: | 2477 // At this point, the per-stream ranges are as follows: |
| 2422 // Audio: [0,46) [200,246) | 2478 // Audio: [0,46) [200,246) |
| 2423 // Video: [0,66) [200,398) | 2479 // Video: [0,66) [200,398) |
| 2424 CheckExpectedRanges("{ [0,46) [200,246) }"); | 2480 CheckExpectedRanges("{ [0,46) [200,246) }"); |
| 2425 | 2481 |
| 2426 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(200), | 2482 demuxer_->Remove(kSourceId, base::TimeDelta::FromMilliseconds(200), |
| 2427 base::TimeDelta::FromMilliseconds(300)); | 2483 base::TimeDelta::FromMilliseconds(300)); |
| 2428 | 2484 |
| 2429 // At this point, the per-stream ranges are as follows: | 2485 // At this point, the per-stream ranges are as follows: |
| 2430 // Audio: [0,46) | 2486 // Audio: [0,46) |
| 2431 // Video: [0,66) [332,398) | 2487 // Video: [0,66) [332,398) |
| 2432 CheckExpectedRanges("{ [0,46) }"); | 2488 CheckExpectedRanges("{ [0,46) }"); |
| 2433 | 2489 |
| 2434 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "200K 223K"); | 2490 AppendMuxedCluster( |
| 2435 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, "200K 233"); | 2491 { kAudioTrackNum, "200K 223K" }, |
| 2492 { kVideoTrackNum, "200K 233" }); | |
| 2436 | 2493 |
| 2437 // At this point, the per-stream ranges are as follows: | 2494 // At this point, the per-stream ranges are as follows: |
| 2438 // Audio: [0,46) [200,246) | 2495 // Audio: [0,46) [200,246) |
| 2439 // Video: [0,66) [200,266) [332,398) | 2496 // Video: [0,66) [200,266) [332,398) |
| 2440 // NOTE: The last range on each stream do not overlap in time. | 2497 // NOTE: The last range on each stream do not overlap in time. |
| 2441 CheckExpectedRanges("{ [0,46) [200,246) }"); | 2498 CheckExpectedRanges("{ [0,46) [200,246) }"); |
| 2442 | 2499 |
| 2443 MarkEndOfStream(PIPELINE_OK); | 2500 MarkEndOfStream(PIPELINE_OK); |
| 2444 | 2501 |
| 2445 // NOTE: The last range on each stream gets extended to the highest | 2502 // NOTE: The last range on each stream gets extended to the highest |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3281 .WillOnce(SaveArg<0>(&text_stream)); | 3338 .WillOnce(SaveArg<0>(&text_stream)); |
| 3282 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); | 3339 ASSERT_TRUE(InitDemuxer(HAS_VIDEO | HAS_TEXT)); |
| 3283 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 3340 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 3284 | 3341 |
| 3285 // Set the append window to [20,280). | 3342 // Set the append window to [20,280). |
| 3286 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); | 3343 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(20); |
| 3287 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); | 3344 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(280); |
| 3288 | 3345 |
| 3289 // Append a cluster that starts before and ends after the append | 3346 // Append a cluster that starts before and ends after the append |
| 3290 // window. | 3347 // window. |
| 3291 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 3348 AppendMuxedCluster( |
| 3292 "0K 30 60 90 120K 150 180 210 240K 270 300 330K"); | 3349 { kVideoTrackNum, "0K 30 60 90 120K 150 180 210 240K 270 300 330K" }, |
| 3293 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K 200K 300K"); | 3350 { kTextTrackNum, "0K 100K 200K 300K" }); |
| 3294 | 3351 |
| 3295 // Verify that text cues that start outside the window are not included | 3352 // Verify that text cues that start outside the window are not included |
| 3296 // in the buffer. Also verify that cues that extend beyond the | 3353 // in the buffer. Also verify that cues that extend beyond the |
| 3297 // window are not included. | 3354 // window are not included. |
| 3298 CheckExpectedRanges(kSourceId, "{ [120,270) }"); | 3355 CheckExpectedRanges(kSourceId, "{ [120,270) }"); |
| 3299 CheckExpectedBuffers(video_stream, "120 150 180 210 240"); | 3356 CheckExpectedBuffers(video_stream, "120 150 180 210 240"); |
| 3300 CheckExpectedBuffers(text_stream, "100"); | 3357 CheckExpectedBuffers(text_stream, "100"); |
| 3301 | 3358 |
| 3302 // Extend the append window to [20,650). | 3359 // Extend the append window to [20,650). |
| 3303 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); | 3360 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); |
| 3304 | 3361 |
| 3305 // Append more data and verify that a new range is created. | 3362 // Append more data and verify that a new range is created. |
| 3306 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 3363 AppendMuxedCluster( |
| 3307 "360 390 420K 450 480 510 540K 570 600 630K"); | 3364 { kVideoTrackNum, "360 390 420K 450 480 510 540K 570 600 630K" }, |
| 3308 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "400K 500K 600K 700K"); | 3365 { kTextTrackNum, "400K 500K 600K 700K" }); |
| 3309 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); | 3366 CheckExpectedRanges(kSourceId, "{ [120,270) [420,630) }"); |
| 3310 | 3367 |
| 3311 // Seek to the new range and verify that the expected buffers are returned. | 3368 // Seek to the new range and verify that the expected buffers are returned. |
| 3312 Seek(base::TimeDelta::FromMilliseconds(420)); | 3369 Seek(base::TimeDelta::FromMilliseconds(420)); |
| 3313 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600"); | 3370 CheckExpectedBuffers(video_stream, "420 450 480 510 540 570 600"); |
| 3314 CheckExpectedBuffers(text_stream, "400 500"); | 3371 CheckExpectedBuffers(text_stream, "400 500"); |
| 3315 } | 3372 } |
| 3316 | 3373 |
| 3317 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) { | 3374 TEST_F(ChunkDemuxerTest, StartWaitingForSeekAfterParseError) { |
| 3318 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 3375 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 3319 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); | 3376 EXPECT_CALL(host_, OnDemuxerError(PIPELINE_ERROR_DECODE)); |
| 3320 AppendGarbage(); | 3377 AppendGarbage(); |
| 3321 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50); | 3378 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(50); |
| 3322 demuxer_->StartWaitingForSeek(seek_time); | 3379 demuxer_->StartWaitingForSeek(seek_time); |
| 3323 } | 3380 } |
| 3324 | 3381 |
| 3325 TEST_F(ChunkDemuxerTest, Remove_AudioVideoText) { | 3382 TEST_F(ChunkDemuxerTest, Remove_AudioVideoText) { |
| 3326 DemuxerStream* text_stream = NULL; | 3383 DemuxerStream* text_stream = NULL; |
| 3327 EXPECT_CALL(host_, AddTextStream(_, _)) | 3384 EXPECT_CALL(host_, AddTextStream(_, _)) |
| 3328 .WillOnce(SaveArg<0>(&text_stream)); | 3385 .WillOnce(SaveArg<0>(&text_stream)); |
| 3329 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 3386 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
| 3330 | 3387 |
| 3331 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 3388 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| 3332 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 3389 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
| 3333 | 3390 |
| 3334 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, | 3391 AppendMuxedCluster( |
| 3335 "0K 20K 40K 60K 80K 100K 120K 140K"); | 3392 { kAudioTrackNum, "0K 20K 40K 60K 80K 100K 120K 140K" }, |
| 3336 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 3393 { kVideoTrackNum, "0K 30 60 90 120K 150 180" }, |
| 3337 "0K 30 60 90 120K 150 180"); | 3394 { kTextTrackNum, "0K 100K 200K" }); |
| 3338 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "0K 100K 200K"); | |
| 3339 | 3395 |
| 3340 CheckExpectedBuffers(audio_stream, "0 20 40 60 80 100 120 140"); | 3396 CheckExpectedBuffers(audio_stream, "0 20 40 60 80 100 120 140"); |
| 3341 CheckExpectedBuffers(video_stream, "0 30 60 90 120 150 180"); | 3397 CheckExpectedBuffers(video_stream, "0 30 60 90 120 150 180"); |
| 3342 CheckExpectedBuffers(text_stream, "0 100 200"); | 3398 CheckExpectedBuffers(text_stream, "0 100 200"); |
| 3343 | 3399 |
| 3344 // Remove the buffers that were added. | 3400 // Remove the buffers that were added. |
| 3345 demuxer_->Remove(kSourceId, base::TimeDelta(), | 3401 demuxer_->Remove(kSourceId, base::TimeDelta(), |
| 3346 base::TimeDelta::FromMilliseconds(300)); | 3402 base::TimeDelta::FromMilliseconds(300)); |
| 3347 | 3403 |
| 3348 // Verify that all the appended data has been removed. | 3404 // Verify that all the appended data has been removed. |
| 3349 CheckExpectedRanges(kSourceId, "{ }"); | 3405 CheckExpectedRanges(kSourceId, "{ }"); |
| 3350 | 3406 |
| 3351 // Append new buffers that are clearly different than the original | 3407 // Append new buffers that are clearly different than the original |
| 3352 // ones and verify that only the new buffers are returned. | 3408 // ones and verify that only the new buffers are returned. |
| 3353 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, | 3409 AppendMuxedCluster( |
| 3354 "1K 21K 41K 61K 81K 101K 121K 141K"); | 3410 { kAudioTrackNum, "1K 21K 41K 61K 81K 101K 121K 141K" }, |
| 3355 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 3411 { kVideoTrackNum, "1K 31 61 91 121K 151 181" }, |
| 3356 "1K 31 61 91 121K 151 181"); | 3412 { kTextTrackNum, "1K 101K 201K" }); |
| 3357 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "1K 101K 201K"); | |
| 3358 | 3413 |
| 3359 Seek(base::TimeDelta()); | 3414 Seek(base::TimeDelta()); |
| 3360 CheckExpectedBuffers(audio_stream, "1 21 41 61 81 101 121 141"); | 3415 CheckExpectedBuffers(audio_stream, "1 21 41 61 81 101 121 141"); |
| 3361 CheckExpectedBuffers(video_stream, "1 31 61 91 121 151 181"); | 3416 CheckExpectedBuffers(video_stream, "1 31 61 91 121 151 181"); |
| 3362 CheckExpectedBuffers(text_stream, "1 101 201"); | 3417 CheckExpectedBuffers(text_stream, "1 101 201"); |
| 3363 } | 3418 } |
| 3364 | 3419 |
| 3365 TEST_F(ChunkDemuxerTest, Remove_StartAtDuration) { | 3420 TEST_F(ChunkDemuxerTest, Remove_StartAtDuration) { |
| 3366 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); | 3421 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
| 3367 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 3422 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3405 bool seek_cb_was_called = false; | 3460 bool seek_cb_was_called = false; |
| 3406 demuxer_->StartWaitingForSeek(seek_time); | 3461 demuxer_->StartWaitingForSeek(seek_time); |
| 3407 demuxer_->Seek(seek_time, | 3462 demuxer_->Seek(seek_time, |
| 3408 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); | 3463 base::Bind(OnSeekDone_OKExpected, &seek_cb_was_called)); |
| 3409 message_loop_.RunUntilIdle(); | 3464 message_loop_.RunUntilIdle(); |
| 3410 | 3465 |
| 3411 EXPECT_FALSE(seek_cb_was_called); | 3466 EXPECT_FALSE(seek_cb_was_called); |
| 3412 | 3467 |
| 3413 bool text_read_done = false; | 3468 bool text_read_done = false; |
| 3414 text_stream->Read(base::Bind(&OnReadDone, | 3469 text_stream->Read(base::Bind(&OnReadDone, |
| 3415 base::TimeDelta::FromMilliseconds(125), | 3470 base::TimeDelta::FromMilliseconds(225), |
| 3416 &text_read_done)); | 3471 &text_read_done)); |
| 3417 | 3472 |
| 3418 // Append audio & video data so the seek completes. | 3473 // Append audio & video data so the seek completes. |
| 3419 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, | 3474 AppendMuxedCluster( |
| 3420 "0K 20K 40K 60K 80K 100K 120K 140K 160K 180K"); | 3475 { kAudioTrackNum, "0K 20K 40K 60K 80K 100K 120K 140K 160K 180K 200K" }, |
| 3421 AppendSingleStreamCluster(kSourceId, kVideoTrackNum, | 3476 { kVideoTrackNum, "0K 30 60 90 120K 150 180 210" }); |
| 3422 "0K 30 60 90 120K 150 180 210"); | |
| 3423 | 3477 |
| 3424 message_loop_.RunUntilIdle(); | 3478 message_loop_.RunUntilIdle(); |
| 3425 EXPECT_TRUE(seek_cb_was_called); | 3479 EXPECT_TRUE(seek_cb_was_called); |
| 3426 EXPECT_FALSE(text_read_done); | 3480 EXPECT_FALSE(text_read_done); |
| 3427 | 3481 |
| 3428 // Read some audio & video buffers to further verify seek completion. | 3482 // Read some audio & video buffers to further verify seek completion. |
| 3429 CheckExpectedBuffers(audio_stream, "120 140"); | 3483 CheckExpectedBuffers(audio_stream, "120 140"); |
| 3430 CheckExpectedBuffers(video_stream, "120 150"); | 3484 CheckExpectedBuffers(video_stream, "120 150"); |
| 3431 | 3485 |
| 3432 EXPECT_FALSE(text_read_done); | 3486 EXPECT_FALSE(text_read_done); |
| 3433 | 3487 |
| 3434 // Append text cues that start after the seek point and verify that | 3488 // Append text cues that start after the seek point and verify that |
| 3435 // they are returned by Read() calls. | 3489 // they are returned by Read() calls. |
| 3436 AppendSingleStreamCluster(kSourceId, kTextTrackNum, "125K 175K 225K"); | 3490 AppendMuxedCluster( |
| 3491 { kAudioTrackNum, "220K 240K 260K 280K" }, | |
| 3492 { kVideoTrackNum, "240K 270 300 330" }, | |
| 3493 { kTextTrackNum, "225K 275K 325K" }); | |
| 3437 | 3494 |
| 3438 message_loop_.RunUntilIdle(); | 3495 message_loop_.RunUntilIdle(); |
| 3439 EXPECT_TRUE(text_read_done); | 3496 EXPECT_TRUE(text_read_done); |
| 3440 | 3497 |
| 3441 // NOTE: we start at 175 here because the buffer at 125 was returned | 3498 // NOTE: we start at 175 here because the buffer at 125 was returned |
|
wolenetz
2014/07/08 00:47:33
nit: s/175/275/ and s/125/225/
| |
| 3442 // to the pending read initiated above. | 3499 // to the pending read initiated above. |
| 3443 CheckExpectedBuffers(text_stream, "175 225"); | 3500 CheckExpectedBuffers(text_stream, "275 325"); |
| 3444 | 3501 |
| 3445 // Verify that audio & video streams continue to return expected values. | 3502 // Verify that audio & video streams continue to return expected values. |
| 3446 CheckExpectedBuffers(audio_stream, "160 180"); | 3503 CheckExpectedBuffers(audio_stream, "160 180"); |
| 3447 CheckExpectedBuffers(video_stream, "180 210"); | 3504 CheckExpectedBuffers(video_stream, "180 210"); |
| 3448 } | 3505 } |
| 3449 | 3506 |
| 3450 TEST_F(ChunkDemuxerTest, ClusterWithUnknownSize) { | 3507 TEST_F(ChunkDemuxerTest, ClusterWithUnknownSize) { |
| 3451 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 3508 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 3452 | 3509 |
| 3453 AppendCluster(GenerateCluster(0, 0, 4, true)); | 3510 AppendCluster(GenerateCluster(0, 0, 4, true)); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 3475 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { | 3532 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { |
| 3476 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 3533 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 3477 | 3534 |
| 3478 AppendCluster(GenerateCluster(0, 0, 4)); | 3535 AppendCluster(GenerateCluster(0, 0, 4)); |
| 3479 AppendData(kCuesHeader, sizeof(kCuesHeader)); | 3536 AppendData(kCuesHeader, sizeof(kCuesHeader)); |
| 3480 AppendCluster(GenerateCluster(46, 66, 5)); | 3537 AppendCluster(GenerateCluster(46, 66, 5)); |
| 3481 CheckExpectedRanges(kSourceId, "{ [0,115) }"); | 3538 CheckExpectedRanges(kSourceId, "{ [0,115) }"); |
| 3482 } | 3539 } |
| 3483 | 3540 |
| 3484 } // namespace media | 3541 } // namespace media |
| OLD | NEW |