static int h263_decode_block(MpegEncContext * s, int16_t * block,

                             int n, int coded)

{

    int level, i, j, run;

    RLTable *rl = &ff_h263_rl_inter;

    const uint8_t *scan_table;

    GetBitContext gb= s->gb;



    scan_table = s->intra_scantable.permutated;

    if (s->h263_aic && s->mb_intra) {

        rl = &ff_rl_intra_aic;

        i = 0;

        if (s->ac_pred) {

            if (s->h263_aic_dir)

                scan_table = s->intra_v_scantable.permutated; /* left */

            else

                scan_table = s->intra_h_scantable.permutated; /* top */

        }

    } else if (s->mb_intra) {

        /* DC coef */

        if (CONFIG_RV10_DECODER && s->codec_id == AV_CODEC_ID_RV10) {

          if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) {

            int component, diff;

            component = (n <= 3 ? 0 : n - 4 + 1);

            level = s->last_dc[component];

            if (s->rv10_first_dc_coded[component]) {

                diff = ff_rv_decode_dc(s, n);

                if (diff == 0xffff)

                    return -1;

                level += diff;

                level = level & 0xff; /* handle wrap round */

                s->last_dc[component] = level;

            } else {

                s->rv10_first_dc_coded[component] = 1;

            }

          } else {

                level = get_bits(&s->gb, 8);

                if (level == 255)

                    level = 128;

          }

        }else{

            level = get_bits(&s->gb, 8);

            if((level&0x7F) == 0){

                av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);

                if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))

                    return -1;

            }

            if (level == 255)

                level = 128;

        }

        block[0] = level;

        i = 1;

    } else {

        i = 0;

    }

    if (!coded) {

        if (s->mb_intra && s->h263_aic)

            goto not_coded;

        s->block_last_index[n] = i - 1;

        return 0;

    }

retry:

    {

    OPEN_READER(re, &s->gb);

    i--; // offset by -1 to allow direct indexing of scan_table

    for(;;) {

        UPDATE_CACHE(re, &s->gb);

        GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);

        if (run == 66) {

            if (level){

                CLOSE_READER(re, &s->gb);

                av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);

                return -1;

            }

            /* escape */

            if (CONFIG_FLV_DECODER && s->h263_flv > 1) {

                int is11 = SHOW_UBITS(re, &s->gb, 1);

                SKIP_CACHE(re, &s->gb, 1);

                run = SHOW_UBITS(re, &s->gb, 7) + 1;

                if (is11) {

                    SKIP_COUNTER(re, &s->gb, 1 + 7);

                    UPDATE_CACHE(re, &s->gb);

                    level = SHOW_SBITS(re, &s->gb, 11);

                    SKIP_COUNTER(re, &s->gb, 11);

                } else {

                    SKIP_CACHE(re, &s->gb, 7);

                    level = SHOW_SBITS(re, &s->gb, 7);

                    SKIP_COUNTER(re, &s->gb, 1 + 7 + 7);

                }

            } else {

                run = SHOW_UBITS(re, &s->gb, 7) + 1;

                SKIP_CACHE(re, &s->gb, 7);

                level = (int8_t)SHOW_UBITS(re, &s->gb, 8);

                SKIP_COUNTER(re, &s->gb, 7 + 8);

                if(level == -128){

                    UPDATE_CACHE(re, &s->gb);

                    if (s->codec_id == AV_CODEC_ID_RV10) {

                        /* XXX: should patch encoder too */

                        level = SHOW_SBITS(re, &s->gb, 12);

                        SKIP_COUNTER(re, &s->gb, 12);

                    }else{

                        level = SHOW_UBITS(re, &s->gb, 5);

                        SKIP_CACHE(re, &s->gb, 5);

                        level |= SHOW_SBITS(re, &s->gb, 6)<<5;

                        SKIP_COUNTER(re, &s->gb, 5 + 6);

                    }

                }

            }

        } else {

            if (SHOW_UBITS(re, &s->gb, 1))

                level = -level;

            SKIP_COUNTER(re, &s->gb, 1);

        }

        i += run;

        if (i >= 64){

            CLOSE_READER(re, &s->gb);

            // redo update without last flag, revert -1 offset

            i = i - run + ((run-1)&63) + 1;

            if (i < 64) {

                // only last marker, no overrun

                block[scan_table[i]] = level;

                break;

            }

            if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){

                //Looks like a hack but no, it's the way it is supposed to work ...

                rl = &ff_rl_intra_aic;

                i = 0;

                s->gb= gb;

                s->bdsp.clear_block(block);

                goto retry;

            }

            av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra);

            return -1;

        }

        j = scan_table[i];

        block[j] = level;

    }

    }

not_coded:

    if (s->mb_intra && s->h263_aic) {

        ff_h263_pred_acdc(s, block, n);

        i = 63;

    }

    s->block_last_index[n] = i;

    return 0;

}

static int h263_decode_block(MpegEncContext * s, int16_t * block,

                             int n, int coded)

{

    int level, i, j, run;

    RLTable *rl = &ff_h263_rl_inter;

    const uint8_t *scan_table;

    GetBitContext gb= s->gb;



    scan_table = s->intra_scantable.permutated;

    if (s->h263_aic && s->mb_intra) {

        rl = &ff_rl_intra_aic;

        i = 0;

        if (s->ac_pred) {

            if (s->h263_aic_dir)

                scan_table = s->intra_v_scantable.permutated; 

            else

                scan_table = s->intra_h_scantable.permutated; 

        }

    } else if (s->mb_intra) {

        

        if (CONFIG_RV10_DECODER && s->codec_id == AV_CODEC_ID_RV10) {

          if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) {

            int component, diff;

            component = (n <= 3 ? 0 : n - 4 + 1);

            level = s->last_dc[component];

            if (s->rv10_first_dc_coded[component]) {

                diff = ff_rv_decode_dc(s, n);

                if (diff == 0xffff)

                    return -1;

                level += diff;

                level = level & 0xff; 

                s->last_dc[component] = level;

            } else {

                s->rv10_first_dc_coded[component] = 1;

            }

          } else {

                level = get_bits(&s->gb, 8);

                if (level == 255)

                    level = 128;

          }

        }else{

            level = get_bits(&s->gb, 8);

            if((level&0x7F) == 0){

                av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);

                if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))

                    return -1;

            }

            if (level == 255)

                level = 128;

        }

        block[0] = level;

        i = 1;

    } else {

        i = 0;

    }

    if (!coded) {

        if (s->mb_intra && s->h263_aic)

            goto not_coded;

        s->block_last_index[n] = i - 1;

        return 0;

    }

retry:

    {

    OPEN_READER(re, &s->gb);

    i--; 

    for(;;) {

        UPDATE_CACHE(re, &s->gb);

        GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);

        if (run == 66) {

            if (level){

                CLOSE_READER(re, &s->gb);

                av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);

                return -1;

            }

            

            if (CONFIG_FLV_DECODER && s->h263_flv > 1) {

                int is11 = SHOW_UBITS(re, &s->gb, 1);

                SKIP_CACHE(re, &s->gb, 1);

                run = SHOW_UBITS(re, &s->gb, 7) + 1;

                if (is11) {

                    SKIP_COUNTER(re, &s->gb, 1 + 7);

                    UPDATE_CACHE(re, &s->gb);

                    level = SHOW_SBITS(re, &s->gb, 11);

                    SKIP_COUNTER(re, &s->gb, 11);

                } else {

                    SKIP_CACHE(re, &s->gb, 7);

                    level = SHOW_SBITS(re, &s->gb, 7);

                    SKIP_COUNTER(re, &s->gb, 1 + 7 + 7);

                }

            } else {

                run = SHOW_UBITS(re, &s->gb, 7) + 1;

                SKIP_CACHE(re, &s->gb, 7);

                level = (int8_t)SHOW_UBITS(re, &s->gb, 8);

                SKIP_COUNTER(re, &s->gb, 7 + 8);

                if(level == -128){

                    UPDATE_CACHE(re, &s->gb);

                    if (s->codec_id == AV_CODEC_ID_RV10) {

                        

                        level = SHOW_SBITS(re, &s->gb, 12);

                        SKIP_COUNTER(re, &s->gb, 12);

                    }else{

                        level = SHOW_UBITS(re, &s->gb, 5);

                        SKIP_CACHE(re, &s->gb, 5);

                        level |= SHOW_SBITS(re, &s->gb, 6)<<5;

                        SKIP_COUNTER(re, &s->gb, 5 + 6);

                    }

                }

            }

        } else {

            if (SHOW_UBITS(re, &s->gb, 1))

                level = -level;

            SKIP_COUNTER(re, &s->gb, 1);

        }

        i += run;

        if (i >= 64){

            CLOSE_READER(re, &s->gb);

            

            i = i - run + ((run-1)&63) + 1;

            if (i < 64) {

                

                block[scan_table[i]] = level;

                break;

            }

            if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){

                

                rl = &ff_rl_intra_aic;

                i = 0;

                s->gb= gb;

                s->bdsp.clear_block(block);

                goto retry;

            }

            av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra);

            return -1;

        }

        j = scan_table[i];

        block[j] = level;

    }

    }

not_coded:

    if (s->mb_intra && s->h263_aic) {

        ff_h263_pred_acdc(s, block, n);

        i = 63;

    }

    s->block_last_index[n] = i;

    return 0;

}

                        level |= SHOW_SBITS(re, &s->gb, 6)<<5;
static int FUNC_0(MpegEncContext * VAR_0, int16_t * VAR_1,

                             int VAR_2, int VAR_3)

{

    int VAR_4, VAR_5, VAR_6, VAR_7;

    RLTable *rl = &ff_h263_rl_inter;

    const uint8_t *VAR_8;

    GetBitContext gb= VAR_0->gb;



    VAR_8 = VAR_0->intra_scantable.permutated;

    if (VAR_0->h263_aic && VAR_0->mb_intra) {

        rl = &ff_rl_intra_aic;

        VAR_5 = 0;

        if (VAR_0->ac_pred) {

            if (VAR_0->h263_aic_dir)

                VAR_8 = VAR_0->intra_v_scantable.permutated; 

            else

                VAR_8 = VAR_0->intra_h_scantable.permutated; 

        }

    } else if (VAR_0->mb_intra) {

        

        if (CONFIG_RV10_DECODER && VAR_0->codec_id == AV_CODEC_ID_RV10) {

          if (VAR_0->rv10_version == 3 && VAR_0->pict_type == AV_PICTURE_TYPE_I) {

            int VAR_9, VAR_10;

            VAR_9 = (VAR_2 <= 3 ? 0 : VAR_2 - 4 + 1);

            VAR_4 = VAR_0->last_dc[VAR_9];

            if (VAR_0->rv10_first_dc_coded[VAR_9]) {

                VAR_10 = ff_rv_decode_dc(VAR_0, VAR_2);

                if (VAR_10 == 0xffff)

                    return -1;

                VAR_4 += VAR_10;

                VAR_4 = VAR_4 & 0xff; 

                VAR_0->last_dc[VAR_9] = VAR_4;

            } else {

                VAR_0->rv10_first_dc_coded[VAR_9] = 1;

            }

          } else {

                VAR_4 = get_bits(&VAR_0->gb, 8);

                if (VAR_4 == 255)

                    VAR_4 = 128;

          }

        }else{

            VAR_4 = get_bits(&VAR_0->gb, 8);

            if((VAR_4&0x7F) == 0){

                av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\VAR_2", VAR_4, VAR_0->mb_x, VAR_0->mb_y);

                if (VAR_0->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))

                    return -1;

            }

            if (VAR_4 == 255)

                VAR_4 = 128;

        }

        VAR_1[0] = VAR_4;

        VAR_5 = 1;

    } else {

        VAR_5 = 0;

    }

    if (!VAR_3) {

        if (VAR_0->mb_intra && VAR_0->h263_aic)

            goto not_coded;

        VAR_0->block_last_index[VAR_2] = VAR_5 - 1;

        return 0;

    }

retry:

    {

    OPEN_READER(re, &VAR_0->gb);

    VAR_5--; 

    for(;;) {

        UPDATE_CACHE(re, &VAR_0->gb);

        GET_RL_VLC(VAR_4, VAR_7, re, &VAR_0->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);

        if (VAR_7 == 66) {

            if (VAR_4){

                CLOSE_READER(re, &VAR_0->gb);

                av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\VAR_2", VAR_0->mb_x, VAR_0->mb_y);

                return -1;

            }

            

            if (CONFIG_FLV_DECODER && VAR_0->h263_flv > 1) {

                int VAR_11 = SHOW_UBITS(re, &VAR_0->gb, 1);

                SKIP_CACHE(re, &VAR_0->gb, 1);

                VAR_7 = SHOW_UBITS(re, &VAR_0->gb, 7) + 1;

                if (VAR_11) {

                    SKIP_COUNTER(re, &VAR_0->gb, 1 + 7);

                    UPDATE_CACHE(re, &VAR_0->gb);

                    VAR_4 = SHOW_SBITS(re, &VAR_0->gb, 11);

                    SKIP_COUNTER(re, &VAR_0->gb, 11);

                } else {

                    SKIP_CACHE(re, &VAR_0->gb, 7);

                    VAR_4 = SHOW_SBITS(re, &VAR_0->gb, 7);

                    SKIP_COUNTER(re, &VAR_0->gb, 1 + 7 + 7);

                }

            } else {

                VAR_7 = SHOW_UBITS(re, &VAR_0->gb, 7) + 1;

                SKIP_CACHE(re, &VAR_0->gb, 7);

                VAR_4 = (int8_t)SHOW_UBITS(re, &VAR_0->gb, 8);

                SKIP_COUNTER(re, &VAR_0->gb, 7 + 8);

                if(VAR_4 == -128){

                    UPDATE_CACHE(re, &VAR_0->gb);

                    if (VAR_0->codec_id == AV_CODEC_ID_RV10) {

                        

                        VAR_4 = SHOW_SBITS(re, &VAR_0->gb, 12);

                        SKIP_COUNTER(re, &VAR_0->gb, 12);

                    }else{

                        VAR_4 = SHOW_UBITS(re, &VAR_0->gb, 5);

                        SKIP_CACHE(re, &VAR_0->gb, 5);

                        VAR_4 |= SHOW_SBITS(re, &VAR_0->gb, 6)<<5;

                        SKIP_COUNTER(re, &VAR_0->gb, 5 + 6);

                    }

                }

            }

        } else {

            if (SHOW_UBITS(re, &VAR_0->gb, 1))

                VAR_4 = -VAR_4;

            SKIP_COUNTER(re, &VAR_0->gb, 1);

        }

        VAR_5 += VAR_7;

        if (VAR_5 >= 64){

            CLOSE_READER(re, &VAR_0->gb);

            

            VAR_5 = VAR_5 - VAR_7 + ((VAR_7-1)&63) + 1;

            if (VAR_5 < 64) {

                

                VAR_1[VAR_8[VAR_5]] = VAR_4;

                break;

            }

            if(VAR_0->alt_inter_vlc && rl == &ff_h263_rl_inter && !VAR_0->mb_intra){

                

                rl = &ff_rl_intra_aic;

                VAR_5 = 0;

                VAR_0->gb= gb;

                VAR_0->bdsp.clear_block(VAR_1);

                goto retry;

            }

            av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_7 overflow at %dx%d VAR_5:%d\VAR_2", VAR_0->mb_x, VAR_0->mb_y, VAR_0->mb_intra);

            return -1;

        }

        VAR_6 = VAR_8[VAR_5];

        VAR_1[VAR_6] = VAR_4;

    }

    }

not_coded:

    if (VAR_0->mb_intra && VAR_0->h263_aic) {

        ff_h263_pred_acdc(VAR_0, VAR_1, VAR_2);

        VAR_5 = 63;

    }

    VAR_0->block_last_index[VAR_2] = VAR_5;

    return 0;

}

static int FUNC_0(MpegEncContext * VAR_0, int16_t * VAR_1,
int VAR_2, int VAR_3)
{ int VAR_4, VAR_5, VAR_6, VAR_7; RLTable *rl = &ff_h263_rl_inter; const uint8_t *VAR_8; GetBitContext gb= VAR_0->gb; VAR_8 = VAR_0->intra_scantable.permutated; if (VAR_0->h263_aic && VAR_0->mb_intra) { rl = &ff_rl_intra_aic; VAR_5 = 0; if (VAR_0->ac_pred) { if (VAR_0->h263_aic_dir)
VAR_8 = VAR_0->intra_v_scantable.permutated; else
VAR_8 = VAR_0->intra_h_scantable.permutated; } } else if (VAR_0->mb_intra) { if (CONFIG_RV10_DECODER && VAR_0->codec_id == AV_CODEC_ID_RV10) { if (VAR_0->rv10_version == 3 && VAR_0->pict_type == AV_PICTURE_TYPE_I) { int VAR_9, VAR_10; VAR_9 = (VAR_2 <= 3 ? 0 : VAR_2 - 4 + 1); VAR_4 = VAR_0->last_dc[VAR_9]; if (VAR_0->rv10_first_dc_coded[VAR_9]) { VAR_10 = ff_rv_decode_dc(VAR_0, VAR_2); if (VAR_10 == 0xffff)
return -1; VAR_4 += VAR_10; VAR_4 = VAR_4 & 0xff; VAR_0->last_dc[VAR_9] = VAR_4; } else { VAR_0->rv10_first_dc_coded[VAR_9] = 1; } } else { VAR_4 = get_bits(&VAR_0->gb, 8); if (VAR_4 == 255)
VAR_4 = 128; } }else{ VAR_4 = get_bits(&VAR_0->gb, 8); if((VAR_4&0x7F) == 0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\VAR_2", VAR_4, VAR_0->mb_x, VAR_0->mb_y); if (VAR_0->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
return -1; } if (VAR_4 == 255)
VAR_4 = 128; } VAR_1[0] = VAR_4; VAR_5 = 1; } else { VAR_5 = 0; } if (!VAR_3) { if (VAR_0->mb_intra && VAR_0->h263_aic)
goto not_coded; VAR_0->block_last_index[VAR_2] = VAR_5 - 1; return 0; } retry:
{ OPEN_READER(re, &VAR_0->gb); VAR_5--; for(;;) { UPDATE_CACHE(re, &VAR_0->gb); GET_RL_VLC(VAR_4, VAR_7, re, &VAR_0->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); if (VAR_7 == 66) { if (VAR_4){ CLOSE_READER(re, &VAR_0->gb); av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\VAR_2", VAR_0->mb_x, VAR_0->mb_y); return -1; } if (CONFIG_FLV_DECODER && VAR_0->h263_flv > 1) { int VAR_11 = SHOW_UBITS(re, &VAR_0->gb, 1); SKIP_CACHE(re, &VAR_0->gb, 1); VAR_7 = SHOW_UBITS(re, &VAR_0->gb, 7) + 1; if (VAR_11) { SKIP_COUNTER(re, &VAR_0->gb, 1 + 7); UPDATE_CACHE(re, &VAR_0->gb); VAR_4 = SHOW_SBITS(re, &VAR_0->gb, 11); SKIP_COUNTER(re, &VAR_0->gb, 11); } else { SKIP_CACHE(re, &VAR_0->gb, 7); VAR_4 = SHOW_SBITS(re, &VAR_0->gb, 7); SKIP_COUNTER(re, &VAR_0->gb, 1 + 7 + 7); } } else { VAR_7 = SHOW_UBITS(re, &VAR_0->gb, 7) + 1; SKIP_CACHE(re, &VAR_0->gb, 7); VAR_4 = (int8_t)SHOW_UBITS(re, &VAR_0->gb, 8); SKIP_COUNTER(re, &VAR_0->gb, 7 + 8); if(VAR_4 == -128){ UPDATE_CACHE(re, &VAR_0->gb); if (VAR_0->codec_id == AV_CODEC_ID_RV10) { VAR_4 = SHOW_SBITS(re, &VAR_0->gb, 12); SKIP_COUNTER(re, &VAR_0->gb, 12); }else{ VAR_4 = SHOW_UBITS(re, &VAR_0->gb, 5); SKIP_CACHE(re, &VAR_0->gb, 5); VAR_4 |= SHOW_SBITS(re, &VAR_0->gb, 6)<<5; SKIP_COUNTER(re, &VAR_0->gb, 5 + 6); } } } } else { if (SHOW_UBITS(re, &VAR_0->gb, 1))
VAR_4 = -VAR_4; SKIP_COUNTER(re, &VAR_0->gb, 1); } VAR_5 += VAR_7; if (VAR_5 >= 64){ CLOSE_READER(re, &VAR_0->gb); VAR_5 = VAR_5 - VAR_7 + ((VAR_7-1)&63) + 1; if (VAR_5 < 64) { VAR_1[VAR_8[VAR_5]] = VAR_4; break; } if(VAR_0->alt_inter_vlc && rl == &ff_h263_rl_inter && !VAR_0->mb_intra){ rl = &ff_rl_intra_aic; VAR_5 = 0; VAR_0->gb= gb; VAR_0->bdsp.clear_block(VAR_1); goto retry; } av_log(VAR_0->avctx, AV_LOG_ERROR, "VAR_7 overflow at %dx%d VAR_5:%d\VAR_2", VAR_0->mb_x, VAR_0->mb_y, VAR_0->mb_intra); return -1; } VAR_6 = VAR_8[VAR_5]; VAR_1[VAR_6] = VAR_4; } } not_coded:
if (VAR_0->mb_intra && VAR_0->h263_aic) { ff_h263_pred_acdc(VAR_0, VAR_1, VAR_2); VAR_5 = 63; } VAR_0->block_last_index[VAR_2] = VAR_5; return 0; }