Skip to main content

SessionDescription

Struct SessionDescription 

Source
pub struct SessionDescription {
Show 13 fields pub version: Version, pub origin: Origin, pub session_name: SessionName, pub session_information: Option<Information>, pub uri: Option<String>, pub email_addresses: Vec<EmailAddress>, pub phone_numbers: Vec<PhoneNumber>, pub connection_information: Option<ConnectionInformation>, pub bandwidth: Vec<Bandwidth>, pub time_descriptions: Vec<TimeDescription>, pub encryption_key: Option<EncryptionKey>, pub attributes: Vec<Attribute>, pub media_descriptions: Vec<MediaDescription>,
}
Expand description

SessionDescription is a a well-defined format for conveying sufficient information to discover and participate in a multimedia session.

Fields§

§version: Version§origin: Origin

o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>

https://www.rfc-editor.org/rfc/rfc8866#section-5.2

§session_name: SessionName

s=<session name>

Never empty in SDP: an empty name is written as -.

https://www.rfc-editor.org/rfc/rfc8866#section-5.3

§session_information: Option<Information>§uri: Option<String>

u=<uri>: an RFC 3986 URI-reference, absolute or relative (RFC 8866 section 9: uri-field = %x75 "=" uri CRLF, uri = URI-reference).

https://www.rfc-editor.org/rfc/rfc8866#section-5.5

§email_addresses: Vec<EmailAddress>

e=<email-address>, any number of lines.

https://www.rfc-editor.org/rfc/rfc8866#section-5.6

§phone_numbers: Vec<PhoneNumber>

p=<phone-number>, any number of lines.

https://www.rfc-editor.org/rfc/rfc8866#section-5.6

§connection_information: Option<ConnectionInformation>

c=<nettype> <addrtype> <connection-address>

https://www.rfc-editor.org/rfc/rfc8866#section-5.7

§bandwidth: Vec<Bandwidth>§time_descriptions: Vec<TimeDescription>

The time descriptions: t=, each with its r= and z= lines. SDP needs at least one: an empty list is written as t=0 0.

https://www.rfc-editor.org/rfc/rfc8866#section-5.9

§encryption_key: Option<EncryptionKey>

Obsolete. RFC 8866 section 5.12: a k= line “MUST NOT be included in an SDP description and MUST be discarded if received”. The parser never sets this field and nothing writes it; it is kept so that code naming it still builds.

§attributes: Vec<Attribute>

a=<attribute>

a=<attribute>:<value>

https://www.rfc-editor.org/rfc/rfc8866#section-5.13

§media_descriptions: Vec<MediaDescription>

Implementations§

Source§

impl SessionDescription

Source

pub fn validate(&self) -> Result<()>

Checks what SessionDescription::unmarshal leaves unchecked: everything that takes more than one line to judge, and the value of every attribute this crate has a type for.

RFC 9429 section 5.8 has a description rejected when a line is not well formed “even if its value is discarded”; this is that check for the a= lines. It returns the first problem found:

  • a media description without c= when the session has none (RFC 8866 section 5.7);
  • a known attribute whose value does not match its grammar, or a property attribute (rtcp-mux, sendrecv, …) that carries a value;
  • an attribute at a level it is not defined for (a=group in a media description, a=rtcp-mux at the session level, …), per the levels of mux;
  • more than one direction attribute at one level (RFC 8866 section 6.7), or more than one of an attribute that a level holds once (mid, setup, ice-ufrag, ice-pwd, simulcast, …);
  • two a=mid with the same tag (RFC 5888 section 4);
  • two a=rid with one id in a section, an a=simulcast naming a rid without an a=rid line;
  • in a section with an RTP profile, a format that is not a payload type (RFC 8866 section 5.14).

An attribute this crate does not know is not an error (RFC 8866 section 5.13). Negotiation rules (what an answer may contain given an offer, which tags a group may name, BUNDLE consistency across sections) are not checked here: they belong to the layer that negotiates.

Source§

impl SessionDescription

Reset cleans the SessionDescription, and sets all fields back to their default values

Source

pub fn new_jsep_session_description(_identity: bool) -> Self

A session description with the session-level lines RFC 9429 section 5.2.1 gives an offer: v=0, o=- <sess-id> <sess-version> IN IP4 0.0.0.0 with a random 63-bit session id and, for the session version, the system clock’s seconds since 1900 (RFC 8866 section 5.2: “it is RECOMMENDED that a timestamp be used”), s=- and t=0 0.

_identity is ignored. It used to add a bare a=identity, which is not SDP: the attribute carries an assertion (RFC 8827 section 5). An application that has one adds it with with_typed(&Identity).

Source

pub fn new_jsep_session_description_with_origin(origin: Origin) -> Self

new_jsep_session_description with the o= line the caller gives, for a session whose origin is kept across descriptions (RFC 9429 section 5.2.2: “The fields of the “o=” line MUST stay the same except for the field“) or drawn from sources the caller controls.

Source

pub fn with_property_attribute(self, key: String) -> Self

WithPropertyAttribute adds a property attribute ‘a=key’ to the session description

Source

pub fn with_value_attribute(self, key: String, value: String) -> Self

WithValueAttribute adds a value attribute ‘a=key:value’ to the session description

Source

pub fn with_fingerprint(self, algorithm: String, value: String) -> Self

WithFingerprint adds a fingerprint to the session description

Source

pub fn with_media(self, md: MediaDescription) -> Self

WithMedia adds a media description to the session description

Source

pub fn get_codec_for_payload_type(&self, payload_type: u8) -> Result<Codec>

get_codec_for_payload_type scans the SessionDescription for the given payload type and returns the codec

Source

pub fn get_payload_type_for_codec(&self, wanted: &Codec) -> Result<u8>

get_payload_type_for_codec scans the SessionDescription for a codec that matches the provided codec as closely as possible and returns its payload type

Source

pub fn has_attribute(&self, key: &str) -> bool

Returns whether an attribute exists

Source

pub fn attribute(&self, key: &str) -> Option<&String>

Attribute returns the value of an attribute and if it exists

Source

pub fn bandwidth_of(&self, kind: BandwidthKind) -> Option<u64>

The value of the first session-level b= line of kind, in the unit of that modifier.

Source

pub fn typed<T: TypedAttribute>(&self) -> Result<Option<T>>

The first a=<T::NAME> attribute at this level, parsed. Ok(None) when there is none, Err when it is malformed.

Source

pub fn typed_all<T: TypedAttribute>(&self) -> Result<Vec<T>>

Every a=<T::NAME> attribute at this level, parsed, in order.

Source

pub fn flag(&self, name: &str) -> Result<bool>

Whether the property attribute name (one without a value, such as rtcp-mux) is present at this level. Err when it carries a value.

Source

pub fn with_typed<T: TypedAttribute>(self, value: &T) -> Self

Appends the a= line of a typed attribute.

Source

pub fn direction(&self) -> Result<Option<Direction>>

The direction attribute at this level (sendrecv, sendonly, recvonly, inactive). Ok(None) when there is none; Err when there are several (RFC 8866 section 6.7: at most one per level) or when one carries a value.

Source

pub fn extmaps(&self) -> Result<Vec<ExtMap>>

a=extmap lines at this level (RFC 8285).

Source

pub fn extmap_allow_mixed(&self) -> Result<bool>

Whether a=extmap-allow-mixed is present at this level (RFC 8285 section 6).

Source

pub fn ice_ufrag(&self) -> Result<Option<IceUfrag>>

a=ice-ufrag at this level (RFC 8839 section 5.4).

Source

pub fn ice_pwd(&self) -> Result<Option<IcePwd>>

a=ice-pwd at this level (RFC 8839 section 5.4).

Source

pub fn ice_options(&self) -> Result<Option<IceOptions>>

a=ice-options at this level (RFC 8839 section 5.6).

Source

pub fn fingerprints(&self) -> Result<Vec<Fingerprint>>

a=fingerprint lines at this level (RFC 8122 section 5).

Source

pub fn setup(&self) -> Result<Option<Setup>>

a=setup at this level (RFC 4145 section 4, RFC 8842).

Source

pub fn tls_id(&self) -> Result<Option<TlsId>>

a=tls-id at this level (RFC 8842 section 4).

Source

pub fn rtcp_xr(&self) -> Result<Option<RtcpXr>>

a=rtcp-xr at this level (RFC 3611 section 5.1).

Source

pub fn cryptex(&self) -> Result<bool>

Whether a=cryptex is present at this level (RFC 9335 section 4).

Source

pub fn groups(&self) -> Result<Vec<Group>>

a=group lines (RFC 5888 section 5), every semantics.

Source

pub fn bundle_groups(&self) -> Result<Vec<Group>>

The a=group:BUNDLE lines (RFC 9143 section 5).

Source

pub fn ice_lite(&self) -> Result<bool>

Whether a=ice-lite is present (RFC 8839 section 5.3).

Source

pub fn ice_pacing(&self) -> Result<Option<IcePacing>>

a=ice-pacing (RFC 8839 section 5.5).

Source

pub fn identity(&self) -> Result<Option<Identity>>

a=identity (RFC 8827 section 5). Only the first one counts.

Source

pub fn tool(&self) -> Result<Option<Tool>>

a=tool (RFC 8866 section 6.3).

Source

pub fn conference_type(&self) -> Result<Option<ConferenceType>>

a=type, the conference type (RFC 8866 section 6.9).

Source

pub fn msid_semantic(&self) -> Result<Option<MsidSemantic>>

a=msid-semantic (draft-ietf-mmusic-msid; browsers still write it).

Source

pub fn marshal(&self) -> String

Marshal takes a SDP struct to text, in the order RFC 8866 section 9 gives:

Session description
   v=  (protocol version)
   o=  (originator and session identifier)
   s=  (session name)
   i=* (session information)
   u=* (URI of description)
   e=* (zero or more email address lines)
   p=* (zero or more phone number lines)
   c=* (connection information -- not required if included in all media)
   b=* (zero or more bandwidth information lines)
   One or more time descriptions:
      t=  (time the session is active)
      r=* (zero or more repeat times)
      z=* (time zone adjustments of those repeat times)
   a=* (zero or more session attribute lines)
   Zero or more media descriptions:
      m=  (media name and transport address)
      i=* (media title)
      c=* (connection information -- optional if included at session level)
      b=* (zero or more bandwidth information lines)
      a=* (zero or more media attribute lines)

k= is never written (section 5.12). An empty session name is written as s=- and an empty list of time descriptions as t=0 0, so that what comes out has the required lines. Field values are written as they are: build them from parsed or checked input.

Source

pub fn unmarshal<R: BufRead + Seek>(reader: &mut R) -> Result<Self>

Unmarshal deserializes a session description, with ParseOptions::strict: the RFC 8866 section 9 grammar, line by line and in its order.

See ParseOptions for what is accepted beyond the grammar, and for what is refused. Attribute values are kept as text: use the typed accessors (mid(), rtpmaps(), candidates(), …) or SessionDescription::validate to check them.

The input is bounded: MAX_SDP_SIZE bytes, MAX_SDP_LINES lines, MAX_MEDIA_DESCRIPTIONS media descriptions, MAX_ATTRIBUTES_PER_SECTION attributes at each level and MAX_FORMATS_PER_MEDIA formats on an m= line.

Source

pub fn unmarshal_with_options<R: BufRead + Seek>( reader: &mut R, options: &ParseOptions, ) -> Result<Self>

SessionDescription::unmarshal with the leniencies options names.

Source

pub fn charset(&self) -> Charset

The character set the session name and information are in (RFC 8866 section 6.10, a=charset): UTF-8 when the description names none.

Source

pub fn parse_with_options(text: &str, options: &ParseOptions) -> Result<Self>

Parses a session description from text, with the leniencies options names.

Source

pub fn parse_located( text: &str, options: &ParseOptions, ) -> Result<Self, SdpParseError>

Self::parse_with_options, saying which line a syntax error is on (W3C webrtc-pc section 11.1: an sdp-syntax-error carries its sdpLineNumber).

§Errors

The error Self::parse_with_options returns, with the number (from 1, blank lines counted) of the line it is about; None for an error about the description as a whole (its size, or a missing t= line at its end).

Trait Implementations§

Source§

impl Clone for SessionDescription

Source§

fn clone(&self) -> Self

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 SessionDescription

Source§

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

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

impl Default for SessionDescription

Source§

fn default() -> Self

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

impl Display for SessionDescription

Writes the description in the order RFC 8866 section 9 requires, whatever order its parts were set in: v o s i u e* p* c b* (t r* z)+ a*, then for each media description m i c b* a*.

Source§

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

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

impl From<SessionDescription> for String

Source§

fn from(sdp: SessionDescription) -> String

Converts to this type from the input type.
Source§

impl FromStr for SessionDescription

Source§

type Err = Error

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

fn from_str(sdp: &str) -> Result<Self>

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

impl TryFrom<String> for SessionDescription

Source§

type Error = Error

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

fn try_from(sdp_string: String) -> Result<Self>

Performs the conversion.

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<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.