Skip to main content

Overview

The MediaEngine defines the codecs and RTP capabilities supported by a PeerConnection. It controls which audio and video codecs are negotiated, which RTP header extensions are enabled, and which RTCP feedback mechanisms are available.
By default, Pion WebRTC includes a comprehensive set of codecs. You only need to configure the MediaEngine if you want to customize codec support or add custom header extensions.

Creating a MediaEngine

basic-usage.go

Default Codecs

Pion WebRTC supports these codecs by default:

Audio Codecs

1

Opus

MimeTypeOpus - 48kHz, stereo, with in-band FEC
2

G.722

MimeTypeG722 - 8kHz narrowband audio
3

PCMU

MimeTypePCMU - 8kHz μ-law encoding (G.711)
4

PCMA

MimeTypePCMA - 8kHz A-law encoding (G.711)
From mediaengine.go:63-88.

Video Codecs

1

VP8

MimeTypeVP8 - Popular codec with RTX support
2

VP9

MimeTypeVP9 - Profile 0 and Profile 2 with RTX
3

H.264

MimeTypeH264 - Multiple profiles:
  • Baseline (profile-level-id=42001f, 42e01f)
  • Main (profile-level-id=4d001f)
  • High (profile-level-id=64001f)
Both packetization modes 0 and 1 supported
4

H.265

MimeTypeH265 - HEVC codec
5

AV1

MimeTypeAV1 - Next-generation codec
All video codecs include RTCP feedback for:
  • goog-remb - Receiver Estimated Maximum Bitrate
  • ccm fir - Full Intra Request
  • nack - Negative Acknowledgment
  • nack pli - Picture Loss Indication
From mediaengine.go:90-234.

Custom Codec Registration

Register a Single Codec

custom-codec.go
From mediaengine.go:256-274.

Register Specific Codecs Only

specific-codecs.go

RTP Header Extensions

Header extensions provide additional metadata in RTP packets.

Registering Header Extensions

header-extensions.go
From mediaengine.go:276-324.

Common Header Extensions

Used for bandwidth estimation and congestion control. Required for TWCC (Transport Wide Congestion Control).
Indicates the audio level of the RTP packet.
Media stream identification. Required for simulcast.
RTP stream identifier. Required for simulcast.

Direction-Specific Extensions

You can limit header extensions to specific transceiver directions:
directional-extensions.go
From mediaengine.go:292-300.

RTCP Feedback

Add RTCP feedback mechanisms to codecs:
rtcp-feedback.go
From mediaengine.go:326-354.

Common Feedback Types

string
Google’s Receiver Estimated Maximum Bitrate - for bandwidth estimation
string
Negative Acknowledgment - request retransmission of lost packets
string
Picture Loss Indication - request keyframe when packet loss affects decoding
string
Full Intra Request - request keyframe
string
Transport-wide Congestion Control - modern bandwidth estimation

Advanced Usage

Disable MediaEngine Copy

By default, the MediaEngine is copied for each PeerConnection. You can disable this:
disable-copy.go
When disabling MediaEngine copy, do not share the same MediaEngine instance between multiple PeerConnections.
From settingengine.go:496-501.

Query Negotiated Codecs

query-codecs.go

Complete Example

complete-example.go

SettingEngine

Configure advanced WebRTC behavior

Interceptors

Process RTP/RTCP packets