829 |
|
|
830 |
pMB->sad16 = best_sad; |
pMB->sad16 = best_sad; |
831 |
pMB->mode = mode; |
pMB->mode = mode; |
832 |
|
pMB->cbp = 63; |
833 |
|
|
834 |
switch (mode) { |
switch (mode) { |
835 |
|
|
919 |
} |
} |
920 |
} |
} |
921 |
|
|
922 |
|
static __inline void |
923 |
|
maxMotionBVOP(int * const MVmaxF, int * const MVmaxB, const MACROBLOCK * const pMB, const int qpel) |
924 |
|
{ |
925 |
|
if (pMB->mode == MODE_FORWARD || pMB->mode == MODE_INTERPOLATE) { |
926 |
|
const VECTOR * const mv = qpel ? pMB->qmvs : pMB->mvs; |
927 |
|
int max = *MVmaxF; |
928 |
|
if (mv[0].x > max) max = mv[0].x; |
929 |
|
else if (-mv[0].x - 1 > max) max = -mv[0].x - 1; |
930 |
|
if (mv[0].y > max) max = mv[0].y; |
931 |
|
else if (-mv[0].y - 1 > max) max = -mv[0].y - 1; |
932 |
|
|
933 |
|
*MVmaxF = max; |
934 |
|
} |
935 |
|
|
936 |
|
if (pMB->mode == MODE_BACKWARD || pMB->mode == MODE_INTERPOLATE) { |
937 |
|
const VECTOR * const mv = qpel ? pMB->b_qmvs : pMB->b_mvs; |
938 |
|
int max = *MVmaxB; |
939 |
|
if (mv[0].x > max) max = mv[0].x; |
940 |
|
else if (-mv[0].x - 1 > max) max = -mv[0].x - 1; |
941 |
|
if (mv[0].y > max) max = mv[0].y; |
942 |
|
else if (-mv[0].y - 1 > max) max = -mv[0].y - 1; |
943 |
|
*MVmaxB = max; |
944 |
|
} |
945 |
|
} |
946 |
|
|
947 |
|
|
948 |
void |
void |
949 |
MotionEstimationBVOP(MBParam * const pParam, |
MotionEstimationBVOP(MBParam * const pParam, |
950 |
FRAMEINFO * const frame, |
FRAMEINFO * const frame, |
965 |
{ |
{ |
966 |
uint32_t i, j; |
uint32_t i, j; |
967 |
int32_t best_sad = 256*4096; |
int32_t best_sad = 256*4096; |
|
int32_t sad2; |
|
968 |
uint32_t skip_sad; |
uint32_t skip_sad; |
969 |
|
int fb_thresh; |
970 |
const MACROBLOCK * const b_mbs = b_reference->mbs; |
const MACROBLOCK * const b_mbs = b_reference->mbs; |
971 |
|
|
972 |
VECTOR f_predMV, b_predMV; |
VECTOR f_predMV, b_predMV; |
973 |
|
|
974 |
|
int MVmaxF = 0, MVmaxB = 0; |
975 |
const int32_t TRB = time_pp - time_bp; |
const int32_t TRB = time_pp - time_bp; |
976 |
const int32_t TRD = time_pp; |
const int32_t TRD = time_pp; |
977 |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
985 |
Data_d.rounding = 0; |
Data_d.rounding = 0; |
986 |
Data_d.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP; |
Data_d.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP; |
987 |
Data_d.iQuant = frame->quant; |
Data_d.iQuant = frame->quant; |
988 |
|
Data_d.quant_sq = frame->quant*frame->quant; |
989 |
Data_d.dctSpace = dct_space; |
Data_d.dctSpace = dct_space; |
990 |
Data_d.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); |
Data_d.quant_type = !(pParam->vol_flags & XVID_VOL_MPEGQUANT); |
991 |
Data_d.mpeg_quant_matrices = pParam->mpeg_quant_matrices; |
Data_d.mpeg_quant_matrices = pParam->mpeg_quant_matrices; |
996 |
memcpy(&Data_b, &Data_d, sizeof(SearchData)); |
memcpy(&Data_b, &Data_d, sizeof(SearchData)); |
997 |
memcpy(&Data_i, &Data_d, sizeof(SearchData)); |
memcpy(&Data_i, &Data_d, sizeof(SearchData)); |
998 |
|
|
999 |
Data_f.iFcode = Data_i.iFcode = frame->fcode; |
Data_f.iFcode = Data_i.iFcode = frame->fcode = b_reference->fcode; |
1000 |
Data_b.iFcode = Data_i.bFcode = frame->bcode; |
Data_b.iFcode = Data_i.bFcode = frame->bcode = b_reference->fcode; |
|
|
|
1001 |
|
|
1002 |
for (j = 0; j < pParam->mb_height; j++) { |
for (j = 0; j < pParam->mb_height; j++) { |
1003 |
|
|
1029 |
|
|
1030 |
if (pMB->mode == MODE_DIRECT_NONE_MV) { |
if (pMB->mode == MODE_DIRECT_NONE_MV) { |
1031 |
pMB->sad16 = best_sad; |
pMB->sad16 = best_sad; |
1032 |
|
pMB->cbp = 0; |
1033 |
continue; |
continue; |
1034 |
} |
} |
1035 |
|
|
1039 |
SearchBF_initial(i, j, frame->motion_flags, frame->bcode, pParam, pMB, |
SearchBF_initial(i, j, frame->motion_flags, frame->bcode, pParam, pMB, |
1040 |
&b_predMV, &best_sad, MODE_BACKWARD, &Data_b, Data_d.currentMV[2]); |
&b_predMV, &best_sad, MODE_BACKWARD, &Data_b, Data_d.currentMV[2]); |
1041 |
|
|
1042 |
sad2 = best_sad; |
if (frame->motion_flags&XVID_ME_BFRAME_EARLYSTOP) |
1043 |
|
fb_thresh = best_sad; |
1044 |
|
else |
1045 |
|
fb_thresh = best_sad + (best_sad>>1); |
1046 |
|
|
1047 |
if (Data_f.iMinSAD[0] < 2*sad2+2000) |
if (Data_f.iMinSAD[0] <= fb_thresh) |
1048 |
SearchBF_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_f); |
SearchBF_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_f); |
1049 |
|
|
1050 |
if (Data_b.iMinSAD[0] < 2*sad2+2000) |
if (Data_b.iMinSAD[0] <= fb_thresh) |
1051 |
SearchBF_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_b); |
SearchBF_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_b); |
1052 |
|
|
1053 |
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, |
1054 |
&Data_i, Data_f.currentMV[0], Data_b.currentMV[0]); |
&Data_i, Data_f.currentMV[0], Data_b.currentMV[0]); |
1055 |
|
|
1056 |
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)) |
1057 |
|| Data_i.iMinSAD[0] <= best_sad) |
|| Data_i.iMinSAD[0] <= best_sad) |
1058 |
|
|
1059 |
SearchInterpolate_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_i); |
SearchInterpolate_final(i, j, frame->motion_flags, pParam, &best_sad, &Data_i); |
1060 |
|
|
1061 |
if ((Data_d.iMinSAD[0] <= 2*best_sad) && (!frame->motion_flags&XVID_ME_SKIP_DELTASEARCH)) |
if (Data_d.iMinSAD[0] <= 2*best_sad) |
1062 |
|
if ((!(frame->motion_flags&XVID_ME_SKIP_DELTASEARCH) && (best_sad > 750)) |
1063 |
|
|| (best_sad > 1000)) |
1064 |
|
|
1065 |
SearchDirect_final(frame->motion_flags, b_mb, &best_sad, &Data_d); |
SearchDirect_final(frame->motion_flags, b_mb, &best_sad, &Data_d); |
1066 |
|
|
1067 |
/* final skip decision */ |
/* final skip decision */ |
1074 |
|
|
1075 |
if (pMB->mode == MODE_DIRECT_NONE_MV) { /* skipped? */ |
if (pMB->mode == MODE_DIRECT_NONE_MV) { /* skipped? */ |
1076 |
pMB->sad16 = skip_sad; |
pMB->sad16 = skip_sad; |
1077 |
|
pMB->cbp = 0; |
1078 |
continue; |
continue; |
1079 |
} |
} |
1080 |
} |
} |
1081 |
|
|
1082 |
if (frame->vop_flags & XVID_VOP_RD_BVOP) |
if (frame->vop_flags & XVID_VOP_RD_BVOP) |
1083 |
ModeDecision_BVOP_RD(&Data_d, &Data_b, &Data_f, &Data_i, |
ModeDecision_BVOP_RD(&Data_d, &Data_b, &Data_f, &Data_i, |
1084 |
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); |
1085 |
else |
else |
1086 |
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); |
1087 |
|
|
1088 |
|
maxMotionBVOP(&MVmaxF, &MVmaxB, pMB, Data_d.qpel); |
1089 |
|
|
1090 |
} |
} |
1091 |
} |
} |
1092 |
|
|
1093 |
|
frame->fcode = getMinFcode(MVmaxF); |
1094 |
|
frame->bcode = getMinFcode(MVmaxB); |
1095 |
} |
} |