I have a simple code with c using gstreamer to read rtsp video. I'm new to gstreamer, I couldn't concatenate gst_parse_launch() with a URL_RTSP variable for my rtsp links.
here is no variable URL_RTSP, that works:
/* Build the pipeline */
pipeline = gst_parse_launch("rtspsrc protocols=tcp location=rtsp://user:pass@protocol:port/cam/realmonitor?channel=1&subtype=0 latency=300 ! decodebin3 ! autovideosink", NULL);
/* Start playing */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
with the variable URL_RTSP, doesn't work:
/*Url Cams*/
std::string URL_RTSP = "rtsp://user:pass@protocol:port/cam/realmonitor?channel=1&subtype=0";
/* Build the pipeline */
pipeline =
gst_parse_launch("rtspsrc protocols=tcp location=" URL_RTSP " latency=300 ! decodebin3 ! autovideosink", NULL);
/* Start playing */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
Error when I try to use with variable, gst_parse_launch() get the error:
there is no proper conversion function from "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>" to "const gchar *"
CodePudding user response:
gst_parse_launch
takes a const gchar*
as the first argument:
GstElement* gst_parse_launch (const gchar* pipeline_description, GError** error)
But, what you provide,
"rtspsrc protocols=tcp location=" URL_RTSP
" latency=300 ! decodebin3 ! autovideosink"
results in a std::string
. I suggest creating the std::string
first, then use the c_str()
member function to pass it a const char*
.
std::string tmp =
"rtspsrc protocols=tcp location=" URL_RTSP
" latency=300 ! decodebin3 ! autovideosink";
pipeline = gst_parse_launch(tmp.c_str(), nullptr);