From patchwork Fri Jun 30 11:37:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 9819343 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 9ED6160224 for ; Fri, 30 Jun 2017 11:37:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FAFC2522B for ; Fri, 30 Jun 2017 11:37:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8410A285F1; Fri, 30 Jun 2017 11:37:57 +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=-1.9 required=2.0 tests=BAYES_00, 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 A16FF2522B for ; Fri, 30 Jun 2017 11:37:56 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id C9FD52674AA; Fri, 30 Jun 2017 13:37:38 +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 A8DC92674A5; Fri, 30 Jun 2017 13:37:37 +0200 (CEST) Received: from smtp-proxy002.phy.lolipop.jp (smtp-proxy002.phy.lolipop.jp [157.7.104.43]) by alsa0.perex.cz (Postfix) with ESMTP id F02E626749D for ; Fri, 30 Jun 2017 13:37:33 +0200 (CEST) Received: from smtp-proxy002.phy.lolipop.lan (HELO smtp-proxy002.phy.lolipop.jp) (172.19.44.43) (smtp-auth username m12129643-o-takashi, mechanism plain) by smtp-proxy002.phy.lolipop.jp (qpsmtpd/0.82) with ESMTPA; Fri, 30 Jun 2017 20:37:31 +0900 Received: from 127.0.0.1 (127.0.0.1) by smtp-proxy002.phy.lolipop.jp (LOLIPOP-Fsecure); Fri, 30 Jun 2017 20:37:29 +0900 (JST) X-Virus-Status: clean(LOLIPOP-Fsecure) From: Takashi Sakamoto To: tiwai@suse.de Date: Fri, 30 Jun 2017 20:37:27 +0900 Message-Id: <20170630113729.13656-5-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170630113729.13656-1-o-takashi@sakamocchi.jp> References: <20170630113729.13656-1-o-takashi@sakamocchi.jp> Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH alsa-lib v2 4/6] pcm: hw: add a helper function to issue appl_ptr without side-effects 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP After starting, PCM substream shift its state to running and applications can move appl_ptr by several ways. When status and control data of runtime of the PCM substream is not mapped, the applications should issue appl_ptr to kernel land. In this case, when any PCM frames is handled by mmap operation, the applications should issue appl_ptr to update. This commit adds a helper function for this purpose. To avoid unexpected change of avail_min, this commit uses a flag just to update appl_ptr. Signed-off-by: Takashi Sakamoto --- src/pcm/pcm_hw.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 8455baaf..51512306 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -151,6 +151,15 @@ static int sync_ptr(snd_pcm_hw_t *hw, unsigned int flags) return 0; } +static int issue_applptr(snd_pcm_hw_t *hw) +{ + if (!hw->mmap_control_fallbacked) + return 0; + + /* Avoid unexpected change of avail_min in kernel space. */ + return sync_ptr1(hw, SNDRV_PCM_SYNC_PTR_AVAIL_MIN); +} + static int request_hwsync(snd_pcm_hw_t *hw) { if (!hw->mmap_status_fallbacked) @@ -667,7 +676,7 @@ static int snd_pcm_hw_start(snd_pcm_t *pcm) assert(pcm->stream != SND_PCM_STREAM_PLAYBACK || snd_pcm_mmap_playback_hw_avail(pcm) > 0); #endif - sync_ptr(hw, 0); + issue_applptr(hw); if (ioctl(hw->fd, SNDRV_PCM_IOCTL_START) < 0) { err = -errno; SYSMSG("SNDRV_PCM_IOCTL_START failed (%i)", err); @@ -1081,7 +1090,7 @@ static snd_pcm_sframes_t snd_pcm_hw_mmap_commit(snd_pcm_t *pcm, snd_pcm_hw_t *hw = pcm->private_data; snd_pcm_mmap_appl_forward(pcm, size); - sync_ptr(hw, 0); + issue_applptr(hw); #ifdef DEBUG_MMAP fprintf(stderr, "appl_forward: hw_ptr = %li, appl_ptr = %li, size = %li\n", *pcm->hw.ptr, *pcm->appl.ptr, size); #endif