diff --git a/ChangeLog b/ChangeLog index 36b9c631c..23d0b639b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-03-09 Moritz Bunkus + + * mkvmerge/mmg: new feature: Made the process priority selectable + and default to 'normal' again (was 'lower' before). + 2004-03-07 Moritz Bunkus * mmg: new feature: mmg will ask for confirmation before diff --git a/doc/mkvmerge.1 b/doc/mkvmerge.1 index 6a06b6e33..03d5d14e3 100644 --- a/doc/mkvmerge.1 +++ b/doc/mkvmerge.1 @@ -355,7 +355,7 @@ The default is 'zlib' compression. Other options: .TP \fB\-i\fR, \fB\-\-identify\fR <\fIfilename\fR> -Will let mkvmerge probe the single file and report its type, the tracks +Will let \fBmkvmerge\fR probe the single file and report its type, the tracks contained in the file and their track IDs. If this option is used then the only other option allowed is the filename. .TP @@ -366,6 +366,13 @@ Lists supported input file types. Lists all languages and their ISO639-2 code which can be used with the \fB\-\-language\fR option. .TP +\fB\-\-priority\fR <\fIpriority\fR> +Sets the process priority that \fBmkvmerge\fR runs with. Valid values are +"lowest", "lower", "normal", "higher" and "highest". If nothing is given then +"normal" is used. On Unix like systems \fBmkvmerge\fR will use the nice(2) +function. Therefore only the super user can use "higher" and "highest". On +Windows all values are useable for every user. +.TP \fB\-h\fR, \fB\-\-help\fR Show usage information. .TP diff --git a/src/mkvmerge.cpp b/src/mkvmerge.cpp index bf05e12f9..7ecf27cae 100644 --- a/src/mkvmerge.cpp +++ b/src/mkvmerge.cpp @@ -334,6 +334,7 @@ usage() { " -l, --list-types Lists supported input file types.\n" " --list-languages Lists all ISO639 languages and their\n" " ISO639-2 codes.\n" + " --priority Set the priority mkvmerge runs with.\n" " -h, --help Show this help.\n" " -V, --version Show version information.\n" " @optionsfile Reads additional command line options from\n" @@ -1408,6 +1409,60 @@ identify(const char *filename) { file->reader->identify(); } +/** \brief Sets the priority mkvmerge runs with + * + * Depending on the OS different functions are used. On Unix like systems + * the process is being nice'd if priority is negative ( = less important). + * Only the super user can increase the priority, but you shouldn't do + * such work as root anyway. + * On Windows SetPriorityClass is used. + */ +static void +set_process_priority(int priority) { +#if defined(SYS_WINDOWS) + switch (priority) { + case -2: + SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE); + break; + case -1: + SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS); + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL); + break; + case 0: + SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); + break; + case 1: + SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); + break; + case 2: + SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); + break; + } +#else + switch (priority) { + case -2: + nice(19); + break; + case -1: + nice(2); + break; + case 0: + nice(0); + break; + case 1: + nice(-2); + break; + case 2: + nice(-5); + break; + } +#endif +} + /** \brief Parses and handles command line arguments * * Also probes input files for their type and creates the appropriate @@ -1424,6 +1479,8 @@ identify(const char *filename) { static void parse_args(int argc, char **argv) { + const char *process_priorities[5] = {"lowest", "lower", "normal", "higher", + "highest"}; track_info_c *ti; int i, j; filelist_t *file; @@ -1544,6 +1601,22 @@ parse_args(int argc, engage_hacks(next_arg); i++; + } else if (!strcmp(this_arg, "--priority")) { + bool found; + + if (next_arg == NULL) + mxerror("'--priority' lacks its argument.\n"); + found = false; + for (j = 0; j < 5; j++) + if (!strcmp(next_arg, process_priorities[j])) { + set_process_priority(j - 2); + found = true; + break; + } + if (!found) + mxerror("'%s' is not a valid priority class.\n", next_arg); + i++; + } else if (!strcmp(this_arg, "-q")) verbose = 0; @@ -2123,7 +2196,7 @@ handle_args(int argc, * * Both platform dependant and independant initialization is done here. * For Unix like systems a signal handler is installed. The locale's - * \c LC_CTYPE is set and the process priority is decreased. + * \c LC_CTYPE is set. */ static void setup() { @@ -2136,12 +2209,6 @@ setup() { #if defined(SYS_UNIX) || defined(COMP_CYGWIN) || defined(SYS_APPLE) signal(SIGUSR1, sighandler); signal(SIGINT, sighandler); - - nice(2); -#endif -#if defined(SYS_WINDOWS) - SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS); - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL); #endif srand(time(NULL)); diff --git a/src/mmg/mmg.cpp b/src/mmg/mmg.cpp index 8bb7b4137..cd5241464 100644 --- a/src/mmg/mmg.cpp +++ b/src/mmg/mmg.cpp @@ -851,6 +851,11 @@ mmg_dialog::update_command_line() { clargs.Add(tc_output->GetValue()); args_start = clargs.Count(); + if (settings_page->cob_priority->GetValue() != wxS("normal")) { + clargs.Add("--priority"); + clargs.Add(settings_page->cob_priority->GetValue()); + } + for (fidx = 0; fidx < files.size(); fidx++) { f = &files[fidx]; tracks_selected_here = false; diff --git a/src/mmg/tab_settings.cpp b/src/mmg/tab_settings.cpp index 07617337a..69538839b 100644 --- a/src/mmg/tab_settings.cpp +++ b/src/mmg/tab_settings.cpp @@ -35,7 +35,7 @@ tab_settings::tab_settings(wxWindow *parent): wxPanel(parent, -1, wxDefaultPosition, wxSize(100, 400), wxTAB_TRAVERSAL) { - new wxStaticBox(this, -1, wxS("mkvmrge executable"), wxPoint(10, 5), + new wxStaticBox(this, -1, wxS("mkvmerge executable"), wxPoint(10, 5), wxSize(475, 50)); tc_mkvmerge = new wxTextCtrl(this, ID_TC_MKVMERGE, wxS(""), wxPoint(15, 25), @@ -44,6 +44,23 @@ tab_settings::tab_settings(wxWindow *parent): new wxButton(this, ID_B_BROWSEMKVMERGE, wxS("Browse"), wxPoint(395, 25), wxDefaultSize, 0); + new wxStaticBox(this, -1, wxS("Miscellaneous options"), wxPoint(10, 65), + wxSize(475, 50)); + new wxStaticText(this, -1, wxS("Process priority:"), wxPoint(15, 85)); + cob_priority = + new wxComboBox(this, ID_COB_PRIORITY, wxS(""), wxPoint(120, 85 + YOFF), + wxSize(90, -1), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY); + cob_priority->SetToolTip(wxS("Sets the priority that mkvmerge will run " + "with.")); +#if defined(SYS_WINDOWS) + cob_priority->Append(wxS("highest")); + cob_priority->Append(wxS("higher")); +#endif + cob_priority->Append(wxS("normal")); + cob_priority->Append(wxS("lower")); + cob_priority->Append(wxS("lowest")); + + new wxStaticBox(this, -1, wxS("About"), wxPoint(10, 350), wxSize(475, 104)); new wxStaticBitmap(this, -1, wxBitmap(matroskalogo_big_xpm), @@ -61,6 +78,7 @@ tab_settings::tab_settings(wxWindow *parent): } tab_settings::~tab_settings() { + save_preferences(); } void @@ -81,21 +99,39 @@ tab_settings::on_browse(wxCommandEvent &evt) { } } +void +tab_settings::on_priority_selected(wxCommandEvent &evt) { + save_preferences(); +} + void tab_settings::load_preferences() { wxConfig *cfg = (wxConfig *)wxConfigBase::Get(); + wxString priority; + int i; cfg->SetPath(wxS("/GUI")); if (!cfg->Read(wxS("mkvmerge_executable"), &mkvmerge_path)) mkvmerge_path = wxS("mkvmerge"); tc_mkvmerge->SetValue(mkvmerge_path); query_mkvmerge_capabilities(); + + if (!cfg->Read(wxS("process_priority"), &priority)) + priority = wxS("normal"); + cob_priority->SetSelection(0); + for (i = 0; i < cob_priority->GetCount(); i++) + if (priority == cob_priority->GetString(i)) { + cob_priority->SetSelection(i); + break; + } } void tab_settings::save_preferences() { wxConfig *cfg = (wxConfig *)wxConfigBase::Get(); - cfg->Write(wxS("/GUI/mkvmerge_executable"), tc_mkvmerge->GetValue()); + cfg->SetPath(wxS("/GUI")); + cfg->Write(wxS("mkvmerge_executable"), tc_mkvmerge->GetValue()); + cfg->Write(wxS("process_priority"), cob_priority->GetValue()); cfg->Flush(); } @@ -138,4 +174,5 @@ tab_settings::query_mkvmerge_capabilities() { IMPLEMENT_CLASS(tab_settings, wxPanel); BEGIN_EVENT_TABLE(tab_settings, wxPanel) EVT_BUTTON(ID_B_BROWSEMKVMERGE, tab_settings::on_browse) + EVT_COMBOBOX(ID_COB_PRIORITY, tab_settings::on_priority_selected) END_EVENT_TABLE(); diff --git a/src/mmg/tab_settings.h b/src/mmg/tab_settings.h index 34b2c72cf..3e5780a2b 100644 --- a/src/mmg/tab_settings.h +++ b/src/mmg/tab_settings.h @@ -24,19 +24,22 @@ #define ID_TC_MKVMERGE 15000 #define ID_B_BROWSEMKVMERGE 15001 +#define ID_COB_PRIORITY 15002 class tab_settings: public wxPanel { DECLARE_CLASS(tab_settings); DECLARE_EVENT_TABLE(); -protected: +public: wxTextCtrl *tc_mkvmerge; wxCheckBox *cb_show_commandline; + wxComboBox *cob_priority; public: tab_settings(wxWindow *parent); virtual ~tab_settings(); void on_browse(wxCommandEvent &evt); + void on_priority_selected(wxCommandEvent &evt); void load_preferences(); void save_preferences();