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 <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "media/base/byte_queue.h" | 15 #include "media/base/byte_queue.h" |
16 #include "media/base/demuxer.h" | 16 #include "media/base/demuxer.h" |
17 #include "media/base/ranges.h" | 17 #include "media/base/ranges.h" |
18 #include "media/base/stream_parser.h" | 18 #include "media/base/stream_parser.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 FFmpegURLProtocol; | 23 class FFmpegURLProtocol; |
24 class SourceState; | 24 class SourceState; |
25 | 25 |
| 26 template <class ConfigType> |
| 27 class TrackInfo { |
| 28 public: |
| 29 TrackInfo(StreamParser::TrackId track_id, const ConfigType& config) : |
| 30 track_id_(track_id), |
| 31 config_(config) { |
| 32 } |
| 33 |
| 34 StreamParser::TrackId track_id() const { return track_id_; } |
| 35 const ConfigType& config() const { return config_; } |
| 36 |
| 37 private: |
| 38 StreamParser::TrackId track_id_; |
| 39 ConfigType config_; |
| 40 }; |
| 41 |
| 42 typedef TrackInfo<AudioDecoderConfig> AudioTrackInfo; |
| 43 typedef TrackInfo<VideoDecoderConfig> VideoTrackInfo; |
| 44 typedef TrackInfo<TextTrackConfig> TextTrackInfo; |
| 45 |
| 46 struct InitSegment { |
| 47 static InitSegment Create( |
| 48 const AudioDecoderConfig& audio_config, |
| 49 const VideoDecoderConfig& video_config, |
| 50 const StreamParser::TextTrackConfigMap& text_configs); |
| 51 |
| 52 ~InitSegment(); |
| 53 |
| 54 bool HasTracks() const; |
| 55 |
| 56 const std::vector<AudioTrackInfo> audio_tracks; |
| 57 const std::vector<VideoTrackInfo> video_tracks; |
| 58 const std::vector<TextTrackInfo> text_tracks; |
| 59 |
| 60 private: |
| 61 InitSegment(const std::vector<AudioTrackInfo>& audio_tracks, |
| 62 const std::vector<VideoTrackInfo>& video_tracks, |
| 63 const std::vector<TextTrackInfo>& text_tracks); |
| 64 }; |
| 65 |
26 class MEDIA_EXPORT ChunkDemuxerStream : public DemuxerStream { | 66 class MEDIA_EXPORT ChunkDemuxerStream : public DemuxerStream { |
27 public: | 67 public: |
28 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; | 68 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; |
29 | 69 |
30 explicit ChunkDemuxerStream(Type type, bool splice_frames_enabled); | 70 explicit ChunkDemuxerStream(Type type, bool splice_frames_enabled); |
31 virtual ~ChunkDemuxerStream(); | 71 virtual ~ChunkDemuxerStream(); |
32 | 72 |
33 // ChunkDemuxerStream control methods. | 73 // ChunkDemuxerStream control methods. |
34 void StartReturningData(); | 74 void StartReturningData(); |
35 void AbortReads(); | 75 void AbortReads(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 bool splice_frames_enabled_; | 164 bool splice_frames_enabled_; |
125 bool partial_append_window_trimming_enabled_; | 165 bool partial_append_window_trimming_enabled_; |
126 | 166 |
127 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); | 167 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); |
128 }; | 168 }; |
129 | 169 |
130 // Demuxer implementation that allows chunks of media data to be passed | 170 // Demuxer implementation that allows chunks of media data to be passed |
131 // from JavaScript to the media stack. | 171 // from JavaScript to the media stack. |
132 class MEDIA_EXPORT ChunkDemuxer : public Demuxer { | 172 class MEDIA_EXPORT ChunkDemuxer : public Demuxer { |
133 public: | 173 public: |
| 174 typedef base::Callback<void(const InitSegment&)> NewInitSegmentCB; |
| 175 |
134 enum Status { | 176 enum Status { |
135 kOk, // ID added w/o error. | 177 kOk, // ID added w/o error. |
136 kNotSupported, // Type specified is not supported. | 178 kNotSupported, // Type specified is not supported. |
137 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs. | 179 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs. |
138 }; | 180 }; |
139 | 181 |
140 // |open_cb| Run when Initialize() is called to signal that the demuxer | 182 // |open_cb| Run when Initialize() is called to signal that the demuxer |
141 // is ready to receive media data via AppenData(). | 183 // is ready to receive media data via AppenData(). |
142 // |need_key_cb| Run when the demuxer determines that an encryption key is | 184 // |need_key_cb| Run when the demuxer determines that an encryption key is |
143 // needed to decrypt the content. | 185 // needed to decrypt the content. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // StartWaitingForSeek() call. This method also arranges for the next Seek() | 226 // StartWaitingForSeek() call. This method also arranges for the next Seek() |
185 // call received before a StartWaitingForSeek() call to immediately call its | 227 // call received before a StartWaitingForSeek() call to immediately call its |
186 // callback without waiting for any data. | 228 // callback without waiting for any data. |
187 // |seek_time| - The presentation timestamp for the seek request that | 229 // |seek_time| - The presentation timestamp for the seek request that |
188 // triggered this call. It represents the most recent position the caller is | 230 // triggered this call. It represents the most recent position the caller is |
189 // trying to seek to. | 231 // trying to seek to. |
190 void CancelPendingSeek(base::TimeDelta seek_time); | 232 void CancelPendingSeek(base::TimeDelta seek_time); |
191 | 233 |
192 // Registers a new |id| to use for AppendData() calls. |type| indicates | 234 // Registers a new |id| to use for AppendData() calls. |type| indicates |
193 // the MIME type for the data that we intend to append for this ID. | 235 // the MIME type for the data that we intend to append for this ID. |
| 236 // BIG TODO(wolenetz): document |new_init_segment_cb| once it's hooked up. |
194 // kOk is returned if the demuxer has enough resources to support another ID | 237 // kOk is returned if the demuxer has enough resources to support another ID |
195 // and supports the format indicated by |type|. | 238 // and supports the format indicated by |type|. |
196 // kNotSupported is returned if |type| is not a supported format. | 239 // kNotSupported is returned if |type| is not a supported format. |
197 // kReachedIdLimit is returned if the demuxer cannot handle another ID right | 240 // kReachedIdLimit is returned if the demuxer cannot handle another ID right |
198 // now. | 241 // now. |
199 Status AddId(const std::string& id, const std::string& type, | 242 Status AddId(const std::string& id, const std::string& type, |
200 std::vector<std::string>& codecs); | 243 std::vector<std::string>& codecs, |
| 244 const NewInitSegmentCB& new_init_segment_cb); |
201 | 245 |
202 // Removed an ID & associated resources that were previously added with | 246 // Removed an ID & associated resources that were previously added with |
203 // AddId(). | 247 // AddId(). |
204 void RemoveId(const std::string& id); | 248 void RemoveId(const std::string& id); |
205 | 249 |
206 // Gets the currently buffered ranges for the specified ID. | 250 // Gets the currently buffered ranges for the specified ID. |
207 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const; | 251 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const; |
208 | 252 |
209 // Appends media data to the source buffer associated with |id|, applying | 253 // Appends media data to the source buffer associated with |id|, applying |
210 // and possibly updating |*timestamp_offset| during coded frame processing. | 254 // and possibly updating |*timestamp_offset| during coded frame processing. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 429 |
386 // Indicates that splice frame generation is enabled. | 430 // Indicates that splice frame generation is enabled. |
387 const bool splice_frames_enabled_; | 431 const bool splice_frames_enabled_; |
388 | 432 |
389 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); | 433 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); |
390 }; | 434 }; |
391 | 435 |
392 } // namespace media | 436 } // namespace media |
393 | 437 |
394 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 438 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
OLD | NEW |