Skip to main content

Overview

Media streams in Pion WebRTC consist of audio and video tracks managed by RTP transceivers. Unlike browser WebRTC, Pion gives you low-level access to RTP packets and fine-grained control over media processing.

Core Components

Track Types

TrackLocal

Sends media from your application to remote peers.

TrackRemote

Receives media from remote peers.

TrackLocal Interface

The TrackLocal interface defines how media is sent:
track_local.go

TrackLocalContext

track_local.go

Creating Local Tracks

Static Sample Track

For sending pre-recorded or generated media:

Writing to Tracks

Writing RTP Packets Directly

Adding Tracks to PeerConnection

Always read RTCP packets from the sender to handle feedback like PLI (Picture Loss Indication) and NACK (Negative Acknowledgment) requests.

RTPSender

The RTPSender manages outgoing media:
rtpsender.go

Reading RTCP Feedback

rtpsender.go

Receiving Media

OnTrack Handler

The OnTrack implementation from the source:
peerconnection.go

RTPReceiver

rtpreceiver.go

Reading RTP Packets

Codec Configuration

Supported Codecs

Custom Codec Parameters

Simulcast

Send multiple quality layers simultaneously:
Simulcast allows receivers to switch between quality layers based on their available bandwidth.

RTP Header Extensions

Track Replacement

The implementation from source:
rtpsender.go

Transceiver Direction

Bandwidth Control

Interceptors

Modify RTP/RTCP in flight:

Statistics

Next Steps

Data Channels

Learn about bidirectional data transfer

WebRTC Overview

Review core concepts