33 |
#include "motion_inlines.h" |
#include "motion_inlines.h" |
34 |
|
|
35 |
|
|
36 |
#define INTRA_THRESH 2200 |
#define INTRA_THRESH 2000 |
37 |
#define INTER_THRESH 40 |
#define INTER_THRESH 40 |
38 |
#define INTRA_THRESH2 95 |
#define INTRA_THRESH2 90 |
39 |
|
|
40 |
static void |
static void |
41 |
CheckCandidate32I(const int x, const int y, const SearchData * const data, const unsigned int Direction) |
CheckCandidate32I(const int x, const int y, SearchData * const data, const unsigned int Direction) |
42 |
{ |
{ |
43 |
/* maximum speed */ |
/* maximum speed */ |
44 |
int32_t sad; |
int32_t sad; |
52 |
if (sad < *(data->iMinSAD)) { |
if (sad < *(data->iMinSAD)) { |
53 |
*(data->iMinSAD) = sad; |
*(data->iMinSAD) = sad; |
54 |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
data->currentMV[0].x = x; data->currentMV[0].y = y; |
55 |
*data->dir = Direction; |
data->dir = Direction; |
56 |
} |
} |
57 |
if (data->temp[0] < data->iMinSAD[1]) { |
if (data->temp[0] < data->iMinSAD[1]) { |
58 |
data->iMinSAD[1] = data->temp[0]; data->currentMV[1].x = x; data->currentMV[1].y = y; } |
data->iMinSAD[1] = data->temp[0]; data->currentMV[1].x = x; data->currentMV[1].y = y; } |
115 |
CheckCandidate32I(pmv[2].x, pmv[2].y, Data, 2); |
CheckCandidate32I(pmv[2].x, pmv[2].y, Data, 2); |
116 |
|
|
117 |
if (*Data->iMinSAD > 500) { /* diamond only if needed */ |
if (*Data->iMinSAD > 500) { /* diamond only if needed */ |
118 |
unsigned int mask = make_mask(pmv, 3, *Data->dir); |
unsigned int mask = make_mask(pmv, 3, Data->dir); |
119 |
xvid_me_DiamondSearch(Data->currentMV->x, Data->currentMV->y, Data, mask, CheckCandidate32I); |
xvid_me_DiamondSearch(Data->currentMV->x, Data->currentMV->y, Data, mask, CheckCandidate32I); |
120 |
} else simplicity++; |
} else simplicity++; |
121 |
|
|
140 |
const int maxIntra, /* maximum number if non-I frames */ |
const int maxIntra, /* maximum number if non-I frames */ |
141 |
const int intraCount, /* number of non-I frames after last I frame; 0 if we force P/B frame */ |
const int intraCount, /* number of non-I frames after last I frame; 0 if we force P/B frame */ |
142 |
const int bCount, /* number of B frames in a row */ |
const int bCount, /* number of B frames in a row */ |
143 |
const int b_thresh) |
const int b_thresh, |
144 |
|
const MACROBLOCK * const prev_mbs) |
145 |
{ |
{ |
146 |
uint32_t x, y, intra = 0; |
uint32_t x, y, intra = 0; |
147 |
int sSAD = 0; |
int sSAD = 0; |
148 |
MACROBLOCK * const pMBs = Current->mbs; |
MACROBLOCK * const pMBs = Current->mbs; |
149 |
const IMAGE * const pCurrent = &Current->image; |
const IMAGE * const pCurrent = &Current->image; |
150 |
int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH + b_thresh; |
int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH + b_thresh; |
151 |
int blocks = 0; |
int blocks = 10; |
152 |
int complexity = 0; |
int complexity = 0; |
153 |
|
|
|
int32_t iMinSAD[5], temp[5]; |
|
|
uint32_t dir; |
|
|
VECTOR currentMV[5]; |
|
154 |
SearchData Data; |
SearchData Data; |
155 |
Data.iEdgedWidth = pParam->edged_width; |
Data.iEdgedWidth = pParam->edged_width; |
|
Data.currentMV = currentMV; |
|
|
Data.iMinSAD = iMinSAD; |
|
156 |
Data.iFcode = Current->fcode; |
Data.iFcode = Current->fcode; |
|
Data.temp = temp; |
|
|
Data.dir = &dir; |
|
157 |
Data.qpel = (pParam->vol_flags & XVID_VOL_QUARTERPEL)? 1: 0; |
Data.qpel = (pParam->vol_flags & XVID_VOL_QUARTERPEL)? 1: 0; |
158 |
Data.qpel_precision = 0; |
Data.qpel_precision = 0; |
159 |
|
|
178 |
if (bCount == 0) pMBs[x + y * pParam->mb_width].mvs[0] = zeroMV; |
if (bCount == 0) pMBs[x + y * pParam->mb_width].mvs[0] = zeroMV; |
179 |
else { /* extrapolation of the vector found for last frame */ |
else { /* extrapolation of the vector found for last frame */ |
180 |
pMBs[x + y * pParam->mb_width].mvs[0].x = |
pMBs[x + y * pParam->mb_width].mvs[0].x = |
181 |
(pMBs[x + y * pParam->mb_width].mvs[0].x * (bCount+1) ) / bCount; |
(prev_mbs[x + y * pParam->mb_width].mvs[0].x * (bCount+1) ) / bCount; |
182 |
pMBs[x + y * pParam->mb_width].mvs[0].y = |
pMBs[x + y * pParam->mb_width].mvs[0].y = |
183 |
(pMBs[x + y * pParam->mb_width].mvs[0].y * (bCount+1) ) / bCount; |
(prev_mbs[x + y * pParam->mb_width].mvs[0].y * (bCount+1) ) / bCount; |
184 |
} |
} |
185 |
|
|
186 |
MEanalyzeMB(pRef->y, pCurrent->y, x, y, pParam, pMBs, &Data); |
MEanalyzeMB(pRef->y, pCurrent->y, x, y, pParam, pMBs, &Data); |
209 |
|
|
210 |
sSAD /= complexity + 4*blocks; |
sSAD /= complexity + 4*blocks; |
211 |
|
|
212 |
if (intraCount > 80 && sSAD > INTRA_THRESH2 ) return I_VOP; |
if (intraCount > 60 && sSAD > INTRA_THRESH2 ) return I_VOP; |
213 |
if (sSAD > InterThresh ) return P_VOP; |
if (sSAD > InterThresh ) return P_VOP; |
214 |
emms(); |
emms(); |
215 |
return B_VOP; |
return B_VOP; |