GStreamer Application Development Manual (0.8.7.3) | ||
---|---|---|
<<< Previous | Next >>> |
GStreamer has support for multithreading through the use of
the GstThread
object. This object is in fact a special GstBin
that will start a new thread (using Glib's
GThread
system) when started.
To create a new thread, you can simply use gst_thread_new
(). From then on, you can use it similar to how you would
use a GstBin
. You can add elements to it,
change state and so on. The largest difference between a thread and
other bins is that the thread does not require iteration. Once set to
the GST_STATE_PLAYING
state, it will iterate
its contained children elements automatically.
Figure 1 shows how a thread can be visualised.
There are several reasons to use threads. However, there's also some reasons to limit the use of threads as much as possible. We will go into the drawbacks of threading in GStreamer in the next section. Let's first list some situations where threads can be useful:
Data buffering, for example when dealing with network streams or when recording data from a live stream such as a video or audio card. Short hickups elsewhere in the pipeline will not cause data loss. See Figure 2 for a visualization of this idea.
Synchronizing output devices, e.g. when playing a stream containing both video and audio data. By using threads for both outputs, they will run independently and their synchronization will be better.
Data pre-rolls. You can use threads and queues (thread boundaries) to cache a few seconds of data before playing. By using this approach, the whole pipeline will already be setup and data will already be decoded. When activating the rest of the pipeline, the switch from PAUSED to PLAYING will be instant.
Above, we've mentioned the "queue" element several times
now. A queue is a thread boundary element. It does so by using a
classic provider/receiver model as learned in threading classes at
universities all around the world. By doing this, it acts both as a
means to make data throughput between threads threadsafe, and it can
also act as a buffer. Queues have several GObject
properties to be configured for specific uses. For example, you can set
lower and upper tresholds for the element. If there's less data than
the lower treshold (default: disabled), it will block output. If
there's more data than the upper treshold, it will block input or
(if configured to do so) drop data.
<<< Previous | Home | Next >>> |
Different Types of Dynamic Parameter | Up | Constraints placed on the pipeline by the GstThread |