uridecodebin
How to use uridecodebin.
uridecodebin能够将URI数据解码成raw media,它会自动选择一个能处理uri数据的source element并将其和decodebin链接。
Github: uridecodebin
uri
bool Create (void)
{
// ...
g_object_set (G_OBJECT (m_source), "uri", m_config.src.c_str(), NULL);
// ...
}signals
source-setup
static void cb_uridecodebin_source_setup (
GstElement* pipeline, GstElement* source, gpointer user_data)
{
VideoPipeline* vp = reinterpret_cast<VideoPipeline*> (user_data);
LOG_INFO_MSG ("cb_uridecodebin_source_setup called");
/* Configure rtspsrc
if (g_object_class_find_property (G_OBJECT_GET_CLASS (source), "latency")) {
LOG_INFO_MSG ("cb_uridecodebin_source_setup set %d latency",
vp->m_config.rtsp_latency);
g_object_set (G_OBJECT (source), "latency", vp->m_config.rtsp_latency, NULL);
}
*/
/* Configure appsrc
GstCaps *m_sCaps;
src_Caps = gst_caps_new_simple ("video/x-raw", "format", G_TYPE_STRING,
m_config.src_format.c_str(), "width", G_TYPE_INT, m_config.src_width,
"height", G_TYPE_INT, m_config.src_height, NULL);
g_object_set (G_OBJECT(source), "caps", src_Caps, NULL);
g_signal_connect (source, "need-data", G_CALLBACK (start_feed), data);
g_signal_connect (source, "enough-data", G_CALLBACK (stop_feed), data);
gst_caps_unref (src_Caps);
*/
}uridecodebin会分析uri属性的值,然后选择合适的srouce element,这个uri值必须是完整的绝对路径,由source类型开始。
child-added
通过打印log可以看出uridecodebin初始化过程中自动添加到pipeline中的所有GstElement:
在uridecodebin只会添加decodebin一个GstElement,上述的GstElement均由decodebin构建,因此除了uridecodebin的child-added回调,还在其回调中添加了一个decodebin的child-added回调,用于设置decodebin构建的GstElement的属性。
在build pipeline中提到关于filesrc插件的解复用,需要手动进行link,但这个link在实际测试过程中有decodebin自动完成,我尝试手动去做link,由于无法获取到h264parse的sink pad程序抛出了段错误。我打印了这时候vp->m_h264parse的指针地址,是一个初始值,说明这时候还未初始化vp->m_h264parse。
pad-added
将uridecodebin的src pad和waylandsin的sink pad连接起来,由于这时是解码后的数据,因此caps为video/x-raw或audio/x-raw类型。
在上文中提到关于qtdemux解复用器的链接问题,事实上uridecodebin内部会自动处理好这部分链接,并且为所有能够解析的数据类型创建src-pad,每创建一种类型的src-pad,pad-added回调就会触发一次,用户需要自行完成uridecodebin的这些src-pad与后续GstElement的链接。可以结合Build Pipeline中关于pad-link的内容一起理解。
在上述代码中我将video/x-raw类型的数据和videoconvert插件链接,将audio/x-raw与audioconvert链接,videoconvert和audioconvert几乎是万能的格式转换插件能够提高代码的可移植性,使得代码能够在各种平台上正常运行,但切记这两者的转换均是使用CPU完成,因此十分消耗性能,在推流中使用会造成极大的延迟。
Last updated
Was this helpful?