--- trunk/xvidcore/src/motion/estimation_bvop.c 2004/07/08 07:12:54 1478 +++ trunk/xvidcore/src/motion/estimation_bvop.c 2004/09/04 14:16:24 1547 @@ -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.7 2004-07-08 07:12:54 syskin Exp $ + * $Id: estimation_bvop.c,v 1.14 2004-09-04 14:16:24 edgomez Exp $ * ****************************************************************************/ @@ -375,8 +375,7 @@ Data_d->CurU = Data_f->CurU = Data_b->CurU = Data_i->CurU = Cur[1]; Data_d->CurV = Data_f->CurV = Data_b->CurV = Data_i->CurV = Cur[2]; - Data_d->lambda16 = lambda/4; - Data_f->lambda16 = Data_b->lambda16 = Data_i->lambda16 = lambda; + Data_d->lambda16 = Data_f->lambda16 = Data_b->lambda16 = Data_i->lambda16 = lambda; /* reset chroma-sad cache */ Data_d->b_chromaX = Data_d->b_chromaY = Data_d->chromaX = Data_d->chromaY = Data_d->chromaSAD = 256*4096; @@ -401,11 +400,9 @@ const uint32_t mode_curr, const VECTOR hint) { - /* [0] is prediction */ - pmv[0].x = (pmv[0].x); pmv[0].y = (pmv[0].y); - - pmv[1].x = pmv[1].y = 0; /* [1] is zero */ + /* [1] is zero */ + pmv[1].x = pmv[1].y = 0; pmv[2].x = hint.x; pmv[2].y = hint.y; @@ -554,7 +551,11 @@ Data->RefP[5] + (dy/2) * stride + dx/2, Data->b_RefP[5] + (b_dy/2) * stride + b_dx/2, stride); - + + if (sum >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) return; /* no skip */ + } else { + int sum = Data->chromaSAD; /* chroma-sad SAD caching keeps it there */ + if (sum >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) return; /* no skip */ } @@ -563,6 +564,10 @@ for (k = 0; k < 4; k++) { pMB->qmvs[k] = pMB->mvs[k] = Data->directmvF[k]; pMB->b_qmvs[k] = pMB->b_mvs[k] = Data->directmvB[k]; + if (Data->qpel) { + pMB->mvs[k].x /= 2; pMB->mvs[k].y /= 2; /* it's a hint for future searches */ + pMB->b_mvs[k].x /= 2; pMB->b_mvs[k].y /= 2; + } } } @@ -611,7 +616,6 @@ CheckCandidateDirect(0, 0, Data, 255); /* will also fill iMinSAD[1..4] with 8x8 SADs */ - /* initial (fast) skip decision */ if (Data->iMinSAD[1] < (int)Data->iQuant * INITIAL_SKIP_THRESH && Data->iMinSAD[2] < (int)Data->iQuant * INITIAL_SKIP_THRESH @@ -623,8 +627,10 @@ return *Data->iMinSAD; /* skipped */ } - skip_sad = 4*MAX(MAX(Data->iMinSAD[1],Data->iMinSAD[2]), MAX(Data->iMinSAD[3],Data->iMinSAD[4])); - if (Data->chroma) skip_sad += Data->chromaSAD; + if (Data->chroma && Data->chromaSAD >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) /* chroma doesn't allow skip */ + skip_sad = 256*4096; + else + skip_sad = 4*MAX(MAX(Data->iMinSAD[1],Data->iMinSAD[2]), MAX(Data->iMinSAD[3],Data->iMinSAD[4])); Data->currentMV[1].x = Data->directmvF[0].x + Data->currentMV->x; /* hints for forward and backward searches */ Data->currentMV[1].y = Data->directmvF[0].y + Data->currentMV->y; @@ -869,6 +875,7 @@ *f_predMV = Data_f->currentMV[0]; } pMB->mvs[0] = *Data_f->currentMV; + pMB->b_mvs[0] = *Data_b->currentMV; /* hint for future searches */ break; case MODE_BACKWARD: @@ -883,6 +890,7 @@ *b_predMV = Data_b->currentMV[0]; } pMB->b_mvs[0] = *Data_b->currentMV; + pMB->mvs[0] = *Data_f->currentMV; /* hint for future searches */ break; @@ -929,7 +937,8 @@ const IMAGE * const b_refHV) { uint32_t i, j; - int32_t best_sad, sad2; + int32_t best_sad = 256*4096; + int32_t sad2; uint32_t skip_sad; const MACROBLOCK * const b_mbs = b_reference->mbs; @@ -938,6 +947,7 @@ const int32_t TRB = time_pp - time_bp; const int32_t TRD = time_pp; + DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); /* some pre-inintialized data for the rest of the search */ SearchData Data_d, Data_f, Data_b, Data_i; @@ -948,6 +958,9 @@ Data_d.rounding = 0; Data_d.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP; Data_d.iQuant = 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; Data_d.RefQ = f_refV->u; /* a good place, also used in MC (for similar purpose) */ @@ -966,9 +979,6 @@ for (i = 0; i < pParam->mb_width; i++) { MACROBLOCK * const pMB = frame->mbs + i + j * pParam->mb_width; const MACROBLOCK * const b_mb = b_mbs + i + j * pParam->mb_width; - int interpol_search = 0; - int bf_search = 0; - int bf_thresh = 0; pMB->mode = -1; initialize_searchData(&Data_d, &Data_f, &Data_b, &Data_i, @@ -994,7 +1004,7 @@ pMB->sad16 = best_sad; continue; } - + SearchBF_initial(i, j, frame->motion_flags, frame->fcode, pParam, pMB, &f_predMV, &best_sad, MODE_FORWARD, &Data_f, Data_d.currentMV[1]); @@ -1003,37 +1013,42 @@ sad2 = best_sad; - if (Data_f.iMinSAD[0] < 2*sad2+1500) + if (Data_f.iMinSAD[0] < 2*sad2+2000) SearchBF_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_f); - if (Data_b.iMinSAD[0] < 2*sad2+1500) + if (Data_b.iMinSAD[0] < 2*sad2+2000) 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)) - || Data_i.iMinSAD[0] <= best_sad)) + if (((Data_i.iMinSAD[0] < 2*best_sad+2000) && !(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] <= best_sad) && (!(frame->motion_flags&XVID_ME_SKIP_DELTASEARCH))) + 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); - /* final skip decision */ - if ( (skip_sad < Data_d.iQuant * MAX_SAD00_FOR_SKIP ) + if ( (skip_sad < 2 * Data_d.iQuant * MAX_SAD00_FOR_SKIP ) && ((100*best_sad)/(skip_sad+1) > FINAL_SKIP_THRESH) ) { + Data_d.chromaSAD = 0; /* green light for chroma check */ + SkipDecisionB(pMB, &Data_d); + if (pMB->mode == MODE_DIRECT_NONE_MV) { /* skipped? */ - pMB->sad16 = best_sad; + pMB->sad16 = skip_sad; continue; } } - ModeDecision_BVOP_SAD(&Data_d, &Data_b, &Data_f, &Data_i, pMB, b_mb, &f_predMV, &b_predMV); + 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); + else + ModeDecision_BVOP_SAD(&Data_d, &Data_b, &Data_f, &Data_i, pMB, b_mb, &f_predMV, &b_predMV); } }