From 0dad9b1e76c73563e521c2476254a0dabe3e2c76 Mon Sep 17 00:00:00 2001 From: Chris Spencer Date: Mon, 21 Feb 2022 11:03:29 +0000 Subject: [PATCH] [client] audio: fix latency calculation if audio device starts early If the audio device starts earlier than required, we slew the read pointer backwards to avoid underrunning. We need to apply this same offset to the recorded device position, otherwise the Spice thread will think playback is further ahead than it really is and inject unnecessary latency to compensate. --- client/src/audio.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/src/audio.c b/client/src/audio.c index 1e5f7a10..c78bb204 100644 --- a/client/src/audio.c +++ b/client/src/audio.c @@ -227,7 +227,10 @@ static int playbackPullFrames(uint8_t * dst, int frames) int offset = ringbuffer_getCount(audio.playback.buffer) - audio.playback.deviceTargetStartFrames; if (offset < 0) + { + data->nextPosition += offset; ringbuffer_consume(audio.playback.buffer, NULL, offset); + } audio.playback.state = STREAM_STATE_RUN; }