简体   繁体   English

g_signal_connect“添加了键盘”不起作用

[英]g_signal_connect “pad-added” doesn't work

I am trying learning how to use dynamic pads in gstreamer. 我正在尝试学习如何在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. 但是,我没有收到任何消息。

Here is the code: 这是代码:

#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);

}

So what is the problem ? 那是什么问题呢? (By the way I am using gstreamer 1.2.1 (通过我使用gstreamer 1.2.1的方式

Your code worked fine for me. 您的代码对我来说很好。

Your demuxer probably could not demultiplex the stream, check the input file that you are providing. 您的解复用器可能无法对流进行解复用,请检查您提供的输入文件。 It is probably not a valid ogg file. 这可能不是有效的ogg文件。

On a related note, do add debugging code to your program ie listen to the bus for messages. 在相关说明中,请在程序中添加调试代码,即侦听总线中的消息。 It helps a lot when something doesn't work. 当某事不起作用时,它会很有帮助。

The basic tutorial 3 of the gstreamer sdk is a perfect example for what you're trying to do. gstreamer sdk的基本教程3是您要尝试执行的操作的完美示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM