1
mirror of https://github.com/mpv-player/mpv synced 2024-11-18 21:16:10 +01:00

command: add all options to property->option bridge

Before this, options with co->data==NULL (i.e. no storage) were not
added to the bridge (except alias options). There are a few options
which might make sense to allow via the bridge ("profile" and
"include"). So allow them.

In command_init(), we merely remove the co->data check, the rest of the
diff is due to switching the if/else branches for convenience.

We also must explicitly error on M_PROPERTY_GET if co->data==NULL. All
other cases check it in some way.

Explicitly exclude options from the property bridge, which would be
added due this, and the result would be pointless.
This commit is contained in:
wm4 2017-06-15 15:22:06 +02:00
parent fd7de84833
commit b8193e4071
4 changed files with 34 additions and 22 deletions

View File

@ -2210,6 +2210,14 @@ caveats with some properties (due to historical reasons):
These properties behave different from the deprecated options with the same
names.
``profile``, ``include``
These are write-only, and will perform actions as they are written to,
exactly as if they were used on the mpv CLI commandline. Their only use is
when using libmpv before ``mpv_initialize()``, which in turn is probably
only useful in encoding mode. Normal libmpv users should use other
mechanisms, such as the ``apply-profile`` command, and the
``mpv_load_config_file`` API function. Avoid these properties.
Property Expansion
------------------

View File

@ -693,7 +693,7 @@ extern const char m_option_path_separator;
#define OPT_PRINT(optname, fn) \
{.name = optname, \
.flags = M_OPT_FIXED | M_OPT_NOCFG | M_OPT_PRE_PARSE, \
.flags = M_OPT_FIXED | M_OPT_NOCFG | M_OPT_PRE_PARSE | M_OPT_NOPROP, \
.type = &m_option_type_print_fn, \
.priv = MP_EXPECT_TYPE(m_opt_print_fn, fn), \
.offset = -1}
@ -726,6 +726,6 @@ extern const char m_option_path_separator;
// "--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, \
.deprecation_message = "", .offset = -1}
.deprecation_message = "", .flags = M_OPT_NOPROP, .offset = -1}
#endif /* MPLAYER_M_OPTION_H */

View File

@ -254,21 +254,25 @@ const struct m_sub_options dvd_conf = {
const m_option_t mp_opts[] = {
// handled in command line pre-parser (parse_commandline.c)
{"v", CONF_TYPE_STORE, M_OPT_FIXED | CONF_NOCFG, .offset = -1},
{"v", CONF_TYPE_STORE, M_OPT_FIXED | CONF_NOCFG | M_OPT_NOPROP, .offset = -1},
{"playlist", CONF_TYPE_STRING, CONF_NOCFG | M_OPT_MIN | M_OPT_FIXED | M_OPT_FILE,
.min = 1, .offset = -1},
{"{", CONF_TYPE_STORE, CONF_NOCFG | M_OPT_FIXED, .offset = -1},
{"}", CONF_TYPE_STORE, CONF_NOCFG | M_OPT_FIXED, .offset = -1},
{"{", CONF_TYPE_STORE, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP, .offset = -1},
{"}", CONF_TYPE_STORE, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP, .offset = -1},
// handled in m_config.c
{ "include", CONF_TYPE_STRING, M_OPT_FILE, .offset = -1},
{ "profile", CONF_TYPE_STRING_LIST, 0, .offset = -1},
{ "show-profile", CONF_TYPE_STRING, CONF_NOCFG | M_OPT_FIXED, .offset = -1},
{ "list-options", CONF_TYPE_STORE, CONF_NOCFG | M_OPT_FIXED, .offset = -1},
{ "show-profile", CONF_TYPE_STRING, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP,
.offset = -1},
{ "list-options", CONF_TYPE_STORE, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP,
.offset = -1},
OPT_FLAG("list-properties", property_print_help,
CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP),
{ "help", CONF_TYPE_STRING, CONF_NOCFG | M_OPT_FIXED, .offset = -1},
{ "h", CONF_TYPE_STRING, CONF_NOCFG | M_OPT_FIXED, .offset = -1},
{ "help", CONF_TYPE_STRING, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP,
.offset = -1},
{ "h", CONF_TYPE_STRING, CONF_NOCFG | M_OPT_FIXED | M_OPT_NOPROP,
.offset = -1},
OPT_PRINT("list-protocols", stream_print_proto_list),
OPT_PRINT("version", print_version),

View File

@ -402,14 +402,14 @@ static int mp_property_generic_option(void *ctx, struct m_property *prop,
if (!opt)
return M_PROPERTY_UNKNOWN;
void *valptr = opt->data;
switch (action) {
case M_PROPERTY_GET_TYPE:
*(struct m_option *)arg = *(opt->opt);
return M_PROPERTY_OK;
case M_PROPERTY_GET:
m_option_copy(opt->opt, arg, valptr);
if (!opt->data)
return M_PROPERTY_NOT_IMPLEMENTED;
m_option_copy(opt->opt, arg, opt->data);
return M_PROPERTY_OK;
case M_PROPERTY_SET:
if (m_config_set_option_raw_direct(mpctx->mconfig, opt, arg, flags) < 0)
@ -5672,7 +5672,16 @@ void command_init(struct MPContext *mpctx)
struct m_property prop = {0};
if (co->data) {
if (co->opt->type == &m_option_type_alias) {
const char *alias = (const char *)co->opt->priv;
prop = (struct m_property){
.name = co->name,
.call = co->opt->deprecation_message ?
mp_property_deprecated_alias : mp_property_alias,
.priv = (void *)alias,
};
} else {
prop = (struct m_property){
.name = co->name,
.call = mp_property_generic_option,
@ -5683,15 +5692,6 @@ void command_init(struct MPContext *mpctx)
prop.name = bstrto0(ctx, bname);
prop.call = mp_property_generic_option_star;
}
} else if (co->opt->type == &m_option_type_alias) {
const char *alias = (const char *)co->opt->priv;
prop = (struct m_property){
.name = co->name,
.call = co->opt->deprecation_message ?
mp_property_deprecated_alias : mp_property_alias,
.priv = (void *)alias,
};
}
if (prop.name) {