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 <set> |
9 #include <string> | 10 #include <string> |
10 #include <utility> | 11 #include <utility> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
14 #include "media/base/byte_queue.h" | 15 #include "media/base/byte_queue.h" |
15 #include "media/base/demuxer.h" | 16 #include "media/base/demuxer.h" |
16 #include "media/base/ranges.h" | 17 #include "media/base/ranges.h" |
17 #include "media/base/stream_parser.h" | 18 #include "media/base/stream_parser.h" |
18 #include "media/base/text_track.h" | |
19 #include "media/filters/source_buffer_stream.h" | 19 #include "media/filters/source_buffer_stream.h" |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 | 22 |
23 class ChunkDemuxerStream; | 23 class ChunkDemuxerStream; |
24 class FFmpegURLProtocol; | 24 class FFmpegURLProtocol; |
25 class SourceState; | 25 class SourceState; |
26 | 26 |
27 // Demuxer implementation that allows chunks of media data to be passed | 27 // Demuxer implementation that allows chunks of media data to be passed |
28 // from JavaScript to the media stack. | 28 // from JavaScript to the media stack. |
29 class MEDIA_EXPORT ChunkDemuxer : public Demuxer { | 29 class MEDIA_EXPORT ChunkDemuxer : public Demuxer { |
30 public: | 30 public: |
31 enum Status { | 31 enum Status { |
32 kOk, // ID added w/o error. | 32 kOk, // ID added w/o error. |
33 kNotSupported, // Type specified is not supported. | 33 kNotSupported, // Type specified is not supported. |
34 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs. | 34 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs. |
35 }; | 35 }; |
36 | 36 |
37 // |open_cb| Run when Initialize() is called to signal that the demuxer | 37 // |open_cb| Run when Initialize() is called to signal that the demuxer |
38 // is ready to receive media data via AppenData(). | 38 // is ready to receive media data via AppenData(). |
39 // |need_key_cb| Run when the demuxer determines that an encryption key is | 39 // |need_key_cb| Run when the demuxer determines that an encryption key is |
40 // needed to decrypt the content. | 40 // needed to decrypt the content. |
41 // |add_text_track_cb| Run when demuxer detects the presence of an inband | 41 // |enable_text| Process inband text tracks in the normal way when true, |
42 // text track. | 42 // otherwise ignore them. |
43 // |log_cb| Run when parsing error messages need to be logged to the error | 43 // |log_cb| Run when parsing error messages need to be logged to the error |
44 // console. | 44 // console. |
45 ChunkDemuxer(const base::Closure& open_cb, | 45 ChunkDemuxer(const base::Closure& open_cb, |
46 const NeedKeyCB& need_key_cb, | 46 const NeedKeyCB& need_key_cb, |
47 const AddTextTrackCB& add_text_track_cb, | 47 bool enable_text, |
48 const LogCB& log_cb); | 48 const LogCB& log_cb); |
49 virtual ~ChunkDemuxer(); | 49 virtual ~ChunkDemuxer(); |
50 | 50 |
51 // Demuxer implementation. | 51 // Demuxer implementation. |
52 virtual void Initialize(DemuxerHost* host, | 52 virtual void Initialize(DemuxerHost* host, |
53 const PipelineStatusCB& cb) OVERRIDE; | 53 const PipelineStatusCB& cb) OVERRIDE; |
54 virtual void Stop(const base::Closure& callback) OVERRIDE; | 54 virtual void Stop(const base::Closure& callback) OVERRIDE; |
55 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; | 55 virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; |
56 virtual void OnAudioRendererDisabled() OVERRIDE; | 56 virtual void OnAudioRendererDisabled() OVERRIDE; |
57 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE; | 57 virtual DemuxerStream* GetStream(DemuxerStream::Type type) OVERRIDE; |
(...skipping 106 matching lines...) Loading... |
164 bool CanEndOfStream_Locked() const; | 164 bool CanEndOfStream_Locked() const; |
165 | 165 |
166 // SourceState callbacks. | 166 // SourceState callbacks. |
167 void OnSourceInitDone(bool success, base::TimeDelta duration); | 167 void OnSourceInitDone(bool success, base::TimeDelta duration); |
168 | 168 |
169 // Creates a DemuxerStream for the specified |type|. | 169 // Creates a DemuxerStream for the specified |type|. |
170 // Returns a new ChunkDemuxerStream instance if a stream of this type | 170 // Returns a new ChunkDemuxerStream instance if a stream of this type |
171 // has not been created before. Returns NULL otherwise. | 171 // has not been created before. Returns NULL otherwise. |
172 ChunkDemuxerStream* CreateDemuxerStream(DemuxerStream::Type type); | 172 ChunkDemuxerStream* CreateDemuxerStream(DemuxerStream::Type type); |
173 | 173 |
174 bool OnTextBuffers(TextTrack* text_track, | 174 void OnNewTextTrack(ChunkDemuxerStream* text_stream, |
175 const StreamParser::BufferQueue& buffers); | 175 TextKind kind, |
| 176 const std::string& name, |
| 177 const std::string& language); |
176 void OnNewMediaSegment(const std::string& source_id, | 178 void OnNewMediaSegment(const std::string& source_id, |
177 base::TimeDelta start_timestamp); | 179 base::TimeDelta start_timestamp); |
178 | 180 |
179 // Computes the intersection between the video & audio | 181 // Computes the intersection between the video & audio |
180 // buffered ranges. | 182 // buffered ranges. |
181 Ranges<base::TimeDelta> ComputeIntersection() const; | 183 Ranges<base::TimeDelta> ComputeIntersection() const; |
182 | 184 |
183 // Applies |time_offset| to the timestamps of |buffers|. | 185 // Applies |time_offset| to the timestamps of |buffers|. |
184 void AdjustBufferTimestamps(const StreamParser::BufferQueue& buffers, | 186 void AdjustBufferTimestamps(const StreamParser::BufferQueue& buffers, |
185 base::TimeDelta timestamp_offset); | 187 base::TimeDelta timestamp_offset); |
(...skipping 31 matching lines...) Loading... |
217 // Seeks all SourceBufferStreams to |seek_time|. | 219 // Seeks all SourceBufferStreams to |seek_time|. |
218 void SeekAllSources(base::TimeDelta seek_time); | 220 void SeekAllSources(base::TimeDelta seek_time); |
219 | 221 |
220 mutable base::Lock lock_; | 222 mutable base::Lock lock_; |
221 State state_; | 223 State state_; |
222 bool cancel_next_seek_; | 224 bool cancel_next_seek_; |
223 | 225 |
224 DemuxerHost* host_; | 226 DemuxerHost* host_; |
225 base::Closure open_cb_; | 227 base::Closure open_cb_; |
226 NeedKeyCB need_key_cb_; | 228 NeedKeyCB need_key_cb_; |
227 AddTextTrackCB add_text_track_cb_; | 229 bool enable_text_; |
228 // Callback used to report error strings that can help the web developer | 230 // Callback used to report error strings that can help the web developer |
229 // figure out what is wrong with the content. | 231 // figure out what is wrong with the content. |
230 LogCB log_cb_; | 232 LogCB log_cb_; |
231 | 233 |
232 PipelineStatusCB init_cb_; | 234 PipelineStatusCB init_cb_; |
233 PipelineStatusCB seek_cb_; | 235 PipelineStatusCB seek_cb_; |
234 | 236 |
235 scoped_ptr<ChunkDemuxerStream> audio_; | 237 scoped_ptr<ChunkDemuxerStream> audio_; |
236 scoped_ptr<ChunkDemuxerStream> video_; | 238 scoped_ptr<ChunkDemuxerStream> video_; |
237 | 239 |
| 240 typedef std::set<ChunkDemuxerStream*> TextStreamSet; |
| 241 TextStreamSet text_stream_set_; |
| 242 |
238 // Keeps |audio_| alive when audio has been disabled. | 243 // Keeps |audio_| alive when audio has been disabled. |
239 scoped_ptr<ChunkDemuxerStream> disabled_audio_; | 244 scoped_ptr<ChunkDemuxerStream> disabled_audio_; |
240 | 245 |
241 base::TimeDelta duration_; | 246 base::TimeDelta duration_; |
242 | 247 |
243 // The duration passed to the last SetDuration(). If | 248 // The duration passed to the last SetDuration(). If |
244 // SetDuration() is never called or an AppendData() call or | 249 // SetDuration() is never called or an AppendData() call or |
245 // a EndOfStream() call changes |duration_|, then this | 250 // a EndOfStream() call changes |duration_|, then this |
246 // variable is set to < 0 to indicate that the |duration_| represents | 251 // variable is set to < 0 to indicate that the |duration_| represents |
247 // the actual duration instead of a user specified value. | 252 // the actual duration instead of a user specified value. |
248 double user_specified_duration_; | 253 double user_specified_duration_; |
249 | 254 |
250 typedef std::map<std::string, SourceState*> SourceStateMap; | 255 typedef std::map<std::string, SourceState*> SourceStateMap; |
251 SourceStateMap source_state_map_; | 256 SourceStateMap source_state_map_; |
252 | 257 |
253 // Used to ensure that (1) config data matches the type and codec provided in | 258 // Used to ensure that (1) config data matches the type and codec provided in |
254 // AddId(), (2) only 1 audio and 1 video sources are added, and (3) ids may be | 259 // AddId(), (2) only 1 audio and 1 video sources are added, and (3) ids may be |
255 // removed with RemoveID() but can not be re-added (yet). | 260 // removed with RemoveID() but can not be re-added (yet). |
256 std::string source_id_audio_; | 261 std::string source_id_audio_; |
257 std::string source_id_video_; | 262 std::string source_id_video_; |
258 | 263 |
259 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); | 264 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); |
260 }; | 265 }; |
261 | 266 |
262 } // namespace media | 267 } // namespace media |
263 | 268 |
264 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 269 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
OLD | NEW |