]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Take a little more care of access to the alsa system; wait 100 ms after finishing...
authorMike Brady <mikebrady@eircom.net>
Tue, 2 Feb 2016 14:43:37 +0000 (14:43 +0000)
committerMike Brady <mikebrady@eircom.net>
Tue, 2 Feb 2016 14:43:37 +0000 (14:43 +0000)
audio_alsa.c
player.c
rtsp.c

index a389ee28754e2d5539712941a2b9c8a39d991517..4e2677b1afce01fcf7cfb73f9a4e8670fea40cf1 100644 (file)
@@ -437,8 +437,10 @@ static uint32_t delay() {
 static void play(short buf[], int samples) {
   int ret = 0;
   if (alsa_handle == NULL) {
+    pthread_mutex_lock(&alsa_mutex);
     ret = open_alsa_device();
     open_mixer();
+    pthread_mutex_unlock(&alsa_mutex);
     if ((ret == 0) && (audio_alsa.volume))
       audio_alsa.volume(set_volume);
   }
@@ -467,6 +469,7 @@ static void play(short buf[], int samples) {
 }
 
 static void flush(void) {
+  pthread_mutex_lock(&alsa_mutex);
   int derr;
   if (alsa_mix_handle) {
     snd_mixer_close(alsa_mix_handle);
@@ -495,6 +498,7 @@ static void flush(void) {
     snd_pcm_close(alsa_handle);
     alsa_handle = NULL;
   }
+  pthread_mutex_unlock(&alsa_mutex);
 }
 
 static void stop(void) {
@@ -513,7 +517,8 @@ static void parameters(audio_parameters *info) {
 }
 
 static void volume(double vol) {
-  debug(2, "Setting volume db to %f.", vol);
+  pthread_mutex_lock(&alsa_mutex);
+       debug(2, "Setting volume db to %f.", vol);
   set_volume = vol;
   if (alsa_mix_handle) {
     if (snd_mixer_selem_set_playback_dB_all(alsa_mix_elem, vol, 0) != 0) {
@@ -523,6 +528,7 @@ static void volume(double vol) {
           die("Failed to set playback dB volume");
     }
   }
+  pthread_mutex_unlock(&alsa_mutex);
 }
 
 static void linear_volume(double vol) {
index a6b1f9157f8328cfe3ebcaff29dc96ee2d23ae9c..348eac63fa100b5daa214336c3c294bf0e152eca 100644 (file)
--- a/player.c
+++ b/player.c
@@ -902,12 +902,13 @@ typedef struct stats { // statistics for running averages
 } stats_t;
 
 static void *player_thread_func(void *arg) {
-       int threads_stop = 0;
+       struct inter_threads_record itr;
+       itr.please_stop = 0;
        // create and start the timing, control and audio receiver threads
        pthread_t rtp_audio_thread, rtp_control_thread, rtp_timing_thread;
-       pthread_create(&rtp_audio_thread, NULL, &rtp_audio_receiver, (void *)&threads_stop);
-  pthread_create(&rtp_control_thread, NULL, &rtp_control_receiver, (void *)&threads_stop);
-  pthread_create(&rtp_timing_thread, NULL, &rtp_timing_receiver, (void *)&threads_stop);
+       pthread_create(&rtp_audio_thread, NULL, &rtp_audio_receiver, (void *)&itr);
+  pthread_create(&rtp_control_thread, NULL, &rtp_control_receiver, (void *)&itr);
+  pthread_create(&rtp_timing_thread, NULL, &rtp_timing_receiver, (void *)&itr);
 
                session_corrections = 0;
                play_segment_reference_frame = 0; // zero signals that we are not in a play segment
@@ -1237,11 +1238,11 @@ static void *player_thread_func(void *arg) {
   }
   if (config.output->stop)
        config.output->stop();
+  usleep(100000); // allow this time to (?) allow the alsa subsystem to finish cleaning up after itself. 50 ms seems too short
   free(outbuf);
   free(silence);
   debug(1,"Shut down audio, control and timing threads");
-  // usleep(1000000);
-  threads_stop = 1;
+  itr.please_stop = 1;
   pthread_kill(rtp_audio_thread, SIGUSR1);
   pthread_kill(rtp_control_thread, SIGUSR1);
   pthread_kill(rtp_timing_thread, SIGUSR1);
diff --git a/rtsp.c b/rtsp.c
index 7a768c3abd52938aad18720fbdb3a5c17f5a6a88..055fc6cd68a3baf053eb1eee6674abb09938a821 100644 (file)
--- a/rtsp.c
+++ b/rtsp.c
@@ -1694,10 +1694,10 @@ static void *rtsp_conversation_thread_func(void *pconn) {
     rtp_shutdown();
     pthread_mutex_unlock(&play_lock);
     pthread_mutex_unlock(&playing_mutex);
-  } else {
-    debug(1, "This RTSP conversation thread doesn't think it's playing for a "
-             "close RTSP connection.");
-  }
+  } // else {
+    //debug(1, "This RTSP conversation thread doesn't think it's playing for a "
+    //         "close RTSP connection.");
+  // }
   if (auth_nonce)
     free(auth_nonce);
   conn->running = 0;