summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2011-02-17 18:37:19 +0100
committerWim Taymans <wim.taymans@collabora.co.uk>2011-03-02 11:23:21 +0100
commit2496523b3e379caadbfe85cda9eb5718f524b38a (patch)
tree0f5c9ea66c3a26672f2950e1af3e3180a6fa5c06
parent2b50d0a2f45e69485e4fd3567751bb0ae7514074 (diff)
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.
-rw-r--r--gst/gstbufferpool.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/gst/gstbufferpool.c b/gst/gstbufferpool.c
index 5d4796b01..1582daa2d 100644
--- a/gst/gstbufferpool.c
+++ b/gst/gstbufferpool.c
@@ -146,18 +146,33 @@ flush_buffers (GstBufferPool * pool)
}
}
+/* the default implementation for allocating and freeing the
+ * buffers when changing the flushing state */
static void
default_set_flushing (GstBufferPool * pool, gboolean flushing)
{
- g_atomic_int_set (&pool->flushing, flushing);
+ guint i;
+ GstBufferPoolPrivate *priv = pool->priv;
if (flushing) {
- /* write the control socket so that waiters get woken up and can check the
- * flushing flag we set above */
- gst_poll_write_control (pool->poll);
+ /* clear the pool */
flush_buffers (pool);
} 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);
+ 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))
pclass->set_flushing (pool, flushing);
+
+ if (!flushing)
+ gst_poll_read_control (pool->poll);
}
static gboolean
default_set_config (GstBufferPool * pool, GstStructure * config)
{
- guint i;
- GstBufferPoolClass *pclass;
GstBufferPoolPrivate *priv = pool->priv;
- pclass = GST_BUFFER_POOL_GET_CLASS (pool);
-
/* parse the config and keep around */
gst_buffer_pool_config_get (config, &priv->size, &priv->min_buffers,
&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;
}