Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / media / formats / common / offset_byte_queue.cc
bloba2b6994e40c52ec0b96314b5000129d76283fbe2
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/basictypes.h"
8 #include "base/logging.h"
10 namespace media {
12 OffsetByteQueue::OffsetByteQueue() : buf_(NULL), size_(0), head_(0) {}
13 OffsetByteQueue::~OffsetByteQueue() {}
15 void OffsetByteQueue::Reset() {
16 queue_.Reset();
17 buf_ = NULL;
18 size_ = 0;
19 head_ = 0;
22 void OffsetByteQueue::Push(const uint8* buf, int size) {
23 queue_.Push(buf, size);
24 Sync();
25 DVLOG(4) << "Buffer pushed. head=" << head() << " tail=" << tail();
28 void OffsetByteQueue::Peek(const uint8** buf, int* size) {
29 *buf = size_ > 0 ? buf_ : NULL;
30 *size = size_;
33 void OffsetByteQueue::Pop(int count) {
34 queue_.Pop(count);
35 head_ += count;
36 Sync();
39 void OffsetByteQueue::PeekAt(int64 offset, const uint8** buf, int* size) {
40 DCHECK(offset >= head());
41 if (offset < head() || offset >= tail()) {
42 *buf = NULL;
43 *size = 0;
44 return;
46 *buf = &buf_[offset - head()];
47 *size = tail() - offset;
50 bool OffsetByteQueue::Trim(int64 max_offset) {
51 if (max_offset < head_) return true;
52 if (max_offset > tail()) {
53 Pop(size_);
54 return false;
56 Pop(max_offset - head_);
57 return true;
60 void OffsetByteQueue::Sync() {
61 queue_.Peek(&buf_, &size_);
64 } // namespace media