static int mmap_flag = 0;
static int interleaved = 1;
static int nonblock = 0;
+static int in_aborting = 0;
static u_char *audiobuf = NULL;
static snd_pcm_uframes_t chunk_size = 0;
static unsigned period_time = 0;
static void signal_handler(int sig)
{
- static int in_aborting;
-
if (in_aborting)
return;
putchar('\n');
if (!quiet_mode)
fprintf(stderr, _("Aborted by signal %s...\n"), strsignal(sig));
- if (stream == SND_PCM_STREAM_CAPTURE) {
- if (fmt_rec_table[file_type].end) {
- fmt_rec_table[file_type].end(fd);
- fd = -1;
- }
- stream = -1;
- }
- if (fd > 1) {
- close(fd);
- fd = -1;
- }
- if (handle && sig != SIGABRT) {
- snd_pcm_close(handle);
+ if (handle)
+ snd_pcm_abort(handle);
+ if (sig == SIGABRT) {
+ /* do not call snd_pcm_close() and abort immediately */
handle = NULL;
+ prg_exit(EXIT_FAILURE);
}
- prg_exit(EXIT_FAILURE);
+ signal(sig, signal_handler);
}
/* call on SIGUSR1 signal. */
{
ssize_t result = 0, res;
- while (count > 0) {
+ while (count > 0 && !in_aborting) {
if ((res = read(fd, buf, count)) == 0)
break;
if (res < 0)
return; /* not fatal error */
}
snd_pcm_format_set_silence(hwparams.format, buf, chunk_size * hwparams.channels);
- while (x > 0) {
+ while (x > 0 && !in_aborting) {
l = x;
if (l > chunk_size)
l = chunk_size;
set_params();
in_buffer = nextblock = 0;
- while (1) {
+ while (!in_aborting) {
Fill_the_buffer: /* need this for repeat */
if (in_buffer < 32) {
/* move the rest of buffer to pos 0 and fill the buf up */
header(rtype, name);
set_params();
- while (loaded > chunk_bytes && written < count) {
+ while (loaded > chunk_bytes && written < count && !in_aborting) {
if (pcm_write(audiobuf + written, chunk_size) <= 0)
return;
written += chunk_bytes;
memmove(audiobuf, audiobuf + written, loaded);
l = loaded;
- while (written < count) {
+ while (written < count && !in_aborting) {
do {
c = count - written;
if (c > chunk_bytes)
/* capture */
fdcount = 0;
- while (rest > 0 && recycle_capture_file == 0) {
+ while (rest > 0 && recycle_capture_file == 0 && !in_aborting) {
size_t c = (rest <= (off64_t)chunk_bytes) ?
(size_t)rest : chunk_bytes;
size_t f = c * 8 / bits_per_frame;
for (channel = 0; channel < channels; ++channel)
bufs[channel] = audiobuf + vsize * channel;
- while (count > 0) {
+ while (count > 0 && !in_aborting) {
size_t c = 0;
size_t expected = count / channels;
if (expected > vsize)
for (channel = 0; channel < channels; ++channel)
bufs[channel] = audiobuf + vsize * channel;
- while (count > 0) {
+ while (count > 0 && !in_aborting) {
size_t rv;
c = count;
if (c > chunk_bytes)