2016-01-14 88 views
1

我有兩個終端在我的ubuntu機器上打開。這個想法是對麥克風說話,然後通過揚聲器播放。在第一個終端上,我使用以下命令設置gstreamer揚聲器:gstreamer停止沉默

gst-launch-0.10 pulsesrc! audioconvert! audio/x-raw-int,channels = 1,depth = 16,width = 16,rate = 22000! rtpL16pay! udpsink主機=本地主機端口= 5000

我用這個命令在其他終端上的監聽

GST推出-0.10 -v udpsrc端口= 5000! 「application/x-rtp,media =(string)audio,clock-rate =(int)22000,width = 16,height = 16,encoding-name =(string)L16,encoding-params =(string)1,channels =(int)1,channel-positions =(int)1,payload =(int)96「! rtpL16depay! audioconvert! alsasink sync = false

我現在要做的是啓動代碼,並在大約2秒鐘沒有聲音時自動停止流。我應該如何去做這件事?

+0

嗨,你有沒有找到解決這個問題的辦法? –

回答

1

Udpsrc具有一個名爲「超時」的屬性,通過設置此屬性,元件將在管道總線上發佈消息,以防在特定的時間間隔內未收到包。你的接收管道應該看起來像這樣:

gst-launch-0.10 -v udpsrc port = 5000 timeout = 2000! 「application/x-rtp,media =(string)audio,clock-rate =(int)22000,width = 16,height = 16,encoding-name =(string)L16,encoding-params =(string)1,channels =(int)1,channel-positions =(int)1,payload =(int)96「! rtpL16depay! audioconvert!然後alsasink同步=假

總線回調應該是這個樣子:

gboolean 
bus_callback (GstBus * bus, GstMessage * message, gpointer data) 
{ 
    GError *error; 
    gchar *parsed_txt; 
    const GstStructure *st = gst_message_get_structure (message); 
    const gchar *typename = GST_MESSAGE_TYPE_NAME (message); 
    const gchar *srcname = GST_MESSAGE_SRC_NAME (message); 

    GST_LOG ("New %s message from %s: %s", typename, srcname, 
     st ? gst_structure_get_name(st) : "(null)"); 

    switch (GST_MESSAGE_TYPE (message)) { 
    case GST_MESSAGE_INFO: 
     gst_message_parse_info (message, &error, &parsed_txt); 
     g_print ("%s\n", parsed_txt); 
     g_free (parsed_txt); 
     g_error_free (error); 
     break; 

    case GST_MESSAGE_ERROR: 
     gst_message_parse_error (message, &error, &parsed_txt); 
     GST_ERROR ("%s (%s)", error->message, 
      parsed_txt ? parsed_txt : "no debug info"); 
     if (parsed_txt) 
     g_free (parsed_txt); 
    GST_DEBUG ("No error handling callback registered"); 

     break; 

    case GST_MESSAGE_ELEMENT: 
     /* We don't care for messages other than timeouts */ 
     if (!gst_structure_has_name (st, "GstUDPSrcTimeout")) 
    break; 
    GST_WARNING ("Timeout received from udpsrc"); 
    gst_element_set_state(GST_ELEMENT (pipeline),GST_STATE_NULL)); 
     break; 

    default: 
     break; 
    } 

祝您好運!