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
ConstructorsConstructorDescriptionAllocate 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 TypeMethodDescriptionvoidaddParent(MiniObject parent) This addsparentas a parent forobject.Having one ore more parents affects the writability ofobject:if aparentis not writable, this MiniObject is also not writable, regardless of its refcount.@Nullable MiniObjectcopy()Creates a copy of the mini-object.static MemoryLayoutThe memory layout of the native struct.@Nullable MemorySegmentThis function gets back user data pointers stored via gst_mini_object_set_qdata().static @Nullable TypegetType()Get the GType of the MiniObject classvoidinit(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.booleanIf this MiniObject has the LOCKABLE flag set, check if the current EXCLUSIVE lock onobjectis the only one, this means that changes to the object will not be visible to any other object.booleanLock the mini-object with the specified access mode inflags.booleanLock the mini-object with the specified access mode inflags.@Nullable MiniObjectChecks if a mini-object is writable.@Nullable MiniObjectCopyFunctionreadCopy()Read the value of the fieldcopy.@Nullable MiniObjectDisposeFunctionRead the value of the fielddispose.intRead the value of the fieldflags.@Nullable MiniObjectFreeFunctionreadFree()Read the value of the fieldfree.intRead the value of the fieldlockstate.Read the value of the fieldpriv_pointer.intRead the value of the fieldpriv_uint.intRead the value of the fieldrefcount.readType()Read the value of the fieldtype.ref()Increase the reference count of the mini-object.voidremoveParent(MiniObject parent) This removesparentas a parent forobject.See gst_mini_object_add_parent().static booleanreplace(@Nullable Out<MiniObject> olddata, @Nullable MiniObject newdata) Atomically modifies a pointer to point to a new mini-object.voidsetQdata(Quark quark, @Nullable MemorySegment data) This sets an opaque, named pointer on a miniobject.static @Nullable MiniObjectsteal(Out<MiniObject> olddata) Replace the currentGstMiniObjectpointer to byolddatawithnulland return the old value.@Nullable MemorySegmentstealQdata(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 booleantake(Out<MiniObject> olddata, MiniObject newdata) Modifies a pointer to point to a new mini-object.voidUnlock the mini-object with the specified access mode inflags.voidUnlock the mini-object with the specified access mode inflags.voidunref()Decreases the reference count of the mini-object, possibly freeing the mini-object.voidweakRef(@Nullable MiniObjectNotify notify) Adds a weak reference callback to a mini object.voidweakUnref(@Nullable MiniObjectNotify notify) Removes a weak reference callback from a mini object.voidwriteCopy(@Nullable MiniObjectCopyFunction copy, Arena _arena) Write a value in the fieldcopy.voidwriteDispose(@Nullable MiniObjectDisposeFunction dispose, Arena _arena) Write a value in the fielddispose.voidwriteFlags(int flags) Write a value in the fieldflags.voidwriteFree(@Nullable MiniObjectFreeFunction free, Arena _arena) Write a value in the fieldfree.voidwriteLockstate(int lockstate) Write a value in the fieldlockstate.voidwritePrivPointer(MemorySegment privPointer) Write a value in the fieldpriv_pointer.voidwritePrivUint(int privUint) Write a value in the fieldpriv_uint.voidwriteRefcount(int refcount) Write a value in the fieldrefcount.voidWrite a value in the fieldtype.Methods inherited from class org.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 fieldtyperefcount- value for the fieldrefcountlockstate- value for the fieldlockstateflags- value for the fieldflagscopy- value for the fieldcopydispose- value for the fielddisposefree- value for the fieldfreeprivUint- value for the fieldprivUintprivPointer- value for the fieldprivPointerarena- 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 fieldtyperefcount- value for the fieldrefcountlockstate- value for the fieldlockstateflags- value for the fieldflagscopy- value for the fieldcopydispose- value for the fielddisposefree- value for the fieldfreeprivUint- value for the fieldprivUintprivPointer- 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
Atomically modifies a pointer to point to a new mini-object. The reference count ofolddatais decreased and the reference count ofnewdatais increased.Either
newdataand the value pointed to byolddatamay benull.- Parameters:
olddata- pointer to a pointer to a mini-object to be replacednewdata- pointer to new mini-object- Returns:
trueifnewdatawas different fromolddata
-
steal
Replace the currentGstMiniObjectpointer to byolddatawithnulland return the old value.- Parameters:
olddata- pointer to a pointer to a mini-object to be stolen- Returns:
- the
GstMiniObjectatoldata
-
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 ofnewdataand thus takes ownership ofnewdata.Either
newdataand the value pointed to byolddatamay benull.- Parameters:
olddata- pointer to a pointer to a mini-object to be replacednewdata- pointer to new mini-object- Returns:
trueifnewdatawas different fromolddata
-
addParent
This addsparentas a parent forobject.Having one ore more parents affects the writability ofobject:if aparentis 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
parentand 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- Since:
- 1.16
-
copy
Creates a copy of the mini-object.MT safe
- Returns:
- the new mini-object if copying is
possible,
nullotherwise.
-
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 MiniObjectCopyFunction copyFunc, @Nullable MiniObjectDisposeFunction disposeFunc, @Nullable MiniObjectFreeFunction freeFunc) Initializes a mini-object with the desired type and copy/dispose/free functions.- Parameters:
flags- initialGstMiniObjectFlagstype- theGTypeof the mini-object to createcopyFunc- the copy function, ornulldisposeFunc- the dispose function, ornullfreeFunc- the free function ornull
-
isWritable
public boolean isWritable()If this MiniObject has the LOCKABLE flag set, check if the current EXCLUSIVE lock onobjectis 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:
trueif the object is writable.
-
lock
-
lock
Lock the mini-object with the specified access mode inflags.- Parameters:
flags-GstLockFlags- Returns:
trueif 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
miniObject)ornullif copying is required but not possible.
-
ref
Increase the reference count of the mini-object.Note that the refcount affects the writability of
miniObject,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 removesparentas a parent forobject.See gst_mini_object_add_parent().- Parameters:
parent- a parentGstMiniObject- Since:
- 1.16
-
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, usingnullas pointer essentially removes the data stored.destroymay be specified which is called withdataas 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
-