summaryrefslogtreecommitdiff
path: root/voctocore/voctocore.py
blob: 43826d1d3b3271197612c25d0e54d47d1327f705 (plain)
  1. #!/usr/bin/python3
  2. import gi, signal, logging, sys
  3. # import GStreamer and GLib-Helper classes
  4. gi.require_version('Gst', '1.0')
  5. from gi.repository import Gtk, Gdk, Gst, GObject, GdkX11, GstVideo
  6. # check min-version
  7. minGst = (1, 4)
  8. minPy = (3, 0)
  9. if Gst.version() < minGst:
  10. raise Exception("GStreamer version", Gst.version(), 'is too old, at least', minGst, 'is required')
  11. if sys.version_info < minPy:
  12. raise Exception("Python version", sys.version_info, 'is too old, at least', minPy, 'is required')
  13. # init GObject & Co. before importing local classes
  14. GObject.threads_init()
  15. Gdk.init([])
  16. Gtk.init([])
  17. Gst.init([])
  18. # import local classes
  19. from lib.args import Args
  20. from lib.pipeline import Pipeline
  21. from lib.controlserver import ControlServer
  22. # main class
  23. class Voctocore(object):
  24. log = logging.getLogger('Voctocore')
  25. def __init__(self):
  26. self.log.debug('creating GObject-MainLoop')
  27. self.mainloop = GObject.MainLoop()
  28. # initialize subsystem
  29. self.log.debug('creating A/V-Pipeline')
  30. self.pipeline = Pipeline()
  31. self.log.debug('creating ControlServer')
  32. self.controlserver = ControlServer(self.pipeline)
  33. def run(self):
  34. self.log.info('running GObject-MainLoop')
  35. try:
  36. self.mainloop.run()
  37. except KeyboardInterrupt:
  38. self.log.info('Terminated via Ctrl-C')
  39. def quit(self):
  40. self.log.info('quitting GObject-MainLoop')
  41. self.mainloop.quit()
  42. # run mainclass
  43. def main():
  44. # configure logging
  45. docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
  46. logging.basicConfig(
  47. level=logging.DEBUG if Args.verbose else logging.WARNING,
  48. format='\x1b[33m%(levelname)8s\x1b[0m \x1b[32m%(name)s\x1b[0m: %(message)s' if docolor else '%(levelname)8s %(name)s: %(message)s')
  49. # make killable by ctrl-c
  50. logging.debug('setting SIGINT handler')
  51. signal.signal(signal.SIGINT, signal.SIG_DFL)
  52. # init main-class and main-loop
  53. logging.debug('initializing Voctocore')
  54. voctocore = Voctocore()
  55. logging.debug('running Voctocore')
  56. voctocore.run()
  57. if __name__ == '__main__':
  58. main()