http://kmt449.blogspot.com/2010/08/linux.html
の続き。
arecordは出力した大きさが2GBになると止まるようです。
alsa-utils-1.0.23のaplay.cへのパッチを作りました。
--adhoc-duration hh:mm:ss
で指定した時間、キャプチャし続けるようにします。00:00:00で、止めるかエラーするまで動き続けます。
--adhoc-durationは、stdoutへ出力するときのみ有効です。
Index: aplay.c
===================================================================
--- aplay.c
(リビジョン 76)
+++ aplay.c
(作業コピー)
@@ -85,6 +85,7 @@
unsigned int rate;
} hwparams, rhwparams;
static int timelimit = 0;
+static long adhoc_duration = -1;
static int quiet_mode = 0;
static int file_type = FORMAT_DEFAULT;
static int open_mode = 0;
@@ -206,7 +207,8 @@
" --max-file-time=# start another output file when the old file has recorded\n"
" for this many seconds\n"
" --process-id-file write the process ID here\n"
-" --use-strftime apply the strftime facility to the output file name\n")
+" --use-strftime apply the strftime facility to the output file name\n"
+" --adhoc-duration=##:##:## ADHOC duration\n")
, command);
printf(_("Recognized sample formats are:"));
for (k = 0; k < SND_PCM_FORMAT_LAST; ++k) {
@@ -333,7 +335,7 @@
static void version(void)
{
-
printf("%s: version " SND_UTIL_VERSION_STR " by Jaroslav Kysela <perex@perex.cz>\n", command);
+
printf("%s: version " SND_UTIL_VERSION_STR "p00 by Jaroslav Kysela <perex@perex.cz>\n", command);
}
/*
@@ -350,9 +352,11 @@
static void signal_handler(int sig)
{
+
int falrm = (sig == SIGALRM);
+
if (verbose==2)
putchar('\n');
-
if (!quiet_mode)
+
if (!quiet_mode && !falrm)
fprintf(stderr, _("Aborted by signal %s...\n"), strsignal(sig));
if (stream == SND_PCM_STREAM_CAPTURE) {
if (fmt_rec_table[file_type].end) {
@@ -369,7 +373,7 @@
snd_pcm_close(handle);
handle = NULL;
}
-
prg_exit(EXIT_FAILURE);
+
prg_exit(falrm ? EXIT_SUCCESS : EXIT_FAILURE);
}
/* call on SIGUSR1 signal. */
@@ -392,7 +396,8 @@
OPT_TEST_NOWAIT,
OPT_MAX_FILE_TIME,
OPT_PROCESS_ID_FILE,
-
OPT_USE_STRFTIME
+
OPT_USE_STRFTIME,
+
OPT_ADHOC_DURATION
};
int main(int argc, char *argv[])
@@ -436,6 +441,7 @@
{"max-file-time", 1, 0, OPT_MAX_FILE_TIME},
{"process-id-file", 1, 0, OPT_PROCESS_ID_FILE},
{"use-strftime", 0, 0, OPT_USE_STRFTIME},
+
{"adhoc-duration", /*has_arg*/1, /*flag*/0, /*val*/OPT_ADHOC_DURATION},
{0, 0, 0, 0}
};
char *pcm_name = "default";
@@ -634,7 +640,17 @@
case OPT_USE_STRFTIME:
use_strftime = 1;
break;
+
case OPT_ADHOC_DURATION:
+
{
+
int hh, mm, ss;
+
if (sscanf(optarg, "%02d:%02d:%02d", &hh, &mm, &ss) != 3) {
+
goto L_ERROR;
+
}
+
adhoc_duration = ((hh * 60) + mm) * 60 + ss + /*margin*/1;
+
}
+
break;
default:
+
L_ERROR:
fprintf(stderr, _("Try `%s --help' for more information.\n"), command);
return 1;
}
@@ -706,6 +722,7 @@
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
signal(SIGABRT, signal_handler);
+
signal(SIGALRM, signal_handler);
signal(SIGUSR1, signal_handler_recycle);
if (interleaved) {
if (optind > argc - 1) {
@@ -2617,6 +2634,17 @@
count = fmt_rec_table[file_type].max_filesize;
}
+
if (adhoc_duration > 0) {
+
if (verbose) {
+
int hh, mm, ss;
+
hh = adhoc_duration / 60 / 60;
+
mm = (adhoc_duration - hh * 60 * 60) / 60;
+
ss = adhoc_duration - hh * 60 * 60 - mm * 60;
+
fprintf(stderr, "adhoc_duration=%ld(%02d:%02d:%02d).\n", adhoc_duration, hh, mm, ss);
+
}
+
alarm(adhoc_duration);
+
}
+
do {
/* open a file to write */
if(!tostdout) {
@@ -2660,8 +2688,10 @@
perror(name);
prg_exit(EXIT_FAILURE);
}
-
count -= c;
-
rest -= c;
+
if (!tostdout || adhoc_duration < 0) {
+
count -= c;
+
rest -= c;
+
}
fdcount += c;
}