From 2899e9ff4998323b9c1b2c7ebb9928b114bee425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Kri=C5=A1tofi=C4=87?= Date: Mon, 30 Dec 2019 15:33:04 +0100 Subject: [PATCH] #5 Implemented the Streamer class Created the Streamer class for the TCP image transfer. --- modules/Streamer.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 modules/Streamer.py diff --git a/modules/Streamer.py b/modules/Streamer.py new file mode 100644 index 0000000..88b019d --- /dev/null +++ b/modules/Streamer.py @@ -0,0 +1,26 @@ +import socket +from modules.Recorder import Recorder + +class Streamer(object): + ''' + Sets the socket and the server address and get the camera from the Recorder class.2 + + Arguments: + host(str) IP address of a server to stream to + port(str) port of a server to stream to + ''' + def __init__(self, host, port, camera_num): + self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.server_address = (host, port) + self.camera = Recorder(camera_num) + + ''' + Gets a frame from camera and sends it to the server via UDP. + ''' + def send_to_server(self): + while True: + frame = self.camera.get_frame() + length = len(frame) + # print("Len: " + str(length)) + if(length < 65536): + self.sock.sendto(frame, self.server_address)