4 # Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Library General Public
8 # License as published by the Free Software Foundation; either
9 # version 2 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Library General Public License for more details.
16 # You should have received a copy of the GNU Library General Public
17 # License along with this library; if not, write to the
18 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 # Boston, MA 02110-1301, USA.
22 # A test more of gst-plugins than of gst-python.
41 data = (('Video capture via V4L',
42 'v4lsrc name=source \n'
44 ' ! ffmpegcolorspace ! autovideosink'),
45 ('Video capture via V4L, fixed frame rate',
46 'v4lsrc name=source autoprobe=false autoprobe-fps=false \n'
47 ' ! video/x-raw-yuv,format=(fourcc)I420,framerate=(double)7.5 \n'
49 ' ! ffmpegcolorspace \n'
53 ' ! audio/x-raw-int,rate=22050,depth=16,channels=1,width=16,signed=(boolean)TRUE,endianness=(int)BYTE_ORDER\n'
54 ' ! level message=true\n'
56 ('Streaming Ogg/Theora+Vorbis playback, tee to disk',
57 'gnomevfssrc location=http://gstreamer.freedesktop.org/media/small/cooldance.ogg \n'
59 ' tee. ! oggdemux name=demux \n'
60 ' demux. ! queue ! theoradec ! ffmpegcolorspace ! autovideosink \n'
61 ' demux. ! queue ! vorbisdec ! audioconvert ! autoaudiosink \n'
62 ' tee. ! queue ! filesink location=/tmp/cooldance.ogg'),
63 ('Video test, YUV format',
65 ' ! video/x-raw-yuv,format=(fourcc)I420 \n'
66 ' ! ffmpegcolorspace ! autovideosink'),
67 ('Video test, RGB format',
69 ' ! video/x-raw-rgb,red_mask=0xff00 \n'
70 ' ! ffmpegcolorspace \n'
74 ' ! video/x-raw-rgb,height=200,width=320 \n'
75 ' ! videoscale method=2 \n'
76 ' ! ffmpegcolorspace ! autovideosink'),
77 ('Reencode Vorbis to mulaw, play',
78 'filesrc location=/tmp/cooldance.ogg \n'
80 ' ! vorbisdec ! audioconvert \n'
81 ' ! mulawenc ! mulawdec ! autoaudiosink'),
82 ('Capture DV via firewire, transcode into Ogg',
84 ' ! dvdemux name=demux \n'
86 ' ! video/x-dv,systemstream=(boolean)false \n'
87 ' ! dvdec drop-factor=2 \n'
90 ' ! video/x-raw-yuv,width=360,height=288 \n'
92 ' ! video/x-raw-yuv,width=240,height=192,framerate=10.0,format=(fourcc)YUY2 \n'
93 ' ! ffmpegcolorspace \n'
95 ' ! oggmux name=mux \n'
96 ' ! filesink location=/tmp/dv.ogg \n'
99 ' ! audio/x-raw-int \n'
106 def escape(s, chars, escaper='\\'):
108 s = s.replace(c, '%s%s' % (escaper, c))
113 m = gtk.ListStore(str, str)
116 m.set_value(i, 0, pair[0])
117 m.set_value(i, 1, pair[1])
121 class Window(gtk.Window):
123 gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
125 self.selected_pipe = None
129 def prepare_ui(self):
130 self.set_default_size(300,400)
131 self.set_title('GStreamer Pipeline Tester')
132 self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
133 self.connect('delete-event', lambda *x: gtk.main_quit())
134 self.set_border_width(18)
135 b = gtk.VBox(False, 12)
139 l.set_markup('<big><b>GStreamer Pipeline Tester</b></big>')
141 b.pack_start(l, False, False, 6)
142 l = gtk.Label('Choose a pipeline below to run.')
144 b.pack_start(l, False, False, 0)
145 sw = gtk.ScrolledWindow()
146 sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
147 sw.set_shadow_type(gtk.SHADOW_IN)
149 b.pack_start(sw, True, True, 6)
150 tv = gtk.TreeView(make_model())
151 tv.set_property('can-default', False)
152 r = gtk.CellRendererText()
153 r.set_property('xalign', 0.5)
154 c = gtk.TreeViewColumn('System', r, text=0)
156 tv.set_headers_visible(False)
159 ds = debugslider.DebugSlider()
161 b.pack_start(ds, False, False, 0)
163 l.set_selectable(True)
165 b.pack_start(l, False, False, 0)
166 bb = gtk.HButtonBox()
167 bb.set_layout(gtk.BUTTONBOX_SPREAD)
169 b.pack_start(bb, False, False, 0)
170 bu = gtk.Button(stock=gtk.STOCK_MEDIA_PLAY)
171 bu.set_property('can-default', True)
172 bu.set_focus_on_click(False)
174 bb.pack_start(bu, True, False, 0)
175 bu.set_property('has-default', True)
179 m, i = s.get_selected()
181 self.selected_pipe = m.get_value(i, 1)
182 pasteable = escape(self.selected_pipe, '\n)(')
183 l.set_markup('<small><tt>%s</tt></small>' % pasteable)
185 self.selected_pipe = None
187 tv.get_selection().connect('changed', on_changed)
189 tv.connect('row-activated', lambda *x: self.play_toggled())
191 bu.connect('clicked', lambda *x: self.play_toggled())
193 def error(self, message, secondary=None):
194 m = gtk.MessageDialog(self,
195 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
200 m.format_secondary_text(secondary)
205 def on_message(self, bus, message):
208 if t == gst.MESSAGE_STATE_CHANGED:
210 elif t == gst.MESSAGE_ERROR:
211 err, debug = message.parse_error()
212 self.error("%s" % err, debug)
213 elif t == gst.MESSAGE_EOS:
216 print '%s: %s:' % (message.src.get_path_string(),
217 message.type.value_nicks[1])
218 if message.structure:
219 print ' %s' % message.structure.to_string()
221 print ' (no structure)'
225 pipestr = self.selected_pipe
227 self.set_sensitive(False)
228 pipeline = gst.parse_launch(pipestr)
229 self.set_sensitive(True)
230 except gobject.GError, e:
231 self.set_sensitive(True)
232 self.error('Could not create pipeline', str(e))
235 bus = pipeline.get_bus()
236 bus.add_signal_watch()
237 watch_id = bus.connect('message', self.on_message)
238 self.pipeline = pipeline
239 self.watch_id = watch_id
240 pipeline.set_state(gst.STATE_PLAYING)
243 bus = self.pipeline.get_bus()
244 bus.disconnect(self.watch_id)
245 bus.remove_signal_watch()
246 self.pipeline.set_state(gst.STATE_NULL)
250 def play_toggled(self):
253 self.button.set_label(gtk.STOCK_MEDIA_PLAY)
258 self.button.set_label(gtk.STOCK_MEDIA_STOP)
260 if __name__ == '__main__':