From 5086b2d4568bfd8b39a4418a2db4dbfbb1fae92f Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 28 Aug 2016 18:15:37 +0200 Subject: player: add option to disable video OSD Normally, OSD can be disabled with --osd-level=0. But this also disables terminal OSD, and some users want _only_ the terminal OSD. Add --video-osd=no, which essentially disables the video OSD. Ideally, it should probably be possible to control terminal and video OSD levels independently, but that would require separate OSD timers (and other state) for both components, so don't do it. But because the current situation isn't too ideal, add a threat to the manpage that might be changed in the future. Fixes #3387. --- options/options.c | 3 +++ options/options.h | 2 ++ 2 files changed, 5 insertions(+) (limited to 'options') diff --git a/options/options.c b/options/options.c index 0ef89650a3..129f0cc53c 100644 --- a/options/options.c +++ b/options/options.c @@ -589,6 +589,8 @@ const m_option_t mp_opts[] = { OPT_STRING("osd-msg2", osd_msg[1], 0), OPT_STRING("osd-msg3", osd_msg[2], 0), + OPT_FLAG("video-osd", video_osd, 0), + OPT_CHOICE("idle", player_idle_mode, 0, ({"no", 0}, {"once", 1}, @@ -739,6 +741,7 @@ const struct MPOpts mp_default_opts = { .gamma_contrast = 1000, .gamma_saturation = 1000, .gamma_hue = 1000, + .video_osd = 1, .osd_level = 1, .osd_duration = 1000, .osd_bar_align_y = 0.5, diff --git a/options/options.h b/options/options.h index 263caaa8de..187abc2c1a 100644 --- a/options/options.h +++ b/options/options.h @@ -127,6 +127,8 @@ typedef struct MPOpts { int osd_level; int osd_duration; int osd_fractions; + int video_osd; + int untimed; char *stream_capture; char *stream_dump; -- cgit v1.2.3 From f42e4374d55a3b68b0c4fcb342d9cdcd5d15c9c7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 28 Aug 2016 19:42:03 +0200 Subject: command: export profile list as a property Targeted at scripts, which can do whatever they want with it. This comes with the promise that they could get randomly broken any time. See #977. --- options/m_config.c | 27 +++++++++++++++++++++++++++ options/m_config.h | 2 ++ 2 files changed, 29 insertions(+) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 1cb01ebfdc..3dbbb5020a 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -36,6 +36,7 @@ #include "options/m_option.h" #include "common/msg.h" #include "common/msg_control.h" +#include "misc/node.h" static const union m_option_value default_value; @@ -933,6 +934,32 @@ int m_config_set_profile(struct m_config *config, char *name, int flags) return 0; } +struct mpv_node m_config_get_profiles(struct m_config *config) +{ + struct mpv_node root; + node_init(&root, MPV_FORMAT_NODE_ARRAY, NULL); + + for (m_profile_t *profile = config->profiles; profile; profile = profile->next) + { + struct mpv_node *entry = node_array_add(&root, MPV_FORMAT_NODE_MAP); + + node_map_add_string(entry, "name", profile->name); + if (profile->desc) + node_map_add_string(entry, "profile-desc", profile->desc); + + struct mpv_node *opts = + node_map_add(entry, "options", MPV_FORMAT_NODE_ARRAY); + + for (int n = 0; n < profile->num_opts; n++) { + struct mpv_node *opt_entry = node_array_add(opts, MPV_FORMAT_NODE_MAP); + node_map_add_string(opt_entry, "key", profile->opts[n * 2 + 0]); + node_map_add_string(opt_entry, "value", profile->opts[n * 2 + 1]); + } + } + + return root; +} + void *m_config_alloc_struct(void *talloc_ctx, const struct m_sub_options *subopts) { diff --git a/options/m_config.h b/options/m_config.h index ed34389921..5937a4492e 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -247,6 +247,8 @@ int m_config_set_profile_option(struct m_config *config, struct m_profile *p, */ int m_config_set_profile(struct m_config *config, char *name, int flags); +struct mpv_node m_config_get_profiles(struct m_config *config); + void *m_config_alloc_struct(void *talloc_ctx, const struct m_sub_options *subopts); -- cgit v1.2.3 From bda614bfd81ae4660ed6356bc124e015645ff3b0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 29 Aug 2016 09:30:39 +0200 Subject: m_config: profile option values can be NULL Sigh. --- options/m_config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 3dbbb5020a..106a8f20ee 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -953,7 +953,8 @@ struct mpv_node m_config_get_profiles(struct m_config *config) for (int n = 0; n < profile->num_opts; n++) { struct mpv_node *opt_entry = node_array_add(opts, MPV_FORMAT_NODE_MAP); node_map_add_string(opt_entry, "key", profile->opts[n * 2 + 0]); - node_map_add_string(opt_entry, "value", profile->opts[n * 2 + 1]); + if (profile->opts[n * 2 + 1]) + node_map_add_string(opt_entry, "value", profile->opts[n * 2 + 1]); } } -- cgit v1.2.3 From 3bb134969eb624e859a546fd7142fe2eae076346 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 30 Aug 2016 23:45:58 +0200 Subject: m_option: remove M_OPT_TYPE_DYNAMIC flag It's actually redundant with whether m_option_type.free is set. Some option types were flagged inconsistently. Its only use was for running an additional sanity check without any real functionality. --- options/m_config.c | 2 +- options/m_option.c | 9 ++------- options/m_option.h | 10 +--------- 3 files changed, 4 insertions(+), 17 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 106a8f20ee..d2fe3fdcfa 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -424,7 +424,7 @@ static void m_config_add_option(struct m_config *config, } else { // Initialize options if (co.data && co.default_data) { - if (arg->type->flags & M_OPT_TYPE_DYNAMIC) { + if (arg->type->free) { // Would leak memory by overwriting *co.data repeatedly. for (int i = 0; i < config->num_opts; i++) { if (co.data == config->opts[i].data) diff --git a/options/m_option.c b/options/m_option.c index 0acdc55b0a..94dab9f59f 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1175,7 +1175,6 @@ static void free_str(void *src) const m_option_type_t m_option_type_string = { .name = "String", .size = sizeof(char *), - .flags = M_OPT_TYPE_DYNAMIC, .parse = parse_str, .print = print_str, .copy = copy_str, @@ -1486,7 +1485,7 @@ const m_option_type_t m_option_type_string_list = { */ .name = "String list", .size = sizeof(char **), - .flags = M_OPT_TYPE_DYNAMIC | M_OPT_TYPE_ALLOW_WILDCARD, + .flags = M_OPT_TYPE_ALLOW_WILDCARD, .parse = parse_str_list, .print = print_str_list, .copy = copy_str_list, @@ -1522,7 +1521,6 @@ static int parse_str_append_list(struct mp_log *log, const m_option_t *opt, const m_option_type_t m_option_type_string_append_list = { .name = "String list", .size = sizeof(char **), - .flags = M_OPT_TYPE_DYNAMIC, .parse = parse_str_append_list, .print = print_str_list, .copy = copy_str_list, @@ -1636,7 +1634,6 @@ static int keyvalue_list_get(const m_option_t *opt, void *ta_parent, const m_option_type_t m_option_type_keyvalue_list = { .name = "Key/value list", .size = sizeof(char **), - .flags = M_OPT_TYPE_DYNAMIC, .parse = parse_keyvalue_list, .print = print_keyvalue_list, .copy = copy_str_list, @@ -1703,7 +1700,6 @@ static int set_msglevels(const m_option_t *opt, void *dst, const m_option_type_t m_option_type_msglevels = { .name = "Output verbosity levels", .size = sizeof(char **), - .flags = M_OPT_TYPE_DYNAMIC, .parse = parse_msglevels, .print = print_keyvalue_list, .copy = copy_str_list, @@ -3284,7 +3280,7 @@ static int get_obj_settings_list(const m_option_t *opt, void *ta_parent, const m_option_type_t m_option_type_obj_settings_list = { .name = "Object settings list", .size = sizeof(m_obj_settings_t *), - .flags = M_OPT_TYPE_DYNAMIC | M_OPT_TYPE_ALLOW_WILDCARD, + .flags = M_OPT_TYPE_ALLOW_WILDCARD, .parse = parse_obj_settings_list, .print = print_obj_settings_list, .copy = copy_obj_settings_list, @@ -3405,7 +3401,6 @@ static int node_get(const m_option_t *opt, void *ta_parent, const m_option_type_t m_option_type_node = { .name = "Complex", .size = sizeof(struct mpv_node), - .flags = M_OPT_TYPE_DYNAMIC, .parse = parse_node, .print = print_node, .copy = copy_node, diff --git a/options/m_option.h b/options/m_option.h index 80be447c42..847cd1097c 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -403,19 +403,11 @@ struct m_option { */ #define M_OPT_TYPE_ALLOW_WILDCARD (1 << 1) -// Dynamic data type. -/** This flag indicates that the data is dynamically allocated (m_option::p - * points to a pointer). It enables a little hack in the \ref Config which - * replaces the initial value of such variables with a dynamic copy in case - * the initial value is statically allocated (pretty common with strings). - */ -#define M_OPT_TYPE_DYNAMIC (1 << 2) - // The parameter is optional and by default no parameter is preferred. If // ambiguous syntax is used ("--opt value"), the command line parser will // assume that the argument takes no parameter. In config files, these // options can be used without "=" and value. -#define M_OPT_TYPE_OPTIONAL_PARAM (1 << 3) +#define M_OPT_TYPE_OPTIONAL_PARAM (1 << 2) ///////////////////////////// Parser flags ///////////////////////////////// -- cgit v1.2.3 From 5f88e6a0db292d272b3dc8f66c257c27327d1733 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 30 Aug 2016 23:47:09 +0200 Subject: m_config: rename is_generated to is_hidden More appropriate. Originally it really was for automatically added options, but now it even needed some stupid comments to indicate that it was used for simply hiding options. --- options/m_config.c | 12 ++++++------ options/m_config.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index d2fe3fdcfa..c98ee6713f 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -334,7 +334,7 @@ static void add_negation_option(struct m_config *config, struct m_config_option co = *orig; co.name = talloc_asprintf(config, "no-%s", orig->name); co.opt = no_opt; - co.is_generated = true; + co.is_hidden = true; MP_TARRAY_APPEND(config, config->opts, config->num_opts, co); // Add --sub-no-opt (unfortunately needed for: "--sub=...:no-opt") if (parent_name[0]) { @@ -441,7 +441,7 @@ static void m_config_add_option(struct m_config *config, add_negation_option(config, &co, parent_name); if (co.opt->type == &m_option_type_alias) { - co.is_generated = true; // hide it + co.is_hidden = true; const char *alias = (const char *)co.opt->priv; char no_alias[40]; snprintf(no_alias, sizeof(no_alias), "no-%s", alias); @@ -456,7 +456,7 @@ static void m_config_add_option(struct m_config *config, } if (co.opt->type == &m_option_type_removed) - co.is_generated = true; // hide it + co.is_hidden = true; } struct m_config_option *m_config_get_co(const struct m_config *config, @@ -519,7 +519,7 @@ const char *m_config_get_positional_option(const struct m_config *config, int p) int pos = 0; for (int n = 0; n < config->num_opts; n++) { struct m_config_option *co = &config->opts[n]; - if (!co->is_generated) { + if (!co->is_hidden) { if (pos == p) return co->name; pos++; @@ -794,7 +794,7 @@ void m_config_print_option_list(const struct m_config *config) const struct m_option *opt = co->opt; if (opt->type->flags & M_OPT_TYPE_HAS_CHILD) continue; - if (co->is_generated) + if (co->is_hidden) continue; if (opt->type == &m_option_type_alias || opt->type == &m_option_type_removed) @@ -848,7 +848,7 @@ char **m_config_list_options(void *ta_parent, const struct m_config *config) const struct m_option *opt = co->opt; if (opt->type->flags & M_OPT_TYPE_HAS_CHILD) continue; - if (co->is_generated) + if (co->is_hidden) continue; // For use with CONF_TYPE_STRING_LIST, it's important not to set list // as allocation parent. diff --git a/options/m_config.h b/options/m_config.h index 5937a4492e..af8ab421f0 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -37,7 +37,7 @@ struct mp_log; // Config option struct m_config_option { - bool is_generated : 1; // Automatically added ("no-" options) + bool is_hidden : 1; // Does not show up in help bool is_set_from_cmdline : 1; // Set by user from command line bool is_set_locally : 1; // Has a backup entry bool warning_was_printed : 1; -- cgit v1.2.3 From e65a8d7b61762ddf07825c59a6ebd47b026b0ea7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 30 Aug 2016 23:48:42 +0200 Subject: m_config: pass parent option in m_config_add_option() Instead of just the parent name. This is a minor refactor as preparation for other things. --- options/m_config.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index c98ee6713f..8a4d5998d6 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -174,7 +174,7 @@ static void substruct_write_ptr(void *ptr, void *val) } static void add_options(struct m_config *config, - const char *parent_name, + struct m_config_option *parent, void *optstruct, const void *optstruct_def, const struct m_option *defs); @@ -202,7 +202,7 @@ struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log, memcpy(config->optstruct, defaults, size); } if (options) - add_options(config, "", config->optstruct, defaults, options); + add_options(config, NULL, config->optstruct, defaults, options); return config; } @@ -344,19 +344,19 @@ static void add_negation_option(struct m_config *config, } static void m_config_add_option(struct m_config *config, - const char *parent_name, + struct m_config_option *parent, void *optstruct, const void *optstruct_def, const struct m_option *arg); static void add_options(struct m_config *config, - const char *parent_name, + struct m_config_option *parent, void *optstruct, const void *optstruct_def, const struct m_option *defs) { for (int i = 0; defs && defs[i].name; i++) - m_config_add_option(config, parent_name, optstruct, optstruct_def, &defs[i]); + m_config_add_option(config, parent, optstruct, optstruct_def, &defs[i]); } // Initialize a field with a given value. In case this is dynamic data, it has @@ -372,7 +372,7 @@ static void init_opt_inplace(const struct m_option *opt, void *dst, } static void m_config_add_option(struct m_config *config, - const char *parent_name, + struct m_config_option *parent, void *optstruct, const void *optstruct_def, const struct m_option *arg) @@ -380,6 +380,8 @@ static void m_config_add_option(struct m_config *config, assert(config != NULL); assert(arg != NULL); + const char *parent_name = parent ? parent->name : ""; + struct m_config_option co = { .opt = arg, .name = arg->name, @@ -419,8 +421,7 @@ static void m_config_add_option(struct m_config *config, if (!new_optstruct_def) new_optstruct_def = subopts->defaults; - add_options(config, co.name, new_optstruct, - new_optstruct_def, subopts->opts); + add_options(config, &co, new_optstruct, new_optstruct_def, subopts->opts); } else { // Initialize options if (co.data && co.default_data) { @@ -451,7 +452,7 @@ static void m_config_add_option(struct m_config *config, new->priv = talloc_strdup(config, no_alias); new->type = &m_option_type_alias; new->offset = -1; - m_config_add_option(config, "", NULL, NULL, new); + m_config_add_option(config, NULL, NULL, NULL, new); } } -- cgit v1.2.3 From af1379c43d6a5274b75bce0adeef9e3a9ce87bdf Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 30 Aug 2016 23:50:57 +0200 Subject: options: make mp_vo_opts options an actual sub-option group Just a minor refactor along the planned option change. This commit will make it easier to update (i.e. copy) the VO options without copying _all_ options. For now, behavior should be equivalent, though. (The VO options were put into a separate struct quite early - when all global variables were removed from the source code. It wasn't clear whether the separate struct would have any actual purpose, but it seems it will now. Awesome, huh.) --- options/options.c | 145 +++++++++++++++++++++++++++++------------------------- options/options.h | 2 +- 2 files changed, 78 insertions(+), 69 deletions(-) (limited to 'options') diff --git a/options/options.c b/options/options.c index 129f0cc53c..dc880d3339 100644 --- a/options/options.c +++ b/options/options.c @@ -97,6 +97,81 @@ const struct m_opt_choice_alternatives mp_hwdec_names[] = { {0} }; +#define OPT_BASE_STRUCT struct mp_vo_opts + +static const m_option_t mp_vo_opt_list[] = { + OPT_SETTINGSLIST("vo", video_driver_list, 0, &vo_obj_list), + OPT_SETTINGSLIST("vo-defaults", vo_defs, 0, &vo_obj_list), + OPT_CHOICE_C("hwdec-preload", hwdec_preload_api, 0, mp_hwdec_names), + OPT_SUBSTRUCT("sws", sws_opts, sws_conf, 0), + OPT_FLAG("taskbar-progress", taskbar_progress, 0), + OPT_FLAG("ontop", ontop, M_OPT_FIXED), + OPT_FLAG("border", border, M_OPT_FIXED), + OPT_FLAG("fit-border", fit_border, M_OPT_FIXED), + OPT_FLAG("on-all-workspaces", all_workspaces, M_OPT_FIXED), + OPT_GEOMETRY("geometry", geometry, 0), + OPT_SIZE_BOX("autofit", autofit, 0), + OPT_SIZE_BOX("autofit-larger", autofit_larger, 0), + OPT_SIZE_BOX("autofit-smaller", autofit_smaller, 0), + OPT_FLOATRANGE("window-scale", window_scale, 0, 0.001, 100), + OPT_FLAG("force-window-position", force_window_position, 0), + OPT_STRING("x11-name", winname, 0), + OPT_FLOATRANGE("monitoraspect", force_monitor_aspect, 0, 0.0, 9.0), + OPT_FLOATRANGE("monitorpixelaspect", monitor_pixel_aspect, 0, 0.2, 9.0), + OPT_FLAG("fullscreen", fullscreen, M_OPT_FIXED), + OPT_FLAG("fs", fullscreen, M_OPT_FIXED), + OPT_FLAG("native-keyrepeat", native_keyrepeat, M_OPT_FIXED), + OPT_FLOATRANGE("panscan", panscan, 0, 0.0, 1.0), + OPT_FLOATRANGE("video-zoom", zoom, 0, -20.0, 20.0), + OPT_FLOATRANGE("video-pan-x", pan_x, 0, -3.0, 3.0), + OPT_FLOATRANGE("video-pan-y", pan_y, 0, -3.0, 3.0), + OPT_FLOATRANGE("video-align-x", align_x, 0, -1.0, 1.0), + OPT_FLOATRANGE("video-align-y", align_y, 0, -1.0, 1.0), + OPT_CHOICE("video-unscaled", unscaled, 0, + ({"no", 0}, {"yes", 1}, {"downscale-big", 2})), + OPT_INT64("wid", WinID, 0), + OPT_CHOICE_OR_INT("screen", screen_id, 0, 0, 32, + ({"default", -1})), + OPT_CHOICE_OR_INT("fs-screen", fsscreen_id, 0, 0, 32, + ({"all", -2}, {"current", -1})), + OPT_FLAG("fs-black-out-screens", fs_black_out_screens, 0), + OPT_FLAG("keepaspect", keepaspect, 0), + OPT_FLAG("keepaspect-window", keepaspect_window, 0), +#if HAVE_X11 + OPT_CHOICE("x11-netwm", x11_netwm, 0, + ({"auto", 0}, {"no", -1}, {"yes", 1})), + OPT_CHOICE("x11-bypass-compositor", x11_bypass_compositor, 0, + ({"no", 0}, {"yes", 1}, {"fs-only", 2}, {"never", 3})), +#endif +#if HAVE_WIN32 + OPT_STRING("vo-mmcss-profile", mmcss_profile, M_OPT_FIXED), +#endif + + {0} +}; + +static const struct m_sub_options vo_sub_opts = { + .opts = mp_vo_opt_list, + .size = sizeof(struct mp_vo_opts), + .defaults = &(const struct mp_vo_opts){ + .video_driver_list = NULL, + .monitor_pixel_aspect = 1.0, + .screen_id = -1, + .fsscreen_id = -1, + .panscan = 0.0f, + .keepaspect = 1, + .keepaspect_window = 1, + .taskbar_progress = 1, + .border = 1, + .fit_border = 1, + .WinID = -1, + .window_scale = 1.0, + .x11_bypass_compositor = 2, + .mmcss_profile = "Playback", + }, +}; + +#undef OPT_BASE_STRUCT #define OPT_BASE_STRUCT struct MPOpts const m_option_t mp_opts[] = { @@ -313,14 +388,11 @@ const m_option_t mp_opts[] = { OPT_FLAG("ad-spdif-dtshd", dtshd, 0), OPT_CHOICE_C("hwdec", hwdec_api, 0, mp_hwdec_names), - OPT_CHOICE_C("hwdec-preload", vo.hwdec_preload_api, 0, mp_hwdec_names), OPT_STRING("hwdec-codecs", hwdec_codecs, 0), #if HAVE_VIDEOTOOLBOX_HWACCEL OPT_IMAGEFORMAT("videotoolbox-format", videotoolbox_format, 0), #endif - OPT_SUBSTRUCT("sws", vo.sws_opts, sws_conf, 0), - // -1 means auto aspect (prefer container size until aspect change) // 0 means square pixels OPT_FLOATRANGE("video-aspect", movie_aspect, 0, -1.0, 10.0), @@ -393,8 +465,6 @@ const m_option_t mp_opts[] = { OPT_FLAG("sub-clear-on-seek", sub_clear_on_seek, 0), //---------------------- libao/libvo options ------------------------ - OPT_SETTINGSLIST("vo", vo.video_driver_list, 0, &vo_obj_list), - OPT_SETTINGSLIST("vo-defaults", vo.vo_defs, 0, &vo_obj_list), OPT_SETTINGSLIST("ao", audio_driver_list, 0, &ao_obj_list), OPT_SETTINGSLIST("ao-defaults", ao_defs, 0, &ao_obj_list), OPT_STRING("audio-device", audio_device, 0), @@ -404,11 +474,6 @@ const m_option_t mp_opts[] = { OPT_FLOATRANGE("audio-wait-open", audio_wait_open, 0, 0, 60), OPT_CHOICE("force-window", force_vo, 0, ({"no", 0}, {"yes", 1}, {"immediate", 2})), - OPT_FLAG("taskbar-progress", vo.taskbar_progress, 0), - OPT_FLAG("ontop", vo.ontop, M_OPT_FIXED), - OPT_FLAG("border", vo.border, M_OPT_FIXED), - OPT_FLAG("fit-border", vo.fit_border, M_OPT_FIXED), - OPT_FLAG("on-all-workspaces", vo.all_workspaces, M_OPT_FIXED), OPT_FLAG("window-dragging", allow_win_drag, CONF_GLOBAL), @@ -431,31 +496,9 @@ const m_option_t mp_opts[] = { .min = 0, .max = 10), OPT_FLOATRANGE("balance", balance, 0, -1, 1), - OPT_GEOMETRY("geometry", vo.geometry, 0), - OPT_SIZE_BOX("autofit", vo.autofit, 0), - OPT_SIZE_BOX("autofit-larger", vo.autofit_larger, 0), - OPT_SIZE_BOX("autofit-smaller", vo.autofit_smaller, 0), - OPT_FLOATRANGE("window-scale", vo.window_scale, 0, 0.001, 100), - OPT_FLAG("force-window-position", vo.force_window_position, 0), - // vo name (X classname) and window title strings - OPT_STRING("x11-name", vo.winname, 0), OPT_STRING("title", wintitle, 0), OPT_STRING("force-media-title", media_title, 0), // set aspect ratio of monitor - useful for 16:9 TV-out - OPT_FLOATRANGE("monitoraspect", vo.force_monitor_aspect, 0, 0.0, 9.0), - OPT_FLOATRANGE("monitorpixelaspect", vo.monitor_pixel_aspect, 0, 0.2, 9.0), - // start in fullscreen mode: - OPT_FLAG("fullscreen", vo.fullscreen, M_OPT_FIXED), - OPT_FLAG("fs", vo.fullscreen, M_OPT_FIXED), - OPT_FLAG("native-keyrepeat", vo.native_keyrepeat, M_OPT_FIXED), - OPT_FLOATRANGE("panscan", vo.panscan, 0, 0.0, 1.0), - OPT_FLOATRANGE("video-zoom", vo.zoom, 0, -20.0, 20.0), - OPT_FLOATRANGE("video-pan-x", vo.pan_x, 0, -3.0, 3.0), - OPT_FLOATRANGE("video-pan-y", vo.pan_y, 0, -3.0, 3.0), - OPT_FLOATRANGE("video-align-x", vo.align_x, 0, -1.0, 1.0), - OPT_FLOATRANGE("video-align-y", vo.align_y, 0, -1.0, 1.0), - OPT_CHOICE("video-unscaled", vo.unscaled, 0, - ({"no", 0}, {"yes", 1}, {"downscale-big", 2})), OPT_FLAG("force-rgba-osd-rendering", force_rgba_osd, 0), OPT_CHOICE_OR_INT("video-rotate", video_rotate, 0, 0, 359, ({"no", -1})), @@ -466,28 +509,10 @@ const m_option_t mp_opts[] = { OPT_FLAG("cursor-autohide-fs-only", cursor_autohide_fs, 0), OPT_FLAG("stop-screensaver", stop_screensaver, 0), - OPT_INT64("wid", vo.WinID, 0), -#if HAVE_X11 - OPT_CHOICE("x11-netwm", vo.x11_netwm, 0, - ({"auto", 0}, {"no", -1}, {"yes", 1})), - OPT_CHOICE("x11-bypass-compositor", vo.x11_bypass_compositor, 0, - ({"no", 0}, {"yes", 1}, {"fs-only", 2}, {"never", 3})), -#endif -#if HAVE_WIN32 - OPT_STRING("vo-mmcss-profile", vo.mmcss_profile, M_OPT_FIXED), -#endif - OPT_STRING("heartbeat-cmd", heartbeat_cmd, 0, .deprecation_message = "use Lua scripting instead"), OPT_FLOAT("heartbeat-interval", heartbeat_interval, CONF_MIN, 0), - OPT_CHOICE_OR_INT("screen", vo.screen_id, 0, 0, 32, - ({"default", -1})), - - OPT_CHOICE_OR_INT("fs-screen", vo.fsscreen_id, 0, 0, 32, - ({"all", -2}, {"current", -1})), - - OPT_FLAG("fs-black-out-screens", vo.fs_black_out_screens, 0), OPT_INTRANGE("brightness", gamma_brightness, 0, -100, 100), OPT_INTRANGE("saturation", gamma_saturation, 0, -100, 100), OPT_INTRANGE("contrast", gamma_contrast, 0, -100, 100), @@ -495,8 +520,6 @@ const m_option_t mp_opts[] = { OPT_INTRANGE("gamma", gamma_gamma, 0, -100, 100), OPT_CHOICE_C("video-output-levels", video_output_levels, 0, mp_csp_levels_names), - OPT_FLAG("keepaspect", vo.keepaspect, 0), - OPT_FLAG("keepaspect-window", vo.keepaspect_window, 0), OPT_FLAG("use-filedir-conf", use_filedir_conf, 0), OPT_CHOICE("osd-level", osd_level, 0, @@ -614,6 +637,8 @@ const m_option_t mp_opts[] = { OPT_PRINT("version", print_version), OPT_PRINT("V", print_version), + OPT_SUBSTRUCT("", vo, vo_sub_opts, 0), + #if HAVE_ENCODING OPT_SUBSTRUCT("", encode_opts, encode_config, 0), #endif @@ -715,22 +740,6 @@ const struct MPOpts mp_default_opts = { .audio_buffer = 0.2, .audio_device = "auto", .audio_client_name = "mpv", - .vo = { - .video_driver_list = NULL, - .monitor_pixel_aspect = 1.0, - .screen_id = -1, - .fsscreen_id = -1, - .panscan = 0.0f, - .keepaspect = 1, - .keepaspect_window = 1, - .taskbar_progress = 1, - .border = 1, - .fit_border = 1, - .WinID = -1, - .window_scale = 1.0, - .x11_bypass_compositor = 2, - .mmcss_profile = "Playback", - }, .allow_win_drag = 1, .wintitle = "${?media-title:${media-title}}${!media-title:No file} - mpv", .heartbeat_interval = 30.0, diff --git a/options/options.h b/options/options.h index 187abc2c1a..130ab4c1cf 100644 --- a/options/options.h +++ b/options/options.h @@ -98,7 +98,7 @@ typedef struct MPOpts { int gapless_audio; double audio_buffer; - mp_vo_opts vo; + mp_vo_opts *vo; int allow_win_drag; char *wintitle; -- cgit v1.2.3 From ce8dae3f0d9d269fc925f3a83abde4cde3b36ebb Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 31 Aug 2016 15:25:22 +0200 Subject: m_property: remove pointless explicitly clamping This is basically dead code, and even the commit that added this code 4 years ago said that this should be for debugging only. (Though it is possible that the clamp callback was used for something else, and then unused again. Also, some of the clamping code remains and is used for internal checking, e.g. clamp_double().) --- options/m_option.c | 47 ----------------------------------------------- options/m_option.h | 7 ------- options/m_property.c | 9 --------- 3 files changed, 63 deletions(-) (limited to 'options') diff --git a/options/m_option.c b/options/m_option.c index 94dab9f59f..45709b9c16 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -133,14 +133,6 @@ static void copy_opt(const m_option_t *opt, void *dst, const void *src) #define VAL(x) (*(int *)(x)) -static int clamp_flag(const m_option_t *opt, void *val) -{ - if (VAL(val) == 0 || VAL(val) == 1) - return 0; - VAL(val) = 0; - return M_OPT_OUT_OF_RANGE; -} - static int parse_flag(struct mp_log *log, const m_option_t *opt, struct bstr name, struct bstr param, void *dst) { @@ -202,7 +194,6 @@ const m_option_type_t m_option_type_flag = { .print = print_flag, .copy = copy_opt, .add = add_flag, - .clamp = clamp_flag, .set = flag_set, .get = flag_get, }; @@ -336,14 +327,6 @@ static int parse_longlong(struct mp_log *log, const m_option_t *opt, return 1; } -static int clamp_int(const m_option_t *opt, void *val) -{ - long long tmp = *(int *)val; - int r = clamp_longlong(opt, &tmp); - *(int *)val = tmp; - return r; -} - static int clamp_int64(const m_option_t *opt, void *val) { long long tmp = *(int64_t *)val; @@ -475,7 +458,6 @@ const m_option_type_t m_option_type_int = { .copy = copy_opt, .add = add_int, .multiply = multiply_int, - .clamp = clamp_int, .set = int_set, .get = int_get, }; @@ -488,7 +470,6 @@ const m_option_type_t m_option_type_int64 = { .copy = copy_opt, .add = add_int64, .multiply = multiply_int64, - .clamp = clamp_int64, .set = int64_set, .get = int64_get, }; @@ -546,21 +527,6 @@ const char *m_opt_choice_str(const struct m_opt_choice_alternatives *choices, return NULL; } -static int clamp_choice(const m_option_t *opt, void *val) -{ - int v = *(int *)val; - if ((opt->flags & M_OPT_MIN) && (opt->flags & M_OPT_MAX)) { - if (v >= opt->min && v <= opt->max) - return 0; - } - ; - for (struct m_opt_choice_alternatives *alt = opt->priv; alt->name; alt++) { - if (alt->value == v) - return 0; - } - return M_OPT_INVALID; -} - static int parse_choice(struct mp_log *log, const struct m_option *opt, struct bstr name, struct bstr param, void *dst) { @@ -750,7 +716,6 @@ const struct m_option_type m_option_type_choice = { .print = print_choice, .copy = copy_opt, .add = add_choice, - .clamp = clamp_choice, .set = choice_set, .get = choice_get, }; @@ -999,7 +964,6 @@ const m_option_type_t m_option_type_double = { .print = print_double, .pretty_print = print_double_f3, .copy = copy_opt, - .clamp = clamp_double, .add = add_double, .multiply = multiply_double, .set = double_set, @@ -1009,14 +973,6 @@ const m_option_type_t m_option_type_double = { #undef VAL #define VAL(x) (*(float *)(x)) -static int clamp_float(const m_option_t *opt, void *val) -{ - double tmp = VAL(val); - int r = clamp_double(opt, &tmp); - VAL(val) = tmp; - return r; -} - static int parse_float(struct mp_log *log, const m_option_t *opt, struct bstr name, struct bstr param, void *dst) { @@ -1078,7 +1034,6 @@ const m_option_type_t m_option_type_float = { .copy = copy_opt, .add = add_float, .multiply = multiply_float, - .clamp = clamp_float, .set = float_set, .get = float_get, }; @@ -1179,7 +1134,6 @@ const m_option_type_t m_option_type_string = { .print = print_str, .copy = copy_str, .free = free_str, - .clamp = clamp_str, .set = str_set, .get = str_get, }; @@ -2462,7 +2416,6 @@ const m_option_type_t m_option_type_time = { .pretty_print = pretty_print_time, .copy = copy_opt, .add = add_double, - .clamp = clamp_double, .set = time_set, .get = time_get, }; diff --git a/options/m_option.h b/options/m_option.h index 847cd1097c..bf7ee5939d 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -291,13 +291,6 @@ struct m_option_type { // to the valid value range of the option. void (*multiply)(const m_option_t *opt, void *val, double f); - // Clamp the value in val to the option's valid value range. - // Return values: - // M_OPT_OUT_OF_RANGE: val was invalid, and modified (clamped) to be valid - // M_OPT_INVALID: val was invalid, and can't be made valid - // 0: val was already valid and is unchanged - int (*clamp)(const m_option_t *opt, void *val); - // Set the option value in dst to the contents of src. // (If the option is dynamic, the old value in *dst has to be freed.) // Return values: diff --git a/options/m_property.c b/options/m_property.c index d0579768c6..4ed4f5f586 100644 --- a/options/m_property.c +++ b/options/m_property.c @@ -125,15 +125,6 @@ int m_property_do(struct mp_log *log, const struct m_property *prop_list, return r; } case M_PROPERTY_SET: { - if (!log) - return M_PROPERTY_ERROR; - m_option_copy(&opt, &val, arg); - r = opt.type->clamp ? opt.type->clamp(&opt, arg) : 0; - m_option_free(&opt, &val); - if (r != 0) { - mp_err(log, "Property '%s': invalid value.\n", name); - return M_PROPERTY_ERROR; - } return do_action(prop_list, name, M_PROPERTY_SET, arg, ctx); } case M_PROPERTY_GET_NODE: { -- cgit v1.2.3 From e024906408c4d079e77b136de9b0562a93daadce Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 31 Aug 2016 16:45:58 +0200 Subject: m_config: handle --no-... options differently Instead of adding "no-"-prefixed aliases to the internal option list, which will act like normal options, do it in the parsing stage. This turns out to be simpler (and cheaper), and avoids adding aliased options. --- options/m_config.c | 97 +++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 53 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 8a4d5998d6..cd18e57b9d 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -298,51 +298,6 @@ void m_config_backup_all_opts(struct m_config *config) ensure_backup(config, &config->opts[n]); } -// Given an option --opt, add --no-opt (if applicable). -static void add_negation_option(struct m_config *config, - struct m_config_option *orig, - const char *parent_name) -{ - const struct m_option *opt = orig->opt; - int value; - if (opt->type == CONF_TYPE_FLAG) { - value = 0; - } else if (opt->type == CONF_TYPE_CHOICE) { - // Find out whether there's a "no" choice. - // m_option_parse() should be used for this, but it prints - // unsilenceable error messages. - struct m_opt_choice_alternatives *alt = opt->priv; - for ( ; alt->name; alt++) { - if (strcmp(alt->name, "no") == 0) - break; - } - if (!alt->name) - return; - value = alt->value; - } else { - return; - } - struct m_option *no_opt = talloc_ptrtype(config, no_opt); - *no_opt = (struct m_option) { - .name = opt->name, - .type = CONF_TYPE_STORE, - .flags = opt->flags & (M_OPT_NOCFG | M_OPT_GLOBAL | M_OPT_PRE_PARSE), - .offset = opt->offset, - .max = value, - }; - // Add --no-sub-opt - struct m_config_option co = *orig; - co.name = talloc_asprintf(config, "no-%s", orig->name); - co.opt = no_opt; - co.is_hidden = true; - MP_TARRAY_APPEND(config, config->opts, config->num_opts, co); - // Add --sub-no-opt (unfortunately needed for: "--sub=...:no-opt") - if (parent_name[0]) { - co.name = talloc_asprintf(config, "%s-no-%s", parent_name, opt->name); - MP_TARRAY_APPEND(config, config->opts, config->num_opts, co); - } -} - static void m_config_add_option(struct m_config *config, struct m_config_option *parent, void *optstruct, @@ -439,8 +394,6 @@ static void m_config_add_option(struct m_config *config, if (arg->name[0]) // no own name -> hidden MP_TARRAY_APPEND(config, config->opts, config->num_opts, co); - add_negation_option(config, &co, parent_name); - if (co.opt->type == &m_option_type_alias) { co.is_hidden = true; const char *alias = (const char *)co.opt->priv; @@ -610,14 +563,42 @@ int m_config_set_option_raw(struct m_config *config, struct m_config_option *co, static int parse_subopts(struct m_config *config, char *name, char *prefix, struct bstr param, int flags); +// Used to turn "--no-foo" into "--foo=no". +static struct m_config_option *m_config_find_negation_opt(struct m_config *config, + struct bstr *name) +{ + assert(!m_config_get_co(config, *name)); + + if (!bstr_eatstart0(name, "no-")) + return NULL; + + struct m_config_option *co = m_config_get_co(config, *name); + + // Not all choice types have this value - if they don't, then parsing them + // will simply result in an error. Good enough. + if (co && co->opt->type != CONF_TYPE_FLAG && + co->opt->type != CONF_TYPE_CHOICE) + co = NULL; + + return co; +} + static int m_config_parse_option(struct m_config *config, struct bstr name, struct bstr param, int flags) { assert(config != NULL); struct m_config_option *co = m_config_get_co(config, name); - if (!co) - return M_OPT_UNKNOWN; + if (!co) { + co = m_config_find_negation_opt(config, &name); + if (!co) + return M_OPT_UNKNOWN; + + if (param.len) + return M_OPT_DISALLOW_PARAM; + + param = bstr0("no"); + } // This is the only mandatory function assert(co->opt->type->parse); @@ -720,12 +701,22 @@ int m_config_set_option(struct m_config *config, struct bstr name, int m_config_set_option_node(struct m_config *config, bstr name, struct mpv_node *data, int flags) { - struct m_config_option *co = m_config_get_co(config, name); - if (!co) - return M_OPT_UNKNOWN; - + struct mpv_node tmp; int r; + struct m_config_option *co = m_config_get_co(config, name); + if (!co) { + co = m_config_find_negation_opt(config, &name); + if (!co) + return M_OPT_UNKNOWN; + if (!(data->format == MPV_FORMAT_STRING && !bstr0(data->u.string).len) && + !(data->format == MPV_FORMAT_FLAG && data->u.flag == 1)) + return M_OPT_INVALID; + tmp.format = MPV_FORMAT_STRING; + tmp.u.string = "no"; + data = &tmp; + } + // 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}; -- cgit v1.2.3 From 7dde096d8a6d9e82cac82bec439fef47d078f352 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 31 Aug 2016 17:09:10 +0200 Subject: m_config: introduce and use OPT_ALIAS for some options OPT_ALIAS redirects the options at a higher level, instead of introducing "duplicate" options with different name but same backing storage. This uses the OPT_REPLACED mechanisms - only the deprecation warning had to be made conditional. Note that e.g. --no-video still works, because the "--no-..." redirection and OPT_ALIAS are orthogonal. The deprecated --sub -> --sub-file alias had to be dropped, because it essentially conflicts with --no-sub. If anyone complains, this could probably still be undone by letting m_config_find_negation_opt do a special mapping for --no-sub. (Which would be dumb, but simple and effective.) --- options/m_config.c | 14 ++++++-------- options/m_option.h | 15 +++++++++++---- options/options.c | 9 ++++----- 3 files changed, 21 insertions(+), 17 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index cd18e57b9d..470951d233 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -362,6 +362,9 @@ static void m_config_add_option(struct m_config *config, co.name = talloc_asprintf(config, "%s-%s", parent_name, co.name); } + if (co.opt->deprecation_message) + co.is_hidden = true; + // Option with children -> add them if (arg->type->flags & M_OPT_TYPE_HAS_CHILD) { const struct m_sub_options *subopts = arg->priv; @@ -395,7 +398,6 @@ static void m_config_add_option(struct m_config *config, MP_TARRAY_APPEND(config, config->opts, config->num_opts, co); if (co.opt->type == &m_option_type_alias) { - co.is_hidden = true; const char *alias = (const char *)co.opt->priv; char no_alias[40]; snprintf(no_alias, sizeof(no_alias), "no-%s", alias); @@ -408,9 +410,6 @@ static void m_config_add_option(struct m_config *config, m_config_add_option(config, NULL, NULL, NULL, new); } } - - if (co.opt->type == &m_option_type_removed) - co.is_hidden = true; } struct m_config_option *m_config_get_co(const struct m_config *config, @@ -434,7 +433,9 @@ struct m_config_option *m_config_get_co(const struct m_config *config, const char *prefix = config->is_toplevel ? "--" : ""; if (co->opt->type == &m_option_type_alias) { const char *alias = (const char *)co->opt->priv; - if (!co->warning_was_printed) { + // deprecation_message is not used, but decides whether it's a + // proper or deprecated alias. + if (co->opt->deprecation_message && !co->warning_was_printed) { MP_WARN(config, "Warning: option %s%s was replaced with " "%s%s and might be removed in the future.\n", prefix, co->name, prefix, alias); @@ -788,9 +789,6 @@ void m_config_print_option_list(const struct m_config *config) continue; if (co->is_hidden) continue; - if (opt->type == &m_option_type_alias || - opt->type == &m_option_type_removed) - continue; MP_INFO(config, " %s%-30s", prefix, co->name); if (opt->type == &m_option_type_choice) { MP_INFO(config, " Choices:"); diff --git a/options/m_option.h b/options/m_option.h index bf7ee5939d..c5385e4241 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -691,13 +691,20 @@ extern const char m_option_path_separator; .type = &m_option_type_subconfig, \ .priv = (void*)&subconf) -// If "--name" was removed, but "--newname" has the same semantics. +// Provide a another name for the option. +#define OPT_ALIAS(optname, newname) \ + {.name = optname, .type = &m_option_type_alias, .priv = newname, \ + .offset = -1} + +// If "--optname" was removed, but "--newname" has the same semantics. // It will be redirected, and a warning will be printed on first use. #define OPT_REPLACED(optname, newname) \ - {.name = optname, .type = &m_option_type_alias, .priv = newname, .offset = -1} + {.name = optname, .type = &m_option_type_alias, .priv = newname, \ + .deprecation_message = "", .offset = -1} -// "--name" doesn't exist, but inform the user about a replacement with msg. +// "--optname" doesn't exist, but inform the user about a replacement with msg. #define OPT_REMOVED(optname, msg) \ - {.name = optname, .type = &m_option_type_removed, .priv = msg, .offset = -1} + {.name = optname, .type = &m_option_type_removed, .priv = msg, \ + .deprecation_message = "", .offset = -1} #endif /* MPLAYER_M_OPTION_H */ diff --git a/options/options.c b/options/options.c index dc880d3339..92eb0fd9c5 100644 --- a/options/options.c +++ b/options/options.c @@ -119,7 +119,7 @@ static const m_option_t mp_vo_opt_list[] = { OPT_FLOATRANGE("monitoraspect", force_monitor_aspect, 0, 0.0, 9.0), OPT_FLOATRANGE("monitorpixelaspect", monitor_pixel_aspect, 0, 0.2, 9.0), OPT_FLAG("fullscreen", fullscreen, M_OPT_FIXED), - OPT_FLAG("fs", fullscreen, M_OPT_FIXED), + OPT_ALIAS("fs", "fullscreen"), OPT_FLAG("native-keyrepeat", native_keyrepeat, M_OPT_FIXED), OPT_FLOATRANGE("panscan", panscan, 0, 0.0, 1.0), OPT_FLOATRANGE("video-zoom", zoom, 0, -20.0, 20.0), @@ -303,9 +303,9 @@ const m_option_t mp_opts[] = { OPT_TRACKCHOICE("ff-aid", stream_id_ff[STREAM_AUDIO]), OPT_TRACKCHOICE("ff-vid", stream_id_ff[STREAM_VIDEO]), OPT_TRACKCHOICE("ff-sid", stream_id_ff[STREAM_SUB]), - OPT_FLAG_STORE("no-sub", stream_id[0][STREAM_SUB], 0, -2), - OPT_FLAG_STORE("no-video", stream_id[0][STREAM_VIDEO], 0, -2), - OPT_FLAG_STORE("no-audio", stream_id[0][STREAM_AUDIO], 0, -2), + OPT_ALIAS("sub", "sid"), + OPT_ALIAS("video", "vid"), + OPT_ALIAS("audio", "aid"), OPT_STRINGLIST("alang", stream_lang[STREAM_AUDIO], 0), OPT_STRINGLIST("slang", stream_lang[STREAM_SUB], 0), @@ -689,7 +689,6 @@ const m_option_t mp_opts[] = { OPT_REPLACED("ss", "start"), OPT_REPLACED("stop-xscreensaver", "stop-screensaver"), OPT_REPLACED("sub-fuzziness", "sub-auto"), - OPT_REPLACED("sub", "sub-file"), OPT_REPLACED("subcp", "sub-codepage"), OPT_REPLACED("subdelay", "sub-delay"), OPT_REPLACED("subfile", "sub-file"), -- cgit v1.2.3 From b10dcecf7d71a076525bc2ac4b6bd72f4c453278 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 31 Aug 2016 17:28:42 +0200 Subject: client API: deprecate "no-..." option handling The client API can do this (and there are apparently some libmpv using projects which rely on this). But it's just unnecessary bloat as it requires a separate code path from the option parser. It would be better to remove this code. Formally deprecate it, including API bump and warning in the API changes file to make it really clear. --- options/m_config.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 470951d233..d1bb72c13b 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -707,6 +707,7 @@ int m_config_set_option_node(struct m_config *config, bstr name, struct m_config_option *co = m_config_get_co(config, name); if (!co) { + bstr orig_name = name; co = m_config_find_negation_opt(config, &name); if (!co) return M_OPT_UNKNOWN; @@ -716,6 +717,12 @@ int m_config_set_option_node(struct m_config *config, bstr name, tmp.format = MPV_FORMAT_STRING; tmp.u.string = "no"; data = &tmp; + + if (!co->warning_was_printed) { + MP_WARN(config, "Option '%.*s': setting 'no-' option via API is " + "deprecated and will stop working.\n", BSTR_P(orig_name)); + co->warning_was_printed = true; + } } // Do this on an "empty" type to make setting the option strictly overwrite -- cgit v1.2.3 From 2057209057555dc138422daa354fe8db816c629c Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 31 Aug 2016 17:39:30 +0200 Subject: m_config: deprecate top-level suboptions This is a really old weird MPlayer feature. While the MPlayer requires you to use the sub-option syntax in these cases, mpv "flattens" them to normal options. The still-supported alternate sub-option syntax remains a weird artifact that hopefully nobody uses. For example you can do "-sub-text font=Foo:color=0.5" instead of using "--sub-text-font=Foo --sub-text-color=0.5". For --sub-text this is an accidental feature, but it used to be documented for --demuxer-rawaudio and some others. This should just be removed, but for now only print a warning to preempt complaints from weird users wanting this feature back. --- options/m_config.c | 5 +++++ options/m_config.h | 2 ++ 2 files changed, 7 insertions(+) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index d1bb72c13b..4912b21cf6 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -626,6 +626,11 @@ static int m_config_parse_option(struct m_config *config, struct bstr name, // Option with children are a bit different to parse if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) { char prefix[110]; + if (!config->subopt_deprecation_warning) { + MP_WARN(config, "Suboptions (--%.*s=...) are deprecated. Use " + "flat options instead.\n", BSTR_P(name)); + config->subopt_deprecation_warning = true; + } assert(strlen(co->name) < 100); sprintf(prefix, "%s-", co->name); return parse_subopts(config, (char *)co->name, prefix, param, flags); diff --git a/options/m_config.h b/options/m_config.h index af8ab421f0..0d8b7961d0 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -77,6 +77,8 @@ typedef struct m_config { // For the command line parser int recursion_depth; + bool subopt_deprecation_warning; + void *optstruct; // struct mpopts or other } m_config_t; -- cgit v1.2.3 From c55d85992078e465f9e0b7b6998ccdc5f5e77703 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 31 Aug 2016 18:10:11 +0200 Subject: m_option: replace --no-video-aspect alias Instead, add a hacky OPT_ASPECT option type, which only exists to accept a "no" parameter, which in combination with the "--no-..." handling code makes --no-video-aspect work again. We can also remove the code in m_config.c, which only existed to make "--no-aspect" (a deprecated alias) to work. --- options/m_config.c | 17 ++------------- options/m_option.c | 63 +++++++++++++++++++++--------------------------------- options/m_option.h | 10 ++++----- options/options.c | 3 +-- 4 files changed, 31 insertions(+), 62 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 4912b21cf6..b5cef17fd8 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -396,20 +396,6 @@ static void m_config_add_option(struct m_config *config, if (arg->name[0]) // no own name -> hidden MP_TARRAY_APPEND(config, config->opts, config->num_opts, co); - - if (co.opt->type == &m_option_type_alias) { - const char *alias = (const char *)co.opt->priv; - char no_alias[40]; - snprintf(no_alias, sizeof(no_alias), "no-%s", alias); - if (m_config_get_co(config, bstr0(no_alias))) { - struct m_option *new = talloc_zero(config, struct m_option); - new->name = talloc_asprintf(config, "no-%s", co.name); - new->priv = talloc_strdup(config, no_alias); - new->type = &m_option_type_alias; - new->offset = -1; - m_config_add_option(config, NULL, NULL, NULL, new); - } - } } struct m_config_option *m_config_get_co(const struct m_config *config, @@ -578,7 +564,8 @@ static struct m_config_option *m_config_find_negation_opt(struct m_config *confi // Not all choice types have this value - if they don't, then parsing them // will simply result in an error. Good enough. if (co && co->opt->type != CONF_TYPE_FLAG && - co->opt->type != CONF_TYPE_CHOICE) + co->opt->type != CONF_TYPE_CHOICE && + co->opt->type != &m_option_type_aspect) co = NULL; return co; diff --git a/options/m_option.c b/options/m_option.c index 45709b9c16..cc8d818eec 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -234,45 +234,6 @@ const m_option_type_t m_option_type_store = { .set = store_set, }; -// Same for float types - -#undef VAL -#define VAL(x) (*(float *)(x)) - -static int parse_store_float(struct mp_log *log, const m_option_t *opt, - struct bstr name, struct bstr param, void *dst) -{ - if (param.len == 0) { - if (dst) - VAL(dst) = opt->max; - return 0; - } else { - mp_err(log, "Invalid parameter for %.*s flag: %.*s\n", - BSTR_P(name), BSTR_P(param)); - return M_OPT_DISALLOW_PARAM; - } -} - -static int store_float_set(const m_option_t *opt, void *dst, struct mpv_node *src) -{ - if (src->format != MPV_FORMAT_FLAG) - return M_OPT_UNKNOWN; - if (!src->u.flag) - return M_OPT_INVALID; - VAL(dst) = opt->max; - return 1; -} - -const m_option_type_t m_option_type_float_store = { - // can only be activated - .name = "Flag", - .size = sizeof(float), - .flags = M_OPT_TYPE_OPTIONAL_PARAM, - .parse = parse_store_float, - .copy = copy_opt, - .set = store_float_set, -}; - // Integer #undef VAL @@ -1038,6 +999,30 @@ const m_option_type_t m_option_type_float = { .get = float_get, }; +static int parse_float_aspect(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) +{ + if (bstr_equals0(param, "no")) { + if (dst) + VAL(dst) = 0.0f; + return 1; + } + return parse_float(log, opt, name, param, dst); +} + +const m_option_type_t m_option_type_aspect = { + .name = "Aspect", + .size = sizeof(float), + .parse = parse_float_aspect, + .print = print_float, + .pretty_print = print_float_f3, + .copy = copy_opt, + .add = add_float, + .multiply = multiply_float, + .set = float_set, + .get = float_get, +}; + ///////////// String #undef VAL diff --git a/options/m_option.h b/options/m_option.h index c5385e4241..17c2d4e451 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -38,7 +38,6 @@ struct mpv_node; // Simple types extern const m_option_type_t m_option_type_flag; extern const m_option_type_t m_option_type_store; -extern const m_option_type_t m_option_type_float_store; extern const m_option_type_t m_option_type_int; extern const m_option_type_t m_option_type_int64; extern const m_option_type_t m_option_type_intpair; @@ -62,6 +61,7 @@ extern const m_option_type_t m_option_type_color; extern const m_option_type_t m_option_type_geometry; extern const m_option_type_t m_option_type_size_box; extern const m_option_type_t m_option_type_channels; +extern const m_option_type_t m_option_type_aspect; extern const m_option_type_t m_option_type_node; // Used internally by m_config.c @@ -207,7 +207,6 @@ struct m_sub_options { union m_option_value { int flag; // not the C type "bool"! int store; - float float_store; int int_; int64_t int64; int intpair[2]; @@ -562,10 +561,6 @@ extern const char m_option_path_separator; OPT_GENERAL(int, optname, varname, flags, .max = value, \ .type = &m_option_type_store) -#define OPT_FLOAT_STORE(optname, varname, flags, value) \ - OPT_GENERAL(float, optname, varname, flags, .max = value, \ - .type = &m_option_type_float_store) - #define OPT_STRINGLIST(...) \ OPT_GENERAL(char**, __VA_ARGS__, .type = &m_option_type_string_list) @@ -667,6 +662,9 @@ extern const char m_option_path_separator; #define OPT_TRACKCHOICE(name, var) \ OPT_CHOICE_OR_INT(name, var, 0, 0, 8190, ({"no", -2}, {"auto", -1})) +#define OPT_ASPECT(...) \ + OPT_GENERAL(float, __VA_ARGS__, .type = &m_option_type_aspect) + #define OPT_STRING_VALIDATE_(optname, varname, flags, validate_fn, ...) \ OPT_GENERAL(char*, optname, varname, flags, __VA_ARGS__, \ .priv = MP_EXPECT_TYPE(m_opt_string_validate_fn, validate_fn)) diff --git a/options/options.c b/options/options.c index 92eb0fd9c5..7b0f3c43e1 100644 --- a/options/options.c +++ b/options/options.c @@ -395,8 +395,7 @@ const m_option_t mp_opts[] = { // -1 means auto aspect (prefer container size until aspect change) // 0 means square pixels - OPT_FLOATRANGE("video-aspect", movie_aspect, 0, -1.0, 10.0), - OPT_FLOAT_STORE("no-video-aspect", movie_aspect, 0, 0.0), + OPT_ASPECT("video-aspect", movie_aspect, 0, -1.0, 10.0), OPT_CHOICE("video-aspect-method", aspect_method, 0, ({"hybrid", 0}, {"bitstream", 1}, {"container", 2})), -- cgit v1.2.3 From 7539928c1c8a12f030da4de4b8be0f697a122212 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 31 Aug 2016 18:17:42 +0200 Subject: m_config: remove some aliasing checks We strictly assume no aliasing (the previous commit removed the last case), so remove the checks. --- options/m_config.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index b5cef17fd8..1c2541a2c6 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -382,16 +382,8 @@ static void m_config_add_option(struct m_config *config, add_options(config, &co, new_optstruct, new_optstruct_def, subopts->opts); } else { // Initialize options - if (co.data && co.default_data) { - if (arg->type->free) { - // Would leak memory by overwriting *co.data repeatedly. - for (int i = 0; i < config->num_opts; i++) { - if (co.data == config->opts[i].data) - assert(0); - } - } + if (co.data && co.default_data) init_opt_inplace(arg, co.data, co.default_data); - } } if (arg->name[0]) // no own name -> hidden @@ -510,17 +502,8 @@ static int handle_set_opt_flags(struct m_config *config, static void handle_on_set(struct m_config *config, struct m_config_option *co, int flags) { - if (flags & M_SETOPT_FROM_CMDLINE) { + if (flags & M_SETOPT_FROM_CMDLINE) co->is_set_from_cmdline = true; - // Mark aliases too - if (co->data) { - for (int n = 0; n < config->num_opts; n++) { - struct m_config_option *co2 = &config->opts[n]; - if (co2->data == co->data) - co2->is_set_from_cmdline = true; - } - } - } if (config->global && (co->opt->flags & M_OPT_TERM)) mp_msg_update_msglevels(config->global); -- cgit v1.2.3 From e22ae2cba0cbca7c773e9ac29e57c48b689fae41 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 31 Aug 2016 22:22:02 +0200 Subject: m_config: remove an unused function Well, almost unused. --- options/m_config.c | 22 ++++++---------------- options/m_config.h | 8 -------- 2 files changed, 6 insertions(+), 24 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 1c2541a2c6..e5600228da 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -725,24 +725,14 @@ int m_config_set_option_node(struct m_config *config, bstr name, return r; } -const struct m_option *m_config_get_option(const struct m_config *config, - struct bstr name) -{ - assert(config != NULL); - - struct m_config_option *co = m_config_get_co(config, name); - return co ? co->opt : NULL; -} - int m_config_option_requires_param(struct m_config *config, bstr name) { - const struct m_option *opt = m_config_get_option(config, name); - if (opt) { - if (bstr_endswith0(name, "-clr")) - return 0; - return m_option_required_params(opt); - } - return M_OPT_UNKNOWN; + struct m_config_option *co = m_config_get_co(config, name); + if (!co) + return M_OPT_UNKNOWN; + if (bstr_endswith0(name, "-clr")) + return 0; + return m_option_required_params(co->opt); } static int sort_opt_compare(const void *pa, const void *pb) diff --git a/options/m_config.h b/options/m_config.h index 0d8b7961d0..e6d093582f 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -173,14 +173,6 @@ int m_config_set_option_node(struct m_config *config, bstr name, int m_config_parse_suboptions(struct m_config *config, char *name, char *subopts); - -/* Get the option matching the given name. - * \param config The config object. - * \param name The option's name. - */ -const struct m_option *m_config_get_option(const struct m_config *config, - struct bstr name); - struct m_config_option *m_config_get_co(const struct m_config *config, struct bstr name); -- cgit v1.2.3 From 6b4f560f3ccca0f7db345bd7a6ed65e9307b432d Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 1 Sep 2016 14:21:32 +0200 Subject: vo, ao: disable positional parameter suboptions Positional parameters cause problems because they can be ambiguous with flag options. If a flag option is removed or turned into a non-flag option, it'll usually be interpreted as value for the first sub-option (as positional parameter), resulting in very confusing error messages. This changes it into a simple "option not found" error. I don't expect that anyone really used positional parameters with --vo or --ao. Although the docs for --ao=pulse seem to encourage positional parameters for the host/sink options, which means it could possibly annoy some PulseAudio users. --vf and --af are still mostly used with positional parameters, so this must be a configurable option in the option parser. --- options/m_option.c | 16 +++++++++------- options/m_option.h | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'options') diff --git a/options/m_option.c b/options/m_option.c index cc8d818eec..a44ca0012d 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -2648,7 +2648,8 @@ static void copy_obj_settings_list(const m_option_t *opt, void *dst, // without '=' sets a flag, or whether it's a positional argument. static int get_obj_param(struct mp_log *log, bstr opt_name, bstr obj_name, struct m_config *config, bstr name, bstr val, - int flags, int *nold, bstr *out_name, bstr *out_val) + int flags, bool nopos, + int *nold, bstr *out_name, bstr *out_val) { int r; @@ -2658,7 +2659,7 @@ static int get_obj_param(struct mp_log *log, bstr opt_name, bstr obj_name, // va.start != NULL => of the form name=val (not positional) // If it's just "name", and the associated option exists and is a flag, // don't accept it as positional argument. - if (val.start || m_config_option_requires_param(config, name) == 0) { + if (val.start || m_config_option_requires_param(config, name) == 0 || nopos) { r = m_config_set_option_ext(config, name, val, flags); if (r < 0) { if (r == M_OPT_UNKNOWN) { @@ -2714,7 +2715,7 @@ static int get_obj_param(struct mp_log *log, bstr opt_name, bstr obj_name, // desc is optional. static int m_obj_parse_sub_config(struct mp_log *log, struct bstr opt_name, struct bstr name, struct bstr *pstr, - struct m_config *config, int flags, + struct m_config *config, int flags, bool nopos, struct m_obj_desc *desc, char ***ret) { int nold = 0; @@ -2735,8 +2736,8 @@ static int m_obj_parse_sub_config(struct mp_log *log, struct bstr opt_name, goto exit; if (bstr_equals0(fname, "help")) goto print_help; - r = get_obj_param(log, opt_name, name, config, fname, fval, flags, &nold, - &fname, &fval); + r = get_obj_param(log, opt_name, name, config, fname, fval, flags, + nopos, &nold, &fname, &fval); if (r < 0) goto exit; @@ -2791,6 +2792,7 @@ static int parse_obj_settings(struct mp_log *log, struct bstr opt, char **plist = NULL; struct m_obj_desc desc; bstr label = {0}; + bool nopos = list->disallow_positional_parameters; if (bstr_eatstart0(pstr, "@")) { if (!bstr_split_tok(*pstr, ":", &label, pstr)) { @@ -2826,7 +2828,7 @@ static int parse_obj_settings(struct mp_log *log, struct bstr opt, struct m_config *config = m_config_from_o