[Home]

Summary:ASTERISK-28785: chan_local: Unnecessary transcoding for Originate (local channels)
Reporter:laszlovl (lvl)Labels:
Date Opened:2020-03-20 06:20:52Date Closed:2020-04-02 04:44:56
Priority:MinorRegression?
Status:Closed/CompleteComponents:Channels/chan_local
Versions:16.8.0 Frequency of
Occurrence
Related
Issues:
is related toASTERISK-20461 channel originate Local/foo * forces translation via slin
Environment:Attachments:
Description:When using (Asterisk Manager) Originate and {{Channel}} is a local channel, Asterisk will sometimes perform unnecessary transcoding, in particular back and forth to slin.

It's hard to describe the bug here thoroughly, because the exact behavior greatly varies between Asterisk versions, Asterisk configuration (particularly allow/disallowed codecs), client, and client configuration (particuarly supported codecs).

I'll focus on a couple of examples here to illustrate. Output is from Asterisk 16.8.0 unless otherwise noted.

Asterisk configuration that I investigated but did **not** make a difference:

* genericplc
* transcode_via_sln
* dtmf_mode

In some scenario's, Asterisk's behavior is random with about 50% of the calls performing unnecessary transcoding (and thus simple bridging), and the other 50% being fine (and thus native bridging).

I identified this commit which - I'm not sure why - changed one of the scenario's to "fail" 100% of the time instead of 50% of the time: https://github.com/asterisk/asterisk/commit/a46fcaca7bcb019a1a2b29d3c9a528da637840d7

So, to reproduce, f.e. let's take a very basic sipp client that'll accept incoming calls and only talks g722. Also take a very basic dialplan to process originates:

{code}
   originate-from => {
       Dial(PJSIP/callee,10,L(5500));
   }
   
   originate-to => {
       Dial(PJSIP/callee);
   }
{code}

Consider the following configuration for the callee endpoint:

{code}
disallow=all
allow=opus
allow=g722
allow=alaw
allow=ulaw
allow=gsm
{code}

Now run an originate:

{code}
   cdict['Channel'] = 'Local/originate-from@default'
   cdict['Context'] = 'default'
   cdict['Exten'] = 'originate-to'
   cdict['Priority'] = '1'
{code}

After local channel optimization is done, Asterisk will end up with two channels, both performing a useless transcode to slin:

{code}
[('WriteTranscode', 'Yes', '(slin@16000)->(g722@16000)'), ('ReadTranscode', 'Yes', '(g722@16000)->(slin@16000)')]
[('NativeFormats', '(g722)'), ('WriteFormat', 'slin16'), ('ReadFormat', 'slin16'), ('Formats', '(g722|slin)')]
[('WriteTranscode', 'Yes', '(slin@16000)->(g722@16000)'), ('ReadTranscode', 'Yes', '(g722@16000)->(slin@16000)')]
[('NativeFormats', '(g722)'), ('WriteFormat', 'slin16'), ('ReadFormat', 'slin16'), ('Formats', '(g722|slin)')]
{code}

Note that bypassing the local channel...

{code}
   cdict['Channel'] = 'PJSIP/callee';
{code}

.. means everything is fine:

{code}
[('WriteTranscode', 'No', ''), ('ReadTranscode', 'No', '')]
[('NativeFormats', '(g722)'), ('WriteFormat', 'g722'), ('ReadFormat', 'g722'), ('Formats', '(g722)')]
[('WriteTranscode', 'No', ''), ('ReadTranscode', 'No', '')]
[('NativeFormats', '(g722)'), ('WriteFormat', 'g722'), ('ReadFormat', 'g722'), ('Formats', '(g722)')]
{code}

Back to the local channel. Playing with the {{codecs}} option for Originate will cause greatly varying results. For example, bringing it in line with the PJSIP codec list..

{code}
   cdict['Codecs'] = 'opus,g722,alaw,ulaw,gsm'
{code}

.. apparently makes Asterisk factor in opus, even though none of the two resulting PJSIP channels can use opus:

{code}
[('WriteTranscode', 'Yes', '(slin@48000)->(slin@16000)->(g722@16000)'), ('ReadTranscode', 'Yes', '(g722@16000)->(slin@16000)->(slin@48000)')]
[('NativeFormats', '(g722)'), ('WriteFormat', 'slin48'), ('ReadFormat', 'slin48'), ('Formats', '(g722)')]
[('WriteTranscode', 'Yes', '(slin@48000)->(slin@16000)->(g722@16000)'), ('ReadTranscode', 'Yes', '(g722@16000)->(slin@16000)->(slin@48000)')]
[('NativeFormats', '(g722)'), ('WriteFormat', 'slin48'), ('ReadFormat', 'slin48'), ('Formats', '(g722|opus)')]
{code}

While removing opus..

{code}
   cdict['Codecs'] = 'g722,alaw,ulaw,gsm'
{code}

.. magically fixes everything:

{code}
[('WriteTranscode', 'No', ''), ('ReadTranscode', 'No', '')]
[('NativeFormats', '(g722)'), ('WriteFormat', 'g722'), ('ReadFormat', 'g722'), ('Formats', '(g722)')]
[('WriteTranscode', 'No', ''), ('ReadTranscode', 'No', '')]
[('NativeFormats', '(g722)'), ('WriteFormat', 'g722'), ('ReadFormat', 'g722'), ('Formats', '(g722)')]
{code}

There's many more variations of the problem I could show, but it looks like the essence of the problem is always the same: local channels instantly "lock down" their preferred codec, without considering the channel they are bridged to. Sometimes this is corrected after the optimization, depending on seemingly unrelated (timing) factors, but most often it isn't.
Comments:By: Asterisk Team (asteriskteam) 2020-03-20 06:20:53.503-0500

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].

Please note that once your issue enters an open state it has been accepted. As Asterisk is an open source project there is no guarantee or timeframe on when your issue will be looked into. If you need expedient resolution you will need to find and pay a suitable developer. Asking for an update on your issue will not yield any progress on it and will not result in a response. All updates are posted to the issue when they occur.

By: Joshua C. Colp (jcolp) 2020-03-31 09:52:04.211-0500

After looking at things I believe this is the same fundamental issue as ASTERISK-20461. If you'd like to add additional information and data there that would be welcome.

By: laszlovl (lvl) 2020-04-02 02:57:52.333-0500

Thanks. Didn't catch that one in my search, but I think you're right. Added some additional information there.

By: Asterisk Team (asteriskteam) 2020-04-02 02:57:53.398-0500

This issue has been reopened as a result of your commenting on it as the reporter. It will be triaged once again as applicable.