summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Hervey <bilboed@bilboed.com>2006-10-20 09:47:16 +0000
committerEdward Hervey <bilboed@bilboed.com>2006-10-20 09:47:16 +0000
commit5b2c08ac3795f863731d92c03dc1f66c0028255b (patch)
tree72d3325a29aa85c485f96e7fca9e31c9567c069c
parent71f58a44b4093c3657e8ae8671c28e4864717270 (diff)
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
-rw-r--r--ChangeLog11
-rw-r--r--examples/decodebin.py109
-rwxr-xr-xexamples/gst123111
-rwxr-xr-xexamples/vorbisplay.py133
4 files changed, 120 insertions, 244 deletions
diff --git a/ChangeLog b/ChangeLog
index 14caf8f..8c6abcc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* examples/audioconcat.py:
diff --git a/examples/decodebin.py b/examples/decodebin.py
new file mode 100644
index 0000000..be044a6
--- /dev/null
+++ b/examples/decodebin.py
@@ -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]
diff --git a/examples/gst123 b/examples/gst123
deleted file mode 100755
index a5a2a17..0000000
--- a/examples/gst123
+++ /dev/null
@@ -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
diff --git a/examples/vorbisplay.py b/examples/vorbisplay.py
deleted file mode 100755
index 2ff6688..0000000
--- a/examples/vorbisplay.py
+++ /dev/null
@@ -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))