Revision cceabc86

View differences:

libavcodec/common.c
286 286
                return -1;
287 287
            /* note: realloc has been done, so reload tables */
288 288
            table = &vlc->table[table_index];
289
            table[i][0] = index; //code
289
            table[i][0] = index - table_index; //code
290 290
        }
291 291
    }
292 292
    return table_index;
libavcodec/common.h
732 732
             const void *codes, int codes_wrap, int codes_size);
733 733
void free_vlc(VLC *vlc);
734 734

  
735
//note table will be trashed (pointer increased)
736
#define GET_VLC(code, name, gb, table, bits, max_depth)\
737
{\
738
    int n, index, nb_bits;\
739
\
740
    index= SHOW_UBITS(name, gb, bits);\
741
    code = table[index][0];\
742
    n    = table[index][1];\
743
\
744
    if(max_depth > 1 && n < 0){\
745
        LAST_SKIP_BITS(name, gb, bits)\
746
        UPDATE_CACHE(name, gb)\
747
\
748
        nb_bits = -n;\
749
        table += code;\
750
\
751
        index= SHOW_UBITS(name, gb, nb_bits);\
752
        code = table[index][0];\
753
        n    = table[index][1];\
754
        if(max_depth > 2 && n < 0){\
755
            LAST_SKIP_BITS(name, gb, nb_bits)\
756
            UPDATE_CACHE(name, gb)\
757
\
758
            nb_bits = -n;\
759
            table += code;\
760
\
761
            index= SHOW_UBITS(name, gb, nb_bits);\
762
            code = table[index][0];\
763
            n    = table[index][1];\
764
        }\
765
    }\
766
    SKIP_BITS(name, gb, n)\
767
}
768

  
735 769
static inline int get_vlc(GetBitContext *s, VLC *vlc)
736 770
{
737
    int code, n, nb_bits, index;
738
    VLC_TYPE (*table)[2];
771
    int code;
772
    VLC_TYPE (*table)[2]= vlc->table;
773
    
739 774
    OPEN_READER(re, s)
740

  
741 775
    UPDATE_CACHE(re, s)
742 776

  
743
    nb_bits = vlc->bits;
744
    table = vlc->table;
745

  
746
#ifdef FAST_GET_FIRST_VLC
747
    index= SHOW_UBITS(re, s, nb_bits);
748
    code = table[index][0];
749
    n = table[index][1];
750
    if (n > 0) {
751
        /* most common case (90%)*/
752
        LAST_SKIP_BITS(re, s, n)
753
        CLOSE_READER(re, s)
754
        return code;
755
    } else if (n == 0) {
756
        return -1;
757
    } else {
758
        LAST_SKIP_BITS(re, s, nb_bits)
759
        UPDATE_CACHE(re, s) //this isnt needed but its faster if its here
777
    GET_VLC(code, re, s, table, vlc->bits, 3)    
760 778

  
761
        nb_bits = -n;
762
        table = vlc->table + code;
763
    }
764
#endif
765
    for(;;) {
766
        index= SHOW_UBITS(re, s, nb_bits);
767
        code = table[index][0];
768
        n = table[index][1];
769
        if (n > 0) {
770
            /* most common case */
771
            SKIP_BITS(re, s, n)
772
#ifdef STATS
773
            st_bit_counts[st_current_index] += n;
774
#endif
775
            break;
776
        } else if (n == 0) {
777
            return -1;
778
        } else {
779
            LAST_SKIP_BITS(re, s, nb_bits)
780
            UPDATE_CACHE(re, s)
781
#ifdef STATS
782
            st_bit_counts[st_current_index] += nb_bits;
783
#endif
784
            nb_bits = -n;
785
            table = vlc->table + code;
786
        }
787
    }
788 779
    CLOSE_READER(re, s)
789 780
    return code;
790 781
}
791 782

  
792

  
793 783
/* define it to include statistics code (useful only for optimizing
794 784
   codec efficiency */
795 785
//#define STATS

Also available in: Unified diff