<p>Joshua Colp has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16074">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core: Don't play silence for Busy() and Congestion() applications.<br><br>When using the Busy() and Congestion() applications the<br>function ast_safe_sleep is used by wait_for_hangup to safely<br>wait on the channel. This function may send silence if Asterisk<br>is configured to do so using the transmit_silence option.<br><br>In a scenario where an answered channel dials a Local channel<br>either directly or through call forwarding and the Busy()<br>or Congestion() dialplan applications were executed with the<br>transmit_silence option enabled the busy or congestion<br>tone would not be heard.<br><br>This is because inband generation of tones (such as busy<br>and congestion) is stopped when other audio is sent to<br>the channel they are being played to. In the given<br>scenario the transmit_silence option would result in<br>silence being sent to the channel, thus stopping the<br>inband generation.<br><br>This change adds a variant of ast_safe_sleep which can be<br>used when silence should not be played to the channel. The<br>wait_for_hangup function has been updated to use this<br>resulting in the tones being generated as expected.<br><br>ASTERISK-29485<br><br>Change-Id: I066bfc987a3ad6f0ccc88e0af4cd63f6a4729133<br>---<br>M include/asterisk/channel.h<br>M main/channel.c<br>M main/pbx.c<br>3 files changed, 25 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/74/16074/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h</span><br><span>index 5bf6c51..e5d7151 100644</span><br><span>--- a/include/asterisk/channel.h</span><br><span>+++ b/include/asterisk/channel.h</span><br><span>@@ -1908,6 +1908,17 @@</span><br><span> int ast_safe_sleep(struct ast_channel *chan, int ms);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Wait for a specified amount of time, looking for hangups, and do not generate silence</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param chan channel to wait for</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param ms length of time in milliseconds to sleep. This should never be less than zero.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \details</span><br><span style="color: hsl(120, 100%, 40%);">+ * Waits for a specified amount of time, servicing the channel as required.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return returns -1 on hangup, otherwise 0.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note Unlike ast_safe_sleep this will not generate silence if Asterisk is configured to do so.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_safe_sleep_without_silence(struct ast_channel *chan, int ms);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Wait for a specified amount of time, looking for hangups and a condition argument</span><br><span> * \param chan channel to wait for</span><br><span> * \param ms length of time in milliseconds to sleep.</span><br><span>diff --git a/main/channel.c b/main/channel.c</span><br><span>index f27a0a3..27d6730 100644</span><br><span>--- a/main/channel.c</span><br><span>+++ b/main/channel.c</span><br><span>@@ -1514,7 +1514,7 @@</span><br><span> }</span><br><span> </span><br><span> /*! \brief Wait, look for hangups and condition arg */</span><br><span style="color: hsl(0, 100%, 40%);">-int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+static int safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data, unsigned int generate_silence)</span><br><span> {</span><br><span> struct ast_frame *f;</span><br><span> struct ast_silence_generator *silgen = NULL;</span><br><span>@@ -1526,7 +1526,7 @@</span><br><span> AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);</span><br><span> </span><br><span> /* If no other generator is present, start silencegen while waiting */</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_opt_transmit_silence && !ast_channel_generatordata(chan)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (generate_silence && ast_opt_transmit_silence && !ast_channel_generatordata(chan)) {</span><br><span> silgen = ast_channel_start_silence_generator(chan);</span><br><span> }</span><br><span> </span><br><span>@@ -1584,10 +1584,20 @@</span><br><span> return res;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return safe_sleep_conditional(chan, timeout_ms, cond, data, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief Wait, look for hangups */</span><br><span> int ast_safe_sleep(struct ast_channel *chan, int ms)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- return ast_safe_sleep_conditional(chan, ms, NULL, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ return safe_sleep_conditional(chan, ms, NULL, NULL, 1);</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%);">+int ast_safe_sleep_without_silence(struct ast_channel *chan, int ms)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return safe_sleep_conditional(chan, ms, NULL, NULL, 0);</span><br><span> }</span><br><span> </span><br><span> struct ast_channel *ast_channel_release(struct ast_channel *chan)</span><br><span>diff --git a/main/pbx.c b/main/pbx.c</span><br><span>index 0609240..d0ee127 100644</span><br><span>--- a/main/pbx.c</span><br><span>+++ b/main/pbx.c</span><br><span>@@ -8275,7 +8275,7 @@</span><br><span> waitsec = -1;</span><br><span> if (waitsec > -1) {</span><br><span> waittime = waitsec * 1000.0;</span><br><span style="color: hsl(0, 100%, 40%);">- ast_safe_sleep(chan, waittime);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_safe_sleep_without_silence(chan, waittime);</span><br><span> } else do {</span><br><span> res = ast_waitfor(chan, -1);</span><br><span> if (res < 0)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16074">change 16074</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/+/16074"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I066bfc987a3ad6f0ccc88e0af4cd63f6a4729133 </div>
<div style="display:none"> Gerrit-Change-Number: 16074 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>