1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gstreamer.BufferList;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gstreamer.Buffer;
30 private import gstreamer.c.functions;
31 public  import gstreamer.c.types;
32 
33 
34 /**
35  * Buffer lists are an object containing a list of buffers.
36  * 
37  * Buffer lists are created with gst_buffer_list_new() and filled with data
38  * using a gst_buffer_list_insert().
39  * 
40  * Buffer lists can be pushed on a srcpad with gst_pad_push_list(). This is
41  * interesting when multiple buffers need to be pushed in one go because it
42  * can reduce the amount of overhead for pushing each buffer individually.
43  */
44 public class BufferList
45 {
46 	/** the main Gtk struct */
47 	protected GstBufferList* gstBufferList;
48 	protected bool ownedRef;
49 
50 	/** Get the main Gtk struct */
51 	public GstBufferList* getBufferListStruct(bool transferOwnership = false)
52 	{
53 		if (transferOwnership)
54 			ownedRef = false;
55 		return gstBufferList;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected void* getStruct()
60 	{
61 		return cast(void*)gstBufferList;
62 	}
63 
64 	/**
65 	 * Sets our main struct and passes it to the parent class.
66 	 */
67 	public this (GstBufferList* gstBufferList, bool ownedRef = false)
68 	{
69 		this.gstBufferList = gstBufferList;
70 		this.ownedRef = ownedRef;
71 	}
72 
73 
74 	/** */
75 	public static GType getType()
76 	{
77 		return gst_buffer_list_get_type();
78 	}
79 
80 	/**
81 	 * Creates a new, empty #GstBufferList. The caller is responsible for unreffing
82 	 * the returned #GstBufferList.
83 	 *
84 	 * Free-function: gst_buffer_list_unref
85 	 *
86 	 * Returns: the new #GstBufferList. gst_buffer_list_unref()
87 	 *     after usage.
88 	 *
89 	 * Throws: ConstructionException GTK+ fails to create the object.
90 	 */
91 	public this()
92 	{
93 		auto __p = gst_buffer_list_new();
94 
95 		if(__p is null)
96 		{
97 			throw new ConstructionException("null returned by new");
98 		}
99 
100 		this(cast(GstBufferList*) __p);
101 	}
102 
103 	/**
104 	 * Creates a new, empty #GstBufferList. The caller is responsible for unreffing
105 	 * the returned #GstBufferList. The list will have @size space preallocated so
106 	 * that memory reallocations can be avoided.
107 	 *
108 	 * Free-function: gst_buffer_list_unref
109 	 *
110 	 * Params:
111 	 *     size = an initial reserved size
112 	 *
113 	 * Returns: the new #GstBufferList. gst_buffer_list_unref()
114 	 *     after usage.
115 	 *
116 	 * Throws: ConstructionException GTK+ fails to create the object.
117 	 */
118 	public this(uint size)
119 	{
120 		auto __p = gst_buffer_list_new_sized(size);
121 
122 		if(__p is null)
123 		{
124 			throw new ConstructionException("null returned by new_sized");
125 		}
126 
127 		this(cast(GstBufferList*) __p);
128 	}
129 
130 	/**
131 	 * Calculates the size of the data contained in buffer list by adding the
132 	 * size of all buffers.
133 	 *
134 	 * Returns: the size of the data contained in buffer list in bytes.
135 	 *
136 	 * Since: 1.14
137 	 */
138 	public size_t calculateSize()
139 	{
140 		return gst_buffer_list_calculate_size(gstBufferList);
141 	}
142 
143 	/**
144 	 * Create a copy of the given buffer list. This will make a newly allocated
145 	 * copy of the buffer that the source buffer list contains.
146 	 *
147 	 * Returns: a new copy of @list.
148 	 *
149 	 * Since: 1.6
150 	 */
151 	public BufferList copyDeep()
152 	{
153 		auto __p = gst_buffer_list_copy_deep(gstBufferList);
154 
155 		if(__p is null)
156 		{
157 			return null;
158 		}
159 
160 		return ObjectG.getDObject!(BufferList)(cast(GstBufferList*) __p, true);
161 	}
162 
163 	alias foreac = foreach_;
164 	/**
165 	 * Call @func with @data for each buffer in @list.
166 	 *
167 	 * @func can modify the passed buffer pointer or its contents. The return value
168 	 * of @func define if this function returns or if the remaining buffers in
169 	 * the list should be skipped.
170 	 *
171 	 * Params:
172 	 *     func = a #GstBufferListFunc to call
173 	 *     userData = user data passed to @func
174 	 *
175 	 * Returns: %TRUE when @func returned %TRUE for each buffer in @list or when
176 	 *     @list is empty.
177 	 */
178 	public bool foreach_(GstBufferListFunc func, void* userData)
179 	{
180 		return gst_buffer_list_foreach(gstBufferList, func, userData) != 0;
181 	}
182 
183 	/**
184 	 * Get the buffer at @idx.
185 	 *
186 	 * You must make sure that @idx does not exceed the number of
187 	 * buffers available.
188 	 *
189 	 * Params:
190 	 *     idx = the index
191 	 *
192 	 * Returns: the buffer at @idx in @group
193 	 *     or %NULL when there is no buffer. The buffer remains valid as
194 	 *     long as @list is valid and buffer is not removed from the list.
195 	 */
196 	public Buffer get(uint idx)
197 	{
198 		auto __p = gst_buffer_list_get(gstBufferList, idx);
199 
200 		if(__p is null)
201 		{
202 			return null;
203 		}
204 
205 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p);
206 	}
207 
208 	/**
209 	 * Gets the buffer at @idx, ensuring it is a writable buffer.
210 	 *
211 	 * You must make sure that @idx does not exceed the number of
212 	 * buffers available.
213 	 *
214 	 * Params:
215 	 *     idx = the index
216 	 *
217 	 * Returns: the buffer at @idx in @group.
218 	 *     The returned  buffer remains valid as long as @list is valid and
219 	 *     the buffer is not removed from the list.
220 	 *
221 	 * Since: 1.14
222 	 */
223 	public Buffer getWritable(uint idx)
224 	{
225 		auto __p = gst_buffer_list_get_writable(gstBufferList, idx);
226 
227 		if(__p is null)
228 		{
229 			return null;
230 		}
231 
232 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p);
233 	}
234 
235 	/**
236 	 * Insert @buffer at @idx in @list. Other buffers are moved to make room for
237 	 * this new buffer.
238 	 *
239 	 * A -1 value for @idx will append the buffer at the end.
240 	 *
241 	 * Params:
242 	 *     idx = the index
243 	 *     buffer = a #GstBuffer
244 	 */
245 	public void insert(int idx, Buffer buffer)
246 	{
247 		gst_buffer_list_insert(gstBufferList, idx, (buffer is null) ? null : buffer.getBufferStruct());
248 	}
249 
250 	/**
251 	 * Returns the number of buffers in @list.
252 	 *
253 	 * Returns: the number of buffers in the buffer list
254 	 */
255 	public uint length()
256 	{
257 		return gst_buffer_list_length(gstBufferList);
258 	}
259 
260 	/**
261 	 * Remove @length buffers starting from @idx in @list. The following buffers
262 	 * are moved to close the gap.
263 	 *
264 	 * Params:
265 	 *     idx = the index
266 	 *     length = the amount to remove
267 	 */
268 	public void remove(uint idx, uint length)
269 	{
270 		gst_buffer_list_remove(gstBufferList, idx, length);
271 	}
272 }