From ef18a3c09bafb02cd8091b24f20ba7cb420af8fd Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 14 Jul 2011 16:21:36 +0200 Subject: [PATCH] v4l2: merge code --- sys/v4l2/gstv4l2object.c | 66 +++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c index 168e5bb..cc8ba7c 100644 --- a/sys/v4l2/gstv4l2object.c +++ b/sys/v4l2/gstv4l2object.c @@ -2514,7 +2514,7 @@ cleanup: } static GstFlowReturn -gst_v4l2_object_grab_frame (GstV4l2Object * v4l2object, GstBuffer ** buf) +gst_v4l2_object_get_mmap (GstV4l2Object * v4l2object, GstBuffer ** buf) { #define NUM_TRIALS 50 GstV4l2BufferPool *pool; @@ -2547,9 +2547,25 @@ gst_v4l2_object_grab_frame (GstV4l2Object * v4l2object, GstBuffer ** buf) } pool_buffer = gst_v4l2_buffer_pool_dqbuf (pool); - if (pool_buffer) - break; + if (pool_buffer == NULL) + goto no_buffer; + + if (v4l2object->size > 0) { + gsize size = gst_buffer_get_size (pool_buffer); + + /* if size does not match what we expected, try again */ + if (size != v4l2object->size) { + GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, READ, + (_("Got unexpected frame size of %u instead of %u."), + size, v4l2object->size), (NULL)); + gst_buffer_unref (pool_buffer); + goto no_buffer; + } + } + /* when we get here all is fine */ + break; + no_buffer: GST_WARNING_OBJECT (v4l2object->element, "trials=%d", trials); /* if the sync() got interrupted, we can retry */ @@ -2573,6 +2589,7 @@ gst_v4l2_object_grab_frame (GstV4l2Object * v4l2object, GstBuffer ** buf) } } + /* if we are handing out the last buffer in the pool, we need to make a * copy and bring the buffer back in the pool. */ need_copy = v4l2object->always_copy @@ -2620,49 +2637,6 @@ too_many_trials: } } -static GstFlowReturn -gst_v4l2_object_get_mmap (GstV4l2Object * v4l2object, GstBuffer ** buf) -{ - GstBuffer *temp; - GstFlowReturn ret; - guint size; - guint count = 0; - -again: - ret = gst_v4l2_object_grab_frame (v4l2object, &temp); - if (G_UNLIKELY (ret != GST_FLOW_OK)) - goto done; - - if (v4l2object->size > 0) { - size = gst_buffer_get_size (temp); - - /* if size does not match what we expected, try again */ - if (size != v4l2object->size) { - GST_ELEMENT_WARNING (v4l2object->element, RESOURCE, READ, - (_("Got unexpected frame size of %u instead of %u."), - size, v4l2object->size), (NULL)); - gst_buffer_unref (temp); - if (count++ > 50) - goto size_error; - - goto again; - } - } - - *buf = temp; -done: - return ret; - - /* ERRORS */ -size_error: - { - GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, READ, - (_("Error reading %d bytes on device '%s'."), - v4l2object->size, v4l2object->videodev), (NULL)); - return GST_FLOW_ERROR; - } -} - GstFlowReturn gst_v4l2_object_get_buffer (GstV4l2Object * v4l2object, GstBuffer ** buf) { -- 2.7.4