| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_FORMATS_COMMON_OFFSET_BYTE_QUEUE_H_ | 5 #ifndef MEDIA_FORMATS_COMMON_OFFSET_BYTE_QUEUE_H_ |
| 6 #define MEDIA_FORMATS_COMMON_OFFSET_BYTE_QUEUE_H_ | 6 #define MEDIA_FORMATS_COMMON_OFFSET_BYTE_QUEUE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | |
| 9 #include "media/base/byte_queue.h" | 8 #include "media/base/byte_queue.h" |
| 10 #include "media/base/media_export.h" | 9 #include "media/base/media_export.h" |
| 11 | 10 |
| 12 namespace media { | 11 namespace media { |
| 13 | 12 |
| 14 // A wrapper around a ByteQueue which maintains a notion of a | 13 // A wrapper around a ByteQueue which maintains a notion of a |
| 15 // monotonically-increasing offset. All buffer access is done by passing these | 14 // monotonically-increasing offset. All buffer access is done by passing these |
| 16 // offsets into this class, going some way towards preventing the proliferation | 15 // offsets into this class, going some way towards preventing the proliferation |
| 17 // of many different meanings of "offset", "head", etc. | 16 // of many different meanings of "offset", "head", etc. |
| 18 class MEDIA_EXPORT OffsetByteQueue { | 17 class MEDIA_EXPORT OffsetByteQueue { |
| 19 public: | 18 public: |
| 20 OffsetByteQueue(); | 19 OffsetByteQueue(); |
| 21 ~OffsetByteQueue(); | 20 ~OffsetByteQueue(); |
| 22 | 21 |
| 23 // These work like their underlying ByteQueue counterparts. | 22 // These work like their underlying ByteQueue counterparts. |
| 24 void Reset(); | 23 void Reset(); |
| 25 void Push(const uint8* buf, int size); | 24 void Push(const uint8_t* buf, int size); |
| 26 void Peek(const uint8** buf, int* size); | 25 void Peek(const uint8_t** buf, int* size); |
| 27 void Pop(int count); | 26 void Pop(int count); |
| 28 | 27 |
| 29 // Sets |buf| to point at the first buffered byte corresponding to |offset|, | 28 // Sets |buf| to point at the first buffered byte corresponding to |offset|, |
| 30 // and |size| to the number of bytes available starting from that offset. | 29 // and |size| to the number of bytes available starting from that offset. |
| 31 // | 30 // |
| 32 // It is an error if the offset is before the current head. It's not an error | 31 // It is an error if the offset is before the current head. It's not an error |
| 33 // if the current offset is beyond tail(), but you will of course get back | 32 // if the current offset is beyond tail(), but you will of course get back |
| 34 // a null |buf| and a |size| of zero. | 33 // a null |buf| and a |size| of zero. |
| 35 void PeekAt(int64 offset, const uint8** buf, int* size); | 34 void PeekAt(int64_t offset, const uint8_t** buf, int* size); |
| 36 | 35 |
| 37 // Marks the bytes up to (but not including) |max_offset| as ready for | 36 // Marks the bytes up to (but not including) |max_offset| as ready for |
| 38 // deletion. This is relatively inexpensive, but will not necessarily reduce | 37 // deletion. This is relatively inexpensive, but will not necessarily reduce |
| 39 // the resident buffer size right away (or ever). | 38 // the resident buffer size right away (or ever). |
| 40 // | 39 // |
| 41 // Returns true if the full range of bytes were successfully trimmed, | 40 // Returns true if the full range of bytes were successfully trimmed, |
| 42 // including the case where |max_offset| is less than the current head. | 41 // including the case where |max_offset| is less than the current head. |
| 43 // Returns false if |max_offset| > tail() (although all bytes currently | 42 // Returns false if |max_offset| > tail() (although all bytes currently |
| 44 // buffered are still cleared). | 43 // buffered are still cleared). |
| 45 bool Trim(int64 max_offset); | 44 bool Trim(int64_t max_offset); |
| 46 | 45 |
| 47 // The head and tail positions, in terms of the file's absolute offsets. | 46 // The head and tail positions, in terms of the file's absolute offsets. |
| 48 // tail() is an exclusive bound. | 47 // tail() is an exclusive bound. |
| 49 int64 head() { return head_; } | 48 int64_t head() { return head_; } |
| 50 int64 tail() { return head_ + size_; } | 49 int64_t tail() { return head_ + size_; } |
| 51 | 50 |
| 52 private: | 51 private: |
| 53 // Synchronize |buf_| and |size_| with |queue_|. | 52 // Synchronize |buf_| and |size_| with |queue_|. |
| 54 void Sync(); | 53 void Sync(); |
| 55 | 54 |
| 56 ByteQueue queue_; | 55 ByteQueue queue_; |
| 57 const uint8* buf_; | 56 const uint8_t* buf_; |
| 58 int size_; | 57 int size_; |
| 59 int64 head_; | 58 int64_t head_; |
| 60 | 59 |
| 61 DISALLOW_COPY_AND_ASSIGN(OffsetByteQueue); | 60 DISALLOW_COPY_AND_ASSIGN(OffsetByteQueue); |
| 62 }; | 61 }; |
| 63 | 62 |
| 64 } // namespace media | 63 } // namespace media |
| 65 | 64 |
| 66 #endif // MEDIA_FORMATS_COMMON_OFFSET_BYTE_QUEUE_H_ | 65 #endif // MEDIA_FORMATS_COMMON_OFFSET_BYTE_QUEUE_H_ |
| OLD | NEW |