SDP全稱是Session Description Protocol,即會話描述協議,用於會話各方間的媒體協商。html
<type>=<value>
。看一下SDP具體是怎樣的,複製如下代碼到控制檯 Enter
~web
const PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; const peer = new PeerConnection(); navigator.mediaDevices.getUserMedia({ video: true, audio: true }) .then(stream => { stream.getTracks().forEach(track => { peer.addTrack(track, stream); }); peer.createOffer().then(e => { console.log(e.sdp); }) }) .catch(e => alert('沒法獲取攝像頭信息'));
v=0
SDP的版本(Protocol version number)。當前規範版本爲0安全
o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
會話全部者有關的參數(Owner/creator and session identifier)。網絡
s=<session name>
本次會話的標題或會話的名稱(Session name)。session
t=<start-time> <stop-time>
會話的起始時間和結束時間(Time session starts and stops)。tcp
m=<media> <port>/<number of ports> <proto> <fmt> ...
媒體行,描述了發送方所支持的媒體類型等信息(Media information)。ide
<proto> 流傳輸協議。舉例說明:編碼
最後的 SAVPF 還有其餘幾種值:AVP, SAVP, AVPF, SAVPF。加密
c=<nettype> <addrtype> <connection-address>
媒體的鏈接信息(Connection information)。每一個媒體描述中至少包含一個 c =
字段,或者在會話描述中包含一個 c =
字段。.net
a=<attribute> | <attribute>:<value>
屬性(attribute)是擴展SDP的主要手段,分爲會話級
屬性和媒體級
屬性:
會話級屬性:添加在第一個媒體描述以前,傳達的信息適用於整個會議而不是單個媒體。
a=group:BUNDLE audio video
經過mid標識符把多個媒體屬性鏈接起來;a=msid-semantic: WMS ma
表示是webrtc媒體流(Webrtc Media Streams);媒體級屬性:媒體描述中添加有關媒體流的信息。
a=mid:audio
上述BUNDLE中用到的媒體標識;a=msid:ma ta
鏈接不一樣的媒體描述,使用相同的MediaStreams;a=sendonly
表示媒體發送端,其餘類型:recvonly,sendrecv,inactive;a=rtcp:9 IN IP4 0.0.0.0
用來傳輸rtcp地地址和端口;a=rtcp-mux
表示rtp,rtcp包使用同一個端口來傳輸;a=ice-xxx:xxx
ice協商過程當中的安全驗證信息;a=fingerprint:xxx
表示dtls協商過程當中須要的認證信息;a=setup:actpass
表示本客戶端在dtls協商過程當中,能夠作客戶端也能夠作服務端;a=rtpmap:111 opus/48000/2
負載類型111,編碼格式opus,48000是時鐘,2是通道數;a=rtcp-fb:111 nack
支持丟包重傳;a=rtcp-fb:111 nack pli
支持關鍵幀丟包重傳;a=rtcp-fb:111 transport-cc
表示opus編碼支持使用rtcp來控制擁塞;a=fmtp:111 minptime=10;useinbandfec=1;maxplaybackrate=16000
對opus編碼可選的補充說明,minptime表明最小打包時長是10ms,useinbandfec=1表明使用opus編碼內置fec特性;a=ssrc:1370113029 cname:NMediaAudio
cname用來標識一個數據源,ssrc當發生衝突時可能會發生變化,可是cname不會發生變化,也會出如今rtcp包中SDEC中,用於音視頻同步;a=candidate:1 1 udp 2013266431 x.x.x.x 43342 typ host generation 0
表示候選人的傳輸地址,查看詳情。