summaryrefslogtreecommitdiff
path: root/voctogui/lib/warningoverlay.py
blob: 6df932e0456b89dd6bd467856f56399db4ce9570 (plain)
  1. import logging
  2. from gi.repository import GLib, Gst
  3. from lib.config import Config
  4. class VideoWarningOverlay(object):
  5. """ Displays a Warning-Overlay above the Video-Feed of another VideoDisplay """
  6. def __init__(self):
  7. self.log = logging.getLogger('VideoWarningOverlay')
  8. self.text = None
  9. self.enabled = False
  10. self.blink_state = False
  11. GLib.timeout_add_seconds(1, self.on_blink_callback)
  12. caps_string = Config.get('mix', 'videocaps')
  13. self.log.debug('parsing video-caps: %s', caps_string)
  14. caps = Gst.Caps.from_string(caps_string)
  15. struct = caps.get_structure(0)
  16. _, self.width = struct.get_int('width')
  17. _, self.height = struct.get_int('height')
  18. self.log.debug('configuring size to %ux%u', self.width, self.height)
  19. def on_blink_callback(self):
  20. self.blink_state = not self.blink_state
  21. return True
  22. def enable(self, text=None):
  23. self.text = text
  24. self.enabled = True
  25. def set_text(self, text=None):
  26. self.text = text
  27. def disable(self):
  28. self.enabled = False
  29. def draw_callback(self, cr, timestamp, duration):
  30. if not self.enabled:
  31. return
  32. w = self.width
  33. h = self.height / 20
  34. if self.blink_state:
  35. cr.set_source_rgba(1.0, 0.0, 0.0, 0.8)
  36. else:
  37. cr.set_source_rgba(1.0, 0.5, 0.0, 0.8)
  38. cr.rectangle(0, 0, w, h)
  39. cr.fill()
  40. text = "Stream is Blanked"
  41. if self.text:
  42. text += ": "+self.text
  43. cr.set_font_size(h*0.75)
  44. xbearing, ybearing, txtwidth, txtheight, xadvance, yadvance = cr.text_extents(text)
  45. cr.move_to(w/2 - txtwidth/2, h*0.75)
  46. cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
  47. cr.show_text(text)