Skip to content

Comments

Three fixes for audio delay issues caused by RTP timer drift#5

Open
gunarsritins wants to merge 1 commit intotrixie-supportfrom
fix-rtp-audio-drift
Open

Three fixes for audio delay issues caused by RTP timer drift#5
gunarsritins wants to merge 1 commit intotrixie-supportfrom
fix-rtp-audio-drift

Conversation

@gunarsritins
Copy link

Fix RTP timer drift causing audio delays

Three fixes for audio delay issues caused by RTP timer drift:

Changes

  1. 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.

  2. Hot socket burst prevention — when the RTP socket has queued packets, call timer_next() after timer_sync() so the timer sleeps for a full tick
    instead of returning immediately and bursting through queued packets. This prevents immediate audio delay spikes when packets queue up.

  3. 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.

/* 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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make it more efficient if the interval is power of 2, eg (rtp_session->timer.tick & 255) == 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants