Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

gst_parse_launch there is no proper conversion function from string to gchar

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  /*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 *"

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading