diff options
Diffstat (limited to 'options')
-rw-r--r-- | options/m_config.c | 51 | ||||
-rw-r--r-- | options/m_option.c | 46 | ||||
-rw-r--r-- | options/m_option.h | 4 | ||||
-rw-r--r-- | options/m_property.c | 17 | ||||
-rw-r--r-- | options/m_property.h | 2 | ||||
-rw-r--r-- | options/options.c | 13 | ||||
-rw-r--r-- | options/options.h | 2 |
7 files changed, 103 insertions, 32 deletions
diff --git a/options/m_config.c b/options/m_config.c index d58c406ed8..a3dcb30067 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -358,6 +358,18 @@ static void add_options(struct m_config *config, m_config_add_option(config, parent_name, optstruct, optstruct_def, &defs[i]); } +// Initialize a field with a given value. In case this is dynamic data, it has +// to be allocated and copied. src can alias dst, also can be NULL. +static void init_opt_inplace(const struct m_option *opt, void *dst, + const void *src) +{ + union m_option_value temp = {0}; + if (src) + memcpy(&temp, src, opt->type->size); + memset(dst, 0, opt->type->size); + m_option_copy(opt, dst, &temp); +} + static void m_config_add_option(struct m_config *config, const char *parent_name, void *optstruct, @@ -418,11 +430,7 @@ static void m_config_add_option(struct m_config *config, assert(0); } } - // In case this is dynamic data, it has to be allocated and copied. - union m_option_value temp = {0}; - memcpy(&temp, co.default_data, arg->type->size); - memset(co.data, 0, arg->type->size); - m_option_copy(arg, co.data, &temp); + init_opt_inplace(arg, co.data, co.default_data); } } @@ -942,24 +950,39 @@ static void free_substruct(void *ptr) } } +// Passing ptr==NULL initializes it from proper defaults. void *m_sub_options_copy(void *talloc_ctx, const struct m_sub_options *opts, const void *ptr) { - void *new = talloc_zero_size(talloc_ctx, opts->size); + void *new = m_config_alloc_struct(talloc_ctx, opts); struct dtor_info *dtor = talloc_ptrtype(new, dtor); *dtor = (struct dtor_info){opts, new}; talloc_set_destructor(dtor, free_substruct); - // also fill/initialize members not described by opts - if (opts->defaults) - memcpy(new, opts->defaults, opts->size); for (int n = 0; opts->opts && opts->opts[n].type; n++) { const struct m_option *opt = &opts->opts[n]; - // not implemented, because it adds lots of complexity - assert(!(opt->type->flags & M_OPT_TYPE_HAS_CHILD)); - void *src = (char *)ptr + opt->offset; + if (opt->offset < 0) + continue; + void *src = ptr ? (char *)ptr + opt->offset : NULL; void *dst = (char *)new + opt->offset; - memset(dst, 0, opt->type->size); - m_option_copy(opt, dst, src); + if (opt->type->flags & M_OPT_TYPE_HAS_CHILD) { + // Specifying a default struct for a sub-option field in the + // containing struct's default struct is not supported here. + // (Out of laziness. Could possibly be supported.) + assert(!substruct_read_ptr(dst)); + + const struct m_sub_options *subopts = opt->priv; + + const void *sub_src = NULL; + if (src) + sub_src = substruct_read_ptr(src); + if (!sub_src) + sub_src = subopts->defaults; + + void *sub_dst = m_sub_options_copy(new, subopts, sub_src); + substruct_write_ptr(dst, sub_dst); + } else { + init_opt_inplace(opt, dst, src); + } } return new; } diff --git a/options/m_option.c b/options/m_option.c index 9f2d8758d0..b7b76634f8 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -106,6 +106,21 @@ const m_option_t *m_option_list_find(const m_option_t *list, const char *name) return m_option_list_findb(list, bstr0(name)); } +int m_option_set_node_or_string(struct mp_log *log, const m_option_t *opt, + const char *name, void *dst, struct mpv_node *src) +{ + if (src->format == MPV_FORMAT_STRING) { + // The af and vf option unfortunately require this, because the + // option name includes the "action". + bstr optname = bstr0(name), a, b; + if (bstr_split_tok(optname, "/", &a, &b)) + optname = b; + return m_option_parse(log, opt, optname, bstr0(src->u.string), dst); + } else { + return m_option_set_node(opt, dst, src); + } +} + // Default function that just does a memcpy static void copy_opt(const m_option_t *opt, void *dst, const void *src) @@ -657,6 +672,8 @@ static int choice_set(const m_option_t *opt, void *dst, struct mpv_node *src) src_str = buf; } else if (src->format == MPV_FORMAT_STRING) { src_str = src->u.string; + } else if (src->format == MPV_FORMAT_FLAG) { + src_str = src->u.flag ? "yes" : "no"; } if (!src_str) return M_OPT_UNKNOWN; @@ -698,8 +715,19 @@ static int choice_get(const m_option_t *opt, void *ta_parent, alt = NULL; } if (alt) { - dst->format = MPV_FORMAT_STRING; - dst->u.string = talloc_strdup(ta_parent, alt->name); + int b = -1; + if (strcmp(alt->name, "yes") == 0) { + b = 1; + } else if (strcmp(alt->name, "no") == 0) { + b = 0; + } + if (b >= 0) { + dst->format = MPV_FORMAT_FLAG; + dst->u.flag = b; + } else { + dst->format = MPV_FORMAT_STRING; + dst->u.string = talloc_strdup(ta_parent, alt->name); + } } else { dst->format = MPV_FORMAT_INT64; dst->u.int64 = ival; @@ -1654,7 +1682,7 @@ static int parse_msglevels(struct mp_log *log, const m_option_t *opt, struct bstr name, struct bstr param, void *dst) { if (bstr_equals0(param, "help")) { - mp_info(log, "Syntax: --msglevel=module1=level:module2=level:...\n" + mp_info(log, "Syntax:\n\n --msglevel=module1=level,module2=level,...\n\n" "'module' is output prefix as shown with -v, or a prefix\n" "of it. level is one of:\n\n" " fatal error warn info status v debug trace\n\n" @@ -2061,6 +2089,10 @@ void m_geometry_apply(int *xpos, int *ypos, int *widw, int *widh, } else if (!(gm->w > 0) && gm->h > 0) { *widw = *widh * asp; } + // Center window after resize. If valid x:y values are passed to + // geometry, then those values will be overriden. + *xpos += prew / 2 - *widw / 2; + *ypos += preh / 2 - *widh / 2; } if (gm->xy_valid) { @@ -2287,10 +2319,18 @@ static int parse_chmap(struct mp_log *log, const m_option_t *opt, return 1; } +static char *print_chmap(const m_option_t *opt, const void *val) +{ + const struct mp_chmap *chmap = val; + return talloc_strdup(NULL, mp_chmap_to_str(chmap)); +} + + const m_option_type_t m_option_type_chmap = { .name = "Audio channels or channel map", .size = sizeof(struct mp_chmap), .parse = parse_chmap, + .print = print_chmap, .copy = copy_opt, }; diff --git a/options/m_option.h b/options/m_option.h index 320a9e5b99..7e6550691a 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -504,6 +504,10 @@ static inline int m_option_set_node(const m_option_t *opt, void *dst, return M_OPT_UNKNOWN; } +// Call m_option_parse for strings, m_option_set_node otherwise. +int m_option_set_node_or_string(struct mp_log *log, const m_option_t *opt, + const char *name, void *dst, struct mpv_node *src); + // see m_option_type.get static inline int m_option_get_node(const m_option_t *opt, void *ta_parent, struct mpv_node *dst, void *src) diff --git a/options/m_property.c b/options/m_property.c index 951b788d4b..d0579768c6 100644 --- a/options/m_property.c +++ b/options/m_property.c @@ -104,16 +104,8 @@ int m_property_do(struct mp_log *log, const struct m_property *prop_list, return str != NULL; } case M_PROPERTY_SET_STRING: { - if (!log) - return M_PROPERTY_ERROR; - bstr optname = bstr0(name), a, b; - if (bstr_split_tok(optname, "/", &a, &b)) - optname = b; - if (m_option_parse(log, &opt, optname, bstr0(arg), &val) < 0) - return M_PROPERTY_ERROR; - r = do_action(prop_list, name, M_PROPERTY_SET, &val, ctx); - m_option_free(&opt, &val); - return r; + struct mpv_node node = { .format = MPV_FORMAT_STRING, .u.string = arg }; + return m_property_do(log, prop_list, name, M_PROPERTY_SET_NODE, &node, ctx); } case M_PROPERTY_SWITCH: { if (!log) @@ -163,11 +155,12 @@ int m_property_do(struct mp_log *log, const struct m_property *prop_list, return r; } case M_PROPERTY_SET_NODE: { + if (!log) + return M_PROPERTY_ERROR; if ((r = do_action(prop_list, name, M_PROPERTY_SET_NODE, arg, ctx)) != M_PROPERTY_NOT_IMPLEMENTED) return r; - struct mpv_node *node = arg; - int err = m_option_set_node(&opt, &val, node); + int err = m_option_set_node_or_string(log, &opt, name, &val, arg); if (err == M_OPT_UNKNOWN) { r = M_PROPERTY_NOT_IMPLEMENTED; } else if (err < 0) { diff --git a/options/m_property.h b/options/m_property.h index 93a4a73578..42fe1c7ecf 100644 --- a/options/m_property.h +++ b/options/m_property.h @@ -184,6 +184,8 @@ struct m_sub_property { // Convenience macros which can be used as part of a sub_property entry. #define SUB_PROP_INT(i) \ .type = {.type = CONF_TYPE_INT}, .value = {.int_ = (i)} +#define SUB_PROP_INT64(i) \ + .type = {.type = CONF_TYPE_INT64}, .value = {.int64 = (i)} #define SUB_PROP_STR(s) \ .type = {.type = CONF_TYPE_STRING}, .value = {.string = (char *)(s)} #define SUB_PROP_FLOAT(f) \ diff --git a/options/options.c b/options/options.c index 1ae48a6fc2..bb2ccb5220 100644 --- a/options/options.c +++ b/options/options.c @@ -82,12 +82,14 @@ extern const struct m_obj_list ao_obj_list; const struct m_opt_choice_alternatives mp_hwdec_names[] = { {"no", HWDEC_NONE}, {"auto", HWDEC_AUTO}, + {"auto-copy", HWDEC_AUTO_COPY}, {"vdpau", HWDEC_VDPAU}, {"videotoolbox",HWDEC_VIDEOTOOLBOX}, {"vaapi", HWDEC_VAAPI}, {"vaapi-copy", HWDEC_VAAPI_COPY}, {"dxva2", HWDEC_DXVA2}, {"dxva2-copy", HWDEC_DXVA2_COPY}, + {"d3d11va", HWDEC_D3D11VA}, {"d3d11va-copy",HWDEC_D3D11VA_COPY}, {"rpi", HWDEC_RPI}, {"mediacodec", HWDEC_MEDIACODEC}, @@ -373,7 +375,7 @@ const m_option_t mp_opts[] = { OPT_CHOICE("ass-shaper", ass_shaper, 0, ({"simple", 0}, {"complex", 1})), OPT_CHOICE("ass-style-override", ass_style_override, 0, - ({"no", 0}, {"yes", 1}, {"force", 3}, {"signfs", 4})), + ({"no", 0}, {"yes", 1}, {"force", 3}, {"signfs", 4}, {"strip", 5})), OPT_FLAG("sub-scale-by-window", sub_scale_by_window, 0), OPT_FLAG("sub-scale-with-window", sub_scale_with_window, 0), OPT_FLAG("ass-scale-with-window", ass_scale_with_window, 0), @@ -396,8 +398,10 @@ const m_option_t mp_opts[] = { OPT_FLAG("audio-fallback-to-null", ao_null_fallback, 0), 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), @@ -458,7 +462,8 @@ const m_option_t mp_opts[] = { #if HAVE_X11 OPT_CHOICE("x11-netwm", vo.x11_netwm, 0, ({"auto", 0}, {"no", -1}, {"yes", 1})), - OPT_FLAG("x11-bypass-compositor", vo.x11_bypass_compositor, 0), + 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), @@ -706,10 +711,12 @@ const struct MPOpts mp_default_opts = { .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 = 0, + .x11_bypass_compositor = 2, .mmcss_profile = "Playback", }, .allow_win_drag = 1, diff --git a/options/options.h b/options/options.h index 95268cd522..5dcc642222 100644 --- a/options/options.h +++ b/options/options.h @@ -9,9 +9,11 @@ typedef struct mp_vo_opts { struct m_obj_settings *video_driver_list, *vo_defs; + int taskbar_progress; int ontop; int fullscreen; int border; + int fit_border; int all_workspaces; int screen_id; |