--- encoder.c 2002/12/09 10:47:05 1.76.2.26 +++ encoder.c 2002/12/12 12:42:31 1.76.2.29 @@ -39,7 +39,7 @@ * MinChen * 14.04.2002 added FrameCodeB() * - * $Id: encoder.c,v 1.76.2.26 2002/12/09 10:47:05 suxen_drol Exp $ + * $Id: encoder.c,v 1.76.2.29 2002/12/12 12:42:31 suxen_drol Exp $ * ****************************************************************************/ @@ -646,6 +646,16 @@ +/* convert pFrame->intra to coding_type */ +static int intra2coding_type(int intra) +{ + if (intra < 0) return -1; + if (intra == 1) return I_VOP; + if (intra == 2) return B_VOP; + + return P_VOP; +} + /***************************************************************************** @@ -855,6 +865,7 @@ // only inc frame num, adapt quant, etc. if we havent seen it before if (pEnc->bframenum_dx50bvop < 0 ) { + mode = intra2coding_type(pFrame->intra); if (pFrame->quant == 0) pEnc->current->quant = RateControlGetQ(&pEnc->rate_control, 0); else @@ -928,14 +939,19 @@ * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ pEnc->iFrameNum++; - if (pEnc->iFrameNum == 0 || pFrame->intra == 1 || pEnc->bframenum_dx50bvop >= 0 || - (pFrame->intra < 0 && pEnc->mbParam.iMaxKeyInterval > 0 && - pEnc->iFrameNum >= pEnc->mbParam.iMaxKeyInterval) - || 2 == (mode = MEanalysis(&pEnc->reference->image, pEnc->current, - &pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval, - (pFrame->intra < 0) ? pEnc->iFrameNum : 0, - bframes_count++))) { + if (pEnc->iFrameNum == 0 || pEnc->bframenum_dx50bvop >= 0 || + (mode < 0 && pEnc->mbParam.iMaxKeyInterval > 0 && + pEnc->iFrameNum >= pEnc->mbParam.iMaxKeyInterval)) + { + mode = I_VOP; + }else{ + mode = MEanalysis(&pEnc->reference->image, pEnc->current, + &pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval, + (mode < 0) ? pEnc->iFrameNum : 0, + bframes_count++); + } + if (mode == I_VOP) { /* * This will be coded as an Intra Frame */ @@ -999,8 +1015,7 @@ * NB : sequences like "IIBB" decode fine with msfdam but, * go screwy with divx 5.00 */ - } else if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes || mode != 0) { -// } else if (pFrame->intra == 0 || pEnc->bframenum_tail >= pEnc->mbParam.max_bframes || mode != 0) { + } else if (mode == P_VOP || pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) { /* * This will be coded as a Predicted Frame */ @@ -1024,7 +1039,7 @@ goto ipvop_loop; } - } else { + } else { /* mode == B_VOP */ /* * This will be coded as a Bidirectional Frame */ @@ -1590,6 +1605,11 @@ stop_coding_timer(); } + if ((pEnc->current->global_flags & XVID_REDUCED)) + { + image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, + pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width); + } emms(); *pBits = BitstreamPos(bs) - *pBits; @@ -1632,13 +1652,10 @@ if ((pEnc->current->global_flags & XVID_REDUCED)) { - // mb_width = (pEnc->mbParam.width + 31) / 32; - // mb_height = (pEnc->mbParam.height + 31) / 32; - - /* XXX: reduced resoltion not yet supported */ - pEnc->current->global_flags &= ~XVID_REDUCED; + mb_width = (pEnc->mbParam.width + 31) / 32; + mb_height = (pEnc->mbParam.height + 31) / 32; } - + start_timer(); image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, @@ -1676,7 +1693,6 @@ if (pEnc->current->global_flags & XVID_HINTEDME_SET) { HintedMESet(pEnc, &bIntra); if (bIntra == 0) { - pEnc->current->fcode = FindFcode(&pEnc->mbParam, pEnc->current); MotionEstimationHinted(&pEnc->mbParam, pEnc->current, pEnc->reference, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV); } @@ -1834,6 +1850,12 @@ } } + if ((pEnc->current->global_flags & XVID_REDUCED)) + { + image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, + pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width); + } + emms(); if (pEnc->current->global_flags & XVID_HINTEDME_GET) { @@ -1899,9 +1921,10 @@ image_dump_yuvpgm(&pEnc->reference->image, pEnc->mbParam.edged_width, pEnc->mbParam.width, pEnc->mbParam.height, s); - } + } */ + *pBits = BitstreamPos(bs) - *pBits; return 0; // inter