Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 36 ยท Concepts and Signalling

SDP Explained

Learn to read WebRTC SDP line by line: session and media sections, codecs and payload types, ICE credentials, DTLS fingerprints, directions, and when to edit SDP.

Every offer and answer carries a block of text called SDP, the Session Description Protocol. It is old (it comes from the 1990s) and not pretty, but you will read it constantly when debugging: it shows exactly which codecs were negotiated, whether ICE credentials are present, and why a call has no video. This lesson teaches you to read it without fear.

SDP is only a description. It does not move any media; it tells the other side what to expect. Think of it as a form each peer fills in: "I want to send one video and one audio stream, here are the codecs I speak, here is my secret handshake fingerprint, here is how to authenticate ICE checks."

The shape of an SDP

An SDP is a list of lines, each type=value, separated by CRLF. It has a session section at the top and one media section per m= line.

TEXT
v=0
o=- 4611731400430051336 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE 0 1
a=msid-semantic: WMS
m=audio 9 UDP/TLS/RTP/SAVPF 111
c=IN IP4 0.0.0.0
a=ice-ufrag:3cWE
a=ice-pwd:VMrjNhaf2a6SIwGJZfuhnTAb
a=fingerprint:sha-256 AB:CD:...
a=setup:actpass
a=mid:0
a=sendrecv
a=rtpmap:111 opus/48000/2
m=video 9 UDP/TLS/RTP/SAVPF 96 97
...

The important line types:

Line Meaning
v=0 Version (always 0)
o= Origin: session id and version number (changes with each renegotiation)
s=-, t=0 0 Session name and time (unused in WebRTC)
a=group:BUNDLE 0 1 Send these media sections over one transport
m= A media section: kind (audio, video, application), port, protocol, payload types
c= Connection address (WebRTC uses 0.0.0.0; real addresses come from ICE)
a=mid Media section identifier, used to match sections between offer and answer
a=ice-ufrag / a=ice-pwd Credentials used to authenticate ICE connectivity checks
a=fingerprint Hash of the DTLS certificate; lets each peer verify the handshake
a=setup DTLS role: actpass (offer), active or passive (answer)
a=sendrecv etc. Direction
a=rtpmap Maps a payload type number to a codec, clock rate and channels
a=fmtp Codec parameters
a=rtcp-fb RTCP feedback mechanisms (NACK, PLI, transport-cc)
a=candidate An ICE candidate (when included)

Look at a real one

The next example creates an offer with one audio and one video transceiver and a data channel, prints a summary of each section and shows the raw SDP for you to explore.

Summarise a real SDP

You will see three sections (audio, video, application) in one BUNDLE group, a fingerprint and ICE credentials in each, and the DTLS role actpass because an offer lets the answerer choose who starts the handshake.

Payload types and codecs

Inside an audio or video section, the numbers after the protocol on the m= line are payload types: small integers that appear in each RTP packet header. The a=rtpmap lines say what each number means:

TEXT
a=rtpmap:111 opus/48000/2
a=rtpmap:96 VP8/90000
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96

Payload type numbers above 95 are dynamic: they are assigned per session, so 96 may be VP8 in one SDP and H.264 in another. Never hard-code them. rtx is a retransmission stream: apt=96 says "this carries retransmissions of payload type 96". The order of payload types on the m= line is the preference order, which is how setCodecPreferences works (see transceivers and senders).

Reading ICE and DTLS lines

  • a=ice-ufrag and a=ice-pwd are one-time credentials. Each peer puts them in its description; the other peer uses them in STUN connectivity checks. A changed ufrag means an ICE restart.
  • a=fingerprint:sha-256 ... is the hash of the peer's self-signed certificate. After the DTLS handshake each side checks that the certificate matches the fingerprint received through signalling. That is why you must protect your signalling channel: an attacker who can alter the SDP can substitute their own fingerprint (more in the security chapter).

Should you edit SDP?

Years ago, apps "munged" SDP with string replacement to force a codec or a bitrate. Today there are real APIs for the common cases:

Goal Use this instead of editing SDP
Prefer a codec transceiver.setCodecPreferences()
Limit bitrate sender.setParameters() with maxBitrate
Pause sending sender.replaceTrack(null) or track.enabled = false
Change direction transceiver.direction = 'recvonly'

Munging is fragile: browsers can reject invalid SDP, and each browser's output differs. Leave it as a last resort. Always treat SDP as an opaque string when sending it through signalling; just send pc.localDescription.

Debugging with SDP

When "there is no video", open the SDP and check:

  1. Is there an m=video line, and is its port non-zero? Port 0 means the section is rejected or stopped.
  2. Is the direction what you expect (sendrecv or recvonly, not inactive)?
  3. Do the offer and answer share at least one codec in that section?
  4. Do both descriptions carry a=ice-ufrag and a=fingerprint?
Detect a rejected media section

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does an m= line in an SDP describe?

    Each m= line starts a media section. The session section above it holds shared attributes.
  2. 2. Why must you not hard-code payload type numbers like 96?

    Numbers from 96 up are dynamic. Always map them using a=rtpmap lines.
  3. 3. What is a=fingerprint used for?

    After the DTLS handshake each side compares the certificate hash with the fingerprint from signalling, which protects against interception.
  4. 4. How do you limit the video bitrate today, without editing SDP?

    RTCRtpSender.setParameters() lets you set encoding limits like maxBitrate.

Summary

  • SDP is a text description of media sections, codecs, ICE credentials and DTLS fingerprints; it carries no media.
  • Read it by section: m= lines, then a=mid, direction, rtpmap, ice-ufrag and fingerprint.
  • A port of 0 on an m= line means the section was rejected.
  • Prefer APIs (setCodecPreferences, setParameters) over editing SDP strings, and always send pc.localDescription unchanged through signalling.

Next: Signalling Channels