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:
parent
e94bab5a99
commit
91f752f43f
@ -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);
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user