const int xy = mb_y*s->mb_stride + mb_x;
void ff_estimate_b_frame_motion(MpegEncContext * s,                             int mb_x, int mb_y){    const int penalty_factor= s->me.mb_penalty_factor;    int fmin, bmin, dmin, fbmin, bimin, fimin;    int type=0;    init_ref(s, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2);        s->me.skip=0;    if(s->avctx->me_threshold){        int vard= (check_input_motion(s, mb_x, mb_y, 0)+128)>>8;                if(vard<s->avctx->me_threshold){//            pix = c->src[0][0];//            sum = s->dsp.pix_sum(pix, s->linesize);//            varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8;        //            pic->mb_var   [s->mb_stride * mb_y + mb_x] = varc;             s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] = vard;/*            pic->mb_mean  [s->mb_stride * mb_y + mb_x] = (sum+128)>>8;            s->mb_var_sum_temp    += varc;*/            s->mc_mb_var_sum_temp += vard;/*            if (vard <= 64 || vard < varc) {                s->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);            }else{                s->scene_change_score+= s->qscale;            }*/            return;        }    }    if (s->codec_id == CODEC_ID_MPEG4)        dmin= direct_search(s, mb_x, mb_y);    else        dmin= INT_MAX;//FIXME penalty stuff for non mpeg4    s->me.skip=0;    fmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) + 3*penalty_factor;        s->me.skip=0;    bmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) + 2*penalty_factor;//printf(" %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);    s->me.skip=0;    fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor;//printf("%d %d %d %d\n", dmin, fmin, bmin, fbmin);        if(s->flags & CODEC_FLAG_INTERLACED_ME){        const int xy = mb_y*s->mb_stride + mb_x;//FIXME mb type penalty        s->me.skip=0;        s->me.current_mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;        fimin= interlaced_search(s, 0,                                 s->b_field_mv_table[0], s->b_field_select_table[0],                                 s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);        s->me.current_mv_penalty= s->me.mv_penalty[s->b_code] + MAX_MV;        bimin= interlaced_search(s, 2,                                 s->b_field_mv_table[1], s->b_field_select_table[1],                                 s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1]);    }else        fimin= bimin= INT_MAX;    {        int score= fmin;        type = CANDIDATE_MB_TYPE_FORWARD;                if (dmin <= score){            score = dmin;            type = CANDIDATE_MB_TYPE_DIRECT;        }        if(bmin<score){            score=bmin;            type= CANDIDATE_MB_TYPE_BACKWARD;         }        if(fbmin<score){            score=fbmin;            type= CANDIDATE_MB_TYPE_BIDIR;        }        if(fimin<score){            score=fimin;            type= CANDIDATE_MB_TYPE_FORWARD_I;        }        if(bimin<score){            score=bimin;            type= CANDIDATE_MB_TYPE_BACKWARD_I;        }                score= ((unsigned)(score*score + 128*256))>>16;        s->mc_mb_var_sum_temp += score;        s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE    }    if(s->avctx->mb_decision > FF_MB_DECISION_SIMPLE){        type= CANDIDATE_MB_TYPE_FORWARD | CANDIDATE_MB_TYPE_BACKWARD | CANDIDATE_MB_TYPE_BIDIR | CANDIDATE_MB_TYPE_DIRECT;        if(fimin < INT_MAX)            type |= CANDIDATE_MB_TYPE_FORWARD_I;        if(bimin < INT_MAX)            type |= CANDIDATE_MB_TYPE_BACKWARD_I;        if(fimin < INT_MAX && bimin < INT_MAX){            type |= CANDIDATE_MB_TYPE_BIDIR_I;        }         //FIXME something smarter        if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT; //dont try direct mode if its invalid for this MB#if 0                if(s->out_format == FMT_MPEG1)            type |= CANDIDATE_MB_TYPE_INTRA;#endif    }    s->mb_type[mb_y*s->mb_stride + mb_x]= type;}