Gstreamer pipeline 到底是如何创建的?

问题描述 投票:0回答:1

我正在从这里学习 Gstreame https://gstreamer.freedesktop.org/documentation/tutorials/basic/dynamic-pipelines.html?gi-language=c

我试图理解给出的

c
程序中的回调函数。

/* Build the pipeline. Note that we are NOT linking the source at this
 * point. We will do it later. */
gst_bin_add_many (GST_BIN (data.pipeline), data.source, data.convert, data.resample, data.sink, NULL);
if (!gst_element_link_many (data.convert, data.resample, data.sink, NULL)) {
g_printerr ("Elements could not be linked.\n");
gst_object_unref (data.pipeline);
return -1;
}

上面我们构建了管道,然后

/* Set the URI to play */
g_object_set (data.source, "uri", "https://gstreamer.freedesktop.org/data/media/sintel_trailer-480p.webm", NULL);

然后

/* Connect to the pad-added signal */
g_signal_connect (data.source, "pad-added", G_CALLBACK (pad_added_handler), &data);

因此,根据我对文档的理解,我们将新的源代码板添加到

data.source
的解码器元素,然后使用三个参数
pad_added_handler
data.source
pad-added
调用
&data

然后

 /* Attempt the link */
 ret = gst_pad_link (new_pad, sink_pad);

最后,该管道的创建如下:

uridecodebin[source-demux-decoder-[src]] -->[sink]audioconvert --> audioresample --> autoaudiosink

我的理解正确吗?

c gstreamer
1个回答
0
投票

uridecodebin
有一个复用器。即,它可以根据提供的 URI 上可用的媒体创建具有不同功能的源 pad,并且在实际探测(访问和分析媒体)之前,它不会知道 URI 上可用的媒体类型。因此
uridecodebin
会延迟源焊盘的创建,直到它拥有所有这些信息。

并且因为该源焊盘不存在,所以我们无法使用

gst_element_link_many
链接该元素。

当所有必需的信息最终可用时,GStreamer 将从该元素请求兼容的源 pad,并且要知道何时发生这种情况,我们必须在该元素的

pad-added
信号上注册回调。这就是用这段代码完成的

g_signal_connect (data.source, "pad-added", G_CALLBACK (pad_added_handler), &data);

因此,当添加新的 pad 时,GStreamer 调用

pad_added_handler
回调并向其传递新源 pad 的实例和提供的数据。

现在我们仍然需要将这个新垫连接到下一个元素的接收垫。所以在回调函数中,我们通过

获取下一个元素的接收垫
GstPad *sink_pad = gst_element_get_static_pad (data->convert, "sink");

最后将这些垫与

链接
ret = gst_pad_link (new_pad, sink_pad);
© www.soinside.com 2019 - 2024. All rights reserved.