def _get_response(self, size=DEFAULT_CHUNK_SIZE) -> RTSPPacket: rcv = None while True: try: rcv = self._rtsp_connection.recv(size) break except socket.timeout: continue print(f"Received from server: {repr(rcv)}") response = RTSPPacket.from_response(rcv) return response
def _send_request(self, request_type=RTSPPacket.INVALID) -> RTSPPacket: if not self.is_rtsp_connected: raise Exception( 'rtsp connection not established. run `setup_rtsp_connection()`' ) request = RTSPPacket(request_type, self.file_path, self._current_sequence_number, self.rtp_port, self.session_id).to_request() print(f"Sending request: {repr(request)}") self._rtsp_connection.send(request) self._current_sequence_number += 1 return self._get_response()
def _get_rtsp_packet(self) -> RTSPPacket: return RTSPPacket.from_request(self._rtsp_recv())
def _send_rtsp_response(self, sequence_number: int): response = RTSPPacket.build_response(sequence_number, self.SESSION_ID) self._rtsp_send(response.encode()) print('Sent response to client.')