Opus codec bandwidth

Hi,

Im not sure why, but Opus codec is ignoring max_bandwidth parameter. Parameter can be added in codecs.conf, but if you will check tcpdump trace, this parameter is ignored.

In codecs.conf im adding:

[opus8]
type=opus
bitrate=8000
cbr=yes
packet_loss=5
max_bandwidth=narrow

endpoints for sure have this codec assigned using:

allow=opus8

But if you will start tcpdump and capture such call you will find that used bandwidth is around 60kbps in case of SRTP (in wireshark statistics->protocol hierarchy). 60kbps is very far from 8kbps,

Is there any way to limit bandwidth for opus? Please help,

Best regards and thanks,

Please post the sip trace of the call.

Also, were the observed packets coming from or going to Asterisk?

Hello,
Please find enclosed sip and rtp trace (because of sire limitation i wasnt able to enclose capture).

res_txt.txt (917.2 KB)

In INVITE and Ok200 you will see that opus was negociated, Checking Statistics->Protocol Hierarchy is showing that RTP for this call (in both directions) is using 43kbps. If you will replace rtp with srtp single call will use 67kbps-90kbps. so the limit:

bitrate=8000
max_bandwidth=narrow

Does not work. In 4G environment it will work, but for most 2G and some 2.5G/3G it wont. Is ther any way to limit opus traffic per call? I check this for both chan sip and chan pjsip. Behaviour is the same.

Best regards,

Codec was installed from downloads.digium.com/pub/telephony/codec_opus:

wget http://downloads.digium.com/pub/telephony/codec_opus/asterisk-13.0/x86-64/codec_opus-13.0_current-x86_64.tar.gz

tar -xvzf codec_opus-13.0_current-x86_64.tar.gz

cd codec_opus-13.0_1.1.0-x86_64

cp codec_opus.so /usr/lib/asterisk/modules/

cp codec_opus_config-en_US.xml /var/lib/asterisk/documentation/thirdparty

This behaviour is reproducable for both asterisk 13 and 15.

Unfortunately that trace does not have the SDP included. Can you post the SDP for the invite and 200 OK. If it’s easier you can get a sip trace directly from the Asterisk log/console by turning on sip debugging for the channel driver. For instance:

*CLI> pjsip set logger on

Sorry for delay,

Please find enclosed SIP trace with SDP. This is incoming call, so SDP from asterisk is in OK 200:

<— SIP read from UDP:192.168.1.173:48866 —>
INVITE sip:999@192.168.13.33 SIP/2.0
Via: SIP/2.0/UDP 10.0.2.15:1043;rport;branch=z9hG4bKPj483cbb9e2ff64ac295e4c88f9ed3be8b
Max-Forwards: 70
From: sip:504@192.168.13.33;tag=65def2f85f21457e8ce6a80d015ac579
To: sip:999@192.168.13.33
Contact: sip:504@10.0.2.15:1043;ob
Call-ID: 283a025397fe426d94298469aabd9503
CSeq: 5536 INVITE
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Supported: replaces, 100rel, timer, norefersub
Session-Expires: 1800
Min-SE: 90
User-Agent: MicroSIP/3.19.10
Authorization: Digest username=“504”, realm=“asterisk”, nonce=“534f3196”, uri="sip:999@192.168.13.33", response=“3817f473a850db5f180372b4fd3cab2d”, algorithm=MD5
Content-Type: application/sdp
Content-Length: 414

v=0
o=- 3758425327 3758425327 IN IP4 10.0.2.15
s=pjmedia
b=AS:67
t=0 0
a=X-nat:0
m=audio 4002 RTP/AVP 123 101
c=IN IP4 10.0.2.15
b=TIAS:48000
a=rtcp:4003 IN IP4 10.0.2.15
a=sendrecv
a=rtpmap:123 opus/48000/2
a=fmtp:123 maxplaybackrate=24000;sprop-maxcapturerate=24000;maxaveragebitrate=20000;useinbandfec=1
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ssrc:1741099167 cname:1fd556cd0feb13f5
<------------->
— (16 headers 16 lines) —
Sending to 192.168.1.173:48866 (NAT)
Using INVITE request as basis request - 283a025397fe426d94298469aabd9503
Found peer ‘504’ for ‘504’ from 192.168.1.173:48866
== Using SIP RTP CoS mark 5
Found RTP audio format 123
Found RTP audio format 101
Found audio description format opus for ID 123
Found audio description format telephone-event for ID 101
Capabilities: us - (opus8|ulaw|alaw|g722|gsm|speex|ilbc), peer - audio=(opus)/video=(nothing)/text=(nothing), combined - (opus8)
Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x1 (telephone-event|), combined - 0x1 (telephone-event|)
Peer audio RTP is at port 10.0.2.15:4002
Looking for 999 in mcs-ctx (domain 192.168.13.33)
sip_route_dump: route/path hop: sip:504@10.0.2.15:1043;ob

<— Transmitting (NAT) to 192.168.1.173:48866 —>
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.0.2.15:1043;branch=z9hG4bKPj483cbb9e2ff64ac295e4c88f9ed3be8b;received=192.168.1.173;rport=48866
From: sip:504@192.168.13.33;tag=65def2f85f21457e8ce6a80d015ac579
To: sip:999@192.168.13.33
Call-ID: 283a025397fe426d94298469aabd9503
CSeq: 5536 INVITE
Server: Asterisk PBX 13.6.0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Session-Expires: 1800;refresher=uas
Contact: sip:999@192.168.13.33:5060
Content-Length: 0

<------------>
– Executing [999@mcs-ctx:1] Answer(“SIP/504-00000000”, “”) in new stack
Audio is at 19174
Adding codec opus8 to SDP
Adding codec ulaw to SDP
Adding codec alaw to SDP
Adding codec g722 to SDP
Adding codec gsm to SDP
Adding codec speex to SDP
Adding codec ilbc to SDP
Adding non-codec 0x1 (telephone-event) to SDP

<— Reliably Transmitting (NAT) to 192.168.1.173:48866 —>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.0.2.15:1043;branch=z9hG4bKPj483cbb9e2ff64ac295e4c88f9ed3be8b;received=192.168.1.173;rport=48866
From: sip:504@192.168.13.33;tag=65def2f85f21457e8ce6a80d015ac579
To: sip:999@192.168.13.33;tag=as43be82d6
Call-ID: 283a025397fe426d94298469aabd9503
CSeq: 5536 INVITE
Server: Asterisk PBX 13.6.0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Session-Expires: 1800;refresher=uas
Contact: sip:999@192.168.13.33:5060
Content-Type: application/sdp
Require: timer
Content-Length: 560

v=0
o=root 1372000500 1372000500 IN IP4 192.168.13.33
s=Asterisk PBX 13.6.0
c=IN IP4 192.168.13.33
t=0 0
m=audio 19174 RTP/AVP 123 0 8 9 3 110 97 101
a=rtpmap:123 opus/48000/2
a=fmtp:123 maxplaybackrate=48000;sprop-maxcapturerate=48000;minptime=10;maxaveragebitrate=20000;stereo=0;sprop-stereo=0;cbr=0;useinbandfec=0;usedtx=0
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:9 G722/8000
a=rtpmap:3 GSM/8000
a=rtpmap:110 speex/8000
a=rtpmap:97 iLBC/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:20
a=sendrecv

<------------>

<— SIP read from UDP:192.168.1.173:48866 —>
ACK sip:999@192.168.13.33:5060 SIP/2.0
Via: SIP/2.0/UDP 10.0.2.15:1043;rport;branch=z9hG4bKPjb3a6f84b4173499f82020b6a65093b02
Max-Forwards: 70
From: sip:504@192.168.13.33;tag=65def2f85f21457e8ce6a80d015ac579
To: sip:999@192.168.13.33;tag=as43be82d6
Call-ID: 283a025397fe426d94298469aabd9503
CSeq: 5536 ACK
Content-Length: 0

<------------->
— (8 headers 0 lines) —
> 0x7f4c28009e50 – Probation passed - setting RTP source address to 192.168.1.173:58663
– Executing [999@mcs-ctx:2] Echo(“SIP/504-00000000”, “”) in new stack
> 0x7f4c28009e50 – Probation passed - setting RTP source address to 192.168.1.173:58663
[Feb 6 07:37:43] WARNING[19517]: chan_mgcp.c:667 retrans_pkt: Maximum retries exceeded for transaction 4 on [192.168.1.137]
[Feb 6 07:37:43] NOTICE[19517]: chan_mgcp.c:2834 handle_response: Transaction 4 timed out
[Feb 6 07:37:44] WARNING[19517]: chan_mgcp.c:667 retrans_pkt: Maximum retries exceeded for transaction 5 on [192.168.1.137]
[Feb 6 07:37:44] NOTICE[19517]: chan_mgcp.c:2834 handle_response: Transaction 5 timed out

<— SIP read from UDP:192.168.1.173:48866 —>
BYE sip:999@192.168.13.33:5060 SIP/2.0
Via: SIP/2.0/UDP 10.0.2.15:1043;rport;branch=z9hG4bKPj0bc8886caad040daaa76ac7ca3054e6a
Max-Forwards: 70
From: sip:504@192.168.13.33;tag=65def2f85f21457e8ce6a80d015ac579
To: sip:999@192.168.13.33;tag=as43be82d6
Call-ID: 283a025397fe426d94298469aabd9503
CSeq: 5537 BYE
User-Agent: MicroSIP/3.19.10
Content-Length: 0

Used config in codecs.conf:

[opus8]
type=opus
bitrate=8000
cbr=yes
packet_loss=5
max_bandwidth=narrow
max_playback_rate=8000

For this test i used chan_sip. But in chan pjsip (on my diffrent installation) behaviour is the same. max_playback_rate is ignored. In config is 8000, but in SDP is:

a=fmtp:123 maxplaybackrate=48000;sprop-maxcapturerate=48000;minptime=10;maxaveragebitrate=20000;stereo=0;sprop-stereo=0;cbr=0;useinbandfec=0;usedtx=0

This endpoint config:

my-codecs ; a template for my preferred codecs
disallow=all
allow=opus8
allow=ulaw
allow=alaw
allow=g722
allow=gsm
allow=speex
allow=ilbc
allow=isac

natted-phone ; another template inheriting basic-options
directmedia=no
host=dynamic
nat=force_rport,comedia

504
secret = pass
mailbox=504
callerid=“Test1 <504>”

Best regards

So Asterisk’s response is odd:

Several of the fmtp parameters do not match with your configuration. Further Asterisk does not add default parameters to the fmtp line. Nor is minptime even added to the line ever. What version of Asterisk are you running?

Note, the reason you are seeing your rates is because according to the SDP your maxplaybackrate is 48,000 thus the codec will operate up to full band

This test was made on Asterisk 13.6.0 and chan_sip,
But i have another installation with Asterisk 15.2.2 with chan_pjsip and the behaviour is the same.

Parameter names in codecs.conf for sure are ok, because if you will insert wrong name during service restart you will get message “unrecognized codec opus8” and all endpoints will get “unauthorized”.

For both installations im using codec_opus-13.0_1.3.0-x86_64. I am able to enable fec, cbr. But im not able to manage bitrate/bandwidth. Good info is that you can limit it on endpoint side and asterisk will comply. If you will set default opus on asterisk (without any customization) and you will limit bandwidth on softphone (by setting proper parameters in sdp on clients side) asterisk will use lower bandwidth.

codec_opus transcoding was not officially supported in Asterisk until a much later version of 13 than you are running. Also there have been several patches to the codec opus format attribute handling code since then as well.

I’d recommend upgrading to the latest version of Asterisk, 13.24.1 or 16.1.1, and re-testing.

1 Like