standard tutorial
- How to initialize GStreamer using
gst_init()
. - How to quickly build a pipeline from a textual description using
gst_parse_launch()
. - How to create an automatic playback pipeline using
playbin
. - How to signal GStreamer to start playback using
gst_element_set_state()
. - How to sit back and relax, while GStreamer takes care of everything, using
gst_element_get_bus()
andgst_bus_timed_pop_filtered()
.
- media from source to sink
- playbin is a special element which acts as a source and as a sink, and is a whole pipeline
- gst_bus_timed_pop_filtered() will block until you receive either an ERROR or an EOS (End-Of-Stream) through that bus.
customize elements
- How to create elements with
gst_element_factory_make()
- How to create an empty pipeline with
gst_pipeline_new()
- How to add elements to the pipeline with
gst_bin_add_many()
- How to link the elements with each other with
gst_element_link()
- source = gst_element_factory_make (“videotestsrc”, “source”);
param1: type
param2: name(if null, GStreamer will provide a unique name for you)- pipeline is also another particular type of BIN
- GStreamer elements are all a particular kind of GObject
- Properties are read from with g_object_get() and written to with g_object_set().
- First use
GST_MESSAGE_TYPE()
then check error viagst_message_parse_error()
.- Messages can be extracted from the bus synchronously with
gst_bus_timed_pop_filtered()
and its siblings, or asynchronously, using signals.
Dynamic pipelines
//piece of invoking.
g_signal_connect(data.source, "pad-added", G_CALLBACK(pad_added_handler), &data);
static void pad_added_handler(GstElement *src, GstPad *new_pad, CustomData *data) {
//Caution: `sink` here refer to pad not element
GstPad *sink_pad = gst_element_get_static_pad(data->convert, "sink");
GstPadLinkReturn ret;
GstCaps *new_pad_caps = NULL;
GstStructure *new_pad_struct = NULL;
const gchar *new_pad_type = NULL;
g_print("Received new pad '%s' from '%s':\n", GST_PAD_NAME(new_pad), GST_ELEMENT_NAME(src));
/* If our converter is already linked, we have nothing to do here */
if (gst_pad_is_linked(sink_pad)) {
g_print("We are already linked. Ignoring.\n");
goto exit;
}
/* Check the new pad's type */
new_pad_caps = gst_pad_get_current_caps(new_pad); //retrive all caps (the kind of data it currently outputs)
new_pad_struct = gst_caps_get_structure(new_pad_caps, 0);
new_pad_type = gst_structure_get_name(new_pad_struct); //get the name and check later
if (!g_str_has_prefix(new_pad_type, "audio/x-raw")) {
g_print("It has type '%s' which is not raw audio. Ignoring.\n", new_pad_type);
goto exit;
}
/* Attempt the link */
ret = gst_pad_link(new_pad, sink_pad);
if (GST_PAD_LINK_FAILED(ret)) {
g_print("Type is '%s' but link failed.\n", new_pad_type);
}
else {
g_print("Link succeeded (type '%s').\n", new_pad_type);
}
exit:
/* Unreference the new pad's caps, if we got them */
if (new_pad_caps != NULL)
gst_caps_unref(new_pad_caps);
/* Unreference the sink pad */
gst_object_unref(sink_pad);
}
GStreamer States
State | Description |
---|---|
NULL |
the NULL state or initial state of an element. |
READY |
the element is ready to go to PAUSED. |
PAUSED |
the element is PAUSED, it is ready to accept and process data. Sink elements however only accept one buffer and then block. |
PLAYING |
the element is PLAYING, the clock is running and the data is flowing. |
You can only move between adjacent ones
element
gst_element_factory_make实际包含了两个功能:
- gst_element_factory_find () //查找工厂
- gst_element_factory_create () //使用改工厂创建对象
gst_object_unref
计数器-1
GstElement
inherits GstObject
连接元素之前必须将他们放入一个bin中
you must add elements to a bin or pipeline before linking them, since adding an element to a bin will disconnect any already existing links. Also, you cannot directly link elements that are not in the same bin or pipeline;
gst_element_set_state (GST_STATE_PLAYING) //其内部会逐个设置 READY, PAUSED
状态会向前传播,一般只需要设置上层的状态
When you set a bin or pipeline to a certain target state, it will usually propagate the state