I am new to GStreamer and I have created a small example where I am recording the webcam and used app sink to get the sample but when I try to stop the pipeline by setting its state to null and sending EOS event, my bus callback function never gets called for the EOS. And because of this memory leak is happening. Guys, Please help me import gi import time import threading gi.require_version('Gst', '1.0') gi.require_version('Gtk', '3.0') gi.require_version('GstApp', '1.0') from gi.repository import GObject, Gst, Gtk, GstApp import signal Gst.init(None) class Main: shutdown = False def __init__(self):
signal.signal(signal.SIGINT, self.keyboardInterruptHandler)
self._pipeline = Gst.parse_launch("avfvideosrc
name=avfvideosrc ! x264enc name=x264enc ! appsink
name=appsink max-buffers=1 drop=false sync=false emit-
signals=true wait-on-eos=false")
bus = self._pipeline.get_bus()
bus.add_signal_watch()
bus.connect("message::eos", self._on_eos_from_sink_pipeline)
bus.connect("message", self.on_status_changed)
appsink = self._pipeline.get_by_name('appsink')
appsink.connect('new-sample', self.on_new_sample)
appsink.connect('eos', self.eos)
#bus.connect('message', self.on_status_changed)
self._pipeline.set_state(Gst.State.PLAYING)
def on_new_sample(self, appsink):
return Gst.FlowReturn.OK
def _on_eos_from_sink_pipeline(self, _bus, _message):
print("Got EOS from sink pipeline")
exit()
def eos(self, sink):
print("SINK EOS")
return True
def on_status_changed(self, bus, message):
print('Status: ', message.type)
print('Object: ', message.src)
print('Parsed Message: ', message.parse_state_changed())
def keyboardInterruptHandler(self,signal, frame):
print("KeyboardInterrupt (ID: {}) has been caught. Cleaning
up...".format(signal))
self.shutdown = True
self.stopFetching()
def stopFetching(self):
print("AT THE START OF STOP FETCHING")
self._pipeline.set_state(Gst.State.NULL)
self._pipeline.send_event(Gst.Event.new_eos())
print("AT THE END OF STOP FETCHING")
start = Main()
Gtk.main()` --Thanks & Regards, Thanks & Regards, Ravi Modha <a href="callto:+91%2020%204674%200881" style="color:rgb(17,85,204)" target="_blank">+91 20 4674 0881 | <a href="callto:+1%20408%20216%208162" style="color:rgb(17,85,204)" target="_blank">+1 408 216 8162 _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
You cannot expect any messages on the
bus after you have set the pipeline to NULL. Your EOS message
will be dropped on the floor and
`self._pipeline.send_event(Gst.Event.new_eos())` would very likely
return FALSE indicating a failure to send the message.
Cheers -Matt On 4/11/19 7:46 pm, Ravi Modha wrote:
_______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel signature.asc (499 bytes) Download Attachment |
This post was updated on .
Hello Mathew,
First of all, Thanks a lot for your reply. Even if I don’t set NULL to pipeline and send the EOS event to the pipeline, I never get EOS message on the bus. The code I added is the small portion of my project and in the project instead of avfvideosrc, we have used v4l2src with appsink. Now without EOS pipeline is not cleaning up its resources and I am getting the memory leaks. Please help me! I am stuck on this for a month. > On Nov 6, 2019, at 5:16 PM, Matthew Waters <ystreet00@gmail.com> wrote: > > You cannot expect any messages on the bus after you have set the pipeline to NULL. Your EOS message will be dropped on the floor and `self._pipeline.send_event(Gst.Event.new_eos())` would very likely return FALSE indicating a failure to send the message. > > Cheers > -Matt > > On 4/11/19 7:46 pm, Ravi Modha wrote: >> I am new to GStreamer and I have created a small example where I am recording the webcam and used app sink to get the sample but when I try to stop the pipeline by setting its state to null and sending EOS event, my bus callback function never gets called for the EOS. And because of this memory leak is happening. >> >> Guys, Please help me >> >> >> >> import gi import time import threading >> >> gi.require_version('Gst', '1.0') gi.require_version('Gtk', '3.0') gi.require_version('GstApp', '1.0') >> >> from gi.repository import GObject, Gst, Gtk, GstApp import signal >> >> Gst.init(None) >> >> class Main: >> >> shutdown = False >> >> def __init__(self): >> signal.signal(signal.SIGINT, self.keyboardInterruptHandler) >> >> self._pipeline = Gst.parse_launch("avfvideosrc >> name=avfvideosrc ! x264enc name=x264enc ! appsink >> name=appsink max-buffers=1 drop=false sync=false emit- >> signals=true wait-on-eos=false") >> bus = self._pipeline.get_bus() >> bus.add_signal_watch() >> bus.connect("message::eos", self._on_eos_from_sink_pipeline) >> bus.connect("message", self.on_status_changed) >> appsink = self._pipeline.get_by_name('appsink') >> appsink.connect('new-sample', self.on_new_sample) >> appsink.connect('eos', self.eos) >> >> #bus.connect('message', self.on_status_changed) >> self._pipeline.set_state(Gst.State.PLAYING) >> >> def on_new_sample(self, appsink): >> return Gst.FlowReturn.OK >> >> def _on_eos_from_sink_pipeline(self, _bus, _message): >> print("Got EOS from sink pipeline") >> exit() >> >> def eos(self, sink): >> print("SINK EOS") >> return True >> >> def on_status_changed(self, bus, message): >> print('Status: ', message.type) >> print('Object: ', message.src) >> print('Parsed Message: ', message.parse_state_changed()) >> >> def keyboardInterruptHandler(self,signal, frame): >> print("KeyboardInterrupt (ID: {}) has been caught. Cleaning >> up...".format(signal)) >> self.shutdown = True >> self.stopFetching() >> >> def stopFetching(self): >> print("AT THE START OF STOP FETCHING") >> self._pipeline.set_state(Gst.State.NULL) >> self._pipeline.send_event(Gst.Event.new_eos()) >> print("AT THE END OF STOP FETCHING") >> start = Main() >> Gtk.main()` >> -- >> Thanks & Regards, >> -- >> Thanks & Regards, >> >> Ravi Modha >> ravi.modha@tudip.com <mailto:ravi.modha@tudip.com> | Skype: ravi.modha@tudip.com <mailto:ravi.modha@tudip.com> >> >> <https://tudip.com/> <https://in.linkedin.com/company/tudip-technologies-pvt-ltd-> <https://clutch.co/profile/tudip-technologies> <https://www.goodfirms.co/companies/view/4439/tudip-technologies-pvt-ltd> <https://www.facebook.com/TudipTechnologies> <https://twitter.com/TudipTech> <https://www.youtube.com/channel/UCoNPz2mbzNF_AZhLQEzuWCg> >> www.tudip.com <https://tudip.com/> | Tudip in News <https://tudip.com/tudip-technologies-in-news/> >> +91 20 4674 0881 <callto:+91%2020%204674%200881> | +1 408 216 8162 <callto:+1%20408%20216%208162> >> >> _______________________________________________ >> gstreamer-devel mailing list >> gstreamer-devel@lists.freedesktop.org <mailto:gstreamer-devel@lists.freedesktop.org> >> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel <https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel> _______________________________________________ gstreamer-devel mailing list gstreamer-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
In reply to this post by ravi.modha
Could someone please help me on this as I am still stuck on it
-- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hi! What you are experiencing is expected, it's by design. Should be documented better though, because it's not really intuitive See: Il giorno mer 20 nov 2019 alle ore 15:54 ravi.modha <[hidden email]> ha scritto: Could someone please help me on this as I am still stuck on it _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Setting a pipeline from playing to paused, ready, or null does not send an EOS event at all. If you read the documentation about states, when changing from playing to paused, to ready, to null, it does not mention sending a synthesized EOS event. The EOS event is sent, for example, when a filesrc has read all the content of a file, but has nothing to do with setting a pipeline to NULL Hope it helps! :) Luca Il giorno mer 20 nov 2019 alle ore 21:31 Luca Bacci <[hidden email]> ha scritto:
_______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Uhm, sorry! I read now that the callbacks are never called even if you send en EOS event yourself. I'll look at it Il giorno mer 20 nov 2019 alle ore 21:54 Luca Bacci <[hidden email]> ha scritto:
_______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
I think that the problem is the on_new_sample() callback. You have to call appsink.pull_sample() otherwise appsink accumulates all buffers passed to it, and also accumulates the EOS event. Try changing to: def on_new_sample(self, appsink): sample = appsink.pull_sample() return Gst.FlowReturn.OK That way you are actually consuming the buffers. Then appsink can empty its queue of buffers and process the EOS Note: remember to remove the call to set_state(Gst.State.NULL): def stopFetching(self): print("AT THE START OF STOP FETCHING") self._pipeline.send_event(Gst.Event.new_eos()) print("AT THE END OF STOP FETCHING") Il giorno mer 20 nov 2019 alle ore 22:46 Luca Bacci <[hidden email]> ha scritto:
_______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
In reply to this post by ravi.modha
bra bra bra ... mainloop = GObject.MainLoop() mainloop.run() Gtk.main() ----- GStreamer is a convenient multimedia platform, I like it. Live in Taiwan -- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Free forum by Nabble | Edit this page |