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 16 matching lines...) Expand all Loading... |
27 class MEDIA_EXPORT SourceBufferStream { | 27 class MEDIA_EXPORT SourceBufferStream { |
28 public: | 28 public: |
29 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; | 29 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; |
30 | 30 |
31 SourceBufferStream(); | 31 SourceBufferStream(); |
32 explicit SourceBufferStream(const AudioDecoderConfig& audio_config); | 32 explicit SourceBufferStream(const AudioDecoderConfig& audio_config); |
33 explicit SourceBufferStream(const VideoDecoderConfig& video_config); | 33 explicit SourceBufferStream(const VideoDecoderConfig& video_config); |
34 | 34 |
35 ~SourceBufferStream(); | 35 ~SourceBufferStream(); |
36 | 36 |
| 37 // Signals that the next buffers appended are part of a new media segment |
| 38 // starting at |media_segment_start_time|. |
| 39 void OnNewMediaSegment(base::TimeDelta media_segment_start_time); |
| 40 |
37 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are | 41 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are |
38 // expected to be in order, but multiple calls to Append() may add buffers out | 42 // expected to be in order, but multiple calls to Append() may add buffers out |
39 // of order or overlapping. Assumes all buffers within |buffers| are in | 43 // of order or overlapping. Assumes all buffers within |buffers| are in |
40 // presentation order and are non-overlapping. | 44 // presentation order and are non-overlapping. |
41 // |media_segment_start_time| refers to the starting timestamp for the media | |
42 // segment to which these buffers belong. | |
43 // Returns true if Append() was successful, false if |buffers| are not added. | 45 // Returns true if Append() was successful, false if |buffers| are not added. |
44 // TODO(vrk): Implement garbage collection. (crbug.com/125070) | 46 // TODO(vrk): Implement garbage collection. (crbug.com/125070) |
45 bool Append(const BufferQueue& buffers, | 47 bool Append(const BufferQueue& buffers); |
46 base::TimeDelta media_segment_start_time); | |
47 | 48 |
48 // Changes the SourceBufferStream's state so that it will start returning | 49 // Changes the SourceBufferStream's state so that it will start returning |
49 // buffers starting from the closest keyframe before |timestamp|. | 50 // buffers starting from the closest keyframe before |timestamp|. |
50 void Seek(base::TimeDelta timestamp); | 51 void Seek(base::TimeDelta timestamp); |
51 | 52 |
52 // Returns true if the SourceBufferStream has seeked to a time without | 53 // Returns true if the SourceBufferStream has seeked to a time without |
53 // buffered data and is waiting for more data to be appended. | 54 // buffered data and is waiting for more data to be appended. |
54 bool IsSeekPending() const; | 55 bool IsSeekPending() const; |
55 | 56 |
56 // Fills |out_buffer| with a new buffer. Buffers are presented in order from | 57 // Fills |out_buffer| with a new buffer. Buffers are presented in order from |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // buffers. | 97 // buffers. |
97 void ResolveCompleteOverlaps( | 98 void ResolveCompleteOverlaps( |
98 const RangeList::iterator& range_with_new_buffers_itr); | 99 const RangeList::iterator& range_with_new_buffers_itr); |
99 void ResolveEndOverlap(const RangeList::iterator& range_with_new_buffers_itr); | 100 void ResolveEndOverlap(const RangeList::iterator& range_with_new_buffers_itr); |
100 | 101 |
101 // This method is a bit tricky to describe. When what would have been the | 102 // This method is a bit tricky to describe. When what would have been the |
102 // next buffer returned from |selected_range_| is overlapped by new data, | 103 // next buffer returned from |selected_range_| is overlapped by new data, |
103 // the |selected_range_| seeks forward to the next keyframe after (or at) the | 104 // the |selected_range_| seeks forward to the next keyframe after (or at) the |
104 // next buffer timestamp and the overlapped buffers are deleted. But for | 105 // next buffer timestamp and the overlapped buffers are deleted. But for |
105 // smooth playback between the old data to the new data's keyframe, some of | 106 // smooth playback between the old data to the new data's keyframe, some of |
106 // these |deleted_buffers| may be temporarily saved into |track_buffer_|. | 107 // these |deleted_buffers_| may be temporarily saved into |track_buffer_|. |
107 // UpdateTrackBuffer() takes these |deleted_buffers| and decides whether it | 108 // UpdateTrackBuffer() takes these |deleted_buffers_| and decides whether it |
108 // wants to save any buffers into |track_buffer_|. | 109 // wants to save any buffers into |track_buffer_|. |
109 // TODO(vrk): This is a little crazy! Ideas for cleanup in crbug.com/129623. | 110 // TODO(vrk): This is a little crazy! Ideas for cleanup in crbug.com/129623. |
110 void UpdateTrackBuffer(const BufferQueue& deleted_buffers); | 111 void UpdateTrackBuffer(); |
111 | 112 |
112 // Checks to see if |range_with_new_buffers_itr| can be merged with the range | 113 // Checks to see if |range_with_new_buffers_itr| can be merged with the range |
113 // next to it, and merges them if so. | 114 // next to it, and merges them if so. |
114 void MergeWithAdjacentRangeIfNecessary( | 115 void MergeWithAdjacentRangeIfNecessary( |
115 const RangeList::iterator& range_with_new_buffers_itr); | 116 const RangeList::iterator& range_with_new_buffers_itr); |
116 | 117 |
117 // Helper method that returns the timestamp for the next buffer that | 118 // Helper method that returns the timestamp for the next buffer that |
118 // |selected_range_| will return from GetNextBuffer() call, or kNoTimestamp() | 119 // |selected_range_| will return from GetNextBuffer() call, or kNoTimestamp() |
119 // if in between seeking (i.e. |selected_range_| is null). | 120 // if in between seeking (i.e. |selected_range_| is null). |
120 base::TimeDelta GetNextBufferTimestamp(); | 121 base::TimeDelta GetNextBufferTimestamp(); |
(...skipping 30 matching lines...) Expand all Loading... |
151 SourceBufferRange* selected_range_; | 152 SourceBufferRange* selected_range_; |
152 | 153 |
153 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If | 154 // Queue of the next buffers to be returned from calls to GetNextBuffer(). If |
154 // |track_buffer_| is empty, return buffers from |selected_range_|. | 155 // |track_buffer_| is empty, return buffers from |selected_range_|. |
155 BufferQueue track_buffer_; | 156 BufferQueue track_buffer_; |
156 | 157 |
157 // True when EndOfStream() has been called and GetNextBuffer() should return | 158 // True when EndOfStream() has been called and GetNextBuffer() should return |
158 // EOS buffers for read requests beyond the buffered data. False initially. | 159 // EOS buffers for read requests beyond the buffered data. False initially. |
159 bool end_of_stream_; | 160 bool end_of_stream_; |
160 | 161 |
| 162 // True if the next buffer that would have been returned from GetNextBuffer() |
| 163 // was deleted during an Append(). Should never be true outside of an |
| 164 // Append() call. |
| 165 bool deleted_next_buffer_; |
| 166 // Candidates for |track_buffer_|. Should always be empty outside of an |
| 167 // Append() call. |
| 168 BufferQueue deleted_buffers_; |
| 169 |
| 170 // The start time of the current media segment being appended. |
| 171 base::TimeDelta media_segment_start_time_; |
| 172 |
| 173 // Points to the range containing the current media segment being appended. |
| 174 RangeList::iterator range_for_next_append_; |
| 175 |
161 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); | 176 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); |
162 }; | 177 }; |
163 | 178 |
164 } // namespace media | 179 } // namespace media |
165 | 180 |
166 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ | 181 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
OLD | NEW |