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

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

Issue 447963003: Introduce DecodeTimestamp class to make it easier to distiguish presentation and decode timestamps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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 // SourceBufferStream is a data structure that stores media Buffers in ranges. 5 // SourceBufferStream is a data structure that stores media Buffers in ranges.
6 // Buffers can be appended out of presentation order. Buffers are retrieved by 6 // Buffers can be appended out of presentation order. Buffers are retrieved by
7 // seeking to the desired start point and calling GetNextBuffer(). Buffers are 7 // seeking to the desired start point and calling GetNextBuffer(). Buffers are
8 // returned in sequential presentation order. 8 // returned in sequential presentation order.
9 9
10 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ 10 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const LogCB& log_cb, 59 const LogCB& log_cb,
60 bool splice_frames_enabled); 60 bool splice_frames_enabled);
61 SourceBufferStream(const TextTrackConfig& text_config, 61 SourceBufferStream(const TextTrackConfig& text_config,
62 const LogCB& log_cb, 62 const LogCB& log_cb,
63 bool splice_frames_enabled); 63 bool splice_frames_enabled);
64 64
65 ~SourceBufferStream(); 65 ~SourceBufferStream();
66 66
67 // Signals that the next buffers appended are part of a new media segment 67 // Signals that the next buffers appended are part of a new media segment
68 // starting at |media_segment_start_time|. 68 // starting at |media_segment_start_time|.
69 void OnNewMediaSegment(base::TimeDelta media_segment_start_time); 69 void OnNewMediaSegment(DecodeTimestamp media_segment_start_time);
wolenetz 2014/08/08 21:30:05 Here and below, is the eventual intent to signal D
acolwell GONE FROM CHROMIUM 2014/08/11 17:05:06 But the ultimate caller (frame_processor.cc) is pa
wolenetz 2014/08/12 00:09:00 Acknowledged.
70 70
71 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are 71 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are
72 // expected to be in order, but multiple calls to Append() may add buffers out 72 // expected to be in order, but multiple calls to Append() may add buffers out
73 // of order or overlapping. Assumes all buffers within |buffers| are in 73 // of order or overlapping. Assumes all buffers within |buffers| are in
74 // presentation order and are non-overlapping. 74 // presentation order and are non-overlapping.
75 // Returns true if Append() was successful, false if |buffers| are not added. 75 // Returns true if Append() was successful, false if |buffers| are not added.
76 // TODO(vrk): Implement garbage collection. (crbug.com/125070) 76 // TODO(vrk): Implement garbage collection. (crbug.com/125070)
77 bool Append(const BufferQueue& buffers); 77 bool Append(const BufferQueue& buffers);
78 78
79 // Removes buffers between |start| and |end| according to the steps 79 // Removes buffers between |start| and |end| according to the steps
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // Attempts to delete approximately |total_bytes_to_free| amount of data from 160 // Attempts to delete approximately |total_bytes_to_free| amount of data from
161 // |ranges_|, starting after the last appended buffer before the current 161 // |ranges_|, starting after the last appended buffer before the current
162 // playback position. 162 // playback position.
163 int FreeBuffersAfterLastAppended(int total_bytes_to_free); 163 int FreeBuffersAfterLastAppended(int total_bytes_to_free);
164 164
165 // Gets the removal range to secure |byte_to_free| from 165 // Gets the removal range to secure |byte_to_free| from
166 // [|start_timestamp|, |end_timestamp|). 166 // [|start_timestamp|, |end_timestamp|).
167 // Returns the size of buffers to secure if future 167 // Returns the size of buffers to secure if future
168 // Remove(|start_timestamp|, |removal_end_timestamp|, duration) is called. 168 // Remove(|start_timestamp|, |removal_end_timestamp|, duration) is called.
169 // Will not update |removal_end_timestamp| if the returned size is 0. 169 // Will not update |removal_end_timestamp| if the returned size is 0.
170 int GetRemovalRange(base::TimeDelta start_timestamp, 170 int GetRemovalRange(DecodeTimestamp start_timestamp,
171 base::TimeDelta end_timestamp, int byte_to_free, 171 DecodeTimestamp end_timestamp, int byte_to_free,
172 base::TimeDelta* removal_end_timestamp); 172 DecodeTimestamp* removal_end_timestamp);
173 173
174 // Prepares |range_for_next_append_| so |new_buffers| can be appended. 174 // Prepares |range_for_next_append_| so |new_buffers| can be appended.
175 // This involves removing buffers between the end of the previous append 175 // This involves removing buffers between the end of the previous append
176 // and any buffers covered by the time range in |new_buffers|. 176 // and any buffers covered by the time range in |new_buffers|.
177 // |deleted_buffers| is an output parameter containing candidates for 177 // |deleted_buffers| is an output parameter containing candidates for
178 // |track_buffer_| if this method ends up removing the current playback 178 // |track_buffer_| if this method ends up removing the current playback
179 // position from the range. 179 // position from the range.
180 void PrepareRangesForNextAppend(const BufferQueue& new_buffers, 180 void PrepareRangesForNextAppend(const BufferQueue& new_buffers,
181 BufferQueue* deleted_buffers); 181 BufferQueue* deleted_buffers);
182 182
183 // Removes buffers, from the |track_buffer_|, that come after |timestamp|. 183 // Removes buffers, from the |track_buffer_|, that come after |timestamp|.
184 void PruneTrackBuffer(const base::TimeDelta timestamp); 184 void PruneTrackBuffer(const DecodeTimestamp timestamp);
185 185
186 // Checks to see if |range_with_new_buffers_itr| can be merged with the range 186 // Checks to see if |range_with_new_buffers_itr| can be merged with the range
187 // next to it, and merges them if so. 187 // next to it, and merges them if so.
188 void MergeWithAdjacentRangeIfNecessary( 188 void MergeWithAdjacentRangeIfNecessary(
189 const RangeList::iterator& range_with_new_buffers_itr); 189 const RangeList::iterator& range_with_new_buffers_itr);
190 190
191 // Returns true if |second_timestamp| is the timestamp of the next buffer in 191 // Returns true if |second_timestamp| is the timestamp of the next buffer in
192 // sequence after |first_timestamp|, false otherwise. 192 // sequence after |first_timestamp|, false otherwise.
193 bool AreAdjacentInSequence( 193 bool AreAdjacentInSequence(
194 base::TimeDelta first_timestamp, base::TimeDelta second_timestamp) const; 194 DecodeTimestamp first_timestamp, DecodeTimestamp second_timestamp) const;
195 195
196 // Helper method that returns the timestamp for the next buffer that 196 // Helper method that returns the timestamp for the next buffer that
197 // |selected_range_| will return from GetNextBuffer() call, or kNoTimestamp() 197 // |selected_range_| will return from GetNextBuffer() call, or kNoTimestamp()
198 // if in between seeking (i.e. |selected_range_| is null). 198 // if in between seeking (i.e. |selected_range_| is null).
199 base::TimeDelta GetNextBufferTimestamp(); 199 DecodeTimestamp GetNextBufferTimestamp();
200
201 // Returns the timestamp of the last buffer in the |selected_range_| or
202 // kNoTimestamp() if |selected_range_| is null.
203 base::TimeDelta GetEndBufferTimestamp();
204 200
205 // Finds the range that should contain a media segment that begins with 201 // Finds the range that should contain a media segment that begins with
206 // |start_timestamp| and returns the iterator pointing to it. Returns 202 // |start_timestamp| and returns the iterator pointing to it. Returns
207 // |ranges_.end()| if there's no such existing range. 203 // |ranges_.end()| if there's no such existing range.
208 RangeList::iterator FindExistingRangeFor(base::TimeDelta start_timestamp); 204 RangeList::iterator FindExistingRangeFor(DecodeTimestamp start_timestamp);
209 205
210 // Inserts |new_range| into |ranges_| preserving sorted order. Returns an 206 // Inserts |new_range| into |ranges_| preserving sorted order. Returns an
211 // iterator in |ranges_| that points to |new_range|. 207 // iterator in |ranges_| that points to |new_range|.
212 RangeList::iterator AddToRanges(SourceBufferRange* new_range); 208 RangeList::iterator AddToRanges(SourceBufferRange* new_range);
213 209
214 // Returns an iterator that points to the place in |ranges_| where 210 // Returns an iterator that points to the place in |ranges_| where
215 // |selected_range_| lives. 211 // |selected_range_| lives.
216 RangeList::iterator GetSelectedRangeItr(); 212 RangeList::iterator GetSelectedRangeItr();
217 213
218 // Sets the |selected_range_| to |range| and resets the next buffer position 214 // Sets the |selected_range_| to |range| and resets the next buffer position
219 // for the previous |selected_range_|. 215 // for the previous |selected_range_|.
220 void SetSelectedRange(SourceBufferRange* range); 216 void SetSelectedRange(SourceBufferRange* range);
221 217
222 // Seeks |range| to |seek_timestamp| and then calls SetSelectedRange() with 218 // Seeks |range| to |seek_timestamp| and then calls SetSelectedRange() with
223 // |range|. 219 // |range|.
224 void SeekAndSetSelectedRange(SourceBufferRange* range, 220 void SeekAndSetSelectedRange(SourceBufferRange* range,
225 base::TimeDelta seek_timestamp); 221 DecodeTimestamp seek_timestamp);
226 222
227 // Resets this stream back to an unseeked state. 223 // Resets this stream back to an unseeked state.
228 void ResetSeekState(); 224 void ResetSeekState();
229 225
230 // Returns true if |seek_timestamp| refers to the beginning of the first range 226 // Returns true if |seek_timestamp| refers to the beginning of the first range
231 // in |ranges_|, false otherwise or if |ranges_| is empty. 227 // in |ranges_|, false otherwise or if |ranges_| is empty.
232 bool ShouldSeekToStartOfBuffered(base::TimeDelta seek_timestamp) const; 228 bool ShouldSeekToStartOfBuffered(base::TimeDelta seek_timestamp) const;
233 229
234 // Returns true if the timestamps of |buffers| are monotonically increasing 230 // Returns true if the timestamps of |buffers| are monotonically increasing
235 // since the previous append to the media segment, false otherwise. 231 // since the previous append to the media segment, false otherwise.
236 bool IsMonotonicallyIncreasing(const BufferQueue& buffers) const; 232 bool IsMonotonicallyIncreasing(const BufferQueue& buffers) const;
237 233
238 // Returns true if |next_timestamp| and |next_is_keyframe| are valid for 234 // Returns true if |next_timestamp| and |next_is_keyframe| are valid for
239 // the first buffer after the previous append. 235 // the first buffer after the previous append.
240 bool IsNextTimestampValid(base::TimeDelta next_timestamp, 236 bool IsNextTimestampValid(DecodeTimestamp next_timestamp,
241 bool next_is_keyframe) const; 237 bool next_is_keyframe) const;
242 238
243 // Returns true if |selected_range_| is the only range in |ranges_| that 239 // Returns true if |selected_range_| is the only range in |ranges_| that
244 // HasNextBufferPosition(). 240 // HasNextBufferPosition().
245 bool OnlySelectedRangeIsSeeked() const; 241 bool OnlySelectedRangeIsSeeked() const;
246 242
247 // Measures the distances between buffer timestamps and tracks the max. 243 // Measures the distances between buffer timestamps and tracks the max.
248 void UpdateMaxInterbufferDistance(const BufferQueue& buffers); 244 void UpdateMaxInterbufferDistance(const BufferQueue& buffers);
249 245
250 // Sets the config ID for each buffer to |append_config_index_|. 246 // Sets the config ID for each buffer to |append_config_index_|.
251 void SetConfigIds(const BufferQueue& buffers); 247 void SetConfigIds(const BufferQueue& buffers);
252 248
253 // Called to complete a config change. Updates |current_config_index_| to 249 // Called to complete a config change. Updates |current_config_index_| to
254 // match the index of the next buffer. Calling this method causes 250 // match the index of the next buffer. Calling this method causes
255 // GetNextBuffer() to stop returning kConfigChange and start returning 251 // GetNextBuffer() to stop returning kConfigChange and start returning
256 // kSuccess. 252 // kSuccess.
257 void CompleteConfigChange(); 253 void CompleteConfigChange();
258 254
259 // Sets |selected_range_| and seeks to the nearest keyframe after 255 // Sets |selected_range_| and seeks to the nearest keyframe after
260 // |timestamp| if necessary and possible. This method only attempts to 256 // |timestamp| if necessary and possible. This method only attempts to
261 // set |selected_range_| if |seleted_range_| is null and |track_buffer_| 257 // set |selected_range_| if |seleted_range_| is null and |track_buffer_|
262 // is empty. 258 // is empty.
263 void SetSelectedRangeIfNeeded(const base::TimeDelta timestamp); 259 void SetSelectedRangeIfNeeded(const DecodeTimestamp timestamp);
264 260
265 // Find a keyframe timestamp that is >= |start_timestamp| and can be used to 261 // Find a keyframe timestamp that is >= |start_timestamp| and can be used to
266 // find a new selected range. 262 // find a new selected range.
267 // Returns kNoTimestamp() if an appropriate keyframe timestamp could not be 263 // Returns kNoTimestamp() if an appropriate keyframe timestamp could not be
268 // found. 264 // found.
269 base::TimeDelta FindNewSelectedRangeSeekTimestamp( 265 DecodeTimestamp FindNewSelectedRangeSeekTimestamp(
270 const base::TimeDelta start_timestamp); 266 const DecodeTimestamp start_timestamp);
271 267
272 // Searches |ranges_| for the first keyframe timestamp that is >= |timestamp|. 268 // Searches |ranges_| for the first keyframe timestamp that is >= |timestamp|.
273 // If |ranges_| doesn't contain a GOP that covers |timestamp| or doesn't 269 // If |ranges_| doesn't contain a GOP that covers |timestamp| or doesn't
274 // have a keyframe after |timestamp| then kNoTimestamp() is returned. 270 // have a keyframe after |timestamp| then kNoTimestamp() is returned.
275 base::TimeDelta FindKeyframeAfterTimestamp(const base::TimeDelta timestamp); 271 DecodeTimestamp FindKeyframeAfterTimestamp(const DecodeTimestamp timestamp);
276 272
277 // Returns "VIDEO" for a video SourceBufferStream, "AUDIO" for an audio 273 // Returns "VIDEO" for a video SourceBufferStream, "AUDIO" for an audio
278 // stream, and "TEXT" for a text stream. 274 // stream, and "TEXT" for a text stream.
279 std::string GetStreamTypeName() const; 275 std::string GetStreamTypeName() const;
280 276
281 // Returns true if we don't have any ranges or the last range is selected 277 // Returns true if we don't have any ranges or the last range is selected
282 // or there is a pending seek beyond any existing ranges. 278 // or there is a pending seek beyond any existing ranges.
283 bool IsEndSelected() const; 279 bool IsEndSelected() const;
284 280
285 // Deletes the range pointed to by |*itr| and removes it from |ranges_|. 281 // Deletes the range pointed to by |*itr| and removes it from |ranges_|.
286 // If |*itr| points to |selected_range_|, then |selected_range_| is set to 282 // If |*itr| points to |selected_range_|, then |selected_range_| is set to
287 // NULL. After the range is removed, |*itr| is to the range after the one that 283 // NULL. After the range is removed, |*itr| is to the range after the one that
288 // was removed or to |ranges_.end()| if the last range was removed. 284 // was removed or to |ranges_.end()| if the last range was removed.
289 void DeleteAndRemoveRange(RangeList::iterator* itr); 285 void DeleteAndRemoveRange(RangeList::iterator* itr);
290 286
291 // Helper function used by Remove() and PrepareRangesForNextAppend() to 287 // Helper function used by Remove() and PrepareRangesForNextAppend() to
292 // remove buffers and ranges between |start| and |end|. 288 // remove buffers and ranges between |start| and |end|.
293 // |is_exclusive| - If set to true, buffers with timestamps that 289 // |is_exclusive| - If set to true, buffers with timestamps that
294 // match |start| are not removed. If set to false, buffers with 290 // match |start| are not removed. If set to false, buffers with
295 // timestamps that match |start| will be removed. 291 // timestamps that match |start| will be removed.
296 // |*deleted_buffers| - Filled with buffers for the current playback position 292 // |*deleted_buffers| - Filled with buffers for the current playback position
297 // if the removal range included the current playback position. These buffers 293 // if the removal range included the current playback position. These buffers
298 // can be used as candidates for placing in the |track_buffer_|. 294 // can be used as candidates for placing in the |track_buffer_|.
299 void RemoveInternal( 295 void RemoveInternal(
300 base::TimeDelta start, base::TimeDelta end, bool is_exclusive, 296 DecodeTimestamp start, DecodeTimestamp end, bool is_exclusive,
301 BufferQueue* deleted_buffers); 297 BufferQueue* deleted_buffers);
302 298
303 Type GetType() const; 299 Type GetType() const;
304 300
305 // See GetNextBuffer() for additional details. This method handles splice 301 // See GetNextBuffer() for additional details. This method handles splice
306 // frame processing. 302 // frame processing.
307 Status HandleNextBufferWithSplice( 303 Status HandleNextBufferWithSplice(
308 scoped_refptr<StreamParserBuffer>* out_buffer); 304 scoped_refptr<StreamParserBuffer>* out_buffer);
309 305
310 // See GetNextBuffer() for additional details. This method handles preroll 306 // See GetNextBuffer() for additional details. This method handles preroll
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // Pointer to the seeked-to Range. This is the range from which 362 // Pointer to the seeked-to Range. This is the range from which
367 // GetNextBuffer() calls are fulfilled after the |track_buffer_| has been 363 // GetNextBuffer() calls are fulfilled after the |track_buffer_| has been
368 // emptied. 364 // emptied.
369 SourceBufferRange* selected_range_; 365 SourceBufferRange* selected_range_;
370 366
371 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If 367 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If
372 // |track_buffer_| is empty, return buffers from |selected_range_|. 368 // |track_buffer_| is empty, return buffers from |selected_range_|.
373 BufferQueue track_buffer_; 369 BufferQueue track_buffer_;
374 370
375 // The start time of the current media segment being appended. 371 // The start time of the current media segment being appended.
376 base::TimeDelta media_segment_start_time_; 372 DecodeTimestamp media_segment_start_time_;
377 373
378 // Points to the range containing the current media segment being appended. 374 // Points to the range containing the current media segment being appended.
379 RangeList::iterator range_for_next_append_; 375 RangeList::iterator range_for_next_append_;
380 376
381 // True when the next call to Append() begins a new media segment. 377 // True when the next call to Append() begins a new media segment.
382 bool new_media_segment_; 378 bool new_media_segment_;
383 379
384 // The timestamp of the last buffer appended to the media segment, set to 380 // The timestamp of the last buffer appended to the media segment, set to
385 // kNoTimestamp() if the beginning of the segment. 381 // kNoDecodeTimestamp() if the beginning of the segment.
386 base::TimeDelta last_appended_buffer_timestamp_; 382 DecodeTimestamp last_appended_buffer_timestamp_;
387 bool last_appended_buffer_is_keyframe_; 383 bool last_appended_buffer_is_keyframe_;
388 384
389 // The decode timestamp on the last buffer returned by the most recent 385 // The decode timestamp on the last buffer returned by the most recent
390 // GetNextBuffer() call. Set to kNoTimestamp() if GetNextBuffer() hasn't been 386 // GetNextBuffer() call. Set to kNoTimestamp() if GetNextBuffer() hasn't been
391 // called yet or a seek has happened since the last GetNextBuffer() call. 387 // called yet or a seek has happened since the last GetNextBuffer() call.
392 base::TimeDelta last_output_buffer_timestamp_; 388 DecodeTimestamp last_output_buffer_timestamp_;
393 389
394 // Stores the largest distance between two adjacent buffers in this stream. 390 // Stores the largest distance between two adjacent buffers in this stream.
395 base::TimeDelta max_interbuffer_distance_; 391 base::TimeDelta max_interbuffer_distance_;
396 392
397 // The maximum amount of data in bytes the stream will keep in memory. 393 // The maximum amount of data in bytes the stream will keep in memory.
398 int memory_limit_; 394 int memory_limit_;
399 395
400 // Indicates that a kConfigChanged status has been reported by GetNextBuffer() 396 // Indicates that a kConfigChanged status has been reported by GetNextBuffer()
401 // and GetCurrentXXXDecoderConfig() must be called to update the current 397 // and GetCurrentXXXDecoderConfig() must be called to update the current
402 // config. GetNextBuffer() must not be called again until 398 // config. GetNextBuffer() must not be called again until
(...skipping 14 matching lines...) Expand all
417 413
418 // Indicates that splice frame generation is enabled. 414 // Indicates that splice frame generation is enabled.
419 const bool splice_frames_enabled_; 415 const bool splice_frames_enabled_;
420 416
421 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); 417 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream);
422 }; 418 };
423 419
424 } // namespace media 420 } // namespace media
425 421
426 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ 422 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698