一. 基础名词概念
名词 | 概念 |
---|---|
Elements | An element is the most important class of objects in GStreamer. |
Pads | Pads are an element’s input and output, where you can connect other elements. A pad type is defined by two properties: its direction and its availability. |
Bins | A bin is a container for a collection of elements. |
Pipelines | A pipeline is a top-level bin. |
Bus | A bus is a simple system that takes care of forwarding messages from the streaming threads to an application in its own thread context |
Capabilities(short: caps) | describe the type of data that is streamed between two pads, or that one pad (template) supports. |
Ghost pads | A pad from some element in the bin that can be accessed directly from the bin as well. gst_element_add_pad (bin, gst_ghost_pad_new (“sink”, pad)); |
一. Bus
- 每一个管道默认拥有一个总线Bus(不知道是不是这么翻译),不需要自己创建,只需设置消息处理函数到总线上即可,总线会自动周期检查消息并调用设置好的回调函数。
使用Glib mainloop时总线信号处理函数注册可用方式:
1 2 3 4 5 6 7 8 |
GstBus *bus; 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); |
二. 流经管道的数据包括了实际媒体数据和相关控制信息,名为Buffer和Event
1 2 3 4 5 |
Buffer包含数据指针和时间戳,被引用总数,标志位 Event包含查询,刷新和流结束通知等事件 |
命令行运行输出文件为其可支持格式
1 2 3 |
gst-launch-1.0 playbin uri=file:///home/rease/Downloads/2.mp3 |
以上为播放音频
三. Pads
Pad 的3种可用性
可用性 | 代表意思 |
---|---|
Dynamic(or sometimes) pads | Sometimes pads exist only in certain cases ( can disappear reanomly) |
Request pads | Appears only if explicitly requested by applications |
Always pads | pads always exist |
-
动态Pads
当需要创建动态pipeline的时候,可以绑定信号处理函数到特定的element,当element自动创建完新的pad会发出pad-added信号,只要捕获此信号,就可以在信号处理函数中完成需要完成的动作,如element之间的链接(link)
123g_signal_connect (GstElement, "pad-added", G_CALLBACK (cb_new_pad), NULL);123456789101112static voidcb_new_pad (GstElement *element, GstPad *pad, gpointer data) {gchar *name; name = gst_pad_get_name (pad);g_print ("A new pad %s was created\n", name);g_free (name);/* here, you would setup a new pad link for the newly created pad */[..]} -
Request pads
request pads不像dynamic pads一样会被自动创建,而是按需创建的。
这种功能在一些场合,如在多路复用器,聚合器和Tee elements中非常有用。
所谓聚合器是指elements将多个输入汇合成一个输出,Tee elements刚好相反。
多路复用器是指从多个信号中选择一个进行输出(亦称数据选择器)。可以通过 gst_element_get_request_pad (TeeElement, name)来获取特定名称的pad,或者使用 gst_element_get_compatible_pad (GstElement, toLinkPad, NULL)自动选择获取与将要链接的源pad兼容的目标pad。再用 gst_pad_link (tolink_pad, pad)进行链接。
Ogg可以以各种格式(如Dirac,MNG,CELT,MPEG-4,MP3等), 嵌入音频和视频