summaryrefslogtreecommitdiff
path: root/voctocore/voctocore.py
blob: 552cf2b38cf4f0599b21f476f0660969fd332fbd (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 Gtk, Gdk, Gst, GObject, GdkX11, GstVideo
  6. # check min-version
  7. minGst = (1, 5)
  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 & Co. before importing local classes
  14. GObject.threads_init()
  15. Gdk.init([])
  16. Gtk.init([])
  17. Gst.init([])
  18. # import local classes
  19. from lib.args import Args
  20. from lib.pipeline import Pipeline
  21. from lib.controlserver import ControlServer
  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. if Args.verbose == 2:
  47. level = logging.DEBUG
  48. elif Args.verbose == 1:
  49. level = logging.INFO
  50. else:
  51. level = logging.WARNING
  52. if docolor:
  53. format = '\x1b[33m%(levelname)8s\x1b[0m \x1b[32m%(name)s\x1b[0m: %(message)s'
  54. else:
  55. format = '%(levelname)8s %(name)s: %(message)s'
  56. logging.basicConfig(level=level, format=format)
  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()