21#ifdef BITSTREAM_TEMPLATE_LE
22# define BS_SUFFIX_LOWER _le
23# define BS_SUFFIX_UPPER LE
25# define BS_SUFFIX_LOWER _be
26# define BS_SUFFIX_UPPER BE
29#define BS_JOIN(x, y, z) x ## y ## z
30#define BS_JOIN3(x, y, z) BS_JOIN(x, y, z)
31#define BS_FUNC(x) BS_JOIN3(bits_, x, BS_SUFFIX_LOWER)
33#define BSCTX BS_JOIN3(Bitstream, Context, BS_SUFFIX_UPPER)
52#if !UNCHECKED_BITSTREAM_READER
53 if (bc->ptr >= bc->buffer_end)
57#ifdef BITSTREAM_TEMPLATE_LE
77#if !UNCHECKED_BITSTREAM_READER
78 if (bc->ptr >= bc->buffer_end)
82#ifdef BITSTREAM_TEMPLATE_LE
83 bc->bits |= (uint64_t)
AV_RL32(bc->ptr) << bc->bits_valid;
85 bc->bits |= (uint64_t)
AV_RB32(bc->ptr) << (32 - bc->bits_valid);
102 unsigned int bit_size)
104 unsigned int buffer_size;
106 if (bit_size > INT_MAX - 7 || !
buffer) {
113 buffer_size = (bit_size + 7) >> 3;
116 bc->buffer_end =
buffer + buffer_size;
117 bc->ptr = bc->buffer;
118 bc->size_in_bits = bit_size;
136 unsigned int byte_size)
138 if (byte_size > INT_MAX / 8)
148 return (bc->ptr - bc->buffer) * 8 - bc->bits_valid;
156 return bc->size_in_bits;
164 return (bc->size_in_bits + (round_up ? 7 : 0)) >> 3;
172 return (bc->buffer - bc->ptr) * 8 + bc->size_in_bits + bc->bits_valid;
179#ifdef BITSTREAM_TEMPLATE_LE
180 return bc->bits & (UINT64_MAX >> (64 - n));
182 return bc->bits >> (64 - n);
188#ifdef BITSTREAM_TEMPLATE_LE
228 if (n > bc->bits_valid) {
262 if (n > bc->bits_valid) {
263 left = bc->bits_valid;
274#ifdef BITSTREAM_TEMPLATE_LE
292#ifdef BITSTREAM_TEMPLATE_LE
334 if (n > bc->bits_valid)
385 if (n < bc->bits_valid)
393 unsigned int skip = n / 8;
409 bc->ptr = bc->buffer;
435 int sign = ~cache >> 31;
438 return ((((uint32_t)(sign ^ cache)) >> (32 - n)) ^ sign) - sign;
467 return (
val ^ sign) - sign;
496 return table[idx].sym;
511 int bits,
int max_depth)
516 int n =
table[idx].len;
518 if (max_depth > 1 && n < 0) {
521 if (max_depth > 2 && n < 0) {
547 const int bits,
const int max_depth,
548 const int symbols_size)
551 int ret, nb_bits,
code, n = Jtable[idx].len;
552 if (Jtable[idx].num) {
554 ret = Jtable[idx].num;
558 if (max_depth > 1 && n < 0) {
561 if (max_depth > 2 && n < 0) {
566 if (symbols_size == 1)
581#undef BS_SUFFIX_UPPER
582#undef BS_SUFFIX_LOWER
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static int BS_FUNC skip_1stop_8data(BSCTX *s)
static int BS_FUNC bytesize(const BSCTX *bc, int round_up)
Return buffer size in bytes.
static uint64_t BS_FUNC priv_val_show(BSCTX *bc, unsigned int n)
static uint64_t BS_FUNC read_64(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-64 range.
static int BS_FUNC tell(const BSCTX *bc)
Return number of bits already read.
static int BS_FUNC read_vlc_multi(BSCTX *bc, uint8_t dst[8], const VLC_MULTI_ELEM *const Jtable, const VLCElem *const table, const int bits, const int max_depth, const int symbols_size)
Parse a vlc / vlc_multi code.
static uint64_t BS_FUNC read_63(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-63 range.
static int BS_FUNC read_vlc(BSCTX *bc, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static uint32_t BS_FUNC peek_nz(BSCTX *bc, unsigned int n)
Return n bits from the buffer but do not change the buffer state.
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static void BS_FUNC seek(BSCTX *bc, unsigned pos)
Seek to the given bit position.
static uint32_t BS_FUNC read_nz(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 1-32 range.
static int BS_FUNC peek_signed(BSCTX *bc, unsigned int n)
Return n bits from the buffer as a signed integer, do not change the buffer state.
static void BS_FUNC priv_skip_remaining(BSCTX *bc, unsigned int n)
static int BS_FUNC decode012(BSCTX *bc)
Return decoded truncated unary code for the values 0, 1, 2.
static int BS_FUNC priv_refill_64(BSCTX *bc)
static int BS_FUNC decode210(BSCTX *bc)
Return decoded truncated unary code for the values 2, 1, 0.
static int32_t BS_FUNC read_signed_nz(BSCTX *bc, unsigned int n)
Return n bits from the buffer as a signed integer, n has to be in the 1-32 range.
static uint32_t BS_FUNC read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
static int BS_FUNC priv_refill_32(BSCTX *bc)
static int BS_FUNC priv_set_idx(BSCTX *bc, int code, int *n, int *nb_bits, const VLCElem *table)
Return the LUT element for the given bitstream configuration.
static uint64_t BS_FUNC priv_val_get(BSCTX *bc, unsigned int n)
static int BS_FUNC read_xbits(BSCTX *bc, unsigned int n)
Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
static int BS_FUNC init8(BSCTX *bc, const uint8_t *buffer, unsigned int byte_size)
Initialize BitstreamContext.
static uint32_t BS_FUNC peek(BSCTX *bc, unsigned int n)
Return n bits from the buffer but do not change the buffer state.
static int32_t BS_FUNC read_signed(BSCTX *bc, unsigned int n)
Return n bits from the buffer as a signed integer.
static unsigned int BS_FUNC read_bit(BSCTX *bc)
Return one bit from the buffer.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
static int BS_FUNC apply_sign(BSCTX *bc, int val)
static int BS_FUNC peek_signed_nz(BSCTX *bc, unsigned int n)
Return n bits from the buffer as a signed integer, do not change the buffer state.
int(* init)(AVBSFContext *ctx)
static const uint8_t bits[8]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static av_const int sign_extend(int val, unsigned bits)
static const uint16_t table[]
const uint8_t * buffer_end