2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstbuffer.h: Header for GstBuffer object
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #ifndef __GST_BUFFER_H__
25 #define __GST_BUFFER_H__
27 #include <gst/gstdata.h>
31 typedef struct _GstBuffer GstBuffer;
32 typedef struct _GstBufferPool GstBufferPool;
34 extern GType _gst_buffer_type;
35 extern GType _gst_buffer_pool_type;
37 #define GST_TYPE_BUFFER (_gst_buffer_type)
38 #define GST_TYPE_BUFFER_POOL (_gst_buffer_pool_type)
40 #define GST_BUFFER(buf) ((GstBuffer *)(buf))
41 #define GST_BUFFER_POOL(pool) ((GstBufferPool *)(pool))
42 #define GST_IS_BUFFER(buf) (GST_DATA_TYPE(buf) == GST_TYPE_BUFFER)
43 #define GST_IS_BUFFER_POOL(buf) (GST_DATA_TYPE(buf) == GST_TYPE_BUFFER_POOL)
45 #define GST_BUFFER_REFCOUNT(buf) GST_DATA_REFCOUNT(buf)
46 #define GST_BUFFER_REFCOUNT_VALUE(buf) GST_DATA_REFCOUNT_VALUE(buf)
47 #define GST_BUFFER_COPY_FUNC(buf) GST_DATA_COPY_FUNC(buf)
48 #define GST_BUFFER_FREE_FUNC(buf) GST_DATA_FREE_FUNC(buf)
50 #define GST_BUFFER_FLAGS(buf) GST_DATA_FLAGS(buf)
51 #define GST_BUFFER_FLAG_IS_SET(buf,flag) GST_DATA_FLAG_IS_SET (buf, flag)
52 #define GST_BUFFER_FLAG_SET(buf,flag) GST_DATA_FLAG_SET (buf, flag)
53 #define GST_BUFFER_FLAG_UNSET(buf,flag) GST_DATA_FLAG_UNSET (buf, flag)
55 #define GST_BUFFER_DATA(buf) (GST_BUFFER(buf)->data)
56 #define GST_BUFFER_SIZE(buf) (GST_BUFFER(buf)->size)
57 #define GST_BUFFER_MAXSIZE(buf) (GST_BUFFER(buf)->maxsize)
58 #define GST_BUFFER_TIMESTAMP(buf) (GST_BUFFER(buf)->timestamp)
59 #define GST_BUFFER_OFFSET(buf) (GST_BUFFER(buf)->offset)
60 #define GST_BUFFER_BUFFERPOOL(buf) (GST_BUFFER(buf)->pool)
61 #define GST_BUFFER_POOL_PRIVATE(buf) (GST_BUFFER(buf)->pool_private)
64 GST_BUFFER_READONLY = GST_DATA_FLAG_LAST,
68 GST_BUFFER_DISCONTINOUS,
71 GST_BUFFER_FLAG_LAST = GST_DATA_FLAG_LAST + 8
77 /* pointer to data and its size */
78 guint8 *data; /* pointer to buffer data */
79 guint size; /* size of buffer data */
80 guint64 maxsize; /* max size of this buffer */
85 /* this is a pointer to the buffer pool (if any) */
87 /* pointer to pool private data of parent buffer in case of a subbuffer */
88 gpointer pool_private;
93 typedef GstBuffer* (*GstBufferPoolBufferNewFunction) (GstBufferPool *pool, guint64 offset, guint size, gpointer user_data);
94 typedef GstBuffer* (*GstBufferPoolBufferCopyFunction) (GstBufferPool *pool, const GstBuffer *buffer, gpointer user_data);
95 typedef void (*GstBufferPoolBufferFreeFunction) (GstBufferPool *pool, GstBuffer *buffer, gpointer user_data);
97 struct _GstBufferPool {
102 GstBufferPoolBufferNewFunction buffer_new;
103 GstBufferPoolBufferCopyFunction buffer_copy;
104 GstBufferPoolBufferFreeFunction buffer_free;
111 void _gst_buffer_initialize (void);
113 /* functions used by subclasses and bufferpools */
114 void gst_buffer_default_free (GstBuffer *buffer);
115 GstBuffer* gst_buffer_default_copy (GstBuffer *buffer);
117 void gst_buffer_print_stats (void);
120 GstBuffer* gst_buffer_new (void);
121 GstBuffer* gst_buffer_new_and_alloc (guint size);
123 /* creating a new buffer from a pool */
124 GstBuffer* gst_buffer_new_from_pool (GstBufferPool *pool, guint64 offset, guint size);
127 #define gst_buffer_ref(buf) GST_BUFFER (gst_data_ref (GST_DATA (buf)))
128 #define gst_buffer_ref_by_count(buf,c) GST_BUFFER (gst_data_ref_by_count (GST_DATA (buf), c))
129 #define gst_buffer_unref(buf) gst_data_unref (GST_DATA (buf))
131 #define gst_buffer_copy(buffer) GST_BUFFER (gst_data_copy (GST_DATA (buffer)))
132 #define gst_buffer_copy_on_write(buffer) GST_BUFFER (gst_data_copy_on_write (GST_DATA (buffer)))
133 #define gst_buffer_free(buffer) gst_data_free (GST_DATA (buffer))
135 /* creating a subbuffer */
136 GstBuffer* gst_buffer_create_sub (GstBuffer *parent, guint offset, guint size);
138 /* merge, span, or append two buffers, intelligently */
139 GstBuffer* gst_buffer_merge (GstBuffer *buf1, GstBuffer *buf2);
140 gboolean gst_buffer_is_span_fast (GstBuffer *buf1, GstBuffer *buf2);
141 GstBuffer* gst_buffer_span (GstBuffer *buf1, guint32 offset, GstBuffer *buf2, guint32 len);
144 /* creating a new buffer pools */
145 GstBufferPool* gst_buffer_pool_new (GstDataFreeFunction free,
146 GstDataCopyFunction copy,
147 GstBufferPoolBufferNewFunction buffer_new,
148 GstBufferPoolBufferCopyFunction buffer_copy,
149 GstBufferPoolBufferFreeFunction buffer_free,
152 /* function used by subclasses and bufferpools */
153 void gst_buffer_pool_default_free (GstBufferPool *pool);
155 gboolean gst_buffer_pool_is_active (GstBufferPool *pool);
156 void gst_buffer_pool_set_active (GstBufferPool *pool, gboolean active);
158 #define gst_buffer_pool_ref(pool) GST_BUFFER_POOL (gst_data_ref (GST_DATA (pool)))
159 #define gst_buffer_pool_ref_by_count(pool,c) GST_BUFFER_POOL (gst_data_ref_by_count (GST_DATA (pool), c))
160 #define gst_buffer_pool_unref(pool) gst_data_unref (GST_DATA (pool))
162 /* bufferpool operations */
163 #define gst_buffer_pool_copy(pool) GST_BUFFER_POOL (gst_data_copy (GST_DATA (pool)))
164 #define gst_buffer_pool_copy_on_write(pool) GST_BUFFER_POOL (gst_data_copy_on_write (GST_DATA (pool)))
165 #define gst_buffer_pool_free(pool) gst_data_free (GST_DATA (pool))
167 void gst_buffer_pool_set_user_data (GstBufferPool *pool, gpointer user_data);
168 gpointer gst_buffer_pool_get_user_data (GstBufferPool *pool);
171 GstBufferPool* gst_buffer_pool_get_default (guint size, guint numbuffers);
176 #endif /* __GST_BUFFER_H__ */