Reputation: 184
I have a Python Deepstream app (based in Gstreamer) and I want it to end properly when pressed Ctrl+C.
My pipeline has the following elements:
source -> streammux -> tee -> nvinfer -> nvvideoconvert -> nvdosd -> filesink
|---> filesink
My main code is:
self.loop = GObject.MainLoop.new(None, False)
GLib.unix_signal_add(-100, 2, self.handle_sigint, None)
self.bus = self.gst_pipeline.get_bus()
self.bus.add_signal_watch()
self.bus.connect("message", self.bus_message_handler)
self.gst_pipeline.set_state(Gst.State.PLAYING)
self.loop.run()
The bus message handler function:
def bus_message_handler(self, bus, message: Gst.Message) -> bool:
t = message.type
logger.info(f"****************** Message received {t}")
if t == Gst.MessageType.EOS:
logger.success("End of Stream")
self.loop.quit()
elif t == Gst.MessageType.WARNING:
err, debug = message.parse_warning()
logger.warning(f"{err}: {debug}")
elif t == Gst.MessageType.ERROR:
err, debug = message.parse_error()
logger.error(f"{err}: {debug}")
self.gst_error = f"{err}: {debug}"
self.loop.quit()
return True
And finally the sigint handler function:
def handle_sigint(self, user_data=None):
logger.info("SIGINT detected. Sending EOS...")
self.gst_pipeline.send_event(Gst.Event.new_eos())
self.bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.EOS)
The expected behaviour would be:
Run -> Ctrl+C pressed -> Print "SIGINT detected. Sending EOS..." -> Print "End of Stream"
But "End of Stream" is never printed out. Why the EOS message is not being received by the bus_message_handler
?
Thanks.
Upvotes: 2
Views: 1767
Reputation: 7403
Wild guess, I haven't actually looked in the code for this detail, but I would assume that timed_pop_filtered()
will take over all bus messages and either discard all messages or return the EOS in question. Since you didn't say it deadlocks/waits forever at the end I assume that timed_pop_filtered()
returned the EOS correctly. Since timed_pop_filtered()
will take away all messages your bus watch will not receive any more messages at this point.
So instead of grabbing away all the messages with timed_pop_filtered()
you probably want to wait for a signal coming from your bus watch that is triggered whenever your EOS arrives there.
Upvotes: 1