}
static GstFlowReturn
-gst_v4l2_buffer_pool_resurect_buffer (GstV4l2BufferPool * pool)
+gst_v4l2_buffer_pool_resurrect_buffer (GstV4l2BufferPool * pool)
{
GstBufferPoolAcquireParams params = { 0 };
GstBuffer *buffer = NULL;
case GST_V4L2_IO_DMABUF:
case GST_V4L2_IO_DMABUF_IMPORT:
if (!V4L2_TYPE_IS_OUTPUT (pool->obj->type)) {
+ guint i;
+
/* For captures, we need to enqueue buffers before we start streaming,
* so the driver don't underflow immediatly. As we have put then back
- * into the base class queue, resurect them, then releasing will queue
+ * into the base class queue, resurrect them, then releasing will queue
* them back. */
- while (gst_v4l2_buffer_pool_resurect_buffer (pool) == GST_FLOW_OK)
- continue;
+ for (i = 0; i < pool->num_allocated; i++)
+ gst_v4l2_buffer_pool_resurrect_buffer (pool);
}
if (obj->ioctl (pool->video_fd, VIDIOC_STREAMON, &obj->type) < 0)
GST_DEBUG_OBJECT (pool, "activating pool");
+ if (pool->other_pool) {
+ GstBuffer *buffer;
+
+ if (!gst_buffer_pool_set_active (pool->other_pool, TRUE))
+ goto other_pool_failed;
+
+ if (gst_buffer_pool_acquire_buffer (pool->other_pool, &buffer, NULL) !=
+ GST_FLOW_OK)
+ goto other_pool_failed;
+
+ if (!gst_v4l2_object_try_import (obj, buffer)) {
+ gst_buffer_unref (buffer);
+ goto cannot_import;
+ }
+ gst_buffer_unref (buffer);
+ }
+
config = gst_buffer_pool_get_config (bpool);
if (!gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
&max_buffers))
count = gst_v4l2_allocator_start (pool->vallocator, min_buffers,
V4L2_MEMORY_MMAP);
+ pool->num_allocated = count;
if (count < GST_V4L2_MIN_BUFFERS) {
min_buffers = count;
pclass->set_config (bpool, config);
gst_structure_free (config);
- if (pool->other_pool)
- if (!gst_buffer_pool_set_active (pool->other_pool, TRUE))
- goto other_pool_failed;
-
/* now, allocate the buffers: */
if (!pclass->start (bpool))
goto start_failed;
if (!V4L2_TYPE_IS_OUTPUT (obj->type)) {
+ if (g_atomic_int_get (&pool->num_queued) < min_buffers)
+ goto queue_failed;
+
pool->group_released_handler =
g_signal_connect_swapped (pool->vallocator, "group-released",
- G_CALLBACK (gst_v4l2_buffer_pool_resurect_buffer), pool);
+ G_CALLBACK (gst_v4l2_buffer_pool_resurrect_buffer), pool);
ret = gst_v4l2_buffer_pool_streamon (pool);
}
}
other_pool_failed:
{
- GST_ERROR_OBJECT (pool, "failed to active the other pool %"
+ GST_ERROR_OBJECT (pool, "failed to activate the other pool %"
GST_PTR_FORMAT, pool->other_pool);
return FALSE;
}
+queue_failed:
+ {
+ GST_ERROR_OBJECT (pool, "failed to queue buffers into the capture queue");
+ return FALSE;
+ }
+cannot_import:
+ {
+ GST_ERROR_OBJECT (pool, "cannot import buffers from downstream pool");
+ return FALSE;
+ }
+}
+
+static gboolean
+gst_v4l2_buffer_pool_vallocator_stop (GstV4l2BufferPool * pool)
+{
+ GstV4l2Return vret;
+
+ if (!pool->vallocator)
+ return TRUE;
+
+ vret = gst_v4l2_allocator_stop (pool->vallocator);
+
+ if (vret == GST_V4L2_BUSY)
+ GST_WARNING_OBJECT (pool, "some buffers are still outstanding");
+
+ return (vret == GST_V4L2_OK);
}
static gboolean
GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
gboolean ret;
+ if (pool->orphaned)
+ return gst_v4l2_buffer_pool_vallocator_stop (pool);
+
GST_DEBUG_OBJECT (pool, "stopping pool");
if (pool->group_released_handler > 0) {
ret = GST_BUFFER_POOL_CLASS (parent_class)->stop (bpool);
- if (ret && pool->vallocator) {
- GstV4l2Return vret;
+ if (ret)
+ ret = gst_v4l2_buffer_pool_vallocator_stop (pool);
- vret = gst_v4l2_allocator_stop (pool->vallocator);
+ return ret;
+}
- if (vret == GST_V4L2_BUSY)
- GST_WARNING_OBJECT (pool, "some buffers are still outstanding");
+gboolean
+gst_v4l2_buffer_pool_orphan (GstBufferPool ** bpool)
+{
+ GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (*bpool);
+ gboolean ret;
- ret = (vret == GST_V4L2_OK);
- }
+ if (!GST_V4L2_ALLOCATOR_CAN_ORPHAN_BUFS (pool->vallocator))
+ return FALSE;
+
+ if (g_getenv ("GST_V4L2_FORCE_DRAIN"))
+ return FALSE;
+
+ GST_DEBUG_OBJECT (pool, "orphaning pool");
+
+ gst_buffer_pool_set_active (*bpool, FALSE);
+ /*
+ * If the buffer pool has outstanding buffers, it will not be stopped
+ * by the base class when set inactive. Stop it manually and mark it
+ * as orphaned
+ */
+ ret = gst_v4l2_buffer_pool_stop (*bpool);
+ if (!ret)
+ ret = gst_v4l2_allocator_orphan (pool->vallocator);
+
+ if (!ret)
+ goto orphan_failed;
+ pool->orphaned = TRUE;
+ gst_object_unref (*bpool);
+ *bpool = NULL;
+
+orphan_failed:
return ret;
}
GST_DEBUG_OBJECT (pool, "acquire");
- /* If this is being called to resurect a lost buffer */
+ /* If this is being called to resurrect a lost buffer */
if (params && params->flags & GST_V4L2_BUFFER_POOL_ACQUIRE_FLAG_RESURRECT) {
ret = pclass->acquire_buffer (bpool, buffer, params);
goto done;
GST_DEBUG_OBJECT (pool, "release buffer %p", buffer);
+ /* If the buffer's pool has been orphaned, dispose of it so that
+ * the pool resources can be freed */
+ if (pool->orphaned) {
+ GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
+ pclass->release_buffer (bpool, buffer);
+ return;
+ }
+
switch (obj->type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
{
GstV4l2MemoryGroup *group;
if (gst_v4l2_is_buffer_valid (buffer, &group)) {
+ GstFlowReturn ret = GST_FLOW_OK;
+
gst_v4l2_allocator_reset_group (pool->vallocator, group);
/* queue back in the device */
if (pool->other_pool)
- gst_v4l2_buffer_pool_prepare_buffer (pool, buffer, NULL);
- if (gst_v4l2_buffer_pool_qbuf (pool, buffer, group) != GST_FLOW_OK)
+ ret = gst_v4l2_buffer_pool_prepare_buffer (pool, buffer, NULL);
+ if (ret != GST_FLOW_OK ||
+ gst_v4l2_buffer_pool_qbuf (pool, buffer, group) != GST_FLOW_OK)
pclass->release_buffer (bpool, buffer);
} else {
/* Simply release invalide/modified buffer, the allocator will
pool->can_poll_device = TRUE;
g_cond_init (&pool->empty_cond);
pool->empty = TRUE;
+ pool->orphaned = FALSE;
}
static void
guint num_queued;
gsize size = gst_buffer_get_size (*buf);
- if (size == 0) {
- if (GST_BUFFER_FLAG_IS_SET (*buf, GST_BUFFER_FLAG_CORRUPTED))
- goto buffer_corrupted;
- else
- goto eos;
- }
+ /* Legacy M2M devices return empty buffer when drained */
+ if (size == 0 && GST_V4L2_IS_M2M (obj->device_caps))
+ goto eos;
if (GST_VIDEO_INFO_FORMAT (&pool->caps_info) !=
GST_VIDEO_FORMAT_ENCODED && size < pool->size)
/* If we have no more buffer, and can allocate it time to do so */
if (num_queued == 0) {
if (GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP)) {
- ret = gst_v4l2_buffer_pool_resurect_buffer (pool);
+ ret = gst_v4l2_buffer_pool_resurrect_buffer (pool);
if (ret == GST_FLOW_OK)
goto done;
}
GstBuffer *copy;
if (GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP)) {
- ret = gst_v4l2_buffer_pool_resurect_buffer (pool);
+ ret = gst_v4l2_buffer_pool_resurrect_buffer (pool);
if (ret == GST_FLOW_OK)
goto done;
}
/* An empty buffer on capture indicates the end of stream */
if (gst_buffer_get_size (tmp) == 0) {
- gboolean corrupted = GST_BUFFER_FLAG_IS_SET (tmp,
- GST_BUFFER_FLAG_CORRUPTED);
-
gst_v4l2_buffer_pool_release_buffer (bpool, tmp);
- if (corrupted)
- goto buffer_corrupted;
- else
+ /* Legacy M2M devices return empty buffer when drained */
+ if (GST_V4L2_IS_M2M (obj->device_caps))
goto eos;
}
GST_ERROR_OBJECT (pool, "failed to copy buffer");
return ret;
}
-buffer_corrupted:
- {
- GST_WARNING_OBJECT (pool, "Dropping corrupted buffer without payload");
- gst_buffer_unref (*buf);
- *buf = NULL;
- return GST_V4L2_FLOW_CORRUPTED_BUFFER;
- }
buffer_truncated:
{
GST_WARNING_OBJECT (pool,