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
Modifier and TypeClassDescriptionstatic class
Task.Builder<B extends Task.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.freedesktop.gstreamer.gst.GstObject
GstObject.DeepNotifyCallback, GstObject.ObjectClass, GstObject.ObjectImpl
Nested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClass
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback
-
Constructor Summary
ConstructorDescriptionTask
(MemorySegment address) Create a Task proxy instance for the provided memory address.Task
(TaskFunction func) Create a new Task that will repeatedly call the providedfunc
withuserData
as a parameter. -
Method Summary
Modifier and TypeMethodDescriptionprotected Task
asParent()
Returns this instance as if it were its parent type.static Task.Builder
<? extends Task.Builder> builder()
ATask.Builder
object constructs aTask
with the specified properties.static void
Wait for all tasks to be stopped.static MemoryLayout
The memory layout of the native struct.getPool()
Get theGstTaskPool
that this task will use for its streaming threads.getState()
Get the current state of the task.static Type
getType()
Get the GType of the Task classboolean
join()
Joins this Task.boolean
pause()
Pauses this Task.boolean
resume()
Resume this Task in case it was paused.void
setEnterCallback
(TaskThreadFunc enterFunc) CallenterFunc
when the task function of this Task is entered.void
setLeaveCallback
(TaskThreadFunc leaveFunc) CallleaveFunc
when the task function of this Task is left.void
Set the mutex used by the task.void
Setpool
as the new GstTaskPool for this Task.boolean
Sets the state of this Task tostate
.boolean
start()
Starts this Task.boolean
stop()
Stops this Task.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, unref
Methods 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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.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 providedfunc
withuserData
as 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
GstTask
to 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
GRecMutex
must be configured using the gst_task_set_lock() function. This lock will always be acquired whilefunc
is called.- Parameters:
func
- TheGstTaskFunction
to use
-
-
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 Javasuper
keyword, 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 theGstTaskPool
that this task will use for its streaming threads.MT safe.
- Returns:
- the
GstTaskPool
used by this Task. gst_object_unref() after usage.
-
getState
Get the current state of the task.- Returns:
- The
GstTaskState
of the taskMT safe.
-
join
public boolean join()Joins this Task. 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:
true
if the task could be joined.MT safe.
-
pause
public boolean pause()Pauses this Task. 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:
true
if 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:
true
if the task could be resumed.MT safe.
-
setEnterCallback
CallenterFunc
when the task function of this Task is entered.userData
will be passed toenterFunc
andnotify
will be called whenuserData
is no longer referenced.- Parameters:
enterFunc
- aGstTaskThreadFunc
-
setLeaveCallback
CallleaveFunc
when the task function of this Task is left.userData
will be passed toleaveFunc
andnotify
will be called whenuserData
is 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
- TheGRecMutex
to use
-
setPool
Setpool
as the new GstTaskPool for this Task. 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:
true
if the state could be changed.
-
start
public boolean start()Starts this Task. The this Task must have a lock associated with it using gst_task_set_lock() or this function will returnfalse
.- Returns:
true
if the task could be started.MT safe.
-
stop
public boolean stop()Stops this Task. 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:
true
if the task could be stopped.MT safe.
-
builder
ATask.Builder
object constructs aTask
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withTask.Builder.build()
.
-