Skip to main content

Overview

Ultra-low latency streaming delivers live video with less than 1 second of delay, enabling truly interactive experiences. Ant Media Server achieves this through WebRTC technology, providing approximately 0.5 seconds of glass-to-glass latency.

What is Ultra-Low Latency?

Latency Comparison:

WebRTC Architecture

How WebRTC Achieves Low Latency

WebRTC eliminates traditional buffering through:
  1. UDP Transport: No TCP retransmission delays
  2. Minimal Buffering: Jitter buffer of ~50-200ms
  3. Direct Peer Connection: No intermediate servers (in P2P mode)
  4. Native Browser Support: No plugin overhead

WebRTC Components in Ant Media Server

The server implements WebRTC through several key interfaces:
IWebRTCAdaptor.java
IWebRTCClient.java
IWebRTCMuxer.java

Configuration

Basic WebRTC Settings

AppSettings.java:1001-1002

Port Configuration

WebRTC requires a range of UDP ports for media:
AppSettings.java:1307-1315
Ensure UDP ports 50000-60000 are open in your firewall for WebRTC to function properly.

ICE Configuration

ICE (Interactive Connectivity Establishment) handles NAT traversal:
AppSettings.java:1325-1340

STUN Configuration

STUN servers help discover public IP addresses for NAT traversal.

TURN Configuration

For restrictive networks, configure TURN relay:

TCP Candidates

Enable TCP fallback for restrictive firewalls:
AppSettings.java:1350
TCP candidates increase latency slightly but improve connectivity in restricted networks.

SDP Semantics

AppSettings.java:1357-1358
Options:
  • unifiedPlan: Modern standard (recommended)
  • planB: Legacy format (deprecated)

Scaling WebRTC

Viewer Limits

Control concurrent WebRTC viewers per stream:
  • -1: Unlimited viewers
  • >0: Maximum concurrent WebRTC viewers per stream

SFU Mode vs. Transcoding

SFU (Selective Forwarding Unit)

When: No encoderSettingsString configured Benefits:
  • Zero transcoding overhead
  • Maximum server capacity
  • Minimal latency
  • CPU efficient
Limitations:
  • All viewers get same quality
  • No adaptive bitrate
  • Requires capable viewers

MCU (Multipoint Control Unit) with Transcoding

When: encoderSettingsString is configured Benefits:
  • Adaptive bitrate for viewers
  • Optimized for each device
  • Better viewer experience
Limitations:
  • Higher CPU usage
  • Slight latency increase (~100-200ms)
  • Resource intensive

Cluster Deployment

For high-scale WebRTC:
Ant Media Server automatically:
  • Distributes load across nodes
  • Routes viewers to optimal servers
  • Handles failover

Performance Optimization

Codec Selection

Supported video codecs:
AppSettings.java:440-448
Recommendations:
  • H.264: Best compatibility, good quality
  • VP8: Open-source, Chrome-optimized
  • H.265: Better compression, limited support

Frame Rate Control

AppSettings.java:1299-1300
Lower frame rates reduce bandwidth:
  • 30 fps: Standard quality
  • 15 fps: Low bandwidth
  • 60 fps: High motion content

Resolution & Bitrate Limits

Prevent resource abuse by limiting incoming streams.

Technical Deep Dive

Media Pipeline

WebRTC media flows through the muxer system:
Muxer.java:840-865

Packet Processing

Minimal buffering for low latency:
Muxer.java:1204-1221

Use Cases

Live Auctions

Requirements:
  • Sub-second latency
  • Synchronized bidding
  • Mobile support
Configuration:

Video Conferencing

Requirements:
  • Bidirectional communication
  • Multiple participants
  • Screen sharing
Configuration:

Interactive Gaming

Requirements:
  • Minimal latency
  • High frame rate
  • Low jitter
Configuration:

Surveillance

Requirements:
  • Real-time monitoring
  • Multiple cameras
  • Recording
Configuration:

Trade-offs: WebRTC vs. HLS

When to Use WebRTC

Advantages:
  • Ultra-low latency (~0.5s)
  • Real-time interaction
  • Built-in encryption (DTLS/SRTP)
  • NAT traversal built-in
Limitations:
  • Higher server resources per viewer
  • Complex firewall configuration
  • Limited CDN support
  • Browser compatibility variations

When to Use HLS

Advantages:
  • Unlimited scalability via CDN
  • Universal device support
  • Lower server resources
  • Simple infrastructure
Limitations:
  • Higher latency (6-30s)
  • Not suitable for interaction
  • Adaptive bitrate complexity

Hybrid Approach

Ant Media Server can deliver both simultaneously:
Use case: Interactive studio with mass audience
  • Studio participants use WebRTC
  • Mass audience uses HLS via CDN

Monitoring & Troubleshooting

WebRTC Statistics

Monitor real-time statistics:
Response includes:

Common Issues

High Packet Loss

Symptoms: Choppy video, audio dropouts Solutions:
  1. Enable stats-based ABR
  2. Reduce bitrate
  3. Check network quality
  4. Configure TURN server

Connection Failures

Symptoms: Unable to establish connection Solutions:
  1. Verify STUN/TURN configuration
  2. Check firewall UDP ports
  3. Enable TCP candidates
  4. Test with different networks

High Latency

Symptoms: >2 seconds delay Solutions:
  1. Disable transcoding (use SFU mode)
  2. Reduce jitter buffer
  3. Check server resources
  4. Optimize network routing

Next Steps

Streaming Protocols

Compare WebRTC with other protocols

Architecture

Understand WebRTC in the system architecture