5 #include "packager/media/base/byte_queue.h"
7 #include "packager/base/logging.h"
13 enum { kDefaultQueueSize = 1024 };
15 ByteQueue::ByteQueue()
16 : buffer_(new uint8_t[kDefaultQueueSize]),
17 size_(kDefaultQueueSize),
22 ByteQueue::~ByteQueue() {}
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);
71 DCHECK_LE(count, used_);
77 if (offset_ == size_) {
83 uint8_t* ByteQueue::front()
const {
84 return buffer_.get() + offset_;