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., 51 Franklin St, Fifth Floor, |
20 | * Boston, MA 02110-1301, 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 | GST_API 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 | |
39 | /** |
40 | * GstBufferListFunc: |
41 | * @buffer: (out) (nullable): pointer the buffer |
42 | * @idx: the index of @buffer |
43 | * @user_data: user data passed to gst_buffer_list_foreach() |
44 | * |
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. |
47 | * |
48 | * When this function returns %TRUE, the next buffer will be |
49 | * returned. When %FALSE is returned, gst_buffer_list_foreach() will return. |
50 | * |
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. |
55 | * |
56 | * Returns: %FALSE when gst_buffer_list_foreach() should stop |
57 | */ |
58 | typedef gboolean (*GstBufferListFunc) (GstBuffer **buffer, guint idx, |
59 | gpointer user_data); |
60 | |
61 | |
62 | /* refcounting */ |
63 | /** |
64 | * gst_buffer_list_ref: |
65 | * @list: a #GstBufferList |
66 | * |
67 | * Increases the refcount of the given buffer list by one. |
68 | * |
69 | * Note that the refcount affects the writability 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. |
73 | * |
74 | * Returns: (transfer full): @list |
75 | */ |
76 | static inline GstBufferList * |
77 | gst_buffer_list_ref (GstBufferList * list) |
78 | { |
79 | return GST_BUFFER_LIST_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST ( |
80 | list))); |
81 | } |
82 | |
83 | /** |
84 | * gst_buffer_list_unref: |
85 | * @list: (transfer full): a #GstBufferList |
86 | * |
87 | * Decreases the refcount of the buffer list. If the refcount reaches 0, the |
88 | * buffer list will be freed. |
89 | */ |
90 | static inline void |
91 | gst_buffer_list_unref (GstBufferList * list) |
92 | { |
93 | gst_mini_object_unref (GST_MINI_OBJECT_CAST (list)); |
94 | } |
95 | |
96 | /** |
97 | * gst_clear_buffer_list: (skip) |
98 | * @list_ptr: a pointer to a #GstBufferList reference |
99 | * |
100 | * Clears a reference to a #GstBufferList. |
101 | * |
102 | * @list_ptr must not be %NULL. |
103 | * |
104 | * If the reference is %NULL then this function does nothing. Otherwise, the |
105 | * reference count of the list is decreased and the pointer is set to %NULL. |
106 | * |
107 | * Since: 1.16 |
108 | */ |
109 | static inline void |
110 | gst_clear_buffer_list (GstBufferList ** list_ptr) |
111 | { |
112 | gst_clear_mini_object ((GstMiniObject **) list_ptr); |
113 | } |
114 | |
115 | /* copy */ |
116 | /** |
117 | * gst_buffer_list_copy: |
118 | * @list: a #GstBufferList |
119 | * |
120 | * Create a shallow copy of the given buffer list. This will make a newly |
121 | * allocated copy of the source list with copies of buffer pointers. The |
122 | * refcount of buffers pointed to will be increased by one. |
123 | * |
124 | * Returns: (transfer full): a new copy of @list. |
125 | */ |
126 | static inline GstBufferList * |
127 | gst_buffer_list_copy (const GstBufferList * list) |
128 | { |
129 | return GST_BUFFER_LIST_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (list))); |
130 | } |
131 | |
132 | /** |
133 | * gst_buffer_list_replace: |
134 | * @old_list: (inout) (transfer full) (nullable): pointer to a pointer to a |
135 | * #GstBufferList to be replaced. |
136 | * @new_list: (transfer none) (allow-none): pointer to a #GstBufferList that |
137 | * will replace the buffer list pointed to by @old_list. |
138 | * |
139 | * Modifies a pointer to a #GstBufferList to point to a different |
140 | * #GstBufferList. The modification is done atomically (so this is useful for |
141 | * ensuring thread safety in some cases), and the reference counts are updated |
142 | * appropriately (the old buffer list is unreffed, the new is reffed). |
143 | * |
144 | * Either @new_list or the #GstBufferList pointed to by @old_list may be %NULL. |
145 | * |
146 | * Returns: %TRUE if @new_list was different from @old_list |
147 | * |
148 | * Since: 1.16 |
149 | */ |
150 | static inline gboolean |
151 | gst_buffer_list_replace (GstBufferList **old_list, GstBufferList *new_list) |
152 | { |
153 | return gst_mini_object_replace ((GstMiniObject **) old_list, |
154 | (GstMiniObject *) new_list); |
155 | } |
156 | |
157 | /** |
158 | * gst_buffer_list_take: |
159 | * @old_list: (inout) (transfer full): pointer to a pointer to a #GstBufferList |
160 | * to be replaced. |
161 | * @new_list: (transfer full) (allow-none): pointer to a #GstBufferList |
162 | * that will replace the bufferlist pointed to by @old_list. |
163 | * |
164 | * Modifies a pointer to a #GstBufferList to point to a different |
165 | * #GstBufferList. This function is similar to gst_buffer_list_replace() except |
166 | * that it takes ownership of @new_list. |
167 | * |
168 | * Returns: %TRUE if @new_list was different from @old_list |
169 | * |
170 | * Since: 1.16 |
171 | */ |
172 | static inline gboolean |
173 | gst_buffer_list_take (GstBufferList **old_list, GstBufferList *new_list) |
174 | { |
175 | return gst_mini_object_take ((GstMiniObject **) old_list, |
176 | (GstMiniObject *) new_list); |
177 | } |
178 | |
179 | /** |
180 | * gst_buffer_list_is_writable: |
181 | * @list: a #GstBufferList |
182 | * |
183 | * Tests if you can safely add buffers and groups into a buffer list. |
184 | */ |
185 | #define gst_buffer_list_is_writable(list) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (list)) |
186 | |
187 | /** |
188 | * gst_buffer_list_make_writable: |
189 | * @list: (transfer full): a #GstBufferList |
190 | * |
191 | * Makes a writable buffer list from the given buffer list. If the source buffer |
192 | * list is already writable, this will simply return the same buffer list. A |
193 | * copy will otherwise be made using gst_buffer_list_copy(). |
194 | * |
195 | * Returns: (transfer full): a writable list, which may or may not be the |
196 | * same as @list |
197 | */ |
198 | #define gst_buffer_list_make_writable(list) GST_BUFFER_LIST_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (list))) |
199 | |
200 | GST_API |
201 | GType gst_buffer_list_get_type (void); |
202 | |
203 | /* allocation */ |
204 | |
205 | GST_API |
206 | GstBufferList * gst_buffer_list_new (void) G_GNUC_MALLOC; |
207 | |
208 | GST_API |
209 | GstBufferList * gst_buffer_list_new_sized (guint size) G_GNUC_MALLOC; |
210 | |
211 | GST_API |
212 | guint gst_buffer_list_length (GstBufferList *list); |
213 | |
214 | GST_API |
215 | GstBuffer * gst_buffer_list_get (GstBufferList *list, guint idx); |
216 | |
217 | GST_API |
218 | GstBuffer * gst_buffer_list_get_writable (GstBufferList *list, guint idx); |
219 | |
220 | GST_API |
221 | void gst_buffer_list_insert (GstBufferList *list, gint idx, GstBuffer *buffer); |
222 | |
223 | GST_API |
224 | void gst_buffer_list_remove (GstBufferList *list, guint idx, guint length); |
225 | |
226 | GST_API |
227 | gboolean gst_buffer_list_foreach (GstBufferList *list, |
228 | GstBufferListFunc func, |
229 | gpointer user_data); |
230 | GST_API |
231 | GstBufferList * gst_buffer_list_copy_deep (const GstBufferList * list); |
232 | |
233 | GST_API |
234 | gsize gst_buffer_list_calculate_size (GstBufferList * list); |
235 | |
236 | #define gst_buffer_list_add(l,b) gst_buffer_list_insert((l),-1,(b)); |
237 | |
238 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC |
239 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstBufferList, gst_buffer_list_unref) |
240 | #endif |
241 | |
242 | G_END_DECLS |
243 | |
244 | #endif /* __GST_BUFFER_LIST_H__ */ |
245 | |