* morituri/common/checksum.py:
* morituri/common/encode.py: * morituri/common/gstreamer.py: Move play to base class of GstPipelineTask.
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
2011-05-23 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/common/checksum.py:
|
||||
* morituri/common/encode.py:
|
||||
* morituri/common/gstreamer.py:
|
||||
Move play to base class of GstPipelineTask.
|
||||
|
||||
2011-05-23 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/common/gstreamer.py:
|
||||
|
||||
@@ -73,6 +73,8 @@ class ChecksumTask(gstreamer.GstPipelineTask):
|
||||
|
||||
self.checksum = None # result
|
||||
|
||||
### gstreamer.GstPipelineTask implementations
|
||||
|
||||
def getPipelineDesc(self):
|
||||
return '''
|
||||
filesrc location="%s" !
|
||||
@@ -136,6 +138,34 @@ class ChecksumTask(gstreamer.GstPipelineTask):
|
||||
#self.pipeline.set_state(gst.STATE_PLAYING)
|
||||
self.debug('scheduled setting to play')
|
||||
|
||||
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'
|
||||
# FIXME: instead of print, do something useful
|
||||
else:
|
||||
self._checksum = self._checksum % 2 ** 32
|
||||
self.debug("last offset %r", self._last.offset)
|
||||
last = self._last.offset + len(self._last) / 4 - 1
|
||||
self.debug("last sample: %r", last)
|
||||
self.debug("frame end: %r", self._frameEnd)
|
||||
self.debug("frame length: %r", self._frameLength)
|
||||
self.debug("checksum: %08X", self._checksum)
|
||||
self.debug("bytes: %d", self._bytes)
|
||||
if self._frameEnd != last:
|
||||
print 'ERROR: did not get all frames, %d missing' % (
|
||||
self._frameEnd - last)
|
||||
|
||||
self.checksum = self._checksum
|
||||
|
||||
### subclass methods
|
||||
def do_checksum_buffer(self, buf, checksum):
|
||||
"""
|
||||
Subclasses should implement this.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
### private methods
|
||||
def _new_buffer_cb(self, sink):
|
||||
buf = sink.emit('pull-buffer')
|
||||
gst.log('received new buffer at offset %r with length %r' % (
|
||||
@@ -165,38 +195,12 @@ class ChecksumTask(gstreamer.GstPipelineTask):
|
||||
# marshall to the main thread
|
||||
self.runner.schedule(0, self.setProgress, progress)
|
||||
|
||||
def do_checksum_buffer(self, buf, checksum):
|
||||
"""
|
||||
Subclasses should implement this.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def _eos_cb(self, sink):
|
||||
# get the last one; FIXME: why does this not get to us before ?
|
||||
#self._new_buffer_cb(sink)
|
||||
self.debug('eos, scheduling stop')
|
||||
self.runner.schedule(0, self.stop)
|
||||
|
||||
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'
|
||||
# FIXME: instead of print, do something useful
|
||||
else:
|
||||
self._checksum = self._checksum % 2 ** 32
|
||||
self.debug("last offset %r", self._last.offset)
|
||||
last = self._last.offset + len(self._last) / 4 - 1
|
||||
self.debug("last sample: %r", last)
|
||||
self.debug("frame end: %r", self._frameEnd)
|
||||
self.debug("frame length: %r", self._frameLength)
|
||||
self.debug("checksum: %08X", self._checksum)
|
||||
self.debug("bytes: %d", self._bytes)
|
||||
if self._frameEnd != last:
|
||||
print 'ERROR: did not get all frames, %d missing' % (
|
||||
self._frameEnd - last)
|
||||
|
||||
self.checksum = self._checksum
|
||||
|
||||
class CRC32Task(ChecksumTask):
|
||||
"""
|
||||
I do a simple CRC32 check.
|
||||
@@ -302,13 +306,6 @@ class TRMTask(gstreamer.GstPipelineTask):
|
||||
# gobject.timeout_add(0L, self.pipeline.set_state, gst.STATE_PLAYING)
|
||||
# would not work.
|
||||
|
||||
def play():
|
||||
self.pipeline.set_state(gst.STATE_PLAYING)
|
||||
return False
|
||||
self.runner.schedule(0, play)
|
||||
|
||||
#self.pipeline.set_state(gst.STATE_PLAYING)
|
||||
gst.debug('scheduled setting to play')
|
||||
|
||||
# FIXME: can't move this to base class because it triggers too soon
|
||||
# in the case of checksum
|
||||
|
||||
@@ -213,21 +213,6 @@ class EncodeTask(gstreamer.GstPipelineTask):
|
||||
srcpad = self._level.get_static_pad('src')
|
||||
srcpad.add_buffer_probe(self._probe_handler)
|
||||
|
||||
# FIXME: move to base class ?
|
||||
self.debug('scheduling setting to play')
|
||||
# since set_state returns non-False, adding it as timeout_add
|
||||
# will repeatedly call it, and block the main loop; so
|
||||
# gobject.timeout_add(0L, self.pipeline.set_state, self.gst.STATE_PLAYING)
|
||||
# would not work.
|
||||
|
||||
def play():
|
||||
self.pipeline.set_state(self.gst.STATE_PLAYING)
|
||||
return False
|
||||
self.runner.schedule(0, play)
|
||||
|
||||
#self.pipeline.set_state(gst.STATE_PLAYING)
|
||||
self.debug('scheduled setting to play')
|
||||
|
||||
def _probe_handler(self, pad, buffer):
|
||||
# update progress based on buffer offset (expected to be in samples)
|
||||
# versus length in samples
|
||||
@@ -312,21 +297,11 @@ class TagReadTask(task.Task):
|
||||
# set up tag callbacks
|
||||
bus.connect('message::tag', self._message_tag_cb)
|
||||
|
||||
self.debug('scheduling setting to play')
|
||||
# since set_state returns non-False, adding it as timeout_add
|
||||
# will repeatedly call it, and block the main loop; so
|
||||
# gobject.timeout_add(0L, self._pipeline.set_state, gst.STATE_PLAYING)
|
||||
# would not work.
|
||||
|
||||
def play():
|
||||
self.debug('setting pipeline to play')
|
||||
self._pipeline.set_state(gst.STATE_PLAYING)
|
||||
return False
|
||||
self.runner.schedule(0, play)
|
||||
|
||||
#self._pipeline.set_state(gst.STATE_PLAYING)
|
||||
self.debug('scheduled setting to play')
|
||||
|
||||
def _message_eos_cb(self, bus, message):
|
||||
self.debug('eos, scheduling stop')
|
||||
self.runner.schedule(0, self.stop)
|
||||
@@ -395,7 +370,8 @@ class TagWriteTask(task.Task):
|
||||
self.debug('scheduling setting to play')
|
||||
# since set_state returns non-False, adding it as timeout_add
|
||||
# will repeatedly call it, and block the main loop; so
|
||||
# gobject.timeout_add(0L, self._pipeline.set_state, gst.STATE_PLAYING)
|
||||
# gobject.timeout_add(0L, self._pipeline.set_state,
|
||||
# gst.STATE_PLAYING)
|
||||
# would not work.
|
||||
|
||||
def play():
|
||||
|
||||
@@ -66,17 +66,36 @@ class GstPipelineTask(task.Task):
|
||||
|
||||
self.parsed()
|
||||
|
||||
self.debug('pausing pipeline')
|
||||
self.pipeline.set_state(self.gst.STATE_PAUSED)
|
||||
self.debug('setting pipeline to PAUSED')
|
||||
self.pipeline.set_state(gst.STATE_PAUSED)
|
||||
self.debug('set pipeline to PAUSED')
|
||||
# FIXME: this can block
|
||||
self.pipeline.get_state()
|
||||
self.debug('paused pipeline')
|
||||
ret = self.pipeline.get_state()
|
||||
self.debug('got pipeline to PAUSED: %r', ret)
|
||||
|
||||
if not self.exception:
|
||||
self.paused()
|
||||
else:
|
||||
raise self.exception
|
||||
|
||||
self.play()
|
||||
|
||||
def play(self):
|
||||
# since set_state returns non-False, adding it as timeout_add
|
||||
# will repeatedly call it, and block the main loop; so
|
||||
# gobject.timeout_add(0L, self._pipeline.set_state,
|
||||
# gst.STATE_PLAYING)
|
||||
# would not work.
|
||||
def playLater():
|
||||
self.debug('setting pipeline to PLAYING')
|
||||
self.pipeline.set_state(self.gst.STATE_PLAYING)
|
||||
self.debug('set pipeline to PLAYING')
|
||||
return False
|
||||
|
||||
self.debug('scheduling setting pipeline to PLAYING')
|
||||
self.runner.schedule(0, playLater)
|
||||
|
||||
|
||||
def stop(self):
|
||||
self.debug('stopping')
|
||||
self.debug('setting state to NULL')
|
||||
|
||||
Reference in New Issue
Block a user