v4l2bufferpool: support orphaning
authorPhilipp Zabel <p.zabel@pengutronix.de>
Thu, 24 Jan 2019 15:12:13 +0000 (16:12 +0100)
committerNicolas Dufresne <nicolas@ndufresne.ca>
Fri, 5 Apr 2019 16:01:55 +0000 (16:01 +0000)
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
sys/v4l2/gstv4l2bufferpool.h

index da19807..a0a17bf 100644 (file)
@@ -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
index 0fffc71..285703c 100644 (file)
@@ -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__ */