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 27 matching lines...) Expand all Loading... |
38 int init_data_size)> NeedKeyCB; | 38 int init_data_size)> NeedKeyCB; |
39 | 39 |
40 // |open_cb| Run when Initialize() is called to signal that the demuxer | 40 // |open_cb| Run when Initialize() is called to signal that the demuxer |
41 // is ready to receive media data via AppenData(). | 41 // is ready to receive media data via AppenData(). |
42 // |need_key_cb| Run when the demuxer determines that an encryption key is | 42 // |need_key_cb| Run when the demuxer determines that an encryption key is |
43 // needed to decrypt the content. | 43 // needed to decrypt the content. |
44 // |log_cb| Run when parsing error messages need to be logged to the error | 44 // |log_cb| Run when parsing error messages need to be logged to the error |
45 // console. | 45 // console. |
46 ChunkDemuxer(const base::Closure& open_cb, const NeedKeyCB& need_key_cb, | 46 ChunkDemuxer(const base::Closure& open_cb, const NeedKeyCB& need_key_cb, |
47 const LogCB& log_cb); | 47 const LogCB& log_cb); |
| 48 virtual ~ChunkDemuxer(); |
48 | 49 |
49 // Demuxer implementation. | 50 // Demuxer implementation. |
50 virtual void Initialize(DemuxerHost* host, | 51 virtual void Initialize(DemuxerHost* host, |
51 const PipelineStatusCB& cb) OVERRIDE; | 52 const PipelineStatusCB& cb) OVERRIDE; |
52 virtual void Stop(const base::Closure& callback) OVERRIDE; | 53 virtual void Stop(const base::Closure& callback) OVERRIDE; |
53 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 54 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
54 virtual void OnAudioRendererDisabled() OVERRIDE; | 55 virtual void OnAudioRendererDisabled() OVERRIDE; |
55 virtual scoped_refptr<DemuxerStream> GetStream( | 56 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE; |
56 DemuxerStream::Type type) OVERRIDE; | |
57 virtual base::TimeDelta GetStartTime() const OVERRIDE; | 57 virtual base::TimeDelta GetStartTime() const OVERRIDE; |
58 | 58 |
59 // Methods used by an external object to control this demuxer. | 59 // Methods used by an external object to control this demuxer. |
60 void StartWaitingForSeek(); | 60 void StartWaitingForSeek(); |
61 void CancelPendingSeek(); | 61 void CancelPendingSeek(); |
62 | 62 |
63 // Registers a new |id| to use for AppendData() calls. |type| indicates | 63 // Registers a new |id| to use for AppendData() calls. |type| indicates |
64 // the MIME type for the data that we intend to append for this ID. | 64 // the MIME type for the data that we intend to append for this ID. |
65 // kOk is returned if the demuxer has enough resources to support another ID | 65 // kOk is returned if the demuxer has enough resources to support another ID |
66 // and supports the format indicated by |type|. | 66 // and supports the format indicated by |type|. |
(...skipping 30 matching lines...) Expand all Loading... |
97 // properly, false if the offset cannot be applied because we're in the | 97 // properly, false if the offset cannot be applied because we're in the |
98 // middle of parsing a media segment. | 98 // middle of parsing a media segment. |
99 bool SetTimestampOffset(const std::string& id, base::TimeDelta offset); | 99 bool SetTimestampOffset(const std::string& id, base::TimeDelta offset); |
100 | 100 |
101 // Signals an EndOfStream request. | 101 // Signals an EndOfStream request. |
102 // Returns false if called in an unexpected state or if there is a gap between | 102 // Returns false if called in an unexpected state or if there is a gap between |
103 // the current position and the end of the buffered data. | 103 // the current position and the end of the buffered data. |
104 bool EndOfStream(PipelineStatus status); | 104 bool EndOfStream(PipelineStatus status); |
105 void Shutdown(); | 105 void Shutdown(); |
106 | 106 |
107 protected: | |
108 virtual ~ChunkDemuxer(); | |
109 | |
110 private: | 107 private: |
111 enum State { | 108 enum State { |
112 WAITING_FOR_INIT, | 109 WAITING_FOR_INIT, |
113 INITIALIZING, | 110 INITIALIZING, |
114 INITIALIZED, | 111 INITIALIZED, |
115 ENDED, | 112 ENDED, |
116 PARSE_ERROR, | 113 PARSE_ERROR, |
117 SHUTDOWN, | 114 SHUTDOWN, |
118 }; | 115 }; |
119 | 116 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 base::TimeDelta timestamp_offset); | 149 base::TimeDelta timestamp_offset); |
153 | 150 |
154 // Returns true if |source_id| is valid, false otherwise. | 151 // Returns true if |source_id| is valid, false otherwise. |
155 bool IsValidId(const std::string& source_id) const; | 152 bool IsValidId(const std::string& source_id) const; |
156 | 153 |
157 // Increases |duration_| if the newly appended |buffers| exceed the current | 154 // Increases |duration_| if the newly appended |buffers| exceed the current |
158 // |duration_|. The |duration_| is set to the end buffered timestamp of | 155 // |duration_|. The |duration_| is set to the end buffered timestamp of |
159 // |stream|. | 156 // |stream|. |
160 void IncreaseDurationIfNecessary( | 157 void IncreaseDurationIfNecessary( |
161 const StreamParser::BufferQueue& buffers, | 158 const StreamParser::BufferQueue& buffers, |
162 const scoped_refptr<ChunkDemuxerStream>& stream); | 159 ChunkDemuxerStream* stream); |
163 | 160 |
164 // Decreases |duration_| if the buffered region is less than |duration_| when | 161 // Decreases |duration_| if the buffered region is less than |duration_| when |
165 // EndOfStream() is called. | 162 // EndOfStream() is called. |
166 void DecreaseDurationIfNecessary(); | 163 void DecreaseDurationIfNecessary(); |
167 | 164 |
168 // Sets |duration_| to |new_duration|, sets |user_specified_duration_| to -1 | 165 // Sets |duration_| to |new_duration|, sets |user_specified_duration_| to -1 |
169 // and notifies |host_|. | 166 // and notifies |host_|. |
170 void UpdateDuration(base::TimeDelta new_duration); | 167 void UpdateDuration(base::TimeDelta new_duration); |
171 | 168 |
172 // Returns the ranges representing the buffered data in the demuxer. | 169 // Returns the ranges representing the buffered data in the demuxer. |
173 Ranges<base::TimeDelta> GetBufferedRanges() const; | 170 Ranges<base::TimeDelta> GetBufferedRanges() const; |
174 | 171 |
175 mutable base::Lock lock_; | 172 mutable base::Lock lock_; |
176 State state_; | 173 State state_; |
177 | 174 |
178 DemuxerHost* host_; | 175 DemuxerHost* host_; |
179 base::Closure open_cb_; | 176 base::Closure open_cb_; |
180 NeedKeyCB need_key_cb_; | 177 NeedKeyCB need_key_cb_; |
181 // Callback used to report error strings that can help the web developer | 178 // Callback used to report error strings that can help the web developer |
182 // figure out what is wrong with the content. | 179 // figure out what is wrong with the content. |
183 LogCB log_cb_; | 180 LogCB log_cb_; |
184 | 181 |
185 PipelineStatusCB init_cb_; | 182 PipelineStatusCB init_cb_; |
186 PipelineStatusCB seek_cb_; | 183 PipelineStatusCB seek_cb_; |
187 | 184 |
188 scoped_refptr<ChunkDemuxerStream> audio_; | 185 scoped_ptr<ChunkDemuxerStream> audio_; |
189 scoped_refptr<ChunkDemuxerStream> video_; | 186 scoped_ptr<ChunkDemuxerStream> video_; |
190 | 187 |
191 base::TimeDelta duration_; | 188 base::TimeDelta duration_; |
192 | 189 |
193 // The duration passed to the last SetDuration(). If | 190 // The duration passed to the last SetDuration(). If |
194 // SetDuration() is never called or an AppendData() call or | 191 // SetDuration() is never called or an AppendData() call or |
195 // a EndOfStream() call changes |duration_|, then this | 192 // a EndOfStream() call changes |duration_|, then this |
196 // variable is set to < 0 to indicate that the |duration_| represents | 193 // variable is set to < 0 to indicate that the |duration_| represents |
197 // the actual duration instead of a user specified value. | 194 // the actual duration instead of a user specified value. |
198 double user_specified_duration_; | 195 double user_specified_duration_; |
199 | 196 |
200 typedef std::map<std::string, SourceState*> SourceStateMap; | 197 typedef std::map<std::string, SourceState*> SourceStateMap; |
201 SourceStateMap source_state_map_; | 198 SourceStateMap source_state_map_; |
202 | 199 |
203 // Used to ensure that (1) config data matches the type and codec provided in | 200 // Used to ensure that (1) config data matches the type and codec provided in |
204 // AddId(), (2) only 1 audio and 1 video sources are added, and (3) ids may be | 201 // AddId(), (2) only 1 audio and 1 video sources are added, and (3) ids may be |
205 // removed with RemoveID() but can not be re-added (yet). | 202 // removed with RemoveID() but can not be re-added (yet). |
206 std::string source_id_audio_; | 203 std::string source_id_audio_; |
207 std::string source_id_video_; | 204 std::string source_id_video_; |
208 | 205 |
209 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); | 206 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); |
210 }; | 207 }; |
211 | 208 |
212 } // namespace media | 209 } // namespace media |
213 | 210 |
214 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 211 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
OLD | NEW |