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.
This commit is contained in:
Arun Raghavan 2025-03-26 11:49:02 -04:00
parent dfdc3e333a
commit 5ef13489db
2 changed files with 13 additions and 7 deletions

View file

@ -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

View file

@ -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;