| 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 } | 317 } |
| 318 | 318 |
| 319 if (!has_audio && !has_video) { | 319 if (!has_audio && !has_video) { |
| 320 return AddId(kSourceId, HAS_AUDIO | HAS_VIDEO); | 320 return AddId(kSourceId, HAS_AUDIO | HAS_VIDEO); |
| 321 } | 321 } |
| 322 | 322 |
| 323 return demuxer_->AddId(source_id, type, codecs, | 323 return demuxer_->AddId(source_id, type, codecs, |
| 324 use_legacy_frame_processor_); | 324 use_legacy_frame_processor_); |
| 325 } | 325 } |
| 326 | 326 |
| 327 ChunkDemuxer::Status AddIdForMp2tSource(const std::string& source_id) { |
| 328 std::vector<std::string> codecs; |
| 329 std::string type = "video/mp2t"; |
| 330 codecs.push_back("mp4a.40.2"); |
| 331 codecs.push_back("avc1.640028"); |
| 332 return demuxer_->AddId(source_id, type, codecs, |
| 333 use_legacy_frame_processor_); |
| 334 } |
| 335 |
| 327 void AppendData(const uint8* data, size_t length) { | 336 void AppendData(const uint8* data, size_t length) { |
| 328 AppendData(kSourceId, data, length); | 337 AppendData(kSourceId, data, length); |
| 329 } | 338 } |
| 330 | 339 |
| 331 void AppendCluster(const std::string& source_id, | 340 void AppendCluster(const std::string& source_id, |
| 332 scoped_ptr<Cluster> cluster) { | 341 scoped_ptr<Cluster> cluster) { |
| 333 AppendData(source_id, cluster->data(), cluster->size()); | 342 AppendData(source_id, cluster->data(), cluster->size()); |
| 334 } | 343 } |
| 335 | 344 |
| 336 void AppendCluster(scoped_ptr<Cluster> cluster) { | 345 void AppendCluster(scoped_ptr<Cluster> cluster) { |
| (...skipping 2381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2718 TEST_P(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) { | 2727 TEST_P(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) { |
| 2719 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 2728 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
| 2720 | 2729 |
| 2721 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); | 2730 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); |
| 2722 // Append only part of the cluster data. | 2731 // Append only part of the cluster data. |
| 2723 AppendData(cluster->data(), cluster->size() - 13); | 2732 AppendData(cluster->data(), cluster->size() - 13); |
| 2724 | 2733 |
| 2725 // Confirm we're in the middle of parsing a media segment. | 2734 // Confirm we're in the middle of parsing a media segment. |
| 2726 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); | 2735 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); |
| 2727 | 2736 |
| 2728 demuxer_->Abort(kSourceId); | 2737 demuxer_->Abort(kSourceId, |
| 2738 append_window_start_for_next_append_, |
| 2739 append_window_end_for_next_append_, |
| 2740 ×tamp_offset_map_[kSourceId]); |
| 2741 |
| 2729 // After Abort(), parsing should no longer be in the middle of a media | 2742 // After Abort(), parsing should no longer be in the middle of a media |
| 2730 // segment. | 2743 // segment. |
| 2731 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId)); | 2744 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId)); |
| 2732 } | 2745 } |
| 2733 | 2746 |
| 2747 #if defined(USE_PROPRIETARY_CODECS) |
| 2748 #if defined(ENABLE_MPEG2TS_STREAM_PARSER) |
| 2749 TEST_P(ChunkDemuxerTest, EmitBuffersDuringAbort) { |
| 2750 EXPECT_CALL(*this, DemuxerOpened()); |
| 2751 demuxer_->Initialize( |
| 2752 &host_, CreateInitDoneCB(kInfiniteDuration(), PIPELINE_OK), true); |
| 2753 EXPECT_EQ(ChunkDemuxer::kOk, AddIdForMp2tSource(kSourceId)); |
| 2754 |
| 2755 // For info: |
| 2756 // DTS/PTS derived using dvbsnoop -s ts -if bear-1280x720.ts -tssubdecode |
| 2757 // Video: first PES: |
| 2758 // PTS: 126912 (0x0001efc0) [= 90 kHz-Timestamp: 0:00:01.4101] |
| 2759 // DTS: 123909 (0x0001e405) [= 90 kHz-Timestamp: 0:00:01.3767] |
| 2760 // Audio: first PES: |
| 2761 // PTS: 126000 (0x0001ec30) [= 90 kHz-Timestamp: 0:00:01.4000] |
| 2762 // DTS: 123910 (0x0001e406) [= 90 kHz-Timestamp: 0:00:01.3767] |
| 2763 // Video: last PES: |
| 2764 // PTS: 370155 (0x0005a5eb) [= 90 kHz-Timestamp: 0:00:04.1128] |
| 2765 // DTS: 367152 (0x00059a30) [= 90 kHz-Timestamp: 0:00:04.0794] |
| 2766 // Audio: last PES: |
| 2767 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309] |
| 2768 |
| 2769 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts"); |
| 2770 AppendData(kSourceId, buffer->data(), buffer->data_size()); |
| 2771 |
| 2772 // Confirm we're in the middle of parsing a media segment. |
| 2773 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); |
| 2774 |
| 2775 // Abort on the Mpeg2 TS parser triggers the emission of the last video |
| 2776 // buffer which is pending in the stream parser. |
| 2777 Ranges<base::TimeDelta> range_before_abort = |
| 2778 demuxer_->GetBufferedRanges(kSourceId); |
| 2779 demuxer_->Abort(kSourceId, |
| 2780 append_window_start_for_next_append_, |
| 2781 append_window_end_for_next_append_, |
| 2782 ×tamp_offset_map_[kSourceId]); |
| 2783 Ranges<base::TimeDelta> range_after_abort = |
| 2784 demuxer_->GetBufferedRanges(kSourceId); |
| 2785 |
| 2786 ASSERT_EQ(range_before_abort.size(), 1u); |
| 2787 ASSERT_EQ(range_after_abort.size(), 1u); |
| 2788 EXPECT_EQ(range_after_abort.start(0), range_before_abort.start(0)); |
| 2789 EXPECT_GT(range_after_abort.end(0), range_before_abort.end(0)); |
| 2790 } |
| 2791 #endif |
| 2792 #endif |
| 2793 |
| 2734 TEST_P(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { | 2794 TEST_P(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { |
| 2735 // TODO(wolenetz): Also test 'unknown' sized clusters. | 2795 // TODO(wolenetz): Also test 'unknown' sized clusters. |
| 2736 // See http://crbug.com/335676. | 2796 // See http://crbug.com/335676. |
| 2737 const uint8 kBuffer[] = { | 2797 const uint8 kBuffer[] = { |
| 2738 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) | 2798 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) |
| 2739 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) | 2799 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) |
| 2740 }; | 2800 }; |
| 2741 | 2801 |
| 2742 // This array indicates expected return value of IsParsingMediaSegment() | 2802 // This array indicates expected return value of IsParsingMediaSegment() |
| 2743 // following each incrementally appended byte in |kBuffer|. | 2803 // following each incrementally appended byte in |kBuffer|. |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3213 // Verify that audio & video streams continue to return expected values. | 3273 // Verify that audio & video streams continue to return expected values. |
| 3214 CheckExpectedBuffers(audio_stream, "160 180"); | 3274 CheckExpectedBuffers(audio_stream, "160 180"); |
| 3215 CheckExpectedBuffers(video_stream, "180 210"); | 3275 CheckExpectedBuffers(video_stream, "180 210"); |
| 3216 } | 3276 } |
| 3217 | 3277 |
| 3218 // TODO(wolenetz): Enable testing of new frame processor based on this flag, | 3278 // TODO(wolenetz): Enable testing of new frame processor based on this flag, |
| 3219 // once the new processor has landed. See http://crbug.com/249422. | 3279 // once the new processor has landed. See http://crbug.com/249422. |
| 3220 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, ChunkDemuxerTest, Values(true)); | 3280 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, ChunkDemuxerTest, Values(true)); |
| 3221 | 3281 |
| 3222 } // namespace media | 3282 } // namespace media |
| OLD | NEW |