Gst.Task¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
- Inherited:
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
cond |
r |
used to pause/resume the task |
|
func |
r |
the function executed by this task |
|
lock |
r |
The lock taken when iterating the task function |
|
notify |
r |
|
|
object |
r |
||
running |
r |
a flag indicating that the task is running |
|
state |
r |
the state of the task |
|
thread |
r |
||
user_data |
r |
user_data passed to the task function |
Class Details¶
- class Gst.Task(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Gst.Task
is used byGst.Element
andGst.Pad
to provide the data passing threads in aGst.Pipeline
.A
Gst.Pad
will typically start aGst.Task
to push or pull data to/from the peer pads. Most source elements start aGst.Task
to push data. In some cases a demuxer element can start aGst.Task
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
Gst.Pad
to start/pause/stop tasks, it might sometimes be needed to create aGst.Task
manually if it is not related to aGst.Pad
.Before the
Gst.Task
can be run, it needs aGLib.RecMutex
that can be set withGst.Task.set_lock
().The task can be started, paused and stopped with
Gst.Task.start
(),Gst.Task.pause
() andGst.Task.stop
() respectively or with theGst.Task.set_state
() function.A
Gst.Task
will repeatedly call theGst.TaskFunction
with the user data that was provided when creating the task withGst.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. UseGst.Task.join
() to make sure the task is completely stopped and the thread is stopped.After creating a
Gst.Task
, useGst.Object.unref
() to free its resources. This can only be done when the task is not running anymore.Task functions can send a
Gst.Message
to send out-of-band data to the application. The application can receive messages from theGst.Bus
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.
- classmethod cleanup_all()[source]¶
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.
- classmethod new(func, *user_data)[source]¶
- Parameters:
func (
Gst.TaskFunction
) – TheGst.TaskFunction
to use
- Returns:
A new
Gst.Task
.MT safe.
- Return type:
Create a new Task that will repeatedly call the provided func with user_data 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
Gst.Task
to change the function.This function will not yet create and start a thread. Use
Gst.Task.start
() orGst.Task.pause
() to create and start theGLib.Thread
.Before the task can be used, a
GLib.RecMutex
must be configured using theGst.Task.set_lock
() function. This lock will always be acquired while func is called.
- get_pool()[source]¶
- Returns:
the
Gst.TaskPool
used by self.Gst.Object.unref
() after usage.- Return type:
Get the
Gst.TaskPool
that this task will use for its streaming threads.MT safe.
- get_state()[source]¶
- Returns:
The
Gst.TaskState
of the taskMT safe.
- Return type:
Get the current state of the task.
- join()[source]¶
-
Joins self. 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.
- pause()[source]¶
-
Pauses self. 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.
- resume()[source]¶
-
Resume self in case it was paused. If the task was stopped, it will remain in that state and this function will return
False
.New in version 1.18.
- set_enter_callback(enter_func, *user_data)[source]¶
- Parameters:
enter_func (
Gst.TaskThreadFunc
) – aGst.TaskThreadFunc
Call enter_func when the task function of self is entered. user_data will be passed to enter_func and notify will be called when user_data is no longer referenced.
- set_leave_callback(leave_func, *user_data)[source]¶
- Parameters:
leave_func (
Gst.TaskThreadFunc
) – aGst.TaskThreadFunc
Call leave_func when the task function of self is left. user_data will be passed to leave_func and notify will be called when user_data is no longer referenced.
- set_lock(mutex)[source]¶
- Parameters:
mutex (
GLib.RecMutex
) – TheGLib.RecMutex
to use
Set the mutex used by the task. The mutex will be acquired before calling the
Gst.TaskFunction
.This function has to be called before calling
Gst.Task.pause
() orGst.Task.start
().MT safe.
- set_pool(pool)[source]¶
- Parameters:
pool (
Gst.TaskPool
) – aGst.TaskPool
Set pool as the new
Gst.TaskPool
for self. Any new streaming threads that will be created by self will now use pool.MT safe.
- set_state(state)[source]¶
- Parameters:
state (
Gst.TaskState
) – the new task state- Returns:
True
if the state could be changed.- Return type:
Sets the state of self to state.
The self must have a lock associated with it using
Gst.Task.set_lock
() when going toGst.TaskState.STARTED
orGst.TaskState.PAUSED
or this function will returnFalse
.MT safe.
- start()[source]¶
-
Starts self. The self must have a lock associated with it using
Gst.Task.set_lock
() or this function will returnFalse
.
- stop()[source]¶
-
Stops self. 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.