softer pthread exiting with pthread_exit

pulseauio thread now uses pthread_exit to exit if something unexpected happens
it also sets audio.terminate to 1 and writes the error message to a audio.error_message
so it can be printed by main thread after cleanup. this also enables main thread to
cleanup terminal upon unexpected error on audio thread
master
karlstav 8 years ago
parent 9e18a91e66
commit 06469b3689
  1. 12
      cava.c
  2. 1
      input/fifo.c
  3. 13
      input/pulse.c

@ -350,6 +350,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
if (is_loop_device_for_sure(audio.source)) {
if (directory_exists("/sys/")) {
if (! directory_exists("/sys/module/snd_aloop/")) {
cleanup();
fprintf(stderr,
"Linux kernel module \"snd_aloop\" does not seem to be loaded.\n"
"Maybe run \"sudo modprobe snd_aloop\".\n");
@ -369,11 +370,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
nanosleep (&req, NULL);
n++;
if (n > 2000) {
#ifdef DEBUG
cleanup();
fprintf(stderr,
"could not get rate and/or format, problems with audio thread? quiting...\n");
#endif
exit(EXIT_FAILURE);
}
}
@ -808,6 +807,15 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
for (o = 0; o < bars; o++) {
flastd[o] = f[o];
}
//checking if audio thread has exited unexpectedly
if (audio.terminate == 1) {
cleanup();
fprintf(stderr,
"Audio thread exited unexpectedly. %s\n", audio.error_message);
exit(EXIT_FAILURE);
}
}//resize terminal
}//reloading config

@ -10,6 +10,7 @@ struct audio_data {
int im; //input mode alsa, fifo or pulse
int channels;
int terminate; // shared variable used to terminate audio thread
char error_message[1024];
};

@ -131,8 +131,10 @@ void* input_pulse(void* data)
int error;
if (!(s = pa_simple_new(NULL, "cava", PA_STREAM_RECORD, audio->source, "audio for cava", &ss, NULL, &pb, &error))) {
fprintf(stderr, __FILE__": Could not open pulseaudio source: %s, %s. To find a list of your pulseaudio sources run 'pacmd list-sources'\n",audio->source, pa_strerror(error));
exit(EXIT_FAILURE);
//fprintf(stderr, __FILE__": Could not open pulseaudio source: %s, %s. To find a list of your pulseaudio sources run 'pacmd list-sources'\n",audio->source, pa_strerror(error));
sprintf(audio->error_message, __FILE__": Could not open pulseaudio source: %s, %s. To find a list of your pulseaudio sources run 'pacmd list-sources'\n",audio->source, pa_strerror(error));
audio->terminate = 1;
pthread_exit(NULL);
}
n = 0;
@ -140,8 +142,11 @@ void* input_pulse(void* data)
while (1) {
/* Record some data ... */
if (pa_simple_read(s, buf, sizeof(buf), &error) < 0) {
fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error));
exit(EXIT_FAILURE);
//fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error));
//exit(EXIT_FAILURE);
sprintf(audio->error_message, __FILE__": pa_simple_read() failed: %s\n", pa_strerror(error));
audio->terminate = 1;
pthread_exit(NULL);
}
//sorting out channels

Loading…
Cancel
Save