SDP, or Session Description Protocol, is a format used primarily in multimedia communications and applications to describe the details of media sessions. These sessions often involve real-time protocols like SIP (Session Initiation Protocol) and WebRTC (Web Real-Time Communication). SDP itself is not a transport protocol; rather, it provides a structured way to describe multimedia data such as audio, video, and application-specific media, facilitating compatibility between communicating devices.
Purpose of SDP
SDP is mainly designed to communicate:
- Session Parameters: Details about the multimedia session, like session name, start and end time, and unique session identifiers.
- Media Description: Specifications of the media (e.g., audio, video, text), including the codecs and formats supported, bandwidth information, and the number of channels.
- Connection Information: Network details, such as the IP address and port numbers, which are used to set up a connection between endpoints.
Core Structure of an SDP Message
An SDP message is structured in key-value format, with each line beginning with a single character denoting the type of information, followed by an =
sign and then the relevant data. Here’s a breakdown of some of the essential fields:
Field | Symbol | Description |
---|---|---|
Version | v= | SDP version (always “0” in current specifications) |
Origin | o= | Session initiator’s details, including username, session ID, and network address |
Session Name | s= | Name of the session |
Session Information | i= | Optional field describing the purpose of the session |
URI | u= | URL pointing to more details about the session |
Email Address | e= | Contact information for the session owner |
Phone Number | p= | Contact phone number |
Connection Information | c= | Network details, such as IP address and type of network |
Timing | t= | Start and end times for the session |
Media Description | m= | Media type, port number, protocol, and format |
Bandwidth | b= | Bandwidth required or preferred for the session |
Attributes | a= | Session or media-level attributes like codecs, encryption, and other session properties |
Basic SDP Example
Let’s start with a simple example of an SDP message describing a multimedia session:
v=0
o=- 1234567890 1234567890 IN IP4 192.0.2.1
s=Example SDP Session
c=IN IP4 192.0.2.1
t=0 0
m=audio 49170 RTP/AVP 0
a=rtpmap:0 PCMU/8000
m=video 51372 RTP/AVP 31
a=rtpmap:31 H261/90000
Explanation of Fields
v=0
: Indicates SDP version 0.o=- 1234567890 1234567890 IN IP4 192.0.2.1
: Defines the origin of the session. The session ID and session version are set to the same value for simplicity, and the IP address is set to192.0.2.1
.s=Example SDP Session
: Names the session.c=IN IP4 192.0.2.1
: Specifies the connection information for the session, setting IP to192.0.2.1
.t=0 0
: The timing of the session is set to0 0
, meaning it is unlimited and always available.m=audio 49170 RTP/AVP 0
: Describes an audio media session, using port49170
with RTP (Real-Time Transport Protocol) and AVP (Audio/Video Profile), using payload type0
(PCMU codec).a=rtpmap:0 PCMU/8000
: An attribute that maps RTP payload type0
toPCMU
codec operating at8000
Hz.m=video 51372 RTP/AVP 31
: Describes a video media session, using port51372
, RTP/AVP profile, and payload type31
(H.261 codec).a=rtpmap:31 H261/90000
: Maps payload type31
toH261
codec operating at90000
Hz.
SDP in WebRTC
In WebRTC (Web Real-Time Communication), SDP plays a crucial role in peer-to-peer connections, helping devices to negotiate and establish compatible media types and formats. Typically, SDP data is exchanged between peers during the “offer/answer” process.
- Offer: The initiating peer creates an SDP message containing the details of the media it wishes to send and receive.
- Answer: The receiving peer returns an SDP message indicating compatible parameters and codecs.
Here’s a simple WebRTC SDP example, highlighting key WebRTC-specific attributes:
v=0
o=- 4962647797900726170 2 IN IP4 127.0.0.1
s=WebRTC Session
t=0 0
a=group:BUNDLE audio video
a=msid-semantic: WMS ARDAMS
m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:f7g6
a=ice-pwd:asd88fgpdd777uzjYhagZg
a=fingerprint:sha-256 4A:61:21:C0:A5:95:E1:A5:BA:53:56:36:12:7C:84:BB:67:9D:49:50:4C:27:32:1E:19:DA:A2:22:32:BD:5E:3A
a=setup:actpass
a=mid:audio
a=sendrecv
a=rtpmap:111 opus/48000/2
a=rtcp-mux
m=video 9 UDP/TLS/RTP/SAVPF 96
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:f7g6
a=ice-pwd:asd88fgpdd777uzjYhagZg
a=fingerprint:sha-256 4A:61:21:C0:A5:95:E1:A5:BA:53:56:36:12:7C:84:BB:67:9D:49:50:4C:27:32:1E:19:DA:A2:22:32:BD:5E:3A
a=setup:actpass
a=mid:video
a=sendrecv
a=rtpmap:96 VP8/90000
a=rtcp-mux
Key WebRTC-Specific Fields
a=group:BUNDLE audio video
: The BUNDLE attribute groups multiple media tracks (e.g., audio and video) into a single transport.a=ice-ufrag
anda=ice-pwd
: ICE (Interactive Connectivity Establishment) credentials used for NAT traversal.a=fingerprint
: SHA-256 hash for secure session establishment (DTLS fingerprint).a=setup:actpass
: Defines the role of each peer in establishing the secure DTLS connection.a=rtpmap
anda=rtcp-mux
: Defines RTP mappings and RTP multiplexing to streamline audio and video transport over a single connection.
SDP Code Sample for WebRTC in JavaScript
Here’s how an SDP offer can be created using WebRTC in JavaScript:
const pc = new RTCPeerConnection();
async function createOffer() {
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
console.log("SDP Offer:", offer.sdp);
}
// Add event listener for handling the generated SDP
pc.onicecandidate = (event) => {
if (event.candidate) {
console.log("ICE Candidate:", event.candidate.candidate);
}
};
// Trigger the function
createOffer();
Conclusion
SDP is a foundational protocol for multimedia communication, particularly in real-time systems like WebRTC. It provides a standardized way to describe multimedia content, network details, and session properties, ensuring that communicating devices can understand each other’s capabilities and requirements.