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 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 const uint8* data = | 666 const uint8* data = |
667 (flags & kWebMFlagKeyframe) != 0 ? kVP8Keyframe : kVP8Interframe; | 667 (flags & kWebMFlagKeyframe) != 0 ? kVP8Keyframe : kVP8Interframe; |
668 int size = (flags & kWebMFlagKeyframe) != 0 ? sizeof(kVP8Keyframe) : | 668 int size = (flags & kWebMFlagKeyframe) != 0 ? sizeof(kVP8Keyframe) : |
669 sizeof(kVP8Interframe); | 669 sizeof(kVP8Interframe); |
670 cb->AddBlockGroup(track_num, timecode, duration, flags, data, size); | 670 cb->AddBlockGroup(track_num, timecode, duration, flags, data, size); |
671 } | 671 } |
672 | 672 |
673 scoped_ptr<Cluster> GenerateCluster(int first_audio_timecode, | 673 scoped_ptr<Cluster> GenerateCluster(int first_audio_timecode, |
674 int first_video_timecode, | 674 int first_video_timecode, |
675 int block_count) { | 675 int block_count) { |
| 676 return GenerateCluster(first_audio_timecode, first_video_timecode, |
| 677 block_count, false); |
| 678 } |
| 679 scoped_ptr<Cluster> GenerateCluster(int first_audio_timecode, |
| 680 int first_video_timecode, |
| 681 int block_count, |
| 682 bool unknown_size) { |
676 CHECK_GT(block_count, 0); | 683 CHECK_GT(block_count, 0); |
677 | 684 |
678 int size = 10; | 685 int size = 10; |
679 scoped_ptr<uint8[]> data(new uint8[size]); | 686 scoped_ptr<uint8[]> data(new uint8[size]); |
680 | 687 |
681 ClusterBuilder cb; | 688 ClusterBuilder cb; |
682 cb.SetClusterTimecode(std::min(first_audio_timecode, first_video_timecode)); | 689 cb.SetClusterTimecode(std::min(first_audio_timecode, first_video_timecode)); |
683 | 690 |
684 if (block_count == 1) { | 691 if (block_count == 1) { |
685 cb.AddBlockGroup(kAudioTrackNum, first_audio_timecode, | 692 cb.AddBlockGroup(kAudioTrackNum, first_audio_timecode, |
(...skipping 29 matching lines...) Expand all Loading... |
715 kWebMFlagKeyframe, data.get(), size); | 722 kWebMFlagKeyframe, data.get(), size); |
716 AddVideoBlockGroup(&cb, kVideoTrackNum, video_timecode, | 723 AddVideoBlockGroup(&cb, kVideoTrackNum, video_timecode, |
717 kVideoBlockDuration, video_flag); | 724 kVideoBlockDuration, video_flag); |
718 } else { | 725 } else { |
719 AddVideoBlockGroup(&cb, kVideoTrackNum, video_timecode, | 726 AddVideoBlockGroup(&cb, kVideoTrackNum, video_timecode, |
720 kVideoBlockDuration, video_flag); | 727 kVideoBlockDuration, video_flag); |
721 cb.AddBlockGroup(kAudioTrackNum, audio_timecode, kAudioBlockDuration, | 728 cb.AddBlockGroup(kAudioTrackNum, audio_timecode, kAudioBlockDuration, |
722 kWebMFlagKeyframe, data.get(), size); | 729 kWebMFlagKeyframe, data.get(), size); |
723 } | 730 } |
724 | 731 |
725 return cb.Finish(); | 732 return unknown_size ? cb.FinishWithUnknownSize() : cb.Finish(); |
726 } | 733 } |
727 | 734 |
728 scoped_ptr<Cluster> GenerateSingleStreamCluster(int timecode, | 735 scoped_ptr<Cluster> GenerateSingleStreamCluster(int timecode, |
729 int end_timecode, | 736 int end_timecode, |
730 int track_number, | 737 int track_number, |
731 int block_duration) { | 738 int block_duration) { |
732 CHECK_GT(end_timecode, timecode); | 739 CHECK_GT(end_timecode, timecode); |
733 | 740 |
734 std::vector<uint8> data(kBlockSize); | 741 std::vector<uint8> data(kBlockSize); |
735 | 742 |
(...skipping 2150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2886 | 2893 |
2887 ASSERT_EQ(range_before_abort.size(), 1u); | 2894 ASSERT_EQ(range_before_abort.size(), 1u); |
2888 ASSERT_EQ(range_after_abort.size(), 1u); | 2895 ASSERT_EQ(range_after_abort.size(), 1u); |
2889 EXPECT_EQ(range_after_abort.start(0), range_before_abort.start(0)); | 2896 EXPECT_EQ(range_after_abort.start(0), range_before_abort.start(0)); |
2890 EXPECT_GT(range_after_abort.end(0), range_before_abort.end(0)); | 2897 EXPECT_GT(range_after_abort.end(0), range_before_abort.end(0)); |
2891 } | 2898 } |
2892 #endif | 2899 #endif |
2893 #endif | 2900 #endif |
2894 | 2901 |
2895 TEST_P(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { | 2902 TEST_P(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { |
2896 // TODO(wolenetz): Also test 'unknown' sized clusters. | |
2897 // See http://crbug.com/335676. | |
2898 const uint8 kBuffer[] = { | 2903 const uint8 kBuffer[] = { |
2899 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) | 2904 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) |
2900 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) | 2905 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) |
| 2906 |
| 2907 0x1F, 0x43, 0xB6, 0x75, 0xFF, // CLUSTER (size = unknown; really 3 due to:) |
| 2908 0xE7, 0x81, 0x02, // Cluster TIMECODE (value = 2) |
| 2909 /* e.g. put some blocks here... */ |
| 2910 0x1A, 0x45, 0xDF, 0xA3, 0x8A, // EBMLHEADER (size = 10, not fully appended) |
2901 }; | 2911 }; |
2902 | 2912 |
2903 // This array indicates expected return value of IsParsingMediaSegment() | 2913 // This array indicates expected return value of IsParsingMediaSegment() |
2904 // following each incrementally appended byte in |kBuffer|. | 2914 // following each incrementally appended byte in |kBuffer|. |
2905 const bool kExpectedReturnValues[] = { | 2915 const bool kExpectedReturnValues[] = { |
2906 false, false, false, false, true, | 2916 false, false, false, false, true, |
2907 true, true, false, | 2917 true, true, false, |
| 2918 |
| 2919 false, false, false, false, true, |
| 2920 true, true, true, |
| 2921 |
| 2922 true, true, true, true, false, |
2908 }; | 2923 }; |
2909 | 2924 |
2910 COMPILE_ASSERT(arraysize(kBuffer) == arraysize(kExpectedReturnValues), | 2925 COMPILE_ASSERT(arraysize(kBuffer) == arraysize(kExpectedReturnValues), |
2911 test_arrays_out_of_sync); | 2926 test_arrays_out_of_sync); |
2912 COMPILE_ASSERT(arraysize(kBuffer) == sizeof(kBuffer), not_one_byte_per_index); | 2927 COMPILE_ASSERT(arraysize(kBuffer) == sizeof(kBuffer), not_one_byte_per_index); |
2913 | 2928 |
2914 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2929 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
2915 | 2930 |
2916 for (size_t i = 0; i < sizeof(kBuffer); i++) { | 2931 for (size_t i = 0; i < sizeof(kBuffer); i++) { |
2917 DVLOG(3) << "Appending and testing index " << i; | 2932 DVLOG(3) << "Appending and testing index " << i; |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3447 | 3462 |
3448 // NOTE: we start at 175 here because the buffer at 125 was returned | 3463 // NOTE: we start at 175 here because the buffer at 125 was returned |
3449 // to the pending read initiated above. | 3464 // to the pending read initiated above. |
3450 CheckExpectedBuffers(text_stream, "175 225"); | 3465 CheckExpectedBuffers(text_stream, "175 225"); |
3451 | 3466 |
3452 // Verify that audio & video streams continue to return expected values. | 3467 // Verify that audio & video streams continue to return expected values. |
3453 CheckExpectedBuffers(audio_stream, "160 180"); | 3468 CheckExpectedBuffers(audio_stream, "160 180"); |
3454 CheckExpectedBuffers(video_stream, "180 210"); | 3469 CheckExpectedBuffers(video_stream, "180 210"); |
3455 } | 3470 } |
3456 | 3471 |
| 3472 TEST_P(ChunkDemuxerTest, ClusterWithUnknownSize) { |
| 3473 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 3474 |
| 3475 AppendCluster(GenerateCluster(0, 0, 4, true)); |
| 3476 CheckExpectedRanges(kSourceId, "{ [0,46) }"); |
| 3477 |
| 3478 // A new cluster indicates end of the previous cluster with unknown size. |
| 3479 AppendCluster(GenerateCluster(46, 66, 5, true)); |
| 3480 CheckExpectedRanges(kSourceId, "{ [0,115) }"); |
| 3481 } |
| 3482 |
3457 // Generate two sets of tests: one using FrameProcessor, and one using | 3483 // Generate two sets of tests: one using FrameProcessor, and one using |
3458 // LegacyFrameProcessor. | 3484 // LegacyFrameProcessor. |
3459 INSTANTIATE_TEST_CASE_P(NewFrameProcessor, ChunkDemuxerTest, Values(false)); | 3485 INSTANTIATE_TEST_CASE_P(NewFrameProcessor, ChunkDemuxerTest, Values(false)); |
3460 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, ChunkDemuxerTest, Values(true)); | 3486 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, ChunkDemuxerTest, Values(true)); |
3461 | 3487 |
3462 } // namespace media | 3488 } // namespace media |
OLD | NEW |