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.)
This commit is contained in:
wm4 committed 2014-10-15 22:39:33 +02:00
1 parent 312531c08c
commit bc0ed90481
2 files changed
+34 -7

No files matched your search

+10
View File
@@ -1361,6 +1361,16 @@ Property list
require reloading the file for changes to take effect. If there is an
equivalent property, prefer setting the property instead.
``file-local-options/<name>``
Similar to ``options/<name>``, but when setting an option through this
property, the option is reset to its old value once the current file has
stopped playing. Trying to write an option while no file is playing (or
is being loaded) results in an error.
(Note that if an option is marked as file-local, even ``options/`` will
access the local value, and the ``old`` value, which will be restored on
end of playback, can not be read or written until end of playback.)
``property-list``
Return the list of top-level properties.
+24 -7
View File
@@ -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},