aboutsummaryrefslogtreecommitdiff
path: root/voctocore/experiments/shmsrc.py
blob: 6fa8c30e73c8846ca7fd3e6c29b5d70f21ee2dde (plain)
  1. #!/usr/bin/python3
  2. from gi.repository import GObject, Gst
  3. class ShmSrc(Gst.Bin):
  4. def __init__(self, socket, caps):
  5. super().__init__()
  6. # Create elements
  7. self.shmsrc = Gst.ElementFactory.make('shmsrc', None)
  8. self.caps = Gst.ElementFactory.make('capsfilter', None)
  9. # Add elements to Bin
  10. self.add(self.shmsrc)
  11. self.add(self.caps)
  12. # Set properties
  13. self.shmsrc.set_property('socket-path', socket)
  14. self.shmsrc.set_property('is-live', True)
  15. self.shmsrc.set_property('do-timestamp', True)
  16. self.caps.set_property('caps', caps)
  17. self.shmsrc.link(self.caps)
  18. self.shmsrc.get_static_pad('src').add_probe(Gst.PadProbeType.BLOCK | Gst.PadProbeType.EVENT_DOWNSTREAM, self.event_probe, None)
  19. self.shmsrc.get_static_pad('src').add_probe(Gst.PadProbeType.IDLE | Gst.PadProbeType.DATA_DOWNSTREAM, self.data_probe, None)
  20. # Add Ghost Pads
  21. self.add_pad(
  22. Gst.GhostPad.new('sink', self.caps.get_static_pad('src'))
  23. )
  24. def event_probe(self, pad, info, ud):
  25. e = info.get_event()
  26. print("event_probe", e.type)
  27. if e.type == Gst.EventType.EOS:
  28. print("shmsrc reported EOS - switching to failover")
  29. return Gst.PadProbeReturn.DROP
  30. return Gst.PadProbeReturn.PASS
  31. def data_probe(self, pad, info, ud):
  32. print("shmsrc sends data - switching to shmsrc")
  33. return Gst.PadProbeReturn.PASS