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> |
| 11 #include <vector> | |
| 11 | 12 |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "media/base/audio_decoder_config.h" | 14 #include "media/base/audio_decoder_config.h" |
| 14 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
| 15 #include "media/base/ranges.h" | 16 #include "media/base/ranges.h" |
| 16 #include "media/base/stream_parser_buffer.h" | 17 #include "media/base/stream_parser_buffer.h" |
| 17 #include "media/base/video_decoder_config.h" | 18 #include "media/base/video_decoder_config.h" |
| 18 | 19 |
| 19 namespace media { | 20 namespace media { |
| 20 | 21 |
| 21 class SourceBufferRange; | 22 class SourceBufferRange; |
| 22 | 23 |
| 23 // SourceBufferStream is a data structure that stores media Buffers in ranges. | 24 // SourceBufferStream is a data structure that stores media Buffers in ranges. |
| 24 // Buffers can be appended out of presentation order. Buffers are retrieved by | 25 // Buffers can be appended out of presentation order. Buffers are retrieved by |
| 25 // seeking to the desired start point and calling GetNextBuffer(). Buffers are | 26 // seeking to the desired start point and calling GetNextBuffer(). Buffers are |
| 26 // returned in sequential presentation order. | 27 // returned in sequential presentation order. |
| 27 class MEDIA_EXPORT SourceBufferStream { | 28 class MEDIA_EXPORT SourceBufferStream { |
| 28 public: | 29 public: |
| 29 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; | 30 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; |
| 30 | 31 |
| 32 // Status returned by GetNextBuffer(). | |
| 33 // kSuccess: Indicates that the next buffer was returned. | |
| 34 // kNeedBuffer: Indicates that we need more data before a buffer can be | |
| 35 // returned. | |
| 36 // kConfigChange: Indicates that the next buffer requires a config change. | |
| 37 enum Status { | |
| 38 kSuccess, | |
| 39 kNeedBuffer, | |
| 40 kConfigChange, | |
| 41 }; | |
| 42 | |
| 31 explicit SourceBufferStream(const AudioDecoderConfig& audio_config); | 43 explicit SourceBufferStream(const AudioDecoderConfig& audio_config); |
| 32 explicit SourceBufferStream(const VideoDecoderConfig& video_config); | 44 explicit SourceBufferStream(const VideoDecoderConfig& video_config); |
| 33 | 45 |
| 34 ~SourceBufferStream(); | 46 ~SourceBufferStream(); |
| 35 | 47 |
| 36 // Signals that the next buffers appended are part of a new media segment | 48 // Signals that the next buffers appended are part of a new media segment |
| 37 // starting at |media_segment_start_time|. | 49 // starting at |media_segment_start_time|. |
| 38 void OnNewMediaSegment(base::TimeDelta media_segment_start_time); | 50 void OnNewMediaSegment(base::TimeDelta media_segment_start_time); |
| 39 | 51 |
| 40 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are | 52 // Add the |buffers| to the SourceBufferStream. Buffers within the queue are |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 51 | 63 |
| 52 // Returns true if the SourceBufferStream has seeked to a time without | 64 // Returns true if the SourceBufferStream has seeked to a time without |
| 53 // buffered data and is waiting for more data to be appended. | 65 // buffered data and is waiting for more data to be appended. |
| 54 bool IsSeekPending() const; | 66 bool IsSeekPending() const; |
| 55 | 67 |
| 56 // Fills |out_buffer| with a new buffer. Buffers are presented in order from | 68 // Fills |out_buffer| with a new buffer. Buffers are presented in order from |
| 57 // the last call to Seek(), or starting with the first buffer appended if | 69 // the last call to Seek(), or starting with the first buffer appended if |
| 58 // Seek() has not been called yet. | 70 // Seek() has not been called yet. |
| 59 // |out_buffer|'s timestamp may be earlier than the |timestamp| passed to | 71 // |out_buffer|'s timestamp may be earlier than the |timestamp| passed to |
| 60 // the last Seek() call. | 72 // the last Seek() call. |
| 61 // Returns true if |out_buffer| is filled with a valid buffer, false if | 73 // Returns kSuccess if |out_buffer| is filled with a valid buffer, kNeedBuffer |
| 62 // there is not enough data buffered to fulfill the request. | 74 // if there is not enough data buffered to fulfill the request, and |
| 63 bool GetNextBuffer(scoped_refptr<StreamParserBuffer>* out_buffer); | 75 // kConfigChange if the next buffer requires a config change. |
| 76 Status GetNextBuffer(scoped_refptr<StreamParserBuffer>* out_buffer); | |
| 64 | 77 |
| 65 // Returns a list of the buffered time ranges. | 78 // Returns a list of the buffered time ranges. |
| 66 Ranges<base::TimeDelta> GetBufferedTime() const; | 79 Ranges<base::TimeDelta> GetBufferedTime() const; |
| 67 | 80 |
| 68 // Notifies this SourceBufferStream that EndOfStream has been called and that | 81 // Notifies this SourceBufferStream that EndOfStream has been called and that |
| 69 // GetNextBuffer() should return EOS buffers after all other buffered data. | 82 // GetNextBuffer() should return EOS buffers after all other buffered data. |
| 70 // Returns false if called when there is a gap between the current position | 83 // Returns false if called when there is a gap between the current position |
| 71 // and the end of the buffered data. | 84 // and the end of the buffered data. |
| 72 void EndOfStream(); | 85 void EndOfStream(); |
| 73 | 86 |
| 74 // Returns true if this SourceBufferStream can successfully call EndOfStream() | 87 // Returns true if this SourceBufferStream can successfully call EndOfStream() |
| 75 // (if there are no gaps between the current position and the remaining data). | 88 // (if there are no gaps between the current position and the remaining data). |
| 76 bool CanEndOfStream() const; | 89 bool CanEndOfStream() const; |
| 77 | 90 |
| 78 const AudioDecoderConfig& GetCurrentAudioDecoderConfig() { | 91 const AudioDecoderConfig& GetCurrentAudioDecoderConfig() { |
| 79 return audio_config_; | 92 return *audio_configs_[current_config_index_]; |
| 80 } | 93 } |
| 81 const VideoDecoderConfig& GetCurrentVideoDecoderConfig() { | 94 const VideoDecoderConfig& GetCurrentVideoDecoderConfig() { |
| 82 return video_config_; | 95 return *video_configs_[current_config_index_]; |
| 83 } | 96 } |
| 84 | 97 |
| 98 // Notifies this object that the audio config has changed and buffers in | |
| 99 // future Append() calls should be associated with this new config. | |
| 100 bool UpdateAudioConfig(const AudioDecoderConfig& config); | |
| 101 | |
| 102 // Notifies this object that the video config has changed and buffers in | |
| 103 // future Append() calls should be associated with this new config. | |
| 104 bool UpdateVideoConfig(const VideoDecoderConfig& config); | |
| 105 | |
| 106 // Updates |current_config_index_| to match the index of the next buffer. | |
| 107 // Calling this method causes GetNextBuffer() to stop returning kConfigChange | |
| 108 // and start returning kSuccess. | |
| 109 void UpdateCurrentConfigIndex(); | |
| 110 | |
| 85 // Returns the largest distance between two adjacent buffers in this stream, | 111 // Returns the largest distance between two adjacent buffers in this stream, |
| 86 // or an estimate if no two adjacent buffers have been appended to the stream | 112 // or an estimate if no two adjacent buffers have been appended to the stream |
| 87 // yet. | 113 // yet. |
| 88 base::TimeDelta GetMaxInterbufferDistance() const; | 114 base::TimeDelta GetMaxInterbufferDistance() const; |
| 89 | 115 |
| 90 private: | 116 private: |
| 91 typedef std::list<SourceBufferRange*> RangeList; | 117 typedef std::list<SourceBufferRange*> RangeList; |
| 92 | 118 |
| 93 // Appends |new_buffers| into |range_for_new_buffers_itr|, handling start and | 119 // Appends |new_buffers| into |range_for_new_buffers_itr|, handling start and |
| 94 // end overlaps if necessary. | 120 // end overlaps if necessary. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 // |selected_range_| lives. | 181 // |selected_range_| lives. |
| 156 RangeList::iterator GetSelectedRangeItr(); | 182 RangeList::iterator GetSelectedRangeItr(); |
| 157 | 183 |
| 158 // Returns true if the timestamps of |buffers| are monotonically increasing | 184 // Returns true if the timestamps of |buffers| are monotonically increasing |
| 159 // since the previous append to the media segment, false otherwise. | 185 // since the previous append to the media segment, false otherwise. |
| 160 bool IsMonotonicallyIncreasing(const BufferQueue& buffers); | 186 bool IsMonotonicallyIncreasing(const BufferQueue& buffers); |
| 161 | 187 |
| 162 // Measures the distances between buffer timestamps and tracks the max. | 188 // Measures the distances between buffer timestamps and tracks the max. |
| 163 void UpdateMaxInterbufferDistance(const BufferQueue& buffers); | 189 void UpdateMaxInterbufferDistance(const BufferQueue& buffers); |
| 164 | 190 |
| 191 // Calls set_config_id() on each buffer with |append_config_index_|. | |
|
vrk (LEFT CHROMIUM)
2012/07/12 19:37:55
nit: Since the "set_config_id()" method isn't in t
acolwell GONE FROM CHROMIUM
2012/07/12 23:07:58
Done.
| |
| 192 void SetConfigIDs(const BufferQueue& buffers); | |
|
xhwang
2012/07/12 18:09:12
s/ID/Id?
acolwell GONE FROM CHROMIUM
2012/07/12 23:07:58
Done.
| |
| 193 | |
| 165 // List of disjoint buffered ranges, ordered by start time. | 194 // List of disjoint buffered ranges, ordered by start time. |
| 166 RangeList ranges_; | 195 RangeList ranges_; |
| 167 | 196 |
| 168 AudioDecoderConfig audio_config_; | 197 int current_config_index_; |
|
vrk (LEFT CHROMIUM)
2012/07/12 19:37:55
nit: add comments for new fields
acolwell GONE FROM CHROMIUM
2012/07/12 23:07:58
Done.
| |
| 169 VideoDecoderConfig video_config_; | 198 int append_config_index_; |
| 199 std::vector<AudioDecoderConfig*> audio_configs_; | |
| 200 std::vector<VideoDecoderConfig*> video_configs_; | |
| 170 | 201 |
| 171 // True if more data needs to be appended before the Seek() can complete, | 202 // True if more data needs to be appended before the Seek() can complete, |
| 172 // false if no Seek() has been requested or the Seek() is completed. | 203 // false if no Seek() has been requested or the Seek() is completed. |
| 173 bool seek_pending_; | 204 bool seek_pending_; |
| 174 | 205 |
| 175 // Timestamp of the last request to Seek(). | 206 // Timestamp of the last request to Seek(). |
| 176 base::TimeDelta seek_buffer_timestamp_; | 207 base::TimeDelta seek_buffer_timestamp_; |
| 177 | 208 |
| 178 // Pointer to the seeked-to Range. This is the range from which | 209 // Pointer to the seeked-to Range. This is the range from which |
| 179 // GetNextBuffer() calls are fulfilled after the |track_buffer_| has been | 210 // GetNextBuffer() calls are fulfilled after the |track_buffer_| has been |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 203 | 234 |
| 204 // Stores the largest distance between two adjacent buffers in this stream. | 235 // Stores the largest distance between two adjacent buffers in this stream. |
| 205 base::TimeDelta max_interbuffer_distance_; | 236 base::TimeDelta max_interbuffer_distance_; |
| 206 | 237 |
| 207 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); | 238 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); |
| 208 }; | 239 }; |
| 209 | 240 |
| 210 } // namespace media | 241 } // namespace media |
| 211 | 242 |
| 212 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ | 243 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
| OLD | NEW |