summaryrefslogtreecommitdiff
path: root/voctocore/voctocore.py
blob: 7a962776c4efe183dfe41dabbb31ccf41f8a795b (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. self.mainloop.run()
  36. def quit(self):
  37. self.log.info('quitting GObject-MainLoop')
  38. self.mainloop.quit()
  39. # run mainclass
  40. def main():
  41. # configure logging
  42. docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
  43. logging.basicConfig(
  44. level=logging.DEBUG if Args.verbose else logging.WARNING,
  45. format='\x1b[33m%(levelname)8s\x1b[0m \x1b[32m%(name)s\x1b[0m: %(message)s' if docolor else '%(levelname)8s %(name)s: %(message)s')
  46. # make killable by ctrl-c
  47. logging.debug('setting SIGINT handler')
  48. signal.signal(signal.SIGINT, signal.SIG_DFL)
  49. # init main-class and main-loop
  50. logging.debug('initializing Voctocore')
  51. voctocore = Voctocore()
  52. logging.debug('running Voctocore')
  53. voctocore.run()
  54. if __name__ == '__main__':
  55. main()