2 * Copyright (C) 2009 Axis Communications <dev-gstreamer at axis dot com>
3 * @author Jonas Holmberg <jonas dot holmberg at axis dot com>
5 * gstbufferlist.h: Header for GstBufferList 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.
23 #ifndef __GST_BUFFER_LIST_H__
24 #define __GST_BUFFER_LIST_H__
26 #include <gst/gstbuffer.h>
30 #define GST_TYPE_BUFFER_LIST (gst_buffer_list_get_type ())
31 #define GST_IS_BUFFER_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_BUFFER_LIST))
32 #define GST_IS_BUFFER_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_BUFFER_LIST))
33 #define GST_BUFFER_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BUFFER_LIST, GstBufferListClass))
34 #define GST_BUFFER_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_BUFFER_LIST, GstBufferList))
35 #define GST_BUFFER_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_BUFFER_LIST, GstBufferListClass))
36 #define GST_BUFFER_LIST_CAST(obj) ((GstBufferList *)obj)
38 typedef struct _GstBufferList GstBufferList;
39 typedef struct _GstBufferListClass GstBufferListClass;
40 typedef struct _GstBufferListIterator GstBufferListIterator;
43 * GstBufferListDoFunction:
44 * @buffer: (transfer full): the #GstBuffer
45 * @user_data: user data
47 * A function for accessing the last buffer returned by
48 * gst_buffer_list_iterator_next(). The function can leave @buffer in the list,
49 * replace @buffer in the list or remove @buffer from the list, depending on
50 * the return value. If the function returns NULL, @buffer will be removed from
51 * the list, otherwise @buffer will be replaced with the returned buffer.
53 * The last buffer returned by gst_buffer_list_iterator_next() will be replaced
54 * with the buffer returned from the function. The function takes ownership of
55 * @buffer and if a different value than @buffer is returned, @buffer must be
56 * unreffed. If NULL is returned, the buffer will be removed from the list. The
57 * list must be writable.
59 * Returns: (transfer full): the buffer to replace @buffer in the list, or NULL
60 * to remove @buffer from the list
64 typedef GstBuffer* (*GstBufferListDoFunction) (GstBuffer * buffer, gpointer user_data);
68 * @GST_BUFFER_LIST_CONTINUE: Retrieve next buffer
69 * @GST_BUFFER_LIST_SKIP_GROUP: Skip to next group
70 * @GST_BUFFER_LIST_END: End iteration
72 * The result of the #GstBufferListFunc.
77 GST_BUFFER_LIST_CONTINUE,
78 GST_BUFFER_LIST_SKIP_GROUP,
84 * @buffer: pointer the buffer
85 * @group: the group index of @buffer
86 * @idx: the index in @group of @buffer
87 * @user_data: user data passed to gst_buffer_list_foreach()
89 * A function that will be called from gst_buffer_list_foreach(). The @buffer
90 * field will point to a the reference of the buffer at @idx in @group.
92 * When this function returns #GST_BUFFER_LIST_CONTINUE, the next buffer will be
93 * returned. When #GST_BUFFER_LIST_SKIP_GROUP is returned, all remaining buffers
94 * in the current group will be skipped and the first buffer of the next group
95 * is returned (if any). When GST_BUFFER_LIST_END is returned,
96 * gst_buffer_list_foreach() will return.
98 * When @buffer is set to NULL, the item will be removed from the bufferlist.
99 * When @buffer has been made writable, the new buffer reference can be assigned
100 * to @buffer. This function is responsible for unreffing the old buffer when
101 * removing or modifying.
103 * Returns: a #GstBufferListItem
107 typedef GstBufferListItem (*GstBufferListFunc) (GstBuffer **buffer, guint group, guint idx,
111 GType gst_buffer_list_get_type (void);
114 GstBufferList *gst_buffer_list_new (void);
118 * gst_buffer_list_ref:
119 * @list: a #GstBufferList
121 * Increases the refcount of the given buffer list by one.
123 * Note that the refcount affects the writeability of @list and its data, see
124 * gst_buffer_list_make_writable(). It is important to note that keeping
125 * additional references to GstBufferList instances can potentially increase
126 * the number of memcpy operations in a pipeline.
128 * Returns: (transfer full): @list
132 #ifdef _FOOL_GTK_DOC_
133 G_INLINE_FUNC GstBufferList * gst_buffer_list_ref (GstBufferList * list);
136 static inline GstBufferList *
137 gst_buffer_list_ref (GstBufferList * list)
139 return GST_BUFFER_LIST_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (
144 * gst_buffer_list_unref:
145 * @list: (transfer full): a #GstBufferList
147 * Decreases the refcount of the buffer list. If the refcount reaches 0, the
148 * buffer list will be freed.
152 #ifdef _FOOL_GTK_DOC_
153 G_INLINE_FUNC void gst_buffer_list_unref (GstBufferList * list);
157 gst_buffer_list_unref (GstBufferList * list)
159 gst_mini_object_unref (GST_MINI_OBJECT_CAST (list));
164 * gst_buffer_list_copy:
165 * @list: a #GstBufferList
167 * Create a shallow copy of the given buffer list. This will make a newly
168 * allocated copy of the source list with copies of buffer pointers. The
169 * refcount of buffers pointed to will be increased by one.
171 * Returns: (transfer full): a new copy of @list.
175 #ifdef _FOOL_GTK_DOC_
176 G_INLINE_FUNC GstBufferList * gst_buffer_list_copy (const GstBufferList * list);
179 static inline GstBufferList *
180 gst_buffer_list_copy (const GstBufferList * list)
182 return GST_BUFFER_LIST_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (list)));
186 * gst_buffer_list_is_writable:
187 * @list: a #GstBufferList
189 * Tests if you can safely add buffers and groups into a buffer list.
193 #define gst_buffer_list_is_writable(list) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (list))
196 * gst_buffer_list_make_writable:
197 * @list: (transfer full): a #GstBufferList
199 * Makes a writable buffer list from the given buffer list. If the source buffer
200 * list is already writable, this will simply return the same buffer list. A
201 * copy will otherwise be made using gst_buffer_list_copy().
203 * Returns: (transfer full): a writable list, which may or may not be the
208 #define gst_buffer_list_make_writable(list) GST_BUFFER_LIST_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (list)))
210 guint gst_buffer_list_n_groups (GstBufferList *list);
212 void gst_buffer_list_foreach (GstBufferList *list,
213 GstBufferListFunc func,
215 GstBuffer * gst_buffer_list_get (GstBufferList *list, guint group, guint idx);
218 GstBufferListIterator * gst_buffer_list_iterate (GstBufferList *list);
219 void gst_buffer_list_iterator_free (GstBufferListIterator *it);
221 guint gst_buffer_list_iterator_n_buffers (const GstBufferListIterator *it);
222 GstBuffer * gst_buffer_list_iterator_next (GstBufferListIterator *it);
223 gboolean gst_buffer_list_iterator_next_group (GstBufferListIterator *it);
225 void gst_buffer_list_iterator_add (GstBufferListIterator *it, GstBuffer *buffer);
226 void gst_buffer_list_iterator_add_list (GstBufferListIterator *it, GList *list);
227 void gst_buffer_list_iterator_add_group (GstBufferListIterator *it);
228 void gst_buffer_list_iterator_remove (GstBufferListIterator *it);
229 GstBuffer * gst_buffer_list_iterator_steal (GstBufferListIterator *it);
230 void gst_buffer_list_iterator_take (GstBufferListIterator *it, GstBuffer *buffer);
232 GstBuffer * gst_buffer_list_iterator_do (GstBufferListIterator *it, GstBufferListDoFunction do_func,
236 GstBuffer * gst_buffer_list_iterator_merge_group (const GstBufferListIterator *it);
240 #endif /* __GST_BUFFER_LIST_H__ */