From bc0ed904811b4e4a0fc3d6129ba92e2c786cbabf Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 15 Oct 2014 22:39:33 +0200 Subject: command: allow setting per-file options at runtime The intended use-case is for doing this at load time, after the load command was issued. (See following commit.) --- player/command.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'player/command.c') diff --git a/player/command.c b/player/command.c index 6daa0555c7..ee782da8ee 100644 --- a/player/command.c +++ b/player/command.c @@ -2674,7 +2674,8 @@ static int mp_property_alias(void *ctx, struct m_property *prop, return mp_property_do(real_property, action, arg, ctx); } -static int access_options(struct m_property_action_arg *ka, MPContext *mpctx) +static int access_options(struct m_property_action_arg *ka, bool local, + MPContext *mpctx) { struct m_config_option *opt = m_config_get_co(mpctx->mconfig, bstr0(ka->key)); @@ -2688,8 +2689,10 @@ static int access_options(struct m_property_action_arg *ka, MPContext *mpctx) m_option_copy(opt->opt, ka->arg, opt->data); return M_PROPERTY_OK; case M_PROPERTY_SET: { - int r = m_config_set_option_raw(mpctx->mconfig, opt, ka->arg, - M_SETOPT_RUNTIME); + if (local && !mpctx->playing) + return M_PROPERTY_ERROR; + int flags = M_SETOPT_RUNTIME | (local ? M_SETOPT_BACKUP : 0); + int r = m_config_set_option_raw(mpctx->mconfig, opt, ka->arg, flags); return r < 0 ? M_PROPERTY_ERROR : M_PROPERTY_OK; } case M_PROPERTY_GET_TYPE: @@ -2699,10 +2702,8 @@ static int access_options(struct m_property_action_arg *ka, MPContext *mpctx) return M_PROPERTY_NOT_IMPLEMENTED; } -static int mp_property_options(void *ctx, struct m_property *prop, - int action, void *arg) +static int access_option_list(int action, void *arg, bool local, MPContext *mpctx) { - MPContext *mpctx = ctx; switch (action) { case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING_LIST}; @@ -2711,11 +2712,26 @@ static int mp_property_options(void *ctx, struct m_property *prop, *(char ***)arg = m_config_list_options(NULL, mpctx->mconfig); return M_PROPERTY_OK; case M_PROPERTY_KEY_ACTION: - return access_options(arg, mpctx); + return access_options(arg, local, mpctx); } return M_PROPERTY_NOT_IMPLEMENTED; } + +static int mp_property_options(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + return access_option_list(action, arg, false, mpctx); +} + +static int mp_property_local_options(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + return access_option_list(action, arg, true, mpctx); +} + static const struct m_property mp_properties[]; static int mp_property_list(void *ctx, struct m_property *prop, @@ -2906,6 +2922,7 @@ static const struct m_property mp_properties[] = { M_PROPERTY_ALIAS("sub", "sid"), {"options", mp_property_options}, + {"file-local-options", mp_property_local_options}, {"property-list", mp_property_list}, {0}, -- cgit v1.2.3