Transcoding, or maybe not?


#1

Hi all

I am using Asterisk 16.0.0 / PJSIP in a setup where internal phones support and prefer G.722 over G.711 A/U which they also support. Support for G.722 from/to my ITSP trunk varies from call to call and is therefore not known in advance. This usually leads to asterisk doing unnecessary transcoding G.722 <-> G711A when placing an outbound call from an internal phone to my ITSP trunk.

In order to eliminate this unnecessary transcoding, I implemented a small pre-bridge-handler that is executed after the outbound call leg to my ITSP has been established and the codec in use on othe outbound call leg is known. It then adjusts the codec on the inbound call leg to use the same codec, which should eliminate the need for transcoding.

[adj-codec]

exten => s,1,Set(LOCAL(cl)=${MASTER_CHANNEL(CHANNEL(audionativeformat)):1:-1})
 same => n,Set(LOCAL(cib)=${CUT(cl,|,1)})
 same => n,Set(LOCAL(cl)=${CHANNEL(audionativeformat):1:-1})
 same => n,Set(LOCAL(cob)=${CUT(cl,|,1)})
 same => n,GotoIf($["${LOCAL(cob)}" = "${LOCAL(cib)}"]?equal)
 same => n,Set(MASTER_CHANNEL(PJSIP_MEDIA_OFFER(audio))=!all,${LOCAL(cob)})
 same => n,Set(MASTER_CHANNEL(PJSIP_SEND_SESSION_REFRESH())=invite)
 same => n(equal),Return()

Basically it seems to do what it’s supposed to. Using the CLI, ‘pjsip show channelstats’ reports both channels as using alaw, also ‘bridge show XXXX’ reports that the bridge is using ‘native_rtp’ technology:

 BridgeId ChannelId ........ UpTime.. Codec.   Count    Lost Pct  Jitter   Count    Lost Pct  Jitter RTT....
 ===========================================================================================================

 198308fe 604-00000027       00:00:09 alaw      328       0    0   0.000    340       0    0   0.000   0.000
 198308fe 608-00000028       00:00:09 alaw      340       0    0   0.000    328       0    0   0.001   0.000



Id: 198308fe-95d9-44db-802c-013d4f197523
Type: basic
Technology: native_rtp
Num-Channels: 2
Channel: PJSIP/604-00000027
Channel: PJSIP/608-00000028

However, looking at the individual channels using ‘core show channel PJSIP/XXXXX’ seems to give some rather odd information.

For the inbound call leg’s channel I get:

  NativeFormats: (alaw)
    WriteFormat: alaw
     ReadFormat: alaw
 WriteTranscode: Yes (slin@16000)->(slin@8000)->(alaw@8000)
  ReadTranscode: Yes (slin@16000)->(slin@8000)->(alaw@8000)

And for the outbound call leg’s channel:

  NativeFormats: (alaw)
    WriteFormat: slin16
     ReadFormat: slin16
 WriteTranscode: Yes (slin@16000)->(slin@8000)->(alaw@8000)
  ReadTranscode: Yes (alaw@8000)->(slin@8000)->(slin@16000)

Something here just doesn’t seem to add up. Is asterisk actually doing any transcoding or not?