All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Henningsson <david.henningsson@canonical.com>
To: alsa-devel@alsa-project.org
Cc: General PulseAudio Discussion
	<pulseaudio-discuss@mail.0pointer.de>,
	Maarten Lankhorst <m.b.lankhorst@gmail.com>
Subject: [PATCH] Alsa-plugins: Pulse: Fix snd_pcm_avail returning 0 in some cases
Date: Thu, 21 Apr 2011 15:22:18 +0200	[thread overview]
Message-ID: <4DB02F8A.4040001@canonical.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 500 bytes --]

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.

This was discovered by Maarten Lankhorst [1], and there is also a test 
program available that triggers this error [2].

[1] 
https://tango.0pointer.de/pipermail/pulseaudio-discuss/2011-April/009935.html

[2] 
https://tango.0pointer.de/pipermail/pulseaudio-discuss/attachments/20110420/3c852d6e/attachment.c


-- 
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic

[-- Attachment #2: 0001-Pulse-Fix-snd_pcm_avail-returning-0-in-some-cases.patch --]
[-- Type: text/x-patch, Size: 1119 bytes --]

>From 73ff6f83e1e4c53181e1794bf2cec3baee7c81b7 Mon Sep 17 00:00:00 2001
From: David Henningsson <david.henningsson@canonical.com>
Date: Thu, 21 Apr 2011 15:10:19 +0200
Subject: [PATCH] Pulse: Fix snd_pcm_avail returning 0 in some cases

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@gmail.com>
Signed-off-by: David Henningsson <david.henningsson@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


[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



             reply	other threads:[~2011-04-21 13:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-21 13:22 David Henningsson [this message]
2011-04-21 23:25 ` [PATCH] Alsa-plugins: Pulse: Fix snd_pcm_avail returning 0 in some cases Raymond Yau
2011-04-26  8:01   ` David Henningsson
2011-04-26 14:39     ` Takashi Iwai
2011-05-07  3:18       ` Raymond Yau
2011-04-27  1:00     ` Raymond Yau
2011-04-29  2:32     ` Raymond Yau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DB02F8A.4040001@canonical.com \
    --to=david.henningsson@canonical.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=m.b.lankhorst@gmail.com \
    --cc=pulseaudio-discuss@mail.0pointer.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.