38 0, 0, 0, 0, 1, 1, 1, 1,
39 2, 2, 2, 2, 3, 3, 3, 3,
40 4, 4, 5, 5, 6, 6, 7, 7,
41 8, 9,10,11,12,13,14,15,
42 16,17,18,19,20,21,22,23,
64 int words = length >> 4;
65 int bits = length & 15;
72 for (i = 0; i < words; i++)
87 #define GET_DATA(v, table, i, wrap, size) \ 89 const uint8_t *ptr = (const uint8_t *)table + i * wrap; \ 92 v = *(const uint8_t *)ptr; \ 95 v = *(const uint16_t *)ptr; \ 98 v = *(const uint32_t *)ptr; \ 127 return (uint32_t)
ff_reverse[ x & 0xFF] << 24 |
144 return (sa->
code >> 1) - (sb->code >> 1);
163 int table_size, table_index,
index, code_prefix,
symbol, subtable_bits;
164 int i, j, k, n, nb, inc;
168 table_size = 1 << table_nb_bits;
170 ff_dlog(
NULL,
"new table index=%d size=%d\n", table_index, table_size);
173 table = &vlc->
table[table_index];
175 for (i = 0; i < table_size; i++) {
181 for (i = 0; i < nb_codes; i++) {
183 code = codes[i].
code;
185 ff_dlog(
NULL,
"i=%d n=%d code=0x%x\n", i, n, code);
186 if (n <= table_nb_bits) {
188 j = code >> (32 - table_nb_bits);
189 nb = 1 << (table_nb_bits - n);
195 for (k = 0; k < nb; k++) {
197 if (table[j][1] != 0) {
208 code_prefix = code >> (32 - table_nb_bits);
211 codes[i].
code = code << table_nb_bits;
212 for (k = i+1; k < nb_codes; k++) {
213 n = codes[k].
bits - table_nb_bits;
216 code = codes[k].
code;
217 if (code >> (32 - table_nb_bits) != code_prefix)
220 codes[k].
code = code << table_nb_bits;
221 subtable_bits =
FFMAX(subtable_bits, n);
223 subtable_bits =
FFMIN(subtable_bits, table_nb_bits);
225 table[j][1] = -subtable_bits;
227 j, codes[i].
bits + table_nb_bits);
228 index =
build_table(vlc, subtable_bits, k-i, codes+i, flags);
232 table = &vlc->
table[table_index];
268 const void *
bits,
int bits_wrap,
int bits_size,
269 const void *codes,
int codes_wrap,
int codes_size,
270 const void *symbols,
int symbols_wrap,
int symbols_size,
289 ff_dlog(
NULL,
"build table nb_codes=%d\n", nb_codes);
295 assert(symbols_size <= 2 || !symbols);
297 #define COPY(condition) \ 298 for (i = 0; i < nb_codes; i++) { \ 299 GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size); \ 302 GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size); \ 303 if (flags & INIT_VLC_LE) \ 304 buf[j].code = bitswap_32(buf[j].code); \ 306 buf[j].code <<= 32 - buf[j].bits; \ 308 GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size) \ 313 COPY(buf[j].bits > nb_bits);
316 COPY(buf[j].bits && buf[j].bits <= nb_bits);
319 ret =
build_table(vlc, nb_bits, nb_codes, buf, flags);
326 if ((flags & INIT_VLC_USE_NEW_STATIC) &&
const uint8_t ff_log2_run[41]
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, 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)
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.
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)
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
#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.
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)
Libavcodec external API header.
#define AVERROR_BUG
Bug detected, please report the issue.
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
#define INIT_VLC_USE_NEW_STATIC
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)