]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
update packet reception statistics to use nanosecond timing
authorMike Brady <mikebradydublin@icloud.com>
Mon, 24 Feb 2020 19:58:35 +0000 (19:58 +0000)
committerMike Brady <mikebradydublin@icloud.com>
Mon, 24 Feb 2020 19:58:35 +0000 (19:58 +0000)
rtp.c

diff --git a/rtp.c b/rtp.c
index 6a90a5cda5dc200c795aae3ac615e8d6f42ba57e..6932420a27e1904271f10544d6eb05530aa61732 100644 (file)
--- a/rtp.c
+++ b/rtp.c
@@ -108,7 +108,7 @@ void *rtp_audio_receiver(void *arg) {
   int32_t last_seqno = -1;
   uint8_t packet[2048], *pktp;
 
-  uint64_t time_of_previous_packet_fp = 0;
+  uint64_t time_of_previous_packet_ns = 0;
   float longest_packet_time_interval_us = 0.0;
 
   // mean and variance calculations from "online_variance" algorithm at
@@ -125,11 +125,11 @@ void *rtp_audio_receiver(void *arg) {
 
     frame_count++;
 
-    uint64_t local_time_now_fp = get_absolute_time_in_fp();
-    if (time_of_previous_packet_fp) {
+    uint64_t local_time_now_ns = get_absolute_time_in_ns();
+    if (time_of_previous_packet_ns) {
       float time_interval_us =
-          (((local_time_now_fp - time_of_previous_packet_fp) * 1000000) >> 32) * 1.0;
-      time_of_previous_packet_fp = local_time_now_fp;
+          (local_time_now_ns - time_of_previous_packet_ns) * 0.001;
+      time_of_previous_packet_ns = local_time_now_ns;
       if (time_interval_us > longest_packet_time_interval_us)
         longest_packet_time_interval_us = time_interval_us;
       stat_n += 1;
@@ -143,11 +143,11 @@ void *rtp_audio_receiver(void *arg) {
         stat_n = 0;
         stat_mean = 0.0;
         stat_M2 = 0.0;
-        time_of_previous_packet_fp = 0;
+        time_of_previous_packet_ns = 0;
         longest_packet_time_interval_us = 0.0;
       }
     } else {
-      time_of_previous_packet_fp = local_time_now_fp;
+      time_of_previous_packet_ns = local_time_now_ns;
     }
 
     if (nread >= 0) {
@@ -270,8 +270,8 @@ void *rtp_control_receiver(void *arg) {
                                                                 obfp += 2;
                                                               };
                                                               *obfp = 0;
-                                             
-                                             
+
+
                                                               // get raw timestamp information
                                                               // I think that a good way to understand these timestamps is that
                                                               // (1) the rtlt below is the timestamp of the frame that should be playing at the
@@ -282,19 +282,19 @@ void *rtp_control_receiver(void *arg) {
                                                               // Thus, (3) the latency can be calculated by subtracting the second from the
                                                               // first.
                                                               // There must be more to it -- there something missing.
-                                             
+
                                                               // In addition, it seems that if the value of the short represented by the second
                                                               // pair of bytes in the packet is 7
                                                               // then an extra time lag is expected to be added, presumably by
                                                               // the AirPort Express.
-                                             
+
                                                               // Best guess is that this delay is 11,025 frames.
-                                             
+
                                                               uint32_t rtlt = nctohl(&packet[4]); // raw timestamp less latency
                                                               uint32_t rt = nctohl(&packet[16]);  // raw timestamp
-                                             
+
                                                               uint32_t fl = nctohs(&packet[2]); //
-                                             
+
                                                               debug(1,"Sync Packet of %d bytes received: \"%s\", flags: %d, timestamps %u and %u,
                                                           giving a latency of %d frames.",plen,obf,fl,rt,rtlt,rt-rtlt);
                                                               //debug(1,"Monotonic timestamps are: %" PRId64 " and %" PRId64 "