We have successfully avoided transcoding in the past by simply enforcing a single codec (g729) on all upstream and downstream trunks. We now however want to only offer alaw on calls from a certain downstream trunk.
We subsequently allowed g722,alaw,g729 on the upstream trunk (chan_sip) and set only the one downstream trunk (chan_iax2) to ‘alaw,g729’. First leg is correct, in that it elects alaw, and we subsequently set SIP_CODEC as a re-inheritable variable (__ prefix) to limit the codec choice as only ‘alaw’. When the 2nd leg of the call is made the offer however still includes the trunk’s preference:
-- Accepting AUTHENTICATED call from 22.214.171.124:4569: -- > requested format = g722, -- > requested prefs = (g722|alaw|g729), -- > actual format = alaw, -- > host prefs = (alaw|g729), -- > priority = mine -- Executing [[email protected]:1] Macro("IAX2/0115550000-15376", "user-callerid,LIMIT,EXTERNAL,") in new stack <snip> -- Executing [[email protected]:31] ExecIf("IAX2/0115550000-15376", "1?Set(__SIP_CODEC=alaw)") in new stack <snip> == Channel 'IAX2/0115550000-15376' jumping out of macro 'dialout-trunk-predial-hook' == Channel 'IAX2/0115550000-15376' jumping out of macro 'dialout-trunk' -- AGI Script Executing Application: (DIAL) Options: (SIP/Provider/27822222222,60,HRL(36000000:61000:30000)) > Limit Data for this call: > timelimit = 36000000 ms (36000.000 s) > play_warning = 61000 ms (61.000 s) > play_to_caller = yes > play_to_callee = no > warning_freq = 30000 ms (30.000 s) > start_sound = > warning_sound = timeleft > end_sound = == Using SIP RTP TOS bits 184 == Using SIP RTP CoS mark 5 Audio is at 14508 Adding codec alaw to SDP Adding codec g722 to SDP Adding codec g729 to SDP Adding non-codec 0x1 (telephone-event) to SDP Reliably Transmitting (NAT) to 126.96.36.199:5060: INVITE sip:[email protected] SIP/2.0 Via: SIP/2.0/UDP 188.8.131.52:5160;branch=z9hG4bK2b5e1142;rport Max-Forwards: 70 From: "User" <sip:[email protected]:5160>;tag=as0497eff5 To: <sip:[email protected]> Contact: <sip:[email protected]:5160> Call-ID: [email protected]:5160 CSeq: 102 INVITE User-Agent: FPBX-184.108.40.206(16.13.0) Date: Fri, 18 Sep 2020 15:57:29 GMT Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE Supported: replaces, timer Remote-Party-ID: "User" <sip:[email protected]>;party=calling;privacy=off;screen=yes Content-Type: application/sdp Content-Length: 319 v=0 o=root 485601917 485601917 IN IP4 220.127.116.11 s=Asterisk PBX 16.13.0 c=IN IP4 18.104.22.168 t=0 0 m=audio 14508 RTP/AVP 8 9 18 101 a=rtpmap:8 PCMA/8000 a=rtpmap:9 G722/8000 a=rtpmap:18 G729/8000 a=fmtp:18 annexb=no a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-16 a=ptime:20 a=maxptime:150 a=sendrecv --- -- Called SIP/Provider/27822222222
PS: I’ve confirmed that calling ‘DumpChan’ shows ‘SIP_CODEC=alaw’ being listed under ‘variables’.
Any tips on how I can override the offered codecs on an outgoing call?