mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-06-17 22:31:21 +00:00
Only start the audio UDP ping thread when we are ready to accept samples
This commit is contained in:
+26
-13
@@ -325,21 +325,11 @@ int startAudioStream(void* audioContext, int arFlags) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = PltCreateThread(UdpPingThreadProc, NULL, &udpPingThread);
|
|
||||||
if (err != 0) {
|
|
||||||
AudioCallbacks.cleanup();
|
|
||||||
closeSocket(rtpSocket);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioCallbacks.start();
|
AudioCallbacks.start();
|
||||||
|
|
||||||
err = PltCreateThread(ReceiveThreadProc, NULL, &receiveThread);
|
err = PltCreateThread(ReceiveThreadProc, NULL, &receiveThread);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
AudioCallbacks.stop();
|
AudioCallbacks.stop();
|
||||||
PltInterruptThread(&udpPingThread);
|
|
||||||
PltJoinThread(&udpPingThread);
|
|
||||||
PltCloseThread(&udpPingThread);
|
|
||||||
closeSocket(rtpSocket);
|
closeSocket(rtpSocket);
|
||||||
AudioCallbacks.cleanup();
|
AudioCallbacks.cleanup();
|
||||||
return err;
|
return err;
|
||||||
@@ -349,11 +339,8 @@ int startAudioStream(void* audioContext, int arFlags) {
|
|||||||
err = PltCreateThread(DecoderThreadProc, NULL, &decoderThread);
|
err = PltCreateThread(DecoderThreadProc, NULL, &decoderThread);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
AudioCallbacks.stop();
|
AudioCallbacks.stop();
|
||||||
PltInterruptThread(&udpPingThread);
|
|
||||||
PltInterruptThread(&receiveThread);
|
PltInterruptThread(&receiveThread);
|
||||||
PltJoinThread(&udpPingThread);
|
|
||||||
PltJoinThread(&receiveThread);
|
PltJoinThread(&receiveThread);
|
||||||
PltCloseThread(&udpPingThread);
|
|
||||||
PltCloseThread(&receiveThread);
|
PltCloseThread(&receiveThread);
|
||||||
closeSocket(rtpSocket);
|
closeSocket(rtpSocket);
|
||||||
AudioCallbacks.cleanup();
|
AudioCallbacks.cleanup();
|
||||||
@@ -361,5 +348,31 @@ int startAudioStream(void* audioContext, int arFlags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't start pinging (which will cause GFE to start sending us traffic)
|
||||||
|
// until everything else is started. Otherwise we could accumulate a
|
||||||
|
// bunch of audio packets in the socket receive buffer while our audio
|
||||||
|
// backend is starting up and create audio latency.
|
||||||
|
err = PltCreateThread(UdpPingThreadProc, NULL, &udpPingThread);
|
||||||
|
if (err != 0) {
|
||||||
|
AudioCallbacks.stop();
|
||||||
|
PltInterruptThread(&receiveThread);
|
||||||
|
if ((AudioCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) {
|
||||||
|
// Signal threads waiting on the LBQ
|
||||||
|
LbqSignalQueueShutdown(&packetQueue);
|
||||||
|
PltInterruptThread(&decoderThread);
|
||||||
|
}
|
||||||
|
PltJoinThread(&receiveThread);
|
||||||
|
if ((AudioCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) {
|
||||||
|
PltJoinThread(&decoderThread);
|
||||||
|
}
|
||||||
|
PltCloseThread(&receiveThread);
|
||||||
|
if ((AudioCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) {
|
||||||
|
PltCloseThread(&decoderThread);
|
||||||
|
}
|
||||||
|
closeSocket(rtpSocket);
|
||||||
|
AudioCallbacks.cleanup();
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user