From patchwork Thu Apr 5 08:22:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Wei X-Patchwork-Id: 7651 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2744023E47 for ; Thu, 5 Apr 2012 08:22:43 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id A84A0A184E5 for ; Thu, 5 Apr 2012 08:22:42 +0000 (UTC) Received: by iage36 with SMTP id e36so2007158iag.11 for ; Thu, 05 Apr 2012 01:22:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :x-spamscore:x-bigfish:x-forefront-antispam-report :x-fb-domain-ip-match:from:to:cc:subject:date:message-id:x-mailer :mime-version:content-type:x-originatororg:x-gm-message-state; bh=TIwvOKpKA/fM6X1qcbGthDrmMF3lq9IJCwZWBo0jqN0=; b=jcGsrIjlx1FvrHnbozh5NxX78bs/a0g75YVywAktn062Rn6644+JSfI0tjKeAGpauY F/Bp/+Z4Dq0XqXOXvHnKpc+V0ln2Hs/HinHh+NACKa2f/V5rtqsEx8DQ5uWfDtZOCf3V lO5kexAevdqs9eYvKpGquEOVc5HgFOTHqNPDjmokEXLf7mbURo3InOHuLVLZ8VajYx29 21yjerE1hf3ha7T6BUU0DMPlRrcLSuvMBO07PyY8tvgedfK9kF72rJDKa8eqj6cobBqa apJquqelvUZQNM3HqjGxIPaAciFKBjtGBwoW5pUNNj5VBYCvT/IQq74He79K+gAyAd7j 9L0g== Received: by 10.50.194.232 with SMTP id hz8mr1037207igc.38.1333614161854; Thu, 05 Apr 2012 01:22:41 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.164.217 with SMTP id f25csp49910iby; Thu, 5 Apr 2012 01:22:41 -0700 (PDT) Received: by 10.180.102.101 with SMTP id fn5mr2544193wib.6.1333614160066; Thu, 05 Apr 2012 01:22:40 -0700 (PDT) Received: from db3outboundpool.messaging.microsoft.com (db3ehsobe005.messaging.microsoft.com. [213.199.154.143]) by mx.google.com with ESMTPS id w74si3502153weq.59.2012.04.05.01.22.38 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 05 Apr 2012 01:22:40 -0700 (PDT) Received-SPF: neutral (google.com: 213.199.154.143 is neither permitted nor denied by best guess record for domain of feng.wei@linaro.org) client-ip=213.199.154.143; Authentication-Results: mx.google.com; spf=neutral (google.com: 213.199.154.143 is neither permitted nor denied by best guess record for domain of feng.wei@linaro.org) smtp.mail=feng.wei@linaro.org Received: from mail111-db3-R.bigfish.com (10.3.81.234) by DB3EHSOBE002.bigfish.com (10.3.84.22) with Microsoft SMTP Server id 14.1.225.23; Thu, 5 Apr 2012 08:22:38 +0000 Received: from mail111-db3 (localhost [127.0.0.1]) by mail111-db3-R.bigfish.com (Postfix) with ESMTP id 5B7EF380083; Thu, 5 Apr 2012 08:22:38 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275dhz2dh87h2a8h668h839hd24h) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-FB-DOMAIN-IP-MATCH: fail Received: from mail111-db3 (localhost.localdomain [127.0.0.1]) by mail111-db3 (MessageSwitch) id 1333614157529691_24632; Thu, 5 Apr 2012 08:22:37 +0000 (UTC) Received: from DB3EHSMHS007.bigfish.com (unknown [10.3.81.242]) by mail111-db3.bigfish.com (Postfix) with ESMTP id 7B188160099; Thu, 5 Apr 2012 08:22:37 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by DB3EHSMHS007.bigfish.com (10.3.87.107) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 5 Apr 2012 08:22:37 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server (TLS) id 14.1.355.3; Thu, 5 Apr 2012 03:22:35 -0500 Received: from wayne-Latitude-E6410.ap.freescale.net ([10.213.130.145]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id q358MXrW027565; Thu, 5 Apr 2012 01:22:34 -0700 From: Feng Wei To: CC: , Feng Wei Subject: [PATCH] Fix unused buffer size to avoid xrun Date: Thu, 5 Apr 2012 16:22:20 +0800 Message-ID: <1333614140-9785-1-git-send-email-feng.wei@linaro.org> X-Mailer: git-send-email 1.7.4.1 MIME-Version: 1.0 X-OriginatorOrg: sigmatel.com X-Gm-Message-State: ALoCoQnlyLxXt5aWvAUXnQ14EAw4GC2DVMzr/2tZkg+btLOj8S08id4OArpO8RgmcuFtL37O+3wc When set latency is less than period time, we will assgin working buffer less than a period size, which will cause unnecessary xrun and wrong message indicating alsa driver bug. Signed-off-by: Feng Wei --- src/modules/alsa/alsa-sink.c | 6 +++--- src/modules/alsa/alsa-source.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c index 5a4b606..a53fb6f 100644 --- a/src/modules/alsa/alsa-sink.c +++ b/src/modules/alsa/alsa-sink.c @@ -953,10 +953,10 @@ static int update_sw_params(struct userdata *u) { b = pa_usec_to_bytes(latency, &u->sink->sample_spec); - /* We need at least one sample in our buffer */ + /* We need at least one period and one sample in our buffer to avoid underflow */ - if (PA_UNLIKELY(b < u->frame_size)) - b = u->frame_size; + if (PA_UNLIKELY(b < u->frame_size + u->fragment_size)) + b = u->frame_size + u->fragment_size; u->hwbuf_unused = PA_LIKELY(b < u->hwbuf_size) ? (u->hwbuf_size - b) : 0; } diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c index 27fd3b9..8c41ca6 100644 --- a/src/modules/alsa/alsa-source.c +++ b/src/modules/alsa/alsa-source.c @@ -876,10 +876,10 @@ static int update_sw_params(struct userdata *u) { b = pa_usec_to_bytes(latency, &u->source->sample_spec); - /* We need at least one sample in our buffer */ + /* We need at least one period and one sample in our buffer to avoid overflow */ - if (PA_UNLIKELY(b < u->frame_size)) - b = u->frame_size; + if (PA_UNLIKELY(b < u->frame_size + u->fragment_size)) + b = u->frame_size + u->fragment_size; u->hwbuf_unused = PA_LIKELY(b < u->hwbuf_size) ? (u->hwbuf_size - b) : 0; }