[client] audio: tune target latency

The target latency is now based upon the device maximum period size
(which may be configured by setting the `PIPEWIRE_LATENCY` environment
variable if using PipeWire), with some allowance for timing jitter from
Spice and the audio device.

PipeWire can change the period size dynamically at any time which must be
taken into account when selecting the target latency to avoid underruns
when the period size is increased. This is explained in detail within the
commit body.
This commit is contained in:
Chris Spencer
2022-01-29 19:23:28 +00:00
committed by Geoffrey McRae
parent ca29fe80a6
commit e1e60fdaa6
4 changed files with 131 additions and 46 deletions

View File

@@ -246,10 +246,13 @@ static void pulseaudio_overflow_cb(pa_stream * p, void * userdata)
}
static void pulseaudio_setup(int channels, int sampleRate,
LG_AudioPullFn pullFn)
int * maxPeriodFrames, LG_AudioPullFn pullFn)
{
if (pa.sink && pa.sinkChannels == channels && pa.sinkSampleRate == sampleRate)
{
*maxPeriodFrames = pa.sinkStart;
return;
}
//TODO: be smarter about this
const int PERIOD_LEN = 80;
@@ -289,6 +292,8 @@ static void pulseaudio_setup(int channels, int sampleRate,
pa.sinkStart = attribs.tlength / pa.sinkStride;
pa.sinkCorked = true;
*maxPeriodFrames = pa.sinkStart;
pa_threaded_mainloop_unlock(pa.loop);
}