Class Task
- All Implemented Interfaces:
Proxy
GstTask is used by GstElement and GstPad to provide the data passing
threads in a GstPipeline.
A GstPad will typically start a GstTask to push or pull data to/from the
peer pads. Most source elements start a GstTask to push data. In some cases
a demuxer element can start a GstTask to pull data from a peer element. This
is typically done when the demuxer can perform random access on the upstream
peer element for improved performance.
Although convenience functions exist on GstPad to start/pause/stop tasks, it
might sometimes be needed to create a GstTask manually if it is not related to
a GstPad.
Before the GstTask can be run, it needs a GRecMutex that can be set with
gst_task_set_lock().
The task can be started, paused and stopped with gst_task_start(), gst_task_pause() and gst_task_stop() respectively or with the gst_task_set_state() function.
A GstTask will repeatedly call the GstTaskFunction with the user data
that was provided when creating the task with gst_task_new(). While calling
the function it will acquire the provided lock. The provided lock is released
when the task pauses or stops.
Stopping a task with gst_task_stop() will not immediately make sure the task is not running anymore. Use gst_task_join() to make sure the task is completely stopped and the thread is stopped.
After creating a GstTask, use gst_object_unref() to free its resources. This can
only be done when the task is not running anymore.
Task functions can send a GstMessage to send out-of-band data to the
application. The application can receive messages from the GstBus in its
mainloop.
For debugging purposes, the task will configure its object name as the thread name on Linux. Please note that the object name should be configured before the task is started; changing the object name after the task has been started, has no effect on the thread name.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classTask.Builder<B extends Task.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class org.freedesktop.gstreamer.gst.GstObject
GstObject.DeepNotifyCallback, GstObject.Object$Impl, GstObject.ObjectClassNested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback -
Constructor Summary
ConstructorsConstructorDescriptionTask()Creates a new Task.Task(MemorySegment address) Create a Task proxy instance for the provided memory address.Task(@Nullable TaskFunction func) Create a new Task that will repeatedly call the providedfuncwithuserDataas a parameter. -
Method Summary
Modifier and TypeMethodDescriptionprotected TaskasParent()Returns this instance as if it were its parent type.static Task.Builder<? extends Task.Builder> builder()ATask.Builderobject constructs aTaskwith the specified properties.static voidWait for all tasks to be stopped.static MemoryLayoutThe memory layout of the native struct.getPool()Get theGstTaskPoolthat this task will use for its streaming threads.getState()Get the current state of the task.static @Nullable TypegetType()Get the GType of the Task classbooleanjoin()Joinstask.After this call, it is safe to unref the task and clean up the lock set with gst_task_set_lock().booleanpause()Pausestask.This method can also be called on a task in the stopped state, in which case a thread will be started and will remain in the paused state.booleanresume()Resume this Task in case it was paused.voidsetEnterCallback(@Nullable TaskThreadFunc enterFunc) CallenterFuncwhen the task function of this Task is entered.voidsetLeaveCallback(@Nullable TaskThreadFunc leaveFunc) CallleaveFuncwhen the task function of this Task is left.voidSet the mutex used by the task.voidSetpoolas the new GstTaskPool fortask.Any new streaming threads that will be created by this Task will now usepool.booleanSets the state of this Task tostate.booleanstart()Startstask.The this Task must have a lock associated with it using gst_task_set_lock() or this function will returnfalse.booleanstop()Stopstask.This method merely schedules the task to stop and will not wait for the task to have completely stopped.Methods inherited from class org.freedesktop.gstreamer.gst.GstObject
addControlBinding, checkUniqueness, deepNotify, defaultDeepNotify, defaultError, emitDeepNotify, getControlBinding, getControlRate, getGValueArray, getName, getParent, getPathString, getValue, getValueArray, hasActiveControlBindings, hasAncestor, hasAsAncestor, hasAsParent, onDeepNotify, ref, refSink, removeControlBinding, replace, setControlBindingDisabled, setControlBindingsDisabled, setControlRate, setName, setParent, suggestNextSync, syncValues, unparent, unrefMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Task
Create a Task proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Task
Create a new Task that will repeatedly call the providedfuncwithuserDataas a parameter. Typically the task will run in a new thread.The function cannot be changed after the task has been created. You must create a new
GstTaskto change the function.This function will not yet create and start a thread. Use gst_task_start() or gst_task_pause() to create and start the GThread.
Before the task can be used, a
GRecMutexmust be configured using the gst_task_set_lock() function. This lock will always be acquired whilefuncis called.- Parameters:
func- TheGstTaskFunctionto use
-
Task
public Task()Creates a new Task.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
cleanupAll
public static void cleanupAll()Wait for all tasks to be stopped. This is mainly used internally to ensure proper cleanup of internal data structures in test suites.MT safe.
-
getPool
Get theGstTaskPoolthat this task will use for its streaming threads.MT safe.
- Returns:
- the
GstTaskPoolused bytask.gst_object_unref() after usage.
-
getState
Get the current state of the task.- Returns:
- The
GstTaskStateof the taskMT safe.
-
join
public boolean join()Joinstask.After this call, it is safe to unref the task and clean up the lock set with gst_task_set_lock().The task will automatically be stopped with this call.
This function cannot be called from within a task function as this would cause a deadlock. The function will detect this and print a g_warning.
- Returns:
trueif the task could be joined.MT safe.
-
pause
public boolean pause()Pausestask.This method can also be called on a task in the stopped state, in which case a thread will be started and will remain in the paused state. This function does not wait for the task to complete the paused state.- Returns:
trueif the task could be paused.MT safe.
-
resume
public boolean resume()Resume this Task in case it was paused. If the task was stopped, it will remain in that state and this function will returnfalse.- Returns:
trueif the task could be resumed.MT safe.
- Since:
- 1.18
-
setEnterCallback
CallenterFuncwhen the task function of this Task is entered.userDatawill be passed toenterFuncandnotifywill be called whenuserDatais no longer referenced.- Parameters:
enterFunc- aGstTaskThreadFunc
-
setLeaveCallback
CallleaveFuncwhen the task function of this Task is left.userDatawill be passed toleaveFuncandnotifywill be called whenuserDatais no longer referenced.- Parameters:
leaveFunc- aGstTaskThreadFunc
-
setLock
Set the mutex used by the task. The mutex will be acquired before calling theGstTaskFunction.This function has to be called before calling gst_task_pause() or gst_task_start().
MT safe.
- Parameters:
mutex- TheGRecMutexto use
-
setPool
Setpoolas the new GstTaskPool fortask.Any new streaming threads that will be created by this Task will now usepool.MT safe.
- Parameters:
pool- aGstTaskPool
-
setState
Sets the state of this Task tostate.The this Task must have a lock associated with it using gst_task_set_lock() when going to GST_TASK_STARTED or GST_TASK_PAUSED or this function will return
false.MT safe.
- Parameters:
state- the new task state- Returns:
trueif the state could be changed.
-
start
public boolean start()Startstask.The this Task must have a lock associated with it using gst_task_set_lock() or this function will returnfalse.- Returns:
trueif the task could be started.MT safe.
-
stop
public boolean stop()Stopstask.This method merely schedules the task to stop and will not wait for the task to have completely stopped. Use gst_task_join() to stop and wait for completion.- Returns:
trueif the task could be stopped.MT safe.
-
builder
ATask.Builderobject constructs aTaskwith the specified properties. Use the variousset...()methods to set properties, and finish construction withTask.Builder.build().- Returns:
- the builder object
-