static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])

{

    Mpeg4DecContext *ctx = (Mpeg4DecContext *)s;

    int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;

    int16_t *mot_val;

    static const int8_t quant_tab[4] = { -1, -2, 1, 2 };

    const int xy = s->mb_x + s->mb_y * s->mb_stride;



    av_assert2(s->h263_pred);



    if (s->pict_type == AV_PICTURE_TYPE_P ||

        s->pict_type == AV_PICTURE_TYPE_S) {

        do {

            if (get_bits1(&s->gb)) {

                /* skip mb */

                s->mb_intra = 0;

                for (i = 0; i < 6; i++)

                    s->block_last_index[i] = -1;

                s->mv_dir  = MV_DIR_FORWARD;

                s->mv_type = MV_TYPE_16X16;

                if (s->pict_type == AV_PICTURE_TYPE_S &&

                    ctx->vol_sprite_usage == GMC_SPRITE) {

                    s->current_picture.mb_type[xy] = MB_TYPE_SKIP  |

                                                     MB_TYPE_GMC   |

                                                     MB_TYPE_16x16 |

                                                     MB_TYPE_L0;

                    s->mcsel       = 1;

                    s->mv[0][0][0] = get_amv(ctx, 0);

                    s->mv[0][0][1] = get_amv(ctx, 1);

                    s->mb_skipped  = 0;

                } else {

                    s->current_picture.mb_type[xy] = MB_TYPE_SKIP  |

                                                     MB_TYPE_16x16 |

                                                     MB_TYPE_L0;

                    s->mcsel       = 0;

                    s->mv[0][0][0] = 0;

                    s->mv[0][0][1] = 0;

                    s->mb_skipped  = 1;


                goto end;


            cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);

            if (cbpc < 0) {


                       "mcbpc damaged at %d %d\n", s->mb_x, s->mb_y);

                return -1;


        } while (cbpc == 20);



        s->bdsp.clear_blocks(s->block[0]);

        dquant      = cbpc & 8;

        s->mb_intra = ((cbpc & 4) != 0);

        if (s->mb_intra)

            goto intra;



        if (s->pict_type == AV_PICTURE_TYPE_S &&

            ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0)

            s->mcsel = get_bits1(&s->gb);

        else

            s->mcsel = 0;

        cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1) ^ 0x0F;








        cbp = (cbpc & 3) | (cbpy << 2);

        if (dquant)

            ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);

        if ((!s->progressive_sequence) &&

            (cbp || (s->workaround_bugs & FF_BUG_XVID_ILACE)))

            s->interlaced_dct = get_bits1(&s->gb);



        s->mv_dir = MV_DIR_FORWARD;

        if ((cbpc & 16) == 0) {

            if (s->mcsel) {

                s->current_picture.mb_type[xy] = MB_TYPE_GMC   |

                                                 MB_TYPE_16x16 |

                                                 MB_TYPE_L0;

                /* 16x16 global motion prediction */

                s->mv_type     = MV_TYPE_16X16;

                mx             = get_amv(ctx, 0);

                my             = get_amv(ctx, 1);

                s->mv[0][0][0] = mx;

                s->mv[0][0][1] = my;

            } else if ((!s->progressive_sequence) && get_bits1(&s->gb)) {

                s->current_picture.mb_type[xy] = MB_TYPE_16x8 |

                                                 MB_TYPE_L0   |

                                                 MB_TYPE_INTERLACED;

                /* 16x8 field motion prediction */

                s->mv_type = MV_TYPE_FIELD;



                s->field_select[0][0] = get_bits1(&s->gb);

                s->field_select[0][1] = get_bits1(&s->gb);



                ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);



                for (i = 0; i < 2; i++) {

                    mx = ff_h263_decode_motion(s, pred_x, s->f_code);

                    if (mx >= 0xffff)

                        return -1;



                    my = ff_h263_decode_motion(s, pred_y / 2, s->f_code);

                    if (my >= 0xffff)

                        return -1;



                    s->mv[0][i][0] = mx;

                    s->mv[0][i][1] = my;


            } else {

                s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;

                /* 16x16 motion prediction */

                s->mv_type = MV_TYPE_16X16;

                ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);

                mx = ff_h263_decode_motion(s, pred_x, s->f_code);



                if (mx >= 0xffff)

                    return -1;



                my = ff_h263_decode_motion(s, pred_y, s->f_code);



                if (my >= 0xffff)

                    return -1;

                s->mv[0][0][0] = mx;

                s->mv[0][0][1] = my;


        } else {

            s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;

            s->mv_type                     = MV_TYPE_8X8;

            for (i = 0; i < 4; i++) {

                mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);

                mx      = ff_h263_decode_motion(s, pred_x, s->f_code);

                if (mx >= 0xffff)

                    return -1;



                my = ff_h263_decode_motion(s, pred_y, s->f_code);

                if (my >= 0xffff)

                    return -1;

                s->mv[0][i][0] = mx;

                s->mv[0][i][1] = my;

                mot_val[0]     = mx;

                mot_val[1]     = my;



    } else if (s->pict_type == AV_PICTURE_TYPE_B) {

        int modb1;   // first bit of modb

        int modb2;   // second bit of modb

        int mb_type;



        s->mb_intra = 0;  // B-frames never contain intra blocks

        s->mcsel    = 0;  //      ...               true gmc blocks



        if (s->mb_x == 0) {

            for (i = 0; i < 2; i++) {

                s->last_mv[i][0][0] =

                s->last_mv[i][0][1] =

                s->last_mv[i][1][0] =

                s->last_mv[i][1][1] = 0;




            ff_thread_await_progress(&s->next_picture_ptr->tf, s->mb_y, 0);




        /* if we skipped it in the future P Frame than skip it now too */

        s->mb_skipped = s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x];  // Note, skiptab=0 if last was GMC



        if (s->mb_skipped) {

            /* skip mb */

            for (i = 0; i < 6; i++)

                s->block_last_index[i] = -1;



            s->mv_dir      = MV_DIR_FORWARD;

            s->mv_type     = MV_TYPE_16X16;

            s->mv[0][0][0] =

            s->mv[0][0][1] =

            s->mv[1][0][0] =

            s->mv[1][0][1] = 0;

            s->current_picture.mb_type[xy] = MB_TYPE_SKIP  |

                                             MB_TYPE_16x16 |

                                             MB_TYPE_L0;

            goto end;




        modb1 = get_bits1(&s->gb);

        if (modb1) {

            // like MB_TYPE_B_DIRECT but no vectors coded

            mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1;

            cbp     = 0;

        } else {

            modb2   = get_bits1(&s->gb);

            mb_type = get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1);

            if (mb_type < 0) {

                av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n");

                return -1;


            mb_type = mb_type_b_map[mb_type];

            if (modb2) {

                cbp = 0;

            } else {

                s->bdsp.clear_blocks(s->block[0]);

                cbp = get_bits(&s->gb, 6);




            if ((!IS_DIRECT(mb_type)) && cbp) {

                if (get_bits1(&s->gb))

                    ff_set_qscale(s, s->qscale + get_bits1(&s->gb) * 4 - 2);




            if (!s->progressive_sequence) {

                if (cbp)

                    s->interlaced_dct = get_bits1(&s->gb);



                if (!IS_DIRECT(mb_type) && get_bits1(&s->gb)) {

                    mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;

                    mb_type &= ~MB_TYPE_16x16;



                    if (USES_LIST(mb_type, 0)) {

                        s->field_select[0][0] = get_bits1(&s->gb);

                        s->field_select[0][1] = get_bits1(&s->gb);


                    if (USES_LIST(mb_type, 1)) {

                        s->field_select[1][0] = get_bits1(&s->gb);

                        s->field_select[1][1] = get_bits1(&s->gb);






            s->mv_dir = 0;

            if ((mb_type & (MB_TYPE_DIRECT2 | MB_TYPE_INTERLACED)) == 0) {

                s->mv_type = MV_TYPE_16X16;



                if (USES_LIST(mb_type, 0)) {

                    s->mv_dir = MV_DIR_FORWARD;



                    mx = ff_h263_decode_motion(s, s->last_mv[0][0][0], s->f_code);

                    my = ff_h263_decode_motion(s, s->last_mv[0][0][1], s->f_code);

                    s->last_mv[0][1][0] =

                    s->last_mv[0][0][0] =

                    s->mv[0][0][0]      = mx;

                    s->last_mv[0][1][1] =

                    s->last_mv[0][0][1] =

                    s->mv[0][0][1]      = my;




                if (USES_LIST(mb_type, 1)) {

                    s->mv_dir |= MV_DIR_BACKWARD;



                    mx = ff_h263_decode_motion(s, s->last_mv[1][0][0], s->b_code);

                    my = ff_h263_decode_motion(s, s->last_mv[1][0][1], s->b_code);

                    s->last_mv[1][1][0] =

                    s->last_mv[1][0][0] =

                    s->mv[1][0][0]      = mx;

                    s->last_mv[1][1][1] =

                    s->last_mv[1][0][1] =

                    s->mv[1][0][1]      = my;


            } else if (!IS_DIRECT(mb_type)) {

                s->mv_type = MV_TYPE_FIELD;



                if (USES_LIST(mb_type, 0)) {

                    s->mv_dir = MV_DIR_FORWARD;



                    for (i = 0; i < 2; i++) {

                        mx = ff_h263_decode_motion(s, s->last_mv[0][i][0], s->f_code);

                        my = ff_h263_decode_motion(s, s->last_mv[0][i][1] / 2, s->f_code);

                        s->last_mv[0][i][0] =

                        s->mv[0][i][0]      = mx;

                        s->last_mv[0][i][1] = (s->mv[0][i][1] = my) * 2;





                if (USES_LIST(mb_type, 1)) {

                    s->mv_dir |= MV_DIR_BACKWARD;



                    for (i = 0; i < 2; i++) {

                        mx = ff_h263_decode_motion(s, s->last_mv[1][i][0], s->b_code);

                        my = ff_h263_decode_motion(s, s->last_mv[1][i][1] / 2, s->b_code);

                        s->last_mv[1][i][0] =

                        s->mv[1][i][0]      = mx;

                        s->last_mv[1][i][1] = (s->mv[1][i][1] = my) * 2;







        if (IS_DIRECT(mb_type)) {

            if (IS_SKIP(mb_type)) {

                mx =

                my = 0;

            } else {

                mx = ff_h263_decode_motion(s, 0, 1);

                my = ff_h263_decode_motion(s, 0, 1);




            s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;

            mb_type  |= ff_mpeg4_set_direct_mv(s, mx, my);


        s->current_picture.mb_type[xy] = mb_type;

    } else { /* I-Frame */

        do {

            cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);

            if (cbpc < 0) {


                       "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);

                return -1;


        } while (cbpc == 8);



        dquant = cbpc & 4;

        s->mb_intra = 1;



intra:

        s->ac_pred = get_bits1(&s->gb);

        if (s->ac_pred)

            s->current_picture.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;

        else

            s->current_picture.mb_type[xy] = MB_TYPE_INTRA;



        cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);



                   "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);

            return -1;


        cbp = (cbpc & 3) | (cbpy << 2);



        ctx->use_intra_dc_vlc = s->qscale < ctx->intra_dc_threshold;



        if (dquant)

            ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);



        if (!s->progressive_sequence)

            s->interlaced_dct = get_bits1(&s->gb);



        s->bdsp.clear_blocks(s->block[0]);

        /* decode each block */

        for (i = 0; i < 6; i++) {

            if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, 1, 0) < 0)

                return -1;

            cbp += cbp;


        goto end;




    /* decode each block */

    for (i = 0; i < 6; i++) {

        if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, 0, 0) < 0)

            return -1;

        cbp += cbp;




end:

    /* per-MB end of slice check */

    if (s->codec_id == AV_CODEC_ID_MPEG4) {

        int next = mpeg4_is_resync(ctx);

        if (next) {

            if        (s->mb_x + s->mb_y*s->mb_width + 1 >  next && (s->avctx->err_recognition & AV_EF_AGGRESSIVE)) {

                return -1;

            } else if (s->mb_x + s->mb_y*s->mb_width + 1 >= next)

                return SLICE_END;



            if (s->pict_type == AV_PICTURE_TYPE_B) {

                const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;

                ff_thread_await_progress(&s->next_picture_ptr->tf,

                                         (s->mb_x + delta >= s->mb_width)

                                         ? FFMIN(s->mb_y + 1, s->mb_height - 1)

                                         : s->mb_y, 0);

                if (s->next_picture.mbskip_table[xy + delta])

                    return SLICE_OK;




            return SLICE_END;





    return SLICE_OK;

static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])

{

    Mpeg4DecContext *ctx = (Mpeg4DecContext *)s;

    int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;

    int16_t *mot_val;

    static const int8_t quant_tab[4] = { -1, -2, 1, 2 };

    const int xy = s->mb_x + s->mb_y * s->mb_stride;



    av_assert2(s->h263_pred);



    if (s->pict_type == AV_PICTURE_TYPE_P ||

        s->pict_type == AV_PICTURE_TYPE_S) {

        do {

            if (get_bits1(&s->gb)) {

                

                s->mb_intra = 0;

                for (i = 0; i < 6; i++)

                    s->block_last_index[i] = -1;

                s->mv_dir  = MV_DIR_FORWARD;

                s->mv_type = MV_TYPE_16X16;

                if (s->pict_type == AV_PICTURE_TYPE_S &&

                    ctx->vol_sprite_usage == GMC_SPRITE) {

                    s->current_picture.mb_type[xy] = MB_TYPE_SKIP  |

                                                     MB_TYPE_GMC   |

                                                     MB_TYPE_16x16 |

                                                     MB_TYPE_L0;

                    s->mcsel       = 1;

                    s->mv[0][0][0] = get_amv(ctx, 0);

                    s->mv[0][0][1] = get_amv(ctx, 1);

                    s->mb_skipped  = 0;

                } else {

                    s->current_picture.mb_type[xy] = MB_TYPE_SKIP  |

                                                     MB_TYPE_16x16 |

                                                     MB_TYPE_L0;

                    s->mcsel       = 0;

                    s->mv[0][0][0] = 0;

                    s->mv[0][0][1] = 0;

                    s->mb_skipped  = 1;


                goto end;


            cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);

            if (cbpc < 0) {


                       "mcbpc damaged at %d %d\n", s->mb_x, s->mb_y);

                return -1;


        } while (cbpc == 20);



        s->bdsp.clear_blocks(s->block[0]);

        dquant      = cbpc & 8;

        s->mb_intra = ((cbpc & 4) != 0);

        if (s->mb_intra)

            goto intra;



        if (s->pict_type == AV_PICTURE_TYPE_S &&

            ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0)

            s->mcsel = get_bits1(&s->gb);

        else

            s->mcsel = 0;

        cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1) ^ 0x0F;








        cbp = (cbpc & 3) | (cbpy << 2);

        if (dquant)

            ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);

        if ((!s->progressive_sequence) &&

            (cbp || (s->workaround_bugs & FF_BUG_XVID_ILACE)))

            s->interlaced_dct = get_bits1(&s->gb);



        s->mv_dir = MV_DIR_FORWARD;

        if ((cbpc & 16) == 0) {

            if (s->mcsel) {

                s->current_picture.mb_type[xy] = MB_TYPE_GMC   |

                                                 MB_TYPE_16x16 |

                                                 MB_TYPE_L0;

                

                s->mv_type     = MV_TYPE_16X16;

                mx             = get_amv(ctx, 0);

                my             = get_amv(ctx, 1);

                s->mv[0][0][0] = mx;

                s->mv[0][0][1] = my;

            } else if ((!s->progressive_sequence) && get_bits1(&s->gb)) {

                s->current_picture.mb_type[xy] = MB_TYPE_16x8 |

                                                 MB_TYPE_L0   |

                                                 MB_TYPE_INTERLACED;

                

                s->mv_type = MV_TYPE_FIELD;



                s->field_select[0][0] = get_bits1(&s->gb);

                s->field_select[0][1] = get_bits1(&s->gb);



                ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);



                for (i = 0; i < 2; i++) {

                    mx = ff_h263_decode_motion(s, pred_x, s->f_code);

                    if (mx >= 0xffff)

                        return -1;



                    my = ff_h263_decode_motion(s, pred_y / 2, s->f_code);

                    if (my >= 0xffff)

                        return -1;



                    s->mv[0][i][0] = mx;

                    s->mv[0][i][1] = my;


            } else {

                s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;

                

                s->mv_type = MV_TYPE_16X16;

                ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);

                mx = ff_h263_decode_motion(s, pred_x, s->f_code);



                if (mx >= 0xffff)

                    return -1;



                my = ff_h263_decode_motion(s, pred_y, s->f_code);



                if (my >= 0xffff)

                    return -1;

                s->mv[0][0][0] = mx;

                s->mv[0][0][1] = my;


        } else {

            s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;

            s->mv_type                     = MV_TYPE_8X8;

            for (i = 0; i < 4; i++) {

                mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);

                mx      = ff_h263_decode_motion(s, pred_x, s->f_code);

                if (mx >= 0xffff)

                    return -1;



                my = ff_h263_decode_motion(s, pred_y, s->f_code);

                if (my >= 0xffff)

                    return -1;

                s->mv[0][i][0] = mx;

                s->mv[0][i][1] = my;

                mot_val[0]     = mx;

                mot_val[1]     = my;



    } else if (s->pict_type == AV_PICTURE_TYPE_B) {

        int modb1;   

        int modb2;   

        int mb_type;



        s->mb_intra = 0;  

        s->mcsel    = 0;  



        if (s->mb_x == 0) {

            for (i = 0; i < 2; i++) {

                s->last_mv[i][0][0] =

                s->last_mv[i][0][1] =

                s->last_mv[i][1][0] =

                s->last_mv[i][1][1] = 0;




            ff_thread_await_progress(&s->next_picture_ptr->tf, s->mb_y, 0);




        

        s->mb_skipped = s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x];  



        if (s->mb_skipped) {

            

            for (i = 0; i < 6; i++)

                s->block_last_index[i] = -1;



            s->mv_dir      = MV_DIR_FORWARD;

            s->mv_type     = MV_TYPE_16X16;

            s->mv[0][0][0] =

            s->mv[0][0][1] =

            s->mv[1][0][0] =

            s->mv[1][0][1] = 0;

            s->current_picture.mb_type[xy] = MB_TYPE_SKIP  |

                                             MB_TYPE_16x16 |

                                             MB_TYPE_L0;

            goto end;




        modb1 = get_bits1(&s->gb);

        if (modb1) {

            

            mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1;

            cbp     = 0;

        } else {

            modb2   = get_bits1(&s->gb);

            mb_type = get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1);

            if (mb_type < 0) {

                av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n");

                return -1;


            mb_type = mb_type_b_map[mb_type];

            if (modb2) {

                cbp = 0;

            } else {

                s->bdsp.clear_blocks(s->block[0]);

                cbp = get_bits(&s->gb, 6);




            if ((!IS_DIRECT(mb_type)) && cbp) {

                if (get_bits1(&s->gb))

                    ff_set_qscale(s, s->qscale + get_bits1(&s->gb) * 4 - 2);




            if (!s->progressive_sequence) {

                if (cbp)

                    s->interlaced_dct = get_bits1(&s->gb);



                if (!IS_DIRECT(mb_type) && get_bits1(&s->gb)) {

                    mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;

                    mb_type &= ~MB_TYPE_16x16;



                    if (USES_LIST(mb_type, 0)) {

                        s->field_select[0][0] = get_bits1(&s->gb);

                        s->field_select[0][1] = get_bits1(&s->gb);


                    if (USES_LIST(mb_type, 1)) {

                        s->field_select[1][0] = get_bits1(&s->gb);

                        s->field_select[1][1] = get_bits1(&s->gb);






            s->mv_dir = 0;

            if ((mb_type & (MB_TYPE_DIRECT2 | MB_TYPE_INTERLACED)) == 0) {

                s->mv_type = MV_TYPE_16X16;



                if (USES_LIST(mb_type, 0)) {

                    s->mv_dir = MV_DIR_FORWARD;



                    mx = ff_h263_decode_motion(s, s->last_mv[0][0][0], s->f_code);

                    my = ff_h263_decode_motion(s, s->last_mv[0][0][1], s->f_code);

                    s->last_mv[0][1][0] =

                    s->last_mv[0][0][0] =

                    s->mv[0][0][0]      = mx;

                    s->last_mv[0][1][1] =

                    s->last_mv[0][0][1] =

                    s->mv[0][0][1]      = my;




                if (USES_LIST(mb_type, 1)) {

                    s->mv_dir |= MV_DIR_BACKWARD;



                    mx = ff_h263_decode_motion(s, s->last_mv[1][0][0], s->b_code);

                    my = ff_h263_decode_motion(s, s->last_mv[1][0][1], s->b_code);

                    s->last_mv[1][1][0] =

                    s->last_mv[1][0][0] =

                    s->mv[1][0][0]      = mx;

                    s->last_mv[1][1][1] =

                    s->last_mv[1][0][1] =

                    s->mv[1][0][1]      = my;


            } else if (!IS_DIRECT(mb_type)) {

                s->mv_type = MV_TYPE_FIELD;



                if (USES_LIST(mb_type, 0)) {

                    s->mv_dir = MV_DIR_FORWARD;



                    for (i = 0; i < 2; i++) {

                        mx = ff_h263_decode_motion(s, s->last_mv[0][i][0], s->f_code);

                        my = ff_h263_decode_motion(s, s->last_mv[0][i][1] / 2, s->f_code);

                        s->last_mv[0][i][0] =

                        s->mv[0][i][0]      = mx;

                        s->last_mv[0][i][1] = (s->mv[0][i][1] = my) * 2;





                if (USES_LIST(mb_type, 1)) {

                    s->mv_dir |= MV_DIR_BACKWARD;



                    for (i = 0; i < 2; i++) {

                        mx = ff_h263_decode_motion(s, s->last_mv[1][i][0], s->b_code);

                        my = ff_h263_decode_motion(s, s->last_mv[1][i][1] / 2, s->b_code);

                        s->last_mv[1][i][0] =

                        s->mv[1][i][0]      = mx;

                        s->last_mv[1][i][1] = (s->mv[1][i][1] = my) * 2;







        if (IS_DIRECT(mb_type)) {

            if (IS_SKIP(mb_type)) {

                mx =

                my = 0;

            } else {

                mx = ff_h263_decode_motion(s, 0, 1);

                my = ff_h263_decode_motion(s, 0, 1);




            s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;

            mb_type  |= ff_mpeg4_set_direct_mv(s, mx, my);


        s->current_picture.mb_type[xy] = mb_type;

    } else { 

        do {

            cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);

            if (cbpc < 0) {


                       "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);

                return -1;


        } while (cbpc == 8);



        dquant = cbpc & 4;

        s->mb_intra = 1;



intra:

        s->ac_pred = get_bits1(&s->gb);

        if (s->ac_pred)

            s->current_picture.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;

        else

            s->current_picture.mb_type[xy] = MB_TYPE_INTRA;



        cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);



                   "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);

            return -1;


        cbp = (cbpc & 3) | (cbpy << 2);



        ctx->use_intra_dc_vlc = s->qscale < ctx->intra_dc_threshold;



        if (dquant)

            ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);



        if (!s->progressive_sequence)

            s->interlaced_dct = get_bits1(&s->gb);



        s->bdsp.clear_blocks(s->block[0]);

        

        for (i = 0; i < 6; i++) {

            if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, 1, 0) < 0)

                return -1;

            cbp += cbp;


        goto end;




    

    for (i = 0; i < 6; i++) {

        if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, 0, 0) < 0)

            return -1;

        cbp += cbp;




end:

    

    if (s->codec_id == AV_CODEC_ID_MPEG4) {

        int next = mpeg4_is_resync(ctx);

        if (next) {

            if        (s->mb_x + s->mb_y*s->mb_width + 1 >  next && (s->avctx->err_recognition & AV_EF_AGGRESSIVE)) {

                return -1;

            } else if (s->mb_x + s->mb_y*s->mb_width + 1 >= next)

                return SLICE_END;



            if (s->pict_type == AV_PICTURE_TYPE_B) {

                const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;

                ff_thread_await_progress(&s->next_picture_ptr->tf,

                                         (s->mb_x + delta >= s->mb_width)

                                         ? FFMIN(s->mb_y + 1, s->mb_height - 1)

                                         : s->mb_y, 0);

                if (s->next_picture.mbskip_table[xy + delta])

                    return SLICE_OK;




            return SLICE_END;





    return SLICE_OK;

static int FUNC_0(MpegEncContext *VAR_0, int16_t VAR_1[6][64])

{

    Mpeg4DecContext *ctx = (Mpeg4DecContext *)VAR_0;

    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10;

    int16_t *mot_val;

    static const int8_t VAR_11[4] = { -1, -2, 1, 2 };

    const int VAR_12 = VAR_0->mb_x + VAR_0->mb_y * VAR_0->mb_stride;



    av_assert2(VAR_0->h263_pred);



    if (VAR_0->pict_type == AV_PICTURE_TYPE_P ||

        VAR_0->pict_type == AV_PICTURE_TYPE_S) {

        do {

            if (get_bits1(&VAR_0->gb)) {

                

                VAR_0->mb_intra = 0;

                for (VAR_4 = 0; VAR_4 < 6; VAR_4++)

                    VAR_0->block_last_index[VAR_4] = -1;

                VAR_0->mv_dir  = MV_DIR_FORWARD;

                VAR_0->mv_type = MV_TYPE_16X16;

                if (VAR_0->pict_type == AV_PICTURE_TYPE_S &&

                    ctx->vol_sprite_usage == GMC_SPRITE) {

                    VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_SKIP  |

                                                     MB_TYPE_GMC   |

                                                     MB_TYPE_16x16 |

                                                     MB_TYPE_L0;

                    VAR_0->mcsel       = 1;

                    VAR_0->mv[0][0][0] = get_amv(ctx, 0);

                    VAR_0->mv[0][0][1] = get_amv(ctx, 1);

                    VAR_0->mb_skipped  = 0;

                } else {

                    VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_SKIP  |

                                                     MB_TYPE_16x16 |

                                                     MB_TYPE_L0;

                    VAR_0->mcsel       = 0;

                    VAR_0->mv[0][0][0] = 0;

                    VAR_0->mv[0][0][1] = 0;

                    VAR_0->mb_skipped  = 1;


                goto end;


            VAR_2 = get_vlc2(&VAR_0->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);

            if (VAR_2 < 0) {


                       "mcbpc damaged at %d %d\n", VAR_0->mb_x, VAR_0->mb_y);

                return -1;


        } while (VAR_2 == 20);



        VAR_0->bdsp.clear_blocks(VAR_0->VAR_1[0]);

        VAR_10      = VAR_2 & 8;

        VAR_0->mb_intra = ((VAR_2 & 4) != 0);

        if (VAR_0->mb_intra)

            goto intra;



        if (VAR_0->pict_type == AV_PICTURE_TYPE_S &&

            ctx->vol_sprite_usage == GMC_SPRITE && (VAR_2 & 16) == 0)

            VAR_0->mcsel = get_bits1(&VAR_0->gb);

        else

            VAR_0->mcsel = 0;

        VAR_3 = get_vlc2(&VAR_0->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1) ^ 0x0F;








        VAR_5 = (VAR_2 & 3) | (VAR_3 << 2);

        if (VAR_10)

            ff_set_qscale(VAR_0, VAR_0->qscale + VAR_11[get_bits(&VAR_0->gb, 2)]);

        if ((!VAR_0->progressive_sequence) &&

            (VAR_5 || (VAR_0->workaround_bugs & FF_BUG_XVID_ILACE)))

            VAR_0->interlaced_dct = get_bits1(&VAR_0->gb);



        VAR_0->mv_dir = MV_DIR_FORWARD;

        if ((VAR_2 & 16) == 0) {

            if (VAR_0->mcsel) {

                VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_GMC   |

                                                 MB_TYPE_16x16 |

                                                 MB_TYPE_L0;

                

                VAR_0->mv_type     = MV_TYPE_16X16;

                VAR_8             = get_amv(ctx, 0);

                VAR_9             = get_amv(ctx, 1);

                VAR_0->mv[0][0][0] = VAR_8;

                VAR_0->mv[0][0][1] = VAR_9;

            } else if ((!VAR_0->progressive_sequence) && get_bits1(&VAR_0->gb)) {

                VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_16x8 |

                                                 MB_TYPE_L0   |

                                                 MB_TYPE_INTERLACED;

                

                VAR_0->mv_type = MV_TYPE_FIELD;



                VAR_0->field_select[0][0] = get_bits1(&VAR_0->gb);

                VAR_0->field_select[0][1] = get_bits1(&VAR_0->gb);



                ff_h263_pred_motion(VAR_0, 0, 0, &VAR_6, &VAR_7);



                for (VAR_4 = 0; VAR_4 < 2; VAR_4++) {

                    VAR_8 = ff_h263_decode_motion(VAR_0, VAR_6, VAR_0->f_code);

                    if (VAR_8 >= 0xffff)

                        return -1;



                    VAR_9 = ff_h263_decode_motion(VAR_0, VAR_7 / 2, VAR_0->f_code);

                    if (VAR_9 >= 0xffff)

                        return -1;



                    VAR_0->mv[0][VAR_4][0] = VAR_8;

                    VAR_0->mv[0][VAR_4][1] = VAR_9;


            } else {

                VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_16x16 | MB_TYPE_L0;

                

                VAR_0->mv_type = MV_TYPE_16X16;

                ff_h263_pred_motion(VAR_0, 0, 0, &VAR_6, &VAR_7);

                VAR_8 = ff_h263_decode_motion(VAR_0, VAR_6, VAR_0->f_code);



                if (VAR_8 >= 0xffff)

                    return -1;



                VAR_9 = ff_h263_decode_motion(VAR_0, VAR_7, VAR_0->f_code);



                if (VAR_9 >= 0xffff)

                    return -1;

                VAR_0->mv[0][0][0] = VAR_8;

                VAR_0->mv[0][0][1] = VAR_9;


        } else {

            VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_8x8 | MB_TYPE_L0;

            VAR_0->mv_type                     = MV_TYPE_8X8;

            for (VAR_4 = 0; VAR_4 < 4; VAR_4++) {

                mot_val = ff_h263_pred_motion(VAR_0, VAR_4, 0, &VAR_6, &VAR_7);

                VAR_8      = ff_h263_decode_motion(VAR_0, VAR_6, VAR_0->f_code);

                if (VAR_8 >= 0xffff)

                    return -1;



                VAR_9 = ff_h263_decode_motion(VAR_0, VAR_7, VAR_0->f_code);

                if (VAR_9 >= 0xffff)

                    return -1;

                VAR_0->mv[0][VAR_4][0] = VAR_8;

                VAR_0->mv[0][VAR_4][1] = VAR_9;

                mot_val[0]     = VAR_8;

                mot_val[1]     = VAR_9;



    } else if (VAR_0->pict_type == AV_PICTURE_TYPE_B) {

        int modb1;   

        int modb2;   

        int mb_type;



        VAR_0->mb_intra = 0;  

        VAR_0->mcsel    = 0;  



        if (VAR_0->mb_x == 0) {

            for (VAR_4 = 0; VAR_4 < 2; VAR_4++) {

                VAR_0->last_mv[VAR_4][0][0] =

                VAR_0->last_mv[VAR_4][0][1] =

                VAR_0->last_mv[VAR_4][1][0] =

                VAR_0->last_mv[VAR_4][1][1] = 0;




            ff_thread_await_progress(&VAR_0->next_picture_ptr->tf, VAR_0->mb_y, 0);




        

        VAR_0->mb_skipped = VAR_0->next_picture.mbskip_table[VAR_0->mb_y * VAR_0->mb_stride + VAR_0->mb_x];  



        if (VAR_0->mb_skipped) {

            

            for (VAR_4 = 0; VAR_4 < 6; VAR_4++)

                VAR_0->block_last_index[VAR_4] = -1;



            VAR_0->mv_dir      = MV_DIR_FORWARD;

            VAR_0->mv_type     = MV_TYPE_16X16;

            VAR_0->mv[0][0][0] =

            VAR_0->mv[0][0][1] =

            VAR_0->mv[1][0][0] =

            VAR_0->mv[1][0][1] = 0;

            VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_SKIP  |

                                             MB_TYPE_16x16 |

                                             MB_TYPE_L0;

            goto end;




        modb1 = get_bits1(&VAR_0->gb);

        if (modb1) {

            

            mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1;

            VAR_5     = 0;

        } else {

            modb2   = get_bits1(&VAR_0->gb);

            mb_type = get_vlc2(&VAR_0->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1);

            if (mb_type < 0) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal MB_type\n");

                return -1;


            mb_type = mb_type_b_map[mb_type];

            if (modb2) {

                VAR_5 = 0;

            } else {

                VAR_0->bdsp.clear_blocks(VAR_0->VAR_1[0]);

                VAR_5 = get_bits(&VAR_0->gb, 6);




            if ((!IS_DIRECT(mb_type)) && VAR_5) {

                if (get_bits1(&VAR_0->gb))

                    ff_set_qscale(VAR_0, VAR_0->qscale + get_bits1(&VAR_0->gb) * 4 - 2);




            if (!VAR_0->progressive_sequence) {

                if (VAR_5)

                    VAR_0->interlaced_dct = get_bits1(&VAR_0->gb);



                if (!IS_DIRECT(mb_type) && get_bits1(&VAR_0->gb)) {

                    mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;

                    mb_type &= ~MB_TYPE_16x16;



                    if (USES_LIST(mb_type, 0)) {

                        VAR_0->field_select[0][0] = get_bits1(&VAR_0->gb);

                        VAR_0->field_select[0][1] = get_bits1(&VAR_0->gb);


                    if (USES_LIST(mb_type, 1)) {

                        VAR_0->field_select[1][0] = get_bits1(&VAR_0->gb);

                        VAR_0->field_select[1][1] = get_bits1(&VAR_0->gb);






            VAR_0->mv_dir = 0;

            if ((mb_type & (MB_TYPE_DIRECT2 | MB_TYPE_INTERLACED)) == 0) {

                VAR_0->mv_type = MV_TYPE_16X16;



                if (USES_LIST(mb_type, 0)) {

                    VAR_0->mv_dir = MV_DIR_FORWARD;



                    VAR_8 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[0][0][0], VAR_0->f_code);

                    VAR_9 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[0][0][1], VAR_0->f_code);

                    VAR_0->last_mv[0][1][0] =

                    VAR_0->last_mv[0][0][0] =

                    VAR_0->mv[0][0][0]      = VAR_8;

                    VAR_0->last_mv[0][1][1] =

                    VAR_0->last_mv[0][0][1] =

                    VAR_0->mv[0][0][1]      = VAR_9;




                if (USES_LIST(mb_type, 1)) {

                    VAR_0->mv_dir |= MV_DIR_BACKWARD;



                    VAR_8 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[1][0][0], VAR_0->b_code);

                    VAR_9 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[1][0][1], VAR_0->b_code);

                    VAR_0->last_mv[1][1][0] =

                    VAR_0->last_mv[1][0][0] =

                    VAR_0->mv[1][0][0]      = VAR_8;

                    VAR_0->last_mv[1][1][1] =

                    VAR_0->last_mv[1][0][1] =

                    VAR_0->mv[1][0][1]      = VAR_9;


            } else if (!IS_DIRECT(mb_type)) {

                VAR_0->mv_type = MV_TYPE_FIELD;



                if (USES_LIST(mb_type, 0)) {

                    VAR_0->mv_dir = MV_DIR_FORWARD;



                    for (VAR_4 = 0; VAR_4 < 2; VAR_4++) {

                        VAR_8 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[0][VAR_4][0], VAR_0->f_code);

                        VAR_9 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[0][VAR_4][1] / 2, VAR_0->f_code);

                        VAR_0->last_mv[0][VAR_4][0] =

                        VAR_0->mv[0][VAR_4][0]      = VAR_8;

                        VAR_0->last_mv[0][VAR_4][1] = (VAR_0->mv[0][VAR_4][1] = VAR_9) * 2;





                if (USES_LIST(mb_type, 1)) {

                    VAR_0->mv_dir |= MV_DIR_BACKWARD;



                    for (VAR_4 = 0; VAR_4 < 2; VAR_4++) {

                        VAR_8 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[1][VAR_4][0], VAR_0->b_code);

                        VAR_9 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[1][VAR_4][1] / 2, VAR_0->b_code);

                        VAR_0->last_mv[1][VAR_4][0] =

                        VAR_0->mv[1][VAR_4][0]      = VAR_8;

                        VAR_0->last_mv[1][VAR_4][1] = (VAR_0->mv[1][VAR_4][1] = VAR_9) * 2;







        if (IS_DIRECT(mb_type)) {

            if (IS_SKIP(mb_type)) {

                VAR_8 =

                VAR_9 = 0;

            } else {

                VAR_8 = ff_h263_decode_motion(VAR_0, 0, 1);

                VAR_9 = ff_h263_decode_motion(VAR_0, 0, 1);




            VAR_0->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;

            mb_type  |= ff_mpeg4_set_direct_mv(VAR_0, VAR_8, VAR_9);


        VAR_0->current_picture.mb_type[VAR_12] = mb_type;

    } else { 

        do {

            VAR_2 = get_vlc2(&VAR_0->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);

            if (VAR_2 < 0) {


                       "I VAR_2 damaged at %d %d\n", VAR_0->mb_x, VAR_0->mb_y);

                return -1;


        } while (VAR_2 == 8);



        VAR_10 = VAR_2 & 4;

        VAR_0->mb_intra = 1;



intra:

        VAR_0->ac_pred = get_bits1(&VAR_0->gb);

        if (VAR_0->ac_pred)

            VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_INTRA | MB_TYPE_ACPRED;

        else

            VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_INTRA;



        VAR_3 = get_vlc2(&VAR_0->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);



                   "I VAR_3 damaged at %d %d\n", VAR_0->mb_x, VAR_0->mb_y);

            return -1;


        VAR_5 = (VAR_2 & 3) | (VAR_3 << 2);



        ctx->use_intra_dc_vlc = VAR_0->qscale < ctx->intra_dc_threshold;



        if (VAR_10)

            ff_set_qscale(VAR_0, VAR_0->qscale + VAR_11[get_bits(&VAR_0->gb, 2)]);



        if (!VAR_0->progressive_sequence)

            VAR_0->interlaced_dct = get_bits1(&VAR_0->gb);



        VAR_0->bdsp.clear_blocks(VAR_0->VAR_1[0]);

        

        for (VAR_4 = 0; VAR_4 < 6; VAR_4++) {

            if (mpeg4_decode_block(ctx, VAR_1[VAR_4], VAR_4, VAR_5 & 32, 1, 0) < 0)

                return -1;

            VAR_5 += VAR_5;


        goto end;




    

    for (VAR_4 = 0; VAR_4 < 6; VAR_4++) {

        if (mpeg4_decode_block(ctx, VAR_1[VAR_4], VAR_4, VAR_5 & 32, 0, 0) < 0)

            return -1;

        VAR_5 += VAR_5;




end:

    

    if (VAR_0->codec_id == AV_CODEC_ID_MPEG4) {

        int next = mpeg4_is_resync(ctx);

        if (next) {

            if        (VAR_0->mb_x + VAR_0->mb_y*VAR_0->mb_width + 1 >  next && (VAR_0->avctx->err_recognition & AV_EF_AGGRESSIVE)) {

                return -1;

            } else if (VAR_0->mb_x + VAR_0->mb_y*VAR_0->mb_width + 1 >= next)

                return SLICE_END;



            if (VAR_0->pict_type == AV_PICTURE_TYPE_B) {

                const int delta= VAR_0->mb_x + 1 == VAR_0->mb_width ? 2 : 1;

                ff_thread_await_progress(&VAR_0->next_picture_ptr->tf,

                                         (VAR_0->mb_x + delta >= VAR_0->mb_width)

                                         ? FFMIN(VAR_0->mb_y + 1, VAR_0->mb_height - 1)

                                         : VAR_0->mb_y, 0);

                if (VAR_0->next_picture.mbskip_table[VAR_12 + delta])

                    return SLICE_OK;




            return SLICE_END;





    return SLICE_OK;

static int FUNC_0(MpegEncContext *VAR_0, int16_t VAR_1[6][64])
{ Mpeg4DecContext *ctx = (Mpeg4DecContext *)VAR_0; int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10; int16_t *mot_val; static const int8_t VAR_11[4] = { -1, -2, 1, 2 }; const int VAR_12 = VAR_0->mb_x + VAR_0->mb_y * VAR_0->mb_stride; av_assert2(VAR_0->h263_pred); if (VAR_0->pict_type == AV_PICTURE_TYPE_P ||
VAR_0->pict_type == AV_PICTURE_TYPE_S) { do { if (get_bits1(&VAR_0->gb)) { VAR_0->mb_intra = 0; for (VAR_4 = 0; VAR_4 < 6; VAR_4++) VAR_0->block_last_index[VAR_4] = -1; VAR_0->mv_dir  = MV_DIR_FORWARD; VAR_0->mv_type = MV_TYPE_16X16; if (VAR_0->pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE) { VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_SKIP  |
MB_TYPE_GMC   |
MB_TYPE_16x16 |
MB_TYPE_L0; VAR_0->mcsel       = 1; VAR_0->mv[0][0][0] = get_amv(ctx, 0); VAR_0->mv[0][0][1] = get_amv(ctx, 1); VAR_0->mb_skipped  = 0; } else { VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_SKIP  |
MB_TYPE_16x16 |
MB_TYPE_L0; VAR_0->mcsel       = 0; VAR_0->mv[0][0][0] = 0; VAR_0->mv[0][0][1] = 0; VAR_0->mb_skipped  = 1; goto end; VAR_2 = get_vlc2(&VAR_0->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); if (VAR_2 < 0) { "mcbpc damaged at %d %d\n", VAR_0->mb_x, VAR_0->mb_y); return -1; } while (VAR_2 == 20); VAR_0->bdsp.clear_blocks(VAR_0->VAR_1[0]); VAR_10      = VAR_2 & 8; VAR_0->mb_intra = ((VAR_2 & 4) != 0); if (VAR_0->mb_intra)
goto intra; if (VAR_0->pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE && (VAR_2 & 16) == 0)
VAR_0->mcsel = get_bits1(&VAR_0->gb); else
VAR_0->mcsel = 0; VAR_3 = get_vlc2(&VAR_0->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1) ^ 0x0F; VAR_5 = (VAR_2 & 3) | (VAR_3 << 2); if (VAR_10)
ff_set_qscale(VAR_0, VAR_0->qscale + VAR_11[get_bits(&VAR_0->gb, 2)]); if ((!VAR_0->progressive_sequence) &&
(VAR_5 || (VAR_0->workaround_bugs & FF_BUG_XVID_ILACE)))
VAR_0->interlaced_dct = get_bits1(&VAR_0->gb); VAR_0->mv_dir = MV_DIR_FORWARD; if ((VAR_2 & 16) == 0) { if (VAR_0->mcsel) { VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_GMC   |
MB_TYPE_16x16 |
MB_TYPE_L0; VAR_0->mv_type     = MV_TYPE_16X16; VAR_8             = get_amv(ctx, 0); VAR_9             = get_amv(ctx, 1); VAR_0->mv[0][0][0] = VAR_8; VAR_0->mv[0][0][1] = VAR_9; } else if ((!VAR_0->progressive_sequence) && get_bits1(&VAR_0->gb)) { VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_16x8 |
MB_TYPE_L0   |
MB_TYPE_INTERLACED; VAR_0->mv_type = MV_TYPE_FIELD; VAR_0->field_select[0][0] = get_bits1(&VAR_0->gb); VAR_0->field_select[0][1] = get_bits1(&VAR_0->gb); ff_h263_pred_motion(VAR_0, 0, 0, &VAR_6, &VAR_7); for (VAR_4 = 0; VAR_4 < 2; VAR_4++) { VAR_8 = ff_h263_decode_motion(VAR_0, VAR_6, VAR_0->f_code); if (VAR_8 >= 0xffff)
return -1; VAR_9 = ff_h263_decode_motion(VAR_0, VAR_7 / 2, VAR_0->f_code); if (VAR_9 >= 0xffff)
return -1; VAR_0->mv[0][VAR_4][0] = VAR_8; VAR_0->mv[0][VAR_4][1] = VAR_9; } else { VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_16x16 | MB_TYPE_L0; VAR_0->mv_type = MV_TYPE_16X16; ff_h263_pred_motion(VAR_0, 0, 0, &VAR_6, &VAR_7); VAR_8 = ff_h263_decode_motion(VAR_0, VAR_6, VAR_0->f_code); if (VAR_8 >= 0xffff)
return -1; VAR_9 = ff_h263_decode_motion(VAR_0, VAR_7, VAR_0->f_code); if (VAR_9 >= 0xffff)
return -1; VAR_0->mv[0][0][0] = VAR_8; VAR_0->mv[0][0][1] = VAR_9; } else { VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_8x8 | MB_TYPE_L0; VAR_0->mv_type                     = MV_TYPE_8X8; for (VAR_4 = 0; VAR_4 < 4; VAR_4++) { mot_val = ff_h263_pred_motion(VAR_0, VAR_4, 0, &VAR_6, &VAR_7); VAR_8      = ff_h263_decode_motion(VAR_0, VAR_6, VAR_0->f_code); if (VAR_8 >= 0xffff)
return -1; VAR_9 = ff_h263_decode_motion(VAR_0, VAR_7, VAR_0->f_code); if (VAR_9 >= 0xffff)
return -1; VAR_0->mv[0][VAR_4][0] = VAR_8; VAR_0->mv[0][VAR_4][1] = VAR_9; mot_val[0]     = VAR_8; mot_val[1]     = VAR_9; } else if (VAR_0->pict_type == AV_PICTURE_TYPE_B) { int modb1; int modb2; int mb_type; VAR_0->mb_intra = 0; VAR_0->mcsel    = 0; if (VAR_0->mb_x == 0) { for (VAR_4 = 0; VAR_4 < 2; VAR_4++) { VAR_0->last_mv[VAR_4][0][0] =
VAR_0->last_mv[VAR_4][0][1] =
VAR_0->last_mv[VAR_4][1][0] =
VAR_0->last_mv[VAR_4][1][1] = 0; ff_thread_await_progress(&VAR_0->next_picture_ptr->tf, VAR_0->mb_y, 0); VAR_0->mb_skipped = VAR_0->next_picture.mbskip_table[VAR_0->mb_y * VAR_0->mb_stride + VAR_0->mb_x]; if (VAR_0->mb_skipped) { for (VAR_4 = 0; VAR_4 < 6; VAR_4++) VAR_0->block_last_index[VAR_4] = -1; VAR_0->mv_dir      = MV_DIR_FORWARD; VAR_0->mv_type     = MV_TYPE_16X16; VAR_0->mv[0][0][0] =
VAR_0->mv[0][0][1] =
VAR_0->mv[1][0][0] =
VAR_0->mv[1][0][1] = 0; VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_SKIP  |
MB_TYPE_16x16 |
MB_TYPE_L0; goto end; modb1 = get_bits1(&VAR_0->gb); if (modb1) { mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1; VAR_5     = 0; } else { modb2   = get_bits1(&VAR_0->gb); mb_type = get_vlc2(&VAR_0->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1); if (mb_type < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal MB_type\n"); return -1; mb_type = mb_type_b_map[mb_type]; if (modb2) { VAR_5 = 0; } else { VAR_0->bdsp.clear_blocks(VAR_0->VAR_1[0]); VAR_5 = get_bits(&VAR_0->gb, 6); if ((!IS_DIRECT(mb_type)) && VAR_5) { if (get_bits1(&VAR_0->gb))
ff_set_qscale(VAR_0, VAR_0->qscale + get_bits1(&VAR_0->gb) * 4 - 2); if (!VAR_0->progressive_sequence) { if (VAR_5)
VAR_0->interlaced_dct = get_bits1(&VAR_0->gb); if (!IS_DIRECT(mb_type) && get_bits1(&VAR_0->gb)) { mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; mb_type &= ~MB_TYPE_16x16; if (USES_LIST(mb_type, 0)) { VAR_0->field_select[0][0] = get_bits1(&VAR_0->gb); VAR_0->field_select[0][1] = get_bits1(&VAR_0->gb); if (USES_LIST(mb_type, 1)) { VAR_0->field_select[1][0] = get_bits1(&VAR_0->gb); VAR_0->field_select[1][1] = get_bits1(&VAR_0->gb); VAR_0->mv_dir = 0; if ((mb_type & (MB_TYPE_DIRECT2 | MB_TYPE_INTERLACED)) == 0) { VAR_0->mv_type = MV_TYPE_16X16; if (USES_LIST(mb_type, 0)) { VAR_0->mv_dir = MV_DIR_FORWARD; VAR_8 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[0][0][0], VAR_0->f_code); VAR_9 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[0][0][1], VAR_0->f_code); VAR_0->last_mv[0][1][0] =
VAR_0->last_mv[0][0][0] =
VAR_0->mv[0][0][0]      = VAR_8; VAR_0->last_mv[0][1][1] =
VAR_0->last_mv[0][0][1] =
VAR_0->mv[0][0][1]      = VAR_9; if (USES_LIST(mb_type, 1)) { VAR_0->mv_dir |= MV_DIR_BACKWARD; VAR_8 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[1][0][0], VAR_0->b_code); VAR_9 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[1][0][1], VAR_0->b_code); VAR_0->last_mv[1][1][0] =
VAR_0->last_mv[1][0][0] =
VAR_0->mv[1][0][0]      = VAR_8; VAR_0->last_mv[1][1][1] =
VAR_0->last_mv[1][0][1] =
VAR_0->mv[1][0][1]      = VAR_9; } else if (!IS_DIRECT(mb_type)) { VAR_0->mv_type = MV_TYPE_FIELD; if (USES_LIST(mb_type, 0)) { VAR_0->mv_dir = MV_DIR_FORWARD; for (VAR_4 = 0; VAR_4 < 2; VAR_4++) { VAR_8 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[0][VAR_4][0], VAR_0->f_code); VAR_9 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[0][VAR_4][1] / 2, VAR_0->f_code); VAR_0->last_mv[0][VAR_4][0] =
VAR_0->mv[0][VAR_4][0]      = VAR_8; VAR_0->last_mv[0][VAR_4][1] = (VAR_0->mv[0][VAR_4][1] = VAR_9) * 2; if (USES_LIST(mb_type, 1)) { VAR_0->mv_dir |= MV_DIR_BACKWARD; for (VAR_4 = 0; VAR_4 < 2; VAR_4++) { VAR_8 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[1][VAR_4][0], VAR_0->b_code); VAR_9 = ff_h263_decode_motion(VAR_0, VAR_0->last_mv[1][VAR_4][1] / 2, VAR_0->b_code); VAR_0->last_mv[1][VAR_4][0] =
VAR_0->mv[1][VAR_4][0]      = VAR_8; VAR_0->last_mv[1][VAR_4][1] = (VAR_0->mv[1][VAR_4][1] = VAR_9) * 2; if (IS_DIRECT(mb_type)) { if (IS_SKIP(mb_type)) { VAR_8 =
VAR_9 = 0; } else { VAR_8 = ff_h263_decode_motion(VAR_0, 0, 1); VAR_9 = ff_h263_decode_motion(VAR_0, 0, 1); VAR_0->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; mb_type  |= ff_mpeg4_set_direct_mv(VAR_0, VAR_8, VAR_9); VAR_0->current_picture.mb_type[VAR_12] = mb_type; } else { do { VAR_2 = get_vlc2(&VAR_0->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); if (VAR_2 < 0) { "I VAR_2 damaged at %d %d\n", VAR_0->mb_x, VAR_0->mb_y); return -1; } while (VAR_2 == 8); VAR_10 = VAR_2 & 4; VAR_0->mb_intra = 1; intra:
VAR_0->ac_pred = get_bits1(&VAR_0->gb); if (VAR_0->ac_pred)
VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_INTRA | MB_TYPE_ACPRED; else
VAR_0->current_picture.mb_type[VAR_12] = MB_TYPE_INTRA; VAR_3 = get_vlc2(&VAR_0->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); "I VAR_3 damaged at %d %d\n", VAR_0->mb_x, VAR_0->mb_y); return -1; VAR_5 = (VAR_2 & 3) | (VAR_3 << 2); ctx->use_intra_dc_vlc = VAR_0->qscale < ctx->intra_dc_threshold; if (VAR_10)
ff_set_qscale(VAR_0, VAR_0->qscale + VAR_11[get_bits(&VAR_0->gb, 2)]); if (!VAR_0->progressive_sequence)
VAR_0->interlaced_dct = get_bits1(&VAR_0->gb); VAR_0->bdsp.clear_blocks(VAR_0->VAR_1[0]); for (VAR_4 = 0; VAR_4 < 6; VAR_4++) { if (mpeg4_decode_block(ctx, VAR_1[VAR_4], VAR_4, VAR_5 & 32, 1, 0) < 0)
return -1; VAR_5 += VAR_5; goto end; for (VAR_4 = 0; VAR_4 < 6; VAR_4++) { if (mpeg4_decode_block(ctx, VAR_1[VAR_4], VAR_4, VAR_5 & 32, 0, 0) < 0)
return -1; VAR_5 += VAR_5; end:
if (VAR_0->codec_id == AV_CODEC_ID_MPEG4) { int next = mpeg4_is_resync(ctx); if (next) { if        (VAR_0->mb_x + VAR_0->mb_y*VAR_0->mb_width + 1 >  next && (VAR_0->avctx->err_recognition & AV_EF_AGGRESSIVE)) { return -1; } else if (VAR_0->mb_x + VAR_0->mb_y*VAR_0->mb_width + 1 >= next) return SLICE_END; if (VAR_0->pict_type == AV_PICTURE_TYPE_B) { const int delta= VAR_0->mb_x + 1 == VAR_0->mb_width ? 2 : 1; ff_thread_await_progress(&VAR_0->next_picture_ptr->tf,
(VAR_0->mb_x + delta >= VAR_0->mb_width)
? FFMIN(VAR_0->mb_y + 1, VAR_0->mb_height - 1)
: VAR_0->mb_y, 0); if (VAR_0->next_picture.mbskip_table[VAR_12 + delta])
return SLICE_OK; return SLICE_END; return SLICE_OK;