2013-09-24 01:35:40 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_BASE_OFFSET_BYTE_QUEUE_H_
|
|
|
|
#define PACKAGER_MEDIA_BASE_OFFSET_BYTE_QUEUE_H_
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/base/byte_queue.h>
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-09-24 01:35:40 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Wrapper around ByteQueue, which encapsulates the notion of a
|
|
|
|
/// monotonically-increasing byte offset. All buffer access is done by passing
|
|
|
|
/// these offsets into this class, reducing the proliferation of many different
|
|
|
|
/// meanings of "offset", "head", etc.
|
2013-09-24 04:17:12 +00:00
|
|
|
class OffsetByteQueue {
|
2013-09-24 01:35:40 +00:00
|
|
|
public:
|
|
|
|
OffsetByteQueue();
|
|
|
|
~OffsetByteQueue();
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @name These work like their underlying ByteQueue counterparts.
|
|
|
|
/// @{
|
2013-09-24 01:35:40 +00:00
|
|
|
void Reset();
|
2014-09-30 21:52:21 +00:00
|
|
|
void Push(const uint8_t* buf, int size);
|
|
|
|
void Peek(const uint8_t** buf, int* size);
|
2013-09-24 01:35:40 +00:00
|
|
|
void Pop(int count);
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Set @a buf to point at the first buffered byte corresponding to @a offset,
|
|
|
|
/// and @a size to the number of bytes available starting from that offset.
|
|
|
|
///
|
|
|
|
/// It is an error if the offset is before the current head. It's not an error
|
|
|
|
/// if the current offset is beyond tail(), but you will of course get back
|
|
|
|
/// a null @a buf and a @a size of zero.
|
2014-09-30 21:52:21 +00:00
|
|
|
void PeekAt(int64_t offset, const uint8_t** buf, int* size);
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Mark the bytes up to (but not including) @a max_offset as ready for
|
|
|
|
/// deletion. This is relatively inexpensive, but will not necessarily reduce
|
|
|
|
/// the resident buffer size right away (or ever).
|
|
|
|
///
|
|
|
|
/// @return true if the full range of bytes were successfully trimmed,
|
|
|
|
/// including the case where @a max_offset is less than the current
|
|
|
|
/// head.
|
|
|
|
/// @return false if @a max_offset > tail() (although all bytes currently
|
|
|
|
/// buffered are still cleared).
|
2014-09-30 21:52:21 +00:00
|
|
|
bool Trim(int64_t max_offset);
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return The head position, in terms of the file's absolute offset.
|
2014-09-30 21:52:21 +00:00
|
|
|
int64_t head() { return head_; }
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return The tail position (exclusive), in terms of the file's absolute
|
|
|
|
/// offset.
|
2014-09-30 21:52:21 +00:00
|
|
|
int64_t tail() { return head_ + size_; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Synchronize |buf_| and |size_| with |queue_|.
|
|
|
|
void Sync();
|
|
|
|
|
|
|
|
ByteQueue queue_;
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint8_t* buf_;
|
2013-09-24 01:35:40 +00:00
|
|
|
int size_;
|
2014-09-30 21:52:21 +00:00
|
|
|
int64_t head_;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(OffsetByteQueue);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_BASE_OFFSET_BYTE_QUEUE_H_
|