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 extern GType _gst_buffer_list_type;
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))
37 typedef struct _GstBufferList GstBufferList;
41 * @buffer: pointer the buffer
42 * @idx: the index of @buffer
43 * @user_data: user data passed to gst_buffer_list_foreach()
45 * A function that will be called from gst_buffer_list_foreach(). The @buffer
46 * field will point to a the reference of the buffer at @idx.
48 * When this function returns %TRUE, the next buffer will be
49 * returned. When %FALSE is returned, gst_buffer_list_foreach() will return.
51 * When @buffer is set to NULL, the item will be removed from the bufferlist.
52 * When @buffer has been made writable, the new buffer reference can be assigned
53 * to @buffer. This function is responsible for unreffing the old buffer when
54 * removing or modifying.
56 * Returns: %FALSE when gst_buffer_list_foreach() should stop
58 typedef gboolean (*GstBufferListFunc) (GstBuffer **buffer, guint idx,
64 * gst_buffer_list_ref:
65 * @list: a #GstBufferList
67 * Increases the refcount of the given buffer list by one.
69 * Note that the refcount affects the writeability of @list and its data, see
70 * gst_buffer_list_make_writable(). It is important to note that keeping
71 * additional references to GstBufferList instances can potentially increase
72 * the number of memcpy operations in a pipeline.
74 * Returns: (transfer full): @list
79 G_INLINE_FUNC GstBufferList * gst_buffer_list_ref (GstBufferList * list);
82 static inline GstBufferList *
83 gst_buffer_list_ref (GstBufferList * list)
85 return GST_BUFFER_LIST_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (
90 * gst_buffer_list_unref:
91 * @list: (transfer full): a #GstBufferList
93 * Decreases the refcount of the buffer list. If the refcount reaches 0, the
94 * buffer list will be freed.
99 G_INLINE_FUNC void gst_buffer_list_unref (GstBufferList * list);
103 gst_buffer_list_unref (GstBufferList * list)
105 gst_mini_object_unref (GST_MINI_OBJECT_CAST (list));
110 * gst_buffer_list_copy:
111 * @list: a #GstBufferList
113 * Create a shallow copy of the given buffer list. This will make a newly
114 * allocated copy of the source list with copies of buffer pointers. The
115 * refcount of buffers pointed to will be increased by one.
117 * Returns: (transfer full): a new copy of @list.
121 #ifdef _FOOL_GTK_DOC_
122 G_INLINE_FUNC GstBufferList * gst_buffer_list_copy (const GstBufferList * list);
125 static inline GstBufferList *
126 gst_buffer_list_copy (const GstBufferList * list)
128 return GST_BUFFER_LIST_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (list)));
132 * gst_buffer_list_is_writable:
133 * @list: a #GstBufferList
135 * Tests if you can safely add buffers and groups into a buffer list.
139 #define gst_buffer_list_is_writable(list) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (list))
142 * gst_buffer_list_make_writable:
143 * @list: (transfer full): a #GstBufferList
145 * Makes a writable buffer list from the given buffer list. If the source buffer
146 * list is already writable, this will simply return the same buffer list. A
147 * copy will otherwise be made using gst_buffer_list_copy().
149 * Returns: (transfer full): a writable list, which may or may not be the
154 #define gst_buffer_list_make_writable(list) GST_BUFFER_LIST_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (list)))
156 GType gst_buffer_list_get_type (void);
159 GstBufferList * gst_buffer_list_new (void);
160 GstBufferList * gst_buffer_list_new_sized (guint size);
162 guint gst_buffer_list_length (GstBufferList *list);
164 GstBuffer * gst_buffer_list_get (GstBufferList *list, guint idx);
165 void gst_buffer_list_insert (GstBufferList *list, guint idx, GstBuffer *buffer);
166 void gst_buffer_list_remove (GstBufferList *list, guint idx, guint length);
168 void gst_buffer_list_foreach (GstBufferList *list,
169 GstBufferListFunc func,
172 #define gst_buffer_list_add(l,b) gst_buffer_list_insert((l),-1,(b));
176 #endif /* __GST_BUFFER_LIST_H__ */