]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Try making dropping and closing the DAC un-cancelable to stop the bcm DMA problem...
authorMike Brady <mikebrady@eircom.net>
Thu, 22 Nov 2018 21:57:54 +0000 (21:57 +0000)
committerMike Brady <mikebrady@eircom.net>
Thu, 22 Nov 2018 21:57:54 +0000 (21:57 +0000)
audio_alsa.c
player.c

index ab3d172c51a812e6fb4e86b569c5d239d5e6f61c..3039fa65b8d0e7380707553e90973414d9f3142c 100644 (file)
@@ -1051,6 +1051,8 @@ static int play(void *buf, int samples) {
 
 static void flush(void) {
   // debug(2,"audio_alsa flush called.");
+  int oldState;
+  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
   pthread_cleanup_debug_mutex_lock(&alsa_mutex, 10000, 1);
   int derr;
   do_mute(1);
@@ -1072,6 +1074,7 @@ static void flush(void) {
   }
   debug_mutex_unlock(&alsa_mutex, 3);
   pthread_cleanup_pop(0); // release the mutex
+  pthread_setcancelstate(oldState, NULL);
 }
 
 static void stop(void) {
index 8b16f3c118ca5c1819e39fcf08e64efa743fe46d..751621e4021711c70fe1536d90e72b5d32a7fda9 100644 (file)
--- a/player.c
+++ b/player.c
@@ -464,6 +464,7 @@ void player_put_packet(seq_t seqno, uint32_t actual_timestamp, uint8_t *data, in
       conn->initial_reference_time = 0;
       conn->initial_reference_timestamp = 0;
     } else {
+    /*
       if ((conn->flush_rtp_timestamp != 0) &&
           (modulo_32_offset(conn->flush_rtp_timestamp, actual_timestamp) > conn->input_rate / 5) &&
           (modulo_32_offset(conn->flush_rtp_timestamp, actual_timestamp) < conn->input_rate)) {
@@ -471,6 +472,7 @@ void player_put_packet(seq_t seqno, uint32_t actual_timestamp, uint8_t *data, in
         debug(2, "Dropping flush request in player_put_packet");
         conn->flush_rtp_timestamp = 0;
       }
+    */
 
       abuf_t *abuf = 0;
 
@@ -849,7 +851,10 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
             debug(1, "Inconsistent sequence numbers detected");
           }
         }
-
+        
+        //if (conn->flush_rtp_timestamp != 0)
+        //  debug(2,"flush_rtp_timestamp is %" PRIx32 " and curframe->given_timestamp is %" PRIx32 ".", conn->flush_rtp_timestamp , curframe->given_timestamp);
+        
         if ((conn->flush_rtp_timestamp != 0) &&
             (curframe->given_timestamp != conn->flush_rtp_timestamp) &&
             (modulo_32_offset(curframe->given_timestamp, conn->flush_rtp_timestamp) <
@@ -945,11 +950,13 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
 
               conn->first_packet_time_to_play = should_be_time;
 
-              if (local_time_now >= conn->first_packet_time_to_play) {
+              if (local_time_now > conn->first_packet_time_to_play) {
+                uint64_t lateness = local_time_now - conn->first_packet_time_to_play;
+                lateness = (lateness * 1000000) >> 32; // microseconds
                 debug(
                     1,
-                    "First packet is late! It should have played before now. Flushing 0.5 seconds");
-                player_flush(conn->first_packet_timestamp + 5 * 4410 * conn->output_sample_ratio,
+                    "First packet is %" PRIu64 " microseconds late! Flushing 0.5 seconds",lateness);
+                do_flush(conn->first_packet_timestamp + 5 * 4410,
                              conn);
               }
             }
@@ -978,8 +985,10 @@ static abuf_t *buffer_get_frame(rtsp_conn_info *conn) {
                                                              // dynamic adjustment
             int64_t filler_size = max_dac_delay;
 
-            if (local_time_now >= conn->first_packet_time_to_play) {
-              // debug(1,"Gone past starting time");
+            if (local_time_now > conn->first_packet_time_to_play) {
+              uint64_t lateness = local_time_now - conn->first_packet_time_to_play;
+              lateness = (lateness * 1000000) >> 32; // microseconds
+              debug(1,"Gone past starting time by %" PRIu64 " microseconds.", lateness);
               have_sent_prefiller_silence = 1;
               conn->ab_buffering = 0;