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

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

Issue 2226443002: Support multiple media tracks in MSE / ChunkDemuxer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mp4 format is not supported on some trybots, so use webm 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
OLDNEW
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 23 matching lines...) Expand all
34 NewTextTrackCB; 34 NewTextTrackCB;
35 35
36 MediaSourceState(std::unique_ptr<StreamParser> stream_parser, 36 MediaSourceState(std::unique_ptr<StreamParser> stream_parser,
37 std::unique_ptr<FrameProcessor> frame_processor, 37 std::unique_ptr<FrameProcessor> frame_processor,
38 const CreateDemuxerStreamCB& create_demuxer_stream_cb, 38 const CreateDemuxerStreamCB& create_demuxer_stream_cb,
39 const scoped_refptr<MediaLog>& media_log); 39 const scoped_refptr<MediaLog>& media_log);
40 40
41 ~MediaSourceState(); 41 ~MediaSourceState();
42 42
43 void Init(const StreamParser::InitCB& init_cb, 43 void Init(const StreamParser::InitCB& init_cb,
44 bool allow_audio, 44 const std::string& expected_codecs,
45 bool allow_video,
46 const StreamParser::EncryptedMediaInitDataCB& 45 const StreamParser::EncryptedMediaInitDataCB&
47 encrypted_media_init_data_cb, 46 encrypted_media_init_data_cb,
48 const NewTextTrackCB& new_text_track_cb); 47 const NewTextTrackCB& new_text_track_cb);
49 48
50 // Appends new data to the StreamParser. 49 // Appends new data to the StreamParser.
51 // Returns true if the data was successfully appended. Returns false if an 50 // Returns true if the data was successfully appended. Returns false if an
52 // error occurred. |*timestamp_offset| is used and possibly updated by the 51 // error occurred. |*timestamp_offset| is used and possibly updated by the
53 // append. |append_window_start| and |append_window_end| correspond to the MSE 52 // 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 53 // spec's similarly named source buffer attributes that are used in coded
55 // frame processing. 54 // frame processing.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 UNINITIALIZED = 0, 128 UNINITIALIZED = 0,
130 PENDING_PARSER_CONFIG, 129 PENDING_PARSER_CONFIG,
131 PENDING_PARSER_INIT, 130 PENDING_PARSER_INIT,
132 PARSER_INITIALIZED 131 PARSER_INITIALIZED
133 }; 132 };
134 133
135 // Called by the |stream_parser_| when a new initialization segment is 134 // Called by the |stream_parser_| when a new initialization segment is
136 // encountered. 135 // encountered.
137 // Returns true on a successful call. Returns false if an error occurred while 136 // Returns true on a successful call. Returns false if an error occurred while
138 // processing decoder configurations. 137 // processing decoder configurations.
139 bool OnNewConfigs(bool allow_audio, 138 bool OnNewConfigs(std::string expected_codecs,
140 bool allow_video,
141 std::unique_ptr<MediaTracks> tracks, 139 std::unique_ptr<MediaTracks> tracks,
142 const StreamParser::TextTrackConfigMap& text_configs); 140 const StreamParser::TextTrackConfigMap& text_configs);
143 141
144 // Called by the |stream_parser_| at the beginning of a new media segment. 142 // Called by the |stream_parser_| at the beginning of a new media segment.
145 void OnNewMediaSegment(); 143 void OnNewMediaSegment();
146 144
147 // Called by the |stream_parser_| at the end of a media segment. 145 // Called by the |stream_parser_| at the end of a media segment.
148 void OnEndOfMediaSegment(); 146 void OnEndOfMediaSegment();
149 147
150 // Called by the |stream_parser_| when new buffers have been parsed. 148 // Called by the |stream_parser_| when new buffers have been parsed.
151 // It processes the new buffers using |frame_processor_|, which includes 149 // It processes the new buffers using |frame_processor_|, which includes
152 // appending the processed frames to associated demuxer streams for each 150 // appending the processed frames to associated demuxer streams for each
153 // frame's track. 151 // frame's track.
154 // Returns true on a successful call. Returns false if an error occurred while 152 // Returns true on a successful call. Returns false if an error occurred while
155 // processing the buffers. 153 // processing the buffers.
156 bool OnNewBuffers(const StreamParser::BufferQueueMap& buffer_queue_map); 154 bool OnNewBuffers(const StreamParser::BufferQueueMap& buffer_queue_map);
157 155
158 void OnSourceInitDone(const StreamParser::InitParameters& params); 156 void OnSourceInitDone(const StreamParser::InitParameters& params);
159 157
160 // EstimateVideoDataSize uses some heuristics to estimate the size of the 158 // EstimateVideoDataSize uses some heuristics to estimate the size of the
161 // video size in the chunk of muxed audio/video data without parsing it. 159 // video size in the chunk of muxed audio/video data without parsing it.
162 // This is used by EvictCodedFrames algorithm, which happens before Append 160 // This is used by EvictCodedFrames algorithm, which happens before Append
163 // (and therefore before parsing is performed) to prepare space for new data. 161 // (and therefore before parsing is performed) to prepare space for new data.
164 size_t EstimateVideoDataSize(size_t muxed_data_chunk_size) const; 162 size_t EstimateVideoDataSize(size_t muxed_data_chunk_size) const;
165 163
164 // Sets memory limits for all demuxer streams.
165 void SetStreamMemoryLimits();
166
166 // Tracks the number of MEDIA_LOGs emitted for segments missing expected audio 167 // Tracks the number of MEDIA_LOGs emitted for segments missing expected audio
167 // or video blocks. Useful to prevent log spam. 168 // or video blocks. Useful to prevent log spam.
168 int num_missing_track_logs_ = 0; 169 int num_missing_track_logs_ = 0;
169 170
170 CreateDemuxerStreamCB create_demuxer_stream_cb_; 171 CreateDemuxerStreamCB create_demuxer_stream_cb_;
171 NewTextTrackCB new_text_track_cb_; 172 NewTextTrackCB new_text_track_cb_;
172 173
173 // During Append(), if OnNewBuffers() coded frame processing updates the 174 // During Append(), if OnNewBuffers() coded frame processing updates the
174 // timestamp offset then |*timestamp_offset_during_append_| is also updated 175 // timestamp offset then |*timestamp_offset_during_append_| is also updated
175 // so Append()'s caller can know the new offset. This pointer is only non-NULL 176 // so Append()'s caller can know the new offset. This pointer is only non-NULL
176 // during the lifetime of an Append() call. 177 // during the lifetime of an Append() call.
177 TimeDelta* timestamp_offset_during_append_; 178 TimeDelta* timestamp_offset_during_append_;
178 179
179 // During Append(), coded frame processing triggered by OnNewBuffers() 180 // During Append(), coded frame processing triggered by OnNewBuffers()
180 // requires these two attributes. These are only valid during the lifetime of 181 // requires these two attributes. These are only valid during the lifetime of
181 // an Append() call. 182 // an Append() call.
182 TimeDelta append_window_start_during_append_; 183 TimeDelta append_window_start_during_append_;
183 TimeDelta append_window_end_during_append_; 184 TimeDelta append_window_end_during_append_;
184 185
185 // Keeps track of whether a media segment is being parsed. 186 // Keeps track of whether a media segment is being parsed.
186 bool parsing_media_segment_; 187 bool parsing_media_segment_;
187 188
188 // Valid only while |parsing_media_segment_| is true. These flags enable 189 // Valid only while |parsing_media_segment_| is true. These flags enable
189 // warning when at least one frame for each A/V track is not in a parsed media 190 // warning when the parsed media segment doesn't have frames for some track.
190 // segment. 191 std::map<StreamParser::TrackId, bool> media_segment_has_data_for_track_;
191 bool media_segment_contained_audio_frame_;
192 bool media_segment_contained_video_frame_;
193 192
194 // The object used to parse appended data. 193 // The object used to parse appended data.
195 std::unique_ptr<StreamParser> stream_parser_; 194 std::unique_ptr<StreamParser> stream_parser_;
196 195
197 ChunkDemuxerStream* audio_; // Not owned by |this|. 196 // Note that ChunkDemuxerStreams are created and owned by the parent
198 ChunkDemuxerStream* video_; // Not owned by |this|. 197 // ChunkDemuxer. They are not owned by |this|.
198 using DemuxerStreamMap = std::map<StreamParser::TrackId, ChunkDemuxerStream*>;
199 DemuxerStreamMap audio_streams_;
200 DemuxerStreamMap video_streams_;
199 201
200 typedef std::map<StreamParser::TrackId, ChunkDemuxerStream*> TextStreamMap; 202 typedef std::map<StreamParser::TrackId, ChunkDemuxerStream*> TextStreamMap;
201 TextStreamMap text_stream_map_; // |this| owns the map's stream pointers. 203 TextStreamMap text_stream_map_; // |this| owns the map's stream pointers.
202 204
203 std::unique_ptr<FrameProcessor> frame_processor_; 205 std::unique_ptr<FrameProcessor> frame_processor_;
204 scoped_refptr<MediaLog> media_log_; 206 scoped_refptr<MediaLog> media_log_;
205 StreamParser::InitCB init_cb_; 207 StreamParser::InitCB init_cb_;
206 208
207 State state_; 209 State state_;
208 210
209 // During Append(), OnNewConfigs() will trigger the initialization segment 211 // During Append(), OnNewConfigs() will trigger the initialization segment
210 // received algorithm. Note, the MSE spec explicitly disallows this algorithm 212 // received algorithm. Note, the MSE spec explicitly disallows this algorithm
211 // during an Abort(), since Abort() is allowed only to emit coded frames, and 213 // during an Abort(), since Abort() is allowed only to emit coded frames, and
212 // only if the parser is PARSING_MEDIA_SEGMENT (not an INIT segment). So we 214 // only if the parser is PARSING_MEDIA_SEGMENT (not an INIT segment). So we
213 // also have a flag here that indicates if Append is in progress and we can 215 // also have a flag here that indicates if Append is in progress and we can
214 // invoke this callback. 216 // invoke this callback.
215 Demuxer::MediaTracksUpdatedCB init_segment_received_cb_; 217 Demuxer::MediaTracksUpdatedCB init_segment_received_cb_;
216 bool append_in_progress_ = false; 218 bool append_in_progress_ = false;
219 bool first_init_segment_received_ = false;
217 220
218 // Indicates that timestampOffset should be updated automatically during 221 // Indicates that timestampOffset should be updated automatically during
219 // OnNewBuffers() based on the earliest end timestamp of the buffers provided. 222 // OnNewBuffers() based on the earliest end timestamp of the buffers provided.
220 // TODO(wolenetz): Refactor this function while integrating April 29, 2014 223 // TODO(wolenetz): Refactor this function while integrating April 29, 2014
221 // changes to MSE spec. See http://crbug.com/371499. 224 // changes to MSE spec. See http://crbug.com/371499.
222 bool auto_update_timestamp_offset_; 225 bool auto_update_timestamp_offset_;
223 226
224 DISALLOW_COPY_AND_ASSIGN(MediaSourceState); 227 DISALLOW_COPY_AND_ASSIGN(MediaSourceState);
225 }; 228 };
226 229
227 } // namespace media 230 } // namespace media
228 231
229 #endif // MEDIA_FILTERS_MEDIA_SOURCE_STATE_H_ 232 #endif // MEDIA_FILTERS_MEDIA_SOURCE_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698