From 5ef13489dbc3cb498021c2c154760f372936ad62 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 26 Mar 2025 11:49:02 -0400 Subject: [PATCH] gst: sink: Correctly set size and offset on planar data We need to make sure the memory sizes are correctly initialised so the meta makes sense, and we don't copy the meta from the input buffer as that doesn't make sense given we have our own meta already. --- src/gst/gstpipewirepool.c | 12 ++++++++++++ src/gst/gstpipewiresink.c | 8 +------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/gst/gstpipewirepool.c b/src/gst/gstpipewirepool.c index f00612fc8..6c6e2dcab 100644 --- a/src/gst/gstpipewirepool.c +++ b/src/gst/gstpipewirepool.c @@ -102,6 +102,18 @@ void gst_pipewire_pool_wrap_buffer (GstPipeWirePool *pool, struct pw_buffer *b) GST_VIDEO_INFO_N_PLANES (&pool->video_info), pool->video_info.offset, pool->video_info.stride); + gsize plane_sizes[GST_VIDEO_MAX_PLANES]; + + if (!gst_video_meta_get_plane_size (meta, plane_sizes)) { + GST_ERROR_OBJECT (pool, "could not compute plane sizes"); + } else { + /* Set memory sizes to expected plane sizes, so we know the valid size, + * and the offsets in the meta make sense */ + for (i = 0; i < gst_buffer_n_memory (buf); i++) { + GstMemory *mem = gst_buffer_peek_memory (buf, i); + gst_memory_resize (mem, 0, plane_sizes[i]); + } + } /* * We need to set the video meta as pooled, else gst_buffer_pool_release_buffer diff --git a/src/gst/gstpipewiresink.c b/src/gst/gstpipewiresink.c index c0d7df8a6..4457e2eac 100644 --- a/src/gst/gstpipewiresink.c +++ b/src/gst/gstpipewiresink.c @@ -654,17 +654,13 @@ do_send_buffer (GstPipeWireSink *pwsink, GstBuffer *buffer) if (meta) { if (meta->n_planes == b->n_datas) { uint32_t n_planes = GST_VIDEO_INFO_N_PLANES (&data->pool->video_info); - gboolean is_planar = n_planes > 1; gsize video_size = 0; for (i = 0; i < n_planes; i++) { struct spa_data *d = &b->datas[i]; d->chunk->stride = meta->stride[i]; - if (is_planar) - d->chunk->offset = meta->offset[i]; - else - d->chunk->offset += meta->offset[i] - video_size; + d->chunk->offset = meta->offset[i] - video_size; video_size += d->chunk->size; } @@ -969,8 +965,6 @@ gst_pipewire_sink_render (GstBaseSink * bsink, GstBuffer * buffer) GST_ERROR_OBJECT(pwsink, "Failed to copy the frame"); return GST_FLOW_ERROR; } - - gst_buffer_copy_into(b, buffer, GST_BUFFER_COPY_METADATA, 0, -1); } else { gst_buffer_map (b, &info, GST_MAP_WRITE); gsize extract_size = (buf_size <= info.maxsize) ? buf_size: info.maxsize;