Gstreamer RTSP `gst-launch-1.0` 等效的 C 代码

Gstreamer RTSP `gst-launch-1.0` Equivalent C Code

我目前正在使用涉及 GStreamer 的 NVIDIA Deepstream 开展一个项目。当我尝试将源元素从 "filesrc" 元素更改为 "rtspsrc" 元素并添加 "rtph264depay" 和 "queue" 时,结果是

0:00:09.533730268 19680 0x7fc02c0025e0 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<udpsrc0> error: Internal data flow error.
0:00:09.533772178 19680 0x7fc02c0025e0 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<udpsrc0> error: streaming task paused, reason not-linked (-1)
ERROR from element udpsrc0: Internal data flow error.
Error: Internal data flow 

我认为这可能是由于 "source" 元素之前(TCP 服务器连接)或之后(NVIDIA 硬件利用元素)的代码造成的。为了测试我的方向是否正确,我尝试了 运行

gst-launch-1.0 rtspsrc location=rtsp://192.168.0.71:8554/h264ESVideoTest ! rtph264depay ! queue ! h264parse ! avdec_h264 ! videoconvert ! videoscale ! autovideosink 

它成功地显示了流,同时显示了它在 C 中的等效代码,如下所示

#include <gst/gst.h>
#include <glib.h>

static gboolean
bus_call (GstBus * bus, GstMessage * msg, gpointer data)
{
  GMainLoop *loop = (GMainLoop *) data;
  switch (GST_MESSAGE_TYPE (msg)) {
    case GST_MESSAGE_EOS:
      g_print ("End of stream\n");
      g_main_loop_quit (loop);
      break;
    case GST_MESSAGE_ERROR:{
      gchar *debug;
      GError *error;
      gst_message_parse_error (msg, &error, &debug);
      g_printerr ("ERROR from element %s: %s\n",
          GST_OBJECT_NAME (msg->src), error->message);
      g_free (debug);
      g_printerr ("Error: %s\n", error->message);
      g_error_free (error);
      g_main_loop_quit (loop);
      break;
    }
    default:
      break;
  }
  return TRUE;
}

int
main (int argc, char *argv[])
{
  GMainLoop *loop = NULL;
  GstElement *pipeline = NULL, 
             *source = NULL, 
             *rtpdepay = NULL,
             *vidqueue = NULL,
             *h264parser = NULL,
             *decoder = NULL, 
             *vidconvert = NULL, 
             *vidscale = NULL, 
             *sink = NULL;

  GstBus *bus = NULL;
  guint bus_watch_id;
  GstCaps *caps1 = NULL, *caps2 = NULL;
  gulong osd_probe_id = 0;
  GstPad *osd_sink_pad = NULL;

  /* GStreamer initialization */
  gst_init (&argc, &argv);
  loop = g_main_loop_new (NULL, FALSE);

  /* Create gstreamer elements */
  pipeline = gst_pipeline_new ("pipeline");
  source = gst_element_factory_make ("rtspsrc", "file-source");
  rtpdepay = gst_element_factory_make ("rtph264depay", "rtpdepay");
  vidqueue = gst_element_factory_make ("queue", "vidqueue");
  h264parser = gst_element_factory_make ("h264parse", "h264parser");
  decoder = gst_element_factory_make ("avdec_h264", "avh264decoder");
  vidconvert = gst_element_factory_make ("videoconvert", "vidconvert");
  vidscale = gst_element_factory_make ("videoscale", "vidscale");
  sink = gst_element_factory_make ("autovideosink", "sink");

  /* Check elements creation */
  if (!pipeline   || 
      !source     || 
      !rtpdepay   || 
      !vidqueue   ||
      !h264parser || 
      !decoder    || 
      !vidconvert || 
      !vidscale   || 
      !sink) {
    g_printerr ("One or more element could not be created. Exiting.\n");
    return -1;
  }

  /* Set input location to the source element */
  g_object_set (G_OBJECT (source), "location", argv[1], NULL);

  /* Add a message handler */
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  bus_watch_id = gst_bus_add_watch (bus, bus_call, loop);
  gst_object_unref (bus);

  /* Set up the pipeline */
  /* Add all elements into the pipeline */
  gst_bin_add_many (GST_BIN (pipeline),
                    source, 
                    rtpdepay, 
                    vidqueue,  
                    h264parser, 
                    decoder, 
                    vidconvert, 
                    vidscale, 
                    sink, 
                    NULL);

  /* Link the elements together */
  gst_element_link_many (source, 
                         rtpdepay, 
                         vidqueue,  
                         h264parser, 
                         decoder, 
                         vidconvert, 
                         vidscale, 
                         sink, 
                         NULL);

  /* Set the pipeline to "playing" state */
  g_print ("Now playing: %s\n", argv[1]);
  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  /* Wait till pipeline encounters an error or EOS */
  g_print ("Running...\n");
  g_main_loop_run (loop);

  /* Out of the main loop */
  g_print ("Returned, stopping playback\n");
  gst_element_set_state (pipeline, GST_STATE_NULL);
  g_print ("Deleting pipeline\n");
  gst_object_unref (GST_OBJECT (pipeline));
  g_source_remove (bus_watch_id);
  g_main_loop_unref (loop);
  return 0;
}

导致与之前相同的错误。

我的印象是任何不需要在 gst-launch-1.0 命令中设置的属性也不需要在 C 代码中设置。 "rtspsrc" 是否有任何需要在 C 中设置但 gst-launch-1.0 会自动设置的属性?还是我完全犯了另一种错误?

编辑1: 附件是 C 代码的显式错误日志

0:00:00.095045906 19967 0x7f60c401d8f0 FIXME                default gstutils.c:3766:gst_pad_create_stream_id_internal:<fakesrc0:src> Creating random stream-id, consider implementing a deterministic way of creating a stream-id
0:00:00.135622983 19967 0x7f60b80031e0 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<udpsrc1> error: Internal data flow error.
0:00:00.135662497 19967 0x7f60b80031e0 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<udpsrc1> error: streaming task paused, reason not-linked (-1)
ERROR from element udpsrc1: Internal data flow error.
Error: Internal data flow error.
Returned, stopping playback
0:00:00.136197250 19967      0x1c9ba30 WARN                 rtspsrc gstrtspsrc.c:5483:gst_rtspsrc_try_send:<file-source> send interrupted
0:00:00.136228722 19967      0x1c9ba30 WARN                 rtspsrc gstrtspsrc.c:7552:gst_rtspsrc_pause:<file-source> PAUSE interrupted

您应该link 使用"pad-added" 信号从源到下沉。检查这个:RTSP pipeline implemented via C code not working?.