27 #ifndef AVCODEC_GET_BITS_H 28 #define AVCODEC_GET_BITS_H 53 #ifndef UNCHECKED_BITSTREAM_READER 54 #define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER 57 #ifndef CACHED_BITSTREAM_READER 58 #define CACHED_BITSTREAM_READER 0 63 #if CACHED_BITSTREAM_READER 123 #if CACHED_BITSTREAM_READER 124 # define MIN_CACHE_BITS 64 125 #elif defined LONG_BITSTREAM_READER 126 # define MIN_CACHE_BITS 32 128 # define MIN_CACHE_BITS 25 131 #if !CACHED_BITSTREAM_READER 133 #define OPEN_READER_NOSIZE(name, gb) \ 134 unsigned int name ## _index = (gb)->index; \ 135 unsigned int av_unused name ## _cache 137 #if UNCHECKED_BITSTREAM_READER 138 #define OPEN_READER(name, gb) OPEN_READER_NOSIZE(name, gb) 140 #define BITS_AVAILABLE(name, gb) 1 142 #define OPEN_READER(name, gb) \ 143 OPEN_READER_NOSIZE(name, gb); \ 144 unsigned int name ## _size_plus8 = (gb)->size_in_bits_plus8 146 #define BITS_AVAILABLE(name, gb) name ## _index < name ## _size_plus8 149 #define CLOSE_READER(name, gb) (gb)->index = name ## _index 151 # ifdef LONG_BITSTREAM_READER 153 # define UPDATE_CACHE_LE(name, gb) name ## _cache = \ 154 AV_RL64((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7) 156 # define UPDATE_CACHE_BE(name, gb) name ## _cache = \ 157 AV_RB64((gb)->buffer + (name ## _index >> 3)) >> (32 - (name ## _index & 7)) 161 # define UPDATE_CACHE_LE(name, gb) name ## _cache = \ 162 AV_RL32((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7) 164 # define UPDATE_CACHE_BE(name, gb) name ## _cache = \ 165 AV_RB32((gb)->buffer + (name ## _index >> 3)) << (name ## _index & 7) 170 #ifdef BITSTREAM_READER_LE 172 # define UPDATE_CACHE(name, gb) UPDATE_CACHE_LE(name, gb) 174 # define SKIP_CACHE(name, gb, num) name ## _cache >>= (num) 178 # define UPDATE_CACHE(name, gb) UPDATE_CACHE_BE(name, gb) 180 # define SKIP_CACHE(name, gb, num) name ## _cache <<= (num) 184 #if UNCHECKED_BITSTREAM_READER 185 # define SKIP_COUNTER(name, gb, num) name ## _index += (num) 187 # define SKIP_COUNTER(name, gb, num) \ 188 name ## _index = FFMIN(name ## _size_plus8, name ## _index + (num)) 191 #define BITS_LEFT(name, gb) ((int)((gb)->size_in_bits - name ## _index)) 193 #define SKIP_BITS(name, gb, num) \ 195 SKIP_CACHE(name, gb, num); \ 196 SKIP_COUNTER(name, gb, num); \ 199 #define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) 201 #define SHOW_UBITS_LE(name, gb, num) zero_extend(name ## _cache, num) 202 #define SHOW_SBITS_LE(name, gb, num) sign_extend(name ## _cache, num) 204 #define SHOW_UBITS_BE(name, gb, num) NEG_USR32(name ## _cache, num) 205 #define SHOW_SBITS_BE(name, gb, num) NEG_SSR32(name ## _cache, num) 207 #ifdef BITSTREAM_READER_LE 208 # define SHOW_UBITS(name, gb, num) SHOW_UBITS_LE(name, gb, num) 209 # define SHOW_SBITS(name, gb, num) SHOW_SBITS_LE(name, gb, num) 211 # define SHOW_UBITS(name, gb, num) SHOW_UBITS_BE(name, gb, num) 212 # define SHOW_SBITS(name, gb, num) SHOW_SBITS_BE(name, gb, num) 215 #define GET_CACHE(name, gb) ((uint32_t) name ## _cache) 221 #if CACHED_BITSTREAM_READER 222 return s->
index - s->bits_left;
228 #if CACHED_BITSTREAM_READER 231 #if !UNCHECKED_BITSTREAM_READER 239 s->cache = s->cache | (uint64_t)
AV_RB32(s->
buffer + (s->
index >> 3)) << (32 - s->bits_left);
246 #if !UNCHECKED_BITSTREAM_READER 259 static inline uint64_t get_val(
GetBitContext *s,
unsigned n,
int is_le)
264 ret = s->cache & ((UINT64_C(1) << n) - 1);
267 ret = s->cache >> (64 - n);
274 static inline unsigned show_val(
const GetBitContext *s,
unsigned n)
276 #ifdef BITSTREAM_READER_LE 277 return s->cache & ((UINT64_C(1) << n) - 1);
279 return s->cache >> (64 - n);
293 #if CACHED_BITSTREAM_READER 296 #if UNCHECKED_BITSTREAM_READER 304 #if CACHED_BITSTREAM_READER 305 static inline void skip_remaining(
GetBitContext *s,
unsigned n)
307 #ifdef BITSTREAM_READER_LE 323 #if CACHED_BITSTREAM_READER 325 int sign = ~cache >> 31;
326 skip_remaining(s, n);
328 return ((((uint32_t)(sign ^ cache)) >> (32 - n)) ^ sign) - sign;
339 return (
NEG_USR32(sign ^ cache, n) ^ sign) - sign;
343 #if !CACHED_BITSTREAM_READER 355 return (
zero_extend(sign ^ cache, n) ^ sign) - sign;
362 #if CACHED_BITSTREAM_READER 381 register unsigned int tmp;
382 #if CACHED_BITSTREAM_READER 385 if (n > s->bits_left) {
386 #ifdef BITSTREAM_READER_LE 391 if (s->bits_left < 32)
395 #ifdef BITSTREAM_READER_LE 396 tmp = get_val(s, n, 1);
398 tmp = get_val(s, n, 0);
422 #if CACHED_BITSTREAM_READER 424 if (n > s->bits_left) {
426 if (s->bits_left < 32)
430 return get_val(s, n, 1);
448 register unsigned int tmp;
449 #if CACHED_BITSTREAM_READER 450 if (n > s->bits_left)
451 #ifdef BITSTREAM_READER_LE 457 tmp = show_val(s, n);
469 #if CACHED_BITSTREAM_READER 470 if (n < s->bits_left)
471 skip_remaining(s, n);
478 unsigned skip = (n / 8) * 8;
483 #ifdef BITSTREAM_READER_LE 489 skip_remaining(s, n);
500 #if CACHED_BITSTREAM_READER 502 #ifdef BITSTREAM_READER_LE 508 #ifdef BITSTREAM_READER_LE 509 return get_val(s, 1, 1);
511 return get_val(s, 1, 0);
516 #ifdef BITSTREAM_READER_LE 517 result >>= index & 7;
520 result <<= index & 7;
523 #if !UNCHECKED_BITSTREAM_READER 551 #if CACHED_BITSTREAM_READER 558 #ifdef BITSTREAM_READER_LE 560 return ret | (
get_bits(s, n - 16) << 16);
562 unsigned ret =
get_bits(s, 16) << (n - 16);
577 #ifdef BITSTREAM_READER_LE 623 int bit_size,
int is_le)
634 buffer_size = (bit_size + 7) >> 3;
642 #if CACHED_BITSTREAM_READER 662 #ifdef BITSTREAM_READER_LE 680 if (byte_size > INT_MAX / 8 || byte_size < 0)
688 if (byte_size > INT_MAX / 8 || byte_size < 0)
706 #define GET_VLC(code, name, gb, table, bits, max_depth) \ 709 unsigned int index; \ 711 index = SHOW_UBITS(name, gb, bits); \ 712 code = table[index][0]; \ 713 n = table[index][1]; \ 715 if (max_depth > 1 && n < 0) { \ 716 LAST_SKIP_BITS(name, gb, bits); \ 717 UPDATE_CACHE(name, gb); \ 721 index = SHOW_UBITS(name, gb, nb_bits) + code; \ 722 code = table[index][0]; \ 723 n = table[index][1]; \ 724 if (max_depth > 2 && n < 0) { \ 725 LAST_SKIP_BITS(name, gb, nb_bits); \ 726 UPDATE_CACHE(name, gb); \ 730 index = SHOW_UBITS(name, gb, nb_bits) + code; \ 731 code = table[index][0]; \ 732 n = table[index][1]; \ 735 SKIP_BITS(name, gb, n); \ 738 #define GET_RL_VLC(level, run, name, gb, table, bits, \ 739 max_depth, need_update) \ 742 unsigned int index; \ 744 index = SHOW_UBITS(name, gb, bits); \ 745 level = table[index].level; \ 746 n = table[index].len; \ 748 if (max_depth > 1 && n < 0) { \ 749 SKIP_BITS(name, gb, bits); \ 751 UPDATE_CACHE(name, gb); \ 756 index = SHOW_UBITS(name, gb, nb_bits) + level; \ 757 level = table[index].level; \ 758 n = table[index].len; \ 759 if (max_depth > 2 && n < 0) { \ 760 LAST_SKIP_BITS(name, gb, nb_bits); \ 762 UPDATE_CACHE(name, gb); \ 766 index = SHOW_UBITS(name, gb, nb_bits) + level; \ 767 level = table[index].level; \ 768 n = table[index].len; \ 771 run = table[index].run; \ 772 SKIP_BITS(name, gb, n); \ 785 return table[idx][0];
798 int bits,
int max_depth)
800 #if CACHED_BITSTREAM_READER 803 int code =
table[idx][0];
804 int n =
table[idx][1];
806 if (max_depth > 1 && n < 0) {
807 skip_remaining(s, bits);
809 if (max_depth > 2 && n < 0) {
810 skip_remaining(s, nb_bits);
814 skip_remaining(s, n);
static int get_xbits_le(GetBitContext *s, int n)
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)
Skips the specified number of bits.
static int set_idx(GetBitContext *s, int code, int *n, int *nb_bits, VLC_TYPE(*table)[2])
static int check_marker(void *logctx, GetBitContext *s, const char *msg)
static av_const unsigned zero_extend(unsigned val, unsigned bits)
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.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
static int get_bits_count(const GetBitContext *s)
#define SHOW_UBITS_LE(name, gb, num)
static int init_get_bits_xe(GetBitContext *s, const uint8_t *buffer, int bit_size, int is_le)
static const uint16_t table[]
static int get_bits_left(GetBitContext *gb)
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
#define UPDATE_CACHE(name, gb)
simple assert() macros that are a bit more flexible than ISO C assert().
#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)
#define AV_LOG_INFO
Standard information.
Libavcodec external API header.
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 + mantissa 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)
#define UPDATE_CACHE_LE(name, gb)
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)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
static unsigned int get_bits_le(GetBitContext *s, int n)
#define SHOW_SBITS(name, gb, num)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_RB64
#define OPEN_READER_NOSIZE(name, gb)
common internal and external API header
#define bit(string, value)
const uint8_t * buffer_end
static int init_get_bits8_le(GetBitContext *s, const uint8_t *buffer, int byte_size)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static int decode012(GetBitContext *gb)
static const uint8_t * align_get_bits(GetBitContext *s)
and forward the result(frame or status change) to the corresponding input.If nothing is possible
static int skip_1stop_8data_bits(GetBitContext *gb)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.