Blame gst/gstbufferpool.c

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