def show_frame(self): if self.is_feeding: _, frame = self.cap.read() frame = cv2.resize(frame, (self.frame_width, self.frame_height)) retval, buf = cv2.imencode(".webp", frame, [cv2.IMWRITE_WEBP_QUALITY, 10]) data = pickle.dumps(buf) data_list = list_split(data, 1024) data_header = message() data_header.username = self.username data_header.message = "data" data_header.messageLength = len(data) data_meta = data_header.meta.add() data_meta.packageSize = 1024 data_meta.packageCount = len(data_list) data_meta.tailSize = len(data_list[-1]) udt_send_command(data_header, self.data_tunnel) for data_package in data_list: self.data_tunnel.send(data_package, 0) img = ImageTk.PhotoImage( image=Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))) self.video_label.imgtk = img self.video_label.config(image=img) self.video_label.after(int(1000 / self.fps), self.show_frame)
def stop(self): self.is_feeding = False finish_command = message() finish_command.message = "videofinish" finish_command.username = self.username tcp_send_command(finish_command, self.command_tunnel) udt_send_command(finish_command, self.data_tunnel) self.cap.release() self.video_window.destroy() logging.warning("VideoSource: video share finished...")
def register_video_client(server_addr, tcp_port, udt_port, username, client_uuid): tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcp_socket.connect((server_addr, tcp_port)) logging.warning("TCP socket connected to %s:%s" % (server_addr, tcp_port)) udt_socket = udt.socket(socket.AF_INET, socket.SOCK_STREAM, 0) udt_socket.connect((server_addr, udt_port)) logging.warning("UDT socket connected to %s:%s" % (server_addr, udt_port)) hello_message = message() hello_message.message = "hello" hello_message.username = username hello_message.uuid = client_uuid tcp_send_command(hello_message, tcp_socket) udt_send_command(hello_message, udt_socket) return tcp_socket, udt_socket
def udt_recv_command(conn): header_length = int.from_bytes(conn.recv(4, 0), 'little') header_message_string = conn.recv(header_length, 0) command = message() command.ParseFromString(header_message_string) return command