mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-02 05:12:02 +00:00
[client] audio: rework synchronization for low latency
Drive playback timing from audio sample positions instead of packet arrival cadence. Use SPICE multimedia timestamps to anchor streams, detect discontinuities, and estimate the long-term source rate. Ignore their coarse phase corrections when steering the playback buffer. Measure the device clock independently and wait for it to stabilize before enabling a bounded, slew-limited phase controller. Align startup buffering from logical producer and consumer positions so backend startup reserves do not become persistent latency. Size the buffer from the backend period, measured delivery jitter, and resampler delay. Update PipeWire and PulseAudio to report their actual startup requirements and presentation latency. Default to a 10 ms device period with 4 ms of additional buffering, and make detailed synchronization diagnostics opt-in through audio:debug. This reduces startup and steady-state latency while compensating for physical and virtual device clock drift without reacting to transport jitter or SPICE timestamp quantization.
This commit is contained in:
1198
client/src/audio.c
1198
client/src/audio.c
File diff suppressed because it is too large
Load Diff
@@ -32,7 +32,7 @@ void audio_playbackStart(int channels, int sampleRate, PSAudioFormat format,
|
||||
void audio_playbackStop(void);
|
||||
void audio_playbackVolume(int channels, const uint16_t volume[]);
|
||||
void audio_playbackMute(bool mute);
|
||||
void audio_playbackData(uint8_t * data, size_t size);
|
||||
void audio_playbackData(uint8_t * data, size_t size, uint32_t time);
|
||||
|
||||
bool audio_supportsRecord(void);
|
||||
void audio_recordStart(int channels, int sampleRate, PSAudioFormat format);
|
||||
|
||||
@@ -530,19 +530,26 @@ static struct Option options[] =
|
||||
},
|
||||
|
||||
// audio options
|
||||
{
|
||||
.module = "audio",
|
||||
.name = "debug",
|
||||
.description = "Enable audio synchronization diagnostics",
|
||||
.type = OPTION_TYPE_BOOL,
|
||||
.value.x_bool = false
|
||||
},
|
||||
{
|
||||
.module = "audio",
|
||||
.name = "periodSize",
|
||||
.description = "Requested audio device period size in samples",
|
||||
.description = "Requested audio device period size in samples (0 = 10 ms)",
|
||||
.type = OPTION_TYPE_INT,
|
||||
.value.x_int = 2048
|
||||
.value.x_int = 0
|
||||
},
|
||||
{
|
||||
.module = "audio",
|
||||
.name = "bufferLatency",
|
||||
.description = "Additional buffer latency in milliseconds",
|
||||
.type = OPTION_TYPE_INT,
|
||||
.value.x_int = 13
|
||||
.value.x_int = 4
|
||||
},
|
||||
{
|
||||
.module = "audio",
|
||||
@@ -763,6 +770,7 @@ bool config_load(int argc, char * argv[])
|
||||
g_params.largeCursorDot = option_get_bool("spice", "largeCursorDot");
|
||||
}
|
||||
|
||||
g_params.audioDebug = option_get_bool("audio", "debug");
|
||||
g_params.audioPeriodSize = option_get_int("audio", "periodSize");
|
||||
g_params.audioBufferLatency = option_get_int("audio", "bufferLatency");
|
||||
g_params.micShowIndicator = option_get_bool("audio", "micShowIndicator");
|
||||
|
||||
@@ -237,6 +237,7 @@ struct AppParams
|
||||
bool showCursorDot;
|
||||
bool largeCursorDot;
|
||||
|
||||
bool audioDebug;
|
||||
int audioPeriodSize;
|
||||
int audioBufferLatency;
|
||||
bool micShowIndicator;
|
||||
|
||||
Reference in New Issue
Block a user