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
ConstructorDescriptionBuffer()
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 TypeMethodDescriptionaddCustomMeta
(String name) Creates and adds aGstCustomMeta
for the desiredname
.addMeta
(MetaInfo info, @Nullable MemorySegment params) Adds metadata forinfo
to this Buffer using the parameters inparams
.Adds aGstParentBufferMeta
to this Buffer that holds a reference onref
until the buffer is freed.addProtectionMeta
(Structure info) Attaches protection metadata to aGstBuffer
.addReferenceTimestampMeta
(Caps reference, ClockTime timestamp, ClockTime duration) Adds aGstReferenceTimestampMeta
to this Buffer that holds atimestamp
and optionallyduration
based on a specific timestampreference
.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
.Appends all the memory frombuf2
to this Buffer.void
appendMemory
(Memory mem) Appends the memory blockmem
to this Buffer.appendRegion
(Buffer buf2, long offset, long size) Appendssize
bytes atoffset
frombuf2
to this Buffer.copy()
Creates a copy of the given buffer.copyDeep()
Creates a copy of the given buffer.boolean
copyInto
(Buffer src, Set<BufferCopyFlags> flags, long offset, long size) Copies the information fromsrc
into this Buffer.boolean
copyInto
(Buffer src, BufferCopyFlags flags, long offset, long size) Copies the information fromsrc
into this Buffer.copyRegion
(Set<BufferCopyFlags> flags, long offset, long size) Creates a sub-buffer from this Buffer atoffset
andsize
.copyRegion
(BufferCopyFlags flags, long offset, long size) Creates a sub-buffer from this Buffer atoffset
andsize
.long
Copiessize
bytes starting fromoffset
in this Buffer todest
.void
extractDup
(long offset, long size, Out<byte[]> dest) Extracts a copy of at mostsize
bytes the data atoffset
into newly-allocated memory.long
fill
(long offset, byte[] src) Copiessize
bytes fromsrc
to this Buffer atoffset
.boolean
Finds the memory blocks that spansize
bytes starting fromoffset
in this Buffer.boolean
Callsfunc
withuserData
for each meta in this Buffer.Gets all the memory blocks in this Buffer.getCustomMeta
(String name) Finds the firstGstCustomMeta
on this Buffer for the desiredname
.getFlags()
Gets theGstBufferFlags
flags set on this buffer.static int
Gets the maximum amount of memory blocks that a buffer can hold.getMemory
(int idx) Gets the memory block at indexidx
in this Buffer.static MemoryLayout
The memory layout of the native struct.getMemoryRange
(int idx, int length) Getslength
memory blocks in this Buffer starting atidx
.Gets the metadata forapi
on buffer.int
getReferenceTimestampMeta
(@Nullable Caps reference) Finds the firstGstReferenceTimestampMeta
on this Buffer that conforms toreference
.long
getSize()
Gets the total size of the memory blocks in this Buffer.long
Gets the total size of the memory blocks in this Buffer.long
getSizesRange
(int idx, int length, @Nullable Out<Long> offset, @Nullable Out<Long> maxsize) Gets the total size oflength
memory blocks stating fromidx
in this Buffer.static Type
getType()
Get the GType of the Buffer classboolean
hasFlags
(Set<BufferFlags> flags) Gives the status of a specific flag on a buffer.boolean
hasFlags
(BufferFlags... flags) Gives the status of a specific flag on a buffer.void
insertMemory
(int idx, Memory mem) Inserts the memory blockmem
into this Buffer atidx
.boolean
Checks if all memory blocks in this Buffer are writable.boolean
isMemoryRangeWritable
(int idx, int length) Checks iflength
memory blocks in this Buffer starting fromidx
are writable.iterateMeta
(@Nullable Out<MemorySegment> state) Retrieves the nextGstMeta
aftercurrent
.iterateMetaFiltered
(@Nullable Out<MemorySegment> state, Type metaApiType) Retrieves the nextGstMeta
of typemetaApiType
after the current one according tostate
.boolean
Fillsinfo
with theGstMapInfo
of all merged memory blocks in this Buffer.boolean
Fillsinfo
with theGstMapInfo
of all merged memory blocks in this Buffer.boolean
Fillsinfo
with theGstMapInfo
oflength
merged memory blocks starting atidx
in this Buffer.boolean
Fillsinfo
with theGstMapInfo
oflength
merged memory blocks starting atidx
in this Buffer.int
memcmp
(long offset, byte[] mem) Comparessize
bytes starting fromoffset
in this Buffer with the memory inmem
.static Buffer
memdup
(byte[] data) Creates a new buffer of sizesize
and fills it with a copy ofdata
.long
memset
(long offset, byte val, long size) Fillsbuf
withsize
bytes withval
starting fromoffset
.int
nMemory()
Gets the amount of memory blocks that this buffer has.peekMemory
(int idx) Gets the memory block atidx
in this Buffer.void
prependMemory
(Memory mem) Prepends the memory blockmem
to this Buffer.readDts()
Read the value of the fielddts
.Read the value of the fieldduration
.Read the value of the fieldmini_object
.long
Read the value of the fieldoffset
.long
Read 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.void
Removes all the memory blocks in this Buffer.void
removeMemory
(int idx) Removes the memory block inb
at indexi
.void
removeMemoryRange
(int idx, int length) Removeslength
memory blocks in this Buffer starting fromidx
.boolean
removeMeta
(Meta meta) Removes the metadata formeta
on this Buffer.static boolean
Modifies a pointer to aGstBuffer
to point to a differentGstBuffer
.void
replaceAllMemory
(Memory mem) Replaces all memory in this Buffer withmem
.void
replaceMemory
(int idx, Memory mem) Replaces the memory block at indexidx
in this Buffer withmem
.void
replaceMemoryRange
(int idx, int length, Memory mem) Replaceslength
memory blocks in this Buffer starting atidx
withmem
.void
resize
(long offset, long size) Sets the offset and total size of the memory blocks in this Buffer.boolean
resizeRange
(int idx, int length, long offset, long size) Sets the total size of thelength
memory blocks starting atidx
in this Bufferboolean
setFlags
(Set<BufferFlags> flags) Sets one or more buffer flags on a buffer.boolean
setFlags
(BufferFlags... flags) Sets one or more buffer flags on a buffer.void
setSize
(long size) Sets the total size of the memory blocks in this Buffer.void
Releases the memory previously mapped with gst_buffer_map().void
unref()
Decreases the refcount of the buffer.boolean
unsetFlags
(Set<BufferFlags> flags) Clears one or more buffer flags.boolean
unsetFlags
(BufferFlags... flags) Clears one or more buffer flags.static Buffer
wrapped
(byte[] data) Creates a new buffer that wraps the givendata
.static Buffer
wrappedBytes
(Bytes bytes) Creates a newGstBuffer
that wraps the givenbytes
.static Buffer
wrappedFull
(Set<MemoryFlags> flags, byte[] data, long maxsize, long offset) Allocates a new buffer that wraps the given memory.static Buffer
wrappedFull
(MemoryFlags flags, byte[] data, long maxsize, long offset) Allocates a new buffer that wraps the given memory.void
Write a value in the fielddts
.void
writeDuration
(ClockTime duration) Write a value in the fieldduration
.void
writeMiniObject
(MiniObject miniObject) Write a value in the fieldmini_object
.void
writeOffset
(long offset) Write a value in the fieldoffset
.void
writeOffsetEnd
(long offsetEnd) Write a value in the fieldoffset_end
.void
writePool
(BufferPool pool) Write a value in the fieldpool
.void
Write a value in the fieldpts
.Methods inherited from class io.github.jwharm.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 @Nullable Allocator allocator, long size, @Nullable @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,null
will be returned. The allocated buffer memory is not cleared.When
allocator
isnull
, the default memory allocator will be used.Note that when
size
== 0, the buffer will not have memory associated with it.- Parameters:
allocator
- theGstAllocator
to use, ornull
to 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 sizesize
and fills it with a copy ofdata
.- Parameters:
data
- data to copy into new buffer- Returns:
- a new
GstBuffer
-
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
-
wrappedFull
Allocates a new buffer that wraps the given memory.data
must point tomaxsize
of memory, the wrapped buffer will have the region fromoffset
andsize
visible.When the buffer is destroyed,
notify
will be called withuserData
.The prefix/padding must be filled with 0 if
flags
containsGST_MEMORY_FLAG_ZERO_PREFIXED
andGST_MEMORY_FLAG_ZERO_PADDED
respectively.- Parameters:
flags
-GstMemoryFlags
data
- data to wrapmaxsize
- allocated size ofdata
offset
- offset indata
- Returns:
- a new
GstBuffer
-
wrappedFull
Allocates a new buffer that wraps the given memory.data
must point tomaxsize
of memory, the wrapped buffer will have the region fromoffset
andsize
visible.When the buffer is destroyed,
notify
will be called withuserData
.The prefix/padding must be filled with 0 if
flags
containsGST_MEMORY_FLAG_ZERO_PREFIXED
andGST_MEMORY_FLAG_ZERO_PADDED
respectively.- Parameters:
flags
-GstMemoryFlags
data
- data to wrapmaxsize
- allocated size ofdata
offset
- 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.
-
replace
public static boolean replace(@Nullable @Nullable Out<Buffer> obuf, @Nullable @Nullable Buffer nbuf) Modifies a pointer to aGstBuffer
to 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
nbuf
or theGstBuffer
pointed to byobuf
may benull
.- Parameters:
obuf
- pointer to a pointer to aGstBuffer
to be replaced.nbuf
- pointer to aGstBuffer
that will replace the buffer pointed to byobuf
.- Returns:
true
whenobuf
was different fromnbuf
.
-
addCustomMeta
Creates and adds aGstCustomMeta
for the desiredname
.name
must have been successfully registered with gst_meta_register_custom().- Parameters:
name
- the registered name of the desired custom meta- Returns:
- The
GstCustomMeta
that was added to the buffer
-
addMeta
Adds metadata forinfo
to this Buffer using the parameters inparams
.- Parameters:
info
- aGstMetaInfo
params
- params forinfo
- Returns:
- the metadata for the api in
info
on this Buffer.
-
addParentBufferMeta
Adds aGstParentBufferMeta
to this Buffer that holds a reference onref
until the buffer is freed.- Parameters:
ref
- aGstBuffer
to ref- Returns:
- The
GstParentBufferMeta
that was added to the buffer
-
addProtectionMeta
Attaches protection metadata to aGstBuffer
.- Parameters:
info
- aGstStructure
holding cryptographic information relating to the sample contained in this Buffer. This function takes ownership ofinfo
.- Returns:
- a pointer to the added
GstProtectionMeta
if successful
-
addReferenceTimestampMeta
public ReferenceTimestampMeta addReferenceTimestampMeta(Caps reference, ClockTime timestamp, ClockTime duration) Adds aGstReferenceTimestampMeta
to this Buffer that holds atimestamp
and optionallyduration
based on a specific timestampreference
. See the documentation ofGstReferenceTimestampMeta
for details.- Parameters:
reference
- identifier for the timestamp reference.timestamp
- timestampduration
- duration, orGST_CLOCK_TIME_NONE
- Returns:
- The
GstReferenceTimestampMeta
that was added to the buffer
-
append
Appends all the memory frombuf2
to this Buffer. The result buffer will contain a concatenation of the memory of this Buffer andbuf2
.- Parameters:
buf2
- the second sourceGstBuffer
to append.- Returns:
- the new
GstBuffer
that contains the memory of the two source buffers.
-
appendMemory
Appends the memory blockmem
to this Buffer. This function takes ownership ofmem
and 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
Appendssize
bytes atoffset
frombuf2
to this Buffer. The result buffer will contain a concatenation of the memory of this Buffer and the requested region ofbuf2
.- Parameters:
buf2
- the second sourceGstBuffer
to append.offset
- the offset inbuf2
size
- the size or -1 ofbuf2
- Returns:
- the new
GstBuffer
that 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,
null
otherwise.
-
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,
null
otherwise.
-
copyInto
Copies the information fromsrc
into this Buffer.If this Buffer already contains memory and
flags
contains GST_BUFFER_COPY_MEMORY, the memory fromsrc
will be appended to this Buffer.flags
indicate which fields will be copied.- Parameters:
src
- a sourceGstBuffer
flags
- flags indicating what metadata fields should be copied.offset
- offset to copy fromsize
- total size to copy. If -1, all data is copied.- Returns:
true
if the copying succeeded,false
otherwise.
-
copyInto
Copies the information fromsrc
into this Buffer.If this Buffer already contains memory and
flags
contains GST_BUFFER_COPY_MEMORY, the memory fromsrc
will be appended to this Buffer.flags
indicate which fields will be copied.- Parameters:
src
- a sourceGstBuffer
flags
- flags indicating what metadata fields should be copied.offset
- offset to copy fromsize
- total size to copy. If -1, all data is copied.- Returns:
true
if the copying succeeded,false
otherwise.
-
copyRegion
Creates a sub-buffer from this Buffer atoffset
andsize
. 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_NONE
andGST_BUFFER_OFFSET_NONE
. Ifoffset
equals 0 andsize
equals the total size ofbuffer
, the duration and offset end fields are also copied. If not they will be set toGST_CLOCK_TIME_NONE
andGST_BUFFER_OFFSET_NONE
.- Parameters:
flags
- theGstBufferCopyFlags
offset
- the offset into parentGstBuffer
at which the new sub-buffer begins.size
- the size of the newGstBuffer
sub-buffer, in bytes. If -1, all data is copied.- Returns:
- the new
GstBuffer
ornull
if copying failed.
-
copyRegion
Creates a sub-buffer from this Buffer atoffset
andsize
. 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_NONE
andGST_BUFFER_OFFSET_NONE
. Ifoffset
equals 0 andsize
equals the total size ofbuffer
, the duration and offset end fields are also copied. If not they will be set toGST_CLOCK_TIME_NONE
andGST_BUFFER_OFFSET_NONE
.- Parameters:
flags
- theGstBufferCopyFlags
offset
- the offset into parentGstBuffer
at which the new sub-buffer begins.size
- the size of the newGstBuffer
sub-buffer, in bytes. If -1, all data is copied.- Returns:
- the new
GstBuffer
ornull
if copying failed.
-
extract
Copiessize
bytes starting fromoffset
in this Buffer todest
.- Parameters:
offset
- the offset to extractdest
- the destination address- Returns:
- The amount of bytes extracted. This value can be lower than
size
when this Buffer did not contain enough data.
-
extractDup
Extracts a copy of at mostsize
bytes the data atoffset
into newly-allocated memory.dest
must 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 benull
if the size is 0.
-
fill
public long fill(long offset, byte[] src) Copiessize
bytes fromsrc
to this Buffer atoffset
.- Parameters:
offset
- the offset to fillsrc
- the source address- Returns:
- The amount of bytes copied. This value can be lower than
size
when 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 spansize
bytes starting fromoffset
in this Buffer.When this function returns
true
,idx
will contain the index of the first memory block where the byte foroffset
can be found andlength
contains the number of memory blocks containing thesize
remaining bytes.skip
contains the number of bytes to skip in the memory block atidx
to get to the byte foroffset
.size
can 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:
true
whensize
bytes starting fromoffset
could be found in this Buffer andidx
,length
andskip
will be filled.
-
foreachMeta
Callsfunc
withuserData
for each meta in this Buffer.func
can modify the passed meta pointer or its contents. The return value offunc
defines if this function returns or if the remaining metadata items in the buffer should be skipped.- Parameters:
func
- aGstBufferForeachMetaFunc
to call- Returns:
false
whenfunc
returnedfalse
for one of the metadata.
-
getAllMemory
Gets all the memory blocks in this Buffer. The memory blocks will be merged into one largeGstMemory
.- Returns:
- a
GstMemory
that contains the merged memory.
-
getCustomMeta
Finds the firstGstCustomMeta
on this Buffer for the desiredname
.- Parameters:
name
- the registered name of the custom meta to retrieve.- Returns:
- the
GstCustomMeta
-
getFlags
Gets theGstBufferFlags
flags set on this buffer.- Returns:
- the flags set on this buffer.
-
getMemory
Gets the memory block at indexidx
in this Buffer.- Parameters:
idx
- an index- Returns:
- a
GstMemory
that contains the data of the memory block atidx
.
-
getMemoryRange
Getslength
memory blocks in this Buffer starting atidx
. The memory blocks will be merged into one largeGstMemory
.If
length
is -1, all memory starting fromidx
is merged.- Parameters:
idx
- an indexlength
- a length- Returns:
- a
GstMemory
that contains the merged data oflength
blocks starting atidx
.
-
getMeta
Gets the metadata forapi
on buffer. When there is no such metadata,null
is returned. If multiple metadata with the givenapi
are 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.api
member for the API type.- Parameters:
api
- theGType
of an API- Returns:
- the metadata for
api
on this Buffer.
-
getNMeta
-
getReferenceTimestampMeta
Finds the firstGstReferenceTimestampMeta
on this Buffer that conforms toreference
. Conformance is tested by checking if the meta's reference is a subset ofreference
.Buffers can contain multiple
GstReferenceTimestampMeta
metadata items.- Parameters:
reference
- a referenceGstCaps
- Returns:
- the
GstReferenceTimestampMeta
ornull
when there is no such metadata on this Buffer.
-
getSize
public long getSize()Gets the total size of the memory blocks in this Buffer.- Returns:
- total size of the memory blocks in this Buffer.
-
getSizes
Gets the total size of the memory blocks in this Buffer.When not
null
,offset
will contain the offset of the data in the first memory block in this Buffer andmaxsize
will contain the sum of the size andoffset
and the amount of extra padding on the last memory block.offset
andmaxsize
can 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 this Buffer.
-
getSizesRange
public long getSizesRange(int idx, int length, @Nullable @Nullable Out<Long> offset, @Nullable @Nullable Out<Long> maxsize) Gets the total size oflength
memory blocks stating fromidx
in this Buffer.When not
null
,offset
will contain the offset of the data in the memory block in this Buffer atidx
andmaxsize
will contain the sum of the size andoffset
and the amount of extra padding on the memory block atidx
+length
-1.offset
andmaxsize
can 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
length
memory blocks starting atidx
in this Buffer.
-
hasFlags
Gives the status of a specific flag on a buffer.- Parameters:
flags
- theGstBufferFlags
flag to check.- Returns:
true
if all flags inflags
are found on this Buffer.
-
hasFlags
Gives the status of a specific flag on a buffer.- Parameters:
flags
- theGstBufferFlags
flag to check.- Returns:
true
if all flags inflags
are found on this Buffer.
-
insertMemory
Inserts the memory blockmem
into this Buffer atidx
. This function takes ownership ofmem
and 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:
true
if all memory blocks in this Buffer are writable
-
isMemoryRangeWritable
public boolean isMemoryRangeWritable(int idx, int length) Checks iflength
memory blocks in this Buffer starting fromidx
are writable.length
can 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:
true
if the memory range is writable
-
iterateMeta
Retrieves the nextGstMeta
aftercurrent
. Ifstate
points tonull
, the first metadata is returned.state
will be updated with an opaque state pointer- Parameters:
state
- an opaque state pointer- Returns:
- The next
GstMeta
ornull
when there are no more items.
-
iterateMetaFiltered
Retrieves the nextGstMeta
of typemetaApiType
after the current one according tostate
. Ifstate
points tonull
, the first metadata of typemetaApiType
is returned.state
will be updated with an opaque state pointer- Parameters:
state
- an opaque state pointermetaApiType
- only returnGstMeta
of this type- Returns:
- The next
GstMeta
of typemetaApiType
ornull
when there are no more items.
-
map
Fillsinfo
with theGstMapInfo
of all merged memory blocks in this Buffer.flags
describe the desired access of the memory. Whenflags
isGST_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
info
should be unmapped with gst_buffer_unmap() after usage.- Parameters:
info
- info about the mappingflags
- flags for the mapping- Returns:
true
if the map succeeded andinfo
contains valid data.
-
map
Fillsinfo
with theGstMapInfo
of all merged memory blocks in this Buffer.flags
describe the desired access of the memory. Whenflags
isGST_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
info
should be unmapped with gst_buffer_unmap() after usage.- Parameters:
info
- info about the mappingflags
- flags for the mapping- Returns:
true
if the map succeeded andinfo
contains valid data.
-
mapRange
Fillsinfo
with theGstMapInfo
oflength
merged memory blocks starting atidx
in this Buffer. Whenlength
is -1, all memory blocks starting fromidx
are merged and mapped.flags
describe the desired access of the memory. Whenflags
isGST_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
info
should be unmapped with gst_buffer_unmap() after usage.- Parameters:
idx
- an indexlength
- a lengthinfo
- info about the mappingflags
- flags for the mapping- Returns:
true
if the map succeeded andinfo
contains valid data.
-
mapRange
Fillsinfo
with theGstMapInfo
oflength
merged memory blocks starting atidx
in this Buffer. Whenlength
is -1, all memory blocks starting fromidx
are merged and mapped.flags
describe the desired access of the memory. Whenflags
isGST_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
info
should be unmapped with gst_buffer_unmap() after usage.- Parameters:
idx
- an indexlength
- a lengthinfo
- info about the mappingflags
- flags for the mapping- Returns:
true
if the map succeeded andinfo
contains valid data.
-
memcmp
public int memcmp(long offset, byte[] mem) Comparessize
bytes starting fromoffset
in 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) Fillsbuf
withsize
bytes withval
starting 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
size
when 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 atidx
in this Buffer. 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 in this Buffer.- Parameters:
idx
- an index- Returns:
- the
GstMemory
atidx
.
-
prependMemory
Prepends the memory blockmem
to this Buffer. This function takes ownership ofmem
and 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
memcpy
operations in a pipeline.- Returns:
- this Buffer
-
removeAllMemory
public void removeAllMemory()Removes all the memory blocks in this Buffer. -
removeMemory
public void removeMemory(int idx) Removes the memory block inb
at indexi
.- Parameters:
idx
- an index
-
removeMemoryRange
public void removeMemoryRange(int idx, int length) Removeslength
memory blocks in this Buffer starting fromidx
.length
can be -1, in which case all memory starting fromidx
is removed.- Parameters:
idx
- an indexlength
- a length
-
removeMeta
Removes the metadata formeta
on this Buffer.- Parameters:
meta
- aGstMeta
- Returns:
true
if the metadata existed and was removed,false
if no such metadata was on this Buffer.
-
replaceAllMemory
Replaces all memory in this Buffer withmem
.- Parameters:
mem
- aGstMemory
-
replaceMemory
Replaces the memory block at indexidx
in this Buffer withmem
.- Parameters:
idx
- an indexmem
- aGstMemory
-
replaceMemoryRange
Replaceslength
memory blocks in this Buffer starting atidx
withmem
.If
length
is -1, all memory starting fromidx
will 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 in this Buffer.- 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 thelength
memory blocks starting atidx
in this Buffer- Parameters:
idx
- an indexlength
- a lengthoffset
- the offset adjustmentsize
- the new size or -1 to just adjust the offset- Returns:
true
if resizing succeeded,false
otherwise.
-
setFlags
Sets one or more buffer flags on a buffer.- Parameters:
flags
- theGstBufferFlags
to set.- Returns:
true
ifflags
were successfully set on buffer.
-
setFlags
Sets one or more buffer flags on a buffer.- Parameters:
flags
- theGstBufferFlags
to set.- Returns:
true
ifflags
were successfully set on buffer.
-
setSize
public void setSize(long size) Sets the total size of the memory blocks in this Buffer.- 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
- theGstBufferFlags
to clear- Returns:
- true if
flags
is successfully cleared from buffer.
-
unsetFlags
Clears one or more buffer flags.- Parameters:
flags
- theGstBufferFlags
to clear- Returns:
- true if
flags
is successfully cleared from buffer.
-