Skip to main content

Crate sdp_types

Crate sdp_types 

Source
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 charset attribute 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.

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_types structs
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.
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.
TimeZone
Time zone information for the session.

Enums§

ParserError
Parsing errors that can be returned from Session::parse.