21#include "config-adpcm.h"
23namespace adpcm_ffmpeg {
27inline uint32_t loadBigEndian(
const uint8_t *p) {
29 for (
int i = 0; i < N; i++) v = (v << 8) | p[i];
34inline uint32_t loadLittleEndian(
const uint8_t *p) {
36 for (
int i = N - 1; i >= 0; i--) v = (v << 8) | p[i];
51 void init(
const uint8_t *buf,
int buf_size) {
52 av_assert(buf_size >= 0);
55 end_ = buf + buf_size;
59 int bytesLeft()
const {
return (
int)(end_ - buffer_); }
61 int tell()
const {
return (
int)(buffer_ - start_); }
63 int size()
const {
return (
int)(end_ - start_); }
66 void skip(
unsigned int size) { buffer_ += FFMIN(end_ - buffer_,
size); }
74 offset = av_clip(
offset, -(buffer_ - start_), end_ - buffer_);
86 return AVERROR(AVERROR_INVALID);
93 uint32_t getLe16Unchecked() {
return read<2, false>(); }
94 uint32_t getBe16Unchecked() {
return read<2, true>(); }
95 uint32_t getLe32Unchecked() {
return read<4, false>(); }
96 uint32_t getBe32Unchecked() {
return read<4, true>(); }
99 uint32_t getByte() {
return readChecked<1, false>(); }
100 uint32_t getLe16() {
return readChecked<2, false>(); }
101 uint32_t getBe16() {
return readChecked<2, true>(); }
102 uint32_t getLe32() {
return readChecked<4, false>(); }
103 uint32_t getBe32() {
return readChecked<4, true>(); }
106 const uint8_t *buffer_ =
nullptr;
107 const uint8_t *start_ =
nullptr;
108 const uint8_t *end_ =
nullptr;
110 template <
int N,
bool BigEndian>
112 const uint32_t v = BigEndian ? loadBigEndian<N>(buffer_)
113 : loadLittleEndian<N>(buffer_);
118 template <
int N,
bool BigEndian>
119 uint32_t readChecked() {
120 if (end_ - buffer_ < N) {
124 return read<N, BigEndian>();
Vector implementation which provides the most important methods as defined by std::vector....
Definition ADPCMVector.h:16
Bounds checked reader for a memory buffer. Reads past the end return 0 and move the position to the e...
Definition ByteReader.h:45
void skip(unsigned int size)
skips up to size bytes (stops at the end of the buffer)
Definition ByteReader.h:66
int seek(int offset, int whence)
moves the position; returns the new position or an error code
Definition ByteReader.h:71
int size() const
total size of the buffer
Definition ByteReader.h:63
int tell() const
current position relative to the start of the buffer
Definition ByteReader.h:61
void skipUnchecked(unsigned int size)
skips size bytes without checking the buffer end
Definition ByteReader.h:68
int bytesLeft() const
number of bytes between the current position and the end
Definition ByteReader.h:59