#include <inttypes.h>
#include <ctype.h>
#include <byteswap.h>
+#include <signal.h>
#define ALSA_PCM_NEW_HW_PARAMS_API
#define ALSA_PCM_NEW_SW_PARAMS_API
static const char *given_test_wav_file = NULL;
static char *wav_file_dir = SOUNDSDIR;
static int debug = 0;
+static snd_pcm_t *pcm_handle = NULL;
#ifdef CONFIG_SUPPORT_CHMAP
static snd_pcm_chmap_t *channel_map;
return 0;
}
+static int prg_exit(int code)
+{
+ if (pcm_handle)
+ snd_pcm_close(pcm_handle);
+ exit(code);
+ return code;
+}
+
+static void signal_handler(int sig)
+{
+ static int in_aborting;
+
+ if (in_aborting)
+ return;
+
+ in_aborting = 1;
+
+ prg_exit(EXIT_FAILURE);
+}
+
static void help(void)
{
const int *fmt;
}
+ signal(SIGINT, signal_handler);
+ signal(SIGTERM, signal_handler);
+ signal(SIGABRT, signal_handler);
+
if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
printf(_("Playback open error: %d,%s\n"), err,snd_strerror(err));
- exit(EXIT_FAILURE);
+ prg_exit(EXIT_FAILURE);
}
+ pcm_handle = handle;
if ((err = set_hwparams(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
printf(_("Setting of hwparams failed: %s\n"), snd_strerror(err));
- snd_pcm_close(handle);
- exit(EXIT_FAILURE);
+ prg_exit(EXIT_FAILURE);
}
if ((err = set_swparams(handle, swparams)) < 0) {
printf(_("Setting of swparams failed: %s\n"), snd_strerror(err));
- snd_pcm_close(handle);
- exit(EXIT_FAILURE);
+ prg_exit(EXIT_FAILURE);
}
#ifdef CONFIG_SUPPORT_CHMAP
err = config_chmap(handle, chmap);
if (err < 0)
- exit(EXIT_FAILURE);
+ prg_exit(EXIT_FAILURE);
#endif
if (debug) {
if (frames == NULL) {
fprintf(stderr, _("No enough memory\n"));
- exit(EXIT_FAILURE);
+ prg_exit(EXIT_FAILURE);
}
+
if (speaker==0) {
if (test_type == TEST_WAV) {
for (chn = 0; chn < channels; chn++) {
if (setup_wav_file(chn) < 0)
- exit(EXIT_FAILURE);
+ prg_exit(EXIT_FAILURE);
}
}
if (err < 0) {
fprintf(stderr, _("Transfer failed: %s\n"), snd_strerror(err));
- free(frames);
- snd_pcm_close(handle);
- exit(EXIT_SUCCESS);
+ prg_exit(EXIT_SUCCESS);
}
}
gettimeofday(&tv2, NULL);
if (test_type == TEST_WAV) {
if (setup_wav_file(chn) < 0)
- exit(EXIT_FAILURE);
+ prg_exit(EXIT_FAILURE);
}
printf(" - %s\n", get_channel_name(chn));
free(frames);
- snd_pcm_close(handle);
- exit(EXIT_SUCCESS);
+ return prg_exit(EXIT_SUCCESS);
}