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() {}
32 size_t size_needed = used_ + size;
35 if (size_needed > size_) {
36 size_t new_size = 2 * size_;
37 while (size_needed > new_size && new_size > size_)
41 CHECK_GT(new_size, size_);
43 std::unique_ptr<uint8_t[]> new_buffer(
new uint8_t[new_size]);
47 memcpy(new_buffer.get(), front(), used_);
49 buffer_.reset(new_buffer.release());
52 }
else if ((offset_ + used_ + size) > size_) {
54 memmove(buffer_.get(), front(), used_);
58 memcpy(front() + used_, data, size);
70 DCHECK_LE(count, used_);
76 if (offset_ == size_) {
82 uint8_t* ByteQueue::front()
const {
83 return buffer_.get() + offset_;