examples/: Removed gst123 and vorbisplay examples which weren't working with 0.10, and replaced them with decodebin.py

Original commit message from CVS:
reviewed by: Edward Hervey  <edward@fluendo.com>
* examples/decodebin.py:
* examples/gst123:
* examples/vorbisplay.py:
Removed gst123 and vorbisplay examples which weren't working with
0.10, and replaced them with decodebin.py
Closes #362183 and #362202
This commit is contained in:
Edward Hervey 2006-10-20 09:47:16 +00:00
parent 71f58a44b4
commit 5b2c08ac37
4 changed files with 120 additions and 244 deletions

View file

@ -1,3 +1,14 @@
2006-10-20 Jason Gerard DeRose <jderose@jasonderose.org>
reviewed by: Edward Hervey <edward@fluendo.com>
* examples/decodebin.py:
* examples/gst123:
* examples/vorbisplay.py:
Removed gst123 and vorbisplay examples which weren't working with
0.10, and replaced them with decodebin.py
Closes #362183 and #362202
2006-10-20 Edward Hervey <edward@fluendo.com> 2006-10-20 Edward Hervey <edward@fluendo.com>
* examples/audioconcat.py: * examples/audioconcat.py:

109
examples/decodebin.py Normal file
View file

@ -0,0 +1,109 @@
#!/usr/bin/env python
# decodebin.py - Audio autopluging example using 'decodebin' element
# Copyright (C) 2006 Jason Gerard DeRose <jderose@jasonderose.org>
# 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.
import sys
import gobject
gobject.threads_init()
import pygst
pygst.require('0.10')
import gst
class Decodebin:
def __init__(self, location):
# The pipeline
self.pipeline = gst.Pipeline()
# Create bus and connect several handlers
self.bus = self.pipeline.get_bus()
self.bus.add_signal_watch()
self.bus.connect('message::eos', self.on_eos)
self.bus.connect('message::tag', self.on_tag)
self.bus.connect('message::error', self.on_error)
# Create elements
self.src = gst.element_factory_make('filesrc')
self.dec = gst.element_factory_make('decodebin')
self.conv = gst.element_factory_make('audioconvert')
self.rsmpl = gst.element_factory_make('audioresample')
self.sink = gst.element_factory_make('alsasink')
# Set 'location' property on filesrc
self.src.set_property('location', location)
# Connect handler for 'new-decoded-pad' signal
self.dec.connect('new-decoded-pad', self.on_new_decoded_pad)
# Add elements to pipeline
self.pipeline.add(self.src, self.dec, self.conv, self.rsmpl, self.sink)
# Link *some* elements
# This is completed in self.on_new_decoded_pad()
self.src.link(self.dec)
gst.element_link_many(self.conv, self.rsmpl, self.sink)
# Reference used in self.on_new_decoded_pad()
self.apad = self.conv.get_pad('sink')
# The MainLoop
self.mainloop = gobject.MainLoop()
# And off we go!
self.pipeline.set_state(gst.STATE_PLAYING)
self.mainloop.run()
def on_new_decoded_pad(self, element, pad, last):
caps = pad.get_caps()
name = caps[0].get_name()
print 'on_new_decoded_pad:', name
if name == 'audio/x-raw-float' or name == 'audio/x-raw-int':
if not self.apad.is_linked(): # Only link once
pad.link(self.apad)
def on_eos(self, bus, msg):
print 'on_eos'
self.mainloop.quit()
def on_tag(self, bus, msg):
taglist = msg.parse_tag()
print 'on_tag:'
for key in taglist.keys():
print '\t%s = %s' % (key, taglist[key])
def on_error(self, bus, msg):
error = msg.parse_error()
print 'on_error:', error[1]
self.mainloop.quit()
if __name__ == '__main__':
if len(sys.argv) == 2:
Decodebin(sys.argv[1])
else:
print 'Usage: %s /path/to/media/file' % sys.argv[0]

View file

@ -1,111 +0,0 @@
#!/usr/bin/env python
# -*- Mode: python -*-
import getopt
import sys
import gst
"""Usage: gst123 [<options>] <input file> ...
-h, --help this help
-V, --version display gst123 version
-d, --device=d uses 'd' as an output device
Possible devices are ('*'=live, '@'=file):
null* wav@ raw@ au@ arts* esd* oss*
-f, --file=filename Set the output filename for a previously
specified file device (with -d).
-k n, --skip n Skip the first 'n' seconds
-b n, --buffer n use an input buffer of 'n' kilobytes
-v, --verbose display progress and other status information
-q, --quiet don't display anything (no title)
-z, --shuffle shuffle play"""
def found_tags_cb(element, source, tags):
for tag in tags.keys():
if tag in ['title', 'artist', 'genre', 'album']:
ntag = tag[0].upper() + tag[1:] + ':'
print '%-8s %s' % (ntag, tags[tag])
def error_cb(bin, element, error, debug):
print error
raise SystemExit
def pad_notify_caps_cb(pad, arg):
caps = pad.get_negotiated_caps()
if not caps:
return
for structure in caps:
print 'Bitstream is %(channels)d channel(s), %(rate)dHz' % structure
def playfile(filename):
bin = gst.Thread('player')
bin.connect('eos', lambda bin: gst.main_quit())
bin.connect('error', error_cb)
source = gst.element_factory_make('filesrc', 'src')
source.set_property('location', filename)
spider = gst.element_factory_make('spider', 'spider')
spider.connect('found-tag', found_tags_cb)
sink = gst.element_factory_make('osssink', 'sink')
#sink.set_property('release-device', 1)
pad = sink.get_pad('sink')
pad.connect('notify::caps', pad_notify_caps_cb)
bin.add_many(source, spider, sink)
if not gst.element_link_many(source, spider, sink):
print "ERROR: could not link"
sys.exit(1)
print 'Playing:', filename
if not bin.set_state(gst.STATE_PLAYING):
print "ERROR: could not set bin to playing"
sys.exit(1)
while 1:
try:
if not gst.main():
break
except KeyboardInterrupt:
if not bin.set_state(gst.STATE_PAUSED):
print "ERROR: could not set bin to paused"
sys.exit(1)
sys.stdout.write("Paused. Press Enter to go back to playing.")
sys.stdout.flush()
try:
sys.stdin.readline()
if not bin.set_state(gst.STATE_PLAYING):
print "ERROR: could not set bin to playing"
sys.exit(1)
print "Playing."
except KeyboardInterrupt:
print
break
bin.set_state(gst.STATE_NULL)
def main(args):
if len(args) > 2:
print 'usage: gst123 files...'
return 2
args2, opt = getopt.getopt(args[1:], 'b:d:f:hk:vVqz',
['help', 'version', 'device=',
'file=', 'skip=', 'buffer=',
'verbose', 'quiet', 'shuffle'])
for arg in args[1:]:
try:
playfile(arg)
except KeyboardInterrupt:
raise SystemExit
if __name__ == '__main__':
sys.exit(main(sys.argv))
for i in range(10, 20, 1):
pass

View file

@ -1,133 +0,0 @@
#!/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))