| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
| 6 #define MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
| 7 |
| 8 #include <deque> |
| 9 #include <list> |
| 10 #include <utility> |
| 11 |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "media/base/media_export.h" |
| 14 #include "media/base/stream_parser_buffer.h" |
| 15 |
| 16 namespace media { |
| 17 |
| 18 class SourceBufferRange; |
| 19 |
| 20 // SourceBufferStream is a data structure that stores media Buffers in ranges. |
| 21 // Buffers can be appended out of presentation order. Buffers are retrieved by |
| 22 // seeking to the desired start point and calling GetNextBuffer(). Buffers are |
| 23 // returned in sequential presentation order. |
| 24 class MEDIA_EXPORT SourceBufferStream { |
| 25 public: |
| 26 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; |
| 27 typedef std::pair<base::TimeDelta, base::TimeDelta> Timespan; |
| 28 typedef std::list<Timespan> TimespanList; |
| 29 |
| 30 SourceBufferStream(); |
| 31 ~SourceBufferStream(); |
| 32 |
| 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 |
| 35 // of order or overlapping. Assumes all buffers within |buffers| are in |
| 36 // presentation order and are non-overlapping. |
| 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) |
| 41 bool Append(const BufferQueue& buffers); |
| 42 |
| 43 // Changes the SourceBufferStream's state so that it will start returning |
| 44 // buffers starting from the closest keyframe before |timestamp|. |
| 45 void Seek(base::TimeDelta timestamp); |
| 46 |
| 47 // 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(). |
| 49 // |out_buffer|'s timestamp may be earlier than the |timestamp| passed to |
| 50 // the last Seek() call. |
| 51 // Returns true if |out_buffer| is filled with a valid buffer, false if |
| 52 // there is not enough data buffered to fulfill the request. |
| 53 bool GetNextBuffer(scoped_refptr<StreamParserBuffer>* out_buffer); |
| 54 |
| 55 // Returns a list of the buffered time ranges. |
| 56 TimespanList GetBufferedTime() const; |
| 57 |
| 58 private: |
| 59 typedef std::list<SourceBufferRange*> RangeList; |
| 60 // List of disjoint buffered ranges, ordered by start time. |
| 61 RangeList ranges_; |
| 62 |
| 63 // True if more data needs to be appended before the Seek() can complete, |
| 64 // false if no Seek() has been requested or the Seek() is completed. |
| 65 bool seek_pending_; |
| 66 |
| 67 // Timestamp of the last request to Seek(). |
| 68 base::TimeDelta seek_buffer_timestamp_; |
| 69 |
| 70 // Pointer to the seeked-to Range. This is the Range from which |
| 71 // GetNextBuffer() calls are fulfilled. |
| 72 SourceBufferRange* selected_range_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(SourceBufferStream); |
| 75 }; |
| 76 |
| 77 } // namespace media |
| 78 |
| 79 #endif // MEDIA_FILTERS_SOURCE_BUFFER_STREAM_H_ |
| OLD | NEW |