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  * Conversion parameters:
26  * inFile  = gstreamer-GstBufferPool.html
27  * outPack = gstreamer
28  * outFile = BufferPool
29  * strct   = GstBufferPool
30  * realStrct=
31  * ctorStrct=
32  * clss    = BufferPool
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_buffer_pool_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gstreamer.Allocator
48  * 	- gstreamer.Buffer
49  * 	- gstreamer.Caps
50  * 	- gstreamer.Structure
51  * structWrap:
52  * 	- GstAllocator* -> Allocator
53  * 	- GstBuffer* -> Buffer
54  * 	- GstCaps* -> Caps
55  * 	- GstStructure* -> Structure
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module gstreamer.BufferPool;
62 
63 public  import gstreamerc.gstreamertypes;
64 
65 private import gstreamerc.gstreamer;
66 private import glib.ConstructionException;
67 private import gobject.ObjectG;
68 
69 private import glib.Str;
70 private import gstreamer.Allocator;
71 private import gstreamer.Buffer;
72 private import gstreamer.Caps;
73 private import gstreamer.Structure;
74 
75 
76 
77 /**
78  * a GstBufferPool is an object that can be used to pre-allocate and recycle
79  * buffers of the same size and with the same properties.
80  *
81  * A GstBufferPool is created with gst_buffer_pool_new().
82  *
83  * After the buffer is created, it needs to be configured.
84  * gst_buffer_pool_get_config() get the current configuration structure from the
85  * pool. With gst_buffer_pool_config_set_params() and
86  * gst_buffer_pool_config_set_allocator() the bufferpool parameters and allocator
87  * can be configured. Other properties can be configured in the pool depending
88  * on the pool implementation.
89  *
90  * A bufferpool can have extra options that can be enabled with
91  * gst_buffer_pool_config_add_option(). The available options can be retrieved
92  * with gst_buffer_pool_get_options(). Some options allow for additional
93  * configuration properties to be set.
94  *
95  * After the configuration structure has been configured,
96  * gst_buffer_pool_set_config() updates the configuration in the pool. This can
97  * fail when the configuration structure is not accepted.
98  *
99  * After the a pool has been configured, it can be activated with
100  * gst_buffer_pool_set_active(). This will preallocate the configured resources
101  * in the pool.
102  *
103  * When the pool is active, gst_buffer_pool_acquire_buffer() can be used to
104  * retrieve a buffer from the pool.
105  *
106  * Buffer allocated from a bufferpool will automatically be returned to the pool
107  * with gst_buffer_pool_release_buffer() when their refcount drops to 0.
108  *
109  * The bufferpool can be deactivated again with gst_buffer_pool_set_active().
110  * All further gst_buffer_pool_acquire_buffer() calls will return an error. When
111  * all buffers are returned to the pool they will be freed.
112  *
113  * Use gst_object_unref() to release the reference to a bufferpool. If the
114  * refcount of the pool reaches 0, the pool will be freed.
115  *
116  * Last reviewed on 2012-03-28 (0.11.3)
117  */
118 public class BufferPool
119 {
120 	
121 	/** the main Gtk struct */
122 	protected GstBufferPool* gstBufferPool;
123 	
124 	
125 	/** Get the main Gtk struct */
126 	public GstBufferPool* getBufferPoolStruct()
127 	{
128 		return gstBufferPool;
129 	}
130 	
131 	
132 	/** the main Gtk struct as a void* */
133 	protected void* getStruct()
134 	{
135 		return cast(void*)gstBufferPool;
136 	}
137 	
138 	/**
139 	 * Sets our main struct and passes it to the parent class
140 	 */
141 	public this (GstBufferPool* gstBufferPool)
142 	{
143 		this.gstBufferPool = gstBufferPool;
144 	}
145 	
146 	/**
147 	 */
148 	
149 	/**
150 	 * Creates a new GstBufferPool instance.
151 	 * Throws: ConstructionException GTK+ fails to create the object.
152 	 */
153 	public this ()
154 	{
155 		// GstBufferPool * gst_buffer_pool_new (void);
156 		auto p = gst_buffer_pool_new();
157 		if(p is null)
158 		{
159 			throw new ConstructionException("null returned by gst_buffer_pool_new()");
160 		}
161 		this(cast(GstBufferPool*) p);
162 	}
163 	
164 	/**
165 	 * Get the configuration values from config.
166 	 * Params:
167 	 * config = a GstBufferPool configuration. [transfer none]
168 	 * caps = the caps of buffers. [out][transfer none][allow-none]
169 	 * size = the size of each buffer, not including prefix and padding. [out][allow-none]
170 	 * minBuffers = the minimum amount of buffers to allocate. [out][allow-none]
171 	 * maxBuffers = the maximum amount of buffers to allocate or 0 for unlimited. [out][allow-none]
172 	 * Returns: TRUE if all parameters could be fetched.
173 	 */
174 	public static int configGetParams(Structure config, out Caps caps, out uint size, out uint minBuffers, out uint maxBuffers)
175 	{
176 		// gboolean gst_buffer_pool_config_get_params (GstStructure *config,  GstCaps **caps,  guint *size,  guint *min_buffers,  guint *max_buffers);
177 		GstCaps* outcaps = null;
178 		
179 		auto p = gst_buffer_pool_config_get_params((config is null) ? null : config.getStructureStruct(), &outcaps, &size, &minBuffers, &maxBuffers);
180 		
181 		caps = ObjectG.getDObject!(Caps)(outcaps);
182 		return p;
183 	}
184 	
185 	/**
186 	 * Configure config with the given parameters.
187 	 * Params:
188 	 * config = a GstBufferPool configuration
189 	 * caps = caps for the buffers
190 	 * size = the size of each buffer, not including prefix and padding
191 	 * minBuffers = the minimum amount of buffers to allocate.
192 	 * maxBuffers = the maximum amount of buffers to allocate or 0 for unlimited.
193 	 */
194 	public static void configSetParams(Structure config, Caps caps, uint size, uint minBuffers, uint maxBuffers)
195 	{
196 		// void gst_buffer_pool_config_set_params (GstStructure *config,  GstCaps *caps,  guint size,  guint min_buffers,  guint max_buffers);
197 		gst_buffer_pool_config_set_params((config is null) ? null : config.getStructureStruct(), (caps is null) ? null : caps.getCapsStruct(), size, minBuffers, maxBuffers);
198 	}
199 	
200 	/**
201 	 * Get the allocator and params from config.
202 	 * Params:
203 	 * config = a GstBufferPool configuration. [transfer none]
204 	 * allocator = a GstAllocator. [transfer none]
205 	 * params = GstAllocationParams
206 	 */
207 	public static int configGetAllocator(Structure config, ref Allocator allocator, GstAllocationParams* params)
208 	{
209 		// gboolean gst_buffer_pool_config_get_allocator  (GstStructure *config,  GstAllocator **allocator,  GstAllocationParams *params);
210 		GstAllocator* outallocator = (allocator is null) ? null : allocator.getAllocatorStruct();
211 		
212 		auto p = gst_buffer_pool_config_get_allocator((config is null) ? null : config.getStructureStruct(), &outallocator, params);
213 		
214 		allocator = ObjectG.getDObject!(Allocator)(outallocator);
215 		return p;
216 	}
217 	
218 	/**
219 	 * Set the allocator and params on config.
220 	 * One of allocator and params can be NULL, but not both. When allocator
221 	 * is NULL, the default allocator of the pool will use the values in param
222 	 * to perform its allocation. When param is NULL, the pool will use the
223 	 * provided allocator with its default GstAllocationParams.
224 	 * A call to gst_buffer_pool_set_config() can update the allocator and params
225 	 * with the values that it is able to do. Some pools are, for example, not able
226 	 * to operate with different allocators or cannot allocate with the values
227 	 * specified in params. Use gst_buffer_pool_get_config() to get the currently
228 	 * used values.
229 	 * Params:
230 	 * config = a GstBufferPool configuration
231 	 * allocator = a GstAllocator
232 	 * params = GstAllocationParams
233 	 */
234 	public static void configSetAllocator(Structure config, Allocator allocator, GstAllocationParams* params)
235 	{
236 		// void gst_buffer_pool_config_set_allocator  (GstStructure *config,  GstAllocator *allocator,  const GstAllocationParams *params);
237 		gst_buffer_pool_config_set_allocator((config is null) ? null : config.getStructureStruct(), (allocator is null) ? null : allocator.getAllocatorStruct(), params);
238 	}
239 	
240 	/**
241 	 * Retrieve the number of values currently stored in the
242 	 * options array of the config structure.
243 	 * Params:
244 	 * config = a GstBufferPool configuration
245 	 * Returns: the options array size as a guint.
246 	 */
247 	public static uint configNOptions(Structure config)
248 	{
249 		// guint gst_buffer_pool_config_n_options (GstStructure *config);
250 		return gst_buffer_pool_config_n_options((config is null) ? null : config.getStructureStruct());
251 	}
252 	
253 	/**
254 	 * Enabled the option in config. This will instruct the bufferpool to enable
255 	 * the specified option on the buffers that it allocates.
256 	 * The supported options by pool can be retrieved with gst_buffer_pool_get_options().
257 	 * Params:
258 	 * config = a GstBufferPool configuration
259 	 * option = an option to add
260 	 */
261 	public static void configAddOption(Structure config, string option)
262 	{
263 		// void gst_buffer_pool_config_add_option (GstStructure *config,  const gchar *option);
264 		gst_buffer_pool_config_add_option((config is null) ? null : config.getStructureStruct(), Str.toStringz(option));
265 	}
266 	
267 	/**
268 	 * Parse an available config and get the option
269 	 * at index of the options API array.
270 	 * Params:
271 	 * config = a GstBufferPool configuration
272 	 * index = position in the option array to read
273 	 * Returns: a gchar of the option at index.
274 	 */
275 	public static string configGetOption(Structure config, uint index)
276 	{
277 		// const gchar * gst_buffer_pool_config_get_option (GstStructure *config,  guint index);
278 		return Str.toString(gst_buffer_pool_config_get_option((config is null) ? null : config.getStructureStruct(), index));
279 	}
280 	
281 	/**
282 	 * Check if config contains option
283 	 * Params:
284 	 * config = a GstBufferPool configuration
285 	 * option = an option
286 	 * Returns: TRUE if the options array contains option.
287 	 */
288 	public static int configHasOption(Structure config, string option)
289 	{
290 		// gboolean gst_buffer_pool_config_has_option (GstStructure *config,  const gchar *option);
291 		return gst_buffer_pool_config_has_option((config is null) ? null : config.getStructureStruct(), Str.toStringz(option));
292 	}
293 	
294 	/**
295 	 * Get a NULL terminated array of string with supported bufferpool options for
296 	 * pool. An option would typically be enabled with
297 	 * gst_buffer_pool_config_add_option().
298 	 * Returns: a NULL terminated array of strings. [array zero-terminated=1][transfer none]
299 	 */
300 	public string[] getOptions()
301 	{
302 		// const gchar ** gst_buffer_pool_get_options (GstBufferPool *pool);
303 		return Str.toStringArray(gst_buffer_pool_get_options(gstBufferPool));
304 	}
305 	
306 	/**
307 	 * Check if the bufferpool supports option.
308 	 * Params:
309 	 * option = an option
310 	 * Returns: a NULL terminated array of strings.
311 	 */
312 	public int hasOption(string option)
313 	{
314 		// gboolean gst_buffer_pool_has_option (GstBufferPool *pool,  const gchar *option);
315 		return gst_buffer_pool_has_option(gstBufferPool, Str.toStringz(option));
316 	}
317 	
318 	/**
319 	 * Get a copy of the current configuration of the pool. This configuration
320 	 * can either be modified and used for the gst_buffer_pool_set_config() call
321 	 * or it must be freed after usage.
322 	 * Returns: a copy of the current configuration of pool. use gst_structure_free() after usage or gst_buffer_pool_set_config(). [transfer full]
323 	 */
324 	public Structure getConfig()
325 	{
326 		// GstStructure * gst_buffer_pool_get_config (GstBufferPool *pool);
327 		auto p = gst_buffer_pool_get_config(gstBufferPool);
328 		
329 		if(p is null)
330 		{
331 			return null;
332 		}
333 		
334 		return ObjectG.getDObject!(Structure)(cast(GstStructure*) p);
335 	}
336 	
337 	/**
338 	 * Set the configuration of the pool. The pool must be inactive and all buffers
339 	 * allocated form this pool must be returned or else this function will do
340 	 * nothing and return FALSE.
341 	 * config is a GstStructure that contains the configuration parameters for
342 	 * the pool. A default and mandatory set of parameters can be configured with
343 	 * gst_buffer_pool_config_set_params(), gst_buffer_pool_config_set_allocator()
344 	 * and gst_buffer_pool_config_add_option().
345 	 * If the parameters in config can not be set exactly, this function returns
346 	 * FALSE and will try to update as much state as possible. The new state can
347 	 * then be retrieved and refined with gst_buffer_pool_get_config().
348 	 * This function takes ownership of config.
349 	 * Params:
350 	 * config = a GstStructure. [transfer full]
351 	 * Returns: TRUE when the configuration could be set.
352 	 */
353 	public int setConfig(Structure config)
354 	{
355 		// gboolean gst_buffer_pool_set_config (GstBufferPool *pool,  GstStructure *config);
356 		return gst_buffer_pool_set_config(gstBufferPool, (config is null) ? null : config.getStructureStruct());
357 	}
358 	
359 	/**
360 	 * Control the active state of pool. When the pool is inactive, new calls to
361 	 * gst_buffer_pool_acquire_buffer() will return with GST_FLOW_FLUSHING.
362 	 * Activating the bufferpool will preallocate all resources in the pool based on
363 	 * the configuration of the pool.
364 	 * Deactivating will free the resources again when there are no outstanding
365 	 * buffers. When there are outstanding buffers, they will be freed as soon as
366 	 * they are all returned to the pool.
367 	 * Params:
368 	 * active = the new active state
369 	 * Returns: FALSE when the pool was not configured or when preallocation of the buffers failed.
370 	 */
371 	public int setActive(int active)
372 	{
373 		// gboolean gst_buffer_pool_set_active (GstBufferPool *pool,  gboolean active);
374 		return gst_buffer_pool_set_active(gstBufferPool, active);
375 	}
376 	
377 	/**
378 	 * Check if pool is active. A pool can be activated with the
379 	 * gst_buffer_pool_set_active() call.
380 	 * Returns: TRUE when the pool is active.
381 	 */
382 	public int isActive()
383 	{
384 		// gboolean gst_buffer_pool_is_active (GstBufferPool *pool);
385 		return gst_buffer_pool_is_active(gstBufferPool);
386 	}
387 	
388 	/**
389 	 * Acquire a buffer from pool. buffer should point to a memory location that
390 	 * can hold a pointer to the new buffer.
391 	 * params can be NULL or contain optional parameters to influence the allocation.
392 	 * Params:
393 	 * buffer = a location for a GstBuffer. [out]
394 	 * params = (transfer none) (allow-none) parameters.
395 	 * Returns: a GstFlowReturn such as GST_FLOW_FLUSHING when the pool is inactive.
396 	 */
397 	public GstFlowReturn acquireBuffer(out Buffer buffer, GstBufferPoolAcquireParams* params)
398 	{
399 		// GstFlowReturn gst_buffer_pool_acquire_buffer (GstBufferPool *pool,  GstBuffer **buffer,  GstBufferPoolAcquireParams *params);
400 		GstBuffer* outbuffer = null;
401 		
402 		auto p = gst_buffer_pool_acquire_buffer(gstBufferPool, &outbuffer, params);
403 		
404 		buffer = ObjectG.getDObject!(Buffer)(outbuffer);
405 		return p;
406 	}
407 	
408 	/**
409 	 * Release buffer to pool. buffer should have previously been allocated from
410 	 * pool with gst_buffer_pool_acquire_buffer().
411 	 * This function is usually called automatically when the last ref on buffer
412 	 * disappears.
413 	 * Params:
414 	 * buffer = a GstBuffer. [transfer full]
415 	 */
416 	public void releaseBuffer(Buffer buffer)
417 	{
418 		// void gst_buffer_pool_release_buffer (GstBufferPool *pool,  GstBuffer *buffer);
419 		gst_buffer_pool_release_buffer(gstBufferPool, (buffer is null) ? null : buffer.getBufferStruct());
420 	}
421 }