From cb311d57f5cda5b13ff3ede1bffaf1cddfd7ebd9 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 29 Apr 2014 16:49:52 -0400 Subject: [PATCH] v4l2bufferpool: Re-enqueue buffer at stream start --- sys/v4l2/gstv4l2bufferpool.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c index d89d2103c3..d03de5b6d7 100644 --- a/sys/v4l2/gstv4l2bufferpool.c +++ b/sys/v4l2/gstv4l2bufferpool.c @@ -602,10 +602,34 @@ start_streaming (GstV4l2BufferPool * pool) case GST_V4L2_IO_USERPTR: case GST_V4L2_IO_DMABUF: case GST_V4L2_IO_DMABUF_IMPORT: + { + /* For capture device, we need to re-enqueue buffers before be can let + * the driver stream again */ + if (!V4L2_TYPE_IS_OUTPUT (obj->type)) { + GstBufferPool *bpool = GST_BUFFER_POOL (pool); + GstBufferPoolAcquireParams params = { 0 }; + GstFlowReturn ret; + + while (pool->num_queued < pool->num_allocated) { + GstBuffer *buf; + + params.flags = GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT; + ret = GST_BUFFER_POOL_CLASS (parent_class)->acquire_buffer (bpool, + &buf, ¶ms); + + if (ret != GST_FLOW_OK) + goto requeue_failed; + + gst_v4l2_buffer_pool_release_buffer (bpool, buf); + } + } + GST_DEBUG_OBJECT (pool, "STREAMON"); + if (v4l2_ioctl (pool->video_fd, VIDIOC_STREAMON, &obj->type) < 0) goto start_failed; break; + } default: g_assert_not_reached (); break; @@ -622,6 +646,11 @@ start_failed: g_strerror (errno)); return FALSE; } +requeue_failed: + { + GST_ERROR_OBJECT (pool, "failed to re-enqueue buffers"); + return FALSE; + } } static void