g_signal_connect“pad-added”不起作用

我正在尝试学习如何在gstreamer中使用动态垫。 所以我尝试添加pad-added信号,这样我就可以在创建元素后收到消息。 但是,我没有收到任何消息。

这是代码:

#include  static void cb_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 */ } int main (int argc, char *argv[]) { GstElement *pipeline, *source, *demux; GMainLoop *loop; /* init */ gst_init (&argc, &argv); /* create elements */ pipeline = gst_pipeline_new ("my_pipeline"); source = gst_element_factory_make ("filesrc", "source"); g_object_set (source, "location", argv[1], NULL); demux = gst_element_factory_make ("oggdemux", "demuxer"); /* put together a pipeline */ gst_bin_add_many (GST_BIN (pipeline), source, demux, NULL); gst_element_link_pads (source, "src", demux, "sink"); /* listen for newly created pads */ g_signal_connect (demux, "pad-added", G_CALLBACK (cb_new_pad), NULL); /* start the pipeline */ gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); } 

那么问题是什么? (顺便说一句,我使用的是gstreamer 1.2.1

你的代码对我来说很好。

您的分路器可能无法解复用流,检查您提供的输入文件。 它可能不是一个有效的ogg文件。

在相关的说明中,请向程序添加调试代码,即收听总线以获取消息。 当某些东西不起作用时,它会有很大的帮助。

gstreamer sdk的基本教程3是您尝试做的完美示例。