MCPcopy Create free account
hub / github.com/GStreamer/gst-python / SwitchTest

Class SwitchTest

old_examples/switch.py:20–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18gtk.gdk.threads_init()
19
20class SwitchTest:
21 def __init__(self, videowidget):
22 self.playing = False
23 pipestr = ('videotestsrc pattern=0 ! queue ! s.sink0'
24 ' videotestsrc pattern=1 ! queue ! s.sink1'
25 ' input-selector name=s ! autovideosink')
26 self.pipeline = gst.parse_launch(pipestr)
27 self.videowidget = videowidget
28
29 bus = self.pipeline.get_bus()
30 bus.enable_sync_message_emission()
31 bus.add_signal_watch()
32 bus.connect('sync-message::element', self.on_sync_message)
33 bus.connect('message', self.on_message)
34
35 def on_sync_message(self, bus, message):
36 if message.structure is None:
37 return
38 if message.structure.get_name() == 'prepare-xwindow-id':
39 # Sync with the X server before giving the X-id to the sink
40 gtk.gdk.threads_enter()
41 gtk.gdk.display_get_default().sync()
42 self.videowidget.set_sink(message.src)
43 message.src.set_property('force-aspect-ratio', True)
44 gtk.gdk.threads_leave()
45
46 def on_message(self, bus, message):
47 t = message.type
48 if t == gst.MESSAGE_ERROR:
49 err, debug = message.parse_error()
50 print "Error: %s" % err, debug
51 if self.on_eos:
52 self.on_eos()
53 self.playing = False
54 elif t == gst.MESSAGE_EOS:
55 if self.on_eos:
56 self.on_eos()
57 self.playing = False
58
59 def play(self):
60 self.playing = True
61 gst.info("playing player")
62 self.pipeline.set_state(gst.STATE_PLAYING)
63
64 def stop(self):
65 self.pipeline.set_state(gst.STATE_NULL)
66 gst.info("stopped player")
67 self.playing = False
68
69 def get_state(self, timeout=1):
70 return self.pipeline.get_state(timeout=timeout)
71
72 def is_playing(self):
73 return self.playing
74
75 def switch(self, padname):
76 switch = self.pipeline.get_by_name('s')
77 stop_time = switch.emit('block')

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected