Go to the documentation of this file.
   26 #ifndef AVCODEC_GET_BITS_H 
   27 #define AVCODEC_GET_BITS_H 
   52 #ifndef UNCHECKED_BITSTREAM_READER 
   53 #define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER 
   56 #ifndef CACHED_BITSTREAM_READER 
   57 #define CACHED_BITSTREAM_READER 0 
   60 #if CACHED_BITSTREAM_READER 
   65 #ifndef BITSTREAM_READER_LE 
   67 # define BITSTREAM_DEFAULT_BE 
   74 #undef BITSTREAM_DEFAULT_BE 
   78 #define get_bits_count      bits_tell 
   79 #define get_bits_bytesize   bits_bytesize 
   80 #define get_bits_left       bits_left 
   81 #define skip_bits_long      bits_skip 
   82 #define skip_bits           bits_skip 
   83 #define get_bits            bits_read_nz 
   84 #define get_bitsz           bits_read 
   85 #define get_bits_long       bits_read 
   86 #define get_bits1           bits_read_bit 
   87 #define get_bits64          bits_read_64 
   88 #define get_xbits           bits_read_xbits 
   89 #define get_sbits           bits_read_signed_nz 
   90 #define get_sbits_long      bits_read_signed 
   91 #define show_bits           bits_peek 
   92 #define show_bits_long      bits_peek 
   93 #define init_get_bits       bits_init 
   94 #define init_get_bits8      bits_init8 
   95 #define align_get_bits      bits_align 
   96 #define get_vlc2            bits_read_vlc 
   97 #define get_vlc_multi       bits_read_vlc_multi 
   99 #define init_get_bits8_le(s, buffer, byte_size) bits_init8_le((BitstreamContextLE*)s, buffer, byte_size) 
  100 #define get_bits_le(s, n)                       bits_read_le((BitstreamContextLE*)s, n) 
  102 #define show_bits1(s)       bits_peek(s, 1) 
  103 #define skip_bits1(s)       bits_skip(s, 1) 
  105 #define skip_1stop_8data_bits bits_skip_1stop_8data 
  107 #else   // CACHED_BITSTREAM_READER 
  167 #define MIN_CACHE_BITS 25 
  169 #define OPEN_READER_NOSIZE(name, gb)            \ 
  170     unsigned int name ## _index = (gb)->index;  \ 
  171     av_unused unsigned int name ## _cache 
  173 #if UNCHECKED_BITSTREAM_READER 
  174 #define OPEN_READER(name, gb) OPEN_READER_NOSIZE(name, gb) 
  176 #define BITS_AVAILABLE(name, gb) 1 
  178 #define OPEN_READER(name, gb)                   \ 
  179     OPEN_READER_NOSIZE(name, gb);               \ 
  180     unsigned int name ## _size_plus8 = (gb)->size_in_bits_plus8 
  182 #define BITS_AVAILABLE(name, gb) name ## _index < name ## _size_plus8 
  185 #define CLOSE_READER(name, gb) (gb)->index = name ## _index 
  187 #define UPDATE_CACHE_BE_EXT(name, gb, bits, dst_bits) name ## _cache = \ 
  188     AV_RB ## bits((gb)->buffer + (name ## _index >> 3)) << (name ## _index & 7) >> (bits - dst_bits) 
  190 #define UPDATE_CACHE_LE_EXT(name, gb, bits, dst_bits) name ## _cache = \ 
  191     (uint ## dst_bits ## _t)(AV_RL ## bits((gb)->buffer + (name ## _index >> 3)) >> (name ## _index & 7)) 
  194 # define UPDATE_CACHE_LE_32(name, gb) UPDATE_CACHE_LE_EXT(name, (gb), 64, 32) 
  195 # define UPDATE_CACHE_BE_32(name, gb) UPDATE_CACHE_BE_EXT(name, (gb), 64, 32) 
  197 # define UPDATE_CACHE_LE(name, gb) UPDATE_CACHE_LE_EXT(name, (gb), 32, 32) 
  198 # define UPDATE_CACHE_BE(name, gb) UPDATE_CACHE_BE_EXT(name, (gb), 32, 32) 
  200 #ifdef BITSTREAM_READER_LE 
  202 # define UPDATE_CACHE(name, gb) UPDATE_CACHE_LE(name, gb) 
  203 # define UPDATE_CACHE_32(name, gb) UPDATE_CACHE_LE_32(name, (gb)) 
  205 # define SKIP_CACHE(name, gb, num) name ## _cache >>= (num) 
  209 # define UPDATE_CACHE(name, gb) UPDATE_CACHE_BE(name, gb) 
  210 # define UPDATE_CACHE_32(name, gb) UPDATE_CACHE_BE_32(name, (gb)) 
  212 # define SKIP_CACHE(name, gb, num) name ## _cache <<= (num) 
  216 #if UNCHECKED_BITSTREAM_READER 
  217 #   define SKIP_COUNTER(name, gb, num) name ## _index += (num) 
  219 #   define SKIP_COUNTER(name, gb, num) \ 
  220     name ## _index = FFMIN(name ## _size_plus8, name ## _index + (num)) 
  223 #define BITS_LEFT(name, gb) ((int)((gb)->size_in_bits - name ## _index)) 
  225 #define SKIP_BITS(name, gb, num)                \ 
  227         SKIP_CACHE(name, gb, num);              \ 
  228         SKIP_COUNTER(name, gb, num);            \ 
  231 #define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) 
  233 #define SHOW_UBITS_LE(name, gb, num) zero_extend(name ## _cache, num) 
  234 #define SHOW_SBITS_LE(name, gb, num) sign_extend(name ## _cache, num) 
  236 #define SHOW_UBITS_BE(name, gb, num) NEG_USR32(name ## _cache, num) 
  237 #define SHOW_SBITS_BE(name, gb, num) NEG_SSR32(name ## _cache, num) 
  239 #ifdef BITSTREAM_READER_LE 
  240 #   define SHOW_UBITS(name, gb, num) SHOW_UBITS_LE(name, gb, num) 
  241 #   define SHOW_SBITS(name, gb, num) SHOW_SBITS_LE(name, gb, num) 
  243 #   define SHOW_UBITS(name, gb, num) SHOW_UBITS_BE(name, gb, num) 
  244 #   define SHOW_SBITS(name, gb, num) SHOW_SBITS_BE(name, gb, num) 
  247 #define GET_CACHE(name, gb) ((uint32_t) name ## _cache) 
  266     return (
s->size_in_bits + (round_up ? 7 : 0)) >> 3;
 
  278 #if UNCHECKED_BITSTREAM_READER 
  281     s->index += 
av_clip(n, -
s->index, 
s->size_in_bits_plus8 - 
s->index);
 
  301     return (
NEG_USR32(sign ^ cache, n) ^ sign) - sign;
 
  315     return (
zero_extend(sign ^ cache, n) ^ sign) - sign;
 
  335     register unsigned int tmp;
 
  371     register unsigned int tmp;
 
  388     unsigned int index = 
s->index;
 
  390 #ifdef BITSTREAM_READER_LE 
  397 #if !UNCHECKED_BITSTREAM_READER 
  398     if (
s->index < 
s->size_in_bits_plus8)
 
  437 #ifdef BITSTREAM_READER_LE 
  456 #ifdef BITSTREAM_READER_LE 
  524     s->size_in_bits       = bit_size;
 
  525     s->size_in_bits_plus8 = bit_size + 8;
 
  542     if (byte_size > INT_MAX / 8 || byte_size < 0)
 
  550     if (byte_size > INT_MAX / 8 || byte_size < 0)
 
  560     return s->buffer + (
s->index >> 3);
 
  568 #define GET_VLC(code, name, gb, table, bits, max_depth)         \ 
  571         unsigned int index;                                     \ 
  573         index = SHOW_UBITS(name, gb, bits);                     \ 
  574         code  = table[index].sym;                               \ 
  575         n     = table[index].len;                               \ 
  577         if (max_depth > 1 && n < 0) {                           \ 
  578             LAST_SKIP_BITS(name, gb, bits);                     \ 
  579             UPDATE_CACHE(name, gb);                             \ 
  583             index = SHOW_UBITS(name, gb, nb_bits) + code;       \ 
  584             code  = table[index].sym;                           \ 
  585             n     = table[index].len;                           \ 
  586             if (max_depth > 2 && n < 0) {                       \ 
  587                 LAST_SKIP_BITS(name, gb, nb_bits);              \ 
  588                 UPDATE_CACHE(name, gb);                         \ 
  592                 index = SHOW_UBITS(name, gb, nb_bits) + code;   \ 
  593                 code  = table[index].sym;                       \ 
  594                 n     = table[index].len;                       \ 
  597         SKIP_BITS(name, gb, n);                                 \ 
  600 #define GET_RL_VLC(level, run, name, gb, table, bits,  \ 
  601                    max_depth, need_update)                      \ 
  604         unsigned int index;                                     \ 
  606         index = SHOW_UBITS(name, gb, bits);                     \ 
  607         level = table[index].level;                             \ 
  608         n     = table[index].len8;                              \ 
  610         if (max_depth > 1 && n < 0) {                           \ 
  611             SKIP_BITS(name, gb, bits);                          \ 
  613                 UPDATE_CACHE(name, gb);                         \ 
  618             index = SHOW_UBITS(name, gb, nb_bits) + level;      \ 
  619             level = table[index].level;                         \ 
  620             n     = table[index].len8;                          \ 
  621             if (max_depth > 2 && n < 0) {                       \ 
  622                 LAST_SKIP_BITS(name, gb, nb_bits);              \ 
  624                     UPDATE_CACHE(name, gb);                     \ 
  628                 index = SHOW_UBITS(name, gb, nb_bits) + level;  \ 
  629                 level = table[index].level;                     \ 
  630                 n     = table[index].len8;                      \ 
  633         run = table[index].run;                                 \ 
  634         SKIP_BITS(name, gb, n);                                 \ 
  647                                      int bits, 
int max_depth)
 
  664                                 const int bits, 
const int max_depth,
 
  665                                 const int symbols_size)
 
  708 #endif // CACHED_BITSTREAM_READER 
  
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static unsigned int show_bits1(GetBitContext *s)
static int get_bits_left(GetBitContext *gb)
#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.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_count(const GetBitContext *s)
static const uint16_t table[]
static av_const unsigned zero_extend(unsigned val, unsigned bits)
#define UPDATE_CACHE(name, gb)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define OPEN_READER_NOSIZE(name, gb)
#define GET_CACHE(name, gb)
static void skip_bits(GetBitContext *s, int n)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int get_vlc_multi(GetBitContext *s, uint8_t *dst, const VLC_MULTI_ELEM *const Jtable, const VLCElem *const table, const int bits, const int max_depth, const int symbols_size)
static int64_t get_sbits64(GetBitContext *s, int n)
Read 0-64 bits as a signed integer.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
#define CLOSE_READER(name, gb)
#define SHOW_SBITS(name, gb, num)
static av_const int64_t sign_extend64(int64_t val, unsigned bits)
static unsigned int get_bits_le(GetBitContext *s, int n)
static int get_sbits(GetBitContext *s, int n)
static int decode012(GetBitContext *gb)
#define SHOW_UBITS_LE(name, gb, num)
and forward the result(frame or status change) to the corresponding input. If nothing is possible
static unsigned int get_bits1(GetBitContext *s)
#define LAST_SKIP_BITS(name, gb, num)
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static int get_bits_bytesize(const GetBitContext *s, int round_up)
Get the size of the GetBitContext's buffer in bytes.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define OPEN_READER(name, gb)
static int get_xbits(GetBitContext *s, int n)
Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
static void skip_bits1(GetBitContext *s)
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
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 show_bits(GetBitContext *s, int n)
Show 1-25 bits.
#define av_builtin_constant_p
static int get_xbits_le(GetBitContext *s, int n)
static const uint8_t * align_get_bits(GetBitContext *s)
#define AV_INPUT_BUFFER_PADDING_SIZE
static int skip_1stop_8data_bits(GetBitContext *gb)
#define SHOW_UBITS(name, gb, num)
#define UPDATE_CACHE_LE(name, gb)
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
static av_const int sign_extend(int val, unsigned bits)
static int decode210(GetBitContext *gb)
#define UPDATE_CACHE_32(name, gb)
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
static int init_get_bits8_le(GetBitContext *s, const uint8_t *buffer, int byte_size)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.