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
ConstructorsConstructorDescriptionMemory()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 TypeMethodDescription@Nullable Memorycopy(long offset, long size) Return a copy ofsizebytes from this Memory starting fromoffset.This copy is guaranteed to be writable.static MemoryLayoutThe memory layout of the native struct.longGet the currentsize,offsetandmaxsizeofmem.static @Nullable TypegetType()Get the GType of the Memory classvoidinit(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.voidinit(MemoryFlags flags, Allocator allocator, Memory parent, long maxsize, long align, long offset, long size) Initializes a newly allocated this Memory with the given parameters.booleanCheck if this Memory and mem2 share the memory with a common parent memory object and that the memory is contiguous.booleanCheck if this Memory if allocated with an allocator formemType.@Nullable MemorymakeMapped(MapInfo info, int flags) Create aGstMemoryobject that is mapped withflags.If this Memory is mappable withflags,this function returns the mapped this Memory directly.booleanFillinfowith the pointer and sizes of the memory in this Memory that can be accessed according toflags.longRead the value of the fieldalign.Read the value of the fieldallocator.longRead the value of the fieldmaxsize.@Nullable MiniObjectRead the value of the fieldmini_object.longRead the value of the fieldoffset.Read the value of the fieldparent.longreadSize()Read the value of the fieldsize.ref()Increase the refcount of this memory.voidresize(long offset, long size) Resize the memory region.share(long offset, long size) Return a shared copy ofsizebytes from this Memory starting fromoffset.No memory copy is performed and the memory region is simply shared.voidRelease the memory obtained with gst_memory_map()voidunref()Decrease the refcount of a memory, freeing it if the refcount reaches 0.static Memorywrapped(Set<MemoryFlags> flags, @org.jspecify.annotations.Nullable byte @Nullable [] data, long maxsize, long offset) Allocate a new memory block that wraps the givendata.static @Nullable Memorywrapped(MemoryFlags flags, @org.jspecify.annotations.Nullable byte @Nullable [] data, long maxsize, long offset) Allocate a new memory block that wraps the givendata.voidwriteAlign(long align) Write a value in the fieldalign.voidwriteAllocator(Allocator allocator) Write a value in the fieldallocator.voidwriteMaxsize(long maxsize) Write a value in the fieldmaxsize.voidwriteMiniObject(@Nullable MiniObject miniObject) Write a value in the fieldmini_object.voidwriteOffset(long offset) Write a value in the fieldoffset.voidwriteParent(Memory parent) Write a value in the fieldparent.voidwriteSize(long size) Write a value in the fieldsize.Methods inherited from class org.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 fieldminiObjectallocator- value for the fieldallocatorparent- value for the fieldparentmaxsize- value for the fieldmaxsizealign- value for the fieldalignoffset- value for the fieldoffsetsize- value for the fieldsizearena- 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 fieldminiObjectallocator- value for the fieldallocatorparent- value for the fieldparentmaxsize- value for the fieldmaxsizealign- value for the fieldalignoffset- value for the fieldoffsetsize- 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
public static Memory wrapped(Set<MemoryFlags> flags, @org.jspecify.annotations.Nullable byte @Nullable [] data, long maxsize, long offset) Allocate a new memory block that wraps the givendata.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
GstMemory.
-
wrapped
public static @Nullable Memory wrapped(MemoryFlags flags, @org.jspecify.annotations.Nullable byte @Nullable [] data, long maxsize, long offset) Allocate a new memory block that wraps the givendata.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
GstMemory.
-
copy
Return a copy ofsizebytes from this Memory starting fromoffset.This copy is guaranteed to be writable.sizecan be set to -1 to return a copy fromoffsetto 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,
nullotherwise.
-
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-GstMemoryFlagsallocator- theGstAllocatorparent- 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-GstMemoryFlagsallocator- theGstAllocatorparent- 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
mem2can be merged efficiently by performing gst_memory_share() on the parent object from the returnedoffset.- Parameters:
mem2- aGstMemoryoffset- a pointer to a result offset- Returns:
trueif 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:
trueif this Memory was allocated from an allocator formemType.- Since:
- 1.2
-
makeMapped
Create aGstMemoryobject 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
GstMemoryobject mapped withflagsornullwhen a mapping is not possible.
-
map
Fillinfowith the pointer and sizes of the memory in this Memory that can be accessed according toflags.This function can return
falsefor various reasons:- the memory backed by this Memory is not accessible with the given
flags. - the memory was already mapped with a different mapping.
infoand 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:
trueif 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 ofmem.GST_MEMORY_FLAG_ZERO_PREFIXEDandGST_MEMORY_FLAG_ZERO_PADDEDwill 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.
-