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 #ifndef MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 5 #ifndef MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
6 #define MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 6 #define MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const; | 67 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const; |
68 | 68 |
69 // Appends media data to the source buffer associated with |id|. Returns | 69 // Appends media data to the source buffer associated with |id|. Returns |
70 // false if this method is called in an invalid state. | 70 // false if this method is called in an invalid state. |
71 bool AppendData(const std::string& id, const uint8* data, size_t length); | 71 bool AppendData(const std::string& id, const uint8* data, size_t length); |
72 | 72 |
73 // Aborts parsing the current segment and reset the parser to a state where | 73 // Aborts parsing the current segment and reset the parser to a state where |
74 // it can accept a new segment. | 74 // it can accept a new segment. |
75 void Abort(const std::string& id); | 75 void Abort(const std::string& id); |
76 | 76 |
| 77 // Sets a time |offset| in seconds to be applied to subsequent buffers |
| 78 // appended to the source buffer assicated with |id|. Returns true if the |
| 79 // offset is set properly, false if the offset cannot be applied because we're |
| 80 // in the middle of parsing a media segment. |
| 81 bool SetTimestampOffset(const std::string& id, double offset); |
| 82 |
77 // Signals an EndOfStream request. | 83 // Signals an EndOfStream request. |
78 // Returns false if called in an unexpected state or if there is a gap between | 84 // Returns false if called in an unexpected state or if there is a gap between |
79 // the current position and the end of the buffered data. | 85 // the current position and the end of the buffered data. |
80 bool EndOfStream(PipelineStatus status); | 86 bool EndOfStream(PipelineStatus status); |
81 void Shutdown(); | 87 void Shutdown(); |
82 | 88 |
83 protected: | 89 protected: |
84 virtual ~ChunkDemuxer(); | 90 virtual ~ChunkDemuxer(); |
85 | 91 |
86 private: | 92 private: |
(...skipping 23 matching lines...) Expand all Loading... |
110 // StreamParser callbacks. | 116 // StreamParser callbacks. |
111 void OnStreamParserInitDone(bool success, base::TimeDelta duration); | 117 void OnStreamParserInitDone(bool success, base::TimeDelta duration); |
112 bool OnNewConfigs(bool has_audio, bool has_video, | 118 bool OnNewConfigs(bool has_audio, bool has_video, |
113 const AudioDecoderConfig& audio_config, | 119 const AudioDecoderConfig& audio_config, |
114 const VideoDecoderConfig& video_config); | 120 const VideoDecoderConfig& video_config); |
115 bool OnAudioBuffers(const StreamParser::BufferQueue& buffers); | 121 bool OnAudioBuffers(const StreamParser::BufferQueue& buffers); |
116 bool OnVideoBuffers(const StreamParser::BufferQueue& buffers); | 122 bool OnVideoBuffers(const StreamParser::BufferQueue& buffers); |
117 bool OnNeedKey(scoped_array<uint8> init_data, int init_data_size); | 123 bool OnNeedKey(scoped_array<uint8> init_data, int init_data_size); |
118 void OnNewMediaSegment(const std::string& source_id, | 124 void OnNewMediaSegment(const std::string& source_id, |
119 base::TimeDelta start_timestamp); | 125 base::TimeDelta start_timestamp); |
| 126 void OnEndOfMediaSegment(const std::string& source_id); |
120 | 127 |
121 // Computes the intersection between the video & audio | 128 // Computes the intersection between the video & audio |
122 // buffered ranges. | 129 // buffered ranges. |
123 Ranges<base::TimeDelta> ComputeIntersection() const; | 130 Ranges<base::TimeDelta> ComputeIntersection() const; |
124 | 131 |
| 132 // Applies |time_offset| to the timestamps of |buffers|. |
| 133 void AdjustBufferTimestamps(const StreamParser::BufferQueue& buffers, |
| 134 base::TimeDelta timestamp_offset); |
| 135 |
| 136 // Returns true if |source_id| is valid, false otherwise. |
| 137 bool IsValidId(const std::string& source_id) const; |
| 138 |
125 mutable base::Lock lock_; | 139 mutable base::Lock lock_; |
126 State state_; | 140 State state_; |
127 | 141 |
128 DemuxerHost* host_; | 142 DemuxerHost* host_; |
129 ChunkDemuxerClient* client_; | 143 ChunkDemuxerClient* client_; |
130 PipelineStatusCB init_cb_; | 144 PipelineStatusCB init_cb_; |
131 PipelineStatusCB seek_cb_; | 145 PipelineStatusCB seek_cb_; |
132 | 146 |
133 scoped_refptr<ChunkDemuxerStream> audio_; | 147 scoped_refptr<ChunkDemuxerStream> audio_; |
134 scoped_refptr<ChunkDemuxerStream> video_; | 148 scoped_refptr<ChunkDemuxerStream> video_; |
135 | 149 |
136 base::TimeDelta duration_; | 150 base::TimeDelta duration_; |
137 | 151 |
138 typedef std::map<std::string, StreamParser*> StreamParserMap; | 152 typedef std::map<std::string, StreamParser*> StreamParserMap; |
139 StreamParserMap stream_parser_map_; | 153 StreamParserMap stream_parser_map_; |
140 | 154 |
| 155 // Contains state belonging to a source id. |
| 156 struct SourceInfo { |
| 157 base::TimeDelta timestamp_offset; |
| 158 bool can_update_offset; |
| 159 }; |
| 160 typedef std::map<std::string, SourceInfo> SourceInfoMap; |
| 161 SourceInfoMap source_info_map_; |
| 162 |
141 // Used to ensure that (1) config data matches the type and codec provided in | 163 // Used to ensure that (1) config data matches the type and codec provided in |
142 // AddId(), (2) only 1 audio and 1 video sources are added, and (3) ids may be | 164 // AddId(), (2) only 1 audio and 1 video sources are added, and (3) ids may be |
143 // removed with RemoveID() but can not be re-added (yet). | 165 // removed with RemoveID() but can not be re-added (yet). |
144 std::string source_id_audio_; | 166 std::string source_id_audio_; |
145 std::string source_id_video_; | 167 std::string source_id_video_; |
146 | 168 |
147 base::TimeDelta start_time_; | 169 base::TimeDelta start_time_; |
148 | 170 |
149 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); | 171 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); |
150 }; | 172 }; |
151 | 173 |
152 } // namespace media | 174 } // namespace media |
153 | 175 |
154 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 176 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
OLD | NEW |