--- encoder.c 2003/07/02 13:15:01 1.95.2.32 +++ encoder.c 2003/08/03 10:20:12 1.95.2.37 @@ -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.95.2.32 2003/07/02 13:15:01 syskin Exp $ + * $Id: encoder.c,v 1.95.2.37 2003/08/03 10:20:12 syskin Exp $ * ****************************************************************************/ @@ -117,7 +117,7 @@ Encoder *pEnc; int n; - if (XVID_MAJOR(create->version) != 1) /* v1.x.x */ + if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */ return XVID_ERR_VERSION; if (create->width%2 || create->height%2) @@ -741,7 +741,7 @@ for (j=0; jmbParam.mb_height; j++) for (i=0; imbParam.mb_width; i++) { - data.dquant[j*data.dquant_stride + i] = frame->mbs[j*pEnc->mbParam.mb_width + i].dquant;; + data.dquant[j*data.dquant_stride + i] = frame->mbs[j*pEnc->mbParam.mb_width + i].dquant; } } @@ -867,7 +867,7 @@ int type; Bitstream bs; - if (XVID_MAJOR(xFrame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1)) /* v1.x.x */ + if (XVID_VERSION_MAJOR(xFrame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1)) /* v1.x.x */ return XVID_ERR_VERSION; xFrame->out_flags = 0; @@ -904,13 +904,13 @@ if (xFrame->quant_intra_matrix) { - memcpy(q->quant_intra_matrix, xFrame->quant_intra_matrix, sizeof(xFrame->quant_intra_matrix)); + memcpy(q->quant_intra_matrix, xFrame->quant_intra_matrix, 64*sizeof(unsigned char)); q->frame.quant_intra_matrix = q->quant_intra_matrix; } if (xFrame->quant_inter_matrix) { - memcpy(q->quant_inter_matrix, xFrame->quant_inter_matrix, sizeof(xFrame->quant_inter_matrix)); + memcpy(q->quant_inter_matrix, xFrame->quant_inter_matrix, 64*sizeof(unsigned char)); q->frame.quant_inter_matrix = q->quant_inter_matrix; } @@ -1285,6 +1285,10 @@ { unsigned int i,j; int quant = frame->quant; + if (quant > 31) + frame->quant = quant = 31; + else if (quant < 1) + frame->quant = quant = 1; for (j=0; jmb_height; j++) for (i=0; imb_width; i++) { @@ -1292,7 +1296,7 @@ quant += pMB->dquant; if (quant > 31) quant = 31; - if (quant < 1) + else if (quant < 1) quant = 1; pMB->quant = quant; } @@ -1356,7 +1360,8 @@ set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); - BitstreamPadAlways(bs); + BitstreamPad(bs); + BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); pEnc->current->sStat.iTextBits = 0; @@ -1395,16 +1400,8 @@ } emms(); -/* XXX: Remove the two #if 0 blocks when we are sure we must always pad the stream */ -#if 0 - /* for divx5 compatibility, we must always pad between the packed p and b frames */ - if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) -#endif - BitstreamPadAlways(bs); -#if 0 - else - BitstreamPad(bs); -#endif + BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ + pEnc->current->length = (BitstreamPos(bs) - bits) / 8; pEnc->fMvPrevSigma = -1; @@ -1437,7 +1434,7 @@ int bIntra=0, skip_possible; FRAMEINFO *const current = pEnc->current; FRAMEINFO *const reference = pEnc->reference; - MBParam * const pParam = &pEnc->mbParam; + MBParam * const pParam = &pEnc->mbParam; int mb_width = pParam->mb_width; int mb_height = pParam->mb_height; @@ -1487,7 +1484,7 @@ current->warp = GlobalMotionEst( current->mbs, pParam, current, reference, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV); - if (current->motion_flags & XVID_GME_REFINE) { + if (current->motion_flags & XVID_ME_GME_REFINE) { gmcval = GlobalMotionEstRefine(¤t->warp, current->mbs, pParam, current, reference, @@ -1545,7 +1542,7 @@ set_timecodes(current,reference,pParam->fbase); if (vol_header) { BitstreamWriteVolHeader(bs, &pEnc->mbParam); - BitstreamPadAlways(bs); + BitstreamPad(bs); } BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1); @@ -1559,9 +1556,6 @@ MACROBLOCK *pMB = ¤t->mbs[x + y * pParam->mb_width]; -/* Mode decision: Check, if the block should be INTRA / INTER or GMC-coded */ -/* For a start, leave INTRA decision as is, only choose only between INTER/GMC - gruel, 9.1.2002 */ - bIntra = (pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q); if (bIntra) { @@ -1579,37 +1573,6 @@ stop_coding_timer(); continue; } - - if (current->coding_type == S_VOP) { - - int32_t iSAD = sad16(current->image.y + 16*y*pParam->edged_width + 16*x, - pEnc->vGMC.y + 16*y*pParam->edged_width + 16*x, - pParam->edged_width, 65536); - - if (current->motion_flags & XVID_ME_CHROMA16) { - iSAD += sad8(current->image.u + 8*y*(pParam->edged_width/2) + 8*x, - pEnc->vGMC.u + 8*y*(pParam->edged_width/2) + 8*x, pParam->edged_width/2); - - iSAD += sad8(current->image.v + 8*y*(pParam->edged_width/2) + 8*x, - pEnc->vGMC.v + 8*y*(pParam->edged_width/2) + 8*x, pParam->edged_width/2); - } - - if (iSAD <= pMB->sad16) { /* mode decision GMC */ - - if ((pParam->vol_flags & XVID_VOL_QUARTERPEL)) - pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv; - else - pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; - - pMB->mode = MODE_INTER; - pMB->mcsel = 1; - pMB->sad16 = iSAD; - } else { - pMB->mcsel = 0; - } - } else { - pMB->mcsel = 0; /* just a precaution */ - } start_timer(); MBMotionCompensation(pMB, x, y, &reference->image, @@ -1825,16 +1788,7 @@ } */ -/* XXX: Remove the two #if 0 blocks when we are sure we must always pad the stream */ -#if 0 - /* for divx5 compatibility, we must always pad between the packed p and b frames */ - if ((pParam->global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) -#endif - BitstreamPadAlways(bs); -#if 0 - else - BitstreamPad(bs); -#endif + BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ current->length = (BitstreamPos(bs) - bits) / 8; @@ -1955,7 +1909,7 @@ /* TODO: dynamic fcode/bcode ??? */ - BitstreamPadAlways(bs); + BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ frame->length = (BitstreamPos(bs) - bits) / 8; #ifdef BFRAMES_DEC_DEBUG