Skip to content

Conversation

@Harsh-Daga
Copy link

@Harsh-Daga Harsh-Daga commented Nov 3, 2025

Summary

Implements adaptive jitter buffer sizing and burst-aware packet discard based on the research paper "Improved Jitter Buffer Management for WebRTC" (ACM Trans. Multimedia Comput. Commun. Appl., 2021).

Issue: #1906

Motivation

Current static jitter buffer configuration presents a dilemma:

  • Low buffer (50ms): Good for low-jitter networks, but causes packet loss on high-jitter networks
  • High buffer (300ms): Handles jitter but adds unnecessary latency on good networks

Users must choose between latency and reliability, with no middle ground for variable network conditions.

Solution

This PR implements two complementary features:

1. Adaptive Buffer Sizing (Opt-in)

  • Continuously measures network jitter using Welford's online algorithm
  • Calculates optimal buffer size: capacity = mean_jitter + 4σ (99.99% coverage)
  • Automatically adjusts between user-configured min/max bounds
  • Provides optimal latency for current network conditions

2. Burst-Aware Packet Discard (Always enabled)

  • Detects packet bursts using timing analysis
  • Removes only minimum necessary packets using formula: n = (Δt/x) - B
  • Falls back to full reset only in extreme cases
  • Significantly reduces packet loss during burst conditions

Implementation Details

New Configuration Options:

--jb-adaptive                    # Enable adaptive sizing
--jb-adaptive-min=INT            # Minimum buffer size (ms), default: 0
--jb-adaptive-max=INT            # Maximum buffer size (ms), default: 300

Two-Tier Overflow Handling:

  • Tier 1 (Proactive): Triggers at 1x capacity, attempts burst-aware discard
  • Tier 2 (Emergency): Triggers at 3x capacity, forces immediate reset

Key Algorithms:

  • Welford's online variance for efficient statistics
  • Standard deviation-based buffer sizing (4σ rule)
  • Codec-agnostic burst detection using RTP timestamps

Backward Compatibility

  • Fully backward compatible - all features opt-in
  • Default behavior unchanged (static buffer)
  • Burst-aware discard improves existing behavior without configuration
  • No breaking changes to API or configuration

Performance Impact

  • Burst-aware: Minimal overhead, runs only during overflow
  • Adaptive: ~10 floating-point operations per packet, recalculated every 10 packets
  • Memory: 40 bytes added per jitter buffer instance

Expected Improvements

Based on the referenced paper and testing:

  • Packet loss reduction: 5% → 2% during burst conditions
  • Latency optimization: Automatic adjustment to network conditions
  • MOS score improvement: Up to 2+ points in high-jitter scenarios
  • Quality consistency: Better handling of variable network conditions

Files Changed

  • include/main.h: Added configuration flags
  • include/jitter_buffer.h: Added adaptive buffer fields
  • daemon/jitter_buffer.c: Core implementation
  • daemon/main.c: Command-line options and validation

Documentation

Detailed technical explanation available in GitHub Gist

Request for Review

Particularly interested in feedback on:

  1. Configuration defaults (min=0, max=300ms)
  2. Adaptation interval (every 10 packets)
  3. 4σ vs 3σ for buffer sizing

@Harsh-Daga Harsh-Daga force-pushed the adaptive-jitter-buffer branch from 8db8247 to 3aa804a Compare November 3, 2025 08:40
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.

1 participant