From 88a8a9cb7e570d3e5535cf86d9bc9288d0c1e155 Mon Sep 17 00:00:00 2001 From: columbarius Date: Sun, 8 Aug 2021 03:31:49 +0200 Subject: [PATCH] screencast: add build_buffer function This function makes it easier to omit attributes like size or stride for cases where they won't be well defined like muliplanar dmabufs --- src/screencast/pipewire_screencast.c | 31 +++++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/screencast/pipewire_screencast.c b/src/screencast/pipewire_screencast.c index 54b48e2..4b4b794 100644 --- a/src/screencast/pipewire_screencast.c +++ b/src/screencast/pipewire_screencast.c @@ -13,6 +13,27 @@ #include "xdpw.h" #include "logger.h" +static struct spa_pod *build_buffer(struct spa_pod_builder *b, uint32_t blocks, uint32_t size, + uint32_t stride, uint32_t datatype) { + assert(blocks > 0); + assert(datatype > 0); + struct spa_pod_frame f[1]; + + spa_pod_builder_push_object(b, &f[0], SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers); + spa_pod_builder_add(b, SPA_PARAM_BUFFERS_buffers, + SPA_POD_CHOICE_RANGE_Int(XDPW_PWR_BUFFERS, XDPW_PWR_BUFFERS_MIN, 32), 0); + spa_pod_builder_add(b, SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(blocks), 0); + if (size > 0) { + spa_pod_builder_add(b, SPA_PARAM_BUFFERS_size, SPA_POD_Int(size), 0); + } + if (stride > 0) { + spa_pod_builder_add(b, SPA_PARAM_BUFFERS_stride, SPA_POD_Int(stride), 0); + } + spa_pod_builder_add(b, SPA_PARAM_BUFFERS_align, SPA_POD_Int(XDPW_PWR_ALIGN), 0); + spa_pod_builder_add(b, SPA_PARAM_BUFFERS_dataType, SPA_POD_CHOICE_FLAGS_Int(datatype), 0); + return spa_pod_builder_pop(b, &f[0]); +} + static struct spa_pod *build_format(struct spa_pod_builder *b, enum spa_video_format format, uint32_t width, uint32_t height, uint32_t framerate) { struct spa_pod_frame f[1]; @@ -110,14 +131,8 @@ static void pwr_handle_stream_param_changed(void *data, uint32_t id, cast->framerate = (uint32_t)(cast->pwr_format.max_framerate.num / cast->pwr_format.max_framerate.denom); - params[0] = spa_pod_builder_add_object(&b, - SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, - SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(XDPW_PWR_BUFFERS, XDPW_PWR_BUFFERS_MIN, 32), - SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), - SPA_PARAM_BUFFERS_size, SPA_POD_Int(cast->screencopy_frame_info.size), - SPA_PARAM_BUFFERS_stride, SPA_POD_Int(cast->screencopy_frame_info.stride), - SPA_PARAM_BUFFERS_align, SPA_POD_Int(XDPW_PWR_ALIGN), - SPA_PARAM_BUFFERS_dataType,SPA_POD_CHOICE_FLAGS_Int(1<screencopy_frame_info.size, + cast->screencopy_frame_info.stride, 1<