Hopefully improve retransmit search

merge-requests/9/head
Phil Taylor 2022-01-14 14:10:21 +00:00
rodzic ce0544ac6a
commit e00b598fd9
2 zmienionych plików z 62 dodań i 58 usunięć

Wyświetl plik

@ -1230,34 +1230,37 @@ void udpBase::sendRetransmitRequest()
qDebug(logUdp()) << "Missing Seq: size=" << rxSeqBuf.size() << "firstKey=" << rxSeqBuf.firstKey() << "lastKey=" << rxSeqBuf.lastKey() << "missing=" << rxSeqBuf.lastKey() - rxSeqBuf.firstKey() - rxSeqBuf.size() + 1;
// We are missing packets so iterate through the buffer and add the missing ones to missing packet list
missingMutex.lock();
for (int i = 0; i < rxSeqBuf.keys().length() - 1; i++) {
for (quint16 j = rxSeqBuf.keys()[i] + 1; j < rxSeqBuf.keys()[i + 1]; j++) {
auto s = rxMissing.find(j);
if (s == rxMissing.end())
{
// We haven't seen this missing packet before
qDebug(logUdp()) << this->metaObject()->className() << ": Adding to missing buffer (len=" << rxMissing.size() << "): " << j;
if (rxMissing.size() > 25)
{
rxMissing.erase(rxMissing.begin());
}
rxMissing.insert(j, 0);
if (rxSeqBuf.size() > BUFSIZE)
{
rxSeqBuf.erase(rxSeqBuf.begin());
}
rxSeqBuf.insert(j, QTime::currentTime()); // Add this missing packet to the rxbuffer as we now long about it.
packetsLost++;
}
else {
if (s.value() == 4)
{
// We have tried 4 times to request this packet, time to give up!
s = rxMissing.erase(s);
}
auto i = std::adjacent_find(rxSeqBuf.keys().begin(), rxSeqBuf.keys().end(), [](int l, int r) {return l + 1 < r; });
while (i != rxSeqBuf.keys().end())
{
quint16 j = 1 + *i;
auto s = rxMissing.find(j);
if (s == rxMissing.end())
{
// We haven't seen this missing packet before
qDebug(logUdp()) << this->metaObject()->className() << ": Adding to missing buffer (len=" << rxMissing.size() << "): " << j;
if (rxMissing.size() > 25)
{
rxMissing.erase(rxMissing.begin());
}
rxMissing.insert(j, 0);
if (rxSeqBuf.size() > BUFSIZE)
{
rxSeqBuf.erase(rxSeqBuf.begin());
}
rxSeqBuf.insert(j, QTime::currentTime()); // Add this missing packet to the rxbuffer as we now long about it.
packetsLost++;
}
else {
if (s.value() == 4)
{
// We have tried 4 times to request this packet, time to give up!
s = rxMissing.erase(s);
}
}
++i;
}
missingMutex.unlock();
}

Wyświetl plik

@ -1584,43 +1584,45 @@ void udpServer::sendRetransmitRequest(CLIENT* c)
if (c->rxMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD)))
{
if (c->missMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD)))
{
for (int i = 0; i < c->rxSeqBuf.keys().length() - 1; i++) {
for (quint16 j = c->rxSeqBuf.keys()[i] + 1; j < c->rxSeqBuf.keys()[i + 1]; j++) {
{
auto i = std::adjacent_find(c->rxSeqBuf.keys().begin(), c->rxSeqBuf.keys().end(), [](int l, int r) {return l + 1 < r; });
while (i != c->rxSeqBuf.keys().end())
{
quint16 j = 1 + *i;
if (c->rxSeqBuf.lastKey() - c->rxSeqBuf.firstKey() - c->rxSeqBuf.size() == 0 && c->type == "AUDIO" &&
(c->txCodec == 0x40 || c->txCodec == 0x80))
{
// Single missing audio packet ignore it!
qDebug(logUdpServer()) << "Single missing audio packet will be handled by FEC (" << hex << j << ")";
c->rxSeqBuf.insert(j, QTime::currentTime()); // Add this missing packet to the rxbuffer as we now long about it.
c->rxMutex.unlock();
c->missMutex.unlock();
return;
}
auto s = c->rxMissing.find(j);
if (s == c->rxMissing.end())
{
// We haven't seen this missing packet before
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.lastKey() - c->rxSeqBuf.firstKey() - c->rxSeqBuf.size() == 0 && c->type == "AUDIO" &&
(c->txCodec == 0x40 || c->txCodec == 0x80))
{
// Single missing audio packet ignore it!
qDebug(logUdpServer()) << "Single missing audio packet will be handled by FEC (" << hex << j << ")";
c->rxSeqBuf.insert(j, QTime::currentTime()); // Add this missing packet to the rxbuffer so it doesn't try to retransmit
c->missMutex.unlock();
c->rxMutex.unlock();
return;
}
if (c->rxSeqBuf.size() > BUFSIZE)
{
c->rxSeqBuf.remove(c->rxSeqBuf.firstKey());
}
c->rxSeqBuf.insert(j, QTime::currentTime()); // Add this missing packet to the rxbuffer as we now long about it.
auto s = c->rxMissing.find(j);
if (s == c->rxMissing.end())
{
// We haven't seen this missing packet before
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() > BUFSIZE)
{
c->rxSeqBuf.remove(c->rxSeqBuf.firstKey());
}
else {
if (s.value() == 4)
{
// We have tried 4 times to request this packet, time to give up!
s = c->rxMissing.erase(s);
}
c->rxSeqBuf.insert(j, QTime::currentTime()); // Add this missing packet to the rxbuffer as we now long about it.
}
else {
if (s.value() == 4)
{
// We have tried 4 times to request this packet, time to give up!
s = c->rxMissing.erase(s);
}
}
++i;
}
}
else {
@ -1632,7 +1634,6 @@ void udpServer::sendRetransmitRequest(CLIENT* c)
qInfo(logUdpServer()) << "Unable to lock rxMutex()";
}
c->missMutex.unlock();
}
}