1. Home
  2. SIP Over WebRTC
  3. What is SDP (Session Description Protocol)?

What is SDP (Session Description Protocol)?

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:

  1. Session Parameters: Details about the multimedia session, like session name, start and end time, and unique session identifiers.
  2. Media Description: Specifications of the media (e.g., audio, video, text), including the codecs and formats supported, bandwidth information, and the number of channels.
  3. 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:

FieldSymbolDescription
Versionv=SDP version (always “0” in current specifications)
Origino=Session initiator’s details, including username, session ID, and network address
Session Names=Name of the session
Session Informationi=Optional field describing the purpose of the session
URIu=URL pointing to more details about the session
Email Addresse=Contact information for the session owner
Phone Numberp=Contact phone number
Connection Informationc=Network details, such as IP address and type of network
Timingt=Start and end times for the session
Media Descriptionm=Media type, port number, protocol, and format
Bandwidthb=Bandwidth required or preferred for the session
Attributesa=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

  1. v=0: Indicates SDP version 0.
  2. 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 to 192.0.2.1.
  3. s=Example SDP Session: Names the session.
  4. c=IN IP4 192.0.2.1: Specifies the connection information for the session, setting IP to 192.0.2.1.
  5. t=0 0: The timing of the session is set to 0 0, meaning it is unlimited and always available.
  6. m=audio 49170 RTP/AVP 0: Describes an audio media session, using port 49170 with RTP (Real-Time Transport Protocol) and AVP (Audio/Video Profile), using payload type 0 (PCMU codec).
  7. a=rtpmap:0 PCMU/8000: An attribute that maps RTP payload type 0 to PCMU codec operating at 8000 Hz.
  8. m=video 51372 RTP/AVP 31: Describes a video media session, using port 51372, RTP/AVP profile, and payload type 31 (H.261 codec).
  9. a=rtpmap:31 H261/90000: Maps payload type 31 to H261 codec operating at 90000 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

  1. a=group:BUNDLE audio video: The BUNDLE attribute groups multiple media tracks (e.g., audio and video) into a single transport.
  2. a=ice-ufrag and a=ice-pwd: ICE (Interactive Connectivity Establishment) credentials used for NAT traversal.
  3. a=fingerprint: SHA-256 hash for secure session establishment (DTLS fingerprint).
  4. a=setup:actpass: Defines the role of each peer in establishing the secure DTLS connection.
  5. a=rtpmap and a=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.

Related Articles