From patchwork Fri Mar 23 14:27:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10304823 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 DF60B60384 for ; Fri, 23 Mar 2018 14:36:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF5EB28E7E for ; Fri, 23 Mar 2018 14:36:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2CAB28EF6; Fri, 23 Mar 2018 14:36:19 +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 8996A28E7E for ; Fri, 23 Mar 2018 14:36:17 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id EDF61266B0F; Fri, 23 Mar 2018 15:28:04 +0100 (CET) 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 1E4F5266B0F; Fri, 23 Mar 2018 15:28:03 +0100 (CET) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [62.225.105.245]) by alsa0.perex.cz (Postfix) with ESMTP id DFF65266A73; Fri, 23 Mar 2018 15:27:58 +0100 (CET) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 479393C09A1; Fri, 23 Mar 2018 15:27:57 +0100 (CET) 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 GAxM2MRj39re; Fri, 23 Mar 2018 15:27:48 +0100 (CET) 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 6A49A3C0012; Fri, 23 Mar 2018 15:27:48 +0100 (CET) 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.382.0; Fri, 23 Mar 2018 15:27:48 +0100 From: To: Date: Fri, 23 Mar 2018 15:27:23 +0100 Message-ID: <1521815243-30432-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 - PCM HW APPEND 1/1] pcm: hw: Keep control data from kernel when SND_PCM_APPEND 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 fix the application pointer would be reseted whenever an application opens a device with SND_PCM_APPEND. This would result in an Xrun if the device is already opened and in running state and the appl_ptr is use. Signed-off-by: Timo Wischer diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index b93926c..65b198c 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -1004,16 +1004,28 @@ static int map_status_and_control_data(snd_pcm_t *pcm, bool force_fallback) hw->sync_ptr = NULL; } - /* Initialize the data. */ - hw->mmap_control->appl_ptr = 0; - hw->mmap_control->avail_min = 1; + /* do not initialize in case of append and keep the values from the + * kernel + */ + if (!(pcm->mode & SND_PCM_APPEND)) { + /* Initialize the data. */ + hw->mmap_control->appl_ptr = 0; + hw->mmap_control->avail_min = 1; + } snd_pcm_set_hw_ptr(pcm, &hw->mmap_status->hw_ptr, hw->fd, SNDRV_PCM_MMAP_OFFSET_STATUS + offsetof(struct snd_pcm_mmap_status, hw_ptr)); snd_pcm_set_appl_ptr(pcm, &hw->mmap_control->appl_ptr, hw->fd, SNDRV_PCM_MMAP_OFFSET_CONTROL); if (hw->mmap_control_fallbacked) { - err = sync_ptr1(hw, 0); + unsigned int flags; + /* read appl_ptr and avail_min from kernel when device opened + * with SND_PCM_APPEND flag + */ + if (pcm->mode & SND_PCM_APPEND) + flags = SNDRV_PCM_SYNC_PTR_APPL | + SNDRV_PCM_SYNC_PTR_AVAIL_MIN; + err = sync_ptr1(hw, flags); if (err < 0) return err; } @@ -1539,6 +1551,8 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name, int fd, mode |= SND_PCM_NONBLOCK; if (fmode & O_ASYNC) mode |= SND_PCM_ASYNC; + if (fmode & O_APPEND) + mode |= SND_PCM_APPEND; if (ioctl(fd, SNDRV_PCM_IOCTL_PVERSION, &ver) < 0) { ret = -errno;