From: Jaroslav Kysela Date: Thu, 10 May 2001 08:26:29 +0000 (+0000) Subject: Added signal handlers X-Git-Tag: v1.0.3~165 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=670c55934e16526a39f59a332807d6c984addd52;p=alsa-tools.git Added signal handlers --- diff --git a/ac3dec/ac3dec.c b/ac3dec/ac3dec.c index e3d0c81..46e2dcb 100644 --- a/ac3dec/ac3dec.c +++ b/ac3dec/ac3dec.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "config.h" @@ -76,6 +77,17 @@ ssize_t fill_buffer(uint_8 **start,uint_8 **end) return bytes_read; } +static void ac3dec_signal_handler(int signal) +{ + if (!quiet) + fprintf(stderr, "Aborted...\n"); + // it's important to close the PCM handle(s), because + // some driver settings have to be recovered + output_close(); + fclose(in_file); + exit(EXIT_FAILURE); +} + int main(int argc,char *argv[]) { struct option long_option[] = @@ -176,6 +188,9 @@ int main(int argc,char *argv[]) fprintf(stderr, "Output open failed\n"); exit(EXIT_FAILURE); } + signal(SIGINT, ac3dec_signal_handler); + signal(SIGTERM, ac3dec_signal_handler); + signal(SIGABRT, ac3dec_signal_handler); do { //Send the samples to the output device output_play(ac3_frame->audio_data, 256 * 6); @@ -183,7 +198,13 @@ int main(int argc,char *argv[]) } else { uint_8 *start, *end; init_spdif(); - output_open(&out_config); + if (output_open(&out_config) < 0) { + fprintf(stderr, "Output open failed\n"); + exit(EXIT_FAILURE); + } + signal(SIGINT, ac3dec_signal_handler); + signal(SIGTERM, ac3dec_signal_handler); + signal(SIGABRT, ac3dec_signal_handler); while (fill_buffer(&start, &end) > 0) if (output_spdif(start, end) < 0) break;