GStreamer is an extremely powerful and versatile framework for creating streaming media applications.
it use GObject,glib,etc.
‧ GObject instentiation
‧ GObject properties (set/get)
‧ GObject casting
‧ GObject referecing/dereferencing
‧ glib memory management
‧ glib signals and callbacks
‧ glib main loop
It's feature contain: plugin. pipeline, source , filter, sink,codec,format,protocal
An element is the most important class of objects in GStreamer.
Pads are element’s input and output, where you can connect other elements.
A bin is a container for a collection of elements.
A pipeline is a special subtype of a bin that allows execution of all of its contained child elements.
初始化:
gst_init (&argc, &argv);
gst_version (&major, &minor, µ, &nano);
or 使用GOption初始化
創建Element:
gst_element_factory_make 相?于gst_element_factory_find + gst_element_factory_create
釋放Element:
gst_object_unref(GST_OBJECT (element));
獲取/設置GstElement/GObject?性
GstElement 繼承了GObject,所以可以設置屬性
g_object_get (G_OBJECT (element), "name", &name, NULL);
Element factories are the basic types retrieved from the GStreamer registry, they describe all plugins
and elements that GStreamer can create.
for creating lists of available elements, such as what pipeline editing applications do.
從 Element Factory 中獲取信息:
gst_plugin_feature_get_name
gst_element_factory_get_klass \\所屬類別
gst_element_factory_get_description\\詳細信息
gst_registry_pool_feature_list\\全部feature list
gst_bin_add_many (GST_BIN (pipeline), source, filter, sink, NULL);\\add source ,filter ,sink elements to pipeline first
gst_element_link_many (source, filter, sink, NULL)\\link all
gst_element_link () ,gst_element_link_pads () ...will also link elements.
elements state:
GST_STATE_NULL
GST_STATE_READY
GST_STATE_PAUSED
GST_STATE_PLAYING
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.
bin:A bin is a container element.
gst_bin_new () or gst_pipeline_new () \\create a new bin
gst_bin_add () \\ add element to bin
gst_bin_remove \\ remove element from bin
gst_bin_get_list \\ get a elements list of bin
bus:A bus is a simple system that takes care of forwarding messages from the pipeline threads to an application in its own thread context.
There are two different ways to use a bus:
‧ Run a GLib/Gtk+ main loop (or iterate the defauly GLib main context yourself regularly) and attach some kind of watch to the bus.
This way the GLib main loop will check the bus for new messages and notify you whenever there are messages.
Typically you would use gst_bus_add_watch() or gst_bus_add_signal_watch() in this case.
To use a bus, attach a message handler to the bus of a pipeline using gst_bus_add_watch().
This handler will be called whenever the pipeline emits a message to the bus.
In this handler, check the signal type (see next section) and do something accordingly.
The return value of the handler should be TRUE to remove the message from the bus.
‧ Check for messages on the bus yourself. This can be done using gst_bus_peek() and/or gst_bus_poll().
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline);
gst_bus_add_signal_watch (bus);
g_signal_connect (bus, "message::error", G_CALLBACK (cb_message_error), NULL);
g_signal_connect (bus, "message::eos", G_CALLBACK (cb_message_eos), NULL);
Message types:
Error
End-of-stream
Tags:emitted when metadata was found in the stream.
State-changes
Buffering:emitted during caching of network-streams.
Element messages: these are special messages that are unique to certain elements and usually represent additional features.
Application-specific messages: any information on those can be extracted by getting the message structure (see above) and reading its fields.
pad:A pad type is defined by two properties: its direction and its availability.
A pad can have any of three availabilities:always, sometimes and on request.
gst_element_get_request_pad \\ get a request pad
capabilities:
Properties are used to describe extra information for capabilities.
Basic types, this can be pretty much any GType registered with Glib.
Range types are GTypes registered by GStreamer to indicate a range of possible values.
A list value (GST_TYPE_LIST): the property can take any value from a list of basic values given in this list.
An array value (GST_TYPE_ARRAY): the property is an array of values.
Capabilities (short: caps) describe the type of data that is streamed between two pads, or that one pad (template) supports.
This makes them very useful for various purposes:
‧ Autoplugging: automatically finding elements to link to a pad based on its capabilities.
All autopluggers use this method.
‧ Compatibility detection: when two pads are linked, GStreamer can verify if the two pads are talking about the same media type.
The process of linking two pads and checking if they are compatible called "caps negotiation".
‧ Metadata: by reading the capabilities from a pad, applications can provide information about the
of media that is being streamed over the pad, which is information about the stream that is currently being played back.
‧ Filtering: an application can use capabilities to limit the possible media types that can stream between two pads to a specific subset of their supported stream types.
An application can, for example, use "filtered caps" to set a specific (fixed or non-fixed) video size that should stream between two pads.
You will see an example of filtered caps later in this manual, in Section 18.2.
You can do caps filtering by inserting a capsfilter element into your pipeline and setting its "caps" property.
Caps filters are placed after converter elements like audioconvert, audioresample, ffmpegcolorspace or videoscale
force those converters to convert data to a specific output format at a certain point in a stream.
gst_caps_get_structure () \\ get a structure of a cap
gst_caps_get_size () \\ get number of caps
gst_structure_get_int (str, "width", &width) \\ get width
gst_structure_get_int (str, "height", &height) \\ get height
gst_caps_new_simple \\ create a simple cap
gst_caps_new_full \\ create more caps
gst_element_link_filtered () it will automatically create a capsfilter element for you and insert it into your bin or pipeline between the two elements you want to connect (this is important if you ever want to disconnect those elements).
Ghost pads:A ghost pad is a pad from some element in the bin that can be accessed directly from the bin as well.
Compare it to a symbolic link in UNIX filesystems.
Using ghost pads on bins, the bin also has a pad and can transparently be used as an element in other parts of your code.
/* add ghostpad */
pad = gst_element_get_static_pad (sink, "sink");
gst_element_add_pad (bin, gst_ghost_pad_new ("sink", pad));
Buffers:Buffers contain the data that will flow through the pipeline you have created.
A buffer consists, amongst others, of:
‧ A pointer to a piece of memory.
‧ The size of the memory.
‧ A timestamp for the buffer.
‧ A refcount that indicates how many elements are using this buffer.
This refcount will be used to destroy the buffer when no element has a reference to it.
Events:Events are control particles that are sent both up- and downstream in a pipeline along with buffers.
GstEvent *event;
event = gst_event_new_seek (GST_SEEK_METHOD_SET | GST_FORMAT_TIME, time_ns);
gst_element_send_event (element, event);
留言列表