From ef402a1c8c9e3bb369c6192ff25be5ca2435b5a5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 23 Mar 2018 14:53:18 +0100 Subject: command: use mpv_node helpers instead of duplicated code They didn't exist yet when this code was added. Completely untested. --- player/command.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'player/command.c') diff --git a/player/command.c b/player/command.c index 7b532cc0c6..b855f1dd96 100644 --- a/player/command.c +++ b/player/command.c @@ -4752,22 +4752,6 @@ static bool check_property_scalable(char *property, struct MPContext *mpctx) prop.type == &m_option_type_aspect; } -static struct mpv_node *add_map_entry(struct mpv_node *dst, const char *key) -{ - struct mpv_node_list *list = dst->u.list; - assert(dst->format == MPV_FORMAT_NODE_MAP && dst->u.list); - MP_TARRAY_GROW(list, list->values, list->num); - MP_TARRAY_GROW(list, list->keys, list->num); - list->keys[list->num] = talloc_strdup(list, key); - return &list->values[list->num++]; -} - -#define ADD_MAP_INT(dst, name, i) (*add_map_entry(dst, name) = \ - (struct mpv_node){.format = MPV_FORMAT_INT64, .u.int64 = (i)}); - -#define ADD_MAP_CSTR(dst, name, s) (*add_map_entry(dst, name) = \ - (struct mpv_node){.format = MPV_FORMAT_STRING, .u.string = (s)}); - int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *res) { struct command_ctx *cmdctx = mpctx->command_ctx; @@ -5370,20 +5354,18 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re struct mp_image *img = screenshot_get_rgb(mpctx, cmd->args[0].v.i); if (!img) return -1; - struct mpv_node_list *info = talloc_zero(NULL, struct mpv_node_list); - talloc_steal(info, img); - *res = (mpv_node){.format = MPV_FORMAT_NODE_MAP, .u.list = info}; - ADD_MAP_INT(res, "w", img->w); - ADD_MAP_INT(res, "h", img->h); - ADD_MAP_INT(res, "stride", img->stride[0]); - ADD_MAP_CSTR(res, "format", "bgr0"); - struct mpv_byte_array *ba = talloc_ptrtype(info, ba); + node_init(res, MPV_FORMAT_NODE_MAP, NULL); + node_map_add_int64(res, "w", img->w); + node_map_add_int64(res, "h", img->h); + node_map_add_int64(res, "stride", img->stride[0]); + node_map_add_string(res, "format", "bgr0"); + struct mpv_byte_array *ba = + node_map_add(res, "data", MPV_FORMAT_BYTE_ARRAY)->u.ba; *ba = (struct mpv_byte_array){ .data = img->planes[0], .size = img->stride[0] * img->h, }; - *add_map_entry(res, "data") = - (struct mpv_node){.format = MPV_FORMAT_BYTE_ARRAY, .u.ba = ba,}; + talloc_steal(ba, img); break; } -- cgit v1.2.3