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
ConstructorsConstructorDescriptionIterator(int size, Type type, Mutex lock, MemorySegment masterCookie, @Nullable IteratorCopyFunction copy, @Nullable IteratorNextFunction next, @Nullable IteratorItemFunction item, @Nullable IteratorResyncFunction resync, @Nullable 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(@Nullable CompareFunc func, Value userData) Create a new iterator from an existing iterator.booleanfindCustom(@Nullable CompareFunc func, Value elem) Find the first element in this Iterator that matches the compare functionfunc.funcshould return 0 when the element is found.fold(@Nullable IteratorFoldFunction func, Value ret) Foldsfuncover the elements ofiter.That is to say,funcwill be called asfunc(object,ret,userData)for each object init.The normal use of this procedure is to accumulate the results of operating on the objects inret.foreach(@Nullable IteratorForeachFunction func) Iterate over all element of this Iterator and call the given functionfuncfor each element.voidfree()Free the iterator.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the Iterator classstatic Iteratorlist(Type type, Mutex lock, MemorySegment masterCookie, List<MemorySegment>[] list, GObject owner, @Nullable IteratorItemFunction item) Create a new iterator designed for iteratinglist.Get the next item from the iterator inelem.voidPushesotheriterator ontoit.All calls performed on this Iterator are forwarded toother.IfotherreturnsIteratorResult.DONE, it is popped again and calls are handled by this Iterator again.intRead the value of the fieldcookie.@Nullable IteratorCopyFunctionreadCopy()Read the value of the fieldcopy.@Nullable IteratorFreeFunctionreadFree()Read the value of the fieldfree.@Nullable IteratorItemFunctionreadItem()Read the value of the fielditem.readLock()Read the value of the fieldlock.Read the value of the fieldmaster_cookie.@Nullable IteratorNextFunctionreadNext()Read the value of the fieldnext.Read the value of the fieldpushed.@Nullable IteratorResyncFunctionRead the value of the fieldresync.intreadSize()Read the value of the fieldsize.readType()Read the value of the fieldtype.voidresync()Resync the iterator.static IteratorThisGstIteratoris a convenient iterator for the common case where aGstIteratorneeds to be returned but only a single object has to be considered.voidwriteCookie(int cookie) Write a value in the fieldcookie.voidwriteCopy(@Nullable IteratorCopyFunction copy, Arena _arena) Write a value in the fieldcopy.voidwriteFree(@Nullable IteratorFreeFunction free, Arena _arena) Write a value in the fieldfree.voidwriteItem(@Nullable IteratorItemFunction item, Arena _arena) Write a value in the fielditem.voidWrite a value in the fieldlock.voidwriteMasterCookie(MemorySegment masterCookie) Write a value in the fieldmaster_cookie.voidwriteNext(@Nullable IteratorNextFunction next, Arena _arena) Write a value in the fieldnext.voidwritePushed(Iterator pushed) Write a value in the fieldpushed.voidwriteResync(@Nullable IteratorResyncFunction resync, Arena _arena) Write a value in the fieldresync.voidwriteSize(int size) Write a value in the fieldsize.voidWrite a value in the fieldtype.Methods inherited from class org.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, @Nullable IteratorCopyFunction copy, @Nullable IteratorNextFunction next, @Nullable IteratorItemFunction item, @Nullable IteratorResyncFunction resync, @Nullable 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
itemfunction is called with the lock held. Thefreefunction is called when the iterator is freed.- Parameters:
size- the size of the iterator structuretype-GTypeof 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, @Nullable IteratorItemFunction item) Create a new iterator designed for iteratinglist.The list you iterate is usually part of a data structure
ownerand is protected withlock.The iterator will use
lockto retrieve the next item of the list and it will then call theitemfunction before releasinglockagain.When a concurrent update to the list is performed, usually by
ownerwhile holdinglock,masterCookiewill be updated. The iterator implementation will notice the update of the cookie and will returnIteratorResult.RESYNCto the user of the iterator in the next call to gst_iterator_next().- Parameters:
type-GTypeof elementslock- pointer to aGMutexprotecting 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
GstIteratorforlist.MT safe.
-
single
ThisGstIteratoris a convenient iterator for the common case where aGstIteratorneeds to be returned but only a single object has to be considered. This happens often for theGstPadIterIntLinkFunction.- Parameters:
type-GTypeof the passed objectobject- object that this iterator should return- Returns:
- the new
GstIteratorforobject.
-
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 tofuncis theGValueof the current iterator element and the second parameter isuserData.funcshould 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.funcshould return 0 when the element is found. The first parameter tofuncwill be the current element of the iterator and the second parameter will beuserData.The result will be stored inelemif a result is found.The iterator will not be freed.
This function will return
falseif an error happened to the iterator or if the element wasn't found.- Parameters:
func- the compare function to useelem- pointer to aGValuewhere to store the result- Returns:
- Returns
trueif the element was found, elsefalse.MT safe.
-
fold
Foldsfuncover the elements ofiter.That is to say,funcwill be called asfunc(object,ret,userData)for each object init.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
funcreturnstrue. When the iterator has no more arguments,IteratorResult.DONEwill be returned. Iffuncreturnsfalse, the fold will stop, andIteratorResult.OKwill be returned. Errors or resyncs will cause fold to returnIteratorResult.ERRORorIteratorResult.RESYNCas 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 functionfuncfor 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,elemwill contain a valid value.elemmust have been initialized to the type of the iterator or initialized to zeroes with g_value_unset(). The caller is responsible for unsetting or resettingelemwith g_value_unset() or g_value_reset() after usage.When this function returns
IteratorResult.DONE, no more elements can be retrieved fromit.A return value of
IteratorResult.RESYNCindicates 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.ERRORindicates an unrecoverable fatal error.- Parameters:
elem- pointer to hold next element- Returns:
- The result of the iteration. Unset
elemafter usage.MT safe.
-
push
Pushesotheriterator ontoit.All calls performed on this Iterator are forwarded toother.IfotherreturnsIteratorResult.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
it,otherwill automatically be popped.MT safe.
- Parameters:
other- TheGstIteratorto 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
it,it will automatically be popped again with this function.MT safe.
-