]> git.alsa-project.org Git - alsa-lib.git/commit
pcm: add a loop to snd_pcm_avail_delay() to avoid bogus delay values
authorKai Vehmanen <kai.vehmanen@linux.intel.com>
Thu, 31 Jul 2025 12:37:33 +0000 (15:37 +0300)
committerJaroslav Kysela <perex@perex.cz>
Thu, 31 Jul 2025 13:25:18 +0000 (15:25 +0200)
commit5f524e300409f0a7b54c5fe9ee194bad1fc39516
tree20da60c3e32cb2170fbabe15ca8207994fe68762
parentee5a58f48e141aeb28df182247c3f789f4160d02
pcm: add a loop to snd_pcm_avail_delay() to avoid bogus delay values

snd_pcm_avail_delay() is expected to report avail and delay values
in atomic fashion. However the function does two separate syscalls
and it cannot guarantee the avail value is the same as was used
to calculate the delay. This is a problem as the reported delay is
always relative to avail frames value.

If application (like e.g. alsa_conformance_test) uses snd_pcm_avail_delay()
to estimate the effective play position, it can observe bogus delay
values (and effective play position going backwards) if
snd_pcm_avail_delay() is called during a DMA burst where hw_ptr
moves quickly.

This commit adds a loop similar to that used in snd_pcm_hw_htimestamp()
to wait until we get a stable avail reading, and only then extract
the delay. This will avoid bogus values if function is called during
DMA bursts.

Closes: https://github.com/alsa-project/alsa-lib/pull/469
Closes: https://github.com/alsa-project/alsa-lib/issues/468
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/pcm/pcm.c