gstreamer停止流畅的沉默

时间:2016-01-14 23:29:20

标签: gstreamer

我的ubuntu机器上有两个终端打开。我的想法是对着麦克风说话,然后通过扬声器播放。在第一个终端上,我用命令设置了一个gstreamer扬声器:

gst-launch-0.10 pulsesrc! audioconvert! audio / x-raw-int,channels = 1,depth = 16,width = 16,rate = 22000! rtpL16pay! udpsink host = localhost port = 5000

另一个终端上的监听器我使用此命令

gst-launch-0.10 -v udpsrc port = 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秒时自动停止流。我应该怎么做呢?

1 个答案:

答案 0 :(得分:2)

Udpsrc有一个名为" timeout"的属性,通过设置此属性,元素将在管道总线上发布消息,以防在特定的时间内没有收到包。您的接收管道应如下所示:

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 sync = false

那么总线回调应该是这样的:

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;
  }

祝你好运!