mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-16 08:56:45 -05:00
alsa: subtract elapsed time from server delay only
Only subtract the elapsed time from the server delay. Our reported delay should always at least still include the data that we have buffered or else read and write operations might think they can read or write more than they actually can.
This commit is contained in:
parent
f58021ed45
commit
da9a5cfa5d
1 changed files with 9 additions and 6 deletions
|
|
@ -231,17 +231,20 @@ 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 = (io->rate * diff) / SPA_NSEC_PER_SEC;
|
||||
}
|
||||
|
||||
filled = pw->time.delay;
|
||||
|
||||
if (io->stream == SND_PCM_STREAM_PLAYBACK)
|
||||
filled -= SPA_MIN(elapsed, filled);
|
||||
else
|
||||
filled += elapsed;
|
||||
|
||||
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)
|
||||
*delayp = filled - SPA_MIN(elapsed, filled);
|
||||
else
|
||||
*delayp = filled + elapsed;
|
||||
*delayp = filled + avail;
|
||||
|
||||
pw_log_trace("avail:%"PRIi64" filled %"PRIi64" elapsed:%"PRIi64" delay:%ld hw:%lu appl:%lu",
|
||||
avail, filled, elapsed, *delayp, pw->hw_ptr, io->appl_ptr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue