Using rtspsrc element for deepstream pipeline

• Nvidia 3060
• DeepStream Version 6.3
• Question

I’m trying to convert the c example named deepstream_test_sr_app into a python pipeline. After performing the conversion, I still get an error… The linking between rtspsrc source element and depay element is unsuccessfull…
Here is the code:

import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst, GObject
import threading
import time 
import sys

def check_pipeline_state(pipeline):
	while True:
		state = pipeline.get_state(Gst.CLOCK_TIME_NONE)[1]
		print("Pipeline state:", Gst.Element.state_get_name(state))
		time.sleep(5)  # attendez 5 secondes avant de vérifier à nouveau


def cb_newpad(element, element_src_pad, data):
	print("IN NEW PAD")
	caps = element_src_pad.get_current_caps()
	structure = caps.get_structure(0)
	name = structure.get_name()
	media_type = structure.get_value("media")
	print(f"Pad added: {media_type} & {name}")
	
	if media_type == "video" and name == "application/x-rtp":
		print("Here we go")
		sinkpad = data.get_static_pad("sink") #where data is depay element
		print("Source pad capabilities:", element_src_pad.query_caps(None).to_string())
		print("Sink pad capabilities:", sinkpad.query_caps(None).to_string())
		if not element_src_pad.link(sinkpad):
			print('Elements could not be linked: 1. Exiting.', flush=True)
			sys.exit(-1)        


def on_error(bus, message):
	err, debug = message.parse_error()
	print(f"Error: {err}, {debug}")

def main():
	GObject.threads_init()
	Gst.init(None)
	# Set the default debug threshold
	Gst.debug_set_default_threshold(3)

	pipeline = Gst.Pipeline()
	
	source = Gst.ElementFactory.make("rtspsrc", "rtsp-source")
	source.set_property("location", "rtsp://192.168.15.59:8554/my_feed_1")
	
	depay_pre_decode = Gst.ElementFactory.make("rtph264depay", "h264-depay")
	
	parse = Gst.ElementFactory.make("h264parse", "parse")
	
	source.connect("pad-added", cb_newpad, depay_pre_decode)
	
	decoder = Gst.ElementFactory.make("nvv4l2decoder", "nvv4l2-decoder")
   
	sink = Gst.ElementFactory.make("fakesink", "sink")

	pipeline.add(source)
	pipeline.add(depay_pre_decode)
	pipeline.add(parse)
	pipeline.add(decoder)
	pipeline.add(sink)
   
	if not depay_pre_decode.link(parse) or \
   	not parse.link(decoder) or \
   	not decoder.link(sink):
		print('Elements could not be linked: 12. Exiting.')
		sys.exit(-1) 
	

	bus = pipeline.get_bus()
	bus.add_signal_watch()
	bus.connect("message::error", on_error)

	loop = GObject.MainLoop()

	pipeline.set_state(Gst.State.PLAYING)
	print("Pipeline state set to PLAYING")
	# Créez et démarrez la thread de vérification de l'état
	state_check_thread = threading.Thread(target=check_pipeline_state, args=(pipeline,))
	state_check_thread.start()

	# Ajoutez ceci pour créer un fichier dot pour debug
	Gst.debug_bin_to_dot_file(pipeline, Gst.DebugGraphDetails.ALL, "/opt/nvidia/deepstream/deepstream-6.2/deepstreamInterface/pipeline.dot")

	try:
		loop.run()
	except Exception as e:
		print(f"Error occurred: {e}")

	pipeline.set_state(Gst.State.NULL)
	print("Pipeline state set to NULL")

if __name__ == "__main__":
	main()

There is no update from you for a period, assuming this is not an issue anymore.
Hence we are closing this topic. If need further support, please open a new one. Thanks

This is an interesting question. The type of return value of element link is different from that of pad link.
So the correct way is

 if element_src_pad.link(sinkpad)  != Gst.PadLinkReturn.OK:
     print('Elements could not be linked: 1. Exiting.', flush=True)
     sys.exit(-1)

You can refer to the documentation of gstreamer python bindings

https://gstreamer.freedesktop.org/documentation/gstreamer/gstpad.html?gi-language=python#gst_pad_link

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.