2005-07-12 15:23:22 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# gst-python
|
|
|
|
# Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
|
|
# A test more of gst-plugins than of gst-python.
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
|
|
|
import gtk.gdk
|
|
|
|
import pango
|
2005-07-13 10:03:04 +00:00
|
|
|
import gobject
|
2005-07-12 15:23:22 +00:00
|
|
|
|
|
|
|
import pygst
|
2005-12-01 19:15:26 +00:00
|
|
|
pygst.require('0.10')
|
2005-07-12 15:23:22 +00:00
|
|
|
import gst
|
|
|
|
|
2005-09-01 14:39:51 +00:00
|
|
|
import debugslider
|
|
|
|
|
2005-07-12 15:23:22 +00:00
|
|
|
|
|
|
|
data = (('Video capture via V4L',
|
|
|
|
'v4lsrc name=source \n'
|
|
|
|
' ! videorate \n'
|
|
|
|
' ! xvimagesink'),
|
2005-07-13 10:03:04 +00:00
|
|
|
('Video capture via V4L, fixed frame rate',
|
|
|
|
'v4lsrc name=source autoprobe=false autoprobe-fps=false \n'
|
2005-09-29 16:38:06 +00:00
|
|
|
' ! video/x-raw-yuv,format=(fourcc)I420,framerate=(double)7.5 \n'
|
2005-07-13 10:03:04 +00:00
|
|
|
' ! videorate \n'
|
2005-07-13 16:57:14 +00:00
|
|
|
' ! ffmpegcolorspace \n'
|
2005-07-13 10:03:04 +00:00
|
|
|
' ! xvimagesink'),
|
2005-07-12 15:23:22 +00:00
|
|
|
('Sound capture via ALSA',
|
|
|
|
'alsasrc\n'
|
|
|
|
' ! audio/x-raw-int,rate=22050,depth=16,channels=1,width=16,signed=(boolean)TRUE,endianness=1234\n'
|
2005-09-05 16:31:50 +00:00
|
|
|
' ! level message=true\n'
|
2005-07-14 11:35:53 +00:00
|
|
|
' ! fakesink'),
|
|
|
|
('Streaming Ogg/Theora+Vorbis playback, tee to disk',
|
|
|
|
'gnomevfssrc location=http://gstreamer.freedesktop.org/media/small/cooldance.ogg \n'
|
|
|
|
' ! tee name=tee \n'
|
|
|
|
' tee. ! oggdemux name=demux \n'
|
|
|
|
' demux. ! queue ! theoradec ! xvimagesink \n'
|
|
|
|
' demux. ! queue ! vorbisdec ! audioconvert ! alsasink \n'
|
2005-08-03 12:32:13 +00:00
|
|
|
' tee. ! queue ! filesink location=cooldance.ogg'),
|
|
|
|
('Video test, YUV format',
|
|
|
|
'videotestsrc \n'
|
|
|
|
' ! video/x-raw-yuv,format=(fourcc)I420 \n'
|
|
|
|
' ! xvimagesink'),
|
|
|
|
('Video test, RGB format',
|
|
|
|
'videotestsrc \n'
|
|
|
|
' ! video/x-raw-rgb,red_mask=0xff00 \n'
|
2006-02-10 10:53:22 +00:00
|
|
|
' ! ffmpegcolorspace \n'
|
|
|
|
' ! ximagesink'),
|
|
|
|
('Software scaling',
|
|
|
|
'videotestsrc \n'
|
|
|
|
' ! video/x-raw-rgb,height=200,width=320 \n'
|
|
|
|
' ! videoscale method=2 \n'
|
2005-08-03 12:32:13 +00:00
|
|
|
' ! ximagesink'),
|
2005-07-14 11:35:53 +00:00
|
|
|
('Reencode Vorbis to mulaw, play via ALSA',
|
|
|
|
'filesrc location=cooldance.ogg \n'
|
|
|
|
' ! oggdemux \n'
|
|
|
|
' ! vorbisdec ! audioconvert \n'
|
2005-08-03 12:32:13 +00:00
|
|
|
' ! mulawenc ! mulawdec ! alsasink'),
|
|
|
|
('Capture DV via firewire, transcode into Ogg',
|
|
|
|
'dv1394src \n'
|
2005-09-05 16:31:50 +00:00
|
|
|
' ! dvdemux name=demux \n'
|
2005-08-03 12:32:13 +00:00
|
|
|
' ! queue \n'
|
2005-09-05 16:31:50 +00:00
|
|
|
' ! video/x-dv,systemstream=(boolean)false \n'
|
|
|
|
' ! dvdec drop-factor=2 \n'
|
2005-08-03 12:32:13 +00:00
|
|
|
' ! videorate \n'
|
|
|
|
' ! videoscale \n'
|
|
|
|
' ! video/x-raw-yuv,width=360,height=288 \n'
|
|
|
|
' ! videoscale \n'
|
|
|
|
' ! video/x-raw-yuv,width=240,height=192,framerate=10.0,format=(fourcc)YUY2 \n'
|
|
|
|
' ! ffmpegcolorspace \n'
|
|
|
|
' ! theoraenc \n'
|
|
|
|
' ! oggmux name=mux \n'
|
|
|
|
' ! filesink location=dv.ogg \n'
|
|
|
|
' \n'
|
2005-09-05 16:31:50 +00:00
|
|
|
' demux. \n'
|
2005-08-03 12:32:13 +00:00
|
|
|
' ! audio/x-raw-int \n'
|
|
|
|
' ! queue \n'
|
|
|
|
' ! audioconvert \n'
|
|
|
|
' ! vorbisenc \n'
|
|
|
|
' ! mux.'))
|
2005-07-12 15:23:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def escape(s, chars, escaper='\\'):
|
|
|
|
for c in chars:
|
|
|
|
s = s.replace(c, '%s%s' % (escaper, c))
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
|
def make_model():
|
|
|
|
m = gtk.ListStore(str, str)
|
|
|
|
for pair in data:
|
|
|
|
i = m.append()
|
|
|
|
m.set_value(i, 0, pair[0])
|
|
|
|
m.set_value(i, 1, pair[1])
|
|
|
|
return m
|
|
|
|
|
|
|
|
|
|
|
|
class Window(gtk.Window):
|
|
|
|
def __init__(self):
|
|
|
|
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
|
|
|
|
self.playing = False
|
|
|
|
self.selected_pipe = None
|
|
|
|
self.pipeline = None
|
|
|
|
self.prepare_ui()
|
|
|
|
|
|
|
|
def prepare_ui(self):
|
|
|
|
self.set_default_size(300,400)
|
|
|
|
self.set_title('GStreamer Pipeline Tester')
|
|
|
|
self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
|
|
|
self.connect('delete-event', lambda *x: gtk.main_quit())
|
|
|
|
self.set_border_width(18)
|
|
|
|
b = gtk.VBox(False, 12)
|
|
|
|
b.show()
|
|
|
|
self.add(b)
|
|
|
|
l = gtk.Label()
|
|
|
|
l.set_markup('<big><b>GStreamer Pipeline Tester</b></big>')
|
|
|
|
l.show()
|
|
|
|
b.pack_start(l, False, False, 6)
|
|
|
|
l = gtk.Label('Choose a pipeline below to run.')
|
|
|
|
l.show()
|
|
|
|
b.pack_start(l, False, False, 0)
|
|
|
|
sw = gtk.ScrolledWindow()
|
|
|
|
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
|
|
|
|
sw.set_shadow_type(gtk.SHADOW_IN)
|
|
|
|
sw.show()
|
|
|
|
b.pack_start(sw, True, True, 6)
|
|
|
|
tv = gtk.TreeView(make_model())
|
2005-07-13 10:03:04 +00:00
|
|
|
tv.set_property('can-default', False)
|
2005-07-12 15:23:22 +00:00
|
|
|
r = gtk.CellRendererText()
|
|
|
|
r.set_property('xalign', 0.5)
|
|
|
|
c = gtk.TreeViewColumn('System', r, text=0)
|
|
|
|
tv.append_column(c)
|
|
|
|
tv.set_headers_visible(False)
|
|
|
|
tv.show()
|
|
|
|
sw.add(tv)
|
2005-09-01 14:39:51 +00:00
|
|
|
ds = debugslider.DebugSlider()
|
|
|
|
ds.show()
|
|
|
|
b.pack_start(ds, False, False, 0)
|
2005-07-12 15:23:22 +00:00
|
|
|
l = gtk.Label()
|
|
|
|
l.set_selectable(True)
|
|
|
|
l.show()
|
|
|
|
b.pack_start(l, False, False, 0)
|
|
|
|
bb = gtk.HButtonBox()
|
|
|
|
bb.set_layout(gtk.BUTTONBOX_SPREAD)
|
|
|
|
bb.show()
|
|
|
|
b.pack_start(bb, False, False, 0)
|
|
|
|
bu = gtk.Button(stock=gtk.STOCK_MEDIA_PLAY)
|
2005-07-13 10:03:04 +00:00
|
|
|
bu.set_property('can-default', True)
|
2005-07-12 15:23:22 +00:00
|
|
|
bu.set_focus_on_click(False)
|
|
|
|
bu.show()
|
|
|
|
bb.pack_start(bu, True, False, 0)
|
2005-07-13 10:03:04 +00:00
|
|
|
bu.set_property('has-default', True)
|
2005-07-14 11:35:53 +00:00
|
|
|
self.button = bu
|
2005-07-12 15:23:22 +00:00
|
|
|
|
|
|
|
def on_changed(s):
|
|
|
|
m, i = s.get_selected()
|
|
|
|
if m:
|
|
|
|
self.selected_pipe = m.get_value(i, 1)
|
|
|
|
pasteable = escape(self.selected_pipe, '\n)(')
|
2005-08-16 16:50:34 +00:00
|
|
|
l.set_markup('<small><tt>%s</tt></small>' % pasteable)
|
2005-07-12 15:23:22 +00:00
|
|
|
else:
|
|
|
|
self.selected_pipe = None
|
|
|
|
l.set_markup('')
|
|
|
|
tv.get_selection().connect('changed', on_changed)
|
|
|
|
|
2005-07-14 11:35:53 +00:00
|
|
|
tv.connect('row-activated', lambda *x: self.play_toggled())
|
2005-07-13 10:03:04 +00:00
|
|
|
|
2005-07-14 11:35:53 +00:00
|
|
|
bu.connect('clicked', lambda *x: self.play_toggled())
|
2005-07-12 15:23:22 +00:00
|
|
|
|
2005-07-13 10:03:04 +00:00
|
|
|
def error(self, message, secondary=None):
|
|
|
|
m = gtk.MessageDialog(self,
|
|
|
|
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
gtk.MESSAGE_ERROR,
|
|
|
|
gtk.BUTTONS_OK,
|
|
|
|
message)
|
|
|
|
if secondary:
|
|
|
|
m.format_secondary_text(secondary)
|
|
|
|
m.run()
|
2005-07-13 15:14:51 +00:00
|
|
|
m.destroy()
|
2005-10-18 10:29:02 +00:00
|
|
|
self.stop()
|
|
|
|
|
2005-07-13 10:03:04 +00:00
|
|
|
def on_message(self, bus, message):
|
|
|
|
t = message.type
|
2005-10-18 10:29:02 +00:00
|
|
|
print message
|
2005-07-13 10:03:04 +00:00
|
|
|
if t == gst.MESSAGE_STATE_CHANGED:
|
|
|
|
pass
|
2005-07-13 15:14:51 +00:00
|
|
|
elif t == gst.MESSAGE_ERROR:
|
|
|
|
err, debug = message.parse_error()
|
|
|
|
self.error("%s" % err, debug)
|
2005-07-14 11:35:53 +00:00
|
|
|
elif t == gst.MESSAGE_EOS:
|
|
|
|
self.play_toggled()
|
2005-07-13 10:03:04 +00:00
|
|
|
else:
|
|
|
|
print '%s: %s:' % (message.src.get_path_string(),
|
|
|
|
message.type.value_nicks[1])
|
2005-07-14 11:35:53 +00:00
|
|
|
if message.structure:
|
|
|
|
print ' %s' % message.structure.to_string()
|
|
|
|
else:
|
|
|
|
print ' (no structure)'
|
2005-07-13 10:03:04 +00:00
|
|
|
return True
|
|
|
|
|
2005-07-12 15:23:22 +00:00
|
|
|
def play(self):
|
|
|
|
pipestr = self.selected_pipe
|
2005-07-13 10:03:04 +00:00
|
|
|
try:
|
|
|
|
self.set_sensitive(False)
|
|
|
|
pipeline = gst.parse_launch(pipestr)
|
|
|
|
self.set_sensitive(True)
|
|
|
|
except gobject.GError, e:
|
|
|
|
self.set_sensitive(True)
|
2005-08-03 12:32:13 +00:00
|
|
|
self.error('Could not create pipeline', str(e))
|
2005-07-13 10:03:04 +00:00
|
|
|
return False
|
2005-09-29 16:38:06 +00:00
|
|
|
|
|
|
|
bus = pipeline.get_bus()
|
|
|
|
bus.add_signal_watch()
|
|
|
|
watch_id = bus.connect('message', self.on_message)
|
2005-10-18 10:29:02 +00:00
|
|
|
self.pipeline = pipeline
|
|
|
|
self.watch_id = watch_id
|
|
|
|
pipeline.set_state(gst.STATE_PLAYING)
|
2005-07-12 15:23:22 +00:00
|
|
|
|
|
|
|
def stop(self):
|
2005-09-29 16:38:06 +00:00
|
|
|
bus = self.pipeline.get_bus()
|
|
|
|
bus.disconnect(self.watch_id)
|
|
|
|
bus.remove_signal_watch()
|
2005-07-12 15:23:22 +00:00
|
|
|
self.pipeline.set_state(gst.STATE_NULL)
|
|
|
|
self.pipeline = None
|
2005-07-13 10:03:04 +00:00
|
|
|
del self.watch_id
|
2005-07-12 15:23:22 +00:00
|
|
|
|
2005-07-14 11:35:53 +00:00
|
|
|
def play_toggled(self):
|
2005-07-12 15:23:22 +00:00
|
|
|
if self.playing:
|
|
|
|
self.stop()
|
2005-07-14 11:35:53 +00:00
|
|
|
self.button.set_label(gtk.STOCK_MEDIA_PLAY)
|
2005-07-12 15:23:22 +00:00
|
|
|
self.playing = False
|
|
|
|
else:
|
2005-10-18 10:29:02 +00:00
|
|
|
self.play()
|
|
|
|
self.playing = True
|
|
|
|
self.button.set_label(gtk.STOCK_MEDIA_STOP)
|
2005-07-12 15:23:22 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
w = Window()
|
|
|
|
w.show()
|
|
|
|
gtk.main()
|