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