Implement an RTP Jitter Buffer With Sequence Number Wraparound

Last updated: November 29, 2026

Quick Overview

Implement a jitter buffer that accepts RTP audio packets with 16-bit sequence numbers arriving out of order, duplicated or late, and on each 20 ms playout tick returns the next packet in order or None for concealment.

Retell AI
Coding & Algorithms
Software Engineer
Retell AI
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Implement a jitter buffer that accepts RTP audio packets with 16-bit sequence numbers arriving out of order, duplicated or late, and on each 20 ms playout tick returns the next packet in order or None for concealment.

Retell's telephony path carries caller audio over SIP and RTP, where network jitter reorders packets and the 16-bit sequence counter wraps every 65,536 packets (about 22 minutes at 50 packets per second, well within a long call). This question checks careful stateful code, modular arithmetic and a clear policy for late and missing packets.

What the Interviewer Expects
  • Unwrap 16-bit sequence numbers into a monotonic extended sequence
  • Order packets with a min-heap keyed by extended sequence
  • Drop duplicates and packets older than the playout point
  • Hold an initial depth before starting playout
  • Return a concealment marker for missing packets instead of stalling
Key Topics to Cover
RTP
sequence wraparound
min-heap
jitter buffering
packet loss concealment
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you make the buffer depth adaptive based on measured jitter?
  • Why can stalling playout on a missing packet be worse than concealment for a voice agent?
  • How would you detect a sender restart where the sequence jumps randomly?
  • How does buffer depth add to the agent's end-to-end response latency?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

push(seq16, payload) adds a packet and returns whether it was accepted. pop() is called every 20 ms. Before playout starts, wait until depth packets are buffered. After that, every tick plays ex...

High-Level Design

Convert each 16-bit number to an extended number closest to the highest one seen: take the high bits of highest, OR in seq16, then shift by 65,536 if that lands more than half the space away. A mi...


Submit Your Answer
Markdown supported

Related Questions