fix docs
[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/gstatomicqueue.h>
28 #include <gst/gstpoll.h>
29 #include <gst/gstclock.h>
30 #include <gst/gstpad.h>
31 #include <gst/gstbuffer.h>
32
33 G_BEGIN_DECLS
34
35 typedef struct _GstBufferPoolPrivate GstBufferPoolPrivate;
36 typedef struct _GstBufferPoolClass GstBufferPoolClass;
37
38 /**
39  * GST_BUFFER_POOL_TRACE_NAME:
40  *
41  * The name used for tracing memory allocations.
42  */
43 #define GST_BUFFER_POOL_TRACE_NAME           "GstBufferPool"
44
45 #define GST_TYPE_BUFFER_POOL                 (gst_buffer_pool_get_type())
46 #define GST_IS_BUFFER_POOL(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_BUFFER_POOL))
47 #define GST_IS_BUFFER_POOL_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_BUFFER_POOL))
48 #define GST_BUFFER_POOL_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
49 #define GST_BUFFER_POOL(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_BUFFER_POOL, GstBufferPool))
50 #define GST_BUFFER_POOL_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
51 #define GST_BUFFER_POOL_CAST(obj)            ((GstBufferPool *)(obj))
52
53 /**
54  * GstBufferPoolFlags:
55  * @GST_BUFFER_POOL_FLAG_NONE: no flags
56  * @GST_BUFFER_POOL_FLAG_KEY_UNIT: buffer is keyframe
57  * @GST_BUFFER_POOL_FLAG_DONTWAIT: don't wait for buffer. This makes the
58  * acquire_buffer method return GST_FLOW_UNEXPECTED.
59  * @GST_BUFFER_POOL_FLAG_DISCONT: buffer is discont
60  * @GST_BUFFER_POOL_FLAG_LAST: last flag, subclasses can use private flags
61  *    starting from this value.
62  *
63  * Additional flags to control the allocation of a buffer
64  */
65 typedef enum {
66   GST_BUFFER_POOL_FLAG_NONE     = 0,
67   GST_BUFFER_POOL_FLAG_KEY_UNIT = (1 << 0),
68   GST_BUFFER_POOL_FLAG_DONTWAIT = (1 << 1),
69   GST_BUFFER_POOL_FLAG_DISCONT  = (1 << 2),
70   GST_BUFFER_POOL_FLAG_LAST     = (1 << 16),
71 } GstBufferPoolFlags;
72
73 /**
74  * GstBufferPoolParams:
75  * @format: the format of @start and @stop
76  * @start: the start position
77  * @stop: the stop position
78  * @flags: additional flags
79  *
80  * Parameters passed to the gst_buffer_pool_acquire_buffer() function to control the
81  * allocation of the buffer.
82  *
83  * The default implementation ignores the @start and @stop members but other
84  * implementations can use this extra information to decide what buffer to
85  * return.
86  */
87 typedef struct _GstBufferPoolParams {
88   GstFormat          format;
89   gint64             start;
90   gint64             stop;
91   GstBufferPoolFlags flags;
92
93   /*< private >*/
94   gpointer _gst_reserved[GST_PADDING];
95 } GstBufferPoolParams;
96
97 /**
98  * GST_BUFFER_POOL_IS_FLUSHING:
99  * @pool: a GstBufferPool
100  *
101  * Check if the bufferpool is flushing. Subclasses might want to check the
102  * state of the pool in the acquire function.
103  */
104 #define GST_BUFFER_POOL_IS_FLUSHING(pool)  (g_atomic_int_get (&pool->flushing))
105
106 /**
107  * GstBufferPool:
108  * @object: the parent structure
109  *
110  * The structure of a #GstBufferPool. Use the associated macros to access the public
111  * variables.
112  */
113 struct _GstBufferPool {
114   GstObject            object;
115
116   /*< private >*/
117   gboolean             active;
118   gboolean             flushing;
119   gboolean             started;
120   gint                 outstanding;
121   GstAtomicQueue      *queue;
122   GstPoll             *poll;
123
124   gboolean             configured;
125   GstStructure        *config;
126
127   GstBufferPoolPrivate *priv;
128
129   gpointer _gst_reserved[GST_PADDING];
130 };
131
132 /**
133  * GstBufferPoolClass:
134  * @object_class:  Object parent class
135  * @get_options: get a list of options supported by this pool
136  * @set_config: apply the bufferpool configuration. The default configuration
137  *              will parse the default config parameters
138  * @start: start the bufferpool. The default implementation will preallocate
139  *         min-buffers buffers and put them in the queue
140  * @stop: stop the bufferpool. the default implementation will free the
141  *        preallocated buffers. This function is called when all the buffers are
142  *        returned to the pool.
143  * @acquire_buffer: get a new buffer from the pool. The default implementation
144  *        will take a buffer from the queue and optionally wait for a buffer to
145  *        be released when there are no buffers available.
146  * @alloc_buffer: allocate a buffer. the default implementation allocates
147  *        buffers from the default memory allocator and with the configured
148  *        size, prefix and alignment.
149  * @reset_buffer: reset the buffer to its state when it was freshly allocated.
150  *        The default implementation will clear the flags and timestamps.
151  * @release_buffer: release a buffer back in the pool. The default
152  *        implementation will put the buffer back in the queue and notify any
153  *        blocking acquire_buffer calls.
154  * @free_buffer: free a buffer. The default implementation unrefs the buffer.
155  *
156  * The GstBufferPool class.
157  */
158 struct _GstBufferPoolClass {
159   GstObjectClass    object_class;
160
161   /* vmethods */
162   const gchar ** (*get_options)    (GstBufferPool *pool);
163   gboolean       (*set_config)     (GstBufferPool *pool, GstStructure *config);
164
165   gboolean       (*start)          (GstBufferPool *pool);
166   gboolean       (*stop)           (GstBufferPool *pool);
167
168   GstFlowReturn  (*acquire_buffer) (GstBufferPool *pool, GstBuffer **buffer,
169                                     GstBufferPoolParams *params);
170   GstFlowReturn  (*alloc_buffer)   (GstBufferPool *pool, GstBuffer **buffer,
171                                     GstBufferPoolParams *params);
172   void           (*reset_buffer)   (GstBufferPool *pool, GstBuffer *buffer,
173                                     GstBufferPoolParams *params);
174   void           (*release_buffer) (GstBufferPool *pool, GstBuffer *buffer);
175   void           (*free_buffer)    (GstBufferPool *pool, GstBuffer *buffer);
176
177   /*< private >*/
178   gpointer _gst_reserved[GST_PADDING];
179 };
180
181 GType       gst_buffer_pool_get_type (void);
182
183 /* allocation */
184 GstBufferPool *  gst_buffer_pool_new  (void);
185
186 /* state management */
187 gboolean         gst_buffer_pool_set_active      (GstBufferPool *pool, gboolean active);
188 gboolean         gst_buffer_pool_is_active       (GstBufferPool *pool);
189
190 gboolean         gst_buffer_pool_set_config      (GstBufferPool *pool, GstStructure *config);
191 GstStructure *   gst_buffer_pool_get_config      (GstBufferPool *pool);
192
193 const gchar **   gst_buffer_pool_get_options     (GstBufferPool *pool);
194 gboolean         gst_buffer_pool_has_option      (GstBufferPool *pool, const gchar *option);
195
196 /* helpers for configuring the config structure */
197 void             gst_buffer_pool_config_set      (GstStructure *config, const GstCaps *caps,
198                                                   guint size, guint min_buffers, guint max_buffers,
199                                                   guint prefix, guint align);
200 gboolean         gst_buffer_pool_config_get      (GstStructure *config, const GstCaps **caps,
201                                                   guint *size, guint *min_buffers, guint *max_buffers,
202                                                   guint *prefix, guint *align);
203
204 /* options */
205 guint            gst_buffer_pool_config_n_options   (GstStructure *config);
206 void             gst_buffer_pool_config_add_option  (GstStructure *config, const gchar *option);
207 const gchar *    gst_buffer_pool_config_get_option  (GstStructure *config, guint index);
208 gboolean         gst_buffer_pool_config_has_option  (GstStructure *config, const gchar *option);
209
210 /* buffer management */
211 GstFlowReturn    gst_buffer_pool_acquire_buffer  (GstBufferPool *pool, GstBuffer **buffer,
212                                                   GstBufferPoolParams *params);
213 void             gst_buffer_pool_release_buffer  (GstBufferPool *pool, GstBuffer *buffer);
214
215 G_END_DECLS
216
217 #endif /* __GST_BUFFER_POOL_H__ */