1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-11 17:39:38 +00:00

client API: access choices as flags if appropriate

Options/properties that are choices, and which include "yes" or "no"
values (or both) can now be read and written as MPV_FORMAT_FLAG.

For write access, rejecting flags in these cases was obnoxiously
unintuitive and inconvenient.

For read access, the value of this is less convincing, and actually it's
a major API change. At this point I probably have to admit that the
finer details of the client API are very unstable.
This commit is contained in:
wm4 2016-05-04 17:37:54 +02:00
parent 833375f88d
commit b2646911a9
3 changed files with 24 additions and 2 deletions

View File

@ -41,6 +41,11 @@ API changes
is invoked with that type directly. This new behavior is equivalent
to mpv_set_option().
This also affects the mp.set_property_native() Lua function.
- generally, setting choice options/properties with "yes"/"no" options
can now be set as MPV_FORMAT_FLAG
- reading a choice property as MPV_FORMAT_NODE will now return a
MPV_FORMAT_FLAG value if the choice is "yes" (true) or "no" (false)
This implicitly affects Lua and JSON IPC interfaces as well.
--- mpv 0.12.0 ---
1.20 - deprecate "GL_MP_D3D_interfaces"/"glMPGetD3DInterface", and introduce
"GL_MP_MPGetNativeDisplay"/"glMPGetNativeDisplay" (this is a

View File

@ -28,6 +28,10 @@ Interface changes
- add "hwdec-interop" and "hwdec-current" properties
- deprecated "hwdec-active" and "hwdec-detected" properties (to be removed
in mpv 0.19.0)
- choice option/property values that are "yes" or "no" will now be returned
as booleans when using the mpv_node functions in the client API, the
"native" property accessors in Lua, and the JSON API. They can be set as
such as well.
--- mpv 0.17.0 ---
- deprecate "track-list/N/audio-channels" property (use
"track-list/N/demux-channel-count" instead)

View File

@ -672,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;
@ -713,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;