From: Mike Brady Date: Mon, 24 Feb 2020 19:58:35 +0000 (+0000) Subject: update packet reception statistics to use nanosecond timing X-Git-Tag: 3.3.7d12~119 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32427423af836734c8997247e500c7bd942bf741;p=thirdparty%2Fshairport-sync.git update packet reception statistics to use nanosecond timing --- diff --git a/rtp.c b/rtp.c index 6a90a5cd..6932420a 100644 --- 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 "