2012年5月30日 星期三

SDP (Session Description Protocol) 閱讀心得


SDP (Session Description Protocol): RFC4566

SDP通常會用在會談初始化過程,用來傳送會談參與者的能力列表,以協調會談雙方的各項參數,例如:媒體的種類為 audio或 video,用來承載SDP的協定(RTP/UDP/IP, etc.),媒體的編碼方式(H.261 video, MPEG video, etc.)

以 RTSP為例,在 RTSP 的溝通過程中,當用戶端詢問伺服器端URL的相關資訊時(發出 DESCRIBE),伺服器會將相關資訊以SDP的格式回復。用戶端可以藉此資訊決定要使用哪種codec與伺服器溝通。

主要用到 SDP的協議,包括SAPRTPRTSPSIPHTTPEmailMIME extension

SDP的基本格式為
<type>=<value>
< type >exactly one case-significant character. ASCII編碼
<value>is structured text whose format depends on <type>. 支援所有ISO 10646所定義的字元,使用UTF-8編碼


一個SDP訊息應該要包含三個部分,
l   Session description
n   v= (protocol version)
n   o= (originator and session identifier)
n   s= (session name)
n   i=* (session information)
n   u=* (URI of description)
n   e=* (email address)
n   p=* (phone number)
n   c=* (connection information -- not required if included in all media)
n   b=* (zero or more bandwidth information lines) One or more time descriptions ("t=" and "r=" lines; see below)
n   z=* (time zone adjustments)
n   k=* (encryption key)
n   a=* (zero or more session attribute lines) Zero or more media descriptions

l   Time description
n   t= (time the session is active)
n   r=* (zero or more repeat times)

l   Media description, if present
n   m= (media name and transport address)
n   i=* (media title)
n   c=* (connection information -- optional if included at session level)
n   b=* (zero or more bandwidth information lines)
n   k=* (encryption key)
n   a=* (zero or more media attribute lines)


Session description
l   v= (protocol version)
根據 RFC4566,此值定義為0

l   o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
例如:o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5 ,此處"IN"表示"Internet"

l   s=<session name>
會談名稱,若要使用非ISO 10646的字元,則需要設定"a=charset",並且指名字符集。

l   i=<session description>
會談描述,提供human-readable的描述。

l   u=<uri>
URI連結,在SDP的會談描述中,最多只能存在一個URI

l   e=<email-address>
電子郵件位址

l   p=<phone-number>
電話號碼

l   c=<nettype> <addrtype> <connection-address>
連線資訊,位址後方可以加上TTL,如下例: 
c=IN IP4 224.2.36.42/127

對於多個位址,如群播位址(multicast)的設定,如下例:設定三個位址
方法一:
c=IN IP4 224.2.1.1/127/3
方法二:
c=IN IP4 224.2.1.1/127c=IN IP4 224.2.1.2/127c=IN IP4 224.2.1.3/127

l   b=<bwtype>:<bandwidth>
建議頻寬,頻寬種類分為”CT””AS”,或是”X-“,頻寬的單位則為kilobitsCT:針對所有的媒體與溝通對象,需要的總頻寬。ASapplication specified,針對某個特定的媒體與溝通對象,所需要的頻寬。X-:提供未來擴充用 
Note that CT gives a total bandwidth figure for all the media at all sites. AS gives a bandwidth figure for a single media at a single site, although there may be many sites sending simultaneously.

l   z=<adjustment time> <offset> <adjustment time> <offset> ....
以 "t=" 與 "r=" 所設定的時間值為基礎時間,進行時間的調整。 
例如:z=2882844526 -1h 2898848070 0
表示當時間為 2882844526 時,將時間設定為基礎時間減掉一個小時,當時間為2898848070時,恢復為基礎時間。

l   k=<method>
     k=<method>:<encryption key>
用來加密傳送通道的鑰匙,RFC4556並不建議使用此種方式。若使用者使用此欄位,則通常需要再定義擴充屬性”a=”。大部分加密演算法都會需要兩把鑰匙,一個用來加密(confidentiality),一個用來確認資料沒被改變(integrity)。但RFC4556並不支援同時傳送兩把鑰匙。

k=clear:<encryption key>:用明碼傳送密鑰。
k=base64:<encoded encryption key>:使用BASE64傳送密鑰。
k=uri:<URI to obtain key>:透過URI取得密鑰。
k=prompt:使用者手動輸入用來解開此段資料的密鑰。

l   a=<attribute>
     a=<attribute>:<value>
用來擴充 SDP協定,使其能夠支援使用者自行定義的屬性。可以針對 "media-level" 或 "session-level" 分別定義。

有兩種設定形式
"a=<flag>",例如:"a=recvonly".
"a=<attribute>:<value>",例如:"a=orient:landscape"

注意:此處所使用的字元並不會因為character set的設定而改變。任何新增的屬性應該要向IANA組織進行註冊。


Time description
用來描述會談開始的時間,以及重複啟動的時間。

l   t=<start-time> <stop-time>
此處的時間使用1900年1月1日開始的秒數來表示

l   r=<repeat interval> <active duration> <offsets from start-time>
格式為days ('d'), hours ('h'), minutes ('m') and seconds ('s')
例如:開始時間為2010年8月1月10AM,每隔七天就會啟動1小時。其表示方法

方法一
t=3487140000 3487143600
r=604800 3600 0
方法二
t=3487140000 3487143600
r=7d 3600 0

Media description
l   m=<media> <port> <proto> <fmt>
     m=<media> <port>/<number of ports> <proto> <fmt>
<media>:媒體種類,目前支援五種定義 "audio", "video", "text", "application", "message"
<port>:傳輸時使用的埠號,此處需要與”c=”設定的IP位址一併檢視。
<number of ports>:RTP session的個數。
<proto>:採用的協議(protocol),此份規格書定義了三種協議,udp、RTP/AVP、RTP/SAVP。
<fmt>:格式(format)

例如:

m=video 49170/2 RTP/AVP 31

表示定義了兩種 RTP/RTCP 傳輸,第一組使用 49170、49171,第一組使用 49172、49173。傳輸協議為RTP/AVP,格式為31。
C=IN IP4 224.2.1.1/127/2

表示定義了兩種 RTP/RTCP 傳輸,第一組使用IP位址為224.2.1.1,埠號為 49170、49171,第一組使用IP位址為224.2.1.2,埠號為 49172、49173。


SDP attributes各項設定
a=cat:<category> 
會談分類,接收者可利用此欄位來過濾不想要的會談(session)
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>]
將一個RTP封包類型號碼對應到用來編碼此封包格式的編碼名稱
原文:maps from an RTP payload type number (as used in an "m=" line) to an encoding name denoting the payload format to be used.

例如:

m=audio 49230 RTP/AVP 96 97 98
a=rtpmap:96 L8/8000
a=rtpmap:97 L16/8000
a=rtpmap:98 L16/11025/2

表示 RTP/AVP 會有三種封裝 96,97,98, 分別對應到編碼 L8/8000, L16/8000, L16/11025/2
       
a=recvonly 
工具啟動時設定為純接收模式(receive only)
a=sendrecv 
工具啟動時設定為發送/接收模式
a=sendonly 
工具啟動時設定為純發送模式(send only)
a=inactive 
工具啟動時設定為無效模式(send only)

a=orient:<orientation> 
方向,通常用在電子白板或是展示時,有三種設定"portrait", "landscape", "seascape" (upside-down landscape).

a=type:<conference type>
會談種類 "broadcast", "meeting", "moderated", "test", "H332", "recvonly"

a=charset:<character set>
字符集

a=sdplang:<language tag>
用來描述 SDP 資訊的語言

a=lang:<language tag>
媒體內容所採用的語言

a=framerate:<frame rate>
最大的影像禎數,單位為 frames/sec

a=quality:<quality>
影像編碼的品質,0表示最差,10表示最好

a=fmtp:<format> <format specific parameters>
SDP可以透過此屬性,將一個特殊的媒體格式與參數傳達給其他參與者。


一個SDP的例子
v=0
o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5
s=SDP Seminar
i=A Seminar on the session description protocol
u=http://www.example.com/seminars/sdp.pdf
e=j.doe@example.com (Jane Doe)
c=IN IP4 224.2.17.12/127
t=2873397496 2873404696
a=recvonly
m=audio 49170 RTP/AVP 0
m=video 51372 RTP/AVP 99
a=rtpmap:99 h263-1998/90000


參考資料
2.          RFC 4566