int h263_decode_mb(MpegEncContext *s,

                   DCTELEM block[6][64])

{

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

    unsigned int val;

    INT16 *mot_val;

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

        

    /* Check for GOB Start Code */

    val = show_bits(&s->gb, 16);

    

    if (val == 0) {

        /* We have a GBSC probably with GSTUFF */

#ifdef DEBUG

        unsigned int gn, gfid;

#endif

        //skip_bits(&s->gb, 16); /* Drop the zeros */

        while (get_bits1(&s->gb) == 0); /* Seek the '1' bit */

#ifdef DEBUG

        fprintf(stderr,"\nGOB Start Code at MB %d\n", 

            (s->mb_y * s->mb_width) + s->mb_x);

        gn = get_bits(&s->gb, 5); /* GN */

        gfid = get_bits(&s->gb, 2); /* GFID */

#else

        skip_bits(&s->gb, 5); /* GN */

        skip_bits(&s->gb, 2); /* GFID */

#endif        

        s->qscale = get_bits(&s->gb, 5); /* GQUANT */

#ifdef DEBUG

        fprintf(stderr, "\nGN: %u GFID: %u Quant: %u\n", gn, gfid, s->qscale);

#endif

    }

    

    if (s->pict_type == P_TYPE) {

        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;

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

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

            s->mb_skiped = 1;

            return 0;

        }

        cbpc = get_vlc(&s->gb, &inter_MCBPC_vlc);

        //fprintf(stderr, "\tCBPC: %d", cbpc);

        if (cbpc < 0)

            return -1;

        

        dquant = cbpc & 8;

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

    } else {

        cbpc = get_vlc(&s->gb, &intra_MCBPC_vlc);

        if (cbpc < 0)

            return -1;

        dquant = cbpc & 4;

        s->mb_intra = 1;

    }



    if (!s->mb_intra) {

        cbpy = get_vlc(&s->gb, &cbpy_vlc);

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

        if (dquant) {

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

            if (s->qscale < 1)

                s->qscale = 1;

            else if (s->qscale > 31)

                s->qscale = 31;

        }

        s->mv_dir = MV_DIR_FORWARD;

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

            /* 16x16 motion prediction */

            s->mv_type = MV_TYPE_16X16;

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

            if (s->umvplus_dec)

               mx = h263p_decode_umotion(s, pred_x);

            else

               mx = h263_decode_motion(s, pred_x);

            if (mx >= 0xffff)

                return -1;

            

            if (s->umvplus_dec)

               my = h263p_decode_umotion(s, pred_y);

            else    

               my = h263_decode_motion(s, pred_y);

            if (my >= 0xffff)

                return -1;

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

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

            if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1)

               skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */

                           

        } else {

            s->mv_type = MV_TYPE_8X8;

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

                mot_val = h263_pred_motion(s, i, &pred_x, &pred_y);

                if (s->umvplus_dec)

                  mx = h263p_decode_umotion(s, pred_x);

                else

                  mx = h263_decode_motion(s, pred_x);

                if (mx >= 0xffff)

                    return -1;

                

                if (s->umvplus_dec)

                  my = h263p_decode_umotion(s, pred_y);

                else    

                  my = h263_decode_motion(s, pred_y);

                if (my >= 0xffff)

                    return -1;

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

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

                if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1)

                  skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */

                mot_val[0] = mx;

                mot_val[1] = my;

            }

        }

    } else {

        s->ac_pred = 0;

	    if (s->h263_pred) {

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

        }

        cbpy = get_vlc(&s->gb, &cbpy_vlc);

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

        if (dquant) {

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

            if (s->qscale < 1)

                s->qscale = 1;

            else if (s->qscale > 31)

                s->qscale = 31;

        }

    }



    /* decode each block */

    if (s->h263_pred) {

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

	    if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0)

                return -1;

	}

    } else {

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

	    if (h263_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0)

                return -1;

	}

    }

    return 0;

}

int h263_decode_mb(MpegEncContext *s,

                   DCTELEM block[6][64])

{

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

    unsigned int val;

    INT16 *mot_val;

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

        

    

    val = show_bits(&s->gb, 16);

    

    if (val == 0) {

        

#ifdef DEBUG

        unsigned int gn, gfid;

#endif

        

        while (get_bits1(&s->gb) == 0); 

#ifdef DEBUG

        fprintf(stderr,"\nGOB Start Code at MB %d\n", 

            (s->mb_y * s->mb_width) + s->mb_x);

        gn = get_bits(&s->gb, 5); 

        gfid = get_bits(&s->gb, 2); 

#else

        skip_bits(&s->gb, 5); 

        skip_bits(&s->gb, 2); 

#endif        

        s->qscale = get_bits(&s->gb, 5); 

#ifdef DEBUG

        fprintf(stderr, "\nGN: %u GFID: %u Quant: %u\n", gn, gfid, s->qscale);

#endif

    }

    

    if (s->pict_type == P_TYPE) {

        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;

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

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

            s->mb_skiped = 1;

            return 0;

        }

        cbpc = get_vlc(&s->gb, &inter_MCBPC_vlc);

        

        if (cbpc < 0)

            return -1;

        

        dquant = cbpc & 8;

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

    } else {

        cbpc = get_vlc(&s->gb, &intra_MCBPC_vlc);

        if (cbpc < 0)

            return -1;

        dquant = cbpc & 4;

        s->mb_intra = 1;

    }



    if (!s->mb_intra) {

        cbpy = get_vlc(&s->gb, &cbpy_vlc);

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

        if (dquant) {

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

            if (s->qscale < 1)

                s->qscale = 1;

            else if (s->qscale > 31)

                s->qscale = 31;

        }

        s->mv_dir = MV_DIR_FORWARD;

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

            

            s->mv_type = MV_TYPE_16X16;

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

            if (s->umvplus_dec)

               mx = h263p_decode_umotion(s, pred_x);

            else

               mx = h263_decode_motion(s, pred_x);

            if (mx >= 0xffff)

                return -1;

            

            if (s->umvplus_dec)

               my = h263p_decode_umotion(s, pred_y);

            else    

               my = h263_decode_motion(s, pred_y);

            if (my >= 0xffff)

                return -1;

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

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

            if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1)

               skip_bits1(&s->gb); 

                           

        } else {

            s->mv_type = MV_TYPE_8X8;

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

                mot_val = h263_pred_motion(s, i, &pred_x, &pred_y);

                if (s->umvplus_dec)

                  mx = h263p_decode_umotion(s, pred_x);

                else

                  mx = h263_decode_motion(s, pred_x);

                if (mx >= 0xffff)

                    return -1;

                

                if (s->umvplus_dec)

                  my = h263p_decode_umotion(s, pred_y);

                else    

                  my = h263_decode_motion(s, pred_y);

                if (my >= 0xffff)

                    return -1;

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

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

                if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1)

                  skip_bits1(&s->gb); 

                mot_val[0] = mx;

                mot_val[1] = my;

            }

        }

    } else {

        s->ac_pred = 0;

	    if (s->h263_pred) {

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

        }

        cbpy = get_vlc(&s->gb, &cbpy_vlc);

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

        if (dquant) {

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

            if (s->qscale < 1)

                s->qscale = 1;

            else if (s->qscale > 31)

                s->qscale = 31;

        }

    }



    

    if (s->h263_pred) {

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

	    if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0)

                return -1;

	}

    } else {

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

	    if (h263_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0)

                return -1;

	}

    }

    return 0;

}

#ifdef DEBUG         unsigned int gn, gfid; #endif #else #endif        
int FUNC_0(MpegEncContext *VAR_0,

                   DCTELEM VAR_1[6][64])

{

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

    unsigned int VAR_11;

    INT16 *mot_val;

    static INT8 VAR_12[4] = { -1, -2, 1, 2 };

        

    

    VAR_11 = show_bits(&VAR_0->gb, 16);

    

    if (VAR_11 == 0) {

        

#ifdef DEBUG

        unsigned int gn, gfid;

#endif

        

        while (get_bits1(&VAR_0->gb) == 0); 

#ifdef DEBUG

        fprintf(stderr,"\nGOB Start Code at MB %d\n", 

            (VAR_0->mb_y * VAR_0->mb_width) + VAR_0->mb_x);

        gn = get_bits(&VAR_0->gb, 5); 

        gfid = get_bits(&VAR_0->gb, 2); 

#else

        skip_bits(&VAR_0->gb, 5); 

        skip_bits(&VAR_0->gb, 2); 

#endif        

        VAR_0->qscale = get_bits(&VAR_0->gb, 5); 

#ifdef DEBUG

        fprintf(stderr, "\nGN: %u GFID: %u Quant: %u\n", gn, gfid, VAR_0->qscale);

#endif

    }

    

    if (VAR_0->pict_type == P_TYPE) {

        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;

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

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

            VAR_0->mb_skiped = 1;

            return 0;

        }

        VAR_2 = get_vlc(&VAR_0->gb, &inter_MCBPC_vlc);

        

        if (VAR_2 < 0)

            return -1;

        

        VAR_10 = VAR_2 & 8;

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

    } else {

        VAR_2 = get_vlc(&VAR_0->gb, &intra_MCBPC_vlc);

        if (VAR_2 < 0)

            return -1;

        VAR_10 = VAR_2 & 4;

        VAR_0->mb_intra = 1;

    }



    if (!VAR_0->mb_intra) {

        VAR_3 = get_vlc(&VAR_0->gb, &cbpy_vlc);

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

        if (VAR_10) {

            VAR_0->qscale += VAR_12[get_bits(&VAR_0->gb, 2)];

            if (VAR_0->qscale < 1)

                VAR_0->qscale = 1;

            else if (VAR_0->qscale > 31)

                VAR_0->qscale = 31;

        }

        VAR_0->mv_dir = MV_DIR_FORWARD;

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

            

            VAR_0->mv_type = MV_TYPE_16X16;

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

            if (VAR_0->umvplus_dec)

               VAR_8 = h263p_decode_umotion(VAR_0, VAR_6);

            else

               VAR_8 = h263_decode_motion(VAR_0, VAR_6);

            if (VAR_8 >= 0xffff)

                return -1;

            

            if (VAR_0->umvplus_dec)

               VAR_9 = h263p_decode_umotion(VAR_0, VAR_7);

            else    

               VAR_9 = h263_decode_motion(VAR_0, VAR_7);

            if (VAR_9 >= 0xffff)

                return -1;

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

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

            if (VAR_0->umvplus_dec && (VAR_8 - VAR_6) == 1 && (VAR_9 - VAR_7) == 1)

               skip_bits1(&VAR_0->gb); 

                           

        } else {

            VAR_0->mv_type = MV_TYPE_8X8;

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

                mot_val = h263_pred_motion(VAR_0, VAR_4, &VAR_6, &VAR_7);

                if (VAR_0->umvplus_dec)

                  VAR_8 = h263p_decode_umotion(VAR_0, VAR_6);

                else

                  VAR_8 = h263_decode_motion(VAR_0, VAR_6);

                if (VAR_8 >= 0xffff)

                    return -1;

                

                if (VAR_0->umvplus_dec)

                  VAR_9 = h263p_decode_umotion(VAR_0, VAR_7);

                else    

                  VAR_9 = h263_decode_motion(VAR_0, VAR_7);

                if (VAR_9 >= 0xffff)

                    return -1;

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

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

                if (VAR_0->umvplus_dec && (VAR_8 - VAR_6) == 1 && (VAR_9 - VAR_7) == 1)

                  skip_bits1(&VAR_0->gb); 

                mot_val[0] = VAR_8;

                mot_val[1] = VAR_9;

            }

        }

    } else {

        VAR_0->ac_pred = 0;

	    if (VAR_0->h263_pred) {

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

        }

        VAR_3 = get_vlc(&VAR_0->gb, &cbpy_vlc);

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

        if (VAR_10) {

            VAR_0->qscale += VAR_12[get_bits(&VAR_0->gb, 2)];

            if (VAR_0->qscale < 1)

                VAR_0->qscale = 1;

            else if (VAR_0->qscale > 31)

                VAR_0->qscale = 31;

        }

    }



    

    if (VAR_0->h263_pred) {

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

	    if (mpeg4_decode_block(VAR_0, VAR_1[VAR_4], VAR_4, (VAR_5 >> (5 - VAR_4)) & 1) < 0)

                return -1;

	}

    } else {

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

	    if (h263_decode_block(VAR_0, VAR_1[VAR_4], VAR_4, (VAR_5 >> (5 - VAR_4)) & 1) < 0)

                return -1;

	}

    }

    return 0;

}

int FUNC_0(MpegEncContext *VAR_0,
DCTELEM VAR_1[6][64])
{ int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10; unsigned int VAR_11; INT16 *mot_val; static INT8 VAR_12[4] = { -1, -2, 1, 2 }; VAR_11 = show_bits(&VAR_0->gb, 16); if (VAR_11 == 0) { #ifdef DEBUG
unsigned int gn, gfid; #endif
while (get_bits1(&VAR_0->gb) == 0); #ifdef DEBUG
fprintf(stderr,"\nGOB Start Code at MB %d\n",
(VAR_0->mb_y * VAR_0->mb_width) + VAR_0->mb_x); gn = get_bits(&VAR_0->gb, 5); gfid = get_bits(&VAR_0->gb, 2); #else
skip_bits(&VAR_0->gb, 5); skip_bits(&VAR_0->gb, 2); #endif
VAR_0->qscale = get_bits(&VAR_0->gb, 5); #ifdef DEBUG
fprintf(stderr, "\nGN: %u GFID: %u Quant: %u\n", gn, gfid, VAR_0->qscale); #endif
} if (VAR_0->pict_type == P_TYPE) { 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; VAR_0->mv[0][0][0] = 0; VAR_0->mv[0][0][1] = 0; VAR_0->mb_skiped = 1; return 0; } VAR_2 = get_vlc(&VAR_0->gb, &inter_MCBPC_vlc); if (VAR_2 < 0)
return -1; VAR_10 = VAR_2 & 8; VAR_0->mb_intra = ((VAR_2 & 4) != 0); } else { VAR_2 = get_vlc(&VAR_0->gb, &intra_MCBPC_vlc); if (VAR_2 < 0)
return -1; VAR_10 = VAR_2 & 4; VAR_0->mb_intra = 1; } if (!VAR_0->mb_intra) { VAR_3 = get_vlc(&VAR_0->gb, &cbpy_vlc); VAR_5 = (VAR_2 & 3) | ((VAR_3 ^ 0xf) << 2); if (VAR_10) { VAR_0->qscale += VAR_12[get_bits(&VAR_0->gb, 2)]; if (VAR_0->qscale < 1)
VAR_0->qscale = 1; else if (VAR_0->qscale > 31)
VAR_0->qscale = 31; } VAR_0->mv_dir = MV_DIR_FORWARD; if ((VAR_2 & 16) == 0) { VAR_0->mv_type = MV_TYPE_16X16; h263_pred_motion(VAR_0, 0, &VAR_6, &VAR_7); if (VAR_0->umvplus_dec)
VAR_8 = h263p_decode_umotion(VAR_0, VAR_6); else
VAR_8 = h263_decode_motion(VAR_0, VAR_6); if (VAR_8 >= 0xffff)
return -1; if (VAR_0->umvplus_dec)
VAR_9 = h263p_decode_umotion(VAR_0, VAR_7); else
VAR_9 = h263_decode_motion(VAR_0, VAR_7); if (VAR_9 >= 0xffff)
return -1; VAR_0->mv[0][0][0] = VAR_8; VAR_0->mv[0][0][1] = VAR_9; if (VAR_0->umvplus_dec && (VAR_8 - VAR_6) == 1 && (VAR_9 - VAR_7) == 1)
skip_bits1(&VAR_0->gb); } else { VAR_0->mv_type = MV_TYPE_8X8; for(VAR_4=0;VAR_4<4;VAR_4++) { mot_val = h263_pred_motion(VAR_0, VAR_4, &VAR_6, &VAR_7); if (VAR_0->umvplus_dec)
VAR_8 = h263p_decode_umotion(VAR_0, VAR_6); else
VAR_8 = h263_decode_motion(VAR_0, VAR_6); if (VAR_8 >= 0xffff)
return -1; if (VAR_0->umvplus_dec)
VAR_9 = h263p_decode_umotion(VAR_0, VAR_7); else
VAR_9 = h263_decode_motion(VAR_0, VAR_7); if (VAR_9 >= 0xffff)
return -1; VAR_0->mv[0][VAR_4][0] = VAR_8; VAR_0->mv[0][VAR_4][1] = VAR_9; if (VAR_0->umvplus_dec && (VAR_8 - VAR_6) == 1 && (VAR_9 - VAR_7) == 1)
skip_bits1(&VAR_0->gb); mot_val[0] = VAR_8; mot_val[1] = VAR_9; } } } else { VAR_0->ac_pred = 0; if (VAR_0->h263_pred) { VAR_0->ac_pred = get_bits1(&VAR_0->gb); } VAR_3 = get_vlc(&VAR_0->gb, &cbpy_vlc); VAR_5 = (VAR_2 & 3) | (VAR_3 << 2); if (VAR_10) { VAR_0->qscale += VAR_12[get_bits(&VAR_0->gb, 2)]; if (VAR_0->qscale < 1)
VAR_0->qscale = 1; else if (VAR_0->qscale > 31)
VAR_0->qscale = 31; } } if (VAR_0->h263_pred) { for (VAR_4 = 0; VAR_4 < 6; VAR_4++) { if (mpeg4_decode_block(VAR_0, VAR_1[VAR_4], VAR_4, (VAR_5 >> (5 - VAR_4)) & 1) < 0)
return -1; } } else { for (VAR_4 = 0; VAR_4 < 6; VAR_4++) { if (h263_decode_block(VAR_0, VAR_1[VAR_4], VAR_4, (VAR_5 >> (5 - VAR_4)) & 1) < 0)
return -1; } } return 0; }