From 3417a791acdd364c86974552550f853a9c56f5b9 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Mon, 3 Jun 2013 17:07:10 +0200 Subject: [PATCH] v4l2: call VIDIOC_REQBUFS with count = 0 in pool_finalize Without this the following sequence fails: - set_caps() - object_stop() (does nothing) - set_format() -> VIDIOC_S_FMT - set_config() -> VIDIOC_REQBUFS with count = N - set_caps() - object_stop() - pool_finalize() - set_format() -> VIDIOC_S_FMT => EBUSY Usually the pool is started after set_config(), in which case object_stop() will result in a pool_stop and therefore VIDIOC_REQBUFS with count = 0 but that is not guaranteed. Also calling VIDIOC_REQBUFS with count = 0 in pool_finalize() if necessary fixes this problem. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=701543 --- sys/v4l2/gstv4l2bufferpool.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c index d5fcd3375a..34a444b39e 100644 --- a/sys/v4l2/gstv4l2bufferpool.c +++ b/sys/v4l2/gstv4l2bufferpool.c @@ -538,6 +538,23 @@ start_failed: } } +static void +gst_v4l2_buffer_pool_free_buffers (GstV4l2BufferPool * pool) +{ + if (pool->num_buffers > 0) { + struct v4l2_requestbuffers breq; + memset (&breq, 0, sizeof (struct v4l2_requestbuffers)); + breq.type = pool->obj->type; + breq.count = 0; + breq.memory = V4L2_MEMORY_MMAP; + if (v4l2_ioctl (pool->video_fd, VIDIOC_REQBUFS, &breq) < 0) { + GST_ERROR_OBJECT (pool, "error releasing buffers: %s", + g_strerror (errno)); + } + pool->num_buffers = 0; + } +} + static gboolean gst_v4l2_buffer_pool_stop (GstBufferPool * bpool) { @@ -582,18 +599,7 @@ gst_v4l2_buffer_pool_stop (GstBufferPool * bpool) g_free (pool->buffers); pool->buffers = NULL; - if (pool->num_buffers > 0) { - struct v4l2_requestbuffers breq; - memset (&breq, 0, sizeof (struct v4l2_requestbuffers)); - breq.type = obj->type; - breq.count = 0; - breq.memory = V4L2_MEMORY_MMAP; - if (v4l2_ioctl (pool->video_fd, VIDIOC_REQBUFS, &breq) < 0) { - GST_ERROR_OBJECT (pool, "error releasing buffers: %s", - g_strerror (errno)); - } - pool->num_buffers = 0; - } + gst_v4l2_buffer_pool_free_buffers (pool); return ret; @@ -1003,6 +1009,8 @@ gst_v4l2_buffer_pool_finalize (GObject * object) { GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (object); + gst_v4l2_buffer_pool_free_buffers (pool); + if (pool->video_fd >= 0) v4l2_close (pool->video_fd); if (pool->allocator)