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