#!/usr/bin/env python import sys, os import pygtk, gtk, gobject import pygst pygst.require("0.10") import gst class Player: def __init__(self, drawing_area, pipe_spec): self.drawing_area = drawing_area # Set up the gstreamer pipeline self.player = gst.parse_launch (pipe_spec) bus = self.player.get_bus() bus.add_signal_watch() bus.enable_sync_message_emission() bus.connect("message", self.on_message) bus.connect("sync-message::element", self.on_sync_message) self.player.set_state(gst.STATE_PLAYING) def set_state(self, state): self.player.set_state(state) def on_message(self, bus, message): t = message.type print "## message: t=%s m=%s" % (t, message) if t == gst.MESSAGE_EOS: self.player.set_state(gst.STATE_NULL) elif t == gst.MESSAGE_ERROR: err, debug = message.parse_error() print "## Error: %s" % err, debug self.player.set_state(gst.STATE_NULL) def on_sync_message(self, bus, message): print "## SYNC: bus=%s msg=%s" % (bus, message) if message.structure is None: return message_name = message.structure.get_name() print "## : name=%s" % message_name if message_name == "prepare-xwindow-id": # Assign the viewport imagesink = message.src print "## : src=%s" % imagesink imagesink.set_property("force-aspect-ratio", True) imagesink.set_xwindow_id(self.drawing_area.window.xid) class GTK_Main: def __init__(self): window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.set_title("Webcam-Viewer") window.set_default_size(500, 400) window.connect("destroy", gtk.main_quit, "WM destroy") vbox = gtk.VBox() window.add(vbox) self.m0 = gtk.DrawingArea() self.m1 = gtk.DrawingArea() self.m2 = gtk.DrawingArea() self.m3 = gtk.DrawingArea() #self.m4 = gtk.Arrow(gtk.ARROW_UP, 0) ## DrawingArea() #self.m5 = gtk.Arrow(gtk.ARROW_UP, 0) ## DrawingArea() # strick lr = gtk.HBox() lhs = gtk.VBox() rhs = gtk.VBox() lhs.add(self.m0) lhs.pack_start(self.m1) rhs.add(self.m2) rhs.add(self.m3) lr.pack_start(lhs) lr.pack_start(rhs) vbox.add(lr) #vbox.add(self.m0) hbox = gtk.HBox() vbox.pack_start(hbox, False) hbox.set_border_width(10) hbox.pack_start(gtk.Label()) self.button = gtk.Button("Stop") self.button.connect("clicked", self.start_stop) hbox.pack_start(self.button, False) self.button2 = gtk.Button("Quit") self.button2.connect("clicked", self.exit) hbox.pack_start(self.button2, False) hbox.add(gtk.Label()) window.show_all() # Set up the gstreamer pipeline #self.player = Player(self.m0, "v4l2src ! autovideosink") self.p0 = Player(self.m0, "udpsrc port=9001 buffer-size=65536 ! smokedec ! autovideosink") self.p1 = Player(self.m1, "udpsrc port=9002 buffer-size=65536 ! smokedec ! autovideosink") self.p2 = Player(self.m2, "udpsrc port=9003 buffer-size=65536 ! smokedec ! autovideosink") self.p3 = Player(self.m3, "udpsrc port=9004 buffer-size=65536 ! smokedec ! autovideosink") def start_stop(self, w): print "## start/stop" if self.button.get_label() == "Start": self.button.set_label("Stop") self.p0.set_state(gst.STATE_PLAYING) else: self.p0.set_state(gst.STATE_NULL) self.button.set_label("Start") def exit(self, widget, data=None): print "## exit" gtk.main_quit() GTK_Main() gtk.gdk.threads_init() gtk.main()