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"
11 OffsetByteQueue::OffsetByteQueue() : buf_(NULL
), size_(0), head_(0) {}
12 OffsetByteQueue::~OffsetByteQueue() {}
14 void OffsetByteQueue::Reset() {
21 void OffsetByteQueue::Push(const uint8
* buf
, int size
) {
22 queue_
.Push(buf
, size
);
24 DVLOG(4) << "Buffer pushed. head=" << head() << " tail=" << tail();
27 void OffsetByteQueue::Peek(const uint8
** buf
, int* size
) {
28 *buf
= size_
> 0 ? buf_
: NULL
;
32 void OffsetByteQueue::Pop(int count
) {
38 void OffsetByteQueue::PeekAt(int64 offset
, const uint8
** buf
, int* size
) {
39 DCHECK(offset
>= head());
40 if (offset
< head() || offset
>= tail()) {
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()) {
55 Pop(max_offset
- head_
);
59 void OffsetByteQueue::Sync() {
60 queue_
.Peek(&buf_
, &size_
);