[Asterisk-code-review] core: Don't play silence for Busy() and Congestion() applications. (asterisk[certified/16.8])

Joshua Colp asteriskteam at digium.com
Mon Jun 21 06:43:52 CDT 2021


Joshua Colp has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/16114 )


Change subject: core: Don't play silence for Busy() and Congestion() applications.
......................................................................

core: Don't play silence for Busy() and Congestion() applications.

When using the Busy() and Congestion() applications the
function ast_safe_sleep is used by wait_for_hangup to safely
wait on the channel. This function may send silence if Asterisk
is configured to do so using the transmit_silence option.

In a scenario where an answered channel dials a Local channel
either directly or through call forwarding and the Busy()
or Congestion() dialplan applications were executed with the
transmit_silence option enabled the busy or congestion
tone would not be heard.

This is because inband generation of tones (such as busy
and congestion) is stopped when other audio is sent to
the channel they are being played to. In the given
scenario the transmit_silence option would result in
silence being sent to the channel, thus stopping the
inband generation.

This change adds a variant of ast_safe_sleep which can be
used when silence should not be played to the channel. The
wait_for_hangup function has been updated to use this
resulting in the tones being generated as expected.

ASTERISK-29485

Change-Id: I066bfc987a3ad6f0ccc88e0af4cd63f6a4729133
---
M include/asterisk/channel.h
M main/channel.c
M main/pbx.c
3 files changed, 25 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/14/16114/1

diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 1013003..e960ff7 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -1908,6 +1908,17 @@
 int ast_safe_sleep(struct ast_channel *chan, int ms);
 
 /*!
+ * \brief Wait for a specified amount of time, looking for hangups, and do not generate silence
+ * \param chan channel to wait for
+ * \param ms length of time in milliseconds to sleep. This should never be less than zero.
+ * \details
+ * Waits for a specified amount of time, servicing the channel as required.
+ * \return returns -1 on hangup, otherwise 0.
+ * \note Unlike ast_safe_sleep this will not generate silence if Asterisk is configured to do so.
+ */
+int ast_safe_sleep_without_silence(struct ast_channel *chan, int ms);
+
+/*!
  * \brief Wait for a specified amount of time, looking for hangups and a condition argument
  * \param chan channel to wait for
  * \param ms length of time in milliseconds to sleep.
diff --git a/main/channel.c b/main/channel.c
index ad5d298..4ffcd76 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -1514,7 +1514,7 @@
 }
 
 /*! \brief Wait, look for hangups and condition arg */
-int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data)
+static int safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data, unsigned int generate_silence)
 {
 	struct ast_frame *f;
 	struct ast_silence_generator *silgen = NULL;
@@ -1526,7 +1526,7 @@
 	AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames);
 
 	/* If no other generator is present, start silencegen while waiting */
-	if (ast_opt_transmit_silence && !ast_channel_generatordata(chan)) {
+	if (generate_silence && ast_opt_transmit_silence && !ast_channel_generatordata(chan)) {
 		silgen = ast_channel_start_silence_generator(chan);
 	}
 
@@ -1584,10 +1584,20 @@
 	return res;
 }
 
+int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data)
+{
+	return safe_sleep_conditional(chan, timeout_ms, cond, data, 1);
+}
+
 /*! \brief Wait, look for hangups */
 int ast_safe_sleep(struct ast_channel *chan, int ms)
 {
-	return ast_safe_sleep_conditional(chan, ms, NULL, NULL);
+	return safe_sleep_conditional(chan, ms, NULL, NULL, 1);
+}
+
+int ast_safe_sleep_without_silence(struct ast_channel *chan, int ms)
+{
+	return safe_sleep_conditional(chan, ms, NULL, NULL, 0);
 }
 
 struct ast_channel *ast_channel_release(struct ast_channel *chan)
diff --git a/main/pbx.c b/main/pbx.c
index bbc6df9..5e08721 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -8256,7 +8256,7 @@
 		waitsec = -1;
 	if (waitsec > -1) {
 		waittime = waitsec * 1000.0;
-		ast_safe_sleep(chan, waittime);
+		ast_safe_sleep_without_silence(chan, waittime);
 	} else do {
 		res = ast_waitfor(chan, -1);
 		if (res < 0)

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16114
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: certified/16.8
Gerrit-Change-Id: I066bfc987a3ad6f0ccc88e0af4cd63f6a4729133
Gerrit-Change-Number: 16114
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210621/ba395982/attachment-0001.html>


More information about the asterisk-code-review mailing list