From 4df014537270db60a91c8b25cbd81d13e26d15a1 Mon Sep 17 00:00:00 2001 From: prhodey <76759868+prhodey@users.noreply.github.com> Date: Wed, 19 Aug 2026 20:10:50 -0400 Subject: [PATCH] Defer buffered AirPlay 2 latency offset conversion --- rtp.c | 7 +++++-- rtsp.c | 7 ++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rtp.c b/rtp.c index 7b7ee774..bcd84149 100644 --- a/rtp.c +++ b/rtp.c @@ -1488,8 +1488,11 @@ int get_ptp_anchor_local_time_info(rtsp_conn_info *conn, uint32_t *anchorRTP, } if (conn->last_anchor_info_is_valid != 0) { - if (anchorRTP != NULL) - *anchorRTP = conn->last_anchor_rtptime; + if (anchorRTP != NULL) { + // Use the current rate in case the stream format has changed. + int32_t added_latency = (int32_t)(config.audio_backend_latency_offset * conn->input_rate); + *anchorRTP = conn->last_anchor_rtptime - added_latency; + } if (anchorLocalTime != NULL) *anchorLocalTime = conn->last_anchor_local_time; } diff --git a/rtsp.c b/rtsp.c index 60a9929c..91ea19ef 100644 --- a/rtsp.c +++ b/rtsp.c @@ -1453,11 +1453,8 @@ void handle_setrateanchori(rtsp_conn_info *conn, rtsp_message *req, rtsp_message // debug(1, "anchor rtpTime is %" PRId64 ".", rtpTime); uint32_t anchorRTPTime = rtpTime; - int32_t added_latency = (int32_t)(config.audio_backend_latency_offset * conn->input_rate); - // debug(1,"anchorRTPTime: %" PRIu32 ", added latency: %" PRId32 ".", anchorRTPTime, - // added_latency); - set_ptp_anchor_info(conn, conn->networkTimeTimelineID, anchorRTPTime - added_latency, - anchorTimeNanoseconds); + // Store the raw anchor; apply the latency offset when it is used. + set_ptp_anchor_info(conn, conn->networkTimeTimelineID, anchorRTPTime, anchorTimeNanoseconds); } item = plist_dict_get_item(messagePlist, "rate");