36 0, 0, 0, 0, 1, 1, 1, 1,
37 2, 2, 2, 2, 3, 3, 3, 3,
38 4, 4, 5, 5, 6, 6, 7, 7,
39 8, 9,10,11,12,13,14,15,
40 16,17,18,19,20,21,22,23,
82 #define GET_DATA(v, table, i, wrap, size) \
84 const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
87 v = *(const uint8_t *)ptr;\
90 v = *(const uint16_t *)ptr;\
93 v = *(const uint32_t *)ptr;\
134 return (sa->
code >> 1) - (sb->code >> 1);
154 int table_size, table_index,
index, code_prefix, symbol, subtable_bits;
155 int i, j, k, n, nb, inc;
159 table_size = 1 << table_nb_bits;
161 av_dlog(
NULL,
"new table index=%d size=%d\n", table_index, table_size);
164 table = &vlc->
table[table_index];
166 for (i = 0; i < table_size; i++) {
172 for (i = 0; i < nb_codes; i++) {
174 code = codes[i].
code;
176 av_dlog(
NULL,
"i=%d n=%d code=0x%x\n", i, n, code);
177 if (n <= table_nb_bits) {
179 j = code >> (32 - table_nb_bits);
180 nb = 1 << (table_nb_bits - n);
186 for (k = 0; k < nb; k++) {
188 if (table[j][1] != 0) {
193 table[j][0] = symbol;
199 code_prefix = code >> (32 - table_nb_bits);
202 codes[i].
code = code << table_nb_bits;
203 for (k = i+1; k < nb_codes; k++) {
204 n = codes[k].
bits - table_nb_bits;
207 code = codes[k].
code;
208 if (code >> (32 - table_nb_bits) != code_prefix)
211 codes[k].
code = code << table_nb_bits;
212 subtable_bits =
FFMAX(subtable_bits, n);
214 subtable_bits =
FFMIN(subtable_bits, table_nb_bits);
216 table[j][1] = -subtable_bits;
218 j, codes[i].
bits + table_nb_bits);
219 index =
build_table(vlc, subtable_bits, k-i, codes+i, flags);
223 table = &vlc->
table[table_index];
259 const void *
bits,
int bits_wrap,
int bits_size,
260 const void *codes,
int codes_wrap,
int codes_size,
261 const void *symbols,
int symbols_wrap,
int symbols_size,
280 av_dlog(
NULL,
"build table nb_codes=%d\n", nb_codes);
284 assert(symbols_size <= 2 || !symbols);
286 #define COPY(condition)\
287 for (i = 0; i < nb_codes; i++) {\
288 GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size);\
291 GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size);\
292 if (flags & INIT_VLC_LE)\
293 buf[j].code = bitswap_32(buf[j].code);\
295 buf[j].code <<= 32 - buf[j].bits;\
297 GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size)\
302 COPY(buf[j].bits > nb_bits);
305 COPY(buf[j].bits && buf[j].bits <= nb_bits);
308 ret =
build_table(vlc, nb_bits, nb_codes, buf, flags);
const uint8_t av_reverse[256]
const uint8_t ff_log2_run[41]
AV_WL32 AV_WL24 AV_WL16 AV_WB32 AV_WB24 AV_RB16
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, VLCcode *codes, int flags)
Build VLC decoding tables suitable for use with get_vlc().
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int ff_init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
static av_always_inline uint32_t bitswap_32(uint32_t x)
bitstream reader API header.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
uint32_t code
codeword, with the first bit-to-be-read in the msb (even if intended for a little-endian bitstream re...
void av_log(void *avcl, int level, const char *fmt,...)
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
static int put_bits_count(PutBitContext *s)
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
static int compare_vlcspec(const void *a, const void *b)
#define INIT_VLC_USE_NEW_STATIC
#define av_dlog(pctx,...)
av_dlog macros Useful to print debug messages that shouldn't get compiled in normally.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
VLC_TYPE(* table)[2]
code, bits
void ff_free_vlc(VLC *vlc)
static int alloc_table(VLC *vlc, int size, int use_static)