Skip to main content

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
From interceptor.go:24-29.

Configuring Default Interceptors

You can pass options to configure the default interceptors:
interceptor-options.go
From interceptor.go:31-75.

NACK Interceptor

NACK (Negative Acknowledgment) enables automatic retransmission of lost RTP packets.

Basic Configuration

nack.go
From interceptor.go:142-168.

NACK with Options

nack-options.go
From interceptor.go:147-168.
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
This registers:
  • Transport-CC header extension for video and audio
  • TWCC RTCP feedback
  • TWCC sender interceptor
From interceptor.go:195-228.

TWCC with Options

twcc-options.go
From interceptor.go:201-228.

TWCC Header Extension Only

If you only want to add TWCC header extensions (to let the remote peer generate reports):
twcc-header.go
From interceptor.go:170-193.

RTCP Reports

Generate Sender and Receiver Reports for connection statistics.
rtcp-reports.go
From interceptor.go:116-140.

RTCP Reports with Options

rtcp-options.go

Stats Interceptor

Collect detailed RTP stream statistics:
stats.go
From interceptor.go:77-95.

Simulcast Extensions

Enable RTP header extensions needed for simulcast:
simulcast.go
This registers:
  • sdp.SDESMidURI - Media stream identification
  • sdp.SDESRTPStreamIDURI - RTP stream ID
  • sdp.SDESRepairRTPStreamIDURI - Repair stream ID
From interceptor.go:252-269.

FlexFEC (Forward Error Correction)

FlexFEC adds redundancy to reduce packet loss impact:
flexfec.go
FlexFEC interceptor must be registered before other interceptors that modify RTP packets (like TWCC), so that FEC packets are not modified.
From interceptor.go:271-304.

RFC 8888 Congestion Control Feedback

Register congestion control feedback as defined in RFC 8888:
rfc8888.go
From interceptor.go:230-250.

Custom Interceptor

You can create custom interceptors to process RTP/RTCP packets:
custom-interceptor.go

Complete Example

complete-example.go

Interceptor Order

The order of interceptors matters:
  1. FlexFEC - Must be first if used, so FEC packets aren’t modified
  2. NACK Responder - Should be early to handle retransmissions
  3. TWCC - Add sequence numbers to packets
  4. Stats - Collect statistics
  5. RTCP Reports - Generate reports
  6. NACK Generator - Request retransmissions
RegisterDefaultInterceptors handles the correct ordering automatically.

MediaEngine

Configure codecs and capabilities

SettingEngine

Advanced configuration options