<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17944">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">dsp: Translate non-PCM codecs if necessary<br><br>The DSP engine in Asterisk is currently only compatible<br>with PCM codecs (G.711 ulaw and alaw) and signed linear<br>audio. This usually isn't an issue, but this prevents<br>codecs like G.722 from being used if any kind of DSP<br>might be needed during the call, and the historical<br>restriction to PCM codecs is arbitrary in this regard.<br><br>This will now attempt to translate the current codec<br>to slin audio before bailing out immediately, as it<br>does now. This is only done on the processed frames,<br>as opposed to changing the codec used on the channel<br>itself.<br><br>Additionally, a misleading error message is updated<br>to provide a more accurate error to the user.<br><br>ASTERISK-29862 #close<br><br>Change-Id: I59740c7acc9c73b4dc20616a967be2b961856bbc<br>---<br>M main/dsp.c<br>1 file changed, 43 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/44/17944/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/dsp.c b/main/dsp.c</span><br><span>index 8b4e3ee..47d5462 100644</span><br><span>--- a/main/dsp.c</span><br><span>+++ b/main/dsp.c</span><br><span>@@ -68,6 +68,7 @@</span><br><span> #include "asterisk/options.h"</span><br><span> #include "asterisk/config.h"</span><br><span> #include "asterisk/test.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/translate.h"</span><br><span> </span><br><span> /*! Number of goertzels for progress detect */</span><br><span> enum gsamp_size {</span><br><span>@@ -437,6 +438,7 @@</span><br><span>        digit_detect_state_t digit_state;</span><br><span>    tone_detect_state_t cng_tone_state;</span><br><span>  tone_detect_state_t ced_tone_state;</span><br><span style="color: hsl(120, 100%, 40%);">+   struct ast_trans_pvt *trans_pvt; /*! Used to convert non-PCM codecs to SLIN if needed */</span><br><span> };</span><br><span> </span><br><span> static void mute_fragment(struct ast_dsp *dsp, fragment_t *fragment)</span><br><span>@@ -1529,12 +1531,44 @@</span><br><span>                         shortdata[x] = AST_ALAW(odata[x]);</span><br><span>           }</span><br><span>    } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                /*Display warning only once. Otherwise you would get hundreds of warnings every second */</span><br><span style="color: hsl(120, 100%, 40%);">+             int translated = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>                if (dsp->display_inband_dtmf_warning) {</span><br><span style="color: hsl(0, 100%, 40%);">-                      ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_format_get_name(af->subclass.format));</span><br><span style="color: hsl(120, 100%, 40%);">+                       if (!dsp->trans_pvt) {</span><br><span style="color: hsl(120, 100%, 40%);">+                             /* try to build a path from whatever codec is being used to slin */</span><br><span style="color: hsl(120, 100%, 40%);">+                           if (!(dsp->trans_pvt = ast_translator_build_path(ast_format_cache_get_slin_by_rate(DEFAULT_SAMPLE_RATE), af->subclass.format))) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                       ast_log(LOG_WARNING, "Cannot build a path from %s (%u) to signed linear\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                                         ast_format_get_name(af->subclass.format),</span><br><span style="color: hsl(120, 100%, 40%);">+                                          ast_format_get_codec_id(af->subclass.format));</span><br><span style="color: hsl(120, 100%, 40%);">+                             } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                                      ast_debug(1, "Successfully created translation path from %s (%u) to signed linear for DSP processing\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                                            ast_format_get_name(af->subclass.format),</span><br><span style="color: hsl(120, 100%, 40%);">+                                          ast_format_get_codec_id(af->subclass.format));</span><br><span style="color: hsl(120, 100%, 40%);">+                             }</span><br><span style="color: hsl(120, 100%, 40%);">+                     }</span><br><span style="color: hsl(120, 100%, 40%);">+                     if (dsp->trans_pvt) {</span><br><span style="color: hsl(120, 100%, 40%);">+                              /* Convert to slin, and allow the original frame to be freed */</span><br><span style="color: hsl(120, 100%, 40%);">+                               af = ast_translate(dsp->trans_pvt, af, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+                         /* update frame variables */</span><br><span style="color: hsl(120, 100%, 40%);">+                          odata = af->data.ptr;</span><br><span style="color: hsl(120, 100%, 40%);">+                              len = af->datalen;</span><br><span style="color: hsl(120, 100%, 40%);">+                         if (ast_format_cache_is_slinear(af->subclass.format)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                    shortdata = af->data.ptr;</span><br><span style="color: hsl(120, 100%, 40%);">+                                  len = af->datalen / 2;</span><br><span style="color: hsl(120, 100%, 40%);">+                                     translated = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+                               } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                                      ast_log(LOG_WARNING, "Codec translated, but not one of the cached slin formats\n");</span><br><span style="color: hsl(120, 100%, 40%);">+                         }</span><br><span style="color: hsl(120, 100%, 40%);">+                     }</span><br><span>            }</span><br><span style="color: hsl(0, 100%, 40%);">-               dsp->display_inband_dtmf_warning = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-                return af;</span><br><span style="color: hsl(120, 100%, 40%);">+            if (!translated) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    /* Display warning only once. Otherwise you would get hundreds of warnings every second */</span><br><span style="color: hsl(120, 100%, 40%);">+                    if (dsp->display_inband_dtmf_warning) {</span><br><span style="color: hsl(120, 100%, 40%);">+                            ast_log(LOG_WARNING, "Inband signaling is not supported on codec %s. Use RFC2833 or switch to G.711 codec\n", ast_format_get_name(af->subclass.format));</span><br><span style="color: hsl(120, 100%, 40%);">+                         dsp->display_inband_dtmf_warning = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+                      }</span><br><span style="color: hsl(120, 100%, 40%);">+                     return af;</span><br><span style="color: hsl(120, 100%, 40%);">+            }</span><br><span>    }</span><br><span> </span><br><span>        /* Initially we do not want to mute anything */</span><br><span>@@ -1741,6 +1775,8 @@</span><br><span>              ast_dsp_prog_reset(dsp);</span><br><span>             /* Initialize fax detector */</span><br><span>                ast_fax_detect_init(dsp);</span><br><span style="color: hsl(120, 100%, 40%);">+             /* Don't immediately build a translation path */</span><br><span style="color: hsl(120, 100%, 40%);">+          dsp->trans_pvt = NULL;</span><br><span>    }</span><br><span>    return dsp;</span><br><span> }</span><br><span>@@ -1772,6 +1808,9 @@</span><br><span> </span><br><span> void ast_dsp_free(struct ast_dsp *dsp)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+   if (dsp->trans_pvt) {</span><br><span style="color: hsl(120, 100%, 40%);">+              ast_translator_free_path(dsp->trans_pvt);</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span>    ast_free(dsp);</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17944">change 17944</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/17944"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I59740c7acc9c73b4dc20616a967be2b961856bbc </div>
<div style="display:none"> Gerrit-Change-Number: 17944 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>