g_type_init() is no longer required and deprecated in glib >= 2.35.0
[platform/upstream/gstreamer.git] / gst / gstbufferpool.h
1 /* GStreamer
2  * Copyright (C) 2010 Wim Taymans <wim.taymans@gmail.com>
3  *
4  * gstbufferpool.h: Header for GstBufferPool object
5  *
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.
10  *
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.
15  *
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.
20  */
21
22
23 #ifndef __GST_BUFFER_POOL_H__
24 #define __GST_BUFFER_POOL_H__
25
26 #include <gst/gstminiobject.h>
27 #include <gst/gstpad.h>
28 #include <gst/gstbuffer.h>
29
30 G_BEGIN_DECLS
31
32 typedef struct _GstBufferPoolPrivate GstBufferPoolPrivate;
33 typedef struct _GstBufferPoolClass GstBufferPoolClass;
34
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))
42
43 /**
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_EOS.
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.
52  *
53  * Additional flags to control the allocation of a buffer
54  */
55 typedef enum {
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;
62
63 typedef struct _GstBufferPoolAcquireParams GstBufferPoolAcquireParams;
64
65 /**
66  * GstBufferPoolAcquireParams:
67  * @format: the format of @start and @stop
68  * @start: the start position
69  * @stop: the stop position
70  * @flags: additional flags
71  *
72  * Parameters passed to the gst_buffer_pool_acquire_buffer() function to control the
73  * allocation of the buffer.
74  *
75  * The default implementation ignores the @start and @stop members but other
76  * implementations can use this extra information to decide what buffer to
77  * return.
78  */
79 struct _GstBufferPoolAcquireParams {
80   GstFormat                 format;
81   gint64                    start;
82   gint64                    stop;
83   GstBufferPoolAcquireFlags flags;
84
85   /*< private >*/
86   gpointer _gst_reserved[GST_PADDING];
87 };
88
89 /**
90  * GST_BUFFER_POOL_IS_FLUSHING:
91  * @pool: a GstBufferPool
92  *
93  * Check if the bufferpool is flushing. Subclasses might want to check the
94  * state of the pool in the acquire function.
95  */
96 #define GST_BUFFER_POOL_IS_FLUSHING(pool)  (g_atomic_int_get (&pool->flushing))
97
98 /**
99  * GstBufferPool:
100  * @object: the parent structure
101  *
102  * The structure of a #GstBufferPool. Use the associated macros to access the public
103  * variables.
104  */
105 struct _GstBufferPool {
106   GstObject            object;
107
108   /*< protected >*/
109   gint                 flushing;
110
111   /*< private >*/
112   GstBufferPoolPrivate *priv;
113
114   gpointer _gst_reserved[GST_PADDING];
115 };
116
117 /**
118  * GstBufferPoolClass:
119  * @object_class:  Object parent class
120  * @get_options: get a list of options supported by this pool
121  * @set_config: apply the bufferpool configuration. The default configuration
122  *              will parse the default config parameters
123  * @start: start the bufferpool. The default implementation will preallocate
124  *         min-buffers buffers and put them in the queue
125  * @stop: stop the bufferpool. the default implementation will free the
126  *        preallocated buffers. This function is called when all the buffers are
127  *        returned to the pool.
128  * @acquire_buffer: get a new buffer from the pool. The default implementation
129  *        will take a buffer from the queue and optionally wait for a buffer to
130  *        be released when there are no buffers available.
131  * @alloc_buffer: allocate a buffer. the default implementation allocates
132  *        buffers from the configured memory allocator and with the configured
133  *        parameters. All metadata that is present on the allocated buffer will
134  *        be marked as #GST_META_FLAG_POOLED and #GST_META_FLAG_LOCKED and will
135  *        not be removed from the buffer in @reset_buffer.
136  * @reset_buffer: reset the buffer to its state when it was freshly allocated.
137  *        The default implementation will clear the flags, timestamps and
138  *        will remove the metadata without the #GST_META_FLAG_POOLED flag (even
139  *        the metadata with #GST_META_FLAG_LOCKED).
140  * @release_buffer: release a buffer back in the pool. The default
141  *        implementation will put the buffer back in the queue and notify any
142  *        blocking acquire_buffer calls.
143  * @free_buffer: free a buffer. The default implementation unrefs the buffer.
144  *
145  * The GstBufferPool class.
146  */
147 struct _GstBufferPoolClass {
148   GstObjectClass    object_class;
149
150   /* vmethods */
151   const gchar ** (*get_options)    (GstBufferPool *pool);
152   gboolean       (*set_config)     (GstBufferPool *pool, GstStructure *config);
153
154   gboolean       (*start)          (GstBufferPool *pool);
155   gboolean       (*stop)           (GstBufferPool *pool);
156
157   GstFlowReturn  (*acquire_buffer) (GstBufferPool *pool, GstBuffer **buffer,
158                                     GstBufferPoolAcquireParams *params);
159   GstFlowReturn  (*alloc_buffer)   (GstBufferPool *pool, GstBuffer **buffer,
160                                     GstBufferPoolAcquireParams *params);
161   void           (*reset_buffer)   (GstBufferPool *pool, GstBuffer *buffer);
162   void           (*release_buffer) (GstBufferPool *pool, GstBuffer *buffer);
163   void           (*free_buffer)    (GstBufferPool *pool, GstBuffer *buffer);
164
165   /*< private >*/
166   gpointer _gst_reserved[GST_PADDING];
167 };
168
169 GType       gst_buffer_pool_get_type (void);
170
171 /* allocation */
172 GstBufferPool *  gst_buffer_pool_new  (void);
173
174 /* state management */
175 gboolean         gst_buffer_pool_set_active      (GstBufferPool *pool, gboolean active);
176 gboolean         gst_buffer_pool_is_active       (GstBufferPool *pool);
177
178 gboolean         gst_buffer_pool_set_config      (GstBufferPool *pool, GstStructure *config);
179 GstStructure *   gst_buffer_pool_get_config      (GstBufferPool *pool);
180
181 const gchar **   gst_buffer_pool_get_options     (GstBufferPool *pool);
182 gboolean         gst_buffer_pool_has_option      (GstBufferPool *pool, const gchar *option);
183
184 /* helpers for configuring the config structure */
185 void             gst_buffer_pool_config_set_params    (GstStructure *config, GstCaps *caps,
186                                                        guint size, guint min_buffers, guint max_buffers);
187 gboolean         gst_buffer_pool_config_get_params    (GstStructure *config, GstCaps **caps,
188                                                        guint *size, guint *min_buffers, guint *max_buffers);
189 void             gst_buffer_pool_config_set_allocator (GstStructure *config, GstAllocator *allocator,
190                                                        const GstAllocationParams *params);
191 gboolean         gst_buffer_pool_config_get_allocator (GstStructure *config, GstAllocator **allocator,
192                                                        GstAllocationParams *params);
193
194 /* options */
195 guint            gst_buffer_pool_config_n_options   (GstStructure *config);
196 void             gst_buffer_pool_config_add_option  (GstStructure *config, const gchar *option);
197 const gchar *    gst_buffer_pool_config_get_option  (GstStructure *config, guint index);
198 gboolean         gst_buffer_pool_config_has_option  (GstStructure *config, const gchar *option);
199
200 /* buffer management */
201 GstFlowReturn    gst_buffer_pool_acquire_buffer  (GstBufferPool *pool, GstBuffer **buffer,
202                                                   GstBufferPoolAcquireParams *params);
203 void             gst_buffer_pool_release_buffer  (GstBufferPool *pool, GstBuffer *buffer);
204
205 G_END_DECLS
206
207 #endif /* __GST_BUFFER_POOL_H__ */