2 * Copyright (C) 2010 Wim Taymans <wim.taymans@gmail.com>
4 * gstbufferpool.h: Header for GstBufferPool object
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #ifndef __GST_BUFFER_POOL_H__
24 #define __GST_BUFFER_POOL_H__
26 #include <gst/gstminiobject.h>
27 #include <gst/gstpad.h>
28 #include <gst/gstbuffer.h>
32 typedef struct _GstBufferPoolPrivate GstBufferPoolPrivate;
33 typedef struct _GstBufferPoolClass GstBufferPoolClass;
35 #define GST_TYPE_BUFFER_POOL (gst_buffer_pool_get_type())
36 #define GST_IS_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_BUFFER_POOL))
37 #define GST_IS_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_BUFFER_POOL))
38 #define GST_BUFFER_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
39 #define GST_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_BUFFER_POOL, GstBufferPool))
40 #define GST_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
41 #define GST_BUFFER_POOL_CAST(obj) ((GstBufferPool *)(obj))
44 * GstBufferPoolAcquireFlags:
45 * @GST_BUFFER_POOL_ACQUIRE_FLAG_NONE: no flags
46 * @GST_BUFFER_POOL_ACQUIRE_FLAG_KEY_UNIT: buffer is keyframe
47 * @GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT: don't wait for buffer. This makes the
48 * acquire_buffer method return GST_FLOW_UNEXPECTED.
49 * @GST_BUFFER_POOL_ACQUIRE_FLAG_DISCONT: buffer is discont
50 * @GST_BUFFER_POOL_ACQUIRE_FLAG_LAST: last flag, subclasses can use private flags
51 * starting from this value.
53 * Additional flags to control the allocation of a buffer
56 GST_BUFFER_POOL_ACQUIRE_FLAG_NONE = 0,
57 GST_BUFFER_POOL_ACQUIRE_FLAG_KEY_UNIT = (1 << 0),
58 GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT = (1 << 1),
59 GST_BUFFER_POOL_ACQUIRE_FLAG_DISCONT = (1 << 2),
60 GST_BUFFER_POOL_ACQUIRE_FLAG_LAST = (1 << 16),
61 } GstBufferPoolAcquireFlags;
64 * GstBufferPoolAcquireParams:
65 * @format: the format of @start and @stop
66 * @start: the start position
67 * @stop: the stop position
68 * @flags: additional flags
70 * Parameters passed to the gst_buffer_pool_acquire_buffer() function to control the
71 * allocation of the buffer.
73 * The default implementation ignores the @start and @stop members but other
74 * implementations can use this extra information to decide what buffer to
77 typedef struct _GstBufferPoolAcquireParams {
81 GstBufferPoolAcquireFlags flags;
84 gpointer _gst_reserved[GST_PADDING];
85 } GstBufferPoolAcquireParams;
88 * GST_BUFFER_POOL_IS_FLUSHING:
89 * @pool: a GstBufferPool
91 * Check if the bufferpool is flushing. Subclasses might want to check the
92 * state of the pool in the acquire function.
94 #define GST_BUFFER_POOL_IS_FLUSHING(pool) (g_atomic_int_get (&pool->flushing))
98 * @object: the parent structure
100 * The structure of a #GstBufferPool. Use the associated macros to access the public
103 struct _GstBufferPool {
110 GstBufferPoolPrivate *priv;
112 gpointer _gst_reserved[GST_PADDING];
116 * GstBufferPoolClass:
117 * @object_class: Object parent class
118 * @get_options: get a list of options supported by this pool
119 * @set_config: apply the bufferpool configuration. The default configuration
120 * will parse the default config parameters
121 * @start: start the bufferpool. The default implementation will preallocate
122 * min-buffers buffers and put them in the queue
123 * @stop: stop the bufferpool. the default implementation will free the
124 * preallocated buffers. This function is called when all the buffers are
125 * returned to the pool.
126 * @acquire_buffer: get a new buffer from the pool. The default implementation
127 * will take a buffer from the queue and optionally wait for a buffer to
128 * be released when there are no buffers available.
129 * @alloc_buffer: allocate a buffer. the default implementation allocates
130 * buffers from the default memory allocator and with the configured
131 * size, prefix, padding and alignment. All metadata that is present on the
132 * allocated buffer will be marked as #GST_META_FLAG_POOLED and will not
133 * be removed from the buffer in @reset_buffer.
134 * @reset_buffer: reset the buffer to its state when it was freshly allocated.
135 * The default implementation will clear the flags, timestamps and
136 * will remove the metadata added after alloc_buffer.
137 * @release_buffer: release a buffer back in the pool. The default
138 * implementation will put the buffer back in the queue and notify any
139 * blocking acquire_buffer calls.
140 * @free_buffer: free a buffer. The default implementation unrefs the buffer.
142 * The GstBufferPool class.
144 struct _GstBufferPoolClass {
145 GstObjectClass object_class;
148 const gchar ** (*get_options) (GstBufferPool *pool);
149 gboolean (*set_config) (GstBufferPool *pool, GstStructure *config);
151 gboolean (*start) (GstBufferPool *pool);
152 gboolean (*stop) (GstBufferPool *pool);
154 GstFlowReturn (*acquire_buffer) (GstBufferPool *pool, GstBuffer **buffer,
155 GstBufferPoolAcquireParams *params);
156 GstFlowReturn (*alloc_buffer) (GstBufferPool *pool, GstBuffer **buffer,
157 GstBufferPoolAcquireParams *params);
158 void (*reset_buffer) (GstBufferPool *pool, GstBuffer *buffer,
159 GstBufferPoolAcquireParams *params);
160 void (*release_buffer) (GstBufferPool *pool, GstBuffer *buffer);
161 void (*free_buffer) (GstBufferPool *pool, GstBuffer *buffer);
164 gpointer _gst_reserved[GST_PADDING];
167 GType gst_buffer_pool_get_type (void);
170 GstBufferPool * gst_buffer_pool_new (void);
172 /* state management */
173 gboolean gst_buffer_pool_set_active (GstBufferPool *pool, gboolean active);
174 gboolean gst_buffer_pool_is_active (GstBufferPool *pool);
176 gboolean gst_buffer_pool_set_config (GstBufferPool *pool, GstStructure *config);
177 GstStructure * gst_buffer_pool_get_config (GstBufferPool *pool);
179 const gchar ** gst_buffer_pool_get_options (GstBufferPool *pool);
180 gboolean gst_buffer_pool_has_option (GstBufferPool *pool, const gchar *option);
183 /* helpers for configuring the config structure */
184 void gst_buffer_pool_config_set_params (GstStructure *config, GstCaps *caps,
185 guint size, guint min_buffers, guint max_buffers);
186 gboolean gst_buffer_pool_config_get_params (GstStructure *config, GstCaps **caps,
187 guint *size, guint *min_buffers, guint *max_buffers);
188 void gst_buffer_pool_config_set_allocator (GstStructure *config, GstAllocator *allocator,
189 const GstAllocationParams *params);
190 gboolean gst_buffer_pool_config_get_allocator (GstStructure *config, GstAllocator **allocator,
191 GstAllocationParams *params);
194 guint gst_buffer_pool_config_n_options (GstStructure *config);
195 void gst_buffer_pool_config_add_option (GstStructure *config, const gchar *option);
196 const gchar * gst_buffer_pool_config_get_option (GstStructure *config, guint index);
197 gboolean gst_buffer_pool_config_has_option (GstStructure *config, const gchar *option);
199 /* buffer management */
200 GstFlowReturn gst_buffer_pool_acquire_buffer (GstBufferPool *pool, GstBuffer **buffer,
201 GstBufferPoolAcquireParams *params);
202 void gst_buffer_pool_release_buffer (GstBufferPool *pool, GstBuffer *buffer);
206 #endif /* __GST_BUFFER_POOL_H__ */