From 3ad03f6673b3b1e56020994f90c8cde9f8932b6c Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 4 Nov 2015 15:44:37 +0100 Subject: options: handle terminal/logging settings eagerly Update msg.c state immediately if a terminal or logging setting is set. Until now, this was delayed until mp[v]_initialize() was called. When using the client API, you could easily miss logged error messages, even when logging was initialized early on by calling mpv_request_log_messages(). (Properties can't be used for this either, because properties do not work before mpv_initialize().) --- options/m_config.c | 31 ++++++++++++++++++------------- options/m_config.h | 1 + options/m_option.h | 3 +++ options/options.c | 12 ++++++------ 4 files changed, 28 insertions(+), 19 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 030c144dfc..c39f3ab41a 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -35,6 +35,7 @@ #include "m_config.h" #include "options/m_option.h" #include "common/msg.h" +#include "common/msg_control.h" static const union m_option_value default_value; @@ -557,18 +558,23 @@ static int handle_set_opt_flags(struct m_config *config, return set ? 2 : 1; } -static void handle_set_from_cmdline(struct m_config *config, - struct m_config_option *co) +static void handle_on_set(struct m_config *config, struct m_config_option *co, + int flags) { - co->is_set_from_cmdline = true; - // Mark aliases too - if (co->data) { - for (int n = 0; n < config->num_opts; n++) { - struct m_config_option *co2 = &config->opts[n]; - if (co2->data == co->data) - co2->is_set_from_cmdline = true; + if (flags & M_SETOPT_FROM_CMDLINE) { + co->is_set_from_cmdline = true; + // Mark aliases too + if (co->data) { + for (int n = 0; n < config->num_opts; n++) { + struct m_config_option *co2 = &config->opts[n]; + if (co2->data == co->data) + co2->is_set_from_cmdline = true; + } } } + + if (config->global && (co->opt->flags & M_OPT_TERM)) + mp_msg_update_msglevels(config->global); } // The type data points to is as in: m_config_get_co(config, name)->opt @@ -588,8 +594,7 @@ int m_config_set_option_raw(struct m_config *config, struct m_config_option *co, return r; m_option_copy(co->opt, co->data, data); - if (flags & M_SETOPT_FROM_CMDLINE) - handle_set_from_cmdline(config, co); + handle_on_set(config, co, flags); return 0; } @@ -637,8 +642,8 @@ static int m_config_parse_option(struct m_config *config, struct bstr name, r = m_option_parse(config->log, co->opt, name, param, set ? co->data : NULL); - if (r >= 0 && set && (flags & M_SETOPT_FROM_CMDLINE)) - handle_set_from_cmdline(config, co); + if (r >= 0 && set) + handle_on_set(config, co, flags); return r; } diff --git a/options/m_config.h b/options/m_config.h index 89f620b6d3..ed34389921 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -51,6 +51,7 @@ struct m_config_option { /** \ingroup Config */ typedef struct m_config { struct mp_log *log; + struct mpv_global *global; // can be NULL // Registered options. struct m_config_option *opts; // all options, even suboptions diff --git a/options/m_option.h b/options/m_option.h index 17756885d9..320a9e5b99 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -363,6 +363,9 @@ struct m_option { // The option expects a file name (or a list of file names) #define M_OPT_FILE (1 << 11) +// Logging-related option - used to update log/terminal settings eagerly +#define M_OPT_TERM (1 << 12) + // These are kept for compatibility with older code. #define CONF_MIN M_OPT_MIN #define CONF_MAX M_OPT_MAX diff --git a/options/options.c b/options/options.c index 45c1b0e277..21ed2f4415 100644 --- a/options/options.c +++ b/options/options.c @@ -113,14 +113,14 @@ const m_option_t mp_opts[] = { // ------------------------- common options -------------------- OPT_FLAG("quiet", quiet, CONF_GLOBAL), OPT_FLAG_STORE("really-quiet", verbose, CONF_GLOBAL | CONF_PRE_PARSE, -10), - OPT_FLAG("terminal", use_terminal, CONF_GLOBAL | CONF_PRE_PARSE), - OPT_GENERAL(char**, "msg-level", msg_levels, CONF_GLOBAL|CONF_PRE_PARSE, - .type = &m_option_type_msglevels), + OPT_FLAG("terminal", use_terminal, CONF_GLOBAL | CONF_PRE_PARSE | M_OPT_TERM), + OPT_GENERAL(char**, "msg-level", msg_levels, CONF_GLOBAL|CONF_PRE_PARSE | + M_OPT_TERM, .type = &m_option_type_msglevels), OPT_STRING("dump-stats", dump_stats, CONF_GLOBAL | CONF_PRE_PARSE), - OPT_FLAG("msg-color", msg_color, CONF_GLOBAL | CONF_PRE_PARSE), + OPT_FLAG("msg-color", msg_color, CONF_GLOBAL | CONF_PRE_PARSE | M_OPT_TERM), OPT_STRING("log-file", log_file, CONF_GLOBAL | CONF_PRE_PARSE | M_OPT_FILE), - OPT_FLAG("msg-module", msg_module, CONF_GLOBAL), - OPT_FLAG("msg-time", msg_time, CONF_GLOBAL), + OPT_FLAG("msg-module", msg_module, CONF_GLOBAL | M_OPT_TERM), + OPT_FLAG("msg-time", msg_time, CONF_GLOBAL | M_OPT_TERM), #ifdef _WIN32 OPT_CHOICE("priority", w32_priority, 0, ({"no", 0}, -- cgit v1.2.3