Skip to contentSkip to conversation

Is function delay of the pulse plugin correct?

DISCUSSION Pavel Hofman 1 participant 1 message Jan 19, 2025

lore
Share & tools
lore
#0 lore raw

Hi,

Please correct me if I am wrong: "avail" means (buffer - buffer_fill), while "delay" means (buffer_fill + device/downstream delay/latency). Some drivers/devices do not track the device delay, and then delay = buffer_fill.

While troubleshooting some playback code, I hit that snd_pcm_delay on the plugin pulse (device pulse) was always returning 0 frames, while snd_pcm_avail was returning dynamic (correct) values.

IIUC while pulse_pcm.c uses generic code for avail, it overrides the generic snd_pcm_ioplug_delay
https://github.com/alsa-project/alsa-lib/blob/35d2efefa95d28e0cd963a06e051f8125823f077/src/pcm/pcm_ioplug.c#L110
with specific pulse_delay
https://github.com/alsa-project/alsa-plugins/blob/52574cb5ccbb8b546df2759e4b341a20332269b6/pulse/pcm_pulse.c#L379
. IIUC this method returns only delay obtained from Pulseaudio, i.e. no fill of the pulse plugin buffer is included. And IIUC in this specific case pulseaudio keeps returning zero for the pa_stream_get_latency call, making snd_pcm_delay return zero too. Therefore the equation (buffer size = avail + delay - driver/device delay) does not seem to hold for the pulse plugin.

The new pipewire plugin does not seem to override the generic snd_pcm_ioplug_delay method
https://github.com/PipeWire/pipewire-alsa/blob/master/alsa-plugins/pcm_pipewire.c#L691-L702
.

Please, is that behavior correct?

With regards,

Pavel.