SDP協議介紹
SDP 完全是一種會話描述格式 ― 它不屬于傳輸協議 ― 它只使用不同的適當的傳輸協議,包括會話通知協議(SAP)、會話初始協議(SIP)、實時流協議(RTSP)、MIME 擴展協議的電子郵件以及超文本傳輸協議(HTTP)。SDP協議是基于文本的協議,這樣就能保證協議的可擴展性比較強,這樣就使其具有廣泛的應用范圍。SDP 不支持會話內容或媒體編碼的協商,所以在流媒體中只用來描述媒體信息。媒體協商這一塊要用RTSP來實現。
SDP協議格式
SDP描述由許多文本行組成,文本行的格式為<類型>=<值>,<類型>是一個字母,<值>是結構化的文本串,其格式依<類型>而定。
<type>=<value>
SDP協議例子
下面是一個helix 流媒體服務器的RTSP協議中的SDP協議:
v=0 //SDP version
// o field定義的源的一些信息。其格式為:o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
o=- 1271659412 1271659412 IN IP4 10.56.136.37 s=<No title>
i=<No author> <No copyright> //session的信息
c=IN IP4 0.0.0.0 //connect 的信息,分別描述了:網絡協議,地址的類型,連接地址。
c=IN IP4 0.0.0.0
t=0 0 //時間信息,分別表示開始的時間和結束的時間,一般在流媒體的直播的時移中見的比較多。
a=SdpplinVersion:1610641560 //描述性的信息
a=StreamCount:integer;2 //用來描述媒體流的信息,表示有兩個媒體流。integer表示信息的格式為整數。
a=control:*
a=DefaultLicenseValue:integer;0 //License信息
a=FileType:string;"MPEG4" ////用來描述媒體流的信息說明當前協商的文件是mpeg4格式的文件
a=LicenseKey:string;"license.Summary.Datatypes.RealMPEG4.Enabled"
a=range:npt=0-72.080000 //用來表示媒體流的長度
m=audio 0 [RTP](http://www.cnblogs.com/qingquan/archive/2011/07/28/2120440.html)/AVP 96 //做為媒體描述信息的重要組成部分描述了媒體信息的詳細內容:表示session的audio是通過[RTP](http://www.cnblogs.com/qingquan/archive/2011/07/28/2120440.html)來格式傳送的,其payload值為96傳送的端口還沒有定。
b=as:24 //audio 的bitrate
b=RR:1800
b=RS:600
a=control:streamid=1 //通過媒體流1來發送音頻
a=range:npt=0-72.080000 //說明媒體流的長度。
a=length:npt=72.080000
a=rtpmap:96 MPEG4-GENERIC/32000/2 //rtpmap的信息,表示音頻為AAC的其sample為32000
a=fmtp:96 profile-level-id=15;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1210 //config為AAC的詳細格式信息
a=mimetype:string;"audio/MPEG4-GENERIC"
a=Helix-Adaptation-Support:1
a=AvgBitRate:integer;48000
a=HasOutOfOrderTS:integer;1
a=MaxBitRate:integer;48000
a=Preroll:integer;1000
a=OpaqueData:buffer;"A4CAgCIAAAAEgICAFEAVABgAAAC7gAAAu4AFgICAAhKIBoCAgAEC"
a=StreamName:string;"Audio Track"
下面是video的信息基本和audio的信息相對稱,這里就不再說了。
m=video 0 [RTP](http://www.cnblogs.com/qingquan/archive/2011/07/28/2120440.html)/AVP 97
b=as:150
b=RR:11250
b=RS:3750
a=control:streamid=2
a=range:npt=0-72.080000
a=length:npt=72.080000
a=rtpmap:97 MP4V-ES/2500
a=fmtp:97 profile-level-id=1;
a=mimetype:string;"video/MP4V-ES"
a=Helix-Adaptation-Support:1
a=AvgBitRate:integer;300000
a=HasOutOfOrderTS:integer;1
a=Height:integer;240 //影片的長度
a=MaxBitRate:integer;300000
a=MaxPacketSize:integer;1400
a=Preroll:integer;1000
a=Width:integer;320 //影片的寬度
a=OpaqueData:buffer;"AzcAAB8ELyARAbd0AAST4AAEk+AFIAAAAbDzAAABtQ7gQMDPAAABAAAAASAAhED6KFAg8KIfBgEC"
a=StreamName:string;"Video Track"
SDP協議學習筆記
在SIP協議的包含的內容是SDP時,應該把Content-Type設置成application/sdp。
SDP:Session Description Protocol
SDP格式:
Session description
v= (protocol version)
o= (owner/creator and session identifier)
s= (session name)
i=* (session information)
u=* (URI of description)
e=* (email address)
p=* (phone number)
c=* (connection information - not required if included in all media)
b=* (zero or more bandwidth information lines)
One or more time descriptions ("t=" and "r=" lines, see below)
z=* (time zone adjustments)
k=* (encryption key)
a=* (zero or more session attribute lines)
Zero or more media descriptions
Time description
t= (time the session is active)
r=* (zero or more repeat times)
Media description, if present
m= (media name and transport address)
i=* (media title)
c=* (connection information - optional if included at
session-level)
b=* (zero or more bandwidth information lines)
k=* (encryption key)
a=* (zero or more media attribute lines)
以上帶"*"號的是可選的,其余的是必須的。一般順序也按照上面的順序來排列。
a=*是sdp協議擴展屬性定義,除上面以外的,分解時其它的都可以扔掉。
a=charset屬性指定協議使用的字符集。一般的是ISO-10646。
示例:
v=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
其中:nettype是IN,代表internet,addrtype是IP4或IP6。unicast-address任務創建計算機的地址。整個這個屬性,是唯一表示一個任務。
e=123@126.com或 p=+1 616 555-6011
對于一個任務只能兩者之中的一個,表示會議控制者的聯系方式。郵件地址可以是[email]j.doe@example.com[/email] (Jane Doe)
形式,括號里面的是描述聯系人的名稱,或者Jane Doe <[email]j.doe@example.com[/email]>
,前面的是聯系人的名稱。
c=<nettype> <addrtype> <connection-address>
這個連接數據,可以是傳話級別的連接數據,或者是單獨一個媒體數據的連接數據。在是多播時,connection-address
就該是一個多播組地址,當是單播時,connection-address
就該是一個單播地址。對于addrtype
是IP4的情況下,connection-address
不僅包含IP地址,并且還要包含a time to live value(TTL 0-255)
,如:c=IN IP4 224.2.36.42/128
,IP6沒有這個TTL值。還允許象這樣的<base multicast address>[/<ttl>]/<number of addresses>
格式的connection-address。如:c=IN IP4 224.2.1.1/127/3
等同于包含c=IN IP4 224.2.1.1/127, c=IN IP4 224.2.1.2/127, c=IN IP4 224.2.1.3/127
三行內容。
b=<bwtype>:<bandwidth> bwtype
可以是CT或AS,CT方式是設置整個會議的帶寬,AS是設置單個會話的帶寬。缺省帶寬是千比特每秒。t=<start-time> <stop-time>
,這個可以有行,指定多個不規則時間段,如果是規則的時間段,則r=屬性
可以使用。start-time
和stop- time
都遵從NTP(Network Time Protocol),是以秒為單位,自從1900以來的時間。要轉換為UNIX時間,減去2208988800。如果stop-time
設置為0,則會話沒有時間限制。如果start-time
也設置為0,則會話被認為是永久的。
r=<repeat-interval> <active duration> <offsets from start-time>
重復次數在時間表示里面可以如下表示:
d - days (86400 seconds)
h - hours (3600 seconds)
m - minutes (60 seconds)
s - seconds (allowed for completeness)
z=<adjustment time> <offset> <adjustment time> <offset> ....
k=<method>
k=<method>:<encryption key>
a=<attribute>
a=<attribute>:<value>
m=<media> <port> <proto> <fmt> ...
m=<media> <port>/<number of ports> <proto> <fmt> ...
其中:<media>
可以是,"audio","video", "text", "application" and "message"
。<port>
是媒體傳送的端口號,它依賴于c=
和<proto>
。<proto>
可以是,udp,RTP/AVP和RTP/SAVP。
a=cat:<category>
分類,根據分類接收者隔離相應的會話
a=keywds:<keywords>
關鍵字,根據關鍵字隔離相應的會話
a=tool:<name and version of tool>
創建任務描述的工具的名稱及版本號
a=ptime:<packet time>
在一個包里面的以毫秒為單位的媒體長度
a=maxptime:<maximum packet time>
以毫秒為單位,能夠壓縮進一個包的媒體量。
a=rtpmap:<payload type> <encoding name>/<clock rate> [/<encoding parameters>]
a=recvonly
a=sendrecv
a=sendonly
a=inactive,
a=orient:<orientation>其可能的值,"portrait", "landscape" and "seascape" 。
a=type:<conference type>,建議值是,"broadcast", "meeting", "moderated", "test" and "H332"。
a=charset:<character set>
a=sdplang:<language tag>指定會話或者是媒體級別使用的語言
a=framerate:<frame rate>設置最大視頻幀速率
a=quality:<quality>值是0-10
a=fmtp:<format> <format specific parameters>