aboutsummaryrefslogtreecommitdiff
path: root/voctogui/voctogui.py
blob: d6bf5b614e52c992946f2df85ccad8888b9a0b07 (plain)
  1. #!/usr/bin/env python3
  2. import gi, signal, logging, sys, os
  3. # import GStreamer and GLib-Helper classes
  4. gi.require_version('Gtk', '3.0')
  5. gi.require_version('Gst', '1.0')
  6. gi.require_version('GdkX11', '3.0')
  7. gi.require_version('GstVideo', '1.0')
  8. from gi.repository import Gtk, Gdk, Gst, GObject, GdkX11, GstVideo
  9. # check min-version
  10. minGst = (1, 5)
  11. minPy = (3, 0)
  12. Gst.init([])
  13. if Gst.version() < minGst:
  14. raise Exception("GStreamer version", Gst.version(), 'is too old, at least', minGst, 'is required')
  15. if sys.version_info < minPy:
  16. raise Exception("Python version", sys.version_info, 'is too old, at least', minPy, 'is required')
  17. # init GObject & Co. before importing local classes
  18. GObject.threads_init()
  19. Gdk.init([])
  20. Gtk.init([])
  21. # import local classes
  22. from lib.args import Args
  23. from lib.config import Config
  24. from lib.ui import Ui
  25. from lib.loghandler import LogHandler
  26. import lib.connection as Connection
  27. import lib.clock as ClockManager
  28. # main class
  29. class Voctogui(object):
  30. def __init__(self):
  31. self.log = logging.getLogger('Voctogui')
  32. # Uf a UI-File was specified on the Command-Line, load it
  33. if Args.ui_file:
  34. self.log.info('loading ui-file from file specified on command-line: %s', self.options.ui_file)
  35. self.ui = Ui(Args.ui_file)
  36. else:
  37. # Paths to look for the gst-switch UI-File
  38. paths = [
  39. os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ui/voctogui.ui'),
  40. '/usr/lib/voctogui/ui/voctogui.ui'
  41. ]
  42. # Look for a gst-switch UI-File and load it
  43. for path in paths:
  44. self.log.debug('trying to load ui-file from file %s', path)
  45. if os.path.isfile(path):
  46. self.log.info('loading ui-file from file %s', path)
  47. self.ui = Ui(path)
  48. break
  49. if self.ui is None:
  50. raise Exception("Can't find any .ui-Files to use (searched %s)" % (', '.join(paths)))
  51. self.ui.setup()
  52. def run(self):
  53. self.log.info('setting UI visible')
  54. self.ui.show()
  55. try:
  56. self.log.info('running Gtk-MainLoop')
  57. Gtk.main()
  58. self.log.info('Gtk-MainLoop ended')
  59. except KeyboardInterrupt:
  60. self.log.info('Terminated via Ctrl-C')
  61. def quit(self):
  62. self.log.info('quitting Gtk-MainLoop')
  63. Gtk.main_quit()
  64. # run mainclass
  65. def main():
  66. # configure logging
  67. docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
  68. handler = LogHandler(docolor, Args.timestamp)
  69. logging.root.addHandler(handler)
  70. if Args.verbose >= 2:
  71. level = logging.DEBUG
  72. elif Args.verbose == 1:
  73. level = logging.INFO
  74. else:
  75. level = logging.WARNING
  76. logging.root.setLevel(level)
  77. # make killable by ctrl-c
  78. logging.debug('setting SIGINT handler')
  79. signal.signal(signal.SIGINT, signal.SIG_DFL)
  80. logging.info('Python Version: %s', sys.version_info)
  81. logging.info('GStreamer Version: %s', Gst.version())
  82. # establish a synchronus connection to server
  83. Connection.establish(
  84. Config.get('server', 'host'))
  85. # fetch config from server
  86. Config.fetchServerConfig()
  87. # Warn when connecting to a non-local core without preview-encoders enabled
  88. # the list-comparison is not complete (one could use a local hostname or the local system ip)
  89. # but it's only here to warn that one might be making a mistake
  90. use_previews = Config.getboolean('previews', 'enabled') and Config.getboolean('previews', 'use')
  91. looks_like_localhost = Config.get('server', 'host') in ['::1', '127.0.0.1', 'localhost']
  92. if not use_previews and not looks_like_localhost:
  93. logging.warn(
  94. 'Connecting to `%s` (which looks like a remote host) might not work without enabeling '
  95. 'the preview encoders (set `[previews] enabled=true` on the core) or it might saturate '
  96. 'your ethernet link between the two machines.',
  97. Config.get('server', 'host')
  98. )
  99. # obtain network-clock
  100. ClockManager.obtainClock(Connection.ip)
  101. # switch connection to nonblocking, event-driven mode
  102. Connection.enterNonblockingMode()
  103. # init main-class and main-loop
  104. # (this binds all event-hander on the Connection)
  105. logging.debug('initializing Voctogui')
  106. voctogui = Voctogui()
  107. # start the Mainloop and show the Window
  108. logging.debug('running Voctogui')
  109. voctogui.run()
  110. if __name__ == '__main__':
  111. main()