If you end up here. You probably work on WebRTC project and already know what SDP is for. But not to the extent that you can speak in its own tongue. Just like, you know what the cookie is and you know how to eat it. But you don’t know how to cook it. In this short note, I’ll try to share what I know about SDP that should be enough for manipulating the media’s codec selections.


First of, a brief understanding of SDP; it is a format to let you and other party (peer) know what you have to offer. Just like a waitress approach you with a menu. Basically SDP is the menu itself. It tells you what could you have. Now in the slightly different fashion. You will offer the SDP back which is actually the answer. In such answer you are allowed to only pick whatever on the menus.

So where are these menu listed? Let’s examine our SDP message. Here is the SDP message offered by iPhone6, iOS12.2.

v=0
o=- 3475033399956577407 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio video
a=msid-semantic: WMS 0e86aef1-29be-4240-996b-a6a7f5849643
m=audio 9 UDP/TLS/RTP/SAVPF 111 103 9 102 0 8 105 13 110 113 126
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:qZJE
a=ice-pwd:42JRGRi6ZTw0691hSnLngg+B
a=ice-options:trickle
a=fingerprint:sha-256 B8:07:E9:06:5D:08:E2:4D:08:24:AE:DB:68:D9:55:17:22:92:9A:22:3D:BF:9B:B8:3C:9C:D6:15:AB:5C:C6:48
a=setup:actpass
a=mid:audio
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=sendrecv
a=rtcp-mux
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:103 ISAC/16000
a=rtpmap:9 G722/8000
a=rtpmap:102 ILBC/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000
a=ssrc:2657301721 cname:Xi8v8cBxp5fMj+8M
a=ssrc:2657301721 msid:0e86aef1-29be-4240-996b-a6a7f5849643 a873839c-5448-4119-b78d-9c527a676c2e
a=ssrc:2657301721 mslabel:0e86aef1-29be-4240-996b-a6a7f5849643
a=ssrc:2657301721 label:a873839c-5448-4119-b78d-9c527a676c2e
m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 127 125 104
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:qZJE
a=ice-pwd:42JRGRi6ZTw0691hSnLngg+B
a=ice-options:trickle
a=fingerprint:sha-256 B8:07:E9:06:5D:08:E2:4D:08:24:AE:DB:68:D9:55:17:22:92:9A:22:3D:BF:9B:B8:3C:9C:D6:15:AB:5C:C6:48
a=setup:actpass
a=mid:video
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:3gpp:video-orientation
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
a=extmap:10 http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07
a=sendrecv
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:96 H264/90000
a=rtcp-fb:96 goog-remb
a=rtcp-fb:96 transport-cc
a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack
a=rtcp-fb:96 nack pli
a=fmtp:96 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640c1f
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtpmap:98 H264/90000
a=rtcp-fb:98 goog-remb
a=rtcp-fb:98 transport-cc
a=rtcp-fb:98 ccm fir
a=rtcp-fb:98 nack
a=rtcp-fb:98 nack pli
a=fmtp:98 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtpmap:100 VP8/90000
a=rtcp-fb:100 goog-remb
a=rtcp-fb:100 transport-cc
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack
a=rtcp-fb:100 nack pli
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtpmap:127 red/90000
a=rtpmap:125 rtx/90000
a=fmtp:125 apt=127
a=rtpmap:104 ulpfec/90000
a=ssrc-group:FID 4018158872 2768135717
a=ssrc:4018158872 cname:Xi8v8cBxp5fMj+8M
a=ssrc:4018158872 msid:0e86aef1-29be-4240-996b-a6a7f5849643 d8484815-86d5-4ca0-97bb-2bda55895eb9
a=ssrc:4018158872 mslabel:0e86aef1-29be-4240-996b-a6a7f5849643
a=ssrc:4018158872 label:d8484815-86d5-4ca0-97bb-2bda55895eb9
a=ssrc:2768135717 cname:Xi8v8cBxp5fMj+8M
a=ssrc:2768135717 msid:0e86aef1-29be-4240-996b-a6a7f5849643 d8484815-86d5-4ca0-97bb-2bda55895eb9
a=ssrc:2768135717 mslabel:0e86aef1-29be-4240-996b-a6a7f5849643
a=ssrc:2768135717 label:d8484815-86d5-4ca0-97bb-2bda55895eb9
In this SDP message, regarding the codec. What you should pay attention is this.

m=audio 9 UDP/TLS/RTP/SAVPF 111 103 9 102 0 8 105 13 110 113 126

This message is actually saying that. Here is the selection of your audio You can choose either

111 103 9 102 0 8 105 13 110 113 126

These numbers are actually the IDs of the codec information of the upcoming section as described below. See the leading numeric value after : . This is more like a description of the codec you can use.


a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:103 ISAC/16000
a=rtpmap:9 G722/8000
a=rtpmap:102 ILBC/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000

Basically when you create answer you will just pick the ID from the list and filter out the rest in these a= nodes.
So here is a basic picture.

...whatever...
m=audio 9 UDP/TLS/RTP/SAVPF 111 103 9 102 0 8 105 13 110 113 126
...describe my audio codecs...
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:103 ISAC/16000
a=rtpmap:9 G722/8000
a=rtpmap:102 ILBC/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000

So, let say if you wish to allow only OPUS audio codec you should modify it to read…


...whatever...
m=audio 9 UDP/TLS/RTP/SAVPF 111
...describe my audio codecs...
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1


Same goes as Video.
This is actually the process call SDP Munging. Which is manipulating the SDP before it get offered. So that when other peer consume the SDP the choices that they can answer will be limited. (So that the codec is enforced).
If you wish to be the expert in this; please continue reading this awesome RFC4566 that I read and fall into sleep.