From 1cb085a82e89ce4c9150871c910c75d9404d1e01 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 29 Nov 2019 00:16:52 +0100 Subject: options: get rid of GLOBAL_CONFIG hack Just an implementation detail that can be cleaned up now. Internally, m_config maintains a tree of m_sub_options structs, except for the root it was not defined explicitly. GLOBAL_CONFIG was a hack to get access to it anyway. Define it explicitly instead. --- audio/decode/ad_lavc.c | 2 +- demux/demux_mkv_timeline.c | 2 +- filters/f_decoder_wrapper.c | 2 +- input/ipc-unix.c | 2 +- input/ipc-win.c | 2 +- options/m_config.c | 32 +++++++++++++++----------------- options/m_config.h | 19 ++++--------------- options/options.c | 10 ++++++++-- options/options.h | 3 +-- player/main.c | 3 +-- 10 files changed, 34 insertions(+), 43 deletions(-) diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index a420021f4a..8362e918f3 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -81,7 +81,7 @@ static bool init(struct mp_filter *da, struct mp_codec_params *codec, const char *decoder) { struct priv *ctx = da->priv; - struct MPOpts *mpopts = mp_get_config_group(ctx, da->global, GLOBAL_CONFIG); + struct MPOpts *mpopts = mp_get_config_group(ctx, da->global, &mp_opt_root); struct ad_lavc_params *opts = mp_get_config_group(ctx, da->global, &ad_lavc_conf); AVCodecContext *lavc_context; diff --git a/demux/demux_mkv_timeline.c b/demux/demux_mkv_timeline.c index 60bdf3b673..5bbadc0781 100644 --- a/demux/demux_mkv_timeline.c +++ b/demux/demux_mkv_timeline.c @@ -515,7 +515,7 @@ void build_ordered_chapter_timeline(struct timeline *tl) .global = tl->global, .tl = tl, .demuxer = demuxer, - .opts = mp_get_config_group(ctx, tl->global, GLOBAL_CONFIG), + .opts = mp_get_config_group(ctx, tl->global, &mp_opt_root), }; if (!ctx->opts->ordered_chapters || !demuxer->access_references) { diff --git a/filters/f_decoder_wrapper.c b/filters/f_decoder_wrapper.c index 9654af3ac9..7ce13606b6 100644 --- a/filters/f_decoder_wrapper.c +++ b/filters/f_decoder_wrapper.c @@ -775,7 +775,7 @@ struct mp_decoder_wrapper *mp_decoder_wrapper_create(struct mp_filter *parent, struct priv *p = f->priv; struct mp_decoder_wrapper *w = &p->public; - p->opt_cache = m_config_cache_alloc(p, f->global, GLOBAL_CONFIG); + p->opt_cache = m_config_cache_alloc(p, f->global, &mp_opt_root); p->log = f->log; p->f = f; p->header = src; diff --git a/input/ipc-unix.c b/input/ipc-unix.c index 94a0b4700b..bfd035298c 100644 --- a/input/ipc-unix.c +++ b/input/ipc-unix.c @@ -387,7 +387,7 @@ done: struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api, struct mpv_global *global) { - struct MPOpts *opts = mp_get_config_group(NULL, global, GLOBAL_CONFIG); + struct MPOpts *opts = mp_get_config_group(NULL, global, &mp_opt_root); struct mp_ipc_ctx *arg = talloc_ptrtype(NULL, arg); *arg = (struct mp_ipc_ctx){ diff --git a/input/ipc-win.c b/input/ipc-win.c index 8bfbaf409b..727a8cca73 100644 --- a/input/ipc-win.c +++ b/input/ipc-win.c @@ -450,7 +450,7 @@ done: struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api, struct mpv_global *global) { - struct MPOpts *opts = mp_get_config_group(NULL, global, GLOBAL_CONFIG); + struct MPOpts *opts = mp_get_config_group(NULL, global, &mp_opt_root); struct mp_ipc_ctx *arg = talloc_ptrtype(NULL, arg); *arg = (struct mp_ipc_ctx){ diff --git a/options/m_config.c b/options/m_config.c index 542288f06f..318ced3d34 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -451,23 +451,15 @@ static void config_destroy(void *p) } struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log, - size_t size, const void *defaults, - const struct m_option *options) + const struct m_sub_options *root) { struct m_config *config = talloc(talloc_ctx, struct m_config); talloc_set_destructor(config, config_destroy); *config = (struct m_config){.log = log,}; - struct m_sub_options *subopts = talloc_ptrtype(config, subopts); - *subopts = (struct m_sub_options){ - .opts = options, - .size = size, - .defaults = defaults, - }; - - config->shadow = m_config_shadow_new(subopts); + config->shadow = m_config_shadow_new(root); - if (size) { + if (root->size) { config->data = allocate_option_data(config, config->shadow, 0, config->shadow->data); config->optstruct = config->data->gdata[0].udata; @@ -500,9 +492,16 @@ static struct m_config *m_config_from_obj_desc(void *talloc_ctx, struct mpv_global *global, struct m_obj_desc *desc) { - struct m_config *c = - m_config_new(talloc_ctx, log, desc->priv_size, desc->priv_defaults, - desc->options); + struct m_sub_options *root = talloc_ptrtype(NULL, root); + *root = (struct m_sub_options){ + .opts = desc->options, + // (global == NULL got repurposed to mean "no alloc") + .size = global ? desc->priv_size : 0, + .defaults = desc->priv_defaults, + }; + + struct m_config *c = m_config_new(talloc_ctx, log, root); + talloc_steal(c, root); c->global = global; if (desc->set_defaults && c->global) desc->set_defaults(c->global, c->optstruct); @@ -513,7 +512,7 @@ struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx, struct mp_log *log, struct m_obj_desc *desc) { - return m_config_new(talloc_ctx, log, 0, desc->priv_defaults, desc->options); + return m_config_from_obj_desc(talloc_ctx, log, NULL, desc); } static const struct m_config_group *find_group(struct mpv_global *global, @@ -1365,8 +1364,7 @@ struct m_config_cache *m_config_cache_alloc(void *ta_parent, int group_index = -1; for (int n = 0; n < shadow->num_groups; n++) { - // group==NULL is special cased to root group. - if (shadow->groups[n].group == group || (!group && !n)) { + if (shadow->groups[n].group == group) { group_index = n; break; } diff --git a/options/m_config.h b/options/m_config.h index 0f05e117a3..357dca5d4d 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -92,16 +92,10 @@ typedef struct m_config { // Create a new config object. // talloc_ctx: talloc parent context for the m_config allocation -// size: size of the optstruct (where option values are stored) -// size==0 creates a config object with no option struct allocated -// defaults: if not NULL, points to a struct of same type as optstruct, which -// contains default values for all options -// options: list of options. Each option defines a member of the optstruct -// and a corresponding option switch or sub-option field. -// Note that the m_config object will keep pointers to defaults and options. +// root: description of all options +// Note that the m_config object will keep pointers to root and log. struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log, - size_t size, const void *defaults, - const struct m_option *options); + const struct m_sub_options *root); // Create a m_config for the given desc. This is for --af/--vf, which have // different sub-options for every filter (represented by separate desc @@ -279,8 +273,6 @@ struct m_config_cache { struct config_cache *internal; }; -#define GLOBAL_CONFIG NULL - // Create a mirror copy from the global options. // Keep in mind that a m_config_cache object is not thread-safe; it merely // provides thread-safe access to the global options. All API functions for @@ -290,9 +282,7 @@ struct m_config_cache { // time. // ta_parent: parent for the returned allocation // global: option data source -// group: the option group to return. This can be GLOBAL_CONFIG for the global -// option struct (MPOpts), or m_sub_options used in a certain -// OPT_SUBSTRUCT() item. +// group: the option group to return struct m_config_cache *m_config_cache_alloc(void *ta_parent, struct mpv_global *global, const struct m_sub_options *group); @@ -355,7 +345,6 @@ void m_config_cache_write_opt(struct m_config_cache *cache, void *ptr); // Like m_config_cache_alloc(), but return the struct (m_config_cache->opts) // directly, with no way to update the config. Basically this returns a copy // with a snapshot of the current option values. -// group==GLOBAL_CONFIG is a special case, and always returns the root group. void *mp_get_config_group(void *ta_parent, struct mpv_global *global, const struct m_sub_options *group); diff --git a/options/options.c b/options/options.c index 6437dc81c5..ee226843c2 100644 --- a/options/options.c +++ b/options/options.c @@ -318,7 +318,7 @@ const struct m_sub_options filter_conf = { #undef OPT_BASE_STRUCT #define OPT_BASE_STRUCT struct MPOpts -const m_option_t mp_opts[] = { +static const m_option_t mp_opts[] = { // handled in command line pre-parser (parse_commandline.c) {"v", &m_option_type_dummy_flag, CONF_NOCFG | M_OPT_NOPROP, .offset = -1}, @@ -896,7 +896,7 @@ const m_option_t mp_opts[] = { {0} }; -const struct MPOpts mp_default_opts = { +static const struct MPOpts mp_default_opts = { .use_terminal = 1, .msg_color = 1, .audio_decoders = NULL, @@ -991,4 +991,10 @@ const struct MPOpts mp_default_opts = { .cuda_device = -1, }; +const struct m_sub_options mp_opt_root = { + .opts = mp_opts, + .size = sizeof(struct MPOpts), + .defaults = &mp_default_opts, +}; + #endif /* MPLAYER_CFG_MPLAYER_H */ diff --git a/options/options.h b/options/options.h index 126e4cb59a..1935888032 100644 --- a/options/options.h +++ b/options/options.h @@ -355,8 +355,6 @@ struct filter_opts { int deinterlace; }; -extern const m_option_t mp_opts[]; -extern const struct MPOpts mp_default_opts; extern const struct m_sub_options vo_sub_opts; extern const struct m_sub_options dvd_conf; extern const struct m_sub_options mp_subtitle_sub_opts; @@ -364,5 +362,6 @@ extern const struct m_sub_options mp_osd_render_sub_opts; extern const struct m_sub_options filter_conf; extern const struct m_sub_options resample_conf; extern const struct m_sub_options stream_conf; +extern const struct m_sub_options mp_opt_root; #endif diff --git a/player/main.c b/player/main.c index 3f39dad04c..f4c7348af4 100644 --- a/player/main.c +++ b/player/main.c @@ -296,8 +296,7 @@ struct MPContext *mp_create(void) mpctx->statusline = mp_log_new(mpctx, mpctx->log, "!statusline"); // Create the config context and register the options - mpctx->mconfig = m_config_new(mpctx, mpctx->log, sizeof(struct MPOpts), - &mp_default_opts, mp_opts); + mpctx->mconfig = m_config_new(mpctx, mpctx->log, &mp_opt_root); mpctx->opts = mpctx->mconfig->optstruct; mpctx->global->config = mpctx->mconfig->shadow; mpctx->mconfig->includefunc = cfg_include; -- cgit v1.2.3