--- branches/dev-api-4/xvidcore/vfw/src/config.c 2004/01/22 16:13:59 1323 +++ branches/dev-api-4/xvidcore/vfw/src/config.c 2004/02/09 10:14:54 1358 @@ -57,9 +57,6 @@ #include #include -#include -#include - #include /* sprintf */ #include /* XviD API */ @@ -73,9 +70,14 @@ #define CheckDlg(hwnd,idc,value) CheckDlgButton(hwnd,idc, value?BST_CHECKED:BST_UNCHECKED) #define EnableDlgWindow(hwnd,idc,state) EnableWindow(GetDlgItem(hwnd,idc),state) +static void zones_update(HWND hDlg, CONFIG * config); + HINSTANCE g_hInst; HWND g_hTooltip; +static int g_use_bitrate = 1; + + int pp_dy, pp_duv, pp_dr, pp_fe; /* decoder options */ /* enumerates child windows, assigns tooltips */ @@ -143,6 +145,38 @@ }; +typedef struct { + char * name; + float value; +} named_float_t; + +static const named_float_t video_fps_list[] = { + { "15.0", 15.0F }, + { "23.976 (FILM)", 23.976F }, + { "25.0 (PAL)", 25.0F }, + { "29.97 (NTSC)", 29.970F }, + { "30.0", 30.0F } +}; + + +typedef struct { + char * name; + int avi_interval; /* audio overhead intervals (milliseconds) */ + float mkv_multiplier; /* mkv multiplier */ +} named_int_t; + + +#define NO_AUDIO 5 +static const named_int_t audio_type_list[] = { + { "MP3-CBR", 1000, 48000/1152/6 }, + { "MP3-VBR", 24, 48000/1152/6 }, + { "OGG", /*?*/1000, 48000*(0.7F/1024 + 0.3F/180) }, + { "AC3", 64, 48000/1536/6 }, + { "DTS", 21, /*?*/48000/1152/6 }, + { "(None)", 0, 0 }, +}; + + /* ===================================================================================== */ /* REGISTRY ============================================================================ */ /* ===================================================================================== */ @@ -154,7 +188,8 @@ {"mode", ®.mode, RC_MODE_1PASS}, {"bitrate", ®.bitrate, 700}, {"desired_size", ®.desired_size, 570000}, - {"use_2pass_bitrate", ®.use_2pass_bitrate, 0}, + {"use_2pass_bitrate", ®.use_2pass_bitrate, 0}, + {"desired_quant", ®.desired_quant, DEFAULT_QUANT}, /* 100-base float */ /* profile */ {"quant_type", ®.quant_type, 0}, @@ -179,7 +214,7 @@ {"ar_y", ®.ar_y, 3}, /* zones */ - {"num_zones", ®.num_zones, 1}, + {"num_zones", ®.num_zones, 1}, /* single pass */ {"rc_reaction_delay_factor",®.rc_reaction_delay_factor, 16}, @@ -188,9 +223,10 @@ /* 2pass1 */ {"discard1pass", ®.discard1pass, 1}, + {"full1pass", ®.full1pass, 0}, /* 2pass2 */ - {"keyframe_boost", ®.keyframe_boost, 0}, + {"keyframe_boost", ®.keyframe_boost, 10}, {"kfreduction", ®.kfreduction, 20}, {"kfthreshold", ®.kfthreshold, 1}, {"curve_compression_high", ®.curve_compression_high, 0}, @@ -199,6 +235,19 @@ {"twopass_max_overflow_improvement", ®.twopass_max_overflow_improvement, 5}, {"twopass_max_overflow_degradation", ®.twopass_max_overflow_degradation, 5}, + /* bitrate calculator */ + {"container_type", ®.container_type, 1}, + {"target_size", ®.target_size, 650 * 1024}, + {"subtitle_size", ®.subtitle_size, 0}, + {"hours", ®.hours, 1}, + {"minutes", ®.minutes, 30}, + {"seconds", ®.seconds, 0}, + {"fps", ®.fps, 2}, + {"audio_mode", ®.audio_mode, 0}, + {"audio_type", ®.audio_type, 0}, + {"audio_rate", ®.audio_rate, 128}, + {"audio_size", ®.audio_size, 0}, + /* motion */ {"motion_search", ®.motion_search, 6}, {"vhq_mode", ®.vhq_mode, 1}, @@ -209,19 +258,19 @@ {"frame_drop_ratio", ®.frame_drop_ratio, 0}, /* quant */ - {"min_iquant", ®.min_iquant, 2}, + {"min_iquant", ®.min_iquant, 1}, {"max_iquant", ®.max_iquant, 31}, - {"min_pquant", ®.min_pquant, 2}, + {"min_pquant", ®.min_pquant, 1}, {"max_pquant", ®.max_pquant, 31}, - {"min_bquant", ®.min_bquant, 2}, + {"min_bquant", ®.min_bquant, 1}, {"max_bquant", ®.max_bquant, 31}, - {"trellis_quant", ®.trellis_quant, 0}, + {"trellis_quant", ®.trellis_quant, 0}, /* debug */ {"fourcc_used", ®.fourcc_used, 0}, {"debug", ®.debug, 0x0}, {"vop_debug", ®.vop_debug, 0}, - {"display_status", ®.display_status, 1}, + {"display_status", ®.display_status, 1}, /* decoder, shared with dshow */ {"Deblock_Y", &pp_dy, 0}, @@ -232,20 +281,20 @@ }; static const REG_STR reg_strs[] = { - {"profile", reg.profile_name, "(unrestricted)"}, + {"profile", reg.profile_name, "AS @ L5"}, {"stats", reg.stats, CONFIG_2PASS_FILE}, }; zone_t stmp; static const REG_INT reg_zone[] = { - {"zone%i_frame", &stmp.frame, 0}, - {"zone%i_mode", &stmp.mode, RC_ZONE_WEIGHT}, - {"zone%i_weight", &stmp.weight, 100}, /* 100-base float */ - {"zone%i_quant", &stmp.quant, 500}, /* 100-base float */ - {"zone%i_type", &stmp.type, XVID_TYPE_AUTO}, - {"zone%i_greyscale", &stmp.greyscale, 0}, - {"zone%i_chroma_opt", &stmp.chroma_opt, 0}, + {"zone%i_frame", &stmp.frame, 0}, + {"zone%i_mode", &stmp.mode, RC_ZONE_WEIGHT}, + {"zone%i_weight", &stmp.weight, 100}, /* 100-base float */ + {"zone%i_quant", &stmp.quant, 500}, /* 100-base float */ + {"zone%i_type", &stmp.type, XVID_TYPE_AUTO}, + {"zone%i_greyscale", &stmp.greyscale, 0}, + {"zone%i_chroma_opt", &stmp.chroma_opt, 0}, {"zone%i_bvop_threshold", &stmp.bvop_threshold, 0}, }; @@ -321,7 +370,7 @@ reg.profile = 0; for (i=0; ici_valid); break; @@ -708,7 +787,7 @@ /* enable/disable controls based on encoder-mode or user selection */ -void adv_mode(HWND hDlg, int idd, CONFIG * config) +static void adv_mode(HWND hDlg, int idd, CONFIG * config) { int profile; int weight_en, quant_en; @@ -781,6 +860,114 @@ SetDlgItemInt(hDlg, IDC_LEVEL_BITRATE, profiles[profile].max_bitrate, FALSE); break; + case IDD_BITRATE : + { + int ctype = SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_GETCURSEL, 0, 0); + int target_size = config_get_uint(hDlg, IDC_BITRATE_TSIZE, 0); + int subtitle_size = config_get_uint(hDlg, IDC_BITRATE_SSIZE, 0); + int fps = SendDlgItemMessage(hDlg, IDC_BITRATE_FPS, CB_GETCURSEL, 0, 0); + + int duration = + 3600 * config_get_uint(hDlg, IDC_BITRATE_HOURS, 0) + + 60 * config_get_uint(hDlg, IDC_BITRATE_MINUTES, 0) + + config_get_uint(hDlg, IDC_BITRATE_SECONDS, 0); + + int audio_type = SendDlgItemMessage(hDlg, IDC_BITRATE_AFORMAT, CB_GETCURSEL, 0, 0); + int audio_mode = IsDlgChecked(hDlg, IDC_BITRATE_AMODE_SIZE); + int audio_rate = config_get_uint(hDlg, IDC_BITRATE_ARATE, 0); + int audio_size = config_get_uint(hDlg, IDC_BITRATE_ASIZE, 0); + + int frames; + int overhead; + int vsize; + + if (duration == 0) + break; + + if (fps < 0 || fps >= sizeof(video_fps_list)/sizeof(named_float_t)) { + fps = 0; + } + if (audio_type < 0 || audio_type >= sizeof(audio_type_list)/sizeof(named_int_t)) { + audio_type = 0; + } + + EnableDlgWindow(hDlg, IDC_BITRATE_AMODE_RATE, audio_type!=NO_AUDIO); + EnableDlgWindow(hDlg, IDC_BITRATE_AMODE_SIZE, audio_type!=NO_AUDIO); + EnableDlgWindow(hDlg, IDC_BITRATE_ARATE, audio_type!=NO_AUDIO && !audio_mode); + EnableDlgWindow(hDlg, IDC_BITRATE_ASIZE, audio_type!=NO_AUDIO && audio_mode); + EnableDlgWindow(hDlg, IDC_BITRATE_ASELECT, audio_type!=NO_AUDIO && audio_mode); + + /* step 1: calculate number of frames */ + frames = (int)(duration * video_fps_list[fps].value); + + /* step 2: calculate audio_size (kbytes)*/ + if (audio_type!=NO_AUDIO) { + if (audio_mode==0) { + audio_size = (duration * audio_rate) / 8; + } + }else{ + audio_size = 0; + } + + /* step 3: calculate container overhead */ + + switch(ctype) { + case 0 : /* AVI */ + case 1 : /* AVI-OpenDML */ + + overhead = frames; + + if (audio_type!=NO_AUDIO) { + overhead += (duration * 1000) / audio_type_list[audio_type].avi_interval; + } + + overhead *= (ctype==0) ? 24 : 16; + + overhead /= 1024; + break; + + case 2 : /* Matroska: gknot formula */ + + /* common overhead */ + overhead = 40 + 12 + 8+ 16*duration + 200 + 100*1/*one audio stream*/ + 11*duration; + + /* video overhead */ + overhead += frames*8 + (int)(frames * 4 * 0.94); + + /* cue tables and menu seek entries (300k default) */ + overhead += 300 * 1024; + + /* audio */ + overhead += (int)(duration * audio_type_list[audio_type].mkv_multiplier); + + overhead /= 1024; + break; + + case 3 : /* OGM: inaccurate model */ + overhead = (int)(0.0039F * (target_size - subtitle_size)); + break; + + default : /* (none) */ + overhead = 0; + break; + } + + SetDlgItemInt(hDlg, IDC_BITRATE_COVERHEAD, overhead, TRUE); + + /* final video bitstream size */ + vsize = target_size - subtitle_size - audio_size - overhead; + if (vsize > 0) { + SetDlgItemInt(hDlg, IDC_BITRATE_VSIZE, vsize, TRUE); + /* convert from kbytes to kbits-per-second */ + SetDlgItemInt(hDlg, IDC_BITRATE_VRATE, (vsize * 8 * 128) / (duration * 125), TRUE); + }else{ + SetDlgItemText(hDlg, IDC_BITRATE_VSIZE, "Overflow"); + SetDlgItemText(hDlg, IDC_BITRATE_VRATE, "Overflow"); + } + + } + break; + case IDD_ZONE : weight_en = IsDlgChecked(hDlg, IDC_ZONE_MODE_WEIGHT); quant_en = IsDlgChecked(hDlg, IDC_ZONE_MODE_QUANT); @@ -819,7 +1006,7 @@ /* upload config data into dialog */ -void adv_upload(HWND hDlg, int idd, CONFIG * config) +static void adv_upload(HWND hDlg, int idd, CONFIG * config) { switch (idd) { @@ -861,6 +1048,7 @@ case IDD_RC_2PASS1 : SetDlgItemText(hDlg, IDC_STATS, config->stats); CheckDlg(hDlg, IDC_DISCARD1PASS, config->discard1pass); + CheckDlg(hDlg, IDC_FULL1PASS, config->full1pass); break; case IDD_RC_2PASS2 : @@ -877,6 +1065,22 @@ SetDlgItemInt(hDlg, IDC_MINKEY, config->kfthreshold, FALSE); break; + case IDD_BITRATE : + SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_SETCURSEL, config->container_type, 0); + SetDlgItemInt(hDlg, IDC_BITRATE_TSIZE, config->target_size, FALSE); + SetDlgItemInt(hDlg, IDC_BITRATE_SSIZE, config->subtitle_size, FALSE); + + SetDlgItemInt(hDlg, IDC_BITRATE_HOURS, config->hours, FALSE); + SetDlgItemInt(hDlg, IDC_BITRATE_MINUTES, config->minutes, FALSE); + SetDlgItemInt(hDlg, IDC_BITRATE_SECONDS, config->seconds, FALSE); + SendDlgItemMessage(hDlg, IDC_BITRATE_FPS, CB_SETCURSEL, config->fps, 0); + + SendDlgItemMessage(hDlg, IDC_BITRATE_AFORMAT, CB_SETCURSEL, config->audio_type, 0); + CheckRadioButton(hDlg, IDC_BITRATE_AMODE_RATE, IDC_BITRATE_AMODE_SIZE, config->audio_mode == 0 ? IDC_BITRATE_AMODE_RATE : IDC_BITRATE_AMODE_SIZE); + SetDlgItemInt(hDlg, IDC_BITRATE_ARATE, config->audio_rate, FALSE); + SetDlgItemInt(hDlg, IDC_BITRATE_ASIZE, config->audio_size, FALSE); + break; + case IDD_ZONE : SetDlgItemInt(hDlg, IDC_ZONE_FRAME, config->zones[config->cur_zone].frame, FALSE); @@ -944,7 +1148,7 @@ /* download config data from dialog */ -void adv_download(HWND hDlg, int idd, CONFIG * config) +static void adv_download(HWND hDlg, int idd, CONFIG * config) { switch (idd) { @@ -991,6 +1195,7 @@ if (GetDlgItemText(hDlg, IDC_STATS, config->stats, MAX_PATH) == 0) lstrcpy(config->stats, CONFIG_2PASS_FILE); config->discard1pass = IsDlgChecked(hDlg, IDC_DISCARD1PASS); + config->full1pass = IsDlgChecked(hDlg, IDC_FULL1PASS); break; case IDD_RC_2PASS2 : @@ -1017,6 +1222,39 @@ break; + case IDD_BITRATE : + config->container_type = SendDlgItemMessage(hDlg, IDC_BITRATE_CFORMAT, CB_GETCURSEL, 0, 0); + config->target_size = config_get_uint(hDlg, IDC_BITRATE_TSIZE, config->target_size); + config->subtitle_size = config_get_uint(hDlg, IDC_BITRATE_SSIZE, config->subtitle_size); + + config->hours = config_get_uint(hDlg, IDC_BITRATE_HOURS, config->hours); + config->minutes = config_get_uint(hDlg, IDC_BITRATE_MINUTES, config->minutes); + config->seconds = config_get_uint(hDlg, IDC_BITRATE_SECONDS, config->seconds); + config->fps = SendDlgItemMessage(hDlg, IDC_BITRATE_FPS, CB_GETCURSEL, 0, 0); + + config->audio_type = SendDlgItemMessage(hDlg, IDC_BITRATE_AFORMAT, CB_GETCURSEL, 0, 0); + config->audio_mode = IsDlgChecked(hDlg, IDC_BITRATE_AMODE_SIZE) ? 1 : 0 ; + config->audio_rate = config_get_uint(hDlg, IDC_BITRATE_ARATE, config->audio_rate); + config->audio_size = config_get_uint(hDlg, IDC_BITRATE_ASIZE, config->audio_size); + + /* the main window uses "AVI bitrate/filesize" not "video bitrate/filesize", + so we have to compensate by frames * 24 bytes */ + { + int frame_compensate = 24 * (int)( + (3600*config->hours + + 60*config->minutes + + config->seconds) * video_fps_list[config->fps].value) / 1024; + + int bitrate_compensate = (int)(24 * video_fps_list[config->fps].value) / 125; + + config->desired_size = + config_get_uint(hDlg, IDC_BITRATE_VSIZE, config->desired_size) - frame_compensate; + + config->bitrate = + config_get_uint(hDlg, IDC_BITRATE_VRATE, config->bitrate) - bitrate_compensate; + } + break; + case IDD_ZONE : config->zones[config->cur_zone].frame = config_get_uint(hDlg, IDC_ZONE_FRAME, config->zones[config->cur_zone].frame); @@ -1097,7 +1335,7 @@ /* advanced dialog proc */ -BOOL CALLBACK adv_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +static BOOL CALLBACK adv_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { PROPSHEETINFO *psi; @@ -1128,9 +1366,48 @@ case IDC_CPU_FORCE : case IDC_AR : case IDC_PAR : + case IDC_BITRATE_AMODE_RATE : + case IDC_BITRATE_AMODE_SIZE : adv_mode(hDlg, psi->idd, psi->config); break; + case IDC_BITRATE_SSELECT : + case IDC_BITRATE_ASELECT : + { + OPENFILENAME ofn; + char filename[MAX_PATH] = ""; + + memset(&ofn, 0, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + + ofn.hwndOwner = hDlg; + if (LOWORD(wParam)==IDC_BITRATE_SSELECT) { + ofn.lpstrFilter = "Subtitle files (*.sub, *.ssa)\0*.sub;*.ssa\0All files (*.*)\0*.*\0\0"; + }else{ + ofn.lpstrFilter = "Audio files (*.mp3, *.ac3)\0*.mp3; *.ac3\0All files (*.*)\0*.*\0\0"; + } + + ofn.lpstrFile = filename; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; + + if (GetOpenFileName(&ofn)) { + HANDLE hFile; + DWORD filesize; + + if ((hFile = CreateFile(filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)) == INVALID_HANDLE_VALUE || + (filesize = GetFileSize(hFile, NULL)) == INVALID_FILE_SIZE) { + MessageBox(hDlg, "Could not get file size", "Error", 0); + }else{ + SetDlgItemInt(hDlg, + LOWORD(wParam)==IDC_BITRATE_SSELECT? IDC_BITRATE_SSIZE : IDC_BITRATE_ASIZE, + filesize / 1024, FALSE); + CloseHandle(hFile); + } + } + } + break; + case IDC_QUANTMATRIX : DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_QUANTMATRIX), hDlg, quantmatrix_proc, (LPARAM)psi->config); break; @@ -1146,7 +1423,7 @@ ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hDlg; - ofn.lpstrFilter = "bitrate curve (*.stats)\0*.stats\0All files (*.*)\0*.*\0\0"; + ofn.lpstrFilter = "bitrate curve (*.pass)\0*.pass\0All files (*.*)\0*.*\0\0"; ofn.lpstrFile = tmp; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_PATHMUSTEXIST; @@ -1157,11 +1434,12 @@ ofn.Flags |= OFN_FILEMUSTEXIST; } - if (GetSaveFileName(&ofn)) - { + if ((psi->idd==IDD_RC_2PASS1 && GetSaveFileName(&ofn)) || + (psi->idd==IDD_RC_2PASS2 && GetOpenFileName(&ofn))) { SetDlgItemText(hDlg, IDC_STATS, tmp); } - } + } + break; case IDC_ZONE_FETCH : SetDlgItemInt(hDlg, IDC_ZONE_FRAME, psi->config->ci.ciActiveFrame, FALSE); @@ -1194,24 +1472,39 @@ default : return TRUE; } + }else if ((HIWORD(wParam) == CBN_EDITCHANGE || HIWORD(wParam)==CBN_SELCHANGE) && + (LOWORD(wParam)==IDC_BITRATE_TSIZE || + LOWORD(wParam)==IDC_BITRATE_ARATE )) { + adv_mode(hDlg, psi->idd, psi->config); }else if (HIWORD(wParam) == LBN_SELCHANGE && (LOWORD(wParam) == IDC_PROFILE_PROFILE || LOWORD(wParam) == IDC_LEVEL_PROFILE || LOWORD(wParam) == IDC_QUANTTYPE || - LOWORD(wParam) == IDC_ASPECT_RATIO)) - { + LOWORD(wParam) == IDC_ASPECT_RATIO || + LOWORD(wParam) == IDC_BITRATE_CFORMAT || + LOWORD(wParam) == IDC_BITRATE_AFORMAT || + LOWORD(wParam) == IDC_BITRATE_FPS)) { adv_mode(hDlg, psi->idd, psi->config); }else if (HIWORD(wParam) == EN_UPDATE && (LOWORD(wParam)==IDC_ZONE_WEIGHT || LOWORD(wParam)==IDC_ZONE_QUANT)) { SendDlgItemMessage(hDlg, IDC_ZONE_SLIDER, TBM_SETPOS, TRUE, get_dlgitem_float(hDlg, LOWORD(wParam), 100)); + } else if (HIWORD(wParam) == EN_UPDATE && (LOWORD(wParam)==IDC_PARX || LOWORD(wParam)==IDC_PARY)) { + if (5 == SendDlgItemMessage(hDlg, IDC_ASPECT_RATIO, CB_GETCURSEL, 0, 0)) { if(LOWORD(wParam)==IDC_PARX) psi->config->par_x = config_get_uint(hDlg, LOWORD(wParam), psi->config->par_x); else psi->config->par_y = config_get_uint(hDlg, LOWORD(wParam), psi->config->par_y); } + } else if (HIWORD(wParam) == EN_UPDATE && + (LOWORD(wParam)==IDC_BITRATE_SSIZE || + LOWORD(wParam)==IDC_BITRATE_HOURS || + LOWORD(wParam)==IDC_BITRATE_MINUTES || + LOWORD(wParam)==IDC_BITRATE_SECONDS || + LOWORD(wParam)==IDC_BITRATE_ASIZE)) { + adv_mode(hDlg, psi->idd, psi->config); } else return 0; break; @@ -1264,7 +1557,7 @@ or fasle if changes were canceled. */ -BOOL adv_dialog(HWND hParent, CONFIG * config, const int * dlgs, int size) +static BOOL adv_dialog(HWND hParent, CONFIG * config, const int * dlgs, int size) { PROPSHEETINFO psi[6]; PROPSHEETPAGE psp[6]; @@ -1290,7 +1583,7 @@ } psh.dwSize = sizeof(PROPSHEETHEADER); - psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW; + psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP; psh.hwndParent = hParent; psh.hInstance = g_hInst; psh.pszCaption = (LPSTR) "XviD Configuration"; @@ -1311,7 +1604,7 @@ /* ===================================================================================== */ -void main_insert_zone(HWND hDlg, zone_t * s, int i, BOOL insert) +static void main_insert_zone(HWND hDlg, zone_t * s, int i, BOOL insert) { char tmp[32]; @@ -1355,19 +1648,20 @@ ListView_SetItemText(hDlg, i, 2, tmp); } -static int g_use_bitrate = 1; -void main_mode(HWND hDlg, CONFIG * config) +static 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; + const int target_en_slider = rc_mode==RC_MODE_1PASS || + (rc_mode==RC_MODE_2PASS2 && config->use_2pass_bitrate); char buf[16]; int max; - g_use_bitrate = rc_mode==RC_MODE_1PASS || config->use_2pass_bitrate; + g_use_bitrate = config->use_2pass_bitrate; if (g_use_bitrate) { SetDlgItemText(hDlg, IDC_BITRATE_S, "Target bitrate (kbps):"); @@ -1384,45 +1678,60 @@ SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) ); - }else{ + } else if (rc_mode==RC_MODE_2PASS2) { SetDlgItemText(hDlg, IDC_BITRATE_S, "Target size (kbytes):"); + } else if (rc_mode==RC_MODE_1PASS) { + SetDlgItemText(hDlg, IDC_BITRATE_S, "Target quantizer:"); + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETRANGE, TRUE, MAKELONG(100, 3100)); + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, + get_dlgitem_float(hDlg, IDC_BITRATE, DEFAULT_QUANT )); + SetDlgItemText(hDlg, IDC_BITRATE_MIN, "1 (maximum quality)"); + SetDlgItemText(hDlg, IDC_BITRATE_MAX, "(smallest file) 31"); + } EnableDlgWindow(hDlg, IDC_BITRATE_S, target_en); EnableDlgWindow(hDlg, IDC_BITRATE, target_en); + EnableDlgWindow(hDlg, IDC_BITRATE_ADV, 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); + EnableDlgWindow(hDlg, IDC_BITRATE_MIN, target_en_slider); + EnableDlgWindow(hDlg, IDC_BITRATE_MAX, target_en_slider); + EnableDlgWindow(hDlg, IDC_SLIDER, target_en_slider); } - -void main_upload(HWND hDlg, CONFIG * config) +static void main_upload(HWND hDlg, CONFIG * config) { SendDlgItemMessage(hDlg, IDC_PROFILE, CB_SETCURSEL, config->profile, 0); SendDlgItemMessage(hDlg, IDC_MODE, CB_SETCURSEL, config->mode, 0); + g_use_bitrate = config->use_2pass_bitrate; + if (g_use_bitrate) { SetDlgItemInt(hDlg, IDC_BITRATE, config->bitrate, FALSE); - }else{ + } else if (config->mode == RC_MODE_2PASS2) { SetDlgItemInt(hDlg, IDC_BITRATE, config->desired_size, FALSE); + } else if (config->mode == RC_MODE_1PASS) { + set_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant); } - zones_update(hDlg, config);} + zones_update(hDlg, config); +} /* downloads data from main dialog */ -void main_download(HWND hDlg, CONFIG * config) +static void main_download(HWND hDlg, CONFIG * config) { config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0); config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0); if (g_use_bitrate) { config->bitrate = config_get_uint(hDlg, IDC_BITRATE, config->bitrate); - }else{ + } else if (config->mode == RC_MODE_2PASS2) { config->desired_size = config_get_uint(hDlg, IDC_BITRATE, config->desired_size); + } else if (config->mode == RC_MODE_1PASS) { + config->desired_quant = get_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant); } } @@ -1433,6 +1742,7 @@ static const int single_dlgs[] = { IDD_RC_CBR }; static const int pass1_dlgs[] = { IDD_RC_2PASS1 }; static const int pass2_dlgs[] = { IDD_RC_2PASS2 }; +static const int bitrate_dlgs[] = { IDD_BITRATE }; static const int zone_dlgs[] = { IDD_ZONE }; static const int decoder_dlgs[] = { IDD_DEC }; static const int adv_dlgs[] = { IDD_MOTION, IDD_QUANT, IDD_DEBUG}; @@ -1558,7 +1868,6 @@ } break; - case IDC_BITRATE_S : /* alternate between bitrate/desired_length metrics */ main_download(hDlg, config); @@ -1567,6 +1876,13 @@ main_upload(hDlg, config); break; + case IDC_BITRATE_ADV : + main_download(hDlg, config); + adv_dialog(hDlg, config, bitrate_dlgs, sizeof(bitrate_dlgs)/sizeof(int)); + main_mode(hDlg, config); + main_upload(hDlg, config); + break; + case IDC_DECODER : main_download(hDlg, config); adv_dialog(hDlg, config, decoder_dlgs, sizeof(decoder_dlgs)/sizeof(int)); @@ -1650,6 +1966,7 @@ case IDC_DEFAULTS : config_reg_default(config); + main_mode(hDlg, config); main_upload(hDlg, config); break; @@ -1664,10 +1981,19 @@ EndDialog(hDlg, IDCANCEL); break; } - }else if (HIWORD(wParam) == LBN_SELCHANGE && + } else if (HIWORD(wParam) == LBN_SELCHANGE && (LOWORD(wParam)==IDC_PROFILE || LOWORD(wParam)==IDC_MODE)) { - main_download(hDlg, config); + config->mode = SendDlgItemMessage(hDlg, IDC_MODE, CB_GETCURSEL, 0, 0); + config->profile = SendDlgItemMessage(hDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0); + + if (!g_use_bitrate) { + if (config->mode == RC_MODE_1PASS) + set_dlgitem_float(hDlg, IDC_BITRATE, config->desired_quant); + else if (config->mode == RC_MODE_2PASS2) + SetDlgItemInt(hDlg, IDC_BITRATE, config->desired_size, FALSE); + } + main_mode(hDlg, config); main_upload(hDlg, config); @@ -1676,7 +2002,11 @@ if (g_use_bitrate) { SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, config_get_uint(hDlg, IDC_BITRATE, DEFAULT_MIN_KBPS) ); + } else if (config->mode == RC_MODE_1PASS) { + SendDlgItemMessage(hDlg, IDC_SLIDER, TBM_SETPOS, TRUE, + get_dlgitem_float(hDlg, IDC_BITRATE, DEFAULT_QUANT) ); } + main_download(hDlg, config); }else { return 0; @@ -1685,7 +2015,12 @@ case WM_HSCROLL : if((HWND)lParam == GetDlgItem(hDlg, IDC_SLIDER)) { - SetDlgItemInt(hDlg, IDC_BITRATE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0), FALSE); + if (g_use_bitrate) + SetDlgItemInt(hDlg, IDC_BITRATE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0), FALSE); + else + set_dlgitem_float(hDlg, IDC_BITRATE, SendMessage((HWND)lParam, TBM_GETPOS, 0, 0)); + + main_download(hDlg, config); break; } return 0; @@ -1782,7 +2117,8 @@ return 1; } -static void + +void sort_zones(zone_t * zones, int zone_num, int * sel) { int i, j; @@ -1826,4 +2162,4 @@ config->cur_zone = sel; ListView_SetItemState(GetDlgItem(hDlg, IDC_ZONES), sel, 0xffffffff, LVIS_SELECTED); -} \ No newline at end of file +}