aboutsummaryrefslogtreecommitdiff
path: root/voctocore/voctocore.py
blob: 0e65bc6421218a56d0fa75ea41c52305181e7ce8 (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 Gst, GObject
  6. # check min-version
  7. minGst = (1, 5)
  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. Gst.init([])
  16. # import local classes
  17. from lib.args import Args
  18. from lib.pipeline import Pipeline
  19. from lib.controlserver import ControlServer
  20. from lib import notifications
  21. # main class
  22. class Voctocore(object):
  23. def __init__(self):
  24. self.log = logging.getLogger('Voctocore')
  25. self.log.debug('creating GObject-MainLoop')
  26. self.mainloop = GObject.MainLoop()
  27. # initialize subsystem
  28. self.log.debug('creating A/V-Pipeline')
  29. self.pipeline = Pipeline()
  30. self.log.debug('creating ControlServer')
  31. self.controlserver = ControlServer(self.pipeline)
  32. def run(self):
  33. self.log.info('running GObject-MainLoop')
  34. try:
  35. self.mainloop.run()
  36. except KeyboardInterrupt:
  37. self.log.info('Terminated via Ctrl-C')
  38. def quit(self):
  39. self.log.info('quitting GObject-MainLoop')
  40. self.mainloop.quit()
  41. # run mainclass
  42. def main():
  43. # configure logging
  44. docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
  45. if Args.verbose == 2:
  46. level = logging.DEBUG
  47. elif Args.verbose == 1:
  48. level = logging.INFO
  49. else:
  50. level = logging.WARNING
  51. if docolor:
  52. format = '\x1b[33m%(levelname)8s\x1b[0m \x1b[32m%(name)s\x1b[0m: %(message)s'
  53. else:
  54. format = '%(levelname)8s %(name)s: %(message)s'
  55. logging.basicConfig(level=level, format=format)
  56. # make killable by ctrl-c
  57. logging.debug('setting SIGINT handler')
  58. signal.signal(signal.SIGINT, signal.SIG_DFL)
  59. logging.info('Python Version: %s', sys.version_info)
  60. logging.info('GStreamer Version: %s', Gst.version())
  61. # init main-class and main-loop
  62. logging.debug('initializing Voctocore')
  63. voctocore = Voctocore()
  64. notifications.controlserver = voctocore.controlserver
  65. logging.debug('running Voctocore')
  66. voctocore.run()
  67. if __name__ == '__main__':
  68. main()