]> git.alsa-project.org Git - alsa-tools.git/commitdiff
Added signal handlers
authorJaroslav Kysela <perex@perex.cz>
Thu, 10 May 2001 08:26:29 +0000 (08:26 +0000)
committerJaroslav Kysela <perex@perex.cz>
Thu, 10 May 2001 08:26:29 +0000 (08:26 +0000)
ac3dec/ac3dec.c

index e3d0c818c9131440e6dc68f49c92aefaffff740c..46e2dcbd810006e050968f9bc76c616ffc914554 100644 (file)
@@ -28,6 +28,7 @@
 #include <string.h>
 #include <getopt.h>
 #include <sys/errno.h>
+#include <sys/signal.h>
 #include <errno.h>
 #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;