95559063bf6d51b7d49b7582f1bac9cd7acc6b34
[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 _GstBufferPool GstBufferPool;
36 typedef struct _GstBufferPoolPrivate GstBufferPoolPrivate;
37 typedef struct _GstBufferPoolClass GstBufferPoolClass;
38
39 /**
40  * GST_BUFFER_POOL_TRACE_NAME:
41  *
42  * The name used for tracing memory allocations.
43  */
44 #define GST_BUFFER_POOL_TRACE_NAME           "GstBufferPool"
45
46 #define GST_TYPE_BUFFER_POOL                 (gst_buffer_pool_get_type())
47 #define GST_IS_BUFFER_POOL(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_BUFFER_POOL))
48 #define GST_IS_BUFFER_POOL_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_BUFFER_POOL))
49 #define GST_BUFFER_POOL_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
50 #define GST_BUFFER_POOL(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_BUFFER_POOL, GstBufferPool))
51 #define GST_BUFFER_POOL_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
52 #define GST_BUFFER_POOL_CAST(obj)            ((GstBufferPool *)(obj))
53
54 /**
55  * GstBufferPoolFlags:
56  * @GST_BUFFER_POOL_FLAG_NONE: no flags
57  * @GST_BUFFER_POOL_FLAG_KEY_UNIT: buffer is keyframe
58  * @GST_BUFFER_POOL_FLAG_WAIT: wait for buffer
59  * @GST_BUFFER_POOL_FLAG_DISCONT: buffer is discont
60  *
61  * Additional flags to control the allocation of a buffer
62  */
63 typedef enum {
64   GST_BUFFER_POOL_FLAG_NONE     = 0,
65   GST_BUFFER_POOL_FLAG_KEY_UNIT = (1 << 0),
66   GST_BUFFER_POOL_FLAG_WAIT     = (1 << 1),
67   GST_BUFFER_POOL_FLAG_DISCONT  = (1 << 2),
68   GST_BUFFER_POOL_FLAG_LAST     = (1 << 16),
69 } GstBufferPoolFlags;
70
71 /**
72  * GstBufferPoolParams:
73  * @format: the format of @start and @stop
74  * @start: the start position
75  * @stop: the stop position
76  * @flags: additional flags
77  *
78  * Parameters passed to the gst_buffer_pool_acquire_buffer() function to control the
79  * allocation of the buffer.
80  */
81 typedef struct _GstBufferPoolParams {
82   GstFormat          format;
83   gint64             start;
84   gint64             stop;
85   GstBufferPoolFlags flags;
86 } GstBufferPoolParams;
87
88 /**
89  * GstBufferPool:
90  * @mini_object: the parent structure
91  *
92  * The structure of a #GstBufferPool. Use the associated macros to access the public
93  * variables.
94  */
95 struct _GstBufferPool {
96   GstObject            object;
97
98   /*< private >*/
99   gboolean             active;
100   GstAtomicQueue      *queue;
101   GstPoll             *poll;
102
103   GstStructure        *config;
104
105   GstBufferPoolPrivate *priv;
106
107   gpointer _gst_reserved[GST_PADDING];
108 };
109
110 struct _GstBufferPoolClass {
111   GstObjectClass    object_class;
112
113   /* vmethods */
114   void           (*set_active)     (GstBufferPool *pool, gboolean active);
115   gboolean       (*set_config)     (GstBufferPool *pool, GstStructure *config);
116
117   GstFlowReturn  (*acquire_buffer) (GstBufferPool *pool, GstBuffer **buffer,
118                                     GstBufferPoolParams *params);
119   GstFlowReturn  (*alloc_buffer)   (GstBufferPool *pool, GstBuffer **buffer,
120                                     GstBufferPoolParams *params);
121   void           (*release_buffer) (GstBufferPool *pool, GstBuffer *buffer);
122   void           (*free_buffer)    (GstBufferPool *pool, GstBuffer *buffer);
123
124   gpointer _gst_reserved[GST_PADDING];
125 };
126
127 GType       gst_buffer_pool_get_type (void);
128
129 /* allocation */
130 GstBufferPool *       gst_buffer_pool_new  (void);
131
132 /* state management */
133 void                  gst_buffer_pool_set_active      (GstBufferPool *pool, gboolean active);
134
135 gboolean              gst_buffer_pool_set_config      (GstBufferPool *pool, GstStructure *config);
136 const GstStructure *  gst_buffer_pool_get_config      (GstBufferPool *pool);
137
138 /* helpers for configuring the config structure */
139 void                  gst_buffer_pool_config_set      (GstStructure *config, guint size,
140                                                        guint min_buffers, guint max_buffers,
141                                                        guint prefix, guint postfix, guint align);
142 gboolean              gst_buffer_pool_config_get      (GstStructure *config, guint *size,
143                                                        guint *min_buffers, guint *max_buffers,
144                                                        guint *prefix, guint *postfix, guint *align);
145
146 /* buffer management */
147 GstFlowReturn         gst_buffer_pool_acquire_buffer  (GstBufferPool *pool, GstBuffer **buffer,
148                                                        GstBufferPoolParams *params);
149 void                  gst_buffer_pool_release_buffer  (GstBufferPool *pool, GstBuffer *buffer);
150
151 G_END_DECLS
152
153 #endif /* __GST_BUFFER_POOL_H__ */