From patchwork Mon Jul 2 14:53:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10502685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8737860532 for ; Mon, 2 Jul 2018 23:10:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73C6928C5B for ; Mon, 2 Jul 2018 23:10:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71FE828CAC; Mon, 2 Jul 2018 23:10:30 +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 4535828CED for ; Mon, 2 Jul 2018 23:10:28 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 100AE267737; Tue, 3 Jul 2018 01:10:27 +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 1636E267737; Tue, 3 Jul 2018 01:10:24 +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 3F2D026771C; Tue, 3 Jul 2018 01:10:17 +0200 (CEST) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 9D1C43C09AD; Mon, 2 Jul 2018 16:53:59 +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 NcW9cIrJgv5l; Mon, 2 Jul 2018 16:53:49 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id A1CD23C0160; Mon, 2 Jul 2018 16:53:49 +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.399.0; Mon, 2 Jul 2018 16:53:49 +0200 From: To: Date: Mon, 2 Jul 2018 16:53:06 +0200 Message-ID: <1530543186-20962-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] snd_interval_refine_first/last: exclude value only if also excluded before 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 commit the following intervals [x y), (x y) were be replaced to (y-1 y) by snd_interval_refine_last(). This was also done if y-1 is part of the previous interval. With this changes it will be replaced with [y-1 y) in case of y-1 is part of the previous interval. A similar behavior will be used for snd_interval_refine_first(). This solves the issue reported here: https://bugzilla.opensuse.org/show_bug.cgi?id=1033179 and work arounded with commit e736715 ("pcm: dmix: Disable var_periodsize as default"). I am able to reproduce the issue with a simplified aplay use case using the following configuration: pcm_slave.adr3_tdm_8ch { pcm { type hw card "Loopback" device 0 } rate 48000 period_size 128 buffer_size 1024 channels 2 } pcm.dshare_Playback_3 { type dmix ipc_key 600 ipc_perm 0660 ipc_gid audio var_periodsize true slave adr3_tdm_8ch } pcm.AdevAcousticoutSpeech { type rate slave.pcm dshare_Playback_3 slave.rate 48000 } $ modprobe snd_aloop $ aplay -v --period-size=352 -c2 -fS16_LE -r22500 -DAdevAcousticoutSpeech /dev/urandom ... Rule 9 (0xffff91d1f230): PERIODS=(0 2) -> NONE BUFFER_SIZE=480 PERIOD_SIZE=[240 240] refine_soft 'AdevAcousticoutSpeech' (end--22) ... aplay: ../../alsa-utils-1.1.5/aplay/aplay.c:1390: set_params: Assertion `err >= 0' failed. Aborted by signal Aborted... The following stack trace shows where the -EINVAL will be thrown: __snd_pcm_hw_params_set_period_size_near() snd1_pcm_hw_param_set_near() snd1_pcm_hw_param_set_last() snd1_pcm_hw_refine_slave() snd1_pcm_hw_refine_soft() snd_pcm_hw_rule_div() snd1_interval_refine() This issue exists due to PERIODS does not include 2 Rule 9 (0xffff91d1f230): PERIODS=(0 9) -> (0 2) BUFFER_SIZE=[120 480] PERIOD_SIZE=(240 241) because of an invalid integer inverval of PERIOD_SIZE of (240 241). This interval is set by snd_interval_refine_last(). Signed-off-by: Timo Wischer --- src/pcm/interval.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pcm/interval.c b/src/pcm/interval.c index 95cedd5..ef4c2ed 100644 --- a/src/pcm/interval.c +++ b/src/pcm/interval.c @@ -200,27 +200,33 @@ int snd_interval_refine(snd_interval_t *i, const snd_interval_t *v) int snd_interval_refine_first(snd_interval_t *i) { + const unsigned int last_max = i->max; + if (snd_interval_empty(i)) return -ENOENT; if (snd_interval_single(i)) return 0; i->max = i->min; - i->openmax = i->openmin; - if (i->openmax) + if (i->openmin) i->max++; + /* only exclude max value if also excluded before refine */ + i->openmax = (i->openmax && i->max >= last_max); return 1; } int snd_interval_refine_last(snd_interval_t *i) { + const unsigned int last_min = i->min; + if (snd_interval_empty(i)) return -ENOENT; if (snd_interval_single(i)) return 0; i->min = i->max; - i->openmin = i->openmax; - if (i->openmin) + if (i->openmax) i->min--; + /* only exclude min value if also excluded before refine */ + i->openmin = (i->openmin && i->min <= last_min); return 1; }