mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-01 03:52:25 +00:00
v4l2: merge code
This commit is contained in:
parent
33d93069c1
commit
ef18a3c09b
1 changed files with 20 additions and 46 deletions
|
@ -2514,7 +2514,7 @@ cleanup:
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_v4l2_object_grab_frame (GstV4l2Object * v4l2object, GstBuffer ** buf)
|
gst_v4l2_object_get_mmap (GstV4l2Object * v4l2object, GstBuffer ** buf)
|
||||||
{
|
{
|
||||||
#define NUM_TRIALS 50
|
#define NUM_TRIALS 50
|
||||||
GstV4l2BufferPool *pool;
|
GstV4l2BufferPool *pool;
|
||||||
|
@ -2547,9 +2547,25 @@ gst_v4l2_object_grab_frame (GstV4l2Object * v4l2object, GstBuffer ** buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
pool_buffer = gst_v4l2_buffer_pool_dqbuf (pool);
|
pool_buffer = gst_v4l2_buffer_pool_dqbuf (pool);
|
||||||
if (pool_buffer)
|
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;
|
break;
|
||||||
|
|
||||||
|
no_buffer:
|
||||||
GST_WARNING_OBJECT (v4l2object->element, "trials=%d", trials);
|
GST_WARNING_OBJECT (v4l2object->element, "trials=%d", trials);
|
||||||
|
|
||||||
/* if the sync() got interrupted, we can retry */
|
/* 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
|
/* 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. */
|
* copy and bring the buffer back in the pool. */
|
||||||
need_copy = v4l2object->always_copy
|
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
|
GstFlowReturn
|
||||||
gst_v4l2_object_get_buffer (GstV4l2Object * v4l2object, GstBuffer ** buf)
|
gst_v4l2_object_get_buffer (GstV4l2Object * v4l2object, GstBuffer ** buf)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue