为什么如果我在其中添加了 udpsink 插件,gstreamer 管道将无法播放



我试图用gstreamer发送RTP流,但我发现管道根本无法播放。当我简化代码时,我发现如果在管道中添加udpsink插件,管道就会被阻塞,并且状态总是READY。

我的代码:

#include <gst/gst.h>
int main(int argc, char *argv[]) {
GstElement *pipeline, *source, *sink, *udp, *convert;
GstBus *bus;
GstMessage *msg;
GstStateChangeReturn ret;
gboolean terminate = FALSE;
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Create the elements */
source  = gst_element_factory_make ("videotestsrc", "source");
convert = gst_element_factory_make ("videoconvert", "convert");
sink    = gst_element_factory_make ("autovideosink", "sink");
udp     = gst_element_factory_make ("udpsink", "udp");
/* Create the empty pipeline */
pipeline = gst_pipeline_new ("test-pipeline");
/* Build the pipeline */
gst_bin_add_many (GST_BIN (pipeline), source, sink, convert, /*udp,*/ NULL);
gst_element_link_many (source, convert, sink, NULL);
/* Modify the source's properties */
g_object_set (source, "pattern", 0, NULL);
/* Start playing */
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
g_printerr ("Unable to set the pipeline to the playing state.n");
gst_object_unref (pipeline);
return -1;
}
bus = gst_element_get_bus (pipeline);
do {
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_EOS);
/* Parse message */
if (msg != NULL) {
GError *err;
gchar *debug_info;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_ERROR:
case GST_MESSAGE_EOS:
terminate = TRUE;
break;
case GST_MESSAGE_STATE_CHANGED:
if (GST_MESSAGE_SRC (msg) == GST_OBJECT (pipeline)) {
GstState old_state, new_state, pending_state;
gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);
g_print ("Pipeline state changed from %s to %sn", gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));
}
break;
default:
/* We should not reach here because we only asked for ERRORs and EOS */
g_printerr ("Unexpected message received.n");
break;
}
gst_message_unref (msg);
}
} while (!terminate);
/* Free resources */
// ...
}

正如您所看到的,如果不添加udpsink,则管道工作正常。这也发生在命令行中:

gst-launch-1.0 -v udpsink videotestsrc ! videoconvert ! autovideosink

上面的命令将弹出一个窗口,视频在第一帧停止。

我不知道我的代码出了什么问题,有人能帮我吗,谢谢!

管道以sink元素结束,例如(autovideosink(之后不能添加任何内容。这就是为什么autovideosink没有src pad,并且不能将其链接到udpsink。您必须将第二个线程链接到udpsink。要创建线程,可以使用queuetee元素。

你可以在这里找到更多(GStreamer基本教程7:多线程和Pad可用性(

最新更新