mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
Update examples, remove some old non-functional ones and add new
Original commit message from CVS: Update examples, remove some old non-functional ones and add new
This commit is contained in:
parent
2425cf1e64
commit
58b2da766e
16 changed files with 354 additions and 925 deletions
|
@ -1,9 +1,8 @@
|
|||
EXTRA_DIST = \
|
||||
bps.py \
|
||||
cp.py \
|
||||
dvdplay.py \
|
||||
f2f.py \
|
||||
ilat.py \
|
||||
lat.py \
|
||||
rot13.py \
|
||||
filesrc.py \
|
||||
gst123 \
|
||||
play.py \
|
||||
vorbisplay.py
|
||||
|
|
|
@ -48,13 +48,13 @@ class BPS(object):
|
|||
gst.main_quit()
|
||||
|
||||
def fakesrc(self, buffers):
|
||||
src = gst.Element('fakesrc','src')
|
||||
src = gst.element_factory_make('fakesrc','src')
|
||||
src.set_property('silent', 1)
|
||||
src.set_property('num_buffers', buffers)
|
||||
return src
|
||||
|
||||
def fakesink(self):
|
||||
sink = gst.Element('fakesink','sink')
|
||||
sink = gst.element_factory_make('fakesink','sink')
|
||||
sink.set_property('silent', 1)
|
||||
return sink
|
||||
|
||||
|
@ -126,6 +126,10 @@ def main(args):
|
|||
bps = BPS()
|
||||
|
||||
buffers = int(args[1])
|
||||
if buffers < 0:
|
||||
print 'buffers must be higher than 0'
|
||||
return
|
||||
|
||||
methods = args[2:]
|
||||
if not methods:
|
||||
methods = ('gtk', 'c', 'py', 'all')
|
||||
|
|
|
@ -30,27 +30,24 @@ def filter(input, output):
|
|||
"A GStreamer copy pipeline which can add arbitrary filters"
|
||||
|
||||
# create a new bin to hold the elements
|
||||
bin = gst.Pipeline('pipeline')
|
||||
|
||||
filesrc = gst.Element('filesrc', 'source');
|
||||
bin = gst.parse_launch('filesrc name=source ! ' +
|
||||
'statistics silent=false buffer-update-freq=1 ' +
|
||||
'update_on_eos=true ! ' +
|
||||
'filesink name=sink')
|
||||
filesrc = bin.get_by_name('source')
|
||||
filesrc.set_property('location', input)
|
||||
|
||||
stats = gst.Element('statistics', 'stats');
|
||||
stats.set_property('silent', False)
|
||||
stats.set_property('buffer_update_freq', True)
|
||||
stats.set_property('update_on_eos', True)
|
||||
|
||||
filesink = gst.Element('filesink', 'sink')
|
||||
filesink = bin.get_by_name('sink')
|
||||
filesink.set_property('location', output)
|
||||
|
||||
bin.add_many(filesrc, stats, filesink)
|
||||
gst.element_link_many(filesrc, stats, filesink)
|
||||
|
||||
# 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)
|
||||
|
|
|
@ -1,227 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# gst-python
|
||||
# Copyright (C) 2002 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
|
||||
import gtk
|
||||
gtk.threads_init()
|
||||
|
||||
class DVDPlayer(object):
|
||||
def idle(self, pipeline):
|
||||
#gtk.threads_enter()
|
||||
pipeline.iterate()
|
||||
#gtk.threads_leave()
|
||||
return 1
|
||||
|
||||
def eof(self, sender):
|
||||
print 'EOS, quiting'
|
||||
sys.exit(0)
|
||||
|
||||
def mpegparse_newpad(self, parser, pad, pipeline):
|
||||
#gtk.threads_enter()
|
||||
print '***** a new pad %s was created' % pad.get_name()
|
||||
if pad.get_name()[:6] == 'video_':
|
||||
pad.link(self.v_queue.get_pad('sink'))
|
||||
self.pipeline.set_state(gst.STATE_PAUSED)
|
||||
self.pipeline.add(self.v_thread)
|
||||
#self.v_thread.set_state(gst.STATE_PLAYING)
|
||||
self.pipeline.set_state(gst.STATE_PLAYING)
|
||||
elif pad.get_name() == 'private_stream_1.0':
|
||||
pad.link(self.a_queue.get_pad('sink'))
|
||||
self.pipeline.set_state(gst.STATE_PAUSED)
|
||||
self.pipeline.add(self.a_thread)
|
||||
#self.a_thread.set_state(gst.STATE_PLAYING);
|
||||
self.pipeline.set_state(gst.STATE_PLAYING)
|
||||
else:
|
||||
print 'unknown pad: %s' % pad.get_name()
|
||||
#gtk.threads_leave()
|
||||
|
||||
def mpegparse_have_size(self, videosink, width, height):
|
||||
gtk.threads_enter()
|
||||
self.gtk_socket.set_usize(width,height)
|
||||
self.appwindow.show_all()
|
||||
gtk.threads_leave()
|
||||
|
||||
def main(self, location, title, chapter, angle):
|
||||
self.location = location
|
||||
self.title = title
|
||||
self.chapter = chapter
|
||||
self.angle = angle
|
||||
|
||||
#gst_init(&argc,&argv);
|
||||
#gnome_init('MPEG2 Video player','0.0.1',argc,argv);
|
||||
|
||||
ret = self.build()
|
||||
if ret:
|
||||
return ret
|
||||
|
||||
return self.run()
|
||||
|
||||
def run(self):
|
||||
print 'setting to PLAYING state'
|
||||
|
||||
gtk.threads_enter()
|
||||
|
||||
self.pipeline.set_state(gst.STATE_PLAYING)
|
||||
|
||||
gtk.idle_add(self.idle,self.pipeline)
|
||||
|
||||
gtk.main()
|
||||
|
||||
self.pipeline.set_state(gst.STATE_NULL)
|
||||
|
||||
gtk.threads_leave()
|
||||
|
||||
return 0
|
||||
|
||||
def build_video_thread(self):
|
||||
# ***** pre-construct the video thread *****
|
||||
self.v_thread = gst.Thread('v_thread')
|
||||
|
||||
self.v_queue = gst.Element('queue','v_queue')
|
||||
|
||||
self.v_decode = gst.Element('mpeg2dec','decode_video')
|
||||
|
||||
self.color = gst.Element('colorspace','color')
|
||||
|
||||
self.efx = gst.Element('identity','identity')
|
||||
#self.efx = gst.Element('edgeTV','EdgeTV')
|
||||
#self.efx = gst.Element('agingTV','AgingTV')
|
||||
#effectv: diceTV: DiceTV
|
||||
#effectv: warpTV: WarpTV
|
||||
#effectv: shagadelicTV: ShagadelicTV
|
||||
#effectv: vertigoTV: VertigoTV
|
||||
#self.efx = gst.Element('revTV','RevTV')
|
||||
#self.efx = gst.Element('quarkTV','QuarkTV')
|
||||
|
||||
self.color2 = gst.Element('colorspace','color2')
|
||||
|
||||
self.show = gst.Element('xvideosink','show')
|
||||
#self.show = Element('sdlvideosink','show')
|
||||
#self.show = Element('fakesink','fakesinkv')
|
||||
#self.show.set_property('silent', 0)
|
||||
#self.show.set_property('sync', 1)
|
||||
|
||||
#self.deinterlace = gst.Element('deinterlace','deinterlace')
|
||||
self.deinterlace = gst.Element('identity','deinterlace')
|
||||
|
||||
last = None
|
||||
for e in (self.v_queue, self.v_decode, self.color, self.efx, self.color2, self.deinterlace, self.show):
|
||||
self.v_thread.add(e)
|
||||
if last:
|
||||
last.link(e)
|
||||
last = e
|
||||
|
||||
#self.v_queue.link(self.v_decode)
|
||||
#self.v_decode.link(self.color)
|
||||
#self.color.link(self.efx)
|
||||
#self.efx.link(self.color2)
|
||||
#self.color2.link(self.show)
|
||||
|
||||
def build_audio_thread(self):
|
||||
# ***** pre-construct the audio thread *****
|
||||
self.a_thread = gst.Thread('a_thread')
|
||||
|
||||
self.a_queue = gst.Element('queue','a_queue')
|
||||
|
||||
self.a_decode = gst.Element('a52dec','decode_audio')
|
||||
|
||||
self.osssink = gst.Element('osssink','osssink')
|
||||
#self.osssink = Element('fakesink','fakesinka')
|
||||
#self.osssink.set_property('silent', 0)
|
||||
#self.osssink.set_property('sync', 0)
|
||||
|
||||
for e in (self.a_queue, self.a_decode, self.osssink):
|
||||
self.a_thread.add(e)
|
||||
|
||||
self.a_queue.link(self.a_decode)
|
||||
self.a_decode.link(self.osssink)
|
||||
|
||||
def build(self):
|
||||
# ***** construct the main pipeline *****
|
||||
self.pipeline = gst.Pipeline('pipeline')
|
||||
|
||||
self.src = gst.Element('dvdreadsrc','src');
|
||||
|
||||
self.src.connect('deep_notify',self.dnprint)
|
||||
self.src.set_property('location', self.location)
|
||||
self.src.set_property('title', self.title)
|
||||
self.src.set_property('chapter', self.chapter)
|
||||
self.src.set_property('angle', self.angle)
|
||||
|
||||
self.parse = gst.Element('mpegdemux','parse')
|
||||
self.parse.set_property('sync', 0)
|
||||
|
||||
self.pipeline.add(self.src)
|
||||
self.pipeline.add(self.parse)
|
||||
|
||||
self.src.link(self.parse)
|
||||
|
||||
# pre-construct the audio/video threads
|
||||
self.build_video_thread()
|
||||
self.build_audio_thread()
|
||||
|
||||
# ***** construct the GUI *****
|
||||
#self.appwindow = gnome_app_new('DVD Player','DVD Player')
|
||||
|
||||
#self.gtk_socket = gtk_socket_new ()
|
||||
#gtk_socket.show()
|
||||
|
||||
#gnome_app_set_contents(GNOME_APP(appwindow),
|
||||
#GTK_WIDGET(gtk_socket));
|
||||
|
||||
#gtk_widget_realize (gtk_socket);
|
||||
#gtk_socket_steal (GTK_SOCKET (gtk_socket),
|
||||
#gst_util_get_int_arg (GTK_OBJECT(show), 'xid'));
|
||||
|
||||
self.parse.connect('new_pad',self.mpegparse_newpad, self.pipeline)
|
||||
self.src.connect('eos',self.eof)
|
||||
#show.connect('have_size',self.mpegparse_have_size, self.pipeline)
|
||||
|
||||
#self.pipeline.connect('error',self.pipeline_error)
|
||||
#self.pipeline.connect('deep_notify',self.dnprint)
|
||||
|
||||
return 0
|
||||
|
||||
def pipeline_error(self, sender, obj, error):
|
||||
print "(%s) ERROR: %s: %s" % (self, obj.name(), error)
|
||||
|
||||
def dnprint(self, sender, obj, param):
|
||||
str = obj.get_property(param.name)
|
||||
print '%s: %s = %s' % (sender.get_name(), param.name, str)
|
||||
|
||||
def main(args):
|
||||
if len(sys.argv) < 5:
|
||||
print 'usage: %s dvdlocation title chapter angle' % sys.argv[0]
|
||||
return -1
|
||||
|
||||
location = sys.argv[1]
|
||||
title = int(sys.argv[2])
|
||||
chapter = int(sys.argv[3])
|
||||
angle = int(sys.argv[4])
|
||||
|
||||
player = DVDPlayer()
|
||||
return player.main(location, title, chapter, angle)
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
|
@ -25,39 +25,25 @@ import sys
|
|||
|
||||
import gst
|
||||
|
||||
def handoff(sender, *args):
|
||||
def handoff_cb(sender, *args):
|
||||
print sender.get_name(), args
|
||||
|
||||
def main(args):
|
||||
# create a new bin to hold the elements
|
||||
#gst_debug_set_categories(-1)
|
||||
bin = gst.Pipeline('pipeline')
|
||||
bin = gst.parse_launch('fakesrc name=source silent=1 num-buffers=10 ! ' +
|
||||
'fakesink name=sink silent=1')
|
||||
source = bin.get_by_name('source')
|
||||
source.connect('handoff', handoff_cb)
|
||||
sink = bin.get_by_name('source')
|
||||
sink.connect('handoff', handoff_cb)
|
||||
|
||||
src = gst.Element('fakesrc', 'src')
|
||||
src.connect('handoff', handoff)
|
||||
src.set_property('silent', 1)
|
||||
src.set_property('num_buffers', 10)
|
||||
|
||||
sink = gst.Element('fakesink', 'sink')
|
||||
sink.connect('handoff', handoff)
|
||||
src.set_property('silent', 1)
|
||||
|
||||
# add objects to the main pipeline
|
||||
for e in (src, sink):
|
||||
bin.add(e)
|
||||
|
||||
# link the elements
|
||||
res = src.link(sink)
|
||||
assert res
|
||||
|
||||
# start playing
|
||||
res = bin.set_state(gst.STATE_PLAYING);
|
||||
assert res
|
||||
|
||||
while bin.iterate():
|
||||
pass
|
||||
|
||||
# stop the bin
|
||||
res = bin.set_state(gst.STATE_NULL)
|
||||
assert res
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ class FileSource(gst.Element):
|
|||
gobject.type_register(FileSource)
|
||||
|
||||
def main(args):
|
||||
|
||||
print 'This example is not finished yet.'
|
||||
return
|
||||
|
||||
|
@ -64,7 +63,7 @@ def main(args):
|
|||
assert filesrc
|
||||
filesrc.set_property('location', args[1])
|
||||
|
||||
filesink = gst.Element('filesink', 'sink')
|
||||
filesink = gst.element_factory_make('filesink', 'sink')
|
||||
filesink.set_property('location', args[2])
|
||||
|
||||
bin.add_many(filesrc, filesink)
|
||||
|
|
111
examples/gst/gst123
Executable file
111
examples/gst/gst123
Executable file
|
@ -0,0 +1,111 @@
|
|||
#!/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
|
|
@ -1,93 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# gst-python
|
||||
# Copyright (C) 2002 David I. Lehn
|
||||
# 2004 Johan Dahlin
|
||||
#
|
||||
# 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 gobject
|
||||
import gst
|
||||
|
||||
class Identity(gst.Element):
|
||||
def __init__(self):
|
||||
self.__gobject_init__()
|
||||
self.sinkpad = gst.Pad('sink', gst.PAD_SINK)
|
||||
self.add_pad(self.sinkpad)
|
||||
self.sinkpad.set_chain_function(self.chain)
|
||||
self.sinkpad.set_link_function(self.pad_link)
|
||||
|
||||
self.srcpad = gst.Pad('src', gst.PAD_SRC)
|
||||
self.add_pad(self.srcpad)
|
||||
self.srcpad.set_link_function(self.pad_link)
|
||||
|
||||
def get_bufferpool(self, pad):
|
||||
print 'get_bufferpool:', self, pad
|
||||
return self.srcpad.get_bufferpool()
|
||||
|
||||
def pad_link(self, pad, caps):
|
||||
print 'pad_link:', self, pad, caps
|
||||
return gst.PAD_LINK_OK
|
||||
|
||||
def chain(self, pad, buf):
|
||||
self.srcpad.push(buf)
|
||||
|
||||
gobject.type_register(Identity)
|
||||
|
||||
def filter(element):
|
||||
# create a new bin to hold the elements
|
||||
bin = gst.Pipeline('pipeline')
|
||||
|
||||
filesrc = gst.Element('sinesrc', 'source');
|
||||
filesink = gst.Element('fakesink', 'sink')
|
||||
|
||||
stats = gst.Element('statistics', 'stats');
|
||||
stats.set_property('silent', False)
|
||||
stats.set_property('buffer_update_freq', True)
|
||||
stats.set_property('update_on_eos', True)
|
||||
|
||||
bin.add_many(filesrc, element, stats, filesink)
|
||||
gst.element_link_many(filesrc, element, stats, filesink)
|
||||
|
||||
# start playing
|
||||
bin.set_state(gst.STATE_PLAYING);
|
||||
|
||||
while bin.iterate():
|
||||
pass
|
||||
|
||||
# stop the bin
|
||||
bin.set_state(gst.STATE_NULL)
|
||||
|
||||
def main(args):
|
||||
"A GStreamer Python subclassing example of an identity filter"
|
||||
print "This example is not finished."
|
||||
sys.exit(1)
|
||||
|
||||
identity = Identity()
|
||||
identity.set_name('identity')
|
||||
if not identity:
|
||||
print 'could not create \"Identity\" element'
|
||||
return -1
|
||||
|
||||
return filter(identity)
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# gst-python
|
||||
# Copyright (C) 2002 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
|
||||
import time
|
||||
from identity import Identity
|
||||
|
||||
def update(sender, *args):
|
||||
print sender.get_name(), args
|
||||
|
||||
def build(filters, b):
|
||||
# create a new bin to hold the elements
|
||||
bin = gst.Pipeline('pipeline')
|
||||
|
||||
src = gst.Element('fakesrc', 'source');
|
||||
src.set_property('silent', 1)
|
||||
src.set_property('num_buffers', b)
|
||||
|
||||
sink = gst.Element('fakesink', 'sink')
|
||||
sink.set_property('silent', 1)
|
||||
|
||||
elements = [src] + filters + [sink]
|
||||
bin.add_many(*elements)
|
||||
gst.element_link_many(*elements)
|
||||
return bin
|
||||
|
||||
def filter(bin):
|
||||
bin.set_state(gst.STATE_PLAYING);
|
||||
while bin.iterate():
|
||||
pass
|
||||
bin.set_state(gst.STATE_NULL)
|
||||
|
||||
ccnt = 0
|
||||
def c():
|
||||
global ccnt
|
||||
id = gst.Element('identity', 'c identity %d' % ccnt);
|
||||
id.set_property('silent', 1)
|
||||
id.set_property('loop_based', 0)
|
||||
ccnt += 1
|
||||
return id
|
||||
|
||||
pcnt = 0
|
||||
def py():
|
||||
id = Identity()
|
||||
assert id
|
||||
global pcnt
|
||||
id.set_name('py identity %d' % pcnt)
|
||||
pcnt += 1
|
||||
return id
|
||||
|
||||
def check(f, n, b):
|
||||
fs = []
|
||||
for i in range(n):
|
||||
fs.append(f())
|
||||
|
||||
pipe = build(fs, b)
|
||||
|
||||
start = time.time()
|
||||
ret = filter(pipe)
|
||||
end = time.time()
|
||||
print '%s b:%d i:%d t:%f' % (f, b, n, end - start)
|
||||
return ret
|
||||
|
||||
def main(args):
|
||||
"Identity timer and latency check"
|
||||
|
||||
if len(args) < 3:
|
||||
print 'usage: %s identites buffers' % args[0]
|
||||
return -1
|
||||
n = int(args[1])
|
||||
b = int(args[2])
|
||||
|
||||
for f in (c, py):
|
||||
check(f, n, b)
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
|
@ -1,178 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# gst-python
|
||||
# Copyright (C) 2002 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 time
|
||||
import gst
|
||||
|
||||
def update(sender, *args):
|
||||
print sender.get_name(), args
|
||||
|
||||
max = 0
|
||||
min = -1
|
||||
total = 0
|
||||
count = 0
|
||||
print_del = 1
|
||||
interations = 0
|
||||
|
||||
def handoff_src(src, buf):
|
||||
#buf.set_timestamp(time.time())
|
||||
pass
|
||||
|
||||
def handoff_sink(sink, buf):
|
||||
global max, min, total, count
|
||||
|
||||
end = time.time()
|
||||
#d = end - buf.get_timestamp()
|
||||
d = end - 0
|
||||
if d > max:
|
||||
max = d
|
||||
if d < min:
|
||||
min = d
|
||||
total += d
|
||||
count += 1
|
||||
avg = total/count
|
||||
|
||||
if (count % print_del) == 0:
|
||||
print '%07d:%08d min:%08d max:%08d avg:%f\n' %\
|
||||
(count, d, min, max, avg),
|
||||
|
||||
def identity_add(pipeline, first, count):
|
||||
last = first
|
||||
|
||||
for i in range(count):
|
||||
name = 'identity_%03d' % i
|
||||
ident = gst.Element('identity', name)
|
||||
ident.set_property('silent', 1)
|
||||
pipeline.add(ident)
|
||||
last.get_pad('src').link(ident.get_pad('sink'))
|
||||
last = ident
|
||||
|
||||
return last
|
||||
|
||||
def fakesrc():
|
||||
src = gst.Element('fakesrc','src')
|
||||
src.set_property('silent', 1)
|
||||
src.set_property('num_buffers', iterations)
|
||||
src.connect('handoff', handoff_src)
|
||||
return src
|
||||
|
||||
def fakesink():
|
||||
sink = gst.Element('fakesink','fakesink')
|
||||
sink.set_property('silent', 1)
|
||||
sink.connect('handoff', handoff_sink)
|
||||
return sink
|
||||
|
||||
def simple(argv):
|
||||
if len(argv) < 1:
|
||||
print 'simple: bad params'
|
||||
return None
|
||||
idents = int(argv[0])
|
||||
|
||||
pipeline = gst.Pipeline('pipeline')
|
||||
|
||||
src = fakesrc()
|
||||
pipeline.add(src)
|
||||
last = identity_add(pipeline, src, idents)
|
||||
sink = fakesink()
|
||||
pipeline.add(sink)
|
||||
last.get_pad('src').link(sink.get_pad('sink'))
|
||||
|
||||
return pipeline
|
||||
|
||||
def queue(argv):
|
||||
if len(argv) < 1:
|
||||
print 'queue: bad params'
|
||||
return None
|
||||
idents = int(argv[0])
|
||||
|
||||
pipeline = gst.Pipeline('pipeline')
|
||||
|
||||
src_thr = gst.Thread('src_thread')
|
||||
|
||||
src = fakesrc()
|
||||
src_thr.add(src)
|
||||
|
||||
src_q = gst.Element('queue','src_q')
|
||||
src_thr.add(src_q)
|
||||
src.get_pad('src').link(src_q.get_pad('sink'))
|
||||
|
||||
pipeline.add(src_thr)
|
||||
|
||||
last = identity_add(pipeline, src_q, idents)
|
||||
|
||||
sink_q = gst.Element('queue','sink_q')
|
||||
pipeline.add(sink_q)
|
||||
last.get_pad('src').link(sink_q.get_pad('sink'))
|
||||
|
||||
sink_thr = gst.Thread('sink_thread')
|
||||
|
||||
sink = fakesink()
|
||||
|
||||
sink_thr.add(sink)
|
||||
|
||||
pipeline.add(sink_thr)
|
||||
|
||||
sink_q.get_pad('src').link(sink.get_pad('sink'))
|
||||
|
||||
return pipeline
|
||||
|
||||
tests = {
|
||||
'simple' : ('ident_count [scheduler_name]', simple),
|
||||
'queue' : ('ident_count [scheduler_name]', queue),
|
||||
}
|
||||
|
||||
def main():
|
||||
"A GStreamer latency tester"
|
||||
global iterations, print_del
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print 'usage: %s iterations print_del test_name [test_params...]' % sys.argv[0]
|
||||
for name in tests.keys():
|
||||
doc, func = tests[name]
|
||||
print ' %s %s' % (name, doc)
|
||||
return -1
|
||||
else:
|
||||
iterations = int(sys.argv[1])
|
||||
print_del = int(sys.argv[2])
|
||||
name = sys.argv[3]
|
||||
|
||||
pipeline = tests[name][1](sys.argv[4:])
|
||||
assert pipeline
|
||||
|
||||
#xmlSaveFile('lat.gst', gst_xml_write(pipeline))
|
||||
|
||||
pipeline.set_state(gst.STATE_PLAYING)
|
||||
|
||||
while count < iterations:
|
||||
pipeline.iterate()
|
||||
|
||||
pipeline.set_state(gst.STATE_NULL)
|
||||
|
||||
print
|
||||
|
||||
return 0;
|
||||
|
||||
if __name__ == '__main__':
|
||||
ret = main()
|
||||
sys.exit (ret)
|
191
examples/gst/play.py
Normal file
191
examples/gst/play.py
Normal file
|
@ -0,0 +1,191 @@
|
|||
import pygtk
|
||||
pygtk.require('2.0')
|
||||
|
||||
import sys
|
||||
|
||||
import gobject
|
||||
import gst
|
||||
import gst.interfaces
|
||||
import gtk
|
||||
|
||||
class GstPlayer:
|
||||
def __init__(self):
|
||||
self.player = gst.element_factory_make("playbin", "player")
|
||||
|
||||
def set_video_sink(self, sink):
|
||||
self.player.set_property('video-sink', sink)
|
||||
print self.player.get_property('video-sink')
|
||||
|
||||
def set_location(self, location):
|
||||
self.player.set_property('uri', location)
|
||||
|
||||
def get_length(self):
|
||||
return self.player.query(gst.QUERY_TOTAL, gst.FORMAT_TIME)
|
||||
|
||||
def get_position(self):
|
||||
return self.player.query(gst.QUERY_POSITION, gst.FORMAT_TIME)
|
||||
|
||||
def seek(self, location):
|
||||
print "seek to %ld on element %s" % (location, self.player.get_name())
|
||||
event = gst.event_new_seek(gst.FORMAT_TIME |
|
||||
gst.SEEK_METHOD_SET |
|
||||
gst.SEEK_FLAG_FLUSH, location)
|
||||
|
||||
self.player.send_event(event)
|
||||
self.player.set_state(gst.STATE_PLAYING)
|
||||
|
||||
def pause(self):
|
||||
self.player.set_state(gst.STATE_PAUSED)
|
||||
|
||||
def play(self):
|
||||
self.player.set_state(gst.STATE_PLAYING)
|
||||
|
||||
def stop(self):
|
||||
self.player.set_state(gst.STATE_READY)
|
||||
|
||||
is_playing = lambda self: self.player.get_state() == gst.STATE_PLAYING
|
||||
is_paused = lambda self: self.player.get_state() == gst.STATE_PAUSED
|
||||
is_stopped = lambda self: self.player.get_state() == gst.STATE_READY
|
||||
|
||||
class VideoWidget(gtk.DrawingArea):
|
||||
def __init__(self, player):
|
||||
gtk.DrawingArea.__init__(self)
|
||||
self.connect('destroy', self.destroy_cb)
|
||||
self.connect_after('realize', self.after_realize_cb)
|
||||
self.set_size_request(400, 400)
|
||||
|
||||
self.player = player
|
||||
self.imagesink = gst.Element('xvimagesink')
|
||||
self.player.set_video_sink(self.imagesink)
|
||||
|
||||
def destroy_cb(self, da):
|
||||
self.set_window_id(0L)
|
||||
|
||||
# Sort of a hack, but it works for now.
|
||||
def after_realize_cb(self, window):
|
||||
gtk.idle_add(self.idler)
|
||||
|
||||
def idler(self):
|
||||
self.set_window_id(self.window.xid)
|
||||
|
||||
def set_window_id(self, xid):
|
||||
self.imagesink.set_xwindow_id(xid)
|
||||
|
||||
|
||||
class PlayerWindow(gtk.Window):
|
||||
UPDATE_INTERVAL = 500
|
||||
def __init__(self):
|
||||
gtk.Window.__init__(self)
|
||||
self.connect('delete-event', gtk.main_quit)
|
||||
self.set_default_size(96, 96)
|
||||
|
||||
self.player = GstPlayer()
|
||||
|
||||
self.create_ui()
|
||||
|
||||
self.update_id = -1
|
||||
|
||||
def load_file(self, location):
|
||||
self.player.set_location(location)
|
||||
|
||||
def create_ui(self):
|
||||
vbox = gtk.VBox()
|
||||
|
||||
videowidget = VideoWidget(self.player)
|
||||
vbox.pack_start(videowidget)
|
||||
|
||||
hbox = gtk.HBox()
|
||||
vbox.pack_start(hbox)
|
||||
|
||||
button = gtk.Button('play')
|
||||
button.connect('clicked', self.play_clicked_cb)
|
||||
hbox.pack_start(button, False)
|
||||
|
||||
button = gtk.Button("pause");
|
||||
button.connect('clicked', self.pause_clicked_cb)
|
||||
hbox.pack_start(button, False)
|
||||
|
||||
button = gtk.Button("stop");
|
||||
button.connect('clicked', self.stop_clicked_cb)
|
||||
hbox.pack_start(button, False)
|
||||
|
||||
self.adjustment = gtk.Adjustment(0.0, 0.00, 100.0, 0.1, 1.0, 1.0)
|
||||
hscale = gtk.HScale(self.adjustment)
|
||||
hscale.set_digits(2)
|
||||
hscale.set_update_policy(gtk.UPDATE_CONTINUOUS)
|
||||
hscale.connect('button-press-event', self.scale_button_press_cb)
|
||||
hscale.connect('button-release-event', self.scale_button_release_cb)
|
||||
hscale.connect('format-value', self.scale_format_value_cb)
|
||||
hbox.pack_start(hscale)
|
||||
|
||||
self.add(vbox)
|
||||
|
||||
def scale_format_value_cb(self, scale, value):
|
||||
duration = self.player.get_length()
|
||||
if duration == -1:
|
||||
real = 0
|
||||
else:
|
||||
real = value * duration / 100
|
||||
|
||||
seconds = real / gst.SECOND
|
||||
|
||||
return "%02d:%02d" % (seconds / 60, seconds % 60)
|
||||
|
||||
def scale_button_press_cb(self, widget, event):
|
||||
self.player.pause()
|
||||
if self.update_id != -1:
|
||||
gtk.timeout_remove(self.update_id)
|
||||
self.update_id = -1
|
||||
|
||||
def scale_button_release_cb(self, widget, event):
|
||||
duration = self.player.get_length()
|
||||
real = long(widget.get_value() * duration / 100)
|
||||
self.player.seek(real)
|
||||
|
||||
self.update_id = gtk.timeout_add(self.UPDATE_INTERVAL,
|
||||
self.update_scale_cb)
|
||||
|
||||
def update_scale_cb(self):
|
||||
length = self.player.get_length()
|
||||
if length:
|
||||
value = self.player.get_position() * 100.0 / length
|
||||
self.adjustment.set_value(value)
|
||||
|
||||
return True
|
||||
|
||||
def play_clicked_cb(self, button):
|
||||
if self.player.is_playing():
|
||||
return
|
||||
|
||||
self.player.play()
|
||||
self.update_id = gtk.timeout_add(self.UPDATE_INTERVAL,
|
||||
self.update_scale_cb)
|
||||
|
||||
def pause_clicked_cb(self, button):
|
||||
if self.player.is_paused():
|
||||
return
|
||||
|
||||
self.player.pause()
|
||||
if self.update_id != -1:
|
||||
gtk.timeout_remove(self.update_id)
|
||||
self.update_id = -1
|
||||
|
||||
def stop_clicked_cb(self, button):
|
||||
if self.player.is_stopped():
|
||||
return
|
||||
|
||||
self.player.stop()
|
||||
if self.update_id != -1:
|
||||
gtk.timeout_remove(self.update_id)
|
||||
self.update_id = -1
|
||||
self.adjustment.set_value(0.0)
|
||||
|
||||
def main(args):
|
||||
w = PlayerWindow()
|
||||
w.load_file(args[1])
|
||||
w.show_all()
|
||||
|
||||
gtk.main()
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
|
@ -1,48 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
import gst
|
||||
|
||||
def found_tags_cb(element, source, tags):
|
||||
for tag in tags.keys():
|
||||
print "%s: %s" % (gst.tag_get_nick(tag), tags[tag])
|
||||
|
||||
def error_cb(*args):
|
||||
print args
|
||||
|
||||
def playfile(filename):
|
||||
bin = gst.Thread('player')
|
||||
bin.connect('eos', lambda x: gst.main_quit())
|
||||
bin.connect('error', error_cb)
|
||||
|
||||
source = gst.Element('filesrc', 'src')
|
||||
source.set_property('location', filename)
|
||||
|
||||
spider = gst.Element('spider', 'spider')
|
||||
spider.connect('found-tag', found_tags_cb)
|
||||
|
||||
sink = gst.Element('osssink', 'sink')
|
||||
#sink.set_property('release-device', 1)
|
||||
|
||||
bin.add_many(source, spider, sink)
|
||||
if not gst.element_link_many(source, spider, sink):
|
||||
print "ERROR: could not link"
|
||||
return 2
|
||||
|
||||
print 'Playing:', os.path.basename(filename)
|
||||
if not bin.set_state(gst.STATE_PLAYING):
|
||||
print "ERROR: could not set bin to playing"
|
||||
return 2
|
||||
|
||||
gst.main()
|
||||
|
||||
def main(args):
|
||||
if len(args) != 2:
|
||||
print 'Usage; player.py filename'
|
||||
return 1
|
||||
return playfile(args[1])
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# gst-python
|
||||
# Copyright (C) 2002 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
|
||||
from identity import Identity
|
||||
from cp import filter
|
||||
|
||||
class Rot13(Identity):
|
||||
def chain(self, pad, buf):
|
||||
# override Identity's chain
|
||||
data = buf.get_data()
|
||||
data2 = ''
|
||||
# waste cycles
|
||||
for c in data:
|
||||
if c.isalpha():
|
||||
if c.islower():
|
||||
a = 'a'
|
||||
else:
|
||||
a = 'A'
|
||||
c = chr((((ord(c) - ord(a)) + 13) % 26) + ord(a))
|
||||
data2 = data2 + c
|
||||
newbuf = gst.Buffer()
|
||||
newbuf.set_data(data2)
|
||||
self.srcpad.push(newbuf)
|
||||
|
||||
gobject.type_register(Rot13)
|
||||
|
||||
def main(args):
|
||||
"A GStreamer Python subclassing example of a rot13 filter"
|
||||
|
||||
rot13 = Rot13()
|
||||
rot13.set_name('rot13')
|
||||
if not rot13:
|
||||
print 'could not create \"Rot13\" element'
|
||||
return -1
|
||||
|
||||
return filter([rot13])
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
|
@ -1,116 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# -*- Mode: Python -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
#
|
||||
# gst-python
|
||||
# Copyright (C) 2002 David I. Lehn <dlehn@users.sourceforge.net>
|
||||
# 2004 Johan Dahlin <johan@gnome.org>
|
||||
# 2004 Thomas Vander Stichele <thomas at apestaart dot 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.
|
||||
|
||||
from gst import *
|
||||
import gst.interface
|
||||
|
||||
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 main():
|
||||
"example for v4l element"
|
||||
|
||||
# create a new bin to hold the elements
|
||||
bin = Pipeline('pipeline')
|
||||
|
||||
# create a v4l reader
|
||||
src = Element('v4lsrc', 'src')
|
||||
|
||||
# colorspace
|
||||
csp = Element('ffmpegcolorspace', 'csp')
|
||||
|
||||
# displayer
|
||||
sink = Element('ximagesink', 'sink')
|
||||
|
||||
# add and link
|
||||
bin.add_many(src, csp, sink)
|
||||
src.link(csp)
|
||||
csp.link(sink)
|
||||
|
||||
# start playing
|
||||
bin.set_state(STATE_PLAYING);
|
||||
dir(src)
|
||||
src.get_channel()
|
||||
|
||||
while bin.iterate(): pass
|
||||
|
||||
# stop the bin
|
||||
bin.set_state(STATE_NULL)
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
ret = main()
|
||||
sys.exit(ret)
|
|
@ -22,7 +22,7 @@
|
|||
#
|
||||
|
||||
import sys
|
||||
from gst import *
|
||||
import gst
|
||||
|
||||
def gst_props_debug_entry(entry, level=0):
|
||||
name = entry.get_name()
|
||||
|
@ -97,52 +97,35 @@ def decoder_notified(sender, pspec):
|
|||
else:
|
||||
print 'notify:', sender, pspec
|
||||
|
||||
def main():
|
||||
def main(args):
|
||||
"Basic example to play an Ogg Vorbis stream through OSS"
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print 'usage: %s <Ogg Vorbis file>' % (sys.argv[0])
|
||||
if len(args) != 2:
|
||||
print 'usage: %s <Ogg Vorbis file>' % args
|
||||
return -1
|
||||
|
||||
# create a new bin to hold the elements
|
||||
bin = Pipeline('pipeline')
|
||||
|
||||
# create a disk reader
|
||||
filesrc = Element ('filesrc', 'disk_source')
|
||||
filesrc.set_property('location', sys.argv[1])
|
||||
|
||||
# now get the demuxer
|
||||
demuxer = Element ('oggdemux', 'demuxer')
|
||||
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)
|
||||
|
||||
# now get the decoder
|
||||
decoder = Element ('vorbisdec', 'decoder')
|
||||
decoder = bin.get_by_name('decoder')
|
||||
decoder.connect('notify', decoder_notified)
|
||||
|
||||
# and an audio sink
|
||||
osssink = Element ('osssink', 'play_audio')
|
||||
|
||||
# add objects to the main pipeline
|
||||
for e in (filesrc, demuxer, decoder, osssink):
|
||||
bin.add(e)
|
||||
|
||||
# link the elements
|
||||
previous = None
|
||||
for e in (filesrc, demuxer, decoder, osssink):
|
||||
if previous:
|
||||
previous.link(e)
|
||||
previous = e
|
||||
|
||||
# start playing
|
||||
bin.set_state(STATE_PLAYING);
|
||||
bin.set_state(gst.STATE_PLAYING);
|
||||
|
||||
while bin.iterate(): pass
|
||||
try:
|
||||
while bin.iterate():
|
||||
pass
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
# stop the bin
|
||||
bin.set_state(STATE_NULL)
|
||||
|
||||
return 0
|
||||
bin.set_state(gst.STATE_NULL)
|
||||
|
||||
if __name__ == '__main__':
|
||||
ret = main()
|
||||
sys.exit(ret)
|
||||
sys.exit(main(sys.argv))
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
import gst
|
||||
|
||||
def decode(filename):
|
||||
output = filename + '.wav'
|
||||
pipeline = ('{ filesrc location="%s" ! spider ! audio/x-raw-int,rate=44100,stereo=2 ! wavenc ! '
|
||||
'filesink location="%s" }') % (filename, output)
|
||||
|
||||
bin = gst.parse_launch(pipeline)
|
||||
bin.set_state(gst.STATE_PLAYING)
|
||||
bin.connect('eos', lambda bin: gst.main_quit())
|
||||
gst.main()
|
||||
|
||||
def main(args):
|
||||
for arg in args[1:]:
|
||||
decode(arg)
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
Loading…
Reference in a new issue