Jitter
Per-SSRC jitter buffer for the voice receive pipeline.
Holds incoming Opus packets indexed by RTP sequence number and replays them at a steady 20ms rate after an initial four-frame delay. Gaps in the sequence are filled via FEC (if the next packet is already buffered) or Opus PLC, so the consumer receives a continuous PCM stream while the speaker talks.
The tick loop runs only while audio is arriving: after five empty slots with nothing buffered it stops, and the next pushed packet resyncs and restarts it. A packet that arrives after a pause, far ahead of the expected sequence, or into an empty buffer resyncs the stream; any other late packet is dropped, so playback never rewinds.
Summary
Properties
Jitter.packets :: { [number]: buffer }Jitter.nextSequence :: numberJitter.stopped :: booleanJitter.running :: booleanJitter.clockAnchor :: numberJitter.tickCount :: numberJitter.emptyTicks :: numberJitter.lastPushClock :: numberJitter.thread :: thread?Jitter.decoder :: opus.DecoderJitter.shouldDecode :: (() -> boolean)?Jitter.decoding :: booleanJitter.decoderStale :: booleanJitter.logger :: logger.LoggerJitter.onRawFrame :: ((sequence: number, packet: buffer) -> ())?Jitter.onPcmFrame :: ((pcm: buffer) -> ())?Properties
Section titled “Properties”packets
Section titled “packets”{ [number]: buffer } }
nextSequence
Section titled “nextSequence”stopped
Section titled “stopped”True once destroy has been called.
running
Section titled “running”True while the tick loop is producing frames.
clockAnchor
Section titled “clockAnchor”tickCount
Section titled “tickCount”emptyTicks
Section titled “emptyTicks”Consecutive slots that had no packet.
lastPushClock
Section titled “lastPushClock”thread
Section titled “thread”decoder
Section titled “decoder”shouldDecode
Section titled “shouldDecode”Asked once per slot whether to decode it; nil decodes every slot.
decoding
Section titled “decoding”The latest answer from shouldDecode, so each change is logged once.
decoderStale
Section titled “decoderStale”True from the slot decoding resumes until a new decoder has replaced the one that sat idle.
logger
Section titled “logger”onRawFrame
Section titled “onRawFrame”onPcmFrame
Section titled “onPcmFrame”Methods
Section titled “Methods”Jitter : push ( sequence , packet ) -> ()
Inserts an Opus packet for the given RTP sequence number, resyncing and restarting the tick loop when the stream was idle, jumped far ahead, or ran dry. Other late packets are dropped.
Parameters
| sequence: number | |
| packet: buffer |
Jitter : start ( onRawFrame , onPcmFrame , shouldDecode ) -> ()
Starts producing frames. onRawFrame(sequence, packet) fires for each packet that was present in its
slot and onPcmFrame(pcm) for every slot while audio is arriving, filling gaps with FEC from the next
buffered packet or Opus PLC. shouldDecode, when given, is asked once per slot: while it returns false the slot
skips decoding, FEC and PLC, so onPcmFrame does not fire while onRawFrame still does, and when it returns true
again a new decoder takes over. shouldDecode must return without yielding; one that yields is closed and warned
about, and the slot decodes. Errors raised by any callback are logged at warn and do not stop the loop.
Parameters
| onRawFrame: (sequence: number, packet: buffer) -> () | |
| onPcmFrame: (pcm: buffer) -> () | |
| shouldDecode: (() -> boolean)? |
destroy
Section titled “destroy”Jitter : destroy ( ) -> ()
Stops the tick loop and frees the Opus decoder. Safe to call more than once, and from inside a frame callback, where the loop stops as soon as the callback returns.
Functions
Section titled “Functions”Jitter . new ( firstSequence , jitterLogger ) -> Jitter
Responsible for constructing this class. jitterLogger receives warnings about callback errors and
undecodable packets, and debug lines for dropped packets; without one, the jitter logs as Jitter.