57 |
Bitstream * bs); |
Bitstream * bs); |
58 |
|
|
59 |
static int FrameCodeP(Encoder * pEnc, |
static int FrameCodeP(Encoder * pEnc, |
60 |
Bitstream * bs); |
Bitstream * bs, |
61 |
|
bool force_inter, |
62 |
|
bool vol_header); |
63 |
|
|
64 |
static void FrameCodeB(Encoder * pEnc, |
static void FrameCodeB(Encoder * pEnc, |
65 |
FRAMEINFO * frame, |
FRAMEINFO * frame, |
102 |
i--; |
i--; |
103 |
} |
} |
104 |
|
|
105 |
if (*base > 65535 || *inc > 65535) { |
/* if neccessary, round to 65535 accuracy */ |
106 |
int *biggest; |
if (*base > 65535) { |
107 |
int *other; |
float div = (float) *base / 65535; |
108 |
|
*base = (int) (*base / div); |
109 |
if (*base > *inc) { |
*inc = (int) (*inc / div); |
|
biggest = base; |
|
|
other = inc; |
|
|
} else { |
|
|
biggest = inc; |
|
|
other = base; |
|
|
} |
|
|
|
|
|
float div = ((float)*biggest)/((float)65535); |
|
|
*biggest = (int)(((float)*biggest)/div); |
|
|
*other = (int)(((float)*other)/div); |
|
110 |
} |
} |
111 |
} |
} |
112 |
|
|
1091 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1092 |
pEnc->mbParam.frame_drop_ratio = -1; /* it must be a coded vop */ |
pEnc->mbParam.frame_drop_ratio = -1; /* it must be a coded vop */ |
1093 |
|
|
1094 |
FrameCodeP(pEnc, &bs); |
FrameCodeP(pEnc, &bs, 1, 0); |
1095 |
|
|
1096 |
|
|
1097 |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) { |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) { |
1343 |
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
1344 |
} |
} |
1345 |
|
|
1346 |
if ( FrameCodeP(pEnc, &bs) == 0 ) { |
if ( FrameCodeP(pEnc, &bs, 1, 0) == 0 ) { |
1347 |
/* N-VOP, we mustn't code b-frames yet */ |
/* N-VOP, we mustn't code b-frames yet */ |
1348 |
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); |
1349 |
goto done; |
goto done; |
1525 |
/* FrameCodeP also handles S(GMC)-VOPs */ |
/* FrameCodeP also handles S(GMC)-VOPs */ |
1526 |
static int |
static int |
1527 |
FrameCodeP(Encoder * pEnc, |
FrameCodeP(Encoder * pEnc, |
1528 |
Bitstream * bs) |
Bitstream * bs, |
1529 |
|
bool force_inter, |
1530 |
|
bool vol_header) |
1531 |
{ |
{ |
1532 |
float fSigma; |
float fSigma; |
1533 |
int bits = BitstreamPos(bs); |
int bits = BitstreamPos(bs); |
1535 |
DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE); |
1536 |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
1537 |
|
|
1538 |
|
int iLimit; |
1539 |
int x, y, k; |
int x, y, k; |
1540 |
int iSearchRange; |
int iSearchRange; |
1541 |
int skip_possible; |
int bIntra=0, skip_possible; |
1542 |
FRAMEINFO *const current = pEnc->current; |
FRAMEINFO *const current = pEnc->current; |
1543 |
FRAMEINFO *const reference = pEnc->reference; |
FRAMEINFO *const reference = pEnc->reference; |
1544 |
MBParam * const pParam = &pEnc->mbParam; |
MBParam * const pParam = &pEnc->mbParam; |
1569 |
current->rounding_type = pParam->m_rounding_type; |
current->rounding_type = pParam->m_rounding_type; |
1570 |
current->fcode = pParam->m_fcode; |
current->fcode = pParam->m_fcode; |
1571 |
|
|
1572 |
|
if (!force_inter) |
1573 |
|
iLimit = (int)(mb_width * mb_height * INTRA_THRESHOLD); |
1574 |
|
else |
1575 |
|
iLimit = mb_width * mb_height + 1; |
1576 |
|
|
1577 |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
1578 |
if (reference->is_interpolated != current->rounding_type) { |
if (reference->is_interpolated != current->rounding_type) { |
1579 |
start_timer(); |
start_timer(); |
1644 |
} |
} |
1645 |
} |
} |
1646 |
|
|
1647 |
|
bIntra = |
1648 |
MotionEstimation(&pEnc->mbParam, current, reference, |
MotionEstimation(&pEnc->mbParam, current, reference, |
1649 |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
1650 |
&pEnc->vGMC, 256*4096); |
&pEnc->vGMC, iLimit); |
1651 |
|
|
1652 |
|
|
1653 |
stop_motion_timer(); |
stop_motion_timer(); |
1654 |
|
|
1655 |
|
if (bIntra == 1) return FrameCodeI(pEnc, bs); |
1656 |
|
|
1657 |
set_timecodes(current,reference,pParam->fbase); |
set_timecodes(current,reference,pParam->fbase); |
1658 |
|
if (vol_header) |
1659 |
|
{ BitstreamWriteVolHeader(bs, &pEnc->mbParam, current); |
1660 |
|
BitstreamPad(bs); |
1661 |
|
} |
1662 |
|
|
1663 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant); |
1664 |
|
|
1671 |
MACROBLOCK *pMB = |
MACROBLOCK *pMB = |
1672 |
¤t->mbs[x + y * pParam->mb_width]; |
¤t->mbs[x + y * pParam->mb_width]; |
1673 |
|
|
1674 |
int bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); |
bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); |
1675 |
|
|
1676 |
if (bIntra) { |
if (bIntra) { |
1677 |
CodeIntraMB(pEnc, pMB); |
CodeIntraMB(pEnc, pMB); |
1873 |
DPRINTF(XVID_DEBUG_DEBUG, "kmu %i %i %i\n", current->sStat.kblks, current->sStat.mblks, current->sStat.ublks); |
DPRINTF(XVID_DEBUG_DEBUG, "kmu %i %i %i\n", current->sStat.kblks, current->sStat.mblks, current->sStat.ublks); |
1874 |
#endif |
#endif |
1875 |
if (current->sStat.kblks + current->sStat.mblks <= |
if (current->sStat.kblks + current->sStat.mblks <= |
1876 |
(pParam->frame_drop_ratio * mb_width * mb_height) / 100 && |
(pParam->frame_drop_ratio * mb_width * mb_height) / 100) |
|
pEnc->mbParam.max_bframes == 0) |
|
1877 |
{ |
{ |
1878 |
current->sStat.kblks = current->sStat.mblks = 0; |
current->sStat.kblks = current->sStat.mblks = 0; |
1879 |
current->sStat.ublks = mb_width * mb_height; |
current->sStat.ublks = mb_width * mb_height; |