39 0, 0, 0, 0, 1, 1, 1, 1,
40 2, 2, 2, 2, 3, 3, 3, 3,
41 4, 4, 5, 5, 6, 6, 7, 7,
42 8, 9,10,11,12,13,14,15,
43 16,17,18,19,20,21,22,23,
65 int words = length >> 4;
66 int bits = length & 15;
73 for (i = 0; i < words; i++)
88 #define GET_DATA(v, table, i, wrap, size) \
90 const uint8_t *ptr = (const uint8_t *)table + i * wrap; \
93 v = *(const uint8_t *)ptr; \
96 v = *(const uint16_t *)ptr; \
99 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;
169 if (table_nb_bits > 30)
172 av_dlog(
NULL,
"new table index=%d size=%d\n", table_index, table_size);
178 for (i = 0; i < nb_codes; i++) {
180 code = codes[i].
code;
182 av_dlog(
NULL,
"i=%d n=%d code=0x%x\n", i, n, code);
183 if (n <= table_nb_bits) {
185 j = code >> (32 - table_nb_bits);
186 nb = 1 << (table_nb_bits -
n);
192 for (k = 0; k < nb; k++) {
195 if (bits != 0 && bits != n) {
200 table[j][0] = symbol;
206 code_prefix = code >> (32 - table_nb_bits);
209 codes[i].
code = code << table_nb_bits;
210 for (k = i+1; k < nb_codes; k++) {
211 n = codes[k].
bits - table_nb_bits;
214 code = codes[k].
code;
215 if (code >> (32 - table_nb_bits) != code_prefix)
218 codes[k].
code = code << table_nb_bits;
219 subtable_bits =
FFMAX(subtable_bits, n);
221 subtable_bits =
FFMIN(subtable_bits, table_nb_bits);
223 table[j][1] = -subtable_bits;
225 j, codes[i].
bits + table_nb_bits);
226 index =
build_table(vlc, subtable_bits, k-i, codes+i, flags);
236 for (i = 0; i < table_size; i++) {
237 if (
table[i][1] == 0)
272 const void *
bits,
int bits_wrap,
int bits_size,
273 const void *codes,
int codes_wrap,
int codes_size,
274 const void *symbols,
int symbols_wrap,
int symbols_size,
303 #define COPY(condition)\
304 for (i = 0; i < nb_codes; i++) { \
305 GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size); \
308 if (buf[j].bits > 3*nb_bits || buf[j].bits>32) { \
309 av_log(NULL, AV_LOG_ERROR, "Too long VLC (%d) in init_vlc\n", buf[j].bits);\
310 if (!(flags & INIT_VLC_USE_NEW_STATIC)) \
314 GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size); \
315 if (buf[j].code >= (1LL<<buf[j].bits)) { \
316 av_log(NULL, AV_LOG_ERROR, "Invalid code in init_vlc\n"); \
317 if (!(flags & INIT_VLC_USE_NEW_STATIC)) \
321 if (flags & INIT_VLC_LE) \
322 buf[j].code = bitswap_32(buf[j].code); \
324 buf[j].code <<= 32 - buf[j].bits; \
326 GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size) \
331 COPY(buf[j].bits > nb_bits);
334 COPY(buf[j].bits && buf[j].bits <= nb_bits);
337 ret =
build_table(vlc, nb_bits, nb_codes, buf, flags);
339 if (flags & INIT_VLC_USE_NEW_STATIC) {