Next: , Previous: GstTagSetter, Up: Top


37 GstTask

Abstraction of GStreamer streaming threads.

37.1 Overview

<gst-task> is used by <gst-element> and <gst-pad> to provide the data passing threads in a <gst-pipeline>.

A <gst-pad> will typically start a <gst-task> to push or pull data to/from the peer pads. Most source elements start a <gst-task> to push data. In some cases a demuxer element can start a <gst-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 a <gst-task> manually if it is not related to a <gst-pad>.

Before the <gst-task> can be run, it needs a <g-static-rec-mutex> 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.

A <gst-task> will repeadedly call the <gst-task-function> with the user data that was provided when creating the task with gst-task-create. Before calling the function it will acquire the provided lock.

Stopping a task with gst-task-stop will not immediatly 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 <gst-task>, use gst-object-unref to free its resources. This can only be done it the task is not running anymore.

Last reviewed on 2006-02-13 (0.10.4)

37.2 Usage

— Class: <gst-task>

This <gobject> class defines no properties, other than those defined by its superclasses.

— Function: gst-task-cleanup-all

Wait for all tasks to be stopped. This is mainly used internally to ensure proper cleanup of internal datastructures in testsuites.

MT safe.

— Function: gst-task-create (func <gst-task-function>) (data <gpointer>)   (ret <gst-task>)

Create a new Task that will repeadedly call the provided func with 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 GstTask to change the function.

func
The <gst-task-function> to use
data
User data to pass to func
ret
A new <gst-task>. MT safe.
— Function: gst-task-get-state (self <gst-task>)   (ret <gst-task-state>)
— Method: get-state

Get the current state of the task.

task
The <gst-task> to query
ret
The <gst-task-state> of the task MT safe.
— Function: gst-task-join (self <gst-task>)   (ret bool)
— Method: join

Joins 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.

task
The <gst-task> to join
ret
TRUE if the task could be joined. MT safe.
— Function: gst-task-pause (self <gst-task>)   (ret bool)
— Method: pause

Pauses 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.

task
The <gst-task> to pause
ret
TRUE if the task could be paused. MT safe.
— Function: gst-task-set-lock (self <gst-task>) (mutex <g-static-rec-mutex*>)
— Method: set-lock

Set the mutex used by the task. The mutex will be acquired before calling the <gst-task-function>.

This function has to be called before calling gst-task-pause or gst-task-start.

MT safe.

task
The <gst-task> to use
mutex
The GMutex to use
— Function: gst-task-start (self <gst-task>)   (ret bool)
— Method: start

Starts task. The task must have a lock associated with it using gst-task-set-lock or thsi function will return FALSE.

task
The <gst-task> to start
ret
TRUE if the task could be started. MT safe.
— Function: gst-task-stop (self <gst-task>)   (ret bool)
— Method: stop

Stops 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.

task
The <gst-task> to stop
ret
TRUE if the task could be stopped. MT safe.