In mmap_emul mode the mmap_emul PCM keeps its own appl_ptr apart from
the slave. A playback commit forwards it and then writes the new frames
to the slave with sync_slave_write(). The commit returns the full size
even when that write fails or comes up short, for example after an xrun.
The status op was snd_pcm_generic_status(), which returns the slave
appl_ptr. When a plugin such as softvol sits above mmap_emul, its
appl_ptr follows the mmap_emul one. After a short write the two differ
and snd_pcm_plugin_status() aborts on
This happens with any hw PCM whose driver lacks mmap support when it is
used through plug with softvol above it, on the first xrun followed by
snd_pcm_status(). We hit it on an LG SoC whose ALSA driver only offers
RW access, where mpv aborts on the first xrun.
It also reproduces without hardware, with a linear PCM over mmap_emul
over an ioplug slave that offers only RW_INTERLEAVED access and fails
one transfer. Whether that transfer returns -EPIPE (state XRUN) or
-EIO, the next snd_pcm_status() on the linear PCM aborts.
Add a status op that reports the mmap_emul appl_ptr in emulation mode
for playback. It takes the frames not yet written to the slave out of
avail, and adds them to delay only while the stream is running or
draining, because the kernel status reports no delay in other states.
A count above the buffer size means the two appl_ptrs are out of sync,
as after snd_pcm_reset() on a running stream, and is ignored.
Non-emulated and capture streams are unchanged.
Closes: https://github.com/alsa-project/alsa-lib/pull/541 Signed-off-by: Andy Saul <asaul@brightsign.biz> Signed-off-by: Jaroslav Kysela <perex@perex.cz>