Gstreamer RTSP`gst-launch-1.0`等效C代码
我目前正在使用NVIDIA Deepstream进行一个涉及GStreamer的项目。当我试图将源元素从“filesrc”元素更改为“rtspsrc”元素并添加“rtph264depay”和“queue”时,结果是Gstreamer RTSP`gst-launch-1.0`等效C代码,c,gstreamer,rtsp,C,Gstreamer,Rtsp,我目前正在使用NVIDIA Deepstream进行一个涉及GStreamer的项目。当我试图将源元素从“filesrc”元素更改为“rtspsrc”元素并添加“rtph264depay”和“queue”时,结果是 0:00:09.533730268 19680 0x7fc02c0025e0 WARN basesrc gstbasesrc.c:2948:gst_base_src_loop:<udpsrc0> error: Internal data f
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
它成功地显示了流,同时用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\u pad\u get\u caps
更改为其gstreamer-1.0等效版本后,它在裸RTSP 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;
}
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