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 / decodebin.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.9 KB  |  72 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import gobject
  6. gobject.threads_init()
  7. import pygst
  8. pygst.require('0.10')
  9. import gst
  10.  
  11. class Decodebin:
  12.     
  13.     def __init__(self, location):
  14.         self.pipeline = gst.Pipeline()
  15.         self.bus = self.pipeline.get_bus()
  16.         self.bus.add_signal_watch()
  17.         self.bus.connect('message::eos', self.on_eos)
  18.         self.bus.connect('message::tag', self.on_tag)
  19.         self.bus.connect('message::error', self.on_error)
  20.         self.src = gst.element_factory_make('filesrc')
  21.         self.dec = gst.element_factory_make('decodebin')
  22.         self.conv = gst.element_factory_make('audioconvert')
  23.         self.rsmpl = gst.element_factory_make('audioresample')
  24.         self.sink = gst.element_factory_make('alsasink')
  25.         self.src.set_property('location', location)
  26.         self.dec.connect('new-decoded-pad', self.on_new_decoded_pad)
  27.         self.pipeline.add(self.src, self.dec, self.conv, self.rsmpl, self.sink)
  28.         self.src.link(self.dec)
  29.         gst.element_link_many(self.conv, self.rsmpl, self.sink)
  30.         self.apad = self.conv.get_pad('sink')
  31.         self.mainloop = gobject.MainLoop()
  32.         self.pipeline.set_state(gst.STATE_PLAYING)
  33.         self.mainloop.run()
  34.  
  35.     
  36.     def on_new_decoded_pad(self, element, pad, last):
  37.         caps = pad.get_caps()
  38.         name = caps[0].get_name()
  39.         print 'on_new_decoded_pad:', name
  40.         if name == 'audio/x-raw-float' or name == 'audio/x-raw-int':
  41.             if not self.apad.is_linked():
  42.                 pad.link(self.apad)
  43.             
  44.         
  45.  
  46.     
  47.     def on_eos(self, bus, msg):
  48.         print 'on_eos'
  49.         self.mainloop.quit()
  50.  
  51.     
  52.     def on_tag(self, bus, msg):
  53.         taglist = msg.parse_tag()
  54.         print 'on_tag:'
  55.         for key in taglist.keys():
  56.             print '\t%s = %s' % (key, taglist[key])
  57.         
  58.  
  59.     
  60.     def on_error(self, bus, msg):
  61.         error = msg.parse_error()
  62.         print 'on_error:', error[1]
  63.         self.mainloop.quit()
  64.  
  65.  
  66. if __name__ == '__main__':
  67.     if len(sys.argv) == 2:
  68.         Decodebin(sys.argv[1])
  69.     else:
  70.         print 'Usage: %s /path/to/media/file' % sys.argv[0]
  71.  
  72.