Introduction
When two people communicate over a video or voice call using WebRTC, they need to exchange details about how the connection should work. This is where Session Description Protocol (SDP) comes into play. SDP is a format used to describe multimedia sessions, helping peers agree on audio/video formats, codecs, network information, and other communication parameters.
In this blog, weβll break down SDP, how it works in WebRTC, and why it’s essential for real-time communication.
What is SDP?
SDP is a text-based format that provides all the necessary information for establishing a multimedia connection. It does not handle media transport or guarantee real-time delivery. Instead, it acts as a negotiation tool that defines:
- The type of media (audio, video, text)
- The codec formats supported
- The network details (IP address, ports, transport protocol)
- Encryption and bandwidth constraints
Essentially, SDP helps two WebRTC peers figure out how to talk to each other before they start sending actual media data.
How SDP Works in WebRTC
WebRTC uses SDP during the signaling process, which allows two browsers or devices to negotiate and establish a connection.
1. SDP Offer and Answer Model
WebRTC uses a process called Offer/Answer to exchange SDP messages:
- Caller (John) generates an SDP offer
- His browser creates an SDP offer containing audio/video capabilities and network information.
- This offer is sent to a signaling server, which relays it to the callee.
- Callee (Kate) receives the offer and sends an SDP answer
- Her browser checks the offer and decides which codecs and settings to accept.
- It generates an SDP answer and sends it back to John.
- Both parties agree on the settings, and media streaming begins π₯π€
Example of an SDP Offer
Letβs take a look at a simplified SDP message:
v=0
o=- 4611731358842697648 2 IN IP4 192.168.1.5
s=WebRTC Call
c=IN IP4 192.168.1.5
t=0 0
m=audio 49170 RTP/AVP 0 8 96
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:96 OPUS/48000
m=video 51372 RTP/AVP 100
a=rtpmap:100 VP8/90000
Breaking It Down
m=audio 49170 RTP/AVP 0 8 96
β Supports audio with PCMU, PCMA, and OPUS codecs.m=video 51372 RTP/AVP 100
β Supports video with the VP8 codec.c=IN IP4 192.168.1.5
β Media will be sent to 192.168.1.5 on the given ports.
This SDP message tells the other peer:
π βI can send/receive video using VP8 and audio using PCMU, PCMA, or OPUS.β
Why is SDP Important?
πΉ Codec Negotiation β Ensures both peers can use a common audio/video format.
πΉ Network Details β Helps peers exchange IP addresses and ports for communication.
πΉ Security and Encryption β Defines encryption settings for a secure connection.
πΉ Bandwidth Control β Helps optimize media quality based on network conditions.
Conclusion
SDP is a crucial component of WebRTC, enabling peers to exchange the necessary details for a successful call. Though it doesn’t transmit media itself, it lays the foundation for a seamless connection by negotiating codecs, network settings, and encryption.
Understanding SDP can help developers debug WebRTC issues, customize media settings, and build better real-time applications.
π