From: <tho...@fr...> - 2005-08-28 17:44:59
|
CVS Root: /cvs/gstreamer Module: gst-python Changes by: thomasvs Date: Sun Aug 28 2005 10:44:59 PDT Branch: BRANCH-GSTREAMER-0_8 Log message: * gst/extend/jukebox.py: * gst/extend/leveller.py: * gst/extend/sources.py: add an explicit .clean() method to source and leveller, to make sure all our elements are cleaned up correctly. Should help for long-living processes. * gst/extend/utils.py: add a gc_collect method that will explicitly garbage-collect if env var GST_GC is set. Useful for debugging refcounting. Modified files: . : ChangeLog gst/extend : jukebox.py leveller.py sources.py utils.py Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-python/ChangeLog.diff?r1=1.157.2.53&r2=1.157.2.54 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-python/gst/extend/jukebox.py.diff?r1=1.1.2.10&r2=1.1.2.11 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-python/gst/extend/leveller.py.diff?r1=1.1.2.6&r2=1.1.2.7 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-python/gst/extend/sources.py.diff?r1=1.1.2.6&r2=1.1.2.7 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-python/gst/extend/utils.py.diff?r1=1.1.2.1&r2=1.1.2.2 ====Begin Diffs==== Index: ChangeLog =================================================================== RCS file: /cvs/gstreamer/gst-python/ChangeLog,v retrieving revision 1.157.2.53 retrieving revision 1.157.2.54 diff -u -d -r1.157.2.53 -r1.157.2.54 --- ChangeLog 27 Aug 2005 09:49:54 -0000 1.157.2.53 +++ ChangeLog 28 Aug 2005 17:44:46 -0000 1.157.2.54 @@ -1,3 +1,15 @@ +2005-08-28 Thomas Vander Stichele <thomas at apestaart dot org> + + * gst/extend/jukebox.py: + * gst/extend/leveller.py: + * gst/extend/sources.py: + add an explicit .clean() method to source and leveller, to make + sure all our elements are cleaned up correctly. Should help + for long-living processes. + * gst/extend/utils.py: + add a gc_collect method that will explicitly garbage-collect + if env var GST_GC is set. Useful for debugging refcounting. 2005-08-27 Thomas Vander Stichele <thomas at apestaart dot org> * gst/extend/jukebox.py: Index: jukebox.py RCS file: /cvs/gstreamer/gst-python/gst/extend/Attic/jukebox.py,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -d -r1.1.2.10 -r1.1.2.11 --- jukebox.py 27 Aug 2005 10:39:31 -0000 1.1.2.10 +++ jukebox.py 28 Aug 2005 17:44:47 -0000 1.1.2.11 @@ -138,7 +138,7 @@ self._scan() # clean up leveller after this handler - gobject.timeout_add(0, l.stop) + gobject.timeout_add(0, l.clean) def _check_prerolled(self): gst.debug("_check_prerolled: index: scan %d, play %d" % ( @@ -253,14 +253,18 @@ sinkpad = srcpad.get_peer() srcpad.unlink(sinkpad) self._adder.release_request_pad(sinkpad) - source.set_state(gst.STATE_NULL) gst.debug('%d pads left on adder' % len(self._adder.get_pad_list())) gst.debug('%r children in jukebox' % [e.get_name() for e in self.get_list()]) if len(self._adder.get_pad_list()) == 1: gst.debug('only a source pad left, so we are done') self.emit('done', sources.EOS) - gobject.timeout_add(0, self.remove, source) + gobject.timeout_add(0, self._source_clean, source) + def _source_clean(self, source): + source.set_state(gst.STATE_NULL) + self.remove(source) + source.clean() gobject.type_register(Jukebox) Index: leveller.py RCS file: /cvs/gstreamer/gst-python/gst/extend/Attic/leveller.py,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -d -r1.1.2.6 -r1.1.2.7 --- leveller.py 27 Aug 2005 10:39:31 -0000 1.1.2.6 +++ leveller.py 28 Aug 2005 17:44:47 -0000 1.1.2.7 @@ -25,6 +25,7 @@ import gobject import gst +import utils from pygobject import gsignal from gst.extend import sources @@ -191,6 +192,22 @@ gst.debug("Setting to NULL") self.set_state(gst.STATE_NULL) gst.debug("Set to NULL") + utils.gc_collect('Leveller.stop()') + def clean(self): + # clean ourselves up completely + self.stop() + # let's be ghetto and clean out our bin manually + self.remove(self._source) + self.remove(self._level) + self.remove(self._fakesink) + gst.debug("Emptied myself") + self._source.clean() + utils.gc_collect('Leveller.clean() cleaned up source') + self._source = None + self._fakesink = None + self._level = None + utils.gc_collect('Leveller.clean() done') gobject.type_register(Leveller) @@ -204,7 +221,6 @@ else: print "in: %f, out: %f, length: %f" % (l.mixin, l.mixout, l.length) print "rms: %f, %f dB" % (l.rms, l.rmsdB) - leveller.stop() main.quit() def _error_cb(leveller, source, gerror, message): @@ -225,3 +241,12 @@ print "Starting" main.run() + leveller.stop() + leveller.clean() + gst.debug('deleting leveller, verify objects are freed') + utils.gc_collect('quit main loop') + del leveller + utils.gc_collect('deleted leveller') + gst.debug('stopping forever') Index: sources.py RCS file: /cvs/gstreamer/gst-python/gst/extend/Attic/sources.py,v --- sources.py 24 Aug 2005 18:39:52 -0000 1.1.2.6 +++ sources.py 28 Aug 2005 17:44:47 -0000 1.1.2.7 EOS = 'EOS' @@ -87,14 +88,34 @@ def _have_eos_cb(self, object): self.eos = True self.emit('done', EOS) + def stop(self): + self.set_state(gst.STATE_NULL) + utils.gc_collect("Source.stop()") + self.remove(self.filesrc) + self.remove(self.dbin) + self.remove(self.audioconvert) + self.remove(self.audioscale) + self.remove(self.volume) + self.filesrc = None + self.dbin = None + self.audioconvert = None + self.audioscale = None + self.volume = None + utils.gc_collect("Source.clean()") gobject.type_register(AudioSource) + # run us to test if __name__ == "__main__": main = gobject.MainLoop() def _done_cb(source, reason): print "Done" + sys.stdout.flush() if reason != EOS: print "Some error happened: %s" % reason @@ -139,3 +160,10 @@ print "Left main loop" pipeline.set_state(gst.STATE_NULL) + pipeline.remove(source) + pipeline.remove(sink) + utils.gc_collect('cleaned out pipeline') + source.clean() + utils.gc_collect('cleaned up source') + source = None + utils.gc_collect('set source to None') Index: utils.py RCS file: /cvs/gstreamer/gst-python/gst/extend/Attic/utils.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- utils.py 10 Aug 2005 11:20:01 -0000 1.1.2.1 +++ utils.py 28 Aug 2005 17:44:47 -0000 1.1.2.2 @@ -1,3 +1,5 @@ +import os @@ -52,3 +54,17 @@ out = " - bytes_level: %ld" % (element.get_property('current-level-bytes')) print out.rjust(len(out) + indent) +def gc_collect(reason=None): + """ + Garbage-collect if GST_GC env var is set. + This helps in debugging object refcounting. + Sprinkle liberally around checkpoints. + if not os.environ.has_key('GST_GC'): + return + import gc + gst.debug('collecting garbage') + if reason: + gst.debug('because of %s' % reason) + gc.collect() + gst.debug('collected garbage') |