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