mirror of
https://github.com/alsa-project/alsa-tools.git
synced 2026-03-27 07:58:28 -04:00
Added signal handlers
This commit is contained in:
parent
c40c3b5623
commit
670c55934e
1 changed files with 22 additions and 1 deletions
|
|
@ -28,6 +28,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <sys/errno.h>
|
#include <sys/errno.h>
|
||||||
|
#include <sys/signal.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
@ -76,6 +77,17 @@ ssize_t fill_buffer(uint_8 **start,uint_8 **end)
|
||||||
return bytes_read;
|
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[])
|
int main(int argc,char *argv[])
|
||||||
{
|
{
|
||||||
struct option long_option[] =
|
struct option long_option[] =
|
||||||
|
|
@ -176,6 +188,9 @@ int main(int argc,char *argv[])
|
||||||
fprintf(stderr, "Output open failed\n");
|
fprintf(stderr, "Output open failed\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
signal(SIGINT, ac3dec_signal_handler);
|
||||||
|
signal(SIGTERM, ac3dec_signal_handler);
|
||||||
|
signal(SIGABRT, ac3dec_signal_handler);
|
||||||
do {
|
do {
|
||||||
//Send the samples to the output device
|
//Send the samples to the output device
|
||||||
output_play(ac3_frame->audio_data, 256 * 6);
|
output_play(ac3_frame->audio_data, 256 * 6);
|
||||||
|
|
@ -183,7 +198,13 @@ int main(int argc,char *argv[])
|
||||||
} else {
|
} else {
|
||||||
uint_8 *start, *end;
|
uint_8 *start, *end;
|
||||||
init_spdif();
|
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)
|
while (fill_buffer(&start, &end) > 0)
|
||||||
if (output_spdif(start, end) < 0)
|
if (output_spdif(start, end) < 0)
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue