首页 > 解决方案 > 属性标记的 SDP 值中的“:”或“/”本身是否允许在它们周围有空格?

问题描述

在 SDP 中,冒号(':') 和斜杠('/') 用于许多属性值(标准和 a= 扩展)。这里只是其中的几个:

  b=AS:41
  a=rtpmap:96 AMR-WB/16000/1
  a=fmtp:96 mode-change-capability=2; max-red=80

我想知道(用于解析和生成 SDP),它们周围是否允许有空间。所有的例子都表明它们周围没有空间。我认为 RFC 4566 的第 9 节给出了 SDP 的语法并不清楚这一点。

标签: webrtcsipsdp

解决方案


我会说,通常,SDP 不喜欢空格。rfc4566 的第一条规则没有回答您的问题,但这是一个开始:

An SDP session description consists of a number of lines of text of
the form:

  <type>=<value>

where <type> MUST be exactly one case-significant character and
<value> is structured text whose format depends on <type>.  In
general, <value> is either a number of fields delimited by a single
space character or a free format string, and is case-significant
unless a specific field defines otherwise.  Whitespace MUST NOT be
used on either side of the "=" sign.

让我们从定义存在于 rfc4566 中的带宽参数开始

bandwidth-fields =    *(%x62 "=" bwtype ":" bandwidth CRLF)
; sub-rules of 'b='
bwtype =              token
token =               1*(token-char)
token-char =          %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39
                     / %x41-5A / %x5E-7E
bandwidth =           1*DIGIT

从以上:

  • bwtype中不允许有空格,因为%x20不是token-char的一部分
  • 带宽中不允许有空格,因为它只包含DIGIT
  • ":" 的左侧或右侧没有空格,否则,规范将使用bwtype SP ":" SP 带宽之类的内容

对于 rtpmap,在 RFC4566 第 6 节中,rtpmap 的定义在这里:

a=rtpmap:<payload type> <encoding name>/<clock rate> [/<encoding
  parameters>]

这似乎引入了时钟速率和编码参数之间的空间要求(但它不是 BNF 格式!!!)。但是,这里有一个勘误表,报告这是一个错误。

根据我的经验,在有效载荷类型和有效载荷定义之间不允许在 rtpmap execpt 中有空格。

对于 rtpmap,您还可以查看较新的 ietf 文档rfc4566bis,它提供了 rtpmap 的 BNF 定义,而这个显然是没有空格的:

rtpmap-value = payload-type SP encoding-name
   "/" clock-rate [ "/" encoding-params ]
payload-type = zero-based-integer
encoding-name = token
clock-rate = integer
encoding-params = channels
channels = integer

fmtp 更棘手,但较新的rfc4566bis中的定义允许字节字符串BNF 定义中的空格:

fmtp-value = fmt SP format-specific-params
format-specific-params = byte-string
byte-string =         1*(%x01-09/%x0B-0C/%x0E-FF)
                      ;any byte except NUL, CR, or LF

此外,根据经验,一些 rfc 在“;”周围使用空格。而其他则不是。我无法找到确切的原因,但这可能与 Content-Type HTML 标头中允许空格有关。要了解更多信息,您可以查看rfc4855rfc2045


推荐阅读