summaryrefslogtreecommitdiffstats
path: root/sys/v4l2/gstv4l2bufferpool.c
diff options
context:
space:
mode:
authorRob Clark <rob@ti.com>2009-08-04 09:22:29 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2009-08-04 09:22:29 +0200
commit99e2ac121d7252aa858a8e0b2db0872d06ca226c (patch)
tree65ea038f9dd9f81507a67d156e217327ab256896 /sys/v4l2/gstv4l2bufferpool.c
parentf19cfbda96d098362cc2a2565197cef347878549 (diff)
v4l2sink: change where buffers get dequeued
It seems to cause strange occasional high latencies (almost 200ms) when dequeuing buffers from _buffer_alloc(). It is simpler and seems to work much better to dqbuf from the same thread that is queuing the next buffer.
Diffstat (limited to 'sys/v4l2/gstv4l2bufferpool.c')
-rw-r--r--sys/v4l2/gstv4l2bufferpool.c48
1 files changed, 9 insertions, 39 deletions
diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c
index bde4991b..494f46d7 100644
--- a/sys/v4l2/gstv4l2bufferpool.c
+++ b/sys/v4l2/gstv4l2bufferpool.c
@@ -61,13 +61,6 @@ gst_v4l2_buffer_finalize (GstV4l2Buffer * buffer)
GST_LOG_OBJECT (pool->v4l2elem, "finalizing buffer %p %d", buffer, index);
GST_V4L2_BUFFER_POOL_LOCK (pool);
- if (GST_BUFFER_SIZE (buffer) != 0) {
- /* BUFFER_SIZE is only set if the frame was dequeued */
- pool->num_live_buffers--;
- GST_DEBUG_OBJECT (pool->v4l2elem, "num_live_buffers--: %d",
- pool->num_live_buffers);
- }
-
if (pool->running) {
if (pool->requeuebuf) {
if (!gst_v4l2_buffer_pool_qbuf (pool, buffer)) {
@@ -368,6 +361,7 @@ gst_v4l2_buffer_pool_new (GstElement * v4l2elem, gint fd, gint num_buffers,
pool->buffers[n] = gst_v4l2_buffer_new (pool, n, caps);
if (!pool->buffers[n])
goto buffer_new_failed;
+ pool->num_live_buffers++;
g_async_queue_push (pool->avail_buffers, pool->buffers[n]);
}
@@ -452,46 +446,17 @@ gst_v4l2_buffer_pool_destroy (GstV4l2BufferPool * pool)
* Get an available buffer in the pool
*
* @pool the "this" object
- * @blocking if <code>TRUE</code>, then suspend until a buffer is available
*/
GstV4l2Buffer *
-gst_v4l2_buffer_pool_get (GstV4l2BufferPool * pool, gboolean blocking)
+gst_v4l2_buffer_pool_get (GstV4l2BufferPool * pool)
{
- GstV4l2Buffer *buf = NULL;
-
- do {
- buf = g_async_queue_try_pop (pool->avail_buffers);
+ GstV4l2Buffer *buf = g_async_queue_try_pop (pool->avail_buffers);
- /* if there isn't a buffer avail, let's try to dequeue one:
- */
- if (blocking && !buf) {
- GST_DEBUG_OBJECT (pool->v4l2elem, "No buffers available.. need to dqbuf");
- buf = gst_v4l2_buffer_pool_dqbuf (pool);
-
- /* note: if we get a buf, we don't want to use it directly (because
- * someone else could still hold a ref).. but instead we release our
- * reference to it, and if no one else holds a ref it will be returned
- * to the pool of available buffers.. and if not, we keep looping.
- */
- if (buf) {
- gst_buffer_unref (GST_BUFFER (buf));
- buf = NULL;
- }
- } else {
- break;
- }
- } while (1);
-
- if (buf) {
- pool->num_live_buffers++;
- GST_DEBUG_OBJECT (pool->v4l2elem, "num_live_buffers++: %d",
- pool->num_live_buffers);
+ if (buf)
GST_BUFFER_SIZE (buf) = buf->vbuffer.length;
- }
pool->running = TRUE;
-
return buf;
}
@@ -623,6 +588,11 @@ gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool)
return NULL;
}
+/**
+ * gst_v4l2_buffer_pool_available_buffers:
+ * Returns the number of buffers available to the driver, ie. buffers that
+ * have been QBUF'd but not yet DQBUF'd.
+ */
gint
gst_v4l2_buffer_pool_available_buffers (GstV4l2BufferPool * pool)
{