OLD | NEW |
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 bool splice_frames_enabled); | 61 bool splice_frames_enabled); |
62 SourceBufferStream(const VideoDecoderConfig& video_config, | 62 SourceBufferStream(const VideoDecoderConfig& video_config, |
63 const scoped_refptr<MediaLog>& media_log, | 63 const scoped_refptr<MediaLog>& media_log, |
64 bool splice_frames_enabled); | 64 bool splice_frames_enabled); |
65 SourceBufferStream(const TextTrackConfig& text_config, | 65 SourceBufferStream(const TextTrackConfig& text_config, |
66 const scoped_refptr<MediaLog>& media_log, | 66 const scoped_refptr<MediaLog>& media_log, |
67 bool splice_frames_enabled); | 67 bool splice_frames_enabled); |
68 | 68 |
69 ~SourceBufferStream(); | 69 ~SourceBufferStream(); |
70 | 70 |
71 // Signals that the next buffers appended are part of a new media segment | 71 // Signals that the next buffers appended are part of a new coded frame group |
72 // starting at |media_segment_start_time|. | 72 // starting at |coded_frame_group_start_time|. |
73 // TODO(acolwell/wolenetz): This should be changed to a presentation | 73 // TODO(acolwell/wolenetz): This should be changed to a presentation |
74 // timestamp. See http://crbug.com/402502 | 74 // timestamp. See http://crbug.com/402502 |
75 void OnNewMediaSegment(DecodeTimestamp media_segment_start_time); | 75 void OnStartOfCodedFrameGroup(DecodeTimestamp coded_frame_group_start_time); |
76 | 76 |
77 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are | 77 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are |
78 // expected to be in order, but multiple calls to Append() may add buffers out | 78 // expected to be in order, but multiple calls to Append() may add buffers out |
79 // of order or overlapping. Assumes all buffers within |buffers| are in | 79 // of order or overlapping. Assumes all buffers within |buffers| are in |
80 // presentation order and are non-overlapping. | 80 // presentation order and are non-overlapping. |
81 // Returns true if Append() was successful, false if |buffers| are not added. | 81 // Returns true if Append() was successful, false if |buffers| are not added. |
82 // TODO(vrk): Implement garbage collection. (crbug.com/125070) | 82 // TODO(vrk): Implement garbage collection. (crbug.com/125070) |
83 bool Append(const BufferQueue& buffers); | 83 bool Append(const BufferQueue& buffers); |
84 | 84 |
85 // Removes buffers between |start| and |end| according to the steps | 85 // Removes buffers between |start| and |end| according to the steps |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // Returns true if |second_timestamp| is the timestamp of the next buffer in | 204 // Returns true if |second_timestamp| is the timestamp of the next buffer in |
205 // sequence after |first_timestamp|, false otherwise. | 205 // sequence after |first_timestamp|, false otherwise. |
206 bool AreAdjacentInSequence( | 206 bool AreAdjacentInSequence( |
207 DecodeTimestamp first_timestamp, DecodeTimestamp second_timestamp) const; | 207 DecodeTimestamp first_timestamp, DecodeTimestamp second_timestamp) const; |
208 | 208 |
209 // Helper method that returns the timestamp for the next buffer that | 209 // Helper method that returns the timestamp for the next buffer that |
210 // |selected_range_| will return from GetNextBuffer() call, or kNoTimestamp() | 210 // |selected_range_| will return from GetNextBuffer() call, or kNoTimestamp() |
211 // if in between seeking (i.e. |selected_range_| is null). | 211 // if in between seeking (i.e. |selected_range_| is null). |
212 DecodeTimestamp GetNextBufferTimestamp(); | 212 DecodeTimestamp GetNextBufferTimestamp(); |
213 | 213 |
214 // Finds the range that should contain a media segment that begins with | 214 // Finds the range that should contain a coded frame group that begins with |
215 // |start_timestamp| and returns the iterator pointing to it. Returns | 215 // |start_timestamp| and returns the iterator pointing to it. Returns |
216 // |ranges_.end()| if there's no such existing range. | 216 // |ranges_.end()| if there's no such existing range. |
217 RangeList::iterator FindExistingRangeFor(DecodeTimestamp start_timestamp); | 217 RangeList::iterator FindExistingRangeFor(DecodeTimestamp start_timestamp); |
218 | 218 |
219 // Inserts |new_range| into |ranges_| preserving sorted order. Returns an | 219 // Inserts |new_range| into |ranges_| preserving sorted order. Returns an |
220 // iterator in |ranges_| that points to |new_range|. | 220 // iterator in |ranges_| that points to |new_range|. |
221 RangeList::iterator AddToRanges(SourceBufferRange* new_range); | 221 RangeList::iterator AddToRanges(SourceBufferRange* new_range); |
222 | 222 |
223 // Returns an iterator that points to the place in |ranges_| where | 223 // Returns an iterator that points to the place in |ranges_| where |
224 // |selected_range_| lives. | 224 // |selected_range_| lives. |
225 RangeList::iterator GetSelectedRangeItr(); | 225 RangeList::iterator GetSelectedRangeItr(); |
226 | 226 |
227 // Sets the |selected_range_| to |range| and resets the next buffer position | 227 // Sets the |selected_range_| to |range| and resets the next buffer position |
228 // for the previous |selected_range_|. | 228 // for the previous |selected_range_|. |
229 void SetSelectedRange(SourceBufferRange* range); | 229 void SetSelectedRange(SourceBufferRange* range); |
230 | 230 |
231 // Seeks |range| to |seek_timestamp| and then calls SetSelectedRange() with | 231 // Seeks |range| to |seek_timestamp| and then calls SetSelectedRange() with |
232 // |range|. | 232 // |range|. |
233 void SeekAndSetSelectedRange(SourceBufferRange* range, | 233 void SeekAndSetSelectedRange(SourceBufferRange* range, |
234 DecodeTimestamp seek_timestamp); | 234 DecodeTimestamp seek_timestamp); |
235 | 235 |
236 // Resets this stream back to an unseeked state. | 236 // Resets this stream back to an unseeked state. |
237 void ResetSeekState(); | 237 void ResetSeekState(); |
238 | 238 |
239 // Returns true if |seek_timestamp| refers to the beginning of the first range | 239 // Returns true if |seek_timestamp| refers to the beginning of the first range |
240 // in |ranges_|, false otherwise or if |ranges_| is empty. | 240 // in |ranges_|, false otherwise or if |ranges_| is empty. |
241 bool ShouldSeekToStartOfBuffered(base::TimeDelta seek_timestamp) const; | 241 bool ShouldSeekToStartOfBuffered(base::TimeDelta seek_timestamp) const; |
242 | 242 |
243 // Returns true if the timestamps of |buffers| are monotonically increasing | 243 // Returns true if the timestamps of |buffers| are monotonically increasing |
244 // since the previous append to the media segment, false otherwise. | 244 // since the previous append to the coded frame group, false otherwise. |
245 bool IsMonotonicallyIncreasing(const BufferQueue& buffers) const; | 245 bool IsMonotonicallyIncreasing(const BufferQueue& buffers); |
246 | |
247 // Returns true if |next_timestamp| and |next_is_keyframe| are valid for | |
248 // the first buffer after the previous append. | |
249 bool IsNextTimestampValid(DecodeTimestamp next_timestamp, | |
250 bool next_is_keyframe) const; | |
251 | 246 |
252 // Returns true if |selected_range_| is the only range in |ranges_| that | 247 // Returns true if |selected_range_| is the only range in |ranges_| that |
253 // HasNextBufferPosition(). | 248 // HasNextBufferPosition(). |
254 bool OnlySelectedRangeIsSeeked() const; | 249 bool OnlySelectedRangeIsSeeked() const; |
255 | 250 |
256 // Measures the distances between buffer timestamps and tracks the max. | 251 // Measures the distances between buffer timestamps and tracks the max. |
257 void UpdateMaxInterbufferDistance(const BufferQueue& buffers); | 252 void UpdateMaxInterbufferDistance(const BufferQueue& buffers); |
258 | 253 |
259 // Sets the config ID for each buffer to |append_config_index_|. | 254 // Sets the config ID for each buffer to |append_config_index_|. |
260 void SetConfigIds(const BufferQueue& buffers); | 255 void SetConfigIds(const BufferQueue& buffers); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 // 2. We don't have any ranges, or the last or no range is selected, | 288 // 2. We don't have any ranges, or the last or no range is selected, |
294 // or there is a pending seek beyond any existing ranges. | 289 // or there is a pending seek beyond any existing ranges. |
295 bool IsEndOfStreamReached() const; | 290 bool IsEndOfStreamReached() const; |
296 | 291 |
297 // Deletes the range pointed to by |*itr| and removes it from |ranges_|. | 292 // Deletes the range pointed to by |*itr| and removes it from |ranges_|. |
298 // If |*itr| points to |selected_range_|, then |selected_range_| is set to | 293 // If |*itr| points to |selected_range_|, then |selected_range_| is set to |
299 // NULL. After the range is removed, |*itr| is to the range after the one that | 294 // NULL. After the range is removed, |*itr| is to the range after the one that |
300 // was removed or to |ranges_.end()| if the last range was removed. | 295 // was removed or to |ranges_.end()| if the last range was removed. |
301 void DeleteAndRemoveRange(RangeList::iterator* itr); | 296 void DeleteAndRemoveRange(RangeList::iterator* itr); |
302 | 297 |
| 298 // Helper function used when updating |range_for_next_append_|. |
| 299 // Returns a guess of what the next append timestamp will be based on |
| 300 // |last_appended_buffer_timestamp_|, |new_coded_frame_group_| and |
| 301 // |coded_frame_group_start_time_|. Returns kNoDecodeTimestamp() if unable to |
| 302 // guess, which can occur prior to first OnStartOfCodedFrameGroup(), or |
| 303 // when the most recent GOP appended to since the last |
| 304 // OnStartOfCodedFrameGroup() is removed. |
| 305 DecodeTimestamp PotentialNextAppendTimestamp() const; |
| 306 |
303 // Helper function used by Remove() and PrepareRangesForNextAppend() to | 307 // Helper function used by Remove() and PrepareRangesForNextAppend() to |
304 // remove buffers and ranges between |start| and |end|. | 308 // remove buffers and ranges between |start| and |end|. |
305 // |exclude_start| - If set to true, buffers with timestamps that | 309 // |exclude_start| - If set to true, buffers with timestamps that |
306 // match |start| are not removed. If set to false, buffers with | 310 // match |start| are not removed. If set to false, buffers with |
307 // timestamps that match |start| will be removed. | 311 // timestamps that match |start| will be removed. |
308 // |*deleted_buffers| - Filled with buffers for the current playback position | 312 // |*deleted_buffers| - Filled with buffers for the current playback position |
309 // if the removal range included the current playback position. These buffers | 313 // if the removal range included the current playback position. These buffers |
310 // can be used as candidates for placing in the |track_buffer_|. | 314 // can be used as candidates for placing in the |track_buffer_|. |
311 void RemoveInternal(DecodeTimestamp start, | 315 void RemoveInternal(DecodeTimestamp start, |
312 DecodeTimestamp end, | 316 DecodeTimestamp end, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 SourceBufferRange* selected_range_ = nullptr; | 394 SourceBufferRange* selected_range_ = nullptr; |
391 | 395 |
392 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If | 396 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If |
393 // |track_buffer_| is empty, return buffers from |selected_range_|. | 397 // |track_buffer_| is empty, return buffers from |selected_range_|. |
394 BufferQueue track_buffer_; | 398 BufferQueue track_buffer_; |
395 | 399 |
396 // If there has been no intervening Seek, this will be true if the last | 400 // If there has been no intervening Seek, this will be true if the last |
397 // emitted buffer emptied |track_buffer_|. | 401 // emitted buffer emptied |track_buffer_|. |
398 bool just_exhausted_track_buffer_ = false; | 402 bool just_exhausted_track_buffer_ = false; |
399 | 403 |
400 // The start time of the current media segment being appended. | 404 // The start time of the current coded frame group being appended. |
401 DecodeTimestamp media_segment_start_time_; | 405 DecodeTimestamp coded_frame_group_start_time_; |
402 | 406 |
403 // Points to the range containing the current media segment being appended. | 407 // Points to the range containing the current coded frame group being |
| 408 // appended. |
404 RangeList::iterator range_for_next_append_; | 409 RangeList::iterator range_for_next_append_; |
405 | 410 |
406 // True when the next call to Append() begins a new media segment. | 411 // True when the next call to Append() begins a new coded frame group. |
407 bool new_media_segment_ = false; | 412 // TODO(wolenetz): Simplify by passing this flag into Append(). |
| 413 bool new_coded_frame_group_ = false; |
408 | 414 |
409 // The timestamp of the last buffer appended to the media segment, set to | 415 // The timestamp of the last buffer appended to the coded frame group, set to |
410 // kNoDecodeTimestamp() if the beginning of the segment. | 416 // kNoDecodeTimestamp() if the beginning of the group. |
411 DecodeTimestamp last_appended_buffer_timestamp_ = kNoDecodeTimestamp(); | 417 DecodeTimestamp last_appended_buffer_timestamp_ = kNoDecodeTimestamp(); |
412 base::TimeDelta last_appended_buffer_duration_ = kNoTimestamp(); | 418 base::TimeDelta last_appended_buffer_duration_ = kNoTimestamp(); |
413 bool last_appended_buffer_is_keyframe_ = false; | 419 bool last_appended_buffer_is_keyframe_ = false; |
414 | 420 |
415 // The decode timestamp on the last buffer returned by the most recent | 421 // The decode timestamp on the last buffer returned by the most recent |
416 // GetNextBuffer() call. Set to kNoDecodeTimestamp() if GetNextBuffer() hasn't | 422 // GetNextBuffer() call. Set to kNoDecodeTimestamp() if GetNextBuffer() hasn't |
417 // been called yet or a seek has happened since the last GetNextBuffer() call. | 423 // been called yet or a seek has happened since the last GetNextBuffer() call. |
418 DecodeTimestamp last_output_buffer_timestamp_; | 424 DecodeTimestamp last_output_buffer_timestamp_; |
419 | 425 |
420 // Stores the largest distance between two adjacent buffers in this stream. | 426 // Stores the largest distance between two adjacent buffers in this stream. |
(...skipping 21 matching lines...) Expand all Loading... |
442 bool pending_buffers_complete_ = false; | 448 bool pending_buffers_complete_ = false; |
443 | 449 |
444 // Indicates that splice frame generation is enabled. | 450 // Indicates that splice frame generation is enabled. |
445 const bool splice_frames_enabled_; | 451 const bool splice_frames_enabled_; |
446 | 452 |
447 // To prevent log spam, count the number of warnings and successes logged. | 453 // To prevent log spam, count the number of warnings and successes logged. |
448 int num_splice_generation_warning_logs_ = 0; | 454 int num_splice_generation_warning_logs_ = 0; |
449 int num_splice_generation_success_logs_ = 0; | 455 int num_splice_generation_success_logs_ = 0; |
450 int num_track_buffer_gap_warning_logs_ = 0; | 456 int num_track_buffer_gap_warning_logs_ = 0; |
451 int num_garbage_collect_algorithm_logs_ = 0; | 457 int num_garbage_collect_algorithm_logs_ = 0; |
| 458 int num_strange_same_timestamps_logs_ = 0; |
452 | 459 |
453 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); | 460 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); |
454 }; | 461 }; |
455 | 462 |
456 } // namespace media | 463 } // namespace media |
457 | 464 |
458 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ | 465 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
OLD | NEW |