37 0, 0, 0, 0, 1, 1, 1, 1,
38 2, 2, 2, 2, 3, 3, 3, 3,
39 4, 4, 5, 5, 6, 6, 7, 7,
40 8, 9,10,11,12,13,14,15,
41 16,17,18,19,20,21,22,23,
63 int words = length >> 4;
64 int bits = length & 15;
71 for (i = 0; i < words; i++)
86 #define GET_DATA(v, table, i, wrap, size) \
88 const uint8_t *ptr = (const uint8_t *)table + i * wrap; \
91 v = *(const uint8_t *)ptr; \
94 v = *(const uint16_t *)ptr; \
97 v = *(const uint32_t *)ptr; \
126 return (uint32_t)
ff_reverse[ x & 0xFF] << 24 |
143 return (sa->
code >> 1) - (sb->code >> 1);
162 int table_size, table_index,
index, code_prefix, symbol, subtable_bits;
163 int i, j, k, n, nb, inc;
167 table_size = 1 << table_nb_bits;
169 av_dlog(
NULL,
"new table index=%d size=%d\n", table_index, table_size);
172 table = &vlc->
table[table_index];
174 for (i = 0; i < table_size; i++) {
180 for (i = 0; i < nb_codes; i++) {
182 code = codes[i].
code;
184 av_dlog(
NULL,
"i=%d n=%d code=0x%x\n", i, n, code);
185 if (n <= table_nb_bits) {
187 j = code >> (32 - table_nb_bits);
188 nb = 1 << (table_nb_bits - n);
194 for (k = 0; k < nb; k++) {
196 if (table[j][1] != 0) {
201 table[j][0] = symbol;
207 code_prefix = code >> (32 - table_nb_bits);
210 codes[i].
code = code << table_nb_bits;
211 for (k = i+1; k < nb_codes; k++) {
212 n = codes[k].
bits - table_nb_bits;
215 code = codes[k].
code;
216 if (code >> (32 - table_nb_bits) != code_prefix)
219 codes[k].
code = code << table_nb_bits;
220 subtable_bits =
FFMAX(subtable_bits, n);
222 subtable_bits =
FFMIN(subtable_bits, table_nb_bits);
224 table[j][1] = -subtable_bits;
226 j, codes[i].
bits + table_nb_bits);
227 index =
build_table(vlc, subtable_bits, k-i, codes+i, flags);
231 table = &vlc->
table[table_index];
267 const void *
bits,
int bits_wrap,
int bits_size,
268 const void *codes,
int codes_wrap,
int codes_size,
269 const void *symbols,
int symbols_wrap,
int symbols_size,
288 av_dlog(
NULL,
"build table nb_codes=%d\n", nb_codes);
294 assert(symbols_size <= 2 || !symbols);
296 #define COPY(condition) \
297 for (i = 0; i < nb_codes; i++) { \
298 GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size); \
301 GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size); \
302 if (flags & INIT_VLC_LE) \
303 buf[j].code = bitswap_32(buf[j].code); \
305 buf[j].code <<= 32 - buf[j].bits; \
307 GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size) \
312 COPY(buf[j].bits > nb_bits);
315 COPY(buf[j].bits && buf[j].bits <= nb_bits);
318 ret =
build_table(vlc, nb_bits, nb_codes, buf, flags);
325 if ((flags & INIT_VLC_USE_NEW_STATIC) &&
const uint8_t ff_log2_run[41]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
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 *ptr)
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)
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
bitstream reader API header.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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...
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
Libavcodec external API header.
static int put_bits_count(PutBitContext *s)
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int compare_vlcspec(const void *a, const void *b)
#define INIT_VLC_USE_NEW_STATIC
#define AVERROR_BUG
Bug detected, please report the issue.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
VLC_TYPE(* table)[2]
code, bits
void avpriv_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
const uint8_t ff_reverse[256]
void ff_free_vlc(VLC *vlc)
static int alloc_table(VLC *vlc, int size, int use_static)