From 7399e5dc6272c066002fbefba91d7b2ac592569c Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Fri, 14 Oct 2022 11:34:52 +0300 Subject: [PATCH] Add frame number to udp packets --- common/network/Udp.cxx | 17 ++++++++++------- common/network/Udp.h | 5 +++++ common/rfb/EncodeManager.cxx | 3 +++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/common/network/Udp.cxx b/common/network/Udp.cxx index e59d0f1..9fd4dfa 100644 --- a/common/network/Udp.cxx +++ b/common/network/Udp.cxx @@ -40,7 +40,7 @@ using namespace network; static rfb::LogWriter vlog("WebUdp"); static WuHost *host = NULL; -rfb::IntParameter udpSize("udpSize", "UDP packet data size", 1300, 500, 1400); +rfb::IntParameter udpSize("udpSize", "UDP packet data size", 1296, 500, 1400); extern settings_t settings; @@ -95,10 +95,11 @@ void *udpserver(void *nport) { } // Send one packet, split into N UDP-sized pieces -static uint8_t udpsend(WuClient *client, const uint8_t *data, unsigned len, uint32_t *id) { +static uint8_t udpsend(WuClient *client, const uint8_t *data, unsigned len, uint32_t *id, + const uint32_t *frame) { const uint32_t DATA_MAX = udpSize; - uint8_t buf[1400 + sizeof(uint32_t) * 4]; + uint8_t buf[1400 + sizeof(uint32_t) * 5]; const uint32_t pieces = (len / DATA_MAX) + ((len % DATA_MAX) ? 1 : 0); uint32_t i; @@ -111,12 +112,13 @@ static uint8_t udpsend(WuClient *client, const uint8_t *data, unsigned len, uint memcpy(&buf[4], &i, sizeof(uint32_t)); memcpy(&buf[8], &pieces, sizeof(uint32_t)); memcpy(&buf[12], &hash, sizeof(uint32_t)); + memcpy(&buf[16], frame, sizeof(uint32_t)); - memcpy(&buf[16], data, curlen); + memcpy(&buf[20], data, curlen); data += curlen; len -= curlen; - if (WuHostSendBinary(host, client, buf, curlen + sizeof(uint32_t) * 4) < 0) + if (WuHostSendBinary(host, client, buf, curlen + sizeof(uint32_t) * 5) < 0) return 1; } @@ -125,7 +127,8 @@ static uint8_t udpsend(WuClient *client, const uint8_t *data, unsigned len, uint return 0; } -UdpStream::UdpStream(): OutStream(), client(NULL), total_len(0), id(0), failed(false) { +UdpStream::UdpStream(): OutStream(), client(NULL), total_len(0), id(0), failed(false), + frame(0) { ptr = data; end = data + UDPSTREAM_BUFSIZE; @@ -137,7 +140,7 @@ void UdpStream::flush() { total_len += len; if (client) { - if (udpsend(client, data, len, &id)) { + if (udpsend(client, data, len, &id, &frame)) { vlog.error("Error sending udp, client gone?"); failed = true; } diff --git a/common/network/Udp.h b/common/network/Udp.h index 0bdeb22..38c9f46 100644 --- a/common/network/Udp.h +++ b/common/network/Udp.h @@ -40,6 +40,10 @@ namespace network { client = cli; } + void setFrameNumber(const unsigned in) { + frame = in; + } + bool isFailed() const; void clearFailed(); private: @@ -48,6 +52,7 @@ namespace network { size_t total_len; uint32_t id; bool failed; + uint32_t frame; }; } diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index cc6f571..0c45fdc 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -675,6 +675,9 @@ Encoder *EncodeManager::startRect(const Rect& rect, int type, const bool trackQu beforeLength = conn->getOutStream(conn->cp.supportsUdp)->length(); + if (conn->cp.supportsUdp) + ((network::UdpStream *) conn->getOutStream(conn->cp.supportsUdp))->setFrameNumber(updates); + stats[klass][activeType].rects++; stats[klass][activeType].pixels += rect.area(); equiv = 12 + rect.area() * (conn->cp.pf().bpp/8);