From owner-freebsd-multimedia@FreeBSD.ORG Sun Feb 3 13:32:18 2013 Return-Path: Delivered-To: freebsd-multimedia@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 766C376F; Sun, 3 Feb 2013 13:32:18 +0000 (UTC) (envelope-from mavbsd@gmail.com) Received: from mail-bk0-f47.google.com (mail-bk0-f47.google.com [209.85.214.47]) by mx1.freebsd.org (Postfix) with ESMTP id D344580C; Sun, 3 Feb 2013 13:32:17 +0000 (UTC) Received: by mail-bk0-f47.google.com with SMTP id jc3so2367237bkc.6 for ; Sun, 03 Feb 2013 05:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=zmgUdIy+wkDWZmJyO3BNrfA95w1ZOSvJVe3mrpcyF5s=; b=eli0wFM2BjYRTlVK+GG3eozJNrYBCjHdCcJz7piZxylGcrlew4iwhJonm+1G+FOffr CzfI1jmftmpWLkPKMf/SFoRntMPtWETp1rge85H81ux1guokyHyQTDN6CN+IHxbEVFTj w3kc4gRKM0YHIOu30TduJhNQf7n0L2+xOG9O/7krBT5Q2xFbBREFCtNMzL5ufPg59tDK BeQvMUsooe/8a9pjgyaWe7f1ufwxZQSO3vKiANgfCMKJ3wC/QAKu2qw3C16S01FkQrGf sFyu87NV6QpBCe8iIKcQ+dBb7rXtnCdd2HnzntqgdDaFUfkwc5tXkZFJXyO1lqB2H0MH BcMw== X-Received: by 10.204.4.81 with SMTP id 17mr4807529bkq.137.1359898331117; Sun, 03 Feb 2013 05:32:11 -0800 (PST) Received: from mavbook.mavhome.dp.ua (mavhome.mavhome.dp.ua. [213.227.240.37]) by mx.google.com with ESMTPS id n1sm4368188bkv.14.2013.02.03.05.32.08 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 03 Feb 2013 05:32:09 -0800 (PST) Sender: Alexander Motin Message-ID: <510E66D7.9070608@FreeBSD.org> Date: Sun, 03 Feb 2013 15:32:07 +0200 From: Alexander Motin User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:17.0) Gecko/20130125 Thunderbird/17.0.2 MIME-Version: 1.0 To: Andriy Gapon Subject: Re: sound(4) vs alsa oss plugin References: <5103A438.9010806@FreeBSD.org> <5108111F.3080205@FreeBSD.org> <510E3F5F.8090104@FreeBSD.org> In-Reply-To: <510E3F5F.8090104@FreeBSD.org> Content-Type: text/plain; charset=x-viet-vps Content-Transfer-Encoding: 7bit Cc: freebsd-multimedia@FreeBSD.org X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Feb 2013 13:32:18 -0000 On 03.02.2013 12:43, Andriy Gapon wrote: > on 29/01/2013 20:12 Alexander Motin said the following: >> I am not sure how it supposed to work in Linux, but IMHO it is obvious >> that single ptr field is not sufficient in such conditions to identify >> full buffer wrap. Additional checks for bytes or blocks fields could >> help, but that is user-level side. I am not sure what kernel can do >> about it. > > I have a very nasty local kernel-side hack that "fixes up" 'ptr' wrap-around > based on a check of 'blocks'. > But root causes are, of course: > - an application using sleep and GET*PTR for interacting with OSS > - ALSA OSS using just 'ptr' > - a 10 millisecond sleep taking e.g. 100 milliseconds once in a while (or under > some circumstances) > >> From the other side, case when buffer wrapped completely is IMHO already >> fatal situation. It means that we are already late -- hardware already >> started to either play or overwrite previous buffer. That is probably >> not much better then if we would woke up some samples later. > > Well, some sound distortion/corruption is very bad, but completely blocked sound > is even worse. > > I have the following patch for ALSA OSS, but haven't tested it yet: > diff --git a/oss/pcm_oss.c b/oss/pcm_oss.c > index d43b44c..4729962 100644 > --- a/oss/pcm_oss.c > +++ b/oss/pcm_oss.c > @@ -83,7 +83,13 @@ static snd_pcm_sframes_t oss_pointer(snd_pcm_ioplug_t *io) > fprintf(stderr, "*** OSS: oss_pointer error\n"); > return 0; > } > - ptr = snd_pcm_bytes_to_frames(io->pcm, info.ptr); > + > + /* > + * Note that the following calculations will produce a temporary glitch > + * when info.bytes wraps around UINT_MAX or INT_MAX depending on type > + * of info.bytes in an OSS implementation. > + */ > + ptr = snd_pcm_bytes_to_frames(io->pcm, info.bytes) % io->buffer_size; > return ptr; > } > > What is the idea of this patch? Won't calculated result be exactly the same? -- Alexander Motin