Skip to main content

CodecStringEntry

Struct CodecStringEntry 

Source
pub struct CodecStringEntry { /* private fields */ }
Expand description

A single entry in a FreeSWITCH codec string.

All fields are private. Use CodecStringEntry::new plus the with_* builder methods to construct, and the read accessors plus Display to inspect and emit.

Implementations§

Source§

impl CodecStringEntry

Source

pub fn new(name: impl Into<String>) -> Result<Self, CodecStringError>

Create a new entry with the given codec name.

Returns CodecStringError::InvalidCodecName if the name is empty, CodecStringError::WireInjection if it contains \n or \r, or CodecStringError::InvalidCharInName if it contains any codec-string grammar delimiter (, @ ~ . ' \ or ASCII whitespace).

Source

pub fn with_module( self, modname: impl Into<String>, ) -> Result<Self, CodecStringError>

Set the module prefix (e.g. "mod_opus").

Returns CodecStringError::WireInjection if the value contains \n or \r, or CodecStringError::InvalidCharInName if it contains a grammar delimiter.

Source

pub fn with_fmtp( self, fmtp: impl Into<String>, ) -> Result<Self, CodecStringError>

Set format parameters (~fmtp in the grammar).

§Errors
Source

pub fn with_rate(self, rate: u32) -> Self

Set the sample rate qualifier (@<n>h).

Source

pub fn with_ptime(self, ptime: u32) -> Self

Set the ptime qualifier (@<n>i).

Source

pub fn with_bitrate(self, bitrate: u32) -> Self

Set the bitrate qualifier (@<n>b).

Source

pub fn with_channels(self, channels: u32) -> Self

Set the channel count qualifier (@<n>c).

FreeSWITCH reads this as atoi into a uint32_t; the field is u32 here to match. SdpCodec::channels stays Option<u8> (from a=rtpmap, realistically tiny) and widens losslessly at the merge boundary.

Source

pub fn modname(&self) -> Option<&str>

The module prefix, if any (e.g. "mod_opus").

Source

pub fn name(&self) -> &str

The codec encoding name (e.g. "PCMU", "opus", "AMR-WB").

Source

pub fn fmtp(&self) -> Option<&str>

The format parameters, if any.

Source

pub fn rate(&self) -> Option<u32>

The sample rate qualifier, if any.

Source

pub fn rate_mut(&mut self) -> &mut Option<u32>

Mutable access to the rate qualifier.

Source

pub fn ptime(&self) -> Option<u32>

The ptime qualifier in milliseconds, if any.

Source

pub fn ptime_mut(&mut self) -> &mut Option<u32>

Mutable access to the ptime qualifier.

Source

pub fn bitrate(&self) -> Option<u32>

The bitrate qualifier in bits/s, if any.

Source

pub fn bitrate_mut(&mut self) -> &mut Option<u32>

Mutable access to the bitrate qualifier.

Source

pub fn channels(&self) -> Option<u32>

The channel count qualifier, if any.

Source

pub fn channels_mut(&mut self) -> &mut Option<u32>

Mutable access to the channel count qualifier.

Source

pub fn set_name( &mut self, name: impl Into<String>, ) -> Result<(), CodecStringError>

Set or replace the codec encoding name.

Returns CodecStringError::InvalidCodecName if empty, CodecStringError::WireInjection if the value contains \n or \r, or CodecStringError::InvalidCharInName if it contains a grammar delimiter.

Source

pub fn set_module( &mut self, modname: impl Into<String>, ) -> Result<(), CodecStringError>

Set or replace the module prefix.

Returns CodecStringError::WireInjection if the value contains \n or \r, or CodecStringError::InvalidCharInName if it contains a grammar delimiter.

Source

pub fn set_fmtp( &mut self, fmtp: impl Into<String>, ) -> Result<(), CodecStringError>

Set or replace the format parameters (~fmtp).

Returns the same errors as with_fmtp.

Source

pub fn clear_fmtp(&mut self)

Clear the format parameters.

Source

pub fn clear_module(&mut self) -> Result<(), CodecStringError>

Clear the module prefix.

Returns CodecStringError::DotInFmtpWithoutModule if the current fmtp contains a . — removing the prefix would make the entry re-parse with the dot as the module boundary, silently dropping the codec. The entry is left unchanged on error.

Source

pub fn clear_rate(&mut self)

Clear the rate qualifier.

Infallible analog to clear_fmtp; use to strip a qualifier that matched no loaded implementation (see CodecString::qualified).

Source

pub fn clear_ptime(&mut self)

Clear the ptime qualifier.

Infallible analog to clear_fmtp; use to strip a qualifier that matched no loaded implementation (see CodecString::qualified).

Source

pub fn clear_bitrate(&mut self)

Clear the bitrate qualifier.

Infallible analog to clear_fmtp; use to strip a qualifier that matched no loaded implementation (see CodecString::qualified).

Source

pub fn clear_channels(&mut self)

Clear the channel count qualifier.

Infallible analog to clear_fmtp; use to strip a qualifier that matched no loaded implementation (see CodecString::qualified).

Source

pub fn simplify(&mut self)

Drop qualifiers whose value already equals the FreeSWITCH default for this codec (default_rate/default_ptime, ported from switch_core.c:2033-2055), leaving bitrate alone. G.722 is exempt entirely.

Precondition: only safe on an entry that already matched a loaded implementation, e.g. one that survived CodecString::retain_available — stripping compares against a per-name table, not against what an implementation registered, so it can make an unmatched qualifier start matching. Both that and the G.722 carve-out are in docs/codec-string-format.md.

Trait Implementations§

Source§

impl Clone for CodecStringEntry

Source§

fn clone(&self) -> CodecStringEntry

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 CodecStringEntry

Source§

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

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

impl Display for CodecStringEntry

Source§

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

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

impl Eq for CodecStringEntry

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 CodecStringEntry

Source§

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

Parse a single codec-string entry from a string.

Reuses the same escape/quote-aware split as CodecString’s parser, then delegates to the same single-entry parser. A top-level (unescaped) comma is CodecStringError::MultipleEntries, not a silent take-first.

Source§

type Err = CodecStringError

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

impl PartialEq for CodecStringEntry

Source§

fn eq(&self, other: &CodecStringEntry) -> 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 CodecStringEntry

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.