JitterBuffer class
Small fixed-target playout buffer for inbound RTP audio.
Real-time audio arrives with packet-to-packet timing jitter, occasional reordering, and occasional loss. A jitter buffer absorbs all three by holding a few frames before handing them to the audio sink in strict timestamp order.
The implementation is deliberately conservative and pure-Dart so it can be unit-tested without sockets or platform plugins:
- Frames are kept in a sequence-number-keyed map.
- On push a frame is queued. If the buffer holds at least targetFrames frames, the oldest is released to the sink.
- Late frames (older than the highest released sequence) are dropped and counted in lateDrops.
- Reordering across the 16-bit sequence wrap-around is detected by comparing the signed 16-bit difference between two sequence numbers (RFC 3550 §A.1).
- Long stalls are detected via tick: callers can pump the clock on a 20 ms timer to release queued frames even when the network has gone quiet.
Constructors
- JitterBuffer({required AudioSink sink, int targetFrames = 3, int maxFrames = 12})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- lateDrops ↔ int
-
Frames received that arrived after their slot was already played out.
getter/setter pair
- length → int
-
Number of frames currently buffered.
no setter
- maxFrames → int
-
Hard ceiling on queue depth. Above this the oldest queued frames
are dropped (to prevent unbounded growth on a stuck consumer).
final
- overflowDrops ↔ int
-
Frames discarded because the queue overflowed maxFrames.
getter/setter pair
- playedFrames ↔ int
-
Number of frames the sink has been handed.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sink → AudioSink
-
Where to write released frames.
final
- targetFrames → int
-
Steady-state depth in frames before we start releasing. With G.711's
20 ms packetisation a target of 3 ≈ 60 ms of latency, which is what
most softphones use for cellular networks.
final
Methods
-
close(
) → Future< void> - Flush every buffered frame to the sink and stop accepting input.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
push(
int sequenceNumber, PcmFrame frame) → void - Hand a freshly-decoded inbound frame to the buffer, identified by its 16-bit RTP sequence number. Releases zero or more frames to the sink as a side effect.
-
tick(
) → void - Pump the clock without a packet arriving (e.g. a 20 ms timer). One call releases at most one frame so callers can drive playback at a steady cadence even during silence.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited