| 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 // SeekableBuffer to support backward and forward seeking in a buffer for | 5 // SeekableBuffer to support backward and forward seeking in a buffer for |
| 6 // reading a media data source. | 6 // reading a media data source. |
| 7 // | 7 // |
| 8 // In order to support backward and forward seeking, this class buffers data in | 8 // In order to support backward and forward seeking, this class buffers data in |
| 9 // both backward and forward directions, the current read position can be reset | 9 // both backward and forward directions, the current read position can be reset |
| 10 // to anywhere in the buffered data. | 10 // to anywhere in the buffered data. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 void Clear(); | 53 void Clear(); |
| 54 | 54 |
| 55 // Reads a maximum of |size| bytes into |data| from the current read | 55 // Reads a maximum of |size| bytes into |data| from the current read |
| 56 // position. Returns the number of bytes read. | 56 // position. Returns the number of bytes read. |
| 57 // The current read position will advance by the amount of bytes read. If | 57 // The current read position will advance by the amount of bytes read. If |
| 58 // reading caused backward_bytes() to exceed backward_capacity(), an eviction | 58 // reading caused backward_bytes() to exceed backward_capacity(), an eviction |
| 59 // of the backward buffer will be done internally. | 59 // of the backward buffer will be done internally. |
| 60 size_t Read(uint8* data, size_t size); | 60 size_t Read(uint8* data, size_t size); |
| 61 | 61 |
| 62 // Copies up to |size| bytes from current position to |data|. Returns | 62 // Copies up to |size| bytes from current position to |data|. Returns |
| 63 // number of bytes copied. Doesn't advance current position. | 63 // number of bytes copied. Doesn't advance current position. Optionally |
| 64 // starts at a |forward_offset| from current position. |
| 64 size_t Peek(uint8* data, size_t size); | 65 size_t Peek(uint8* data, size_t size); |
| 66 size_t Peek(uint8* data, size_t size, size_t forward_offset); |
| 65 | 67 |
| 66 // Returns pointer to the current chunk of data that is being consumed. | 68 // Returns pointer to the current chunk of data that is being consumed. |
| 67 // If there is no data left in the buffer false is returned, otherwise | 69 // If there is no data left in the buffer false is returned, otherwise |
| 68 // true is returned and |data| and |size| are updated. The returned | 70 // true is returned and |data| and |size| are updated. The returned |
| 69 // |data| value becomes invalid when Read(), Append() or Seek() | 71 // |data| value becomes invalid when Read(), Append() or Seek() |
| 70 // are called. | 72 // are called. |
| 71 bool GetCurrentChunk(const uint8** data, size_t* size) const; | 73 bool GetCurrentChunk(const uint8** data, size_t* size) const; |
| 72 | 74 |
| 73 // Appends |buffer_in| to this buffer. Returns false if forward_bytes() is | 75 // Appends |buffer_in| to this buffer. Returns false if forward_bytes() is |
| 74 // greater than or equals to forward_capacity(), true otherwise. The data | 76 // greater than or equals to forward_capacity(), true otherwise. The data |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 132 |
| 131 // A helper method to evict buffers in the backward direction until backward | 133 // A helper method to evict buffers in the backward direction until backward |
| 132 // bytes is within the backward capacity. | 134 // bytes is within the backward capacity. |
| 133 void EvictBackwardBuffers(); | 135 void EvictBackwardBuffers(); |
| 134 | 136 |
| 135 // An internal method shared by Read() and SeekForward() that actually does | 137 // An internal method shared by Read() and SeekForward() that actually does |
| 136 // reading. It reads a maximum of |size| bytes into |data|. Returns the number | 138 // reading. It reads a maximum of |size| bytes into |data|. Returns the number |
| 137 // of bytes read. The current read position will be moved forward by the | 139 // of bytes read. The current read position will be moved forward by the |
| 138 // number of bytes read. If |data| is NULL, only the current read position | 140 // number of bytes read. If |data| is NULL, only the current read position |
| 139 // will advance but no data will be copied. | 141 // will advance but no data will be copied. |
| 140 size_t InternalRead(uint8* data, size_t size, bool advance_position); | 142 size_t InternalRead( |
| 143 uint8* data, size_t size, bool advance_position, size_t forward_offset); |
| 141 | 144 |
| 142 // A helper method that moves the current read position forward by |size| | 145 // A helper method that moves the current read position forward by |size| |
| 143 // bytes. | 146 // bytes. |
| 144 // If the return value is true, the operation completed successfully. | 147 // If the return value is true, the operation completed successfully. |
| 145 // If the return value is false, |size| is greater than forward_bytes() and | 148 // If the return value is false, |size| is greater than forward_bytes() and |
| 146 // the seek operation failed. The current read position is not updated. | 149 // the seek operation failed. The current read position is not updated. |
| 147 bool SeekForward(size_t size); | 150 bool SeekForward(size_t size); |
| 148 | 151 |
| 149 // A helper method that moves the current read position backward by |size| | 152 // A helper method that moves the current read position backward by |size| |
| 150 // bytes. | 153 // bytes. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 170 // Keeps track of the most recent time we've seen in case the |buffers_| is | 173 // Keeps track of the most recent time we've seen in case the |buffers_| is |
| 171 // empty when our owner asks what time it is. | 174 // empty when our owner asks what time it is. |
| 172 base::TimeDelta current_time_; | 175 base::TimeDelta current_time_; |
| 173 | 176 |
| 174 DISALLOW_COPY_AND_ASSIGN(SeekableBuffer); | 177 DISALLOW_COPY_AND_ASSIGN(SeekableBuffer); |
| 175 }; | 178 }; |
| 176 | 179 |
| 177 } // namespace media | 180 } // namespace media |
| 178 | 181 |
| 179 #endif // MEDIA_BASE_SEEKABLE_BUFFER_H_ | 182 #endif // MEDIA_BASE_SEEKABLE_BUFFER_H_ |
| OLD | NEW |