mirror of
https://github.com/shaka-project/shaka-packager.git
synced 2026-04-13 08:40:49 +00:00
Some checks failed
Update Issues / update-issues (push) Has been cancelled
Release / Settings (push) Has been cancelled
Release / release (push) Has been cancelled
Release / Compute latest release flag (push) Has been cancelled
Release / Update docs (push) Has been cancelled
Release / Update docker image (push) Has been cancelled
Release / Build (push) Has been cancelled
Release / Artifacts (push) Has been cancelled
Release / Update NPM (push) Has been cancelled
This was done by git clang-format v18. Results are the same up to v22. Newer versions were not tested. Commands: ``` FIRST_SHA1=58a19df git clang-format --style Chromium $FIRST_SHA1 git commit -a ``` From now on, we won't have to trip over ancient style issues from other parts of a file we're working on. "Probability factor of one to one. We have normality. I repeat, we have normality. Anything you still can't cope with is therefore your own problem." ~Douglas Adams
70 lines
1.4 KiB
C++
70 lines
1.4 KiB
C++
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include <packager/media/base/offset_byte_queue.h>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <absl/log/log.h>
|
|
|
|
#include <packager/macros/logging.h>
|
|
|
|
namespace shaka {
|
|
namespace media {
|
|
|
|
OffsetByteQueue::OffsetByteQueue() : buf_(NULL), size_(0), head_(0) {}
|
|
OffsetByteQueue::~OffsetByteQueue() {}
|
|
|
|
void OffsetByteQueue::Reset() {
|
|
queue_.Reset();
|
|
buf_ = NULL;
|
|
size_ = 0;
|
|
head_ = 0;
|
|
}
|
|
|
|
void OffsetByteQueue::Push(const uint8_t* buf, int size) {
|
|
queue_.Push(buf, size);
|
|
Sync();
|
|
DVLOG(4) << "Buffer pushed. head=" << head() << " tail=" << tail();
|
|
}
|
|
|
|
void OffsetByteQueue::Peek(const uint8_t** buf, int* size) {
|
|
*buf = size_ > 0 ? buf_ : NULL;
|
|
*size = size_;
|
|
}
|
|
|
|
void OffsetByteQueue::Pop(int count) {
|
|
queue_.Pop(count);
|
|
head_ += count;
|
|
Sync();
|
|
}
|
|
|
|
void OffsetByteQueue::PeekAt(int64_t offset, const uint8_t** buf, int* size) {
|
|
if (offset < head() || offset >= tail()) {
|
|
*buf = NULL;
|
|
*size = 0;
|
|
return;
|
|
}
|
|
*buf = &buf_[offset - head()];
|
|
*size = tail() - offset;
|
|
}
|
|
|
|
bool OffsetByteQueue::Trim(int64_t max_offset) {
|
|
if (max_offset < head_)
|
|
return true;
|
|
if (max_offset > tail()) {
|
|
Pop(size_);
|
|
return false;
|
|
}
|
|
Pop(max_offset - head_);
|
|
return true;
|
|
}
|
|
|
|
void OffsetByteQueue::Sync() {
|
|
queue_.Peek(&buf_, &size_);
|
|
}
|
|
|
|
} // namespace media
|
|
} // namespace shaka
|