From 6bf81ebe592989b9b061cf652d639fcec82e9acd Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 17 Mar 2026 14:01:27 +0100 Subject: [PATCH] modules: align rtp_timestamps for sender When the driver changes, the clock position can also change and there would be a discont in the rtp_timestamp. This is not usually a problem except in RAOP mode where the base rtp timestamp is negotiated and anything that deviates too much is to be discarded. If we are not using direct_timestamp for the sender, make sure we always keep the rtp_time aligned to avoid this problem. See #5167 --- src/modules/module-rtp/audio.c | 8 +++++--- src/modules/module-rtp/stream.c | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/modules/module-rtp/audio.c b/src/modules/module-rtp/audio.c index 27c4b218e..eec37317f 100644 --- a/src/modules/module-rtp/audio.c +++ b/src/modules/module-rtp/audio.c @@ -546,7 +546,7 @@ static void rtp_audio_flush_packets(struct impl *impl, uint32_t num_packets, uin else header.m = 0; - rtp_timestamp = impl->ts_offset + (set_timestamp ? set_timestamp : timestamp); + rtp_timestamp = impl->ts_offset + impl->ts_align + (set_timestamp ? set_timestamp : timestamp); header.sequence_number = htons(impl->seq); header.timestamp = htonl(rtp_timestamp); @@ -705,8 +705,10 @@ static void rtp_audio_process_capture(void *data) * that resynchronization is needed, then this will be done immediately below. */ if (!impl->have_sync) { - pw_log_info("(re)sync to timestamp:%u seq:%u ts_offset:%u SSRC:%u", - actual_timestamp, impl->seq, impl->ts_offset, impl->ssrc); + if (!impl->direct_timestamp) + impl->ts_align = actual_timestamp - impl->ring.readindex; + pw_log_info("(re)sync to timestamp:%u seq:%u ts_offset:%u ts_align:%u SSRC:%u", + actual_timestamp, impl->seq, impl->ts_offset, impl->ts_align, impl->ssrc); spa_ringbuffer_read_update(&impl->ring, actual_timestamp); spa_ringbuffer_write_update(&impl->ring, actual_timestamp); memset(impl->buffer, 0, BUFFER_SIZE); diff --git a/src/modules/module-rtp/stream.c b/src/modules/module-rtp/stream.c index 5ca41eb12..992563aea 100644 --- a/src/modules/module-rtp/stream.c +++ b/src/modules/module-rtp/stream.c @@ -109,6 +109,7 @@ struct impl { uint32_t mtu; uint32_t header_size; uint32_t payload_size; + uint32_t ts_align; struct spa_ringbuffer ring; uint8_t buffer[BUFFER_SIZE];