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