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: Origino=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
session_name: SessionNames=<session name>
Never empty in SDP: an empty name is written as -.
session_information: Option<Information>i=<session description>
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).
email_addresses: Vec<EmailAddress>e=<email-address>, any number of lines.
phone_numbers: Vec<PhoneNumber>p=<phone-number>, any number of lines.
connection_information: Option<ConnectionInformation>c=<nettype> <addrtype> <connection-address>
bandwidth: Vec<Bandwidth>b=<bwtype>:<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.
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>§media_descriptions: Vec<MediaDescription>Implementations§
Source§impl SessionDescription
impl SessionDescription
Sourcepub fn validate(&self) -> Result<()>
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=groupin a media description,a=rtcp-muxat the session level, …), per the levels ofmux; - 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=midwith the same tag (RFC 5888 section 4); - two
a=ridwith one id in a section, ana=simulcastnaming a rid without ana=ridline; - 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
impl SessionDescription
Reset cleans the SessionDescription, and sets all fields back to their default values
Sourcepub fn new_jsep_session_description(_identity: bool) -> Self
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).
Sourcepub fn new_jsep_session_description_with_origin(origin: Origin) -> Self
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
Sourcepub fn with_property_attribute(self, key: String) -> Self
pub fn with_property_attribute(self, key: String) -> Self
WithPropertyAttribute adds a property attribute ‘a=key’ to the session description
Sourcepub fn with_value_attribute(self, key: String, value: String) -> Self
pub fn with_value_attribute(self, key: String, value: String) -> Self
WithValueAttribute adds a value attribute ‘a=key:value’ to the session description
Sourcepub fn with_fingerprint(self, algorithm: String, value: String) -> Self
pub fn with_fingerprint(self, algorithm: String, value: String) -> Self
WithFingerprint adds a fingerprint to the session description
Sourcepub fn with_media(self, md: MediaDescription) -> Self
pub fn with_media(self, md: MediaDescription) -> Self
WithMedia adds a media description to the session description
Sourcepub fn get_codec_for_payload_type(&self, payload_type: u8) -> Result<Codec>
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
Sourcepub fn get_payload_type_for_codec(&self, wanted: &Codec) -> Result<u8>
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
Sourcepub fn has_attribute(&self, key: &str) -> bool
pub fn has_attribute(&self, key: &str) -> bool
Returns whether an attribute exists
Sourcepub fn attribute(&self, key: &str) -> Option<&String>
pub fn attribute(&self, key: &str) -> Option<&String>
Attribute returns the value of an attribute and if it exists
Sourcepub fn bandwidth_of(&self, kind: BandwidthKind) -> Option<u64>
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.
Sourcepub fn typed<T: TypedAttribute>(&self) -> Result<Option<T>>
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.
Sourcepub fn typed_all<T: TypedAttribute>(&self) -> Result<Vec<T>>
pub fn typed_all<T: TypedAttribute>(&self) -> Result<Vec<T>>
Every a=<T::NAME> attribute at this level, parsed, in order.
Sourcepub fn flag(&self, name: &str) -> Result<bool>
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.
Sourcepub fn with_typed<T: TypedAttribute>(self, value: &T) -> Self
pub fn with_typed<T: TypedAttribute>(self, value: &T) -> Self
Appends the a= line of a typed attribute.
Sourcepub fn direction(&self) -> Result<Option<Direction>>
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.
Sourcepub fn extmap_allow_mixed(&self) -> Result<bool>
pub fn extmap_allow_mixed(&self) -> Result<bool>
Whether a=extmap-allow-mixed is present at this level (RFC 8285 section 6).
Sourcepub fn ice_ufrag(&self) -> Result<Option<IceUfrag>>
pub fn ice_ufrag(&self) -> Result<Option<IceUfrag>>
a=ice-ufrag at this level (RFC 8839 section 5.4).
Sourcepub fn ice_pwd(&self) -> Result<Option<IcePwd>>
pub fn ice_pwd(&self) -> Result<Option<IcePwd>>
a=ice-pwd at this level (RFC 8839 section 5.4).
Sourcepub fn ice_options(&self) -> Result<Option<IceOptions>>
pub fn ice_options(&self) -> Result<Option<IceOptions>>
a=ice-options at this level (RFC 8839 section 5.6).
Sourcepub fn fingerprints(&self) -> Result<Vec<Fingerprint>>
pub fn fingerprints(&self) -> Result<Vec<Fingerprint>>
a=fingerprint lines at this level (RFC 8122 section 5).
Sourcepub fn setup(&self) -> Result<Option<Setup>>
pub fn setup(&self) -> Result<Option<Setup>>
a=setup at this level (RFC 4145 section 4, RFC 8842).
Sourcepub fn rtcp_xr(&self) -> Result<Option<RtcpXr>>
pub fn rtcp_xr(&self) -> Result<Option<RtcpXr>>
a=rtcp-xr at this level (RFC 3611 section 5.1).
Sourcepub fn cryptex(&self) -> Result<bool>
pub fn cryptex(&self) -> Result<bool>
Whether a=cryptex is present at this level (RFC 9335 section 4).
Sourcepub fn groups(&self) -> Result<Vec<Group>>
pub fn groups(&self) -> Result<Vec<Group>>
a=group lines (RFC 5888 section 5), every semantics.
Sourcepub fn bundle_groups(&self) -> Result<Vec<Group>>
pub fn bundle_groups(&self) -> Result<Vec<Group>>
The a=group:BUNDLE lines (RFC 9143 section 5).
Sourcepub fn ice_pacing(&self) -> Result<Option<IcePacing>>
pub fn ice_pacing(&self) -> Result<Option<IcePacing>>
a=ice-pacing (RFC 8839 section 5.5).
Sourcepub fn identity(&self) -> Result<Option<Identity>>
pub fn identity(&self) -> Result<Option<Identity>>
a=identity (RFC 8827 section 5). Only the first one counts.
Sourcepub fn conference_type(&self) -> Result<Option<ConferenceType>>
pub fn conference_type(&self) -> Result<Option<ConferenceType>>
a=type, the conference type (RFC 8866 section 6.9).
Sourcepub fn msid_semantic(&self) -> Result<Option<MsidSemantic>>
pub fn msid_semantic(&self) -> Result<Option<MsidSemantic>>
a=msid-semantic (draft-ietf-mmusic-msid; browsers still write it).
Sourcepub fn marshal(&self) -> String
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.
Sourcepub fn unmarshal<R: BufRead + Seek>(reader: &mut R) -> Result<Self>
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.
Sourcepub fn unmarshal_with_options<R: BufRead + Seek>(
reader: &mut R,
options: &ParseOptions,
) -> Result<Self>
pub fn unmarshal_with_options<R: BufRead + Seek>( reader: &mut R, options: &ParseOptions, ) -> Result<Self>
SessionDescription::unmarshal with the leniencies options names.
Sourcepub fn charset(&self) -> Charset
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.
Sourcepub fn parse_with_options(text: &str, options: &ParseOptions) -> Result<Self>
pub fn parse_with_options(text: &str, options: &ParseOptions) -> Result<Self>
Parses a session description from text, with the leniencies options names.
Sourcepub fn parse_located(
text: &str,
options: &ParseOptions,
) -> Result<Self, SdpParseError>
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
impl Clone for SessionDescription
Source§impl Debug for SessionDescription
impl Debug for SessionDescription
Source§impl Default for SessionDescription
impl Default for SessionDescription
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*.
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*.