def clean(self): """ Clean up the leveller. After calling this, the object cannot be used anymore. """ # clean ourselves up completely self.stop() self.remove(self._source) self.remove(self._level) self.remove(self._fakesink) gst.debug("Emptied myself") utils.gc_collect('Leveller.clean() cleaned up source') self.debug("source refcount: %d" % self._source.__grefcount__) self._source = None self._fakesink = None self._level = None self.rmsdBs = None self.peakdBs = None self.decaydBs = None utils.gc_collect('Leveller.clean() done') self.debug("clean done, refcount now %d" % self.__grefcount__)
def stop(self): """ Stop the leveller. Call this after the leveller emitted 'done'. Calls clean. """ gst.debug("Setting to NULL") self.set_state(gst.STATE_NULL) self.debug("Set to NULL, refcount now %d" % self.__grefcount__) utils.gc_collect('Leveller.stop()')
def clean(self): """ Clean up the leveller. After calling this, the object cannot be used anymore. """ self.pipeline.remove(self._source) self.pipeline.remove(self._level) self.pipeline.remove(self._fakesink) self.debug("Emptied myself") from gst.extend import utils utils.gc_collect('Leveller.clean() cleaned up source') self.debug("source refcount: %d" % self._source.__grefcount__) self._source = None self._fakesink = None self._level = None self.rmsdBs = None self.peakdBs = None self.decaydBs = None utils.gc_collect('Leveller.clean() done') self.debug("clean done, refcount now %d" % self.pipeline.__grefcount__)
def run(leveller): gst.debug('leveller refcount on creation: %d' % leveller.__grefcount__) bus = leveller.get_bus() bus.add_signal_watch() done = False success = False gst.debug('leveller refcount before start: %d' % leveller.__grefcount__) utils.gc_collect('before start') leveller.start() gst.debug('leveller refcount after start: %d' % leveller.__grefcount__) utils.gc_collect('after start') while not done: # this call blocks until there is a message message = bus.poll(gst.MESSAGE_ANY, gst.SECOND) if message: gst.log("got message from poll: %s/%r" % (message.type, message)) else: gst.log("got NOTHING from poll") if message: if message.type == gst.MESSAGE_EOS: done = True success = True elif message.type == gst.MESSAGE_ERROR: done = True # message, if set, holds a ref to leveller, so we delete it here # to assure cleanup of leveller when we del it m = repr(message) del message utils.gc_collect('deleted message %s' % m) bus.remove_signal_watch() del bus utils.gc_collect('deleted bus') leveller.stop() return success
try: leveller = Leveller(sys.argv[1]) except IndexError: sys.stderr.write("Please give a file to calculate level of\n") sys.exit(1) success = run(leveller) if success: print 'Successfully analyzed file.' if len(sys.argv) > 2: path = sys.argv[2] handle = open(path, 'w') import pickle rms = leveller.get_rms_dB() pickle.dump(rms, handle, pickle.HIGHEST_PROTOCOL) handle.close() print 'Dumped RMS dB pickle to %s' % path leveller.clean() assert leveller.__grefcount__ == 1, "There is a leak in leveller's refcount" gst.debug('deleting leveller, verify objects are freed') del leveller utils.gc_collect('deleted leveller') utils.gc_collect('deleted leveller') utils.gc_collect('deleted leveller') # some more cleanup to help valgrind gst.debug('stopping forever')
else: gst.log("got NOTHING from poll") if message: if message.type == gst.MESSAGE_EOS: done = True success = True elif message.type == gst.MESSAGE_ERROR: sys.stderr.write('Error analyzing file:\n') error, debug = message.parse_error() sys.stderr.write('%s.\n' % error) done = True # message, if set, holds a ref to leveller, so we delete it here # to assure cleanup of leveller when we del it del message utils.gc_collect('deleted message') l.stop() if success: print 'Successfully analyzed file %r' % path trackMixes = l.get_track_mixes() print '%d slice(s) found.' % len(trackMixes) for i, m in enumerate(trackMixes): print '- slice %d: %s - %s' % ( i, gst.TIME_ARGS(m.start), gst.TIME_ARGS(m.end)) print ' - peak %02.3f dB (%03.3f %%)' % ( m.peak, common.decibelToRaw(m.peak) * 100.0) print ' - rms %r dB' % m.rms print ' - peak rms %r dB' % m.rmsPeak print ' - 95 percentile rms %r dB' % m.rmsPercentile