From fe7db610355b623305d08135869b3f4ff4487b6d Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 19 Sep 2016 19:51:26 +0200 Subject: [PATCH] options: slightly better option update mechanism Extend the flag-based notification mechanism that was used via M_OPT_TERM. Make the vo_opengl update mechanism use this (which, btw., also fixes compilation with OpenGL renderers forcibly disabled). While this adds a 3rd mechanism and just seems to further the chaos, I'd rather have a very simple mechanism now, than actually furthering the mess by mixing old and new update mechanisms. In particular, we'll be able to remove quite some property implementations, and replace them with much simpler update handling. The new update mechanism can also more easily refactored once we have a final mechanism that handles everything in an uniform way. --- options/m_config.c | 26 ++++++++++++++++++-------- options/m_config.h | 7 +++++++ options/m_option.h | 17 ++++++++++++++--- options/options.c | 14 +++++++------- player/command.c | 21 ++++++++++++--------- player/command.h | 1 + player/main.c | 3 +++ video/out/opengl/video.c | 1 + 8 files changed, 63 insertions(+), 27 deletions(-) diff --git a/options/m_config.c b/options/m_config.c index 6dd72380d9..4659c9aa21 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -418,6 +418,9 @@ static void add_sub_options(struct m_config *config, for (int n = 0; n < config->num_groups; n++) assert(config->groups[n].group != subopts); + // You can only use UPDATE_ flags here. + assert(!(subopts->change_flags & ~(unsigned)UPDATE_OPTS_MASK)); + void *new_optstruct = NULL; if (config->optstruct) { // only if not noalloc new_optstruct = talloc_zero_size(config, subopts->size); @@ -1255,16 +1258,23 @@ void m_config_notify_change_co(struct m_config *config, if (co->shadow_offset >= 0) m_option_copy(co->opt, shadow->data + co->shadow_offset, co->data); pthread_mutex_unlock(&shadow->lock); - - int group = co->group; - while (group >= 0) { - atomic_fetch_add(&config->groups[group].ts, 1); - group = config->groups[group].parent_group; - } } - if (config->global && (co->opt->flags & M_OPT_TERM)) - mp_msg_update_msglevels(config->global); + int changed = co->opt->flags & UPDATE_OPTS_MASK; + + int group = co->group; + while (group >= 0) { + struct m_config_group *g = &config->groups[group]; + atomic_fetch_add(&g->ts, 1); + if (g->group) + changed |= g->group->change_flags; + group = g->parent_group; + } + + if (config->option_change_callback) { + config->option_change_callback(config->option_change_callback_ctx, co, + changed); + } } bool m_config_is_in_group(struct m_config *config, diff --git a/options/m_config.h b/options/m_config.h index 8befc51805..74390f150b 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -77,10 +77,17 @@ typedef struct m_config { int (*includefunc)(void *ctx, char *filename, int flags); void *includefunc_ctx; + // Can intercept option write accesses. int (*option_set_callback)(void *ctx, struct m_config_option *co, void *data, int flags); void *option_set_callback_cb; + // Notification after an option was successfully written to. + // Uses flags as set in UPDATE_OPTS_MASK. + void (*option_change_callback)(void *ctx, struct m_config_option *co, + int flags); + void *option_change_callback_ctx; + // For the command line parser int recursion_depth; diff --git a/options/m_option.h b/options/m_option.h index 6435584716..a47bbaa7d7 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -191,6 +191,9 @@ struct m_sub_options { const struct m_option *opts; size_t size; const void *defaults; + // Change flags passed to mp_option_change_callback() if any option that is + // directly or indirectly part of this group is changed. + int change_flags; }; #define CONF_TYPE_FLAG (&m_option_type_flag) @@ -372,12 +375,20 @@ 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) - // Do not add as property. #define M_OPT_NOPROP (1 << 13) +// The following are also part of the M_OPT_* flags, and are used to update +// certain groups of options. +#define UPDATE_OPT_FIRST (1 << 14) +#define UPDATE_TERM (1 << 14) // terminal options +#define UPDATE_RENDERER (1 << 15) // mainly vo_opengl options +#define UPDATE_OPT_LAST (1 << 15) + +// All bits between _FIRST and _LAST (inclusive) +#define UPDATE_OPTS_MASK \ + (((UPDATE_OPT_LAST << 1) - 1) & ~(unsigned)(UPDATE_OPT_FIRST - 1)) + // 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 631d108119..88af4a1d8b 100644 --- a/options/options.c +++ b/options/options.c @@ -256,14 +256,14 @@ 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 | M_OPT_TERM), - OPT_GENERAL(char**, "msg-level", msg_levels, CONF_PRE_PARSE | M_OPT_TERM, + OPT_FLAG("terminal", use_terminal, CONF_GLOBAL | 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, CONF_GLOBAL | CONF_PRE_PARSE), - OPT_FLAG("msg-color", msg_color, CONF_PRE_PARSE | M_OPT_TERM), - OPT_STRING("log-file", log_file, CONF_PRE_PARSE | M_OPT_FILE), - OPT_FLAG("msg-module", msg_module, M_OPT_TERM), - OPT_FLAG("msg-time", msg_time, M_OPT_TERM), + OPT_STRING("dump-stats", dump_stats, UPDATE_TERM | CONF_PRE_PARSE), + OPT_FLAG("msg-color", msg_color, CONF_PRE_PARSE | UPDATE_TERM), + OPT_STRING("log-file", log_file, CONF_PRE_PARSE | M_OPT_FILE | UPDATE_TERM), + OPT_FLAG("msg-module", msg_module, UPDATE_TERM), + OPT_FLAG("msg-time", msg_time, UPDATE_TERM), #ifdef _WIN32 OPT_CHOICE("priority", w32_priority, CONF_GLOBAL, ({"no", 0}, diff --git a/player/command.c b/player/command.c index 1807f269b9..a4a4263dde 100644 --- a/player/command.c +++ b/player/command.c @@ -5626,17 +5626,20 @@ void mp_notify(struct MPContext *mpctx, int event, void *arg) mp_client_broadcast_event(mpctx, event, arg); } -extern const struct m_sub_options gl_video_conf; +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); + + if (flags & UPDATE_RENDERER) { + if (mpctx->video_out) + vo_control(mpctx->video_out, VOCTRL_UPDATE_RENDER_OPTS, NULL); + } +} void mp_notify_property(struct MPContext *mpctx, const char *property) { - struct m_config_option *co = - m_config_get_co_raw(mpctx->mconfig, bstr0(property)); - if (co) { - if (m_config_is_in_group(mpctx->mconfig, &gl_video_conf, co)) { - if (mpctx->video_out) - vo_control(mpctx->video_out, VOCTRL_UPDATE_RENDER_OPTS, NULL); - } - } mp_client_property_change(mpctx, property); } diff --git a/player/command.h b/player/command.h index 33e5b74927..27a4d39913 100644 --- a/player/command.h +++ b/player/command.h @@ -37,6 +37,7 @@ int mp_property_do(const char* name, int action, void* val, struct MPContext *mpctx); int mp_on_set_option(void *ctx, struct m_config_option *co, void *data, int flags); +void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags); void mp_notify(struct MPContext *mpctx, int event, void *arg); void mp_notify_property(struct MPContext *mpctx, const char *property); diff --git a/player/main.c b/player/main.c index 12f0191fc6..334224d6a6 100644 --- a/player/main.c +++ b/player/main.c @@ -359,6 +359,9 @@ struct MPContext *mp_create(void) 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; } diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c index 546d9cc9e5..5b1020f65e 100644 --- a/video/out/opengl/video.c +++ b/video/out/opengl/video.c @@ -415,6 +415,7 @@ const struct m_sub_options gl_video_conf = { }, .size = sizeof(struct gl_video_opts), .defaults = &gl_video_opts_def, + .change_flags = UPDATE_RENDERER, }; #define LEGACY_SCALER_OPTS(n) \