summaryrefslogtreecommitdiff
path: root/voctocore/experiments/binlinktest.py
blob: 690daaa5d02d5fd9edf41733b8702f5c52f9abbd (plain)
  1. #!/usr/bin/python3
  2. import gi, time
  3. gi.require_version('Gst', '1.0')
  4. from gi.repository import GLib, Gst, GObject
  5. GObject.threads_init()
  6. Gst.init(None)
  7. class SrcBin(Gst.Bin):
  8. def __init__(self):
  9. super().__init__()
  10. self.src = Gst.ElementFactory.make('videotestsrc', 'src')
  11. self.add(self.src)
  12. self.add_pad(
  13. Gst.GhostPad.new('src', self.src.get_static_pad('src'))
  14. )
  15. class SinkBin(Gst.Bin):
  16. def __init__(self):
  17. super().__init__()
  18. self.sink = Gst.ElementFactory.make('autovideosink', 'sink')
  19. self.add(self.sink)
  20. self.add_pad(
  21. Gst.GhostPad.new('sink', self.sink.get_static_pad('sink'))
  22. )
  23. class MixBin(Gst.Bin):
  24. def __init__(self):
  25. super().__init__()
  26. self.mix = Gst.ElementFactory.make('videomixer', 'src')
  27. self.add(self.mix)
  28. self.add_pad(
  29. Gst.GhostPad.new('src', self.mix.get_static_pad('src'))
  30. )
  31. def add_src(self, src):
  32. sinkpad = self.mix.get_request_pad('sink_%u')
  33. sinkpad.set_property('alpha', 0.75)
  34. srcpad = src.get_static_pad('src')
  35. # works
  36. #print(src.link(self.mix)) # True
  37. # doesn't
  38. print(srcpad.link(sinkpad)) # Error => GST_PAD_LINK_WRONG_HIERARCHY
  39. class Example:
  40. def __init__(self):
  41. self.mainloop = GObject.MainLoop()
  42. self.pipeline = Gst.Pipeline()
  43. self.src = SrcBin()
  44. self.sink = SinkBin()
  45. self.mix = MixBin()
  46. # Add elements to pipeline
  47. self.pipeline.add(self.src)
  48. self.pipeline.add(self.sink)
  49. self.pipeline.add(self.mix)
  50. self.mix.add_src(self.src)
  51. self.mix.link(self.sink)
  52. def run(self):
  53. self.pipeline.set_state(Gst.State.PLAYING)
  54. self.mainloop.run()
  55. def kill(self):
  56. self.pipeline.set_state(Gst.State.NULL)
  57. self.mainloop.quit()
  58. example = Example()
  59. example.run()