--- encoder.c 2004/03/30 12:31:52 1.103 +++ encoder.c 2004/12/05 13:56:13 1.110 @@ -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.103 2004/03/30 12:31:52 syskin Exp $ + * $Id: encoder.c,v 1.110 2004/12/05 13:56:13 syskin Exp $ * ****************************************************************************/ @@ -57,9 +57,7 @@ Bitstream * bs); static int FrameCodeP(Encoder * pEnc, - Bitstream * bs, - bool force_inter, - bool vol_header); + Bitstream * bs); static void FrameCodeB(Encoder * pEnc, FRAMEINFO * frame, @@ -102,11 +100,22 @@ i--; } - /* if neccessary, round to 65535 accuracy */ - if (*base > 65535) { - float div = (float) *base / 65535; - *base = (int) (*base / div); - *inc = (int) (*inc / div); + if (*base > 65535 || *inc > 65535) { + int *biggest; + int *other; + float div; + + if (*base > *inc) { + biggest = base; + other = inc; + } else { + biggest = inc; + other = base; + } + + div = ((float)*biggest)/((float)65535); + *biggest = (int)(((float)*biggest)/div); + *other = (int)(((float)*other)/div); } } @@ -1091,7 +1100,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, 1, 0); + FrameCodeP(pEnc, &bs); if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) { @@ -1308,9 +1317,6 @@ /* prevent vol/vop misuse */ - if (!(pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE)) - pEnc->current->vop_flags &= ~XVID_VOP_REDUCED; - if (!(pEnc->current->vol_flags & XVID_VOL_INTERLACING)) pEnc->current->vop_flags &= ~(XVID_VOP_TOPFIELDFIRST|XVID_VOP_ALTERNATESCAN); @@ -1343,7 +1349,7 @@ pEnc->mbParam.edged_width, pEnc->mbParam.height); } - if ( FrameCodeP(pEnc, &bs, 1, 0) == 0 ) { + if ( FrameCodeP(pEnc, &bs) == 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; @@ -1438,20 +1444,6 @@ uint16_t x, y; - if ((pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE)) - { - mb_width = (pEnc->mbParam.width + 31) / 32; - mb_height = (pEnc->mbParam.height + 31) / 32; - - /* 16x16->8x8 downsample requires 1 additional edge pixel*/ - /* XXX: setedges is overkill */ - start_timer(); - image_setedges(&pEnc->current->image, - pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, - pEnc->mbParam.width, pEnc->mbParam.height, 0); - stop_edges_timer(); - } - pEnc->mbParam.m_rounding_type = 1; pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; pEnc->current->coding_type = I_VOP; @@ -1496,12 +1488,6 @@ stop_coding_timer(); } - if ((pEnc->current->vop_flags & XVID_VOP_REDUCED)) - { - image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, - pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width, - 16, 0); - } emms(); BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ @@ -1525,9 +1511,7 @@ /* FrameCodeP also handles S(GMC)-VOPs */ static int FrameCodeP(Encoder * pEnc, - Bitstream * bs, - bool force_inter, - bool vol_header) + Bitstream * bs) { float fSigma; int bits = BitstreamPos(bs); @@ -1535,10 +1519,9 @@ 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 bIntra=0, skip_possible; + int skip_possible; FRAMEINFO *const current = pEnc->current; FRAMEINFO *const reference = pEnc->reference; MBParam * const pParam = &pEnc->mbParam; @@ -1550,13 +1533,6 @@ /* IMAGE *pCurrent = ¤t->image; */ IMAGE *pRef = &reference->image; - if ((current->vop_flags & XVID_VOP_REDUCED)) - { - mb_width = (pParam->width + 31) / 32; - mb_height = (pParam->height + 31) / 32; - } - - if (!reference->is_edged) { start_timer(); image_setedges(pRef, pParam->edged_width, pParam->edged_height, @@ -1569,11 +1545,6 @@ 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(); @@ -1644,21 +1615,14 @@ } } - bIntra = - MotionEstimation(&pEnc->mbParam, current, reference, + MotionEstimation(&pEnc->mbParam, current, reference, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, - &pEnc->vGMC, iLimit); + &pEnc->vGMC, 256*4096); 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); @@ -1671,7 +1635,7 @@ MACROBLOCK *pMB = ¤t->mbs[x + y * pParam->mb_width]; - bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); + int bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); if (bIntra) { CodeIntraMB(pEnc, pMB); @@ -1703,7 +1667,6 @@ pParam->height, pParam->edged_width, (current->vol_flags & XVID_VOL_QUARTERPEL), - (current->vop_flags & XVID_VOP_REDUCED), current->rounding_type); stop_comp_timer(); @@ -1836,13 +1799,6 @@ } } - if ((current->vop_flags & XVID_VOP_REDUCED)) - { - image_deblock_rrv(¤t->image, pParam->edged_width, - current->mbs, mb_width, mb_height, pParam->mb_width, - 16, 0); - } - emms(); if (current->sStat.iMvCount == 0) @@ -1873,7 +1829,8 @@ 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) + (pParam->frame_drop_ratio * mb_width * mb_height) / 100 && + ( (pEnc->bframenum_head >= pEnc->bframenum_tail) || !(pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP)) ) { current->sStat.kblks = current->sStat.mblks = 0; current->sStat.ublks = mb_width * mb_height; @@ -1950,8 +1907,6 @@ fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mode,mb->cbp); \ } - /* XXX: pEnc->current->global_flags &= ~XVID_VOP_REDUCED; reduced resoltion not yet supported */ - if (!first){ fp=fopen("C:\\XVIDDBGE.TXT","w"); } @@ -2022,7 +1977,7 @@ if (mb->mode == MODE_NOT_CODED) { if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) { MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image, - NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0, 0); + NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0); } continue;