aboutsummaryrefslogtreecommitdiffhomepage
path: root/player
diff options
context:
space:
mode:
authorGravatar wm4 <wm4@nowhere>2018-03-23 14:53:18 +0100
committerGravatar wm4 <wm4@nowhere>2018-03-26 19:47:08 +0200
commitef402a1c8c9e3bb369c6192ff25be5ca2435b5a5 (patch)
tree655367436ee5859883db9368842c5a32c26cc0ee /player
parent4655923d387047d51f1d1face5d40d757a76123e (diff)
command: use mpv_node helpers instead of duplicated code
They didn't exist yet when this code was added. Completely untested.
Diffstat (limited to 'player')
-rw-r--r--player/command.c34
1 files changed, 8 insertions, 26 deletions
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;
}