From 3482288750fb3d1a9601aad89d5490cedd85fb17 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 23 May 2011 15:26:19 +0000 Subject: [PATCH] * morituri/common/gstreamer.py: Add a stop method and a stopped overridable handler. * morituri/common/checksum.py: * morituri/common/encode.py: Adapt to using stopped. --- ChangeLog | 8 ++++++++ morituri/common/checksum.py | 16 ++-------------- morituri/common/encode.py | 11 +---------- morituri/common/gstreamer.py | 24 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6763cab..be31a91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-05-23 Thomas Vander Stichele + + * morituri/common/gstreamer.py: + Add a stop method and a stopped overridable handler. + * morituri/common/checksum.py: + * morituri/common/encode.py: + Adapt to using stopped. + 2011-05-23 Thomas Vander Stichele * morituri/test/test_common_encode.py: diff --git a/morituri/common/checksum.py b/morituri/common/checksum.py index 9163547..d2beaef 100644 --- a/morituri/common/checksum.py +++ b/morituri/common/checksum.py @@ -177,11 +177,7 @@ class ChecksumTask(gstreamer.GstPipelineTask): self.debug('eos, scheduling stop') self.runner.schedule(0, self.stop) - def stop(self): - self.debug('stopping') - self.debug('setting state to NULL') - self.pipeline.set_state(gst.STATE_NULL) - + def stopped(self): if not self._last: # see http://bugzilla.gnome.org/show_bug.cgi?id=578612 print 'ERROR: checksum: not a single buffer gotten' @@ -199,9 +195,7 @@ class ChecksumTask(gstreamer.GstPipelineTask): print 'ERROR: did not get all frames, %d missing' % ( self._frameEnd - last) - # publicize and stop self.checksum = self._checksum - task.Task.stop(self) class CRC32Task(ChecksumTask): """ @@ -336,11 +330,5 @@ class TRMTask(gstreamer.GstPipelineTask): position += buf.duration self.setProgress(float(position) / self._length) - def stop(self): - gst.debug('stopping') - gst.debug('setting state to NULL') - self.pipeline.set_state(gst.STATE_NULL) - - # publicize and stop + def stopped(self): self.trm = self._trm - task.Task.stop(self) diff --git a/morituri/common/encode.py b/morituri/common/encode.py index b260917..e9a6a71 100644 --- a/morituri/common/encode.py +++ b/morituri/common/encode.py @@ -259,16 +259,7 @@ class EncodeTask(gstreamer.GstPipelineTask): self.log('higher peakdB found, now %r', self._peakdB) self._peakdB = p - # FIXME: move to base class, have stopped handler ? - def stop(self): - self.debug('stopping') - self.debug('setting state to NULL') - self.pipeline.set_state(self.gst.STATE_NULL) - self.debug('set state to NULL') - # FIXME: maybe this should move lower ? If used by BaseMultiTask, - # this starts the next task without showing us the peakdB - task.Task.stop(self) - + def stopped(self): if self._peakdB is not None: self.debug('peakdB %r', self._peakdB) self.peak = math.sqrt(math.pow(10, self._peakdB / 10.0)) diff --git a/morituri/common/gstreamer.py b/morituri/common/gstreamer.py index 8d752be..4975413 100644 --- a/morituri/common/gstreamer.py +++ b/morituri/common/gstreamer.py @@ -40,6 +40,7 @@ class GstPipelineTask(task.Task): gst = None + ### task.Task implementations def start(self, runner): import gst self.gst = gst @@ -76,9 +77,25 @@ class GstPipelineTask(task.Task): else: raise self.exception + def stop(self): + self.debug('stopping') + self.debug('setting state to NULL') + self.pipeline.set_state(self.gst.STATE_NULL) + self.debug('set state to NULL') + self.stopped() + task.Task.stop(self) + + + ### subclass required implementations def getPipelineDesc(self): + """ + subclasses should implement this to provide a pipeline description. + + @rtype: str + """ raise NotImplementedError + ### subclass optional implementations def parsed(self): """ Called after parsing the pipeline but before setting it to paused. @@ -91,6 +108,13 @@ class GstPipelineTask(task.Task): """ pass + def stopped(self): + """ + Called after pipeline is set back to NULL but before chaining up to + stop() + """ + pass + def bus_eos_cb(self, bus, message): """ Called synchronously (ie from messaging thread) on eos message.