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 3011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3022 TEST_F(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) { | 3022 TEST_F(ChunkDemuxerTest, IsParsingMediaSegmentMidMediaSegment) { |
3023 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); | 3023 ASSERT_TRUE(InitDemuxer(HAS_AUDIO | HAS_VIDEO)); |
3024 | 3024 |
3025 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); | 3025 scoped_ptr<Cluster> cluster = GenerateCluster(0, 2); |
3026 // Append only part of the cluster data. | 3026 // Append only part of the cluster data. |
3027 AppendData(cluster->data(), cluster->size() - 13); | 3027 AppendData(cluster->data(), cluster->size() - 13); |
3028 | 3028 |
3029 // Confirm we're in the middle of parsing a media segment. | 3029 // Confirm we're in the middle of parsing a media segment. |
3030 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); | 3030 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); |
3031 | 3031 |
3032 demuxer_->Abort(kSourceId, | 3032 demuxer_->ResetParserState(kSourceId, |
3033 append_window_start_for_next_append_, | 3033 append_window_start_for_next_append_, |
3034 append_window_end_for_next_append_, | 3034 append_window_end_for_next_append_, |
3035 ×tamp_offset_map_[kSourceId]); | 3035 ×tamp_offset_map_[kSourceId]); |
3036 | 3036 |
3037 // After Abort(), parsing should no longer be in the middle of a media | 3037 // After ResetParserState(), parsing should no longer be in the middle of a |
3038 // segment. | 3038 // media segment. |
3039 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId)); | 3039 ASSERT_FALSE(demuxer_->IsParsingMediaSegment(kSourceId)); |
3040 } | 3040 } |
3041 | 3041 |
3042 #if defined(USE_PROPRIETARY_CODECS) | 3042 #if defined(USE_PROPRIETARY_CODECS) |
3043 #if defined(ENABLE_MPEG2TS_STREAM_PARSER) | 3043 #if defined(ENABLE_MPEG2TS_STREAM_PARSER) |
3044 TEST_F(ChunkDemuxerTest, EmitBuffersDuringAbort) { | 3044 TEST_F(ChunkDemuxerTest, EmitBuffersDuringAbort) { |
3045 EXPECT_CALL(*this, DemuxerOpened()); | 3045 EXPECT_CALL(*this, DemuxerOpened()); |
3046 demuxer_->Initialize( | 3046 demuxer_->Initialize( |
3047 &host_, CreateInitDoneCB(kInfiniteDuration(), PIPELINE_OK), true); | 3047 &host_, CreateInitDoneCB(kInfiniteDuration(), PIPELINE_OK), true); |
3048 EXPECT_EQ(ChunkDemuxer::kOk, AddIdForMp2tSource(kSourceId)); | 3048 EXPECT_EQ(ChunkDemuxer::kOk, AddIdForMp2tSource(kSourceId)); |
(...skipping 12 matching lines...) Expand all Loading... |
3061 // Audio: last PES: | 3061 // Audio: last PES: |
3062 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309] | 3062 // PTS: 353788 (0x000565fc) [= 90 kHz-Timestamp: 0:00:03.9309] |
3063 | 3063 |
3064 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts"); | 3064 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("bear-1280x720.ts"); |
3065 EXPECT_CALL(*this, InitSegmentReceived()); | 3065 EXPECT_CALL(*this, InitSegmentReceived()); |
3066 AppendData(kSourceId, buffer->data(), buffer->data_size()); | 3066 AppendData(kSourceId, buffer->data(), buffer->data_size()); |
3067 | 3067 |
3068 // Confirm we're in the middle of parsing a media segment. | 3068 // Confirm we're in the middle of parsing a media segment. |
3069 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); | 3069 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); |
3070 | 3070 |
3071 // Abort on the Mpeg2 TS parser triggers the emission of the last video | 3071 // ResetParserState on the Mpeg2 TS parser triggers the emission of the last |
3072 // buffer which is pending in the stream parser. | 3072 // video buffer which is pending in the stream parser. |
3073 Ranges<base::TimeDelta> range_before_abort = | 3073 Ranges<base::TimeDelta> range_before_abort = |
3074 demuxer_->GetBufferedRanges(kSourceId); | 3074 demuxer_->GetBufferedRanges(kSourceId); |
3075 demuxer_->Abort(kSourceId, | 3075 demuxer_->ResetParserState(kSourceId, |
3076 append_window_start_for_next_append_, | 3076 append_window_start_for_next_append_, |
3077 append_window_end_for_next_append_, | 3077 append_window_end_for_next_append_, |
3078 ×tamp_offset_map_[kSourceId]); | 3078 ×tamp_offset_map_[kSourceId]); |
3079 Ranges<base::TimeDelta> range_after_abort = | 3079 Ranges<base::TimeDelta> range_after_abort = |
3080 demuxer_->GetBufferedRanges(kSourceId); | 3080 demuxer_->GetBufferedRanges(kSourceId); |
3081 | 3081 |
3082 ASSERT_EQ(range_before_abort.size(), 1u); | 3082 ASSERT_EQ(range_before_abort.size(), 1u); |
3083 ASSERT_EQ(range_after_abort.size(), 1u); | 3083 ASSERT_EQ(range_after_abort.size(), 1u); |
3084 EXPECT_EQ(range_after_abort.start(0), range_before_abort.start(0)); | 3084 EXPECT_EQ(range_after_abort.start(0), range_before_abort.start(0)); |
3085 EXPECT_GT(range_after_abort.end(0), range_before_abort.end(0)); | 3085 EXPECT_GT(range_after_abort.end(0), range_before_abort.end(0)); |
3086 } | 3086 } |
3087 | 3087 |
3088 TEST_F(ChunkDemuxerTest, SeekCompleteDuringAbort) { | 3088 TEST_F(ChunkDemuxerTest, SeekCompleteDuringAbort) { |
(...skipping 20 matching lines...) Expand all Loading... |
3109 EXPECT_CALL(*this, InitSegmentReceived()); | 3109 EXPECT_CALL(*this, InitSegmentReceived()); |
3110 AppendData(kSourceId, buffer->data(), buffer->data_size()); | 3110 AppendData(kSourceId, buffer->data(), buffer->data_size()); |
3111 | 3111 |
3112 // Confirm we're in the middle of parsing a media segment. | 3112 // Confirm we're in the middle of parsing a media segment. |
3113 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); | 3113 ASSERT_TRUE(demuxer_->IsParsingMediaSegment(kSourceId)); |
3114 | 3114 |
3115 // Seek to a time corresponding to buffers that will be emitted during the | 3115 // Seek to a time corresponding to buffers that will be emitted during the |
3116 // abort. | 3116 // abort. |
3117 Seek(base::TimeDelta::FromMilliseconds(4110)); | 3117 Seek(base::TimeDelta::FromMilliseconds(4110)); |
3118 | 3118 |
3119 // Abort on the Mpeg2 TS parser triggers the emission of the last video | 3119 // ResetParserState on the Mpeg2 TS parser triggers the emission of the last |
3120 // buffer which is pending in the stream parser. | 3120 // video buffer which is pending in the stream parser. |
3121 demuxer_->Abort(kSourceId, | 3121 demuxer_->ResetParserState(kSourceId, |
3122 append_window_start_for_next_append_, | 3122 append_window_start_for_next_append_, |
3123 append_window_end_for_next_append_, | 3123 append_window_end_for_next_append_, |
3124 ×tamp_offset_map_[kSourceId]); | 3124 ×tamp_offset_map_[kSourceId]); |
3125 } | 3125 } |
3126 | 3126 |
3127 #endif | 3127 #endif |
3128 #endif | 3128 #endif |
3129 | 3129 |
3130 TEST_F(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { | 3130 TEST_F(ChunkDemuxerTest, WebMIsParsingMediaSegmentDetection) { |
3131 const uint8 kBuffer[] = { | 3131 const uint8 kBuffer[] = { |
3132 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) | 3132 0x1F, 0x43, 0xB6, 0x75, 0x83, // CLUSTER (size = 3) |
3133 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) | 3133 0xE7, 0x81, 0x01, // Cluster TIMECODE (value = 1) |
3134 | 3134 |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3848 // audio size is 80 bytes, new data is 28 bytes, we need to remove just one 10 | 3848 // audio size is 80 bytes, new data is 28 bytes, we need to remove just one 10 |
3849 // byte block to stay under 100 bytes memory limit after append | 3849 // byte block to stay under 100 bytes memory limit after append |
3850 // 80 - 10 + 28 = 98). | 3850 // 80 - 10 + 28 = 98). |
3851 // For video stream 150 + 52 = 202. Video limit is 150 bytes. We need to | 3851 // For video stream 150 + 52 = 202. Video limit is 150 bytes. We need to |
3852 // remove at least 6 blocks to stay under limit. | 3852 // remove at least 6 blocks to stay under limit. |
3853 CheckExpectedBuffers(audio_stream, "40K 80K 120K 160K 200K 240K 280K"); | 3853 CheckExpectedBuffers(audio_stream, "40K 80K 120K 160K 200K 240K 280K"); |
3854 CheckExpectedBuffers(video_stream, "60K 70 80K 90 100K 110 120K 130 140K"); | 3854 CheckExpectedBuffers(video_stream, "60K 70 80K 90 100K 110 120K 130 140K"); |
3855 } | 3855 } |
3856 | 3856 |
3857 } // namespace media | 3857 } // namespace media |
OLD | NEW |