aboutsummaryrefslogtreecommitdiff
path: root/voctocore/voctocore.py
blob: bf9b97320165292878d6679fc4b1f1fb3a1187c1 (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. from lib.loghandler import LogHandler
  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. timestamp = Args.timestamp > 0
  46. handler = LogHandler(docolor,timestamp)
  47. logging.root.addHandler(handler)
  48. if Args.verbose >= 2:
  49. level = logging.DEBUG
  50. elif Args.verbose == 1:
  51. level = logging.INFO
  52. else:
  53. level = logging.WARNING
  54. logging.root.setLevel(level)
  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()