Task

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.

Last reviewed on 2012-03-29 (0.11.3)

Constructors

this
this(GstTask* gstTask)

Sets our main struct and passes it to the parent class

this
this(GstTaskFunction func, void* userData, GDestroyNotify notify)

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 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 while func is called.

Members

Functions

getPool
TaskPool getPool()

Get the GstTaskPool that this task will use for its streaming threads. MT safe.

getState
GstTaskState getState()

Get the current state of the task.

getStruct
void* getStruct()

the main Gtk struct as a void*

getTaskStruct
GstTask* getTaskStruct()

Get the main Gtk struct

join
int 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.

pause
int 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.

setEnterCallback
void setEnterCallback(GstTaskThreadFunc enterFunc, void* userData, GDestroyNotify notify)

Call enter_func when the task function of task is entered. user_data will be passed to enter_func and notify will be called when user_data is no longer referenced.

setLeaveCallback
void setLeaveCallback(GstTaskThreadFunc leaveFunc, void* userData, GDestroyNotify notify)

Call leave_func when the task function of task is left. user_data will be passed to leave_func and notify will be called when user_data is no longer referenced.

setLock
void setLock(RecMutex mutex)

Set the mutex used by the task. The mutex will be acquired before calling the GstTaskFunction. This function has to be called before calling gst_task_pause() or gst_task_start(). MT safe.

setPool
void setPool(TaskPool pool)

Set pool as the new GstTaskPool for task. Any new streaming threads that will be created by task will now use pool. MT safe.

setState
int setState(GstTaskState state)

Sets the state of task to state. The 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.

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.
start
int start()

Starts task. The task must have a lock associated with it using gst_task_set_lock() or this function will return FALSE.

stop
int 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.

Static functions

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

Variables

gstTask
GstTask* gstTask;

the main Gtk struct

Inherited Members

From ObjectGst

gstObject
GstObject* gstObject;

the main Gtk struct

getObjectGstStruct
GstObject* getObjectGstStruct()

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.
connectedSignals
int[string] connectedSignals;
onDeepNotifyListeners
void delegate(ObjectGst, ParamSpec, ObjectGst)[] onDeepNotifyListeners;
Undocumented in source.
addOnDeepNotify
void addOnDeepNotify(void delegate(ObjectGst, ParamSpec, ObjectGst) dlg, ConnectFlags connectFlags)

The deep notify signal is used to be notified of property changes. It is typically attached to the toplevel bin to receive notifications from all the elements contained in that bin.

callBackDeepNotify
void callBackDeepNotify(GstObject* gstobjectStruct, GstObject* propObject, GParamSpec* prop, ObjectGst _objectGst)
Undocumented in source. Be warned that the author may not have intended to support it.
setName
int setName(string name)

Sets the name of object, or gives object a guaranteed unique name (if name is NULL). This function makes a copy of the provided name, so the caller retains ownership of the name it sent.

getName
string getName()

Returns a copy of the name of object. Caller should g_free() the return value after usage. For a nameless object, this returns NULL, which you can safely g_free() as well. Free-function: g_free

setParent
int setParent(ObjectGst parent)

Sets the parent of object to parent. The object's reference count will be incremented, and any floating reference will be removed (see gst_object_ref_sink()).

getParent
ObjectGst getParent()

Returns the parent of object. This function increases the refcount of the parent object so you should gst_object_unref() it after usage.

unparent
void unparent()

Clear the parent of object, removing the associated reference. This function decreases the refcount of object. MT safe. Grabs and releases object's lock.

defaultDeepNotify
void defaultDeepNotify(ObjectG object, ObjectGst orig, ParamSpec pspec, string[] excludedProps)

A default deep_notify signal callback for an object. The user data should contain a pointer to an array of strings that should be excluded from the notify. The default handler will print the new value of the property using g_print. MT safe. This function grabs and releases object's LOCK for getting its path string.

defaultError
void defaultError(ErrorG error, char dbug)

A default error function that uses g_printerr() to display the error message and the optional debug sting.. The default handler will simply print the error string using g_print.

checkUniqueness
int checkUniqueness(ListG list, string name)

Checks to see if there is any object named name in list. This function does not do any locking of any kind. You might want to protect the provided list with the lock of the owner of the list. This function will lock each GstObject in the list to compare the name, so be carefull when passing a list with a locked object.

hasAncestor
int hasAncestor(ObjectGst ancestor)

Check if object has an ancestor ancestor somewhere up in the hierarchy. One can e.g. check if a GstElement is inside a GstPipeline.

doref
void* doref(void* object)

Increments the reference count on object. This function does not take the lock on object because it relies on atomic refcounting. This object returns the input parameter to ease writing

unref
void unref(void* object)

Decrements the reference count on object. If reference count hits zero, destroy object. This function does not take the lock on object as it relies on atomic refcounting. The unref method should never be called with the LOCK held since this might deadlock the dispose function.

refSink
void* refSink(void* object)

Increase the reference count of object, and possibly remove the floating reference, if object has a floating reference. In other words, if the object is floating, then this call "assumes ownership" of the floating reference, converting it to a normal reference by clearing the floating flag while leaving the reference count unchanged. If the object is not floating, then this call adds a new normal reference increasing the reference count by one.

replace
int replace(ObjectGst oldobj, ObjectGst newobj)

Atomically modifies a pointer to point to a new object. The reference count of oldobj is decreased and the reference count of newobj is increased. Either newobj and the value pointed to by oldobj may be NULL.

getPathString
string getPathString()

Generates a string describing the path of object in the object hierarchy. Only useful (or used) for debugging. Free-function: g_free

suggestNextSync
GstClockTime suggestNextSync()

Returns a suggestion for timestamps where buffers should be split to get best controller results.

syncValues
int syncValues(GstClockTime timestamp)

Sets the properties of the object, according to the GstControlSources that (maybe) handle them and for the given timestamp. If this function fails, it is most likely the application developers fault. Most probably the control sources are not setup correctly.

hasActiveControlBindings
int hasActiveControlBindings()

Check if the object has an active controlled properties.

setControlBindingsDisabled
void setControlBindingsDisabled(int disabled)

This function is used to disable all controlled properties of the object for some time, i.e. gst_object_sync_values() will do nothing.

setControlBindingDisabled
void setControlBindingDisabled(string propertyName, int disabled)

This function is used to disable the GstController on a property for some time, i.e. gst_controller_sync_values() will do nothing for the property.

addControlBinding
int addControlBinding(ControlBinding binding)

Attach the GstControlBinding to the object. If there already was a GstControlBinding for this property it will be replaced. The object will take ownership of the binding.

getControlBinding
ControlBinding getControlBinding(string propertyName)

Gets the corresponding GstControlBinding for the property. This should be unreferenced again after use.

removeControlBinding
int removeControlBinding(ControlBinding binding)

Removes the corresponding GstControlBinding. If it was the last ref of the binding, it will be disposed.

getValue
Value getValue(string propertyName, GstClockTime timestamp)

Gets the value for the given controlled property at the requested time.

getValueArray
int getValueArray(string propertyName, GstClockTime timestamp, GstClockTime interval, void[] values)

Gets a number of values for the given controlled property starting at the requested time. The array values need to hold enough space for n_values of the same type as the objects property's type. This function is useful if one wants to e.g. draw a graph of the control curve or apply a control curve sample by sample. The values are unboxed and ready to be used. The similar function gst_object_get_g_value_array() returns the array as GValues and is better suites for bindings.

getGValueArray
int getGValueArray(string propertyName, GstClockTime timestamp, GstClockTime interval, uint nValues, Value values)

Gets a number of GValues for the given controlled property starting at the requested time. The array values need to hold enough space for n_values of GValue. This function is useful if one wants to e.g. draw a graph of the control curve or apply a control curve sample by sample.

getControlRate
GstClockTime getControlRate()

Obtain the control-rate for this object. Audio processing GstElement objects will use this rate to sub-divide their processing loop and call gst_object_sync_values() inbetween. The length of the processing segment should be up to control-rate nanoseconds. If the object is not under property control, this will return GST_CLOCK_TIME_NONE. This allows the element to avoid the sub-dividing. The control-rate is not expected to change if the element is in GST_STATE_PAUSED or GST_STATE_PLAYING.

setControlRate
void setControlRate(GstClockTime controlRate)

Change the control-rate for this object. Audio processing GstElement objects will use this rate to sub-divide their processing loop and call gst_object_sync_values() inbetween. The length of the processing segment should be up to control-rate nanoseconds. The control-rate should not change if the element is in GST_STATE_PAUSED or GST_STATE_PLAYING.

Meta