From 82303e8be7fc076efec5e7231fec4ac3f4b0d0d5 Mon Sep 17 00:00:00 2001 From: fduncanh Date: Wed, 27 Apr 2022 13:14:07 -0400 Subject: [PATCH] identify meaning of rtp_next in time synchronization --- lib/raop_rtp.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/raop_rtp.c b/lib/raop_rtp.c index e4a542b..4c2c4b4 100644 --- a/lib/raop_rtp.c +++ b/lib/raop_rtp.c @@ -452,15 +452,20 @@ raop_rtp_thread_udp(void *arg) assert(result >= 0); } else if (type_c == 0x54 && packetlen >= 20) { // The unit for the rtp clock is 1 / sample rate = 1 / 44100 - uint32_t sync_rtp = byteutils_get_int_be(packet, 4) - 11025; - uint64_t sync_ntp_raw = byteutils_get_long_be(packet, 8); + uint32_t sync_rtp = byteutils_get_int_be(packet, 4); + uint64_t sync_ntp_raw = byteutils_get_long_be(packet, 8); + uint32_t next_rtp = byteutils_get_int_be(packet, 16); + // next_rtp = sync_rtp + 7497 = 441 * 17 (0.17 sec) for AAC_ELD + // next_rtp = sync_rtp + 77175 = 441 * 175 (1.75 sec) for ALAC + /* subtract 44100/4 from sync_rtp */ + sync_rtp -= 11025; uint64_t sync_ntp_remote = raop_ntp_timestamp_to_micro_seconds(sync_ntp_raw, true); uint64_t sync_ntp_local = raop_ntp_convert_remote_time(raop_rtp->ntp, sync_ntp_remote); - // It's not clear what the additional rtp timestamp indicates - uint32_t next_rtp = byteutils_get_int_be(packet, 16); + raop_rtp_sync_clock(raop_rtp, sync_rtp, sync_ntp_local); + logger_log(raop_rtp->logger, LOGGER_DEBUG, "raop_rtp sync: ntp=%llu, local ntp: %llu, rtp=%u, rtp_next=%u", sync_ntp_remote, sync_ntp_local, sync_rtp, next_rtp); - raop_rtp_sync_clock(raop_rtp, sync_rtp, sync_ntp_local); + } else { logger_log(raop_rtp->logger, LOGGER_DEBUG, "raop_rtp unknown packet"); }