[PATCH] Pulse: Fix snd_pcm_avail returning 0 in some cases

David Henningsson david.henningsson at canonical.com
Thu Apr 21 15:10:19 CEST 2011


Due to a round-off error, snd_pcm_avail could in some cases
return 0 even though more data could be written to the stream.

Reported-by: Maarten Lankhorst <m.b.lankhorst at gmail.com>
Signed-off-by: David Henningsson <david.henningsson at canonical.com>
---
 pulse/pcm_pulse.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/pulse/pcm_pulse.c b/pulse/pcm_pulse.c
index 2df0a80..9105d4d 100644
--- a/pulse/pcm_pulse.c
+++ b/pulse/pcm_pulse.c
@@ -92,8 +92,8 @@ static int update_ptr(snd_pcm_pulse_t *pcm)
 		size -= pcm->offset;
 
 	/* Prevent accidental overrun of the fake ringbuffer */
-	if (size >= pcm->buffer_attr.tlength)
-		size = pcm->buffer_attr.tlength-1;
+	if (size > pcm->buffer_attr.tlength - pcm->frame_size)
+		size = pcm->buffer_attr.tlength - pcm->frame_size;
 
 	if (size > pcm->last_size) {
 		pcm->ptr += size - pcm->last_size;
-- 
1.7.4.1


--------------090807090806050001010504--


More information about the Alsa-devel mailing list