Class BufferPool
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
VideoBufferPool
GstBufferPool is an object that can be used to pre-allocate and recycle
buffers of the same size and with the same properties.
A GstBufferPool is created with gst_buffer_pool_new().
Once a pool is created, it needs to be configured. A call to gst_buffer_pool_get_config() returns the current configuration structure from the pool. With gst_buffer_pool_config_set_params() and gst_buffer_pool_config_set_allocator() the bufferpool parameters and allocator can be configured. Other properties can be configured in the pool depending on the pool implementation.
A bufferpool can have extra options that can be enabled with gst_buffer_pool_config_add_option(). The available options can be retrieved with gst_buffer_pool_get_options(). Some options allow for additional configuration properties to be set.
After the configuration structure has been configured, gst_buffer_pool_set_config() updates the configuration in the pool. This can fail when the configuration structure is not accepted.
After the pool has been configured, it can be activated with gst_buffer_pool_set_active(). This will preallocate the configured resources in the pool.
When the pool is active, gst_buffer_pool_acquire_buffer() can be used to retrieve a buffer from the pool.
Buffers allocated from a bufferpool will automatically be returned to the pool with gst_buffer_pool_release_buffer() when their refcount drops to 0.
The bufferpool can be deactivated again with gst_buffer_pool_set_active(). All further gst_buffer_pool_acquire_buffer() calls will return an error. When all buffers are returned to the pool they will be freed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classTheGstBufferPoolclass.static classBufferPool.Builder<B extends BufferPool.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.freedesktop.gstreamer.gst.GstObject
GstObject.DeepNotifyCallback, GstObject.Object$Impl, GstObject.ObjectClassNested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new BufferPool.BufferPool(MemorySegment address) Create a BufferPool proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionacquireBuffer(@Nullable Out<Buffer> buffer, @Nullable BufferPoolAcquireParams params) Acquires a buffer frompool.buffershould point to a memory location that can hold a pointer to the new buffer.protected FlowReturnallocBuffer(@Nullable Out<Buffer> buffer, @Nullable BufferPoolAcquireParams params) Allocate a buffer.protected BufferPoolasParent()Returns this instance as if it were its parent type.static BufferPool.Builder<? extends BufferPool.Builder> builder()ABufferPool.Builderobject constructs aBufferPoolwith the specified properties.static voidconfigAddOption(Structure config, String option) Enables the option inconfig.This will instruct thebufferpoolto enable the specified option on the buffers that it allocates.static booleanconfigGetAllocator(Structure config, @Nullable Out<Allocator> allocator, @Nullable AllocationParams params) Gets theallocatorandparamsfromconfig.static @Nullable StringconfigGetOption(Structure config, int index) Parses an availableconfigand gets the option atindexof the options API array.static booleanconfigGetParams(Structure config, @Nullable Out<Caps> caps, @Nullable Out<Integer> size, @Nullable Out<Integer> minBuffers, @Nullable Out<Integer> maxBuffers) Gets the configuration values fromconfig.static booleanconfigHasOption(Structure config, String option) Checks ifconfigcontainsoption.static intconfigNOptions(Structure config) Retrieves the number of values currently stored in the options array of theconfigstructure.static voidconfigSetAllocator(Structure config, @Nullable Allocator allocator, @Nullable AllocationParams params) Sets theallocatorandparamsonconfig.static voidconfigSetParams(Structure config, @Nullable Caps caps, int size, int minBuffers, int maxBuffers) Configuresconfigwith the given parameters.static booleanconfigValidateParams(Structure config, @Nullable Caps caps, int size, int minBuffers, int maxBuffers) Validates that changes made toconfigare still valid in the context of the expected parameters.protected voidEnter the flushing state.protected voidLeave the flushing state.protected voidfreeBuffer(Buffer buffer) Free a buffer.Gets a copy of the current configuration of the pool.static MemoryLayoutThe memory layout of the native struct.String[]Gets anullterminated array of string with supported bufferpool options forpool.An option would typically be enabled with gst_buffer_pool_config_add_option().static @Nullable TypegetType()Get the GType of the BufferPool classbooleanChecks if the bufferpool supportsoption.booleanisActive()Checks if this BufferPool is active.voidreleaseBuffer(Buffer buffer) Releasesbuffertopool.buffershould have previously been allocated from this BufferPool with gst_buffer_pool_acquire_buffer().protected voidresetBuffer(Buffer buffer) Reset the buffer to its state when it was freshly allocated.booleansetActive(boolean active) Controls the active state ofpool.When the pool is inactive, new calls to gst_buffer_pool_acquire_buffer() will return withFlowReturn.FLUSHING.booleanSets the configuration of the pool.voidsetFlushing(boolean flushing) Enables or disables the flushing state of a this BufferPool without freeing or allocating buffers.protected booleanstart()Start the bufferpool.protected booleanstop()Stop the bufferpool.Methods inherited from class org.freedesktop.gstreamer.gst.GstObject
addControlBinding, checkUniqueness, deepNotify, defaultDeepNotify, defaultError, emitDeepNotify, getControlBinding, getControlRate, getGValueArray, getName, getParent, getPathString, getValue, getValueArray, hasActiveControlBindings, hasAncestor, hasAsAncestor, hasAsParent, onDeepNotify, ref, refSink, removeControlBinding, replace, setControlBindingDisabled, setControlBindingsDisabled, setControlRate, setName, setParent, suggestNextSync, syncValues, unparent, unrefMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
BufferPool
Create a BufferPool proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
BufferPool
public BufferPool()Creates a new BufferPool.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
configAddOption
Enables the option inconfig.This will instruct thebufferpoolto enable the specified option on the buffers that it allocates.The options supported by
poolcan be retrieved with gst_buffer_pool_get_options().- Parameters:
config- aGstBufferPoolconfigurationoption- an option to add
-
configGetAllocator
public static boolean configGetAllocator(Structure config, @Nullable Out<Allocator> allocator, @Nullable AllocationParams params) Gets theallocatorandparamsfromconfig.- Parameters:
config- aGstBufferPoolconfigurationallocator- aGstAllocator, ornullparams-GstAllocationParams, ornull- Returns:
true, if the values are set.
-
configGetOption
-
configGetParams
public static boolean configGetParams(Structure config, @Nullable Out<Caps> caps, @Nullable Out<Integer> size, @Nullable Out<Integer> minBuffers, @Nullable Out<Integer> maxBuffers) Gets the configuration values fromconfig.- Parameters:
config- aGstBufferPoolconfigurationcaps- the caps of bufferssize- the size of each buffer, not including prefix and paddingminBuffers- the minimum amount of buffers to allocate.maxBuffers- the maximum amount of buffers to allocate or 0 for unlimited.- Returns:
trueif all parameters could be fetched.
-
configHasOption
-
configNOptions
Retrieves the number of values currently stored in the options array of theconfigstructure.- Parameters:
config- aGstBufferPoolconfiguration- Returns:
- the options array size as a
guint.
-
configSetAllocator
public static void configSetAllocator(Structure config, @Nullable Allocator allocator, @Nullable AllocationParams params) Sets theallocatorandparamsonconfig.One of
allocatorandparamscan benull, but not both. Whenallocatorisnull, the default allocator of the pool will use the values inparamto perform its allocation. Whenparamisnull, the pool will use the providedallocatorwith its defaultGstAllocationParams.A call to gst_buffer_pool_set_config() can update the allocator and params with the values that it is able to do. Some pools are, for example, not able to operate with different allocators or cannot allocate with the values specified in
params.Use gst_buffer_pool_get_config() to get the currently used values.- Parameters:
config- aGstBufferPoolconfigurationallocator- aGstAllocatorparams-GstAllocationParams
-
configSetParams
public static void configSetParams(Structure config, @Nullable Caps caps, int size, int minBuffers, int maxBuffers) Configuresconfigwith the given parameters.- Parameters:
config- aGstBufferPoolconfigurationcaps- caps for the bufferssize- the size of each buffer, not including prefix and paddingminBuffers- the minimum amount of buffers to allocate.maxBuffers- the maximum amount of buffers to allocate or 0 for unlimited.
-
configValidateParams
public static boolean configValidateParams(Structure config, @Nullable Caps caps, int size, int minBuffers, int maxBuffers) Validates that changes made toconfigare still valid in the context of the expected parameters. This function is a helper that can be used to validate changes made by a pool to a config when gst_buffer_pool_set_config() returnsfalse. This expects thatcapshaven't changed and thatminBuffersaren't lower then what we initially expected. This does not check if options or allocator parameters are still valid, won't check if size have changed, since changing the size is valid to adapt padding.- Parameters:
config- aGstBufferPoolconfigurationcaps- the excepted caps of bufferssize- the expected size of each buffer, not including prefix and paddingminBuffers- the expected minimum amount of buffers to allocate.maxBuffers- the expect maximum amount of buffers to allocate or 0 for unlimited.- Returns:
true, if the parameters are valid in this context.- Since:
- 1.4
-
acquireBuffer
public FlowReturn acquireBuffer(@Nullable Out<Buffer> buffer, @Nullable BufferPoolAcquireParams params) Acquires a buffer frompool.buffershould point to a memory location that can hold a pointer to the new buffer. When the pool is empty, this function will by default block until a buffer is released into the pool again or when the pool is set to flushing or deactivated.paramscan contain optional parameters to influence the allocation.- Parameters:
buffer- a location for aGstBufferparams- parameters.- Returns:
- a
GstFlowReturnsuch asFlowReturn.FLUSHINGwhen the pool is inactive.
-
getConfig
Gets a copy of the current configuration of the pool. This configuration can be modified and used for the gst_buffer_pool_set_config() call.- Returns:
- a copy of the current configuration of
pool.
-
getOptions
Gets anullterminated array of string with supported bufferpool options forpool.An option would typically be enabled with gst_buffer_pool_config_add_option().- Returns:
- a
nullterminated array of strings.
-
hasOption
Checks if the bufferpool supportsoption.- Parameters:
option- an option- Returns:
trueif the buffer pool containsoption.
-
isActive
public boolean isActive()Checks if this BufferPool is active. A pool can be activated with the gst_buffer_pool_set_active() call.- Returns:
truewhen the pool is active.
-
releaseBuffer
Releasesbuffertopool.buffershould have previously been allocated from this BufferPool with gst_buffer_pool_acquire_buffer().This function is usually called automatically when the last ref on
bufferdisappears.- Parameters:
buffer- aGstBuffer
-
setActive
public boolean setActive(boolean active) Controls the active state ofpool.When the pool is inactive, new calls to gst_buffer_pool_acquire_buffer() will return withFlowReturn.FLUSHING.Activating the bufferpool will preallocate all resources in the pool based on the configuration of the pool.
Deactivating will free the resources again when there are no outstanding buffers. When there are outstanding buffers, they will be freed as soon as they are all returned to the pool.
- Parameters:
active- the new active state- Returns:
falsewhen the pool was not configured or when preallocation of the buffers failed.
-
setConfig
Sets the configuration of the pool. If the pool is already configured, and the configuration hasn't changed, this function will returntrue. If the pool is active, this method will returnfalseand active configuration will remain. Buffers allocated from this pool must be returned or else this function will do nothing and returnfalse.configis aGstStructurethat contains the configuration parameters for the pool. A default and mandatory set of parameters can be configured with gst_buffer_pool_config_set_params(), gst_buffer_pool_config_set_allocator() and gst_buffer_pool_config_add_option().If the parameters in
configcan not be set exactly, this function returnsfalseand will try to update as much state as possible. The new state can then be retrieved and refined with gst_buffer_pool_get_config().This function takes ownership of
config.- Parameters:
config- aGstStructure- Returns:
truewhen the configuration could be set.
-
setFlushing
public void setFlushing(boolean flushing) Enables or disables the flushing state of a this BufferPool without freeing or allocating buffers.- Parameters:
flushing- whether to start or stop flushing- Since:
- 1.4
-
allocBuffer
protected FlowReturn allocBuffer(@Nullable Out<Buffer> buffer, @Nullable BufferPoolAcquireParams params) Allocate a buffer. the default implementation allocates buffers from the configured memory allocator and with the configured parameters. All metadata that is present on the allocated buffer will be marked asGST_META_FLAG_POOLEDandGST_META_FLAG_LOCKEDand will not be removed from the buffer inGstBufferPoolClass::reset_buffer. The buffer should have theGST_BUFFER_FLAG_TAG_MEMORYcleared.- Parameters:
buffer- a location for aGstBufferparams- parameters.- Returns:
- a
GstFlowReturnto indicate whether the allocation was successful.
-
flushStart
protected void flushStart()Enter the flushing state.- Since:
- 1.4
-
flushStop
protected void flushStop()Leave the flushing state.- Since:
- 1.4
-
freeBuffer
Free a buffer. The default implementation unrefs the buffer.- Parameters:
buffer- theGstBufferto free
-
resetBuffer
Reset the buffer to its state when it was freshly allocated. The default implementation will clear the flags, timestamps and will remove the metadata without theGST_META_FLAG_POOLEDflag (even the metadata withGST_META_FLAG_LOCKED). If theGST_BUFFER_FLAG_TAG_MEMORYwas set, this function can also try to restore the memory and clear theGST_BUFFER_FLAG_TAG_MEMORYagain.- Parameters:
buffer- theGstBufferto reset
-
start
protected boolean start()Start the bufferpool. The default implementation will preallocate min-buffers buffers and put them in the queue.Subclasses do not need to chain up to the parent's default implementation if they don't want min-buffers based preallocation.
- Returns:
- whether the pool could be started.
-
stop
protected boolean stop()Stop the bufferpool. the default implementation will free the preallocated buffers. This function is called when all the buffers are returned to the pool.- Returns:
- whether the pool could be stopped.
-
builder
ABufferPool.Builderobject constructs aBufferPoolwith the specified properties. Use the variousset...()methods to set properties, and finish construction withBufferPool.Builder.build().- Returns:
- the builder object
-