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

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

Powered by Google App Engine
This is Rietveld 408576698