From 4696fe68246400feb28a23003fcc8a6d90f3869f Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Thu, 13 Jan 2022 21:50:43 +0000 Subject: [PATCH] Set buffer size with a #define --- packettypes.h | 2 ++ udphandler.cpp | 8 ++++---- udpserver.cpp | 16 ++++++++-------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packettypes.h b/packettypes.h index 46cad4c..ae19b3f 100644 --- a/packettypes.h +++ b/packettypes.h @@ -22,6 +22,8 @@ #define AUDIO_SIZE 0x18 #define DATA_SIZE 0x15 +#define BUFSIZE 50 // Number of packets to buffer + // 0x10 length control packet (connect/disconnect/idle.) typedef union control_packet { struct { diff --git a/udphandler.cpp b/udphandler.cpp index 476dff6..eaa58de 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -1154,7 +1154,7 @@ void udpBase::dataReceived(QByteArray r) { rxBufferMutex.lock(); if (rxSeqBuf.isEmpty()) { - if (rxSeqBuf.size() > 400) + if (rxSeqBuf.size() > BUFSIZE) { rxSeqBuf.erase(rxSeqBuf.begin()); } @@ -1178,7 +1178,7 @@ void udpBase::dataReceived(QByteArray r) { // Add incoming packet to the received buffer and if it is in the missing buffer, remove it. rxSeqBuf.insert(in->seq, QTime::currentTime()); - if (rxSeqBuf.size() > 400) + if (rxSeqBuf.size() > BUFSIZE) { rxSeqBuf.erase(rxSeqBuf.begin()); } @@ -1242,7 +1242,7 @@ void udpBase::sendRetransmitRequest() rxMissing.erase(rxMissing.begin()); } rxMissing.insert(j, 0); - if (rxSeqBuf.size() > 400) + if (rxSeqBuf.size() > BUFSIZE) { rxSeqBuf.erase(rxSeqBuf.begin()); } @@ -1388,7 +1388,7 @@ void udpBase::sendTrackedPacket(QByteArray d) congestion = 0; } txSeqBuf.insert(sendSeq,s); - if (txSeqBuf.size() > 400) + if (txSeqBuf.size() > BUFSIZE) { txSeqBuf.erase(txSeqBuf.begin()); } diff --git a/udpserver.cpp b/udpserver.cpp index 50cf933..bff231d 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -831,7 +831,7 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) // Add incoming packet to the received buffer and if it is in the missing buffer, remove it. if (current->rxMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { - if (current->rxSeqBuf.size() > 400) + if (current->rxSeqBuf.size() > BUFSIZE) { current->rxSeqBuf.remove(current->rxSeqBuf.firstKey()); } @@ -1126,7 +1126,7 @@ void udpServer::sendCapabilities(CLIENT* c) s.data = QByteArray::fromRawData((const char*)p.packet, sizeof(p)); if (c->txMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { - if (c->txSeqBuf.size() > 400) + if (c->txSeqBuf.size() > BUFSIZE) { c->txSeqBuf.remove(c->txSeqBuf.firstKey()); } @@ -1197,7 +1197,7 @@ void udpServer::sendConnectionInfo(CLIENT* c) if (c->txMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { - if (c->txSeqBuf.size() > 400) + if (c->txSeqBuf.size() > BUFSIZE) { c->txSeqBuf.remove(c->txSeqBuf.firstKey()); } @@ -1255,7 +1255,7 @@ void udpServer::sendTokenResponse(CLIENT* c, quint8 type) if (c->txMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { - if (c->txSeqBuf.size() > 400) + if (c->txSeqBuf.size() > BUFSIZE) { c->txSeqBuf.remove(c->txSeqBuf.firstKey()); } @@ -1373,7 +1373,7 @@ void udpServer::sendStatus(CLIENT* c) s.data = QByteArray::fromRawData((const char*)p.packet, sizeof(p)); if (c->txMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { - if (c->txSeqBuf.size() > 400) + if (c->txSeqBuf.size() > BUFSIZE) { c->txSeqBuf.remove(c->txSeqBuf.firstKey()); } @@ -1428,7 +1428,7 @@ void udpServer::dataForServer(QByteArray d) if (client->txMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { - if (client->txSeqBuf.size() > 400) + if (client->txSeqBuf.size() > BUFSIZE) { client->txSeqBuf.remove(client->txSeqBuf.firstKey()); } @@ -1510,7 +1510,7 @@ void udpServer::receiveAudioData(const audioPacket& d) s.data = t; if (client->txMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { - if (client->txSeqBuf.size() > 400) + if (client->txSeqBuf.size() > BUFSIZE) { client->txSeqBuf.remove(client->txSeqBuf.firstKey()); } @@ -1605,7 +1605,7 @@ void udpServer::sendRetransmitRequest(CLIENT* c) qDebug(logUdp()) << this->metaObject()->className() << ": Adding to missing buffer (len=" << c->rxMissing.size() << "): " << j << dec << missingTime.msecsTo(QTime::currentTime()) << "ms"; c->rxMissing.insert(j, 0); - if (c->rxSeqBuf.size() > 400) + if (c->rxSeqBuf.size() > BUFSIZE) { c->rxSeqBuf.remove(c->rxSeqBuf.firstKey()); }