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; \
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;
168 if (table_nb_bits > 30)
171 av_dlog(NULL,
"new table index=%d size=%d\n", table_index, table_size);
176 for (i = 0; i < table_size; i++) {
182 for (i = 0; i < nb_codes; i++) {
184 code = codes[i].
code;
186 av_dlog(NULL,
"i=%d n=%d code=0x%x\n", i, n, code);
187 if (n <= table_nb_bits) {
189 j = code >> (32 - table_nb_bits);
190 nb = 1 << (table_nb_bits -
n);
196 for (k = 0; k < nb; k++) {
197 av_dlog(NULL,
"%4x: code=%d n=%d\n", j, i, n);
198 if (
table[j][1] != 0) {
203 table[j][0] = symbol;
209 code_prefix = code >> (32 - table_nb_bits);
212 codes[i].
code = code << table_nb_bits;
213 for (k = i+1; k < nb_codes; k++) {
214 n = codes[k].
bits - table_nb_bits;
217 code = codes[k].
code;
218 if (code >> (32 - table_nb_bits) != code_prefix)
221 codes[k].
code = code << table_nb_bits;
222 subtable_bits =
FFMAX(subtable_bits, n);
224 subtable_bits =
FFMIN(subtable_bits, table_nb_bits);
226 table[j][1] = -subtable_bits;
227 av_dlog(NULL,
"%4x: n=%d (subtable)\n",
228 j, codes[i].
bits + table_nb_bits);
229 index =
build_table(vlc, subtable_bits, k-i, codes+i, flags);
270 const void *
bits,
int bits_wrap,
int bits_size,
271 const void *codes,
int codes_wrap,
int codes_size,
272 const void *symbols,
int symbols_wrap,
int symbols_size,
283 if (state == vlc + 1) {
304 #define COPY(condition)\
305 for (i = 0; i < nb_codes; i++) { \
306 GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size); \
309 if (buf[j].bits > 3*nb_bits || buf[j].bits>32) { \
310 av_log(NULL, AV_LOG_ERROR, "Too long VLC (%d) in init_vlc\n", buf[j].bits);\
311 if (!(flags & INIT_VLC_USE_NEW_STATIC)) \
315 GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size); \
316 if (buf[j].code >= (1LL<<buf[j].bits)) { \
317 av_log(NULL, AV_LOG_ERROR, "Invalid code in init_vlc\n"); \
318 if (!(flags & INIT_VLC_USE_NEW_STATIC)) \
322 if (flags & INIT_VLC_LE) \
323 buf[j].code = bitswap_32(buf[j].code); \
325 buf[j].code <<= 32 - buf[j].bits; \
327 GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size) \
332 COPY(buf[j].bits > nb_bits);
335 COPY(buf[j].bits && buf[j].bits <= nb_bits);
338 ret =
build_table(vlc, nb_bits, nb_codes, buf, flags);
340 if (flags & INIT_VLC_USE_NEW_STATIC) {