From dfc20013ccc6735f4116fa7da09bbf72fc657f38 Mon Sep 17 00:00:00 2001
From: Philipp Zabel
Date: Thu, 24 Jan 2019 16:12:13 +0100
Subject: [PATCH] v4l2bufferpool: support orphaning
Now that the v4l2allocator allows orphaning the V4L2 buffer queue, add
support for orphaning in the v4l2bufferpool. gst_v4l2_buffer_pool_orphan
can be used as a replacement for gst_v4l2_buffer_pool_stop, without
having to wait for buffers to be returned to the pool.
---
sys/v4l2/gstv4l2bufferpool.c | 34 ++++++++++++++++++++++++++++++++++
sys/v4l2/gstv4l2bufferpool.h | 4 ++++
2 files changed, 38 insertions(+)
diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c
index da19807b89..a0a17bf22e 100644
--- a/sys/v4l2/gstv4l2bufferpool.c
+++ b/sys/v4l2/gstv4l2bufferpool.c
@@ -938,6 +938,9 @@ gst_v4l2_buffer_pool_stop (GstBufferPool * bpool)
GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
gboolean ret;
+ if (pool->orphaned)
+ return TRUE;
+
GST_DEBUG_OBJECT (pool, "stopping pool");
if (pool->group_released_handler > 0) {
@@ -970,6 +973,36 @@ gst_v4l2_buffer_pool_stop (GstBufferPool * bpool)
return ret;
}
+gboolean
+gst_v4l2_buffer_pool_orphan (GstBufferPool ** bpool)
+{
+ GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (*bpool);
+ gboolean ret;
+
+ 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)
+ gst_v4l2_allocator_orphan (pool->vallocator);
+
+ pool->orphaned = TRUE;
+ gst_object_unref (*bpool);
+ *bpool = NULL;
+ return ret;
+}
+
static void
gst_v4l2_buffer_pool_flush_start (GstBufferPool * bpool)
{
@@ -1564,6 +1597,7 @@ gst_v4l2_buffer_pool_init (GstV4l2BufferPool * pool)
pool->can_poll_device = TRUE;
g_cond_init (&pool->empty_cond);
pool->empty = TRUE;
+ pool->orphaned = FALSE;
}
static void
diff --git a/sys/v4l2/gstv4l2bufferpool.h b/sys/v4l2/gstv4l2bufferpool.h
index 0fffc71c08..285703cdb7 100644
--- a/sys/v4l2/gstv4l2bufferpool.h
+++ b/sys/v4l2/gstv4l2bufferpool.h
@@ -64,6 +64,8 @@ struct _GstV4l2BufferPool
gboolean empty;
GCond empty_cond;
+ gboolean orphaned;
+
GstV4l2Allocator *vallocator;
GstAllocator *allocator;
GstAllocationParams params;
@@ -109,6 +111,8 @@ void gst_v4l2_buffer_pool_copy_at_threshold (GstV4l2BufferPool *
gboolean gst_v4l2_buffer_pool_flush (GstBufferPool *pool);
+gboolean gst_v4l2_buffer_pool_orphan (GstBufferPool ** pool);
+
G_END_DECLS
#endif /*__GST_V4L2_BUFFER_POOL_H__ */