--- trunk/xvidcore/src/encoder.c 2002/07/29 19:21:23 349 +++ trunk/xvidcore/src/encoder.c 2002/09/04 21:16:02 402 @@ -3,6 +3,8 @@ * XVID MPEG-4 VIDEO CODEC * - Encoder main module - * + * Copyright(C) 2002 Michael Militzer + * * This program is an implementation of a part of one or more MPEG-4 * Video tools as specified in ISO/IEC 14496-2 standard. Those intending * to use this software module in hardware or software products are @@ -28,22 +30,6 @@ * ****************************************************************************/ -/***************************************************************************** - * - * History - * - * 10.07.2002 added BFRAMES_DEC_DEBUG support - * MinChen - * 20.06.2002 bframe patch - * 08.05.2002 fix some problem in DEBUG mode; - * MinChen - * 14.04.2002 added FrameCodeB() - * - * $Id: encoder.c,v 1.66 2002-07-29 19:21:23 chl Exp $ - * - ****************************************************************************/ - - #include #include #include @@ -425,6 +411,7 @@ pEnc->mbParam.m_ticks = 0; pEnc->m_framenum = 0; pEnc->last_pframe = 0; + pEnc->last_sync = 0; #endif pParam->handle = (void *) pEnc; @@ -620,17 +607,28 @@ } -#ifdef BFRAMES void inc_frame_num(Encoder * pEnc) { - pEnc->iFrameNum++; pEnc->mbParam.m_ticks += pEnc->mbParam.fincr; +#ifdef BFRAMES + pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase; + if (pEnc->mbParam.m_ticks < pEnc->last_sync) + pEnc->mbParam.m_seconds = 1; // more than 1 second since last I or P is not supported. + else + pEnc->mbParam.m_seconds = 0; + + if (pEnc->current->coding_type != B_VOP) + pEnc->last_sync = pEnc->mbParam.m_ticks; +#else + pEnc->mbParam.m_seconds = pEnc->mbParam.m_ticks / pEnc->mbParam.fbase; pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase; -} + #endif +} + #ifdef BFRAMES void queue_image(Encoder * pEnc, XVID_ENC_FRAME * pFrame) @@ -826,7 +824,7 @@ pFrame->intra = 0; - BitstreamPutBits(&bs, 0x7f, 8); + BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); // write N_VOP BitstreamPad(&bs); pFrame->length = BitstreamLength(&bs); @@ -1044,6 +1042,8 @@ goto bvop_loop; } + pEnc->iFrameNum++; + BitstreamPad(&bs); pFrame->length = BitstreamLength(&bs); @@ -1118,10 +1118,8 @@ pEnc->current->global_flags = pFrame->general; pEnc->current->motion_flags = pFrame->motion; -#ifdef BFRAMES pEnc->current->seconds = pEnc->mbParam.m_seconds; pEnc->current->ticks = pEnc->mbParam.m_ticks; -#endif pEnc->mbParam.hint = &pFrame->hint; start_timer(); @@ -1251,12 +1249,8 @@ DEBUG(temp); #endif -#ifdef BFRAMES inc_frame_num(pEnc); -#else pEnc->iFrameNum++; -#endif - stop_global_timer(); write_timer(); @@ -1536,6 +1530,11 @@ stop_prediction_timer(); start_timer(); + if (pEnc->current->global_flags & XVID_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->sStat); stop_coding_timer(); } @@ -1572,8 +1571,7 @@ DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); int iLimit; - int k; - int x, y; + int x, y, k; int iSearchRange; int bIntra; @@ -1725,19 +1723,28 @@ } if (!bSkip) { + if (pEnc->current->global_flags & XVID_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; + } MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat); pMB->cbp = 0x80; /* trick! so cbp!=0, but still nothing is written to bs */ } else MBSkip(bs); - #else MBSkip(bs); /* without B-frames, no precautions are needed */ -#endif +#endif } else { + if (pEnc->current->global_flags & XVID_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; + } MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat); } @@ -1777,7 +1784,7 @@ #ifdef BFRAMES /* frame drop code */ // DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->sStat.kblks, pEnc->sStat.mblks, pEnc->sStat.ublks); - if (pEnc->sStat.kblks + pEnc->sStat.mblks <= + if (pEnc->sStat.kblks + pEnc->sStat.mblks < (pEnc->frame_drop_ratio * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height) / 100) { pEnc->sStat.kblks = pEnc->sStat.mblks = 0; @@ -1923,8 +1930,7 @@ mb->quant = frame->quant; mb->cbp = - MBTransQuantInter(&pEnc->mbParam, frame, mb, x, y, dct_codes, - qcoeff); + MBTransQuantInterBVOP(&pEnc->mbParam, frame, mb, dct_codes, qcoeff); //mb->cbp = MBTransQuantBVOP(&pEnc->mbParam, x, y, dct_codes, qcoeff, &frame->image, frame->quant); if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0)