aboutsummaryrefslogtreecommitdiff
path: root/voctocore/voctocore.py
blob: fa712f785694ead5950e2931176226c02958bd00 (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.pipeline import Pipeline
  20. from lib.controlserver import ControlServer
  21. from lib.loghandler import LogHandler
  22. # main class
  23. class Voctocore(object):
  24. def __init__(self):
  25. self.log = logging.getLogger('Voctocore')
  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. try:
  36. self.mainloop.run()
  37. except KeyboardInterrupt:
  38. self.log.info('Terminated via Ctrl-C')
  39. def quit(self):
  40. self.log.info('quitting GObject-MainLoop')
  41. self.mainloop.quit()
  42. # run mainclass
  43. def main():
  44. # configure logging
  45. docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
  46. handler = LogHandler(docolor, Args.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()