1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-18 04:45:33 +00:00

player: some M_SETOPT_RUNTIME cleanups

Add this flag where needed. You shouldn't be able to set e.g. config-dir
in these situations.

Remove the mpctx->initialized check from the property/option bridge,
since it's in use strictly only after initialization. Likewise, the
apply-profile command doesn't need to check this.
This commit is contained in:
wm4 2016-09-22 20:35:38 +02:00
parent 6ba2bbd090
commit 6fe83fdc33
3 changed files with 9 additions and 21 deletions

View File

@ -331,12 +331,12 @@ direct_option:
} }
// Property-option bridge. (Maps the property to the option with the same name.) // Property-option bridge. (Maps the property to the option with the same name.)
static int mp_property_generic_option_do(void *ctx, struct m_property *prop, static int mp_property_generic_option(void *ctx, struct m_property *prop,
int action, void *arg, bool force) int action, void *arg)
{ {
MPContext *mpctx = ctx; MPContext *mpctx = ctx;
const char *optname = prop->name; const char *optname = prop->name;
int flags = mpctx->initialized && !force ? M_SETOPT_RUNTIME : 0; int flags = M_SETOPT_RUNTIME;
struct m_config_option *opt = m_config_get_co(mpctx->mconfig, struct m_config_option *opt = m_config_get_co(mpctx->mconfig,
bstr0(optname)); bstr0(optname));
@ -360,18 +360,6 @@ static int mp_property_generic_option_do(void *ctx, struct m_property *prop,
return M_PROPERTY_NOT_IMPLEMENTED; return M_PROPERTY_NOT_IMPLEMENTED;
} }
static int mp_property_generic_option(void *ctx, struct m_property *prop,
int action, void *arg)
{
return mp_property_generic_option_do(ctx, prop, action, arg, true);
}
static int mp_property_generic_option_bridge(void *ctx, struct m_property *prop,
int action, void *arg)
{
return mp_property_generic_option_do(ctx, prop, action, arg, false);
}
// Dumb special-case: the option name ends in a "*". // Dumb special-case: the option name ends in a "*".
static int mp_property_generic_option_star(void *ctx, struct m_property *prop, static int mp_property_generic_option_star(void *ctx, struct m_property *prop,
int action, void *arg) int action, void *arg)
@ -380,7 +368,7 @@ static int mp_property_generic_option_star(void *ctx, struct m_property *prop,
char name[80]; char name[80];
snprintf(name, sizeof(name), "%s*", prop->name); snprintf(name, sizeof(name), "%s*", prop->name);
prop2.name = name; prop2.name = name;
return mp_property_generic_option_bridge(ctx, &prop2, action, arg); return mp_property_generic_option(ctx, &prop2, action, arg);
} }
/// Playback speed (RW) /// Playback speed (RW)
@ -5478,8 +5466,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
case MP_CMD_APPLY_PROFILE: { case MP_CMD_APPLY_PROFILE: {
char *profile = cmd->args[0].v.s; char *profile = cmd->args[0].v.s;
int flags = mpctx->initialized ? M_SETOPT_RUNTIME : 0; if (m_config_set_profile(mpctx->mconfig, profile, M_SETOPT_RUNTIME) < 0)
if (m_config_set_profile(mpctx->mconfig, profile, flags) < 0)
return -1; return -1;
break; break;
} }
@ -5523,7 +5510,7 @@ void command_init(struct MPContext *mpctx)
struct m_property prop = { struct m_property prop = {
.name = co->name, .name = co->name,
.call = mp_property_generic_option_bridge, .call = mp_property_generic_option,
}; };
bstr bname = bstr0(prop.name); bstr bname = bstr0(prop.name);

View File

@ -92,7 +92,8 @@ static int try_load_config(struct MPContext *mpctx, const char *file, int flags)
// Set options file-local, and don't set them if the user set them via the // Set options file-local, and don't set them if the user set them via the
// command line. // command line.
#define FILE_LOCAL_FLAGS (M_SETOPT_BACKUP | M_SETOPT_PRESERVE_CMDLINE) #define FILE_LOCAL_FLAGS \
(M_SETOPT_BACKUP | M_SETOPT_RUNTIME | M_SETOPT_PRESERVE_CMDLINE)
static void mp_load_per_file_config(struct MPContext *mpctx) static void mp_load_per_file_config(struct MPContext *mpctx)
{ {

View File

@ -770,7 +770,7 @@ static void load_per_file_options(m_config_t *conf,
{ {
for (int n = 0; n < params_count; n++) { for (int n = 0; n < params_count; n++) {
m_config_set_option_ext(conf, params[n].name, params[n].value, m_config_set_option_ext(conf, params[n].name, params[n].value,
M_SETOPT_BACKUP); M_SETOPT_RUNTIME | M_SETOPT_BACKUP);
} }
} }