如何解决如果我向其中添加了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,NULL);
/* Modify the source's properties */
g_object_set (source,"pattern",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 %s\n",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
上面的命令将弹出一个窗口,视频在第一帧停止。
我不知道我的代码有什么问题,任何人都可以给我帮助,谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。