Skip to main content

9. SDP语法 (SDP Grammar)

本节提供SDP的增强巴科斯-诺尔范式(Augmented BNF)语法。ABNF在[RFC5234]和[RFC7405]中定义。

; SDP语法 (SDP Syntax)
session-description = version-field
origin-field
session-name-field
[information-field]
[uri-field]
*email-field
*phone-field
[connection-field]
*bandwidth-field
1*time-description
[key-field]
*attribute-field
*media-description

version-field = %s"v" "=" 1*DIGIT CRLF
;本备忘录描述版本0

origin-field = %s"o" "=" username SP sess-id SP sess-version SP
nettype SP addrtype SP unicast-address CRLF

session-name-field = %s"s" "=" text CRLF

information-field = %s"i" "=" text CRLF

uri-field = %s"u" "=" uri CRLF

email-field = %s"e" "=" email-address CRLF

phone-field = %s"p" "=" phone-number CRLF

connection-field = %s"c" "=" nettype SP addrtype SP
connection-address CRLF
;连接字段必须在每个媒体描述中
;或在会话级别存在

bandwidth-field = %s"b" "=" bwtype ":" bandwidth CRLF

time-description = time-field
[repeat-description]

repeat-description = 1*repeat-field
[zone-field]

time-field = %s"t" "=" start-time SP stop-time CRLF

repeat-field = %s"r" "=" repeat-interval SP typed-time
1*(SP typed-time) CRLF

zone-field = %s"z" "=" time SP ["-"] typed-time
*(SP time SP ["-"] typed-time) CRLF

key-field = %s"k" "=" key-type CRLF

attribute-field = %s"a" "=" attribute CRLF

media-description = media-field
[information-field]
*connection-field
*bandwidth-field
[key-field]
*attribute-field

media-field = %s"m" "=" media SP port ["/" integer]
SP proto 1*(SP fmt) CRLF

; 'o='的子规则
username = non-ws-string
;定义很宽泛,但不包括空格

sess-id = 1*DIGIT
;对于此用户名/主机应该是唯一的

sess-version = 1*DIGIT

nettype = token
;通常是"IN"

addrtype = token
;通常是"IP4"或"IP6"

; 'u='的子规则
uri = URI-reference
; 参见RFC 3986

; 'e='的子规则,定义参见RFC 5322
email-address = address-and-comment / dispname-and-address
/ addr-spec
address-and-comment = addr-spec 1*SP "(" 1*email-safe ")"
dispname-and-address = 1*email-safe 1*SP "<" addr-spec ">"

; 'p='的子规则
phone-number = phone *SP "(" 1*email-safe ")" /
1*email-safe "<" phone ">" /
phone

phone = ["+"] 1*DIGIT 1*(SP / "-" / DIGIT)

; 'c='的子规则
connection-address = multicast-address / unicast-address

; 'm='的子规则
media = token
;通常是"audio"、"video"、"text"、
;"application"或"message"

fmt = token
;通常是RTP有效负载类型

proto = token *("/" token)
;通常是"RTP/AVP"或"udp"

port = 1*DIGIT

; 通用子规则:地址
unicast-address = IP4-address / IP6-address / FQDN / extn-addr

multicast-address = IP4-multicast / IP6-multicast / FQDN / extn-addr

IP4-multicast = m1 3( "." decimal-uchar ) [ "/" ttl ] [ "/" integer ]
;IPv4多播地址可以有TTL和层数

m1 = ("22" ("4"/"5"/"6"/"7"/"8"/"9")) /
("23" DIGIT )

IP6-multicast = hexpart [ "/" integer ]
;IPv6多播地址和层数

ttl = (POS-DIGIT *2DIGIT) / "0"

FQDN = 4*(alpha-numeric / "-" / ".")
;完全限定域名的定义宽松

IP4-address = b1 3("." decimal-uchar)

b1 = decimal-uchar
;除0.x.x.x外的任何IP地址

IP6-address = hexpart [ ":" IP4-address ]

hexpart = hexseq / hexseq "::" [ hexseq ] /
"::" [ hexseq ]

hexseq = hex4 *( ":" hex4)

hex4 = 1*4HEXDIG

; 'b='的子规则
bwtype = token

bandwidth = 1*DIGIT

; 't='的子规则
start-time = time / "0"

stop-time = time / "0"

time = POS-DIGIT 9*DIGIT
;以NTP格式表示的十进制整数

; 'r='的子规则
repeat-interval = typed-time

typed-time = 1*DIGIT [fixed-len-time-unit]

fixed-len-time-unit = %s"d" / %s"h" / %s"m" / %s"s"

; 'k='的子规则
key-type = %s"prompt" /
%s"clear:" key-data /
%s"base64:" key-data /
%s"uri:" uri

key-data = email-safe

; 'a='的子规则
attribute = (att-field ":" att-value) / att-field

att-field = token

att-value = byte-string

; 通用基本类型
token = 1*(token-char)

token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39
/ %x41-5A / %x5E-7E

byte-string = 1*(%x01-09/%x0B-0C/%x0E-FF)
;任何非空的字节串

non-ws-string = 1*(VCHAR/%x80-FF)
;任何非空字符串,不包括空白

text = byte-string
;使用ISO 10646的UTF-8编码,
;除非指定了"a=charset:"

decimal-uchar = DIGIT /
POS-DIGIT DIGIT /
("1" 2(DIGIT)) /
("2" ("0"/"1"/"2"/"3"/"4") DIGIT) /
("2" "5" ("0"/"1"/"2"/"3"/"4"/"5"))

integer = POS-DIGIT *DIGIT

alpha-numeric = ALPHA / DIGIT

POS-DIGIT = %x31-39 ; 1 - 9

extn-addr = non-ws-string

; 外部定义
email-safe = %x01-09/%x0B-0C/%x0E-27/%x2A-3B/%x3D/%x3F-FF
;任何字节,除NULL、CR、LF、或字符():<>

URI-reference = <按RFC 3986定义>

addr-spec = <按RFC 5322定义>

ALPHA = <按RFC 5234定义>

DIGIT = <按RFC 5234定义>

CRLF = <按RFC 5234定义>

HEXDIG = <按RFC 5234定义>

SP = <按RFC 5234定义>

VCHAR = <按RFC 5234定义>

注意:本语法定义了SDP会话描述的完整语法。所有SDP实现必须(MUST)严格遵守此语法。任何不符合此语法的会话描述应被视为格式错误并被拒绝。