--- encoder.c 2003/06/28 15:49:40 1.95.2.31 +++ encoder.c 2003/08/02 15:08:19 1.95.2.36 @@ -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.31 2003/06/28 15:49:40 chl Exp $ + * $Id: encoder.c,v 1.95.2.36 2003/08/02 15:08:19 edgomez 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; } @@ -1196,6 +1196,7 @@ image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP"); } + pEnc->iFrameNum = 1; /* ---- update vol flags at IVOP ----------- */ pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags; @@ -1355,7 +1356,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; @@ -1394,16 +1396,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; @@ -1436,7 +1430,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; @@ -1486,7 +1480,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, @@ -1544,7 +1538,7 @@ set_timecodes(current,reference,pParam->fbase); if (vol_header) { BitstreamWriteVolHeader(bs, &pEnc->mbParam); - BitstreamPadAlways(bs); + BitstreamPad(bs); } BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1); @@ -1558,9 +1552,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) { @@ -1578,37 +1569,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, @@ -1824,16 +1784,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; @@ -1954,7 +1905,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