Class Buffer
- All Implemented Interfaces:
Proxy
GstMemory blocks that the buffer contains.
Buffers are usually created with gst_buffer_new(). After a buffer has been created one will typically allocate memory for it and add it to the buffer. The following example creates a buffer that can hold a given video frame with a given width, height and bits per plane.
GstBuffer *buffer;
GstMemory *memory;
gint size, width, height, bpp;
...
size = width * height * bpp;
buffer = gst_buffer_new ();
memory = gst_allocator_alloc (NULL, size, NULL);
gst_buffer_insert_memory (buffer, -1, memory);
...
Alternatively, use gst_buffer_new_allocate() to create a buffer with preallocated data of a given size.
Buffers can contain a list of GstMemory objects. You can retrieve how many
memory objects with gst_buffer_n_memory() and you can get a pointer
to memory with gst_buffer_peek_memory()
A buffer will usually have timestamps, and a duration, but neither of these
are guaranteed (they may be set to GST_CLOCK_TIME_NONE). Whenever a
meaningful value can be given for these, they should be set. The timestamps
and duration are measured in nanoseconds (they are GstClockTime values).
The buffer DTS refers to the timestamp when the buffer should be decoded and is usually monotonically increasing. The buffer PTS refers to the timestamp when the buffer content should be presented to the user and is not always monotonically increasing.
A buffer can also have one or both of a start and an end offset. These are
media-type specific. For video buffers, the start offset will generally be
the frame number. For audio buffers, it will be the number of samples
produced so far. For compressed data, it could be the byte offset in a
source or destination file. Likewise, the end offset will be the offset of
the end of the buffer. These can only be meaningfully interpreted if you
know the media type of the buffer (the preceding CAPS event). Either or both
can be set to GST_BUFFER_OFFSET_NONE.
gst_buffer_ref() is used to increase the refcount of a buffer. This must be done when you want to keep a handle to the buffer after pushing it to the next element. The buffer refcount determines the writability of the buffer, a buffer is only writable when the refcount is exactly 1, i.e. when the caller has the only reference to the buffer.
To efficiently create a smaller buffer out of an existing one, you can use gst_buffer_copy_region(). This method tries to share the memory objects between the two buffers.
If a plug-in wants to modify the buffer data or metadata in-place, it should first obtain a buffer that is safe to modify by using gst_buffer_make_writable(). This function is optimized so that a copy will only be made when it is necessary.
Several flags of the buffer can be set and unset with the
GST_BUFFER_FLAG_SET() and GST_BUFFER_FLAG_UNSET() macros. Use
GST_BUFFER_FLAG_IS_SET() to test if a certain GstBufferFlags flag is set.
Buffers can be efficiently merged into a larger buffer with gst_buffer_append(). Copying of memory will only be done when absolutely needed.
Arbitrary extra metadata can be set on a buffer with gst_buffer_add_meta().
Metadata can be retrieved with gst_buffer_get_meta(). See also GstMeta.
An element should either unref the buffer or push it out on a src pad
using gst_pad_push() (see GstPad).
Buffers are usually freed by unreffing them with gst_buffer_unref(). When
the refcount drops to 0, any memory and metadata pointed to by the buffer is
unreffed as well. Buffers allocated from a GstBufferPool will be returned to
the pool when the refcount drops to 0.
The GstParentBufferMeta is a meta which can be attached to a GstBuffer
to hold a reference to another buffer that is only released when the child
GstBuffer is released.
Typically, GstParentBufferMeta is used when the child buffer is directly
using the GstMemory of the parent buffer, and wants to prevent the parent
buffer from being returned to a buffer pool until the GstMemory is available
for re-use. (Since: 1.6)
-
Constructor Summary
ConstructorsConstructorDescriptionBuffer()Creates a newly allocated buffer without any data.Buffer(MemorySegment address) Create a Buffer proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescription@Nullable CustomMetaaddCustomMeta(String name) Creates and adds aGstCustomMetafor the desiredname.namemust have been successfully registered with gst_meta_register_custom().@Nullable MetaaddMeta(MetaInfo info, @Nullable MemorySegment params) Adds metadata forinfoto this Buffer using the parameters inparams.@Nullable ParentBufferMetaAdds aGstParentBufferMetato this Buffer that holds a reference onrefuntil the buffer is freed.addProtectionMeta(Structure info) Attaches protection metadata to aGstBuffer.@Nullable ReferenceTimestampMetaaddReferenceTimestampMeta(Caps reference, ClockTime timestamp, ClockTime duration) Adds aGstReferenceTimestampMetato this Buffer that holds atimestampand optionallydurationbased on a specific timestampreference.See the documentation ofGstReferenceTimestampMetafor details.static Bufferallocate(@Nullable Allocator allocator, long size, @Nullable AllocationParams params) Tries to create a newly allocated buffer with data of the given size and extra parameters fromallocator.If the requested amount of memory can't be allocated,nullwill be returned.Appends all the memory frombuf2tobuf1.The result buffer will contain a concatenation of the memory of this Buffer andbuf2.voidappendMemory(Memory mem) Appends the memory blockmemtobuffer.This function takes ownership ofmemand thus doesn't increase its refcount.appendRegion(Buffer buf2, long offset, long size) Appendssizebytes atoffsetfrombuf2tobuf1.The result buffer will contain a concatenation of the memory of this Buffer and the requested region ofbuf2.@Nullable Buffercopy()Creates a copy of the given buffer.@Nullable BuffercopyDeep()Creates a copy of the given buffer.booleancopyInto(Buffer src, Set<BufferCopyFlags> flags, long offset, long size) Copies the information fromsrcintodest.booleancopyInto(Buffer src, BufferCopyFlags flags, long offset, long size) Copies the information fromsrcintodest.@Nullable BuffercopyRegion(Set<BufferCopyFlags> flags, long offset, long size) Creates a sub-buffer from this Buffer atoffsetandsize.This sub-buffer uses the actual memory space of the parent buffer.@Nullable BuffercopyRegion(BufferCopyFlags flags, long offset, long size) Creates a sub-buffer from this Buffer atoffsetandsize.This sub-buffer uses the actual memory space of the parent buffer.longCopiessizebytes starting fromoffsetin this Buffer todest.voidextractDup(long offset, long size, @Nullable Out<byte[]> dest) Extracts a copy of at mostsizebytes the data atoffsetinto newly-allocated memory.longfill(long offset, @org.jspecify.annotations.Nullable byte @Nullable [] src) Copiessizebytes fromsrcto this Buffer atoffset.booleanFinds the memory blocks that spansizebytes starting fromoffsetinbuffer.booleanforeachMeta(@Nullable BufferForeachMetaFunc func) CallsfuncwithuserDatafor each meta inbuffer.@Nullable MemoryGets all the memory blocks inbuffer.The memory blocks will be merged into one largeGstMemory.@Nullable CustomMetagetCustomMeta(String name) Finds the firstGstCustomMetaon this Buffer for the desiredname.getFlags()Gets theGstBufferFlagsflags set on this buffer.static intGets the maximum amount of memory blocks that a buffer can hold.@Nullable MemorygetMemory(int idx) Gets the memory block at indexidxinbuffer.static MemoryLayoutThe memory layout of the native struct.@Nullable MemorygetMemoryRange(int idx, int length) Getslengthmemory blocks in this Buffer starting atidx.The memory blocks will be merged into one largeGstMemory.@Nullable MetaGets the metadata forapion buffer.int@Nullable ReferenceTimestampMetagetReferenceTimestampMeta(@Nullable Caps reference) Finds the firstGstReferenceTimestampMetaon this Buffer that conforms toreference.Conformance is tested by checking if the meta's reference is a subset ofreference.longgetSize()Gets the total size of the memory blocks inbuffer.longGets the total size of the memory blocks inbuffer.longgetSizesRange(int idx, int length, @Nullable Out<Long> offset, @Nullable Out<Long> maxsize) Gets the total size oflengthmemory blocks stating fromidxinbuffer.static @Nullable TypegetType()Get the GType of the Buffer classbooleanhasFlags(Set<BufferFlags> flags) Gives the status of a specific flag on a buffer.booleanhasFlags(BufferFlags... flags) Gives the status of a specific flag on a buffer.voidinsertMemory(int idx, Memory mem) Inserts the memory blockmeminto this Buffer atidx.This function takes ownership ofmemand thus doesn't increase its refcount.booleanChecks if all memory blocks in this Buffer are writable.booleanisMemoryRangeWritable(int idx, int length) Checks iflengthmemory blocks in this Buffer starting fromidxare writable.@Nullable MetaiterateMeta(@Nullable Out<MemorySegment> state) Retrieves the nextGstMetaaftercurrent.Ifstatepoints tonull, the first metadata is returned.@Nullable MetaiterateMetaFiltered(@Nullable Out<MemorySegment> state, Type metaApiType) Retrieves the nextGstMetaof typemetaApiTypeafter the current one according tostate.Ifstatepoints tonull, the first metadata of typemetaApiTypeis returned.booleanFillsinfowith theGstMapInfoof all merged memory blocks inbuffer.booleanFillsinfowith theGstMapInfooflengthmerged memory blocks starting atidxinbuffer.Whenlengthis -1, all memory blocks starting fromidxare merged and mapped.intmemcmp(long offset, @org.jspecify.annotations.Nullable byte @Nullable [] mem) Comparessizebytes starting fromoffsetin this Buffer with the memory inmem.static Buffermemdup(@org.jspecify.annotations.Nullable byte @Nullable [] data) Creates a new buffer of sizesizeand fills it with a copy ofdata.longmemset(long offset, byte val, long size) Fillsbufwithsizebytes withvalstarting fromoffset.intnMemory()Gets the amount of memory blocks that this buffer has.@Nullable MemorypeekMemory(int idx) Gets the memory block atidxinbuffer.The memory block stays valid until the memory block in this Buffer is removed, replaced or merged, typically with any call that modifies the memory inbuffer.voidprependMemory(Memory mem) Prepends the memory blockmemtobuffer.This function takes ownership ofmemand thus doesn't increase its refcount.readDts()Read the value of the fielddts.Read the value of the fieldduration.@Nullable MiniObjectRead the value of the fieldmini_object.longRead the value of the fieldoffset.longRead the value of the fieldoffset_end.readPool()Read the value of the fieldpool.readPts()Read the value of the fieldpts.ref()Increases the refcount of the given buffer by one.voidRemoves all the memory blocks inbuffer.voidremoveMemory(int idx) Removes the memory block inbat indexi.voidremoveMemoryRange(int idx, int length) Removeslengthmemory blocks in this Buffer starting fromidx.booleanremoveMeta(Meta meta) Removes the metadata formetaonbuffer.static booleanModifies a pointer to aGstBufferto point to a differentGstBuffer.voidreplaceAllMemory(Memory mem) Replaces all memory in this Buffer withmem.voidreplaceMemory(int idx, Memory mem) Replaces the memory block at indexidxin this Buffer withmem.voidreplaceMemoryRange(int idx, int length, Memory mem) Replaceslengthmemory blocks in this Buffer starting atidxwithmem.voidresize(long offset, long size) Sets the offset and total size of the memory blocks inbuffer.booleanresizeRange(int idx, int length, long offset, long size) Sets the total size of thelengthmemory blocks starting atidxin this BufferbooleansetFlags(Set<BufferFlags> flags) Sets one or more buffer flags on a buffer.booleansetFlags(BufferFlags... flags) Sets one or more buffer flags on a buffer.voidsetSize(long size) Sets the total size of the memory blocks inbuffer.voidReleases the memory previously mapped with gst_buffer_map().voidunref()Decreases the refcount of the buffer.booleanunsetFlags(Set<BufferFlags> flags) Clears one or more buffer flags.booleanunsetFlags(BufferFlags... flags) Clears one or more buffer flags.static Bufferwrapped(@org.jspecify.annotations.Nullable byte @Nullable [] data) Creates a new buffer that wraps the givendata.The memory will be freed with g_free() and will be marked writable.static BufferwrappedBytes(byte[] bytes) Creates a newGstBufferthat wraps the givenbytes.The data insidebytescannot benulland the resulting buffer will be marked as read only.static BufferwrappedFull(Set<MemoryFlags> flags, @org.jspecify.annotations.Nullable byte @Nullable [] data, long maxsize, long offset) Allocates a new buffer that wraps the given memory.static BufferwrappedFull(MemoryFlags flags, @org.jspecify.annotations.Nullable byte @Nullable [] data, long maxsize, long offset) Allocates a new buffer that wraps the given memory.voidWrite a value in the fielddts.voidwriteDuration(ClockTime duration) Write a value in the fieldduration.voidwriteMiniObject(@Nullable MiniObject miniObject) Write a value in the fieldmini_object.voidwriteOffset(long offset) Write a value in the fieldoffset.voidwriteOffsetEnd(long offsetEnd) Write a value in the fieldoffset_end.voidwritePool(BufferPool pool) Write a value in the fieldpool.voidWrite a value in the fieldpts.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Buffer
Create a Buffer proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Buffer
public Buffer()Creates a newly allocated buffer without any data.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readMiniObject
Read the value of the fieldmini_object.- Returns:
- The value of the field
mini_object
-
writeMiniObject
Write a value in the fieldmini_object.- Parameters:
miniObject- The new value for the fieldmini_object
-
readPool
-
writePool
Write a value in the fieldpool.- Parameters:
pool- The new value for the fieldpool
-
readPts
-
writePts
Write a value in the fieldpts.- Parameters:
pts- The new value for the fieldpts
-
readDts
-
writeDts
Write a value in the fielddts.- Parameters:
dts- The new value for the fielddts
-
readDuration
Read the value of the fieldduration.- Returns:
- The value of the field
duration
-
writeDuration
Write a value in the fieldduration.- Parameters:
duration- The new value for the fieldduration
-
readOffset
public long readOffset()Read the value of the fieldoffset.- Returns:
- The value of the field
offset
-
writeOffset
public void writeOffset(long offset) Write a value in the fieldoffset.- Parameters:
offset- The new value for the fieldoffset
-
readOffsetEnd
public long readOffsetEnd()Read the value of the fieldoffset_end.- Returns:
- The value of the field
offset_end
-
writeOffsetEnd
public void writeOffsetEnd(long offsetEnd) Write a value in the fieldoffset_end.- Parameters:
offsetEnd- The new value for the fieldoffset_end
-
allocate
public static Buffer allocate(@Nullable Allocator allocator, long size, @Nullable AllocationParams params) Tries to create a newly allocated buffer with data of the given size and extra parameters fromallocator.If the requested amount of memory can't be allocated,nullwill be returned. The allocated buffer memory is not cleared.When
allocatorisnull, the default memory allocator will be used.Note that when
size== 0, the buffer will not have memory associated with it.- Parameters:
allocator- theGstAllocatorto use, ornullto use the default allocatorsize- the size in bytes of the new buffer's data.params- optional parameters- Returns:
- a new
GstBuffer
-
memdup
Creates a new buffer of sizesizeand fills it with a copy ofdata.- Parameters:
data- data to copy into new buffer- Returns:
- a new
GstBuffer - Since:
- 1.20
-
wrapped
Creates a new buffer that wraps the givendata.The memory will be freed with g_free() and will be marked writable.- Parameters:
data- data to wrap- Returns:
- a new
GstBuffer
-
wrappedBytes
Creates a newGstBufferthat wraps the givenbytes.The data insidebytescannot benulland the resulting buffer will be marked as read only.- Parameters:
bytes- aGBytesto wrap- Returns:
- a new
GstBufferwrappingbytes - Since:
- 1.16
-
wrappedFull
public static Buffer wrappedFull(Set<MemoryFlags> flags, @org.jspecify.annotations.Nullable byte @Nullable [] data, long maxsize, long offset) Allocates a new buffer that wraps the given memory.datamust point tomaxsizeof memory, the wrapped buffer will have the region fromoffsetandsizevisible.When the buffer is destroyed,
notifywill be called withuserData.The prefix/padding must be filled with 0 if
flagscontainsGST_MEMORY_FLAG_ZERO_PREFIXEDandGST_MEMORY_FLAG_ZERO_PADDEDrespectively.- Parameters:
flags-GstMemoryFlagsdata- data to wrapmaxsize- allocated size ofdataoffset- offset indata- Returns:
- a new
GstBuffer
-
wrappedFull
public static Buffer wrappedFull(MemoryFlags flags, @org.jspecify.annotations.Nullable byte @Nullable [] data, long maxsize, long offset) Allocates a new buffer that wraps the given memory.datamust point tomaxsizeof memory, the wrapped buffer will have the region fromoffsetandsizevisible.When the buffer is destroyed,
notifywill be called withuserData.The prefix/padding must be filled with 0 if
flagscontainsGST_MEMORY_FLAG_ZERO_PREFIXEDandGST_MEMORY_FLAG_ZERO_PADDEDrespectively.- Parameters:
flags-GstMemoryFlagsdata- data to wrapmaxsize- allocated size ofdataoffset- offset indata- Returns:
- a new
GstBuffer
-
getMaxMemory
public static int getMaxMemory()Gets the maximum amount of memory blocks that a buffer can hold. This is a compile time constant that can be queried with the function.When more memory blocks are added, existing memory blocks will be merged together to make room for the new block.
- Returns:
- the maximum amount of memory blocks that a buffer can hold.
- Since:
- 1.2
-
replace
Modifies a pointer to aGstBufferto point to a differentGstBuffer. The modification is done atomically (so this is useful for ensuring thread safety in some cases), and the reference counts are updated appropriately (the old buffer is unreffed, the new is reffed).Either
nbufor theGstBufferpointed to byobufmay benull.- Parameters:
obuf- pointer to a pointer to aGstBufferto be replaced.nbuf- pointer to aGstBufferthat will replace the buffer pointed to byobuf.- Returns:
truewhenobufwas different fromnbuf.
-
addCustomMeta
Creates and adds aGstCustomMetafor the desiredname.namemust have been successfully registered with gst_meta_register_custom().- Parameters:
name- the registered name of the desired custom meta- Returns:
- The
GstCustomMetathat was added to the buffer - Since:
- 1.20
-
addMeta
Adds metadata forinfoto this Buffer using the parameters inparams.- Parameters:
info- aGstMetaInfoparams- params forinfo- Returns:
- the metadata for the api in
infoonbuffer.
-
addParentBufferMeta
Adds aGstParentBufferMetato this Buffer that holds a reference onrefuntil the buffer is freed.- Parameters:
ref- aGstBufferto ref- Returns:
- The
GstParentBufferMetathat was added to the buffer - Since:
- 1.6
-
addProtectionMeta
Attaches protection metadata to aGstBuffer.- Parameters:
info- aGstStructureholding cryptographic information relating to the sample contained inbuffer.This function takes ownership ofinfo.- Returns:
- a pointer to the added
GstProtectionMetaif successful - Since:
- 1.6
-
addReferenceTimestampMeta
public @Nullable ReferenceTimestampMeta addReferenceTimestampMeta(Caps reference, ClockTime timestamp, ClockTime duration) Adds aGstReferenceTimestampMetato this Buffer that holds atimestampand optionallydurationbased on a specific timestampreference.See the documentation ofGstReferenceTimestampMetafor details.- Parameters:
reference- identifier for the timestamp reference.timestamp- timestampduration- duration, orGST_CLOCK_TIME_NONE- Returns:
- The
GstReferenceTimestampMetathat was added to the buffer - Since:
- 1.14
-
append
-
appendMemory
Appends the memory blockmemtobuffer.This function takes ownership ofmemand thus doesn't increase its refcount.This function is identical to gst_buffer_insert_memory() with an index of -1. See gst_buffer_insert_memory() for more details.
- Parameters:
mem- aGstMemory.
-
appendRegion
Appendssizebytes atoffsetfrombuf2tobuf1.The result buffer will contain a concatenation of the memory of this Buffer and the requested region ofbuf2.- Parameters:
buf2- the second sourceGstBufferto append.offset- the offset inbuf2size- the size or -1 ofbuf2- Returns:
- the new
GstBufferthat contains the memory of the two source buffers.
-
copy
Creates a copy of the given buffer. This will only copy the buffer's data to a newly allocated memory if needed (if the type of memory requires it), otherwise the underlying data is just referenced. Check gst_buffer_copy_deep() if you want to force the data to be copied to newly allocated memory.- Returns:
- a new copy of this Buffer if the copy succeeded,
nullotherwise.
-
copyDeep
Creates a copy of the given buffer. This will make a newly allocated copy of the data the source buffer contains.- Returns:
- a new copy of this Buffer if the copy succeeded,
nullotherwise. - Since:
- 1.6
-
copyInto
Copies the information fromsrcintodest.If this Buffer already contains memory and
flagscontains GST_BUFFER_COPY_MEMORY, the memory fromsrcwill be appended todest.flagsindicate which fields will be copied.- Parameters:
src- a sourceGstBufferflags- flags indicating what metadata fields should be copied.offset- offset to copy fromsize- total size to copy. If -1, all data is copied.- Returns:
trueif the copying succeeded,falseotherwise.
-
copyInto
Copies the information fromsrcintodest.If this Buffer already contains memory and
flagscontains GST_BUFFER_COPY_MEMORY, the memory fromsrcwill be appended todest.flagsindicate which fields will be copied.- Parameters:
src- a sourceGstBufferflags- flags indicating what metadata fields should be copied.offset- offset to copy fromsize- total size to copy. If -1, all data is copied.- Returns:
trueif the copying succeeded,falseotherwise.
-
copyRegion
Creates a sub-buffer from this Buffer atoffsetandsize.This sub-buffer uses the actual memory space of the parent buffer. This function will copy the offset and timestamp fields when the offset is 0. If not, they will be set toGST_CLOCK_TIME_NONEandGST_BUFFER_OFFSET_NONE. Ifoffsetequals 0 andsizeequals the total size ofbuffer,the duration and offset end fields are also copied. If not they will be set toGST_CLOCK_TIME_NONEandGST_BUFFER_OFFSET_NONE.- Parameters:
flags- theGstBufferCopyFlagsoffset- the offset into parentGstBufferat which the new sub-buffer begins.size- the size of the newGstBuffersub-buffer, in bytes. If -1, all data is copied.- Returns:
- the new
GstBufferornullif copying failed.
-
copyRegion
Creates a sub-buffer from this Buffer atoffsetandsize.This sub-buffer uses the actual memory space of the parent buffer. This function will copy the offset and timestamp fields when the offset is 0. If not, they will be set toGST_CLOCK_TIME_NONEandGST_BUFFER_OFFSET_NONE. Ifoffsetequals 0 andsizeequals the total size ofbuffer,the duration and offset end fields are also copied. If not they will be set toGST_CLOCK_TIME_NONEandGST_BUFFER_OFFSET_NONE.- Parameters:
flags- theGstBufferCopyFlagsoffset- the offset into parentGstBufferat which the new sub-buffer begins.size- the size of the newGstBuffersub-buffer, in bytes. If -1, all data is copied.- Returns:
- the new
GstBufferornullif copying failed.
-
extract
Copiessizebytes starting fromoffsetin this Buffer todest.- Parameters:
offset- the offset to extractdest- the destination address- Returns:
- The amount of bytes extracted. This value can be lower than
sizewhen this Buffer did not contain enough data.
-
extractDup
Extracts a copy of at mostsizebytes the data atoffsetinto newly-allocated memory.destmust be freed using g_free() when done.- Parameters:
offset- the offset to extractsize- the size to extractdest- A pointer where the destination array will be written. Might benullif the size is 0.- Since:
- 1.0.10
-
fill
public long fill(long offset, @org.jspecify.annotations.Nullable byte @Nullable [] src) Copiessizebytes fromsrcto this Buffer atoffset.- Parameters:
offset- the offset to fillsrc- the source address- Returns:
- The amount of bytes copied. This value can be lower than
sizewhen this Buffer did not contain enough data.
-
findMemory
public boolean findMemory(long offset, long size, Out<Integer> idx, Out<Integer> length, Out<Long> skip) Finds the memory blocks that spansizebytes starting fromoffsetinbuffer.When this function returns
true,idxwill contain the index of the first memory block where the byte foroffsetcan be found andlengthcontains the number of memory blocks containing thesizeremaining bytes.skipcontains the number of bytes to skip in the memory block atidxto get to the byte foroffset.sizecan be -1 to get all the memory blocks afteridx.- Parameters:
offset- an offsetsize- a sizeidx- pointer to indexlength- pointer to lengthskip- pointer to skip- Returns:
truewhensizebytes starting fromoffsetcould be found in this Buffer andidx,lengthandskipwill be filled.
-
foreachMeta
CallsfuncwithuserDatafor each meta inbuffer.funccan modify the passed meta pointer or its contents. The return value offuncdefines if this function returns or if the remaining metadata items in the buffer should be skipped.- Parameters:
func- aGstBufferForeachMetaFuncto call- Returns:
falsewhenfuncreturnedfalsefor one of the metadata.
-
getAllMemory
Gets all the memory blocks inbuffer.The memory blocks will be merged into one largeGstMemory.- Returns:
- a
GstMemorythat contains the merged memory.
-
getCustomMeta
Finds the firstGstCustomMetaon this Buffer for the desiredname.- Parameters:
name- the registered name of the custom meta to retrieve.- Returns:
- the
GstCustomMeta - Since:
- 1.20
-
getFlags
Gets theGstBufferFlagsflags set on this buffer.- Returns:
- the flags set on this buffer.
- Since:
- 1.10
-
getMemory
Gets the memory block at indexidxinbuffer.- Parameters:
idx- an index- Returns:
- a
GstMemorythat contains the data of the memory block atidx.
-
getMemoryRange
Getslengthmemory blocks in this Buffer starting atidx.The memory blocks will be merged into one largeGstMemory.If
lengthis -1, all memory starting fromidxis merged.- Parameters:
idx- an indexlength- a length- Returns:
- a
GstMemorythat contains the merged data oflengthblocks starting atidx.
-
getMeta
Gets the metadata forapion buffer. When there is no such metadata,nullis returned. If multiple metadata with the givenapiare attached to this buffer only the first one is returned. To handle multiple metadata with a given API use gst_buffer_iterate_meta() or gst_buffer_foreach_meta() instead and check themeta->info.apimember for the API type.- Parameters:
api- theGTypeof an API- Returns:
- the metadata for
apionbuffer.
-
getNMeta
-
getReferenceTimestampMeta
Finds the firstGstReferenceTimestampMetaon this Buffer that conforms toreference.Conformance is tested by checking if the meta's reference is a subset ofreference.Buffers can contain multiple
GstReferenceTimestampMetametadata items.- Parameters:
reference- a referenceGstCaps- Returns:
- the
GstReferenceTimestampMetaornullwhen there is no such metadata onbuffer. - Since:
- 1.14
-
getSize
public long getSize()Gets the total size of the memory blocks inbuffer.- Returns:
- total size of the memory blocks in
buffer.
-
getSizes
Gets the total size of the memory blocks inbuffer.When not
null,offsetwill contain the offset of the data in the first memory block in this Buffer andmaxsizewill contain the sum of the size andoffsetand the amount of extra padding on the last memory block.offsetandmaxsizecan be used to resize the buffer memory blocks with gst_buffer_resize().- Parameters:
offset- a pointer to the offsetmaxsize- a pointer to the maxsize- Returns:
- total size of the memory blocks in
buffer.
-
getSizesRange
public long getSizesRange(int idx, int length, @Nullable Out<Long> offset, @Nullable Out<Long> maxsize) Gets the total size oflengthmemory blocks stating fromidxinbuffer.When not
null,offsetwill contain the offset of the data in the memory block in this Buffer atidxandmaxsizewill contain the sum of the size andoffsetand the amount of extra padding on the memory block atidx+length-1.offsetandmaxsizecan be used to resize the buffer memory blocks with gst_buffer_resize_range().- Parameters:
idx- an indexlength- a lengthoffset- a pointer to the offsetmaxsize- a pointer to the maxsize- Returns:
- total size of
lengthmemory blocks starting atidxinbuffer.
-
hasFlags
Gives the status of a specific flag on a buffer.- Parameters:
flags- theGstBufferFlagsflag to check.- Returns:
trueif all flags inflagsare found onbuffer.- Since:
- 1.10
-
hasFlags
Gives the status of a specific flag on a buffer.- Parameters:
flags- theGstBufferFlagsflag to check.- Returns:
trueif all flags inflagsare found onbuffer.- Since:
- 1.10
-
insertMemory
Inserts the memory blockmeminto this Buffer atidx.This function takes ownership ofmemand thus doesn't increase its refcount.Only gst_buffer_get_max_memory() can be added to a buffer. If more memory is added, existing memory blocks will automatically be merged to make room for the new memory.
- Parameters:
idx- the index to add the memory at, or -1 to append it to the endmem- aGstMemory.
-
isAllMemoryWritable
public boolean isAllMemoryWritable()Checks if all memory blocks in this Buffer are writable.Note that this function does not check if this Buffer is writable, use gst_buffer_is_writable() to check that if needed.
- Returns:
trueif all memory blocks in this Buffer are writable- Since:
- 1.4
-
isMemoryRangeWritable
public boolean isMemoryRangeWritable(int idx, int length) Checks iflengthmemory blocks in this Buffer starting fromidxare writable.lengthcan be -1 to check all the memory blocks afteridx.Note that this function does not check if this Buffer is writable, use gst_buffer_is_writable() to check that if needed.
- Parameters:
idx- an indexlength- a length, should not be 0- Returns:
trueif the memory range is writable- Since:
- 1.4
-
iterateMeta
Retrieves the nextGstMetaaftercurrent.Ifstatepoints tonull, the first metadata is returned.statewill be updated with an opaque state pointer- Parameters:
state- an opaque state pointer- Returns:
- The next
GstMetaornullwhen there are no more items.
-
iterateMetaFiltered
Retrieves the nextGstMetaof typemetaApiTypeafter the current one according tostate.Ifstatepoints tonull, the first metadata of typemetaApiTypeis returned.statewill be updated with an opaque state pointer- Parameters:
state- an opaque state pointermetaApiType- only returnGstMetaof this type- Returns:
- The next
GstMetaof typemetaApiTypeornullwhen there are no more items. - Since:
- 1.12
-
map
Fillsinfowith theGstMapInfoof all merged memory blocks inbuffer.flagsdescribe the desired access of the memory. WhenflagsisGST_MAP_WRITE, this Buffer should be writable (as returned from gst_buffer_is_writable()).When this Buffer is writable but the memory isn't, a writable copy will automatically be created and returned. The readonly copy of the buffer memory will then also be replaced with this writable copy.
The memory in
infoshould be unmapped with gst_buffer_unmap() after usage.- Parameters:
info- info about the mappingflags- flags for the mapping- Returns:
trueif the map succeeded andinfocontains valid data.
-
mapRange
Fillsinfowith theGstMapInfooflengthmerged memory blocks starting atidxinbuffer.Whenlengthis -1, all memory blocks starting fromidxare merged and mapped.flagsdescribe the desired access of the memory. WhenflagsisGST_MAP_WRITE, this Buffer should be writable (as returned from gst_buffer_is_writable()).When this Buffer is writable but the memory isn't, a writable copy will automatically be created and returned. The readonly copy of the buffer memory will then also be replaced with this writable copy.
The memory in
infoshould be unmapped with gst_buffer_unmap() after usage.- Parameters:
idx- an indexlength- a lengthinfo- info about the mappingflags- flags for the mapping- Returns:
trueif the map succeeded andinfocontains valid data.
-
memcmp
public int memcmp(long offset, @org.jspecify.annotations.Nullable byte @Nullable [] mem) Comparessizebytes starting fromoffsetin this Buffer with the memory inmem.- Parameters:
offset- the offset in this Buffermem- the memory to compare- Returns:
- 0 if the memory is equal.
-
memset
public long memset(long offset, byte val, long size) Fillsbufwithsizebytes withvalstarting fromoffset.- Parameters:
offset- the offset in this Bufferval- the value to setsize- the size to set- Returns:
- The amount of bytes filled. This value can be lower than
sizewhen this Buffer did not contain enough data.
-
nMemory
public int nMemory()Gets the amount of memory blocks that this buffer has. This amount is never larger than what gst_buffer_get_max_memory() returns.- Returns:
- the number of memory blocks this buffer is made of.
-
peekMemory
Gets the memory block atidxinbuffer.The memory block stays valid until the memory block in this Buffer is removed, replaced or merged, typically with any call that modifies the memory inbuffer.- Parameters:
idx- an index- Returns:
- the
GstMemoryatidx.
-
prependMemory
Prepends the memory blockmemtobuffer.This function takes ownership ofmemand thus doesn't increase its refcount.This function is identical to gst_buffer_insert_memory() with an index of 0. See gst_buffer_insert_memory() for more details.
- Parameters:
mem- aGstMemory.
-
ref
Increases the refcount of the given buffer by one.Note that the refcount affects the writability of this Buffer and its metadata, see gst_buffer_is_writable(). It is important to note that keeping additional references to GstBuffer instances can potentially increase the number of
memcpyoperations in a pipeline.- Returns:
- this Buffer
-
removeAllMemory
public void removeAllMemory()Removes all the memory blocks inbuffer. -
removeMemory
public void removeMemory(int idx) Removes the memory block inbat indexi.- Parameters:
idx- an index
-
removeMemoryRange
public void removeMemoryRange(int idx, int length) Removeslengthmemory blocks in this Buffer starting fromidx.lengthcan be -1, in which case all memory starting fromidxis removed.- Parameters:
idx- an indexlength- a length
-
removeMeta
Removes the metadata formetaonbuffer.- Parameters:
meta- aGstMeta- Returns:
trueif the metadata existed and was removed,falseif no such metadata was onbuffer.
-
replaceAllMemory
Replaces all memory in this Buffer withmem.- Parameters:
mem- aGstMemory
-
replaceMemory
Replaces the memory block at indexidxin this Buffer withmem.- Parameters:
idx- an indexmem- aGstMemory
-
replaceMemoryRange
Replaceslengthmemory blocks in this Buffer starting atidxwithmem.If
lengthis -1, all memory starting fromidxwill be removed and replaced withmem.this Buffer should be writable.
- Parameters:
idx- an indexlength- a length, should not be 0mem- aGstMemory
-
resize
public void resize(long offset, long size) Sets the offset and total size of the memory blocks inbuffer.- Parameters:
offset- the offset adjustmentsize- the new size or -1 to just adjust the offset
-
resizeRange
public boolean resizeRange(int idx, int length, long offset, long size) Sets the total size of thelengthmemory blocks starting atidxin this Buffer- Parameters:
idx- an indexlength- a lengthoffset- the offset adjustmentsize- the new size or -1 to just adjust the offset- Returns:
trueif resizing succeeded,falseotherwise.
-
setFlags
Sets one or more buffer flags on a buffer.- Parameters:
flags- theGstBufferFlagsto set.- Returns:
trueifflagswere successfully set on buffer.- Since:
- 1.10
-
setFlags
Sets one or more buffer flags on a buffer.- Parameters:
flags- theGstBufferFlagsto set.- Returns:
trueifflagswere successfully set on buffer.- Since:
- 1.10
-
setSize
public void setSize(long size) Sets the total size of the memory blocks inbuffer.- Parameters:
size- the new size
-
unmap
Releases the memory previously mapped with gst_buffer_map().- Parameters:
info- aGstMapInfo
-
unref
public void unref()Decreases the refcount of the buffer. If the refcount reaches 0, the buffer with the associated metadata and memory will be freed. -
unsetFlags
Clears one or more buffer flags.- Parameters:
flags- theGstBufferFlagsto clear- Returns:
- true if
flagsis successfully cleared from buffer. - Since:
- 1.10
-
unsetFlags
Clears one or more buffer flags.- Parameters:
flags- theGstBufferFlagsto clear- Returns:
- true if
flagsis successfully cleared from buffer. - Since:
- 1.10
-