]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
check that the clock is valid and reduce the Buffered Audio lead time to 0.25 seconds
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 1 May 2021 10:03:45 +0000 (11:03 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sat, 1 May 2021 10:03:45 +0000 (11:03 +0100)
ptp-utilities.c
rtp.c

index 53dbd4d0487aba72339f8c4040246ecbd2a8e5f6..887005220b06ace3dc5692db18e67e166dc44012 100644 (file)
@@ -75,11 +75,17 @@ int ptp_get_clock_info(uint64_t *actual_clock_id, uint64_t *raw_offset) {
     struct shm_structure nqptp_data;
     if (get_nqptp_data(&nqptp_data) == 0) {
       if (nqptp_data.version == NQPTP_SHM_STRUCTURES_VERSION) {
-      if (actual_clock_id != NULL)
-        *actual_clock_id = nqptp_data.master_clock_id;
-      if (raw_offset != NULL)
-        *raw_offset = nqptp_data.local_to_master_time_offset;
-      response = 0;
+        // assuming a clock id can not be zero
+        if (nqptp_data.master_clock_id != 0) {
+          if (actual_clock_id != NULL)
+            *actual_clock_id = nqptp_data.master_clock_id;
+          if (raw_offset != NULL)
+            *raw_offset = nqptp_data.local_to_master_time_offset;
+          response = 0;
+        } else {
+          debug(1,"clock not valid");
+          response = -2; // clock info not valid
+        }
       } else {
         if (failure_message_sent == 0) {
           warn("This version of Shairport Sync requires an NQPTP with a Shared Memory Interface Version %u, but the installed version is %u. Please install the correct version of NQPTP.", NQPTP_SHM_STRUCTURES_VERSION, nqptp_data.version);
diff --git a/rtp.c b/rtp.c
index f0f90ed8146d6456c1a267995261e5bc88627e11..59cea3fab5f0536b665248bfdea37a23d6a917df 100644 (file)
--- a/rtp.c
+++ b/rtp.c
@@ -1256,8 +1256,11 @@ int get_ptp_anchor_local_time_info(rtsp_conn_info *conn, uint32_t *anchorRTP,
   } else if (ptp_status == -1) {
     debug(3, "don't have the ptp clock interface");
     response = -1;
+  } else if (ptp_status == -2) {
+    debug(1, "ptp clock not valid");
+    response = -1;
   } else {
-    debug(3, "ptp clock not valid");
+    debug(3, "ptp clock error");
     response = -1;
   }
   return response;
@@ -2040,7 +2043,7 @@ void *rtp_buffered_audio_processor(void *arg) {
       // debug(1,"player buffer size and occupancy: %u and %u", player_buffer_size,
       // player_buffer_occupancy);
       if (player_buffer_occupancy >
-          ((0.5 + 0.1) * 44100.0 / 352)) { // must be greater than the lead time.
+          ((0.25 + 0.1) * 44100.0 / 352)) { // must be greater than the lead time.
         // if there is enough stuff in the player's buffer, sleep for a while and try again
         // debug(1,"sleep for 20 ms");
         usleep(20000); // wait for a while
@@ -2064,7 +2067,7 @@ void *rtp_buffered_audio_processor(void *arg) {
               int64_t lead_time = buffer_should_be_time - get_absolute_time_in_ns();
               // debug(1,"lead time in buffered_audio is %f milliseconds.", lead_time * 0.000001);
               // ask for 0.5 sec of leadtime
-              if ((lead_time >= (int64_t)(0.5 * 1000000000)) || (streaming_has_started == 1)) {
+              if ((lead_time >= (int64_t)(0.25 * 1000000000)) || (streaming_has_started == 1)) {
                 if (streaming_has_started == 0)
                   debug(1, "rtp lead time is %f ms.", 0.000001 * lead_time);
                 streaming_has_started = 1;