Skip to main content

rtc_sdp/
lib.rs

1#![warn(rust_2018_idioms)]
2#![warn(missing_docs)]
3#![allow(dead_code)]
4
5//! SDP parsing and serialization.
6//!
7//! The Session Description Protocol ([RFC 8866], superseding [RFC 4566]) as WebRTC uses
8//! it: offers and answers, media sections, and the attributes that carry codecs, ICE
9//! candidates, DTLS fingerprints and header-extension mappings ([RFC 8285]).
10//!
11//! # Structure
12//!
13//! * [`SessionDescription`] — a whole session description: `unmarshal` one from a string,
14//!   `marshal` it back, or build one up section by section.
15//! * [`MediaDescription`] — one `m=` section, with its attributes, formats and connection
16//!   data.
17//! * [`extmap`] — `a=extmap` header-extension declarations and the well-known extension
18//!   URIs.
19//! * [`direction`] — `sendrecv`/`sendonly`/`recvonly`/`inactive`.
20//!
21//! # Example
22//!
23//! ```
24//! use rtc_sdp::SessionDescription;
25//! use std::io::Cursor;
26//!
27//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
28//! let sdp = "v=0\r\n\
29//!            o=- 0 0 IN IP4 127.0.0.1\r\n\
30//!            s=-\r\n\
31//!            t=0 0\r\n\
32//!            m=audio 9 UDP/TLS/RTP/SAVPF 111\r\n\
33//!            a=mid:0\r\n\
34//!            a=sendrecv\r\n";
35//!
36//! let desc = SessionDescription::unmarshal(&mut Cursor::new(sdp))?;
37//! for media in &desc.media_descriptions {
38//!     assert_eq!(media.media_name.media, "audio");
39//!     assert_eq!(media.attribute("mid").flatten(), Some("0"));
40//! }
41//!
42//! // Printing it back yields valid SDP.
43//! assert!(desc.marshal().starts_with("v=0"));
44//! # Ok(())
45//! # }
46//! ```
47//!
48//! This crate is deliberately a *syntax* layer: it parses and prints SDP faithfully and
49//! leaves negotiation semantics ([RFC 8829]) to the [`rtc`](https://docs.rs/rtc) crate,
50//! which re-exports it as `rtc::sdp`.
51//!
52//! [RFC 8866]: https://datatracker.ietf.org/doc/html/rfc8866
53//! [RFC 4566]: https://datatracker.ietf.org/doc/html/rfc4566
54//! [RFC 8285]: https://datatracker.ietf.org/doc/html/rfc8285
55//! [RFC 8829]: https://datatracker.ietf.org/doc/html/rfc8829
56
57/// Session and media descriptions — the `v=`/`m=` structure of an SDP document.
58pub mod description;
59/// Transmission direction (`sendrecv`, `sendonly`, `recvonly`, `inactive`).
60pub mod direction;
61/// `a=extmap` RTP header-extension declarations and the well-known extension URIs.
62pub mod extmap;
63/// Parsing helpers plus the codec and connection-role types shared across descriptions.
64pub mod util;
65
66pub(crate) mod lexer;
67
68pub use description::{media::MediaDescription, session::SessionDescription};