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