pub struct SdpCodecs { /* private fields */ }Expand description
Codecs and ancillary data extracted from an SDP session description.
Produced by SdpCodecs::parse. The accessors that feed a codec string reflect
the same extraction logic as FreeSWITCH’s
switch_core_media_set_r_sdp_codec_string; sections is the
wider view, every m= line the offer carried. See docs/codec-string-format.md
for the mapping rules.
Implementations§
Source§impl SdpCodecs
impl SdpCodecs
Sourcepub fn parse(sdp: &str) -> Result<Self, SdpCodecError>
pub fn parse(sdp: &str) -> Result<Self, SdpCodecError>
Parse an SDP session description from a UTF-8 string.
Sourcepub fn parse_bytes(bytes: &[u8]) -> Result<Self, SdpCodecError>
pub fn parse_bytes(bytes: &[u8]) -> Result<Self, SdpCodecError>
Parse an SDP session description from bytes.
Sourcepub fn sections(&self) -> &[SdpMediaSection]
pub fn sections(&self) -> &[SdpMediaSection]
Every m= section the offer carried, in offer order.
This is the inventory, including the sections no codec string can reach — a held or declined stream, or a media type the switch derives no codec from.
Sourcepub fn entries(&self) -> impl Iterator<Item = &SdpCodecEntry>
pub fn entries(&self) -> impl Iterator<Item = &SdpCodecEntry>
Codec entries from the negotiable sections, in SDP offer order.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of codec entries; payloads from non_codec_payloads
are not counted.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true when the offer negotiates no codecs, ignoring any non-codec payloads.
Sourcepub fn unmapped(&self) -> impl Iterator<Item = &UnmappedPayload>
pub fn unmapped(&self) -> impl Iterator<Item = &UnmappedPayload>
Payload types that could not be named (no a=rtpmap, no static-table entry).
These are surfaced as data rather than an error so the caller can distinguish
“never offered” from “offered but unresolvable”. A non-negotiable section’s
unresolvable payloads stay on SdpMediaSection::unmapped.
Sourcepub fn warnings(&self) -> &[SdpWarning]
pub fn warnings(&self) -> &[SdpWarning]
Recoverable parse warnings (e.g. unparseable numeric attributes).
Covers every section, negotiable or not — the excluded ones are parsed rather than skipped, so they warn where the switch has no occasion to.
Sourcepub fn non_codec_payloads(&self) -> impl Iterator<Item = &NonCodecPayload>
pub fn non_codec_payloads(&self) -> impl Iterator<Item = &NonCodecPayload>
Payloads the switch negotiates outside the codec string, in m= order.
Never included in entries or unmapped,
and drawn from the negotiable sections only; a held section’s are on
SdpMediaSection::non_codec_payloads. Not deduplicated: two sections offering
the same kind at one clock rate under different payload types yield two entries.
See NonCodecPayload for what the switch itself retains from these.
Sourcepub fn audio_codec_string(
&self,
options: &CodecStringOptions,
warnings: Option<&mut Vec<SdpWarning>>,
) -> Result<CodecString, CodecStringError>
pub fn audio_codec_string( &self, options: &CodecStringOptions, warnings: Option<&mut Vec<SdpWarning>>, ) -> Result<CodecString, CodecStringError>
Build a FreeSWITCH codec string from this offer’s audio codecs.
Emits a literal t38 entry for each m=image section the offer carried, in
its original m-line position among the audio entries — C writes ,t38 inside
the same per-m-line loop that emits audio codecs (switch_core_media.c:13651),
so an m=image section before an m=audio section puts t38 first, not last.
Does not deduplicate — an offer carrying the AMR octet-aligned/bandwidth-efficient
pair yields two identical entries under default options (they differ only in
fmtp, which is off by default for audio). Call CodecString::dedup after
composing the final string.
warnings = None is strict: any unrepresentable codec name or fmtp is Err.
warnings = Some(acc) is lenient: an unrepresentable fmtp is cleared (the codec
is still emitted) and an unrepresentable codec name is skipped (the codec is
dropped); both push a warning to acc rather than failing the whole call. An
offer past CodecString::MAX_SWITCH_ENTRIES is
CodecStringError::TooManyEntries in either mode — the limit is structural,
not a per-codec oddity.
Sourcepub fn video_codec_string(
&self,
options: &CodecStringOptions,
warnings: Option<&mut Vec<SdpWarning>>,
) -> Result<CodecString, CodecStringError>
pub fn video_codec_string( &self, options: &CodecStringOptions, warnings: Option<&mut Vec<SdpWarning>>, ) -> Result<CodecString, CodecStringError>
Build a FreeSWITCH codec string from this offer’s video codecs.
Selects straight from the video codecs, where the audio builder walks every entry
instead: only the audio string interleaves T.38, which has to keep its m-line
position. Does not deduplicate; see
audio_codec_string for why. warnings follows the
same strict/lenient convention.
Sourcepub fn fmtp_for(&self, name: &str, clock_rate: u32) -> Option<&str>
pub fn fmtp_for(&self, name: &str, clock_rate: u32) -> Option<&str>
Look up the fmtp of an offered audio codec by name and clock rate.
Drives rtp_force_audio_fmtp once the caller knows which codec ended up first
in its final, composed, filtered codec string — “first codec in the offer” is
routinely not that codec, so this takes the name and rate explicitly rather than
exposing a “primary” accessor that would often name the wrong payload map.
Several payload types commonly share one name+rate with different fmtp — the
AMR octet-aligned/bandwidth-efficient pair is the recurring case. When they
disagree, the first one carrying an fmtp wins; a caller driving
rtp_force_audio_fmtp from this can otherwise pin octet-aligned when the
switch negotiated bandwidth-efficient.