diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c index 5a2d4a030a..e12ec10156 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2bufferpool.c @@ -1240,8 +1240,7 @@ gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer, GstV4l2Object *obj = pool->obj; GstClockTime timestamp; GstV4l2MemoryGroup *group; - GstVideoMeta *vmeta; - gsize size; + const GstVideoInfo *info = &obj->info; gint i; gint old_buffer_state; @@ -1292,9 +1291,9 @@ gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer, timestamp = GST_TIMEVAL_TO_TIME (group->buffer.timestamp); - size = 0; - vmeta = gst_buffer_get_video_meta (outbuf); for (i = 0; i < group->n_mem; i++) { + const GstVideoFormatInfo *finfo = info->finfo; + GST_LOG_OBJECT (pool, "dequeued buffer %p seq:%d (ix=%d), mem %p used %d, plane=%d, flags %08x, ts %" GST_TIME_FORMAT ", pool-queued=%d, buffer=%p, previous-state=%i", @@ -1302,10 +1301,15 @@ gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer, group->planes[i].bytesused, i, group->buffer.flags, GST_TIME_ARGS (timestamp), pool->num_queued, outbuf, old_buffer_state); - if (vmeta) { - vmeta->offset[i] = size; - size += gst_memory_get_sizes (group->mem[i], NULL, NULL); + /* Ensure our offset matches the expected plane size, or image size if + * there is only one memory */ + if (group->n_mem == 1) { + gst_memory_resize (group->mem[0], 0, info->size + info->offset[0]); + break; } + + if (!GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) + gst_memory_resize (group->mem[i], 0, obj->plane_size[i]); } /* Ignore timestamp and field for OUTPUT device */ diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c index 5679ef4226..ea5e1c9ff2 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.c @@ -3576,18 +3576,11 @@ gst_v4l2_object_save_format (GstV4l2Object * v4l2object, if ((align->padding_left + align->padding_top) > 0) GST_WARNING_OBJECT (v4l2object->dbg_obj, "Left and top padding is not permitted for tiled formats"); + memset (v4l2object->plane_size, 0, + sizeof (v4l2object->plane_size[0] * GST_VIDEO_MAX_PLANES)); } else { - for (i = 0; i < finfo->n_planes; i++) { - gint vedge, hedge; - - /* FIXME we assume plane as component as this is true for all supported - * format we support. */ - - hedge = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, i, align->padding_left); - vedge = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, i, align->padding_top); - - info->offset[i] += (vedge * info->stride[i]) + - (hedge * GST_VIDEO_INFO_COMP_PSTRIDE (info, i)); + if (!gst_video_info_align_full (info, align, v4l2object->plane_size)) { + GST_WARNING_OBJECT (v4l2object->dbg_obj, "Failed to align video info"); } } diff --git a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.h b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.h index 13b6f91ad6..5223cbbaca 100644 --- a/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.h +++ b/subprojects/gst-plugins-good/sys/v4l2/gstv4l2object.h @@ -148,6 +148,7 @@ struct _GstV4l2Object { GstVideoInfo info; GstVideoAlignment align; GstVideoTransferFunction transfer; + gsize plane_size[GST_VIDEO_MAX_PLANES]; /* Features */ gboolean need_video_meta;