home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / gst-python / 0.10 / examples / filesrc.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.8 KB  |  74 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import gobject
  6. import pygst
  7. pygst.require('0.10')
  8. import gst
  9.  
  10. class FileSource(gst.BaseSrc):
  11.     __gsttemplates__ = (gst.PadTemplate('src', gst.PAD_SRC, gst.PAD_ALWAYS, gst.caps_new_any()),)
  12.     blocksize = 4096
  13.     fd = None
  14.     
  15.     def __init__(self, name):
  16.         self.__gobject_init__()
  17.         self.curoffset = 0
  18.         self.set_name(name)
  19.  
  20.     
  21.     def set_property(self, name, value):
  22.         if name == 'location':
  23.             self.fd = open(value, 'r')
  24.         
  25.  
  26.     
  27.     def do_create(self, offset, size):
  28.         if offset != self.curoffset:
  29.             self.fd.seek(offset, 0)
  30.         
  31.         data = self.fd.read(self.blocksize)
  32.         if data:
  33.             self.curoffset += len(data)
  34.             return (gst.FLOW_OK, gst.Buffer(data))
  35.         return (gst.FLOW_UNEXPECTED, None)
  36.  
  37.  
  38. gobject.type_register(FileSource)
  39.  
  40. def main(args):
  41.     if len(args) != 3:
  42.         print 'Usage: %s input output' % args[0]
  43.         return -1
  44.     bin = gst.Pipeline('pipeline')
  45.     filesrc = FileSource('filesource')
  46.     if not filesrc:
  47.         raise AssertionError
  48.     filesrc.set_property('location', args[1])
  49.     filesink = gst.element_factory_make('filesink', 'sink')
  50.     filesink.set_property('location', args[2])
  51.     bin.add(filesrc, filesink)
  52.     gst.element_link_many(filesrc, filesink)
  53.     bin.set_state(gst.STATE_PLAYING)
  54.     mainloop = gobject.MainLoop()
  55.     
  56.     def bus_event(bus, message):
  57.         t = message.type
  58.         if t == gst.MESSAGE_EOS:
  59.             mainloop.quit()
  60.         elif t == gst.MESSAGE_ERROR:
  61.             (err, debug) = message.parse_error()
  62.             print 'Error: %s' % err, debug
  63.             mainloop.quit()
  64.         
  65.         return True
  66.  
  67.     bin.get_bus().add_watch(bus_event)
  68.     mainloop.run()
  69.     bin.set_state(gst.STATE_NULL)
  70.  
  71. if __name__ == '__main__':
  72.     sys.exit(main(sys.argv))
  73.  
  74.