26 #ifndef AVCODEC_GET_BITS_H 27 #define AVCODEC_GET_BITS_H 50 #ifndef UNCHECKED_BITSTREAM_READER 51 #define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER 58 #if !UNCHECKED_BITSTREAM_READER 59 int size_in_bits_plus8;
107 #ifdef LONG_BITSTREAM_READER 108 # define MIN_CACHE_BITS 32 110 # define MIN_CACHE_BITS 25 113 #define OPEN_READER_NOSIZE(name, gb) \ 114 unsigned int name ## _index = (gb)->index; \ 115 unsigned int av_unused name ## _cache = 0 117 #if UNCHECKED_BITSTREAM_READER 118 #define OPEN_READER(name, gb) OPEN_READER_NOSIZE(name, gb) 120 #define BITS_AVAILABLE(name, gb) 1 122 #define OPEN_READER(name, gb) \ 123 OPEN_READER_NOSIZE(name, gb); \ 124 unsigned int name ## _size_plus8 = (gb)->size_in_bits_plus8 126 #define BITS_AVAILABLE(name, gb) name ## _index < name ## _size_plus8 129 #define CLOSE_READER(name, gb) (gb)->index = name ## _index 131 #ifdef BITSTREAM_READER_LE 133 # ifdef LONG_BITSTREAM_READER 134 # define UPDATE_CACHE(name, gb) name ## _cache = \ 135 AV_RL64((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7) 137 # define UPDATE_CACHE(name, gb) name ## _cache = \ 138 AV_RL32((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7) 141 # define SKIP_CACHE(name, gb, num) name ## _cache >>= (num) 145 # ifdef LONG_BITSTREAM_READER 146 # define UPDATE_CACHE(name, gb) name ## _cache = \ 147 AV_RB64((gb)->buffer + (name ## _index >> 3)) >> (32 - (name ## _index & 7)) 149 # define UPDATE_CACHE(name, gb) name ## _cache = \ 150 AV_RB32((gb)->buffer + (name ## _index >> 3)) << (name ## _index & 7) 153 # define SKIP_CACHE(name, gb, num) name ## _cache <<= (num) 157 #if UNCHECKED_BITSTREAM_READER 158 # define SKIP_COUNTER(name, gb, num) name ## _index += (num) 160 # define SKIP_COUNTER(name, gb, num) \ 161 name ## _index = FFMIN(name ## _size_plus8, name ## _index + (num)) 164 #define SKIP_BITS(name, gb, num) \ 166 SKIP_CACHE(name, gb, num); \ 167 SKIP_COUNTER(name, gb, num); \ 170 #define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) 172 #ifdef BITSTREAM_READER_LE 173 # define SHOW_UBITS(name, gb, num) zero_extend(name ## _cache, num) 174 # define SHOW_SBITS(name, gb, num) sign_extend(name ## _cache, num) 176 # define SHOW_UBITS(name, gb, num) NEG_USR32(name ## _cache, num) 177 # define SHOW_SBITS(name, gb, num) NEG_SSR32(name ## _cache, num) 180 #define GET_CACHE(name, gb) ((uint32_t) name ## _cache) 189 #if UNCHECKED_BITSTREAM_READER 211 return (
NEG_USR32(sign ^ cache, n) ^ sign) - sign;
271 #ifdef BITSTREAM_READER_LE 272 result >>= index & 7;
275 result <<= index & 7;
278 #if !UNCHECKED_BITSTREAM_READER 279 if (s->
index < s->size_in_bits_plus8)
305 #ifdef BITSTREAM_READER_LE 307 return ret | (
get_bits(s, n - 16) << 16);
309 int ret =
get_bits(s, 16) << (n - 16);
323 #ifdef BITSTREAM_READER_LE 368 if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {
374 buffer_size = (bit_size + 7) >> 3;
378 #if !UNCHECKED_BITSTREAM_READER 379 s->size_in_bits_plus8 = bit_size + 8;
398 if (byte_size > INT_MAX / 8)
416 #define GET_VLC(code, name, gb, table, bits, max_depth) \ 419 unsigned int index; \ 421 index = SHOW_UBITS(name, gb, bits); \ 422 code = table[index][0]; \ 423 n = table[index][1]; \ 425 if (max_depth > 1 && n < 0) { \ 426 LAST_SKIP_BITS(name, gb, bits); \ 427 UPDATE_CACHE(name, gb); \ 431 index = SHOW_UBITS(name, gb, nb_bits) + code; \ 432 code = table[index][0]; \ 433 n = table[index][1]; \ 434 if (max_depth > 2 && n < 0) { \ 435 LAST_SKIP_BITS(name, gb, nb_bits); \ 436 UPDATE_CACHE(name, gb); \ 440 index = SHOW_UBITS(name, gb, nb_bits) + code; \ 441 code = table[index][0]; \ 442 n = table[index][1]; \ 445 SKIP_BITS(name, gb, n); \ 448 #define GET_RL_VLC(level, run, name, gb, table, bits, \ 449 max_depth, need_update) \ 452 unsigned int index; \ 454 index = SHOW_UBITS(name, gb, bits); \ 455 level = table[index].level; \ 456 n = table[index].len; \ 458 if (max_depth > 1 && n < 0) { \ 459 SKIP_BITS(name, gb, bits); \ 461 UPDATE_CACHE(name, gb); \ 466 index = SHOW_UBITS(name, gb, nb_bits) + level; \ 467 level = table[index].level; \ 468 n = table[index].len; \ 469 if (max_depth > 2 && n < 0) { \ 470 LAST_SKIP_BITS(name, gb, nb_bits); \ 472 UPDATE_CACHE(name, gb); \ 476 index = SHOW_UBITS(name, gb, nb_bits) + level; \ 477 level = table[index].level; \ 478 n = table[index].len; \ 481 run = table[index].run; \ 482 SKIP_BITS(name, gb, n); \ 494 int bits,
int max_depth)
501 GET_VLC(code,
re, s, table, bits, max_depth);
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static unsigned int show_bits1(GetBitContext *s)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static void skip_bits_long(GetBitContext *s, int n)
static int get_sbits(GetBitContext *s, int n)
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
static int get_bits_count(const GetBitContext *s)
static int get_bits_left(GetBitContext *gb)
static uint64_t get_bits64(GetBitContext *s, int n)
#define UPDATE_CACHE(name, gb)
#define CLOSE_READER(name, gb)
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define LAST_SKIP_BITS(name, gb, num)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define GET_VLC(code, name, gb, table, bits, max_depth)
If the vlc code is invalid and max_depth=1, then no bits will be removed.
#define SHOW_UBITS(name, gb, num)
static int decode210(GetBitContext *gb)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static int get_xbits(GetBitContext *s, int n)
Read MPEG-1 dc-style VLC (sign bit + mantisse with no MSB).
#define OPEN_READER(name, gb)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define GET_CACHE(name, gb)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static av_const int sign_extend(int val, unsigned bits)
#define SHOW_SBITS(name, gb, num)
#define OPEN_READER_NOSIZE(name, gb)
common internal and external API header
const uint8_t * buffer_end
static int decode012(GetBitContext *gb)
static const uint8_t * align_get_bits(GetBitContext *s)
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.