--- encoder.c 2003/03/26 11:01:03 1.95.2.14 +++ encoder.c 2003/05/16 17:16:21 1.95.2.23 @@ -26,7 +26,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.14 2003/03/26 11:01:03 suxen_drol Exp $ + * $Id: encoder.c,v 1.95.2.23 2003/05/16 17:16:21 suxen_drol Exp $ * ****************************************************************************/ @@ -134,6 +134,8 @@ return XVID_ERR_MEMORY; memset(pEnc, 0, sizeof(Encoder)); + pEnc->mbParam.profile = create->profile; + /* global flags */ pEnc->mbParam.global_flags = create->global; @@ -151,11 +153,28 @@ if (pEnc->mbParam.fincr>0) simplify_time(&pEnc->mbParam.fincr, &pEnc->mbParam.fbase); - /* plugin */ - pEnc->num_plugins = create->num_plugins; - pEnc->plugins = xvid_malloc(sizeof(xvid_enc_plugin_t) * pEnc->num_plugins, CACHE_LINE); - if (pEnc->plugins == NULL) - goto xvid_err_memory0; + /* zones */ + if(create->num_zones > 0) { + pEnc->num_zones = create->num_zones; + pEnc->zones = xvid_malloc(sizeof(xvid_enc_zone_t) * pEnc->num_zones, CACHE_LINE); + if (pEnc->zones == NULL) + goto xvid_err_memory0; + memcpy(pEnc->zones, create->zones, sizeof(xvid_enc_zone_t) * pEnc->num_zones); + } else { + pEnc->num_zones = 0; + pEnc->zones = NULL; + } + + /* plugins */ + if(create->num_plugins > 0) { + pEnc->num_plugins = create->num_plugins; + pEnc->plugins = xvid_malloc(sizeof(xvid_enc_plugin_t) * pEnc->num_plugins, CACHE_LINE); + if (pEnc->plugins == NULL) + goto xvid_err_memory0; + } else { + pEnc->num_plugins = 0; + pEnc->plugins = NULL; + } for (n=0; nnum_plugins;n++) { xvid_plg_create_t pcreate; @@ -169,6 +188,8 @@ memset(&pcreate, 0, sizeof(xvid_plg_create_t)); pcreate.version = XVID_VERSION; + pcreate.num_zones = pEnc->num_zones; + pcreate.zones = pEnc->zones; pcreate.width = pEnc->mbParam.width; pcreate.height = pEnc->mbParam.height; pcreate.fincr = pEnc->mbParam.fincr; @@ -181,7 +202,7 @@ } } - if ((pEnc->mbParam.global_flags & XVID_EXTRASTATS_ENABLE) || + if ((pEnc->mbParam.global_flags & XVID_GLOBAL_EXTRASTATS_ENABLE) || (pEnc->mbParam.plugin_flags & XVID_REQPSNR)) { pEnc->mbParam.plugin_flags |= XVID_REQORIGINAL; /* psnr calculation requires the original */ } @@ -197,13 +218,19 @@ pEnc->mbParam.max_bframes = MAX(create->max_bframes, 0); pEnc->mbParam.bquant_ratio = MAX(create->bquant_ratio, 0); pEnc->mbParam.bquant_offset = create->bquant_offset; + + /* min/max quant */ + for (n=0; n<3; n++) { + pEnc->mbParam.min_quant[n] = create->min_quant[n] > 0 ? create->min_quant[n] : 2; + pEnc->mbParam.max_quant[n] = create->max_quant[n] > 0 ? create->max_quant[n] : 31; + } /* frame drop ratio */ pEnc->mbParam.frame_drop_ratio = MAX(create->frame_drop_ratio, 0); /* max keyframe interval */ - pEnc->mbParam.iMaxKeyInterval = create->max_key_interval <=0 ? 250 : create->max_key_interval; - /*XXX: replace 250 hard code with "10seconds * framerate" */ + pEnc->mbParam.iMaxKeyInterval = create->max_key_interval <= 0 ? + 10 * pEnc->mbParam.fbase / pEnc->mbParam.fincr : create->max_key_interval; /* Bitrate allocator defaults @@ -500,6 +527,8 @@ } xvid_free(pEnc->plugins); + xvid_free(pEnc->zones); + xvid_free(pEnc); create->handle = NULL; @@ -577,6 +606,8 @@ pEnc->mbParam.edged_height); image_destroy(&pEnc->f_refhv, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height); + image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width, + pEnc->mbParam.edged_height); if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width, @@ -598,8 +629,7 @@ } - if (pEnc->num_plugins>0) - { + if (pEnc->num_plugins>0) { xvid_plg_destroy_t pdestroy; memset(&pdestroy, 0, sizeof(xvid_plg_destroy_t)); @@ -614,6 +644,9 @@ xvid_free(pEnc->plugins); } + if (pEnc->num_plugins>0) + xvid_free(pEnc->zones); + xvid_free(pEnc); return 0; /* ok */ @@ -635,12 +668,21 @@ memset(&data, 0, sizeof(xvid_plg_data_t)); data.version = XVID_VERSION; + /* find zone */ + for(i=0; inum_zones && pEnc->zones[i].frame<=frame->frame_num; i++) ; + data.zone = i>0 ? &pEnc->zones[i-1] : NULL; + data.width = pEnc->mbParam.width; data.height = pEnc->mbParam.height; data.mb_width = pEnc->mbParam.mb_width; data.mb_height = pEnc->mbParam.mb_height; data.fincr = frame->fincr; data.fbase = pEnc->mbParam.fbase; + + for (i=0; i<3; i++) { + data.min_quant[i] = pEnc->mbParam.min_quant[i]; + data.max_quant[i] = pEnc->mbParam.max_quant[i]; + } data.reference.csp = XVID_CSP_USER; data.reference.plane[0] = pEnc->reference->image.y; @@ -662,12 +704,12 @@ if (opt == XVID_PLG_BEFORE) { data.type = XVID_TYPE_AUTO; - data.quant = 2; + data.quant = 0; - if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { + if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { data.dquant = pEnc->temp_dquants; data.dquant_stride = pEnc->mbParam.mb_width; - memset(data.dquant, 0, data.mb_width*data.mb_height); + memset(data.dquant, 0, data.mb_width*data.mb_height); } /* todo: [vol,vop,motion]_flags*/ @@ -683,7 +725,7 @@ data.original.stride[2] = pEnc->mbParam.edged_width/2; } - if ((frame->vol_flags & XVID_EXTRASTATS) || + if ((frame->vol_flags & XVID_VOL_EXTRASTATS) || (pEnc->mbParam.plugin_flags & XVID_REQPSNR)) { data.sse_y = @@ -754,7 +796,7 @@ /* copy modified values back into frame*/ if (opt == XVID_PLG_BEFORE) { *type = data.type; - *quant = data.quant; + *quant = data.quant > 0 ? data.quant : 2; /* default */ if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { for (j=0; jmbParam.mb_height; j++) @@ -855,14 +897,14 @@ if (image_input (&q->image, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width, (uint8_t**)xFrame->input.plane, xFrame->input.stride, - xFrame->input.csp, xFrame->vol_flags & XVID_INTERLACING)) + xFrame->input.csp, xFrame->vol_flags & XVID_VOL_INTERLACING)) { emms(); return XVID_ERR_FORMAT; } stop_conv_timer(); - if ((xFrame->vop_flags & XVID_CHROMAOPT)) { + if ((xFrame->vop_flags & XVID_VOP_CHROMAOPT)) { image_chroma_optimize(&q->image, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width); } @@ -919,7 +961,7 @@ indentical to the future-referece frame. */ - if ((pEnc->mbParam.global_flags & XVID_PACKED && pEnc->bframenum_tail > 0)) { + if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED && pEnc->bframenum_tail > 0)) { int tmp; int bits; @@ -961,7 +1003,7 @@ if (xFrame->input.csp == XVID_CSP_NULL) /* no futher input */ { - if (!(pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->mbParam.max_bframes > 0) { + if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->mbParam.max_bframes > 0) { call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); } @@ -1015,7 +1057,7 @@ pEnc->current->bcode = pEnc->mbParam.m_fcode; - if ((xFrame->vop_flags & XVID_CHROMAOPT)) { + if ((xFrame->vop_flags & XVID_VOP_CHROMAOPT)) { image_chroma_optimize(&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width); } @@ -1041,26 +1083,18 @@ }else{ type = MEanalysis(&pEnc->reference->image, pEnc->current, &pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval, - pEnc->iFrameNum, pEnc->bframenum_tail); - - if (type == B_VOP && !(pEnc->current->vop_flags & XVID_DYNAMIC_BFRAMES)) { - type = P_VOP; /* disable dynamic bframes */ - } + pEnc->iFrameNum, pEnc->bframenum_tail, xFrame->bframe_threshold); } } /* bframes buffer overflow check */ - if (type != I_VOP) { - if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) { - type = P_VOP; - }else{ - type = B_VOP; - } + if (type == B_VOP && pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) { + type = P_VOP; } pEnc->iFrameNum++; - if ((pEnc->current->vop_flags & XVID_DEBUG)) { + if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5, "%i st:%i if:%i", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum); } @@ -1070,7 +1104,7 @@ * (we dont encode here, rather we store the frame in the bframes queue, to be encoded later) * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ if (type == B_VOP) { - if ((pEnc->current->vop_flags & XVID_DEBUG)) { + if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP"); } @@ -1101,7 +1135,7 @@ } /* for unpacked bframes, output the stats for the last encoded frame */ - if (!(pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0) + if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) { if (pEnc->current->stamp > 0) { call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); @@ -1115,7 +1149,7 @@ * if the frame prior to an iframe is scheduled as a bframe, we must change it to a pframe * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ - if (type == I_VOP && (pEnc->mbParam.global_flags & XVID_CLOSED_GOP) && pEnc->bframenum_tail > 0) { + if (type == I_VOP && (pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP) && pEnc->bframenum_tail > 0) { // place this frame back on the encoding-queue (head) // we will deal with it next time @@ -1131,7 +1165,7 @@ pEnc->bframenum_tail--; SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); - if ((pEnc->current->vop_flags & XVID_DEBUG)) { + if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP"); } @@ -1151,7 +1185,7 @@ pEnc->bframenum_head, pEnc->bframenum_tail, pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); - if ((pEnc->current->vop_flags & XVID_DEBUG)) { + if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP"); } @@ -1159,7 +1193,7 @@ /* ---- update vol flags at IVOP ----------- */ pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags; - if ((pEnc->mbParam.vol_flags & XVID_MPEGQUANT)) { + if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) { if (frame->quant_intra_matrix != NULL) set_intra_matrix(frame->quant_intra_matrix); if (frame->quant_inter_matrix != NULL) @@ -1168,11 +1202,11 @@ /* prevent vol/vop misuse */ - if (!(pEnc->current->vol_flags & XVID_REDUCED_ENABLE)) - pEnc->current->vop_flags &= ~XVID_REDUCED; + if (!(pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE)) + pEnc->current->vop_flags &= ~XVID_VOP_REDUCED; - if (!(pEnc->current->vol_flags & XVID_INTERLACING)) - pEnc->current->vop_flags &= ~(XVID_TOPFIELDFIRST|XVID_ALTERNATESCAN); + if (!(pEnc->current->vol_flags & XVID_VOL_INTERLACING)) + pEnc->current->vop_flags &= ~(XVID_VOP_TOPFIELDFIRST|XVID_VOP_ALTERNATESCAN); /* ^^^------------------------ */ @@ -1194,7 +1228,7 @@ pEnc->bframenum_head, pEnc->bframenum_tail, pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); - if ((pEnc->current->vop_flags & XVID_DEBUG)) { + if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP"); } @@ -1216,12 +1250,12 @@ pEnc->flush_bframes = 1; /* packed & queued_bframes: dont bother outputting stats, we do so after the flush */ - if ((pEnc->mbParam.global_flags & XVID_PACKED) && pEnc->bframenum_tail > 0) { + if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) { goto repeat; } /* packed or no-bframes: output stats */ - if ((pEnc->mbParam.global_flags & XVID_PACKED) || pEnc->mbParam.max_bframes == 0) { + if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) || pEnc->mbParam.max_bframes == 0) { call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); } @@ -1290,7 +1324,7 @@ uint16_t x, y; - if ((pEnc->current->vol_flags & XVID_REDUCED_ENABLE)) + if ((pEnc->current->vol_flags & XVID_VOL_REDUCED_ENABLE)) { mb_width = (pEnc->mbParam.width + 31) / 32; mb_height = (pEnc->mbParam.height + 31) / 32; @@ -1336,7 +1370,7 @@ stop_prediction_timer(); start_timer(); - if (pEnc->current->vop_flags & XVID_GREYSCALE) + if (pEnc->current->vop_flags & XVID_VOP_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; @@ -1345,7 +1379,7 @@ stop_coding_timer(); } - if ((pEnc->current->vop_flags & XVID_REDUCED)) + 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, @@ -1353,11 +1387,16 @@ } 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_PACKED) && pEnc->bframenum_tail > 0) + if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) +#endif BitstreamPadAlways(bs); +#if 0 else BitstreamPad(bs); +#endif pEnc->current->length = (BitstreamPos(bs) - bits) / 8; pEnc->fMvPrevSigma = -1; @@ -1400,7 +1439,7 @@ /* IMAGE *pCurrent = &pEnc->current->image; */ IMAGE *pRef = &pEnc->reference->image; - if ((pEnc->current->vop_flags & XVID_REDUCED)) + if ((pEnc->current->vop_flags & XVID_VOP_REDUCED)) { mb_width = (pEnc->mbParam.width + 31) / 32; mb_height = (pEnc->mbParam.height + 31) / 32; @@ -1422,12 +1461,12 @@ else iLimit = mb_width * mb_height + 1; - if ((pEnc->current->vop_flags & XVID_HALFPEL)) { + if ((pEnc->current->vop_flags & XVID_VOP_HALFPEL)) { start_timer(); image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, - (pEnc->mbParam.vol_flags & XVID_QUARTERPEL), + (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), pEnc->current->rounding_type); stop_inter_timer(); } @@ -1450,7 +1489,7 @@ if (bIntra == 1) return FrameCodeI(pEnc, bs); - if ( ( pEnc->current->vol_flags & XVID_GMC ) + if ( ( pEnc->current->vol_flags & XVID_VOL_GMC ) && ( (pEnc->current->warp.duv[1].x != 0) || (pEnc->current->warp.duv[1].y != 0) ) ) { pEnc->current->coding_type = S_VOP; @@ -1462,7 +1501,7 @@ generate_GMCimage(&pEnc->current->gmc_data, &pEnc->reference->image, pEnc->mbParam.mb_width, pEnc->mbParam.mb_height, pEnc->mbParam.edged_width, pEnc->mbParam.edged_width/2, - pEnc->mbParam.m_fcode, (pEnc->mbParam.vol_flags & XVID_QUARTERPEL), 0, + pEnc->mbParam.m_fcode, (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0, pEnc->current->rounding_type, pEnc->current->mbs, &pEnc->vGMC); } @@ -1511,7 +1550,7 @@ pEnc->vGMC.y + 16*y*pEnc->mbParam.edged_width + 16*x, pEnc->mbParam.edged_width, 65536); - if (pEnc->current->motion_flags & PMV_CHROMA16) { + if (pEnc->current->motion_flags & XVID_ME_CHROMA16) { iSAD += sad8(pEnc->current->image.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, pEnc->vGMC.u + 8*y*(pEnc->mbParam.edged_width/2) + 8*x, pEnc->mbParam.edged_width/2); @@ -1521,7 +1560,7 @@ if (iSAD <= pMB->sad16) { /* mode decision GMC */ - if ((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) + if ((pEnc->mbParam.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; @@ -1544,8 +1583,8 @@ dct_codes, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.edged_width, - (pEnc->current->vol_flags & XVID_QUARTERPEL), - (pEnc->current->vop_flags & XVID_REDUCED), + (pEnc->current->vol_flags & XVID_VOL_QUARTERPEL), + (pEnc->current->vop_flags & XVID_VOP_REDUCED), pEnc->current->rounding_type); stop_comp_timer(); @@ -1580,7 +1619,7 @@ if (pEnc->current->coding_type == S_VOP) skip_possible &= (pMB->mcsel == 1); else if (pEnc->current->coding_type == P_VOP) { - if ((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) + if ((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) skip_possible &= ( (pMB->qmvs[0].x == 0) && (pMB->qmvs[0].y == 0) ); else skip_possible &= ( (pMB->mvs[0].x == 0) && (pMB->mvs[0].y == 0) ); @@ -1607,7 +1646,7 @@ } if (!bSkip) { /* no SKIP, but trivial block */ - if((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) { + if((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) { VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); pMB->pmvs[0].x = - predMV.x; pMB->pmvs[0].y = - predMV.y; @@ -1634,13 +1673,13 @@ } /* ordinary case: normal coded INTER/INTER4V block */ - if ((pEnc->current->vop_flags & XVID_GREYSCALE)) + if ((pEnc->current->vop_flags & XVID_VOP_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; } - if((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) { + if((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) { VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x; pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y; @@ -1657,7 +1696,7 @@ { int k; for (k=1;k<4;k++) { - if((pEnc->mbParam.vol_flags & XVID_QUARTERPEL)) { + if((pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL)) { VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, k); pMB->pmvs[k].x = pMB->qmvs[k].x - predMV.x; pMB->pmvs[k].y = pMB->qmvs[k].y - predMV.y; @@ -1678,7 +1717,7 @@ } } - if ((pEnc->current->vop_flags & XVID_REDUCED)) + 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, @@ -1700,14 +1739,14 @@ iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode); if ((fSigma > iSearchRange / 3) - && (pEnc->mbParam.m_fcode <= (3 + (pEnc->mbParam.vol_flags & XVID_QUARTERPEL?1:0) ))) /* maximum search range 128 */ + && (pEnc->mbParam.m_fcode <= (3 + (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL?1:0) ))) /* maximum search range 128 */ { pEnc->mbParam.m_fcode++; iSearchRange *= 2; } else if ((fSigma < iSearchRange / 6) && (pEnc->fMvPrevSigma >= 0) && (pEnc->fMvPrevSigma < iSearchRange / 6) - && (pEnc->mbParam.m_fcode >= (2 + (pEnc->mbParam.vol_flags & XVID_QUARTERPEL?1:0) ))) /* minimum search range 16 */ + && (pEnc->mbParam.m_fcode >= (2 + (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL?1:0) ))) /* minimum search range 16 */ { pEnc->mbParam.m_fcode--; iSearchRange /= 2; @@ -1754,11 +1793,16 @@ } */ +/* 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_PACKED) && pEnc->bframenum_tail > 0) + if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) +#endif BitstreamPadAlways(bs); +#if 0 else BitstreamPad(bs); +#endif pEnc->current->length = (BitstreamPos(bs) - bits) / 8; @@ -1786,7 +1830,7 @@ fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mode,mb->cbp); \ } - /* XXX: pEnc->current->global_flags &= ~XVID_REDUCED; reduced resoltion not yet supported */ + /* XXX: pEnc->current->global_flags &= ~XVID_VOP_REDUCED; reduced resoltion not yet supported */ if (!first){ fp=fopen("C:\\XVIDDBGE.TXT","w"); @@ -1802,7 +1846,7 @@ start_timer(); image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, - (pEnc->mbParam.vol_flags & XVID_QUARTERPEL), 0); + (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); stop_inter_timer(); /* backward */ @@ -1812,7 +1856,7 @@ start_timer(); image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, - (pEnc->mbParam.vol_flags & XVID_QUARTERPEL), 0); + (pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); stop_inter_timer(); start_timer(); @@ -1849,7 +1893,7 @@ for (y = 0; y < pEnc->mbParam.mb_height; y++) { for (x = 0; x < pEnc->mbParam.mb_width; x++) { MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width]; - int direction = frame->vop_flags & XVID_ALTERNATESCAN ? 2 : 0; + int direction = frame->vop_flags & XVID_VOP_ALTERNATESCAN ? 2 : 0; /* decoder ignores mb when refence block is INTER(0,0), CBP=0 */ if (mb->mode == MODE_NOT_CODED) { @@ -1890,7 +1934,7 @@ /* TODO: dynamic fcode/bcode ??? */ - BitstreamPad(bs); + BitstreamPadAlways(bs); frame->length = (BitstreamPos(bs) - bits) / 8; #ifdef BFRAMES_DEC_DEBUG