如果我向其中添加了udpsink插件,为什么gstreamer管道无法播放

问题描述

我尝试使用gstreamer发送RTP流,但是我发现管道根本无法播放。当我简化代码时,我发现如果在管道中添加了udpsink插件,该管道将被阻塞,并且状态始终为READY。

我的代码:

#include <gst/gst.h>

int main(int argc,char *argv[]) {
  GstElement *pipeline,*source,*sink,*udp,*convert;
  GstBus *bus;
  GstMessage *msg;
  GstStateChangeReturn ret;
  gboolean terminate = FALSE;

  /* Initialize GStreamer */
  gst_init (&argc,&argv);

  /* Create the elements */
  source  = gst_element_factory_make ("videotestsrc","source");
  convert = gst_element_factory_make ("videoconvert","convert");
  sink    = gst_element_factory_make ("autovideosink","sink");
  udp     = gst_element_factory_make ("udpsink","udp");

  /* Create the empty pipeline */
  pipeline = gst_pipeline_new ("test-pipeline");

  /* Build the pipeline */
  gst_bin_add_many (GST_BIN (pipeline),source,sink,convert,/*udp,*/ NULL);
  gst_element_link_many (source,NULL);

  /* Modify the source's properties */
  g_object_set (source,"pattern",NULL);

  /* Start playing */
  ret = gst_element_set_state (pipeline,GST_STATE_PLAYING);
  if (ret == GST_STATE_CHANGE_FAILURE) {
    g_printerr ("Unable to set the pipeline to the playing state.\n");
    gst_object_unref (pipeline);
    return -1;
  }

  bus = gst_element_get_bus (pipeline);
  do {
    msg = gst_bus_timed_pop_filtered (bus,GST_CLOCK_TIME_NONE,GST_MESSAGE_ERROR | GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_EOS);

    /* Parse message */
    if (msg != NULL) {
      GError *err;
      gchar *debug_info;

      switch (GST_MESSAGE_TYPE (msg)) {
        case GST_MESSAGE_ERROR:
        case GST_MESSAGE_EOS:
          terminate = TRUE;
          break;
        case GST_MESSAGE_STATE_CHANGED:
          if (GST_MESSAGE_SRC (msg) == GST_OBJECT (pipeline)) {
            GstState old_state,new_state,pending_state;
            gst_message_parse_state_changed (msg,&old_state,&new_state,&pending_state);
            g_print ("Pipeline state changed from %s to %s\n",gst_element_state_get_name (old_state),gst_element_state_get_name (new_state));
          }
          break;
        default:
          /* We should not reach here because we only asked for ERRORs and EOS */
          g_printerr ("Unexpected message received.\n");
          break;
      }
      gst_message_unref (msg);
    }
  } while (!terminate);

  /* Free resources */
  // ...
}

如您所见,如果未添加udpsink,则管道可以正常工作。这也发生在命令行中:

gst-launch-1.0 -v udpsink videotestsrc ! videoconvert ! autovideosink

上面的命令将弹出一个窗口,视频在第一帧停止。

我不知道我的代码有什么问题,任何人都可以给我帮助,谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...