--- estimation_bvop.c 2004/12/09 04:20:44 1.19 +++ estimation_bvop.c 2004/12/17 11:57:59 1.22 @@ -21,7 +21,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: estimation_bvop.c,v 1.19 2004/12/09 04:20:44 syskin Exp $ + * $Id: estimation_bvop.c,v 1.22 2004/12/17 11:57:59 syskin Exp $ * ****************************************************************************/ @@ -965,9 +965,8 @@ { uint32_t i, j; int32_t best_sad = 256*4096; - int32_t sad2; uint32_t skip_sad; - + int fb_thresh; const MACROBLOCK * const b_mbs = b_reference->mbs; VECTOR f_predMV, b_predMV; @@ -986,6 +985,7 @@ Data_d.rounding = 0; Data_d.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP; Data_d.iQuant = frame->quant; + Data_d.quant_sq = frame->quant*frame->quant; Data_d.dctSpace = dct_space; Data_d.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); Data_d.mpeg_quant_matrices = pParam->mpeg_quant_matrices; @@ -1039,24 +1039,30 @@ SearchBF_initial(i, j, frame->motion_flags, frame->bcode, pParam, pMB, &b_predMV, &best_sad, MODE_BACKWARD, &Data_b, Data_d.currentMV[2]); - sad2 = best_sad; + if (frame->motion_flags&XVID_ME_BFRAME_EARLYSTOP) + fb_thresh = best_sad; + else + fb_thresh = best_sad + (best_sad>>1); - if (Data_f.iMinSAD[0] < 2*sad2+2000) + if (Data_f.iMinSAD[0] <= fb_thresh) SearchBF_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_f); - if (Data_b.iMinSAD[0] < 2*sad2+2000) + if (Data_b.iMinSAD[0] <= fb_thresh) SearchBF_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_b); SearchInterpolate_initial(i, j, frame->motion_flags, pParam, &f_predMV, &b_predMV, &best_sad, &Data_i, Data_f.currentMV[0], Data_b.currentMV[0]); - if (((Data_i.iMinSAD[0] < 2*best_sad+2000) && !(frame->motion_flags&XVID_ME_FAST_MODEINTERPOLATE)) + if (((Data_i.iMinSAD[0] < best_sad +(best_sad>>3)) && !(frame->motion_flags&XVID_ME_FAST_MODEINTERPOLATE)) || Data_i.iMinSAD[0] <= best_sad) SearchInterpolate_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_i); - if ((Data_d.iMinSAD[0] <= 2*best_sad) && (!frame->motion_flags&XVID_ME_SKIP_DELTASEARCH)) - SearchDirect_final(frame->motion_flags, b_mb, &best_sad, &Data_d); + if (Data_d.iMinSAD[0] <= 2*best_sad) + if ((!(frame->motion_flags&XVID_ME_SKIP_DELTASEARCH) && (best_sad > 750)) + || (best_sad > 1000)) + + SearchDirect_final(frame->motion_flags, b_mb, &best_sad, &Data_d); /* final skip decision */ if ( (skip_sad < 2 * Data_d.iQuant * MAX_SAD00_FOR_SKIP ) @@ -1075,7 +1081,7 @@ if (frame->vop_flags & XVID_VOP_RD_BVOP) ModeDecision_BVOP_RD(&Data_d, &Data_b, &Data_f, &Data_i, - pMB, b_mb, &f_predMV, &b_predMV, frame->motion_flags, pParam, i, j); + pMB, b_mb, &f_predMV, &b_predMV, frame->motion_flags, pParam, i, j, best_sad); else ModeDecision_BVOP_SAD(&Data_d, &Data_b, &Data_f, &Data_i, pMB, b_mb, &f_predMV, &b_predMV);