mirror of
https://github.com/mpv-player/mpv
synced 2024-12-25 08:12:17 +00:00
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().)
This commit is contained in:
parent
f00edfd9c5
commit
3ad03f6673
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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},
|
||||
|
@ -351,6 +351,7 @@ struct MPContext *mp_create(void)
|
||||
mpctx->mconfig->includefunc_ctx = mpctx;
|
||||
mpctx->mconfig->use_profiles = true;
|
||||
mpctx->mconfig->is_toplevel = true;
|
||||
mpctx->mconfig->global = mpctx->global;
|
||||
m_config_parse(mpctx->mconfig, "", bstr0(def_config), NULL, 0);
|
||||
|
||||
mpctx->global->opts = mpctx->opts;
|
||||
|
Loading…
Reference in New Issue
Block a user