SDP的內(nèi)容解析與 實(shí)例分析

前言:

零、背景

實(shí)時(shí)傳輸前,雙方為了建立實(shí)時(shí)數(shù)據(jù)傳輸?shù)耐ǖ溃?(1)交換各自的IP地址和端口號(hào)(通常是UDP,實(shí)時(shí)性更好),(2)交換各自在的數(shù)據(jù)傳輸時(shí)的加解密方式,(3)交換各自在傳輸時(shí)報(bào)文的格式標(biāo)準(zhǔn)。從而保障了數(shù)據(jù)交互。對(duì)應(yīng)的,在sdp格式報(bào)文中,會(huì)把上述內(nèi)容攜帶上,通信雙方可能通過(guò)websocket或者其他的方式進(jìn)行互換sdp。(用websocket很大原因是因?yàn)榫W(wǎng)頁(yè)端需要接入,同時(shí)也方便好用,坑也多)

一、SDP協(xié)議介紹

SDP 完全是一種會(huì)話描述格式 ― 它不屬于傳輸協(xié)議 ― 它只使用不同的適當(dāng)?shù)膫鬏攨f(xié)議,包括會(huì)話通知協(xié)議(SAP)、會(huì)話初始協(xié)議(SIP)、實(shí)時(shí)流協(xié)議(RTSP)、MIME 擴(kuò)展協(xié)議的電子郵件以及超文本傳輸協(xié)議(HTTP)。SDP協(xié)議是也是基于文本的協(xié)議,這樣就能保證協(xié)議的可擴(kuò)展性比較強(qiáng),這樣就使其具有廣泛的應(yīng)用范圍。SDP 不支持會(huì)話內(nèi)容或媒體編碼的協(xié)商,所以在流媒體中只用來(lái)描述媒體信息。媒體協(xié)商這一塊要用RTSP來(lái)實(shí)現(xiàn).

二、SDP協(xié)議格式

SDP描述由許多文本行組成,文本行的格式為<類型>=<值>,<類型>是一個(gè)字母,<值>是結(jié)構(gòu)化的文本串,其格式依<類型>而定。

<type>=<value>[CRLF]


一 :包含幾大部分

1, rtpParams

主要是 video、audio的動(dòng)態(tài)pt范圍, 和每一種codec的preferredPT,用在兩個(gè)端之間協(xié)商統(tǒng)一

2, rtcpParams

主要是rtcp控制報(bào)文(nack,pli,remb,fir等)在兩端的識(shí)別,事先統(tǒng)一好每一種控制報(bào)文的PT

3, dtlsParams

Udp傳輸時(shí),會(huì)在udp的套接字上包裝一層ssl, 會(huì)需要兩端交換對(duì)稱加密方式

4, iceParams

NA

5, icecandidates

核心內(nèi)容,對(duì)端的UDP,ip地址和 端口

6,media-ssrc

在一次會(huì)話中唯一標(biāo)準(zhǔn)一個(gè)媒體流

audio-ssrc?

video-ssrc


二: 各個(gè)部分實(shí)例

rtpParams:

Codecs:

0:?{kind: "audio", mimeType: "audio/opus", clockRate: 48000, channels: 2, preferredPayloadType: 100,…}

1:?{kind: "video", mimeType: "video/VP8", clockRate: 90000,…}

2:?{kind: "video", mimeType: "video/rtx", preferredPayloadType: 102, clockRate: 90000, rtcpFeedback: [],…}

3:?{kind: "video", mimeType: "video/VP9", clockRate: 90000,…}

a=rtpmap:103 ISAC/16000\r\n

a=rtpmap:104 ISAC/32000\r\n

a=rtpmap:9 G722/8000\r\n

a=rtpmap:0 PCMU/8000\r\n

a=rtpmap:8 PCMA/8000\r\n

a=rtpmap:113 telephone-event/16000\r\n

a=rtpmap:126 telephone-event/8000\r\n

m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 122 127 121 125 107 108 109 124 120 123 119 114 115 116\r\n

m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126\r\n

fecMechanisms: 不使用fec 可以不需要

headExtensions:

? ? audio ExtMap

? ? video ExtMap


rtcpParams:

定義 nack,fir pliremb 的pt

preferredPayloadType:?100

rtcpFeedback:?[]

a=sendonly\r\n

a=rtcp-mux\r\n

a=rtcp-rsize\r\n

a=rtpmap:96 VP8/90000\r\n

a=rtcp-fb:96 goog-remb\r\n

a=rtcp-fb:96 transport-cc\r\n

a=rtcp-fb:96 ccm fir\r\n

a=rtcp-fb:96 nack\r\n

a=rtcp-fb:96 nack pli\r\n

a=rtpmap:97 rtx/90000\r\n

a=fmtp:97 apt=96\r\n

a=rtpmap:98 VP9/90000\r\n

a=rtcp-fb:98 goog-remb\r\n

a=rtcp-fb:98 transport-cc\r\n

a=rtcp-fb:98 ccm fir\r\n

a=rtcp-fb:98 nack\r\n

a=rtcp-fb:98 nack pli\r\n



dtlsParams:

fingerprints:?[{algorithm: "sha-1", value: "DB:E8:DB:EB:A6:85:7B:2A:10:10:3B:A0:7E:1E:0C:CA:64:CB:36:95"},…]

role:?"auto"

iceParams

iceLite:?true

password:?"y9fs202dur4fzvm8rek5n1befw5wogzp"

usernameFragment:?"5synhr1w1yjyuudn"

a=ice-ufrag:Ksf1\r\n

a=ice-pwd:GDop22TqcfiuREGVcDlNh8Cv\r\n

a=ice-options:trickle\r\n

a=fingerprint:sha-256 F8:91:E5:A6:77:09:7A:AB:AE:94:87:95:09:53:7D:78:10:20:21:4E:10:78:E6:76:DE:FD:4E:D5:4D:FD:7D:D9\r\n

a=setup:actpass\r\n

iceCandidates

{foundation: "udpcandidate", ip: "172.28.100.38", port: 42795, priority: 1076302079, protocol: "udp",…}


media-ssrc:

m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126\r\n

...

a=ssrc:1913322051 cname:buToKXw9QTcWQHBF\r\n

a=ssrc:1913322051 msid:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3 1faaeb69-cb20-4c41-9a83-5b9316458dd7\r\n

a=ssrc:1913322051 mslabel:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3\r\n

a=ssrc:1913322051 label:1faaeb69-cb20-4c41-9a83-5b9316458dd7\r\n

——————

m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 122 127 121 125 107 108 109 124 120 123 119 114 115 116\r\n

...

a=ssrc-group:FID 4051905094 3634016184\r\n

a=ssrc:4051905094 cname:buToKXw9QTcWQHBF\r\n

a=ssrc:4051905094 msid:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3 d3674fe2-2344-43fe-aa19-832fb0425310\r\n

a=ssrc:4051905094 mslabel:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3\r\n

a=ssrc:4051905094 label:d3674fe2-2344-43fe-aa19-832fb0425310\r\n

a=ssrc:3634016184 cname:buToKXw9QTcWQHBF\r\n

a=ssrc:3634016184 msid:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3 d3674fe2-2344-43fe-aa19-832fb0425310\r\n

a=ssrc:3634016184 mslabel:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3\r\n

a=ssrc:3634016184 label:d3674fe2-2344-43fe-aa19-832fb0425310\r\n


三:順序解讀 SDP

可以參考這個(gè):?https://blog.csdn.net/xyblog/article/details/49741267

給個(gè)例子:offer? 和 answer的 sdp

offer sdp:


———————————————————————————————————>>>>

offer sdp 來(lái)源 :

pc=newRTCPeerConnection

pc.createOffer(this.offerConstraint).then(sdp=>{

let_sdp=JSON.parse(JSON.stringify(sdp));

pc.setLocalDescription(_sdp).then(_=>{

y(_sdp);

}).catch(this.onerror)

}).catch(this.onerror)


v=0\r\n

o=- 2243792401850741077 2 IN IP4 127.0.0.1\r\n

s=-\r\n

t=0 0\r\n

a=group:BUNDLE audio video\r\n

a=msid-semantic: WMS 1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3\r\n

m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126\r\n

c=IN IP4 0.0.0.0\r\n

a=rtcp:9 IN IP4 0.0.0.0\r\n

a=ice-ufrag:Ksf1\r\n

a=ice-pwd:GDop22TqcfiuREGVcDlNh8Cv\r\n

a=ice-options:trickle\r\n

a=fingerprint:sha-256 F8:91:E5:A6:77:09:7A:AB:AE:94:87:95:09:53:7D:78:10:20:21:4E:10:78:E6:76:DE:FD:4E:D5:4D:FD:7D:D9\r\n

a=setup:actpass\r\n

a=mid:audio\r\n

a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\n

a=extmap:2http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\n

a=sendonly\r\n

a=rtcp-mux\r\n

a=rtpmap:111 opus/48000/2\r\n

a=rtcp-fb:111 nack\r\n

a=rtcp-fb:111 transport-cc\r\n

a=fmtp:111 minptime=10;useinbandfec=1\r\n

a=rtpmap:103 ISAC/16000\r\n

a=rtpmap:104 ISAC/32000\r\n

a=rtpmap:9 G722/8000\r\n

a=rtpmap:0 PCMU/8000\r\n

a=rtpmap:8 PCMA/8000\r\n

a=rtpmap:106 CN/32000\r\n

a=rtpmap:105 CN/16000\r\n

a=rtpmap:13 CN/8000\r\n

a=rtpmap:110 telephone-event/48000\r\n

a=rtpmap:112 telephone-event/32000\r\n

a=rtpmap:113 telephone-event/16000\r\n

a=rtpmap:126 telephone-event/8000\r\n

a=ssrc:1913322051 cname:buToKXw9QTcWQHBF\r\n

a=ssrc:1913322051 msid:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3 1faaeb69-cb20-4c41-9a83-5b9316458dd7\r\n

a=ssrc:1913322051 mslabel:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3\r\n

a=ssrc:1913322051 label:1faaeb69-cb20-4c41-9a83-5b9316458dd7\r\n

m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 122 127 121 125 107 108 109 124 120 123 119 114 115 116\r\n

c=IN IP4 0.0.0.0\r\n

a=rtcp:9 IN IP4 0.0.0.0\r\n

a=ice-ufrag:Ksf1\r\n

a=ice-pwd:GDop22TqcfiuREGVcDlNh8Cv\r\n

a=ice-options:trickle\r\n

a=fingerprint:sha-256 F8:91:E5:A6:77:09:7A:AB:AE:94:87:95:09:53:7D:78:10:20:21:4E:10:78:E6:76:DE:FD:4E:D5:4D:FD:7D:D9\r\n

a=setup:actpass\r\n

a=mid:video\r\n

a=extmap:14 urn:ietf:params:rtp-hdrext:toffset\r\n

a=extmap:13http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n

a=extmap:3 urn:3gpp:video-orientation\r\n

a=extmap:2http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\n

a=extmap:5http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\n

a=extmap:6http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\r\n

a=extmap:7http://www.webrtc.org/experiments/rtp-hdrext/video-timing\r\n

a=extmap:8http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07\r\n

a=extmap:9http://www.webrtc.org/experiments/rtp-hdrext/color-space\r\n

a=sendonly\r\n

a=rtcp-mux\r\n

a=rtcp-rsize\r\n

a=rtpmap:96 VP8/90000\r\n

a=rtcp-fb:96 goog-remb\r\n

a=rtcp-fb:96 transport-cc\r\n

a=rtcp-fb:96 ccm fir\r\n

a=rtcp-fb:96 nack\r\n

a=rtcp-fb:96 nack pli\r\n

a=rtpmap:97 rtx/90000\r\n

a=fmtp:97 apt=96\r\n

a=rtpmap:98 VP9/90000\r\n

a=rtcp-fb:98 goog-remb\r\n

a=rtcp-fb:98 transport-cc\r\n

a=rtcp-fb:98 ccm fir\r\n

a=rtcp-fb:98 nack\r\n

a=rtcp-fb:98 nack pli\r\n

a=fmtp:98 profile-id=0\r\n

a=rtpmap:99 rtx/90000\r\n

a=fmtp:99 apt=98\r\n

a=rtpmap:100 VP9/90000\r\n

a=rtcp-fb:100 goog-remb\r\n

a=rtcp-fb:100 transport-cc\r\n

a=rtcp-fb:100 ccm fir\r\n

a=rtcp-fb:100 nack\r\n

a=rtcp-fb:100 nack pli\r\n

a=fmtp:100 profile-id=2\r\n

a=rtpmap:101 rtx/90000\r\n

a=fmtp:101 apt=100\r\n

a=rtpmap:102 H264/90000\r\n

a=rtcp-fb:102 goog-remb\r\n

a=rtcp-fb:102 transport-cc\r\n

a=rtcp-fb:102 ccm fir\r\n

a=rtcp-fb:102 nack\r\n

a=rtcp-fb:102 nack pli\r\n

a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f\r\n

a=rtpmap:122 rtx/90000\r\n

a=fmtp:122 apt=102\r\n

a=rtpmap:127 H264/90000\r\n

a=rtcp-fb:127 goog-remb\r\n

a=rtcp-fb:127 transport-cc\r\n

a=rtcp-fb:127 ccm fir\r\n

a=rtcp-fb:127 nack\r\n

a=rtcp-fb:127 nack pli\r\n

a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f\r\n

a=rtpmap:121 rtx/90000\r\n

a=fmtp:121 apt=127\r\n

a=rtpmap:125 H264/90000\r\n

a=rtcp-fb:125 goog-remb\r\n

a=rtcp-fb:125 transport-cc\r\n

a=rtcp-fb:125 ccm fir\r\n

a=rtcp-fb:125 nack\r\n

a=rtcp-fb:125 nack pli\r\n

a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\n

a=rtpmap:107 rtx/90000\r\n

a=fmtp:107 apt=125\r\n

a=rtpmap:108 H264/90000\r\n

a=rtcp-fb:108 goog-remb\r\n

a=rtcp-fb:108 transport-cc\r\n

a=rtcp-fb:108 ccm fir\r\n

a=rtcp-fb:108 nack\r\n

a=rtcp-fb:108 nack pli\r\n

a=fmtp:108 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f\r\n

a=rtpmap:109 rtx/90000\r\n

a=fmtp:109 apt=108\r\n

a=rtpmap:124 H264/90000\r\n

a=rtcp-fb:124 goog-remb\r\n

a=rtcp-fb:124 transport-cc\r\n

a=rtcp-fb:124 ccm fir\r\n

a=rtcp-fb:124 nack\r\n

a=rtcp-fb:124 nack pli\r\n

a=fmtp:124 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d0032\r\n

a=rtpmap:120 rtx/90000\r\n

a=fmtp:120 apt=124\r\n

a=rtpmap:123 H264/90000\r\n

a=rtcp-fb:123 goog-remb\r\n

a=rtcp-fb:123 transport-cc\r\n

a=rtcp-fb:123 ccm fir\r\n

a=rtcp-fb:123 nack\r\n

a=rtcp-fb:123 nack pli\r\n

a=fmtp:123 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640032\r\n

a=rtpmap:119 rtx/90000\r\n

a=fmtp:119 apt=123\r\n

a=rtpmap:114 red/90000\r\n

a=rtpmap:115 rtx/90000\r\n

a=fmtp:115 apt=114\r\n

a=rtpmap:116 ulpfec/90000\r\n

a=ssrc-group:FID 4051905094 3634016184\r\n

a=ssrc:4051905094 cname:buToKXw9QTcWQHBF\r\n

a=ssrc:4051905094 msid:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3 d3674fe2-2344-43fe-aa19-832fb0425310\r\n

a=ssrc:4051905094 mslabel:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3\r\n

a=ssrc:4051905094 label:d3674fe2-2344-43fe-aa19-832fb0425310\r\n

a=ssrc:3634016184 cname:buToKXw9QTcWQHBF\r\n

a=ssrc:3634016184 msid:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3 d3674fe2-2344-43fe-aa19-832fb0425310\r\n

a=ssrc:3634016184 mslabel:1jMfa2Vph7cdloTWnLDiIBh7MVKIesEwpOC3\r\n

a=ssrc:3634016184 label:d3674fe2-2344-43fe-aa19-832fb0425310\r\n


answer sdp


v=0\r\n

o=- 0 0 IN IP4 127.0.0.1\r\n

s=MY-PROTOL\r\n

t=0 0\r\n

a=msid-semantic: WMS *\r\n

a=group:BUNDLE audio video\r\n

m=audio 9 UDP/TLS/RTP/SAVPF 111\r\n

c=IN IP4 0.0.0.0\r\n

a=rtpmap:111 opus/48000/2\r\n

a=fmtp:111 minptime=10;useinbandfec=1\r\n

a=rtcp:1 IN IP4 0.0.0.0\r\n

a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\n

a=setup:active\r\n

a=mid:audio\r\n

a=recvonly\r\n

a=ice-ufrag:qctxy\r\n

a=ice-pwd:a123456789b123456789cd\r\n

a=fingerprint:sha-256 A5:5F:18:86:E7:32:5E:11:44:A7:B4:11:E1:18:6C:EE:8B:F6:6D:D6:CA:C7:D2:DF:AC:29:FC:95:09:71:AA:3C\r\n

a=candidate:xxxxxx 1 udp xxxxx x 44572 typ host generation 0\r\n

a=end-of-candidates\r\n

a=rtcp-mux\r\n

m=video 9 UDP/TLS/RTP/SAVPF 101\r\n

c=IN IP4 0.0.0.0\r\n

a=rtpmap:101 H264/90000\r\n

a=fmtp:101 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\n

a=rtcp:1 IN IP4 0.0.0.0\r\n

a=rtcp-fb:101 ccm fir\r\n

a=rtcp-fb:101 nack\r\n

a=rtcp-fb:101 nack pli\r\n

a=rtcp-fb:101 goog-remb\r\n

a=extmap:3 urn:3gpp:video-orientation\r\n

a=extmap:5http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\n

a=extmap:13http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n

a=extmap:14 urn:ietf:params:rtp-hdrext:toffset\r\n

a=setup:active\r\n

a=mid:video\r\n

a=recvonly\r\n

a=ice-ufrag:qctxy\r\n

a=ice-pwd:a123456789b123456789cd\r\n

a=fingerprint:sha-256 A5:5F:18:86:E7:32:5E:11:44:A7:B4:11:E1:18:6C:EE:8B:F6:6D:D6:CA:C7:D2:DF:AC:29:FC:95:09:71:AA:3C\r\n

a=candidate:xxxxxxx 1 udp xxxxxxx x 44572 typ host generation 0\r\n

a=end-of-candidates\r\n

a=rtcp-mux\r\n

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容