--- trunk/xvidcore/vfw/src/codec.c 2004/04/05 20:39:49 1413 +++ trunk/xvidcore/vfw/src/codec.c 2005/03/27 03:59:42 1607 @@ -502,6 +502,15 @@ pass2.kfthreshold = codec->config.kfthreshold; pass2.container_frame_overhead = 24; /* AVI */ + /* VBV */ + pass2.vbv_size = profiles[codec->config.profile].max_vbv_size; + pass2.vbv_initial = (profiles[codec->config.profile].max_vbv_size*3)/4; /* 75% */ + pass2.vbv_maxrate = profiles[codec->config.profile].max_bitrate; + + // XXX: xvidcore current provides a "peak bits over 3secs" constraint. + // according to the latest dxn literature, a 1sec constraint is now used + pass2.vbv_peakrate = profiles[codec->config.profile].vbv_peakrate * 3; + plugins[create.num_plugins].func = codec->xvid_plugin_2pass2_func; plugins[create.num_plugins].param = &pass2; create.num_plugins++; @@ -557,18 +566,33 @@ create.max_quant[2] = codec->config.max_bquant; if ((profiles[codec->config.profile].flags & PROFILE_BVOP) && codec->config.use_bvop) { - create.max_bframes = codec->config.max_bframes; - create.bquant_ratio = codec->config.bquant_ratio; - create.bquant_offset = codec->config.bquant_offset; - if (codec->config.packed) - create.global |= XVID_GLOBAL_PACKED; + /* dxn: prevent bframes usage if interlacing is selected */ + if (!((profiles[codec->config.profile].flags & PROFILE_DXN) && codec->config.interlacing)) { + create.max_bframes = codec->config.max_bframes; + create.bquant_ratio = codec->config.bquant_ratio; + create.bquant_offset = codec->config.bquant_offset; + + if (codec->config.packed) + create.global |= XVID_GLOBAL_PACKED; + + create.global |= XVID_GLOBAL_CLOSED_GOP; - if (codec->config.closed_gov) - create.global |= XVID_GLOBAL_CLOSED_GOP; + /* dxn: restrict max bframes and enable packed bframes */ + if ((profiles[codec->config.profile].flags & PROFILE_DXN)) { + if (create.max_bframes > profiles[codec->config.profile].dxn_max_bframes) + create.max_bframes = profiles[codec->config.profile].dxn_max_bframes; + + create.global |= XVID_GLOBAL_PACKED; + } + } } + /* dxn: always write divx5 userdata */ + if ((profiles[codec->config.profile].flags & PROFILE_DXN)) + create.global |= XVID_GLOBAL_DIVX5_USERDATA; + create.frame_drop_ratio = codec->config.frame_drop_ratio; create.num_threads = codec->config.num_threads; @@ -588,6 +612,7 @@ return ICERR_UNSUPPORTED; } + free(create.zones); codec->ehandle = create.handle; codec->framenum = 0; codec->keyspacing = 0; @@ -636,12 +661,19 @@ frame->vop_flags |= XVID_VOP_CHROMAOPT; } + if (config->zones[i].cartoon_mode) { + frame->vop_flags |= XVID_VOP_CARTOON; + frame->motion |= XVID_ME_DETECT_STATIC_MOTION; + } + if ((profiles[config->profile].flags & PROFILE_BVOP) && config->use_bvop) { frame->bframe_threshold = config->zones[i].bvop_threshold; } } +#define CALC_BI_STRIDE(width,bitcount) ((((width * bitcount) + 31) & ~31) >> 3) + LRESULT compress(CODEC * codec, ICCOMPRESS * icc) { BITMAPINFOHEADER * inhdr = icc->lpbiInput; @@ -671,12 +703,6 @@ } } - if ((profiles[codec->config.profile].flags & PROFILE_REDUCED) && - codec->config.reduced_resolution) { - frame.vol_flags |= XVID_VOL_REDUCED_ENABLE; - frame.vop_flags |= XVID_VOP_REDUCED; /* XXX: need auto decion mode */ - } - if ((profiles[codec->config.profile].flags & PROFILE_QPEL) && codec->config.qpel) { frame.vol_flags |= XVID_VOL_QUARTERPEL; frame.motion |= XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE8; @@ -690,7 +716,10 @@ if ((profiles[codec->config.profile].flags & PROFILE_INTERLACE) && codec->config.interlacing) frame.vol_flags |= XVID_VOL_INTERLACING; - if (codec->config.ar_mode == 0) { /* PAR */ + /* dxn: force 1:1 picture aspect ration */ + if ((profiles[codec->config.profile].flags & PROFILE_DXN)) { + frame.par = XVID_PAR_11_VGA; + } else if (codec->config.ar_mode == 0) { /* PAR */ if (codec->config.display_aspect_ratio != 5) { frame.par = codec->config.display_aspect_ratio + 1; } else { @@ -710,6 +739,10 @@ frame.vop_flags |= XVID_VOP_HALFPEL; frame.vop_flags |= XVID_VOP_HQACPRED; + if (codec->config.interlacing && codec->config.tff) + frame.vop_flags |= XVID_VOP_TOPFIELDFIRST; + + if (codec->config.vop_debug) frame.vop_flags |= XVID_VOP_DEBUG; @@ -717,17 +750,14 @@ frame.vop_flags |= XVID_VOP_TRELLISQUANT; } - if (codec->config.motion_search > 4) - frame.vop_flags |= XVID_VOP_INTER4V; + if ((profiles[codec->config.profile].flags & PROFILE_4MV)) { + if (codec->config.motion_search > 4) + frame.vop_flags |= XVID_VOP_INTER4V; + } if (codec->config.chromame) frame.motion |= XVID_ME_CHROMA_PVOP + XVID_ME_CHROMA_BVOP; - if (codec->config.cartoon_mode) { - frame.vop_flags |= XVID_VOP_CARTOON; - frame.motion |= XVID_ME_DETECT_STATIC_MOTION; - } - if (codec->config.turbo) frame.motion |= XVID_ME_FASTREFINE16 | XVID_ME_FASTREFINE8 | XVID_ME_SKIP_DELTASEARCH | XVID_ME_FAST_MODEINTERPOLATE | @@ -735,6 +765,9 @@ frame.motion |= pmvfast_presets[codec->config.motion_search]; + if (codec->config.vhq_bframe) frame.vop_flags |= XVID_VOP_RD_BVOP; + + switch (codec->config.vhq_mode) { case VHQ_MODE_DECISION : @@ -771,7 +804,7 @@ } frame.input.plane[0] = icc->lpInput; - frame.input.stride[0] = (((icc->lpbiInput->biWidth * icc->lpbiInput->biBitCount) + 31) & ~31) >> 3; + frame.input.stride[0] = CALC_BI_STRIDE(icc->lpbiInput->biWidth, icc->lpbiInput->biBitCount); if ((frame.input.csp = get_colorspace(inhdr)) == XVID_CSP_NULL) return ICERR_BADFORMAT; @@ -924,7 +957,8 @@ outhdr->biPlanes = 1; outhdr->biBitCount = 24; outhdr->biCompression = BI_RGB; /* sonic foundry vegas video v3 only supports BI_RGB */ - outhdr->biSizeImage = outhdr->biWidth * outhdr->biHeight * outhdr->biBitCount; + outhdr->biSizeImage = outhdr->biHeight * CALC_BI_STRIDE(outhdr->biWidth, outhdr->biBitCount); + outhdr->biXPelsPerMeter = 0; outhdr->biYPelsPerMeter = 0; outhdr->biClrUsed = 0; @@ -952,6 +986,7 @@ memset(&init, 0, sizeof(init)); init.version = XVID_VERSION; init.cpu_flags = codec->config.cpu; + init.debug = codec->config.debug; codec->xvid_global_func(0, XVID_GBL_INIT, &init, NULL); memset(&create, 0, sizeof(create)); @@ -981,7 +1016,8 @@ REG_GET_N("Brightness", pp_brightness, 0); REG_GET_N("Deblock_Y", pp_dy, 0) REG_GET_N("Deblock_UV", pp_duv, 0) - REG_GET_N("Dering", pp_dr, 0) + REG_GET_N("Dering_Y", pp_dry, 0) + REG_GET_N("Dering_UV", pp_druv, 0) REG_GET_N("FilmEffect", pp_fe, 0) RegCloseKey(hKey); @@ -1029,13 +1065,13 @@ convert.input.csp = get_colorspace(icd->lpbiInput); convert.input.plane[0] = icd->lpInput; - convert.input.stride[0] = (((icd->lpbiInput->biWidth *icd->lpbiInput->biBitCount) + 31) & ~31) >> 3; + convert.input.stride[0] = CALC_BI_STRIDE(icd->lpbiInput->biWidth, icd->lpbiInput->biBitCount); if (convert.input.csp == XVID_CSP_I420 || convert.input.csp == XVID_CSP_YV12) convert.input.stride[0] = (convert.input.stride[0]*2)/3; convert.output.csp = get_colorspace(icd->lpbiOutput); convert.output.plane[0] = icd->lpOutput; - convert.output.stride[0] = (((icd->lpbiOutput->biWidth *icd->lpbiOutput->biBitCount) + 31) & ~31) >> 3; + convert.output.stride[0] = CALC_BI_STRIDE(icd->lpbiOutput->biWidth, icd->lpbiOutput->biBitCount); if (convert.output.csp == XVID_CSP_I420 || convert.output.csp == XVID_CSP_YV12) convert.output.stride[0] = (convert.output.stride[0]*2)/3; @@ -1065,9 +1101,9 @@ return ICERR_BADFORMAT; } frame.output.plane[0] = icd->lpOutput; - frame.output.stride[0] = (((icd->lpbiOutput->biWidth * icd->lpbiOutput->biBitCount) + 31) & ~31) >> 3; + frame.output.stride[0] = CALC_BI_STRIDE(icd->lpbiOutput->biWidth, icd->lpbiOutput->biBitCount); if (frame.output.csp == XVID_CSP_I420 || frame.output.csp == XVID_CSP_YV12) - frame.output.stride[0] = (frame.output.stride[0]*2)/3; + frame.output.stride[0] = CALC_BI_STRIDE(icd->lpbiOutput->biWidth, 8); } else { @@ -1076,7 +1112,8 @@ if (pp_dy)frame.general |= XVID_DEBLOCKY; if (pp_duv) frame.general |= XVID_DEBLOCKUV; -/* if (pp_dr) frame.general |= XVID_DERING; */ + if (pp_dry) frame.general |= XVID_DERINGY; + if (pp_druv) frame.general |= XVID_DERINGUV; if (pp_fe) frame.general |= XVID_FILMEFFECT; frame.brightness = pp_brightness;