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 <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 <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "media/base/byte_queue.h" | 19 #include "media/base/byte_queue.h" |
20 #include "media/base/demuxer.h" | 20 #include "media/base/demuxer.h" |
21 #include "media/base/demuxer_stream.h" | 21 #include "media/base/demuxer_stream.h" |
| 22 #include "media/base/media_tracks.h" |
22 #include "media/base/ranges.h" | 23 #include "media/base/ranges.h" |
23 #include "media/base/stream_parser.h" | 24 #include "media/base/stream_parser.h" |
24 #include "media/filters/media_source_state.h" | 25 #include "media/filters/media_source_state.h" |
25 #include "media/filters/source_buffer_stream.h" | 26 #include "media/filters/source_buffer_stream.h" |
26 | 27 |
27 namespace media { | 28 namespace media { |
28 | 29 |
29 class FFmpegURLProtocol; | 30 class FFmpegURLProtocol; |
30 | 31 |
31 class MEDIA_EXPORT ChunkDemuxerStream : public DemuxerStream { | 32 class MEDIA_EXPORT ChunkDemuxerStream : public DemuxerStream { |
32 public: | 33 public: |
33 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; | 34 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; |
34 | 35 |
35 ChunkDemuxerStream(Type type, bool splice_frames_enabled); | 36 ChunkDemuxerStream(Type type, |
| 37 bool splice_frames_enabled, |
| 38 MediaTrack::TrackId media_track_id); |
36 ~ChunkDemuxerStream() override; | 39 ~ChunkDemuxerStream() override; |
37 | 40 |
38 // ChunkDemuxerStream control methods. | 41 // ChunkDemuxerStream control methods. |
39 void StartReturningData(); | 42 void StartReturningData(); |
40 void AbortReads(); | 43 void AbortReads(); |
41 void CompletePendingReadIfPossible(); | 44 void CompletePendingReadIfPossible(); |
42 void Shutdown(); | 45 void Shutdown(); |
43 | 46 |
44 // SourceBufferStream manipulation methods. | 47 // SourceBufferStream manipulation methods. |
45 void Seek(base::TimeDelta time); | 48 void Seek(base::TimeDelta time); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 114 |
112 // Sets the memory limit, in bytes, on the SourceBufferStream. | 115 // Sets the memory limit, in bytes, on the SourceBufferStream. |
113 void SetStreamMemoryLimit(size_t memory_limit); | 116 void SetStreamMemoryLimit(size_t memory_limit); |
114 | 117 |
115 bool supports_partial_append_window_trimming() const { | 118 bool supports_partial_append_window_trimming() const { |
116 return partial_append_window_trimming_enabled_; | 119 return partial_append_window_trimming_enabled_; |
117 } | 120 } |
118 | 121 |
119 void SetLiveness(Liveness liveness); | 122 void SetLiveness(Liveness liveness); |
120 | 123 |
| 124 MediaTrack::TrackId media_track_id() const { return media_track_id_; } |
| 125 |
121 private: | 126 private: |
122 enum State { | 127 enum State { |
123 UNINITIALIZED, | 128 UNINITIALIZED, |
124 RETURNING_DATA_FOR_READS, | 129 RETURNING_DATA_FOR_READS, |
125 RETURNING_ABORT_FOR_READS, | 130 RETURNING_ABORT_FOR_READS, |
126 SHUTDOWN, | 131 SHUTDOWN, |
127 }; | 132 }; |
128 | 133 |
129 // Assigns |state_| to |state| | 134 // Assigns |state_| to |state| |
130 void ChangeState_Locked(State state); | 135 void ChangeState_Locked(State state); |
131 | 136 |
132 void CompletePendingReadIfPossible_Locked(); | 137 void CompletePendingReadIfPossible_Locked(); |
133 | 138 |
134 // Specifies the type of the stream. | 139 // Specifies the type of the stream. |
135 Type type_; | 140 Type type_; |
136 | 141 |
137 Liveness liveness_; | 142 Liveness liveness_; |
138 | 143 |
139 std::unique_ptr<SourceBufferStream> stream_; | 144 std::unique_ptr<SourceBufferStream> stream_; |
140 | 145 |
| 146 const MediaTrack::TrackId media_track_id_; |
| 147 |
141 mutable base::Lock lock_; | 148 mutable base::Lock lock_; |
142 State state_; | 149 State state_; |
143 ReadCB read_cb_; | 150 ReadCB read_cb_; |
144 bool splice_frames_enabled_; | 151 bool splice_frames_enabled_; |
145 bool partial_append_window_trimming_enabled_; | 152 bool partial_append_window_trimming_enabled_; |
146 | 153 |
147 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); | 154 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); |
148 }; | 155 }; |
149 | 156 |
150 // Demuxer implementation that allows chunks of media data to be passed | 157 // Demuxer implementation that allows chunks of media data to be passed |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 // kReachedIdLimit is returned if the demuxer cannot handle another ID right | 208 // kReachedIdLimit is returned if the demuxer cannot handle another ID right |
202 // now. | 209 // now. |
203 Status AddId(const std::string& id, const std::string& type, | 210 Status AddId(const std::string& id, const std::string& type, |
204 std::vector<std::string>& codecs); | 211 std::vector<std::string>& codecs); |
205 | 212 |
206 // Notifies a caller via |tracks_updated_cb| that the set of media tracks | 213 // Notifies a caller via |tracks_updated_cb| that the set of media tracks |
207 // for a given |id| has changed. | 214 // for a given |id| has changed. |
208 void SetTracksWatcher(const std::string& id, | 215 void SetTracksWatcher(const std::string& id, |
209 const MediaTracksUpdatedCB& tracks_updated_cb); | 216 const MediaTracksUpdatedCB& tracks_updated_cb); |
210 | 217 |
| 218 const DemuxerStream* GetDemuxerStreamByTrackId( |
| 219 MediaTrack::TrackId track_id) const override; |
| 220 |
211 // Removed an ID & associated resources that were previously added with | 221 // Removed an ID & associated resources that were previously added with |
212 // AddId(). | 222 // AddId(). |
213 void RemoveId(const std::string& id); | 223 void RemoveId(const std::string& id); |
214 | 224 |
215 // Gets the currently buffered ranges for the specified ID. | 225 // Gets the currently buffered ranges for the specified ID. |
216 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const; | 226 Ranges<base::TimeDelta> GetBufferedRanges(const std::string& id) const; |
217 | 227 |
218 // Appends media data to the source buffer associated with |id|, applying | 228 // Appends media data to the source buffer associated with |id|, applying |
219 // and possibly updating |*timestamp_offset| during coded frame processing. | 229 // and possibly updating |*timestamp_offset| during coded frame processing. |
220 // |append_window_start| and |append_window_end| correspond to the MSE spec's | 230 // |append_window_start| and |append_window_end| correspond to the MSE spec's |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 void OnSourceInitDone(const StreamParser::InitParameters& params); | 329 void OnSourceInitDone(const StreamParser::InitParameters& params); |
320 | 330 |
321 // Creates a DemuxerStream for the specified |type|. | 331 // Creates a DemuxerStream for the specified |type|. |
322 // Returns a new ChunkDemuxerStream instance if a stream of this type | 332 // Returns a new ChunkDemuxerStream instance if a stream of this type |
323 // has not been created before. Returns NULL otherwise. | 333 // has not been created before. Returns NULL otherwise. |
324 ChunkDemuxerStream* CreateDemuxerStream(DemuxerStream::Type type); | 334 ChunkDemuxerStream* CreateDemuxerStream(DemuxerStream::Type type); |
325 | 335 |
326 void OnNewTextTrack(ChunkDemuxerStream* text_stream, | 336 void OnNewTextTrack(ChunkDemuxerStream* text_stream, |
327 const TextTrackConfig& config); | 337 const TextTrackConfig& config); |
328 | 338 |
| 339 void OnInitSegmentReported(const MediaTracksUpdatedCB& tracks_updated_cb, |
| 340 std::unique_ptr<MediaTracks> tracks); |
| 341 |
329 // Returns true if |source_id| is valid, false otherwise. | 342 // Returns true if |source_id| is valid, false otherwise. |
330 bool IsValidId(const std::string& source_id) const; | 343 bool IsValidId(const std::string& source_id) const; |
331 | 344 |
332 // Increases |duration_| to |new_duration|, if |new_duration| is higher. | 345 // Increases |duration_| to |new_duration|, if |new_duration| is higher. |
333 void IncreaseDurationIfNecessary(base::TimeDelta new_duration); | 346 void IncreaseDurationIfNecessary(base::TimeDelta new_duration); |
334 | 347 |
335 // Decreases |duration_| if the buffered region is less than |duration_| when | 348 // Decreases |duration_| if the buffered region is less than |duration_| when |
336 // EndOfStream() is called. | 349 // EndOfStream() is called. |
337 void DecreaseDurationIfNecessary(); | 350 void DecreaseDurationIfNecessary(); |
338 | 351 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 std::string source_id_video_; | 420 std::string source_id_video_; |
408 | 421 |
409 // Indicates that splice frame generation is enabled. | 422 // Indicates that splice frame generation is enabled. |
410 const bool splice_frames_enabled_; | 423 const bool splice_frames_enabled_; |
411 | 424 |
412 // Accumulate, by type, detected track counts across the SourceBuffers. | 425 // Accumulate, by type, detected track counts across the SourceBuffers. |
413 int detected_audio_track_count_; | 426 int detected_audio_track_count_; |
414 int detected_video_track_count_; | 427 int detected_video_track_count_; |
415 int detected_text_track_count_; | 428 int detected_text_track_count_; |
416 | 429 |
| 430 int next_track_id_; |
| 431 std::map<MediaTrack::TrackId, const DemuxerStream*> |
| 432 track_id_to_demux_stream_map_; |
| 433 |
417 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); | 434 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxer); |
418 }; | 435 }; |
419 | 436 |
420 } // namespace media | 437 } // namespace media |
421 | 438 |
422 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ | 439 #endif // MEDIA_FILTERS_CHUNK_DEMUXER_H_ |
OLD | NEW |