dd99993b96d8ee0318eb381ab7ce2c1f58157e6f
2 # Let's see if we can get a viewport working, building on code from example2.py
3 # Some final info and updated code stolen from
4 # http://bazaar.launchpad.net/~jderose/+junk/gst-examples/view/head:/video-player-1.0
6 # GdkX11 to get access to xid, GstVideo to get access to set_window_handle
7 from gi
.repository
import Gtk
, Gst
, GdkX11
, GstVideo
13 # Create gui bits and bobs
15 self
.mainwindow
= Gtk
.Builder()
16 self
.mainwindow
.add_from_file("example3.glade")
19 "on_play_clicked" : self
.OnPlay
,
20 "on_stop_clicked" : self
.OnStop
,
21 "on_quit_clicked" : self
.OnQuit
,
24 self
.mainwindow
.connect_signals(signals
)
26 # Create GStreamer bits and bobs
28 # Initiate the pipeline
30 self
.pipeline
= Gst
.Pipeline("mypipeline")
32 # Add a videotestsrc element to the pipeline, set it to pattern "snow."
33 self
.videotestsrc
= Gst
.ElementFactory
.make("videotestsrc", "videosource")
34 self
.videotestsrc
.set_property("pattern", "snow")
35 self
.pipeline
.add(self
.videotestsrc
)
37 # Add a capsfilter that we want to apply to our videotestsrc
38 self
.videotestcaps
= Gst
.ElementFactory
.make("capsfilter", "videotestcaps")
39 self
.videotestcaps
.set_property("caps",Gst
.Caps
.from_string("video/x-raw,width=640,height=480"))
40 self
.pipeline
.add(self
.videotestcaps
)
42 # Link the capsfilter to the videotestsrc
43 self
.videotestsrc
.link(self
.videotestcaps
)
45 # Add a videosink element to the pipeline
46 self
.videosink
= Gst
.ElementFactory
.make("autovideosink", "videosink")
47 self
.pipeline
.add(self
.videosink
)
49 # Link the already linked videotestcaps to the sink
50 self
.videotestcaps
.link(self
.videosink
)
52 # Set up a bus to our pipeline to get notified when the video is ready
53 self
.bus
= self
.pipeline
.get_bus()
54 self
.bus
.enable_sync_message_emission()
55 self
.bus
.connect("sync-message::element", self
.OnSyncElement
)
57 # Summon the window and connect the window's close button to quit
58 self
.window
= self
.mainwindow
.get_object("mainwindow")
59 self
.window
.connect("delete-event", Gtk
.main_quit
)
60 self
.window
.show_all()
62 # Get window ID of the viewport widget from the GUI
63 self
.win_id
= self
.mainwindow
.get_object("viewport").get_window().get_xid()
66 # When we get a message that video is ready to display, set the
67 # correct window id to hook it to our viewport
68 def OnSyncElement(self
, bus
, message
):
69 if message
.get_structure().get_name() == "prepare-window-handle":
70 print "prepare-window-handle"
71 message
.src
.set_window_handle(self
.win_id
)
73 def OnPlay(self
, widget
):
75 self
.pipeline
.set_state(Gst
.State
.PLAYING
)
77 def OnStop(self
, widget
):
79 self
.pipeline
.set_state(Gst
.State
.READY
)
81 def OnQuit(self
, widget
):
85 # Workaround to get Ctrl+C to terminate from command line
86 # ref: https://bugzilla.gnome.org/show_bug.cgi?id=622084#c12
87 signal
.signal(signal
.SIGINT
, signal
.SIG_DFL
)