summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-19 19:54:54 +0200
committerwm4 <wm4@nowhere>2016-09-19 19:54:54 +0200
commitb62634c051e5657d60394a10d7ae8a8707f3bcc7 (patch)
tree8d8bbb946d3fdcbcc307fa5e1660e657475ee895
parent75fe626aa60a4175c5b833ab8afe271120d88106 (diff)
downloadmpv-b62634c051e5657d60394a10d7ae8a8707f3bcc7.tar.bz2
mpv-b62634c051e5657d60394a10d7ae8a8707f3bcc7.tar.xz
player: make --terminal freetly settable at runtime
So client API users don't have to care about whether to set this before or after mpv_initialize(). We still don't enable terminal at any point before mpv_initialize(), because reasons. This also subtly changes some behavior how terminal options are applied while parsing. This essentially reverts the behavior as it was reported in issue #2588. Originally, I was hoping to get rid of the pre-parse option pass, but it seems this is absolutely not possible due to the way config and command line parsing are entangled. Command line options take priority over configfile options, so they have to be applied later - but we also want to apply logging and terminal options as specified on the command-line, but _before_ parsing the config files. It has to be this way to see config file error messages on the terminal, or to hide them if --no-terminal is used. libmpv considerations also factor into this.
-rw-r--r--options/options.c4
-rw-r--r--osdep/terminal-unix.c4
-rw-r--r--osdep/terminal-win.c3
-rw-r--r--player/command.c2
-rw-r--r--player/core.h1
-rw-r--r--player/main.c49
6 files changed, 35 insertions, 28 deletions
diff --git a/options/options.c b/options/options.c
index 88af4a1d8b..5c1cf59919 100644
--- a/options/options.c
+++ b/options/options.c
@@ -256,7 +256,7 @@ const m_option_t mp_opts[] = {
OPT_FLAG("quiet", quiet, 0),
OPT_FLAG_STORE("really-quiet", verbose,
CONF_GLOBAL | CONF_PRE_PARSE | M_OPT_NOPROP, -10),
- OPT_FLAG("terminal", use_terminal, CONF_GLOBAL | CONF_PRE_PARSE | UPDATE_TERM),
+ OPT_FLAG("terminal", use_terminal, CONF_PRE_PARSE | UPDATE_TERM),
OPT_GENERAL(char**, "msg-level", msg_levels, CONF_PRE_PARSE | UPDATE_TERM,
.type = &m_option_type_msglevels),
OPT_STRING("dump-stats", dump_stats, UPDATE_TERM | CONF_PRE_PARSE),
@@ -650,7 +650,7 @@ const m_option_t mp_opts[] = {
{"once", 1},
{"yes", 2})),
- OPT_FLAG("input-terminal", consolecontrols, CONF_GLOBAL),
+ OPT_FLAG("input-terminal", consolecontrols, UPDATE_TERM),
OPT_STRING("input-file", input_file, M_OPT_FILE),
OPT_STRING("input-ipc-server", ipc_path, M_OPT_FILE | M_OPT_FIXED),
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c
index 64d6df3f37..9b4e5709cc 100644
--- a/osdep/terminal-unix.c
+++ b/osdep/terminal-unix.c
@@ -410,11 +410,9 @@ static void *terminal_thread(void *ptr)
void terminal_setup_getch(struct input_ctx *ictx)
{
- if (!getch2_enabled)
+ if (!getch2_enabled || input_ctx)
return;
- assert(!input_ctx); // already setup
-
if (mp_make_wakeup_pipe(death_pipe) < 0)
return;
diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c
index cda9e69040..c04a13a639 100644
--- a/osdep/terminal-win.c
+++ b/osdep/terminal-win.c
@@ -136,7 +136,8 @@ static void *input_thread_fn(void *ptr)
void terminal_setup_getch(struct input_ctx *ictx)
{
- assert(!running);
+ if (running)
+ return;
HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
if (GetNumberOfConsoleInputEvents(in, &(DWORD){0})) {
diff --git a/player/command.c b/player/command.c
index a4a4263dde..bd7380cbec 100644
--- a/player/command.c
+++ b/player/command.c
@@ -5631,7 +5631,7 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags)
struct MPContext *mpctx = ctx;
if (flags & UPDATE_TERM)
- mp_msg_update_msglevels(mpctx->global);
+ mp_update_logging(mpctx);
if (flags & UPDATE_RENDERER) {
if (mpctx->video_out)
diff --git a/player/core.h b/player/core.h
index 22e19e49ef..c36972e807 100644
--- a/player/core.h
+++ b/player/core.h
@@ -487,6 +487,7 @@ struct MPContext *mp_create(void);
void mp_destroy(struct MPContext *mpctx);
void mp_print_version(struct mp_log *log, int always);
void wakeup_playloop(void *ctx);
+void mp_update_logging(struct MPContext *mpctx);
// misc.c
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t);
diff --git a/player/main.c b/player/main.c
index 334224d6a6..afdb6d1e5a 100644
--- a/player/main.c
+++ b/player/main.c
@@ -116,11 +116,23 @@ static bool cas_terminal_owner(struct MPContext *old, struct MPContext *new)
return r;
}
-static void update_logging(struct MPContext *mpctx)
+void mp_update_logging(struct MPContext *mpctx)
{
mp_msg_update_msglevels(mpctx->global);
- if (mpctx->opts->use_terminal && cas_terminal_owner(NULL, mpctx))
- terminal_init();
+
+ bool enable = mpctx->opts->use_terminal;
+ bool enabled = cas_terminal_owner(mpctx, mpctx);
+ if (enable != enabled) {
+ if (enable && cas_terminal_owner(NULL, mpctx)) {
+ terminal_init();
+ } else if (!enable) {
+ terminal_uninit();
+ cas_terminal_owner(mpctx, NULL);
+ }
+ }
+
+ if (cas_terminal_owner(mpctx, mpctx) && mpctx->opts->consolecontrols)
+ terminal_setup_getch(mpctx->input);
}
void mp_print_version(struct mp_log *log, int always)
@@ -356,12 +368,6 @@ struct MPContext *mp_create(void)
mp_input_set_cancel(mpctx->input, mpctx->playback_abort);
- mpctx->mconfig->option_set_callback = mp_on_set_option;
- mpctx->mconfig->option_set_callback_cb = mpctx;
-
- mpctx->mconfig->option_change_callback = mp_option_change_callback;
- mpctx->mconfig->option_change_callback_ctx = mpctx;
-
return mpctx;
}
@@ -376,32 +382,39 @@ int mp_initialize(struct MPContext *mpctx, char **options)
assert(!mpctx->initialized);
- if (options) {
- // Preparse the command line, so we can init the terminal early.
+ // Preparse the command line, so we can init the terminal early.
+ if (options)
m_config_preparse_command_line(mpctx->mconfig, mpctx->global, options);
- update_logging(mpctx);
+ mp_update_logging(mpctx);
+ if (options) {
MP_VERBOSE(mpctx, "Command line options:");
for (int i = 0; options[i]; i++)
MP_VERBOSE(mpctx, " '%s'", options[i]);
MP_VERBOSE(mpctx, "\n");
}
- update_logging(mpctx);
mp_print_version(mpctx->log, false);
mp_parse_cfgfiles(mpctx);
- update_logging(mpctx);
if (options) {
int r = m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist,
mpctx->global, options);
if (r < 0)
return r == M_OPT_EXIT ? -2 : -1;
- update_logging(mpctx);
}
+ // From this point on, all mpctx members are initialized.
+ mpctx->initialized = true;
+ mpctx->mconfig->option_set_callback = mp_on_set_option;
+ mpctx->mconfig->option_set_callback_cb = mpctx;
+ mpctx->mconfig->option_change_callback = mp_option_change_callback;
+ mpctx->mconfig->option_change_callback_ctx = mpctx;
+ // Run all update handlers.
+ mp_option_change_callback(mpctx, NULL, UPDATE_OPTS_MASK);
+
if (handle_help_options(mpctx))
return -2;
@@ -448,18 +461,12 @@ int mp_initialize(struct MPContext *mpctx, char **options)
MP_WARN(mpctx, "There will be no OSD and no text subtitles.\n");
#endif
- // From this point on, all mpctx members are initialized.
- mpctx->initialized = true;
-
mp_get_resume_defaults(mpctx);
// Lua user scripts (etc.) can call arbitrary functions. Load them at a point
// where this is safe.
mp_load_scripts(mpctx);
- if (opts->consolecontrols && cas_terminal_owner(mpctx, mpctx))
- terminal_setup_getch(mpctx->input);
-
if (opts->force_vo == 2 && handle_force_window(mpctx, false) < 0)
return -1;