Class Iterator
- All Implemented Interfaces:
Proxy
Various GStreamer objects provide access to their internal structures using an iterator.
Note that if calling a GstIterator function results in your code receiving a refcounted object (with, say, g_value_get_object()), the refcount for that object will not be increased. Your code is responsible for taking a reference if it wants to continue using it later.
The basic use pattern of an iterator is as follows:
GstIterator *it = _get_iterator(object);
GValue item = G_VALUE_INIT;
done = FALSE;
while (!done) {
switch (gst_iterator_next (it, &item)) {
case GST_ITERATOR_OK:
...get/use/change item here...
g_value_reset (&item);
break;
case GST_ITERATOR_RESYNC:
...rollback changes to items...
gst_iterator_resync (it);
break;
case GST_ITERATOR_ERROR:
...wrong parameters were given...
done = TRUE;
break;
case GST_ITERATOR_DONE:
done = TRUE;
break;
}
}
g_value_unset (&item);
gst_iterator_free (it);
-
Constructor Summary
ConstructorDescriptionIterator
(int size, Type type, Mutex lock, MemorySegment masterCookie, IteratorCopyFunction copy, IteratorNextFunction next, IteratorItemFunction item, IteratorResyncFunction resync, IteratorFreeFunction free) Create a new iterator.Iterator
(MemorySegment address) Create a Iterator proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Copy the iterator and its state.filter
(CompareFunc func, Value userData) Create a new iterator from an existing iterator.boolean
findCustom
(CompareFunc func, Value elem) Find the first element in this Iterator that matches the compare functionfunc
.fold
(IteratorFoldFunction func, Value ret) Foldsfunc
over the elements ofiter
.Iterate over all element of this Iterator and call the given functionfunc
for each element.void
free()
Free the iterator.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the Iterator classstatic Iterator
list
(Type type, Mutex lock, MemorySegment masterCookie, List<MemorySegment>[] list, GObject owner, IteratorItemFunction item) Create a new iterator designed for iteratinglist
.Get the next item from the iterator inelem
.void
Pushesother
iterator onto this Iterator.int
Read the value of the fieldcookie
.readCopy()
Read the value of the fieldcopy
.readFree()
Read the value of the fieldfree
.readItem()
Read the value of the fielditem
.readLock()
Read the value of the fieldlock
.Read the value of the fieldmaster_cookie
.readNext()
Read the value of the fieldnext
.Read the value of the fieldpushed
.Read the value of the fieldresync
.int
readSize()
Read the value of the fieldsize
.readType()
Read the value of the fieldtype
.void
resync()
Resync the iterator.static Iterator
ThisGstIterator
is a convenient iterator for the common case where aGstIterator
needs to be returned but only a single object has to be considered.void
writeCookie
(int cookie) Write a value in the fieldcookie
.void
writeCopy
(IteratorCopyFunction copy, Arena _arena) Write a value in the fieldcopy
.void
writeFree
(IteratorFreeFunction free, Arena _arena) Write a value in the fieldfree
.void
writeItem
(IteratorItemFunction item, Arena _arena) Write a value in the fielditem
.void
Write a value in the fieldlock
.void
writeMasterCookie
(MemorySegment masterCookie) Write a value in the fieldmaster_cookie
.void
writeNext
(IteratorNextFunction next, Arena _arena) Write a value in the fieldnext
.void
writePushed
(Iterator pushed) Write a value in the fieldpushed
.void
writeResync
(IteratorResyncFunction resync, Arena _arena) Write a value in the fieldresync
.void
writeSize
(int size) Write a value in the fieldsize
.void
Write a value in the fieldtype
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Iterator
Create a Iterator proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Iterator
public Iterator(int size, Type type, Mutex lock, MemorySegment masterCookie, IteratorCopyFunction copy, IteratorNextFunction next, IteratorItemFunction item, IteratorResyncFunction resync, IteratorFreeFunction free) Create a new iterator. This function is mainly used for objects implementing the next/resync/free function to iterate a data structure.For each item retrieved, the
item
function is called with the lock held. Thefree
function is called when the iterator is freed.- Parameters:
size
- the size of the iterator structuretype
-GType
of childrenlock
- pointer to aGMutex
.masterCookie
- pointer to a guint32 that is changed when the items in the iterator changed.copy
- copy functionnext
- function to get next itemitem
- function to call on each item retrievedresync
- function to resync the iteratorfree
- function to free the iterator
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
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
-
readNext
Read the value of the fieldnext
.- Returns:
- The value of the field
next
-
writeNext
Write a value in the fieldnext
.- Parameters:
next
- The new value for the fieldnext
_arena
- to control the memory allocation scope
-
readItem
Read the value of the fielditem
.- Returns:
- The value of the field
item
-
writeItem
Write a value in the fielditem
.- Parameters:
item
- The new value for the fielditem
_arena
- to control the memory allocation scope
-
readResync
Read the value of the fieldresync
.- Returns:
- The value of the field
resync
-
writeResync
Write a value in the fieldresync
.- Parameters:
resync
- The new value for the fieldresync
_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
-
readPushed
Read the value of the fieldpushed
.- Returns:
- The value of the field
pushed
-
writePushed
Write a value in the fieldpushed
.- Parameters:
pushed
- The new value for the fieldpushed
-
readType
-
writeType
Write a value in the fieldtype
.- Parameters:
type
- The new value for the fieldtype
-
readLock
-
writeLock
Write a value in the fieldlock
.- Parameters:
lock
- The new value for the fieldlock
-
readCookie
public int readCookie()Read the value of the fieldcookie
.- Returns:
- The value of the field
cookie
-
writeCookie
public void writeCookie(int cookie) Write a value in the fieldcookie
.- Parameters:
cookie
- The new value for the fieldcookie
-
readMasterCookie
Read the value of the fieldmaster_cookie
.- Returns:
- The value of the field
master_cookie
-
writeMasterCookie
Write a value in the fieldmaster_cookie
.- Parameters:
masterCookie
- The new value for the fieldmaster_cookie
-
readSize
public int readSize()Read the value of the fieldsize
.- Returns:
- The value of the field
size
-
writeSize
public void writeSize(int size) Write a value in the fieldsize
.- Parameters:
size
- The new value for the fieldsize
-
list
public static Iterator list(Type type, Mutex lock, MemorySegment masterCookie, List<MemorySegment>[] list, GObject owner, IteratorItemFunction item) Create a new iterator designed for iteratinglist
.The list you iterate is usually part of a data structure
owner
and is protected withlock
.The iterator will use
lock
to retrieve the next item of the list and it will then call theitem
function before releasinglock
again.When a concurrent update to the list is performed, usually by
owner
while holdinglock
,masterCookie
will be updated. The iterator implementation will notice the update of the cookie and will returnIteratorResult.RESYNC
to the user of the iterator in the next call to gst_iterator_next().- Parameters:
type
-GType
of elementslock
- pointer to aGMutex
protecting the list.masterCookie
- pointer to a guint32 that is incremented when the list is changed.list
- pointer to the listowner
- object owning the listitem
- function to call on each item retrieved- Returns:
- the new
GstIterator
forlist
.MT safe.
-
single
ThisGstIterator
is a convenient iterator for the common case where aGstIterator
needs to be returned but only a single object has to be considered. This happens often for theGstPadIterIntLinkFunction
.- Parameters:
type
-GType
of the passed objectobject
- object that this iterator should return- Returns:
- the new
GstIterator
forobject
.
-
copy
-
filter
Create a new iterator from an existing iterator. The new iterator will only return those elements that match the given compare functionfunc
. The first parameter that is passed tofunc
is theGValue
of the current iterator element and the second parameter isuserData
.func
should return 0 for elements that should be included in the filtered iterator.When this iterator is freed, this Iterator will also be freed.
- Parameters:
func
- the compare function to select elementsuserData
- user data passed to the compare function- Returns:
- a new
GstIterator
.MT safe.
-
findCustom
Find the first element in this Iterator that matches the compare functionfunc
.func
should return 0 when the element is found. The first parameter tofunc
will be the current element of the iterator and the second parameter will beuserData
. The result will be stored inelem
if a result is found.The iterator will not be freed.
This function will return
false
if an error happened to the iterator or if the element wasn't found.- Parameters:
func
- the compare function to useelem
- pointer to aGValue
where to store the result- Returns:
- Returns
true
if the element was found, elsefalse
.MT safe.
-
fold
Foldsfunc
over the elements ofiter
. That is to say,func
will be called asfunc
(object,ret
,userData
) for each object in this Iterator. The normal use of this procedure is to accumulate the results of operating on the objects inret
.This procedure can be used (and is used internally) to implement the gst_iterator_foreach() and gst_iterator_find_custom() operations.
The fold will proceed as long as
func
returnstrue
. When the iterator has no more arguments,IteratorResult.DONE
will be returned. Iffunc
returnsfalse
, the fold will stop, andIteratorResult.OK
will be returned. Errors or resyncs will cause fold to returnIteratorResult.ERROR
orIteratorResult.RESYNC
as appropriate.The iterator will not be freed.
- Parameters:
func
- the fold functionret
- the seed value passed to the fold function- Returns:
- A
GstIteratorResult
, as described above.MT safe.
-
foreach
Iterate over all element of this Iterator and call the given functionfunc
for each element.- Parameters:
func
- the function to call for each element.- Returns:
- the result call to gst_iterator_fold(). The iterator will not be
freed.
MT safe.
-
free
public void free()Free the iterator.MT safe.
-
next
Get the next item from the iterator inelem
.Only when this function returns
IteratorResult.OK
,elem
will contain a valid value.elem
must have been initialized to the type of the iterator or initialized to zeroes with g_value_unset(). The caller is responsible for unsetting or resettingelem
with g_value_unset() or g_value_reset() after usage.When this function returns
IteratorResult.DONE
, no more elements can be retrieved from this Iterator.A return value of
IteratorResult.RESYNC
indicates that the element list was concurrently updated. The user of this Iterator should call gst_iterator_resync() to get the newly updated list.A return value of
IteratorResult.ERROR
indicates an unrecoverable fatal error.- Parameters:
elem
- pointer to hold next element- Returns:
- The result of the iteration. Unset
elem
after usage.MT safe.
-
push
Pushesother
iterator onto this Iterator. All calls performed on this Iterator are forwarded toother
. Ifother
returnsIteratorResult.DONE
, it is popped again and calls are handled by this Iterator again.This function is mainly used by objects implementing the iterator next function to recurse into substructures.
When gst_iterator_resync() is called on this Iterator,
other
will automatically be popped.MT safe.
- Parameters:
other
- TheGstIterator
to push
-
resync
public void resync()Resync the iterator. this function is mostly called after gst_iterator_next() returnedIteratorResult.RESYNC
.When an iterator was pushed on this Iterator, it will automatically be popped again with this function.
MT safe.
-