--- trunk/xvidcore/src/encoder.c 2002/07/29 19:21:23 349 +++ trunk/xvidcore/src/encoder.c 2002/08/07 10:09:00 366 @@ -39,7 +39,7 @@ * MinChen * 14.04.2002 added FrameCodeB() * - * $Id: encoder.c,v 1.66 2002-07-29 19:21:23 chl Exp $ + * $Id: encoder.c,v 1.73 2002-08-07 10:09:00 chl Exp $ * ****************************************************************************/ @@ -425,6 +425,7 @@ pEnc->mbParam.m_ticks = 0; pEnc->m_framenum = 0; pEnc->last_pframe = 0; + pEnc->last_sync = 0; #endif pParam->handle = (void *) pEnc; @@ -623,11 +624,23 @@ #ifdef BFRAMES void inc_frame_num(Encoder * pEnc) { - pEnc->iFrameNum++; pEnc->mbParam.m_ticks += pEnc->mbParam.fincr; - pEnc->mbParam.m_seconds = pEnc->mbParam.m_ticks / pEnc->mbParam.fbase; pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase; + +/* fprintf(stderr, "ENC %c %i:%i %i\n", + pEnc->current->coding_type == I_VOP ? 'I' : pEnc->current->coding_type == P_VOP ? 'P' : 'B', + pEnc->mbParam.m_seconds, pEnc->mbParam.m_ticks,pEnc->last_sync); +*/ + + 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; + } #endif @@ -826,7 +839,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 +1057,8 @@ goto bvop_loop; } + pEnc->iFrameNum++; + BitstreamPad(&bs); pFrame->length = BitstreamLength(&bs); @@ -1253,10 +1268,8 @@ #ifdef BFRAMES inc_frame_num(pEnc); -#else - pEnc->iFrameNum++; #endif - + pEnc->iFrameNum++; stop_global_timer(); write_timer(); @@ -1536,6 +1549,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 +1590,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 +1742,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 +1803,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;