From patchwork Sat Dec 8 01:55:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guedes, Andre" X-Patchwork-Id: 10719109 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 276241731 for ; Sat, 8 Dec 2018 02:02:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14EA72DC03 for ; Sat, 8 Dec 2018 02:02:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0826C2DC46; Sat, 8 Dec 2018 02:02:59 +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 4750F2DC03 for ; Sat, 8 Dec 2018 02:02:58 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id C9205267D65; Sat, 8 Dec 2018 03:02:40 +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 8CC6D267D58; Sat, 8 Dec 2018 03:02:28 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by alsa0.perex.cz (Postfix) with ESMTP id 812A8267D44 for ; Sat, 8 Dec 2018 03:02:24 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Dec 2018 18:02:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,328,1539673200"; d="scan'208";a="116977203" Received: from aguedesl-mac01.jf.intel.com ([10.24.12.59]) by FMSMGA003.fm.intel.com with ESMTP; 07 Dec 2018 18:02:20 -0800 From: Andre Guedes To: alsa-devel@alsa-project.org Date: Fri, 7 Dec 2018 17:55:46 -0800 Message-Id: <20181208015550.20268-4-andre.guedes@intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181208015550.20268-1-andre.guedes@intel.com> References: <20181208015550.20268-1-andre.guedes@intel.com> MIME-Version: 1.0 Cc: tiwai@suse.de, liam.r.girdwood@linux.intel.com, pierre-louis.bossart@linux.intel.com Subject: [alsa-devel] [PATCH - AAF PCM plugin 3/7] aaf: Refactor AVTPDU transmission routines 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 This patch does some code refactoring in the AVTPDU transmission routines in order to prepare the code to support the transmission offload mechanism that will be added by upcoming patches. No functionality is added or removed by this patch. In summary, code from aaf_tx_pdu() is moved into aaf_mclk_timeout_ playback() and into a new function introduced by this patch called aaf_tx_pdus(). Below follows more details about the code refactoring. The function aaf_tx_pdu() is modified so it only takes care of setting the payload, sequence number and presentation time from the AVTPDU, and sending it to the kernel. The new function aaf_tx_pdus() calculates the presentation time from each AVTPDU and calls aaf_tx_pdu() multiple times, according to the pdu count argument. Finally, the function aaf_mclk_timeout_playback() now checks if there are frames available to the "hardware" and takes care of moving the hardware pointer forward. Signed-off-by: Andre Guedes --- aaf/pcm_aaf.c | 54 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/aaf/pcm_aaf.c b/aaf/pcm_aaf.c index 8410dcf..1ad1586 100644 --- a/aaf/pcm_aaf.c +++ b/aaf/pcm_aaf.c @@ -661,28 +661,18 @@ static uint64_t aaf_mclk_gettime(snd_pcm_aaf_t *aaf) (aaf->timer_expirations - 1); } -static int aaf_tx_pdu(snd_pcm_aaf_t *aaf) +static int aaf_tx_pdu(snd_pcm_aaf_t *aaf, snd_pcm_uframes_t ptr, + uint64_t ptime) { int res; - uint64_t ptime; ssize_t n; - snd_pcm_uframes_t hw_avail; snd_pcm_ioplug_t *io = &aaf->io; struct avtp_stream_pdu *pdu = aaf->pdu; - hw_avail = snd_pcm_ioplug_hw_avail(io, aaf->hw_ptr, io->appl_ptr); - if (hw_avail < aaf->frames_per_pdu) { - /* If the number of available frames is less than number of - * frames needed to fill an AVTPDU, we reached an underrun - * state. - */ - return -EPIPE; - } - res = snd_pcm_areas_copy_wrap(aaf->payload_areas, 0, aaf->frames_per_pdu, aaf->audiobuf_areas, - (aaf->hw_ptr % io->buffer_size), + (ptr % io->buffer_size), io->buffer_size, io->channels, aaf->frames_per_pdu, io->format); if (res < 0) { @@ -694,7 +684,6 @@ static int aaf_tx_pdu(snd_pcm_aaf_t *aaf) if (res < 0) return res; - ptime = aaf_mclk_gettime(aaf) + aaf->mtt + aaf->t_uncertainty; res = avtp_aaf_pdu_set(pdu, AVTP_AAF_FIELD_TIMESTAMP, ptime); if (res < 0) return res; @@ -707,7 +696,27 @@ static int aaf_tx_pdu(snd_pcm_aaf_t *aaf) return -EIO; } - aaf_inc_ptr(&aaf->hw_ptr, aaf->frames_per_pdu, aaf->boundary); + return 0; +} + +static int aaf_tx_pdus(snd_pcm_aaf_t *aaf, int pdu_count) +{ + int res; + uint64_t ptime; + snd_pcm_uframes_t ptr; + + ptime = aaf_mclk_gettime(aaf) + aaf->mtt + aaf->t_uncertainty; + ptr = aaf->hw_ptr; + + while (pdu_count--) { + res = aaf_tx_pdu(aaf, ptr, ptime); + if (res < 0) + return res; + + ptime += aaf->timer_period; + ptr += aaf->frames_per_pdu; + } + return 0; } @@ -845,6 +854,8 @@ static int aaf_mclk_timeout_playback(snd_pcm_aaf_t *aaf) int res; ssize_t n; uint64_t expirations; + snd_pcm_uframes_t hw_avail; + snd_pcm_ioplug_t *io = &aaf->io; n = read(aaf->timer_fd, &expirations, sizeof(uint64_t)); if (n < 0) { @@ -858,9 +869,20 @@ static int aaf_mclk_timeout_playback(snd_pcm_aaf_t *aaf) while (expirations--) { aaf->timer_expirations++; - res = aaf_tx_pdu(aaf); + hw_avail = snd_pcm_ioplug_hw_avail(io, aaf->hw_ptr, io->appl_ptr); + if (hw_avail < aaf->frames_per_pdu) { + /* If the number of available frames is less than + * number of frames needed to fill an AVTPDU, we + * reached an underrun state. + */ + return -EPIPE; + } + + res = aaf_tx_pdus(aaf, 1); if (res < 0) return res; + + aaf_inc_ptr(&aaf->hw_ptr, aaf->frames_per_pdu, aaf->boundary); } return 0;