Add frame number to udp packets

pull/201/head
Lauri Kasanen 3 years ago
parent 7350b12b3d
commit 7399e5dc62
No known key found for this signature in database

@ -40,7 +40,7 @@ using namespace network;
static rfb::LogWriter vlog("WebUdp"); static rfb::LogWriter vlog("WebUdp");
static WuHost *host = NULL; 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; extern settings_t settings;
@ -95,10 +95,11 @@ void *udpserver(void *nport) {
} }
// Send one packet, split into N UDP-sized pieces // 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; 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); const uint32_t pieces = (len / DATA_MAX) + ((len % DATA_MAX) ? 1 : 0);
uint32_t i; 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[4], &i, sizeof(uint32_t));
memcpy(&buf[8], &pieces, sizeof(uint32_t)); memcpy(&buf[8], &pieces, sizeof(uint32_t));
memcpy(&buf[12], &hash, 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; data += curlen;
len -= 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; return 1;
} }
@ -125,7 +127,8 @@ static uint8_t udpsend(WuClient *client, const uint8_t *data, unsigned len, uint
return 0; 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; ptr = data;
end = data + UDPSTREAM_BUFSIZE; end = data + UDPSTREAM_BUFSIZE;
@ -137,7 +140,7 @@ void UdpStream::flush() {
total_len += len; total_len += len;
if (client) { if (client) {
if (udpsend(client, data, len, &id)) { if (udpsend(client, data, len, &id, &frame)) {
vlog.error("Error sending udp, client gone?"); vlog.error("Error sending udp, client gone?");
failed = true; failed = true;
} }

@ -40,6 +40,10 @@ namespace network {
client = cli; client = cli;
} }
void setFrameNumber(const unsigned in) {
frame = in;
}
bool isFailed() const; bool isFailed() const;
void clearFailed(); void clearFailed();
private: private:
@ -48,6 +52,7 @@ namespace network {
size_t total_len; size_t total_len;
uint32_t id; uint32_t id;
bool failed; bool failed;
uint32_t frame;
}; };
} }

@ -675,6 +675,9 @@ Encoder *EncodeManager::startRect(const Rect& rect, int type, const bool trackQu
beforeLength = conn->getOutStream(conn->cp.supportsUdp)->length(); 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].rects++;
stats[klass][activeType].pixels += rect.area(); stats[klass][activeType].pixels += rect.area();
equiv = 12 + rect.area() * (conn->cp.pf().bpp/8); equiv = 12 + rect.area() * (conn->cp.pf().bpp/8);

Loading…
Cancel
Save