78 |
#include "quant/quant_matrix.h" |
#include "quant/quant_matrix.h" |
79 |
#include "utils/mem_align.h" |
#include "utils/mem_align.h" |
80 |
|
|
|
#ifdef _SMP |
|
|
#include "motion/smp_motion_est.h" |
|
|
#endif |
|
81 |
/***************************************************************************** |
/***************************************************************************** |
82 |
* Local macros |
* Local macros |
83 |
****************************************************************************/ |
****************************************************************************/ |
210 |
/* 1 keyframe each 10 seconds */ |
/* 1 keyframe each 10 seconds */ |
211 |
|
|
212 |
if (pParam->max_key_interval <= 0) |
if (pParam->max_key_interval <= 0) |
213 |
pParam->max_key_interval = 10 * pParam->fincr / pParam->fbase; |
pParam->max_key_interval = 10 * pParam->fbase / pParam->fincr; |
214 |
|
|
215 |
pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE); |
pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE); |
216 |
if (pEnc == NULL) |
if (pEnc == NULL) |
236 |
|
|
237 |
pEnc->mbParam.m_quant_type = H263_QUANT; |
pEnc->mbParam.m_quant_type = H263_QUANT; |
238 |
|
|
|
#ifdef _SMP |
|
|
pEnc->mbParam.num_threads = MIN(pParam->num_threads, MAXNUMTHREADS); |
|
|
#endif |
|
|
|
|
239 |
pEnc->sStat.fMvPrevSigma = -1; |
pEnc->sStat.fMvPrevSigma = -1; |
240 |
|
|
241 |
/* Fill rate control parameters */ |
/* Fill rate control parameters */ |
543 |
|
|
544 |
} |
} |
545 |
|
|
546 |
BitstreamPutBits(&bs, 0xFFFF, 16); |
/* Fix from CVS_HEAD (2003-03-17) |
547 |
BitstreamPutBits(&bs, 0xFFFF, 16); |
* |
548 |
|
* Relic from OpenDivX - now disabled |
549 |
|
* |
550 |
|
* BitstreamPutBits(&bs, 0xFFFF, 16); |
551 |
|
* BitstreamPutBits(&bs, 0xFFFF, 16); |
552 |
|
*/ |
553 |
BitstreamPad(&bs); |
BitstreamPad(&bs); |
554 |
pFrame->length = BitstreamLength(&bs); |
pFrame->length = BitstreamLength(&bs); |
555 |
|
|
641 |
return; |
return; |
642 |
} |
} |
643 |
|
|
644 |
pEnc->current->fcode = |
pEnc->current->fcode = (hint->rawhints != 0) ? |
645 |
(hint->rawhints) ? hint->mvhint.fcode : BitstreamGetBits(&bs, |
(uint32_t)hint->mvhint.fcode : BitstreamGetBits(&bs, FCODEBITS); |
|
FCODEBITS); |
|
646 |
|
|
647 |
length = pEnc->current->fcode + 5; |
length = pEnc->current->fcode + 5; |
648 |
high = 1 << (length - 1); |
high = 1 << (length - 1); |
657 |
VECTOR tmp; |
VECTOR tmp; |
658 |
int vec; |
int vec; |
659 |
|
|
660 |
pMB->mode = |
pMB->mode = (hint->rawhints != 0) ? |
661 |
(hint->rawhints) ? bhint->mode : BitstreamGetBits(&bs, |
(uint32_t)bhint->mode : BitstreamGetBits(&bs, MODEBITS); |
|
MODEBITS); |
|
662 |
|
|
663 |
pMB->mode = (pMB->mode == MODE_INTER_Q) ? MODE_INTER : pMB->mode; |
pMB->mode = (pMB->mode == MODE_INTER_Q) ? MODE_INTER : pMB->mode; |
664 |
pMB->mode = (pMB->mode == MODE_INTRA_Q) ? MODE_INTRA : pMB->mode; |
pMB->mode = (pMB->mode == MODE_INTRA_Q) ? MODE_INTRA : pMB->mode; |
665 |
|
|
666 |
if (pMB->mode == MODE_INTER) { |
if (pMB->mode == MODE_INTER) { |
667 |
tmp.x = |
tmp.x = (hint->rawhints) ? |
668 |
(hint->rawhints) ? bhint->mvs[0].x : BitstreamGetBits(&bs, |
bhint->mvs[0].x : (int)BitstreamGetBits(&bs, length); |
669 |
length); |
tmp.y = (hint->rawhints) ? |
670 |
tmp.y = |
bhint->mvs[0].y : (int)BitstreamGetBits(&bs, length); |
|
(hint->rawhints) ? bhint->mvs[0].y : BitstreamGetBits(&bs, |
|
|
length); |
|
671 |
tmp.x -= (tmp.x >= high) ? high * 2 : 0; |
tmp.x -= (tmp.x >= high) ? high * 2 : 0; |
672 |
tmp.y -= (tmp.y >= high) ? high * 2 : 0; |
tmp.y -= (tmp.y >= high) ? high * 2 : 0; |
673 |
|
|
681 |
} |
} |
682 |
} else if (pMB->mode == MODE_INTER4V) { |
} else if (pMB->mode == MODE_INTER4V) { |
683 |
for (vec = 0; vec < 4; ++vec) { |
for (vec = 0; vec < 4; ++vec) { |
684 |
tmp.x = |
tmp.x = (hint->rawhints) ? |
685 |
(hint->rawhints) ? bhint->mvs[vec]. |
bhint->mvs[vec].x : (int)BitstreamGetBits(&bs, length); |
686 |
x : BitstreamGetBits(&bs, length); |
tmp.y = (hint->rawhints) ? |
687 |
tmp.y = |
bhint->mvs[vec].y : (int)BitstreamGetBits(&bs, length); |
|
(hint->rawhints) ? bhint->mvs[vec]. |
|
|
y : BitstreamGetBits(&bs, length); |
|
688 |
tmp.x -= (tmp.x >= high) ? high * 2 : 0; |
tmp.x -= (tmp.x >= high) ? high * 2 : 0; |
689 |
tmp.y -= (tmp.y >= high) ? high * 2 : 0; |
tmp.y -= (tmp.y >= high) ? high * 2 : 0; |
690 |
|
|
924 |
HintedMESet(pEnc, &bIntra); |
HintedMESet(pEnc, &bIntra); |
925 |
} else { |
} else { |
926 |
|
|
|
#ifdef _SMP |
|
|
if (pEnc->mbParam.num_threads > 1) |
|
|
bIntra = |
|
|
SMP_MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference, |
|
|
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
|
|
iLimit); |
|
|
else |
|
|
#endif |
|
927 |
bIntra = |
bIntra = |
928 |
MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference, |
MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference, |
929 |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |