summaryrefslogtreecommitdiffstats
path: root/options/m_config_frontend.c
diff options
context:
space:
mode:
Diffstat (limited to 'options/m_config_frontend.c')
-rw-r--r--options/m_config_frontend.c76
1 files changed, 49 insertions, 27 deletions
diff --git a/options/m_config_frontend.c b/options/m_config_frontend.c
index a3356c4111..d800cdb75d 100644
--- a/options/m_config_frontend.c
+++ b/options/m_config_frontend.c
@@ -15,28 +15,28 @@
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <assert.h>
+#include <errno.h>
#include <float.h>
-#include <stdlib.h>
+#include <stdatomic.h>
+#include <stdbool.h>
#include <stdio.h>
-#include <errno.h>
+#include <stdlib.h>
#include <string.h>
#include <strings.h>
-#include <assert.h>
-#include <stdbool.h>
-#include <pthread.h>
#include "libmpv/client.h"
-#include "m_config.h"
-#include "m_config_frontend.h"
-#include "options/m_option.h"
#include "common/common.h"
#include "common/global.h"
-#include "common/msg.h"
#include "common/msg_control.h"
+#include "common/msg.h"
+#include "m_config_frontend.h"
+#include "m_config.h"
#include "misc/dispatch.h"
#include "misc/node.h"
-#include "osdep/atomic.h"
+#include "options/m_option.h"
+#include "osdep/threads.h"
extern const char mp_help_text[];
@@ -168,18 +168,9 @@ static int m_config_set_obj_params(struct m_config *config, struct mp_log *log,
struct m_config *m_config_from_obj_desc_and_args(void *ta_parent,
struct mp_log *log, struct mpv_global *global, struct m_obj_desc *desc,
- const char *name, struct m_obj_settings *defaults, char **args)
+ char **args)
{
struct m_config *config = m_config_from_obj_desc(ta_parent, log, global, desc);
-
- for (int n = 0; defaults && defaults[n].name; n++) {
- struct m_obj_settings *entry = &defaults[n];
- if (name && strcmp(entry->name, name) == 0) {
- if (m_config_set_obj_params(config, log, global, desc, entry->attribs) < 0)
- goto error;
- }
- }
-
if (m_config_set_obj_params(config, log, global, desc, args) < 0)
goto error;
@@ -244,6 +235,26 @@ 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) {
+ 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 +271,11 @@ 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, 0, &config->opts[n]);
+}
struct m_config_option *m_config_get_co_raw(const struct m_config *config,
struct bstr name)
@@ -509,6 +525,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);
}
@@ -726,7 +749,7 @@ int m_config_set_option_cli(struct m_config *config, struct bstr name,
BSTR_P(name), BSTR_P(param), flags);
}
- union m_option_value val = {0};
+ union m_option_value val = m_option_value_default;
// Some option types are "impure" and work on the existing data.
// (Prime examples: --vf-add, --sub-file)
@@ -760,7 +783,7 @@ int m_config_set_option_node(struct m_config *config, bstr name,
// Do this on an "empty" type to make setting the option strictly overwrite
// the old value, as opposed to e.g. appending to lists.
- union m_option_value val = {0};
+ union m_option_value val = m_option_value_default;
if (data->format == MPV_FORMAT_STRING) {
bstr param = bstr0(data->u.string);
@@ -826,7 +849,7 @@ void m_config_print_option_list(const struct m_config *config, const char *name)
MP_INFO(config, " %s%-30s", prefix, co->name);
if (opt->type == &m_option_type_choice) {
MP_INFO(config, " Choices:");
- struct m_opt_choice_alternatives *alt = opt->priv;
+ const struct m_opt_choice_alternatives *alt = opt->priv;
for (int n = 0; alt[n].name; n++)
MP_INFO(config, " %s", alt[n].name);
if (opt->min < opt->max)
@@ -845,11 +868,10 @@ void m_config_print_option_list(const struct m_config *config, const char *name)
}
char *def = NULL;
const void *defptr = m_config_get_co_default(config, co);
- const union m_option_value default_value = {0};
if (!defptr)
- defptr = &default_value;
+ defptr = &m_option_value_default;
if (defptr)
- def = m_option_pretty_print(opt, defptr);
+ def = m_option_pretty_print(opt, defptr, false);
if (def) {
MP_INFO(config, " (default: %s)", def);
talloc_free(def);
@@ -1009,7 +1031,7 @@ int m_config_restore_profile(struct m_config *config, char *name)
return M_OPT_INVALID;
if (!p->backups)
- MP_WARN(config, "Profile contains no restore data.\n");
+ MP_WARN(config, "Profile '%s' contains no restore data.\n", name);
restore_backups(&p->backups, config);