if(s->mb_x==0) PRINT_MB_TYPE("\n")
if(s->mb_x==0) PRINT_MB_TYPE("\n");
int h263_decode_mb(MpegEncContext *s,                   DCTELEM block[6][64]){    int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;    INT16 *mot_val;    static INT8 quant_tab[4] = { -1, -2, 1, 2 };    if(s->mb_x==0) PRINT_MB_TYPE("\n")    if(s->resync_marker){        if(s->resync_mb_x == s->mb_x && s->resync_mb_y+1 == s->mb_y){            s->first_slice_line=0;         }    }    if(s->data_partitioning && s->pict_type!=B_TYPE)        return mpeg4_decode_partitioned_mb(s, block);    if (s->pict_type == P_TYPE || s->pict_type==S_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;            if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){                const int a= s->sprite_warping_accuracy;//                int l = (1 << (s->f_code - 1)) * 32;                PRINT_MB_TYPE("G");                s->mcsel=1;                if(s->divx_version==500 && s->divx_build==413){                    s->mv[0][0][0] = s->sprite_offset[0][0] / (1<<(a-s->quarter_sample));                    s->mv[0][0][1] = s->sprite_offset[0][1] / (1<<(a-s->quarter_sample));                }else{                    s->mv[0][0][0] = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample);                    s->mv[0][0][1] = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample);                }/*                if (s->mv[0][0][0] < -l) s->mv[0][0][0]= -l;                else if (s->mv[0][0][0] >= l) s->mv[0][0][0]= l-1;                if (s->mv[0][0][1] < -l) s->mv[0][0][1]= -l;                else if (s->mv[0][0][1] >= l) s->mv[0][0][1]= l-1;*/                s->mb_skiped = 0;            }else{                PRINT_MB_TYPE("S");                s->mcsel=0;                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;        if (cbpc > 20)            cbpc+=3;        else if (cbpc == 20)            fprintf(stderr, "Stuffing !");                dquant = cbpc & 8;        s->mb_intra = ((cbpc & 4) != 0);        if (s->mb_intra) goto intra;                if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0)            s->mcsel= get_bits1(&s->gb);        else s->mcsel= 0;        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;            h263_dc_scale(s);        }        s->mv_dir = MV_DIR_FORWARD;        if ((cbpc & 16) == 0) {            PRINT_MB_TYPE("P");            /* 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 if(!s->mcsel)               mx = h263_decode_motion(s, pred_x, s->f_code);            else {               const int a= s->sprite_warping_accuracy;//        int l = (1 << (s->f_code - 1)) * 32;                if(s->divx_version==500 && s->divx_build==413){                    mx = s->sprite_offset[0][0] / (1<<(a-s->quarter_sample));                }else{                    mx = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample);                }//        if (mx < -l) mx= -l, printf("C");//        else if (mx >= l) mx= l-1, printf("C");            }            if (mx >= 0xffff)                return -1;                        if (s->umvplus_dec)               my = h263p_decode_umotion(s, pred_y);            else if(!s->mcsel)               my = h263_decode_motion(s, pred_y, s->f_code);            else{               const int a= s->sprite_warping_accuracy;//       int l = (1 << (s->f_code - 1)) * 32;                if(s->divx_version==500 && s->divx_build==413){                    my = s->sprite_offset[0][1] / (1<<(a-s->quarter_sample));                }else{                    my = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample);                }//       if (my < -l) my= -l, printf("C");//       else if (my >= l) my= l-1, printf("C");            }            if (my >= 0xffff)                return -1;            s->mv[0][0][0] = mx;            s->mv[0][0][1] = my;            /*fprintf(stderr, "\n MB %d", (s->mb_y * s->mb_width) + s->mb_x);            fprintf(stderr, "\n\tmvx: %d\t\tpredx: %d", mx, pred_x);            fprintf(stderr, "\n\tmvy: %d\t\tpredy: %d", my, pred_y);*/            if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1)               skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */                                   } else {            PRINT_MB_TYPE("4");            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, s->f_code);                if (mx >= 0xffff)                    return -1;                                if (s->umvplus_dec)                  my = h263p_decode_umotion(s, pred_y);                else                      my = 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;                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 if(s->pict_type==B_TYPE) {        int modb1; // first bit of modb        int modb2; // second bit of modb        int mb_type;        uint16_t time_pp;        uint16_t time_pb;        int xy;        s->mb_intra = 0; //B-frames never contain intra blocks        s->mcsel=0;      //     ...               true gmc blocks        if(s->mb_x==0){            s->last_mv[0][0][0]=             s->last_mv[0][0][1]=             s->last_mv[1][0][0]=             s->last_mv[1][0][1]= 0;        }        /* if we skipped it in the future P Frame than skip it now too */        s->mb_skiped= s->mbskip_table[s->mb_y * s->mb_width + s->mb_x]; // Note, skiptab=0 if last was GMC        if(s->mb_skiped){                /* 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] = 0;            s->mv[0][0][1] = 0;            s->mv[1][0][0] = 0;            s->mv[1][0][1] = 0;//FIXME is this correct?/*            s->last_mv[0][0][0]=            s->last_mv[0][0][1]=0;*/            PRINT_MB_TYPE("s")            return 0;        }        modb1= get_bits1(&s->gb);        if(modb1==0){            modb2= get_bits1(&s->gb);            mb_type= get_vlc(&s->gb, &mb_type_b_vlc);            if(modb2==0) cbp= get_bits(&s->gb, 6);            else cbp=0;            if (mb_type && cbp) {                if(get_bits1(&s->gb)){                    s->qscale +=get_bits1(&s->gb)*4 - 2;                    if (s->qscale < 1)                        s->qscale = 1;                    else if (s->qscale > 31)                        s->qscale = 31;                    h263_dc_scale(s);                }            }        }else{            mb_type=4; //like 0 but no vectors coded            cbp=0;        }        s->mv_type = MV_TYPE_16X16; // we'll switch to 8x8 only if the last P frame had 8x8 for this MB and mb_type=0 here        mx=my=0; //for case 4, we could put this to the mb_type=4 but than gcc compains about uninitalized mx/my        switch(mb_type)        {        case 0: /* direct */            mx = h263_decode_motion(s, 0, 1);            my = h263_decode_motion(s, 0, 1);        case 4: /* direct with mx=my=0 */            s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;            xy= s->block_index[0];            time_pp= s->pp_time;            time_pb= time_pp - s->bp_time;//if(time_pp>3000 )printf("%d %d  ", time_pp, time_pb);            //FIXME 4MV            //FIXME avoid divides            s->mv[0][0][0] = s->motion_val[xy][0]*time_pb/time_pp + mx;            s->mv[0][0][1] = s->motion_val[xy][1]*time_pb/time_pp + my;            s->mv[1][0][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0]                                : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp + mx;            s->mv[1][0][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1]                                 : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp + my;/*            s->mv[0][0][0] =             s->mv[0][0][1] =             s->mv[1][0][0] =             s->mv[1][0][1] = 1000;*/            PRINT_MB_TYPE("D");            break;        case 1:             s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;            mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code);            my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code);            s->last_mv[0][0][0]= s->mv[0][0][0] = mx;            s->last_mv[0][0][1]= s->mv[0][0][1] = my;            mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code);            my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code);            s->last_mv[1][0][0]= s->mv[1][0][0] = mx;            s->last_mv[1][0][1]= s->mv[1][0][1] = my;            PRINT_MB_TYPE("i");            break;        case 2:             s->mv_dir = MV_DIR_BACKWARD;            mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code);            my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code);            s->last_mv[1][0][0]= s->mv[1][0][0] = mx;            s->last_mv[1][0][1]= s->mv[1][0][1] = my;            PRINT_MB_TYPE("B");            break;        case 3:            s->mv_dir = MV_DIR_FORWARD;            mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code);            my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code);            s->last_mv[0][0][0]= s->mv[0][0][0] = mx;            s->last_mv[0][0][1]= s->mv[0][0][1] = my;            PRINT_MB_TYPE("F");            break;        default:             printf("illegal MB_type\n");            return -1;        }    } else { /* I-Frame */        cbpc = get_vlc(&s->gb, &intra_MCBPC_vlc);        if (cbpc < 0)            return -1;        dquant = cbpc & 4;        s->mb_intra = 1;intra:        PRINT_MB_TYPE("I");        s->ac_pred = 0;        if (s->h263_pred || s->h263_aic) {            s->ac_pred = get_bits1(&s->gb);            if (s->ac_pred && s->h263_aic)                s->h263_aic_dir = get_bits1(&s->gb);        }        cbpy = get_vlc(&s->gb, &cbpy_vlc);        if(cbpy<0) return -1;        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;            h263_dc_scale(s);        }    }    /* 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;}