All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Guedes <andre.guedes@intel.com>
To: alsa-devel@alsa-project.org
Cc: tiwai@suse.de, liam.r.girdwood@linux.intel.com,
	pierre-louis.bossart@linux.intel.com
Subject: [PATCH - AAF PCM plugin 2/7] aaf: Add presentation time tolerance
Date: Fri,  7 Dec 2018 17:55:45 -0800	[thread overview]
Message-ID: <20181208015550.20268-3-andre.guedes@intel.com> (raw)
In-Reply-To: <20181208015550.20268-1-andre.guedes@intel.com>

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 <andre.guedes@intel.com>
---
 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
-- 
2.19.1

  parent reply	other threads:[~2018-12-08  2:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-08  1:55 [PATCH - AAF PCM plugin 0/7] Follow-up improvements Andre Guedes
2018-12-08  1:55 ` [PATCH - AAF PCM plugin 1/7] doc: Fix typo in AAF doc Andre Guedes
2018-12-08  1:55 ` Andre Guedes [this message]
2018-12-08  1:55 ` [PATCH - AAF PCM plugin 3/7] aaf: Refactor AVTPDU transmission routines Andre Guedes
2018-12-08  1:55 ` [PATCH - AAF PCM plugin 4/7] aaf: Refactor AVTPDU reception routines Andre Guedes
2018-12-08  1:55 ` [PATCH - AAF PCM plugin 5/7] aaf: Refactor timeout routines Andre Guedes
2018-12-08  1:55 ` [PATCH - AAF PCM plugin 6/7] aaf: Tx multiple AVTPDUs per media clock tick Andre Guedes
2018-12-08  1:55 ` [PATCH - AAF PCM plugin 7/7] aaf: AVTPDU transmission periodicity Andre Guedes
2018-12-10 10:22 ` [PATCH - AAF PCM plugin 0/7] Follow-up improvements Takashi Iwai
2018-12-10 10:59   ` Takashi Iwai
2018-12-10 20:44     ` Guedes, Andre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181208015550.20268-3-andre.guedes@intel.com \
    --to=andre.guedes@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.