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