summaryrefslogtreecommitdiff
path: root/voctocore/voctocore.py
blob: b1955e05c59ef9d27a2bf5e5d9dbf4d1d8a31616 (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. from gi.repository import Gst, GstNet, 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. handler = LogHandler(docolor, Args.timestamp)
  46. logging.root.addHandler(handler)
  47. if Args.verbose >= 2:
  48. level = logging.DEBUG
  49. elif Args.verbose == 1:
  50. level = logging.INFO
  51. else:
  52. level = logging.WARNING
  53. logging.root.setLevel(level)
  54. # make killable by ctrl-c
  55. logging.debug('setting SIGINT handler')
  56. signal.signal(signal.SIGINT, signal.SIG_DFL)
  57. logging.info('Python Version: %s', sys.version_info)
  58. logging.info('GStreamer Version: %s', Gst.version())
  59. # init main-class and main-loop
  60. logging.debug('initializing Voctocore')
  61. voctocore = Voctocore()
  62. logging.debug('running Voctocore')
  63. voctocore.run()
  64. if __name__ == '__main__':
  65. main()