]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
prevent cancellation while performing ao-related operations.
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 29 Jun 2024 18:59:28 +0000 (19:59 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 29 Jun 2024 19:00:13 +0000 (20:00 +0100)
audio_ao.c

index 617464876066e009a3f186161df45ff8e4581a6d..b53eedc743b58c85db94b1647569a62adc33a230 100644 (file)
@@ -69,6 +69,8 @@ static void help(void) {
 }
 
 static int init(int argc, char **argv) {
+  int oldState;
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); // make this un-cancellable
   ao_initialize();
   driver = ao_default_driver_id();
   if (driver == -1) {
@@ -133,14 +135,18 @@ static int init(int argc, char **argv) {
     fmt.byte_format = AO_FMT_NATIVE;
     fmt.matrix = strdup("L,R");
   }
+  pthread_setcancelstate(oldState, NULL);
   return 0;
 }
 
 static void deinit(void) {
+  int oldState;
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); // make this un-cancellable
   if (dev != NULL)
     ao_close(dev);
   dev = NULL;
   ao_shutdown();
+  pthread_setcancelstate(oldState, NULL);
 }
 
 static void start(__attribute__((unused)) int sample_rate,
@@ -166,10 +172,13 @@ static int play(void *buf, int samples, __attribute__((unused)) int sample_type,
 
 static void stop(void) {
   // debug(1,"libao stop");
+  int oldState;
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); // make this un-cancellable
   if (dev != NULL) {
     ao_close(dev);
     dev = NULL;
   }
+  pthread_setcancelstate(oldState, NULL);
 }
 
 audio_output audio_ao = {.name = "ao",