Class Memory
- All Implemented Interfaces:
Proxy
GstBuffer
.
A GstMemory object has an allocated region of memory of maxsize. The maximum size does not change during the lifetime of the memory object. The memory also has an offset and size property that specifies the valid range of memory in the allocated region.
Memory is usually created by allocators with a gst_allocator_alloc()
method call. When null
is used as the allocator, the default allocator will
be used.
New allocators can be registered with gst_allocator_register(). Allocators are identified by name and can be retrieved with gst_allocator_find(). gst_allocator_set_default() can be used to change the default allocator.
New memory can be created with gst_memory_new_wrapped() that wraps the memory allocated elsewhere.
Refcounting of the memory block is performed with gst_memory_ref() and gst_memory_unref().
The size of the memory can be retrieved and changed with gst_memory_get_sizes() and gst_memory_resize() respectively.
Getting access to the data of the memory is performed with gst_memory_map(). The call will return a pointer to offset bytes into the region of memory. After the memory access is completed, gst_memory_unmap() should be called.
Memory can be copied with gst_memory_copy(), which will return a writable copy. gst_memory_share() will create a new memory block that shares the memory with an existing memory block at a custom offset and with a custom size.
Memory can be efficiently merged when gst_memory_is_span() returns true
.
-
Constructor Summary
ConstructorDescriptionMemory()
Allocate a new Memory.Allocate a new Memory.Memory
(MemorySegment address) Create a Memory proxy instance for the provided memory address.Memory
(MiniObject miniObject, Allocator allocator, Memory parent, long maxsize, long align, long offset, long size) Allocate a new Memory with the fields set to the provided values.Memory
(MiniObject miniObject, Allocator allocator, Memory parent, long maxsize, long align, long offset, long size, Arena arena) Allocate a new Memory with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptioncopy
(long offset, long size) Return a copy ofsize
bytes from this Memory starting fromoffset
.static MemoryLayout
The memory layout of the native struct.long
Get the currentsize
,offset
andmaxsize
of this Memory.static Type
getType()
Get the GType of the Memory classvoid
init
(Set<MemoryFlags> flags, Allocator allocator, Memory parent, long maxsize, long align, long offset, long size) Initializes a newly allocated this Memory with the given parameters.void
init
(MemoryFlags flags, Allocator allocator, Memory parent, long maxsize, long align, long offset, long size) Initializes a newly allocated this Memory with the given parameters.boolean
Check if this Memory and mem2 share the memory with a common parent memory object and that the memory is contiguous.boolean
Check if this Memory if allocated with an allocator formemType
.makeMapped
(MapInfo info, Set<MapFlags> flags) Create aGstMemory
object that is mapped withflags
.makeMapped
(MapInfo info, MapFlags... flags) Create aGstMemory
object that is mapped withflags
.boolean
Fillinfo
with the pointer and sizes of the memory in this Memory that can be accessed according toflags
.boolean
Fillinfo
with the pointer and sizes of the memory in this Memory that can be accessed according toflags
.long
Read the value of the fieldalign
.Read the value of the fieldallocator
.long
Read the value of the fieldmaxsize
.Read the value of the fieldmini_object
.long
Read the value of the fieldoffset
.Read the value of the fieldparent
.long
readSize()
Read the value of the fieldsize
.ref()
Increase the refcount of this memory.void
resize
(long offset, long size) Resize the memory region.share
(long offset, long size) Return a shared copy ofsize
bytes from this Memory starting fromoffset
.void
Release the memory obtained with gst_memory_map()void
unref()
Decrease the refcount of a memory, freeing it if the refcount reaches 0.static Memory
wrapped
(Set<MemoryFlags> flags, byte[] data, long maxsize, long offset) Allocate a new memory block that wraps the givendata
.static Memory
wrapped
(MemoryFlags flags, byte[] data, long maxsize, long offset) Allocate a new memory block that wraps the givendata
.void
writeAlign
(long align) Write a value in the fieldalign
.void
writeAllocator
(Allocator allocator) Write a value in the fieldallocator
.void
writeMaxsize
(long maxsize) Write a value in the fieldmaxsize
.void
writeMiniObject
(MiniObject miniObject) Write a value in the fieldmini_object
.void
writeOffset
(long offset) Write a value in the fieldoffset
.void
writeParent
(Memory parent) Write a value in the fieldparent
.void
writeSize
(long size) Write a value in the fieldsize
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Memory
Create a Memory proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Memory
Allocate a new Memory.- Parameters:
arena
- to control the memory allocation scope
-
Memory
public Memory()Allocate a new Memory. The memory is allocated withArena.ofAuto()
. -
Memory
public Memory(MiniObject miniObject, Allocator allocator, Memory parent, long maxsize, long align, long offset, long size, Arena arena) Allocate a new Memory with the fields set to the provided values.- Parameters:
miniObject
- value for the fieldminiObject
allocator
- value for the fieldallocator
parent
- value for the fieldparent
maxsize
- value for the fieldmaxsize
align
- value for the fieldalign
offset
- value for the fieldoffset
size
- value for the fieldsize
arena
- to control the memory allocation scope
-
Memory
public Memory(MiniObject miniObject, Allocator allocator, Memory parent, long maxsize, long align, long offset, long size) Allocate a new Memory with the fields set to the provided values. The memory is allocated withArena.ofAuto()
.- Parameters:
miniObject
- value for the fieldminiObject
allocator
- value for the fieldallocator
parent
- value for the fieldparent
maxsize
- value for the fieldmaxsize
align
- value for the fieldalign
offset
- value for the fieldoffset
size
- value for the fieldsize
-
-
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
-
readAllocator
Read the value of the fieldallocator
.- Returns:
- The value of the field
allocator
-
writeAllocator
Write a value in the fieldallocator
.- Parameters:
allocator
- The new value for the fieldallocator
-
readParent
Read the value of the fieldparent
.- Returns:
- The value of the field
parent
-
writeParent
Write a value in the fieldparent
.- Parameters:
parent
- The new value for the fieldparent
-
readMaxsize
public long readMaxsize()Read the value of the fieldmaxsize
.- Returns:
- The value of the field
maxsize
-
writeMaxsize
public void writeMaxsize(long maxsize) Write a value in the fieldmaxsize
.- Parameters:
maxsize
- The new value for the fieldmaxsize
-
readAlign
public long readAlign()Read the value of the fieldalign
.- Returns:
- The value of the field
align
-
writeAlign
public void writeAlign(long align) Write a value in the fieldalign
.- Parameters:
align
- The new value for the fieldalign
-
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
-
readSize
public long readSize()Read the value of the fieldsize
.- Returns:
- The value of the field
size
-
writeSize
public void writeSize(long size) Write a value in the fieldsize
.- Parameters:
size
- The new value for the fieldsize
-
wrapped
Allocate a new memory block that wraps the givendata
.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
GstMemory
.
-
wrapped
Allocate a new memory block that wraps the givendata
.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
GstMemory
.
-
copy
Return a copy ofsize
bytes from this Memory starting fromoffset
. This copy is guaranteed to be writable.size
can be set to -1 to return a copy fromoffset
to the end of the memory region.- Parameters:
offset
- offset to copy fromsize
- size to copy, or -1 to copy to the end of the memory region- Returns:
- a new copy of this Memory if the copy succeeded,
null
otherwise.
-
getSizes
-
init
public void init(Set<MemoryFlags> flags, Allocator allocator, Memory parent, long maxsize, long align, long offset, long size) Initializes a newly allocated this Memory with the given parameters. This function will call gst_mini_object_init() with the default memory parameters.- Parameters:
flags
-GstMemoryFlags
allocator
- theGstAllocator
parent
- the parent of this Memorymaxsize
- the total size of the memoryalign
- the alignment of the memoryoffset
- The offset in the memorysize
- the size of valid data in the memory
-
init
public void init(MemoryFlags flags, Allocator allocator, Memory parent, long maxsize, long align, long offset, long size) Initializes a newly allocated this Memory with the given parameters. This function will call gst_mini_object_init() with the default memory parameters.- Parameters:
flags
-GstMemoryFlags
allocator
- theGstAllocator
parent
- the parent of this Memorymaxsize
- the total size of the memoryalign
- the alignment of the memoryoffset
- The offset in the memorysize
- the size of valid data in the memory
-
isSpan
Check if this Memory and mem2 share the memory with a common parent memory object and that the memory is contiguous.If this is the case, the memory of this Memory and
mem2
can be merged efficiently by performing gst_memory_share() on the parent object from the returnedoffset
.- Parameters:
mem2
- aGstMemory
offset
- a pointer to a result offset- Returns:
true
if the memory is contiguous and of a common parent.
-
isType
Check if this Memory if allocated with an allocator formemType
.- Parameters:
memType
- a memory type- Returns:
true
if this Memory was allocated from an allocator formemType
.
-
makeMapped
Create aGstMemory
object that is mapped withflags
. If this Memory is mappable withflags
, this function returns the mapped this Memory directly. Otherwise a mapped copy of this Memory is returned.This function takes ownership of old this Memory and returns a reference to a new
GstMemory
.- Parameters:
info
- pointer for infoflags
- mapping flags- Returns:
- a
GstMemory
object mapped withflags
ornull
when a mapping is not possible.
-
makeMapped
Create aGstMemory
object that is mapped withflags
. If this Memory is mappable withflags
, this function returns the mapped this Memory directly. Otherwise a mapped copy of this Memory is returned.This function takes ownership of old this Memory and returns a reference to a new
GstMemory
.- Parameters:
info
- pointer for infoflags
- mapping flags- Returns:
- a
GstMemory
object mapped withflags
ornull
when a mapping is not possible.
-
map
Fillinfo
with the pointer and sizes of the memory in this Memory that can be accessed according toflags
.This function can return
false
for various reasons:- the memory backed by this Memory is not accessible with the given
flags
. - the memory was already mapped with a different mapping.
info
and its contents remain valid for as long as this Memory is valid and until gst_memory_unmap() is called.For each gst_memory_map() call, a corresponding gst_memory_unmap() call should be done.
- Parameters:
info
- pointer for infoflags
- mapping flags- Returns:
true
if the map operation was successful.
- the memory backed by this Memory is not accessible with the given
-
map
Fillinfo
with the pointer and sizes of the memory in this Memory that can be accessed according toflags
.This function can return
false
for various reasons:- the memory backed by this Memory is not accessible with the given
flags
. - the memory was already mapped with a different mapping.
info
and its contents remain valid for as long as this Memory is valid and until gst_memory_unmap() is called.For each gst_memory_map() call, a corresponding gst_memory_unmap() call should be done.
- Parameters:
info
- pointer for infoflags
- mapping flags- Returns:
true
if the map operation was successful.
- the memory backed by this Memory is not accessible with the given
-
ref
Increase the refcount of this memory.- Returns:
- this Memory (for convenience when doing assignments)
-
resize
public void resize(long offset, long size) Resize the memory region. this Memory should be writable and offset + size should be less than the maxsize of this Memory.GST_MEMORY_FLAG_ZERO_PREFIXED
andGST_MEMORY_FLAG_ZERO_PADDED
will be cleared when offset or padding is increased respectively.- Parameters:
offset
- a new offsetsize
- a new size
-
unmap
Release the memory obtained with gst_memory_map()- Parameters:
info
- aGstMapInfo
-
unref
public void unref()Decrease the refcount of a memory, freeing it if the refcount reaches 0.
-