bufferpool: prealloc when unset flushing

According to the design doc we need to prealloc buffers when we unset the
flushing state, not in set_config.
Set the flushing state better.
This commit is contained in:
Wim Taymans 2011-02-17 18:37:19 +01:00
parent 2b50d0a2f4
commit 2496523b3e

View file

@ -146,18 +146,33 @@ flush_buffers (GstBufferPool * pool)
} }
} }
/* the default implementation for allocating and freeing the
* buffers when changing the flushing state */
static void static void
default_set_flushing (GstBufferPool * pool, gboolean flushing) default_set_flushing (GstBufferPool * pool, gboolean flushing)
{ {
g_atomic_int_set (&pool->flushing, flushing); guint i;
GstBufferPoolPrivate *priv = pool->priv;
if (flushing) { if (flushing) {
/* write the control socket so that waiters get woken up and can check the /* clear the pool */
* flushing flag we set above */
gst_poll_write_control (pool->poll);
flush_buffers (pool); flush_buffers (pool);
} else { } else {
gst_poll_read_control (pool->poll); GstBufferPoolClass *pclass;
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
if (G_LIKELY (pclass->alloc_buffer)) {
/* we need to prealloc buffers */
for (i = priv->min_buffers; i > 0; i--) {
GstBuffer *buffer;
if (pclass->alloc_buffer (pool, &buffer, NULL) == GST_FLOW_OK) {
/* store in the queue */
gst_buffer_pool_release_buffer (pool, buffer);
}
}
}
} }
} }
@ -178,38 +193,28 @@ gst_buffer_pool_set_flushing (GstBufferPool * pool, gboolean flushing)
pclass = GST_BUFFER_POOL_GET_CLASS (pool); pclass = GST_BUFFER_POOL_GET_CLASS (pool);
if (!g_atomic_int_compare_and_exchange (&pool->flushing, !flushing, flushing))
return;
if (flushing)
gst_poll_write_control (pool->poll);
if (G_LIKELY (pclass->set_flushing)) if (G_LIKELY (pclass->set_flushing))
pclass->set_flushing (pool, flushing); pclass->set_flushing (pool, flushing);
if (!flushing)
gst_poll_read_control (pool->poll);
} }
static gboolean static gboolean
default_set_config (GstBufferPool * pool, GstStructure * config) default_set_config (GstBufferPool * pool, GstStructure * config)
{ {
guint i;
GstBufferPoolClass *pclass;
GstBufferPoolPrivate *priv = pool->priv; GstBufferPoolPrivate *priv = pool->priv;
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
/* parse the config and keep around */ /* parse the config and keep around */
gst_buffer_pool_config_get (config, &priv->size, &priv->min_buffers, gst_buffer_pool_config_get (config, &priv->size, &priv->min_buffers,
&priv->max_buffers, &priv->prefix, &priv->postfix, &priv->align); &priv->max_buffers, &priv->prefix, &priv->postfix, &priv->align);
/* we need to prealloc buffers */
for (i = priv->min_buffers; i > 0; i--) {
GstBuffer *buffer;
if (G_LIKELY (pclass->alloc_buffer)) {
if (!pclass->alloc_buffer (pool, &buffer, NULL))
return FALSE;
} else
return FALSE;
/* store in the queue */
gst_atomic_queue_push (pool->queue, buffer);
gst_poll_write_control (pool->poll);
}
return TRUE; return TRUE;
} }