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