home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / python-gst0.10 / examples / vorbisplay.py < prev    next >
Encoding:
Python Source  |  2006-07-31  |  4.1 KB  |  134 lines

  1. #!/usr/bin/env python
  2. # -*- Mode: Python -*-
  3. # vi:si:et:sw=4:sts=4:ts=4
  4.  
  5. # gst-python
  6. # Copyright (C) 2003 David I. Lehn
  7. #
  8. # This library is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU Library General Public
  10. # License as published by the Free Software Foundation; either
  11. # version 2 of the License, or (at your option) any later version.
  12. #
  13. # This library is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. # Library General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Library General Public
  19. # License along with this library; if not, write to the
  20. # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. # Boston, MA 02111-1307, USA.
  22. # Author: David I. Lehn <dlehn@users.sourceforge.net>
  23. #
  24.  
  25. import sys
  26. import gst
  27.  
  28. def gst_props_debug_entry(entry, level=0):
  29.     name = entry.get_name()
  30.     type = entry.get_props_type()
  31.     indent = ' '*level
  32.  
  33.     if type == PROPS_INT_TYPE:
  34.         ret, val = entry.get_int()
  35.         assert ret
  36.         print '%s%s: int %d' % (indent, name, val)
  37.     elif type == PROPS_FLOAT_TYPE:
  38.         ret, val = entry.get_float()
  39.         assert ret
  40.         print '%s%s: float %f' % (indent, name, val)
  41.     elif type == PROPS_FOURCC_TYPE:
  42.         ret, val = entry.get_fourcc()
  43.         assert ret
  44.         print '%s%s: fourcc %c%c%c%c' % (indent, name,
  45.                     (val>>0)&0xff,
  46.                     (val>>8)&0xff,
  47.                     (val>>16)&0xff,
  48.                     (val>>24)&0xff)
  49.     elif type == PROPS_BOOLEAN_TYPE:
  50.         ret, val = entry.get_bool()
  51.         assert ret
  52.         print '%s%s: bool %d' % (indent, name, val)
  53.     elif type == PROPS_STRING_TYPE:
  54.         ret, val = entry.get_string()
  55.         assert ret
  56.         print '%s%s: string "%s"' % (indent, name, val)
  57.     elif type == PROPS_INT_RANGE_TYPE:
  58.         ret, min, max = entry.get_int_range()
  59.         assert ret
  60.         print '%s%s: int range %d-%d' % (indent, name, min, max)
  61.     elif type == PROPS_FLOAT_RANGE_TYPE:
  62.         ret, min, max = entry.get_float_range()
  63.         assert ret
  64.         print '%s%s: float range %f-%f' % (indent, name, min, max)
  65.     elif type == PROPS_LIST_TYPE:
  66.         ret, val = entry.get_list()
  67.         assert ret
  68.         print '[list] ('
  69.         for e in val:
  70.             gst_props_debug_entry(e, level+1)
  71.         print ')'
  72.     else:
  73.         print '%sWARNING: %s: unknown property type %d' % (indent, name, type)
  74.  
  75. def debug_caps(caps):
  76.     props = caps.get_props()
  77.     ret, plist = props.get_list()
  78.     for e in plist:
  79.         gst_props_debug_entry(e, level=1)
  80.  
  81. def streaminfo(sender, pspec):
  82.     assert pspec.name == 'streaminfo'
  83.     caps = sender.get_property(pspec.name)
  84.     print 'streaminfo:'
  85.     debug_caps(caps)
  86.  
  87. def metadata(sender, pspec):
  88.     assert pspec.name == 'metadata'
  89.     caps = sender.get_property(pspec.name)
  90.     print 'metadata:'
  91.     debug_caps(caps)
  92.  
  93. def decoder_notified(sender, pspec):
  94.     if pspec.name == 'streaminfo':
  95.         streaminfo(sender, pspec)
  96.     elif pspec.name == 'metadata':
  97.         metadata(sender, pspec)
  98.     else:
  99.         print 'notify:', sender, pspec
  100.                                      
  101. def main(args):
  102.     "Basic example to play an Ogg Vorbis stream through OSS"
  103.  
  104.     if len(args) != 2:
  105.         print 'usage: %s <Ogg Vorbis file>' % args
  106.         return -1
  107.     
  108.     bin = gst.parse_launch('filesrc name=source ! ' + 
  109.                            'oggdemux name=demuxer ! ' + 
  110.                            'vorbisdec name=decoder ! ' + 
  111.                            'audioconvert ! osssink') 
  112.     filesrc = bin.get_by_name('source')
  113.     filesrc.set_property('location', args[1])
  114.     demuxer = bin.get_by_name('demuxer')
  115.     demuxer.connect('notify', decoder_notified)
  116.     decoder = bin.get_by_name('decoder')
  117.     decoder.connect('notify', decoder_notified)
  118.  
  119.     # start playing
  120.     bin.set_state(gst.STATE_PLAYING);
  121.  
  122.     try:
  123.         while bin.iterate(): 
  124.         pass
  125.     except KeyboardInterrupt:
  126.         pass
  127.  
  128.     # stop the bin
  129.     bin.set_state(gst.STATE_NULL)
  130.  
  131. if __name__ == '__main__':
  132.     sys.exit(main(sys.argv))
  133.