1479 |
stop_prediction_timer(); |
stop_prediction_timer(); |
1480 |
|
|
1481 |
start_timer(); |
start_timer(); |
|
if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE) |
|
|
{ pMB->cbp &= 0x3C; /* keep only bits 5-2 */ |
|
|
qcoeff[4*64+0]=0; /* zero, because for INTRA MBs DC value is saved */ |
|
|
qcoeff[5*64+0]=0; |
|
|
} |
|
1482 |
MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat); |
MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat); |
1483 |
stop_coding_timer(); |
stop_coding_timer(); |
1484 |
} |
} |
1498 |
return 1; /* intra */ |
return 1; /* intra */ |
1499 |
} |
} |
1500 |
|
|
1501 |
|
static __inline void |
1502 |
|
updateFcode(Statistics * sStat, Encoder * pEnc) |
1503 |
|
{ |
1504 |
|
float fSigma; |
1505 |
|
int iSearchRange; |
1506 |
|
|
1507 |
#define INTRA_THRESHOLD 0.5 |
if (sStat->iMvCount == 0) |
1508 |
#define BFRAME_SKIP_THRESHHOLD 30 |
sStat->iMvCount = 1; |
1509 |
|
|
1510 |
|
fSigma = (float) sqrt((float) sStat->iMvSum / sStat->iMvCount); |
1511 |
|
|
1512 |
|
iSearchRange = 16 << pEnc->mbParam.m_fcode; |
1513 |
|
|
1514 |
|
if ((3.0 * fSigma > iSearchRange) && (pEnc->mbParam.m_fcode <= 5) ) |
1515 |
|
pEnc->mbParam.m_fcode++; |
1516 |
|
|
1517 |
|
else if ((5.0 * fSigma < iSearchRange) |
1518 |
|
&& (4.0 * pEnc->fMvPrevSigma < iSearchRange) |
1519 |
|
&& (pEnc->mbParam.m_fcode >= 2) ) |
1520 |
|
pEnc->mbParam.m_fcode--; |
1521 |
|
|
1522 |
|
pEnc->fMvPrevSigma = fSigma; |
1523 |
|
} |
1524 |
|
|
1525 |
|
#define BFRAME_SKIP_THRESHHOLD 30 |
1526 |
|
|
1527 |
/* FrameCodeP also handles S(GMC)-VOPs */ |
/* FrameCodeP also handles S(GMC)-VOPs */ |
1528 |
static int |
static int |
1529 |
FrameCodeP(Encoder * pEnc, |
FrameCodeP(Encoder * pEnc, |
1530 |
Bitstream * bs) |
Bitstream * bs) |
1531 |
{ |
{ |
|
float fSigma; |
|
1532 |
int bits = BitstreamPos(bs); |
int bits = BitstreamPos(bs); |
1533 |
|
|
1534 |
DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE); |
1535 |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
1536 |
|
|
1537 |
int x, y, k; |
int x, y, k; |
|
int iSearchRange; |
|
1538 |
int skip_possible; |
int skip_possible; |
1539 |
FRAMEINFO *const current = pEnc->current; |
FRAMEINFO *const current = pEnc->current; |
1540 |
FRAMEINFO *const reference = pEnc->reference; |
FRAMEINFO *const reference = pEnc->reference; |
1543 |
int mb_height = pParam->mb_height; |
int mb_height = pParam->mb_height; |
1544 |
int coded = 1; |
int coded = 1; |
1545 |
|
|
|
|
|
|
/* IMAGE *pCurrent = ¤t->image; */ |
|
1546 |
IMAGE *pRef = &reference->image; |
IMAGE *pRef = &reference->image; |
1547 |
|
|
1548 |
if (!reference->is_edged) { |
if (!reference->is_edged) { |
1646 |
MACROBLOCK *pMB = |
MACROBLOCK *pMB = |
1647 |
¤t->mbs[x + y * pParam->mb_width]; |
¤t->mbs[x + y * pParam->mb_width]; |
1648 |
|
|
1649 |
int bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); |
if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) { |
|
|
|
|
if (bIntra) { |
|
1650 |
CodeIntraMB(pEnc, pMB); |
CodeIntraMB(pEnc, pMB); |
1651 |
MBTransQuantIntra(&pEnc->mbParam, current, pMB, x, y, |
MBTransQuantIntra(&pEnc->mbParam, current, pMB, x, y, |
1652 |
dct_codes, qcoeff); |
dct_codes, qcoeff); |
1657 |
|
|
1658 |
current->sStat.kblks++; |
current->sStat.kblks++; |
1659 |
|
|
|
if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE) { |
|
|
pMB->cbp &= 0x3C; /* keep only bits 5-2 */ |
|
|
qcoeff[4*64+0]=0; /* zero, because for INTRA MBs DC value is saved */ |
|
|
qcoeff[5*64+0]=0; |
|
|
} |
|
1660 |
MBCoding(current, pMB, qcoeff, bs, ¤t->sStat); |
MBCoding(current, pMB, qcoeff, bs, ¤t->sStat); |
1661 |
stop_coding_timer(); |
stop_coding_timer(); |
1662 |
continue; |
continue; |
1758 |
} |
} |
1759 |
/* ordinary case: normal coded INTER/INTER4V block */ |
/* ordinary case: normal coded INTER/INTER4V block */ |
1760 |
|
|
|
if ((current->vop_flags & XVID_VOP_GREYSCALE)) |
|
|
{ pMB->cbp &= 0x3C; /* keep only bits 5-2 */ |
|
|
qcoeff[4*64+0]=0; /* zero, because DC for INTRA MBs DC value is saved */ |
|
|
qcoeff[5*64+0]=0; |
|
|
} |
|
|
|
|
1761 |
if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) { |
if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) { |
1762 |
VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0); |
VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0); |
1763 |
pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x; |
pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x; |
1797 |
} |
} |
1798 |
|
|
1799 |
emms(); |
emms(); |
1800 |
|
updateFcode(¤t->sStat, pEnc); |
|
if (current->sStat.iMvCount == 0) |
|
|
current->sStat.iMvCount = 1; |
|
|
|
|
|
fSigma = (float) sqrt((float) current->sStat.iMvSum / current->sStat.iMvCount); |
|
|
|
|
|
iSearchRange = 16 << pParam->m_fcode; |
|
|
|
|
|
if ((3.0 * fSigma > iSearchRange) && (pParam->m_fcode <= 5) ) |
|
|
pParam->m_fcode++; |
|
|
|
|
|
else if ((5.0 * fSigma < iSearchRange) |
|
|
&& (4.0 * pEnc->fMvPrevSigma < iSearchRange) |
|
|
&& (pParam->m_fcode >= 2) ) /* minimum search range 32 */ |
|
|
pParam->m_fcode--; |
|
|
|
|
|
pEnc->fMvPrevSigma = fSigma; |
|
1801 |
|
|
1802 |
/* frame drop code */ |
/* frame drop code */ |
1803 |
#if 0 |
#if 0 |
1977 |
|
|
1978 |
if (mb->mode == MODE_DIRECT && (mb->cbp | mb->pmvs[3].x | mb->pmvs[3].y) == 0) |
if (mb->mode == MODE_DIRECT && (mb->cbp | mb->pmvs[3].x | mb->pmvs[3].y) == 0) |
1979 |
mb->mode = MODE_DIRECT_NONE_MV; /* skipped */ |
mb->mode = MODE_DIRECT_NONE_MV; /* skipped */ |
1980 |
|
else |
|
/* keep only bits 5-2 -- Chroma blocks will just be skipped by the |
|
|
* coding function for BFrames, that's why we don't zero teh DC |
|
|
* coeffs */ |
|
1981 |
if (frame->vop_flags & XVID_VOP_GREYSCALE) |
if (frame->vop_flags & XVID_VOP_GREYSCALE) |
1982 |
|
/* keep only bits 5-2 -- Chroma blocks will just be skipped by MBCodingBVOP */ |
1983 |
mb->cbp &= 0x3C; |
mb->cbp &= 0x3C; |
1984 |
|
|
1985 |
start_timer(); |
start_timer(); |
1991 |
|
|
1992 |
emms(); |
emms(); |
1993 |
|
|
|
/* TODO: dynamic fcode/bcode ??? */ |
|
|
|
|
1994 |
BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ |
BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ |
1995 |
frame->length = (BitstreamPos(bs) - bits) / 8; |
frame->length = (BitstreamPos(bs) - bits) / 8; |
1996 |
|
|