From patchwork Wed May 15 06:26:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Channaiah Vanitha (RBEI/ECF3)" X-Patchwork-Id: 10944291 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 C9447912 for ; Wed, 15 May 2019 06:47:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B78E0289BF for ; Wed, 15 May 2019 06:47:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABF82289CB; Wed, 15 May 2019 06:47:05 +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,DKIM_SIGNED, DKIM_VALID,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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D51C5289BF for ; Wed, 15 May 2019 06:47:04 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 2D6EB825; Wed, 15 May 2019 08:46:13 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2D6EB825 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1557902823; bh=ZRGzEpq2LmFGhXq16rjkWrpeMuk0JmTevA3Bw3rv960=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lOtDOr9/+wCzsyPH7rEUD7k3BZMtWpZSNH6/pGJaruO+FAI5ZB1uqsfaAS3uag07T VlZYcdCKqLKCfRgxwu7FfRG0SYZywvjENAQ0d24eoqtfRHlja1BHzzsl3AFYNEVRCN Iwz104aj+gxaIvLPVj1kCAO6B0HmD35U74q3oAdo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C7C66F89708; Wed, 15 May 2019 08:45:07 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 94AF7F89708; Wed, 15 May 2019 08:44:59 +0200 (CEST) Received: from de-out1.bosch-org.com (de-out1.bosch-org.com [139.15.230.186]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 0A31BF89684; Wed, 15 May 2019 08:44:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0A31BF89684 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=in.bosch.com header.i=@in.bosch.com header.b="oaL2qrZR" Received: from si0vm1947.rbesz01.com (unknown [139.15.230.188]) by si0vms0217.rbdmz01.com (Postfix) with ESMTPS id 453lR92TlNz4f3m1b; Wed, 15 May 2019 08:44:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=in.bosch.com; s=2015-01-21; t=1557902693; bh=j9ghyqlcIsq1VvBEl8XAwe9fmi0UKdHNOBlJj7mLn+I=; l=10; h=From:Subject:From:Reply-To:Sender; b=oaL2qrZRIP5uqBmnPzEvheI+ejP5ESE6VPhCFvHBkLkgQ96+VRtBKlCBvi1Y2W28S Ncieu6/OkSRvH3YMU04J8SGrIX8d8VGlFj62PBMUkATxiODyx0oMr9up9xPBCINB07 3ui2EAyF+GNomoasgLeHPsG/2s0gT9Y6qtN9+6/Y= Received: from si0vm02576.rbesz01.com (unknown [10.58.172.176]) by si0vm1947.rbesz01.com (Postfix) with ESMTPS id 453lR9244gz6CjQSL; Wed, 15 May 2019 08:44:53 +0200 (CEST) X-AuditID: 0a3aad0d-173ff700000036fe-c8-5cdbb5652519 Received: from fe0vm1652.rbesz01.com ( [10.58.173.29]) (using TLS with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by si0vm02576.rbesz01.com (SMG Outbound) with SMTP id 3C.F9.14078.565BBDC5; Wed, 15 May 2019 08:44:53 +0200 (CEST) Received: from FE-HUB2000.de.bosch.com (unknown [10.4.103.109]) by fe0vm1652.rbesz01.com (Postfix) with ESMTPS id 453lR90S6rz5gK; Wed, 15 May 2019 08:44:53 +0200 (CEST) Received: from localhost.localdomain (10.47.103.61) by FE-HUB2000.de.bosch.com (10.4.103.109) with Microsoft SMTP Server id 15.1.1713.5; Wed, 15 May 2019 08:44:51 +0200 From: To: , Date: Wed, 15 May 2019 11:56:32 +0530 Message-ID: <1557901597-19215-2-git-send-email-vanitha.channaiah@in.bosch.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> References: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.47.103.61] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrALsWRmVeSWpSXmKPExsXCZbVWVjd16+0Yg61TuCyuXDzEZLF2eQOr xcvNb5gsFk2byeTA4rHhcxObx6z21ewem09XBzBHcdmkpOZklqUW6dslcGVcXtPFWvBatWL/ uVssDYw/5LsYOTkkBEwkzixrY+xi5OIQEpjJJPFm0kNWCGcNo8TXSbuZ4JzJO9eyg7SwCahJ HLn2AcwWEdCVePp4EhuIzSxQJDFx9gYmEFtYIE3i6MqNYDUsAqoSPw+3s4LYvAJ+Eq0/nrNC rJaTuHmukxnE5hTwl9j26SELiC0EVHN78TtmiHpBiZMzn7BAzJeQOPjiBTNEr4LElGszWCcw CsxCUjYLSdkCRqZVjGLFmQZluQZGpuZmekVJqcVVBoZ6yfm5mxghAcq7g/Hct7RDjAIcjEo8 vCWLbscIsSaWFVfmHmI05WBSEuVtSQMK8SXlp1RmJBZnxBeV5qQWK0nxylzwihEShgsXlybl ZhYXZ+bnHWKU4GBWEuGNUrwRI8SbklhZlVqUD9F2iFGag0VJnDedwz9GSCA9sSQ1OzW1ILUI JmvNwaEkwRu/BWihYFFqempFWmZOCUxaSZaXkYGBQUgMWQbZWiYOzkOMxhw8QLtvgYzgLS5I zC3OTIdql4RoF4KJIrSeYjSXEue1AekRAMlmlObBbZWS4b329nqMkCiSBELnK8brjMBwE+ad ugmomQeYVhH2SfBKg4JIECqI0GS0GKhHoJVbYsJlHYn9EwMlDn/YxSgxb8dXRokp6xeySVza NYtd4syxCZwS63oOckrs+/WTU2LOw/dcEqvfzOOWWHxnLo/EjOtbeCW27rojILHk4iMRiamd 90QlfrxrFpfYcuqNhMSah+ekJTr2PJOWuLnhmIzE/1cvZSTudX2RkTh/sF8RxFWUuPRrsbLE yXvfVCT2NaxUlThzdZOWxJGfT3Ul7k1p1ZPY8WW93itgUDIBg9Iy8xYoKEsSS7AEJVQU4Tep BkbLQykRZ86VV1ROOljvpnNn7WvucIf//fMW9wj4rmJ3aeJKVXIwjotmCRdt/7h5ihoXN9OD Nznysw/YuC9iPZ9QrMUZtzsrRGf+ZzaF/3+2i7jrft7rdDb+zsnJeyXOG84PeTm33Es7q/ue lvGO0KYSv8Y4ht4bv5hlHpRLXi7Y9NWq8uC1rUosxRmJhlrMRcWJAKHjVBxDBAAA Cc: twischer@de.adit-jv.com, alsa-devel@alsa-project.org, Vanitha Channaiah Subject: [alsa-devel] [PATCH v2 1/6] pcm: direct: Add generic hw_ptr_alignment function for dmix, dshare and dsnoop X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" X-Virus-Scanned: ClamAV using ClamSMTP From: Vanitha Channaiah Move the code snd_pcm_direct_reset_slave_ptr() from pcm_dmix.c to pcm_direct.c and its header so that the helper function can be re-used by other direct-pcm plugins. There is no change in the behavior or the functionality. Signed-off-by: Vanitha Channaiah --- src/pcm/pcm_direct.c | 19 +++++++++++++++++++ src/pcm/pcm_direct.h | 8 ++++++++ src/pcm/pcm_dmix.c | 25 ++----------------------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index 666a8ce..411a035 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -2040,3 +2040,22 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf, return 0; } + +void snd_pcm_direct_reset_slave_ptr(snd_pcm_t *pcm, snd_pcm_direct_t *dmix) +{ + dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr; + + if (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_ROUNDUP || + (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_AUTO && + pcm->buffer_size <= pcm->period_size * 2)) + dmix->slave_appl_ptr = + ((dmix->slave_appl_ptr + dmix->slave_period_size - 1) / + dmix->slave_period_size) * dmix->slave_period_size; + else if (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_ROUNDDOWN || + (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_AUTO && + (dmix->slave_period_size * SEC_TO_MS) / + pcm->rate < LOW_LATENCY_PERIOD_TIME)) + dmix->slave_appl_ptr = dmix->slave_hw_ptr = + ((dmix->slave_hw_ptr / dmix->slave_period_size) * + dmix->slave_period_size); +} diff --git a/src/pcm/pcm_direct.h b/src/pcm/pcm_direct.h index da5e280..a71aab1 100644 --- a/src/pcm/pcm_direct.h +++ b/src/pcm/pcm_direct.h @@ -24,6 +24,11 @@ #define DIRECT_IPC_SEMS 1 #define DIRECT_IPC_SEM_CLIENT 0 +/* Seconds representing in Milli seconds */ +#define SEC_TO_MS 1000 +/* slave_period time for low latency requirements in ms */ +#define LOW_LATENCY_PERIOD_TIME 10 + typedef void (mix_areas_t)(unsigned int size, volatile void *dst, void *src, @@ -257,6 +262,8 @@ struct snd_pcm_direct { snd1_pcm_direct_get_chmap #define snd_pcm_direct_set_chmap \ snd1_pcm_direct_set_chmap +#define snd_pcm_direct_reset_slave_ptr \ + snd1_pcm_direct_reset_slave_ptr int snd_pcm_direct_semaphore_create_or_connect(snd_pcm_direct_t *dmix); @@ -341,6 +348,7 @@ int snd_pcm_direct_slave_recover(snd_pcm_direct_t *direct); int snd_pcm_direct_client_chk_xrun(snd_pcm_direct_t *direct, snd_pcm_t *pcm); int snd_timer_async(snd_timer_t *timer, int sig, pid_t pid); struct timespec snd_pcm_hw_fast_tstamp(snd_pcm_t *pcm); +void snd_pcm_direct_reset_slave_ptr(snd_pcm_t *pcm, snd_pcm_direct_t *dmix); struct snd_pcm_direct_open_conf { key_t ipc_key; diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c index c5592cd..dcde40d 100644 --- a/src/pcm/pcm_dmix.c +++ b/src/pcm/pcm_dmix.c @@ -55,9 +55,6 @@ const char *_snd_module_pcm_dmix = ""; #define STATE_RUN_PENDING 1024 #endif -#define SEC_TO_MS 1000 /* Seconds representing in Milli seconds */ -#define LOW_LATENCY_PERIOD_TIME 10 /* slave_period time for low latency requirements in ms */ - /* * */ @@ -560,30 +557,12 @@ static int snd_pcm_dmix_hwsync(snd_pcm_t *pcm) } } -static void reset_slave_ptr(snd_pcm_t *pcm, snd_pcm_direct_t *dmix) -{ - dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr; - - if (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_ROUNDUP || - (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_AUTO && - pcm->buffer_size <= pcm->period_size * 2)) - dmix->slave_appl_ptr = - ((dmix->slave_appl_ptr + dmix->slave_period_size - 1) - / dmix->slave_period_size) * dmix->slave_period_size; - else if (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_ROUNDDOWN || - (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_AUTO && - (dmix->slave_period_size * SEC_TO_MS) / pcm->rate < LOW_LATENCY_PERIOD_TIME)) - dmix->slave_appl_ptr = dmix->slave_hw_ptr = - ((dmix->slave_hw_ptr / dmix->slave_period_size) * - dmix->slave_period_size); -} - static int snd_pcm_dmix_reset(snd_pcm_t *pcm) { snd_pcm_direct_t *dmix = pcm->private_data; dmix->hw_ptr %= pcm->period_size; dmix->appl_ptr = dmix->last_appl_ptr = dmix->hw_ptr; - reset_slave_ptr(pcm, dmix); + snd_pcm_direct_reset_slave_ptr(pcm, dmix); return 0; } @@ -592,7 +571,7 @@ static int snd_pcm_dmix_start_timer(snd_pcm_t *pcm, snd_pcm_direct_t *dmix) int err; snd_pcm_hwsync(dmix->spcm); - reset_slave_ptr(pcm, dmix); + snd_pcm_direct_reset_slave_ptr(pcm, dmix); err = snd_timer_start(dmix->timer); if (err < 0) return err; From patchwork Wed May 15 06:26:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Channaiah Vanitha (RBEI/ECF3)" X-Patchwork-Id: 10944293 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 2ABC5912 for ; Wed, 15 May 2019 06:47:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1732D289C4 for ; Wed, 15 May 2019 06:47:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B5B6289CC; Wed, 15 May 2019 06:47:42 +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,DKIM_SIGNED, DKIM_VALID,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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 31DB1289C4 for ; Wed, 15 May 2019 06:47:41 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 5D5DE167C; Wed, 15 May 2019 08:46:49 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 5D5DE167C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1557902859; bh=HfTVUukeh0e/yjyQoxSkyj9aFrCgn0TNY7sH4jWKbyY=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=HZfoYfCN/TWsipiDo9mlV3x+1tIVAyj3paOwMr3ek8R9L2xHF73rM+pODsYBeSZ4a im/vHc0L9Kisj6yeKQEpAZzyRq6r04mKwnksYW3qdND4MPBi1iCv9CnTZh2Y54S8H4 vgSpXVvXy+TWwR/ljeidsEofoYdR3/M5F8hXBglY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 84003F89739; Wed, 15 May 2019 08:45:09 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9CC4FF89719; Wed, 15 May 2019 08:45:00 +0200 (CEST) Received: from de-out1.bosch-org.com (de-out1.bosch-org.com [139.15.230.186]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 74E03F8968A; Wed, 15 May 2019 08:44:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 74E03F8968A Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=in.bosch.com header.i=@in.bosch.com header.b="j6f3d7JI" Received: from fe0vm1650.rbesz01.com (unknown [139.15.230.188]) by si0vms0216.rbdmz01.com (Postfix) with ESMTPS id 453lRB5zDyz1XLGMG; Wed, 15 May 2019 08:44:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=in.bosch.com; s=2015-01-21; t=1557902694; bh=j9ghyqlcIsq1VvBEl8XAwe9fmi0UKdHNOBlJj7mLn+I=; l=10; h=From:Subject:From:Reply-To:Sender; b=j6f3d7JICG5/fg9xm5mu/tDNUl68W9pd1fP1I4i5JpDFnBGx7dczHEvus/NN/CC0T sZzpl5bXuB+uZ09SWOiXmY3K3mIEtjCTseWu9GN0aIHnGNHDWQw5tWyJqpJOza0JPV 0IvVyvso27LS+G1rKJI0mXZb3EkF5zJtDuNbtnZk= Received: from fe0vm7918.rbesz01.com (unknown [10.58.172.176]) by fe0vm1650.rbesz01.com (Postfix) with ESMTPS id 453lRB5htxz1CS; Wed, 15 May 2019 08:44:54 +0200 (CEST) X-AuditID: 0a3aad10-057ff70000007f88-11-5cdbb566c631 Received: from fe0vm1652.rbesz01.com ( [10.58.173.29]) (using TLS with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by fe0vm7918.rbesz01.com (SMG Outbound) with SMTP id 09.5A.32648.665BBDC5; Wed, 15 May 2019 08:44:54 +0200 (CEST) Received: from FE-HUB2000.de.bosch.com (unknown [10.4.103.109]) by fe0vm1652.rbesz01.com (Postfix) with ESMTPS id 453lRB3BlDz5gM; Wed, 15 May 2019 08:44:54 +0200 (CEST) Received: from localhost.localdomain (10.47.103.61) by FE-HUB2000.de.bosch.com (10.4.103.109) with Microsoft SMTP Server id 15.1.1713.5; Wed, 15 May 2019 08:44:53 +0200 From: To: , Date: Wed, 15 May 2019 11:56:33 +0530 Message-ID: <1557901597-19215-3-git-send-email-vanitha.channaiah@in.bosch.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> References: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.47.103.61] X-Brightmail-Tracker: H4sIAAAAAAAAA21Sf0wTZxjud3dtj9JjX690vNYf2864LSYqONdVRpZl2x+4GNmyv2a6uGNc f0TakrsWQbOFGBmTTYLKSIsBDMQgQxEpbOggaCNTkRgQRaW6BZnBEge44rbEBXdnwfaP/fPl fZ/3ed7n+558NMme1Zppl8cniB6+kNPoKF32yZXr7N0RW+ZAaLX1+kiYsJ5sKVNbo6GHhLWp Nki8S+V2xPZqcusq2rS5oSt7PiK363IKhEJXsSBueOdznXNu+DBZVLum5MDdsLoMnV5ViWga 8Cb4re+zSqSjWRwgoPHeOBlvTiBoGxggKlFKvJns/ESpNfhVuDA2p1XqdLwO7k8e0ig1iUU4 eKSDUJYasR+mFhgFpvAaiE09IZWawdugYq7hGR3wKrh9df8zPAXnwY9/TlBxq20QaZ5Z5Bvg cvB3Kr4e4PyDB2Rc+zLUjAXU1QjXJdHqkmhHEfEDMtmFzGL3W5uzrOvFfEHanZm1/guvuxPF w8Q96MygPYwwjTg9U9wUsbFqvlgqdYfRmzTBmZh9dhlKy/cWlDp5yblD9BcKEmdmVgx/aGON z2HJn+92SZLL6wkjoEkundn+yi0byxTwpbsF0RuXhdFymuIyGAedZ2Oxg/cJOwWhSBCXpm/T NAfMji7Z0CAKDqHE7ir0LY25lQxSqVTsi8mTZFuCTgmjN2i97D2urGCkIt4tuRyL8mVxObuE JqSD6H36/N8T9SRLebwewZzB5Ch6rDCdfs/zG5hXMGN/3LSxpqRBYss0uo3kDI3M952yWC// 2YQ3MMuVuAyLYEK08ZiswSMsnHq0D0FDz2MErb0NFESaqtTw871/1XDm6jcamO/u1UBsVD6u na3TQuBgLQ0dN5/SMNRQrYPyI1M6WLhUmQpDkVupcPxRNBWmG0cY6Gu/lgaxigsvQP+VIQz/ tC5gCMw3G2Dk618MEIg+ZOFO/WP5aBs1wvRsVzqcOLXXJHv0m6CquT8Daqq+A/i1/diyaTlY Qg52s2tcCdbH+/4n2EU08TpzGdIfj65t0UqXcoLlr4v22U0fO386917aa7tqRoeprYZo0B/M /aq8t4/6y3b6JZNltvS6sbrXcsBweI/HsOtJgc4y0TqzcaprJ3ModN/y5afzR4n+2m+r99va Y4N586Oqlszscxc/iF129GSvDm21EPUzkyXGLU+7N9xoz0b6scZBFUdJTj5rLSlK/H8hY7qp TQQAAA== Cc: twischer@de.adit-jv.com, alsa-devel@alsa-project.org, Vanitha Channaiah Subject: [alsa-devel] [PATCH v2 2/6] pcm: dshare: Added "hw_ptr_alignment" option in configuration for alignment of slave pointers X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" X-Virus-Scanned: ClamAV using ClamSMTP From: Vanitha Channaiah This change adapt the fix commit 6b058fda9dce ("pcm: dmix: Add option to allow alignment of slave pointers") for dshare plugin Issue is that snd_pcm_wait() goes back to waiting because the hw_ptr is not period aligned. Therefore snd_pcm_wait() will block for a longer time as required. With these rcar driver changes the exact position of the dma is returned. During snd_pcm_start they read hw_ptr as reference, and this hw_ptr is now not period aligned, and is a little ahead over the period while it is read. Therefore when the avail is calculated during snd_pcm_wait(), it is missing the avail_min by a few frames. An additional option hw_ptr_alignment is provided to dshare configuration, to allow the user to configure the slave application and hw pointer alignment at startup Signed-off-by: Vanitha Channaiah --- src/pcm/pcm_dshare.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c index f135b5d..cf8a863 100644 --- a/src/pcm/pcm_dshare.c +++ b/src/pcm/pcm_dshare.c @@ -333,16 +333,16 @@ static int snd_pcm_dshare_reset(snd_pcm_t *pcm) snd_pcm_direct_t *dshare = pcm->private_data; dshare->hw_ptr %= pcm->period_size; dshare->appl_ptr = dshare->last_appl_ptr = dshare->hw_ptr; - dshare->slave_appl_ptr = dshare->slave_hw_ptr = *dshare->spcm->hw.ptr; + snd_pcm_direct_reset_slave_ptr(pcm, dshare); return 0; } -static int snd_pcm_dshare_start_timer(snd_pcm_direct_t *dshare) +static int snd_pcm_dshare_start_timer(snd_pcm_t *pcm, snd_pcm_direct_t *dshare) { int err; snd_pcm_hwsync(dshare->spcm); - dshare->slave_appl_ptr = dshare->slave_hw_ptr = *dshare->spcm->hw.ptr; + snd_pcm_direct_reset_slave_ptr(pcm, dshare); err = snd_timer_start(dshare->timer); if (err < 0) return err; @@ -364,7 +364,8 @@ static int snd_pcm_dshare_start(snd_pcm_t *pcm) else if (avail < 0) return 0; else { - if ((err = snd_pcm_dshare_start_timer(dshare)) < 0) + err = snd_pcm_dshare_start_timer(pcm, dshare); + if (err < 0) return err; snd_pcm_dshare_sync_area(pcm); } @@ -547,7 +548,8 @@ static snd_pcm_sframes_t snd_pcm_dshare_mmap_commit(snd_pcm_t *pcm, return 0; snd_pcm_mmap_appl_forward(pcm, size); if (dshare->state == STATE_RUN_PENDING) { - if ((err = snd_pcm_dshare_start_timer(dshare)) < 0) + err = snd_pcm_dshare_start_timer(pcm, dshare); + if (err < 0) return err; } else if (dshare->state == SND_PCM_STATE_RUNNING || dshare->state == SND_PCM_STATE_DRAINING) { @@ -755,6 +757,7 @@ int snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name, dshare->slowptr = opts->slowptr; dshare->max_periods = opts->max_periods; dshare->var_periodsize = opts->var_periodsize; + dshare->hw_ptr_alignment = opts->hw_ptr_alignment; dshare->sync_ptr = snd_pcm_dshare_sync_ptr; retry: @@ -912,6 +915,12 @@ pcm.name { ipc_key INT # unique IPC key ipc_key_add_uid BOOL # add current uid to unique IPC key ipc_perm INT # IPC permissions (octal, default 0600) + hw_ptr_alignment STR # Slave application and hw pointer alignment type + # STR can be one of the below strings : + # no + # roundup + # rounddown + # auto (default) slave STR # or slave { # Slave definition @@ -936,6 +945,27 @@ pcm.name { } \endcode +hw_ptr_alignment specifies slave application and hw +pointer alignment type. By default hw_ptr_alignment is auto. Below are +the possible configurations: +- no: minimal latency with minimal frames dropped at startup. But + wakeup of application (return from snd_pcm_wait() or poll()) can + take up to 2 * period. +- roundup: It is guaranteed that all frames will be played at + startup. But the latency will increase upto period-1 frames. +- rounddown: It is guaranteed that a wakeup will happen for each + period and frames can be written from application. But on startup + upto period-1 frames will be dropped. +- auto: Selects the best approach depending on the used period and + buffer size. + If the application buffer size is < 2 * application period, + "roundup" will be selected to avoid under runs. If the slave_period + is < 10ms we could expect that there are low latency + requirements. Therefore "rounddown" will be chosen to avoid long + wakeup times. Such wakeup delay could otherwise end up with Xruns in + case of a dependency to another sound device (e.g. forwarding of + microphone to speaker). Else "no" will be chosen. + \subsection pcm_plugins_dshare_funcref Function reference
    From patchwork Wed May 15 06:26:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Channaiah Vanitha (RBEI/ECF3)" X-Patchwork-Id: 10944295 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 1A95E1398 for ; Wed, 15 May 2019 06:48:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04AC82899C for ; Wed, 15 May 2019 06:48:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E854728999; Wed, 15 May 2019 06:48:22 +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,DKIM_SIGNED, DKIM_VALID,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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0AB5228999 for ; Wed, 15 May 2019 06:48:21 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 31ADB168E; Wed, 15 May 2019 08:47:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 31ADB168E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1557902900; bh=QSQxC8kAqxMMJbdeKRpLBmpA9ED93A0WkSSQ5r3FRRY=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=chCOA2hWUcZVkO9IoaP2Y2xgmAZAvfBRgSU3Hg2UZqdx0+V0b5dC6CnVkZUSZ5QPq WTdP8pagLAEHxxl63LJtPPZYAPq86hLTzpIr078ZBDWt+cKqb0ZFZtpb7ebHCTo3wi dJ9Leyx1IqyIfFCdkCUGd8B0VyX0gBG0+Szj2CEI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id ECB7EF8973F; Wed, 15 May 2019 08:45:13 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id A9C1AF89713; Wed, 15 May 2019 08:45:00 +0200 (CEST) Received: from de-out1.bosch-org.com (de-out1.bosch-org.com [139.15.230.186]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 63F65F806E5; Wed, 15 May 2019 08:44:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 63F65F806E5 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=in.bosch.com header.i=@in.bosch.com header.b="b86UbeY0" Received: from fe0vm1650.rbesz01.com (unknown [139.15.230.188]) by fe0vms0186.rbdmz01.com (Postfix) with ESMTPS id 453lRD1B5Zz1XLFrv; Wed, 15 May 2019 08:44:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=in.bosch.com; s=2015-01-21; t=1557902696; bh=j9ghyqlcIsq1VvBEl8XAwe9fmi0UKdHNOBlJj7mLn+I=; l=10; h=From:Subject:From:Reply-To:Sender; b=b86UbeY0spmXMQl8XRiAlcd0NUaexX+O1ORmoHwfyWrREDum4jBanrI8hRrU7NiyN kh6Ux+UGk3nv6UctFLbvSG20Ggrk+nrejg+eGTQSYxeQZreyBGuveor+JH/Ht/E05a 4GmW3qgDotLnCaTOxXbv5wUN8ghWoiMpdjJoL7YI= Received: from fe0vm1740.rbesz01.com (unknown [10.58.172.176]) by fe0vm1650.rbesz01.com (Postfix) with ESMTPS id 453lRD0w9Cz1CP; Wed, 15 May 2019 08:44:56 +0200 (CEST) X-AuditID: 0a3aad14-cc5ff7000000410a-09-5cdbb5675ce5 Received: from fe0vm1651.rbesz01.com ( [10.58.173.29]) (using TLS with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by fe0vm1740.rbesz01.com (SMG Outbound) with SMTP id CB.D8.16650.765BBDC5; Wed, 15 May 2019 08:44:55 +0200 (CEST) Received: from FE-HUB2000.de.bosch.com (unknown [10.4.103.109]) by fe0vm1651.rbesz01.com (Postfix) with ESMTPS id 453lRC5zs1zR7g; Wed, 15 May 2019 08:44:55 +0200 (CEST) Received: from localhost.localdomain (10.47.103.61) by FE-HUB2000.de.bosch.com (10.4.103.109) with Microsoft SMTP Server id 15.1.1713.5; Wed, 15 May 2019 08:44:54 +0200 From: To: , Date: Wed, 15 May 2019 11:56:34 +0530 Message-ID: <1557901597-19215-4-git-send-email-vanitha.channaiah@in.bosch.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> References: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.47.103.61] X-Brightmail-Tracker: H4sIAAAAAAAAA21Sf0wbZRjmu7u2R+nh9Sjba8eMnHEzRkZxW2ST6YwJQZewGZNlkmbsGEfb SFu8KwjTaF1wOjQTtGtKEWRlsF+yNYORDTC6sjjnCFnRsY3WxY2pQFCZUDeD2bzjYO0f/nN5 vud9nvf5vidH4ky/xkjaHC5ecHDlrFpLaNd3Ls+ynIqYTZ7963N/DIew3M5DblXuRNcUlhvw NmIbiYLgzG51gf+DY5qCrotvbcGLtHmlfLmtiheyn9uhtYbdB7AKX3b1QGub2o1aVtahZBLo NeC59LeqDmlJhvZhsHtmmlAOXyLw9O3DZNX84aN2l4zV9Ao4NzKtkbGBzoJfxj5VyxinBWho Cs7r0+g34EKwcx4T9OPguduOZEzRhTDa0IGU5Efg2tBeXMbJ9Gbo+esGoWQVQqTtD1zR6+FC 4y1C2Q9wdnwcV7yPgmfEp6pHtD9B5k+QtSLsKEov401V9pxn1phWCSW8uMuUs2qn034SKXUa TqO5UFkI0SRidZQrEDEzKq5KrLGH0FoSY9Op2jKJSi1xltZYOdFaLFSW8yJrpDIuvWxm0h7Q YmWJ3SaKNqcjhIDEWQNVlHnVzFClXM0uXnAqthBaRhLsUspCbjYztIVz8a/zfAUvLE6fJUkW qOJuKVAv8Ba+usxW7locs8splJSUxCxJnCTGYmRyCK0mdVL23i5pBSVWcHbRZlmwP6zYmUU2 bv0evUievXOjGWcIh9PBG5dSefIVaFlprXQ8uIExgxr5/YqZSU8YxLdMomtI6jCNWi2bddJf G88Gaplcl36BjJuebpc89MUlcOJ2LYKB6V4ELadjCG5+EsPhSH8LAXOxWyrou/mvCs4MfagG z4kDapg91a+Ggdb3NTDc69eAr8FLQvDKfRIGW+q1cL2uWwv3vqtLgcHI1RQ4fHsiBdqizTqY /CJMwVfHh1NhwHsnFe4euUeDb7ZND+E93+rBNzHFQLQ5Jn2O/ZAG1wNNBpj8s9sgZXydPikV i0nFrrONysW6ONf/FLvAxl9ndKNNn52J9mqjzfXV+4KX8wqe6KBmG7dvyt/zzcax4d96pt/O y9yQkf/TmLi1pmPt5ZOjtS81bfvV/VQ+hRW+NtcovhCN9MR+ZnD21WIdaf54g+n8K9sDj7kP 92Uceu9+f9HB52czz2d5d75zzo+/Gx4M6KMPTXz+z9SOmcI3s4fWEVvHvStYQrRyOU/igsj9 B9WS7qBPBAAA Cc: twischer@de.adit-jv.com, alsa-devel@alsa-project.org, Vanitha Channaiah Subject: [alsa-devel] [PATCH v2 3/6] pcm: dsnoop: Added "hw_ptr_alignment" option in configuration for slave pointer alignment X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" X-Virus-Scanned: ClamAV using ClamSMTP From: Vanitha Channaiah This change adapt the fix commit 6b058fda9dce ("pcm: dmix: Add option to allow alignment of slave pointers") for dsnoop plugin Issue is that snd_pcm_wait() goes back to waiting because the hw_ptr is not period aligned. Therefore snd_pcm_wait() will block for a longer time as required. With these rcar driver changes the exact position of the dma is returned. During snd_pcm_start they read hw_ptr as reference, and this hw_ptr is now not period aligned, and is a little ahead over the period while it is read. Therefore when the avail is calculated during snd_pcm_wait(), it is missing the avail_min by a few frames. An additional option hw_ptr_alignment is provided to dsnoop configuration, to allow the user to configure the slave application and hw pointer alignment at startup Signed-off-by: Vanitha Channaiah --- src/pcm/pcm_direct.c | 1 - src/pcm/pcm_dmix.c | 2 ++ src/pcm/pcm_dshare.c | 2 ++ src/pcm/pcm_dsnoop.c | 30 +++++++++++++++++++++++++++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index 411a035..54d9900 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -2043,7 +2043,6 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf, void snd_pcm_direct_reset_slave_ptr(snd_pcm_t *pcm, snd_pcm_direct_t *dmix) { - dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr; if (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_ROUNDUP || (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_AUTO && diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c index dcde40d..274726e 100644 --- a/src/pcm/pcm_dmix.c +++ b/src/pcm/pcm_dmix.c @@ -562,6 +562,7 @@ static int snd_pcm_dmix_reset(snd_pcm_t *pcm) snd_pcm_direct_t *dmix = pcm->private_data; dmix->hw_ptr %= pcm->period_size; dmix->appl_ptr = dmix->last_appl_ptr = dmix->hw_ptr; + dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr; snd_pcm_direct_reset_slave_ptr(pcm, dmix); return 0; } @@ -571,6 +572,7 @@ static int snd_pcm_dmix_start_timer(snd_pcm_t *pcm, snd_pcm_direct_t *dmix) int err; snd_pcm_hwsync(dmix->spcm); + dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr; snd_pcm_direct_reset_slave_ptr(pcm, dmix); err = snd_timer_start(dmix->timer); if (err < 0) diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c index cf8a863..b75809c 100644 --- a/src/pcm/pcm_dshare.c +++ b/src/pcm/pcm_dshare.c @@ -333,6 +333,7 @@ static int snd_pcm_dshare_reset(snd_pcm_t *pcm) snd_pcm_direct_t *dshare = pcm->private_data; dshare->hw_ptr %= pcm->period_size; dshare->appl_ptr = dshare->last_appl_ptr = dshare->hw_ptr; + dshare->slave_appl_ptr = dshare->slave_hw_ptr = *dshare->spcm->hw.ptr; snd_pcm_direct_reset_slave_ptr(pcm, dshare); return 0; } @@ -342,6 +343,7 @@ static int snd_pcm_dshare_start_timer(snd_pcm_t *pcm, snd_pcm_direct_t *dshare) int err; snd_pcm_hwsync(dshare->spcm); + dshare->slave_appl_ptr = dshare->slave_hw_ptr = *dshare->spcm->hw.ptr; snd_pcm_direct_reset_slave_ptr(pcm, dshare); err = snd_timer_start(dshare->timer); if (err < 0) diff --git a/src/pcm/pcm_dsnoop.c b/src/pcm/pcm_dsnoop.c index d08b624..58b1e53 100644 --- a/src/pcm/pcm_dsnoop.c +++ b/src/pcm/pcm_dsnoop.c @@ -278,6 +278,7 @@ static int snd_pcm_dsnoop_reset(snd_pcm_t *pcm) dsnoop->hw_ptr %= pcm->period_size; dsnoop->appl_ptr = dsnoop->hw_ptr; dsnoop->slave_appl_ptr = dsnoop->slave_hw_ptr; + snd_pcm_direct_reset_slave_ptr(pcm, dsnoop); return 0; } @@ -285,12 +286,13 @@ static int snd_pcm_dsnoop_start(snd_pcm_t *pcm) { snd_pcm_direct_t *dsnoop = pcm->private_data; int err; - + if (dsnoop->state != SND_PCM_STATE_PREPARED) return -EBADFD; snd_pcm_hwsync(dsnoop->spcm); snoop_timestamp(pcm); dsnoop->slave_appl_ptr = dsnoop->slave_hw_ptr; + snd_pcm_direct_reset_slave_ptr(pcm, dsnoop); err = snd_timer_start(dsnoop->timer); if (err < 0) return err; @@ -627,6 +629,7 @@ int snd_pcm_dsnoop_open(snd_pcm_t **pcmp, const char *name, dsnoop->max_periods = opts->max_periods; dsnoop->var_periodsize = opts->var_periodsize; dsnoop->sync_ptr = snd_pcm_dsnoop_sync_ptr; + dsnoop->hw_ptr_alignment = opts->hw_ptr_alignment; retry: if (first_instance) { @@ -771,6 +774,12 @@ pcm.name { ipc_key INT # unique IPC key ipc_key_add_uid BOOL # add current uid to unique IPC key ipc_perm INT # IPC permissions (octal, default 0600) + hw_ptr_alignment STR # Slave application and hw pointer alignment type + # STR can be one of the below strings : + # no + # roundup + # rounddown + # auto (default) slave STR # or slave { # Slave definition @@ -795,6 +804,25 @@ pcm.name { } \endcode +hw_ptr_alignment specifies slave application and hw +pointer alignment type. By default hw_ptr_alignment is auto. Below are +the possible configurations: +- no: minimal latency with minimal frames dropped at startup. But + wakeup of application (return from snd_pcm_wait() or poll()) can + take up to 2 * period. +- roundup: It is guaranteed that all frames will be played at + startup. But the latency will increase upto period-1 frames. +- rounddown: It is guaranteed that a wakeup will happen for each + period and frames can be written from application. But on startup + upto period-1 frames will be dropped. +- auto: Selects the best approach depending on the used period and + buffer size. + If the application buffer size is < 2 * application period, + "roundup" will be selected to avoid over runs. If the slave_period + is < 10ms we could expect that there are low latency + requirements. Therefore "rounddown" will be chosen to avoid long + wakeup times. Else "no" will be chosen. + \subsection pcm_plugins_dsnoop_funcref Function reference
      From patchwork Wed May 15 06:26:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Channaiah Vanitha (RBEI/ECF3)" X-Patchwork-Id: 10944297 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 CA2F5912 for ; Wed, 15 May 2019 06:48:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6A89289C4 for ; Wed, 15 May 2019 06:48:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A98BA289BF; Wed, 15 May 2019 06:48:58 +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,DKIM_SIGNED, DKIM_VALID,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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EF50D289BF for ; Wed, 15 May 2019 06:48:57 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 34D87169B; Wed, 15 May 2019 08:48:06 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 34D87169B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1557902936; bh=2aytasbJFN9tX5A/BtdPtYh/Y5pOX7oGTCujQGc2mO4=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=vCumqYNZUqzkn76B8jIcwxfHd+pl0NpA3sqZUuJJO35IvLNcAVnfz8LJcaZ+Mln5Y i6fKVKquQ9Nqli3WiR9om6W5pgCNRY8CUP86APg2uKCdd6As3F2Vg75TIAqVz+SGAx JBXVCnUZfYCaVRyIJ0ltQq30cUjznfpzfqQlV/rM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 03ED3F89745; Wed, 15 May 2019 08:45:15 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4557DF89737; Wed, 15 May 2019 08:45:05 +0200 (CEST) Received: from de-out1.bosch-org.com (de-out1.bosch-org.com [139.15.230.186]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id ADF79F896B2; Wed, 15 May 2019 08:44:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz ADF79F896B2 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=in.bosch.com header.i=@in.bosch.com header.b="hcl8x5/G" Received: from si0vm1948.rbesz01.com (unknown [139.15.230.188]) by fe0vms0187.rbdmz01.com (Postfix) with ESMTPS id 453lRF3VbDz1XLDR6; Wed, 15 May 2019 08:44:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=in.bosch.com; s=2015-01-21; t=1557902697; bh=j9ghyqlcIsq1VvBEl8XAwe9fmi0UKdHNOBlJj7mLn+I=; l=10; h=From:Subject:From:Reply-To:Sender; b=hcl8x5/G7oDQt8Iwxy6Ilp5TKsxGZ6EjOYf3KwpBDb2trjHyD/hdhgkZLoFC8uurf 4Jiyt71Lnk0LauvlLgsW7AFyyPl4WDiHZUtTnDfVth7fIzzgXq3TrH4b8OXgLtiTR3 l8Ilby35qFSvPpn6rXIspa5W9MHtsGh3FMmXVqps= Received: from fe0vm02900.rbesz01.com (unknown [10.58.172.176]) by si0vm1948.rbesz01.com (Postfix) with ESMTPS id 453lRF37xCz1Tk; Wed, 15 May 2019 08:44:57 +0200 (CEST) X-AuditID: 0a3aad0c-d01ff700000039d6-03-5cdbb569f645 Received: from si0vm1949.rbesz01.com ( [10.58.173.29]) (using TLS with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by fe0vm02900.rbesz01.com (SMG Outbound) with SMTP id 76.F3.14806.965BBDC5; Wed, 15 May 2019 08:44:57 +0200 (CEST) Received: from FE-HUB2000.de.bosch.com (fe-hub2000.de.bosch.com [10.4.103.109]) by si0vm1949.rbesz01.com (Postfix) with ESMTPS id 453lRF0nwBz6Cjg7y; Wed, 15 May 2019 08:44:57 +0200 (CEST) Received: from localhost.localdomain (10.47.103.61) by FE-HUB2000.de.bosch.com (10.4.103.109) with Microsoft SMTP Server id 15.1.1713.5; Wed, 15 May 2019 08:44:55 +0200 From: To: , Date: Wed, 15 May 2019 11:56:35 +0530 Message-ID: <1557901597-19215-5-git-send-email-vanitha.channaiah@in.bosch.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> References: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.47.103.61] X-Brightmail-Tracker: H4sIAAAAAAAAA21SbUwTZxznuZZydD12Pd7+FjRyRrO50JWXKSKKb4nEBF32kXRxhxztsb7A XUtAsww3zVyN8QWitog4BN/BRtRQom6WuawTdHUOtWVkMMeQAZLZfVG27I4W2w/79nt+L8/v uV8Ol1HuBA3OWWwsb2FMtEIpVxZ2LszmrgX1uoZRouCh34sVdJ5tiC941j2JFbQddWLr5CXu F58pSlxfXEwo6b67631ZmbKogjVxtSz/7tqPlMb+X1+h6oC6bnqvI74BXU1yIBwHMh96x9Y4 UCJOkU4MPr+xwoGUIv4awdBMqyJ8uISg1XMXk1wKchl8OziTIOEUMht+/+2IQsIykofDze45 TzJZA57d++awnFwKv3hnZRImyK0w+cfNOQzkInhy78s5nEhug+t/jcjDr9gKwdPTEb8afM6n 8vD9ALfHxyPZxdA0eDz+ECJdMTZXjO0Uwi6gtEpWV2vW5a7S6bR8OSvs1OVod1jNV1B4TlUP utNu8CISR7SKqG0L6ql4plaoN3vRezhGpxJ7KkUqqdxaUW9kBON23m5iBVpDZP64RU8lv6YF e7mZEwTOavEiwGV0ClGW9VhPERVM/U6Wt4ZjXpSBy+l0woBv01OkgbGxH7NsNcvPq6txnAZi +1WxUM2zBraukjPZ5mV6IYHi4uKotFglthbDE70oD1eJ3QHpCkKoZswCZ4jEF4Tj1Dwbjf6A VmrSiSIpQ0qq0W553arJJAanHump1BghmpxAT5C4WzKRJ4VV4p8a7QMiQ5pIHSGjodwOMUNe wKFvphfByZ6/ETRd/koBD3pdCXBx8uQbcHqoRQXfH2p5EwL+YxR4fA8oaB4IaeDSyL0M6B8O ZMKwI5QJ928fzALvqam3of/nK8th9lHHO3DuxO5sGG7aq4We0GUtNP7j1oLv32e50jEPjjxv XQGhZv9K8E8/LhTVmdVw47y/CHqOXiuG/nbHOhj+rnE9+G61bJgQx8TEMVdxAWlMG2P7nzEj bPTrNA0oaY0rVJM/1F3ViAYg//r6++dzug4PbPykM9neW7qMdS5x/wR1jrFjnX1VTycWh7pS Cvs+fAsbKxlsXSL7wL/W9zCrYrMQ0lfdQX8GU63nivctHS1t83CjU3nOF3sMs/vLPKakTely dbup5uw3Zxa8HC+zF095dgRH0g7YP+3Kt9BywcjkLJfxAvMfY1qMcEMEAAA= Cc: twischer@de.adit-jv.com, alsa-devel@alsa-project.org, Vanitha Channaiah Subject: [alsa-devel] [PATCH v2 4/6] pcm: direct: Round up of slave_app_ptr pointer if buffer size is less than 2 period size. X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" X-Virus-Scanned: ClamAV using ClamSMTP From: Vanitha Channaiah For buffer size less than two period size, the start position of slave_app_ptr is rounded up in order to avoid xruns For e.g.: Considering below parameters and its values Period size = 96 Buffer size = 191 slave_appl_ptr = slave_hw_ptr = unaligned value Issue: - During the start of the stream, app_ptr = hw_ptr = 0 - Application writes one period of data in the buffer i.e app_ptr = 96, hw_ptr = 0 - Now, the avail is just period-1 frames available. avail = hw_ptr + buffer_size - app_ptr = 95 i.e. shortage of 1 frame space - so application is waiting for the 1frame space to be available. - slave_app_ptr and slave_hw_ptr would get updated to lower values - This could lead to under run to occur. Fix: If we round Up the slave_app_ptr pointer, - During the start of the stream, app_ptr = hw_ptr = 0 - Application writes one period of data in the buffer i.e app_ptr = 96, hw_ptr = 0 - Round Up of slave_app_ptr pointer leads to below calculation: - slave_app_ptr rounded to 96 - slave_app_ptr and slave_hw_ptr would get updated to larger value nearing to 2 period size - avail = greater than period size. - Here, there is a lower chance of under run. Signed-off-by: Vanitha Channaiah --- src/pcm/pcm_direct.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index 54d9900..b56da85 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -2043,10 +2043,12 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf, void snd_pcm_direct_reset_slave_ptr(snd_pcm_t *pcm, snd_pcm_direct_t *dmix) { - + /* For buffer size less than two period size, the start position + * of slave app ptr is rounded up in order to avoid xruns + */ if (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_ROUNDUP || (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_AUTO && - pcm->buffer_size <= pcm->period_size * 2)) + pcm->buffer_size < pcm->period_size * 2)) dmix->slave_appl_ptr = ((dmix->slave_appl_ptr + dmix->slave_period_size - 1) / dmix->slave_period_size) * dmix->slave_period_size; From patchwork Wed May 15 06:26:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Channaiah Vanitha (RBEI/ECF3)" X-Patchwork-Id: 10944299 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 2AA08912 for ; Wed, 15 May 2019 06:49:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17ED4289BF for ; Wed, 15 May 2019 06:49:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B997289CA; Wed, 15 May 2019 06:49:39 +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,DKIM_SIGNED, DKIM_VALID,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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 44B0F289BF for ; Wed, 15 May 2019 06:49:38 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 88FD516B4; Wed, 15 May 2019 08:48:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 88FD516B4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1557902976; bh=pTUMRlK/NBjOZTZFNLyuihcwzGM4kmE+dWSJLCLCHWc=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Fx979K82KUkDn4wdzlT1gI/Biz/qli8NQmakhT9QmD3bNggSAaCAaLSp4GEZStWmd ETMj4LN2qx3+7HysqclC5DH3TGXeCZvl3f3V2EDwC1WYdRY6g6CpzX1h8HsIQGJADV e4IgD/iPsAOvlUf1737jwwMiANcCCWIc4aIu4Etg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 5B955F8974A; Wed, 15 May 2019 08:45:18 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 6154DF89708; Wed, 15 May 2019 08:45:04 +0200 (CEST) Received: from de-out1.bosch-org.com (de-out1.bosch-org.com [139.15.230.186]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 11A52F89708; Wed, 15 May 2019 08:44:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 11A52F89708 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=in.bosch.com header.i=@in.bosch.com header.b="ErEuyC2k" Received: from fe0vm1650.rbesz01.com (unknown [139.15.230.188]) by si0vms0216.rbdmz01.com (Postfix) with ESMTPS id 453lRG5W62z1XLGMJ; Wed, 15 May 2019 08:44:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=in.bosch.com; s=2015-01-21; t=1557902698; bh=j9ghyqlcIsq1VvBEl8XAwe9fmi0UKdHNOBlJj7mLn+I=; l=10; h=From:Subject:From:Reply-To:Sender; b=ErEuyC2kuAycXUZ76yE91GaaUmwrQ8a1NJWHDLbToNuizcnaSwFuVYP5cda3HxJMN Gcn0QiQjYMMVxGxOksdChMlEXXhV6+0mgP9qNvu1fCH8e7UDT5j0gSFx/xxbjfrUJO M0q1ZIm7izmsvTzGZGFg7+/8t8D2xr+HA6HBjiYU= Received: from fe0vm1740.rbesz01.com (unknown [10.58.172.176]) by fe0vm1650.rbesz01.com (Postfix) with ESMTPS id 453lRG5Dh9z1CT; Wed, 15 May 2019 08:44:58 +0200 (CEST) X-AuditID: 0a3aad14-cc5ff7000000410a-0f-5cdbb56ae04e Received: from fe0vm1652.rbesz01.com ( [10.58.173.29]) (using TLS with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by fe0vm1740.rbesz01.com (SMG Outbound) with SMTP id CC.D8.16650.A65BBDC5; Wed, 15 May 2019 08:44:58 +0200 (CEST) Received: from FE-HUB2000.de.bosch.com (unknown [10.4.103.109]) by fe0vm1652.rbesz01.com (Postfix) with ESMTPS id 453lRG3cr1z5gM; Wed, 15 May 2019 08:44:58 +0200 (CEST) Received: from localhost.localdomain (10.47.103.61) by FE-HUB2000.de.bosch.com (10.4.103.109) with Microsoft SMTP Server id 15.1.1713.5; Wed, 15 May 2019 08:44:57 +0200 From: To: , Date: Wed, 15 May 2019 11:56:36 +0530 Message-ID: <1557901597-19215-6-git-send-email-vanitha.channaiah@in.bosch.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> References: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.47.103.61] X-Brightmail-Tracker: H4sIAAAAAAAAA22Sb0wbZRzH+9yV9mh65Dja8bOMRbtsMyxjIGyUrU6m0ZBFwDfsxdLIDrnS alvIXSFQ3+BcMaBOIA1hVQeBoYSuZiu4IGgWbssCTHDDyt+ly8LQyaAhLhriIPOOAu0L31y+ z/f3+zzfPN8cgdPXlDrC6nCynIOx6RUqueqYP/XQ+9/PmzLc/n2G4D0BM/i/rYsz/Nm3jBk6 Wy9iefL8q0/PKfK9n/iU+X13PnwHP6MylrE2azXLHT5xVmV57p/AKsd0Ndcv9Cvq0NyuRhRP AJUNT3yCshGpCJpqw+By709xkcMVBOHAGr5z2GgKKiREQe2HW1OrSklrqEOwuNCy6eMUB81f XsUknUS9Cu2t/2xqObUPgr61TU1ShdD9bByLRO+B2YkGXNLxVBFc/+uhXNK0uDPfFcYj+4kw evGRPHI/wPDjx3iEfRE8U21xTYjyxqx5Y9Y6ENaLtGY2o9qemZOdkc6VsrwrIzP9vQp7AEX6 1AygZ4JZQBSB9GrS2TlvouOYar7WLqAjBKbXkufNopVQWlFWa2F4SwlXZWN5vY7cffeUiU7a sfmqUruV560VDgEBges15JmXZkw0WcbUuliuIoIJKIWQ65PJcqLIRFPljJP9gGUrWW57epwg 9ECW9IuBiRxbztaYrTbn9lifSiKZTEbvip3ExmJEvICyCLWY3dAnXkHylYydt5Zv4S9EcHrb jaJjKEeXTBqlWEqaWqocO6m63eTUyrSJ1sYMouQSmkVib0lklgSrxV81mgdkilRR4pYZhV7p FhmqMR7uL19AcGngbwSTg14leFo7CQiFxxOgx/8wAWaGGzTw82+TWrixtKGFcMdHydC+8EQH 60OLqTD5b9de6Lk3vReWv+7YDzeX2w7AjTs/ip/h8AEY6e14WWQDabD+6x9pEPK402F9ejEb Vs+NHIFVYfwo3L/2aQ6E6gUDrD+4ZISAe8YIa3MhI1ye+OYkfHfFd3JJLBMTy8y1zkllOhnn /5S55UZfp6tD6nffapkLWdyciy+xTNQPDB4/a2jOu5srS2k/SCV40enCqdyapgJfZdXzN+C1 Ic+p+tmsPLvhzYXbjtyjX/zyA3eC7ykqLjhdbC78TH3MNTrW9VXY6xhJ616xfD5mazkfdBX0 u58O6kZ/tz7ymAKv7/EpVw5rhj6eDTY/eFtWvKGX8xYmMw3neOY/iQMVOkQEAAA= Cc: twischer@de.adit-jv.com, alsa-devel@alsa-project.org, Vanitha Channaiah Subject: [alsa-devel] [PATCH v2 5/6] pcm: restructuring sw params function X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" X-Virus-Scanned: ClamAV using ClamSMTP From: Vanitha Channaiah snd_pcm_sw_params() is reformatted by using _snd_pcm_sw_params_internal() function. Critical section of snd_pcm_sw_param() is moved to _snd_pcm_sw_params_internal(). This allows to call the snd_pcm_sw_params() function from an internal function which has already locked the API mutex. Calling snd_pcm_sw_params() from an internal function with locked API mutex would end up in an deadlock because recursive locking is not supported. This patch doesnot change the behavior or the functionality. To avoid double lock conditions, a separate _snd_pcm_sw_params_internal() function is added which can be used internally by any other functions in alsa-lib Signed-off-by: Vanitha Channaiah --- src/pcm/pcm.c | 12 +----------- src/pcm/pcm_local.h | 1 + src/pcm/pcm_params.c | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 3a71d79..f0db545 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -968,21 +968,11 @@ int snd_pcm_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params) } #endif __snd_pcm_lock(pcm); /* forced lock due to pcm field change */ - err = pcm->ops->sw_params(pcm->op_arg, params); + err = _snd_pcm_sw_params_internal(pcm, params); if (err < 0) { __snd_pcm_unlock(pcm); return err; } - pcm->tstamp_mode = params->tstamp_mode; - pcm->tstamp_type = params->tstamp_type; - pcm->period_step = params->period_step; - pcm->avail_min = params->avail_min; - pcm->period_event = sw_get_period_event(params); - pcm->start_threshold = params->start_threshold; - pcm->stop_threshold = params->stop_threshold; - pcm->silence_threshold = params->silence_threshold; - pcm->silence_size = params->silence_size; - pcm->boundary = params->boundary; __snd_pcm_unlock(pcm); return 0; } diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index d52229d..e103f72 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -661,6 +661,7 @@ static inline int muldiv_near(int a, int b, int c) return n; } +int _snd_pcm_sw_params_internal(snd_pcm_t *pcm, snd_pcm_sw_params_t *params); int snd_pcm_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params); int _snd_pcm_hw_params_internal(snd_pcm_t *pcm, snd_pcm_hw_params_t *params); #undef _snd_pcm_hw_params diff --git a/src/pcm/pcm_params.c b/src/pcm/pcm_params.c index 8826bc3..3ba05fb 100644 --- a/src/pcm/pcm_params.c +++ b/src/pcm/pcm_params.c @@ -2439,3 +2439,24 @@ int _snd_pcm_hw_params_internal(snd_pcm_t *pcm, snd_pcm_hw_params_t *params) return 0; } +int _snd_pcm_sw_params_internal(snd_pcm_t *pcm, snd_pcm_sw_params_t *params) +{ + int err; + + assert(pcm && params); + assert(pcm->setup); + err = pcm->ops->sw_params(pcm->op_arg, params); + if (err < 0) + return err; + pcm->tstamp_mode = params->tstamp_mode; + pcm->tstamp_type = params->tstamp_type; + pcm->period_step = params->period_step; + pcm->avail_min = params->avail_min; + pcm->period_event = sw_get_period_event(params); + pcm->start_threshold = params->start_threshold; + pcm->stop_threshold = params->stop_threshold; + pcm->silence_threshold = params->silence_threshold; + pcm->silence_size = params->silence_size; + pcm->boundary = params->boundary; + return 0; +} From patchwork Wed May 15 06:26:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Channaiah Vanitha (RBEI/ECF3)" X-Patchwork-Id: 10944301 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 B2145912 for ; Wed, 15 May 2019 06:50:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D9ED28938 for ; Wed, 15 May 2019 06:50:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91C65289D7; Wed, 15 May 2019 06:50:22 +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,DKIM_SIGNED, DKIM_VALID,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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 95E65289CE for ; Wed, 15 May 2019 06:50:21 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id CA48316C9; Wed, 15 May 2019 08:49:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz CA48316C9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1557903019; bh=mARxSfedDgPJPIKo3evICVWwCTTSGYJf1EpY9VuZYeo=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XYupo3p0orosPMTntNhhed8JPe/VfXGMfXs5SNhsgZalFCSJA2+chM5j2OyOsdz/P I+KVAUtxxtRkvmH017pCKWuzzSizheCrNDOc3EhAZWzFurp/eTkxQIESFfVCxAOL/b JELwlHHYmhoiKIXPHSdS5lM4Vvh6pF1YoahldXxE= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 59E1FF89730; Wed, 15 May 2019 08:45:30 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 297C6F89737; Wed, 15 May 2019 08:45:06 +0200 (CEST) Received: from de-out1.bosch-org.com (de-out1.bosch-org.com [139.15.230.186]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 61091F806E5; Wed, 15 May 2019 08:45:00 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 61091F806E5 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=in.bosch.com header.i=@in.bosch.com header.b="dwhk/gtb" Received: from si0vm1948.rbesz01.com (unknown [139.15.230.188]) by si0vms0216.rbdmz01.com (Postfix) with ESMTPS id 453lRJ12Vxz1XLGMG; Wed, 15 May 2019 08:45:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=in.bosch.com; s=2015-01-21; t=1557902700; bh=j9ghyqlcIsq1VvBEl8XAwe9fmi0UKdHNOBlJj7mLn+I=; l=10; h=From:Subject:From:Reply-To:Sender; b=dwhk/gtbqrWjjQsxNJ8MwNuOPS4JoNumUsKIBvsWaYJ2XsZ4m375XZoFL7WiTPoTT V5w5QW+3+e+tvEVz2oPuXlfGc0LyH2Rp6BDGc7EZhPCnSsSD5YG8FBYf5jPNK+eZf/ 7xyJ4IcdJTeZnP/d/OYBaEUc7ZJj636fD8YKOve8= Received: from si0vm2083.rbesz01.com (unknown [10.58.172.176]) by si0vm1948.rbesz01.com (Postfix) with ESMTPS id 453lRJ0gtdz1Tg; Wed, 15 May 2019 08:45:00 +0200 (CEST) X-AuditID: 0a3aad17-5a7ff70000001fa9-22-5cdbb56bf032 Received: from si0vm1949.rbesz01.com ( [10.58.173.29]) (using TLS with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by si0vm2083.rbesz01.com (SMG Outbound) with SMTP id B4.D1.08105.B65BBDC5; Wed, 15 May 2019 08:44:59 +0200 (CEST) Received: from FE-HUB2000.de.bosch.com (unknown [10.4.103.109]) by si0vm1949.rbesz01.com (Postfix) with ESMTPS id 453lRH683jz6Cjg80; Wed, 15 May 2019 08:44:59 +0200 (CEST) Received: from localhost.localdomain (10.47.103.61) by FE-HUB2000.de.bosch.com (10.4.103.109) with Microsoft SMTP Server id 15.1.1713.5; Wed, 15 May 2019 08:44:58 +0200 From: To: , Date: Wed, 15 May 2019 11:56:37 +0530 Message-ID: <1557901597-19215-7-git-send-email-vanitha.channaiah@in.bosch.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> References: <1557901597-19215-1-git-send-email-vanitha.channaiah@in.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.47.103.61] X-Brightmail-Tracker: H4sIAAAAAAAAA21Sb0wTZxzmvbuWa8PBceXoj4LLvGQu0alVXKyMLduyLKgJmn2badRDrvQi LeyuEMElIyA2FafYMIWqjcIyjKMRBY2MD2ONGeAYEQLVARugmPiPhSAVVELW88D2w7499/z5 PXmfHIkzgXgTKTpdguTkCzmtntBnBVatP3h91Gqu7s6yDA0EMUuguUJjedz2DLM0nm7APiVy Wp9XanN87p/jc9r+OLwb36PPzhcKxVJB2vjJfr194am5eG7boeHF19oKtPDBMaQjgd4CV05c x44hPcnQ9RhMnpzF1Y8rCP5uaEGKi6FbELj71ypYS6+BW6GZeAWn0Ovh4QOvVsE4LcGps62Y gg20E7qWmnAFE/R7MHXV8+YORefCUtUNrdr8DvzV73nj0dG74MbsJKF25cJo07+46k+G3oYp Qr0P8NujR7iafRfqQvWaWkT7Ymy+GNsFhF1GrCyaSx2bzZbMDVKeIJebN204UOS4htQ1jTdR c8gWRDSJuATK1ThqZTR8qVzmCKIPSYxjqSO2CJWYV5RfZudl+z6ppFCQOROVcWeHlTG8peWS PIcoy2KRM4iAxLkUas/qe1aGyufLygWpSI0FUTpJcEaqgNxlZegC3iUcFIRiQVpRPyJJDqh9 7ZHCZEkoEA7ZxELXisytolBcXByTGqvE1mKkLogyyYRI94hygpKLeYcsFizH09Q4s8JGo7fR VpORylYytKLaS5xvW00ZVGj6rpVhY4Ro8gm6iyK7GahMJZwQ+VGjfUClKxMlL5PR0OamSIbu YGEmmAH+Sgl6/b8j8N8MI+iseongpfsOBr3tXgIu9U4Q0Dfm0cCtztMaGJt/pYWZ+2EKFtte JEKf/0gSDJ3wJUFP7fkkGBk4w0DIPcPAnLfLAPenHxpgzhNKgfrhAAv1060s9A0PsuA970mF usoXqfDcd9EI4bEOgPbbzwAWJv5Jg6vjf6ZDy2R/+pPIlFhkym3iiDKli3f9z5TLbPRtpgr0 2byctnPLeP/hnqO/Tt37wZrTtHW6uXknLA2mses6Tp6zTdmO28fPzObWyLXfCeJQOOP7bx5k 1fy48du9n8vrjHWJ/p6BxWpdY9f27b98+XF5/H73kL/mq/buzkDWRLjli6pBbddunbf0aHb3 gbNrKp8GBumGx9Xvs/Onkn3DPx3/mucI2c5vWotLMv8fyS+YQEAEAAA= Cc: twischer@de.adit-jv.com, alsa-devel@alsa-project.org, Vanitha Channaiah Subject: [alsa-devel] [PATCH v2 6/6] pcm: Update pcm->avail_min with needed_slave_avail_min, after reading unaligned frames X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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" X-Virus-Scanned: ClamAV using ClamSMTP From: Vanitha Channaiah This Fix was analyzed for below usecase : alsa configuration: pcm.line_in { type dsnoop ipc_key INT slave { pcm hardware channels 2 period_time 8000 rate 48000 format S16_LE } bindings { 0 0 1 1 } } pcm.hardware { type hw card "gmd-card" device 0 subdevice 0 channels 2 period_time 2000 rate 48000 format S16_LE } command: $arecord -v -D line_in -r 48000 -c 2 -f S16_LE recordfile.wav Direct Snoop PCM Its setup is: stream : CAPTURE access : RW_INTERLEAVED format : S16_LE subformat : STD channels : 2 rate : 48000 exact rate : 48000 (48000/1) msbits : 16 buffer_size : 1536 period_size : 384 period_time : 8000 tstamp_mode : NONE tstamp_type : MONOTONIC period_step : 1 avail_min : 384 period_event : 0 start_threshold : 1 stop_threshold : 1536 silence_threshold: 0 silence_size : 0 boundary : huge value Hardware PCM card 3 'gmd-card' device 0 subdevice 0 Its setup is: stream : CAPTURE access : MMAP_INTERLEAVED format : S16_LE subformat : STD channels : 2 rate : 48000 exact rate : 48000 (48000/1) msbits : 16 buffer_size : 1536 period_size : 96 period_time : 2000 tstamp_mode : ENABLE tstamp_type : MONOTONIC period_step : 1 avail_min : 96 period_event : 0 start_threshold : 1 stop_threshold : huge value silence_threshold: 0 silence_size : 0 boundary : huge value appl_ptr : 0 hw_ptr : 576 Here, there are no other plugins apart from Dsnoop. Issue: After partial read of unaligned frames(not one period frames), snd_pcm_wait() would block for the pcm->avail_min which would result in blocking for longer periods i.e more than one period as specified by pcm->avail_min For e.g.: Slave period size = 0x60 Client period-size=0x180 No. of Ticks = 4 pcm->avail_min = one period size = 0x180 Issue: - During the start of streaming, the position of slave hw_ptr returned from the driver is 0x20. - avail is 0x20 - hw_ptr is calculated by new_slave_hw_ptr - old_slave_hw_ptr i.e. 0x20 - 0 = 0x20 - hw_ptr updated to 0x20 - avail is 0x20 - app_ptr updated to 0x20 - Now, avail = 0 - snd_pcm_wait() waits till avail=0x180 because pcm->avail_min = 0x180 - After 4 snd_pcm_elapsed(), slave_hw_ptr = 0x180 - Since app_ptr has updated with 0x20, avail becomes 0x160 There is a shortage of 0x20 frames and hence snd_pcm_wait() goes back to wait again. - Now, snd_pcm_wait is locked. - After another 4 snd_pcm_elapsed() slave_hw_ptr = 0x300 - avail = 0x2e0 - snd_pcm_wait() unlocks. So, here snd_pcm_wait() is locked for more than 1 period(exactly 2 periods) Also, this issue can be seen without dsnoop plugin, when HW reports unaligned hw_ptr For e.g. period size = 0x60 pcm->avail_min = 0x60 - During the start of streaming, the position of slave hw_ptr returned from the driver is 0x20. - hw_ptr is calculated by new_slave_hw_ptr - old_slave_hw_ptr i.e. 0x20 - 0 = 0x20 - hw_ptr updated to 0x20 - avail is 0x20 - app_ptr updated to 0x20 - Now, avail = 0 - snd_pcm_wait() waits till avail=0x60 because pcm->avail_min=0x60 - After 1 snd_pcm_elapsed(), slave_hw_ptr = 0x60 - Since app_ptr has updated with 0x20, avail becomes 0x40 There is a shortage of 0x20 frames and hence snd_pcm_wait() goes back to wait again. - Now, snd_pcm_wait is locked. - After another 1 snd_pcm_elapsed(), slave_hw_ptr = 0x120 - avail = 0xe0 - snd_pcm_wait() unlocks. So, here snd_pcm_wait() is locked for more than 1 period (exactly 2 periods) Fix: After reading unaligned frames(not one period frames), set the pcm->avail_min to the needed_avail_slave_min frames so that snd_pcm_wait() blocks till needed_avail_slave_min available Once needed_avail_slave_min frames are read, set back the original pcm->avail_min For ex: Slave period size = 0x60 Client period-size=0x180 No. of Ticks = 4 pcm->avail_min = one period size = 0x180 Fix: - During the start of streaming, the position of slave_hw_ptr returned from the driver is 0x20. - hw_ptr is calculated by new_slave_hw_ptr - old_slave_hw_ptr i.e. 0x20 - 0 = 0x20 - hw_ptr updated to 0x20 - avail is 0x20 - app_ptr updated to 0x20 - Now, avail = 0 - calculate needed_avail_slave_min = 0x160 - update the needed_avail_slave_min to pcm->avail_min i.e. pcm->avail_min = 0x160 - snd_pcm_wait() waits till avail=0x160 - After 4 snd_pcm_elapsed(), slave_hw_ptr = 0x180 - snd_pcm_wait() unlocks. - Once needed_avail_slave_min frames are read, set back the original pcm->avail_min to 0x180 So, here snd_pcm_wait() is locked for 1 period only. Signed-off-by: Vanitha Channaiah --- src/pcm/pcm.c | 21 +++++++++++++++++++++ src/pcm/pcm_local.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index f0db545..f361eb1 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -973,6 +973,7 @@ int snd_pcm_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params) __snd_pcm_unlock(pcm); return err; } + pcm->original_avail_min = pcm->avail_min; __snd_pcm_unlock(pcm); return 0; } @@ -7267,6 +7268,17 @@ void snd_pcm_areas_from_bufs(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas, snd_pcm_unlock(pcm); } +static void snd_pcm_set_avail_min(snd_pcm_t *pcm, snd_pcm_uframes_t avail) +{ + if (avail != pcm->avail_min) { + snd_pcm_sw_params_t swparams; + + snd_pcm_sw_params_current(pcm, &swparams); + swparams.avail_min = avail; + _snd_pcm_sw_params_internal(pcm, &swparams); + } +} + snd_pcm_sframes_t snd_pcm_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas, snd_pcm_uframes_t offset, snd_pcm_uframes_t size, snd_pcm_xfer_areas_func_t func) @@ -7274,6 +7286,7 @@ snd_pcm_sframes_t snd_pcm_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_ snd_pcm_uframes_t xfer = 0; snd_pcm_sframes_t err = 0; snd_pcm_state_t state; + snd_pcm_uframes_t needed_slave_avail_min = 0; if (size == 0) return 0; @@ -7332,6 +7345,14 @@ snd_pcm_sframes_t snd_pcm_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_ if (err < 0) break; frames = err; + pcm->unaligned_frames += frames; + pcm->unaligned_frames %= pcm->period_size; + if (pcm->unaligned_frames) { + needed_slave_avail_min = pcm->period_size - pcm->unaligned_frames; + snd_pcm_set_avail_min(pcm, needed_slave_avail_min); + } else { + snd_pcm_set_avail_min(pcm, pcm->original_avail_min); + } offset += frames; size -= frames; xfer += frames; diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index e103f72..3fdffb4 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -210,6 +210,8 @@ struct _snd_pcm { snd_pcm_tstamp_type_t tstamp_type; /* timestamp type */ unsigned int period_step; snd_pcm_uframes_t avail_min; /* min avail frames for wakeup */ + snd_pcm_uframes_t unaligned_frames; + snd_pcm_uframes_t original_avail_min; int period_event; snd_pcm_uframes_t start_threshold; snd_pcm_uframes_t stop_threshold;