All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Hofman <pavel.hofman@ivitera.com>
To: alsa-devel@alsa-project.org
Cc: Pavel Hofman <pavel.hofman@ivitera.com>
Subject: [PATCH] aplay: Support setting timestamp
Date: Thu, 16 Jun 2022 08:54:26 +0200	[thread overview]
Message-ID: <20220616065426.27915-1-pavel.hofman@ivitera.com> (raw)

To allow enabling timestamp and specify its type, a new option
--tstamp-type=TYPE is added. Recognized values are none (default),
gettimeofday, monotonic, monotonic-raw.

Signed-off-by: Pavel Hofman <pavel.hofman@ivitera.com>
---
 aplay/aplay.1 |  4 ++++
 aplay/aplay.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/aplay/aplay.1 b/aplay/aplay.1
index 3bba59d..d3b7dce 100644
--- a/aplay/aplay.1
+++ b/aplay/aplay.1
@@ -207,6 +207,10 @@ sampling rates, numbers of channels, period and buffer bytes/sizes/times.
 For raw device hw:X this option basically lists hardware capabilities of
 the soundcard.
 .TP
+\fI\-\-tstamp\-type=TYPE\fP
+Specifies timestamp type inside the software configuration container.
+Types are: none (default), gettimeofday, monotonic, monotonic\-raw.
+.TP
 \fI\-\-fatal\-errors\fP
 Disables recovery attempts when errors (e.g. xrun) are encountered; the
 aplay process instead aborts immediately.
diff --git a/aplay/aplay.c b/aplay/aplay.c
index 63a4e34..5d15a32 100644
--- a/aplay/aplay.c
+++ b/aplay/aplay.c
@@ -139,6 +139,8 @@ static int use_strftime = 0;
 volatile static int recycle_capture_file = 0;
 static long term_c_lflag = -1;
 static int dump_hw_params = 0;
+static int enable_tstamp = 0;
+static snd_pcm_tstamp_type_t tstamp_type = SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY;
 
 static int fd = -1;
 static off64_t pbrec_count = LLONG_MAX, fdcount;
@@ -244,6 +246,8 @@ _("Usage: %s [OPTION]... [FILE]...\n"
 "    --process-id-file   write the process ID here\n"
 "    --use-strftime      apply the strftime facility to the output file name\n"
 "    --dump-hw-params    dump hw_params of the device\n"
+"    --tstamp-type=TYPE  set timestamp (TYPE: none (default), gettimeofday,\n"
+"                        monotonic, monotonic-raw)\n"
 "    --fatal-errors      treat all errors as fatal\n"
   )
 		, command);
@@ -430,6 +434,7 @@ enum {
 	OPT_PROCESS_ID_FILE,
 	OPT_USE_STRFTIME,
 	OPT_DUMP_HWPARAMS,
+	OPT_TSTAMP_TYPE,
 	OPT_FATAL_ERRORS,
 };
 
@@ -517,6 +522,7 @@ int main(int argc, char *argv[])
 		{"use-strftime", 0, 0, OPT_USE_STRFTIME},
 		{"interactive", 0, 0, 'i'},
 		{"dump-hw-params", 0, 0, OPT_DUMP_HWPARAMS},
+		{"tstamp-type", 1, 0, OPT_TSTAMP_TYPE},
 		{"fatal-errors", 0, 0, OPT_FATAL_ERRORS},
 #ifdef CONFIG_SUPPORT_CHMAP
 		{"chmap", 1, 0, 'm'},
@@ -799,6 +805,23 @@ int main(int argc, char *argv[])
 		case OPT_DUMP_HWPARAMS:
 			dump_hw_params = 1;
 			break;
+		case OPT_TSTAMP_TYPE:
+			if (strcasecmp(optarg, "gettimeofday") == 0) {
+				enable_tstamp = 1;
+				tstamp_type = SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY;
+			} else if (strcasecmp(optarg, "monotonic") == 0) {
+				enable_tstamp = 1;
+				tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC;
+			} else if (strcasecmp(optarg, "monotonic-raw") == 0) {
+				enable_tstamp = 1;
+				tstamp_type = SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW;
+			} else if (strcasecmp(optarg, "none") == 0)
+				enable_tstamp = 0;
+			else {
+				error(_("unrecognized timestamp type %s"), optarg);
+				return 1;
+			}
+			break;
 		case OPT_FATAL_ERRORS:
 			fatal_errors = 1;
 			break;
@@ -1453,6 +1476,15 @@ static void set_params(void)
 		stop_threshold = (double) rate * stop_delay / 1000000;
 	err = snd_pcm_sw_params_set_stop_threshold(handle, swparams, stop_threshold);
 	assert(err >= 0);
+	if (enable_tstamp) {
+		err = snd_pcm_sw_params_set_tstamp_mode(handle, swparams, SND_PCM_TSTAMP_ENABLE);
+		assert(err >= 0);
+		err = snd_pcm_sw_params_set_tstamp_type(handle, swparams, tstamp_type);
+		if (err < 0) {
+			error(_("Unable to set the requested timestamp type."));
+			prg_exit(EXIT_FAILURE);
+		}
+	}
 
 	if (snd_pcm_sw_params(handle, swparams) < 0) {
 		error(_("unable to install sw params:"));
-- 
2.25.1


             reply	other threads:[~2022-06-16  6:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-16  6:54 Pavel Hofman [this message]
2022-06-16  8:13 ` [PATCH] aplay: Support setting timestamp Takashi Sakamoto
2022-06-16 10:00   ` Pavel Hofman
2022-06-16 10:50     ` Jaroslav Kysela
2022-06-18 15:13       ` Pavel Hofman
2022-06-18  8:23     ` Takashi Sakamoto
2022-06-18 15:20       ` Pavel Hofman

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=20220616065426.27915-1-pavel.hofman@ivitera.com \
    --to=pavel.hofman@ivitera.com \
    --cc=alsa-devel@alsa-project.org \
    /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.