From 6196026c76f84e01eb6e81fbb60e052c865e13c9 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Sun, 16 Mar 2014 16:55:43 +0100 Subject: [PATCH] v4l2bufferpool: Enforce activation outside of process Enforce pool being activate from before calling pool process. This should help catching basic errors in the usage of buffer pool. --- sys/v4l2/gstv4l2bufferpool.c | 21 ++------------------- sys/v4l2/gstv4l2sink.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c index f1170301fe..eb359044bc 100644 --- a/sys/v4l2/gstv4l2bufferpool.c +++ b/sys/v4l2/gstv4l2bufferpool.c @@ -1438,6 +1438,8 @@ gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer * buf) GST_DEBUG_OBJECT (pool, "process buffer %p", buf); + g_return_val_if_fail (gst_buffer_pool_is_active (bpool), GST_FLOW_ERROR); + switch (obj->type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: @@ -1495,20 +1497,6 @@ gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer * buf) GST_LOG_OBJECT (pool, "processing buffer from our pool"); } else { GST_LOG_OBJECT (pool, "alloc buffer from our pool"); - if (!gst_buffer_pool_is_active (bpool)) { - GstStructure *config; - - /* this pool was not activated, configure and activate */ - GST_DEBUG_OBJECT (pool, "activating pool"); - - config = gst_buffer_pool_get_config (bpool); - gst_buffer_pool_config_add_option (config, - GST_BUFFER_POOL_OPTION_VIDEO_META); - gst_buffer_pool_set_config (bpool, config); - - if (!gst_buffer_pool_set_active (bpool, TRUE)) - goto activate_failed; - } /* this can block if all buffers are outstanding which would be * strange because we would expect the upstream element to have @@ -1565,11 +1553,6 @@ done: return ret; /* ERRORS */ -activate_failed: - { - GST_ERROR_OBJECT (obj->element, "failed to activate pool"); - return GST_FLOW_ERROR; - } acquire_failed: { GST_WARNING_OBJECT (obj->element, "failed to acquire a buffer: %s", diff --git a/sys/v4l2/gstv4l2sink.c b/sys/v4l2/gstv4l2sink.c index 24f6d3f9d6..41989d5348 100644 --- a/sys/v4l2/gstv4l2sink.c +++ b/sys/v4l2/gstv4l2sink.c @@ -600,12 +600,28 @@ gst_v4l2sink_show_frame (GstBaseSink * bsink, GstBuffer * buf) GstFlowReturn ret; GstV4l2Sink *v4l2sink = GST_V4L2SINK (bsink); GstV4l2Object *obj = v4l2sink->v4l2object; + GstBufferPool *bpool = GST_BUFFER_POOL (obj->pool); GST_DEBUG_OBJECT (v4l2sink, "render buffer: %p", buf); if (G_UNLIKELY (obj->pool == NULL)) goto not_negotiated; + if (G_UNLIKELY (!gst_buffer_pool_is_active (bpool))) { + GstStructure *config; + + /* this pool was not activated, configure and activate */ + GST_DEBUG_OBJECT (bsink, "activating pool"); + + config = gst_buffer_pool_get_config (bpool); + gst_buffer_pool_config_add_option (config, + GST_BUFFER_POOL_OPTION_VIDEO_META); + gst_buffer_pool_set_config (bpool, config); + + if (!gst_buffer_pool_set_active (bpool, TRUE)) + goto activate_failed; + } + ret = gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL_CAST (obj->pool), buf); @@ -617,4 +633,11 @@ not_negotiated: GST_ERROR_OBJECT (bsink, "not negotiated"); return GST_FLOW_NOT_NEGOTIATED; } +activate_failed: + { + GST_ELEMENT_ERROR (bsink, RESOURCE, SETTINGS, + (_("Failed to allocated required memory.")), + ("Buffer pool activation failed")); + return GST_FLOW_ERROR; + } }