OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_MEDIA_SOURCE_STATE_H_ | 5 #ifndef MEDIA_FILTERS_MEDIA_SOURCE_STATE_H_ |
6 #define MEDIA_FILTERS_MEDIA_SOURCE_STATE_H_ | 6 #define MEDIA_FILTERS_MEDIA_SOURCE_STATE_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class ChunkDemuxerStream; | 21 class ChunkDemuxerStream; |
22 class FrameProcessor; | 22 class FrameProcessor; |
23 | 23 |
24 // Contains state belonging to a source id. | 24 // Contains state belonging to a source id. |
25 class MEDIA_EXPORT MediaSourceState { | 25 class MEDIA_EXPORT MediaSourceState { |
26 public: | 26 public: |
27 // Callback signature used to create ChunkDemuxerStreams. | 27 // Callback signature used to create ChunkDemuxerStreams. |
28 typedef base::Callback<ChunkDemuxerStream*(DemuxerStream::Type)> | 28 typedef base::Callback<ChunkDemuxerStream*(DemuxerStream::Type)> |
29 CreateDemuxerStreamCB; | 29 CreateDemuxerStreamCB; |
30 | 30 |
31 typedef base::Closure InitSegmentReceivedCB; | |
32 | |
33 typedef base::Callback<void(ChunkDemuxerStream*, const TextTrackConfig&)> | 31 typedef base::Callback<void(ChunkDemuxerStream*, const TextTrackConfig&)> |
34 NewTextTrackCB; | 32 NewTextTrackCB; |
35 | 33 |
36 MediaSourceState(scoped_ptr<StreamParser> stream_parser, | 34 MediaSourceState(scoped_ptr<StreamParser> stream_parser, |
37 scoped_ptr<FrameProcessor> frame_processor, | 35 scoped_ptr<FrameProcessor> frame_processor, |
38 const CreateDemuxerStreamCB& create_demuxer_stream_cb, | 36 const CreateDemuxerStreamCB& create_demuxer_stream_cb, |
39 const scoped_refptr<MediaLog>& media_log); | 37 const scoped_refptr<MediaLog>& media_log); |
40 | 38 |
41 ~MediaSourceState(); | 39 ~MediaSourceState(); |
42 | 40 |
43 void Init(const StreamParser::InitCB& init_cb, | 41 void Init(const StreamParser::InitCB& init_cb, |
44 bool allow_audio, | 42 bool allow_audio, |
45 bool allow_video, | 43 bool allow_video, |
46 const StreamParser::EncryptedMediaInitDataCB& | 44 const StreamParser::EncryptedMediaInitDataCB& |
47 encrypted_media_init_data_cb, | 45 encrypted_media_init_data_cb, |
48 const NewTextTrackCB& new_text_track_cb); | 46 const NewTextTrackCB& new_text_track_cb); |
49 | 47 |
50 // Appends new data to the StreamParser. | 48 // Appends new data to the StreamParser. |
51 // Returns true if the data was successfully appended. Returns false if an | 49 // Returns true if the data was successfully appended. Returns false if an |
52 // error occurred. |*timestamp_offset| is used and possibly updated by the | 50 // error occurred. |*timestamp_offset| is used and possibly updated by the |
53 // append. |append_window_start| and |append_window_end| correspond to the MSE | 51 // append. |append_window_start| and |append_window_end| correspond to the MSE |
54 // spec's similarly named source buffer attributes that are used in coded | 52 // spec's similarly named source buffer attributes that are used in coded |
55 // frame processing. |init_segment_received_cb| is run for each new fully | 53 // frame processing. |
56 // parsed initialization segment. | |
57 bool Append(const uint8_t* data, | 54 bool Append(const uint8_t* data, |
58 size_t length, | 55 size_t length, |
59 TimeDelta append_window_start, | 56 TimeDelta append_window_start, |
60 TimeDelta append_window_end, | 57 TimeDelta append_window_end, |
61 TimeDelta* timestamp_offset, | 58 TimeDelta* timestamp_offset); |
62 const InitSegmentReceivedCB& init_segment_received_cb); | |
63 | 59 |
64 // Aborts the current append sequence and resets the parser. | 60 // Aborts the current append sequence and resets the parser. |
65 void ResetParserState(TimeDelta append_window_start, | 61 void ResetParserState(TimeDelta append_window_start, |
66 TimeDelta append_window_end, | 62 TimeDelta append_window_end, |
67 TimeDelta* timestamp_offset); | 63 TimeDelta* timestamp_offset); |
68 | 64 |
69 // Calls Remove(|start|, |end|, |duration|) on all | 65 // Calls Remove(|start|, |end|, |duration|) on all |
70 // ChunkDemuxerStreams managed by this object. | 66 // ChunkDemuxerStreams managed by this object. |
71 void Remove(TimeDelta start, TimeDelta end, TimeDelta duration); | 67 void Remove(TimeDelta start, TimeDelta end, TimeDelta duration); |
72 | 68 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // |memory_limit| is the maximum number of bytes each stream of type |type| | 106 // |memory_limit| is the maximum number of bytes each stream of type |type| |
111 // is allowed to hold in its buffer. | 107 // is allowed to hold in its buffer. |
112 void SetMemoryLimits(DemuxerStream::Type type, size_t memory_limit); | 108 void SetMemoryLimits(DemuxerStream::Type type, size_t memory_limit); |
113 bool IsSeekWaitingForData() const; | 109 bool IsSeekWaitingForData() const; |
114 | 110 |
115 typedef std::list<Ranges<TimeDelta>> RangesList; | 111 typedef std::list<Ranges<TimeDelta>> RangesList; |
116 static Ranges<TimeDelta> ComputeRangesIntersection( | 112 static Ranges<TimeDelta> ComputeRangesIntersection( |
117 const RangesList& activeRanges, | 113 const RangesList& activeRanges, |
118 bool ended); | 114 bool ended); |
119 | 115 |
| 116 void SetTracksWatcher(const Demuxer::MediaTracksUpdatedCB& tracks_updated_cb); |
| 117 |
120 private: | 118 private: |
121 // Called by the |stream_parser_| when a new initialization segment is | 119 // Called by the |stream_parser_| when a new initialization segment is |
122 // encountered. | 120 // encountered. |
123 // Returns true on a successful call. Returns false if an error occurred while | 121 // Returns true on a successful call. Returns false if an error occurred while |
124 // processing decoder configurations. | 122 // processing decoder configurations. |
125 bool OnNewConfigs(bool allow_audio, | 123 bool OnNewConfigs(bool allow_audio, |
126 bool allow_video, | 124 bool allow_video, |
127 const AudioDecoderConfig& audio_config, | 125 scoped_ptr<MediaTracks> tracks, |
128 const VideoDecoderConfig& video_config, | |
129 const StreamParser::TextTrackConfigMap& text_configs); | 126 const StreamParser::TextTrackConfigMap& text_configs); |
130 | 127 |
131 // Called by the |stream_parser_| at the beginning of a new media segment. | 128 // Called by the |stream_parser_| at the beginning of a new media segment. |
132 void OnNewMediaSegment(); | 129 void OnNewMediaSegment(); |
133 | 130 |
134 // Called by the |stream_parser_| at the end of a media segment. | 131 // Called by the |stream_parser_| at the end of a media segment. |
135 void OnEndOfMediaSegment(); | 132 void OnEndOfMediaSegment(); |
136 | 133 |
137 // Called by the |stream_parser_| when new buffers have been parsed. | 134 // Called by the |stream_parser_| when new buffers have been parsed. |
138 // It processes the new buffers using |frame_processor_|, which includes | 135 // It processes the new buffers using |frame_processor_|, which includes |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 173 |
177 // Valid only while |parsing_media_segment_| is true. These flags enable | 174 // Valid only while |parsing_media_segment_| is true. These flags enable |
178 // warning when at least one frame for each A/V track is not in a parsed media | 175 // warning when at least one frame for each A/V track is not in a parsed media |
179 // segment. | 176 // segment. |
180 bool media_segment_contained_audio_frame_; | 177 bool media_segment_contained_audio_frame_; |
181 bool media_segment_contained_video_frame_; | 178 bool media_segment_contained_video_frame_; |
182 | 179 |
183 // The object used to parse appended data. | 180 // The object used to parse appended data. |
184 scoped_ptr<StreamParser> stream_parser_; | 181 scoped_ptr<StreamParser> stream_parser_; |
185 | 182 |
| 183 scoped_ptr<MediaTracks> media_tracks_; |
| 184 |
186 ChunkDemuxerStream* audio_; // Not owned by |this|. | 185 ChunkDemuxerStream* audio_; // Not owned by |this|. |
187 ChunkDemuxerStream* video_; // Not owned by |this|. | 186 ChunkDemuxerStream* video_; // Not owned by |this|. |
188 | 187 |
189 typedef std::map<StreamParser::TrackId, ChunkDemuxerStream*> TextStreamMap; | 188 typedef std::map<StreamParser::TrackId, ChunkDemuxerStream*> TextStreamMap; |
190 TextStreamMap text_stream_map_; // |this| owns the map's stream pointers. | 189 TextStreamMap text_stream_map_; // |this| owns the map's stream pointers. |
191 | 190 |
192 scoped_ptr<FrameProcessor> frame_processor_; | 191 scoped_ptr<FrameProcessor> frame_processor_; |
193 scoped_refptr<MediaLog> media_log_; | 192 scoped_refptr<MediaLog> media_log_; |
194 StreamParser::InitCB init_cb_; | 193 StreamParser::InitCB init_cb_; |
195 | 194 |
196 // During Append(), OnNewConfigs() will trigger the initialization segment | 195 // During Append(), OnNewConfigs() will trigger the initialization segment |
197 // received algorithm. This callback is only non-NULL during the lifetime of | 196 // received algorithm. Note, the MSE spec explicitly disallows this algorithm |
198 // an Append() call. Note, the MSE spec explicitly disallows this algorithm | |
199 // during an Abort(), since Abort() is allowed only to emit coded frames, and | 197 // during an Abort(), since Abort() is allowed only to emit coded frames, and |
200 // only if the parser is PARSING_MEDIA_SEGMENT (not an INIT segment). | 198 // only if the parser is PARSING_MEDIA_SEGMENT (not an INIT segment). So we |
201 InitSegmentReceivedCB init_segment_received_cb_; | 199 // also have a flag here that indicates if Append is in progress and we can |
| 200 // invoke this callback. |
| 201 Demuxer::MediaTracksUpdatedCB init_segment_received_cb_; |
| 202 bool append_in_progress_ = false; |
202 | 203 |
203 // Indicates that timestampOffset should be updated automatically during | 204 // Indicates that timestampOffset should be updated automatically during |
204 // OnNewBuffers() based on the earliest end timestamp of the buffers provided. | 205 // OnNewBuffers() based on the earliest end timestamp of the buffers provided. |
205 // TODO(wolenetz): Refactor this function while integrating April 29, 2014 | 206 // TODO(wolenetz): Refactor this function while integrating April 29, 2014 |
206 // changes to MSE spec. See http://crbug.com/371499. | 207 // changes to MSE spec. See http://crbug.com/371499. |
207 bool auto_update_timestamp_offset_; | 208 bool auto_update_timestamp_offset_; |
208 | 209 |
209 DISALLOW_COPY_AND_ASSIGN(MediaSourceState); | 210 DISALLOW_COPY_AND_ASSIGN(MediaSourceState); |
210 }; | 211 }; |
211 | 212 |
212 } // namespace media | 213 } // namespace media |
213 | 214 |
214 #endif // MEDIA_FILTERS_MEDIA_SOURCE_STATE_H_ | 215 #endif // MEDIA_FILTERS_MEDIA_SOURCE_STATE_H_ |
OLD | NEW |