push method

void push(
  1. int sequenceNumber,
  2. PcmFrame frame
)

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.

Implementation

void push(int sequenceNumber, PcmFrame frame) {
  if (_closed) return;
  final seq = sequenceNumber & 0xFFFF;

  final last = _lastReleasedSeq;
  if (last != null && _signedDiff(seq, last) <= 0) {
    // Late or duplicate of something we've already played out.
    lateDrops++;
    return;
  }
  if (_queue.containsKey(seq)) {
    // Duplicate that hasn't been played yet — keep the first copy.
    return;
  }

  _queue[seq] = frame;
  _insertSorted(seq);

  // If we've blown past the ceiling, drop the oldest to keep latency
  // bounded.
  while (_seqs.length > maxFrames) {
    final dropped = _seqs.removeAt(0);
    _queue.remove(dropped);
    overflowDrops++;
  }

  while (_seqs.length > targetFrames) {
    _releaseOldest();
  }
  // Once we've reached the target depth at least once, switch to
  // "playing" mode where [tick] will continue draining one frame at a
  // time even if the queue dips below the target (steady-state playout).
  if (_seqs.length >= targetFrames) _playing = true;
}