summaryrefslogtreecommitdiff
path: root/voctocore/experiments/failovertest.py
blob: 31491971107dcf04534ac1b3f287cc311ffd7848 (plain)
  1. #!/usr/bin/python3
  2. import gi
  3. import signal
  4. from termcolor import colored
  5. # import GStreamer and GTK-Helper classes
  6. gi.require_version('Gst', '1.0')
  7. from gi.repository import GLib, Gst, Gtk, GObject
  8. # init GObject before importing local classes
  9. GObject.threads_init()
  10. Gst.init(None)
  11. loop = GLib.MainLoop()
  12. def busfunc(bus, message):
  13. print(colored(message.src.get_name(), 'green'), message.type, message)
  14. if message.type == Gst.MessageType.ERROR:
  15. (err, debug) = message.parse_error()
  16. print(colored(err, 'red'))
  17. print(colored(debug, 'yellow'))
  18. if message.src.get_name() == 'http':
  19. failover = p.get_by_name('failover')
  20. failover.set_property('active-pad', failover.get_static_pad('sink_1'))
  21. # make killable by ctrl-c
  22. signal.signal(signal.SIGINT, signal.SIG_DFL)
  23. print("parse_launch")
  24. p = Gst.parse_launch("""
  25. input-selector name=failover ! autovideosink
  26. videotestsrc ! video/x-raw,width=1280,height=720 ! failover.sink_1
  27. souphttpsrc name=http location="http://localhost/~peter/ED_1280.avi" ! decodebin ! failover.sink_0
  28. """)
  29. print("add_watch")
  30. bus = p.get_bus()
  31. bus.add_signal_watch()
  32. bus.connect('message', busfunc)
  33. # print("add_watch")
  34. # httpbus = p.get_by_name('http').get_bus()
  35. # httpbus.add_watch(0, busfunc, None)
  36. print("set_state(PLAYING)")
  37. p.set_state(Gst.State.PLAYING)
  38. loop.run()