Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / gst / gstbufferlist.h
1 /* GStreamer
2  * Copyright (C) 2009 Axis Communications <dev-gstreamer at axis dot com>
3  * @author Jonas Holmberg <jonas dot holmberg at axis dot com>
4  *
5  * gstbufferlist.h: Header for GstBufferList object
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifndef __GST_BUFFER_LIST_H__
24 #define __GST_BUFFER_LIST_H__
25
26 #include <gst/gstbuffer.h>
27
28 G_BEGIN_DECLS
29
30 extern GType _gst_buffer_list_type;
31
32 #define GST_TYPE_BUFFER_LIST      (_gst_buffer_list_type)
33 #define GST_IS_BUFFER_LIST(obj)   (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_BUFFER_LIST))
34 #define GST_BUFFER_LIST_CAST(obj) ((GstBufferList *)obj)
35 #define GST_BUFFER_LIST(obj)      (GST_BUFFER_LIST_CAST(obj))
36
37 typedef struct _GstBufferList GstBufferList;
38 typedef struct _GstBufferListIterator GstBufferListIterator;
39
40 /**
41  * GstBufferListDoFunction:
42  * @buffer: (transfer full): the #GstBuffer
43  * @user_data: user data
44  *
45  * A function for accessing the last buffer returned by
46  * gst_buffer_list_iterator_next(). The function can leave @buffer in the list,
47  * replace @buffer in the list or remove @buffer from the list, depending on
48  * the return value. If the function returns NULL, @buffer will be removed from
49  * the list, otherwise @buffer will be replaced with the returned buffer.
50  *
51  * The last buffer returned by gst_buffer_list_iterator_next() will be replaced
52  * with the buffer returned from the function. The function takes ownership of
53  * @buffer and if a different value than @buffer is returned, @buffer must be
54  * unreffed. If NULL is returned, the buffer will be removed from the list. The
55  * list must be writable.
56  *
57  * Returns: (transfer full): the buffer to replace @buffer in the list, or NULL
58  *     to remove @buffer from the list
59  *
60  * Since: 0.10.24
61  */
62 typedef GstBuffer* (*GstBufferListDoFunction) (GstBuffer * buffer, gpointer user_data);
63
64 /**
65  * GstBufferListItem:
66  * @GST_BUFFER_LIST_CONTINUE:   Retrieve next buffer
67  * @GST_BUFFER_LIST_SKIP_GROUP: Skip to next group
68  * @GST_BUFFER_LIST_END:        End iteration
69  *
70  * The result of the #GstBufferListFunc.
71  *
72  * Since: 0.10.24
73  */
74 typedef enum {
75   GST_BUFFER_LIST_CONTINUE,
76   GST_BUFFER_LIST_SKIP_GROUP,
77   GST_BUFFER_LIST_END
78 } GstBufferListItem;
79
80 /**
81  * GstBufferListFunc:
82  * @buffer: pointer the buffer
83  * @group: the group index of @buffer
84  * @idx: the index in @group of @buffer
85  * @user_data: user data passed to gst_buffer_list_foreach()
86  *
87  * A function that will be called from gst_buffer_list_foreach(). The @buffer
88  * field will point to a the reference of the buffer at @idx in @group.
89  *
90  * When this function returns #GST_BUFFER_LIST_CONTINUE, the next buffer will be
91  * returned. When #GST_BUFFER_LIST_SKIP_GROUP is returned, all remaining buffers
92  * in the current group will be skipped and the first buffer of the next group
93  * is returned (if any). When GST_BUFFER_LIST_END is returned,
94  * gst_buffer_list_foreach() will return.
95  *
96  * When @buffer is set to NULL, the item will be removed from the bufferlist.
97  * When @buffer has been made writable, the new buffer reference can be assigned
98  * to @buffer. This function is responsible for unreffing the old buffer when
99  * removing or modifying.
100  *
101  * Returns: a #GstBufferListItem
102  *
103  * Since: 0.10.24
104  */
105 typedef GstBufferListItem (*GstBufferListFunc)   (GstBuffer **buffer, guint group, guint idx,
106                                                   gpointer user_data);
107
108
109 /* allocation */
110 GstBufferList *gst_buffer_list_new (void);
111
112 /* refcounting */
113 /**
114  * gst_buffer_list_ref:
115  * @list: a #GstBufferList
116  *
117  * Increases the refcount of the given buffer list by one.
118  *
119  * Note that the refcount affects the writeability of @list and its data, see
120  * gst_buffer_list_make_writable(). It is important to note that keeping
121  * additional references to GstBufferList instances can potentially increase
122  * the number of memcpy operations in a pipeline.
123  *
124  * Returns: (transfer full): @list
125  *
126  * Since: 0.10.24
127  */
128 #ifdef _FOOL_GTK_DOC_
129 G_INLINE_FUNC GstBufferList * gst_buffer_list_ref (GstBufferList * list);
130 #endif
131
132 static inline GstBufferList *
133 gst_buffer_list_ref (GstBufferList * list)
134 {
135   return GST_BUFFER_LIST_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (
136       list)));
137 }
138
139 /**
140  * gst_buffer_list_unref:
141  * @list: (transfer full): a #GstBufferList
142  *
143  * Decreases the refcount of the buffer list. If the refcount reaches 0, the
144  * buffer list will be freed.
145  *
146  * Since: 0.10.24
147  */
148 #ifdef _FOOL_GTK_DOC_
149 G_INLINE_FUNC void gst_buffer_list_unref (GstBufferList * list);
150 #endif
151
152 static inline void
153 gst_buffer_list_unref (GstBufferList * list)
154 {
155   gst_mini_object_unref (GST_MINI_OBJECT_CAST (list));
156 }
157
158 /* copy */
159 /**
160  * gst_buffer_list_copy:
161  * @list: a #GstBufferList
162  *
163  * Create a shallow copy of the given buffer list. This will make a newly
164  * allocated copy of the source list with copies of buffer pointers. The
165  * refcount of buffers pointed to will be increased by one.
166  *
167  * Returns: (transfer full): a new copy of @list.
168  *
169  * Since: 0.10.24
170  */
171 #ifdef _FOOL_GTK_DOC_
172 G_INLINE_FUNC GstBufferList * gst_buffer_list_copy (const GstBufferList * list);
173 #endif
174
175 static inline GstBufferList *
176 gst_buffer_list_copy (const GstBufferList * list)
177 {
178   return GST_BUFFER_LIST_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (list)));
179 }
180
181 /**
182  * gst_buffer_list_is_writable:
183  * @list: a #GstBufferList
184  *
185  * Tests if you can safely add buffers and groups into a buffer list.
186  *
187  * Since: 0.10.24
188  */
189 #define gst_buffer_list_is_writable(list) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (list))
190
191 /**
192  * gst_buffer_list_make_writable:
193  * @list: (transfer full): a #GstBufferList
194  *
195  * Makes a writable buffer list from the given buffer list. If the source buffer
196  * list is already writable, this will simply return the same buffer list. A
197  * copy will otherwise be made using gst_buffer_list_copy().
198  *
199  * Returns: (transfer full): a writable list, which may or may not be the
200  *     same as @list
201  *
202  * Since: 0.10.24
203  */
204 #define gst_buffer_list_make_writable(list) GST_BUFFER_LIST_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (list)))
205
206 guint                    gst_buffer_list_n_groups              (GstBufferList *list);
207
208 void                     gst_buffer_list_foreach               (GstBufferList *list,
209                                                                 GstBufferListFunc func,
210                                                                 gpointer user_data);
211 GstBuffer *              gst_buffer_list_get                   (GstBufferList *list, guint group, guint idx);
212
213 /* iterator */
214 GstBufferListIterator *  gst_buffer_list_iterate               (GstBufferList *list);
215 void                     gst_buffer_list_iterator_free         (GstBufferListIterator *it);
216
217 guint                    gst_buffer_list_iterator_n_buffers    (const GstBufferListIterator *it);
218 GstBuffer *              gst_buffer_list_iterator_next         (GstBufferListIterator *it);
219 gboolean                 gst_buffer_list_iterator_next_group   (GstBufferListIterator *it);
220
221 void                     gst_buffer_list_iterator_add          (GstBufferListIterator *it, GstBuffer *buffer);
222 void                     gst_buffer_list_iterator_add_list     (GstBufferListIterator *it, GList *list);
223 void                     gst_buffer_list_iterator_add_group    (GstBufferListIterator *it);
224 void                     gst_buffer_list_iterator_remove       (GstBufferListIterator *it);
225 GstBuffer *              gst_buffer_list_iterator_steal        (GstBufferListIterator *it);
226 void                     gst_buffer_list_iterator_take         (GstBufferListIterator *it, GstBuffer *buffer);
227
228 GstBuffer *              gst_buffer_list_iterator_do           (GstBufferListIterator *it, GstBufferListDoFunction do_func,
229                                                                 gpointer user_data);
230
231 /* conversion */
232 GstBuffer *              gst_buffer_list_iterator_merge_group  (const GstBufferListIterator *it);
233
234 G_END_DECLS
235
236 #endif /* __GST_BUFFER_LIST_H__ */