SDP的内容解析与 实例分析
发布网友
发布时间:2022-09-25 18:49
我来回答
共1个回答
热心网友
时间:2023-09-20 09:39
零、背景
实时传输前,双方为了建立实时数据传输的通道, (1)交换各自的IP地址和端口号(通常是UDP,实时性更好),(2)交换各自在的数据传输时的加解密方式,(3)交换各自在传输时报文的格式标准。从而保障了数据交互。对应的,在sdp格式报文中,会把上述内容携带上,通信双方可能通过websocket或者其他的方式进行互换sdp。(用websocket很大原因是因为网页端需要接入,同时也方便好用,坑也多)
一、SDP协议介绍
SDP 完全是一种会话描述格式 ― 它不属于传输协议 ― 它只使用不同的适当的传输协议,包括会话通知协议(SAP)、会话初始协议(SIP)、 实时流协议(RTSP)、 MIME 扩展协议的电子邮件以及超文本传输协议(HTTP)。SDP协议是也是基于文本的协议,这样就能保证协议的可扩展性比较强,这样就使其具有广泛的应用范围。SDP 不支持会话内容或媒体编码的协商,所以在流媒体中只用来描述媒体信息。媒体协商这一块要用 RTSP 来实现.
二、SDP协议格式
SDP描述由许多文本行组成,文本行的格式为<类型>=<值>,<类型>是一个字母,<值>是结构化的文本串,其格式依<类型>而定。
<type>=<value>[CRLF]
主要是 video、audio的动态pt范围, 和每一种codec的preferredPT,用在两个端之间协商统一
主要是rtcp控制报文(nack,pli,remb,fir等)在两端的识别,事先统一好每一种控制报文的PT
Udp传输时,会在udp的套接字上包装一层ssl, 会需要两端交换对称加密方式
NA
核心内容,对端的UDP,ip地址和 端口
在一次会话中唯一标准一个媒体流
audio-ssrc
video-ssrc
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
定义 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
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"
iceLite: true
password: "y9fs202r4fzvm8rek5n1befw5wogzp"
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
{foundation: "udpcandidate", ip: "172.28.100.38", port: 42795, priority: 1076302079, protocol: "udp",…}
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
可以参考这个: https://blog.csdn.net/xyblog/article/details/49741267
给个例子:offer 和 answer的 sdp
offer sdp:
———————————————————————————————————>>>>
offer sdp 来源 :
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:2 http://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:13 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n
a=extmap:3 urn:3gpp:video-orientation\r\n
a=extmap:2 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\n
a=extmap:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\n
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\r\n
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing\r\n
a=extmap:8 http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07\r\n
a=extmap:9 http://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:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\n
a=extmap:13 http://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