Changeset 449


Ignore:
Timestamp:
21-05-11 19:01:19 (2 years ago)
Author:
thomas
Message:
  • morituri/common/checksum.py:
  • morituri/image/image.py:
  • morituri/test/test_common_checksum.py:
  • morituri/common/gstreamer.py (added): Factor out GstException? and GstPipelineTask?.
Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r447 r449  
     12011-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 
    192011-05-21  Thomas Vander Stichele  <thomas at apestaart dot org> 
    210 
  • trunk/morituri/common/checksum.py

    r442 r449  
    2727import gst 
    2828 
    29 from morituri.common import common, task 
     29from morituri.common import common, task, gstreamer 
    3030 
    3131# checksums are not CRC's. a CRC is a specific type of checksum. 
    3232 
    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 
     34class ChecksumTask(gstreamer.GstPipelineTask): 
    10935    """ 
    11036    I am a task that calculates a checksum of the decoded audio data. 
     
    342268        return checksum 
    343269 
    344 class TRMTask(GstPipelineTask): 
     270class TRMTask(gstreamer.GstPipelineTask): 
    345271    """ 
    346272    I calculate a MusicBrainz TRM fingerprint. 
  • trunk/morituri/image/image.py

    r382 r449  
    295295            index = track.indexes[1] 
    296296            add(index) 
     297 
     298class 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  
    88gobject.threads_init() 
    99 
    10 from morituri.common import task, checksum, log 
     10from morituri.common import task, checksum, log, gstreamer 
    1111 
    1212from morituri.test import common as tcommon 
     
    2424        e = self.assertRaises(task.TaskException, self.runner.run, 
    2525            checksumtask, verbose=False) 
    26         self.failUnless(isinstance(e.exception, checksum.GstException)) 
     26        self.failUnless(isinstance(e.exception, gstreamer.GstException)) 
    2727        os.unlink(path) 
    2828 
     
    3434        e = self.assertRaises(task.TaskException, self.runner.run, 
    3535            checksumtask, verbose=False) 
    36         self.failUnless(isinstance(e.exception, checksum.GstException)) 
     36        self.failUnless(isinstance(e.exception, gstreamer.GstException)) 
    3737        os.unlink(path) 
    3838 
Note: See TracChangeset for help on using the changeset viewer.