Skip to content

Commit

Permalink
#9 Streamer and Recorder separated entirely
Browse files Browse the repository at this point in the history
Streamer and Recorder class are now completly separated! Meaning they are truly independent.
  • Loading branch information
kcuric committed Jan 4, 2020
1 parent e162bb2 commit f702618
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 4 additions & 2 deletions client/app.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
import sys, signal

recorder = Recorder(0)
stream = Streamer('127.0.0.1', 5005, recorder) #35.204.145.0
stream = Streamer('127.0.0.1', 5005) #35.204.145.0

# SIGNAL HANDLING
def receive_signal(signal_number, frame):
@@ -16,7 +16,9 @@ def receive_signal(signal_number, frame):
sys.exit()

def main():
stream.send_to_server()
while True:
frame = recorder.get_frame()
stream.send_to_server(frame)

if __name__ == "__main__":
signal.signal(signal.SIGINT, receive_signal)
15 changes: 6 additions & 9 deletions client/modules/Streamer.py
Original file line number Diff line number Diff line change
@@ -8,10 +8,9 @@ class Streamer(object):
host(str) IP address of a server to stream to
port(str) port of a server to stream to
'''
def __init__(self, host, port, recorder):
def __init__(self, host, port):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.server_address = (host, port)
self.camera = recorder

'''
Finalizer which is called after all the references to the object
@@ -23,10 +22,8 @@ def __del__(self):
'''
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)
if(length < 65536):
self.sock.sendto(frame, self.server_address)
print("sent to server")
def send_to_server(self, payload):
length = len(payload)
if(length < 65536):
self.sock.sendto(payload, self.server_address)
print("Sent to server! Payload size: {}".format(len(payload)))

0 comments on commit f702618

Please sign in to comment.