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

Side by Side Diff: media/formats/webm/webm_cluster_parser.h

Issue 2158923004: Convert media constants to constexpr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ 5 #ifndef MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_
6 #define MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ 6 #define MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <deque> 10 #include <deque>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 Track(int track_num, 54 Track(int track_num,
55 bool is_video, 55 bool is_video,
56 base::TimeDelta default_duration, 56 base::TimeDelta default_duration,
57 const scoped_refptr<MediaLog>& media_log); 57 const scoped_refptr<MediaLog>& media_log);
58 Track(const Track& other); 58 Track(const Track& other);
59 ~Track(); 59 ~Track();
60 60
61 int track_num() const { return track_num_; } 61 int track_num() const { return track_num_; }
62 62
63 // If a buffer is currently held aside pending duration calculation, returns 63 // If a buffer is currently held aside pending duration calculation, returns
64 // its decode timestamp. Otherwise, returns kInfiniteDuration(). 64 // its decode timestamp. Otherwise, returns kInfiniteDuration.
65 DecodeTimestamp GetReadyUpperBound(); 65 DecodeTimestamp GetReadyUpperBound();
66 66
67 // Prepares |ready_buffers_| for retrieval. Prior to calling, 67 // Prepares |ready_buffers_| for retrieval. Prior to calling,
68 // |ready_buffers_| must be empty. Moves all |buffers_| with decode 68 // |ready_buffers_| must be empty. Moves all |buffers_| with decode
69 // timestamp before |before_timestamp| to |ready_buffers_|, preserving their 69 // timestamp before |before_timestamp| to |ready_buffers_|, preserving their
70 // order. 70 // order.
71 void ExtractReadyBuffers(const DecodeTimestamp before_timestamp); 71 void ExtractReadyBuffers(const DecodeTimestamp before_timestamp);
72 72
73 const BufferQueue& ready_buffers() const { return ready_buffers_; } 73 const BufferQueue& ready_buffers() const { return ready_buffers_; }
74 74
75 // If |last_added_buffer_missing_duration_| is set, updates its duration 75 // If |last_added_buffer_missing_duration_| is set, updates its duration
76 // relative to |buffer|'s timestamp, and adds it to |buffers_| and unsets 76 // relative to |buffer|'s timestamp, and adds it to |buffers_| and unsets
77 // |last_added_buffer_missing_duration_|. Then, if |buffer| is missing 77 // |last_added_buffer_missing_duration_|. Then, if |buffer| is missing
78 // duration, saves |buffer| into |last_added_buffer_missing_duration_|, or 78 // duration, saves |buffer| into |last_added_buffer_missing_duration_|, or
79 // otherwise adds |buffer| to |buffers_|. 79 // otherwise adds |buffer| to |buffers_|.
80 bool AddBuffer(const scoped_refptr<StreamParserBuffer>& buffer); 80 bool AddBuffer(const scoped_refptr<StreamParserBuffer>& buffer);
81 81
82 // If |last_added_buffer_missing_duration_| is set, updates its duration to 82 // If |last_added_buffer_missing_duration_| is set, updates its duration to
83 // be non-kNoTimestamp() value of |estimated_next_frame_duration_| or a 83 // be non-kNoTimestamp value of |estimated_next_frame_duration_| or a
84 // hard-coded default, then adds it to |buffers_| and unsets 84 // hard-coded default, then adds it to |buffers_| and unsets
85 // |last_added_buffer_missing_duration_|. (This method helps stream parser 85 // |last_added_buffer_missing_duration_|. (This method helps stream parser
86 // emit all buffers in a media segment before signaling end of segment.) 86 // emit all buffers in a media segment before signaling end of segment.)
87 void ApplyDurationEstimateIfNeeded(); 87 void ApplyDurationEstimateIfNeeded();
88 88
89 // Clears |ready_buffers_| (use ExtractReadyBuffers() to fill it again). 89 // Clears |ready_buffers_| (use ExtractReadyBuffers() to fill it again).
90 // Leaves as-is |buffers_| and any possibly held-aside buffer that is 90 // Leaves as-is |buffers_| and any possibly held-aside buffer that is
91 // missing duration. 91 // missing duration.
92 void ClearReadyBuffers(); 92 void ClearReadyBuffers();
93 93
(...skipping 30 matching lines...) Expand all
124 scoped_refptr<StreamParserBuffer> last_added_buffer_missing_duration_; 124 scoped_refptr<StreamParserBuffer> last_added_buffer_missing_duration_;
125 125
126 // Buffers in (decode) timestamp order that were previously parsed into and 126 // Buffers in (decode) timestamp order that were previously parsed into and
127 // extracted from |buffers_|. Buffers are moved from |buffers_| to 127 // extracted from |buffers_|. Buffers are moved from |buffers_| to
128 // |ready_buffers_| by ExtractReadyBuffers() if they are below a specified 128 // |ready_buffers_| by ExtractReadyBuffers() if they are below a specified
129 // upper bound timestamp. Track users can therefore extract only those 129 // upper bound timestamp. Track users can therefore extract only those
130 // parsed buffers which are "ready" for emission (all before some maximum 130 // parsed buffers which are "ready" for emission (all before some maximum
131 // timestamp). 131 // timestamp).
132 BufferQueue ready_buffers_; 132 BufferQueue ready_buffers_;
133 133
134 // If kNoTimestamp(), then |estimated_next_frame_duration_| will be used. 134 // If kNoTimestamp, then |estimated_next_frame_duration_| will be used.
135 base::TimeDelta default_duration_; 135 base::TimeDelta default_duration_;
136 136
137 // If kNoTimestamp(), then a default value will be used. This estimate is 137 // If kNoTimestamp, then a default value will be used. This estimate is
138 // the maximum (for video), or minimum (for audio) duration seen so far for 138 // the maximum (for video), or minimum (for audio) duration seen so far for
139 // this track, and is used only if |default_duration_| is kNoTimestamp(). 139 // this track, and is used only if |default_duration_| is kNoTimestamp.
140 // TODO(chcunningham): Use maximum for audio too, adding checks to disable 140 // TODO(chcunningham): Use maximum for audio too, adding checks to disable
141 // splicing when these estimates are observed in SourceBufferStream. 141 // splicing when these estimates are observed in SourceBufferStream.
142 base::TimeDelta estimated_next_frame_duration_; 142 base::TimeDelta estimated_next_frame_duration_;
143 143
144 scoped_refptr<MediaLog> media_log_; 144 scoped_refptr<MediaLog> media_log_;
145 }; 145 };
146 146
147 typedef std::map<int, Track> TextTrackMap; 147 typedef std::map<int, Track> TextTrackMap;
148 148
149 public: 149 public:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // Resets the Track objects associated with each text track. 232 // Resets the Track objects associated with each text track.
233 void ResetTextTracks(); 233 void ResetTextTracks();
234 234
235 // Clears the the ready buffers associated with each text track. 235 // Clears the the ready buffers associated with each text track.
236 void ClearTextTrackReadyBuffers(); 236 void ClearTextTrackReadyBuffers();
237 237
238 // Helper method for Get{Audio,Video,Text}Buffers() that recomputes 238 // Helper method for Get{Audio,Video,Text}Buffers() that recomputes
239 // |ready_buffer_upper_bound_| and calls ExtractReadyBuffers() on each track. 239 // |ready_buffer_upper_bound_| and calls ExtractReadyBuffers() on each track.
240 // If |cluster_ended_| is true, first applies duration estimate if needed for 240 // If |cluster_ended_| is true, first applies duration estimate if needed for
241 // |audio_| and |video_| and sets |ready_buffer_upper_bound_| to 241 // |audio_| and |video_| and sets |ready_buffer_upper_bound_| to
242 // kInfiniteDuration(). Otherwise, sets |ready_buffer_upper_bound_| to the 242 // kInfiniteDuration. Otherwise, sets |ready_buffer_upper_bound_| to the
243 // minimum upper bound across |audio_| and |video_|. (Text tracks can have no 243 // minimum upper bound across |audio_| and |video_|. (Text tracks can have no
244 // buffers missing duration, so they are not involved in calculating the upper 244 // buffers missing duration, so they are not involved in calculating the upper
245 // bound.) 245 // bound.)
246 // Parse() or Reset() must be called between calls to UpdateReadyBuffers() to 246 // Parse() or Reset() must be called between calls to UpdateReadyBuffers() to
247 // clear each track's ready buffers and to reset |ready_buffer_upper_bound_| 247 // clear each track's ready buffers and to reset |ready_buffer_upper_bound_|
248 // to kNoDecodeTimestamp(). 248 // to kNoDecodeTimestamp().
249 void UpdateReadyBuffers(); 249 void UpdateReadyBuffers();
250 250
251 // Search for the indicated track_num among the text tracks. Returns NULL 251 // Search for the indicated track_num among the text tracks. Returns NULL
252 // if that track num is not a text track. 252 // if that track num is not a text track.
253 Track* FindTextTrack(int track_num); 253 Track* FindTextTrack(int track_num);
254 254
255 // Attempts to read the duration from the encoded audio data, returning as 255 // Attempts to read the duration from the encoded audio data, returning as
256 // TimeDelta or kNoTimestamp() if duration cannot be retrieved. This obviously 256 // TimeDelta or kNoTimestamp if duration cannot be retrieved. This obviously
257 // violates layering rules, but is useful for MSE to know duration in cases 257 // violates layering rules, but is useful for MSE to know duration in cases
258 // where it isn't explicitly given and cannot be calculated for Blocks at the 258 // where it isn't explicitly given and cannot be calculated for Blocks at the
259 // end of a Cluster (the next Cluster in playback-order may not be the next 259 // end of a Cluster (the next Cluster in playback-order may not be the next
260 // Cluster we parse, so we can't simply use the delta of the first Block in 260 // Cluster we parse, so we can't simply use the delta of the first Block in
261 // the next Cluster). Avoid calling if encrypted; may produce unexpected 261 // the next Cluster). Avoid calling if encrypted; may produce unexpected
262 // output. See implementation for supported codecs. 262 // output. See implementation for supported codecs.
263 base::TimeDelta TryGetEncodedAudioDuration(const uint8_t* data, int size); 263 base::TimeDelta TryGetEncodedAudioDuration(const uint8_t* data, int size);
264 264
265 // Reads Opus packet header to determine packet duration. Duration returned 265 // Reads Opus packet header to determine packet duration. Duration returned
266 // as TimeDelta or kNoTimestamp() upon failure to read duration from packet. 266 // as TimeDelta or kNoTimestamp upon failure to read duration from packet.
267 base::TimeDelta ReadOpusDuration(const uint8_t* data, int size); 267 base::TimeDelta ReadOpusDuration(const uint8_t* data, int size);
268 268
269 // Tracks the number of MEDIA_LOGs made in process of reading encoded 269 // Tracks the number of MEDIA_LOGs made in process of reading encoded
270 // duration. Useful to prevent log spam. 270 // duration. Useful to prevent log spam.
271 int num_duration_errors_ = 0; 271 int num_duration_errors_ = 0;
272 272
273 double timecode_multiplier_; // Multiplier used to convert timecodes into 273 double timecode_multiplier_; // Multiplier used to convert timecodes into
274 // microseconds. 274 // microseconds.
275 std::set<int64_t> ignored_tracks_; 275 std::set<int64_t> ignored_tracks_;
276 std::string audio_encryption_key_id_; 276 std::string audio_encryption_key_id_;
(...skipping 29 matching lines...) Expand all
306 // Subset of |text_track_map_| maintained by GetTextBuffers(), and cleared by 306 // Subset of |text_track_map_| maintained by GetTextBuffers(), and cleared by
307 // ClearTextTrackReadyBuffers(). Callers of GetTextBuffers() get a const-ref 307 // ClearTextTrackReadyBuffers(). Callers of GetTextBuffers() get a const-ref
308 // to this member. 308 // to this member.
309 TextBufferQueueMap text_buffers_map_; 309 TextBufferQueueMap text_buffers_map_;
310 310
311 // Limits the range of buffers returned by Get{Audio,Video,Text}Buffers() to 311 // Limits the range of buffers returned by Get{Audio,Video,Text}Buffers() to
312 // this exclusive upper bound. Set to kNoDecodeTimestamp(), meaning not yet 312 // this exclusive upper bound. Set to kNoDecodeTimestamp(), meaning not yet
313 // calculated, by Reset() and Parse(). If kNoDecodeTimestamp(), then 313 // calculated, by Reset() and Parse(). If kNoDecodeTimestamp(), then
314 // Get{Audio,Video,Text}Buffers() will calculate it to be the minimum (decode) 314 // Get{Audio,Video,Text}Buffers() will calculate it to be the minimum (decode)
315 // timestamp across all tracks' |last_buffer_missing_duration_|, or 315 // timestamp across all tracks' |last_buffer_missing_duration_|, or
316 // kInfiniteDuration() if no buffers are currently missing duration. 316 // kInfiniteDuration if no buffers are currently missing duration.
317 DecodeTimestamp ready_buffer_upper_bound_; 317 DecodeTimestamp ready_buffer_upper_bound_;
318 318
319 scoped_refptr<MediaLog> media_log_; 319 scoped_refptr<MediaLog> media_log_;
320 320
321 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); 321 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser);
322 }; 322 };
323 323
324 } // namespace media 324 } // namespace media
325 325
326 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ 326 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698