#include <icy/webrtc/codecnegotiator.h>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.
| Return | Name | Description |
|---|---|---|
std::optional< NegotiatedCodec > | negotiateVideo static | 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 |
std::optional< NegotiatedCodec > | negotiateAudio static | 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 |
bool | hasEncoder static | Check if FFmpeg has an encoder for the given codec name. Accepts both FFmpeg names ("libx264") and RTP names ("H264"). |
std::string | rtpToFfmpeg static | Map an RTP codec name to the preferred FFmpeg encoder name. Returns empty string if no mapping exists. |
std::string | ffmpegToRtp static | Map an FFmpeg encoder name to the RTP codec name. Returns empty string if no mapping exists. |
uint32_t | clockRate static | Get the standard RTP clock rate for a codec. |
int | defaultPayloadType static | Get the default RTP payload type for a codec. Returns 0 for dynamic payload types (caller should assign). |
std::optional< CodecSpec > | specFromRtp static | Return the canonical codec spec for an RTP name, if known. |
std::optional< CodecSpec > | specFromFfmpeg static | Return the canonical codec spec for an FFmpeg encoder name, if known. |
std::optional< CodecSpec > | specFromVideoCodec static | Resolve 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 static | Resolve the canonical codec spec from an explicit audio codec config. Prefers the FFmpeg encoder when present, otherwise falls back to RTP name. |
CodecSpec | requireVideoSpec static | Resolve a strict canonical video codec spec or throw. |
CodecSpec | requireAudioSpec static | Resolve a strict canonical audio codec spec or throw. |
av::VideoCodec | resolveWebRtcVideoCodec static | Resolve a browser-safe WebRTC video codec config from an explicit codec. |
av::AudioCodec | resolveWebRtcAudioCodec static | Resolve a browser-safe WebRTC audio codec config from an explicit codec. |
std::optional< CodecSpec > | detectCodec static | Detect the first known codec present in an SDP snippet for the given media type. |
std::optional< CodecSpec > | detectCodecInMedia static | Detect the first known codec from a structured rtc::Description::Media object for the given media type. |
AVCodecID | decoderCodecId static | Return the FFmpeg decoder codec ID for a given codec spec. Returns AV_CODEC_ID_NONE if no mapping is known. |
static
static std::optional< NegotiatedCodec > negotiateVideo(const std::vector< std::string > & offeredCodecs)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
static
static std::optional< NegotiatedCodec > negotiateAudio(const std::vector< std::string > & offeredCodecs)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
static
static bool hasEncoder(const std::string & name)Check if FFmpeg has an encoder for the given codec name. Accepts both FFmpeg names ("libx264") and RTP names ("H264").
static
static std::string rtpToFfmpeg(const std::string & rtpName)Map an RTP codec name to the preferred FFmpeg encoder name. Returns empty string if no mapping exists.
static
static std::string ffmpegToRtp(const std::string & ffmpegName)Map an FFmpeg encoder name to the RTP codec name. Returns empty string if no mapping exists.
static
static uint32_t clockRate(const std::string & rtpName)Get the standard RTP clock rate for a codec.
static
static int defaultPayloadType(const std::string & rtpName)Get the default RTP payload type for a codec. Returns 0 for dynamic payload types (caller should assign).
static
static std::optional< CodecSpec > specFromRtp(const std::string & rtpName)Return the canonical codec spec for an RTP name, if known.
static
static std::optional< CodecSpec > specFromFfmpeg(const std::string & ffmpegName)Return the canonical codec spec for an FFmpeg encoder name, if known.
static
static std::optional< CodecSpec > specFromVideoCodec(const av::VideoCodec & codec)Resolve the canonical codec spec from an explicit video codec config. Prefers the FFmpeg encoder when present, otherwise falls back to RTP name.
static
static std::optional< CodecSpec > specFromAudioCodec(const av::AudioCodec & codec)Resolve the canonical codec spec from an explicit audio codec config. Prefers the FFmpeg encoder when present, otherwise falls back to RTP name.
static
static CodecSpec requireVideoSpec(const av::VideoCodec & codec)Resolve a strict canonical video codec spec or throw.
static
static CodecSpec requireAudioSpec(const av::AudioCodec & codec)Resolve a strict canonical audio codec spec or throw.
static
static av::VideoCodec resolveWebRtcVideoCodec(const av::VideoCodec & codec)Resolve a browser-safe WebRTC video codec config from an explicit codec.
static
static av::AudioCodec resolveWebRtcAudioCodec(const av::AudioCodec & codec)Resolve a browser-safe WebRTC audio codec config from an explicit codec.
static
static std::optional< CodecSpec > detectCodec(std::string_view sdp, CodecMediaType mediaType)Detect the first known codec present in an SDP snippet for the given media type.
static
static std::optional< CodecSpec > detectCodecInMedia(const rtc::Description::Media & media, CodecMediaType mediaType)Detect the first known codec from a structured rtc::Description::Media object for the given media type.
static
static AVCodecID decoderCodecId(const CodecSpec & spec)Return the FFmpeg decoder codec ID for a given codec spec. Returns AV_CODEC_ID_NONE if no mapping is known.