Class MiniObject
- All Implemented Interfaces:
Proxy
GstMiniObject
is a simple structure that can be used to implement refcounted
types.
Subclasses will include GstMiniObject
as the first member in their structure
and then call gst_mini_object_init() to initialize the GstMiniObject
fields.
gst_mini_object_ref() and gst_mini_object_unref() increment and decrement the
refcount respectively. When the refcount of a mini-object reaches 0, the
dispose function is called first and when this returns true
, the free
function of the miniobject is called.
A copy can be made with gst_mini_object_copy().
gst_mini_object_is_writable() will return true
when the refcount of the
object is exactly 1 and there is no parent or a single parent exists and is
writable itself, meaning the current caller has the only reference to the
object. gst_mini_object_make_writable() will return a writable version of
the object, which might be a new copy when the refcount was not 1.
Opaque data can be associated with a GstMiniObject
with
gst_mini_object_set_qdata() and gst_mini_object_get_qdata(). The data is
meant to be specific to the particular object and is not automatically copied
with gst_mini_object_copy() or similar methods.
A weak reference can be added and remove with gst_mini_object_weak_ref() and gst_mini_object_weak_unref() respectively.
-
Constructor Summary
ConstructorDescriptionAllocate a new MiniObject.MiniObject
(Arena arena) Allocate a new MiniObject.MiniObject
(MemorySegment address) Create a MiniObject proxy instance for the provided memory address.MiniObject
(Type type, int refcount, int lockstate, int flags, MiniObjectCopyFunction copy, MiniObjectDisposeFunction dispose, MiniObjectFreeFunction free, int privUint, MemorySegment privPointer) Allocate a new MiniObject with the fields set to the provided values.MiniObject
(Type type, int refcount, int lockstate, int flags, MiniObjectCopyFunction copy, MiniObjectDisposeFunction dispose, MiniObjectFreeFunction free, int privUint, MemorySegment privPointer, Arena arena) Allocate a new MiniObject with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addParent
(MiniObject parent) This addsparent
as a parent for this MiniObject.copy()
Creates a copy of the mini-object.static MemoryLayout
The memory layout of the native struct.This function gets back user data pointers stored via gst_mini_object_set_qdata().static Type
getType()
Get the GType of the MiniObject classvoid
init
(int flags, Type type, @Nullable MiniObjectCopyFunction copyFunc, @Nullable MiniObjectDisposeFunction disposeFunc, @Nullable MiniObjectFreeFunction freeFunc) Initializes a mini-object with the desired type and copy/dispose/free functions.boolean
If this MiniObject has the LOCKABLE flag set, check if the current EXCLUSIVE lock onobject
is the only one, this means that changes to the object will not be visible to any other object.boolean
Lock the mini-object with the specified access mode inflags
.boolean
Lock the mini-object with the specified access mode inflags
.Checks if a mini-object is writable.readCopy()
Read the value of the fieldcopy
.Read the value of the fielddispose
.int
Read the value of the fieldflags
.readFree()
Read the value of the fieldfree
.int
Read the value of the fieldlockstate
.Read the value of the fieldpriv_pointer
.int
Read the value of the fieldpriv_uint
.int
Read the value of the fieldrefcount
.readType()
Read the value of the fieldtype
.ref()
Increase the reference count of the mini-object.void
removeParent
(MiniObject parent) This removesparent
as a parent for this MiniObject.static boolean
replace
(@Nullable Out<MiniObject> olddata, @Nullable MiniObject newdata) Atomically modifies a pointer to point to a new mini-object.void
setQdata
(Quark quark, @Nullable MemorySegment data) This sets an opaque, named pointer on a miniobject.static MiniObject
steal
(Out<MiniObject> olddata) Replace the currentGstMiniObject
pointer to byolddata
withnull
and return the old value.stealQdata
(Quark quark) This function gets back user data pointers stored via gst_mini_object_set_qdata() and removes the data from this MiniObject without invoking itsdestroy()
function (if any was set).static boolean
take
(Out<MiniObject> olddata, MiniObject newdata) Modifies a pointer to point to a new mini-object.void
Unlock the mini-object with the specified access mode inflags
.void
Unlock the mini-object with the specified access mode inflags
.void
unref()
Decreases the reference count of the mini-object, possibly freeing the mini-object.void
weakRef
(MiniObjectNotify notify) Adds a weak reference callback to a mini object.void
weakUnref
(MiniObjectNotify notify) Removes a weak reference callback from a mini object.void
writeCopy
(MiniObjectCopyFunction copy, Arena _arena) Write a value in the fieldcopy
.void
writeDispose
(MiniObjectDisposeFunction dispose, Arena _arena) Write a value in the fielddispose
.void
writeFlags
(int flags) Write a value in the fieldflags
.void
writeFree
(MiniObjectFreeFunction free, Arena _arena) Write a value in the fieldfree
.void
writeLockstate
(int lockstate) Write a value in the fieldlockstate
.void
writePrivPointer
(MemorySegment privPointer) Write a value in the fieldpriv_pointer
.void
writePrivUint
(int privUint) Write a value in the fieldpriv_uint
.void
writeRefcount
(int refcount) Write a value in the fieldrefcount
.void
Write a value in the fieldtype
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
MiniObject
Create a MiniObject proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
MiniObject
Allocate a new MiniObject.- Parameters:
arena
- to control the memory allocation scope
-
MiniObject
public MiniObject()Allocate a new MiniObject. The memory is allocated withArena.ofAuto()
. -
MiniObject
public MiniObject(Type type, int refcount, int lockstate, int flags, MiniObjectCopyFunction copy, MiniObjectDisposeFunction dispose, MiniObjectFreeFunction free, int privUint, MemorySegment privPointer, Arena arena) Allocate a new MiniObject with the fields set to the provided values.- Parameters:
type
- value for the fieldtype
refcount
- value for the fieldrefcount
lockstate
- value for the fieldlockstate
flags
- value for the fieldflags
copy
- value for the fieldcopy
dispose
- value for the fielddispose
free
- value for the fieldfree
privUint
- value for the fieldprivUint
privPointer
- value for the fieldprivPointer
arena
- to control the memory allocation scope
-
MiniObject
public MiniObject(Type type, int refcount, int lockstate, int flags, MiniObjectCopyFunction copy, MiniObjectDisposeFunction dispose, MiniObjectFreeFunction free, int privUint, MemorySegment privPointer) Allocate a new MiniObject with the fields set to the provided values. The memory is allocated withArena.ofAuto()
.- Parameters:
type
- value for the fieldtype
refcount
- value for the fieldrefcount
lockstate
- value for the fieldlockstate
flags
- value for the fieldflags
copy
- value for the fieldcopy
dispose
- value for the fielddispose
free
- value for the fieldfree
privUint
- value for the fieldprivUint
privPointer
- value for the fieldprivPointer
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readType
-
writeType
Write a value in the fieldtype
.- Parameters:
type
- The new value for the fieldtype
-
readRefcount
public int readRefcount()Read the value of the fieldrefcount
.- Returns:
- The value of the field
refcount
-
writeRefcount
public void writeRefcount(int refcount) Write a value in the fieldrefcount
.- Parameters:
refcount
- The new value for the fieldrefcount
-
readLockstate
public int readLockstate()Read the value of the fieldlockstate
.- Returns:
- The value of the field
lockstate
-
writeLockstate
public void writeLockstate(int lockstate) Write a value in the fieldlockstate
.- Parameters:
lockstate
- The new value for the fieldlockstate
-
readFlags
public int readFlags()Read the value of the fieldflags
.- Returns:
- The value of the field
flags
-
writeFlags
public void writeFlags(int flags) Write a value in the fieldflags
.- Parameters:
flags
- The new value for the fieldflags
-
readCopy
Read the value of the fieldcopy
.- Returns:
- The value of the field
copy
-
writeCopy
Write a value in the fieldcopy
.- Parameters:
copy
- The new value for the fieldcopy
_arena
- to control the memory allocation scope
-
readDispose
Read the value of the fielddispose
.- Returns:
- The value of the field
dispose
-
writeDispose
Write a value in the fielddispose
.- Parameters:
dispose
- The new value for the fielddispose
_arena
- to control the memory allocation scope
-
readFree
Read the value of the fieldfree
.- Returns:
- The value of the field
free
-
writeFree
Write a value in the fieldfree
.- Parameters:
free
- The new value for the fieldfree
_arena
- to control the memory allocation scope
-
readPrivUint
public int readPrivUint()Read the value of the fieldpriv_uint
.- Returns:
- The value of the field
priv_uint
-
writePrivUint
public void writePrivUint(int privUint) Write a value in the fieldpriv_uint
.- Parameters:
privUint
- The new value for the fieldpriv_uint
-
readPrivPointer
Read the value of the fieldpriv_pointer
.- Returns:
- The value of the field
priv_pointer
-
writePrivPointer
Write a value in the fieldpriv_pointer
.- Parameters:
privPointer
- The new value for the fieldpriv_pointer
-
replace
public static boolean replace(@Nullable @Nullable Out<MiniObject> olddata, @Nullable @Nullable MiniObject newdata) Atomically modifies a pointer to point to a new mini-object. The reference count ofolddata
is decreased and the reference count ofnewdata
is increased.Either
newdata
and the value pointed to byolddata
may benull
.- Parameters:
olddata
- pointer to a pointer to a mini-object to be replacednewdata
- pointer to new mini-object- Returns:
true
ifnewdata
was different fromolddata
-
steal
Replace the currentGstMiniObject
pointer to byolddata
withnull
and return the old value.- Parameters:
olddata
- pointer to a pointer to a mini-object to be stolen- Returns:
- the
GstMiniObject
atoldata
-
take
Modifies a pointer to point to a new mini-object. The modification is done atomically. This version is similar to gst_mini_object_replace() except that it does not increase the refcount ofnewdata
and thus takes ownership ofnewdata
.Either
newdata
and the value pointed to byolddata
may benull
.- Parameters:
olddata
- pointer to a pointer to a mini-object to be replacednewdata
- pointer to new mini-object- Returns:
true
ifnewdata
was different fromolddata
-
addParent
This addsparent
as a parent for this MiniObject. Having one ore more parents affects the writability of this MiniObject: if aparent
is not writable, this MiniObject is also not writable, regardless of its refcount. this MiniObject is only writable if all the parents are writable and its own refcount is exactly 1.Note: This function does not take ownership of
parent
and also does not take an additional reference. It is the responsibility of the caller to remove the parent again at a later time.- Parameters:
parent
- a parentGstMiniObject
-
copy
Creates a copy of the mini-object.MT safe
- Returns:
- the new mini-object if copying is
possible,
null
otherwise.
-
getQdata
This function gets back user data pointers stored via gst_mini_object_set_qdata().- Parameters:
quark
- AGQuark
, naming the user data pointer- Returns:
- The user data pointer set, or
null
-
init
public void init(int flags, Type type, @Nullable @Nullable MiniObjectCopyFunction copyFunc, @Nullable @Nullable MiniObjectDisposeFunction disposeFunc, @Nullable @Nullable MiniObjectFreeFunction freeFunc) Initializes a mini-object with the desired type and copy/dispose/free functions.- Parameters:
flags
- initialGstMiniObjectFlags
type
- theGType
of the mini-object to createcopyFunc
- the copy function, ornull
disposeFunc
- the dispose function, ornull
freeFunc
- the free function ornull
-
isWritable
public boolean isWritable()If this MiniObject has the LOCKABLE flag set, check if the current EXCLUSIVE lock onobject
is the only one, this means that changes to the object will not be visible to any other object.If the LOCKABLE flag is not set, check if the refcount of this MiniObject is exactly 1, meaning that no other reference exists to the object and that the object is therefore writable.
Modification of a mini-object should only be done after verifying that it is writable.
- Returns:
true
if the object is writable.
-
lock
-
lock
Lock the mini-object with the specified access mode inflags
.- Parameters:
flags
-GstLockFlags
- Returns:
true
if this MiniObject could be locked.
-
makeWritable
Checks if a mini-object is writable. If not, a writable copy is made and returned. This gives away the reference to the original mini object, and returns a reference to the new object.MT safe
- Returns:
- a writable mini-object (which may or may not be
the same as this MiniObject) or
null
if copying is required but not possible.
-
ref
Increase the reference count of the mini-object.Note that the refcount affects the writability of
mini
-object, see gst_mini_object_is_writable(). It is important to note that keeping additional references to GstMiniObject instances can potentially increase the number of memcpy operations in a pipeline, especially if the miniobject is aGstBuffer
.- Returns:
- the mini-object.
-
removeParent
This removesparent
as a parent for this MiniObject. See gst_mini_object_add_parent().- Parameters:
parent
- a parentGstMiniObject
-
setQdata
This sets an opaque, named pointer on a miniobject. The name is specified through aGQuark
(retrieved e.g. via g_quark_from_static_string()), and the pointer can be gotten back from the this MiniObject with gst_mini_object_get_qdata() until the this MiniObject is disposed. Setting a previously set user data pointer, overrides (frees) the old pointer set, usingnull
as pointer essentially removes the data stored.destroy
may be specified which is called withdata
as argument when the this MiniObject is disposed, or the data is being overwritten by a call to gst_mini_object_set_qdata() with the samequark
.- Parameters:
quark
- AGQuark
, naming the user data pointerdata
- An opaque user data pointer
-
stealQdata
This function gets back user data pointers stored via gst_mini_object_set_qdata() and removes the data from this MiniObject without invoking itsdestroy()
function (if any was set).- Parameters:
quark
- AGQuark
, naming the user data pointer- Returns:
- The user data pointer set, or
null
-
unlock
-
unlock
Unlock the mini-object with the specified access mode inflags
.- Parameters:
flags
-GstLockFlags
-
unref
public void unref()Decreases the reference count of the mini-object, possibly freeing the mini-object. -
weakRef
Adds a weak reference callback to a mini object. Weak references are used for notification when a mini object is finalized. They are called "weak references" because they allow you to safely hold a pointer to the mini object without calling gst_mini_object_ref() (gst_mini_object_ref() adds a strong reference, that is, forces the object to stay alive).- Parameters:
notify
- callback to invoke before the mini object is freed
-
weakUnref
Removes a weak reference callback from a mini object.- Parameters:
notify
- callback to search for
-