mirror of
https://github.com/mpv-player/mpv
synced 2025-02-16 12:17:12 +00:00
command: export some option metadata
This might be interesting for GUIs and such. It's probably still a little bit insufficient. For example, the filter and audio/video output lists are not available through this.
This commit is contained in:
parent
71168e740e
commit
5d12a2696e
@ -1446,7 +1446,15 @@ Property list
|
||||
Additional per-option information.
|
||||
|
||||
This has a number of sub-properties. Replace ``<name>`` with the name of
|
||||
a top-level option.
|
||||
a top-level option. No guarantee of stability is given to any of these
|
||||
sub-properties - they may change radically in the feature.
|
||||
|
||||
``option-info/<name>/name``
|
||||
Returns the name of the option.
|
||||
|
||||
``option-info/<name>/type``
|
||||
Return the name of the option type, like ``String`` or ``Integer``.
|
||||
For many complex types, this isn't very accurate.
|
||||
|
||||
``option-info/<name>/set-from-commandline``
|
||||
|
||||
@ -1454,6 +1462,21 @@ Property list
|
||||
``no`` otherwise. What this is set to if the option is e.g. changed
|
||||
at runtime is left undefined (meaning it could change in the future).
|
||||
|
||||
``option-info/<name>/default-value``
|
||||
The default value of the option. May not always be available.
|
||||
|
||||
``option-info/<name>/min``, ``option-info/<name>/max``
|
||||
Integer minimum and maximum values allowed for the option. Only
|
||||
available if the options are numeric, and the minimum/maximum has been
|
||||
set internally. It's also possible that only one of these is set.
|
||||
|
||||
``option-info/<name>/choices``
|
||||
If the option is a choice option, the possible choices. Choices that
|
||||
are integers may or may not be included (they can be implied by ``min``
|
||||
and ``max``). Note that options which behave like choice options, but
|
||||
are not actual choice options internally, may not have this info
|
||||
available.
|
||||
|
||||
``property-list``
|
||||
Return the list of top-level properties.
|
||||
|
||||
|
@ -696,7 +696,7 @@ static char *print_choice(const m_option_t *opt, const void *val)
|
||||
}
|
||||
|
||||
const struct m_option_type m_option_type_choice = {
|
||||
.name = "String", // same as arbitrary strings in option list for now
|
||||
.name = "Choice",
|
||||
.size = sizeof(int),
|
||||
.parse = parse_choice,
|
||||
.print = print_choice,
|
||||
|
@ -189,6 +189,8 @@ struct m_sub_property {
|
||||
.type = {.type = CONF_TYPE_STRING}, .value = {.string = (char *)(s)}
|
||||
#define SUB_PROP_FLOAT(f) \
|
||||
.type = {.type = CONF_TYPE_FLOAT}, .value = {.float_ = (f)}
|
||||
#define SUB_PROP_DOUBLE(f) \
|
||||
.type = {.type = CONF_TYPE_DOUBLE}, .value = {.double_ = (f)}
|
||||
#define SUB_PROP_FLAG(f) \
|
||||
.type = {.type = CONF_TYPE_FLAG}, .value = {.flag = (f)}
|
||||
|
||||
|
@ -3017,14 +3017,46 @@ static int mp_property_option_info(void *ctx, struct m_property *prop,
|
||||
if (!co)
|
||||
return M_PROPERTY_UNKNOWN;
|
||||
|
||||
union m_option_value def = {0};
|
||||
if (co->default_data)
|
||||
memcpy(&def, co->default_data, co->opt->type->size);
|
||||
|
||||
const struct m_option *opt = co->opt;
|
||||
bool has_minmax =
|
||||
opt->type == &m_option_type_int ||
|
||||
opt->type == &m_option_type_int64 ||
|
||||
opt->type == &m_option_type_float ||
|
||||
opt->type == &m_option_type_double;
|
||||
char **choices = NULL;
|
||||
|
||||
if (opt->type == &m_option_type_choice) {
|
||||
has_minmax = true;
|
||||
struct m_opt_choice_alternatives *alt = opt->priv;
|
||||
int num = 0;
|
||||
for ( ; alt->name; alt++)
|
||||
MP_TARRAY_APPEND(NULL, choices, num, alt->name);
|
||||
MP_TARRAY_APPEND(NULL, choices, num, NULL);
|
||||
}
|
||||
|
||||
struct m_sub_property props[] = {
|
||||
{"name", SUB_PROP_STR(co->name)},
|
||||
{"type", SUB_PROP_STR(opt->type->name)},
|
||||
{"set-from-commandline", SUB_PROP_FLAG(co->is_set_from_cmdline)},
|
||||
{"default-value", *opt, def},
|
||||
{"min", SUB_PROP_DOUBLE(opt->min),
|
||||
.unavailable = !(has_minmax && (opt->flags & M_OPT_MIN))},
|
||||
{"max", SUB_PROP_DOUBLE(opt->max),
|
||||
.unavailable = !(has_minmax && (opt->flags & M_OPT_MAX))},
|
||||
{"choices", .type = {.type = CONF_TYPE_STRING_LIST},
|
||||
.value = {.string_list = choices}, .unavailable = !choices},
|
||||
{0}
|
||||
};
|
||||
|
||||
struct m_property_action_arg next_ka = *ka;
|
||||
next_ka.key = rem;
|
||||
return m_property_read_sub(props, M_PROPERTY_KEY_ACTION, &next_ka);
|
||||
int r = m_property_read_sub(props, M_PROPERTY_KEY_ACTION, &next_ka);
|
||||
talloc_free(choices);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||
|
Loading…
Reference in New Issue
Block a user