375 |
Data_d->CurU = Data_f->CurU = Data_b->CurU = Data_i->CurU = Cur[1]; |
Data_d->CurU = Data_f->CurU = Data_b->CurU = Data_i->CurU = Cur[1]; |
376 |
Data_d->CurV = Data_f->CurV = Data_b->CurV = Data_i->CurV = Cur[2]; |
Data_d->CurV = Data_f->CurV = Data_b->CurV = Data_i->CurV = Cur[2]; |
377 |
|
|
378 |
Data_d->lambda16 = lambda/4; |
Data_d->lambda16 = Data_f->lambda16 = Data_b->lambda16 = Data_i->lambda16 = lambda; |
|
Data_f->lambda16 = Data_b->lambda16 = Data_i->lambda16 = lambda; |
|
379 |
|
|
380 |
/* reset chroma-sad cache */ |
/* reset chroma-sad cache */ |
381 |
Data_d->b_chromaX = Data_d->b_chromaY = Data_d->chromaX = Data_d->chromaY = Data_d->chromaSAD = 256*4096; |
Data_d->b_chromaX = Data_d->b_chromaY = Data_d->chromaX = Data_d->chromaY = Data_d->chromaSAD = 256*4096; |
400 |
const uint32_t mode_curr, |
const uint32_t mode_curr, |
401 |
const VECTOR hint) |
const VECTOR hint) |
402 |
{ |
{ |
|
|
|
403 |
/* [0] is prediction */ |
/* [0] is prediction */ |
404 |
pmv[0].x = (pmv[0].x); pmv[0].y = (pmv[0].y); |
/* [1] is zero */ |
405 |
|
pmv[1].x = pmv[1].y = 0; |
|
pmv[1].x = pmv[1].y = 0; /* [1] is zero */ |
|
406 |
|
|
407 |
pmv[2].x = hint.x; pmv[2].y = hint.y; |
pmv[2].x = hint.x; pmv[2].y = hint.y; |
408 |
|
|
522 |
{ |
{ |
523 |
int k; |
int k; |
524 |
|
|
|
pMB->mode = MODE_DIRECT; /* just to initialize it */ |
|
|
|
|
525 |
if (!Data->chroma) { |
if (!Data->chroma) { |
526 |
int dx = 0, dy = 0, b_dx = 0, b_dy = 0; |
int dx = 0, dy = 0, b_dx = 0, b_dy = 0; |
527 |
int32_t sum; |
int32_t sum; |
541 |
b_dx = (b_dx >> 3) + roundtab_76[b_dx & 0xf]; |
b_dx = (b_dx >> 3) + roundtab_76[b_dx & 0xf]; |
542 |
|
|
543 |
sum = sad8bi(Data->CurU, |
sum = sad8bi(Data->CurU, |
544 |
Data->RefP[4] + (dy/2) * stride + dx/2, |
Data->RefP[4] + (dy/2) * (int)stride + dx/2, |
545 |
Data->b_RefP[4] + (b_dy/2) * stride + b_dx/2, |
Data->b_RefP[4] + (b_dy/2) * (int)stride + b_dx/2, |
546 |
stride); |
stride); |
547 |
|
|
548 |
if (sum >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) return; /* no skip */ |
if (sum >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) return; /* no skip */ |
549 |
|
|
550 |
sum += sad8bi(Data->CurV, |
sum += sad8bi(Data->CurV, |
551 |
Data->RefP[5] + (dy/2) * stride + dx/2, |
Data->RefP[5] + (dy/2) * (int)stride + dx/2, |
552 |
Data->b_RefP[5] + (b_dy/2) * stride + b_dx/2, |
Data->b_RefP[5] + (b_dy/2) * (int)stride + b_dx/2, |
553 |
stride); |
stride); |
554 |
|
|
555 |
if (sum >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) return; /* no skip */ |
if (sum >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) return; /* no skip */ |
564 |
for (k = 0; k < 4; k++) { |
for (k = 0; k < 4; k++) { |
565 |
pMB->qmvs[k] = pMB->mvs[k] = Data->directmvF[k]; |
pMB->qmvs[k] = pMB->mvs[k] = Data->directmvF[k]; |
566 |
pMB->b_qmvs[k] = pMB->b_mvs[k] = Data->directmvB[k]; |
pMB->b_qmvs[k] = pMB->b_mvs[k] = Data->directmvB[k]; |
567 |
|
if (Data->qpel) { |
568 |
|
pMB->mvs[k].x /= 2; pMB->mvs[k].y /= 2; /* it's a hint for future searches */ |
569 |
|
pMB->b_mvs[k].x /= 2; pMB->b_mvs[k].y /= 2; |
570 |
|
} |
571 |
} |
} |
572 |
} |
} |
573 |
|
|
616 |
|
|
617 |
CheckCandidateDirect(0, 0, Data, 255); /* will also fill iMinSAD[1..4] with 8x8 SADs */ |
CheckCandidateDirect(0, 0, Data, 255); /* will also fill iMinSAD[1..4] with 8x8 SADs */ |
618 |
|
|
|
|
|
619 |
/* initial (fast) skip decision */ |
/* initial (fast) skip decision */ |
620 |
if (Data->iMinSAD[1] < (int)Data->iQuant * INITIAL_SKIP_THRESH |
if (Data->iMinSAD[1] < (int)Data->iQuant * INITIAL_SKIP_THRESH |
621 |
&& Data->iMinSAD[2] < (int)Data->iQuant * INITIAL_SKIP_THRESH |
&& Data->iMinSAD[2] < (int)Data->iQuant * INITIAL_SKIP_THRESH |
627 |
return *Data->iMinSAD; /* skipped */ |
return *Data->iMinSAD; /* skipped */ |
628 |
} |
} |
629 |
|
|
630 |
|
if (Data->chroma && Data->chromaSAD >= MAX_CHROMA_SAD_FOR_SKIP * (int)Data->iQuant) /* chroma doesn't allow skip */ |
631 |
|
skip_sad = 256*4096; |
632 |
|
else |
633 |
skip_sad = 4*MAX(MAX(Data->iMinSAD[1],Data->iMinSAD[2]), MAX(Data->iMinSAD[3],Data->iMinSAD[4])); |
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; |
|
634 |
|
|
635 |
Data->currentMV[1].x = Data->directmvF[0].x + Data->currentMV->x; /* hints for forward and backward searches */ |
Data->currentMV[1].x = Data->directmvF[0].x + Data->currentMV->x; /* hints for forward and backward searches */ |
636 |
Data->currentMV[1].y = Data->directmvF[0].y + Data->currentMV->y; |
Data->currentMV[1].y = Data->directmvF[0].y + Data->currentMV->y; |
643 |
Data->directmvB[0].y |
Data->directmvB[0].y |
644 |
: Data->currentMV[1].y - Data->referencemv[0].y); |
: Data->currentMV[1].y - Data->referencemv[0].y); |
645 |
|
|
646 |
|
*best_sad = Data->iMinSAD[0]; |
647 |
|
|
648 |
return skip_sad; |
return skip_sad; |
649 |
} |
} |
650 |
|
|
877 |
*f_predMV = Data_f->currentMV[0]; |
*f_predMV = Data_f->currentMV[0]; |
878 |
} |
} |
879 |
pMB->mvs[0] = *Data_f->currentMV; |
pMB->mvs[0] = *Data_f->currentMV; |
880 |
|
pMB->b_mvs[0] = *Data_b->currentMV; /* hint for future searches */ |
881 |
break; |
break; |
882 |
|
|
883 |
case MODE_BACKWARD: |
case MODE_BACKWARD: |
892 |
*b_predMV = Data_b->currentMV[0]; |
*b_predMV = Data_b->currentMV[0]; |
893 |
} |
} |
894 |
pMB->b_mvs[0] = *Data_b->currentMV; |
pMB->b_mvs[0] = *Data_b->currentMV; |
895 |
|
pMB->mvs[0] = *Data_f->currentMV; /* hint for future searches */ |
896 |
break; |
break; |
897 |
|
|
898 |
|
|
939 |
const IMAGE * const b_refHV) |
const IMAGE * const b_refHV) |
940 |
{ |
{ |
941 |
uint32_t i, j; |
uint32_t i, j; |
942 |
int32_t best_sad, sad2; |
int32_t best_sad = 256*4096; |
943 |
|
int32_t sad2; |
944 |
uint32_t skip_sad; |
uint32_t skip_sad; |
945 |
|
|
946 |
const MACROBLOCK * const b_mbs = b_reference->mbs; |
const MACROBLOCK * const b_mbs = b_reference->mbs; |
949 |
|
|
950 |
const int32_t TRB = time_pp - time_bp; |
const int32_t TRB = time_pp - time_bp; |
951 |
const int32_t TRD = time_pp; |
const int32_t TRD = time_pp; |
952 |
|
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
953 |
|
|
954 |
/* some pre-inintialized data for the rest of the search */ |
/* some pre-inintialized data for the rest of the search */ |
955 |
SearchData Data_d, Data_f, Data_b, Data_i; |
SearchData Data_d, Data_f, Data_b, Data_i; |
960 |
Data_d.rounding = 0; |
Data_d.rounding = 0; |
961 |
Data_d.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP; |
Data_d.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP; |
962 |
Data_d.iQuant = frame->quant; |
Data_d.iQuant = frame->quant; |
963 |
|
Data_d.dctSpace = dct_space; |
964 |
|
Data_d.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); |
965 |
|
Data_d.mpeg_quant_matrices = pParam->mpeg_quant_matrices; |
966 |
|
|
967 |
Data_d.RefQ = f_refV->u; /* a good place, also used in MC (for similar purpose) */ |
Data_d.RefQ = f_refV->u; /* a good place, also used in MC (for similar purpose) */ |
968 |
|
|
1015 |
|
|
1016 |
sad2 = best_sad; |
sad2 = best_sad; |
1017 |
|
|
1018 |
if (Data_f.iMinSAD[0] < 2*sad2+1500) |
if (Data_f.iMinSAD[0] < 2*sad2+2000) |
1019 |
SearchBF_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_f); |
SearchBF_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_f); |
1020 |
|
|
1021 |
if (Data_b.iMinSAD[0] < 2*sad2+1500) |
if (Data_b.iMinSAD[0] < 2*sad2+2000) |
1022 |
SearchBF_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_b); |
SearchBF_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_b); |
1023 |
|
|
1024 |
SearchInterpolate_initial(i, j, frame->motion_flags, pParam, &f_predMV, &b_predMV, &best_sad, |
SearchInterpolate_initial(i, j, frame->motion_flags, pParam, &f_predMV, &b_predMV, &best_sad, |
1029 |
|
|
1030 |
SearchInterpolate_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_i); |
SearchInterpolate_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_i); |
1031 |
|
|
1032 |
|
if ((Data_d.iMinSAD[0] <= 2*best_sad) && (!frame->motion_flags&XVID_ME_SKIP_DELTASEARCH)) |
|
if ((Data_d.iMinSAD[0] <= best_sad) && (!(frame->motion_flags&XVID_ME_SKIP_DELTASEARCH))) |
|
1033 |
SearchDirect_final(frame->motion_flags, b_mb, &best_sad, &Data_d); |
SearchDirect_final(frame->motion_flags, b_mb, &best_sad, &Data_d); |
1034 |
|
|
|
|
|
1035 |
/* final skip decision */ |
/* final skip decision */ |
1036 |
if ( (skip_sad < Data_d.iQuant * MAX_SAD00_FOR_SKIP ) |
if ( (skip_sad < 2 * Data_d.iQuant * MAX_SAD00_FOR_SKIP ) |
1037 |
&& ((100*best_sad)/(skip_sad+1) > FINAL_SKIP_THRESH) ) { |
&& ((100*best_sad)/(skip_sad+1) > FINAL_SKIP_THRESH) ) { |
1038 |
|
|
1039 |
|
Data_d.chromaSAD = 0; /* green light for chroma check */ |
1040 |
|
|
1041 |
SkipDecisionB(pMB, &Data_d); |
SkipDecisionB(pMB, &Data_d); |
1042 |
|
|
1043 |
if (pMB->mode == MODE_DIRECT_NONE_MV) { /* skipped? */ |
if (pMB->mode == MODE_DIRECT_NONE_MV) { /* skipped? */ |
1044 |
pMB->sad16 = best_sad; |
pMB->sad16 = skip_sad; |
1045 |
continue; |
continue; |
1046 |
} |
} |
1047 |
} |
} |
1048 |
|
|
1049 |
|
if (frame->vop_flags & XVID_VOP_RD_BVOP) |
1050 |
|
ModeDecision_BVOP_RD(&Data_d, &Data_b, &Data_f, &Data_i, |
1051 |
|
pMB, b_mb, &f_predMV, &b_predMV, frame->motion_flags, pParam, i, j); |
1052 |
|
else |
1053 |
ModeDecision_BVOP_SAD(&Data_d, &Data_b, &Data_f, &Data_i, pMB, b_mb, &f_predMV, &b_predMV); |
ModeDecision_BVOP_SAD(&Data_d, &Data_b, &Data_f, &Data_i, pMB, b_mb, &f_predMV, &b_predMV); |
1054 |
|
|
1055 |
} |
} |