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.
This commit is contained in:
wm4 2016-08-31 18:10:11 +02:00
parent 2057209057
commit c55d859920
5 changed files with 35 additions and 68 deletions

View File

@ -712,13 +712,14 @@ Video
This option has no effect if ``--video-unscaled`` option is used.
``--video-aspect=<ratio>``
``--video-aspect=<ratio|no>``
Override video aspect ratio, in case aspect information is incorrect or
missing in the file being played. See also ``--no-video-aspect``.
Two values have special meaning:
These values have special meaning:
:0: disable aspect ratio handling, pretend the video has square pixels
:no: same as ``0``
:-1: use the video stream or container aspect (default)
But note that handling of these special values might change in the future.
@ -727,10 +728,7 @@ Video
- ``--video-aspect=4:3`` or ``--video-aspect=1.3333``
- ``--video-aspect=16:9`` or ``--video-aspect=1.7777``
``--no-video-aspect``
Ignore aspect ratio information from video file and assume the video has
square pixels. See also ``--video-aspect``.
- ``--no-video-aspect`` or ``--video-aspect=no``
``--video-aspect-method=<hybrid|bitstream|container>``
This sets the default video aspect determination method (if the aspect is

View File

@ -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;

View File

@ -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

View File

@ -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))

View File

@ -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})),