Add mutex for incoming audio on udp and server

merge-requests/7/head
Phil Taylor 2021-11-15 19:28:44 +00:00
rodzic b5591e0867
commit 42675ae770
4 zmienionych plików z 54 dodań i 34 usunięć

Wyświetl plik

@ -856,7 +856,11 @@ void udpAudio::sendTxAudio()
return;
}
QByteArray audio;
if (audioMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD)))
{
txaudio->getNextAudioChunk(audio);
// Now we have the next audio chunk, we can release the mutex.
audioMutex.unlock();
if (audio.length() > 0) {
int counter = 1;
@ -886,6 +890,10 @@ void udpAudio::sendTxAudio()
counter++;
}
}
}
else {
qInfo(logUdpServer()) << "Unable to lock mutex for rxaudio";
}
}
void udpAudio::changeLatency(quint16 value)

Wyświetl plik

@ -32,6 +32,7 @@
#define AREYOUTHERE_PERIOD 500
#define WATCHDOG_PERIOD 500
#define RETRANSMIT_PERIOD 100
#define LOCK_PERIOD 100
struct udpPreferences {
QString ipAddress;
@ -197,6 +198,8 @@ private:
QTimer* txAudioTimer=Q_NULLPTR;
bool enableTx = true;
QMutex audioMutex;
};

Wyświetl plik

@ -1469,8 +1469,12 @@ void udpServer::sendRxAudio()
{
QByteArray audio;
if (rxaudio) {
if (audioMutex.try_lock_for(std::chrono::milliseconds(LOCK_PERIOD)))
{
audio.clear();
rxaudio->getNextAudioChunk(audio);
// Now we have the next audio chunk, we can release the mutex.
audioMutex.unlock();
int len = 0;
while (len < audio.length()) {
audioPacket partial;
@ -1479,6 +1483,10 @@ void udpServer::sendRxAudio()
len = len + partial.data.length();
}
}
else {
qInfo(logUdpServer()) << "Unable to lock mutex for rxaudio";
}
}
}

Wyświetl plik

@ -154,6 +154,7 @@ private:
QMutex udpMutex; // Used for critical operations.
QMutex connMutex;
QMutex audioMutex;
QList <CLIENT*> controlClients = QList<CLIENT*>();
QList <CLIENT*> civClients = QList<CLIENT*>();