From patchwork Sat Dec 8 01:55:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guedes, Andre" X-Patchwork-Id: 10719105 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 4BB4313BF for ; Sat, 8 Dec 2018 02:02:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B14E2DB9D for ; Sat, 8 Dec 2018 02:02:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F72A2DBAA; Sat, 8 Dec 2018 02:02:41 +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 764952DB9D for ; Sat, 8 Dec 2018 02:02:40 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id EEC7F267D3B; Sat, 8 Dec 2018 03:02:31 +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 C7E0F267D53; Sat, 8 Dec 2018 03:02:26 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by alsa0.perex.cz (Postfix) with ESMTP id 48E0E267D3B 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="116977201" 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:45 -0800 Message-Id: <20181208015550.20268-3-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 2/7] aaf: Add presentation time tolerance 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 Different AVTP applications have different presentation time tolerance. The current version of the plugin doesn't support any tolerance so this patch extends the AAF plugin in order to enable the user to configure that tolerance value. The presentation time tolerance is specified in microseconds and it is relevant only when the plugin is operating in capture mode. For more information see the 'Plugin Configuration' session in doc/aaf.txt This patch also does some code refactoring and encapsulates all presentation time validation code in the new is_ptime_valid() helper function. Signed-off-by: Andre Guedes --- aaf/pcm_aaf.c | 48 +++++++++++++++++++++++++++++++++++++----------- doc/aaf.txt | 6 ++++++ 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/aaf/pcm_aaf.c b/aaf/pcm_aaf.c index b1c3d83..8410dcf 100644 --- a/aaf/pcm_aaf.c +++ b/aaf/pcm_aaf.c @@ -60,6 +60,7 @@ typedef struct { int mtt; int t_uncertainty; snd_pcm_uframes_t frames_per_pdu; + int ptime_tolerance; int sk_fd; int timer_fd; @@ -328,6 +329,17 @@ static int aaf_load_config(snd_pcm_aaf_t *aaf, snd_config_t *conf) goto err; aaf->frames_per_pdu = frames_per_pdu; + } else if (strcmp(id, "ptime_tolerance") == 0) { + long ptime_tolerance; + + if (snd_config_get_integer(entry, + &ptime_tolerance) < 0) + goto err; + + if (ptime_tolerance < 0) + goto err; + + aaf->ptime_tolerance = ptime_tolerance * NSEC_PER_USEC; } else { SNDERR("Invalid configuration: %s", id); goto err; @@ -699,6 +711,27 @@ static int aaf_tx_pdu(snd_pcm_aaf_t *aaf) return 0; } +static bool is_ptime_valid(snd_pcm_aaf_t *aaf, uint32_t avtp_time) +{ + const uint64_t exp_ptime = aaf->prev_ptime + aaf->timer_period; + const uint64_t lower_bound = exp_ptime - aaf->ptime_tolerance; + const uint64_t upper_bound = exp_ptime + aaf->ptime_tolerance; + const uint64_t ptime = (exp_ptime & 0xFFFFFFFF00000000ULL) | avtp_time; + + if (ptime < lower_bound || ptime > upper_bound) { + pr_debug("Presentation time not expected"); + return false; + } + + if (ptime < aaf_mclk_gettime(aaf)) { + pr_debug("Presentation time in the past"); + return false; + } + + aaf->prev_ptime = ptime; + return true; +} + static int aaf_rx_pdu(snd_pcm_aaf_t *aaf) { int res; @@ -753,19 +786,10 @@ static int aaf_rx_pdu(snd_pcm_aaf_t *aaf) if (res < 0) return res; } else { - uint64_t ptime = aaf->prev_ptime + aaf->timer_period; - - if (avtp_time != ptime % (1ULL << 32)) { - pr_debug("Packet dropped: PT not expected"); + if (!is_ptime_valid(aaf, avtp_time)) { + pr_debug("Packet dropped: PT not valid"); return 0; } - - if (ptime < aaf_mclk_gettime(aaf)) { - pr_debug("Packet dropped: PT in the past"); - return 0; - } - - aaf->prev_ptime = ptime; } hw_avail = snd_pcm_ioplug_hw_avail(io, aaf->hw_virt_ptr, io->appl_ptr); @@ -950,6 +974,8 @@ static void aaf_dump(snd_pcm_ioplug_t *io, snd_output_t *out) aaf->t_uncertainty / NSEC_PER_USEC); snd_output_printf(out, " frames per AVTPDU: %lu\n", aaf->frames_per_pdu); + snd_output_printf(out, " ptime tolerance: %d\n", + aaf->ptime_tolerance / NSEC_PER_USEC); } static int aaf_hw_params(snd_pcm_ioplug_t *io, diff --git a/doc/aaf.txt b/doc/aaf.txt index cae86d8..e72eba2 100644 --- a/doc/aaf.txt +++ b/doc/aaf.txt @@ -121,6 +121,11 @@ as follows: * frames_per_pdu: Number of audio frames transmitted in one AVTPDU. + * ptime_tolerance: Presentation time tolerance in microseconds. + AVTPDUs with presentation time off by +- ptime_tolerance are not + considered invalid. This option is relevant only when operating in + capture mode. + Plugin Usage ------------ @@ -138,6 +143,7 @@ below: mtt 2000 time_uncertainty 125 frames_per_pdu 6 + ptime_tolerance 100 } Put the above to ~/.asoundrc (or /etc/asound.conf), and use the AAF PCM virtual