Avoid accumulating audio latency from audio captured by the host before we're ready to play it

This commit is contained in:
Cameron Gutman 2019-01-06 13:24:36 -08:00
parent 610c00bf2d
commit f884003066

View File

@ -152,6 +152,7 @@ static void ReceiveThreadProc(void* context) {
PQUEUED_AUDIO_PACKET packet;
int queueStatus;
int useSelect;
int packetsToDrop = 100;
packet = NULL;
@ -182,6 +183,10 @@ static void ReceiveThreadProc(void* context) {
}
else if (packet->size == 0) {
// Receive timed out; try again
// If we hit this path, there are no queued audio packets on the host PC,
// so we don't need to drop anything.
packetsToDrop = 0;
continue;
}
@ -196,6 +201,14 @@ static void ReceiveThreadProc(void* context) {
continue;
}
// 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.
if (packetsToDrop > 0) {
packetsToDrop--;
continue;
}
// RTP sequence number must be in host order for the RTP queue
rtp->sequenceNumber = htons(rtp->sequenceNumber);