2013-12-19 51 views
0

我正在學習如何在gstreamer中使用動態pad。所以我試着添加pad添加信號,這樣一旦元素被創建,我就可以收到消息。但是,我沒有收到任何消息。g_signal_connect「pad-added」不起作用

下面是代碼:

#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

回答

1

您的代碼爲我工作的罰款。

你分路器可能無法解複用流,請檢查您所提供的輸入文件。這可能不是一個有效的OGG文件。

相關提示,千萬調試代碼添加到您的程序,即監聽總線的消息,它幫助了很多東西時,不工作。

GStreamer的SDK的basic tutorial 3是完美的例子,你想要做什麼。

+0

我試了幾個視頻。我沒有得到任何錯誤,但函數不會進入cb_new_pad函數。 – user655561

+0

我嘗試了基本教程3,並且遇到同樣的問題。 我在使用虛擬框的Ubuntu 12.04上使用gstreamer 1.2.1。 這個問題的原因是什麼? – user655561

+0

所以當你運行基本教程3時,你沒有收到任何錯誤信息? cmd提示符上的gst-launch是否工作? – rubndsouza