From patchwork Thu Oct 18 11:33:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10647091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4568A3B73 for ; Thu, 18 Oct 2018 12:51:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35FA7287A5 for ; Thu, 18 Oct 2018 12:51:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29D882887A; Thu, 18 Oct 2018 12:51:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6822287A5 for ; Thu, 18 Oct 2018 12:51:48 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id AFE6F267875; Thu, 18 Oct 2018 13:33:40 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5B11D267875; Thu, 18 Oct 2018 13:33:38 +0200 (CEST) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [62.225.105.245]) by alsa0.perex.cz (Postfix) with ESMTP id 864222675B5; Thu, 18 Oct 2018 13:33:34 +0200 (CEST) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 2F0873C02EC; Thu, 18 Oct 2018 13:33:34 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Fv907V48RnFh; Thu, 18 Oct 2018 13:33:28 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 3E31F3C013F; Thu, 18 Oct 2018 13:33:28 +0200 (CEST) Received: from vmlxhi-087.adit-jv.com (10.72.93.172) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 18 Oct 2018 13:33:27 +0200 From: To: Date: Thu, 18 Oct 2018 13:33:24 +0200 Message-ID: <1539862404-21955-1-git-send-email-twischer@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.72.93.172] Cc: Timo Wischer , alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - Intervals v2 1/1] interval: Interpret (x x+1] correctly and return x+1 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Timo Wischer Without this change an interval of (x x+1] will be interpreted as an empty interval but the right value would be x+1. This leads to a failing snd_pcm_hw_params() call which returns -EINVAL. An example issue log is given in the following: snd_pcm_hw_params failed with err -22 (Invalid argument) ACCESS: MMAP_NONINTERLEAVED FORMAT: S16_LE SUBFORMAT: STD SAMPLE_BITS: 16 FRAME_BITS: 16 CHANNELS: 1 RATE: 16000 PERIOD_TIME: (15999 16000] PERIOD_SIZE: (255 256] PERIOD_BYTES: (510 512] PERIODS: [2 3) BUFFER_TIME: 32000 BUFFER_SIZE: 512 BUFFER_BYTES: 1024 In case of (x x+1) we have to interpret it anyway as a single value of x to compensate rounding issues. For example the period size will result in an interval of (352 353) when the period time is 16ms and the sample rate 22050 Hz (16ms * 22,05 kHz = 352,8 frames). But 352 has to be chosen to allow a buffer size of 705 (32ms * 22,05 kHz = 705,6 frames) which has to be >= 2x period size to avoid Xruns. The buffer size will not end up with an interval of (705 706) simular to the period size because snd_pcm_rate_hw_refine_cchange() calls snd_interval_floor() for the buffer size. Therefore this value will be interpreted as an integer interval instead of a real interval further on. This issue seems to exist since the change of 9bb985c38 ("pcm: snd_interval_refine_first/last: exclude value only if also excluded before") Signed-off-by: Timo Wischer Signed-off-by: Timo Wischer --- > On 10/18/18 12:57, Takashi Iwai wrote: > This change looks risky. The snd_interval_value() might be called > even if the interval isn't reduced to a single value. Rather check > openmin instead. If I would do "if (i->openmin)" on an interval of (x x+1) x+1 would be returned. But this would result in the second issue which I have tried to describe in the commit message: x has to be returned otherwise it is not guaranteed that buffer_size >= 2x period_size. And this would result in continuously Xruns. Therefore I would like to prefer "if (i->openmin && !i->openmax)" diff --git a/src/pcm/interval_inline.h b/src/pcm/interval_inline.h index a68e292..d9a30b2 100644 --- a/src/pcm/interval_inline.h +++ b/src/pcm/interval_inline.h @@ -51,12 +51,14 @@ INTERVAL_INLINE int snd_interval_single(const snd_interval_t *i) { assert(!snd_interval_empty(i)); return (i->min == i->max || - (i->min + 1 == i->max && i->openmax)); + (i->min + 1 == i->max && (i->openmin || i->openmax))); } INTERVAL_INLINE int snd_interval_value(const snd_interval_t *i) { assert(snd_interval_single(i)); + if (i->openmin && !i->openmax) + return i->max; return i->min; }