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 gstreamer.c.functions; 37 public import gstreamer.c.types; 38 public import gstreamerc.gstreamertypes; 39 40 41 /** 42 * A #GstBufferPool is an object that can be used to pre-allocate and recycle 43 * buffers of the same size and with the same properties. 44 * 45 * A #GstBufferPool is created with gst_buffer_pool_new(). 46 * 47 * Once a pool is created, it needs to be configured. A call to 48 * gst_buffer_pool_get_config() returns the current configuration structure from 49 * the pool. With gst_buffer_pool_config_set_params() and 50 * gst_buffer_pool_config_set_allocator() the bufferpool parameters and 51 * allocator can be configured. Other properties can be configured in the pool 52 * depending on the pool implementation. 53 * 54 * A bufferpool can have extra options that can be enabled with 55 * gst_buffer_pool_config_add_option(). The available options can be retrieved 56 * with gst_buffer_pool_get_options(). Some options allow for additional 57 * configuration properties to be set. 58 * 59 * After the configuration structure has been configured, 60 * gst_buffer_pool_set_config() updates the configuration in the pool. This can 61 * fail when the configuration structure is not accepted. 62 * 63 * After the a pool has been configured, it can be activated with 64 * gst_buffer_pool_set_active(). This will preallocate the configured resources 65 * in the pool. 66 * 67 * When the pool is active, gst_buffer_pool_acquire_buffer() can be used to 68 * retrieve a buffer from the pool. 69 * 70 * Buffers allocated from a bufferpool will automatically be returned to the 71 * pool with gst_buffer_pool_release_buffer() when their refcount drops to 0. 72 * 73 * The bufferpool can be deactivated again with gst_buffer_pool_set_active(). 74 * All further gst_buffer_pool_acquire_buffer() calls will return an error. When 75 * all buffers are returned to the pool they will be freed. 76 * 77 * Use gst_object_unref() to release the reference to a bufferpool. If the 78 * refcount of the pool reaches 0, the pool will be freed. 79 */ 80 public class BufferPool : ObjectGst 81 { 82 /** the main Gtk struct */ 83 protected GstBufferPool* gstBufferPool; 84 85 /** Get the main Gtk struct */ 86 public GstBufferPool* getBufferPoolStruct(bool transferOwnership = false) 87 { 88 if (transferOwnership) 89 ownedRef = false; 90 return gstBufferPool; 91 } 92 93 /** the main Gtk struct as a void* */ 94 protected override void* getStruct() 95 { 96 return cast(void*)gstBufferPool; 97 } 98 99 /** 100 * Sets our main struct and passes it to the parent class. 101 */ 102 public this (GstBufferPool* gstBufferPool, bool ownedRef = false) 103 { 104 this.gstBufferPool = gstBufferPool; 105 super(cast(GstObject*)gstBufferPool, ownedRef); 106 } 107 108 109 /** */ 110 public static GType getType() 111 { 112 return gst_buffer_pool_get_type(); 113 } 114 115 /** 116 * Creates a new #GstBufferPool instance. 117 * 118 * Returns: a new #GstBufferPool instance 119 * 120 * Throws: ConstructionException GTK+ fails to create the object. 121 */ 122 public this() 123 { 124 auto p = gst_buffer_pool_new(); 125 126 if(p is null) 127 { 128 throw new ConstructionException("null returned by new"); 129 } 130 131 this(cast(GstBufferPool*) p); 132 } 133 134 /** 135 * Enabled the option in @config. This will instruct the @bufferpool to enable 136 * the specified option on the buffers that it allocates. 137 * 138 * The supported options by @pool can be retrieved with gst_buffer_pool_get_options(). 139 * 140 * Params: 141 * config = a #GstBufferPool configuration 142 * option = an option to add 143 */ 144 public static void configAddOption(Structure config, string option) 145 { 146 gst_buffer_pool_config_add_option((config is null) ? null : config.getStructureStruct(), Str.toStringz(option)); 147 } 148 149 /** 150 * Get the @allocator and @params from @config. 151 * 152 * Params: 153 * config = a #GstBufferPool configuration 154 * allocator = a #GstAllocator, or %NULL 155 * params = #GstAllocationParams, or %NULL 156 * 157 * Returns: %TRUE, if the values are set. 158 */ 159 public static bool configGetAllocator(Structure config, ref Allocator allocator, out AllocationParams params) 160 { 161 GstAllocator* outallocator = allocator.getAllocatorStruct(); 162 GstAllocationParams* outparams = gMalloc!GstAllocationParams(); 163 164 auto p = gst_buffer_pool_config_get_allocator((config is null) ? null : config.getStructureStruct(), &outallocator, outparams) != 0; 165 166 allocator = ObjectG.getDObject!(Allocator)(outallocator); 167 params = ObjectG.getDObject!(AllocationParams)(outparams, true); 168 169 return p; 170 } 171 172 /** 173 * Parse an available @config and get the option at @index of the options API 174 * array. 175 * 176 * Params: 177 * config = a #GstBufferPool configuration 178 * index = position in the option array to read 179 * 180 * Returns: a #gchar of the option at @index. 181 */ 182 public static string configGetOption(Structure config, uint index) 183 { 184 return Str.toString(gst_buffer_pool_config_get_option((config is null) ? null : config.getStructureStruct(), index)); 185 } 186 187 /** 188 * Get the configuration values from @config. 189 * 190 * Params: 191 * config = a #GstBufferPool configuration 192 * caps = the caps of buffers 193 * size = the size of each buffer, not including prefix and padding 194 * minBuffers = the minimum amount of buffers to allocate. 195 * maxBuffers = the maximum amount of buffers to allocate or 0 for unlimited. 196 * 197 * Returns: %TRUE if all parameters could be fetched. 198 */ 199 public static bool configGetParams(Structure config, out Caps caps, out uint size, out uint minBuffers, out uint maxBuffers) 200 { 201 GstCaps* outcaps = null; 202 203 auto p = gst_buffer_pool_config_get_params((config is null) ? null : config.getStructureStruct(), &outcaps, &size, &minBuffers, &maxBuffers) != 0; 204 205 caps = ObjectG.getDObject!(Caps)(outcaps); 206 207 return p; 208 } 209 210 /** 211 * Check if @config contains @option. 212 * 213 * Params: 214 * config = a #GstBufferPool configuration 215 * option = an option 216 * 217 * Returns: %TRUE if the options array contains @option. 218 */ 219 public static bool configHasOption(Structure config, string option) 220 { 221 return gst_buffer_pool_config_has_option((config is null) ? null : config.getStructureStruct(), Str.toStringz(option)) != 0; 222 } 223 224 /** 225 * Retrieve the number of values currently stored in the options array of the 226 * @config structure. 227 * 228 * Params: 229 * config = a #GstBufferPool configuration 230 * 231 * Returns: the options array size as a #guint. 232 */ 233 public static uint configNOptions(Structure config) 234 { 235 return gst_buffer_pool_config_n_options((config is null) ? null : config.getStructureStruct()); 236 } 237 238 /** 239 * Set the @allocator and @params on @config. 240 * 241 * One of @allocator and @params can be %NULL, but not both. When @allocator 242 * is %NULL, the default allocator of the pool will use the values in @param 243 * to perform its allocation. When @param is %NULL, the pool will use the 244 * provided @allocator with its default #GstAllocationParams. 245 * 246 * A call to gst_buffer_pool_set_config() can update the allocator and params 247 * with the values that it is able to do. Some pools are, for example, not able 248 * to operate with different allocators or cannot allocate with the values 249 * specified in @params. Use gst_buffer_pool_get_config() to get the currently 250 * used values. 251 * 252 * Params: 253 * config = a #GstBufferPool configuration 254 * allocator = a #GstAllocator 255 * params = #GstAllocationParams 256 */ 257 public static void configSetAllocator(Structure config, Allocator allocator, AllocationParams params) 258 { 259 gst_buffer_pool_config_set_allocator((config is null) ? null : config.getStructureStruct(), (allocator is null) ? null : allocator.getAllocatorStruct(), (params is null) ? null : params.getAllocationParamsStruct()); 260 } 261 262 /** 263 * Configure @config with the given parameters. 264 * 265 * Params: 266 * config = a #GstBufferPool configuration 267 * caps = caps for the buffers 268 * size = the size of each buffer, not including prefix and padding 269 * minBuffers = the minimum amount of buffers to allocate. 270 * maxBuffers = the maximum amount of buffers to allocate or 0 for unlimited. 271 */ 272 public static void configSetParams(Structure config, Caps caps, uint size, uint minBuffers, uint maxBuffers) 273 { 274 gst_buffer_pool_config_set_params((config is null) ? null : config.getStructureStruct(), (caps is null) ? null : caps.getCapsStruct(), size, minBuffers, maxBuffers); 275 } 276 277 /** 278 * Validate that changes made to @config are still valid in the context of the 279 * expected parameters. This function is a helper that can be used to validate 280 * changes made by a pool to a config when gst_buffer_pool_set_config() 281 * returns %FALSE. This expects that @caps haven't changed and that 282 * @min_buffers aren't lower then what we initially expected. 283 * This does not check if options or allocator parameters are still valid, 284 * won't check if size have changed, since changing the size is valid to adapt 285 * padding. 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 * Returns: %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 * Returns: 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 * Returns: 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, true); 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 * Returns: 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 * Returns: %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 * Returns: %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 * Returns: %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 method will return %FALSE and active configuration 426 * will remain. Buffers allocated form this pool must be returned or else this 427 * function will do nothing and 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 * Returns: %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(true)) != 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 }