Hi all,
I’m working on a DeepStream project where I use the Python bindings on Jetson devices. I have a working code written in Gst-Python and I’m experimenting with RTSP/HTTP camera sources. Sometimes in both of these camera types, the streams can get dropped and the stream becomes a black-screen.
I’ve tried to listen different types of messages from the GStreamer bus for the pipeline when I disconnect the RTSP cameras but once I unplug the camera’s power, both of the stream and the messages on the terminal stops. Eventually, my aim is re-connecting to the cameras automatically when the stream drops. Here is my simple gstreamer code:
Element Creation:
def main():
# Standard GStreamer initialization
GObject.threads_init()
Gst.init(None)
# Create gstreamer elements
# Create Pipeline element that will form a connection of other elements
print("Creating Pipeline \n ")
pipeline = Gst.Pipeline()
if not pipeline:
sys.stderr.write(" Unable to create Pipeline \n")
# Source element for reading from the file
print("Creating Source \n ")
source = Gst.ElementFactory.make("rtspsrc", "rtsp-cam-source")
if not source:
sys.stderr.write(" Unable to create Source \n")
caps_source = Gst.ElementFactory.make("capsfilter", "caps-source")
caps_source.set_property("caps", Gst.caps_from_string("application/x-rtp"))
if not caps_source:
sys.stderr.write(" Unable to create Caps-Source \n")
...
Creating other pipeline elements...
...
Property Setting:
source.set_property('location', 'rtsp://<user>:<pass>@<cam-ip>:<port>/<streaming-url>')
source.set_property('message-forward', 1)
source.set_property('latency', 0)
source.set_property('timeout', 0)
source.set_property('tcp-timeout', 0)
source.set_property('udp-reconnect', 0)
source.set_property('retry', 0)
appsink.set_property('sync', 0)
appsink.set_property('emit-signals', 1)
Display:
while True:
# pipe_state = pipeline.get_state(Gst.CLOCK_TIME_NONE)
message = bus.timed_pop_filtered(10000, Gst.MessageType.ANY)
if image_arr is not None:
cv2.imshow("Doruk Receive Image from Pipeline Buffer", image_arr)
if cv2.waitKey(1) == ord('q'):
pipeline.set_state(Gst.State.NULL)
pipeline.send_event(Gst.Event.new_eos())
break
if message:
if message.type == Gst.MessageType.ERROR:
err, debug = message.parse_error()
print(("Error received from element %s: %s" % (
message.src.get_name(), err)))
print(("Debugging information: %s" % debug))
break
elif message.type == Gst.MessageType.EOS:
print("End-Of-Stream reached.")
break
elif message.type == Gst.MessageType.STATE_CHANGED:
# print(message.type)
if isinstance(message.src, Gst.Pipeline):
old_state, new_state, pending_state = message.parse_state_changed()
print(("Pipeline state changed from %s to %s." %
(old_state.value_nick, new_state.value_nick)))
else:
print(message.type)