How to change rtspsrc location dynamically?

I am trying to change location of the an rtsp stream dynamically, the mediafactory is created like this (based on one example of gst-rtsp-server):
factory = gst_rtsp_media_factory_new();

gst_rtsp_media_factory_set_launch(factory, “(”
“-e rtspsrc latency=500 name=stream1 buffer-mode=auto”
" protocols=tcp tcp-timeout=100000000 retry=20 ! queue ! "
" rtph265depay ! h265parse ! vaapidecodebin ! queue ! "
" videorate ! video/x-raw,format=I420,framerate=5/1 ! "
" textoverlay text=“DEMO” font-desc=“Sans, 30” name=textsrc ! "
" videorate ! video/x-raw,framerate=15/1 ! vaapih264enc ! "
" rtph264pay name=pay0 pt=97 perfect-rtptime=true mtu=1400" “)”);
g_signal_connect(factory, “media-configure”, (GCallback)media_configure,

the media_configure function declared in the beinging is the following:

static void
media_configure(GstRTSPMediaFactory *factory, GstRTSPMedia *media,
gpointer user_data)
GstElement *element, *rtsp_src;
media1 = media;
gchar *current_location;
element = gst_rtsp_media_get_element(media);
rtsp_src = gst_bin_get_by_name(GST_BIN (element), “stream1”);
g_object_set (G_OBJECT (rtsp_src), “location”, location1, NULL);
g_object_get (G_OBJECT (rtsp_src), “location”, &current_location, NULL);
g_print(“Current location of rtsp source is: %s \n”, current_location);

pthread_create(&test_thread, NULL, &thread_func, 1);


I used the thread function to test switching between different locations for the rtspsrc dynamically, but that didn’t work (the stream continues with the old location when I check it on vlc).

thread_func( GstRTSPMedia media)
GstElement *element, *rtsp_src;
element = gst_rtsp_media_get_element(media);
rtsp_src = gst_bin_get_by_name(GST_BIN (element), “stream1”);


if(counter %2 == 0)
  g_object_set (G_OBJECT (src), "location", location2, NULL);
} else
  g_object_set (G_OBJECT (src), "location", location1, NULL);

gst_object_unref (GST_OBJECT (element));
gst_object_unref (GST_OBJECT (src));

So my question is, how can I switch dynamically between source locations(URLs)?

We don’t have experience bout the usecase, you may go to gstreamer forum to get further suggestion. If the rtsp sources are with identical resolution, the hardware decoder nvv4l2decoder should work fine, although the case is not tested/verified. If the sources are with dynamic resolution change, we would suggest re-initialize the gstreamer pipeline when the source changes.