From patchwork Fri Mar 2 16:21:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10255117 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 6592960211 for ; Fri, 2 Mar 2018 16:22:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C1392899B for ; Fri, 2 Mar 2018 16:22:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A8C028A14; Fri, 2 Mar 2018 16:22:13 +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 CB4FE28A25 for ; Fri, 2 Mar 2018 16:21:55 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 825C8267439; Fri, 2 Mar 2018 17:21:50 +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 53C0B267440; Fri, 2 Mar 2018 17:21:48 +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 91681267440 for ; Fri, 2 Mar 2018 17:21:46 +0100 (CET) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 2AD4F3C0BAC; Fri, 2 Mar 2018 17:21:46 +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 oBd5w8h3yLzs; Fri, 2 Mar 2018 17:21:36 +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 665783C023A; Fri, 2 Mar 2018 17:21:36 +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, 2 Mar 2018 17:21:36 +0100 From: To: Date: Fri, 2 Mar 2018 17:21:12 +0100 Message-ID: <1520007674-14618-2-git-send-email-twischer@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520007674-14618-1-git-send-email-twischer@de.adit-jv.com> References: <1520007674-14618-1-git-send-email-twischer@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.172] Cc: Timo Wischer , alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - PCM 2/3] pcm: ioplug: Provide hw_avail helper function for plugins 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 This function can be called without calling snd_pcm_avail_update(). The call to snd_pcm_avail_update() can take some time. Therefore some developers would not like to call it from a real-time context (e.g. from JACK client context). Signed-off-by: Timo Wischer diff --git a/include/pcm_ioplug.h b/include/pcm_ioplug.h index e75f973..778d9c6 100644 --- a/include/pcm_ioplug.h +++ b/include/pcm_ioplug.h @@ -234,6 +234,9 @@ int snd_pcm_ioplug_set_param_list(snd_pcm_ioplug_t *io, int type, unsigned int n /* change PCM status */ int snd_pcm_ioplug_set_state(snd_pcm_ioplug_t *ioplug, snd_pcm_state_t state); +/* calucalte the available frames */ +snd_pcm_uframes_t snd_pcm_ioplug_hw_avail(const snd_pcm_ioplug_t* const ioplug, const snd_pcm_uframes_t hw_ptr, const snd_pcm_uframes_t appl_ptr); + /** \} */ #endif /* __ALSA_PCM_IOPLUG_H */ diff --git a/src/pcm/pcm_ioplug.c b/src/pcm/pcm_ioplug.c index 9970646..a0cb778 100644 --- a/src/pcm/pcm_ioplug.c +++ b/src/pcm/pcm_ioplug.c @@ -1148,3 +1148,27 @@ int snd_pcm_ioplug_set_state(snd_pcm_ioplug_t *ioplug, snd_pcm_state_t state) ioplug->state = state; return 0; } + +/** + * \brief Get the available frames. This function can be used to calculate the + * the available frames before calling #snd_pcm_avail_update() + * \param ioplug the ioplug handle + * \param hw_ptr hardware pointer in frames + * \param appl_ptr application pointer in frames + * \return available frames for the hardware + */ +snd_pcm_uframes_t snd_pcm_ioplug_hw_avail(const snd_pcm_ioplug_t* const ioplug, + const snd_pcm_uframes_t hw_ptr, + const snd_pcm_uframes_t appl_ptr) +{ + /* available data/space which can be transfered by the user application */ + const snd_pcm_uframes_t user_avail = __snd_pcm_avail(ioplug->pcm, hw_ptr, + appl_ptr); + + if (user_avail > ioplug->pcm->buffer_size) { + /* there was an Xrun */ + return 0; + } + /* available data/space which can be transfered by the DMA */ + return ioplug->pcm->buffer_size - user_avail; +} diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index 3d95e17..b695b92 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -467,10 +467,12 @@ static inline int snd_pcm_check_error(snd_pcm_t *pcm, int err) return err; } -static inline snd_pcm_uframes_t snd_pcm_mmap_playback_avail(snd_pcm_t *pcm) +static inline snd_pcm_uframes_t __snd_pcm_playback_avail(snd_pcm_t *pcm, + const snd_pcm_uframes_t hw_ptr, + const snd_pcm_uframes_t appl_ptr) { snd_pcm_sframes_t avail; - avail = *pcm->hw.ptr + pcm->buffer_size - *pcm->appl.ptr; + avail = hw_ptr + pcm->buffer_size - appl_ptr; if (avail < 0) avail += pcm->boundary; else if ((snd_pcm_uframes_t) avail >= pcm->boundary) @@ -478,21 +480,40 @@ static inline snd_pcm_uframes_t snd_pcm_mmap_playback_avail(snd_pcm_t *pcm) return avail; } -static inline snd_pcm_uframes_t snd_pcm_mmap_capture_avail(snd_pcm_t *pcm) +static inline snd_pcm_uframes_t snd_pcm_mmap_playback_avail(snd_pcm_t *pcm) +{ + return __snd_pcm_playback_avail(pcm, *pcm->hw.ptr, *pcm->appl.ptr); +} + +static inline snd_pcm_uframes_t __snd_pcm_capture_avail(snd_pcm_t *pcm, + const snd_pcm_uframes_t hw_ptr, + const snd_pcm_uframes_t appl_ptr) { snd_pcm_sframes_t avail; - avail = *pcm->hw.ptr - *pcm->appl.ptr; + avail = hw_ptr - appl_ptr; if (avail < 0) avail += pcm->boundary; return avail; } -static inline snd_pcm_uframes_t snd_pcm_mmap_avail(snd_pcm_t *pcm) +static inline snd_pcm_uframes_t snd_pcm_mmap_playback_avail(snd_pcm_t *pcm) +{ + return __snd_pcm_capture_avail(pcm, *pcm->hw.ptr, *pcm->appl.ptr); +} + +static inline snd_pcm_uframes_t __snd_pcm_avail(snd_pcm_t *pcm, + const snd_pcm_uframes_t hw_ptr, + const snd_pcm_uframes_t appl_ptr) { if (pcm->stream == SND_PCM_STREAM_PLAYBACK) - return snd_pcm_mmap_playback_avail(pcm); + return snd_pcm_playback_avail(pcm, hw_ptr, appl_ptr); else - return snd_pcm_mmap_capture_avail(pcm); + return snd_pcm_capture_avail(pcm, hw_ptr, appl_ptr); +} + +static inline snd_pcm_uframes_t snd_pcm_mmap_avail(snd_pcm_t *pcm) +{ + return __snd_pcm_avail(pcm, *pcm->hw.ptr, *pcm->appl.ptr); } static inline snd_pcm_sframes_t snd_pcm_mmap_playback_hw_avail(snd_pcm_t *pcm)