Revision c03a7172 libavcodec/h263.c

View differences:

libavcodec/h263.c
1704 1704
        init_vlc_rl(&rl_inter);
1705 1705
        init_vlc_rl(&rl_intra);
1706 1706
        init_vlc_rl(&rl_intra_aic);
1707
        init_vlc(&dc_lum, DC_VLC_BITS, 9 /* 13 */,
1707
        init_vlc(&dc_lum, DC_VLC_BITS, 10 /* 13 */,
1708 1708
                 &DCtab_lum[0][1], 2, 1,
1709 1709
                 &DCtab_lum[0][0], 2, 1);
1710
        init_vlc(&dc_chrom, DC_VLC_BITS, 9 /* 13 */,
1710
        init_vlc(&dc_chrom, DC_VLC_BITS, 10 /* 13 */,
1711 1711
                 &DCtab_chrom[0][1], 2, 1,
1712 1712
                 &DCtab_chrom[0][0], 2, 1);
1713 1713
        init_vlc(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
......
2917 2917
static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
2918 2918
                              int n, int coded)
2919 2919
{
2920
    int code, level, i, j, last, run;
2920
    int level, i, last, run;
2921 2921
    int dc_pred_dir;
2922 2922
    RLTable *rl;
2923
    RL_VLC_ELEM *rl_vlc;
2923 2924
    const UINT8 *scan_table;
2925
    int qmul, qadd;
2924 2926

  
2925 2927
    if (s->mb_intra) {
2926 2928
	/* DC coef */
......
2935 2937
                return DECODING_ACDC_LOST;
2936 2938
        }
2937 2939
        block[0] = level;
2938
        i = 1;
2940
        i = 0;
2939 2941
        if (!coded) 
2940 2942
            goto not_coded;
2941 2943
        rl = &rl_intra;
2944
        rl_vlc = rl_intra.rl_vlc[0];
2942 2945
        if (s->ac_pred) {
2943 2946
            if (dc_pred_dir == 0) 
2944 2947
                scan_table = ff_alternate_vertical_scan; /* left */
......
2947 2950
        } else {
2948 2951
            scan_table = zigzag_direct;
2949 2952
        }
2953
        qmul=1;
2954
        qadd=0;
2950 2955
    } else {
2951
	i = 0;
2956
        i = -1;
2952 2957
        if (!coded) {
2953
            s->block_last_index[n] = i - 1;
2958
            s->block_last_index[n] = i;
2954 2959
            return 0;
2955 2960
        }
2956 2961
        rl = &rl_inter;
2962
        rl_vlc = rl_inter.rl_vlc[s->qscale];
2957 2963
        scan_table = zigzag_direct;
2964
        qmul = s->qscale << 1;
2965
        qadd = (s->qscale - 1) | 1;
2958 2966
    }
2959

  
2967
  {
2968
    OPEN_READER(re, &s->gb);
2960 2969
    for(;;) {
2961
        code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2);
2962
        if (code < 0)
2963
            return DECODING_AC_LOST;
2964
        if (code == rl->n) {
2970
        UPDATE_CACHE(re, &s->gb);
2971
        GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2);
2972
        if (level==0) {
2973
            int cache;
2974
            cache= GET_CACHE(re, &s->gb);
2965 2975
            /* escape */
2966
            if (get_bits1(&s->gb) != 0) {
2967
                if (get_bits1(&s->gb) != 0) {
2976
            if (cache&0x80000000) {
2977
                if (cache&0x40000000) {
2968 2978
                    /* third escape */
2969
                    last = get_bits1(&s->gb);
2970
                    run = get_bits(&s->gb, 6);
2971
                    if(get_bits1(&s->gb)==0){
2979
                    SKIP_CACHE(re, &s->gb, 2);
2980
                    last=  SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
2981
                    run=   SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6);
2982
                    SKIP_COUNTER(re, &s->gb, 2+1+6);
2983
                    UPDATE_CACHE(re, &s->gb);
2984

  
2985
                    if(SHOW_UBITS(re, &s->gb, 1)==0){
2972 2986
                        fprintf(stderr, "1. marker bit missing in 3. esc\n");
2973 2987
                        return DECODING_AC_LOST;
2974
                    }
2975
                    level = get_bits(&s->gb, 12);
2976
                    level = (level << 20) >> 20; /* sign extend */
2977
                    if(get_bits1(&s->gb)==0){
2988
                    }; SKIP_CACHE(re, &s->gb, 1);
2989
                    
2990
                    level= SHOW_SBITS(re, &s->gb, 12); SKIP_CACHE(re, &s->gb, 12);
2991
 
2992
                    if(SHOW_UBITS(re, &s->gb, 1)==0){
2978 2993
                        fprintf(stderr, "2. marker bit missing in 3. esc\n");
2979 2994
                        return DECODING_AC_LOST;
2980
                    }
2995
                    }; LAST_SKIP_CACHE(re, &s->gb, 1);
2996
                    
2997
                    SKIP_COUNTER(re, &s->gb, 1+12+1);
2998
                    
2981 2999
                    if(level>512 || level<-512){ //FIXME check that QP=1 is ok with this too
2982 3000
                        fprintf(stderr, "|level| overflow in 3. esc\n");
2983 3001
                        return DECODING_AC_LOST;
......
3002 3020
                        }
3003 3021
                    }
3004 3022
#endif
3023
		    if (level>0) level= level * qmul + qadd;
3024
                    else         level= level * qmul - qadd;
3025

  
3026
                    i+= run + 1;
3027
                    if(last) i+=192;
3005 3028
                } else {
3006 3029
                    /* second escape */
3007
                    code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2);
3008
                    if (code < 0 || code >= rl->n)
3009
                        return DECODING_AC_LOST;
3010
                    run = rl->table_run[code];
3011
                    level = rl->table_level[code];
3012
                    last = code >= rl->last;
3013
                    run += rl->max_run[last][level] + 1;
3014
                    if (get_bits1(&s->gb))
3015
                        level = -level;
3030
#if MIN_CACHE_BITS < 20
3031
                    LAST_SKIP_BITS(re, &s->gb, 2);
3032
                    UPDATE_CACHE(re, &s->gb);
3033
#else
3034
                    SKIP_BITS(re, &s->gb, 2);
3035
#endif
3036
                    GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2);
3037
                    i+= run + rl->max_run[run>>7][level/qmul] +1; //FIXME opt indexing
3038
                    level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
3039
                    LAST_SKIP_BITS(re, &s->gb, 1);
3016 3040
                }
3017 3041
            } else {
3018 3042
                /* first escape */
3019
                code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2);
3020
                if (code < 0 || code >= rl->n)
3021
                    return DECODING_AC_LOST;
3022
                run = rl->table_run[code];
3023
                level = rl->table_level[code];
3024
                last = code >= rl->last;
3025
                level += rl->max_level[last][run];
3026
                if (get_bits1(&s->gb))
3027
                    level = -level;
3043
#if MIN_CACHE_BITS < 19
3044
                LAST_SKIP_BITS(re, &s->gb, 1);
3045
                UPDATE_CACHE(re, &s->gb);
3046
#else
3047
                SKIP_BITS(re, &s->gb, 1);
3048
#endif
3049
                GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2);
3050
                i+= run;
3051
                level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
3052
                level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
3053
                LAST_SKIP_BITS(re, &s->gb, 1);
3028 3054
            }
3029 3055
        } else {
3030
            run = rl->table_run[code];
3031
            level = rl->table_level[code];
3032
            last = code >= rl->last;
3033
            if (get_bits1(&s->gb))
3034
                level = -level;
3056
            i+= run;
3057
            level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
3058
            LAST_SKIP_BITS(re, &s->gb, 1);
3035 3059
        }
3036
        i += run;
3037
        if (i >= 64)
3038
            return DECODING_AC_LOST;
3039
	j = scan_table[i];
3040
        block[j] = level;
3041
        i++;
3042
        if (last)
3060
        if (i > 62){
3061
            i-= 192;
3062
            if(i&(~63)){
3063
                fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
3064
                return DECODING_AC_LOST;
3065
            }
3066

  
3067
            block[scan_table[i]] = level;
3043 3068
            break;
3069
        }
3070

  
3071
        block[scan_table[i]] = level;
3044 3072
    }
3073
    CLOSE_READER(re, &s->gb);
3074
  }
3045 3075
 not_coded:
3046 3076
    if (s->mb_intra) {
3047 3077
        mpeg4_pred_ac(s, block, n, dc_pred_dir);
3048 3078
        if (s->ac_pred) {
3049
            i = 64; /* XXX: not optimal */
3079
            i = 63; /* XXX: not optimal */
3050 3080
        }
3051 3081
    }
3052
    s->block_last_index[n] = i - 1;
3082
    s->block_last_index[n] = i;
3053 3083
    return 0;
3054 3084
}
3055 3085

  

Also available in: Unified diff