Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / formats / common / offset_byte_queue.cc
blob0bbff80c7cf242ced75c0ae20cf3f74e797ecd6e
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
3 // found in the LICENSE file.
5 #include "media/formats/common/offset_byte_queue.h"
7 #include "base/logging.h"
9 namespace media {
11 OffsetByteQueue::OffsetByteQueue() : buf_(NULL), size_(0), head_(0) {}
12 OffsetByteQueue::~OffsetByteQueue() {}
14 void OffsetByteQueue::Reset() {
15 queue_.Reset();
16 buf_ = NULL;
17 size_ = 0;
18 head_ = 0;
21 void OffsetByteQueue::Push(const uint8* buf, int size) {
22 queue_.Push(buf, size);
23 Sync();
24 DVLOG(4) << "Buffer pushed. head=" << head() << " tail=" << tail();
27 void OffsetByteQueue::Peek(const uint8** buf, int* size) {
28 *buf = size_ > 0 ? buf_ : NULL;
29 *size = size_;
32 void OffsetByteQueue::Pop(int count) {
33 queue_.Pop(count);
34 head_ += count;
35 Sync();
38 void OffsetByteQueue::PeekAt(int64 offset, const uint8** buf, int* size) {
39 DCHECK(offset >= head());
40 if (offset < head() || offset >= tail()) {
41 *buf = NULL;
42 *size = 0;
43 return;
45 *buf = &buf_[offset - head()];
46 *size = tail() - offset;
49 bool OffsetByteQueue::Trim(int64 max_offset) {
50 if (max_offset < head_) return true;
51 if (max_offset > tail()) {
52 Pop(size_);
53 return false;
55 Pop(max_offset - head_);
56 return true;
59 void OffsetByteQueue::Sync() {
60 queue_.Peek(&buf_, &size_);
63 } // namespace media