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

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

Issue 2226443002: Support multiple media tracks in MSE / ChunkDemuxer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed integer overflow Created 4 years, 3 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/webmediasource_impl.cc ('k') | media/filters/chunk_demuxer.cc » ('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 <string> 14 #include <string>
14 #include <utility> 15 #include <utility>
15 #include <vector> 16 #include <vector>
16 17
17 #include "base/macros.h" 18 #include "base/macros.h"
18 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
19 #include "media/base/byte_queue.h" 20 #include "media/base/byte_queue.h"
20 #include "media/base/demuxer.h" 21 #include "media/base/demuxer.h"
21 #include "media/base/demuxer_stream.h" 22 #include "media/base/demuxer_stream.h"
22 #include "media/base/media_tracks.h" 23 #include "media/base/media_tracks.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 void StartWaitingForSeek(base::TimeDelta seek_time) override; 211 void StartWaitingForSeek(base::TimeDelta seek_time) override;
211 void CancelPendingSeek(base::TimeDelta seek_time) override; 212 void CancelPendingSeek(base::TimeDelta seek_time) override;
212 213
213 // Registers a new |id| to use for AppendData() calls. |type| indicates 214 // Registers a new |id| to use for AppendData() calls. |type| indicates
214 // the MIME type for the data that we intend to append for this ID. 215 // the MIME type for the data that we intend to append for this ID.
215 // kOk is returned if the demuxer has enough resources to support another ID 216 // kOk is returned if the demuxer has enough resources to support another ID
216 // and supports the format indicated by |type|. 217 // and supports the format indicated by |type|.
217 // kNotSupported is returned if |type| is not a supported format. 218 // kNotSupported is returned if |type| is not a supported format.
218 // kReachedIdLimit is returned if the demuxer cannot handle another ID right 219 // kReachedIdLimit is returned if the demuxer cannot handle another ID right
219 // now. 220 // now.
220 Status AddId(const std::string& id, const std::string& type, 221 Status AddId(const std::string& id,
221 std::vector<std::string>& codecs); 222 const std::string& type,
223 const std::string& codecs);
222 224
223 // Notifies a caller via |tracks_updated_cb| that the set of media tracks 225 // Notifies a caller via |tracks_updated_cb| that the set of media tracks
224 // for a given |id| has changed. 226 // for a given |id| has changed.
225 void SetTracksWatcher(const std::string& id, 227 void SetTracksWatcher(const std::string& id,
226 const MediaTracksUpdatedCB& tracks_updated_cb); 228 const MediaTracksUpdatedCB& tracks_updated_cb);
227 229
228 // Removed an ID & associated resources that were previously added with 230 // Removed an ID & associated resources that were previously added with
229 // AddId(). 231 // AddId().
230 void RemoveId(const std::string& id); 232 void RemoveId(const std::string& id);
231 233
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // state. UnmarkEndOfStream() must not be called if a matching 307 // state. UnmarkEndOfStream() must not be called if a matching
306 // MarkEndOfStream() has not come before it. 308 // MarkEndOfStream() has not come before it.
307 void MarkEndOfStream(PipelineStatus status); 309 void MarkEndOfStream(PipelineStatus status);
308 void UnmarkEndOfStream(); 310 void UnmarkEndOfStream();
309 311
310 void Shutdown(); 312 void Shutdown();
311 313
312 // Sets the memory limit on each stream of a specific type. 314 // Sets the memory limit on each stream of a specific type.
313 // |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|
314 // is allowed to hold in its buffer. 316 // is allowed to hold in its buffer.
315 void SetMemoryLimits(DemuxerStream::Type type, size_t memory_limit); 317 void SetMemoryLimitsForTest(DemuxerStream::Type type, size_t memory_limit);
316 318
317 // Returns the ranges representing the buffered data in the demuxer. 319 // Returns the ranges representing the buffered data in the demuxer.
318 // TODO(wolenetz): Remove this method once MediaSourceDelegate no longer 320 // TODO(wolenetz): Remove this method once MediaSourceDelegate no longer
319 // requires it for doing hack browser seeks to I-frame on Android. See 321 // requires it for doing hack browser seeks to I-frame on Android. See
320 // http://crbug.com/304234. 322 // http://crbug.com/304234.
321 Ranges<base::TimeDelta> GetBufferedRanges() const; 323 Ranges<base::TimeDelta> GetBufferedRanges() const;
322 324
323 private: 325 private:
324 enum State { 326 enum State {
325 WAITING_FOR_INIT, 327 WAITING_FOR_INIT,
(...skipping 11 matching lines...) Expand all
337 void ReportError_Locked(PipelineStatus error); 339 void ReportError_Locked(PipelineStatus error);
338 340
339 // Returns true if any stream has seeked to a time without buffered data. 341 // Returns true if any stream has seeked to a time without buffered data.
340 bool IsSeekWaitingForData_Locked() const; 342 bool IsSeekWaitingForData_Locked() const;
341 343
342 // Returns true if all streams can successfully call EndOfStream, 344 // Returns true if all streams can successfully call EndOfStream,
343 // false if any can not. 345 // false if any can not.
344 bool CanEndOfStream_Locked() const; 346 bool CanEndOfStream_Locked() const;
345 347
346 // MediaSourceState callbacks. 348 // MediaSourceState callbacks.
347 void OnSourceInitDone(const StreamParser::InitParameters& params); 349 void OnSourceInitDone(const std::string& source_id,
350 const StreamParser::InitParameters& params);
348 351
349 // Creates a DemuxerStream for the specified |type|. 352 // Creates a DemuxerStream of the specified |type| for the MediaSourceState
350 // Returns a new ChunkDemuxerStream instance if a stream of this type 353 // with the given |source_id|.
351 // has not been created before. Returns NULL otherwise. 354 // Returns a pointer to a new ChunkDemuxerStream instance, which is owned by
352 ChunkDemuxerStream* CreateDemuxerStream(DemuxerStream::Type type); 355 // ChunkDemuxer.
356 ChunkDemuxerStream* CreateDemuxerStream(const std::string& source_id,
357 DemuxerStream::Type type);
353 358
354 void OnNewTextTrack(ChunkDemuxerStream* text_stream, 359 void OnNewTextTrack(ChunkDemuxerStream* text_stream,
355 const TextTrackConfig& config); 360 const TextTrackConfig& config);
356 361
357 // Returns true if |source_id| is valid, false otherwise. 362 // Returns true if |source_id| is valid, false otherwise.
358 bool IsValidId(const std::string& source_id) const; 363 bool IsValidId(const std::string& source_id) const;
359 364
360 // Increases |duration_| to |new_duration|, if |new_duration| is higher. 365 // Increases |duration_| to |new_duration|, if |new_duration| is higher.
361 void IncreaseDurationIfNecessary(base::TimeDelta new_duration); 366 void IncreaseDurationIfNecessary(base::TimeDelta new_duration);
362 367
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // MediaLog for reporting messages and properties to debug content and engine. 406 // MediaLog for reporting messages and properties to debug content and engine.
402 scoped_refptr<MediaLog> media_log_; 407 scoped_refptr<MediaLog> media_log_;
403 408
404 PipelineStatusCB init_cb_; 409 PipelineStatusCB init_cb_;
405 // Callback to execute upon seek completion. 410 // Callback to execute upon seek completion.
406 // TODO(wolenetz/acolwell): Protect against possible double-locking by first 411 // TODO(wolenetz/acolwell): Protect against possible double-locking by first
407 // releasing |lock_| before executing this callback. See 412 // releasing |lock_| before executing this callback. See
408 // http://crbug.com/308226 413 // http://crbug.com/308226
409 PipelineStatusCB seek_cb_; 414 PipelineStatusCB seek_cb_;
410 415
411 std::unique_ptr<ChunkDemuxerStream> audio_; 416 std::vector<std::unique_ptr<ChunkDemuxerStream>> audio_streams_;
412 std::unique_ptr<ChunkDemuxerStream> video_; 417 std::vector<std::unique_ptr<ChunkDemuxerStream>> video_streams_;
413 418
414 // Counter to ensure that we do not transition too early to INITIALIZED. 419 // Keep track of which ids still remain uninitialized so that we transition
415 // Incremented in AddId(), decremented in OnSourceInitDone(). 420 // into the INITIALIZED only after all ids/SourceBuffers got init segment.
416 int pending_source_init_done_count_; 421 std::set<std::string> pending_source_init_ids_;
417 422
418 base::TimeDelta duration_; 423 base::TimeDelta duration_;
419 424
420 // The duration passed to the last SetDuration(). If 425 // The duration passed to the last SetDuration(). If
421 // SetDuration() is never called or an AppendData() call or 426 // SetDuration() is never called or an AppendData() call or
422 // a EndOfStream() call changes |duration_|, then this 427 // a EndOfStream() call changes |duration_|, then this
423 // variable is set to < 0 to indicate that the |duration_| represents 428 // variable is set to < 0 to indicate that the |duration_| represents
424 // the actual duration instead of a user specified value. 429 // the actual duration instead of a user specified value.
425 double user_specified_duration_; 430 double user_specified_duration_;
426 431
427 base::Time timeline_offset_; 432 base::Time timeline_offset_;
428 DemuxerStream::Liveness liveness_; 433 DemuxerStream::Liveness liveness_;
429 434
430 typedef std::map<std::string, MediaSourceState*> MediaSourceStateMap; 435 typedef std::map<std::string, MediaSourceState*> MediaSourceStateMap;
431 MediaSourceStateMap source_state_map_; 436 MediaSourceStateMap source_state_map_;
432 437
433 // Used to ensure that (1) config data matches the type and codec provided in 438 std::map<std::string, std::vector<ChunkDemuxerStream*>> id_to_streams_map_;
434 // AddId(), (2) only 1 audio and 1 video sources are added, and (3) ids may be 439 // Used to hold alive the demuxer streams that were created for removed /
435 // removed with RemoveID() but can not be re-added (yet). 440 // released MediaSourceState objects. Demuxer clients might still have
436 std::string source_id_audio_; 441 // references to these streams, so we need to keep them alive. But they'll be
437 std::string source_id_video_; 442 // in a shut down state, so reading from them will return EOS.
443 std::vector<std::unique_ptr<ChunkDemuxerStream>> removed_streams_;
438 444
439 // Indicates that splice frame generation is enabled. 445 // Indicates that splice frame generation is enabled.
440 const bool splice_frames_enabled_; 446 const bool splice_frames_enabled_;
441 447
442 // Accumulate, by type, detected track counts across the SourceBuffers. 448 // Accumulate, by type, detected track counts across the SourceBuffers.
443 int detected_audio_track_count_; 449 int detected_audio_track_count_;
444 int detected_video_track_count_; 450 int detected_video_track_count_;
445 int detected_text_track_count_; 451 int detected_text_track_count_;
446 452
447 std::map<MediaTrack::Id, const DemuxerStream*> track_id_to_demux_stream_map_; 453 std::map<MediaTrack::Id, DemuxerStream*> track_id_to_demux_stream_map_;
448 454
449 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); 455 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer);
450 }; 456 };
451 457
452 } // namespace media 458 } // namespace media
453 459
454 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ 460 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_
OLDNEW
« no previous file with comments | « media/blink/webmediasource_impl.cc ('k') | media/filters/chunk_demuxer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698