bufferpool: add macro to check for flushing
[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
58  * @GST_BUFFER_POOL_FLAG_DISCONT: buffer is discont
59  *
60  * Additional flags to control the allocation of a buffer
61  */
62 typedef enum {
63   GST_BUFFER_POOL_FLAG_NONE     = 0,
64   GST_BUFFER_POOL_FLAG_KEY_UNIT = (1 << 0),
65   GST_BUFFER_POOL_FLAG_DONTWAIT = (1 << 1),
66   GST_BUFFER_POOL_FLAG_DISCONT  = (1 << 2),
67   GST_BUFFER_POOL_FLAG_LAST     = (1 << 16),
68 } GstBufferPoolFlags;
69
70 /**
71  * GstBufferPoolParams:
72  * @format: the format of @start and @stop
73  * @start: the start position
74  * @stop: the stop position
75  * @flags: additional flags
76  *
77  * Parameters passed to the gst_buffer_pool_acquire_buffer() function to control the
78  * allocation of the buffer.
79  */
80 typedef struct _GstBufferPoolParams {
81   GstFormat          format;
82   gint64             start;
83   gint64             stop;
84   GstBufferPoolFlags flags;
85 } GstBufferPoolParams;
86
87 /**
88  * GST_BUFFER_POOL_IS_FLUSHING:
89  * @pool: a GstBufferPool
90  *
91  * Check if the bufferpool is flushing. Subclasses might want to check the
92  * state of the pool in the acquire function.
93  */
94 #define GST_BUFFER_POOL_IS_FLUSHING(pool)  (g_atomic_int_get (&pool->flushing))
95
96 /**
97  * GstBufferPool:
98  * @object: the parent structure
99  *
100  * The structure of a #GstBufferPool. Use the associated macros to access the public
101  * variables.
102  */
103 struct _GstBufferPool {
104   GstObject            object;
105
106   /*< private >*/
107   gboolean             active;
108   gboolean             flushing;
109   gboolean             started;
110   gint                 outstanding;
111   GstAtomicQueue      *queue;
112   GstPoll             *poll;
113
114   gboolean             configured;
115   GstStructure        *config;
116
117   GstBufferPoolPrivate *priv;
118
119   gpointer _gst_reserved[GST_PADDING];
120 };
121
122 struct _GstBufferPoolClass {
123   GstObjectClass    object_class;
124
125   /* vmethods */
126   const gchar ** (*get_metas)      (GstBufferPool *pool);
127   gboolean       (*set_config)     (GstBufferPool *pool, GstStructure *config);
128
129   gboolean       (*start)          (GstBufferPool *pool);
130   gboolean       (*stop)           (GstBufferPool *pool);
131
132   GstFlowReturn  (*acquire_buffer) (GstBufferPool *pool, GstBuffer **buffer,
133                                     GstBufferPoolParams *params);
134   GstFlowReturn  (*alloc_buffer)   (GstBufferPool *pool, GstBuffer **buffer,
135                                     GstBufferPoolParams *params);
136   void           (*release_buffer) (GstBufferPool *pool, GstBuffer *buffer);
137   void           (*free_buffer)    (GstBufferPool *pool, GstBuffer *buffer);
138
139   gpointer _gst_reserved[GST_PADDING];
140 };
141
142 GType       gst_buffer_pool_get_type (void);
143
144 /* allocation */
145 GstBufferPool *  gst_buffer_pool_new  (void);
146
147 /* state management */
148 gboolean         gst_buffer_pool_set_active      (GstBufferPool *pool, gboolean active);
149
150 gboolean         gst_buffer_pool_set_config      (GstBufferPool *pool, GstStructure *config);
151 GstStructure *   gst_buffer_pool_get_config      (GstBufferPool *pool);
152
153 const gchar **   gst_buffer_pool_get_metas       (GstBufferPool *pool);
154
155 /* helpers for configuring the config structure */
156 void             gst_buffer_pool_config_set      (GstStructure *config, const GstCaps *caps,
157                                                   guint size, guint min_buffers, guint max_buffers,
158                                                   guint prefix, guint align);
159 gboolean         gst_buffer_pool_config_get      (GstStructure *config, const GstCaps **caps,
160                                                   guint *size, guint *min_buffers, guint *max_buffers,
161                                                   guint *prefix, guint *align);
162
163 guint            gst_buffer_pool_config_n_metas  (GstStructure *config);
164 void             gst_buffer_pool_config_add_meta (GstStructure *config, const gchar *api);
165 const gchar *    gst_buffer_pool_config_get_meta (GstStructure *config, guint index);
166 gboolean         gst_buffer_pool_config_has_meta (GstStructure *config, const gchar *api);
167
168 /* buffer management */
169 GstFlowReturn    gst_buffer_pool_acquire_buffer  (GstBufferPool *pool, GstBuffer **buffer,
170                                                   GstBufferPoolParams *params);
171 void             gst_buffer_pool_release_buffer  (GstBufferPool *pool, GstBuffer *buffer);
172
173 G_END_DECLS
174
175 #endif /* __GST_BUFFER_POOL_H__ */