gstbufferpool.h 9.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* GStreamer
 * Copyright (C) 2010 Wim Taymans <wim.taymans@gmail.com>
 *
 * gstbufferpool.h: Header for GstBufferPool object
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
18 19
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
20 21 22 23 24 25 26 27 28 29 30 31
 */


#ifndef __GST_BUFFER_POOL_H__
#define __GST_BUFFER_POOL_H__

#include <gst/gstminiobject.h>
#include <gst/gstpad.h>
#include <gst/gstbuffer.h>

G_BEGIN_DECLS

32
typedef struct _GstBufferPoolPrivate GstBufferPoolPrivate;
33 34 35 36 37 38 39 40 41 42 43
typedef struct _GstBufferPoolClass GstBufferPoolClass;

#define GST_TYPE_BUFFER_POOL                 (gst_buffer_pool_get_type())
#define GST_IS_BUFFER_POOL(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_BUFFER_POOL))
#define GST_IS_BUFFER_POOL_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_BUFFER_POOL))
#define GST_BUFFER_POOL_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
#define GST_BUFFER_POOL(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_BUFFER_POOL, GstBufferPool))
#define GST_BUFFER_POOL_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_BUFFER_POOL, GstBufferPoolClass))
#define GST_BUFFER_POOL_CAST(obj)            ((GstBufferPool *)(obj))

/**
44 45 46
 * GstBufferPoolAcquireFlags:
 * @GST_BUFFER_POOL_ACQUIRE_FLAG_NONE: no flags
 * @GST_BUFFER_POOL_ACQUIRE_FLAG_KEY_UNIT: buffer is keyframe
Wim Taymans's avatar
Wim Taymans committed
47 48 49
 * @GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT: when the bufferpool is empty, acquire_buffer
 * will by default block until a buffer is released into the pool again. Setting
 * this flag makes acquire_buffer return #GST_FLOW_EOS instead of blocking.
50 51
 * @GST_BUFFER_POOL_ACQUIRE_FLAG_DISCONT: buffer is discont
 * @GST_BUFFER_POOL_ACQUIRE_FLAG_LAST: last flag, subclasses can use private flags
Wim Taymans's avatar
Wim Taymans committed
52
 *    starting from this value.
53 54 55 56
 *
 * Additional flags to control the allocation of a buffer
 */
typedef enum {
57 58 59 60 61 62
  GST_BUFFER_POOL_ACQUIRE_FLAG_NONE     = 0,
  GST_BUFFER_POOL_ACQUIRE_FLAG_KEY_UNIT = (1 << 0),
  GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT = (1 << 1),
  GST_BUFFER_POOL_ACQUIRE_FLAG_DISCONT  = (1 << 2),
  GST_BUFFER_POOL_ACQUIRE_FLAG_LAST     = (1 << 16),
} GstBufferPoolAcquireFlags;
63

64 65
typedef struct _GstBufferPoolAcquireParams GstBufferPoolAcquireParams;

66
/**
67
 * GstBufferPoolAcquireParams:
68 69 70 71 72 73 74
 * @format: the format of @start and @stop
 * @start: the start position
 * @stop: the stop position
 * @flags: additional flags
 *
 * Parameters passed to the gst_buffer_pool_acquire_buffer() function to control the
 * allocation of the buffer.
75 76 77 78
 *
 * The default implementation ignores the @start and @stop members but other
 * implementations can use this extra information to decide what buffer to
 * return.
79
 */
80
struct _GstBufferPoolAcquireParams {
81 82 83 84
  GstFormat                 format;
  gint64                    start;
  gint64                    stop;
  GstBufferPoolAcquireFlags flags;
Wim Taymans's avatar
Wim Taymans committed
85

Wim Taymans's avatar
Wim Taymans committed
86
  /*< private >*/
Wim Taymans's avatar
Wim Taymans committed
87
  gpointer _gst_reserved[GST_PADDING];
88
};
89

90 91 92 93 94 95 96 97 98
/**
 * GST_BUFFER_POOL_IS_FLUSHING:
 * @pool: a GstBufferPool
 *
 * Check if the bufferpool is flushing. Subclasses might want to check the
 * state of the pool in the acquire function.
 */
#define GST_BUFFER_POOL_IS_FLUSHING(pool)  (g_atomic_int_get (&pool->flushing))

99 100 101 102 103 104 105 106 107
/**
 * GstBufferPool:
 *
 * The structure of a #GstBufferPool. Use the associated macros to access the public
 * variables.
 */
struct _GstBufferPool {
  GstObject            object;

108 109
  /*< protected >*/
  gint                 flushing;
110

111
  /*< private >*/
112
  GstBufferPoolPrivate *priv;
113 114 115 116

  gpointer _gst_reserved[GST_PADDING];
};

117 118 119
/**
 * GstBufferPoolClass:
 * @object_class:  Object parent class
120
 * @get_options: get a list of options supported by this pool
121 122 123 124 125 126 127 128 129 130 131
 * @set_config: apply the bufferpool configuration. The default configuration
 *              will parse the default config parameters
 * @start: start the bufferpool. The default implementation will preallocate
 *         min-buffers buffers and put them in the queue
 * @stop: stop the bufferpool. the default implementation will free the
 *        preallocated buffers. This function is called when all the buffers are
 *        returned to the pool.
 * @acquire_buffer: get a new buffer from the pool. The default implementation
 *        will take a buffer from the queue and optionally wait for a buffer to
 *        be released when there are no buffers available.
 * @alloc_buffer: allocate a buffer. the default implementation allocates
Wim Taymans's avatar
Wim Taymans committed
132 133
 *        buffers from the configured memory allocator and with the configured
 *        parameters. All metadata that is present on the allocated buffer will
Wim Taymans's avatar
Wim Taymans committed
134
 *        be marked as #GST_META_FLAG_POOLED and #GST_META_FLAG_LOCKED and will
135 136
 *        not be removed from the buffer in @reset_buffer. The buffer should
 *        have the GST_BUFFER_FLAG_TAG_MEMORY cleared.
137
 * @reset_buffer: reset the buffer to its state when it was freshly allocated.
138
 *        The default implementation will clear the flags, timestamps and
Wim Taymans's avatar
Wim Taymans committed
139
 *        will remove the metadata without the #GST_META_FLAG_POOLED flag (even
140
 *        the metadata with #GST_META_FLAG_LOCKED). If the
141 142
 *        #GST_BUFFER_FLAG_TAG_MEMORY was set, this function can also try to
 *        restore the memory and clear the #GST_BUFFER_FLAG_TAG_MEMORY again.
143 144
 * @release_buffer: release a buffer back in the pool. The default
 *        implementation will put the buffer back in the queue and notify any
145
 *        blocking acquire_buffer calls when the #GST_BUFFER_FLAG_TAG_MEMORY
146
 *        is not set on the buffer. If #GST_BUFFER_FLAG_TAG_MEMORY is set, the
147
 *        buffer will be freed with @free_buffer.
148
 * @free_buffer: free a buffer. The default implementation unrefs the buffer.
Nicolas Dufresne's avatar
Nicolas Dufresne committed
149 150
 * @flush_start: enter the flushing state. (Since 1.4)
 * @flush_stop: leave the flushign state. (Since 1.4)
151 152 153
 *
 * The GstBufferPool class.
 */
154 155 156
struct _GstBufferPoolClass {
  GstObjectClass    object_class;

157
  /*< public >*/
158
  const gchar ** (*get_options)    (GstBufferPool *pool);
159
  gboolean       (*set_config)     (GstBufferPool *pool, GstStructure *config);
160

161 162 163
  gboolean       (*start)          (GstBufferPool *pool);
  gboolean       (*stop)           (GstBufferPool *pool);

164
  GstFlowReturn  (*acquire_buffer) (GstBufferPool *pool, GstBuffer **buffer,
165
                                    GstBufferPoolAcquireParams *params);
166
  GstFlowReturn  (*alloc_buffer)   (GstBufferPool *pool, GstBuffer **buffer,
167
                                    GstBufferPoolAcquireParams *params);
168
  void           (*reset_buffer)   (GstBufferPool *pool, GstBuffer *buffer);
169 170
  void           (*release_buffer) (GstBufferPool *pool, GstBuffer *buffer);
  void           (*free_buffer)    (GstBufferPool *pool, GstBuffer *buffer);
171 172
  void           (*flush_start)    (GstBufferPool *pool);
  void           (*flush_stop)     (GstBufferPool *pool);
173

Wim Taymans's avatar
Wim Taymans committed
174
  /*< private >*/
175
  gpointer _gst_reserved[GST_PADDING - 2];
176 177 178 179 180
};

GType       gst_buffer_pool_get_type (void);

/* allocation */
181
GstBufferPool *  gst_buffer_pool_new  (void);
182 183

/* state management */
184
gboolean         gst_buffer_pool_set_active      (GstBufferPool *pool, gboolean active);
185
gboolean         gst_buffer_pool_is_active       (GstBufferPool *pool);
186

187 188 189
gboolean         gst_buffer_pool_set_config      (GstBufferPool *pool, GstStructure *config);
GstStructure *   gst_buffer_pool_get_config      (GstBufferPool *pool);

190
const gchar **   gst_buffer_pool_get_options     (GstBufferPool *pool);
191
gboolean         gst_buffer_pool_has_option      (GstBufferPool *pool, const gchar *option);
192

193
void             gst_buffer_pool_set_flushing    (GstBufferPool *pool, gboolean flushing);
194

195
/* helpers for configuring the config structure */
196
void             gst_buffer_pool_config_set_params    (GstStructure *config, GstCaps *caps,
197
                                                       guint size, guint min_buffers, guint max_buffers);
198
gboolean         gst_buffer_pool_config_get_params    (GstStructure *config, GstCaps **caps,
199 200 201 202 203
                                                       guint *size, guint *min_buffers, guint *max_buffers);
void             gst_buffer_pool_config_set_allocator (GstStructure *config, GstAllocator *allocator,
                                                       const GstAllocationParams *params);
gboolean         gst_buffer_pool_config_get_allocator (GstStructure *config, GstAllocator **allocator,
                                                       GstAllocationParams *params);
204

205 206 207 208 209
/* options */
guint            gst_buffer_pool_config_n_options   (GstStructure *config);
void             gst_buffer_pool_config_add_option  (GstStructure *config, const gchar *option);
const gchar *    gst_buffer_pool_config_get_option  (GstStructure *config, guint index);
gboolean         gst_buffer_pool_config_has_option  (GstStructure *config, const gchar *option);
210 211
gboolean         gst_buffer_pool_config_validate_params (GstStructure *config, GstCaps *caps,
                                                         guint size, guint min_buffers, guint max_buffers);
212 213

/* buffer management */
214
GstFlowReturn    gst_buffer_pool_acquire_buffer  (GstBufferPool *pool, GstBuffer **buffer,
215
                                                  GstBufferPoolAcquireParams *params);
216
void             gst_buffer_pool_release_buffer  (GstBufferPool *pool, GstBuffer *buffer);
217 218 219 220

G_END_DECLS

#endif /* __GST_BUFFER_POOL_H__ */