[alsa-devel] [PATCH alsa-lib 2/2] pcm_plugin: Fix return value of snd_pcm_rewind

David Henningsson david.henningsson at canonical.com
Thu May 30 12:26:34 CEST 2013

In case the rewind did not rewind as much as expected, e g due to
time delay between the latest avail update and the rewind, we must
properly account for that in the plugin layer.

Otherwise, the plugin's appl ptr and the hw's appl ptr become
unsynchronised, which is very bad, especially in mmap_shadow plugins,
e g, this could cause the overlapping memcpy in the softvol plugin
as seen here:

Signed-off-by: David Henningsson <david.henningsson at canonical.com>
 src/pcm/pcm_plugin.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Btw, I was also considering always syncing the appl.ptr (for playback)
with the slave in snd_pcm_plugin_avail_update, like we do for the
hw.ptr. Do you think this would be a good idea?

diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
index 96218a8..17157e8 100644
--- a/src/pcm/pcm_plugin.c
+++ b/src/pcm/pcm_plugin.c
@@ -219,9 +219,9 @@ static snd_pcm_sframes_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t
 		return sframes;
-	snd_pcm_mmap_appl_backward(pcm, (snd_pcm_uframes_t) frames);
+	snd_pcm_mmap_appl_backward(pcm, (snd_pcm_uframes_t) sframes);
-	return (snd_pcm_sframes_t) frames;
+	return (snd_pcm_sframes_t) sframes;
 static snd_pcm_sframes_t snd_pcm_plugin_forwardable(snd_pcm_t *pcm)

More information about the Alsa-devel mailing list