From f42fbc2e54af93cb647d1f08cfbd9f7fe5d9f9c0 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Wed, 4 May 2022 15:43:34 +0100 Subject: [PATCH 1/9] Try using float for all audio. Not tested on Linux/Mac --- audiohandler.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/audiohandler.cpp b/audiohandler.cpp index 8eba4d2..d395003 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -90,7 +90,7 @@ bool audioHandler::init(audioSetup setupIn) if (setup.codec == 0x40 || setup.codec == 0x80) { setup.format.setSampleType(QAudioFormat::Float); } - + qDebug(logAudio()) << "Creating" << (setup.isinput ? "Input" : "Output") << "audio device:" << setup.name << ", bits" << setup.format.sampleSize() << ", codec" << setup.codec << @@ -134,8 +134,14 @@ bool audioHandler::init(audioSetup setupIn) format.setSampleSize(16); } } + format.setSampleType(QAudioFormat::Float); + if (!setup.port.isFormatSupported(format)) { + qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Attempt to select Float failed, reverting to SignedInt"; + format.setSampleType(QAudioFormat::SignedInt); + } - qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Internal: sample rate" << format.sampleRate() << "channel count" << format.channelCount(); + qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << format.sampleSize() << "Channel Count" << format.channelCount() << + "Sample Rate" << format.sampleRate() << "Codec" << format.codec() << "Sample Type" << format.sampleType(); // We "hopefully" now have a valid format that is supported so try connecting From bdca404457c1c1dd9dcafc4645126e913657afe1 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Wed, 4 May 2022 20:21:29 +0100 Subject: [PATCH 2/9] Make udpserver and client behave the same way for retransmit --- udphandler.cpp | 51 +++++++++++++++++++++----------------------------- udpserver.cpp | 19 ++++++++++--------- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/udphandler.cpp b/udphandler.cpp index abcc9b0..cc21e9d 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -202,7 +202,7 @@ void udpHandler::dataReceived() } QString tempLatency; - if (status.rxLatency > status.rxCurrentLatency && !status.rxUnderrun) + if (status.rxCurrentLatency < status.rxLatency*1.2 && !status.rxUnderrun) { tempLatency = QString("%1 ms").arg(status.rxCurrentLatency,3); } @@ -1199,7 +1199,7 @@ void udpBase::dataReceived(QByteArray r) case (CONTROL_SIZE): // Empty response used for simple comms and retransmit requests. { control_packet_t in = (control_packet_t)r.constData(); - if (in->type == 0x01) + if (in->type == 0x01 && in->len == 0x10) { // Single packet request packetsLost++; @@ -1210,7 +1210,7 @@ void udpBase::dataReceived(QByteArray r) // Found matching entry? // Send "untracked" as it has already been sent once. // Don't constantly retransmit the same packet, give-up eventually - qDebug(logUdp()) << this->metaObject()->className() << ": Sending retransmit of " << QString("0x%1").arg(match->seqNum,0,16); + qDebug(logUdp()) << this->metaObject()->className() << ": Sending (single packet) retransmit of " << QString("0x%1").arg(match->seqNum,0,16); match->retransmitCount++; udpMutex.lock(); udp->writeDatagram(match->data, radioIP, port); @@ -1302,7 +1302,7 @@ void udpBase::dataReceived(QByteArray r) else { // Found matching entry? // Send "untracked" as it has already been sent once. - qDebug(logUdp()) << this->metaObject()->className() << ": Remote has requested retransmit of " << QString("0x%1").arg(match->seqNum,0,16); + qDebug(logUdp()) << this->metaObject()->className() << ": Sending (multiple packet) retransmit of " << QString("0x%1").arg(match->seqNum,0,16); match->retransmitCount++; udpMutex.lock(); udp->writeDatagram(match->data, radioIP, port); @@ -1423,20 +1423,28 @@ void udpBase::sendRetransmitRequest() missingMutex.lock(); for (auto it = rxMissing.begin(); it != rxMissing.end(); ++it) { - if (it.value() < 10) - { - missingSeqs.append(it.key() & 0xff); - missingSeqs.append(it.key() >> 8 & 0xff); - missingSeqs.append(it.key() & 0xff); - missingSeqs.append(it.key() >> 8 & 0xff); - it.value()++; + if (&it.key() != Q_NULLPTR) { + if (it.value() < 4) + { + missingSeqs.append(it.key() & 0xff); + missingSeqs.append(it.key() >> 8 & 0xff); + missingSeqs.append(it.key() & 0xff); + missingSeqs.append(it.key() >> 8 & 0xff); + it.value()++; + } + else { + qInfo(logUdp()) << this->metaObject()->className() << ": No response for missing packet" << it.key() << "deleting"; + it = rxMissing.erase(it); + } } } missingMutex.unlock(); + if (missingSeqs.length() != 0) { control_packet p; memset(p.packet, 0x0, sizeof(p)); // We can't be sure it is initialized with 0x00! + p.len = sizeof(p); p.type = 0x01; p.seq = 0x0000; p.sentid = myId; @@ -1453,7 +1461,8 @@ void udpBase::sendRetransmitRequest() { qInfo(logUdp()) << this->metaObject()->className() << ": sending request for multiple missing packets : " << missingSeqs.toHex(':'); missingMutex.lock(); - missingSeqs.insert(0, p.packet, sizeof(p.packet)); + p.len = sizeof(p)+missingSeqs.size(); + missingSeqs.insert(0, p.packet, sizeof(p)); missingMutex.unlock(); udpMutex.lock(); @@ -1506,24 +1515,6 @@ void udpBase::sendPing() return; } -void udpBase::sendRetransmitRange(quint16 first, quint16 second, quint16 third, quint16 fourth) -{ - retransmit_range_packet p; - memset(p.packet, 0x0, sizeof(p)); // We can't be sure it is initialized with 0x00! - p.len = sizeof(p); - p.type = 0x00; - p.sentid = myId; - p.rcvdid = remoteId; - p.first = first; - p.second = second; - p.third = third; - p.fourth = fourth; - udpMutex.lock(); - udp->writeDatagram(QByteArray::fromRawData((const char*)p.packet, sizeof(p)), radioIP, port); - udpMutex.unlock(); - return; -} - void udpBase::sendTrackedPacket(QByteArray d) { diff --git a/udpserver.cpp b/udpserver.cpp index 6d6cb5c..d7c771e 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -796,17 +796,15 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) if (current->idleTimer != Q_NULLPTR && !current->idleTimer->isActive()) { current->idleTimer->start(100); } - } // This is a retransmit request - else if (in->type == 0x01) + } // This is a single packet retransmit request + else if (in->type == 0x01 && in->len == 0x10) { - // Single packet request - qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Received 'retransmit' request for " << QString("0x%1").arg(in->seq,0,16); QMap::iterator match = current->txSeqBuf.find(in->seq); if (match != current->txSeqBuf.end() && match->retransmitCount < 5) { // Found matching entry? // Don't constantly retransmit the same packet, give-up eventually - qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Sending retransmit of " << QString("0x%1").arg(match->seqNum,0,16); + qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Sending (single packet) retransmit of " << QString("0x%1").arg(match->seqNum, 0, 16); match->retransmitCount++; if (udpMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { @@ -820,6 +818,7 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) } else { // Just send an idle! + qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested (single) packet " << QString("0x%1").arg(in->seq, 0, 16) << "not found"; sendControl(current, 0x00, in->seq); } } @@ -843,7 +842,7 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) return s.seqNum == cs; }); if (match == current->txSeqBuf.end()) { - qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested packet " << QString("0x%1").arg(seq,0,16) << " not found"; + qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested (multiple) packet " << QString("0x%1").arg(seq,0,16) << " not found"; // Just send idle packet. sendControl(current, 0, in->seq); } @@ -851,7 +850,7 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) { // Found matching entry? // Send "untracked" as it has already been sent once. - qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Sending retransmit of " << QString("0x%1").arg(match->seqNum,0,16); + qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Sending (multiple packet) retransmit of " << QString("0x%1").arg(match->seqNum,0,16); match->retransmitCount++; if (udpMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { @@ -933,9 +932,9 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) current->rxSeqBuf.insert(f, QTime::currentTime()); if (f != in->seq) { - qInfo(logUdpServer()) << "Detected missing packet" << f; if (!current->rxMissing.contains(f)) { + qInfo(logUdpServer()) << "Detected new missing packet" << f; current->rxMissing.insert(f, 0); } } @@ -1750,6 +1749,7 @@ void udpServer::sendRetransmitRequest(CLIENT* c) p.rcvdid = c->remoteId; if (missingSeqs.length() == 4) // This is just a single missing packet so send using a control. { + p.len = sizeof(p); p.seq = (missingSeqs[0] & 0xff) | (quint16)(missingSeqs[1] << 8); qInfo(logUdp()) << this->metaObject()->className() << ": sending request for missing packet : " << QString("0x%1").arg(p.seq,0,16); @@ -1767,7 +1767,8 @@ void udpServer::sendRetransmitRequest(CLIENT* c) { qInfo(logUdp()) << this->metaObject()->className() << ": sending request for multiple missing packets : " << missingSeqs.toHex(); - missingSeqs.insert(0, p.packet, sizeof(p.packet)); + p.len = sizeof(p) + missingSeqs.size(); + missingSeqs.insert(0, p.packet, sizeof(p)); if (udpMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { From 3aefa6893964506a45cbe3e0c466accd80de66c5 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Wed, 4 May 2022 20:37:58 +0100 Subject: [PATCH 3/9] More fixes to make client and server behave in same way --- udphandler.cpp | 4 ---- udpserver.cpp | 17 ++++++++--------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/udphandler.cpp b/udphandler.cpp index cc21e9d..865ae76 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -1317,10 +1317,6 @@ void udpBase::dataReceived(QByteArray r) { rxBufferMutex.lock(); if (rxSeqBuf.isEmpty()) { - if (rxSeqBuf.size() > BUFSIZE) - { - rxSeqBuf.erase(rxSeqBuf.begin()); - } rxSeqBuf.insert(in->seq, QTime::currentTime()); } else diff --git a/udpserver.cpp b/udpserver.cpp index d7c771e..8fff956 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -885,10 +885,10 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) else { - if (in->seq < current->rxSeqBuf.firstKey()) + if (in->seq < current->rxSeqBuf.firstKey() || in->seq - current->rxSeqBuf.lastKey() > MAX_MISSING) { - qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): ******* seq number may have rolled over ****** previous highest: " << - QString("0x%1").arg(current->rxSeqBuf.lastKey(),0,16) << " current: " << QString("0x%1").arg(in->seq,0,16); + qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "Large seq number gap detected, previous highest: " << + QString("0x%1").arg(current->rxSeqBuf.lastKey(), 0, 16) << " current: " << QString("0x%1").arg(in->seq, 0, 16); // Looks like it has rolled over so clear buffer and start again. if (current->rxMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { @@ -918,6 +918,8 @@ 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. //int missCounter = 0; if (in->seq > current->rxSeqBuf.lastKey() + 1) { + qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "1 or more missing packets detected, previous: " << + QString("0x%1").arg(current->rxSeqBuf.lastKey(), 0, 16) << " current: " << QString("0x%1").arg(in->seq, 0, 16); // We are likely missing packets then! if (current->missMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { @@ -931,12 +933,9 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) } current->rxSeqBuf.insert(f, QTime::currentTime()); - if (f != in->seq) { - if (!current->rxMissing.contains(f)) - { - qInfo(logUdpServer()) << "Detected new missing packet" << f; - current->rxMissing.insert(f, 0); - } + if (f != in->seq && !current->rxMissing.contains(f)) + { + current->rxMissing.insert(f, 0); } } current->missMutex.unlock(); From 85ba0fb56967fdae1ae1ce6d180009c12089ad03 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Wed, 4 May 2022 22:29:05 +0100 Subject: [PATCH 4/9] When using Float, force 32bit as Mac doesn't like it otherwise --- audiohandler.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/audiohandler.cpp b/audiohandler.cpp index d395003..4a51aab 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -126,6 +126,17 @@ bool audioHandler::init(audioSetup setupIn) } } + if (format.sampleType()==QAudioFormat::SignedInt) { + format.setSampleType(QAudioFormat::Float); + format.setSampleSize(32); + if (!setup.port.isFormatSupported(format)) { + qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Attempt to select 32bit Float failed, reverting to SignedInt"; + format.setSampleType(QAudioFormat::SignedInt); + format.setSampleSize(16); + } + + } + if (format.sampleSize() == 24) { // We can't convert this easily so use 32 bit instead. format.setSampleSize(32); @@ -134,11 +145,6 @@ bool audioHandler::init(audioSetup setupIn) format.setSampleSize(16); } } - format.setSampleType(QAudioFormat::Float); - if (!setup.port.isFormatSupported(format)) { - qCritical(logAudio()) << (setup.isinput ? "Input" : "Output") << "Attempt to select Float failed, reverting to SignedInt"; - format.setSampleType(QAudioFormat::SignedInt); - } qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Selected format: SampleSize" << format.sampleSize() << "Channel Count" << format.channelCount() << "Sample Rate" << format.sampleRate() << "Codec" << format.codec() << "Sample Type" << format.sampleType(); @@ -695,4 +701,4 @@ void audioHandler::stateChanged(QAudio::State state) void audioHandler::clearUnderrun() { isUnderrun = false; -} \ No newline at end of file +} From cac93198a63cebdb2ab8695aaa8f9702da94d371 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Thu, 5 May 2022 00:06:50 +0100 Subject: [PATCH 5/9] Debugging retransmission (again!) --- udphandler.cpp | 14 ++++++++------ udpserver.cpp | 14 +++++--------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/udphandler.cpp b/udphandler.cpp index 865ae76..ae66207 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -1205,17 +1205,20 @@ void udpBase::dataReceived(QByteArray r) packetsLost++; congestion = static_cast(packetsSent) / packetsLost * 100; txBufferMutex.lock(); - QMap::iterator match = txSeqBuf.find(in->seq); + auto match = txSeqBuf.find(in->seq); if (match != txSeqBuf.end()) { // Found matching entry? // Send "untracked" as it has already been sent once. // Don't constantly retransmit the same packet, give-up eventually - qDebug(logUdp()) << this->metaObject()->className() << ": Sending (single packet) retransmit of " << QString("0x%1").arg(match->seqNum,0,16); + qDebug(logUdp()) << this->metaObject()->className() << ": Sending (single packet) retransmit of " << QString("0x%1").arg(match->seqNum, 0, 16); match->retransmitCount++; udpMutex.lock(); udp->writeDatagram(match->data, radioIP, port); udpMutex.unlock(); } + else { + qDebug(logUdp()) << this->metaObject()->className() << ": Remote requested packet " << QString("0x%1").arg(in->seq, 0, 16) << " not found, have " << txSeqBuf.begin()->seqNum << "to" << txSeqBuf.end()->seqNum;; + } txBufferMutex.unlock(); } if (in->type == 0x04) { @@ -1293,9 +1296,9 @@ void udpBase::dataReceived(QByteArray r) for (quint16 i = 0x10; i < r.length(); i = i + 2) { quint16 seq = (quint8)r[i] | (quint8)r[i + 1] << 8; - QMap::iterator match = txSeqBuf.find(seq); + auto match = txSeqBuf.find(seq); if (match == txSeqBuf.end()) { - qDebug(logUdp()) << this->metaObject()->className() << ": Remote requested packet " << QString("0x%1").arg(seq,0,16) << " not found"; + qDebug(logUdp()) << this->metaObject()->className() << ": Remote requested packet " << QString("0x%1").arg(seq, 0, 16) << " not found, have " << txSeqBuf.begin()->seqNum << "to" << txSeqBuf.end()->seqNum;; // Just send idle packet. sendControl(false, 0, seq); } @@ -1307,7 +1310,6 @@ void udpBase::dataReceived(QByteArray r) udpMutex.lock(); udp->writeDatagram(match->data, radioIP, port); udpMutex.unlock(); - match++; packetsLost++; congestion = static_cast(packetsSent) / packetsLost * 100; } @@ -1374,7 +1376,7 @@ void udpBase::dataReceived(QByteArray r) else { // This is probably one of our missing packets! missingMutex.lock(); - QMap::iterator s = rxMissing.find(in->seq); + auto s = rxMissing.find(in->seq); if (s != rxMissing.end()) { qInfo(logUdp()) << this->metaObject()->className() << ": Missing SEQ has been received! " << QString("0x%1").arg(in->seq,0,16); diff --git a/udpserver.cpp b/udpserver.cpp index 8fff956..206898e 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -799,7 +799,7 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) } // This is a single packet retransmit request else if (in->type == 0x01 && in->len == 0x10) { - QMap::iterator match = current->txSeqBuf.find(in->seq); + auto match = current->txSeqBuf.find(in->seq); if (match != current->txSeqBuf.end() && match->retransmitCount < 5) { // Found matching entry? @@ -818,7 +818,7 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) } else { // Just send an idle! - qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested (single) packet " << QString("0x%1").arg(in->seq, 0, 16) << "not found"; + qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested (single) packet " << QString("0x%1").arg(in->seq, 0, 16) << "not found, have " << current->txSeqBuf.begin()->seqNum << "to" << current->txSeqBuf.end()->seqNum; sendControl(current, 0x00, in->seq); } } @@ -838,11 +838,9 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) for (quint16 i = 0x10; i < r.length(); i = i + 2) { quint16 seq = (quint8)r[i] | (quint8)r[i + 1] << 8; - auto match = std::find_if(current->txSeqBuf.begin(), current->txSeqBuf.end(), [&cs = seq](SEQBUFENTRY& s) { - return s.seqNum == cs; - }); + auto match = current->txSeqBuf.find(seq); if (match == current->txSeqBuf.end()) { - qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested (multiple) packet " << QString("0x%1").arg(seq,0,16) << " not found"; + qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested (multiple) packet " << QString("0x%1").arg(seq,0,16) << " not found , have " << current->txSeqBuf.begin()->seqNum << "to" << current->txSeqBuf.end()->seqNum;; // Just send idle packet. sendControl(current, 0, in->seq); } @@ -860,8 +858,6 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) else { qInfo(logUdpServer()) << "Unable to lock udpMutex()"; } - - match++; } } } @@ -962,7 +958,7 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) // Check whether this is one of our missing ones! if (current->missMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { - QMap::iterator s = current->rxMissing.find(in->seq); + auto s = current->rxMissing.find(in->seq); if (s != current->rxMissing.end()) { qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Missing SEQ has been received! " << QString("0x%1").arg(in->seq,0,16); From 24841c5da9f1f9df80cc8a3231aa99198ba30366 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Thu, 5 May 2022 00:23:42 +0100 Subject: [PATCH 6/9] Fix debug message --- udphandler.cpp | 4 ++-- udpserver.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/udphandler.cpp b/udphandler.cpp index ae66207..d373525 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -1217,7 +1217,7 @@ void udpBase::dataReceived(QByteArray r) udpMutex.unlock(); } else { - qDebug(logUdp()) << this->metaObject()->className() << ": Remote requested packet " << QString("0x%1").arg(in->seq, 0, 16) << " not found, have " << txSeqBuf.begin()->seqNum << "to" << txSeqBuf.end()->seqNum;; + qDebug(logUdp()) << this->metaObject()->className() << ": Remote requested packet " << QString("0x%1").arg(in->seq, 0, 16) << " not found, have " << txSeqBuf.firstKey() << "to" << txSeqBuf.lastKey(); } txBufferMutex.unlock(); } @@ -1298,7 +1298,7 @@ void udpBase::dataReceived(QByteArray r) quint16 seq = (quint8)r[i] | (quint8)r[i + 1] << 8; auto match = txSeqBuf.find(seq); if (match == txSeqBuf.end()) { - qDebug(logUdp()) << this->metaObject()->className() << ": Remote requested packet " << QString("0x%1").arg(seq, 0, 16) << " not found, have " << txSeqBuf.begin()->seqNum << "to" << txSeqBuf.end()->seqNum;; + qDebug(logUdp()) << this->metaObject()->className() << ": Remote requested packet " << QString("0x%1").arg(seq, 0, 16) << " not found, have " << txSeqBuf.firstKey() << "to" << txSeqBuf.lastKey(); // Just send idle packet. sendControl(false, 0, seq); } diff --git a/udpserver.cpp b/udpserver.cpp index 206898e..6a1cfd1 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -818,7 +818,7 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) } else { // Just send an idle! - qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested (single) packet " << QString("0x%1").arg(in->seq, 0, 16) << "not found, have " << current->txSeqBuf.begin()->seqNum << "to" << current->txSeqBuf.end()->seqNum; + qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested (single) packet " << QString("0x%1").arg(in->seq, 0, 16) << "not found, have " << current->txSeqBuf.firstKey() << "to" << current->txSeqBuf.lastKey(); sendControl(current, 0x00, in->seq); } } @@ -840,7 +840,7 @@ void udpServer::commonReceived(QList* l, CLIENT* current, QByteArray r) quint16 seq = (quint8)r[i] | (quint8)r[i + 1] << 8; auto match = current->txSeqBuf.find(seq); if (match == current->txSeqBuf.end()) { - qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested (multiple) packet " << QString("0x%1").arg(seq,0,16) << " not found , have " << current->txSeqBuf.begin()->seqNum << "to" << current->txSeqBuf.end()->seqNum;; + qInfo(logUdpServer()) << current->ipAddress.toString() << "(" << current->type << "): Requested (multiple) packet " << QString("0x%1").arg(seq,0,16) << " not found , have " << current->txSeqBuf.firstKey() << "to" << current->txSeqBuf.lastKey(); // Just send idle packet. sendControl(current, 0, in->seq); } From 4b19ed522fabf600d04fe5cea3f842caf8f43b8d Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Thu, 5 May 2022 00:31:55 +0100 Subject: [PATCH 7/9] Hopefully fix occasional retransmit bug --- udphandler.cpp | 2 +- udpserver.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/udphandler.cpp b/udphandler.cpp index d373525..81812e8 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -1421,7 +1421,7 @@ void udpBase::sendRetransmitRequest() missingMutex.lock(); for (auto it = rxMissing.begin(); it != rxMissing.end(); ++it) { - if (&it.key() != Q_NULLPTR) { + if (it.key() != NULL) { if (it.value() < 4) { missingSeqs.append(it.key() & 0xff); diff --git a/udpserver.cpp b/udpserver.cpp index 6a1cfd1..2da30db 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -1715,7 +1715,7 @@ void udpServer::sendRetransmitRequest(CLIENT* c) { for (auto it = c->rxMissing.begin(); it != c->rxMissing.end(); ++it) { - if (&it.key() != Q_NULLPTR) + if (it.key() != NULL) { if (it.value() < 4) { From 7b5f29f4fe122d5bcd3106efdafe9d9c21f1e855 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Thu, 5 May 2022 01:49:21 +0100 Subject: [PATCH 8/9] More retransmit debugging --- udphandler.cpp | 9 +++++++-- udpserver.cpp | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/udphandler.cpp b/udphandler.cpp index 81812e8..fc7ecbf 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -1421,7 +1421,8 @@ void udpBase::sendRetransmitRequest() missingMutex.lock(); for (auto it = rxMissing.begin(); it != rxMissing.end(); ++it) { - if (it.key() != NULL) { + if (it.key() != 0x0) + { if (it.value() < 4) { missingSeqs.append(it.key() & 0xff); @@ -1429,11 +1430,15 @@ void udpBase::sendRetransmitRequest() missingSeqs.append(it.key() & 0xff); missingSeqs.append(it.key() >> 8 & 0xff); it.value()++; + it++; } else { qInfo(logUdp()) << this->metaObject()->className() << ": No response for missing packet" << it.key() << "deleting"; it = rxMissing.erase(it); - } + } + } else { + qInfo(logUdp()) << this->metaObject()->className() << ": found empty key in missing buffer"; + it++; } } missingMutex.unlock(); diff --git a/udpserver.cpp b/udpserver.cpp index 2da30db..3a178af 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -1715,7 +1715,7 @@ void udpServer::sendRetransmitRequest(CLIENT* c) { for (auto it = c->rxMissing.begin(); it != c->rxMissing.end(); ++it) { - if (it.key() != NULL) + if (it.key() != 0x00) { if (it.value() < 4) { @@ -1724,6 +1724,7 @@ void udpServer::sendRetransmitRequest(CLIENT* c) missingSeqs.append(it.key() & 0xff); missingSeqs.append(it.key() >> 8 & 0xff); it.value()++; + it++; } else { @@ -1731,6 +1732,9 @@ void udpServer::sendRetransmitRequest(CLIENT* c) qInfo(logUdp()) << this->metaObject()->className() << ": No response for missing packet" << it.key() << "deleting"; it = c->rxMissing.erase(it); } + } else { + qInfo(logUdp()) << this->metaObject()->className() << ": found empty key in missing buffer"; + it++; } } From 069c5368d870c7695b4423dc0ce21c154b6575a4 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Thu, 5 May 2022 02:01:20 +0100 Subject: [PATCH 9/9] More debugging --- udphandler.cpp | 3 ++- udpserver.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/udphandler.cpp b/udphandler.cpp index fc7ecbf..65ce54d 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -1419,7 +1419,8 @@ void udpBase::sendRetransmitRequest() QByteArray missingSeqs; missingMutex.lock(); - for (auto it = rxMissing.begin(); it != rxMissing.end(); ++it) + auto it = rxMissing.begin(); + while (it != rxMissing.end()) { if (it.key() != 0x0) { diff --git a/udpserver.cpp b/udpserver.cpp index 3a178af..2158451 100644 --- a/udpserver.cpp +++ b/udpserver.cpp @@ -1713,7 +1713,8 @@ void udpServer::sendRetransmitRequest(CLIENT* c) if (c->missMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD))) { - for (auto it = c->rxMissing.begin(); it != c->rxMissing.end(); ++it) + auto it = c->rxMissing.begin(); + while (it != c->rxMissing.end()) { if (it.key() != 0x00) {