2010-11-02 17:56:29 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2010 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
*
|
|
|
|
* gstbufferpool.c: GstBufferPool baseclass
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-11-02 17:56:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gstbufferpool
|
|
|
|
* @short_description: Pool for buffers
|
|
|
|
* @see_also: #GstBuffer
|
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* A #GstBufferPool is an object that can be used to pre-allocate and recycle
|
2012-03-28 16:12:23 +00:00
|
|
|
* buffers of the same size and with the same properties.
|
|
|
|
*
|
|
|
|
* A #GstBufferPool is created with gst_buffer_pool_new().
|
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* Once a pool is created, it needs to be configured. A call to
|
|
|
|
* gst_buffer_pool_get_config() returns the current configuration structure from
|
|
|
|
* the pool. With gst_buffer_pool_config_set_params() and
|
|
|
|
* gst_buffer_pool_config_set_allocator() the bufferpool parameters and
|
|
|
|
* allocator can be configured. Other properties can be configured in the pool
|
|
|
|
* depending on the pool implementation.
|
2012-03-28 16:12:23 +00:00
|
|
|
*
|
|
|
|
* A bufferpool can have extra options that can be enabled with
|
|
|
|
* gst_buffer_pool_config_add_option(). The available options can be retrieved
|
|
|
|
* with gst_buffer_pool_get_options(). Some options allow for additional
|
|
|
|
* configuration properties to be set.
|
|
|
|
*
|
|
|
|
* After the configuration structure has been configured,
|
|
|
|
* gst_buffer_pool_set_config() updates the configuration in the pool. This can
|
|
|
|
* fail when the configuration structure is not accepted.
|
|
|
|
*
|
|
|
|
* After the a pool has been configured, it can be activated with
|
|
|
|
* gst_buffer_pool_set_active(). This will preallocate the configured resources
|
|
|
|
* in the pool.
|
|
|
|
*
|
|
|
|
* When the pool is active, gst_buffer_pool_acquire_buffer() can be used to
|
|
|
|
* retrieve a buffer from the pool.
|
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* Buffers allocated from a bufferpool will automatically be returned to the
|
|
|
|
* pool with gst_buffer_pool_release_buffer() when their refcount drops to 0.
|
2012-03-28 16:12:23 +00:00
|
|
|
*
|
|
|
|
* The bufferpool can be deactivated again with gst_buffer_pool_set_active().
|
|
|
|
* All further gst_buffer_pool_acquire_buffer() calls will return an error. When
|
|
|
|
* all buffers are returned to the pool they will be freed.
|
|
|
|
*
|
|
|
|
* Use gst_object_unref() to release the reference to a bufferpool. If the
|
|
|
|
* refcount of the pool reaches 0, the pool will be freed.
|
2010-11-02 17:56:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gst_private.h"
|
2011-10-05 09:20:37 +00:00
|
|
|
#include "glib-compat-private.h"
|
2010-11-02 17:56:29 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2012-02-27 08:48:06 +00:00
|
|
|
#include "gstatomicqueue.h"
|
|
|
|
#include "gstpoll.h"
|
2010-11-02 17:56:29 +00:00
|
|
|
#include "gstinfo.h"
|
2011-02-17 16:29:27 +00:00
|
|
|
#include "gstquark.h"
|
2012-01-26 10:22:29 +00:00
|
|
|
#include "gstvalue.h"
|
2010-11-02 17:56:29 +00:00
|
|
|
|
|
|
|
#include "gstbufferpool.h"
|
|
|
|
|
2011-03-03 17:38:32 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_buffer_pool_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_buffer_pool_debug
|
2011-02-17 15:46:51 +00:00
|
|
|
|
|
|
|
#define GST_BUFFER_POOL_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BUFFER_POOL, GstBufferPoolPrivate))
|
|
|
|
|
2012-01-19 08:27:04 +00:00
|
|
|
#define GST_BUFFER_POOL_LOCK(pool) (g_rec_mutex_lock(&pool->priv->rec_lock))
|
|
|
|
#define GST_BUFFER_POOL_UNLOCK(pool) (g_rec_mutex_unlock(&pool->priv->rec_lock))
|
2011-02-21 11:18:41 +00:00
|
|
|
|
2011-02-17 15:46:51 +00:00
|
|
|
struct _GstBufferPoolPrivate
|
|
|
|
{
|
2012-02-26 19:44:50 +00:00
|
|
|
GstAtomicQueue *queue;
|
|
|
|
GstPoll *poll;
|
|
|
|
|
2012-01-19 08:27:04 +00:00
|
|
|
GRecMutex rec_lock;
|
2012-02-26 19:44:50 +00:00
|
|
|
|
|
|
|
gboolean started;
|
|
|
|
gboolean active;
|
2014-01-30 11:42:02 +00:00
|
|
|
gint outstanding; /* number of buffers that are in use */
|
2012-02-26 19:44:50 +00:00
|
|
|
|
|
|
|
gboolean configured;
|
|
|
|
GstStructure *config;
|
|
|
|
|
2011-02-21 17:43:19 +00:00
|
|
|
guint size;
|
2011-02-17 15:46:51 +00:00
|
|
|
guint min_buffers;
|
|
|
|
guint max_buffers;
|
2012-08-10 10:23:03 +00:00
|
|
|
guint cur_buffers;
|
2012-03-15 21:09:02 +00:00
|
|
|
GstAllocator *allocator;
|
2012-03-15 12:28:28 +00:00
|
|
|
GstAllocationParams params;
|
2011-02-17 15:46:51 +00:00
|
|
|
};
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
static void gst_buffer_pool_finalize (GObject * object);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstBufferPool, gst_buffer_pool, GST_TYPE_OBJECT);
|
|
|
|
|
2011-02-21 16:33:38 +00:00
|
|
|
static gboolean default_start (GstBufferPool * pool);
|
|
|
|
static gboolean default_stop (GstBufferPool * pool);
|
2010-11-02 17:56:29 +00:00
|
|
|
static gboolean default_set_config (GstBufferPool * pool,
|
2011-02-17 15:46:51 +00:00
|
|
|
GstStructure * config);
|
2010-11-02 17:56:29 +00:00
|
|
|
static GstFlowReturn default_alloc_buffer (GstBufferPool * pool,
|
2012-03-15 13:01:44 +00:00
|
|
|
GstBuffer ** buffer, GstBufferPoolAcquireParams * params);
|
2010-11-02 17:56:29 +00:00
|
|
|
static GstFlowReturn default_acquire_buffer (GstBufferPool * pool,
|
2012-03-15 13:01:44 +00:00
|
|
|
GstBuffer ** buffer, GstBufferPoolAcquireParams * params);
|
2012-04-25 07:06:05 +00:00
|
|
|
static void default_reset_buffer (GstBufferPool * pool, GstBuffer * buffer);
|
2010-11-02 17:56:29 +00:00
|
|
|
static void default_free_buffer (GstBufferPool * pool, GstBuffer * buffer);
|
|
|
|
static void default_release_buffer (GstBufferPool * pool, GstBuffer * buffer);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_buffer_pool_class_init (GstBufferPoolClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
|
2011-03-03 15:31:49 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstBufferPoolPrivate));
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
gobject_class->finalize = gst_buffer_pool_finalize;
|
|
|
|
|
2011-02-21 16:33:38 +00:00
|
|
|
klass->start = default_start;
|
|
|
|
klass->stop = default_stop;
|
2010-11-02 17:56:29 +00:00
|
|
|
klass->set_config = default_set_config;
|
|
|
|
klass->acquire_buffer = default_acquire_buffer;
|
2011-07-21 16:50:25 +00:00
|
|
|
klass->reset_buffer = default_reset_buffer;
|
2010-11-02 17:56:29 +00:00
|
|
|
klass->alloc_buffer = default_alloc_buffer;
|
|
|
|
klass->release_buffer = default_release_buffer;
|
|
|
|
klass->free_buffer = default_free_buffer;
|
2011-03-03 17:38:32 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_buffer_pool_debug, "bufferpool", 0,
|
|
|
|
"bufferpool debug");
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_buffer_pool_init (GstBufferPool * pool)
|
|
|
|
{
|
2012-03-15 21:09:02 +00:00
|
|
|
GstBufferPoolPrivate *priv;
|
2011-02-17 15:46:51 +00:00
|
|
|
|
2012-03-15 21:09:02 +00:00
|
|
|
priv = pool->priv = GST_BUFFER_POOL_GET_PRIVATE (pool);
|
2011-02-21 11:18:41 +00:00
|
|
|
|
2012-03-15 21:09:02 +00:00
|
|
|
g_rec_mutex_init (&priv->rec_lock);
|
|
|
|
|
|
|
|
priv->poll = gst_poll_new_timer ();
|
2014-01-30 11:42:02 +00:00
|
|
|
priv->queue = gst_atomic_queue_new (16);
|
2012-02-26 19:44:50 +00:00
|
|
|
pool->flushing = 1;
|
2012-03-15 21:09:02 +00:00
|
|
|
priv->active = FALSE;
|
|
|
|
priv->configured = FALSE;
|
|
|
|
priv->started = FALSE;
|
|
|
|
priv->config = gst_structure_new_id_empty (GST_QUARK (BUFFER_POOL_CONFIG));
|
|
|
|
gst_buffer_pool_config_set_params (priv->config, NULL, 0, 0, 0);
|
|
|
|
priv->allocator = NULL;
|
|
|
|
gst_allocation_params_init (&priv->params);
|
|
|
|
gst_buffer_pool_config_set_allocator (priv->config, priv->allocator,
|
|
|
|
&priv->params);
|
2014-01-30 11:26:05 +00:00
|
|
|
/* 1 control write for flushing */
|
|
|
|
gst_poll_write_control (priv->poll);
|
|
|
|
/* 1 control write for marking that we are not waiting for poll */
|
2012-03-15 21:09:02 +00:00
|
|
|
gst_poll_write_control (priv->poll);
|
2010-11-02 17:56:29 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pool, "created");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_buffer_pool_finalize (GObject * object)
|
|
|
|
{
|
2011-02-18 15:15:30 +00:00
|
|
|
GstBufferPool *pool;
|
2012-03-15 21:09:02 +00:00
|
|
|
GstBufferPoolPrivate *priv;
|
2011-02-18 15:15:30 +00:00
|
|
|
|
|
|
|
pool = GST_BUFFER_POOL_CAST (object);
|
2012-03-15 21:09:02 +00:00
|
|
|
priv = pool->priv;
|
2011-02-18 15:15:30 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pool, "finalize");
|
|
|
|
|
|
|
|
gst_buffer_pool_set_active (pool, FALSE);
|
2012-03-15 21:09:02 +00:00
|
|
|
gst_atomic_queue_unref (priv->queue);
|
|
|
|
gst_poll_free (priv->poll);
|
|
|
|
gst_structure_free (priv->config);
|
|
|
|
g_rec_mutex_clear (&priv->rec_lock);
|
|
|
|
if (priv->allocator)
|
2012-07-09 14:02:50 +00:00
|
|
|
gst_object_unref (priv->allocator);
|
2011-02-18 15:15:30 +00:00
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
G_OBJECT_CLASS (gst_buffer_pool_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_pool_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GstBufferPool instance.
|
|
|
|
*
|
2013-10-30 22:02:02 +00:00
|
|
|
* Returns: (transfer floating): a new #GstBufferPool instance
|
2010-11-02 17:56:29 +00:00
|
|
|
*/
|
|
|
|
GstBufferPool *
|
|
|
|
gst_buffer_pool_new (void)
|
|
|
|
{
|
|
|
|
GstBufferPool *result;
|
|
|
|
|
|
|
|
result = g_object_newv (GST_TYPE_BUFFER_POOL, 0, NULL);
|
|
|
|
GST_DEBUG_OBJECT (result, "created new buffer pool");
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-02-21 17:43:19 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
default_alloc_buffer (GstBufferPool * pool, GstBuffer ** buffer,
|
2012-03-15 13:01:44 +00:00
|
|
|
GstBufferPoolAcquireParams * params)
|
2011-02-21 17:43:19 +00:00
|
|
|
{
|
|
|
|
GstBufferPoolPrivate *priv = pool->priv;
|
|
|
|
|
2012-03-15 21:09:02 +00:00
|
|
|
*buffer =
|
|
|
|
gst_buffer_new_allocate (priv->allocator, priv->size, &priv->params);
|
2011-02-21 17:43:19 +00:00
|
|
|
|
2014-07-30 12:46:22 +00:00
|
|
|
if (!*buffer)
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
|
2011-02-21 17:43:19 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-22 14:55:29 +00:00
|
|
|
static gboolean
|
|
|
|
mark_meta_pooled (GstBuffer * buffer, GstMeta ** meta, gpointer user_data)
|
|
|
|
{
|
2015-06-24 13:35:16 +00:00
|
|
|
GST_DEBUG_OBJECT (GST_BUFFER_POOL (user_data),
|
|
|
|
"marking meta %p as POOLED in buffer %p", *meta, buffer);
|
2011-12-22 14:55:29 +00:00
|
|
|
GST_META_FLAG_SET (*meta, GST_META_FLAG_POOLED);
|
2012-04-17 13:37:27 +00:00
|
|
|
GST_META_FLAG_SET (*meta, GST_META_FLAG_LOCKED);
|
2011-12-22 14:55:29 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-08-10 10:23:03 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
do_alloc_buffer (GstBufferPool * pool, GstBuffer ** buffer,
|
|
|
|
GstBufferPoolAcquireParams * params)
|
|
|
|
{
|
|
|
|
GstBufferPoolPrivate *priv = pool->priv;
|
|
|
|
GstFlowReturn result;
|
|
|
|
gint cur_buffers, max_buffers;
|
|
|
|
GstBufferPoolClass *pclass;
|
|
|
|
|
|
|
|
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (!pclass->alloc_buffer))
|
|
|
|
goto no_function;
|
|
|
|
|
|
|
|
max_buffers = priv->max_buffers;
|
|
|
|
|
|
|
|
/* increment the allocation counter */
|
|
|
|
cur_buffers = g_atomic_int_add (&priv->cur_buffers, 1);
|
|
|
|
if (max_buffers && cur_buffers >= max_buffers)
|
|
|
|
goto max_reached;
|
|
|
|
|
|
|
|
result = pclass->alloc_buffer (pool, buffer, params);
|
|
|
|
if (G_UNLIKELY (result != GST_FLOW_OK))
|
|
|
|
goto alloc_failed;
|
|
|
|
|
2014-02-27 14:14:59 +00:00
|
|
|
/* lock all metadata and mark as pooled, we want this to remain on
|
|
|
|
* the buffer and we want to remove any other metadata that gets added
|
|
|
|
* later */
|
2012-08-10 10:23:03 +00:00
|
|
|
gst_buffer_foreach_meta (*buffer, mark_meta_pooled, pool);
|
2014-03-07 20:43:44 +00:00
|
|
|
|
|
|
|
/* un-tag memory, this is how we expect the buffer when it is
|
2014-02-27 14:14:59 +00:00
|
|
|
* released again */
|
2014-03-07 20:43:44 +00:00
|
|
|
GST_BUFFER_FLAG_UNSET (*buffer, GST_BUFFER_FLAG_TAG_MEMORY);
|
2012-08-10 10:23:03 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (pool, "allocated buffer %d/%d, %p", cur_buffers,
|
2014-04-15 13:55:25 +00:00
|
|
|
max_buffers, *buffer);
|
2012-08-10 10:23:03 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_function:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (pool, "no alloc function");
|
|
|
|
return GST_FLOW_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
max_reached:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (pool, "max buffers reached");
|
|
|
|
g_atomic_int_add (&priv->cur_buffers, -1);
|
|
|
|
return GST_FLOW_EOS;
|
|
|
|
}
|
|
|
|
alloc_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "alloc function failed");
|
|
|
|
g_atomic_int_add (&priv->cur_buffers, -1);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-30 11:42:02 +00:00
|
|
|
/* the default implementation for preallocating the buffers in the pool */
|
2011-02-18 15:15:30 +00:00
|
|
|
static gboolean
|
2011-02-21 16:33:38 +00:00
|
|
|
default_start (GstBufferPool * pool)
|
2010-11-02 17:56:29 +00:00
|
|
|
{
|
2011-02-17 17:37:19 +00:00
|
|
|
guint i;
|
|
|
|
GstBufferPoolPrivate *priv = pool->priv;
|
2011-02-21 16:33:38 +00:00
|
|
|
GstBufferPoolClass *pclass;
|
2010-11-02 17:56:29 +00:00
|
|
|
|
2011-02-21 16:33:38 +00:00
|
|
|
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
|
|
|
|
|
|
|
|
/* we need to prealloc buffers */
|
|
|
|
for (i = 0; i < priv->min_buffers; i++) {
|
|
|
|
GstBuffer *buffer;
|
|
|
|
|
2012-08-10 10:23:03 +00:00
|
|
|
if (do_alloc_buffer (pool, &buffer, NULL) != GST_FLOW_OK)
|
2011-02-21 16:33:38 +00:00
|
|
|
goto alloc_failed;
|
|
|
|
|
2011-07-15 11:27:13 +00:00
|
|
|
/* release to the queue, we call the vmethod directly, we don't need to do
|
|
|
|
* the other refcount handling right now. */
|
|
|
|
if (G_LIKELY (pclass->release_buffer))
|
|
|
|
pclass->release_buffer (pool, buffer);
|
2011-02-21 16:33:38 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
alloc_failed:
|
|
|
|
{
|
2012-08-10 10:23:03 +00:00
|
|
|
GST_WARNING_OBJECT (pool, "failed to allocate buffer");
|
2011-02-21 16:33:38 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 17:43:19 +00:00
|
|
|
/* must be called with the lock */
|
|
|
|
static gboolean
|
|
|
|
do_start (GstBufferPool * pool)
|
|
|
|
{
|
2012-08-10 10:23:03 +00:00
|
|
|
GstBufferPoolPrivate *priv = pool->priv;
|
|
|
|
|
|
|
|
if (!priv->started) {
|
2011-02-21 17:43:19 +00:00
|
|
|
GstBufferPoolClass *pclass;
|
|
|
|
|
|
|
|
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
|
|
|
|
|
2011-03-03 17:21:31 +00:00
|
|
|
GST_LOG_OBJECT (pool, "starting");
|
2011-02-21 17:43:19 +00:00
|
|
|
/* start the pool, subclasses should allocate buffers and put them
|
|
|
|
* in the queue */
|
|
|
|
if (G_LIKELY (pclass->start)) {
|
|
|
|
if (!pclass->start (pool))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-08-10 10:23:03 +00:00
|
|
|
priv->started = TRUE;
|
2011-02-21 17:43:19 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-02-21 16:33:38 +00:00
|
|
|
static void
|
|
|
|
default_free_buffer (GstBufferPool * pool, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
}
|
|
|
|
|
2014-02-25 16:46:49 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-02-21 17:43:19 +00:00
|
|
|
/* must be called with the lock */
|
2011-02-21 16:33:38 +00:00
|
|
|
static gboolean
|
|
|
|
default_stop (GstBufferPool * pool)
|
|
|
|
{
|
2012-08-10 10:23:03 +00:00
|
|
|
GstBufferPoolPrivate *priv = pool->priv;
|
2011-02-21 16:33:38 +00:00
|
|
|
GstBuffer *buffer;
|
|
|
|
|
|
|
|
/* clear the pool */
|
2012-08-10 10:23:03 +00:00
|
|
|
while ((buffer = gst_atomic_queue_pop (priv->queue))) {
|
|
|
|
gst_poll_read_control (priv->poll);
|
2014-02-25 16:46:49 +00:00
|
|
|
do_free_buffer (pool, buffer);
|
2011-02-21 16:33:38 +00:00
|
|
|
}
|
2014-02-25 16:46:49 +00:00
|
|
|
return priv->cur_buffers == 0;
|
2011-02-21 16:33:38 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 17:43:19 +00:00
|
|
|
/* must be called with the lock */
|
2011-02-21 16:33:38 +00:00
|
|
|
static gboolean
|
|
|
|
do_stop (GstBufferPool * pool)
|
|
|
|
{
|
2012-08-10 10:23:03 +00:00
|
|
|
GstBufferPoolPrivate *priv = pool->priv;
|
|
|
|
|
|
|
|
if (priv->started) {
|
2011-02-21 16:33:38 +00:00
|
|
|
GstBufferPoolClass *pclass;
|
2011-02-18 15:15:30 +00:00
|
|
|
|
2011-02-21 16:33:38 +00:00
|
|
|
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
|
2011-02-18 15:15:30 +00:00
|
|
|
|
2011-03-03 17:21:31 +00:00
|
|
|
GST_LOG_OBJECT (pool, "stopping");
|
2011-02-21 16:33:38 +00:00
|
|
|
if (G_LIKELY (pclass->stop)) {
|
|
|
|
if (!pclass->stop (pool))
|
|
|
|
return FALSE;
|
2011-02-18 15:15:30 +00:00
|
|
|
}
|
2012-08-10 10:23:03 +00:00
|
|
|
priv->started = FALSE;
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
2011-02-18 15:15:30 +00:00
|
|
|
return TRUE;
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 19:26:59 +00:00
|
|
|
/* must be called with the lock */
|
|
|
|
static void
|
|
|
|
do_set_flushing (GstBufferPool * pool, gboolean flushing)
|
|
|
|
{
|
|
|
|
GstBufferPoolPrivate *priv = pool->priv;
|
|
|
|
GstBufferPoolClass *pclass;
|
|
|
|
|
|
|
|
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
|
|
|
|
|
|
|
|
if (GST_BUFFER_POOL_IS_FLUSHING (pool) == flushing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (flushing) {
|
|
|
|
g_atomic_int_set (&pool->flushing, 1);
|
|
|
|
gst_poll_write_control (priv->poll);
|
|
|
|
|
|
|
|
if (pclass->flush_start)
|
|
|
|
pclass->flush_start (pool);
|
|
|
|
} else {
|
|
|
|
if (pclass->flush_stop)
|
|
|
|
pclass->flush_stop (pool);
|
|
|
|
|
|
|
|
gst_poll_read_control (priv->poll);
|
|
|
|
g_atomic_int_set (&pool->flushing, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
/**
|
2011-02-18 11:50:21 +00:00
|
|
|
* gst_buffer_pool_set_active:
|
2010-11-02 17:56:29 +00:00
|
|
|
* @pool: a #GstBufferPool
|
2011-02-18 11:50:21 +00:00
|
|
|
* @active: the new active state
|
2010-11-02 17:56:29 +00:00
|
|
|
*
|
2013-04-04 14:39:23 +00:00
|
|
|
* Control the active state of @pool. When the pool is inactive, new calls to
|
2014-01-31 07:08:37 +00:00
|
|
|
* gst_buffer_pool_acquire_buffer() will return with %GST_FLOW_FLUSHING.
|
2011-02-18 15:15:30 +00:00
|
|
|
*
|
2011-08-04 08:54:29 +00:00
|
|
|
* Activating the bufferpool will preallocate all resources in the pool based on
|
|
|
|
* the configuration of the pool.
|
|
|
|
*
|
|
|
|
* Deactivating will free the resources again when there are no outstanding
|
|
|
|
* buffers. When there are outstanding buffers, they will be freed as soon as
|
|
|
|
* they are all returned to the pool.
|
|
|
|
*
|
2011-02-18 15:15:30 +00:00
|
|
|
* Returns: %FALSE when the pool was not configured or when preallocation of the
|
|
|
|
* buffers failed.
|
2010-11-02 17:56:29 +00:00
|
|
|
*/
|
2011-02-18 15:15:30 +00:00
|
|
|
gboolean
|
2011-02-18 11:50:21 +00:00
|
|
|
gst_buffer_pool_set_active (GstBufferPool * pool, gboolean active)
|
2010-11-02 17:56:29 +00:00
|
|
|
{
|
2011-02-21 16:33:38 +00:00
|
|
|
gboolean res = TRUE;
|
2012-08-10 10:23:03 +00:00
|
|
|
GstBufferPoolPrivate *priv;
|
2010-11-02 17:56:29 +00:00
|
|
|
|
2011-02-18 15:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);
|
2010-11-02 17:56:29 +00:00
|
|
|
|
2011-03-03 17:21:31 +00:00
|
|
|
GST_LOG_OBJECT (pool, "active %d", active);
|
|
|
|
|
2012-08-10 10:23:03 +00:00
|
|
|
priv = pool->priv;
|
|
|
|
|
2011-02-21 11:18:41 +00:00
|
|
|
GST_BUFFER_POOL_LOCK (pool);
|
2011-02-18 15:15:30 +00:00
|
|
|
/* just return if we are already in the right state */
|
2012-08-10 10:23:03 +00:00
|
|
|
if (priv->active == active)
|
2011-02-21 11:18:41 +00:00
|
|
|
goto was_ok;
|
2011-02-18 15:15:30 +00:00
|
|
|
|
|
|
|
/* we need to be configured */
|
2012-08-10 10:23:03 +00:00
|
|
|
if (!priv->configured)
|
2011-02-21 11:18:41 +00:00
|
|
|
goto not_configured;
|
2011-02-17 17:37:19 +00:00
|
|
|
|
2011-02-21 16:33:38 +00:00
|
|
|
if (active) {
|
|
|
|
if (!do_start (pool))
|
|
|
|
goto start_failed;
|
|
|
|
|
2014-05-23 19:26:59 +00:00
|
|
|
/* flush_stop my release buffers, setting to active to avoid running
|
|
|
|
* do_stop while activating the pool */
|
|
|
|
priv->active = TRUE;
|
|
|
|
|
2011-02-21 16:33:38 +00:00
|
|
|
/* unset the flushing state now */
|
2014-05-23 19:26:59 +00:00
|
|
|
do_set_flushing (pool, FALSE);
|
2011-02-21 16:33:38 +00:00
|
|
|
} else {
|
2011-07-15 11:27:13 +00:00
|
|
|
gint outstanding;
|
|
|
|
|
2011-02-21 16:33:38 +00:00
|
|
|
/* set to flushing first */
|
2014-05-23 19:26:59 +00:00
|
|
|
do_set_flushing (pool, TRUE);
|
2011-02-17 17:37:19 +00:00
|
|
|
|
2011-02-21 16:33:38 +00:00
|
|
|
/* when all buffers are in the pool, free them. Else they will be
|
|
|
|
* freed when they are released */
|
2012-08-10 10:23:03 +00:00
|
|
|
outstanding = g_atomic_int_get (&priv->outstanding);
|
2011-07-15 11:27:13 +00:00
|
|
|
GST_LOG_OBJECT (pool, "outstanding buffers %d", outstanding);
|
|
|
|
if (outstanding == 0) {
|
2011-02-21 16:33:38 +00:00
|
|
|
if (!do_stop (pool))
|
|
|
|
goto stop_failed;
|
2011-02-21 11:18:41 +00:00
|
|
|
}
|
2014-05-23 19:26:59 +00:00
|
|
|
|
|
|
|
priv->active = FALSE;
|
2011-02-21 11:18:41 +00:00
|
|
|
}
|
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
2011-02-18 15:15:30 +00:00
|
|
|
|
|
|
|
return res;
|
2011-02-21 11:18:41 +00:00
|
|
|
|
|
|
|
was_ok:
|
|
|
|
{
|
2011-02-21 16:33:38 +00:00
|
|
|
GST_DEBUG_OBJECT (pool, "pool was in the right state");
|
2011-02-21 11:18:41 +00:00
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
not_configured:
|
|
|
|
{
|
2011-02-21 16:33:38 +00:00
|
|
|
GST_ERROR_OBJECT (pool, "pool was not configured");
|
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
start_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (pool, "start failed");
|
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
stop_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "stop failed");
|
2011-02-21 11:18:41 +00:00
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
|
|
|
|
2011-08-04 08:54:29 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_pool_is_active:
|
|
|
|
* @pool: a #GstBufferPool
|
|
|
|
*
|
|
|
|
* Check if @pool is active. A pool can be activated with the
|
|
|
|
* gst_buffer_pool_set_active() call.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE when the pool is active.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_buffer_pool_is_active (GstBufferPool * pool)
|
|
|
|
{
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
GST_BUFFER_POOL_LOCK (pool);
|
2012-02-26 19:44:50 +00:00
|
|
|
res = pool->priv->active;
|
2011-08-04 08:54:29 +00:00
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
static gboolean
|
2011-02-17 15:46:51 +00:00
|
|
|
default_set_config (GstBufferPool * pool, GstStructure * config)
|
2010-11-02 17:56:29 +00:00
|
|
|
{
|
2011-02-17 15:46:51 +00:00
|
|
|
GstBufferPoolPrivate *priv = pool->priv;
|
2012-03-27 10:40:36 +00:00
|
|
|
GstCaps *caps;
|
2011-02-21 17:43:19 +00:00
|
|
|
guint size, min_buffers, max_buffers;
|
2012-03-15 21:09:02 +00:00
|
|
|
GstAllocator *allocator;
|
|
|
|
GstAllocationParams params;
|
2010-11-02 17:56:29 +00:00
|
|
|
|
2011-02-17 15:46:51 +00:00
|
|
|
/* parse the config and keep around */
|
2012-03-15 21:09:02 +00:00
|
|
|
if (!gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
|
|
|
|
&max_buffers))
|
|
|
|
goto wrong_config;
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
|
2011-02-21 17:43:19 +00:00
|
|
|
goto wrong_config;
|
|
|
|
|
2011-06-02 16:13:10 +00:00
|
|
|
GST_DEBUG_OBJECT (pool, "config %" GST_PTR_FORMAT, config);
|
|
|
|
|
2011-02-21 17:43:19 +00:00
|
|
|
priv->size = size;
|
|
|
|
priv->min_buffers = min_buffers;
|
|
|
|
priv->max_buffers = max_buffers;
|
2012-08-10 10:23:03 +00:00
|
|
|
priv->cur_buffers = 0;
|
2012-03-15 21:09:02 +00:00
|
|
|
|
|
|
|
if (priv->allocator)
|
2012-07-09 14:02:50 +00:00
|
|
|
gst_object_unref (priv->allocator);
|
2012-03-15 21:09:02 +00:00
|
|
|
if ((priv->allocator = allocator))
|
2012-07-09 14:02:50 +00:00
|
|
|
gst_object_ref (allocator);
|
2012-03-15 21:09:02 +00:00
|
|
|
priv->params = params;
|
2011-02-17 15:46:51 +00:00
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
return TRUE;
|
2011-02-21 17:43:19 +00:00
|
|
|
|
|
|
|
wrong_config:
|
|
|
|
{
|
2011-06-02 16:13:10 +00:00
|
|
|
GST_WARNING_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config);
|
2011-02-21 17:43:19 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_pool_set_config:
|
|
|
|
* @pool: a #GstBufferPool
|
2011-11-10 12:53:33 +00:00
|
|
|
* @config: (transfer full): a #GstStructure
|
2010-11-02 17:56:29 +00:00
|
|
|
*
|
2014-05-06 19:35:14 +00:00
|
|
|
* Set the configuration of the pool. If the pool is already configured, and
|
|
|
|
* the configuration haven't change, this function will return %TRUE. If the
|
2015-03-01 18:15:40 +00:00
|
|
|
* pool is active, this method will return %FALSE and active configuration
|
|
|
|
* will remain. Buffers allocated form this pool must be returned or else this
|
|
|
|
* function will do nothing and return %FALSE.
|
2010-11-02 17:56:29 +00:00
|
|
|
*
|
2011-07-15 09:52:22 +00:00
|
|
|
* @config is a #GstStructure that contains the configuration parameters for
|
2011-02-17 15:46:51 +00:00
|
|
|
* the pool. A default and mandatory set of parameters can be configured with
|
2012-08-11 21:19:32 +00:00
|
|
|
* gst_buffer_pool_config_set_params(), gst_buffer_pool_config_set_allocator()
|
|
|
|
* and gst_buffer_pool_config_add_option().
|
2011-02-17 15:46:51 +00:00
|
|
|
*
|
2012-06-18 10:15:57 +00:00
|
|
|
* If the parameters in @config can not be set exactly, this function returns
|
2014-01-30 11:42:02 +00:00
|
|
|
* %FALSE and will try to update as much state as possible. The new state can
|
2012-08-11 21:19:32 +00:00
|
|
|
* then be retrieved and refined with gst_buffer_pool_get_config().
|
|
|
|
*
|
|
|
|
* This function takes ownership of @config.
|
2012-06-18 10:15:57 +00:00
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* Returns: %TRUE when the configuration could be set.
|
2010-11-02 17:56:29 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2011-02-17 15:46:51 +00:00
|
|
|
gst_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
2010-11-02 17:56:29 +00:00
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
GstBufferPoolClass *pclass;
|
2012-08-10 10:23:03 +00:00
|
|
|
GstBufferPoolPrivate *priv;
|
2010-11-02 17:56:29 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);
|
|
|
|
g_return_val_if_fail (config != NULL, FALSE);
|
|
|
|
|
2012-08-10 10:23:03 +00:00
|
|
|
priv = pool->priv;
|
|
|
|
|
2011-02-21 11:18:41 +00:00
|
|
|
GST_BUFFER_POOL_LOCK (pool);
|
2014-05-06 19:35:14 +00:00
|
|
|
|
|
|
|
/* nothing to do if config is unchanged */
|
|
|
|
if (priv->configured && gst_structure_is_equal (config, priv->config))
|
|
|
|
goto config_unchanged;
|
|
|
|
|
2011-02-18 15:15:30 +00:00
|
|
|
/* can't change the settings when active */
|
2015-03-01 18:15:40 +00:00
|
|
|
if (priv->active)
|
|
|
|
goto was_active;
|
2010-11-02 17:56:29 +00:00
|
|
|
|
2011-02-18 15:15:30 +00:00
|
|
|
/* we can't change when outstanding buffers */
|
2012-08-10 10:23:03 +00:00
|
|
|
if (g_atomic_int_get (&priv->outstanding) != 0)
|
2011-02-21 11:18:41 +00:00
|
|
|
goto have_outstanding;
|
2011-02-18 15:15:30 +00:00
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
|
|
|
|
|
2011-02-21 16:33:38 +00:00
|
|
|
/* set the new config */
|
2010-11-02 17:56:29 +00:00
|
|
|
if (G_LIKELY (pclass->set_config))
|
|
|
|
result = pclass->set_config (pool, config);
|
|
|
|
else
|
|
|
|
result = FALSE;
|
|
|
|
|
2014-04-08 23:27:55 +00:00
|
|
|
/* save the config regardless of the result so user can read back the
|
|
|
|
* modified config and evaluate if the changes are acceptable */
|
|
|
|
if (priv->config)
|
|
|
|
gst_structure_free (priv->config);
|
|
|
|
priv->config = config;
|
2011-02-18 15:15:30 +00:00
|
|
|
|
2014-04-08 23:27:55 +00:00
|
|
|
if (result) {
|
2011-02-18 15:15:30 +00:00
|
|
|
/* now we are configured */
|
2012-08-10 10:23:03 +00:00
|
|
|
priv->configured = TRUE;
|
2011-02-17 15:46:51 +00:00
|
|
|
}
|
2011-02-21 11:18:41 +00:00
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
2010-11-02 17:56:29 +00:00
|
|
|
|
|
|
|
return result;
|
2011-02-21 11:18:41 +00:00
|
|
|
|
2014-05-06 19:35:14 +00:00
|
|
|
config_unchanged:
|
|
|
|
{
|
|
|
|
gst_structure_free (config);
|
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-02-21 11:18:41 +00:00
|
|
|
/* ERRORS */
|
|
|
|
was_active:
|
|
|
|
{
|
2012-03-14 16:16:36 +00:00
|
|
|
gst_structure_free (config);
|
2015-03-01 18:15:40 +00:00
|
|
|
GST_INFO_OBJECT (pool, "can't change config, we are active");
|
2011-02-21 11:18:41 +00:00
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
have_outstanding:
|
|
|
|
{
|
2012-03-14 16:16:36 +00:00
|
|
|
gst_structure_free (config);
|
2011-02-21 16:33:38 +00:00
|
|
|
GST_WARNING_OBJECT (pool, "can't change config, have outstanding buffers");
|
2011-02-21 11:18:41 +00:00
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_pool_get_config:
|
|
|
|
* @pool: a #GstBufferPool
|
|
|
|
*
|
2011-02-21 11:18:41 +00:00
|
|
|
* Get a copy of the current configuration of the pool. This configuration
|
|
|
|
* can either be modified and used for the gst_buffer_pool_set_config() call
|
|
|
|
* or it must be freed after usage.
|
|
|
|
*
|
2011-11-10 12:53:33 +00:00
|
|
|
* Returns: (transfer full): a copy of the current configuration of @pool. use
|
2011-02-21 11:18:41 +00:00
|
|
|
* gst_structure_free() after usage or gst_buffer_pool_set_config().
|
2011-02-17 15:46:51 +00:00
|
|
|
*/
|
2011-02-21 11:18:41 +00:00
|
|
|
GstStructure *
|
2011-02-17 15:46:51 +00:00
|
|
|
gst_buffer_pool_get_config (GstBufferPool * pool)
|
|
|
|
{
|
2011-02-21 11:18:41 +00:00
|
|
|
GstStructure *result;
|
|
|
|
|
2011-02-17 15:46:51 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), NULL);
|
|
|
|
|
2012-11-08 04:33:01 +00:00
|
|
|
GST_BUFFER_POOL_LOCK (pool);
|
2012-02-26 19:44:50 +00:00
|
|
|
result = gst_structure_copy (pool->priv->config);
|
2011-02-21 11:18:41 +00:00
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
|
|
|
|
|
|
|
return result;
|
2011-02-17 15:46:51 +00:00
|
|
|
}
|
|
|
|
|
2011-07-29 15:10:09 +00:00
|
|
|
static const gchar *empty_option[] = { NULL };
|
2011-06-21 10:32:46 +00:00
|
|
|
|
2011-06-20 11:26:06 +00:00
|
|
|
/**
|
2011-07-29 15:10:09 +00:00
|
|
|
* gst_buffer_pool_get_options:
|
2011-06-20 11:26:06 +00:00
|
|
|
* @pool: a #GstBufferPool
|
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* Get a %NULL terminated array of string with supported bufferpool options for
|
2011-07-29 15:10:09 +00:00
|
|
|
* @pool. An option would typically be enabled with
|
|
|
|
* gst_buffer_pool_config_add_option().
|
2011-06-20 11:26:06 +00:00
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* Returns: (array zero-terminated=1) (transfer none): a %NULL terminated array
|
|
|
|
* of strings.
|
2011-06-20 11:26:06 +00:00
|
|
|
*/
|
|
|
|
const gchar **
|
2011-07-29 15:10:09 +00:00
|
|
|
gst_buffer_pool_get_options (GstBufferPool * pool)
|
2011-06-20 11:26:06 +00:00
|
|
|
{
|
|
|
|
GstBufferPoolClass *pclass;
|
|
|
|
const gchar **result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), NULL);
|
|
|
|
|
|
|
|
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
|
|
|
|
|
2011-07-30 12:04:43 +00:00
|
|
|
if (G_LIKELY (pclass->get_options)) {
|
|
|
|
if ((result = pclass->get_options (pool)) == NULL)
|
|
|
|
goto invalid_result;
|
|
|
|
} else
|
2011-07-29 15:10:09 +00:00
|
|
|
result = empty_option;
|
2011-06-20 11:26:06 +00:00
|
|
|
|
|
|
|
return result;
|
2011-07-30 12:04:43 +00:00
|
|
|
|
|
|
|
/* ERROR */
|
|
|
|
invalid_result:
|
|
|
|
{
|
|
|
|
g_warning ("bufferpool subclass returned NULL options");
|
|
|
|
return empty_option;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_pool_has_option:
|
|
|
|
* @pool: a #GstBufferPool
|
|
|
|
* @option: an option
|
|
|
|
*
|
|
|
|
* Check if the bufferpool supports @option.
|
|
|
|
*
|
2014-05-29 22:04:45 +00:00
|
|
|
* Returns: %TRUE if the buffer pool contains @option.
|
2011-07-30 12:04:43 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_buffer_pool_has_option (GstBufferPool * pool, const gchar * option)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
const gchar **options;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), FALSE);
|
|
|
|
g_return_val_if_fail (option != NULL, FALSE);
|
|
|
|
|
|
|
|
options = gst_buffer_pool_get_options (pool);
|
|
|
|
|
|
|
|
for (i = 0; options[i]; i++) {
|
|
|
|
if (g_str_equal (options[i], option))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2011-06-20 11:26:06 +00:00
|
|
|
}
|
|
|
|
|
2011-02-17 15:46:51 +00:00
|
|
|
/**
|
2012-03-15 21:09:02 +00:00
|
|
|
* gst_buffer_pool_config_set_params:
|
2011-06-20 11:26:06 +00:00
|
|
|
* @config: a #GstBufferPool configuration
|
2011-04-27 15:56:12 +00:00
|
|
|
* @caps: caps for the buffers
|
2012-03-14 18:37:22 +00:00
|
|
|
* @size: the size of each buffer, not including prefix and padding
|
2011-02-17 15:46:51 +00:00
|
|
|
* @min_buffers: the minimum amount of buffers to allocate.
|
|
|
|
* @max_buffers: the maximum amount of buffers to allocate or 0 for unlimited.
|
|
|
|
*
|
|
|
|
* Configure @config with the given parameters.
|
2010-11-02 17:56:29 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-03-27 10:40:36 +00:00
|
|
|
gst_buffer_pool_config_set_params (GstStructure * config, GstCaps * caps,
|
2012-03-15 21:09:02 +00:00
|
|
|
guint size, guint min_buffers, guint max_buffers)
|
2011-02-17 15:46:51 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (config != NULL);
|
2012-03-26 15:38:50 +00:00
|
|
|
g_return_if_fail (max_buffers == 0 || min_buffers <= max_buffers);
|
2012-06-18 08:13:38 +00:00
|
|
|
g_return_if_fail (caps == NULL || gst_caps_is_fixed (caps));
|
2011-02-17 15:46:51 +00:00
|
|
|
|
2011-02-17 16:29:27 +00:00
|
|
|
gst_structure_id_set (config,
|
2011-03-03 15:31:49 +00:00
|
|
|
GST_QUARK (CAPS), GST_TYPE_CAPS, caps,
|
2011-02-17 16:29:27 +00:00
|
|
|
GST_QUARK (SIZE), G_TYPE_UINT, size,
|
|
|
|
GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
|
2012-03-15 21:09:02 +00:00
|
|
|
GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_pool_config_set_allocator:
|
|
|
|
* @config: a #GstBufferPool configuration
|
2014-06-11 23:19:01 +00:00
|
|
|
* @allocator: (allow-none): a #GstAllocator
|
|
|
|
* @params: (allow-none): #GstAllocationParams
|
2012-03-15 21:09:02 +00:00
|
|
|
*
|
|
|
|
* Set the @allocator and @params on @config.
|
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* One of @allocator and @params can be %NULL, but not both. When @allocator
|
|
|
|
* is %NULL, the default allocator of the pool will use the values in @param
|
|
|
|
* to perform its allocation. When @param is %NULL, the pool will use the
|
|
|
|
* provided @allocator with its default #GstAllocationParams.
|
2012-03-15 21:09:02 +00:00
|
|
|
*
|
|
|
|
* A call to gst_buffer_pool_set_config() can update the allocator and params
|
|
|
|
* with the values that it is able to do. Some pools are, for example, not able
|
|
|
|
* to operate with different allocators or cannot allocate with the values
|
|
|
|
* specified in @params. Use gst_buffer_pool_get_config() to get the currently
|
|
|
|
* used values.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_buffer_pool_config_set_allocator (GstStructure * config,
|
|
|
|
GstAllocator * allocator, const GstAllocationParams * params)
|
|
|
|
{
|
|
|
|
g_return_if_fail (config != NULL);
|
|
|
|
g_return_if_fail (allocator != NULL || params != NULL);
|
|
|
|
|
|
|
|
gst_structure_id_set (config,
|
|
|
|
GST_QUARK (ALLOCATOR), GST_TYPE_ALLOCATOR, allocator,
|
|
|
|
GST_QUARK (PARAMS), GST_TYPE_ALLOCATION_PARAMS, params, NULL);
|
2011-02-17 15:46:51 +00:00
|
|
|
}
|
|
|
|
|
2011-06-20 11:26:06 +00:00
|
|
|
/**
|
2011-07-29 15:10:09 +00:00
|
|
|
* gst_buffer_pool_config_add_option:
|
2011-06-20 11:26:06 +00:00
|
|
|
* @config: a #GstBufferPool configuration
|
2011-07-29 15:10:09 +00:00
|
|
|
* @option: an option to add
|
2011-06-20 11:26:06 +00:00
|
|
|
*
|
2011-07-29 15:10:09 +00:00
|
|
|
* Enabled the option in @config. This will instruct the @bufferpool to enable
|
|
|
|
* the specified option on the buffers that it allocates.
|
2011-06-20 11:26:06 +00:00
|
|
|
*
|
2011-07-29 15:10:09 +00:00
|
|
|
* The supported options by @pool can be retrieved with gst_buffer_pool_get_options().
|
2011-06-20 11:26:06 +00:00
|
|
|
*/
|
|
|
|
void
|
2011-07-29 15:10:09 +00:00
|
|
|
gst_buffer_pool_config_add_option (GstStructure * config, const gchar * option)
|
2011-06-20 11:26:06 +00:00
|
|
|
{
|
|
|
|
const GValue *value;
|
2012-01-26 10:22:29 +00:00
|
|
|
GValue option_value = { 0, };
|
|
|
|
guint i, len;
|
2011-06-20 11:26:06 +00:00
|
|
|
|
|
|
|
g_return_if_fail (config != NULL);
|
|
|
|
|
2011-07-29 15:10:09 +00:00
|
|
|
value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
|
2011-06-20 11:26:06 +00:00
|
|
|
if (value) {
|
2012-01-26 10:22:29 +00:00
|
|
|
len = gst_value_array_get_size (value);
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
const GValue *nth_val = gst_value_array_get_value (value, i);
|
|
|
|
|
|
|
|
if (g_str_equal (option, g_value_get_string (nth_val)))
|
|
|
|
return;
|
|
|
|
}
|
2011-06-20 11:26:06 +00:00
|
|
|
} else {
|
|
|
|
GValue new_array_val = { 0, };
|
|
|
|
|
2012-01-26 10:22:29 +00:00
|
|
|
g_value_init (&new_array_val, GST_TYPE_ARRAY);
|
2011-07-29 15:10:09 +00:00
|
|
|
gst_structure_id_take_value (config, GST_QUARK (OPTIONS), &new_array_val);
|
2012-01-26 10:22:29 +00:00
|
|
|
value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
|
2011-08-01 16:12:12 +00:00
|
|
|
}
|
2011-07-29 15:10:09 +00:00
|
|
|
g_value_init (&option_value, G_TYPE_STRING);
|
|
|
|
g_value_set_string (&option_value, option);
|
2013-06-05 09:02:50 +00:00
|
|
|
gst_value_array_append_and_take_value ((GValue *) value, &option_value);
|
2011-06-20 11:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-07-29 15:10:09 +00:00
|
|
|
* gst_buffer_pool_config_n_options:
|
2011-06-20 11:26:06 +00:00
|
|
|
* @config: a #GstBufferPool configuration
|
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* Retrieve the number of values currently stored in the options array of the
|
|
|
|
* @config structure.
|
2011-06-20 11:26:06 +00:00
|
|
|
*
|
2011-07-29 15:10:09 +00:00
|
|
|
* Returns: the options array size as a #guint.
|
2011-06-20 11:26:06 +00:00
|
|
|
*/
|
|
|
|
guint
|
2011-07-29 15:10:09 +00:00
|
|
|
gst_buffer_pool_config_n_options (GstStructure * config)
|
2011-06-20 11:26:06 +00:00
|
|
|
{
|
|
|
|
const GValue *value;
|
|
|
|
guint size = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail (config != NULL, 0);
|
|
|
|
|
2011-07-29 15:10:09 +00:00
|
|
|
value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
|
2011-06-20 11:26:06 +00:00
|
|
|
if (value) {
|
2012-01-26 10:22:29 +00:00
|
|
|
size = gst_value_array_get_size (value);
|
2011-06-20 11:26:06 +00:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-07-29 15:10:09 +00:00
|
|
|
* gst_buffer_pool_config_get_option:
|
2011-06-20 11:26:06 +00:00
|
|
|
* @config: a #GstBufferPool configuration
|
2011-07-29 15:10:09 +00:00
|
|
|
* @index: position in the option array to read
|
2011-06-20 11:26:06 +00:00
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* Parse an available @config and get the option at @index of the options API
|
|
|
|
* array.
|
2011-06-20 11:26:06 +00:00
|
|
|
*
|
2011-07-29 15:10:09 +00:00
|
|
|
* Returns: a #gchar of the option at @index.
|
2011-06-20 11:26:06 +00:00
|
|
|
*/
|
|
|
|
const gchar *
|
2011-07-29 15:10:09 +00:00
|
|
|
gst_buffer_pool_config_get_option (GstStructure * config, guint index)
|
2011-06-20 11:26:06 +00:00
|
|
|
{
|
|
|
|
const GValue *value;
|
|
|
|
const gchar *ret = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (config != NULL, 0);
|
|
|
|
|
2011-07-29 15:10:09 +00:00
|
|
|
value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
|
2011-06-20 11:26:06 +00:00
|
|
|
if (value) {
|
2012-01-26 10:22:29 +00:00
|
|
|
const GValue *option_value;
|
2011-06-20 11:26:06 +00:00
|
|
|
|
2012-01-26 10:22:29 +00:00
|
|
|
option_value = gst_value_array_get_value (value, index);
|
2011-07-29 15:10:09 +00:00
|
|
|
if (option_value)
|
|
|
|
ret = g_value_get_string (option_value);
|
2011-06-20 11:26:06 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-07-29 15:10:09 +00:00
|
|
|
* gst_buffer_pool_config_has_option:
|
2011-06-20 11:26:06 +00:00
|
|
|
* @config: a #GstBufferPool configuration
|
2011-07-29 15:10:09 +00:00
|
|
|
* @option: an option
|
2011-06-20 11:26:06 +00:00
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* Check if @config contains @option.
|
2011-06-20 11:26:06 +00:00
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* Returns: %TRUE if the options array contains @option.
|
2011-06-20 11:26:06 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2011-07-29 15:10:09 +00:00
|
|
|
gst_buffer_pool_config_has_option (GstStructure * config, const gchar * option)
|
2011-06-20 11:26:06 +00:00
|
|
|
{
|
|
|
|
const GValue *value;
|
2012-01-26 10:22:29 +00:00
|
|
|
guint i, len;
|
2011-06-20 11:26:06 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (config != NULL, 0);
|
|
|
|
|
2011-07-29 15:10:09 +00:00
|
|
|
value = gst_structure_id_get_value (config, GST_QUARK (OPTIONS));
|
2011-06-20 11:26:06 +00:00
|
|
|
if (value) {
|
2012-01-26 10:22:29 +00:00
|
|
|
len = gst_value_array_get_size (value);
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
const GValue *nth_val = gst_value_array_get_value (value, i);
|
|
|
|
|
|
|
|
if (g_str_equal (option, g_value_get_string (nth_val)))
|
2011-06-20 11:26:06 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-17 15:46:51 +00:00
|
|
|
/**
|
2012-03-15 21:09:02 +00:00
|
|
|
* gst_buffer_pool_config_get_params:
|
2011-11-10 12:53:33 +00:00
|
|
|
* @config: (transfer none): a #GstBufferPool configuration
|
2012-03-27 10:40:36 +00:00
|
|
|
* @caps: (out) (transfer none) (allow-none): the caps of buffers
|
|
|
|
* @size: (out) (allow-none): the size of each buffer, not including prefix and padding
|
|
|
|
* @min_buffers: (out) (allow-none): the minimum amount of buffers to allocate.
|
|
|
|
* @max_buffers: (out) (allow-none): the maximum amount of buffers to allocate or 0 for unlimited.
|
2011-02-17 15:46:51 +00:00
|
|
|
*
|
|
|
|
* Get the configuration values from @config.
|
2012-03-27 10:40:36 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if all parameters could be fetched.
|
2011-02-17 15:46:51 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2012-03-27 10:40:36 +00:00
|
|
|
gst_buffer_pool_config_get_params (GstStructure * config, GstCaps ** caps,
|
2012-03-15 21:09:02 +00:00
|
|
|
guint * size, guint * min_buffers, guint * max_buffers)
|
2010-11-02 17:56:29 +00:00
|
|
|
{
|
2011-02-17 15:46:51 +00:00
|
|
|
g_return_val_if_fail (config != NULL, FALSE);
|
|
|
|
|
2012-03-27 10:40:36 +00:00
|
|
|
if (caps) {
|
|
|
|
*caps = g_value_get_boxed (gst_structure_id_get_value (config,
|
|
|
|
GST_QUARK (CAPS)));
|
|
|
|
}
|
2011-02-17 16:29:27 +00:00
|
|
|
return gst_structure_id_get (config,
|
|
|
|
GST_QUARK (SIZE), G_TYPE_UINT, size,
|
|
|
|
GST_QUARK (MIN_BUFFERS), G_TYPE_UINT, min_buffers,
|
2012-03-15 21:09:02 +00:00
|
|
|
GST_QUARK (MAX_BUFFERS), G_TYPE_UINT, max_buffers, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_pool_config_get_allocator:
|
|
|
|
* @config: (transfer none): a #GstBufferPool configuration
|
2015-09-15 17:05:11 +00:00
|
|
|
* @allocator: (out) (allow-none) (transfer none): a #GstAllocator, or %NULL
|
|
|
|
* @params: (out) (allow-none): #GstAllocationParams, or %NULL
|
2012-03-15 21:09:02 +00:00
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* Get the @allocator and @params from @config.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE, if the values are set.
|
2012-03-15 21:09:02 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_buffer_pool_config_get_allocator (GstStructure * config,
|
|
|
|
GstAllocator ** allocator, GstAllocationParams * params)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (config != NULL, FALSE);
|
|
|
|
|
|
|
|
if (allocator)
|
2012-07-09 14:02:50 +00:00
|
|
|
*allocator = g_value_get_object (gst_structure_id_get_value (config,
|
2012-03-15 21:09:02 +00:00
|
|
|
GST_QUARK (ALLOCATOR)));
|
|
|
|
if (params) {
|
|
|
|
GstAllocationParams *p;
|
|
|
|
|
|
|
|
p = g_value_get_boxed (gst_structure_id_get_value (config,
|
|
|
|
GST_QUARK (PARAMS)));
|
|
|
|
if (p) {
|
|
|
|
*params = *p;
|
|
|
|
} else {
|
|
|
|
gst_allocation_params_init (params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 16:47:43 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_pool_config_validate_params:
|
|
|
|
* @config: (transfer none): a #GstBufferPool configuration
|
|
|
|
* @caps: (transfer none): the excepted caps of buffers
|
|
|
|
* @size: the expected size of each buffer, not including prefix and padding
|
|
|
|
* @min_buffers: the expected minimum amount of buffers to allocate.
|
|
|
|
* @max_buffers: the expect maximum amount of buffers to allocate or 0 for unlimited.
|
|
|
|
*
|
|
|
|
* Validate that changes made to @config are still valid in the context of the
|
|
|
|
* expected parameters. This function is a helper that can be used to validate
|
|
|
|
* changes made by a pool to a config when gst_buffer_pool_set_config()
|
2014-12-16 15:13:03 +00:00
|
|
|
* returns %FALSE. This expects that @caps haven't changed and that
|
|
|
|
* @min_buffers aren't lower then what we initially expected.
|
|
|
|
* This does not check if options or allocator parameters are still valid,
|
|
|
|
* won't check if size have changed, since changing the size is valid to adapt
|
|
|
|
* padding.
|
2014-05-08 16:47:43 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*
|
|
|
|
* Returns: %TRUE, if the parameters are valid in this context.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_buffer_pool_config_validate_params (GstStructure * config, GstCaps * caps,
|
|
|
|
guint size, guint min_buffers, G_GNUC_UNUSED guint max_buffers)
|
|
|
|
{
|
|
|
|
GstCaps *newcaps;
|
|
|
|
guint newsize, newmin;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (config != NULL, FALSE);
|
|
|
|
|
|
|
|
gst_buffer_pool_config_get_params (config, &newcaps, &newsize, &newmin, NULL);
|
|
|
|
|
2014-12-16 15:13:03 +00:00
|
|
|
if (gst_caps_is_equal (caps, newcaps) && (newsize >= size)
|
2014-05-08 16:47:43 +00:00
|
|
|
&& (newmin >= min_buffers))
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
default_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
|
2012-03-15 13:01:44 +00:00
|
|
|
GstBufferPoolAcquireParams * params)
|
2010-11-02 17:56:29 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn result;
|
2011-02-17 15:46:51 +00:00
|
|
|
GstBufferPoolPrivate *priv = pool->priv;
|
2010-11-02 17:56:29 +00:00
|
|
|
|
|
|
|
while (TRUE) {
|
2012-02-26 19:44:50 +00:00
|
|
|
if (G_UNLIKELY (GST_BUFFER_POOL_IS_FLUSHING (pool)))
|
2011-03-04 11:06:11 +00:00
|
|
|
goto flushing;
|
2010-11-02 17:56:29 +00:00
|
|
|
|
|
|
|
/* try to get a buffer from the queue */
|
2012-08-10 10:23:03 +00:00
|
|
|
*buffer = gst_atomic_queue_pop (priv->queue);
|
2011-02-21 17:43:19 +00:00
|
|
|
if (G_LIKELY (*buffer)) {
|
2012-08-10 10:23:03 +00:00
|
|
|
gst_poll_read_control (priv->poll);
|
2010-11-02 17:56:29 +00:00
|
|
|
result = GST_FLOW_OK;
|
2011-03-04 11:06:11 +00:00
|
|
|
GST_LOG_OBJECT (pool, "acquired buffer %p", *buffer);
|
2010-11-02 17:56:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-10 10:23:03 +00:00
|
|
|
/* no buffer, try to allocate some more */
|
|
|
|
GST_LOG_OBJECT (pool, "no buffer, trying to allocate");
|
2016-02-10 13:01:54 +00:00
|
|
|
result = do_alloc_buffer (pool, buffer, params);
|
2012-08-10 10:23:03 +00:00
|
|
|
if (G_LIKELY (result == GST_FLOW_OK))
|
|
|
|
/* we have a buffer, return it */
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (result != GST_FLOW_EOS))
|
|
|
|
/* something went wrong, return error */
|
2010-11-02 17:56:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* check if we need to wait */
|
2012-03-15 13:01:44 +00:00
|
|
|
if (params && (params->flags & GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT)) {
|
2011-03-04 11:06:11 +00:00
|
|
|
GST_LOG_OBJECT (pool, "no more buffers");
|
2010-11-02 17:56:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-30 11:26:05 +00:00
|
|
|
/* now we release the control socket, we wait for a buffer release or
|
|
|
|
* flushing */
|
|
|
|
gst_poll_read_control (pool->priv->poll);
|
|
|
|
GST_LOG_OBJECT (pool, "waiting for free buffers or flushing");
|
2012-08-10 10:23:03 +00:00
|
|
|
gst_poll_wait (priv->poll, GST_CLOCK_TIME_NONE);
|
2014-01-30 11:26:05 +00:00
|
|
|
gst_poll_write_control (pool->priv->poll);
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
2011-02-18 15:15:30 +00:00
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
return result;
|
2011-03-04 11:06:11 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
flushing:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (pool, "we are flushing");
|
2012-02-08 14:16:46 +00:00
|
|
|
return GST_FLOW_FLUSHING;
|
2011-03-04 11:06:11 +00:00
|
|
|
}
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 17:43:19 +00:00
|
|
|
static inline void
|
|
|
|
dec_outstanding (GstBufferPool * pool)
|
|
|
|
{
|
2012-02-26 19:44:50 +00:00
|
|
|
if (g_atomic_int_dec_and_test (&pool->priv->outstanding)) {
|
2011-02-21 17:43:19 +00:00
|
|
|
/* all buffers are returned to the pool, see if we need to free them */
|
2012-02-26 19:44:50 +00:00
|
|
|
if (GST_BUFFER_POOL_IS_FLUSHING (pool)) {
|
2011-02-21 17:43:19 +00:00
|
|
|
/* take the lock so that set_active is not run concurrently */
|
|
|
|
GST_BUFFER_POOL_LOCK (pool);
|
2014-05-23 19:26:59 +00:00
|
|
|
/* now that we have the lock, check if we have been de-activated with
|
|
|
|
* outstanding buffers */
|
|
|
|
if (!pool->priv->active)
|
2011-02-21 17:43:19 +00:00
|
|
|
do_stop (pool);
|
|
|
|
|
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-23 14:37:45 +00:00
|
|
|
static gboolean
|
|
|
|
remove_meta_unpooled (GstBuffer * buffer, GstMeta ** meta, gpointer user_data)
|
|
|
|
{
|
2012-04-17 13:37:27 +00:00
|
|
|
if (!GST_META_FLAG_IS_SET (*meta, GST_META_FLAG_POOLED)) {
|
|
|
|
GST_META_FLAG_UNSET (*meta, GST_META_FLAG_LOCKED);
|
2011-12-23 14:37:45 +00:00
|
|
|
*meta = NULL;
|
2012-04-17 13:37:27 +00:00
|
|
|
}
|
2011-12-23 14:37:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-21 16:50:25 +00:00
|
|
|
static void
|
2012-04-25 07:06:05 +00:00
|
|
|
default_reset_buffer (GstBufferPool * pool, GstBuffer * buffer)
|
2011-07-21 16:50:25 +00:00
|
|
|
{
|
2014-02-27 14:14:59 +00:00
|
|
|
GST_BUFFER_FLAGS (buffer) &= GST_BUFFER_FLAG_TAG_MEMORY;
|
2011-07-21 16:50:25 +00:00
|
|
|
|
2011-10-28 10:15:44 +00:00
|
|
|
GST_BUFFER_PTS (buffer) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_DTS (buffer) = GST_CLOCK_TIME_NONE;
|
2011-07-21 16:50:25 +00:00
|
|
|
GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE;
|
|
|
|
GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE;
|
2011-12-23 14:37:45 +00:00
|
|
|
|
|
|
|
/* remove all metadata without the POOLED flag */
|
|
|
|
gst_buffer_foreach_meta (buffer, remove_meta_unpooled, pool);
|
2011-07-21 16:50:25 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
/**
|
|
|
|
* gst_buffer_pool_acquire_buffer:
|
|
|
|
* @pool: a #GstBufferPool
|
2011-11-10 12:53:33 +00:00
|
|
|
* @buffer: (out): a location for a #GstBuffer
|
2014-03-02 16:55:45 +00:00
|
|
|
* @params: (transfer none) (allow-none): parameters.
|
2010-11-02 17:56:29 +00:00
|
|
|
*
|
|
|
|
* Acquire a buffer from @pool. @buffer should point to a memory location that
|
|
|
|
* can hold a pointer to the new buffer.
|
|
|
|
*
|
2014-01-30 11:42:02 +00:00
|
|
|
* @params can be %NULL or contain optional parameters to influence the
|
|
|
|
* allocation.
|
2010-11-02 17:56:29 +00:00
|
|
|
*
|
2014-01-31 07:08:37 +00:00
|
|
|
* Returns: a #GstFlowReturn such as %GST_FLOW_FLUSHING when the pool is
|
2011-02-18 11:50:21 +00:00
|
|
|
* inactive.
|
2010-11-02 17:56:29 +00:00
|
|
|
*/
|
|
|
|
GstFlowReturn
|
|
|
|
gst_buffer_pool_acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
|
2012-03-15 13:01:44 +00:00
|
|
|
GstBufferPoolAcquireParams * params)
|
2010-11-02 17:56:29 +00:00
|
|
|
{
|
|
|
|
GstBufferPoolClass *pclass;
|
|
|
|
GstFlowReturn result;
|
|
|
|
|
2011-02-17 15:46:51 +00:00
|
|
|
g_return_val_if_fail (GST_IS_BUFFER_POOL (pool), GST_FLOW_ERROR);
|
|
|
|
g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
|
|
|
|
|
2011-02-21 17:43:19 +00:00
|
|
|
/* assume we'll have one more outstanding buffer we need to do that so
|
|
|
|
* that concurrent set_active doesn't clear the buffers */
|
2012-02-26 19:44:50 +00:00
|
|
|
g_atomic_int_inc (&pool->priv->outstanding);
|
2011-02-21 17:43:19 +00:00
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
if (G_LIKELY (pclass->acquire_buffer))
|
|
|
|
result = pclass->acquire_buffer (pool, buffer, params);
|
|
|
|
else
|
|
|
|
result = GST_FLOW_NOT_SUPPORTED;
|
|
|
|
|
2011-02-22 11:35:45 +00:00
|
|
|
if (G_LIKELY (result == GST_FLOW_OK)) {
|
|
|
|
/* all buffers from the pool point to the pool and have the refcount of the
|
|
|
|
* pool incremented */
|
|
|
|
(*buffer)->pool = gst_object_ref (pool);
|
|
|
|
} else {
|
2011-02-21 17:43:19 +00:00
|
|
|
dec_outstanding (pool);
|
2011-02-22 11:35:45 +00:00
|
|
|
}
|
2010-11-02 17:56:29 +00:00
|
|
|
|
2011-02-18 15:15:30 +00:00
|
|
|
return result;
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
default_release_buffer (GstBufferPool * pool, GstBuffer * buffer)
|
|
|
|
{
|
2014-02-27 14:14:59 +00:00
|
|
|
GST_LOG_OBJECT (pool, "released buffer %p %d", buffer,
|
|
|
|
GST_MINI_OBJECT_FLAGS (buffer));
|
|
|
|
|
2014-02-27 15:40:34 +00:00
|
|
|
/* memory should be untouched */
|
2014-12-16 11:21:59 +00:00
|
|
|
if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY)))
|
|
|
|
goto memory_tagged;
|
2014-02-27 15:40:34 +00:00
|
|
|
|
2014-03-26 19:56:08 +00:00
|
|
|
/* size should have been reset. This is not a catch all, pool with
|
|
|
|
* size requirement per memory should do their own check. */
|
2014-12-16 11:21:59 +00:00
|
|
|
if (G_UNLIKELY (gst_buffer_get_size (buffer) != pool->priv->size))
|
|
|
|
goto size_changed;
|
2014-03-26 19:56:08 +00:00
|
|
|
|
2014-02-27 15:40:34 +00:00
|
|
|
/* all memory should be exclusive to this buffer (and thus be writable) */
|
2014-12-16 11:21:59 +00:00
|
|
|
if (G_UNLIKELY (!gst_buffer_is_all_memory_writable (buffer)))
|
|
|
|
goto not_writable;
|
2014-02-27 15:40:34 +00:00
|
|
|
|
|
|
|
/* keep it around in our queue */
|
|
|
|
gst_atomic_queue_push (pool->priv->queue, buffer);
|
|
|
|
gst_poll_write_control (pool->priv->poll);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
2014-12-16 11:21:59 +00:00
|
|
|
memory_tagged:
|
|
|
|
{
|
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pool,
|
|
|
|
"discarding buffer %p: memory tag set", buffer);
|
|
|
|
goto discard;
|
|
|
|
}
|
|
|
|
size_changed:
|
|
|
|
{
|
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pool,
|
|
|
|
"discarding buffer %p: size %" G_GSIZE_FORMAT " != %u",
|
|
|
|
buffer, gst_buffer_get_size (buffer), pool->priv->size);
|
|
|
|
goto discard;
|
|
|
|
}
|
|
|
|
not_writable:
|
|
|
|
{
|
|
|
|
GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pool,
|
|
|
|
"discarding buffer %p: memory not writable", buffer);
|
|
|
|
goto discard;
|
|
|
|
}
|
2014-02-27 15:40:34 +00:00
|
|
|
discard:
|
|
|
|
{
|
2014-02-27 14:14:59 +00:00
|
|
|
do_free_buffer (pool, buffer);
|
2014-02-27 15:40:34 +00:00
|
|
|
return;
|
2014-02-27 14:14:59 +00:00
|
|
|
}
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_pool_release_buffer:
|
|
|
|
* @pool: a #GstBufferPool
|
2012-03-27 10:39:53 +00:00
|
|
|
* @buffer: (transfer full): a #GstBuffer
|
2010-11-02 17:56:29 +00:00
|
|
|
*
|
|
|
|
* Release @buffer to @pool. @buffer should have previously been allocated from
|
|
|
|
* @pool with gst_buffer_pool_acquire_buffer().
|
|
|
|
*
|
|
|
|
* This function is usually called automatically when the last ref on @buffer
|
|
|
|
* disappears.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_buffer_pool_release_buffer (GstBufferPool * pool, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstBufferPoolClass *pclass;
|
|
|
|
|
2011-02-17 15:46:51 +00:00
|
|
|
g_return_if_fail (GST_IS_BUFFER_POOL (pool));
|
|
|
|
g_return_if_fail (buffer != NULL);
|
|
|
|
|
2011-02-22 11:35:45 +00:00
|
|
|
/* check that the buffer is ours, all buffers returned to the pool have the
|
|
|
|
* pool member set to NULL and the pool refcount decreased */
|
2012-01-22 01:25:22 +00:00
|
|
|
if (!g_atomic_pointer_compare_and_exchange (&buffer->pool, pool, NULL))
|
2011-02-22 11:35:45 +00:00
|
|
|
return;
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
pclass = GST_BUFFER_POOL_GET_CLASS (pool);
|
|
|
|
|
2012-04-25 07:06:05 +00:00
|
|
|
/* reset the buffer when needed */
|
|
|
|
if (G_LIKELY (pclass->reset_buffer))
|
|
|
|
pclass->reset_buffer (pool, buffer);
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
if (G_LIKELY (pclass->release_buffer))
|
|
|
|
pclass->release_buffer (pool, buffer);
|
2011-02-18 15:15:30 +00:00
|
|
|
|
2011-02-21 17:43:19 +00:00
|
|
|
dec_outstanding (pool);
|
2011-02-22 11:35:45 +00:00
|
|
|
|
|
|
|
/* decrease the refcount that the buffer had to us */
|
|
|
|
gst_object_unref (pool);
|
2010-11-02 17:56:29 +00:00
|
|
|
}
|
2014-05-23 19:26:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_buffer_pool_set_flushing:
|
|
|
|
* @pool: a #GstBufferPool
|
|
|
|
* @flushing: whether to start or stop flushing
|
|
|
|
*
|
2014-07-01 06:39:18 +00:00
|
|
|
* Enable or disable the flushing state of a @pool without freeing or
|
2014-05-23 19:26:59 +00:00
|
|
|
* allocating buffers.
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_buffer_pool_set_flushing (GstBufferPool * pool, gboolean flushing)
|
|
|
|
{
|
|
|
|
GstBufferPoolPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_BUFFER_POOL (pool));
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (pool, "flushing %d", flushing);
|
|
|
|
|
|
|
|
priv = pool->priv;
|
|
|
|
|
|
|
|
GST_BUFFER_POOL_LOCK (pool);
|
|
|
|
|
|
|
|
if (!priv->active) {
|
|
|
|
GST_WARNING_OBJECT (pool, "can't change flushing state of inactive pool");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_set_flushing (pool, flushing);
|
|
|
|
|
|
|
|
done:
|
|
|
|
GST_BUFFER_POOL_UNLOCK (pool);
|
|
|
|
}
|