9 # VideoWidget taken from play.py in gst-python examples
10 class VideoWidget(gtk.DrawingArea):
12 gtk.DrawingArea.__init__(self)
14 self.unset_flags(gtk.DOUBLE_BUFFERED)
16 def do_expose_event(self, event):
18 self.imagesink.expose()
23 def set_sink(self, sink):
24 assert self.window.xid
26 self.imagesink.set_xwindow_id(self.window.xid)
31 # hildon has one program instance per app, so get instance
32 self.p = hildon.Program.get_instance()
33 # set name of application: this shows in titlebar
34 gtk.set_application_name("Maemo GStreamer VideoTest")
35 # stackable window in case we want more windows in future in app
36 self.w = hildon.StackableWindow()
38 self.video_widget = VideoWidget()
39 # video widget we want to expand to size
40 box.pack_start(self.video_widget, True, True, 0)
41 # a button finger height to play/pause
42 self.button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
43 hildon.BUTTON_ARRANGEMENT_VERTICAL, title="Pause")
44 self.button.connect_after("clicked", self.on_button_clicked)
45 # don't want button to expand or fill, just stay finger height
46 box.pack_start(self.button, False, False, 0)
48 self.w.connect("delete-event", gtk.main_quit)
49 self.p.add_window(self.w)
51 self.start_streaming()
53 def start_streaming(self):
54 # we use ximagesink solely for screenshotting ability
55 # less cpu usage would happen with videotestsrc ! xvimagesink
57 gst.parse_launch("videotestsrc ! videoscale ! ximagesink")
58 bus = self.pipeline.get_bus()
59 # need to connect to sync message handler so we get the sink to be
60 # embedded at the right time and not have a temporary new window
61 bus.enable_sync_message_emission()
62 bus.add_signal_watch()
63 bus.connect("sync-message::element", self.on_sync_message)
64 bus.connect("message", self.on_message)
65 self.pipeline.set_state(gst.STATE_PLAYING)
67 def on_sync_message(self, bus, message):
68 if message.structure is None:
70 if message.structure.get_name() == 'prepare-xwindow-id':
71 # all this is needed to sync with the X server before giving the
73 gtk.gdk.threads_enter()
74 gtk.gdk.display_get_default().sync()
75 self.video_widget.set_sink(message.src)
76 message.src.set_property("force-aspect-ratio", True)
77 gtk.gdk.threads_leave()
79 def on_message(self, bus, message):
80 if message.type == gst.MESSAGE_ERROR:
81 err, debug = message.parse_error()
82 hildon.hildon_banner_show_information(self.w, '',
85 def on_button_clicked(self, widget):
86 success, state, pending = self.pipeline.get_state(1)
87 # do not listen if in middle of state change
89 if state == gst.STATE_PLAYING:
90 self.pipeline.set_state(gst.STATE_PAUSED)
91 self.button.set_label("Play")
93 self.pipeline.set_state(gst.STATE_PLAYING)
94 self.button.set_label("Pause")
100 if __name__ == '__main__':