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