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

问题描述 投票:-1回答:1

我目前正在使用涉及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 

我认为这可能是由于前面的代码(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会自动执行?还是我完全犯了另一种错误?

EDIT1:attach是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
c gstreamer rtsp
1个回答
0
投票

您应该使用“pad-added”信号将source链接到sink。检查一下:RTSP pipeline implemented via C code not working?

© www.soinside.com 2019 - 2024. All rights reserved.