--- encoder.c 2004/04/04 03:07:11 1.102.2.4 +++ encoder.c 2004/03/30 12:31:52 1.103 @@ -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.102.2.4 2004/04/04 03:07:11 syskin Exp $ + * $Id: encoder.c,v 1.103 2004/03/30 12:31:52 syskin Exp $ * ****************************************************************************/ @@ -57,7 +57,9 @@ Bitstream * bs); static int FrameCodeP(Encoder * pEnc, - Bitstream * bs); + Bitstream * bs, + bool force_inter, + bool vol_header); static void FrameCodeB(Encoder * pEnc, FRAMEINFO * frame, @@ -1089,7 +1091,7 @@ pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); pEnc->mbParam.frame_drop_ratio = -1; /* it must be a coded vop */ - FrameCodeP(pEnc, &bs); + FrameCodeP(pEnc, &bs, 1, 0); if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) { @@ -1341,7 +1343,7 @@ pEnc->mbParam.edged_width, pEnc->mbParam.height); } - if ( FrameCodeP(pEnc, &bs) == 0 ) { + if ( FrameCodeP(pEnc, &bs, 1, 0) == 0 ) { /* N-VOP, we mustn't code b-frames yet */ call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); goto done; @@ -1523,7 +1525,9 @@ /* FrameCodeP also handles S(GMC)-VOPs */ static int FrameCodeP(Encoder * pEnc, - Bitstream * bs) + Bitstream * bs, + bool force_inter, + bool vol_header) { float fSigma; int bits = BitstreamPos(bs); @@ -1531,9 +1535,10 @@ DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE); DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); + int iLimit; int x, y, k; int iSearchRange; - int skip_possible; + int bIntra=0, skip_possible; FRAMEINFO *const current = pEnc->current; FRAMEINFO *const reference = pEnc->reference; MBParam * const pParam = &pEnc->mbParam; @@ -1564,6 +1569,11 @@ current->rounding_type = pParam->m_rounding_type; current->fcode = pParam->m_fcode; + if (!force_inter) + iLimit = (int)(mb_width * mb_height * INTRA_THRESHOLD); + else + iLimit = mb_width * mb_height + 1; + if ((current->vop_flags & XVID_VOP_HALFPEL)) { if (reference->is_interpolated != current->rounding_type) { start_timer(); @@ -1634,14 +1644,21 @@ } } - MotionEstimation(&pEnc->mbParam, current, reference, + bIntra = + MotionEstimation(&pEnc->mbParam, current, reference, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, - &pEnc->vGMC, 256*4096); + &pEnc->vGMC, iLimit); stop_motion_timer(); + if (bIntra == 1) return FrameCodeI(pEnc, bs); + set_timecodes(current,reference,pParam->fbase); + if (vol_header) + { BitstreamWriteVolHeader(bs, &pEnc->mbParam, current); + BitstreamPad(bs); + } BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant); @@ -1654,7 +1671,7 @@ MACROBLOCK *pMB = ¤t->mbs[x + y * pParam->mb_width]; - int bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); + bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); if (bIntra) { CodeIntraMB(pEnc, pMB); @@ -1856,8 +1873,7 @@ DPRINTF(XVID_DEBUG_DEBUG, "kmu %i %i %i\n", current->sStat.kblks, current->sStat.mblks, current->sStat.ublks); #endif if (current->sStat.kblks + current->sStat.mblks <= - (pParam->frame_drop_ratio * mb_width * mb_height) / 100 && - ( (pEnc->bframenum_head >= pEnc->bframenum_tail) || !(pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP)) ) + (pParam->frame_drop_ratio * mb_width * mb_height) / 100) { current->sStat.kblks = current->sStat.mblks = 0; current->sStat.ublks = mb_width * mb_height;