From 6afd1c5d57007d81dfcda4e0fd1ecfe972f1b4b5 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 19 Feb 2015 23:12:31 -0500 Subject: [PATCH] v4l2: Enable copy when no known allocation params When there is no allocation parameters in the query, enable copy threshold. When this threshold is reached, the buffer pool will start copying when the pool reaches a critical level. If the driver supports CREATE_BUFS, this will be used instead. --- sys/v4l2/gstv4l2bufferpool.c | 18 +++++++++++------- sys/v4l2/gstv4l2bufferpool.h | 3 +++ sys/v4l2/gstv4l2object.c | 12 ++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c index e782c157d2..11201f95d4 100644 --- a/sys/v4l2/gstv4l2bufferpool.c +++ b/sys/v4l2/gstv4l2bufferpool.c @@ -686,15 +686,11 @@ gst_v4l2_buffer_pool_start (GstBufferPool * bpool) * falling back to copy if the pipeline needed more buffers. This also * prevent having to do REQBUFS(N)/REQBUFS(0) everytime configure is * called. */ - if (count != min_buffers) { - GST_WARNING_OBJECT (pool, "using %u buffers instead of %u", - count, min_buffers); + if (count != min_buffers || pool->enable_copy_threshold) { + GST_WARNING_OBJECT (pool, + "Uncertain or not enough buffers, enabling copy threshold"); min_buffers = count; copy_threshold = min_latency; - - /* The initial minimum could be provide either by GstBufferPool or - * driver needs. */ - min_buffers = count; } break; @@ -1863,3 +1859,11 @@ gst_v4l2_buffer_pool_set_other_pool (GstV4l2BufferPool * pool, gst_object_unref (pool->other_pool); pool->other_pool = gst_object_ref (other_pool); } + +void +gst_v4l2_buffer_pool_copy_at_threshold (GstV4l2BufferPool * pool, gboolean copy) +{ + GST_OBJECT_LOCK (pool); + pool->enable_copy_threshold = copy; + GST_OBJECT_UNLOCK (pool); +} diff --git a/sys/v4l2/gstv4l2bufferpool.h b/sys/v4l2/gstv4l2bufferpool.h index 76013cef0d..dc2999e7b3 100644 --- a/sys/v4l2/gstv4l2bufferpool.h +++ b/sys/v4l2/gstv4l2bufferpool.h @@ -75,6 +75,7 @@ struct _GstV4l2BufferPool GstVideoInfo caps_info; /* Default video information */ gboolean add_videometa; /* set if video meta should be added */ + gboolean enable_copy_threshold; /* If copy_threshold should be set */ guint min_latency; /* number of buffers we will hold */ guint max_latency; /* number of buffers we can hold */ @@ -103,6 +104,8 @@ GstFlowReturn gst_v4l2_buffer_pool_process (GstV4l2BufferPool * bpool, Gst void gst_v4l2_buffer_pool_set_other_pool (GstV4l2BufferPool * pool, GstBufferPool * other_pool); +void gst_v4l2_buffer_pool_copy_at_threshold (GstV4l2BufferPool * pool, + gboolean copy); G_END_DECLS diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c index 64e881fa7e..94a11559c2 100644 --- a/sys/v4l2/gstv4l2object.c +++ b/sys/v4l2/gstv4l2object.c @@ -3306,6 +3306,18 @@ gst_v4l2_object_decide_allocation (GstV4l2Object * obj, GstQuery * query) * driver and 1 more, so we don't endup up with everything downstream or * held by the decoder. */ own_min = min + obj->min_buffers + 1; + + /* If no allocation parameters where provided, allow for a little more + * buffers and enable copy threshold */ + if (!update) { + own_min += 3; + gst_v4l2_buffer_pool_copy_at_threshold (GST_V4L2_BUFFER_POOL (pool), + TRUE); + } else { + gst_v4l2_buffer_pool_copy_at_threshold (GST_V4L2_BUFFER_POOL (pool), + FALSE); + } + } else { /* In this case we'll have to configure two buffer pool. For our buffer * pool, we'll need what the driver one, and one more, so we can dequeu */