Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: media/filters/chunk_demuxer.h

Issue 2643743002: Mojify demuxers and allow running {Chunk/FFmpeg}Demuxer in a Utility Process (Closed)
Patch Set: Rebase and make sure to unbind mojom::DemuxerPtr on the bound thread during termination Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/blink/websourcebuffer_impl.cc ('k') | media/filters/default_demuxer_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <deque> 11 #include <deque>
12 #include <map> 12 #include <map>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 #include <utility> 15 #include <utility>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/memory_pressure_listener.h"
20 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
21 #include "media/base/byte_queue.h" 20 #include "media/base/byte_queue.h"
22 #include "media/base/demuxer.h" 21 #include "media/base/demuxer.h"
23 #include "media/base/demuxer_stream.h" 22 #include "media/base/demuxer_stream.h"
24 #include "media/base/media_tracks.h" 23 #include "media/base/media_tracks.h"
25 #include "media/base/ranges.h" 24 #include "media/base/ranges.h"
25 #include "media/base/source_buffer.h"
26 #include "media/base/stream_parser.h" 26 #include "media/base/stream_parser.h"
27 #include "media/filters/source_buffer_state.h" 27 #include "media/filters/source_buffer_state.h"
28 #include "media/filters/source_buffer_stream.h" 28 #include "media/filters/source_buffer_stream.h"
29 29
30 namespace media { 30 namespace media {
31 31
32 class MEDIA_EXPORT ChunkDemuxerStream : public DemuxerStream { 32 class MEDIA_EXPORT ChunkDemuxerStream : public DemuxerStream {
33 public: 33 public:
34 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; 34 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue;
35 35
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ReadCB read_cb_; 160 ReadCB read_cb_;
161 bool partial_append_window_trimming_enabled_; 161 bool partial_append_window_trimming_enabled_;
162 bool is_enabled_; 162 bool is_enabled_;
163 StreamStatusChangeCB stream_status_change_cb_; 163 StreamStatusChangeCB stream_status_change_cb_;
164 164
165 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); 165 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream);
166 }; 166 };
167 167
168 // Demuxer implementation that allows chunks of media data to be passed 168 // Demuxer implementation that allows chunks of media data to be passed
169 // from JavaScript to the media stack. 169 // from JavaScript to the media stack.
170 class MEDIA_EXPORT ChunkDemuxer : public Demuxer { 170 class MEDIA_EXPORT ChunkDemuxer : public Demuxer, public SourceBuffer {
171 public: 171 public:
172 enum Status {
173 kOk, // ID added w/o error.
174 kNotSupported, // Type specified is not supported.
175 kReachedIdLimit, // Reached ID limit. We can't handle any more IDs.
176 };
177 172
178 // |open_cb| Run when Initialize() is called to signal that the demuxer 173 // |open_cb| Run when Initialize() is called to signal that the demuxer
179 // is ready to receive media data via AppenData(). 174 // is ready to receive media data via AppenData().
180 // |encrypted_media_init_data_cb| Run when the demuxer determines that an 175 // |encrypted_media_init_data_cb| Run when the demuxer determines that an
181 // encryption key is needed to decrypt the content. 176 // encryption key is needed to decrypt the content.
182 // |media_log| Used to report content and engine debug messages. 177 // |media_log| Used to report content and engine debug messages.
183 ChunkDemuxer(const base::Closure& open_cb, 178 ChunkDemuxer(const base::Closure& open_cb,
184 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, 179 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb,
185 const scoped_refptr<MediaLog>& media_log); 180 const scoped_refptr<MediaLog>& media_log);
186 ~ChunkDemuxer() override; 181 ~ChunkDemuxer() override;
(...skipping 23 matching lines...) Expand all
210 205
211 // Registers a new |id| to use for AppendData() calls. |type| indicates 206 // Registers a new |id| to use for AppendData() calls. |type| indicates
212 // the MIME type for the data that we intend to append for this ID. 207 // the MIME type for the data that we intend to append for this ID.
213 // kOk is returned if the demuxer has enough resources to support another ID 208 // kOk is returned if the demuxer has enough resources to support another ID
214 // and supports the format indicated by |type|. 209 // and supports the format indicated by |type|.
215 // kNotSupported is returned if |type| is not a supported format. 210 // kNotSupported is returned if |type| is not a supported format.
216 // kReachedIdLimit is returned if the demuxer cannot handle another ID right 211 // kReachedIdLimit is returned if the demuxer cannot handle another ID right
217 // now. 212 // now.
218 Status AddId(const std::string& id, 213 Status AddId(const std::string& id,
219 const std::string& type, 214 const std::string& type,
220 const std::string& codecs); 215 const std::string& codecs) final;
221 216
222 // Notifies a caller via |tracks_updated_cb| that the set of media tracks 217 // Notifies a caller via |tracks_updated_cb| that the set of media tracks
223 // for a given |id| has changed. 218 // for a given |id| has changed.
224 void SetTracksWatcher(const std::string& id, 219 void SetTracksWatcher(const std::string& id,
225 const MediaTracksUpdatedCB& tracks_updated_cb); 220 const MediaTracksUpdatedCB& tracks_updated_cb) final;
226 221
227 // Removed an ID & associated resources that were previously added with 222 // Removed an ID & associated resources that were previously added with
228 // AddId(). 223 // AddId().
229 void RemoveId(const std::string& id); 224 void RemoveId(const std::string& id) final;
230 225
231 // Gets the currently buffered ranges for the specified ID. 226 // Gets the currently buffered ranges for the specified ID.
232 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const; 227 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const final;
233 228
234 // Gets the highest buffered PTS for the specified |id|. If there is nothing 229 // Gets the highest buffered PTS for the specified |id|. If there is nothing
235 // buffered, returns base::TimeDelta(). 230 // buffered, returns base::TimeDelta().
236 base::TimeDelta GetHighestPresentationTimestamp(const std::string& id) const; 231 base::TimeDelta GetHighestPresentationTimestamp(
232 const std::string& id) const final;
237 233
238 void OnEnabledAudioTracksChanged(const std::vector<MediaTrack::Id>& track_ids, 234 void OnEnabledAudioTracksChanged(const std::vector<MediaTrack::Id>& track_ids,
239 base::TimeDelta currTime) override; 235 base::TimeDelta currTime) final;
240 // |track_ids| is either empty or contains a single video track id. 236 // |track_ids| is either empty or contains a single video track id.
241 void OnSelectedVideoTrackChanged(const std::vector<MediaTrack::Id>& track_ids, 237 void OnSelectedVideoTrackChanged(const std::vector<MediaTrack::Id>& track_ids,
242 base::TimeDelta currTime) override; 238 base::TimeDelta currTime) final;
243 239
244 // Appends media data to the source buffer associated with |id|, applying 240 // Appends media data to the source buffer associated with |id|, applying
245 // and possibly updating |*timestamp_offset| during coded frame processing. 241 // and possibly updating |*timestamp_offset| during coded frame processing.
246 // |append_window_start| and |append_window_end| correspond to the MSE spec's 242 // |append_window_start| and |append_window_end| correspond to the MSE spec's
247 // similarly named source buffer attributes that are used in coded frame 243 // similarly named source buffer attributes that are used in coded frame
248 // processing. Returns true on success, false if the caller needs to run the 244 // processing. Returns true on success, false if the caller needs to run the
249 // append error algorithm with decode error parameter set to true. 245 // append error algorithm with decode error parameter set to true.
250 bool AppendData(const std::string& id, 246 bool AppendData(const std::string& id,
251 const uint8_t* data, 247 const uint8_t* data,
252 size_t length, 248 size_t length,
253 base::TimeDelta append_window_start, 249 base::TimeDelta append_window_start,
254 base::TimeDelta append_window_end, 250 base::TimeDelta append_window_end,
255 base::TimeDelta* timestamp_offset); 251 base::TimeDelta* timestamp_offset) final;
256 252
257 // Aborts parsing the current segment and reset the parser to a state where 253 // Aborts parsing the current segment and reset the parser to a state where
258 // it can accept a new segment. 254 // it can accept a new segment.
259 // Some pending frames can be emitted during that process. These frames are 255 // Some pending frames can be emitted during that process. These frames are
260 // applied |timestamp_offset|. 256 // applied |timestamp_offset|.
261 void ResetParserState(const std::string& id, 257 void ResetParserState(const std::string& id,
262 base::TimeDelta append_window_start, 258 base::TimeDelta append_window_start,
263 base::TimeDelta append_window_end, 259 base::TimeDelta append_window_end,
264 base::TimeDelta* timestamp_offset); 260 base::TimeDelta* timestamp_offset) final;
265 261
266 // Remove buffers between |start| and |end| for the source buffer 262 // Remove buffers between |start| and |end| for the source buffer
267 // associated with |id|. 263 // associated with |id|.
268 void Remove(const std::string& id, base::TimeDelta start, 264 void Remove(const std::string& id,
269 base::TimeDelta end); 265 base::TimeDelta start,
266 base::TimeDelta end) final;
270 267
271 // If the buffer is full, attempts to try to free up space, as specified in 268 // If the buffer is full, attempts to try to free up space, as specified in
272 // the "Coded Frame Eviction Algorithm" in the Media Source Extensions Spec. 269 // the "Coded Frame Eviction Algorithm" in the Media Source Extensions Spec.
273 // Returns false iff buffer is still full after running eviction. 270 // Returns false iff buffer is still full after running eviction.
274 // https://w3c.github.io/media-source/#sourcebuffer-coded-frame-eviction 271 // https://w3c.github.io/media-source/#sourcebuffer-coded-frame-eviction
275 bool EvictCodedFrames(const std::string& id, 272 bool EvictCodedFrames(const std::string& id,
276 base::TimeDelta currentMediaTime, 273 base::TimeDelta currentMediaTime,
277 size_t newDataSize); 274 size_t newDataSize) final;
278 275
279 void OnMemoryPressure( 276 void OnMemoryPressure(
280 base::TimeDelta currentMediaTime, 277 base::TimeDelta currentMediaTime,
281 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level, 278 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level,
282 bool force_instant_gc); 279 bool force_instant_gc) final;
283 280
284 // Returns the current presentation duration. 281 // Returns the current presentation duration.
285 double GetDuration(); 282 double GetDuration() final;
286 double GetDuration_Locked(); 283 double GetDuration_Locked() final;
287 284
288 // Notifies the demuxer that the duration of the media has changed to 285 // Notifies the demuxer that the duration of the media has changed to
289 // |duration|. 286 // |duration|.
290 void SetDuration(double duration); 287 void SetDuration(double duration) final;
291 288
292 // Returns true if the source buffer associated with |id| is currently parsing 289 // Returns true if the source buffer associated with |id| is currently parsing
293 // a media segment, or false otherwise. 290 // a media segment, or false otherwise.
294 bool IsParsingMediaSegment(const std::string& id); 291 bool IsParsingMediaSegment(const std::string& id) final;
295 292
296 // Set the append mode to be applied to subsequent buffers appended to the 293 // Set the append mode to be applied to subsequent buffers appended to the
297 // source buffer associated with |id|. If |sequence_mode| is true, caller 294 // source buffer associated with |id|. If |sequence_mode| is true, caller
298 // is requesting "sequence" mode. Otherwise, caller is requesting "segments" 295 // is requesting "sequence" mode. Otherwise, caller is requesting "segments"
299 // mode. 296 // mode.
300 void SetSequenceMode(const std::string& id, bool sequence_mode); 297 void SetSequenceMode(const std::string& id, bool sequence_mode) final;
301 298
302 // Signals the coded frame processor for the source buffer associated with 299 // Signals the coded frame processor for the source buffer associated with
303 // |id| to update its group start timestamp to be |timestamp_offset| if it is 300 // |id| to update its group start timestamp to be |timestamp_offset| if it is
304 // in sequence append mode. 301 // in sequence append mode.
305 void SetGroupStartTimestampIfInSequenceMode(const std::string& id, 302 void SetGroupStartTimestampIfInSequenceMode(
306 base::TimeDelta timestamp_offset); 303 const std::string& id,
304 base::TimeDelta timestamp_offset) final;
307 305
308 // Called to signal changes in the "end of stream" 306 // Called to signal changes in the "end of stream"
309 // state. UnmarkEndOfStream() must not be called if a matching 307 // state. UnmarkEndOfStream() must not be called if a matching
310 // MarkEndOfStream() has not come before it. 308 // MarkEndOfStream() has not come before it.
311 void MarkEndOfStream(PipelineStatus status); 309 void MarkEndOfStream(PipelineStatus status) final;
312 void UnmarkEndOfStream(); 310 void UnmarkEndOfStream() final;
313 311
314 void Shutdown(); 312 void Shutdown() final;
315 313
316 // Sets the memory limit on each stream of a specific type. 314 // Sets the memory limit on each stream of a specific type.
317 // |memory_limit| is the maximum number of bytes each stream of type |type| 315 // |memory_limit| is the maximum number of bytes each stream of type |type|
318 // is allowed to hold in its buffer. 316 // is allowed to hold in its buffer.
319 void SetMemoryLimitsForTest(DemuxerStream::Type type, size_t memory_limit); 317 void SetMemoryLimitsForTest(DemuxerStream::Type type,
318 size_t memory_limit) final;
320 319
321 // Returns the ranges representing the buffered data in the demuxer. 320 // Returns the ranges representing the buffered data in the demuxer.
322 // TODO(wolenetz): Remove this method once MediaSourceDelegate no longer 321 // TODO(wolenetz): Remove this method once MediaSourceDelegate no longer
323 // requires it for doing hack browser seeks to I-frame on Android. See 322 // requires it for doing hack browser seeks to I-frame on Android. See
324 // http://crbug.com/304234. 323 // http://crbug.com/304234.
325 Ranges<base::TimeDelta> GetBufferedRanges() const; 324 Ranges<base::TimeDelta> GetBufferedRanges() const final;
326 325
327 private: 326 private:
328 enum State { 327 enum State {
329 WAITING_FOR_INIT, 328 WAITING_FOR_INIT,
330 INITIALIZING, 329 INITIALIZING,
331 INITIALIZED, 330 INITIALIZED,
332 ENDED, 331 ENDED,
333 PARSE_ERROR, 332 PARSE_ERROR,
334 SHUTDOWN, 333 SHUTDOWN,
335 }; 334 };
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 int detected_text_track_count_; 451 int detected_text_track_count_;
453 452
454 std::map<MediaTrack::Id, DemuxerStream*> track_id_to_demux_stream_map_; 453 std::map<MediaTrack::Id, DemuxerStream*> track_id_to_demux_stream_map_;
455 454
456 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); 455 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer);
457 }; 456 };
458 457
459 } // namespace media 458 } // namespace media
460 459
461 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ 460 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_
OLDNEW
« no previous file with comments | « media/blink/websourcebuffer_impl.cc ('k') | media/filters/default_demuxer_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698