From 4f90392f07e8822d1984ed990f622ad36022a4a3 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 9 Oct 2020 19:57:57 +0200 Subject: [PATCH] pcm: fix the snd_pcm_plugin_status() avail and delay fields The avail and delay fields in the returned status structure does not reflect the actual hw_ptr/appl_ptr. This change correct this. TODO: Unfortunately, the delay might contain also information about extra hardware / buffering delay which is hidden with this change. Link: https://lore.kernel.org/alsa-devel/d9c1f37e-5c8d-f289-270e-c6cda7a56ce3@axis.com/ Reported-by: Jonas Holmberg Tested-by: Jonas Holmberg Signed-off-by: Jaroslav Kysela --- src/pcm/pcm_plugin.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c index ea60eb98..5739cfc2 100644 --- a/src/pcm/pcm_plugin.c +++ b/src/pcm/pcm_plugin.c @@ -541,16 +541,20 @@ static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm) static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status) { snd_pcm_plugin_t *plugin = pcm->private_data; - snd_pcm_sframes_t err; + snd_pcm_sframes_t err, avail; /* sync with the latest hw and appl ptrs */ - snd_pcm_plugin_avail_update(pcm); + avail = snd_pcm_plugin_avail_update(pcm); + if (avail < 0) + return avail; err = snd_pcm_status(plugin->gen.slave, status); if (err < 0) return err; status->appl_ptr = *pcm->appl.ptr; status->hw_ptr = *pcm->hw.ptr; + status->avail = avail; + status->delay = snd_pcm_mmap_delay(pcm); return 0; } -- 2.47.1