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 public  import gstreamerc.gstreamertypes;
33 
34 
35 /**
36  * Buffer lists are an object containing a list of buffers.
37  * 
38  * Buffer lists are created with gst_buffer_list_new() and filled with data
39  * using a gst_buffer_list_insert().
40  * 
41  * Buffer lists can be pushed on a srcpad with gst_pad_push_list(). This is
42  * interesting when multiple buffers need to be pushed in one go because it
43  * can reduce the amount of overhead for pushing each buffer individually.
44  */
45 public class BufferList
46 {
47 	/** the main Gtk struct */
48 	protected GstBufferList* gstBufferList;
49 	protected bool ownedRef;
50 
51 	/** Get the main Gtk struct */
52 	public GstBufferList* getBufferListStruct(bool transferOwnership = false)
53 	{
54 		if (transferOwnership)
55 			ownedRef = false;
56 		return gstBufferList;
57 	}
58 
59 	/** the main Gtk struct as a void* */
60 	protected void* getStruct()
61 	{
62 		return cast(void*)gstBufferList;
63 	}
64 
65 	/**
66 	 * Sets our main struct and passes it to the parent class.
67 	 */
68 	public this (GstBufferList* gstBufferList, bool ownedRef = false)
69 	{
70 		this.gstBufferList = gstBufferList;
71 		this.ownedRef = ownedRef;
72 	}
73 
74 
75 	/** */
76 	public static GType getType()
77 	{
78 		return gst_buffer_list_get_type();
79 	}
80 
81 	/**
82 	 * Creates a new, empty #GstBufferList. The caller is responsible for unreffing
83 	 * the returned #GstBufferList.
84 	 *
85 	 * Free-function: gst_buffer_list_unref
86 	 *
87 	 * Returns: the new #GstBufferList. gst_buffer_list_unref()
88 	 *     after usage.
89 	 *
90 	 * Throws: ConstructionException GTK+ fails to create the object.
91 	 */
92 	public this()
93 	{
94 		auto p = gst_buffer_list_new();
95 
96 		if(p is null)
97 		{
98 			throw new ConstructionException("null returned by new");
99 		}
100 
101 		this(cast(GstBufferList*) p);
102 	}
103 
104 	/**
105 	 * Creates a new, empty #GstBufferList. The caller is responsible for unreffing
106 	 * the returned #GstBufferList. The list will have @size space preallocated so
107 	 * that memory reallocations can be avoided.
108 	 *
109 	 * Free-function: gst_buffer_list_unref
110 	 *
111 	 * Params:
112 	 *     size = an initial reserved size
113 	 *
114 	 * Returns: the new #GstBufferList. gst_buffer_list_unref()
115 	 *     after usage.
116 	 *
117 	 * Throws: ConstructionException GTK+ fails to create the object.
118 	 */
119 	public this(uint size)
120 	{
121 		auto p = gst_buffer_list_new_sized(size);
122 
123 		if(p is null)
124 		{
125 			throw new ConstructionException("null returned by new_sized");
126 		}
127 
128 		this(cast(GstBufferList*) p);
129 	}
130 
131 	/**
132 	 * Calculates the size of the data contained in buffer list by adding the
133 	 * size of all buffers.
134 	 *
135 	 * Returns: the size of the data contained in buffer list in bytes.
136 	 *
137 	 * Since: 1.14
138 	 */
139 	public size_t calculateSize()
140 	{
141 		return gst_buffer_list_calculate_size(gstBufferList);
142 	}
143 
144 	/**
145 	 * Create a copy of the given buffer list. This will make a newly allocated
146 	 * copy of the buffer that the source buffer list contains.
147 	 *
148 	 * Returns: a new copy of @list.
149 	 *
150 	 * Since: 1.6
151 	 */
152 	public BufferList copyDeep()
153 	{
154 		auto p = gst_buffer_list_copy_deep(gstBufferList);
155 
156 		if(p is null)
157 		{
158 			return null;
159 		}
160 
161 		return ObjectG.getDObject!(BufferList)(cast(GstBufferList*) p, true);
162 	}
163 
164 	alias foreac = foreach_;
165 	/**
166 	 * Call @func with @data for each buffer in @list.
167 	 *
168 	 * @func can modify the passed buffer pointer or its contents. The return value
169 	 * of @func define if this function returns or if the remaining buffers in
170 	 * the list should be skipped.
171 	 *
172 	 * Params:
173 	 *     func = a #GstBufferListFunc to call
174 	 *     userData = user data passed to @func
175 	 *
176 	 * Returns: %TRUE when @func returned %TRUE for each buffer in @list or when
177 	 *     @list is empty.
178 	 */
179 	public bool foreach_(GstBufferListFunc func, void* userData)
180 	{
181 		return gst_buffer_list_foreach(gstBufferList, func, userData) != 0;
182 	}
183 
184 	/**
185 	 * Get the buffer at @idx.
186 	 *
187 	 * You must make sure that @idx does not exceed the number of
188 	 * buffers available.
189 	 *
190 	 * Params:
191 	 *     idx = the index
192 	 *
193 	 * Returns: the buffer at @idx in @group
194 	 *     or %NULL when there is no buffer. The buffer remains valid as
195 	 *     long as @list is valid and buffer is not removed from the list.
196 	 */
197 	public Buffer get(uint idx)
198 	{
199 		auto p = gst_buffer_list_get(gstBufferList, idx);
200 
201 		if(p is null)
202 		{
203 			return null;
204 		}
205 
206 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p);
207 	}
208 
209 	/**
210 	 * Gets the buffer at @idx, ensuring it is a writable buffer.
211 	 *
212 	 * You must make sure that @idx does not exceed the number of
213 	 * buffers available.
214 	 *
215 	 * Params:
216 	 *     idx = the index
217 	 *
218 	 * Returns: the buffer at @idx in @group.
219 	 *     The returned  buffer remains valid as long as @list is valid and
220 	 *     the buffer is not removed from the list.
221 	 *
222 	 * Since: 1.14
223 	 */
224 	public Buffer getWritable(uint idx)
225 	{
226 		auto p = gst_buffer_list_get_writable(gstBufferList, idx);
227 
228 		if(p is null)
229 		{
230 			return null;
231 		}
232 
233 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p);
234 	}
235 
236 	/**
237 	 * Insert @buffer at @idx in @list. Other buffers are moved to make room for
238 	 * this new buffer.
239 	 *
240 	 * A -1 value for @idx will append the buffer at the end.
241 	 *
242 	 * Params:
243 	 *     idx = the index
244 	 *     buffer = a #GstBuffer
245 	 */
246 	public void insert(int idx, Buffer buffer)
247 	{
248 		gst_buffer_list_insert(gstBufferList, idx, (buffer is null) ? null : buffer.getBufferStruct());
249 	}
250 
251 	/**
252 	 * Returns the number of buffers in @list.
253 	 *
254 	 * Returns: the number of buffers in the buffer list
255 	 */
256 	public uint length()
257 	{
258 		return gst_buffer_list_length(gstBufferList);
259 	}
260 
261 	/**
262 	 * Remove @length buffers starting from @idx in @list. The following buffers
263 	 * are moved to close the gap.
264 	 *
265 	 * Params:
266 	 *     idx = the index
267 	 *     length = the amount to remove
268 	 */
269 	public void remove(uint idx, uint length)
270 	{
271 		gst_buffer_list_remove(gstBufferList, idx, length);
272 	}
273 }