From 942fb43d0cdc58b0b2fad15bab564fd5105698ff Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 24 Feb 2014 20:39:51 +0100 Subject: 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. --- player/client.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'player') 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: -- cgit v1.2.3