96 |
if (pParam->max_quantizer < pParam->min_quantizer) |
if (pParam->max_quantizer < pParam->min_quantizer) |
97 |
pParam->max_quantizer = pParam->min_quantizer; |
pParam->max_quantizer = pParam->min_quantizer; |
98 |
|
|
99 |
if ((pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), 16)) == NULL) |
if ((pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE)) == NULL) |
100 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
101 |
|
|
102 |
/* Fill members of Encoder structure */ |
/* Fill members of Encoder structure */ |
161 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
162 |
} |
} |
163 |
|
|
164 |
pEnc->pMBs = xvid_malloc(sizeof(MACROBLOCK) * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height, 16); |
pEnc->pMBs = xvid_malloc(sizeof(MACROBLOCK) * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height, CACHE_LINE); |
165 |
if (pEnc->pMBs == NULL) |
if (pEnc->pMBs == NULL) |
166 |
{ |
{ |
167 |
image_destroy(&pEnc->sCurrent, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height); |
image_destroy(&pEnc->sCurrent, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height); |
253 |
|
|
254 |
if ((pEnc->mbParam.global_flags & XVID_LUMIMASKING) > 0) |
if ((pEnc->mbParam.global_flags & XVID_LUMIMASKING) > 0) |
255 |
{ |
{ |
256 |
int * temp_dquants = (int *) xvid_malloc(pEnc->mbParam.mb_width * pEnc->mbParam.mb_height * sizeof(int), 16); |
int * temp_dquants = (int *) xvid_malloc(pEnc->mbParam.mb_width * pEnc->mbParam.mb_height * sizeof(int), CACHE_LINE); |
257 |
|
|
258 |
pEnc->mbParam.quant = adaptive_quantization(pEnc->sCurrent.y, pEnc->mbParam.width, |
pEnc->mbParam.quant = adaptive_quantization(pEnc->sCurrent.y, pEnc->mbParam.width, |
259 |
temp_dquants, pFrame->quant, pFrame->quant, |
temp_dquants, pFrame->quant, pFrame->quant, |
364 |
|
|
365 |
static int FrameCodeI(Encoder * pEnc, Bitstream * bs, uint32_t *pBits) |
static int FrameCodeI(Encoder * pEnc, Bitstream * bs, uint32_t *pBits) |
366 |
{ |
{ |
367 |
|
#ifdef LINUX |
368 |
|
DECLARE_ALIGNED_MATRIX(dct_codes,6,64,int16_t,16); |
369 |
|
DECLARE_ALIGNED_MATRIX(qcoeff,6,64,int16_t,16); |
370 |
|
#else |
371 |
CACHE_ALIGN int16_t dct_codes[6][64]; |
CACHE_ALIGN int16_t dct_codes[6][64]; |
372 |
CACHE_ALIGN int16_t qcoeff[6][64]; |
CACHE_ALIGN int16_t qcoeff[6][64]; |
373 |
|
#endif |
374 |
uint16_t x, y; |
uint16_t x, y; |
375 |
|
|
376 |
pEnc->iFrameNum = 0; |
pEnc->iFrameNum = 0; |
377 |
pEnc->mbParam.rounding_type = 1; |
pEnc->mbParam.rounding_type = 1; |
378 |
pEnc->mbParam.coding_type = I_VOP; |
pEnc->mbParam.coding_type = I_VOP; |
379 |
|
|
380 |
BitstreamWriteVolHeader(bs, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.quant_type); |
BitstreamWriteVolHeader(bs, &pEnc->mbParam); |
381 |
BitstreamWriteVopHeader(bs, I_VOP, pEnc->mbParam.rounding_type, |
BitstreamWriteVopHeader(bs, &pEnc->mbParam); |
|
pEnc->mbParam.quant, |
|
|
pEnc->mbParam.fixed_code); |
|
382 |
|
|
383 |
*pBits = BitstreamPos(bs); |
*pBits = BitstreamPos(bs); |
384 |
|
|
393 |
|
|
394 |
CodeIntraMB(pEnc, pMB); |
CodeIntraMB(pEnc, pMB); |
395 |
|
|
396 |
MBTransQuantIntra(&pEnc->mbParam, x, y, dct_codes, qcoeff, &pEnc->sCurrent); |
MBTransQuantIntra(&pEnc->mbParam, pMB, x, y, dct_codes, qcoeff, &pEnc->sCurrent); |
397 |
|
|
398 |
start_timer(); |
start_timer(); |
399 |
MBPrediction(&pEnc->mbParam, x, y, pEnc->mbParam.mb_width, qcoeff, pEnc->pMBs); |
MBPrediction(&pEnc->mbParam, x, y, pEnc->mbParam.mb_width, qcoeff, pEnc->pMBs); |
421 |
static int FrameCodeP(Encoder * pEnc, Bitstream * bs, uint32_t *pBits, bool force_inter, bool vol_header) |
static int FrameCodeP(Encoder * pEnc, Bitstream * bs, uint32_t *pBits, bool force_inter, bool vol_header) |
422 |
{ |
{ |
423 |
float fSigma; |
float fSigma; |
424 |
|
#ifdef LINUX |
425 |
|
DECLARE_ALIGNED_MATRIX(dct_codes,6,64,int16_t,16); |
426 |
|
DECLARE_ALIGNED_MATRIX(qcoeff,6,64,int16_t,16); |
427 |
|
#else |
428 |
CACHE_ALIGN int16_t dct_codes[6][64]; |
CACHE_ALIGN int16_t dct_codes[6][64]; |
429 |
CACHE_ALIGN int16_t qcoeff[6][64]; |
CACHE_ALIGN int16_t qcoeff[6][64]; |
430 |
|
#endif |
431 |
|
|
432 |
int iLimit; |
int iLimit; |
433 |
uint32_t x, y; |
uint32_t x, y; |
437 |
IMAGE *pCurrent = &pEnc->sCurrent; |
IMAGE *pCurrent = &pEnc->sCurrent; |
438 |
IMAGE *pRef = &pEnc->sReference; |
IMAGE *pRef = &pEnc->sReference; |
439 |
|
|
440 |
image_setedges(pRef,pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, pEnc->mbParam.width, pEnc->mbParam.height); |
start_timer(); |
441 |
|
image_setedges(pRef,pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.global_flags & XVID_INTERLACING); |
442 |
|
stop_edges_timer(); |
443 |
|
|
444 |
pEnc->mbParam.rounding_type = 1 - pEnc->mbParam.rounding_type; |
pEnc->mbParam.rounding_type = 1 - pEnc->mbParam.rounding_type; |
445 |
|
|
468 |
pEnc->mbParam.coding_type = P_VOP; |
pEnc->mbParam.coding_type = P_VOP; |
469 |
|
|
470 |
if(vol_header) |
if(vol_header) |
471 |
BitstreamWriteVolHeader(bs, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.quant_type); |
BitstreamWriteVolHeader(bs, &pEnc->mbParam); |
472 |
|
|
473 |
BitstreamWriteVopHeader(bs, P_VOP, pEnc->mbParam.rounding_type, |
BitstreamWriteVopHeader(bs, &pEnc->mbParam); |
|
pEnc->mbParam.quant, |
|
|
pEnc->mbParam.fixed_code); |
|
474 |
|
|
475 |
*pBits = BitstreamPos(bs); |
*pBits = BitstreamPos(bs); |
476 |
|
|
509 |
} |
} |
510 |
pMB->quant = pEnc->mbParam.quant; |
pMB->quant = pEnc->mbParam.quant; |
511 |
|
|
512 |
pMB->cbp = MBTransQuantInter(&pEnc->mbParam, x, y, dct_codes, qcoeff, pCurrent); |
pMB->field_pred = 0; |
513 |
|
|
514 |
|
pMB->cbp = MBTransQuantInter(&pEnc->mbParam, pMB, x, y, dct_codes, qcoeff, pCurrent); |
515 |
} |
} |
516 |
else |
else |
517 |
{ |
{ |
518 |
CodeIntraMB(pEnc, pMB); |
CodeIntraMB(pEnc, pMB); |
519 |
MBTransQuantIntra(&pEnc->mbParam, x, y, dct_codes, qcoeff, pCurrent); |
MBTransQuantIntra(&pEnc->mbParam, pMB, x, y, dct_codes, qcoeff, pCurrent); |
520 |
} |
} |
521 |
|
|
522 |
start_timer(); |
start_timer(); |