--- branches/dev-api-4/xvidcore/vfw/src/config.c 2003/06/09 01:25:19 1053 +++ branches/dev-api-4/xvidcore/vfw/src/config.c 2003/06/10 10:07:03 1061 @@ -64,7 +64,6 @@ #include /* XviD API */ #include "debug.h" -#include "codec.h" #include "config.h" #include "resource.h" @@ -148,44 +147,36 @@ static const REG_INT reg_ints[] = { {"mode", ®.mode, RC_MODE_1PASS}, {"bitrate", ®.bitrate, 700}, - /* {"desired_size", ®.desired_size, 570000}, not used */ + {"desired_size", ®.desired_size, 570000}, + {"use_2pass_bitrate", ®.use_2pass_bitrate, 0}, - {"rc_reaction_delay_factor",®.rc_reaction_delay_factor, 16}, - {"rc_averaging_period", ®.rc_averaging_period, 100}, - {"rc_buffer", ®.rc_buffer, 100}, - - {"motion_search", ®.motion_search, 6}, - {"quant_type", ®.quant_type, 0}, - {"fourcc_used", ®.fourcc_used, 0}, - {"vhq_mode", ®.vhq_mode, 0}, - {"max_key_interval", ®.max_key_interval, 300}, - {"min_key_interval", ®.min_key_interval, 1}, + /* profile */ + {"quant_type", ®.quant_type, 0}, {"lum_masking", ®.lum_masking, 0}, {"interlacing", ®.interlacing, 0}, {"qpel", ®.qpel, 0}, {"gmc", ®.gmc, 0}, - {"chromame", ®.chromame, 0}, + {"reduced_resolution", ®.reduced_resolution, 0}, {"use_bvop", ®.use_bvop, 0}, {"max_bframes", ®.max_bframes, 2}, {"bquant_ratio", ®.bquant_ratio, 150}, /* 100-base float */ {"bquant_offset", ®.bquant_offset, 100}, /* 100-base float */ {"packed", ®.packed, 0}, {"closed_gov", ®.closed_gov, 1}, - {"vop_debug", ®.vop_debug, 0}, - {"debug", ®.debug, 0x0}, - {"reduced_resolution", ®.reduced_resolution, 0}, - {"frame_drop_ratio", ®.frame_drop_ratio, 0}, - {"min_iquant", ®.min_iquant, 2}, - {"max_iquant", ®.max_iquant, 31}, - {"min_pquant", ®.min_pquant, 2}, - {"max_pquant", ®.max_pquant, 31}, - {"min_bquant", ®.min_bquant, 2}, - {"max_bquant", ®.max_bquant, 31}, - {"trellis_quant", ®.trellis_quant, 0}, + /* zones */ + {"num_zones", ®.num_zones, 1}, + /* single pass */ + {"rc_reaction_delay_factor",®.rc_reaction_delay_factor, 16}, + {"rc_averaging_period", ®.rc_averaging_period, 100}, + {"rc_buffer", ®.rc_buffer, 100}, + + /* 2pass1 */ + {"discard1pass", ®.discard1pass, 1}, + + /* 2pass2 */ {"keyframe_boost", ®.keyframe_boost, 0}, - {"discard1pass", ®.discard1pass, 1}, {"kftreshold", ®.kftreshold, 10}, {"kfreduction", ®.kfreduction, 20}, {"curve_compression_high", ®.curve_compression_high, 0}, @@ -195,7 +186,28 @@ {"twopass_max_overflow_improvement", ®.twopass_max_overflow_improvement, 60}, {"twopass_max_overflow_degradation", ®.twopass_max_overflow_degradation, 60}, - {"num_zones", ®.num_zones, 1}, + /* motion */ + {"motion_search", ®.motion_search, 6}, + {"vhq_mode", ®.vhq_mode, 0}, + {"chromame", ®.chromame, 0}, + {"max_key_interval", ®.max_key_interval, 300}, + {"min_key_interval", ®.min_key_interval, 1}, + {"frame_drop_ratio", ®.frame_drop_ratio, 0}, + + /* quant */ + {"min_iquant", ®.min_iquant, 2}, + {"max_iquant", ®.max_iquant, 31}, + {"min_pquant", ®.min_pquant, 2}, + {"max_pquant", ®.max_pquant, 31}, + {"min_bquant", ®.min_bquant, 2}, + {"max_bquant", ®.max_bquant, 31}, + {"trellis_quant", ®.trellis_quant, 0}, + + /* debug */ + {"fourcc_used", ®.fourcc_used, 0}, + {"debug", ®.debug, 0x0}, + {"vop_debug", ®.vop_debug, 0}, + {"display_status", ®.display_status, 1}, }; static const REG_STR reg_strs[] = { @@ -838,9 +850,10 @@ SetDlgItemInt(hDlg, IDC_NUMTHREADS, config->num_threads, FALSE); - CheckDlg(hDlg, IDC_VOPDEBUG, config->vop_debug); - set_dlgitem_hex(hDlg, IDC_DEBUG, config->debug); SendDlgItemMessage(hDlg, IDC_FOURCC, CB_SETCURSEL, config->fourcc_used, 0); + set_dlgitem_hex(hDlg, IDC_DEBUG, config->debug); + CheckDlg(hDlg, IDC_VOPDEBUG, config->vop_debug); + CheckDlg(hDlg, IDC_DISPLAY_STATUS, config->display_status); break; } } @@ -970,8 +983,9 @@ config->num_threads = config_get_uint(hDlg, IDC_NUMTHREADS, config->num_threads); config->fourcc_used = SendDlgItemMessage(hDlg, IDC_FOURCC, CB_GETCURSEL, 0, 0); - config->vop_debug = IsDlgChecked(hDlg, IDC_VOPDEBUG); config->debug = get_dlgitem_hex(hDlg, IDC_DEBUG, config->debug); + config->vop_debug = IsDlgChecked(hDlg, IDC_VOPDEBUG); + config->display_status = IsDlgChecked(hDlg, IDC_DISPLAY_STATUS); break; } } @@ -1202,43 +1216,61 @@ ListView_SetItemText(hDlg, i, 2, tmp); } +static int g_use_bitrate = 1; void main_mode(HWND hDlg, CONFIG * config) { + const int profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0); + const int rc_mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0); + /* enable target rate/size control only for 1pass and 2pass modes*/ + const int target_en = rc_mode==RC_MODE_1PASS || rc_mode==RC_MODE_2PASS2; + char buf[16]; - int profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0); - int bitrate_en; int max; - - wsprintf(buf, "%i kbps", DEFAULT_MIN_KBPS); - SetDlgItemText(hDlg, IDC_BITRATE_MIN, buf); - max = profiles[profile].max_bitrate; - if (max == 0) max = DEFAULT_MAX_KBPS; - wsprintf(buf, "%i kbps", max); - SetDlgItemText(hDlg, IDC_BITRATE_MAX, buf); - - SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(DEFAULT_MIN_KBPS, max)); - SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, - config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) ); - - bitrate_en = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0); - bitrate_en = bitrate_en==RC_MODE_1PASS || bitrate_en==RC_MODE_2PASS2; - - EnableDlgWindow(hDlg, IDC_BITRATE_S, bitrate_en); - EnableDlgWindow(hDlg, IDC_BITRATE, bitrate_en); - EnableDlgWindow(hDlg, IDC_BITRATE_MIN, bitrate_en); - EnableDlgWindow(hDlg, IDC_BITRATE_MAX, bitrate_en); - EnableDlgWindow(hDlg, IDC_SLIDER, bitrate_en); + g_use_bitrate = rc_mode==RC_MODE_1PASS || config->use_2pass_bitrate; + + if (g_use_bitrate) { + SetDlgItemText(hDlg, IDC_BITRATE_S, "Target bitrate (kbps):"); + + wsprintf(buf, "%i kbps", DEFAULT_MIN_KBPS); + SetDlgItemText(hDlg, IDC_BITRATE_MIN, buf); + + max = profiles[profile].max_bitrate; + if (max == 0) max = DEFAULT_MAX_KBPS; + wsprintf(buf, "%i kbps", max); + SetDlgItemText(hDlg, IDC_BITRATE_MAX, buf); + + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(DEFAULT_MIN_KBPS, max)); + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, + config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) ); + + }else{ + SetDlgItemText(hDlg, IDC_BITRATE_S, "Target size (kbytes):"); + } + + EnableDlgWindow(hDlg, IDC_BITRATE_S, target_en); + EnableDlgWindow(hDlg, IDC_BITRATE, target_en); + + EnableDlgWindow(hDlg, IDC_BITRATE_MIN, target_en && g_use_bitrate); + EnableDlgWindow(hDlg, IDC_BITRATE_MAX, target_en && g_use_bitrate); + EnableDlgWindow(hDlg, IDC_SLIDER, target_en && g_use_bitrate); } + + void main_upload(HWND hDlg, CONFIG * config) { int i; SendDlgItemMessage(hDlg, IDC_PROFILE, CB_SETCURSEL, config->profile, 0); - SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0); - SetDlgItemInt(hDlg, IDC_BITRATE, config->bitrate, FALSE); + SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0); + + if (g_use_bitrate) { + SetDlgItemInt(hDlg, IDC_BITRATE, config->bitrate, FALSE); + }else{ + SetDlgItemInt(hDlg, IDC_BITRATE, config->desired_size, FALSE); + } ListView_DeleteAllItems(GetDlgItem(hDlg,IDC_ZONES)); for (i=0; i < config->num_zones; i++) { @@ -1252,10 +1284,13 @@ { config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0); config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0); - config->bitrate = config_get_uint(hDlg, IDC_BITRATE, config->bitrate); -} - + if (g_use_bitrate) { + config->bitrate = config_get_uint(hDlg, IDC_BITRATE, config->bitrate); + }else{ + config->desired_size = config_get_uint(hDlg, IDC_BITRATE, config->desired_size); + } +} /* main dialog proc */ @@ -1292,7 +1327,6 @@ InitCommonControls(); - if ((g_hTooltip = CreateWindow(TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, g_hInst, NULL))) @@ -1304,6 +1338,8 @@ EnumChildWindows(hDlg, enum_tooltips, 0); } + SetClassLong(GetDlgItem(hDlg, IDC_BITRATE_S), GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_HAND)); + { DWORD ext_style = ListView_GetExtendedListViewStyle(GetDlgItem(hDlg,IDC_ZONES)); ext_style |= LVS_EX_FULLROWSELECT | LVS_EX_FLATSB ; @@ -1338,8 +1374,10 @@ } } + /* XXX: main_mode needs RC_MODE_xxx, main_upload needs g_use_bitrate set correctly... */ main_upload(hDlg, config); main_mode(hDlg, config); + main_upload(hDlg, config); break; case WM_NOTIFY : @@ -1387,6 +1425,15 @@ } break; + + case IDC_BITRATE_S : + /* alternate between bitrate/desired_length metrics */ + main_download(hDlg, config); + config->use_2pass_bitrate = !config->use_2pass_bitrate; + main_mode(hDlg, config); + main_upload(hDlg, config); + break; + case IDC_BITRATE_CALC : main_download(hDlg, config); adv_dialog(hDlg, config, bitrate_dlgs, sizeof(bitrate_dlgs)/sizeof(int)); @@ -1502,11 +1549,18 @@ } }else if (HIWORD(wParam) == LBN_SELCHANGE && (LOWORD(wParam)==IDC_PROFILE || LOWORD(wParam)==IDC_MODE)) { + + main_download(hDlg, config); main_mode(hDlg, config); + main_upload(hDlg, config); + }else if (HIWORD(wParam)==EN_UPDATE && LOWORD(wParam)==IDC_BITRATE) { - SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, - config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) ); + if (g_use_bitrate) { + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, + config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) ); + } + }else { return 0; }