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 <map> | 9 #include <map> |
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/filters/source_buffer_stream.h" | 19 #include "media/filters/source_buffer_stream.h" |
19 | 20 |
20 namespace media { | 21 namespace media { |
21 | 22 |
22 class ChunkDemuxerStream; | |
23 class FFmpegURLProtocol; | 23 class FFmpegURLProtocol; |
24 class SourceState; | 24 class SourceState; |
25 | 25 |
26 class ChunkDemuxerStream : public DemuxerStream { | |
27 public: | |
28 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; | |
29 | |
30 explicit ChunkDemuxerStream(Type type); | |
31 virtual ~ChunkDemuxerStream(); | |
32 | |
33 // ChunkDemuxerStream control methods. | |
34 void StartReturningData(); | |
35 void AbortReads(); | |
36 void CompletePendingReadIfPossible(); | |
37 void Shutdown(); | |
38 | |
39 // SourceBufferStream manipulation methods. | |
40 void Seek(base::TimeDelta time); | |
41 bool IsSeekWaitingForData() const; | |
42 | |
43 // Add buffers to this stream. Buffers are stored in SourceBufferStreams, | |
44 // which handle ordering and overlap resolution. | |
45 // Returns true if buffers were successfully added. | |
46 bool Append(const StreamParser::BufferQueue& buffers); | |
47 | |
48 // Removes buffers between |start| and |end| according to the steps | |
49 // in the "Coded Frame Removal Algorithm" in the Media Source | |
50 // Extensions Spec. | |
51 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc e.html#sourcebuffer-coded-frame-removal | |
52 // | |
53 // |duration| is the current duration of the presentation. It is | |
54 // required by the computation outlined in the spec. | |
55 void Remove(base::TimeDelta start, base::TimeDelta end, | |
56 base::TimeDelta duration); | |
57 | |
58 // Signal to the stream that duration has changed to |duration|. | |
59 void OnSetDuration(base::TimeDelta duration); | |
60 | |
61 // Returns the range of buffered data in this stream, capped at |duration|. | |
62 Ranges<base::TimeDelta> GetBufferedRanges(base::TimeDelta duration) const; | |
63 | |
64 // Returns the duration of the buffered data. | |
65 // Returns base::TimeDelta() if the stream has no buffered data. | |
66 base::TimeDelta GetBufferedDuration() const; | |
67 | |
68 // Signal to the stream that buffers handed in through subsequent calls to | |
69 // Append() belong to a media segment that starts at |start_timestamp|. | |
70 void OnNewMediaSegment(base::TimeDelta start_timestamp); | |
71 | |
72 // Called when midstream config updates occur. | |
73 // Returns true if the new config is accepted. | |
74 // Returns false if the new config should trigger an error. | |
75 bool UpdateAudioConfig(const AudioDecoderConfig& config, const LogCB& log_cb); | |
76 bool UpdateVideoConfig(const VideoDecoderConfig& config, const LogCB& log_cb); | |
77 void UpdateTextConfig(const TextTrackConfig& config, const LogCB& log_cb); | |
78 | |
79 void MarkEndOfStream(); | |
80 void UnmarkEndOfStream(); | |
81 | |
82 // DemuxerStream methods. | |
83 virtual void Read(const ReadCB& read_cb) OVERRIDE; | |
84 virtual Type type() OVERRIDE; | |
85 virtual void EnableBitstreamConverter() OVERRIDE; | |
86 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; | |
87 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; | |
88 | |
89 // Returns the text track configuration. It is an error to call this method | |
90 // if type() != TEXT. | |
91 TextTrackConfig text_track_config(); | |
92 | |
93 // Sets the memory limit, in bytes, on the SourceBufferStream. | |
94 void set_memory_limit_for_testing(int memory_limit) { | |
95 stream_->set_memory_limit_for_testing(memory_limit); | |
96 } | |
97 | |
98 private: | |
99 enum State { | |
100 UNINITIALIZED, | |
101 RETURNING_DATA_FOR_READS, | |
102 RETURNING_ABORT_FOR_READS, | |
103 SHUTDOWN, | |
104 }; | |
105 | |
106 // Assigns |state_| to |state| | |
107 void ChangeState_Locked(State state); | |
108 | |
109 void CompletePendingReadIfPossible_Locked(); | |
110 | |
111 // Specifies the type of the stream. | |
112 Type type_; | |
113 | |
114 scoped_ptr<SourceBufferStream> stream_; | |
115 | |
116 mutable base::Lock lock_; | |
117 State state_; | |
118 ReadCB read_cb_; | |
119 | |
120 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); | |
121 }; | |
122 | |
26 // Demuxer implementation that allows chunks of media data to be passed | 123 // Demuxer implementation that allows chunks of media data to be passed |
27 // from JavaScript to the media stack. | 124 // from JavaScript to the media stack. |
28 class MEDIA_EXPORT ChunkDemuxer : public Demuxer { | 125 class MEDIA_EXPORT ChunkDemuxer : public Demuxer { |
29 public: | 126 public: |
30 enum Status { | 127 enum Status { |
31 kOk, // ID added w/o error. | 128 kOk, // ID added w/o error. |
32 kNotSupported, // Type specified is not supported. | 129 kNotSupported, // Type specified is not supported. |
33 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs. | 130 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs. |
34 }; | 131 }; |
35 | 132 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 Status AddId(const std::string& id, const std::string& type, | 188 Status AddId(const std::string& id, const std::string& type, |
92 std::vector<std::string>& codecs); | 189 std::vector<std::string>& codecs); |
93 | 190 |
94 // Removed an ID & associated resources that were previously added with | 191 // Removed an ID & associated resources that were previously added with |
95 // AddId(). | 192 // AddId(). |
96 void RemoveId(const std::string& id); | 193 void RemoveId(const std::string& id); |
97 | 194 |
98 // Gets the currently buffered ranges for the specified ID. | 195 // Gets the currently buffered ranges for the specified ID. |
99 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const; | 196 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const; |
100 | 197 |
101 // Appends media data to the source buffer associated with |id|. | 198 // Appends media data to the source buffer associated with |id|, applying |
102 // Appending may update |*timestamp_offset| if |timestamp_offset| is not NULL. | 199 // and possibly updating |*timestamp_offset| during coded frame processing. |
200 // |append_window_start| and |append_window_end| correspond to the MSE spec's | |
201 // similarly named source buffer attributes that are used in coded frame | |
202 // processing. | |
103 void AppendData(const std::string& id, const uint8* data, size_t length, | 203 void AppendData(const std::string& id, const uint8* data, size_t length, |
104 double* timestamp_offset); | 204 const base::TimeDelta& append_window_start, |
acolwell GONE FROM CHROMIUM
2014/03/11 20:00:37
nit: s/const base::TimeDelta&/base::TimeDelta/
wolenetz
2014/03/12 00:46:14
Done in the prereq CL I split out of this.
| |
205 const base::TimeDelta& append_window_end, | |
206 base::TimeDelta* timestamp_offset); | |
105 | 207 |
106 // Aborts parsing the current segment and reset the parser to a state where | 208 // Aborts parsing the current segment and reset the parser to a state where |
107 // it can accept a new segment. | 209 // it can accept a new segment. |
108 void Abort(const std::string& id); | 210 void Abort(const std::string& id); |
109 | 211 |
110 // Remove buffers between |start| and |end| for the source buffer | 212 // Remove buffers between |start| and |end| for the source buffer |
111 // associated with |id|. | 213 // associated with |id|. |
112 void Remove(const std::string& id, base::TimeDelta start, | 214 void Remove(const std::string& id, base::TimeDelta start, |
113 base::TimeDelta end); | 215 base::TimeDelta end); |
114 | 216 |
115 // Returns the current presentation duration. | 217 // Returns the current presentation duration. |
116 double GetDuration(); | 218 double GetDuration(); |
117 double GetDuration_Locked(); | 219 double GetDuration_Locked(); |
118 | 220 |
119 // Notifies the demuxer that the duration of the media has changed to | 221 // Notifies the demuxer that the duration of the media has changed to |
120 // |duration|. | 222 // |duration|. |
121 void SetDuration(double duration); | 223 void SetDuration(double duration); |
122 | 224 |
123 // Sets a time |offset| to be applied to subsequent buffers appended to the | 225 // Returns true if the source buffer associated with |id| is currently parsing |
124 // source buffer associated with |id|. Returns true if the offset is set | 226 // a media segment, or false otherwise. |
125 // properly, false if the offset cannot be applied because we're in the | 227 bool IsParsingMediaSegment(const std::string& id); |
126 // middle of parsing a media segment. | |
127 bool SetTimestampOffset(const std::string& id, base::TimeDelta offset); | |
128 | 228 |
129 // Set the append mode to be applied to subsequent buffers appended to the | 229 // Set the append mode to be applied to subsequent buffers appended to the |
130 // source buffer associated with |id|. If |sequence_mode| is true, caller | 230 // source buffer associated with |id|. If |sequence_mode| is true, caller |
131 // is requesting "sequence" mode. Otherwise, caller is requesting "segments" | 231 // is requesting "sequence" mode. Otherwise, caller is requesting "segments" |
132 // mode. Returns true if the mode update was allowed. Returns false if | 232 // mode. |
133 // the mode cannot be updated because we're in the middle of parsing a media | 233 void SetSequenceMode(const std::string& id, bool sequence_mode); |
134 // segment. | |
135 // In "sequence" mode, appended media will be treated as adjacent in time. | |
136 // In "segments" mode, timestamps in appended media determine coded frame | |
137 // placement. | |
138 bool SetSequenceMode(const std::string& id, bool sequence_mode); | |
139 | 234 |
140 // Called to signal changes in the "end of stream" | 235 // Called to signal changes in the "end of stream" |
141 // state. UnmarkEndOfStream() must not be called if a matching | 236 // state. UnmarkEndOfStream() must not be called if a matching |
142 // MarkEndOfStream() has not come before it. | 237 // MarkEndOfStream() has not come before it. |
143 void MarkEndOfStream(PipelineStatus status); | 238 void MarkEndOfStream(PipelineStatus status); |
144 void UnmarkEndOfStream(); | 239 void UnmarkEndOfStream(); |
145 | 240 |
146 // Set the append window start and end values for the source buffer | |
147 // associated with |id|. | |
148 void SetAppendWindowStart(const std::string& id, base::TimeDelta start); | |
149 void SetAppendWindowEnd(const std::string& id, base::TimeDelta end); | |
150 | |
151 void Shutdown(); | 241 void Shutdown(); |
152 | 242 |
153 // Sets the memory limit on each stream. |memory_limit| is the | 243 // Sets the memory limit on each stream. |memory_limit| is the |
154 // maximum number of bytes each stream is allowed to hold in its buffer. | 244 // maximum number of bytes each stream is allowed to hold in its buffer. |
155 void SetMemoryLimitsForTesting(int memory_limit); | 245 void SetMemoryLimitsForTesting(int memory_limit); |
156 | 246 |
157 // Returns the ranges representing the buffered data in the demuxer. | 247 // Returns the ranges representing the buffered data in the demuxer. |
158 // TODO(wolenetz): Remove this method once MediaSourceDelegate no longer | 248 // TODO(wolenetz): Remove this method once MediaSourceDelegate no longer |
159 // requires it for doing hack browser seeks to I-frame on Android. See | 249 // requires it for doing hack browser seeks to I-frame on Android. See |
160 // http://crbug.com/304234. | 250 // http://crbug.com/304234. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 // removed with RemoveID() but can not be re-added (yet). | 365 // removed with RemoveID() but can not be re-added (yet). |
276 std::string source_id_audio_; | 366 std::string source_id_audio_; |
277 std::string source_id_video_; | 367 std::string source_id_video_; |
278 | 368 |
279 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); | 369 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); |
280 }; | 370 }; |
281 | 371 |
282 } // namespace media | 372 } // namespace media |
283 | 373 |
284 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 374 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
OLD | NEW |