--- encoder.c 2004/12/09 04:20:44 1.112 +++ encoder.c 2004/12/10 04:10:12 1.115 @@ -21,7 +21,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: encoder.c,v 1.112 2004/12/09 04:20:44 syskin Exp $ + * $Id: encoder.c,v 1.115 2004/12/10 04:10:12 syskin Exp $ * ****************************************************************************/ @@ -1479,11 +1479,6 @@ stop_prediction_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; - } MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->current->sStat); stop_coding_timer(); } @@ -1503,24 +1498,43 @@ return 1; /* intra */ } +static __inline void +updateFcode(Statistics * sStat, Encoder * pEnc) +{ + float fSigma; + int iSearchRange; -#define INTRA_THRESHOLD 0.5 -#define BFRAME_SKIP_THRESHHOLD 30 + if (sStat->iMvCount == 0) + sStat->iMvCount = 1; + + fSigma = (float) sqrt((float) sStat->iMvSum / sStat->iMvCount); + iSearchRange = 16 << pEnc->mbParam.m_fcode; + + if ((3.0 * fSigma > iSearchRange) && (pEnc->mbParam.m_fcode <= 5) ) + pEnc->mbParam.m_fcode++; + + else if ((5.0 * fSigma < iSearchRange) + && (4.0 * pEnc->fMvPrevSigma < iSearchRange) + && (pEnc->mbParam.m_fcode >= 2) ) + pEnc->mbParam.m_fcode--; + + pEnc->fMvPrevSigma = fSigma; +} + +#define BFRAME_SKIP_THRESHHOLD 30 /* FrameCodeP also handles S(GMC)-VOPs */ static int FrameCodeP(Encoder * pEnc, Bitstream * bs) { - float fSigma; int bits = BitstreamPos(bs); DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE); DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); int x, y, k; - int iSearchRange; int skip_possible; FRAMEINFO *const current = pEnc->current; FRAMEINFO *const reference = pEnc->reference; @@ -1529,8 +1543,6 @@ int mb_height = pParam->mb_height; int coded = 1; - - /* IMAGE *pCurrent = ¤t->image; */ IMAGE *pRef = &reference->image; if (!reference->is_edged) { @@ -1634,9 +1646,7 @@ MACROBLOCK *pMB = ¤t->mbs[x + y * pParam->mb_width]; - int bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); - - if (bIntra) { + if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) { CodeIntraMB(pEnc, pMB); MBTransQuantIntra(&pEnc->mbParam, current, pMB, x, y, dct_codes, qcoeff); @@ -1647,11 +1657,6 @@ current->sStat.kblks++; - 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; - } MBCoding(current, pMB, qcoeff, bs, ¤t->sStat); stop_coding_timer(); continue; @@ -1673,7 +1678,7 @@ pMB->field_pred = 0; if (pMB->cbp != 0) { - MBTransQuantInter(&pEnc->mbParam, current, pMB, x, y, + pMB->cbp = MBTransQuantInter(&pEnc->mbParam, current, pMB, x, y, dct_codes, qcoeff); } @@ -1753,12 +1758,6 @@ } /* ordinary case: normal coded INTER/INTER4V block */ - 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; - } - if((pParam->vol_flags & XVID_VOL_QUARTERPEL)) { VECTOR predMV = get_qpmv2(current->mbs, pParam->mb_width, 0, x, y, 0); pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x; @@ -1798,23 +1797,7 @@ } emms(); - - 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; + updateFcode(¤t->sStat, pEnc); /* frame drop code */ #if 0 @@ -1994,12 +1977,10 @@ if (mb->mode == MODE_DIRECT && (mb->cbp | mb->pmvs[3].x | mb->pmvs[3].y) == 0) mb->mode = MODE_DIRECT_NONE_MV; /* skipped */ - - /* 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 */ - if (frame->vop_flags & XVID_VOP_GREYSCALE) - mb->cbp &= 0x3C; + else + if (frame->vop_flags & XVID_VOP_GREYSCALE) + /* keep only bits 5-2 -- Chroma blocks will just be skipped by MBCodingBVOP */ + mb->cbp &= 0x3C; start_timer(); MBCodingBVOP(frame, mb, qcoeff, frame->fcode, frame->bcode, bs, @@ -2010,8 +1991,6 @@ emms(); - /* TODO: dynamic fcode/bcode ??? */ - BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ frame->length = (BitstreamPos(bs) - bits) / 8;