背景
rtpengine
提供媒体代理功能, 和sip代理(opensips
或者kamailio
)一起组成完整的代理服务。
针对rtpengine
的使用,记录几个常用方法。
rtpengine的官方文档: rtpengine
当前测试的rtpegnine版本:
Version: 13.3.1.7+0~mr13.3.1.7 git-HEAD-c2223681
rtpengine 是否支持视频?
一直对rtpengine
的视频支持不是很清楚,官方文档也没有明确说明。 rtpengine
支持的编码有:
从支持的编码上看,都是音频编码,没有视频编码,所以我也认为是不支持视频的。
最近有空,就使用mircoSIP
测试了视频功能,发现rtpengine支持视频。
完整的一通视频sip图:
媒体相关的信令:
可以看到音频用的是g711u,视频用的是h264
以下这通电话的详细sdp信令:
microSIP
发出INVITE
信令:
可以看到既有audio
又有video
opensips
转发INVITE
信令:
opensips
收到183ring
信令:
opensips
转发183ring
信令:
- 接通之后,
microSIP
发出媒体控制信令INFO
:
opensips
转发INFO
信令:
目前视频流传输这块发现rtpengine
有报错, 从效果来看,并没有卡顿情况:
综上所述, rtpengine
支持视频,因为没有相应的编码,所以视频流透传。
rtpengine 的几个codec设置
在做媒体代理转发时,需要对sdp
中的codec
做调整, 而sdp
是rtpengine
生成的,
所以opensips
或者kamailio
调用rtpengine_manager
时,设置codec
参数可以调整sdp
中的codec
。
rtpengine
提供的参数文档为: ng_control_protocol
codec-transcode
介绍
transcode
官方的解释是:
Similar to
offer
but allows codecs to be added to the list of offered codecs even if they were not present in the original list of codecs. In this case, the transcoding engine will be engaged. Only codecs that are supported for both decoding and encoding can be added in this manner. This also has the side effect of automatically stripping all unsupported codecs from the list of offered codecs, as rtpengine must expect to receive or even send in any codec that is present in the list.
意思就是: 可以添加原编码列表中没有的新编码,这个新的编码必须是rtpengine
支持的fully supported
的codecs
.
此时会启用转码功能。另外也可以通过opus/48000/2/32000
这样,设置采样率,声道数。
验证
codec-transcode-PCMU
(源sdp含有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,PCMA,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMA,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMA,telephone-event
可以看到,codec-transcode-PCMU
其实不起作用.
codec-transcode-G722
(源sdp没有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,PCMA,G722,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMA,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMA,telephone-event
当和codec-strip-all codec-mask-all
一起使用时,codec-transcode-PCMU
不会启用转码,codec-transcode-G722
会启用转码.
codec-strip
介绍
strip
官方的解释是:
Contains a list of strings. Each string is the name of a codec or RTP payload type that should be removed from the SDP. Codec names are case sensitive, and can be either from the list of codecs explicitly defined by the SDP through an
a=rtpmap
attribute, or can be from the list of RFC-defined codecs. Examples arePCMU
,opus
, ortelephone-event
. Codecs stripped using this option are only removed from the outgoing rewritten SDP and don’t affect the list of codecs that was offered by the source SDP. See theignore
option above for a similar mechanism that affects the offer codecs.
意思就是: 从sdp
中移除指定的编码. 可以是具体的某个编码,也可以是all
orfull
移除所有编码.
验证
codec-strip-PCMU
(源sdp含有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMA,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMA,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMA,telephone-event
codec-strip-PCMA codec-transcode-G722
(uas使用G722
)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,G722,telephone-event uas-->>opensips: 200OK Note over uas,opensips: G722,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMU,telephone-event
codec-strip-G722
(源sdp没有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,PCMA,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMA,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMA,telephone-event
这种方式下,codec-accept-G722
不起作用.
-
codec-strip-all
(删除所有)opensips
转发INVITE
时的sdp
信息:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
v=0 o=- 3959939030 3959939030 IN IP4 172.16.4.111 s=pjmedia b=AS:84 t=0 0 a=X-nat:0 m=audio 32560 RTP/AVP 0 8 101 c=IN IP4 172.16.4.111 b=TIAS:64000 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-16 a=ssrc:1854882148 cname:0baf6e5578824b50 a=sendrecv a=rtcp:32561
可以看到好像并没有变化,查看
rtpengine
的日志,有Warning
:1 2 3 4
[1750921364.090656] DEBUG: [0349a2eed9304f22ac7cb87970e1d5f7]: [codec] Stripping codec PCMU/8000/ (0) due to strip=all or strip=full [1750921364.090663] DEBUG: [0349a2eed9304f22ac7cb87970e1d5f7]: [codec] Stripping codec PCMA/8000/ (8) due to strip=all or strip=full [1750921364.090666] DEBUG: [0349a2eed9304f22ac7cb87970e1d5f7]: [codec] Stripping codec telephone-event/8000/0-16 (101) due to strip=all or strip=full [1750921364.090669] WARNING: [0349a2eed9304f22ac7cb87970e1d5f7]: [core] Usage error: List of codecs empty. Restoring original list of codecs. Results may be unexpected.
rtpengine
触发了保护机制,不允许删除所有的codecs
.如果想查看效果,可以这样用
codec-strip-all codec-transcode-G722
删除所有,新增G722
1 2 3 4 5 6 7 8 9 10 11 12 13
v=0 o=- 3959939604 3959939604 IN IP4 172.16.4.111 s=pjmedia b=AS:84 t=0 0 a=X-nat:0 m=audio 32710 RTP/AVP 9 c=IN IP4 172.16.4.111 b=TIAS:64000 a=rtpmap:9 G722/8000 a=ssrc:607722213 cname:2664202b2fde465f a=sendrecv a=rtcp:32711
codec-mask
介绍
mask
官方的解释是:
Similar to
strip
except that codecs listed here will still be accepted and used for transcoding on the offering side. Useful only in combination withtranscode
. For example, if an offer advertises Opus and the optionsmask=opus, transcode=G723
are given, then the rewritten outgoing offer will contain only G.723 as offered codec, and transcoding will happen between Opus and G.723. In contrast, if onlytranscode=G723
were given, then the rewritten outgoing offer would contain both Opus and G.723. On the other hand, ifstrip=opus, transcode=G723
were given, then Opus would be unavailable for transcoding.
意思就是: 功能和strip
类似,如果和transcode
一起使用, 会设置A-leg
方向的编码,也可以设置all
orfull
。
正常情况下, A---- opensips ----B
, B
返回200OK
的编码,opensips
会透传给A
,
但是如果想改变opensips---A
的200OK
编码,就需要设置mask
。
目前实际测试情况不太一样,并没有达到官方描述的效果,不知道是否是使用方法问题。
验证
codec-mask-PCMA
(源sdp含有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMU,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMU,telephone-event
可以看到PCMA
被删除了。
codec-mask-PCMA codec-transcode-G722
(uas使用G722
)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,G722,telephone-event uas-->>opensips: 200OK Note over uas,opensips: G722,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMU,telephone-event
codec-mask-G722
(源sdp没有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,PCMA,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMA,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMA,telephone-event
这种方式下,codec-accept-G722
不起作用.
codec-accept
介绍
accept
官方的解释是:
Similar to
mask
andconsume
but doesn’t remove the codec from the list of offered codecs. This means that a codec listed underaccept
will still be offered to the remote peer, but if the remote peer rejects it, it will still be accepted towards the original offerer and then used for transcoding. It is a more selective version of what thealways transcode
flag does.
意思是: 和mask
功能一样,但是不会删除codec, 当双向不一致会转码.
验证
codec-accept-PCMA
(源sdp含有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,<br/>telephone-event opensips->>+uas: INVITE Note over opensips,uas: PCMU, PCMA,<br/>telephone-event uas-->>-opensips: 200OK Note over uas,opensips: PCMU,<br/>telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMA,<br/>telephone-event
可以看到,这种方式设置了A-leg
的编码, A-leg
和B-leg
之间实现转码.
codec-accept-PCMA codec-transcode-G722
(uas使用G722)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,<br/>telephone-event opensips->>+uas: INVITE Note over opensips,uas: PCMU, PCMA,<br/>telephone-event uas-->>-opensips: 200OK Note over uas,opensips: G722,<br/>telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMA,<br/>telephone-event
codec-accept-G722
(源sdp没有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,<br/>telephone-event opensips->>+uas: INVITE Note over opensips,uas: PCMU, PCMA,<br/>telephone-event uas-->>-opensips: 200OK Note over uas,opensips: PCMU,<br/>telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMU,<br/>telephone-event
这种方式下,codec-accept-G722
不起作用.
codec-consume
介绍
consume
官方的解释是:
Identical to
mask
but enables the transcoding engine even if no other transcoding related options are given.
意思是: 和mask
功能一样,但是会开启转码引擎,即使没有其他转码相关的选项。
验证
codec-consume-PCMA
(源sdp含有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMU,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMA,telephone-event
可以看到,consume-PCMA
设置后, 转发到B-leg
的INVITE
删除了PCMA
,但是转发到A-leg
的200OK
,选择了PCMA
, A-leg
和B-leg
实现转码。
codec-consume-PCMA codec-transcode-G722
(uas使用G722)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,G722,telephone-event uas-->>opensips: 200OK Note over uas,opensips: G722,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMA,telephone-event
codec-consume-G722
(源sdp没有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,PCMA,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMU,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMU, telephone-event
这种方式下,codec-accept-G722
不起作用.
codec-except
介绍
except
官方的解释是:
Contains a list of strings. Each string is the name of a codec that should be included in the list of codecs offered. This is primarily useful to block all codecs (
strip -> all
ormask -> all
) except the ones given in theexcept
whitelist. Codecs that were not present in the original list of codecs offered by the client will be ignored.
意思就是: 白名单,和codec-strip-all
orcodec-mask-all
一起使用才有效。
验证
codec-strip-all codec-except-PCMA
(源sdp含有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMA uas-->>opensips: 200OK Note over uas,opensips: PCMA,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMA
codec-strip-all codec-except-G722
(源sdp没有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,PCMA,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMU,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMU,telephone-event
这种方式下,codec-accept-G722
不起作用.
codec-offer
介绍
offer
官方的解释是:
This is identical to
except
but additionally allows the codec order to be changed. So the first codec listed inoffer
will be the primary (preferred) codec in the output SDP, even if it wasn’t originally so.
意思就是:和except
一样,但是会改变编码顺序.
验证
codec-strip-all codec-offer-PCMA codec-offer-PCMU
(源sdp含有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMA,PCMU uas-->>opensips: 200OK Note over uas,opensips: PCMA,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMA
可以看到,转发B-leg
的INVITE
时,编码顺序改变了。
codec-strip-all codec-except-PCMA codec-except-PCMU
在转发B-leg
的INVITE
时, PCMU PCMA
编码顺序不会变.
codec-strip-all codec-offer-G722
(源sdp没有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,PCMA,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMU,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMU,telephone-event
这种方式下,codec-accept-G722
不起作用.
codec-ignore
介绍
ignore
官方的解释是:
Similar to the
strip
option below, but affects only codecs listed in the incoming received SDP. Codecs listed here are treated as if they were never offered, and so will not be used for media towards the offerer. Note that codecs listed here would still be used in the outgoing rewritten offer SDP, unless the same codecs are also listed understrip
. This means that if a codec is only ignored but not stripped, and if that codec is then accepted by the answerer, transcoding will necessarily be enabled.
验证
codec-ignore-PCMA
(源sdp含有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,PCMA,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMU,telephone-event opensips-->> microSIP: 200OK Note over opensips,microSIP: PCMA,telephone-event
可以看到,转发A-leg
的200OK
,使用了PCMA
,实现转码. 其效果和accept
一样
codec-ignore-G722
(源sdp没有的codecs)
sequenceDiagram microSIP->>opensips: INVITE Note over microSIP,opensips: PCMU,PCMA,telephone-event opensips->>uas: INVITE Note over opensips,uas: PCMU,PCMA,telephone-event uas-->>opensips: 200OK Note over uas,opensips: PCMU,telephone-event opensips-->> microSIP: 200OK Note over opensips, microSIP: PCMU,telephone-event
这种方式下,codec-accept-G722
不起作用.