pub struct CodecString(/* private fields */);Expand description
A FreeSWITCH codec string — a comma-separated list of CodecStringEntry values.
Parses the grammar from docs/codec-string-format.md and emits it back via
Display. Both directions are infallible given a valid list;
validation happens at entry construction time.
Implementations§
Source§impl CodecString
impl CodecString
Sourcepub fn retain_available<'a, I>(
&mut self,
implementations: I,
) -> Vec<CodecStringEntry>where
I: IntoIterator<Item = &'a CodecImplementation>,
pub fn retain_available<'a, I>(
&mut self,
implementations: I,
) -> Vec<CodecStringEntry>where
I: IntoIterator<Item = &'a CodecImplementation>,
Remove entries that match no implementation in implementations, returning the
removed entries in their original order.
Ports the drop behaviour of switch_loadable_module_get_codecs_sorted
(switch_loadable_module.c:2849-2909): a name/modname miss
(switch_loadable_module_get_codec_interface returning NULL) or a qualifier miss
against every implementation registered under that name both silently drop the
entry in FreeSWITCH. A name-only implementation list (all qualifiers None) models
only the first failure; CodecString::qualified identifies the entries still
exposed to the second, qualifier-matching failure.
Source§impl CodecString
impl CodecString
Sourcepub const MAX_SWITCH_ENTRIES: usize = 50
pub const MAX_SWITCH_ENTRIES: usize = 50
Maximum entries FreeSWITCH processes per codec string (SWITCH_MAX_CODECS,
switch_types.h:595).
The cap applies to raw token slots — including the empty ones consecutive commas
produce — not to the number of parsed entries. Enforced by
push and by both parse modes; see docs/codec-string-format.md
for what the switch does with the 50th slot and everything after it.
Sourcepub fn push(&mut self, entry: CodecStringEntry) -> Result<(), CodecStringError>
pub fn push(&mut self, entry: CodecStringEntry) -> Result<(), CodecStringError>
Append an entry to the list.
Returns CodecStringError::TooManyEntries when the list already holds
MAX_SWITCH_ENTRIES; the entry is not appended.
The bulk operations (Extend, FromIterator, extend_from,
append, insert) do not check the cap.
Sourcepub fn entries(&self) -> &[CodecStringEntry]
pub fn entries(&self) -> &[CodecStringEntry]
All entries in order.
Sourcepub fn iter(&self) -> Iter<'_, CodecStringEntry> ⓘ
pub fn iter(&self) -> Iter<'_, CodecStringEntry> ⓘ
Iterator over entries.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, CodecStringEntry> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, CodecStringEntry> ⓘ
Mutable iterator over entries.
Sourcepub fn extend_from(&mut self, other: &CodecString)
pub fn extend_from(&mut self, other: &CodecString)
Append all entries from other (non-draining; other is unchanged).
Sourcepub fn append(&mut self, other: &mut CodecString)
pub fn append(&mut self, other: &mut CodecString)
Move all entries from other into self, leaving other empty.
Sourcepub fn retain(&mut self, f: impl FnMut(&CodecStringEntry) -> bool)
pub fn retain(&mut self, f: impl FnMut(&CodecStringEntry) -> bool)
Retain only entries for which f returns true.
Sourcepub fn insert(
&mut self,
index: usize,
entry: CodecStringEntry,
) -> Result<(), CodecStringEntry>
pub fn insert( &mut self, index: usize, entry: CodecStringEntry, ) -> Result<(), CodecStringEntry>
Insert an entry at position index, shifting later entries right.
Non-panicking: returns Err(entry) when index > len instead of panicking
like Vec::insert.
Sourcepub fn remove(&mut self, index: usize) -> Option<CodecStringEntry>
pub fn remove(&mut self, index: usize) -> Option<CodecStringEntry>
Remove and return the entry at position index.
Non-panicking: returns None when index >= len instead of panicking
like Vec::remove.
Sourcepub fn qualified(&self) -> impl Iterator<Item = &CodecStringEntry>
pub fn qualified(&self) -> impl Iterator<Item = &CodecStringEntry>
Iterator over entries that carry at least one explicit qualifier or fmtp.
Two unrelated reasons make these worth surfacing to the caller. A numeric
qualifier (rate/ptime/bitrate/channels) risks a silent, unlogged drop at
match time: FreeSWITCH’s implementation matching compares these against
what’s loaded, and neither of its two passes falls back to an unqualified
match — mod_amr.c:690-716 registers AMR at 20 ms only, so AMR@8000h@40i
matches nothing and vanishes unlogged. An fmtp never affects that matching
(switch_loadable_module.c:2876-2877 just copies it through once a match is
already found by name/qualifiers), so it can’t cause this drop — but the
switch hands it to the codec implementation, where it changes negotiated
behaviour (AMR octet-aligned vs bandwidth-efficient is the case that
matters), and an SDP a=fmtp doesn’t translate cleanly into a codec-string
~fmtp in general.
Source§impl CodecString
impl CodecString
Sourcepub fn parse_lenient(
s: &str,
warnings: &mut Vec<SdpWarning>,
) -> Result<Self, CodecStringError>
pub fn parse_lenient( s: &str, warnings: &mut Vec<SdpWarning>, ) -> Result<Self, CodecStringError>
Parse a codec string in lenient mode.
Behaves like the FromStr impl except that qualifier values that overflow
u32 or carry no recognised letter are recorded as
SdpWarning::CodecStringQualifier in warnings rather than returning
an error. The affected qualifier is omitted from the parsed entry. A slot
count over MAX_SWITCH_ENTRIES records
SdpWarning::CodecStringTruncated and every entry is still returned.
Use this when the input comes from a FreeSWITCH channel variable or any
trusted internal source — FreeSWITCH itself logs these anomalies and
continues. Use the FromStr impl (or .parse()) for policy strings you
control; those must be strictly correct.
Sourcepub fn dedup(&mut self)
pub fn dedup(&mut self)
Remove duplicate entries, porting switch_loadable_module_get_codecs_sorted’s
dedup pass (switch_loadable_module.c:2811-2847).
The key is the name, the normalized ptime, rate and channels, and the fmtp, all
case-insensitive; bitrate and module name are read by the C parser and then not
compared. The first occurrence keeps its position. The loop shape, the
normalization rules and what a deployment’s <default-ptimes> does to them are
in docs/codec-string-format.md.
Invariant: the last entry bearing a name is never removed, so a bare name survives to take the deployment’s own default at match time.
Trait Implementations§
Source§impl Clone for CodecString
impl Clone for CodecString
Source§fn clone(&self) -> CodecString
fn clone(&self) -> CodecString
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CodecString
impl Debug for CodecString
Source§impl Default for CodecString
impl Default for CodecString
Source§fn default() -> CodecString
fn default() -> CodecString
Source§impl Display for CodecString
impl Display for CodecString
impl Eq for CodecString
Source§impl Extend<CodecStringEntry> for CodecString
impl Extend<CodecStringEntry> for CodecString
Source§fn extend<I: IntoIterator<Item = CodecStringEntry>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = CodecStringEntry>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<CodecStringEntry> for CodecString
impl FromIterator<CodecStringEntry> for CodecString
Source§fn from_iter<I: IntoIterator<Item = CodecStringEntry>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = CodecStringEntry>>(iter: I) -> Self
Source§impl FromStr for CodecString
impl FromStr for CodecString
Source§impl IntoIterator for CodecString
impl IntoIterator for CodecString
Source§impl<'a> IntoIterator for &'a CodecString
impl<'a> IntoIterator for &'a CodecString
Source§impl<'a> IntoIterator for &'a mut CodecString
impl<'a> IntoIterator for &'a mut CodecString
Source§impl PartialEq for CodecString
impl PartialEq for CodecString
impl StructuralPartialEq for CodecString
Auto Trait Implementations§
impl Freeze for CodecString
impl RefUnwindSafe for CodecString
impl Send for CodecString
impl Sync for CodecString
impl Unpin for CodecString
impl UnsafeUnpin for CodecString
impl UnwindSafe for CodecString
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.