gst: correct buffer & meta offset calculation

The offset in GstVideoMeta point to location of merge-mapped buffer memories (see "gst_buffer_find_memory()") instead of raw memory location for each plane, make adjustment to comply this rule.

Also some cleanups.

Fixes 023577e391
This commit is contained in:
Huang-Huang Bao 2023-02-03 19:45:50 +08:00 committed by Wim Taymans
parent 4f9f32084c
commit 4b60569c4a
2 changed files with 11 additions and 5 deletions

View file

@ -508,13 +508,16 @@ do_send_buffer (GstPipeWireSink *pwsink, GstBuffer *buffer)
GstVideoMeta *meta = gst_buffer_get_video_meta (buffer); GstVideoMeta *meta = gst_buffer_get_video_meta (buffer);
if (meta) { if (meta) {
if (meta->n_planes == b->n_datas) { if (meta->n_planes == b->n_datas) {
gsize video_size = 0;
for (i = 0; i < meta->n_planes; i++) { for (i = 0; i < meta->n_planes; i++) {
struct spa_data *d = &b->datas[i]; struct spa_data *d = &b->datas[i];
d->chunk->offset = meta->offset[i]; d->chunk->offset += meta->offset[i] - video_size;
d->chunk->stride = meta->stride[i]; d->chunk->stride = meta->stride[i];
video_size += d->chunk->size;
} }
} else { } else {
GST_ERROR ("plane num not matching, meta:%d buffer:%d", meta->n_planes, b->n_datas); GST_ERROR ("plane num not matching, meta:%u buffer:%u", meta->n_planes, b->n_datas);
} }
} }

View file

@ -616,6 +616,7 @@ static GstBuffer *dequeue_buffer(GstPipeWireSrc *pwsrc)
} }
if (pwsrc->is_video) { if (pwsrc->is_video) {
gsize video_size = 0;
GstVideoInfo *info = &pwsrc->video_info; GstVideoInfo *info = &pwsrc->video_info;
GstVideoMeta *meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE, GstVideoMeta *meta = gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
GST_VIDEO_INFO_FORMAT (info), GST_VIDEO_INFO_FORMAT (info),
@ -625,11 +626,13 @@ static GstBuffer *dequeue_buffer(GstPipeWireSrc *pwsrc)
info->offset, info->offset,
info->stride); info->stride);
meta->n_planes = b->buffer->n_datas; meta->n_planes = MIN(meta->n_planes, b->buffer->n_datas);
for (i = 0; i < b->buffer->n_datas; i++) { for (i = 0; i < meta->n_planes; i++) {
struct spa_data *d = &b->buffer->datas[i]; struct spa_data *d = &b->buffer->datas[i];
meta->offset[i] = d->chunk->offset; meta->offset[i] = video_size;
meta->stride[i] = d->chunk->stride; meta->stride[i] = d->chunk->stride;
video_size += d->chunk->size;
} }
} }