Expand description
Crate for handling SDP (RFC 8866) session descriptions, including a parser and serializer.
§Serializing an SDP
// Create SDP session description
let sdp = sdp_types::Session {
...
};
// or
let sdp = sdp_types::Session::new(sdp_types::Origin::new(...), "my-session");
// or
let sdp = sdp_types::Session::builder(sdp_types::Origin::new(...), "my-session")
.attribute(...)
.attribute(...)
.media(...)
.media(...)
...
.build();
// And write it to an `Vec<u8>`
let mut output = Vec::new();
sdp.write(&mut output).unwrap();§Parsing an SDP
// Parse SDP session description from a byte slice
let sdp = sdp_types::Session::parse(&data).unwrap();
// Access the 'tool' attribute
match sdp.get_first_attribute_value("tool") {
Some(Some(tool)) => println!("tool: {tool}"),
Some(None) => println!("tool: empty"),
None => println!("no tool attribute"),
}
// Access all the 'rtpmap' attributes as an `RtpMap` type
// returns an iterator of type `Iterator<Item = Result<RtpMap, AttributeError>>`
let r = sdp.attributes_typed::<sdp_types::RtpMap>();
// Access the first 'rtpmap' attribute as an `RtpMap` type:
match sdp.get_first_attribute_typed::<sdp_types::RtpMap>() {
Some(Ok(rtpmap)) => println!("rtpmap: {rtpmap}"),
Some(Err(err)) => println!("rtpmap: parsing error: {err}"),
None => println!("no rtpmap attribute"),
}§Limitations
-
SDP session descriptions are by default in UTF-8 but an optional
charsetattribute can change this for various SDP fields, including various other attributes. This is currently not supported, only UTF-8 is supported. -
Network addresses, Phone numbers, E-Mail addresses and various other fields are currently parsed as a plain string and not according to the SDP grammar.
§Validation
The parser checks the structure of a session description (line keys, field
counts, and the syntax of numeric and enum fields) but does not enforce
all semantic constraints of the RFCs. Likewise the data model accepts
values that the RFC grammars would not allow, e.g. Origin::sess_id must
be a numeric string but this is not checked. Lines containing NUL or CR
bytes are rejected, and the “nettype”/“addrtype” subfields of “o=” and
“c=” must be RFC 8866 tokens; other non-conforming model values are still
written verbatim.
Session::write() writes the data model out as-is without validating it,
apart from stripping characters that would break the line structure (CR,
LF, NUL) and writing a t=0 0 line if the session description contains no
time description at all.
Applications that need stricter conformance must validate session descriptions themselves.
Re-exports§
pub use attributes::*;pub use clock_signalling::*;pub use enums::*;
Modules§
- attributes
- Contains all the Session description Attributes defined as Structs/Enums
- builders
- Builders for the
sdp_typesstructs - clock_
signalling - enums
- Contains all the helper enums used by a Session, Media and other Attribute structs
Structs§
- Attribute
- Attributes for the session or media.
- Bandwidth
- Bandwidth information for the session or media.
- Connection
- Connection data for the session or media.
- Connection
Address - A parsed SDP connection address (RFC 8866
Section 5.7), see
Connection::try_address. - Key
- Encryption key for the session or media.
- Media
- Media description.
- Origin
- Originator of the session.
- Repeat
- Repeat times for timing information.
- Session
- SDP session description.
- Time
- Timing information of the session.
- Time
Zone - Time zone information for the session.
Enums§
- Connection
Address Error - Errors of
Connection::try_address. - Parser
Error - Parsing errors that can be returned from
Session::parse.