21 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
* |
* |
24 |
* $Id: encoder.c,v 1.102.2.1 2004-03-31 19:35:31 edgomez Exp $ |
* $Id: encoder.c,v 1.102.2.2 2004-04-03 10:39:27 syskin Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
57 |
Bitstream * bs); |
Bitstream * bs); |
58 |
|
|
59 |
static int FrameCodeP(Encoder * pEnc, |
static int FrameCodeP(Encoder * pEnc, |
60 |
Bitstream * bs, |
Bitstream * bs); |
|
bool force_inter, |
|
|
bool vol_header); |
|
61 |
|
|
62 |
static void FrameCodeB(Encoder * pEnc, |
static void FrameCodeB(Encoder * pEnc, |
63 |
FRAMEINFO * frame, |
FRAMEINFO * frame, |
1089 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1090 |
pEnc->mbParam.frame_drop_ratio = -1; /* it must be a coded vop */ |
pEnc->mbParam.frame_drop_ratio = -1; /* it must be a coded vop */ |
1091 |
|
|
1092 |
FrameCodeP(pEnc, &bs, 1, 0); |
FrameCodeP(pEnc, &bs); |
1093 |
|
|
1094 |
|
|
1095 |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) { |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) { |
1341 |
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
1342 |
} |
} |
1343 |
|
|
1344 |
if ( FrameCodeP(pEnc, &bs, 1, 0) == 0 ) { |
if ( FrameCodeP(pEnc, &bs) == 0 ) { |
1345 |
/* N-VOP, we mustn't code b-frames yet */ |
/* N-VOP, we mustn't code b-frames yet */ |
1346 |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
1347 |
goto done; |
goto done; |
1523 |
/* FrameCodeP also handles S(GMC)-VOPs */ |
/* FrameCodeP also handles S(GMC)-VOPs */ |
1524 |
static int |
static int |
1525 |
FrameCodeP(Encoder * pEnc, |
FrameCodeP(Encoder * pEnc, |
1526 |
Bitstream * bs, |
Bitstream * bs) |
|
bool force_inter, |
|
|
bool vol_header) |
|
1527 |
{ |
{ |
1528 |
float fSigma; |
float fSigma; |
1529 |
int bits = BitstreamPos(bs); |
int bits = BitstreamPos(bs); |
1531 |
DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE); |
1532 |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
1533 |
|
|
|
int iLimit; |
|
1534 |
int x, y, k; |
int x, y, k; |
1535 |
int iSearchRange; |
int iSearchRange; |
1536 |
int bIntra=0, skip_possible; |
int skip_possible; |
1537 |
FRAMEINFO *const current = pEnc->current; |
FRAMEINFO *const current = pEnc->current; |
1538 |
FRAMEINFO *const reference = pEnc->reference; |
FRAMEINFO *const reference = pEnc->reference; |
1539 |
MBParam * const pParam = &pEnc->mbParam; |
MBParam * const pParam = &pEnc->mbParam; |
1564 |
current->rounding_type = pParam->m_rounding_type; |
current->rounding_type = pParam->m_rounding_type; |
1565 |
current->fcode = pParam->m_fcode; |
current->fcode = pParam->m_fcode; |
1566 |
|
|
|
if (!force_inter) |
|
|
iLimit = (int)(mb_width * mb_height * INTRA_THRESHOLD); |
|
|
else |
|
|
iLimit = mb_width * mb_height + 1; |
|
|
|
|
1567 |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
1568 |
if (reference->is_interpolated != current->rounding_type) { |
if (reference->is_interpolated != current->rounding_type) { |
1569 |
start_timer(); |
start_timer(); |
1634 |
} |
} |
1635 |
} |
} |
1636 |
|
|
|
bIntra = |
|
1637 |
MotionEstimation(&pEnc->mbParam, current, reference, |
MotionEstimation(&pEnc->mbParam, current, reference, |
1638 |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
1639 |
&pEnc->vGMC, iLimit); |
&pEnc->vGMC, 256*4096); |
1640 |
|
|
1641 |
|
|
1642 |
stop_motion_timer(); |
stop_motion_timer(); |
1643 |
|
|
|
if (bIntra == 1) return FrameCodeI(pEnc, bs); |
|
|
|
|
1644 |
set_timecodes(current,reference,pParam->fbase); |
set_timecodes(current,reference,pParam->fbase); |
|
if (vol_header) |
|
|
{ BitstreamWriteVolHeader(bs, &pEnc->mbParam, current); |
|
|
BitstreamPad(bs); |
|
|
} |
|
1645 |
|
|
1646 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant); |
1647 |
|
|
1654 |
MACROBLOCK *pMB = |
MACROBLOCK *pMB = |
1655 |
¤t->mbs[x + y * pParam->mb_width]; |
¤t->mbs[x + y * pParam->mb_width]; |
1656 |
|
|
1657 |
bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); |
int bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); |
1658 |
|
|
1659 |
if (bIntra) { |
if (bIntra) { |
1660 |
CodeIntraMB(pEnc, pMB); |
CodeIntraMB(pEnc, pMB); |