Shaka Packager SDK
offset_byte_queue.cc
1 // Copyright (c) 2012 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.
4 
5 #include <packager/media/base/offset_byte_queue.h>
6 
7 #include <cstdint>
8 
9 #include <absl/log/log.h>
10 
11 #include <packager/macros/logging.h>
12 
13 namespace shaka {
14 namespace media {
15 
16 OffsetByteQueue::OffsetByteQueue() : buf_(NULL), size_(0), head_(0) {}
17 OffsetByteQueue::~OffsetByteQueue() {}
18 
19 void OffsetByteQueue::Reset() {
20  queue_.Reset();
21  buf_ = NULL;
22  size_ = 0;
23  head_ = 0;
24 }
25 
26 void OffsetByteQueue::Push(const uint8_t* buf, int size) {
27  queue_.Push(buf, size);
28  Sync();
29  DVLOG(4) << "Buffer pushed. head=" << head() << " tail=" << tail();
30 }
31 
32 void OffsetByteQueue::Peek(const uint8_t** buf, int* size) {
33  *buf = size_ > 0 ? buf_ : NULL;
34  *size = size_;
35 }
36 
37 void OffsetByteQueue::Pop(int count) {
38  queue_.Pop(count);
39  head_ += count;
40  Sync();
41 }
42 
43 void OffsetByteQueue::PeekAt(int64_t offset, const uint8_t** buf, int* size) {
44  if (offset < head() || offset >= tail()) {
45  *buf = NULL;
46  *size = 0;
47  return;
48  }
49  *buf = &buf_[offset - head()];
50  *size = tail() - offset;
51 }
52 
53 bool OffsetByteQueue::Trim(int64_t max_offset) {
54  if (max_offset < head_) return true;
55  if (max_offset > tail()) {
56  Pop(size_);
57  return false;
58  }
59  Pop(max_offset - head_);
60  return true;
61 }
62 
63 void OffsetByteQueue::Sync() {
64  queue_.Peek(&buf_, &size_);
65 }
66 
67 } // namespace media
68 } // namespace shaka
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66