summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-24 20:39:51 +0100
committerwm4 <wm4@nowhere>2014-02-24 22:50:23 +0100
commit942fb43d0cdc58b0b2fad15bab564fd5105698ff (patch)
tree797aa3db62fb264869123e335f35266539335e52 /player
parenta6ebfbea6922632efb2cab020303397a418959f1 (diff)
downloadmpv-942fb43d0cdc58b0b2fad15bab564fd5105698ff.tar.bz2
mpv-942fb43d0cdc58b0b2fad15bab564fd5105698ff.tar.xz
client API: implement setting options using their native type too
This is only half-implemented: actually the option will first be converted from mpv_node to its native type, then it's converted to a string, and then back to its native type. This is because the option API was made for strings and not anything else. Other than being grossly inelegant, the only downside is probably with string lists and key/value lists, which don't escape strings containing syntax elements correctly.
Diffstat (limited to 'player')
-rw-r--r--player/client.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/player/client.c b/player/client.c
index d61c0a5056..11fe86bdfc 100644
--- a/player/client.c
+++ b/player/client.c
@@ -508,15 +508,24 @@ int mpv_set_option(mpv_handle *ctx, const char *name, mpv_format format,
return err;
}
} else {
- if (format != MPV_FORMAT_STRING)
+ const struct m_option *type = get_mp_type(format);
+ if (!type)
return MPV_ERROR_OPTION_FORMAT;
- const char *value = *(char **)data;
- int err = m_config_set_option0(ctx->mpctx->mconfig, name, value);
+ struct mpv_node tmp;
+ if (format != MPV_FORMAT_NODE) {
+ tmp.format = format;
+ memcpy(&tmp.u, data, type->type->size);
+ format = MPV_FORMAT_NODE;
+ data = &tmp;
+ }
+ int err = m_config_set_option_node(ctx->mpctx->mconfig, bstr0(name),
+ data, 0);
switch (err) {
case M_OPT_MISSING_PARAM:
case M_OPT_INVALID:
- case M_OPT_OUT_OF_RANGE:
return MPV_ERROR_OPTION_ERROR;
+ case M_OPT_OUT_OF_RANGE:
+ return MPV_ERROR_OPTION_FORMAT;
case M_OPT_UNKNOWN:
return MPV_ERROR_OPTION_NOT_FOUND;
default: