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, resurrect them, then releasing will queue
* them back. */
- while (gst_v4l2_buffer_pool_resurrect_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)
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;
}
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
gst_v4l2_buffer_pool_stop (GstBufferPool * bpool)
{
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);
+
+ return ret;
+}
+
+gboolean
+gst_v4l2_buffer_pool_orphan (GstBufferPool ** bpool)
+{
+ GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (*bpool);
+ gboolean ret;
- vret = gst_v4l2_allocator_stop (pool->vallocator);
+ if (!GST_V4L2_ALLOCATOR_CAN_ORPHAN_BUFS (pool->vallocator))
+ return FALSE;
- if (vret == GST_V4L2_BUSY)
- GST_WARNING_OBJECT (pool, "some buffers are still outstanding");
+ if (g_getenv ("GST_V4L2_FORCE_DRAIN"))
+ return FALSE;
- ret = (vret == GST_V4L2_OK);
- }
+ 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, "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:
pool->can_poll_device = TRUE;
g_cond_init (&pool->empty_cond);
pool->empty = TRUE;
+ pool->orphaned = FALSE;
}
static void