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.
This commit is contained in:
Nicolas Dufresne 2014-03-16 16:55:43 +01:00
parent efe68f086f
commit 6196026c76
2 changed files with 25 additions and 19 deletions

View file

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

View file

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