summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2021-07-21 11:06:41 +0200
committerDudemanguy <random342@airmail.cc>2021-07-21 13:19:28 +0000
commit1d1d1fbff9648e9adf7acf571514abf618ffc40f (patch)
tree9a3fde28a5fe5e2f5465fe7b7fdecddc24a03b4c /options
parentccb87ad6374c69beb7e88357003bb13cb427a6ee (diff)
downloadmpv-1d1d1fbff9648e9adf7acf571514abf618ffc40f.tar.bz2
mpv-1d1d1fbff9648e9adf7acf571514abf618ffc40f.tar.xz
options: add watch-later-options
This allows configuring which options are saved by quit-watch-later. Fixes #4126, #4641 and #5567. Toggling a video or audio filter twice would treat the option as changed because the backup value is NULL, and the current value of vf/af is a list with one empty item, so obj_settings_list_equal had to be changed.
Diffstat (limited to 'options')
-rw-r--r--options/m_config_frontend.c35
-rw-r--r--options/m_config_frontend.h9
-rw-r--r--options/m_option.c2
-rw-r--r--options/options.c39
-rw-r--r--options/options.h1
5 files changed, 85 insertions, 1 deletions
diff --git a/options/m_config_frontend.c b/options/m_config_frontend.c
index a3356c4111..4a8c583f91 100644
--- a/options/m_config_frontend.c
+++ b/options/m_config_frontend.c
@@ -244,6 +244,28 @@ void m_config_restore_backups(struct m_config *config)
restore_backups(&config->backup_opts, config);
}
+bool m_config_watch_later_backup_opt_changed(struct m_config *config,
+ char *opt_name)
+{
+ struct m_config_option *co = m_config_get_co(config, bstr0(opt_name));
+ if (!co) {
+ // --watch-later-options= makes the first list item an empty string.
+ if (strcmp(opt_name, "") != 0)
+ MP_ERR(config, "Option %s not found.\n", opt_name);
+ return false;
+ }
+
+ for (struct m_opt_backup *bc = config->watch_later_backup_opts; bc;
+ bc = bc->next) {
+ if (strcmp(bc->co->name, co->name) == 0) {
+ struct m_config_option *bc_co = (struct m_config_option *)bc->backup;
+ return !m_option_equal(co->opt, co->data, bc_co);
+ }
+ }
+
+ return false;
+}
+
void m_config_backup_opt(struct m_config *config, const char *opt)
{
struct m_config_option *co = m_config_get_co(config, bstr0(opt));
@@ -260,6 +282,12 @@ void m_config_backup_all_opts(struct m_config *config)
ensure_backup(&config->backup_opts, BACKUP_LOCAL, &config->opts[n]);
}
+void m_config_backup_watch_later_opts(struct m_config *config)
+{
+ for (int n = 0; n < config->num_opts; n++)
+ ensure_backup(&config->watch_later_backup_opts, BACKUP_LOCAL,
+ &config->opts[n]);
+}
struct m_config_option *m_config_get_co_raw(const struct m_config *config,
struct bstr name)
@@ -509,6 +537,13 @@ static void config_destroy(void *p)
config->option_change_callback = NULL;
m_config_restore_backups(config);
+ struct m_opt_backup **list = &config->watch_later_backup_opts;
+ while (*list) {
+ struct m_opt_backup *bc = *list;
+ *list = bc->next;
+ talloc_free(bc);
+ }
+
talloc_free(config->cache);
talloc_free(config->shadow);
}
diff --git a/options/m_config_frontend.h b/options/m_config_frontend.h
index ee6b9aec46..2812033b75 100644
--- a/options/m_config_frontend.h
+++ b/options/m_config_frontend.h
@@ -75,6 +75,7 @@ typedef struct m_config {
int profile_backup_flags;
struct m_opt_backup *backup_opts;
+ struct m_opt_backup *watch_later_backup_opts;
bool use_profiles;
bool is_toplevel;
@@ -134,10 +135,18 @@ void m_config_backup_opt(struct m_config *config, const char *opt);
// Call m_config_backup_opt() on all options.
void m_config_backup_all_opts(struct m_config *config);
+// Backup options on startup so that quit-watch-later can compare the current
+// values to their backups, and save them only if they have been changed.
+void m_config_backup_watch_later_opts(struct m_config *config);
+
// Restore all options backed up with m_config_backup_opt(), and delete the
// backups afterwards.
void m_config_restore_backups(struct m_config *config);
+// Whether opt_name is different from its initial value.
+bool m_config_watch_later_backup_opt_changed(struct m_config *config,
+ char *opt_name);
+
enum {
M_SETOPT_PRE_PARSE_ONLY = 1, // Silently ignore non-M_OPT_PRE_PARSE opt.
M_SETOPT_CHECK_ONLY = 2, // Don't set, just check name/value
diff --git a/options/m_option.c b/options/m_option.c
index 4c199967b3..9b946680b7 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -3668,7 +3668,7 @@ static bool obj_settings_list_equal(const m_option_t *opt, void *pa, void *pb)
struct m_obj_settings *b = VAL(pb);
if (a == b || !a || !b)
- return a == b;
+ return a == b || (!a && !b[0].name) || (!b && !a[0].name);
for (int n = 0; a[n].name || b[n].name; n++) {
if (!a[n].name || !b[n].name)
diff --git a/options/options.c b/options/options.c
index cf0eebf527..4ea23cc702 100644
--- a/options/options.c
+++ b/options/options.c
@@ -695,6 +695,7 @@ static const m_option_t mp_opts[] = {
OPT_FLAG(ignore_path_in_watch_later_config)},
{"watch-later-directory", OPT_STRING(watch_later_directory),
.flags = M_OPT_FILE},
+ {"watch-later-options", OPT_STRINGLIST(watch_later_options)},
{"ordered-chapters", OPT_FLAG(ordered_chapters)},
{"ordered-chapters-files", OPT_STRING(ordered_chapters_files),
@@ -1043,6 +1044,44 @@ static const struct MPOpts mp_default_opts = {
},
.cuda_device = -1,
+
+ .watch_later_options = (char **)(const char*[]){
+ "osd-level",
+ "speed",
+ "edition",
+ "pause",
+ "volume",
+ "mute",
+ "audio-delay",
+ "fullscreen",
+ "ontop",
+ "border",
+ "gamma",
+ "brightness",
+ "contrast",
+ "saturation",
+ "hue",
+ "deinterlace",
+ "vf",
+ "af",
+ "panscan",
+ "aid",
+ "vid",
+ "sid",
+ "sub-delay",
+ "sub-speed",
+ "sub-pos",
+ "sub-visibility",
+ "sub-scale",
+ "sub-use-margins",
+ "sub-ass-force-margins",
+ "sub-ass-vsfilter-aspect-compat",
+ "sub-ass-override",
+ "ab-loop-a",
+ "ab-loop-b",
+ "video-aspect-override",
+ NULL
+ },
};
const struct m_sub_options mp_opt_root = {
diff --git a/options/options.h b/options/options.h
index f0de6781ee..41aa88abb9 100644
--- a/options/options.h
+++ b/options/options.h
@@ -252,6 +252,7 @@ typedef struct MPOpts {
int write_filename_in_watch_later_config;
int ignore_path_in_watch_later_config;
char *watch_later_directory;
+ char **watch_later_options;
int pause;
int keep_open;
int keep_open_pause;