Skip to main content
Pion Interceptor provides a comprehensive set of built-in interceptors for common WebRTC operations. These interceptors can be composed together to add functionality to RTP/RTCP streams.

Available Interceptors

Congestion Control

NACK

Request and respond to packet retransmissions

GCC

Google Congestion Control for bandwidth estimation

TWCC

Transport-wide congestion control feedback

RFC 8888

RTP Congestion Control Feedback

Quality and Reliability

FlexFEC

Forward error correction for packet recovery

Jitter Buffer

Smooth packet arrival and handle network jitter

Pacing

Control packet sending rate

Reporting and Monitoring

Reports

Generate sender and receiver reports

Statistics

Collect detailed stream statistics

Interval PLI

Request keyframes at regular intervals

Debugging

Packet Dump

Dump RTP/RTCP packets for debugging and analysis

How Interceptors Work

Interceptors sit in the RTP/RTCP processing pipeline and can:
  • Read incoming RTP/RTCP packets
  • Write outgoing RTP/RTCP packets
  • Modify packet contents
  • Generate new RTCP feedback
  • Buffer packets for reordering or retransmission
Interceptors are bound to streams and peer connections, allowing fine-grained control over packet processing.

Creating an Interceptor Chain

Multiple interceptors can be composed together:
import (
    "github.com/pion/interceptor"
    "github.com/pion/interceptor/pkg/gcc"
    "github.com/pion/interceptor/pkg/nack"
    "github.com/pion/interceptor/pkg/report"
)

// Create an interceptor registry
m := &interceptor.Registry{}

// Register multiple interceptors
interceptor.RegisterDefaultInterceptors(m, &mediaEngine)

// Add NACK support
generatorFactory, _ := nack.NewGeneratorInterceptor()
m.Add(generatorFactory)

responderFactory, _ := nack.NewResponderInterceptor()
m.Add(responderFactory)

// Add sender/receiver reports
senderFactory, _ := report.NewSenderInterceptor()
m.Add(senderFactory)

receiverFactory, _ := report.NewReceiverInterceptor()
m.Add(receiverFactory)

Configuration Options

Most interceptors support configuration through functional options:
// Configure NACK generator with custom settings
generatorFactory, _ := nack.NewGeneratorInterceptor(
    nack.GeneratorSize(1024),
    nack.GeneratorInterval(100 * time.Millisecond),
    nack.GeneratorMaxNacksPerPacket(3),
)
See individual interceptor pages for specific configuration options and usage examples.

Best Practices

  1. Order Matters: The order in which interceptors are added affects the processing pipeline
  2. Resource Management: Always close interceptors when done to free resources
  3. Logging: Use logger factories for debugging and monitoring
  4. Testing: Test interceptor chains with your specific use case

Next Steps

Explore the individual interceptor documentation to learn more about each component and how to configure them for your use case.

Build docs developers (and LLMs) love