【问题标题】:gstreamer stop streaming on silencegstreamer 在静音时停止流式传输
【发布时间】:2016-04-20 11:56:09
【问题描述】:

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

gst-launch-0.10 pulsesrc !音频转换!音频/x-raw-int,channels=1,depth=16,width=16,rate=22000 ! rtpL16pay ! udpsink 主机=localhost 端口=5000

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

gst-launch-0.10 -v udpsrc 端口=5000 ! “应用程序/x-rtp,媒体=(字符串)音频,时钟速率=(int)22000,宽度=16,高度=16,编码名称=(字符串)L16,编码参数=(字符串)1,通道=(int)1,通道位置=(int)1,有效载荷=(int)96“! rtpL16depay!音频转换! alsasink 同步=false

我现在要做的是启动代码,并在大约 2 秒内没有声音时自动停止流。我该怎么做呢?

【问题讨论】:

  • 嗨,你找到解决这个问题的方法了吗?

标签: gstreamer


【解决方案1】:

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

gst-launch-0.10 -v udpsrc 端口=5000 超时=2000 ! “应用程序/x-rtp,媒体=(字符串)音频,时钟速率=(int)22000,宽度=16,高度=16,编码名称=(字符串)L16,编码参数=(字符串)1,通道=(int)1,通道位置=(int)1,有效载荷=(int)96“! rtpL16depay!音频转换! alsasink 同步=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;
  }

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-25
    • 2015-12-13
    • 2011-09-24
    • 2013-04-13
    • 1970-01-01
    • 2016-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多