19 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
22 |
* $Id: vop_type_decision.c,v 1.1.2.5 2003-11-19 12:24:25 syskin Exp $ |
* $Id: vop_type_decision.c,v 1.1.2.6 2003-12-04 12:08:03 syskin Exp $ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
37 |
#define INTER_THRESH 40 |
#define INTER_THRESH 40 |
38 |
#define INTRA_THRESH2 90 |
#define INTRA_THRESH2 90 |
39 |
|
|
40 |
|
/* when we are in 1/I_SENS_TH before forced keyframe, we start to decrese i-frame threshold */ |
41 |
|
#define I_SENS_TH 3 |
42 |
|
|
43 |
|
/* how much we subtract from each p-frame threshold for 2nd, 3rd etc. b-frame in a row */ |
44 |
|
#define P_SENS_BIAS 18 |
45 |
|
|
46 |
|
/* .. but never below INTER_THRESH_MIN */ |
47 |
|
#define INTER_THRESH_MIN 5 |
48 |
|
|
49 |
static void |
static void |
50 |
CheckCandidate32I(const int x, const int y, SearchData * const data, const unsigned int Direction) |
CheckCandidate32I(const int x, const int y, SearchData * const data, const unsigned int Direction) |
51 |
{ |
{ |
156 |
int sSAD = 0; |
int sSAD = 0; |
157 |
MACROBLOCK * const pMBs = Current->mbs; |
MACROBLOCK * const pMBs = Current->mbs; |
158 |
const IMAGE * const pCurrent = &Current->image; |
const IMAGE * const pCurrent = &Current->image; |
159 |
int IntraThresh = INTRA_THRESH, InterThresh = INTER_THRESH + b_thresh; |
int IntraThresh = INTRA_THRESH, |
160 |
|
InterThresh = INTER_THRESH + b_thresh, |
161 |
|
IntraThresh2 = INTRA_THRESH2; |
162 |
|
|
163 |
int blocks = 10; |
int blocks = 10; |
164 |
int complexity = 0; |
int complexity = 0; |
165 |
|
|
170 |
Data.qpel_precision = 0; |
Data.qpel_precision = 0; |
171 |
|
|
172 |
if (intraCount != 0) { |
if (intraCount != 0) { |
173 |
if (intraCount < 10) /* we're right after an I frame */ |
if (intraCount < 30) { |
174 |
IntraThresh += 15* (intraCount - 10) * (intraCount - 10); |
/* we're right after an I frame |
175 |
else |
we increase thresholds to prevent consecutive i-frames */ |
176 |
if ( 5*(maxIntra - intraCount) < maxIntra) /* we're close to maximum. 2 sec when max is 10 sec */ |
if (intraCount < 10) IntraThresh += 15*(10 - intraCount)*(10 - intraCount); |
177 |
IntraThresh -= (IntraThresh * (maxIntra - 8*(maxIntra - intraCount)))/maxIntra; |
IntraThresh2 += 4*(30 - intraCount); |
178 |
|
} else if (I_SENS_TH*(maxIntra - intraCount) < maxIntra) { |
179 |
|
/* we're close to maximum. we decrease thresholds to catch any good keyframe */ |
180 |
|
IntraThresh -= IntraThresh*((maxIntra - I_SENS_TH*(maxIntra - intraCount))/maxIntra); |
181 |
|
IntraThresh2 -= IntraThresh2*((maxIntra - I_SENS_TH*(maxIntra - intraCount))/maxIntra); |
182 |
|
} |
183 |
} |
} |
184 |
|
|
185 |
InterThresh -= 20 * bCount; |
InterThresh -= P_SENS_BIAS * bCount; |
186 |
if (InterThresh < 10 + b_thresh) InterThresh = 10 + b_thresh; |
if (InterThresh < INTER_THRESH_MIN) InterThresh = INTER_THRESH_MIN; |
187 |
|
|
188 |
if (sadInit) (*sadInit) (); |
if (sadInit) (*sadInit) (); |
189 |
|
|
216 |
|
|
217 |
if (pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0) |
if (pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0) |
218 |
if (dev > 1000 && pMB->sad16 < 1000) |
if (dev > 1000 && pMB->sad16 < 1000) |
219 |
sSAD += 1000; |
sSAD += 512; |
220 |
|
|
221 |
sSAD += (dev < 4000) ? pMB->sad16 : pMB->sad16/2; /* blocks with big contrast differences usually have large SAD - while they look very good in b-frames */ |
sSAD += (dev < 3000) ? pMB->sad16 : pMB->sad16/2; /* blocks with big contrast differences usually have large SAD - while they look very good in b-frames */ |
222 |
} |
} |
223 |
} |
} |
224 |
} |
} |
226 |
|
|
227 |
sSAD /= complexity + 4*blocks; |
sSAD /= complexity + 4*blocks; |
228 |
|
|
229 |
if (intraCount > 60 && sSAD > INTRA_THRESH2 ) return I_VOP; |
if (sSAD > IntraThresh2) return I_VOP; |
230 |
if (sSAD > InterThresh ) return P_VOP; |
if (sSAD > InterThresh ) return P_VOP; |
231 |
emms(); |
emms(); |
232 |
return B_VOP; |
return B_VOP; |