v4l2bufferpool: cleanly handle streamon failure for output device

On streamon failure, the queued buffer is not released from the
bufferpool class point of view because it is queued to the driver and
the flush logic is not performed since we are not in streaming state.
It causes the v4l2 bufferpool to always return that stop method failed
and to leak v4l2 objects and buffers.

This commit solve this by performing the flush logic in error case, ie
flushing the allocator and restoring queued buffer state to non-queued.

https://bugzilla.gnome.org/show_bug.cgi?id=738102
This commit is contained in:
Aurélien Zanelli 2014-10-07 15:29:33 +02:00 committed by Nicolas Dufresne
parent 8e9c752eca
commit 1dcc883261

View file

@ -1712,7 +1712,21 @@ gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer ** buf)
/* if we are not streaming yet (this is the first buffer, start
* streaming now */
if (!gst_v4l2_buffer_pool_streamon (pool)) {
/* don't check return value because qbuf would have failed */
gst_v4l2_is_buffer_valid (to_queue, &group);
/* qbuf has taken the ref of the to_queue buffer but we are no in
* streaming state, so the flush logic won't be performed.
* To avoid leaks, flush the allocator and restore the queued
* buffer as non-queued */
gst_v4l2_allocator_flush (pool->vallocator);
pool->buffers[group->buffer.index] = NULL;
gst_mini_object_set_qdata (GST_MINI_OBJECT (to_queue),
GST_V4L2_IMPORT_QUARK, NULL, NULL);
gst_buffer_unref (to_queue);
g_atomic_int_add (&pool->num_queued, -1);
goto start_failed;
}