Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
gstreamer在静默状态下停止流式处理_Gstreamer - Fatal编程技术网

gstreamer在静默状态下停止流式处理

gstreamer在静默状态下停止流式处理,gstreamer,Gstreamer,我的ubuntu机器上有两个打开的终端。这个想法是对着麦克风讲话,然后通过扬声器播放。在第一个终端上,我使用以下命令设置gstreamer扬声器: gst-launch-0.10脉冲加速器!音频转换!音频/x-raw-int,通道=1,深度=16,宽度=16,速率=22000!rtpL16pay!udpsink主机=本地主机端口=5000 另一个终端上的侦听器使用此命令 gst-launch-0.10-v udpsrc端口=5000!“应用程序/x-rtp,媒体=(字符串)音频,时钟频率=(in

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

gst-launch-0.10脉冲加速器!音频转换!音频/x-raw-int,通道=1,深度=16,宽度=16,速率=22000!rtpL16pay!udpsink主机=本地主机端口=5000

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

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


我现在要做的是启动代码,并在大约2秒钟内没有声音时自动停止流。如何执行此操作?

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

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

然后,总线回调应该如下所示:

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

祝你好运

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