After being created, an element will not actually perform any actions yet. You need to change elements state to make it do something. GStreamer knows four element states, each with a very specific meaning. Those four states are:
GST_STATE_NULL
: this is the default state.
This state will deallocate all resources held by the element.
GST_STATE_READY
: in the ready state, an
element has allocated all of its global resources, that is,
resources that can be kept within streams. You can think about
opening devices, allocating buffers and so on. However, the
stream is not opened in this state, so the stream positions is
automatically zero. If a stream was previously opened, it should
be closed in this state, and position, properties and such should
be reset.
GST_STATE_PAUSED
: in this state, an
element has opened the stream, but is not actively processing
it. An element is allowed to modify a stream's position, read
and process data and such to prepare for playback as soon as
state is changed to PLAYING, but it is not
allowed to play the data which would make the clock run.
In summary, PAUSED is the same as PLAYING but without a running
clock.
Elements going into the PAUSED state should prepare themselves for moving over to the PLAYING state as soon as possible. Video or audio outputs would, for example, wait for data to arrive and queue it so they can play it right after the state change. Also, video sinks can already play the first frame (since this does not affect the clock yet). Autopluggers could use this same state transition to already plug together a pipeline. Most other elements, such as codecs or filters, do not need to explicitely do anything in this state, however.
GST_STATE_PLAYING
: in the PLAYING state,
an element does exactly the same as in the PAUSED state, except
that the clock now runs.
You can change the state of an element using the function
gst_element_set_state ()
. If you set an element
to another state, GStreamer will internally traverse all intermediate
states. So if you set an element from NULL to PLAYING, GStreamer
will internally set the element to READY and PAUSED in between.
When moved to GST_STATE_PLAYING
, pipelines
will process data automatically. They do not need to be iterated in
any form. Internally, GStreamer will start threads that take this
task on to them. GStreamer will also take care of switching
messages from the pipeline's thread into the application's own
thread, by using a GstBus
. See
Chapter 7 for details.