diff options
Diffstat (limited to 'voctocore')
-rw-r--r-- | voctocore/experiments/shmsrc.py | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/voctocore/experiments/shmsrc.py b/voctocore/experiments/shmsrc.py index 6fa8c30..3fd400d 100644 --- a/voctocore/experiments/shmsrc.py +++ b/voctocore/experiments/shmsrc.py @@ -7,25 +7,45 @@ class ShmSrc(Gst.Bin): # Create elements self.shmsrc = Gst.ElementFactory.make('shmsrc', None) - self.caps = Gst.ElementFactory.make('capsfilter', None) + self.caps1 = Gst.ElementFactory.make('capsfilter', None) + self.caps2 = Gst.ElementFactory.make('capsfilter', None) + self.switch = Gst.ElementFactory.make('input-selector', None) + self.secondsrc = Gst.ElementFactory.make('videotestsrc', None) # Add elements to Bin self.add(self.shmsrc) - self.add(self.caps) + self.add(self.caps1) + self.add(self.caps2) + self.add(self.switch) + self.add(self.secondsrc) + + # Get Switcher-Pads + self.firstpad = self.switch.get_request_pad('sink_%u') + self.secondpad = self.switch.get_request_pad('sink_%u') # Set properties self.shmsrc.set_property('socket-path', socket) self.shmsrc.set_property('is-live', True) self.shmsrc.set_property('do-timestamp', True) + self.caps1.set_property('caps', caps) + self.caps2.set_property('caps', caps) + self.switch.set_property('active-pad', self.firstpad) + self.secondsrc.set_property('pattern', 'snow') + + # Link elements + self.shmsrc.link(self.caps1) + self.caps1.get_static_pad('src').link(self.firstpad) + + self.secondsrc.link(self.caps2) + self.caps2.get_static_pad('src').link(self.secondpad) - self.caps.set_property('caps', caps) - self.shmsrc.link(self.caps) + # Install pad probes self.shmsrc.get_static_pad('src').add_probe(Gst.PadProbeType.BLOCK | Gst.PadProbeType.EVENT_DOWNSTREAM, self.event_probe, None) self.shmsrc.get_static_pad('src').add_probe(Gst.PadProbeType.IDLE | Gst.PadProbeType.DATA_DOWNSTREAM, self.data_probe, None) # Add Ghost Pads self.add_pad( - Gst.GhostPad.new('sink', self.caps.get_static_pad('src')) + Gst.GhostPad.new('sink', self.switch.get_static_pad('src')) ) def event_probe(self, pad, info, ud): @@ -33,9 +53,11 @@ class ShmSrc(Gst.Bin): print("event_probe", e.type) if e.type == Gst.EventType.EOS: print("shmsrc reported EOS - switching to failover") + self.switch.set_property('active-pad', self.secondpad) return Gst.PadProbeReturn.DROP return Gst.PadProbeReturn.PASS def data_probe(self, pad, info, ud): print("shmsrc sends data - switching to shmsrc") + # todo: add a timeout of 2*framerate (ie 2*1/25 seconds) return Gst.PadProbeReturn.PASS |