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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 451 |
452 if (track_number == kTextTrackNum || | 452 if (track_number == kTextTrackNum || |
453 track_number == kAlternateTextTrackNum) { | 453 track_number == kAlternateTextTrackNum) { |
454 block_info.duration = kTextBlockDuration; | 454 block_info.duration = kTextBlockDuration; |
455 ASSERT_EQ(kWebMFlagKeyframe, block_info.flags) | 455 ASSERT_EQ(kWebMFlagKeyframe, block_info.flags) |
456 << "Text block with timestamp " << block_info.timestamp_in_ms | 456 << "Text block with timestamp " << block_info.timestamp_in_ms |
457 << " was not marked as a keyframe." | 457 << " was not marked as a keyframe." |
458 << " All text blocks must be keyframes"; | 458 << " All text blocks must be keyframes"; |
459 } | 459 } |
460 | 460 |
| 461 if (track_number == kAudioTrackNum) |
| 462 ASSERT_TRUE(block_info.flags & kWebMFlagKeyframe); |
| 463 |
461 blocks->push_back(block_info); | 464 blocks->push_back(block_info); |
462 } | 465 } |
463 } | 466 } |
464 | 467 |
465 scoped_ptr<Cluster> GenerateCluster(const std::vector<BlockInfo>& blocks, | 468 scoped_ptr<Cluster> GenerateCluster(const std::vector<BlockInfo>& blocks, |
466 bool unknown_size) { | 469 bool unknown_size) { |
467 DCHECK_GT(blocks.size(), 0u); | 470 DCHECK_GT(blocks.size(), 0u); |
468 ClusterBuilder cb; | 471 ClusterBuilder cb; |
469 | 472 |
470 std::vector<uint8> data(10); | 473 std::vector<uint8> data(10); |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 DemuxerStream* text_stream = NULL; | 1366 DemuxerStream* text_stream = NULL; |
1364 EXPECT_CALL(host_, AddTextStream(_, _)) | 1367 EXPECT_CALL(host_, AddTextStream(_, _)) |
1365 .WillOnce(SaveArg<0>(&text_stream)); | 1368 .WillOnce(SaveArg<0>(&text_stream)); |
1366 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( | 1369 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( |
1367 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); | 1370 HAS_TEXT | HAS_AUDIO | HAS_VIDEO, false, false)); |
1368 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); | 1371 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO); |
1369 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); | 1372 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO); |
1370 ASSERT_TRUE(audio_stream && video_stream && text_stream); | 1373 ASSERT_TRUE(audio_stream && video_stream && text_stream); |
1371 | 1374 |
1372 AppendMuxedCluster( | 1375 AppendMuxedCluster( |
1373 MuxedStreamInfo(kAudioTrackNum, "0 23K"), | 1376 MuxedStreamInfo(kAudioTrackNum, "23K"), |
1374 MuxedStreamInfo(kVideoTrackNum, "0 30K"), | 1377 MuxedStreamInfo(kVideoTrackNum, "0 30K"), |
1375 MuxedStreamInfo(kTextTrackNum, "25K 40K")); | 1378 MuxedStreamInfo(kTextTrackNum, "25K 40K")); |
1376 CheckExpectedRanges(kSourceId, "{ [23,46) }"); | 1379 CheckExpectedRanges(kSourceId, "{ [23,46) }"); |
1377 | 1380 |
1378 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); | 1381 AppendInitSegment(HAS_TEXT | HAS_AUDIO | HAS_VIDEO); |
1379 AppendMuxedCluster( | 1382 AppendMuxedCluster( |
1380 MuxedStreamInfo(kAudioTrackNum, "46 69K"), | 1383 MuxedStreamInfo(kAudioTrackNum, "46K 69K"), |
1381 MuxedStreamInfo(kVideoTrackNum, "60 90K"), | 1384 MuxedStreamInfo(kVideoTrackNum, "60 90K"), |
1382 MuxedStreamInfo(kTextTrackNum, "80K 90K")); | 1385 MuxedStreamInfo(kTextTrackNum, "80K 90K")); |
1383 CheckExpectedRanges(kSourceId, "{ [23,92) }"); | 1386 CheckExpectedRanges(kSourceId, "{ [23,92) }"); |
1384 | 1387 |
1385 CheckExpectedBuffers(audio_stream, "23 69"); | 1388 CheckExpectedBuffers(audio_stream, "23 46 69"); |
1386 CheckExpectedBuffers(video_stream, "30 90"); | 1389 CheckExpectedBuffers(video_stream, "30 90"); |
1387 CheckExpectedBuffers(text_stream, "25 40 80 90"); | 1390 CheckExpectedBuffers(text_stream, "25 40 80 90"); |
1388 } | 1391 } |
1389 | 1392 |
1390 // Make sure that the demuxer reports an error if Shutdown() | 1393 // Make sure that the demuxer reports an error if Shutdown() |
1391 // is called before all the initialization segments are appended. | 1394 // is called before all the initialization segments are appended. |
1392 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { | 1395 TEST_F(ChunkDemuxerTest, Shutdown_BeforeAllInitSegmentsAppended) { |
1393 EXPECT_CALL(*this, DemuxerOpened()); | 1396 EXPECT_CALL(*this, DemuxerOpened()); |
1394 demuxer_->Initialize( | 1397 demuxer_->Initialize( |
1395 &host_, CreateInitDoneCB( | 1398 &host_, CreateInitDoneCB( |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2494 AppendCluster(GenerateSingleStreamCluster(1230, 1240, kVideoTrackNum, 10)); | 2497 AppendCluster(GenerateSingleStreamCluster(1230, 1240, kVideoTrackNum, 10)); |
2495 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); | 2498 CheckExpectedRanges("{ [0,23) [320,400) [520,570) [720,750) [920,950) }"); |
2496 } | 2499 } |
2497 | 2500 |
2498 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) { | 2501 TEST_F(ChunkDemuxerTest, GetBufferedRanges_AudioVideoText) { |
2499 EXPECT_CALL(host_, AddTextStream(_, _)); | 2502 EXPECT_CALL(host_, AddTextStream(_, _)); |
2500 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); | 2503 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO | HAS_TEXT)); |
2501 | 2504 |
2502 // Append audio & video data | 2505 // Append audio & video data |
2503 AppendMuxedCluster( | 2506 AppendMuxedCluster( |
2504 MuxedStreamInfo(kAudioTrackNum, "0K 23"), | 2507 MuxedStreamInfo(kAudioTrackNum, "0K 23K"), |
2505 MuxedStreamInfo(kVideoTrackNum, "0K 33")); | 2508 MuxedStreamInfo(kVideoTrackNum, "0K 33")); |
2506 | 2509 |
2507 // Verify that a text track with no cues does not result in an empty buffered | 2510 // Verify that a text track with no cues does not result in an empty buffered |
2508 // range. | 2511 // range. |
2509 CheckExpectedRanges("{ [0,46) }"); | 2512 CheckExpectedRanges("{ [0,46) }"); |
2510 | 2513 |
2511 // Add some text cues. | 2514 // Add some text cues. |
2512 AppendMuxedCluster( | 2515 AppendMuxedCluster( |
2513 MuxedStreamInfo(kAudioTrackNum, "100K 123"), | 2516 MuxedStreamInfo(kAudioTrackNum, "100K 123K"), |
2514 MuxedStreamInfo(kVideoTrackNum, "100K 133"), | 2517 MuxedStreamInfo(kVideoTrackNum, "100K 133"), |
2515 MuxedStreamInfo(kTextTrackNum, "100K 200K")); | 2518 MuxedStreamInfo(kTextTrackNum, "100K 200K")); |
2516 | 2519 |
2517 // Verify that the text cues are not reflected in the buffered ranges. | 2520 // Verify that the text cues are not reflected in the buffered ranges. |
2518 CheckExpectedRanges("{ [0,46) [100,146) }"); | 2521 CheckExpectedRanges("{ [0,46) [100,146) }"); |
2519 | 2522 |
2520 // Remove the buffered ranges. | 2523 // Remove the buffered ranges. |
2521 demuxer_->Remove(kSourceId, base::TimeDelta(), | 2524 demuxer_->Remove(kSourceId, base::TimeDelta(), |
2522 base::TimeDelta::FromMilliseconds(250)); | 2525 base::TimeDelta::FromMilliseconds(250)); |
2523 CheckExpectedRanges("{ }"); | 2526 CheckExpectedRanges("{ }"); |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3349 AppendSingleStreamCluster( | 3352 AppendSingleStreamCluster( |
3350 kSourceId, kAudioTrackNum, | 3353 kSourceId, kAudioTrackNum, |
3351 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); | 3354 "0K 30K 60K 90K 120K 150K 180K 210K 240K 270K 300K 330K"); |
3352 | 3355 |
3353 // Verify that frames that end outside the window are not included | 3356 // Verify that frames that end outside the window are not included |
3354 // in the buffer. Also verify that buffers that start inside the | 3357 // in the buffer. Also verify that buffers that start inside the |
3355 // window and extend beyond the end of the window are not included. | 3358 // window and extend beyond the end of the window are not included. |
3356 // | 3359 // |
3357 // The first 50ms of the range should be truncated since it overlaps | 3360 // The first 50ms of the range should be truncated since it overlaps |
3358 // the start of the append window. | 3361 // the start of the append window. |
3359 CheckExpectedRanges(kSourceId, "{ [50,270) }"); | 3362 CheckExpectedRanges(kSourceId, "{ [50,280) }"); |
3360 | 3363 |
3361 // The "50P" buffer is the "0" buffer marked for complete discard. The next | 3364 // The "50P" buffer is the "0" buffer marked for complete discard. The next |
3362 // "50" buffer is the "30" buffer marked with 20ms of start discard. | 3365 // "50" buffer is the "30" buffer marked with 20ms of start discard. |
3363 CheckExpectedBuffers(stream, "50P 50 60 90 120 150 180 210 240"); | 3366 CheckExpectedBuffers(stream, "50P 50 60 90 120 150 180 210 240"); |
3364 | 3367 |
3365 // Extend the append window to [50,650). | 3368 // Extend the append window to [50,650). |
3366 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); | 3369 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(650); |
3367 | 3370 |
3368 // Append more data and verify that a new range is created. | 3371 // Append more data and verify that a new range is created. |
3369 AppendSingleStreamCluster( | 3372 AppendSingleStreamCluster( |
3370 kSourceId, kAudioTrackNum, | 3373 kSourceId, kAudioTrackNum, |
3371 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); | 3374 "360K 390K 420K 450K 480K 510K 540K 570K 600K 630K"); |
3372 CheckExpectedRanges(kSourceId, "{ [50,270) [360,630) }"); | 3375 CheckExpectedRanges(kSourceId, "{ [50,280) [360,650) }"); |
3373 } | 3376 } |
3374 | 3377 |
3375 TEST_F(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) { | 3378 TEST_F(ChunkDemuxerTest, AppendWindow_AudioOverlapStartAndEnd) { |
3376 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); | 3379 ASSERT_TRUE(InitDemuxer(HAS_AUDIO)); |
3377 | 3380 |
3378 // Set the append window to [10,20). | 3381 // Set the append window to [10,20). |
3379 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10); | 3382 append_window_start_for_next_append_ = base::TimeDelta::FromMilliseconds(10); |
3380 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20); | 3383 append_window_end_for_next_append_ = base::TimeDelta::FromMilliseconds(20); |
3381 | 3384 |
3382 // Append a cluster that starts before and ends after the append window. | 3385 // Append a cluster that starts before and ends after the append window. |
3383 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K"); | 3386 AppendSingleStreamCluster(kSourceId, kAudioTrackNum, "0K"); |
3384 | 3387 |
3385 // Verify that everything is dropped in this case. No partial append should | 3388 // Verify the append is clipped to the append window. |
3386 // be generated. | 3389 CheckExpectedRanges(kSourceId, "{ [10,20) }"); |
3387 CheckExpectedRanges(kSourceId, "{ }"); | |
3388 } | 3390 } |
3389 | 3391 |
3390 TEST_F(ChunkDemuxerTest, AppendWindow_WebMFile_AudioOnly) { | 3392 TEST_F(ChunkDemuxerTest, AppendWindow_WebMFile_AudioOnly) { |
3391 EXPECT_CALL(*this, DemuxerOpened()); | 3393 EXPECT_CALL(*this, DemuxerOpened()); |
3392 demuxer_->Initialize( | 3394 demuxer_->Initialize( |
3393 &host_, | 3395 &host_, |
3394 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), | 3396 CreateInitDoneCB(base::TimeDelta::FromMilliseconds(2744), PIPELINE_OK), |
3395 true); | 3397 true); |
3396 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); | 3398 ASSERT_EQ(ChunkDemuxer::kOk, AddId(kSourceId, HAS_AUDIO)); |
3397 | 3399 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3653 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { | 3655 TEST_F(ChunkDemuxerTest, CuesBetweenClusters) { |
3654 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 3656 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
3655 | 3657 |
3656 AppendCluster(GenerateCluster(0, 0, 4)); | 3658 AppendCluster(GenerateCluster(0, 0, 4)); |
3657 AppendData(kCuesHeader, sizeof(kCuesHeader)); | 3659 AppendData(kCuesHeader, sizeof(kCuesHeader)); |
3658 AppendCluster(GenerateCluster(46, 66, 5)); | 3660 AppendCluster(GenerateCluster(46, 66, 5)); |
3659 CheckExpectedRanges(kSourceId, "{ [0,115) }"); | 3661 CheckExpectedRanges(kSourceId, "{ [0,115) }"); |
3660 } | 3662 } |
3661 | 3663 |
3662 } // namespace media | 3664 } // namespace media |
OLD | NEW |