summaryrefslogtreecommitdiff
path: root/voctocore/lib/avpreviewoutput.py
diff options
context:
space:
mode:
authorMaZderMind <github@mazdermind.de>2015-05-14 20:41:03 +0200
committerMaZderMind <github@mazdermind.de>2015-05-14 20:41:03 +0200
commitb81461b9a433b8ac0c3b3a098e42b12faf9e8d27 (patch)
tree86791b5677a00a7e9daade692b99f42528478b8d /voctocore/lib/avpreviewoutput.py
parentb3b9f5630ecfdb9ff7f4e6955fa875f80ae93f84 (diff)
Extract TCP Connection handling into separate classes
Diffstat (limited to 'voctocore/lib/avpreviewoutput.py')
-rw-r--r--voctocore/lib/avpreviewoutput.py43
1 files changed, 10 insertions, 33 deletions
diff --git a/voctocore/lib/avpreviewoutput.py b/voctocore/lib/avpreviewoutput.py
index 2fa8c3a..0ad3515 100644
--- a/voctocore/lib/avpreviewoutput.py
+++ b/voctocore/lib/avpreviewoutput.py
@@ -1,26 +1,23 @@
#!/usr/bin/python3
-import logging, socket
-from gi.repository import GObject, Gst
+import logging
+from gi.repository import Gst
from lib.config import Config
+from lib.tcpmulticonnection import TCPMultiConnection
-class AVPreviewOutput(object):
+class AVPreviewOutput(TCPMultiConnection):
log = logging.getLogger('AVPreviewOutput')
name = None
- port = None
caps = None
- boundSocket = None
receiverPipeline = None
- currentConnections = []
-
def __init__(self, channel, port):
self.log = logging.getLogger('AVPreviewOutput['+channel+']')
+ super().__init__(port)
self.channel = channel
- self.port = port
if Config.has_option('previews', 'videocaps'):
vcaps_out = Config.get('previews', 'videocaps')
@@ -63,34 +60,14 @@ class AVPreviewOutput(object):
self.receiverPipeline = Gst.parse_launch(pipeline)
self.receiverPipeline.set_state(Gst.State.PLAYING)
- self.log.debug('Binding to Output-Socket on [::]:%u', port)
- self.boundSocket = socket.socket(socket.AF_INET6)
- self.boundSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- self.boundSocket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)
- self.boundSocket.bind(('::', port))
- self.boundSocket.listen(1)
-
- self.log.debug('Setting GObject io-watch on Socket')
- GObject.io_add_watch(self.boundSocket, GObject.IO_IN, self.on_connect)
-
- def on_connect(self, sock, *args):
- conn, addr = sock.accept()
- self.log.info("Incomming Connection from %s", addr)
+ def on_accepted(self, conn, addr):
+ self.log.debug('Adding fd %u to multifdsink', conn.fileno())
+ fdsink = self.receiverPipeline.get_by_name('fd')
+ fdsink.emit('add', conn.fileno())
def on_disconnect(multifdsink, fileno):
if fileno == conn.fileno():
self.log.debug('fd %u removed from multifdsink', fileno)
+ self.close_connection(conn)
- self.currentConnections.remove(conn)
- self.log.info('Disconnected Receiver %s', addr)
- self.log.info('Now %u Receiver connected', len(self.currentConnections))
-
- self.log.debug('Adding fd %u to multifdsink', conn.fileno())
- fdsink = self.receiverPipeline.get_by_name('fd')
- fdsink.emit('add', conn.fileno())
fdsink.connect('client-fd-removed', on_disconnect)
-
- self.currentConnections.append(conn)
- self.log.info('Now %u Receiver connected', len(self.currentConnections))
-
- return True