Skip to main content

CodecString

Struct CodecString 

Source
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

Source

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

Source

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.

Source

pub fn new() -> Self

Create an empty codec string.

Source

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.

Source

pub fn entries(&self) -> &[CodecStringEntry]

All entries in order.

Source

pub fn iter(&self) -> Iter<'_, CodecStringEntry> ⓘ

Iterator over entries.

Source

pub fn len(&self) -> usize

Number of entries.

Source

pub fn is_empty(&self) -> bool

true when the list is empty.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, CodecStringEntry> ⓘ

Mutable iterator over entries.

Source

pub fn extend_from(&mut self, other: &CodecString)

Append all entries from other (non-draining; other is unchanged).

Source

pub fn append(&mut self, other: &mut CodecString)

Move all entries from other into self, leaving other empty.

Source

pub fn clear(&mut self)

Remove all entries.

Source

pub fn retain(&mut self, f: impl FnMut(&CodecStringEntry) -> bool)

Retain only entries for which f returns true.

Source

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.

Source

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.

Source

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

Source

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.

Source

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

Source§

fn clone(&self) -> CodecString

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodecString

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CodecString

Source§

fn default() -> CodecString

Returns the “default value” for a type. Read more
Source§

impl Display for CodecString

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for CodecString

Source§

impl Extend<CodecStringEntry> for CodecString

Source§

fn extend<I: IntoIterator<Item = CodecStringEntry>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<CodecStringEntry> for CodecString

Source§

fn from_iter<I: IntoIterator<Item = CodecStringEntry>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromStr for CodecString

Source§

type Err = CodecStringError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl IntoIterator for CodecString

Source§

type Item = CodecStringEntry

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<CodecStringEntry>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a CodecString

Source§

type Item = &'a CodecStringEntry

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, CodecStringEntry>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut CodecString

Source§

type Item = &'a mut CodecStringEntry

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, CodecStringEntry>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for CodecString

Source§

fn eq(&self, other: &CodecString) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CodecString

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.