bufferpool: refactor free_buffer

Make a do_free_buffer method to also decrements the number of allocated
buffers. Stop will now be successful when all buffers are freed.
This commit is contained in:
Wim Taymans 2014-02-25 17:46:49 +01:00
parent 1199b9fc81
commit 301fa0e935

View file

@ -359,27 +359,36 @@ default_free_buffer (GstBufferPool * pool, GstBuffer * buffer)
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
} }
static void
do_free_buffer (GstBufferPool * pool, GstBuffer * buffer)
{
GstBufferPoolPrivate *priv;
GstBufferPoolClass *pclass;
priv = pool->priv;
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
g_atomic_int_add (&priv->cur_buffers, -1);
GST_LOG_OBJECT (pool, "freeing buffer %p (%u left)", buffer,
priv->cur_buffers);
if (G_LIKELY (pclass->free_buffer))
pclass->free_buffer (pool, buffer);
}
/* must be called with the lock */ /* must be called with the lock */
static gboolean static gboolean
default_stop (GstBufferPool * pool) default_stop (GstBufferPool * pool)
{ {
GstBufferPoolPrivate *priv = pool->priv; GstBufferPoolPrivate *priv = pool->priv;
GstBuffer *buffer; GstBuffer *buffer;
GstBufferPoolClass *pclass;
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
/* clear the pool */ /* clear the pool */
while ((buffer = gst_atomic_queue_pop (priv->queue))) { while ((buffer = gst_atomic_queue_pop (priv->queue))) {
GST_LOG_OBJECT (pool, "freeing buffer %p", buffer);
gst_poll_read_control (priv->poll); gst_poll_read_control (priv->poll);
do_free_buffer (pool, buffer);
if (G_LIKELY (pclass->free_buffer))
pclass->free_buffer (pool, buffer);
} }
priv->cur_buffers = 0; return priv->cur_buffers == 0;
return TRUE;
} }
/* must be called with the lock */ /* must be called with the lock */