Class Task

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Task extends GstObject

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.

  • Constructor Details

    • Task

      public Task(MemorySegment address)
      Create a Task instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Task

      public Task(@Nullable TaskFunction func)

      Create a new Task that will repeatedly call the provided func with userData 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.

      Parameters:
      func - The GstTaskFunction to use
    • Task

      public Task()
      Create a new Task.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Task class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Task asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GstObject
      Returns:
      the instance as if it were its 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

      public TaskPool getPool()

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

      MT safe.

      Returns:
      the GstTaskPool used by task. gst_object_unref() after usage.
    • getState

      public TaskState getState()
      Get the current state of the task.
      Returns:

      The GstTaskState of the task

      MT safe.

    • join

      public boolean 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.

      Returns:

      true if the task could be joined.

      MT safe.

    • pause

      public boolean 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.
      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 return false.
      Returns:

      true if the task could be resumed.

      MT safe.

      Since:
      1.18
    • setEnterCallback

      public void setEnterCallback(@Nullable TaskThreadFunc enterFunc)
      Call enterFunc when the task function of this Task is entered. userData will be passed to enterFunc and notify will be called when userData is no longer referenced.
      Parameters:
      enterFunc - a GstTaskThreadFunc
    • setLeaveCallback

      public void setLeaveCallback(@Nullable TaskThreadFunc leaveFunc)
      Call leaveFunc when the task function of this Task is left. userData will be passed to leaveFunc and notify will be called when userData is no longer referenced.
      Parameters:
      leaveFunc - a GstTaskThreadFunc
    • setLock

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

      Parameters:
      mutex - The GRecMutex to use
    • setPool

      public void setPool(TaskPool pool)

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

      MT safe.

      Parameters:
      pool - a GstTaskPool
    • setState

      public boolean setState(TaskState state)

      Sets the state of this Task to state.

      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 task. The this Task must have a lock associated with it using gst_task_set_lock() or this function will return false.
      Returns:

      true if the task could be started.

      MT safe.

    • stop

      public boolean 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.
      Returns:

      true if the task could be stopped.

      MT safe.

    • builder

      public static Task.Builder<? extends Task.Builder> builder()
      A Task.Builder object constructs a Task with the specified properties. Use the various set...() methods to set properties, and finish construction with Task.Builder.build().
      Returns:
      the builder object