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秒没有声音时自动停止流。 我应该如何去做这件事?


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 ("%sn", 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;
  }

祝你好运!

链接地址: http://www.djcxy.com/p/43995.html

上一篇: gstreamer stop streaming on silence

下一篇: Send PCM data to VLC player using gstreamer