转:https://blog.csdn.net/shij19/article/details/52946510
SDP 完全是一种会话描述格式―它不属于传输协议―它只使用不同的适当的传输协议,包括会话通知协议(SAP)、会话初始协议(SIP)、实时流协议(RTSP)、MIME扩展协议的电子邮件以及超文本传输协议(HTTP)。SDP协议是也是基于文本的协议,这样就能保证协议的可扩展性比较强,这样就使其具有广泛的应用范围。SDP不支持会话内容或媒体编码的协商,所以在流媒体中只用来描述媒体信息。媒体协商这一块要用RTSP来实现
SDP包括以下一些方面:
1)会话的名称和目的
2)会话存活时间
3)包含在会话中的媒体信息,包括:
媒体类型(video, audio, etc)
传输协议(RTP/UDP/IP, H.320,etc)
媒体格式(H.261 video, MPEGvideo, etc)
多播或远端(单播)地址和端口
4)为接收媒体而需的信息(addresses,ports, formats and so on)
5)使用的带宽信息
6)可信赖的接洽信息(Contactinformation)
二、 SDP协议结构
SDP描述由许多文本行组成,文本行的格式为<</span>类型>=<</span>值>,
<</span>类型>是一个字母,
<</span>值>是结构化的文本串,其格式依<</span>类型>而定。
<type>=[CRLF]
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 allmedia)
b=* (bandwidth information)
One or more time descriptions (see below)
z=* (time zone adjustments)
k=* (encryption key)
a=* (zero or moresession attribute lines)
Zero or more media descriptions (see below)
Time description //时间描述部分
t= (time the session is active)
r=* (zero or more repeat times)
Media description //媒体描述部分
m= (media name and transport address)
i=* (media title)
c=* (connection information - optional if included atsession-level)
b=* (bandwidth information)
k=* (encryption key)
a=* (zero or more media attribute lines)
三、 SDP 字段
字段 | 含义 | 说明 |
Session description | ||
V= | protocol version | 协议版本,总是0 |
O= | (owner/creator and session identifier | 会发初始者信息以及对应的地址 |
s= | session name | 会话名字,每个会话中只能有一个s= |
i=* | session information | 会话描述信息 |
u=* | URI of description | 通过URI描述会话以外的会议信息 |
e=* | email address | Email地址 |
p=* | phone number | 手机号码 |
c=* | connection information - not required if included in allmedia | 连接信息 |
b=* | bandwidth information | 带宽信息 |
z=* | time zone adjustments | 时间信息 |
k=* | encryption key | 秘钥 |
a=* | zero or more session attribute lines | 媒体属性 |
Time description | ||
t= | time the session is active |
|
r=* | (zero or more repeat times |
|
Media description | ||
m= | media name and transport address | 媒体名字和传输地址 |
i=* | media title | 媒体名称 |
c=* | connection information - optional if included atsession-level | 连接信息 |
b=* | bandwidth information | 带宽信息 |
k=* | encryption key | 秘钥 |
a=* | zero or more media attribute lines | 媒体属性 |
3.1 Protocol Version
字段: v=
SDP协议版本,目前唯一值,v=0
3.2 Origin
字段: o=
会话发起者以及对应的地址
结构:
o=
可以是发起者的主机名,或者用”-“
例如:o=- 1014 1000 IN IP62409:8095:40e:1e3:a281:fb44:9d9f:946a
3.3 sessionname
字段: s=
会话名称,每个SDP会话只能有一个s=属性
结构:
s=
例:s=QCVOIP
3.4 sessiondescription
字段: i=*
会话描述信息,一个会话中,最多只能有一个i=*字段
结构:i=<<aname="OLE_LINK10">sessiondescription>
3.5 URI
字段: u=*
会话以外的会议信息。原文为:Thisfield is optional, but if it is present it should be specifiedbefore the first media field
结构:
u=
3.6 EmailAddress and Phone Number
字段: e=*
P=*
Email地址和手机号码。用户conference中。
3.7 Connection Data
字段: c=
连接数据
结构:
c=
例如 c=INIP62409:8095:40e:1e3:a281:fb44:9d9f:946a
3.8 Bandwidth
字段: b=*
带宽信息
结构:
b=:
的单位是kbps
is a single alphanumeric word giving the meaning of the bandwidthfigure.有两种类型
1.CT Conference Total:会议总带宽,通过=CT以决定是否可以有2个或更多的会议共存。
2. AS Application-Specific Maximum:应用最大的带宽需求
例如:
b=AS:49
b=RS:0
b=RR:0
3.9 Times,Repeat Times and Time Zones
字段: z=*
会话开始和结束时间,一般在直播中较常见。
结构:
t=
如果 和都为0,那么表示通话将一直存在,直到用户结束为止。
3.10 EncryptionKeys
字段: k=
秘钥。
结构:
k=
k=:
3.11 attribute
字段: a=
媒体属性
结构:
a=
a=:
协议中给出了一些建议的属性
字段&结构 | 说明 |
a=cat: | 会话等级,用户可以根据会话等级筛选接收内容 |
a=keywds: | 类似cat,关键字,用户可以根据关键字筛选会话,Thisallows a receiver to select interesting session based on keywords |
a=tool: |
|
a=ptime: | 一个媒体文件在数据包中持续的时间长度,单位ms |
a=recvonly | 仅接收 |
a=sendrecv | 发送和接收同时 |
a=sendonly | 仅发送 |
a=orient: |
|
a=type: | 会议类型,常见的有,三方通话要用到此属性。 ‘broadcast’, ‘meeting’, ‘moderated’, ‘test’ and‘H332’.‘recvonly’ |
a=charset: | display the session name and information data 显示会话名称等信息 |
a=sdplang: | 语音描述。这个是会话级,或媒体级别的描述sessionlevel attribute or a media level attribute |
a=lang: |
|
a=framerate: | This gives the maximum video frame rate in frames/sec |
a=quality: | the quality of the encoding as an integer value.取值范围0~10 10 - the best still-image quality the compression scheme cangive. 5 - the default behaviour given no quality suggestion. 0 - the worst still-image quality the codec designer thinks isstill usable. |
a=fmtp: | 用于转换SDP的一个参数 |
3.12 MediaAnnouncements
字段: m=
媒体名称和传输地址
结构:
m=
例如:
m=video 49170/2 RTP/AVP 31
描述了mediatype。例如是vedio
描述了send发送端口.49170表示有2对端口,第一对端口是49170/19171,第二对端口是49172/49173
描述了传输协议Transportprotocol .常见的有UDP、RTP/AVP
subfield media type 子媒体格式。对于语音或视频自媒体,通常是mediapayload (type asdefined in the RTP Audio/Video Profile)
另外还有动态编码,例如语音16KHZ的语音编码是线性的,如果是动态的编码,还需要对payload进行单独说明
m=video 49232 RTP/AVP 98
a=rtpmap:98 L16/16000/2 //对payload=98进行说明/L16表示16bit线性编码,/16000是采样速率/
格式:
a=rtpmap: /[/
parameters>]
rtpmap:RTP mapping
例如:
m=audio 49230 RTP/AVP 96 97 98
a=rtpmap:96 L8/8000
a=rtpmap:97 L16/8000
a=rtpmap:98L16/11025/2