From fcfdececce2ab5e36c7b7317a7cae393f4ae7cc3 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 27 Jul 2011 13:41:28 +0200 Subject: [PATCH] bufferpool: check for metadata Only add video metadata when it was configured in the pool. Fail if there was no video metadata configured and the strides are not the default ones. --- sys/v4l2/gstv4l2bufferpool.c | 29 +++++++++++++++++++++++++++-- sys/v4l2/gstv4l2bufferpool.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c index f7393704cd..91ee34c32e 100644 --- a/sys/v4l2/gstv4l2bufferpool.c +++ b/sys/v4l2/gstv4l2bufferpool.c @@ -174,7 +174,7 @@ gst_v4l2_buffer_pool_alloc_buffer (GstBufferPool * bpool, GstBuffer ** buffer, meta->mem, NULL, meta->vbuffer.length, 0, meta->vbuffer.length)); /* add metadata to raw video buffers */ - if (info->finfo) { + if (pool->add_videometa && info->finfo) { gsize offset[GST_VIDEO_MAX_PLANES]; gint stride[GST_VIDEO_MAX_PLANES]; @@ -226,12 +226,29 @@ static gboolean gst_v4l2_buffer_pool_set_config (GstBufferPool * bpool, GstStructure * config) { GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); + GstV4l2Object *obj = pool->obj; const GstCaps *caps; guint size, min_buffers, max_buffers; guint prefix, align; GST_DEBUG_OBJECT (pool, "set config"); + pool->add_videometa = + gst_buffer_pool_config_has_meta (config, GST_META_API_VIDEO); + + if (!pool->add_videometa) { + gint stride; + + /* we don't have video metadata, see if the strides are compatible */ + stride = GST_VIDEO_INFO_PLANE_STRIDE (&obj->info, 0); + + GST_DEBUG_OBJECT (pool, "no videometadata, checking strides %d and %u", + stride, obj->bytesperline); + + if (stride != obj->bytesperline) + goto missing_video_api; + } + /* parse the config and keep around */ if (!gst_buffer_pool_config_get (config, &caps, &size, &min_buffers, &max_buffers, &prefix, &align)) @@ -250,9 +267,17 @@ gst_v4l2_buffer_pool_set_config (GstBufferPool * bpool, GstStructure * config) return GST_BUFFER_POOL_CLASS (parent_class)->set_config (bpool, config); + /* ERRORS */ +missing_video_api: + { + GST_ERROR_OBJECT (pool, "missing GstMetaVideo API in config, " + "default stride: %d, wanted stride %u", + GST_VIDEO_INFO_PLANE_STRIDE (&obj->info, 0), obj->bytesperline); + return FALSE; + } wrong_config: { - GST_WARNING_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config); + GST_ERROR_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config); return FALSE; } } diff --git a/sys/v4l2/gstv4l2bufferpool.h b/sys/v4l2/gstv4l2bufferpool.h index f677e952b0..2765dfee3f 100644 --- a/sys/v4l2/gstv4l2bufferpool.h +++ b/sys/v4l2/gstv4l2bufferpool.h @@ -56,6 +56,7 @@ struct _GstV4l2BufferPool guint max_buffers; guint prefix; guint align; + gboolean add_videometa; guint num_buffers; guint num_allocated; /* number of buffers allocated by the driver */