v4l2bufferpool: Prevent num_queued from going negative
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Fri, 23 May 2014 23:10:21 +0000 (19:10 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>
Sat, 24 May 2014 19:38:53 +0000 (15:38 -0400)
sys/v4l2/gstv4l2bufferpool.c

index 488f48f..ea08558 100644 (file)
@@ -990,12 +990,12 @@ gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool * pool, GstBuffer * buf)
 
   GST_LOG_OBJECT (pool, "queuing buffer %i", index);
 
+  g_atomic_int_inc (&pool->num_queued);
+  pool->buffers[index] = buf;
+
   if (!gst_v4l2_allocator_qbuf (pool->vallocator, group))
     goto queue_failed;
 
-  pool->buffers[index] = buf;
-  g_atomic_int_inc (&pool->num_queued);
-
   return GST_FLOW_OK;
 
 already_queued:
@@ -1008,6 +1008,8 @@ queue_failed:
     GST_ERROR_OBJECT (pool, "could not queue a buffer %i", index);
     /* Mark broken buffer to the allocator */
     GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_TAG_MEMORY);
+    g_atomic_int_add (&pool->num_queued, -1);
+    pool->buffers[index] = NULL;
     return GST_FLOW_ERROR;
   }
 }