Changeset 449
- Timestamp:
- 21-05-11 19:01:19 (2 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
-
ChangeLog (modified) (1 diff)
-
morituri/common/checksum.py (modified) (2 diffs)
-
morituri/common/gstreamer.py (added)
-
morituri/image/image.py (modified) (1 diff)
-
morituri/test/test_common_checksum.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ChangeLog
r447 r449 1 2011-05-21 Thomas Vander Stichele <thomas at apestaart dot org> 2 3 * morituri/common/checksum.py: 4 * morituri/image/image.py: 5 * morituri/test/test_common_checksum.py: 6 * morituri/common/gstreamer.py (added): 7 Factor out GstException and GstPipelineTask. 8 1 9 2011-05-21 Thomas Vander Stichele <thomas at apestaart dot org> 2 10 -
trunk/morituri/common/checksum.py
r442 r449 27 27 import gst 28 28 29 from morituri.common import common, task 29 from morituri.common import common, task, gstreamer 30 30 31 31 # checksums are not CRC's. a CRC is a specific type of checksum. 32 32 33 # FIXME: probably this should move higher up the module hierarchy and 34 # be used wider 35 class GstException(Exception): 36 def __init__(self, gerror, debug): 37 self.args = (gerror, debug, ) 38 self.gerror = gerror 39 self.debug = debug 40 41 # FIXME: this should move up too; other tasks might have use for it. 42 class GstPipelineTask(task.Task): 43 """ 44 I am a base class for tasks that use a GStreamer pipeline. 45 46 I handle errors and raise them appropriately. 47 """ 48 def start(self, runner): 49 task.Task.start(self, runner) 50 desc = self.getPipelineDesc() 51 52 self.debug('creating pipeline %r', desc) 53 self.pipeline = gst.parse_launch(desc) 54 55 self._bus = self.pipeline.get_bus() 56 gst.debug('got bus %r' % self._bus) 57 58 # a signal watch calls callbacks from an idle loop 59 # self._bus.add_signal_watch() 60 61 # sync emission triggers sync-message signals which calls callbacks 62 # from the thread that signals, but happens immediately 63 self._bus.enable_sync_message_emission() 64 self._bus.connect('sync-message::eos', self.bus_eos_cb) 65 self._bus.connect('sync-message::tag', self.bus_tag_cb) 66 self._bus.connect('sync-message::error', self.bus_error_cb) 67 68 self.parsed() 69 70 self.debug('pausing pipeline') 71 self.pipeline.set_state(gst.STATE_PAUSED) 72 self.pipeline.get_state() 73 self.debug('paused pipeline') 74 75 if not self.exception: 76 self.paused() 77 else: 78 raise self.exception 79 80 def getPipelineDesc(self): 81 raise NotImplementedError 82 83 def parsed(self): 84 """ 85 Called after parsing the pipeline but before setting it to paused. 86 """ 87 pass 88 89 def paused(self): 90 """ 91 Called after pipeline is paused 92 """ 93 pass 94 95 def bus_eos_cb(self, bus, message): 96 pass 97 98 def bus_tag_cb(self, bus, message): 99 pass 100 101 def bus_error_cb(self, bus, message): 102 exc = GstException(*message.parse_error()) 103 self.setAndRaiseException(exc) 104 gst.debug('error, scheduling stop') 105 #self.runner.schedule(0, self.stop) 106 107 108 class ChecksumTask(GstPipelineTask): 33 34 class ChecksumTask(gstreamer.GstPipelineTask): 109 35 """ 110 36 I am a task that calculates a checksum of the decoded audio data. … … 342 268 return checksum 343 269 344 class TRMTask( GstPipelineTask):270 class TRMTask(gstreamer.GstPipelineTask): 345 271 """ 346 272 I calculate a MusicBrainz TRM fingerprint. -
trunk/morituri/image/image.py
r382 r449 295 295 index = track.indexes[1] 296 296 add(index) 297 298 class ImageJoinTask(task.Task): 299 """ 300 I concatenate the decoded audio from all tracks into a single .wav 301 I can optionally offset the joint audio to compensate for a write offset. 302 """ 303 304 description = "Joining tracks" 305 306 def __init__(self, image, outfile): 307 308 self._image = image 309 cue = image.cue 310 self._tasks = [] 311 self.lengths = {} 312 313 def add(index): 314 # here to avoid import gst eating our options 315 from morituri.common import encode 316 317 path = image.getRealPath(index.path) 318 assert type(path) is unicode, "%r is not unicode" % path 319 self.debug('schedule encode of %r', path) 320 root, ext = os.path.splitext(os.path.basename(path)) 321 outpath = os.path.join(outdir, root + '.' + profile.extension) 322 self.debug('schedule encode to %r', outpath) 323 taskk = encode.EncodeTask(path, os.path.join(outdir, 324 root + '.' + profile.extension), profile) 325 self.addTask(taskk) 326 327 try: 328 htoa = cue.table.tracks[0].indexes[0] 329 self.debug('encoding htoa track') 330 add(htoa) 331 except (KeyError, IndexError): 332 self.debug('no htoa track') 333 pass 334 335 for trackIndex, track in enumerate(cue.table.tracks): 336 self.debug('encoding track %d', trackIndex + 1) 337 index = track.indexes[1] 338 add(index) -
trunk/morituri/test/test_common_checksum.py
r442 r449 8 8 gobject.threads_init() 9 9 10 from morituri.common import task, checksum, log 10 from morituri.common import task, checksum, log, gstreamer 11 11 12 12 from morituri.test import common as tcommon … … 24 24 e = self.assertRaises(task.TaskException, self.runner.run, 25 25 checksumtask, verbose=False) 26 self.failUnless(isinstance(e.exception, checksum.GstException))26 self.failUnless(isinstance(e.exception, gstreamer.GstException)) 27 27 os.unlink(path) 28 28 … … 34 34 e = self.assertRaises(task.TaskException, self.runner.run, 35 35 checksumtask, verbose=False) 36 self.failUnless(isinstance(e.exception, checksum.GstException))36 self.failUnless(isinstance(e.exception, gstreamer.GstException)) 37 37 os.unlink(path) 38 38
Note: See TracChangeset
for help on using the changeset viewer.
