Overview
Interceptors allow you to intercept and process RTP and RTCP packets as they flow through the WebRTC stack. They enable advanced features like:- NACK (Negative Acknowledgment) for packet loss recovery
- TWCC (Transport Wide Congestion Control) for bandwidth estimation
- RTCP Sender/Receiver Reports for statistics
- Custom packet processing and modification
- FlexFEC forward error correction
Pion provides a default set of interceptors that handle most common use cases. You only need to configure interceptors manually for advanced scenarios.
Default Interceptors
Pion registers these interceptors by default:1
NACK Generator & Responder
Automatically requests retransmission of lost packets and responds to NACK requests
2
RTCP Reports
Generates Sender and Receiver Reports for connection statistics
3
Stats Interceptor
Collects RTP stream statistics accessible via GetStats()
4
TWCC Sender
Generates Transport-Wide Congestion Control feedback for bandwidth estimation
5
Simulcast Extensions
Enables RTP header extensions needed for simulcast (MID, RID)
Using Default Interceptors
default-interceptors.go
Configuring Default Interceptors
You can pass options to configure the default interceptors:interceptor-options.go
NACK Interceptor
NACK (Negative Acknowledgment) enables automatic retransmission of lost RTP packets.Basic Configuration
nack.go
NACK with Options
nack-options.go
NACK automatically registers the required RTCP feedback (
nack and nack pli) to the MediaEngine.TWCC (Transport-Wide Congestion Control)
TWCC provides fine-grained bandwidth estimation by tracking individual RTP packets.Configure TWCC Sender
twcc.go
- Transport-CC header extension for video and audio
- TWCC RTCP feedback
- TWCC sender interceptor
TWCC with Options
twcc-options.go
TWCC Header Extension Only
If you only want to add TWCC header extensions (to let the remote peer generate reports):twcc-header.go
RTCP Reports
Generate Sender and Receiver Reports for connection statistics.rtcp-reports.go
RTCP Reports with Options
rtcp-options.go
Stats Interceptor
Collect detailed RTP stream statistics:stats.go
Simulcast Extensions
Enable RTP header extensions needed for simulcast:simulcast.go
sdp.SDESMidURI- Media stream identificationsdp.SDESRTPStreamIDURI- RTP stream IDsdp.SDESRepairRTPStreamIDURI- Repair stream ID
FlexFEC (Forward Error Correction)
FlexFEC adds redundancy to reduce packet loss impact:flexfec.go
RFC 8888 Congestion Control Feedback
Register congestion control feedback as defined in RFC 8888:rfc8888.go
Custom Interceptor
You can create custom interceptors to process RTP/RTCP packets:custom-interceptor.go
Complete Example
Full Interceptor Configuration
Full Interceptor Configuration
complete-example.go
Interceptor Order
The order of interceptors matters:- FlexFEC - Must be first if used, so FEC packets aren’t modified
- NACK Responder - Should be early to handle retransmissions
- TWCC - Add sequence numbers to packets
- Stats - Collect statistics
- RTCP Reports - Generate reports
- NACK Generator - Request retransmissions
RegisterDefaultInterceptors handles the correct ordering automatically.Related Resources
MediaEngine
Configure codecs and capabilities
SettingEngine
Advanced configuration options