summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-02 14:49:34 +0200
committerwm4 <wm4@nowhere>2016-09-02 14:49:34 +0200
commit4fa6bcbb902d500ca0a1b9d2feeab5a4e5a98345 (patch)
treef4c900cdf5536a1a7373965b49d92943fbb59aed /options
parent875aeb0f5c0c2853fc85b28727b5b849bee4a74d (diff)
downloadmpv-4fa6bcbb902d500ca0a1b9d2feeab5a4e5a98345.tar.bz2
mpv-4fa6bcbb902d500ca0a1b9d2feeab5a4e5a98345.tar.xz
m_config: add helper function for initializing af/ao/vf/vo suboptions
Normally I'd prefer a bunch of smaller functions with fewer parameters over a single function with a lot of parameters. But future changes will require messing with the parameters in a slightly more complex way, so a combined function will be needed anyway. The now-unused "global" parameter is required for later as well.
Diffstat (limited to 'options')
-rw-r--r--options/m_config.c22
-rw-r--r--options/m_config.h9
2 files changed, 22 insertions, 9 deletions
diff --git a/options/m_config.c b/options/m_config.c
index d4c19808b0..7da23dc8d0 100644
--- a/options/m_config.c
+++ b/options/m_config.c
@@ -221,7 +221,7 @@ struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx,
return m_config_new(talloc_ctx, log, 0, desc->priv_defaults, desc->options);
}
-int m_config_set_obj_params(struct m_config *conf, char **args)
+static int m_config_set_obj_params(struct m_config *conf, char **args)
{
for (int n = 0; args && args[n * 2 + 0]; n++) {
int r = m_config_set_option(conf, bstr0(args[n * 2 + 0]),
@@ -232,8 +232,8 @@ int m_config_set_obj_params(struct m_config *conf, char **args)
return 0;
}
-int m_config_apply_defaults(struct m_config *config, const char *name,
- struct m_obj_settings *defaults)
+static int m_config_apply_defaults(struct m_config *config, const char *name,
+ struct m_obj_settings *defaults)
{
int r = 0;
for (int n = 0; defaults && defaults[n].name; n++) {
@@ -246,6 +246,22 @@ int m_config_apply_defaults(struct m_config *config, const char *name,
return r;
}
+struct m_config *m_config_from_obj_desc_and_args(void *ta_parent,
+ struct mp_log *log, struct mpv_global *global, struct m_obj_desc *desc,
+ const char *name, struct m_obj_settings *defaults, char **args)
+{
+ struct m_config *config = m_config_from_obj_desc(ta_parent, log, desc);
+ if (m_config_apply_defaults(config, name, defaults) < 0)
+ goto error;
+ if (m_config_set_obj_params(config, args) < 0)
+ goto error;
+
+ return config;
+error:
+ talloc_free(config);
+ return NULL;
+}
+
static void ensure_backup(struct m_config *config, struct m_config_option *co)
{
if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
diff --git a/options/m_config.h b/options/m_config.h
index 4ac673859f..c8225706ee 100644
--- a/options/m_config.h
+++ b/options/m_config.h
@@ -106,12 +106,9 @@ struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx,
struct mp_log *log,
struct m_obj_desc *desc);
-int m_config_set_obj_params(struct m_config *conf, char **args);
-
-// Search for the object with the given name in the defaults list, and apply
-// its parameters.
-int m_config_apply_defaults(struct m_config *config, const char *name,
- struct m_obj_settings *defaults);
+struct m_config *m_config_from_obj_desc_and_args(void *ta_parent,
+ struct mp_log *log, struct mpv_global *global, struct m_obj_desc *desc,
+ const char *name, struct m_obj_settings *defaults, char **args);
// Make sure the option is backed up. If it's already backed up, do nothing.
// All backed up options can be restored with m_config_restore_backups().