- /* first pass: map codes and compute auxillary table sizes */
- for(i=0;i<nb_codes;i++) {
- GET_DATA(n, bits, i, bits_wrap, bits_size);
- GET_DATA(code, codes, i, codes_wrap, codes_size);
- /* we accept tables with holes */
- if (n <= 0)
- continue;
- if (!symbols)
- symbol = i;
- else
- GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size);
-#if defined(DEBUG_VLC) && 0
- av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code);
-#endif
- /* if code matches the prefix, it is in the table */
- n -= n_prefix;
- if(flags & INIT_VLC_LE)
- code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix)-1);
- else
- code_prefix2= code >> n;
- if (n > 0 && code_prefix2 == code_prefix) {
- if (n <= table_nb_bits) {
- /* no need to add another table */
- j = (code << (table_nb_bits - n)) & (table_size - 1);
- nb = 1 << (table_nb_bits - n);
- for(k=0;k<nb;k++) {
- if(flags & INIT_VLC_LE)
- j = (code >> n_prefix) + (k<<n);
-#ifdef DEBUG_VLC
- av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n",
- j, i, n);
-#endif
- if (table[j][1] /*bits*/ != 0) {
- av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
- return -1;
- }
- table[j][1] = n; //bits
- table[j][0] = symbol;
- j++;
+ /* first pass: map codes and compute auxiliary table sizes */
+ for (i = 0; i < nb_codes; i++) {
+ n = codes[i].bits;
+ code = codes[i].code;
+ symbol = codes[i].symbol;
+ ff_dlog(NULL, "i=%d n=%d code=0x%x\n", i, n, code);
+ if (n <= table_nb_bits) {
+ /* no need to add another table */
+ j = code >> (32 - table_nb_bits);
+ nb = 1 << (table_nb_bits - n);
+ inc = 1;
+ if (flags & INIT_VLC_LE) {
+ j = bitswap_32(code);
+ inc = 1 << n;
+ }
+ for (k = 0; k < nb; k++) {
+ ff_dlog(NULL, "%4x: code=%d n=%d\n", j, i, n);
+ if (table[j][1] /*bits*/ != 0) {
+ av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
+ return AVERROR_INVALIDDATA;