5 #include <packager/media/base/byte_queue.h>
7 #include <absl/log/check.h>
8 #include <absl/log/log.h>
14 enum { kDefaultQueueSize = 1024 };
16 ByteQueue::ByteQueue()
17 : buffer_(new uint8_t[kDefaultQueueSize]),
18 size_(kDefaultQueueSize),
23 ByteQueue::~ByteQueue() {}
25 void ByteQueue::Reset() {
30 void ByteQueue::Push(
const uint8_t* data,
int size) {
33 size_t size_needed = used_ + size;
36 if (size_needed > size_) {
37 size_t new_size = 2 * size_;
38 while (size_needed > new_size && new_size > size_)
42 CHECK_GT(new_size, size_);
44 std::unique_ptr<uint8_t[]> new_buffer(
new uint8_t[new_size]);
48 memcpy(new_buffer.get(), front(), used_);
50 buffer_.reset(new_buffer.release());
53 }
else if ((offset_ + used_ + size) > size_) {
55 memmove(buffer_.get(), front(), used_);
59 memcpy(front() + used_, data, size);
63 void ByteQueue::Peek(
const uint8_t** data,
int* size)
const {
70 void ByteQueue::Pop(
int count) {
71 DCHECK_LE(count, used_);
77 if (offset_ == size_) {
83 uint8_t* ByteQueue::front()
const {
84 return buffer_.get() + offset_;
All the methods that are virtual are virtual for mocking.