mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-20 23:36:38 +00:00
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:
parent
1199b9fc81
commit
301fa0e935
1 changed files with 19 additions and 10 deletions
|
@ -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 */
|
||||||
|
|
Loading…
Reference in a new issue