summaryrefslogtreecommitdiff
path: root/voctocore/lib/videosrcmirror.py
blob: 8fb911df17c732bf1c375af12754a7e153515abe (plain)
  1. #!/usr/bin/python3
  2. import logging, socket
  3. from gi.repository import GObject, Gst
  4. from lib.config import Config
  5. class VideoSrcMirror(object):
  6. log = logging.getLogger('VideoSrcMirror')
  7. name = None
  8. port = None
  9. caps = None
  10. boundSocket = None
  11. receiverPipelines = []
  12. currentConnections = []
  13. def __init__(self, name, port, caps):
  14. self.log = logging.getLogger('VideoSrcMirror['+name+']')
  15. self.name = name
  16. self.port = port
  17. self.caps = caps
  18. self.log.debug('Binding to Mirror-Socket on [::]:%u', port)
  19. self.boundSocket = socket.socket(socket.AF_INET6)
  20. self.boundSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  21. self.boundSocket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)
  22. self.boundSocket.bind(('::', port))
  23. self.boundSocket.listen(1)
  24. self.log.debug('Setting GObject io-watch on Socket')
  25. GObject.io_add_watch(self.boundSocket, GObject.IO_IN, self.on_connect)
  26. def on_connect(self, sock, *args):
  27. conn, addr = sock.accept()
  28. self.log.info("incomming connection from %s", addr)
  29. pipeline = """
  30. intervideosrc channel={name}_mirror !
  31. {caps} !
  32. textoverlay text={name}_mirror halignment=left valignment=top ypad=125 !
  33. gdppay !
  34. fdsink fd={fd}
  35. """.format(
  36. fd=conn.fileno(),
  37. name=self.name,
  38. caps=self.caps
  39. )
  40. self.log.debug('Launching Mirror-Receiver-Pipeline:\n%s', pipeline)
  41. receiverPipeline = Gst.parse_launch(pipeline)
  42. self.log.debug('Binding End-of-Stream-Signal on Source-Receiver-Pipeline')
  43. receiverPipeline.bus.add_signal_watch()
  44. receiverPipeline.bus.connect("message::eos", self.on_disconnect)
  45. receiverPipeline.set_state(Gst.State.PLAYING)
  46. self.receiverPipelines.append(receiverPipeline)
  47. self.currentConnections.append(conn)
  48. return True
  49. def on_disconnect(self, bus, message):
  50. self.log.info('Received End-of-Stream-Signal on Source-Receiver-Pipeline')