1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-11 08:37:59 +00:00

m_property: add mechanism to access properties as mpv_node

Allows retrieving properties by their native values (or something close
to it), rather than having to go through string conversion. The caller
could actually just copy the value itself and then use the m_option
functions to convert it to mpv_node, but maybe it's more flexible this
way.
This commit is contained in:
wm4 2014-02-24 20:10:26 +01:00
parent e94bab5a99
commit 91f752f43f
2 changed files with 47 additions and 0 deletions

View File

@ -29,6 +29,8 @@
#include <libavutil/common.h>
#include "libmpv/client.h"
#include "talloc.h"
#include "m_option.h"
#include "m_property.h"
@ -192,6 +194,40 @@ int m_property_do(struct mp_log *log, const m_option_t *prop_list,
}
return do_action(prop_list, name, M_PROPERTY_SET, arg, ctx);
}
case M_PROPERTY_GET_NODE: {
if ((r = do_action(prop_list, name, M_PROPERTY_GET_NODE, arg, ctx)) !=
M_PROPERTY_NOT_IMPLEMENTED)
return r;
if ((r = do_action(prop_list, name, M_PROPERTY_GET, &val, ctx)) <= 0)
return r;
struct mpv_node *node = arg;
int err = m_option_get_node(&opt, NULL, node, &val);
if (err == M_OPT_UNKNOWN) {
r = M_PROPERTY_NOT_IMPLEMENTED;
} else if (r < 0) {
r = M_PROPERTY_INVALID_FORMAT;
} else {
r = M_PROPERTY_OK;
}
m_option_free(&opt, &val);
return r;
}
case M_PROPERTY_SET_NODE: {
if ((r = do_action(prop_list, name, M_PROPERTY_SET_NODE, arg, ctx)) !=
M_PROPERTY_NOT_IMPLEMENTED)
return r;
struct mpv_node *node = arg;
int err = m_option_set_node(&opt, &val, node);
if (err == M_OPT_UNKNOWN) {
r = M_PROPERTY_NOT_IMPLEMENTED;
} else if (r < 0) {
r = M_PROPERTY_INVALID_FORMAT;
} else {
r = do_action(prop_list, name, M_PROPERTY_SET, &val, ctx);
}
m_option_free(&opt, &val);
return r;
}
default:
return do_action(prop_list, name, action, arg, ctx);
}

View File

@ -68,6 +68,14 @@ enum mp_property_action {
// arg: char*
M_PROPERTY_SET_STRING,
// Set a mpv_node value.
// arg: mpv_node*
M_PROPERTY_GET_NODE,
// Get a mpv_node value.
// arg: mpv_node*
M_PROPERTY_SET_NODE,
// Pass down an action to a sub-property.
// arg: struct m_property_action_arg*
M_PROPERTY_KEY_ACTION,
@ -102,6 +110,9 @@ enum mp_property_return {
// Returned when asking for a property that doesn't exist.
M_PROPERTY_UNKNOWN = -3,
// When trying to set invalid or incorrectly formatted data.
M_PROPERTY_INVALID_FORMAT = -4,
};
// Access a property.