Featured image of post 关于rtpengine的几个小知识

关于rtpengine的几个小知识

背景

rtpengine提供媒体代理功能, 和sip代理(opensips或者kamailio)一起组成完整的代理服务。

针对rtpengine的使用,记录几个常用方法。 rtpengine的官方文档: rtpengine

当前测试的rtpegnine版本:

Version: 13.3.1.7+0~mr13.3.1.7 git-HEAD-c2223681

rtpengine 是否支持视频?

一直对rtpengine的视频支持不是很清楚,官方文档也没有明确说明。 rtpengine支持的编码有:

codec

从支持的编码上看,都是音频编码,没有视频编码,所以我也认为是不支持视频的。 最近有空,就使用mircoSIP测试了视频功能,发现rtpengine支持视频

完整的一通视频sip图:

video

媒体相关的信令:

rtp

可以看到音频用的是g711u,视频用的是h264

以下这通电话的详细sdp信令:

  1. microSIP发出INVITE信令:

invite

可以看到既有audio又有video

  1. opensips转发INVITE信令:

invite

  1. opensips收到183ring信令:

183

  1. opensips转发183ring信令:

183

  1. 接通之后,microSIP发出媒体控制信令INFO:

info

  1. opensips转发INFO信令:

info

目前视频流传输这块发现rtpengine有报错, 从效果来看,并没有卡顿情况:

warning

综上所述, rtpengine支持视频,因为没有相应的编码,所以视频流透传。

rtpengine 的几个codec设置

在做媒体代理转发时,需要对sdp中的codec做调整, 而sdprtpengine生成的, 所以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 supportedcodecs. 此时会启用转码功能。另外也可以通过opus/48000/2/32000这样,设置采样率,声道数。

验证

  1. 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其实不起作用.

  1. 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 are PCMU, opus, or telephone-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 the ignore option above for a similar mechanism that affects the offer codecs.

意思就是: 从sdp中移除指定的编码. 可以是具体的某个编码,也可以是allorfull移除所有编码.

验证

  1. 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
  1. 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
  1. 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不起作用.

  1. 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 with transcode. For example, if an offer advertises Opus and the options mask=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 only transcode=G723 were given, then the rewritten outgoing offer would contain both Opus and G.723. On the other hand, if strip=opus, transcode=G723 were given, then Opus would be unavailable for transcoding.

意思就是: 功能和strip类似,如果和transcode一起使用, 会设置A-leg方向的编码,也可以设置allorfull。 正常情况下, A---- opensips ----B, B返回200OK的编码,opensips会透传给A, 但是如果想改变opensips---A200OK编码,就需要设置mask

目前实际测试情况不太一样,并没有达到官方描述的效果,不知道是否是使用方法问题。

验证

  1. 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被删除了。

  1. 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
  1. 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 and consume but doesn’t remove the codec from the list of offered codecs. This means that a codec listed under accept 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 the always transcode flag does.

意思是: 和mask功能一样,但是不会删除codec, 当双向不一致会转码.

验证

  1. 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-legB-leg之间实现转码.

  1. 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
  1. 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功能一样,但是会开启转码引擎,即使没有其他转码相关的选项。

验证

  1. 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-legINVITE删除了PCMA,但是转发到A-leg200OK,选择了PCMA, A-legB-leg实现转码。

  1. 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
  1. 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 or mask -> all) except the ones given in the except whitelist. Codecs that were not present in the original list of codecs offered by the client will be ignored.

意思就是: 白名单,和codec-strip-allorcodec-mask-all一起使用才有效。

验证

  1. 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
  1. 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 in offer will be the primary (preferred) codec in the output SDP, even if it wasn’t originally so.

意思就是:和except一样,但是会改变编码顺序.

验证

  1. 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-legINVITE时,编码顺序改变了。 codec-strip-all codec-except-PCMA codec-except-PCMU在转发B-legINVITE时, PCMU PCMA编码顺序不会变.

  1. 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 under strip. 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.

验证

  1. 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-leg200OK,使用了PCMA,实现转码. 其效果和accept一样

  1. 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不起作用.

本博客已稳定运行
发表了49篇文章 · 总计83.39k字
本站总访问量 次 · 您是本站第 位访问者
粤ICP备2025368587号-1| 使用 Hugo 构建
主题 StackJimmy 设计