All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: tiwai@suse.de, perex@perex.cz
Cc: alsa-devel@alsa-project.org
Subject: [PATCH 20/35] axfer: add options related to duration and obsolete '--max-file-size' option
Date: Tue, 13 Nov 2018 15:41:32 +0900	[thread overview]
Message-ID: <20181113064147.13577-20-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20181113064147.13577-1-o-takashi@sakamocchi.jp>

In aplay, some options are available to stop data transmission by frame
unit. This commit adds support for the options below:
 * --duration (-d)
  * For duration seconds. The number of data frames transferred in this
  * runtime is calculated by this value and sampling rate.
 * --samples (-s)
  * For the number of data frames to handle in this runtime.

An original aplay has a similar option; '--max-file-time'. This option
is used for capture data transmission to switch file to write data frame
up to maximum number of frames which container format supports, instead
of terminating. However, this may brings complicated file handling to
this program. To reduce maintaining cost, this option is obsoleted.
Additionally, a handler for SIGUSR1 Unix signal has similar feature to
switch the file. For the same reason, the handler is also obsoleted.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 axfer/subcmd-transfer.c |  2 ++
 axfer/xfer-options.c    | 38 ++++++++++++++++++++++++++++++++++++--
 axfer/xfer.h            |  4 ++++
 3 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/axfer/subcmd-transfer.c b/axfer/subcmd-transfer.c
index 36817f3..d5f16cb 100644
--- a/axfer/subcmd-transfer.c
+++ b/axfer/subcmd-transfer.c
@@ -327,6 +327,8 @@ static int context_pre_process(struct context *ctx, snd_pcm_stream_t direction,
 	if (err < 0)
 		return err;
 
+	xfer_options_calculate_duration(&ctx->xfer, total_frame_count);
+
 	return 0;
 }
 
diff --git a/axfer/xfer-options.c b/axfer/xfer-options.c
index 21fc6bb..9233647 100644
--- a/axfer/xfer-options.c
+++ b/axfer/xfer-options.c
@@ -17,6 +17,8 @@ enum no_short_opts {
 	// 128 or later belong to non us-ascii character set.
 	OPT_XFER_TYPE = 128,
 	OPT_DUMP_HW_PARAMS,
+	// Obsoleted.
+	OPT_MAX_FILE_TIME,
 };
 
 static int allocate_paths(struct xfer_context *xfer, char *const *paths,
@@ -228,7 +230,7 @@ int xfer_options_parse_args(struct xfer_context *xfer,
 			    const struct xfer_data *data, int argc,
 			    char *const *argv)
 {
-	static const char *short_opts = "CPhvqf:c:r:t:I";
+	static const char *short_opts = "CPhvqd:s:f:c:r:t:I";
 	static const struct option long_opts[] = {
 		// For generic purposes.
 		{"capture",		0, 0, 'C'},
@@ -237,6 +239,8 @@ int xfer_options_parse_args(struct xfer_context *xfer,
 		{"help",		0, 0, 'h'},
 		{"verbose",		0, 0, 'v'},
 		{"quiet",		0, 0, 'q'},
+		{"duration",		1, 0, 'd'},
+		{"samples",		1, 0, 's'},
 		// For transfer backend.
 		{"format",		1, 0, 'f'},
 		{"channels",		1, 0, 'c'},
@@ -247,6 +251,8 @@ int xfer_options_parse_args(struct xfer_context *xfer,
 		{"separate-channels",	0, 0, 'I'},
 		// For debugging.
 		{"dump-hw-params",	0, 0, OPT_DUMP_HW_PARAMS},
+		// Obsoleted.
+		{"max-file-time",	1, 0, OPT_MAX_FILE_TIME},
 	};
 	char *s_opts;
 	struct option *l_opts;
@@ -295,6 +301,10 @@ int xfer_options_parse_args(struct xfer_context *xfer,
 			++xfer->verbose;
 		else if (key == 'q')
 			xfer->quiet = true;
+		else if (key == 'd')
+			xfer->duration_seconds = arg_parse_decimal_num(optarg, &err);
+		else if (key == 's')
+			xfer->duration_frames = arg_parse_decimal_num(optarg, &err);
 		else if (key == 'f')
 			xfer->sample_format_literal = arg_duplicate_string(optarg, &err);
 		else if (key == 'c')
@@ -309,7 +319,13 @@ int xfer_options_parse_args(struct xfer_context *xfer,
 			xfer->dump_hw_params = true;
 		else if (key == '?')
 			return -EINVAL;
-		else {
+		else if (key == OPT_MAX_FILE_TIME) {
+			fprintf(stderr,
+				"An option '--%s' is obsoleted and has no "
+				"effect.\n",
+				l_opts[l_index].name);
+			err = -EINVAL;
+		} else {
 			err = xfer->ops->parse_opt(xfer, key, optarg);
 			if (err < 0 && err != -ENXIO)
 				break;
@@ -326,6 +342,24 @@ int xfer_options_parse_args(struct xfer_context *xfer,
 	return validate_options(xfer);
 }
 
+void xfer_options_calculate_duration(struct xfer_context *xfer,
+				     uint64_t *total_frame_count)
+{
+	uint64_t frame_count;
+
+	if (xfer->duration_seconds > 0) {
+		frame_count = xfer->duration_seconds * xfer->frames_per_second;
+		if (frame_count < *total_frame_count)
+			*total_frame_count = frame_count;
+	}
+
+	if (xfer->duration_frames > 0) {
+		frame_count = xfer->duration_frames;
+		if (frame_count < *total_frame_count)
+			*total_frame_count = frame_count;
+	}
+}
+
 static const char *const allowed_duplication[] = {
 	"/dev/null",
 	"/dev/zero",
diff --git a/axfer/xfer.h b/axfer/xfer.h
index a234851..21ab85d 100644
--- a/axfer/xfer.h
+++ b/axfer/xfer.h
@@ -30,6 +30,8 @@ struct xfer_context {
 	char *sample_format_literal;
 	char *cntr_format_literal;
 	unsigned int verbose;
+	unsigned int duration_seconds;
+	unsigned int duration_frames;
 	unsigned int frames_per_second;
 	unsigned int samples_per_frame;
 	bool help:1;
@@ -68,6 +70,8 @@ int xfer_options_parse_args(struct xfer_context *xfer,
 			    const struct xfer_data *data, int argc,
 			    char *const *argv);
 int xfer_options_fixup_paths(struct xfer_context *xfer);
+void xfer_options_calculate_duration(struct xfer_context *xfer,
+				     uint64_t *total_frame_count);
 
 // For internal use in 'xfer' module.
 
-- 
2.19.1

  parent reply	other threads:[~2018-11-13  6:42 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1542090296222634077-webhooks-bot@alsa-project.org>
2018-11-13  6:24 ` alsa-utils: axfer: rewrite aplay, adding 'timer-based scheduling' option GitHub pull_request - opened
2018-11-13  6:41   ` [PATCH 01/35] axfer: add an entry point for this command Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 02/35] axfer: add a sub-command to print list of PCMs/devices Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 03/35] axfer: add a common interface to handle a file with audio-specific data format Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 04/35] axfer: add support for a container of Microsoft/IBM RIFF/Wave format Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 05/35] axfer: add support for a container of Sparc AU format Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 06/35] axfer: add support for a container of Creative Tech. voice format Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 07/35] axfer: add support for a container of raw data Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 08/35] axfer: add unit test for container interface Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 09/35] axfer: add a common interface to align data frames on different layout Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 10/35] axfer: add support for a mapper for single target Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 11/35] axfer: add support for a mapper for multiple target Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 12/35] axfer: add a unit test for mapper interface Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 13/35] axfer: add a common interface to transfer data frames Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 14/35] axfer: add a parser for command-line options Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 15/35] axfer: add support to transfer data frames by alsa-lib PCM APIs Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 16/35] axfer: add support for blocking data transmission operation of alsa-lib PCM API Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 17/35] axfer: add a sub-command to transfer data frames Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 18/35] axfer: add informative output and an option to suppress it Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 19/35] axfer: add an option to dump available hardware parameters Takashi Sakamoto
2018-11-13  6:41     ` Takashi Sakamoto [this message]
2018-11-13  6:41     ` [PATCH 21/35] axfer: add an option to finish transmission at XRUN Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 22/35] axfer: add support for non-blocking operation Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 23/35] axfer: add support for MMAP PCM operation Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 24/35] axfer: add an option to suppress event waiting Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 25/35] axfer: add options for buffer arrangement Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 26/35] axfer: add options for software parameters of PCM substream Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 27/35] axfer: add options for plugins in alsa-lib Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 28/35] axfer: add a common interface of waiter for I/O event notification Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 29/35] axfer: add an option for waiter type Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 30/35] axfer: add an implementation of waiter for poll(2) Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 31/35] axfer: add an implementation of waiter for select(2) Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 32/35] axfer: add an implementation of waiter for epoll(7) Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 33/35] axfer: add support for timer-based scheduling model with MMAP operation Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 34/35] axfer: obsolete some unimplemented options Takashi Sakamoto
2018-11-13  6:41     ` [PATCH 35/35] axfer: add support for libffado transmission backend Takashi Sakamoto
2018-11-13 11:27     ` [PATCH 01/35] axfer: add an entry point for this command Takashi Iwai
2018-11-14 16:05       ` Takashi Sakamoto
2018-11-14 16:23         ` Takashi Iwai

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=20181113064147.13577-20-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=perex@perex.cz \
    --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.