Three fixes for audio delay issues caused by RTP timer drift#5
Open
gunarsritins wants to merge 1 commit intotrixie-supportfrom
Open
Three fixes for audio delay issues caused by RTP timer drift#5gunarsritins wants to merge 1 commit intotrixie-supportfrom
gunarsritins wants to merge 1 commit intotrixie-supportfrom
Conversation
| /* Periodic drift correction: every 250 ticks, resync timer to wall-clock | ||
| * before sleeping. Sub-tick scheduling latency (~38us per 20ms on ARM) | ||
| * compounds over time because timerfd read() returns 1 even when late. */ | ||
| if ((rtp_session->timer.tick % 250) == 0) { |
There was a problem hiding this comment.
you can make it more efficient if the interval is power of 2, eg (rtp_session->timer.tick & 255) == 0
AlexPereverzyevUbiquiti
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix RTP timer drift causing audio delays
Three fixes for audio delay issues caused by RTP timer drift:
Changes
Periodic timer sync — every 250 ticks (~5s), resync the RTP timer to wall-clock before sleeping. Sub-tick scheduling latency compounds over time
because timerfd
read()returns 1 even when the timer fires late, causing gradual audio delay on long calls.Hot socket burst prevention — when the RTP socket has queued packets, call
timer_next()aftertimer_sync()so the timer sleeps for a full tickinstead of returning immediately and bursting through queued packets. This prevents immediate audio delay spikes when packets queue up.
AUDIO_SYNC timer resync — when the media layer handles AUDIO_SYNC (codec changes, hold/resume), resync the RTP timer via new
switch_rtp_timer_sync().Previously, resuming from hold could cause a burst of catch-up packets as the timer tried to make up for elapsed time, resulting in audio delay after
hold/resume.
Testing
Verified on ARM64 (UDR and UCKP). Gradual drift on long calls, immediate delay spikes, and post-hold audio delay all resolved.