summaryrefslogtreecommitdiffstats
path: root/core/m_config.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-08-02 17:59:43 +0200
committerwm4 <wm4@nowhere>2013-08-02 18:00:38 +0200
commitd1c563c0a9f24e8ed661c29a8718f7fde162a4ff (patch)
treed8ca65b9ee32ffe5d354a6952193403640b9fa4c /core/m_config.c
parent878a94d000093d253206cc50e10632d64f8728cb (diff)
downloadmpv-d1c563c0a9f24e8ed661c29a8718f7fde162a4ff.tar.bz2
mpv-d1c563c0a9f24e8ed661c29a8718f7fde162a4ff.tar.xz
options: don't make options set during playback file local (e.g. --vf)
Refactor file local options handling: instead of making all options implicitly file local between loading a file and terminating playback, explicitly make options file local which are required to be file local. Or in other words, introduce a M_SETOPT_BACKUP flag, which forces file local-ness when setting an option, and use this for file local command line options, per-file config files, and per-protocol/extension/vo/ao profiles. In particular, this changes the "vf" input command such that video filters stay permanent even when going to the next file in the playlist. The underlying reason for this is that the "vf" command uses the option setting command. This influences the "af" command as well.
Diffstat (limited to 'core/m_config.c')
-rw-r--r--core/m_config.c61
1 files changed, 24 insertions, 37 deletions
diff --git a/core/m_config.c b/core/m_config.c
index e63952e577..f362b43836 100644
--- a/core/m_config.c
+++ b/core/m_config.c
@@ -54,20 +54,21 @@ struct m_opt_backup {
void *backup;
};
-static int parse_include(struct m_config *config, struct bstr param, bool set)
+static int parse_include(struct m_config *config, struct bstr param, bool set,
+ int flags)
{
if (param.len == 0)
return M_OPT_MISSING_PARAM;
if (!set)
return 1;
char *filename = bstrdup0(NULL, param);
- config->includefunc(config, filename);
+ config->includefunc(config, filename, flags);
talloc_free(filename);
return 1;
}
static int parse_profile(struct m_config *config, const struct m_option *opt,
- struct bstr name, struct bstr param, bool set)
+ struct bstr name, struct bstr param, bool set, int flags)
{
if (!bstrcmp0(param, "help")) {
struct m_profile *p;
@@ -97,7 +98,7 @@ static int parse_profile(struct m_config *config, const struct m_option *opt,
list[i]);
r = M_OPT_INVALID;
} else if (set)
- m_config_set_profile(config, p);
+ m_config_set_profile(config, p, flags);
}
m_option_free(opt, &list);
return r;
@@ -182,8 +183,7 @@ static void add_options(struct m_config *config,
static int config_destroy(void *p)
{
struct m_config *config = p;
- if (config->file_local_mode)
- m_config_leave_file_local(config);
+ m_config_restore_backups(config);
for (struct m_config_option *copt = config->opts; copt; copt = copt->next)
m_option_free(copt->opt, copt->data);
return 0;
@@ -257,8 +257,6 @@ int m_config_initialize_obj(struct m_config *config, struct m_obj_desc *desc,
static void ensure_backup(struct m_config *config, struct m_config_option *co)
{
- if (!config->file_local_mode)
- return;
if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
return;
if (co->opt->flags & M_OPT_GLOBAL)
@@ -279,20 +277,8 @@ static void ensure_backup(struct m_config *config, struct m_config_option *co)
config->backup_opts = bc;
}
-void m_config_enter_file_local(struct m_config *config)
-{
- assert(!config->file_local_mode);
- config->file_local_mode = true;
- for (struct m_config_option *co = config->opts; co; co = co->next) {
- if (co->opt->flags & M_OPT_LOCAL)
- ensure_backup(config, co);
- }
-}
-
-void m_config_leave_file_local(struct m_config *config)
+void m_config_restore_backups(struct m_config *config)
{
- assert(config->file_local_mode);
- config->file_local_mode = false;
while (config->backup_opts) {
struct m_opt_backup *bc = config->backup_opts;
config->backup_opts = bc->next;
@@ -303,7 +289,7 @@ void m_config_leave_file_local(struct m_config *config)
}
}
-void m_config_mark_file_local(struct m_config *config, const char *opt)
+void m_config_backup_opt(struct m_config *config, const char *opt)
{
struct m_config_option *co = m_config_get_co(config, bstr0(opt));
if (co) {
@@ -313,7 +299,7 @@ void m_config_mark_file_local(struct m_config *config, const char *opt)
}
}
-void m_config_mark_all_file_local(struct m_config *config)
+void m_config_backup_all_opts(struct m_config *config)
{
for (struct m_config_option *co = config->opts; co; co = co->next)
ensure_backup(config, co);
@@ -346,8 +332,7 @@ static void add_negation_option(struct m_config *config,
*no_opt = (struct m_option) {
.name = talloc_asprintf(no_opt, "no-%s", opt->name),
.type = CONF_TYPE_STORE,
- .flags = opt->flags & (M_OPT_NOCFG | M_OPT_GLOBAL | M_OPT_LOCAL |
- M_OPT_PRE_PARSE),
+ .flags = opt->flags & (M_OPT_NOCFG | M_OPT_GLOBAL | M_OPT_PRE_PARSE),
.new = opt->new,
.p = opt->p,
.offset = opt->offset,
@@ -527,17 +512,21 @@ static int m_config_parse_option(struct m_config *config, struct bstr name,
BSTR_P(name));
return M_OPT_INVALID;
}
- if (config->file_local_mode && (co->opt->flags & M_OPT_GLOBAL)) {
- mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
- "The %.*s option is global and can't be set per-file.\n",
- BSTR_P(name));
- return M_OPT_INVALID;
+ if (flags & M_SETOPT_BACKUP) {
+ if (co->opt->flags & M_OPT_GLOBAL) {
+ mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
+ "The %.*s option is global and can't be set per-file.\n",
+ BSTR_P(name));
+ return M_OPT_INVALID;
+ }
+ if (set)
+ ensure_backup(config, co);
}
if (config->includefunc && bstr_equals0(name, "include"))
- return parse_include(config, param, set);
+ return parse_include(config, param, set, flags);
if (config->use_profiles && bstr_equals0(name, "profile"))
- return parse_profile(config, co->opt, name, param, set);
+ return parse_profile(config, co->opt, name, param, set, flags);
if (config->use_profiles && bstr_equals0(name, "show-profile"))
return show_profile(config, param);
if (bstr_equals0(name, "list-options"))
@@ -551,9 +540,6 @@ static int m_config_parse_option(struct m_config *config, struct bstr name,
return parse_subopts(config, co->name, prefix, param, flags);
}
- if (set)
- ensure_backup(config, co);
-
return m_option_parse(co->opt, name, param, set ? co->data : NULL);
}
@@ -763,7 +749,8 @@ int m_config_set_profile_option(struct m_config *config, struct m_profile *p,
return 1;
}
-void m_config_set_profile(struct m_config *config, struct m_profile *p)
+void m_config_set_profile(struct m_config *config, struct m_profile *p,
+ int flags)
{
if (config->profile_depth > MAX_PROFILE_DEPTH) {
mp_tmsg(MSGT_CFGPARSER, MSGL_WARN,
@@ -775,7 +762,7 @@ void m_config_set_profile(struct m_config *config, struct m_profile *p)
m_config_set_option_ext(config,
bstr0(p->opts[2 * i]),
bstr0(p->opts[2 * i + 1]),
- M_SETOPT_FROM_CONFIG_FILE);
+ flags | M_SETOPT_FROM_CONFIG_FILE);
}
config->profile_depth--;
}