d203020205698866099d8f4e9e53218ee18e4684
2 # Let's see if we can get a viewport AND audio working, combining ex. 2 and 3
4 # GdkX11 to get access to xid, GstVideo to get access to set_window_handle
5 from gi
.repository
import Gtk
, Gst
, GdkX11
, GstVideo
11 # Create gui bits and bobs
13 self
.mainwindow
= Gtk
.Builder()
14 self
.mainwindow
.add_from_file("example3.glade")
17 "on_play_clicked" : self
.OnPlay
,
18 "on_stop_clicked" : self
.OnStop
,
19 "on_quit_clicked" : self
.OnQuit
,
22 self
.mainwindow
.connect_signals(signals
)
24 # Create GStreamer bits and bobs
26 # Initiate the pipeline
28 self
.pipeline
= Gst
.Pipeline("mypipeline")
30 # Add a videotestsrc element to the pipeline, set it to pattern "snow."
31 self
.videotestsrc
= Gst
.ElementFactory
.make("videotestsrc", "videosource")
32 self
.videotestsrc
.set_property("pattern", "snow")
33 self
.pipeline
.add(self
.videotestsrc
)
35 # Add a capsfilter that we want to apply to our videotestsrc
36 self
.videotestcaps
= Gst
.ElementFactory
.make("capsfilter", "videotestcaps")
37 self
.videotestcaps
.set_property("caps",Gst
.Caps
.from_string("video/x-raw,width=640,height=480"))
38 self
.pipeline
.add(self
.videotestcaps
)
40 # Link the capsfilter to the videotestsrc
41 self
.videotestsrc
.link(self
.videotestcaps
)
43 # Add a videosink element to the pipeline
44 self
.videosink
= Gst
.ElementFactory
.make("autovideosink", "videosink")
45 self
.pipeline
.add(self
.videosink
)
47 # Link the already linked videotestcaps to the sink
48 self
.videotestcaps
.link(self
.videosink
)
50 # Add an audiotestsrc element to the pipeline
51 self
.audiotestsrc
= Gst
.ElementFactory
.make("audiotestsrc", "audio")
52 self
.audiotestsrc
.set_property("freq", 800)
53 self
.pipeline
.add(self
.audiotestsrc
)
55 # Add a pulsesink element to the pipeline
56 self
.pulsesink
= Gst
.ElementFactory
.make("pulsesink", "sink")
57 self
.pipeline
.add(self
.pulsesink
)
59 # Link the two elements together
60 self
.audiotestsrc
.link(self
.pulsesink
)
62 # Set up a bus to our pipeline to get notified when the video is ready
63 self
.bus
= self
.pipeline
.get_bus()
64 self
.bus
.enable_sync_message_emission()
65 self
.bus
.connect("sync-message::element", self
.OnSyncElement
)
67 # Summon the window and connect the window's close button to quit
68 self
.window
= self
.mainwindow
.get_object("mainwindow")
69 self
.window
.connect("delete-event", Gtk
.main_quit
)
70 self
.window
.show_all()
72 # Get window ID of the viewport widget from the GUI
73 self
.win_id
= self
.mainwindow
.get_object("viewport").get_window().get_xid()
76 # When we get a message that video is ready to display, set the
77 # correct window id to hook it to our viewport
78 def OnSyncElement(self
, bus
, message
):
79 if message
.get_structure().get_name() == "prepare-window-handle":
80 print "prepare-window-handle"
81 message
.src
.set_window_handle(self
.win_id
)
83 def OnPlay(self
, widget
):
85 self
.pipeline
.set_state(Gst
.State
.PLAYING
)
87 def OnStop(self
, widget
):
89 self
.pipeline
.set_state(Gst
.State
.READY
)
91 def OnQuit(self
, widget
):
95 # Workaround to get Ctrl+C to terminate from command line
96 # ref: https://bugzilla.gnome.org/show_bug.cgi?id=622084#c12
97 signal
.signal(signal
.SIGINT
, signal
.SIG_DFL
)