Created
November 28, 2011 16:18
-
-
Save shamun/1400946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, os | |
import pygtk, gtk, gobject | |
import pygst | |
pygst.require("0.10") | |
import gst | |
import time | |
class GTK_Main: | |
def __init__(self): | |
window = gtk.Window(gtk.WINDOW_TOPLEVEL) | |
window.set_title("Input-selector test") | |
window.set_default_size(300, 100) | |
window.connect("destroy", gtk.main_quit, "WM destroy") | |
vbox = gtk.VBox() | |
window.add(vbox) | |
self.movie_window = gtk.DrawingArea() | |
vbox.add(self.movie_window) | |
hbox = gtk.HBox() | |
vbox.pack_start(hbox, False) | |
hbox.set_border_width(10) | |
hbox.pack_start(gtk.Label()) | |
self.button = gtk.Button("1) Press this (After that press Start )") | |
self.button.connect("clicked", self.start_stop) | |
hbox.pack_start(self.button, False) | |
self.button2 = gtk.Button("2) Press Switch (to see if you can seamlessly view the switching)") | |
self.button2.connect("clicked", self.exit) | |
hbox.pack_start(self.button2, False) | |
hbox.add(gtk.Label()) | |
window.show_all() | |
self.mySwitch = "sink1" | |
self.player = gst.parse_launch ("multifilesrc location=/var/tmp/wall1.jpg ! decodebin2 ! queue ! s.sink0 videotestsrc pattern=18 ! videobalance name=vb ! videoscale ! video/x-raw-yuv, width=800,height=600 ! queue ! s.sink1 input-selector name=s ! tee name=t ! queue ! xvimagesink sync=false name=gl t. ! queue ! fakesink") | |
#self.player = gst.parse_launch ("multifilesrc location=/var/tmp/wall1.jpg ! decodebin2 ! queue ! s.sink0 videotestsrc pattern=18 ! videobalance name=vb ! videoscale ! video/x-raw-yuv, width=800,height=600 ! queue ! s.sink1 input-selector name=s ! tee name=t ! queue ! xvimagesink sync=false name=gl t. ! queue ! ffmpegcolorspace ! x264enc tune=zerolatency bitrate=1000 ! rtph264pay ! udpsink host=127.0.0.1 port=2222 name=udpsink0") | |
bus = self.player.get_bus() | |
bus.add_signal_watch() | |
bus.enable_sync_message_emission() | |
def start_stop(self, w): | |
if self.button.get_label() == "Start": | |
self.button.set_label("Stop") | |
self.player.set_state(gst.STATE_PLAYING) | |
else: | |
self.player.set_state(gst.STATE_NULL) | |
self.button.set_label("Start") | |
def exit(self, widget, data=None): | |
while True: | |
print "Switching to: " + self.mySwitch; | |
sel = self.player.get_by_name("s") | |
sel.emit('switch', | |
sel.get_static_pad(self.mySwitch), | |
sel.emit('block'), | |
sel.get_static_pad(self.mySwitch).get_property('running-time') ) | |
if self.mySwitch.startswith("sink0"): | |
self.mySwitch = "sink1" | |
else: | |
self.mySwitch = "sink0" | |
time.sleep(5) | |
GTK_Main() | |
gtk.gdk.threads_init() | |
gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment