[英]Gstreamer Python: EOS message not received?
I have a Python Deepstream app (based in Gstreamer) and I want it to end properly when pressed Ctrl+C.我有一个 Python Deepstream 应用程序(基于 Gstreamer),我希望它在按下 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:总线消息处理程序 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:最后是信号处理程序 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
?为什么
bus_message_handler
没有收到 EOS 消息?
Thanks.谢谢。
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.大胆猜测,我实际上并没有在代码中查看这个细节,但我假设
timed_pop_filtered()
将接管所有总线消息并丢弃所有消息或返回有问题的 EOS。 Since you didn't say it deadlocks/waits forever at the end I assume that timed_pop_filtered()
returned the EOS correctly.由于您没有说它最后会死锁/永远等待,我假设
timed_pop_filtered()
正确返回了 EOS。 Since timed_pop_filtered()
will take away all messages your bus watch will not receive any more messages at this point.由于
timed_pop_filtered()
将带走所有消息,因此您的总线手表此时不会再收到任何消息。
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.因此,与其使用
timed_pop_filtered()
获取所有消息,不如等待来自总线手表的信号,只要 EOS 到达那里就会触发该信号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.