summaryrefslogtreecommitdiff
path: root/voctocore/voctocore.py
blob: 1d04c4f7c05aa6f6fcd9074919167b9f0d2c8d6c (plain)
  1. #!/usr/bin/env python3
  2. import gi, signal, logging, sys
  3. # import GStreamer and GLib-Helper classes
  4. gi.require_version('Gst', '1.0')
  5. gi.require_version('GstNet', '1.0')
  6. from gi.repository import Gst, GstNet, GObject
  7. # check min-version
  8. minGst = (1, 5)
  9. minPy = (3, 0)
  10. Gst.init([])
  11. if Gst.version() < minGst:
  12. raise Exception("GStreamer version", Gst.version(), 'is too old, at least', minGst, 'is required')
  13. if sys.version_info < minPy:
  14. raise Exception("Python version", sys.version_info, 'is too old, at least', minPy, 'is required')
  15. # init GObject & Co. before importing local classes
  16. GObject.threads_init()
  17. # import local classes
  18. from lib.args import Args
  19. from lib.loghandler import LogHandler
  20. # main class
  21. class Voctocore(object):
  22. def __init__(self):
  23. # import local which use the config or the logging system
  24. # this is required, so that we can cnfigure logging, before reading the config
  25. from lib.pipeline import Pipeline
  26. from lib.controlserver import ControlServer
  27. self.log = logging.getLogger('Voctocore')
  28. self.log.debug('creating GObject-MainLoop')
  29. self.mainloop = GObject.MainLoop()
  30. # initialize subsystem
  31. self.log.debug('creating A/V-Pipeline')
  32. self.pipeline = Pipeline()
  33. self.log.debug('creating ControlServer')
  34. self.controlserver = ControlServer(self.pipeline)
  35. def run(self):
  36. self.log.info('running GObject-MainLoop')
  37. try:
  38. self.mainloop.run()
  39. except KeyboardInterrupt:
  40. self.log.info('Terminated via Ctrl-C')
  41. def quit(self):
  42. self.log.info('quitting GObject-MainLoop')
  43. self.mainloop.quit()
  44. # run mainclass
  45. def main():
  46. # configure logging
  47. docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
  48. handler = LogHandler(docolor, Args.timestamp)
  49. logging.root.addHandler(handler)
  50. if Args.verbose >= 2:
  51. level = logging.DEBUG
  52. elif Args.verbose == 1:
  53. level = logging.INFO
  54. else:
  55. level = logging.WARNING
  56. logging.root.setLevel(level)
  57. # make killable by ctrl-c
  58. logging.debug('setting SIGINT handler')
  59. signal.signal(signal.SIGINT, signal.SIG_DFL)
  60. logging.info('Python Version: %s', sys.version_info)
  61. logging.info('GStreamer Version: %s', Gst.version())
  62. # init main-class and main-loop
  63. logging.debug('initializing Voctocore')
  64. voctocore = Voctocore()
  65. logging.debug('running Voctocore')
  66. voctocore.run()
  67. if __name__ == '__main__':
  68. main()