g_signal_connect“添加了便笺簿"不起作用 [英] g_signal_connect "pad-added" doesn't work
问题描述
我正在尝试学习如何在gstreamer中使用动态填充.因此,我尝试添加添加了填充信号的信号,以便在创建元素后能够收到一条消息.但是,我没有收到任何消息.
I am trying learning how to use dynamic pads in gstreamer. So I tried to add pad-added signal so I can get a message once an element is created. However, I didn't get any message.
这是代码:
#include <gst/gst.h>
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的方式
So what is the problem ? (By the way I am using gstreamer 1.2.1
推荐答案
您的代码对我来说效果很好.
Your code worked fine for me.
您的解复用器可能无法对流进行解复用,请检查您提供的输入文件.这可能不是有效的ogg文件.
Your demuxer probably could not demultiplex the stream, check the input file that you are providing. It is probably not a valid ogg file.
在相关说明中,请向程序中添加调试代码,即侦听总线中的消息.当某些事情不起作用时,它会很有帮助.
On a related note, do add debugging code to your program i.e. listen to the bus for messages. It helps a lot when something doesn't work.
其中的基础教程3 gstreamer sdk是您尝试做的完美示例.
The basic tutorial 3 of the gstreamer sdk is a perfect example for what you're trying to do.
这篇关于g_signal_connect“添加了便笺簿"不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!