summaryrefslogtreecommitdiff
path: root/voctocore/controlserver.py
blob: da27408b0eb1c4b07142a23a0f25b16aea88faf7 (plain)
  1. import socket, threading, queue
  2. from gi.repository import GObject
  3. class ControlServer():
  4. def __init__(self, videomix):
  5. '''Initialize server and start listening.'''
  6. self.videomix = videomix
  7. sock = socket.socket()
  8. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  9. sock.bind(('0.0.0.0', 23000))
  10. sock.listen(1)
  11. GObject.io_add_watch(sock, GObject.IO_IN, self.listener)
  12. def listener(self, sock, *args):
  13. '''Asynchronous connection listener. Starts a handler for each connection.'''
  14. conn, addr = sock.accept()
  15. print("Connected")
  16. GObject.io_add_watch(conn, GObject.IO_IN, self.handler)
  17. return True
  18. def handler(self, conn, *args):
  19. '''Asynchronous connection handler. Processes each line from the socket.'''
  20. line = conn.recv(4096)
  21. if not len(line):
  22. print("Connection closed.")
  23. return False
  24. livevideo = self.videomix.pipeline.get_by_name('livevideo')
  25. pad = livevideo.get_static_pad('sink_1')
  26. pad.set_property('alpha', 00)
  27. print(line)
  28. return True