From 955dde5272b3ba10dbab87514801d5324877c08a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 24 Nov 2021 13:09:24 +0100 Subject: [PATCH] alsa-plugin: use hw_avail in _delay for playback for playback streams we want to include the hw_avail, which is the amount of data that the hardware can read or the amount of data the application has written. This is in contrast to using _avail for the capture stream, which is what the application can read. hw_avail for a capture stream is how many samples the hardware can write or the amount of free space. See #1697 --- pipewire-alsa/alsa-plugins/pcm_pipewire.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pipewire-alsa/alsa-plugins/pcm_pipewire.c b/pipewire-alsa/alsa-plugins/pcm_pipewire.c index 4eceb5fd7..ab01dddda 100644 --- a/pipewire-alsa/alsa-plugins/pcm_pipewire.c +++ b/pipewire-alsa/alsa-plugins/pcm_pipewire.c @@ -223,7 +223,11 @@ static int snd_pcm_pipewire_delay(snd_pcm_ioplug_t *io, snd_pcm_sframes_t *delay diff = SPA_TIMESPEC_TO_NSEC(&ts) - pw->time.now; elapsed = (pw->time.rate.denom * diff) / (pw->time.rate.num * SPA_NSEC_PER_SEC); } - avail = snd_pcm_ioplug_avail(io, pw->hw_ptr, io->appl_ptr); + if (io->stream == SND_PCM_STREAM_PLAYBACK) + avail = snd_pcm_ioplug_hw_avail(io, pw->hw_ptr, io->appl_ptr); + else + avail = snd_pcm_ioplug_avail(io, pw->hw_ptr, io->appl_ptr); + filled = pw->time.delay + avail; if (io->stream == SND_PCM_STREAM_PLAYBACK) @@ -231,8 +235,8 @@ static int snd_pcm_pipewire_delay(snd_pcm_ioplug_t *io, snd_pcm_sframes_t *delay else *delayp = filled + elapsed; - pw_log_trace("avail:%"PRIi64" filled %"PRIi64" elapsed:%"PRIi64" delay:%ld", - avail, filled, elapsed, *delayp); + pw_log_trace("avail:%"PRIi64" filled %"PRIi64" elapsed:%"PRIi64" delay:%ld %lu %lu", + avail, filled, elapsed, *delayp, pw->hw_ptr, io->appl_ptr); return 0; }