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:| Protocol | Typical Latency | Use Case |
|---|---|---|
| WebRTC | 0.5s | Real-time interaction |
| LL-HLS | 2-6s | Low-latency at scale |
| LL-DASH | 3-6s | Standards-based low latency |
| HLS | 6-30s | Large-scale distribution |
| RTMP | 3-5s | Legacy broadcasting |
WebRTC Architecture
How WebRTC Achieves Low Latency
WebRTC eliminates traditional buffering through:- UDP Transport: No TCP retransmission delays
- Minimal Buffering: Jitter buffer of ~50-200ms
- Direct Peer Connection: No intermediate servers (in P2P mode)
- 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
ICE Configuration
ICE (Interactive Connectivity Establishment) handles NAT traversal:AppSettings.java:1325-1340
STUN Configuration
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
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: NoencoderSettingsString configured
Benefits:
- Zero transcoding overhead
- Maximum server capacity
- Minimal latency
- CPU efficient
- 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
- Higher CPU usage
- Slight latency increase (~100-200ms)
- Resource intensive
Cluster Deployment
For high-scale WebRTC:- Distributes load across nodes
- Routes viewers to optimal servers
- Handles failover
Performance Optimization
Codec Selection
Supported video codecs:AppSettings.java:440-448
- H.264: Best compatibility, good quality
- VP8: Open-source, Chrome-optimized
- H.265: Better compression, limited support
Frame Rate Control
AppSettings.java:1299-1300
- 30 fps: Standard quality
- 15 fps: Low bandwidth
- 60 fps: High motion content
Resolution & Bitrate Limits
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
Video Conferencing
Requirements:- Bidirectional communication
- Multiple participants
- Screen sharing
Interactive Gaming
Requirements:- Minimal latency
- High frame rate
- Low jitter
Surveillance
Requirements:- Real-time monitoring
- Multiple cameras
- Recording
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
- 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
- Higher latency (6-30s)
- Not suitable for interaction
- Adaptive bitrate complexity
Hybrid Approach
Ant Media Server can deliver both simultaneously:- Studio participants use WebRTC
- Mass audience uses HLS via CDN
Monitoring & Troubleshooting
WebRTC Statistics
Monitor real-time statistics:Common Issues
High Packet Loss
Symptoms: Choppy video, audio dropouts Solutions:- Enable stats-based ABR
- Reduce bitrate
- Check network quality
- Configure TURN server
Connection Failures
Symptoms: Unable to establish connection Solutions:- Verify STUN/TURN configuration
- Check firewall UDP ports
- Enable TCP candidates
- Test with different networks
High Latency
Symptoms: >2 seconds delay Solutions:- Disable transcoding (use SFU mode)
- Reduce jitter buffer
- Check server resources
- Optimize network routing
Next Steps
Streaming Protocols
Compare WebRTC with other protocols
Architecture
Understand WebRTC in the system architecture
