2010-11-02 17:56:29 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2010 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
*
|
|
|
|
* gstbufferpool.h: Header for GstBufferPool object
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __GST_BUFFER_POOL_H__
|
|
|
|
#define __GST_BUFFER_POOL_H__
|
|
|
|
|
|
|
|
#include <gst/gstminiobject.h>
|
|
|
|
#include <gst/gstpad.h>
|
|
|
|
#include <gst/gstbuffer.h>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2011-02-17 15:46:51 +00:00
|
|
|
typedef struct _GstBufferPoolPrivate GstBufferPoolPrivate;
|
2010-11-02 17:56:29 +00:00
|
|
|
typedef struct _GstBufferPoolClass GstBufferPoolClass;
|
|
|
|
|
|
|
|
#define GST_TYPE_BUFFER_POOL (gst_buffer_pool_get_type())
|
|
|
|
#define GST_IS_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_BUFFER_POOL))
|
|
|
|
#define GST_IS_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_BUFFER_POOL))
|
|
|
|
#define GST_BUFFER_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
|
|
|
|
#define GST_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_BUFFER_POOL, GstBufferPool))
|
|
|
|
#define GST_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
|
|
|
|
#define GST_BUFFER_POOL_CAST(obj) ((GstBufferPool *)(obj))
|
|
|
|
|
|
|
|
/**
|
2012-03-15 13:01:44 +00:00
|
|
|
* GstBufferPoolAcquireFlags:
|
|
|
|
* @GST_BUFFER_POOL_ACQUIRE_FLAG_NONE: no flags
|
|
|
|
* @GST_BUFFER_POOL_ACQUIRE_FLAG_KEY_UNIT: buffer is keyframe
|
2012-12-06 08:48:08 +00:00
|
|
|
* @GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT: when the bufferpool is empty, acquire_buffer
|
|
|
|
* will by default block until a buffer is released into the pool again. Setting
|
|
|
|
* this flag makes acquire_buffer return #GST_FLOW_EOS instead of blocking.
|
2012-03-15 13:01:44 +00:00
|
|
|
* @GST_BUFFER_POOL_ACQUIRE_FLAG_DISCONT: buffer is discont
|
|
|
|
* @GST_BUFFER_POOL_ACQUIRE_FLAG_LAST: last flag, subclasses can use private flags
|
2011-09-26 18:47:35 +00:00
|
|
|
* starting from this value.
|
2010-11-02 17:56:29 +00:00
|
|
|
*
|
|
|
|
* Additional flags to control the allocation of a buffer
|
|
|
|
*/
|
|
|
|
typedef enum {
|
2012-03-15 13:01:44 +00:00
|
|
|
GST_BUFFER_POOL_ACQUIRE_FLAG_NONE = 0,
|
|
|
|
GST_BUFFER_POOL_ACQUIRE_FLAG_KEY_UNIT = (1 << 0),
|
|
|
|
GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT = (1 << 1),
|
|
|
|
GST_BUFFER_POOL_ACQUIRE_FLAG_DISCONT = (1 << 2),
|
|
|
|
GST_BUFFER_POOL_ACQUIRE_FLAG_LAST = (1 << 16),
|
|
|
|
} GstBufferPoolAcquireFlags;
|
2010-11-02 17:56:29 +00:00
|
|
|
|
2012-06-19 23:06:49 +00:00
|
|
|
typedef struct _GstBufferPoolAcquireParams GstBufferPoolAcquireParams;
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
/**
|
2012-03-15 13:01:44 +00:00
|
|
|
* GstBufferPoolAcquireParams:
|
2010-11-02 17:56:29 +00:00
|
|
|
* @format: the format of @start and @stop
|
|
|
|
* @start: the start position
|
|
|
|
* @stop: the stop position
|
|
|
|
* @flags: additional flags
|
|
|
|
*
|
|
|
|
* Parameters passed to the gst_buffer_pool_acquire_buffer() function to control the
|
|
|
|
* allocation of the buffer.
|
2011-07-21 16:50:25 +00:00
|
|
|
*
|
|
|
|
* The default implementation ignores the @start and @stop members but other
|
|
|
|
* implementations can use this extra information to decide what buffer to
|
|
|
|
* return.
|
2010-11-02 17:56:29 +00:00
|
|
|
*/
|
2012-06-19 23:06:49 +00:00
|
|
|
struct _GstBufferPoolAcquireParams {
|
2012-03-15 13:01:44 +00:00
|
|
|
GstFormat format;
|
|
|
|
gint64 start;
|
|
|
|
gint64 stop;
|
|
|
|
GstBufferPoolAcquireFlags flags;
|
2011-11-11 15:52:41 +00:00
|
|
|
|
2011-11-14 09:27:01 +00:00
|
|
|
/*< private >*/
|
2011-11-11 15:52:41 +00:00
|
|
|
gpointer _gst_reserved[GST_PADDING];
|
2012-06-19 23:06:49 +00:00
|
|
|
};
|
2010-11-02 17:56:29 +00:00
|
|
|
|
2011-07-15 09:52:22 +00:00
|
|
|
/**
|
|
|
|
* GST_BUFFER_POOL_IS_FLUSHING:
|
|
|
|
* @pool: a GstBufferPool
|
|
|
|
*
|
|
|
|
* Check if the bufferpool is flushing. Subclasses might want to check the
|
|
|
|
* state of the pool in the acquire function.
|
|
|
|
*/
|
|
|
|
#define GST_BUFFER_POOL_IS_FLUSHING(pool) (g_atomic_int_get (&pool->flushing))
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
/**
|
|
|
|
* GstBufferPool:
|
|
|
|
*
|
|
|
|
* The structure of a #GstBufferPool. Use the associated macros to access the public
|
|
|
|
* variables.
|
|
|
|
*/
|
|
|
|
struct _GstBufferPool {
|
|
|
|
GstObject object;
|
|
|
|
|
2012-02-26 19:44:50 +00:00
|
|
|
/*< protected >*/
|
|
|
|
gint flushing;
|
2011-02-17 15:46:51 +00:00
|
|
|
|
2012-02-26 19:44:50 +00:00
|
|
|
/*< private >*/
|
2011-02-17 15:46:51 +00:00
|
|
|
GstBufferPoolPrivate *priv;
|
2010-11-02 17:56:29 +00:00
|
|
|
|
|
|
|
gpointer _gst_reserved[GST_PADDING];
|
|
|
|
};
|
|
|
|
|
2011-07-21 16:50:25 +00:00
|
|
|
/**
|
|
|
|
* GstBufferPoolClass:
|
|
|
|
* @object_class: Object parent class
|
2011-07-29 15:10:09 +00:00
|
|
|
* @get_options: get a list of options supported by this pool
|
2011-07-21 16:50:25 +00:00
|
|
|
* @set_config: apply the bufferpool configuration. The default configuration
|
|
|
|
* will parse the default config parameters
|
|
|
|
* @start: start the bufferpool. The default implementation will preallocate
|
|
|
|
* min-buffers buffers and put them in the queue
|
|
|
|
* @stop: stop the bufferpool. the default implementation will free the
|
|
|
|
* preallocated buffers. This function is called when all the buffers are
|
|
|
|
* returned to the pool.
|
|
|
|
* @acquire_buffer: get a new buffer from the pool. The default implementation
|
|
|
|
* will take a buffer from the queue and optionally wait for a buffer to
|
|
|
|
* be released when there are no buffers available.
|
|
|
|
* @alloc_buffer: allocate a buffer. the default implementation allocates
|
2012-03-28 16:12:23 +00:00
|
|
|
* buffers from the configured memory allocator and with the configured
|
|
|
|
* parameters. All metadata that is present on the allocated buffer will
|
2012-04-17 13:37:27 +00:00
|
|
|
* be marked as #GST_META_FLAG_POOLED and #GST_META_FLAG_LOCKED and will
|
2014-03-07 20:43:44 +00:00
|
|
|
* not be removed from the buffer in @reset_buffer. The buffer should
|
|
|
|
* have the GST_BUFFER_FLAG_TAG_MEMORY cleared.
|
2011-07-21 16:50:25 +00:00
|
|
|
* @reset_buffer: reset the buffer to its state when it was freshly allocated.
|
2011-12-23 14:37:45 +00:00
|
|
|
* The default implementation will clear the flags, timestamps and
|
2012-04-17 13:37:27 +00:00
|
|
|
* will remove the metadata without the #GST_META_FLAG_POOLED flag (even
|
2014-02-27 14:14:59 +00:00
|
|
|
* the metadata with #GST_META_FLAG_LOCKED). If the
|
2014-03-07 20:43:44 +00:00
|
|
|
* #GST_BUFFER_FLAG_TAG_MEMORY was set, this function can also try to
|
|
|
|
* restore the memory and clear the #GST_BUFFER_FLAG_TAG_MEMORY again.
|
2011-07-21 16:50:25 +00:00
|
|
|
* @release_buffer: release a buffer back in the pool. The default
|
|
|
|
* implementation will put the buffer back in the queue and notify any
|
2014-02-27 14:14:59 +00:00
|
|
|
* blocking acquire_buffer calls when the #GST_BUFFER_FLAG_TAG_MEMORY
|
2014-03-07 20:43:44 +00:00
|
|
|
* is not set on the buffer. If #GST_BUFFER_FLAG_TAG_MEMORY is set, the
|
2014-02-27 14:14:59 +00:00
|
|
|
* buffer will be freed with @free_buffer.
|
2011-07-21 16:50:25 +00:00
|
|
|
* @free_buffer: free a buffer. The default implementation unrefs the buffer.
|
2014-05-23 19:26:59 +00:00
|
|
|
* @flush_start: enter the flushing state. Since: 1.4
|
|
|
|
* @flush_stop: leave the flushign state. Since: 1.4
|
2011-07-21 16:50:25 +00:00
|
|
|
*
|
|
|
|
* The GstBufferPool class.
|
|
|
|
*/
|
2010-11-02 17:56:29 +00:00
|
|
|
struct _GstBufferPoolClass {
|
|
|
|
GstObjectClass object_class;
|
|
|
|
|
2014-01-31 07:08:37 +00:00
|
|
|
/*< public >*/
|
2011-07-29 15:10:09 +00:00
|
|
|
const gchar ** (*get_options) (GstBufferPool *pool);
|
2011-02-17 15:46:51 +00:00
|
|
|
gboolean (*set_config) (GstBufferPool *pool, GstStructure *config);
|
2010-11-02 17:56:29 +00:00
|
|
|
|
2011-02-21 16:33:38 +00:00
|
|
|
gboolean (*start) (GstBufferPool *pool);
|
|
|
|
gboolean (*stop) (GstBufferPool *pool);
|
|
|
|
|
2010-11-02 17:56:29 +00:00
|
|
|
GstFlowReturn (*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 (*alloc_buffer) (GstBufferPool *pool, GstBuffer **buffer,
|
2012-03-15 13:01:44 +00:00
|
|
|
GstBufferPoolAcquireParams *params);
|
2012-04-25 07:06:05 +00:00
|
|
|
void (*reset_buffer) (GstBufferPool *pool, GstBuffer *buffer);
|
2010-11-02 17:56:29 +00:00
|
|
|
void (*release_buffer) (GstBufferPool *pool, GstBuffer *buffer);
|
|
|
|
void (*free_buffer) (GstBufferPool *pool, GstBuffer *buffer);
|
2014-05-23 19:26:59 +00:00
|
|
|
void (*flush_start) (GstBufferPool *pool);
|
|
|
|
void (*flush_stop) (GstBufferPool *pool);
|
2010-11-02 17:56:29 +00:00
|
|
|
|
2011-09-26 18:47:35 +00:00
|
|
|
/*< private >*/
|
2014-05-23 19:26:59 +00:00
|
|
|
gpointer _gst_reserved[GST_PADDING - 2];
|
2010-11-02 17:56:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GType gst_buffer_pool_get_type (void);
|
|
|
|
|
|
|
|
/* allocation */
|
2011-06-20 11:26:06 +00:00
|
|
|
GstBufferPool * gst_buffer_pool_new (void);
|
2010-11-02 17:56:29 +00:00
|
|
|
|
|
|
|
/* state management */
|
2011-06-20 11:26:06 +00:00
|
|
|
gboolean gst_buffer_pool_set_active (GstBufferPool *pool, gboolean active);
|
2011-08-04 08:54:29 +00:00
|
|
|
gboolean gst_buffer_pool_is_active (GstBufferPool *pool);
|
2011-02-17 15:46:51 +00:00
|
|
|
|
2011-06-20 11:26:06 +00:00
|
|
|
gboolean gst_buffer_pool_set_config (GstBufferPool *pool, GstStructure *config);
|
|
|
|
GstStructure * gst_buffer_pool_get_config (GstBufferPool *pool);
|
|
|
|
|
2011-07-29 15:10:09 +00:00
|
|
|
const gchar ** gst_buffer_pool_get_options (GstBufferPool *pool);
|
2011-07-30 12:04:43 +00:00
|
|
|
gboolean gst_buffer_pool_has_option (GstBufferPool *pool, const gchar *option);
|
2010-11-02 17:56:29 +00:00
|
|
|
|
2014-05-23 19:26:59 +00:00
|
|
|
void gst_buffer_pool_set_flushing (GstBufferPool *poo, gboolean flushing);
|
|
|
|
|
2011-02-17 15:46:51 +00:00
|
|
|
/* helpers for configuring the config structure */
|
2012-03-27 10:40:36 +00:00
|
|
|
void 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);
|
2012-03-27 10:40:36 +00:00
|
|
|
gboolean 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);
|
|
|
|
void gst_buffer_pool_config_set_allocator (GstStructure *config, GstAllocator *allocator,
|
|
|
|
const GstAllocationParams *params);
|
|
|
|
gboolean gst_buffer_pool_config_get_allocator (GstStructure *config, GstAllocator **allocator,
|
|
|
|
GstAllocationParams *params);
|
2011-06-20 11:26:06 +00:00
|
|
|
|
2011-07-29 15:10:09 +00:00
|
|
|
/* options */
|
|
|
|
guint gst_buffer_pool_config_n_options (GstStructure *config);
|
|
|
|
void gst_buffer_pool_config_add_option (GstStructure *config, const gchar *option);
|
|
|
|
const gchar * gst_buffer_pool_config_get_option (GstStructure *config, guint index);
|
|
|
|
gboolean gst_buffer_pool_config_has_option (GstStructure *config, const gchar *option);
|
2014-05-08 16:47:43 +00:00
|
|
|
gboolean gst_buffer_pool_config_validate_params (GstStructure *config, GstCaps *caps,
|
|
|
|
guint size, guint min_buffers, guint max_buffers);
|
2010-11-02 17:56:29 +00:00
|
|
|
|
|
|
|
/* buffer management */
|
2011-06-20 11:26:06 +00:00
|
|
|
GstFlowReturn gst_buffer_pool_acquire_buffer (GstBufferPool *pool, GstBuffer **buffer,
|
2012-03-15 13:01:44 +00:00
|
|
|
GstBufferPoolAcquireParams *params);
|
2011-06-20 11:26:06 +00:00
|
|
|
void gst_buffer_pool_release_buffer (GstBufferPool *pool, GstBuffer *buffer);
|
2010-11-02 17:56:29 +00:00
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
|
|
|
|
#endif /* __GST_BUFFER_POOL_H__ */
|