summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-24 19:35:06 +0100
committerwm4 <wm4@nowhere>2014-02-24 20:50:47 +0100
commit1e27d130a2c7d09ae9b9a97c7431f0a1c1d73ea2 (patch)
tree1cf63ca938e8a63c7c8e94975f6da35608b85834
parent1e30048184930403265cad091863aa0a5d1e9d76 (diff)
downloadmpv-1e27d130a2c7d09ae9b9a97c7431f0a1c1d73ea2.tar.bz2
mpv-1e27d130a2c7d09ae9b9a97c7431f0a1c1d73ea2.tar.xz
client API: change semantics for MPV_FORMAT_STRING
With mpv_set_property(h, "property", MPV_FORMAT_STRING, ptr), ptr now has to be of type char** instead of char*. This makes it more consistent with mpv_get_property() and also non-pointer formats, which will be introduced in the following commits. mpv_set_property() of course does not change its interface (only its implementation is adjusted to keep its interface). This also affects mpv_set_option(), but again not mpv_set_option_string().
-rw-r--r--libmpv/client.h16
-rw-r--r--player/client.c10
2 files changed, 19 insertions, 7 deletions
diff --git a/libmpv/client.h b/libmpv/client.h
index 901995ab29..2ad2fc4c0e 100644
--- a/libmpv/client.h
+++ b/libmpv/client.h
@@ -372,10 +372,16 @@ typedef enum mpv_format {
* printf("%s\n", result);
* mpv_free(result);
*
+ * Or just use mpv_get_property_string().
+ *
* Example for writing:
*
* char *value = "the new value";
- * mpv_set_property(ctx, "property", MPV_FORMAT_STRING, (void *)value);
+ * // yep, you pass the address to the variable
+ * // (needed for symmetry with other types and mpv_get_property)
+ * mpv_set_property(ctx, "property", MPV_FORMAT_STRING, &value);
+ *
+ * Or just use mpv_set_property_string().
*
*/
MPV_FORMAT_STRING = 1,
@@ -673,7 +679,13 @@ typedef struct mpv_event_property {
*/
mpv_format format;
/**
- * Received property value. Depends on the format.
+ * Received property value. Depends on the format. This is like the
+ * pointer argument passed to mpv_get_property().
+ *
+ * For example, for MPV_FORMAT_STRING you get the string with:
+ *
+ * char *value = *(char **)(event_property->data);
+ *
* Note that this is set to NULL if retrieving the property failed.
* See mpv_event.error for the status.
*/
diff --git a/player/client.c b/player/client.c
index 39c28d2074..39d816c0bb 100644
--- a/player/client.c
+++ b/player/client.c
@@ -462,7 +462,7 @@ int mpv_set_option(mpv_handle *ctx, const char *name, mpv_format format,
} else {
if (format != MPV_FORMAT_STRING)
return MPV_ERROR_OPTION_FORMAT;
- const char *value = data;
+ const char *value = *(char **)data;
int err = m_config_set_option0(ctx->mpctx->mconfig, name, value);
switch (err) {
case M_OPT_MISSING_PARAM:
@@ -481,7 +481,7 @@ int mpv_set_option(mpv_handle *ctx, const char *name, mpv_format format,
int mpv_set_option_string(mpv_handle *ctx, const char *name, const char *data)
{
- return mpv_set_option(ctx, name, MPV_FORMAT_STRING, (void *)data);
+ return mpv_set_option(ctx, name, MPV_FORMAT_STRING, &data);
}
// Run a command in the playback thread.
@@ -635,7 +635,7 @@ int mpv_set_property(mpv_handle *ctx, const char *name, mpv_format format,
.mpctx = ctx->mpctx,
.name = name,
.format = format,
- .data = data,
+ .data = *(char **)data,
};
run_locked(ctx, setproperty_fn, &req);
return req.status;
@@ -643,7 +643,7 @@ int mpv_set_property(mpv_handle *ctx, const char *name, mpv_format format,
int mpv_set_property_string(mpv_handle *ctx, const char *name, const char *data)
{
- return mpv_set_property(ctx, name, MPV_FORMAT_STRING, (void *)data);
+ return mpv_set_property(ctx, name, MPV_FORMAT_STRING, &data);
}
int mpv_set_property_async(mpv_handle *ctx, uint64_t ud, const char *name,
@@ -657,7 +657,7 @@ int mpv_set_property_async(mpv_handle *ctx, uint64_t ud, const char *name,
.mpctx = ctx->mpctx,
.name = talloc_strdup(req, name),
.format = MPV_FORMAT_STRING,
- .data = talloc_strdup(req, data), // for now always a string
+ .data = talloc_strdup(req, *(char **)data), // for now always a string
.reply_ctx = ctx,
.userdata = ud,
};