aboutsummaryrefslogtreecommitdiff
path: root/voctocore/voctocore.py
blob: 8c15463f3d207525429d98644008923118a33926 (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 GLib, Gst, GObject
  6. # check min-version
  7. minGst = (1, 4)
  8. minPy = (3, 0)
  9. if Gst.version() < minGst:
  10. raise Exception("GStreamer version", Gst.version(), 'is too old, at least', minGst, 'is required')
  11. if sys.version_info < minPy:
  12. raise Exception("Python version", sys.version_info, 'is too old, at least', minPy, 'is required')
  13. # init GObject before importing local classes
  14. GObject.threads_init()
  15. Gst.init(None)
  16. # import local classes
  17. from lib.pipeline import Pipeline
  18. from lib.controlserver import ControlServer
  19. # main class
  20. class Voctocore:
  21. log = logging.getLogger('Voctocore')
  22. def __init__(self):
  23. self.log.debug('creating GObject-MainLoop')
  24. self.mainloop = GObject.MainLoop()
  25. # initialize subsystem
  26. self.log.debug('creating Video-Pipeline')
  27. self.pipeline = Pipeline()
  28. self.log.debug('creating ControlServer')
  29. self.controlserver = ControlServer(self.pipeline)
  30. def run(self):
  31. self.log.info('running Video-Pipeline')
  32. self.pipeline.run()
  33. self.log.info('running GObject-MainLoop')
  34. self.mainloop.run()
  35. def kill(self):
  36. self.log.info('quitting Video-Pipeline')
  37. self.pipeline.quit()
  38. self.log.info('quitting GObject-MainLoop')
  39. self.mainloop.quit()
  40. def on_eos(self, bus, msg):
  41. self.log.warning('received EOS-Signal on the Video-Bus from Element %s. This shouldn\'t happen if the program is not terminating right now', msg.src)
  42. self.kill()
  43. def on_error(self, bus, msg):
  44. err = msg.parse_error()
  45. self.log.error('received Error-Signal on the Video-Bus from Element %s: %s', msg.src, err[1])
  46. self.kill()
  47. # run mainclass
  48. def main(argv):
  49. # configure logging
  50. logging.basicConfig(level=logging.DEBUG,
  51. format='%(levelname)8s %(name)s: %(message)s')
  52. # make killable by ctrl-c
  53. logging.debug('setting SIGINT handler')
  54. signal.signal(signal.SIGINT, signal.SIG_DFL)
  55. # init main-class and main-loop
  56. logging.debug('initializing Voctocore')
  57. voctocore = Voctocore()
  58. logging.debug('running Voctocore')
  59. voctocore.run()
  60. if __name__ == '__main__':
  61. main(sys.argv)