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