Fix misc bugs in arecord

- remove unused static declaration
- fix double close in signal handler
- fix NULL reference
- fix max file size to stdout with non-raw format
- code clean up
This commit is contained in:
Takashi Iwai 2006-05-18 12:33:35 +02:00
parent 56190f977b
commit ca5cc4b984

View file

@ -116,7 +116,6 @@ static void begin_voc(int fd, size_t count);
static void end_voc(int fd); static void end_voc(int fd);
static void begin_wave(int fd, size_t count); static void begin_wave(int fd, size_t count);
static void end_wave(int fd); static void end_wave(int fd);
static void end_raw(int fd);
static void begin_au(int fd, size_t count); static void begin_au(int fd, size_t count);
static void end_au(int fd); static void end_au(int fd);
@ -310,7 +309,8 @@ static void signal_handler(int sig)
if (!quiet_mode) if (!quiet_mode)
fprintf(stderr, _("Aborted by signal %s...\n"), strsignal(sig)); fprintf(stderr, _("Aborted by signal %s...\n"), strsignal(sig));
if (stream == SND_PCM_STREAM_CAPTURE) { if (stream == SND_PCM_STREAM_CAPTURE) {
fmt_rec_table[file_type].end(fd); if (fmt_rec_table[file_type].end)
fmt_rec_table[file_type].end(fd);
stream = -1; stream = -1;
} }
if (fd > 1) { if (fd > 1) {
@ -1924,7 +1924,7 @@ static void header(int rtype, char *name)
fprintf(stderr, "%s %s '%s' : ", fprintf(stderr, "%s %s '%s' : ",
(stream == SND_PCM_STREAM_PLAYBACK) ? _("Playing") : _("Recording"), (stream == SND_PCM_STREAM_PLAYBACK) ? _("Playing") : _("Recording"),
gettext(fmt_rec_table[rtype].what), gettext(fmt_rec_table[rtype].what),
name); name ? name : "stdin");
fprintf(stderr, "%s, ", snd_pcm_format_description(hwparams.format)); fprintf(stderr, "%s, ", snd_pcm_format_description(hwparams.format));
fprintf(stderr, _("Rate %d Hz, "), hwparams.rate); fprintf(stderr, _("Rate %d Hz, "), hwparams.rate);
if (hwparams.channels == 1) if (hwparams.channels == 1)
@ -2116,6 +2116,8 @@ static void capture(char *orig_name)
fd = fileno(stdout); fd = fileno(stdout);
name = "stdout"; name = "stdout";
tostdout=1; tostdout=1;
if (count > fmt_rec_table[file_type].max_filesize)
count = fmt_rec_table[file_type].max_filesize;
} }
do { do {
@ -2147,26 +2149,24 @@ static void capture(char *orig_name)
fmt_rec_table[file_type].start(fd, rest); fmt_rec_table[file_type].start(fd, rest);
/* capture */ /* capture */
fdcount = 0;
while (rest > 0) { while (rest > 0) {
ssize_t err; size_t c = (rest <= (off64_t)chunk_bytes) ?
size_t c = (rest <= (off_t)chunk_bytes) ?
(size_t)rest : chunk_bytes; (size_t)rest : chunk_bytes;
c = c * 8 / bits_per_frame; size_t f = c * 8 / bits_per_frame;
if ((size_t)(err = pcm_read(audiobuf, c)) != c) if (pcm_read(audiobuf, f) != f)
break; break;
c = err * bits_per_frame / 8; if (write(fd, audiobuf, c) != c) {
if ((err = write(fd, audiobuf, c)) != c) {
perror(name); perror(name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (err > 0) { count -= c;
count -= err; rest -= c;
rest -= err; fdcount += c;
}
} }
/* finish sample container */ /* finish sample container */
if (fmt_rec_table[file_type].end) if (fmt_rec_table[file_type].end && !tostdout)
fmt_rec_table[file_type].end(fd); fmt_rec_table[file_type].end(fd);
/* repeat the loop when format is raw without timelimit or /* repeat the loop when format is raw without timelimit or