Chromium Code Reviews| 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 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ | 5 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
| 6 #define MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ | 6 #define MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 typedef std::list<Timespan> TimespanList; | 28 typedef std::list<Timespan> TimespanList; |
| 29 | 29 |
| 30 SourceBufferStream(); | 30 SourceBufferStream(); |
| 31 ~SourceBufferStream(); | 31 ~SourceBufferStream(); |
| 32 | 32 |
| 33 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are | 33 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are |
| 34 // expected to be in order, but multiple calls to Append() may add buffers out | 34 // expected to be in order, but multiple calls to Append() may add buffers out |
| 35 // of order or overlapping. Assumes all buffers within |buffers| are in | 35 // of order or overlapping. Assumes all buffers within |buffers| are in |
| 36 // presentation order and are non-overlapping. | 36 // presentation order and are non-overlapping. |
| 37 // Returns true if Append() was successful, false if |buffers| are not added. | 37 // Returns true if Append() was successful, false if |buffers| are not added. |
| 38 // TODO(vrk): Implement proper end-overlapping. (crbug.com/125072) | |
| 39 // This may trigger garbage collection. | |
| 40 // TODO(vrk): Implement garbage collection. (crbug.com/125070) | 38 // TODO(vrk): Implement garbage collection. (crbug.com/125070) |
| 41 bool Append(const BufferQueue& buffers); | 39 bool Append(const BufferQueue& buffers); |
| 42 | 40 |
| 43 // Changes the SourceBufferStream's state so that it will start returning | 41 // Changes the SourceBufferStream's state so that it will start returning |
| 44 // buffers starting from the closest keyframe before |timestamp|. | 42 // buffers starting from the closest keyframe before |timestamp|. |
| 45 void Seek(base::TimeDelta timestamp); | 43 void Seek(base::TimeDelta timestamp); |
| 46 | 44 |
| 47 // Fills |out_buffer| with a new buffer. Seek() must be called before calling | 45 // Fills |out_buffer| with a new buffer. Seek() must be called before calling |
| 48 // this method. Buffers are presented in order from the last call to Seek(). | 46 // this method. Buffers are presented in order from the last call to Seek(). |
| 49 // |out_buffer|'s timestamp may be earlier than the |timestamp| passed to | 47 // |out_buffer|'s timestamp may be earlier than the |timestamp| passed to |
| 50 // the last Seek() call. | 48 // the last Seek() call. |
| 51 // Returns true if |out_buffer| is filled with a valid buffer, false if | 49 // Returns true if |out_buffer| is filled with a valid buffer, false if |
| 52 // there is not enough data buffered to fulfill the request. | 50 // there is not enough data buffered to fulfill the request. |
| 53 bool GetNextBuffer(scoped_refptr<StreamParserBuffer>* out_buffer); | 51 bool GetNextBuffer(scoped_refptr<StreamParserBuffer>* out_buffer); |
| 54 | 52 |
| 55 // Returns a list of the buffered time ranges. | 53 // Returns a list of the buffered time ranges. |
| 56 TimespanList GetBufferedTime() const; | 54 TimespanList GetBufferedTime() const; |
| 57 | 55 |
| 58 private: | 56 private: |
| 59 typedef std::list<SourceBufferRange*> RangeList; | 57 typedef std::list<SourceBufferRange*> RangeList; |
| 60 | 58 |
| 59 // Appends |new_buffers| into |range_for_new_buffers_itr|, handling start and | |
| 60 // end overlaps if necessary. | |
| 61 void InsertIntoExistingRange( | |
| 62 const RangeList::iterator& range_for_new_buffers_itr, | |
| 63 const BufferQueue& new_buffers); | |
| 64 | |
| 61 // Resolve overlapping ranges such that no ranges overlap anymore. | 65 // Resolve overlapping ranges such that no ranges overlap anymore. |
| 62 // |range_itr| points to the iterator in |ranges_| immediately after | 66 // |range_with_new_buffers_itr| points to the range that has newly appended |
| 63 // |new_range|. Returns the iterator in |ranges_| immediately after | 67 // buffers. |
| 64 // |new_range|, which may be different from the original |range_itr|. | 68 void ResolveCompleteOverlaps( |
| 65 RangeList::iterator ResolveCompleteOverlaps( | 69 const RangeList::iterator& range_with_new_buffers_itr); |
| 66 const RangeList::iterator& range_itr, SourceBufferRange* new_range); | 70 void ResolveEndOverlap(const RangeList::iterator& range_with_new_buffers_itr); |
| 67 RangeList::iterator ResolveEndOverlaps( | |
| 68 const RangeList::iterator& range_itr, SourceBufferRange* new_range); | |
| 69 | 71 |
| 70 // Checks to see if the range pointed to by |range_itr| can be appended to the | 72 // Adds buffers to |track_buffer_| and updates |selected_range_| accordingly. |
| 71 // end of |new_range|, and if so, appends the range and updates |ranges_| to | 73 // |range_with_new_buffers_itr| points to the range containing the newly |
| 72 // reflect this. | 74 // appended buffers. |
| 75 // |deleted_buffers| contains all the buffers that were deleted as a result | |
| 76 // of appending new buffers into |range_with_new_buffers_itr|. |next_buffer| | |
| 77 // points to the next buffer in |deleted_buffers| that was deleted. Assumes | |
|
acolwell GONE FROM CHROMIUM
2012/05/22 19:35:23
The "that was deleted" here confuses me. I don't r
vrk (LEFT CHROMIUM)
2012/05/24 20:06:30
Yeah sorry, I didn't know how to describe this wit
| |
| 78 // |deleted_buffers| and |next_buffer| are valid. | |
| 79 void UpdateTrackBuffer( | |
| 80 const RangeList::iterator& range_with_new_buffers_itr, | |
| 81 const BufferQueue& deleted_buffers, | |
| 82 const BufferQueue::iterator& next_buffer); | |
| 83 | |
| 84 // Checks to see if |range_with_new_buffers_itr| can be merged with the range | |
| 85 // next to it, and merges them if so. | |
| 73 void MergeWithAdjacentRangeIfNecessary( | 86 void MergeWithAdjacentRangeIfNecessary( |
| 74 const RangeList::iterator& range_itr, SourceBufferRange* new_range); | 87 const RangeList::iterator& range_with_new_buffers_itr); |
| 75 | 88 |
| 76 // List of disjoint buffered ranges, ordered by start time. | 89 // List of disjoint buffered ranges, ordered by start time. |
| 77 RangeList ranges_; | 90 RangeList ranges_; |
| 78 | 91 |
| 79 // True if more data needs to be appended before the Seek() can complete, | 92 // True if more data needs to be appended before the Seek() can complete, |
| 80 // false if no Seek() has been requested or the Seek() is completed. | 93 // false if no Seek() has been requested or the Seek() is completed. |
| 81 bool seek_pending_; | 94 bool seek_pending_; |
| 82 | 95 |
| 83 // Timestamp of the last request to Seek(). | 96 // Timestamp of the last request to Seek(). |
| 84 base::TimeDelta seek_buffer_timestamp_; | 97 base::TimeDelta seek_buffer_timestamp_; |
| 85 | 98 |
| 86 // Pointer to the seeked-to Range. This is the range from which | 99 // Pointer to the seeked-to Range. This is the range from which |
| 87 // GetNextBuffer() calls are fulfilled after the |track_buffer_| has been | 100 // GetNextBuffer() calls are fulfilled after the |track_buffer_| has been |
| 88 // emptied. | 101 // emptied. |
| 89 SourceBufferRange* selected_range_; | 102 SourceBufferRange* selected_range_; |
| 90 | 103 |
| 91 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If | 104 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If |
| 92 // |track_buffer_| is empty, return buffers from |selected_range_|. | 105 // |track_buffer_| is empty, return buffers from |selected_range_|. |
| 93 BufferQueue track_buffer_; | 106 BufferQueue track_buffer_; |
| 94 | 107 |
| 95 // True if the next buffer after the end of the |track_buffer_| is not | |
| 96 // buffered yet and we need to wait for the next keyframe after | |
| 97 // |track_buffer_| to be appended. | |
| 98 bool waiting_for_keyframe_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); | 108 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); |
| 101 }; | 109 }; |
| 102 | 110 |
| 103 } // namespace media | 111 } // namespace media |
| 104 | 112 |
| 105 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ | 113 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
| OLD | NEW |