Home
WebRTC module

CodecNegotiator

Maps RTP codec names to FFmpeg encoders and queries FFmpeg at runtime to determine what codecs are available.

CodecNegotiator

#include <icy/webrtc/codecnegotiator.h>
class CodecNegotiator

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:118

Maps RTP codec names to FFmpeg encoders and queries FFmpeg at runtime to determine what codecs are available.

This is stateless - all methods are static. Call negotiate*() with a list of RTP codec names offered by the remote peer, and it returns the best match that FFmpeg can encode.

List of all members

NameKindOwner
negotiateVideofunctionDeclared here
negotiateAudiofunctionDeclared here
hasEncoderfunctionDeclared here
rtpToFfmpegfunctionDeclared here
ffmpegToRtpfunctionDeclared here
clockRatefunctionDeclared here
defaultPayloadTypefunctionDeclared here
specFromRtpfunctionDeclared here
specFromFfmpegfunctionDeclared here
specFromVideoCodecfunctionDeclared here
specFromAudioCodecfunctionDeclared here
requireVideoSpecfunctionDeclared here
requireAudioSpecfunctionDeclared here
resolveWebRtcVideoCodecfunctionDeclared here
resolveWebRtcAudioCodecfunctionDeclared here
detectCodecfunctionDeclared here
detectCodecInMediafunctionDeclared here
decoderCodecIdfunctionDeclared here

Public Static Methods

ReturnNameDescription
std::optional< NegotiatedCodec >negotiateVideo staticNegotiate the best video codec from a list of offered RTP codec names. Returns the first match that FFmpeg can encode, in preference order: H264 > VP8 > VP9 > AV1 > H265
std::optional< NegotiatedCodec >negotiateAudio staticNegotiate the best audio codec from a list of offered RTP codec names. Returns the first match that FFmpeg can encode, in preference order: opus > PCMU > PCMA
boolhasEncoder staticCheck if FFmpeg has an encoder for the given codec name. Accepts both FFmpeg names ("libx264") and RTP names ("H264").
std::stringrtpToFfmpeg staticMap an RTP codec name to the preferred FFmpeg encoder name. Returns empty string if no mapping exists.
std::stringffmpegToRtp staticMap an FFmpeg encoder name to the RTP codec name. Returns empty string if no mapping exists.
uint32_tclockRate staticGet the standard RTP clock rate for a codec.
intdefaultPayloadType staticGet the default RTP payload type for a codec. Returns 0 for dynamic payload types (caller should assign).
std::optional< CodecSpec >specFromRtp staticReturn the canonical codec spec for an RTP name, if known.
std::optional< CodecSpec >specFromFfmpeg staticReturn the canonical codec spec for an FFmpeg encoder name, if known.
std::optional< CodecSpec >specFromVideoCodec staticResolve the canonical codec spec from an explicit video codec config. Prefers the FFmpeg encoder when present, otherwise falls back to RTP name.
std::optional< CodecSpec >specFromAudioCodec staticResolve the canonical codec spec from an explicit audio codec config. Prefers the FFmpeg encoder when present, otherwise falls back to RTP name.
CodecSpecrequireVideoSpec staticResolve a strict canonical video codec spec or throw.
CodecSpecrequireAudioSpec staticResolve a strict canonical audio codec spec or throw.
av::VideoCodecresolveWebRtcVideoCodec staticResolve a browser-safe WebRTC video codec config from an explicit codec.
av::AudioCodecresolveWebRtcAudioCodec staticResolve a browser-safe WebRTC audio codec config from an explicit codec.
std::optional< CodecSpec >detectCodec staticDetect the first known codec present in an SDP snippet for the given media type.
std::optional< CodecSpec >detectCodecInMedia staticDetect the first known codec from a structured rtc::Description::Media object for the given media type.
AVCodecIDdecoderCodecId staticReturn the FFmpeg decoder codec ID for a given codec spec. Returns AV_CODEC_ID_NONE if no mapping is known.

negotiateVideo

static

static std::optional< NegotiatedCodec > negotiateVideo(const std::vector< std::string > & offeredCodecs)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:125

Negotiate the best video codec from a list of offered RTP codec names. Returns the first match that FFmpeg can encode, in preference order: H264 > VP8 > VP9 > AV1 > H265


negotiateAudio

static

static std::optional< NegotiatedCodec > negotiateAudio(const std::vector< std::string > & offeredCodecs)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:131

Negotiate the best audio codec from a list of offered RTP codec names. Returns the first match that FFmpeg can encode, in preference order: opus > PCMU > PCMA


hasEncoder

static

static bool hasEncoder(const std::string & name)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:135

Check if FFmpeg has an encoder for the given codec name. Accepts both FFmpeg names ("libx264") and RTP names ("H264").


rtpToFfmpeg

static

static std::string rtpToFfmpeg(const std::string & rtpName)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:139

Map an RTP codec name to the preferred FFmpeg encoder name. Returns empty string if no mapping exists.


ffmpegToRtp

static

static std::string ffmpegToRtp(const std::string & ffmpegName)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:143

Map an FFmpeg encoder name to the RTP codec name. Returns empty string if no mapping exists.


clockRate

static

static uint32_t clockRate(const std::string & rtpName)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:146

Get the standard RTP clock rate for a codec.


defaultPayloadType

static

static int defaultPayloadType(const std::string & rtpName)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:150

Get the default RTP payload type for a codec. Returns 0 for dynamic payload types (caller should assign).


specFromRtp

static

static std::optional< CodecSpec > specFromRtp(const std::string & rtpName)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:154

Return the canonical codec spec for an RTP name, if known.


specFromFfmpeg

static

static std::optional< CodecSpec > specFromFfmpeg(const std::string & ffmpegName)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:158

Return the canonical codec spec for an FFmpeg encoder name, if known.


specFromVideoCodec

static

static std::optional< CodecSpec > specFromVideoCodec(const av::VideoCodec & codec)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:163

Resolve the canonical codec spec from an explicit video codec config. Prefers the FFmpeg encoder when present, otherwise falls back to RTP name.


specFromAudioCodec

static

static std::optional< CodecSpec > specFromAudioCodec(const av::AudioCodec & codec)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:168

Resolve the canonical codec spec from an explicit audio codec config. Prefers the FFmpeg encoder when present, otherwise falls back to RTP name.


requireVideoSpec

static

static CodecSpec requireVideoSpec(const av::VideoCodec & codec)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:171

Resolve a strict canonical video codec spec or throw.


requireAudioSpec

static

static CodecSpec requireAudioSpec(const av::AudioCodec & codec)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:174

Resolve a strict canonical audio codec spec or throw.


resolveWebRtcVideoCodec

static

static av::VideoCodec resolveWebRtcVideoCodec(const av::VideoCodec & codec)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:178

Resolve a browser-safe WebRTC video codec config from an explicit codec.


resolveWebRtcAudioCodec

static

static av::AudioCodec resolveWebRtcAudioCodec(const av::AudioCodec & codec)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:182

Resolve a browser-safe WebRTC audio codec config from an explicit codec.


detectCodec

static

static std::optional< CodecSpec > detectCodec(std::string_view sdp, CodecMediaType mediaType)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:187

Detect the first known codec present in an SDP snippet for the given media type.


detectCodecInMedia

static

static std::optional< CodecSpec > detectCodecInMedia(const rtc::Description::Media & media, CodecMediaType mediaType)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:192

Detect the first known codec from a structured rtc::Description::Media object for the given media type.


decoderCodecId

static

static AVCodecID decoderCodecId(const CodecSpec & spec)

Defined in src/webrtc/include/icy/webrtc/codecnegotiator.h:197

Return the FFmpeg decoder codec ID for a given codec spec. Returns AV_CODEC_ID_NONE if no mapping is known.