mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 01:15:46 +00:00
Reduce NAT keepalive packet rate after connection is established
This commit is contained in:
parent
e9bc1070b7
commit
40fa4ef3c8
@ -15,6 +15,8 @@ static PLT_THREAD decoderThread;
|
||||
|
||||
static unsigned short lastSeq;
|
||||
|
||||
static int receivedDataFromPeer;
|
||||
|
||||
#define RTP_PORT 48000
|
||||
|
||||
#define MAX_PACKET_SIZE 1400
|
||||
@ -68,6 +70,7 @@ void initializeAudioStream(void) {
|
||||
}
|
||||
RtpqInitializeQueue(&rtpReorderQueue, RTPQ_DEFAULT_MAX_SIZE, RTPQ_DEFAULT_QUEUE_TIME);
|
||||
lastSeq = 0;
|
||||
receivedDataFromPeer = 0;
|
||||
}
|
||||
|
||||
static void freePacketList(PLINKED_BLOCKING_QUEUE_ENTRY entry) {
|
||||
@ -100,7 +103,7 @@ static void UdpPingThreadProc(void* context) {
|
||||
memcpy(&saddr, &RemoteAddr, sizeof(saddr));
|
||||
saddr.sin6_port = htons(RTP_PORT);
|
||||
|
||||
// Send PING every 500 milliseconds
|
||||
// Send PING every second until we get data back then every 5 seconds after that.
|
||||
while (!PltIsThreadInterrupted(&udpPingThread)) {
|
||||
err = sendto(rtpSocket, pingData, sizeof(pingData), 0, (struct sockaddr*)&saddr, RemoteAddrLen);
|
||||
if (err != sizeof(pingData)) {
|
||||
@ -109,7 +112,13 @@ static void UdpPingThreadProc(void* context) {
|
||||
return;
|
||||
}
|
||||
|
||||
PltSleepMs(500);
|
||||
// Send less frequently if we've received data from our peer
|
||||
if (receivedDataFromPeer) {
|
||||
PltSleepMs(5000);
|
||||
}
|
||||
else {
|
||||
PltSleepMs(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,6 +210,10 @@ static void ReceiveThreadProc(void* context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We've received data, so we can stop sending our ping packets
|
||||
// as quickly, since we're now just keeping the NAT session open.
|
||||
receivedDataFromPeer = 1;
|
||||
|
||||
// GFE accumulates audio samples before we are ready to receive them,
|
||||
// so we will drop the first 100 packets to avoid accumulating latency
|
||||
// by sending audio frames to the player faster than they can be played.
|
||||
|
@ -20,6 +20,8 @@ static PLT_THREAD udpPingThread;
|
||||
static PLT_THREAD receiveThread;
|
||||
static PLT_THREAD decoderThread;
|
||||
|
||||
static int receivedDataFromPeer;
|
||||
|
||||
// We can't request an IDR frame until the depacketizer knows
|
||||
// that a packet was lost. This timeout bounds the time that
|
||||
// the RTP queue will wait for missing/reordered packets.
|
||||
@ -30,6 +32,7 @@ static PLT_THREAD decoderThread;
|
||||
void initializeVideoStream(void) {
|
||||
initializeVideoDepacketizer(StreamConfig.packetSize);
|
||||
RtpfInitializeQueue(&rtpQueue); //TODO RTP_QUEUE_DELAY
|
||||
receivedDataFromPeer = 0;
|
||||
}
|
||||
|
||||
// Clean up the video stream
|
||||
@ -55,7 +58,13 @@ static void UdpPingThreadProc(void* context) {
|
||||
return;
|
||||
}
|
||||
|
||||
PltSleepMs(500);
|
||||
// Send less frequently if we've received data from our peer
|
||||
if (receivedDataFromPeer) {
|
||||
PltSleepMs(5000);
|
||||
}
|
||||
else {
|
||||
PltSleepMs(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,6 +113,10 @@ static void ReceiveThreadProc(void* context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We've received data, so we can stop sending our ping packets
|
||||
// as quickly, since we're now just keeping the NAT session open.
|
||||
receivedDataFromPeer = 1;
|
||||
|
||||
// RTP sequence number must be in host order for the RTP queue
|
||||
packet = (PRTP_PACKET)&buffer[0];
|
||||
packet->sequenceNumber = htons(packet->sequenceNumber);
|
||||
|
Loading…
x
Reference in New Issue
Block a user