[Asterisk-code-review] bridge_builtin_features: add beep via touch variable (asterisk[certified/18.9])

Friendly Automation asteriskteam at digium.com
Mon Mar 20 08:22:31 CDT 2023


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/19976 )

Change subject: bridge_builtin_features: add beep via touch variable
......................................................................

bridge_builtin_features: add beep via touch variable

Add periodic beep option to one-touch recording by setting
the touch variable TOUCH_MONITOR_BEEP or
TOUCH_MIXMONITOR_BEEP to the desired interval in seconds.

If the interval is less than 5 seconds, a minimum of 5
seconds will be imposed.  If the interval is set to an
invalid value, it will default to 15 seconds.

A new test event PERIODIC_HOOK_ENABLED was added to the
func_periodic_hook hook_on function to indicate when
a hook is started.  This is so we can test that the touch
variable starts the hook as expected.

ASTERISK-30446

Change-Id: I800e494a789ba7a930bbdcd717e89d86040d6661
---
M bridges/bridge_builtin_features.c
A doc/CHANGES-staging/bridge_builtin_features_beep_on_monitor.txt
M funcs/func_periodic_hook.c
M main/features_config.c
4 files changed, 107 insertions(+), 13 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit




diff --git a/bridges/bridge_builtin_features.c b/bridges/bridge_builtin_features.c
index 671cfb9..9f8143e 100644
--- a/bridges/bridge_builtin_features.c
+++ b/bridges/bridge_builtin_features.c
@@ -53,6 +53,7 @@
 #include "asterisk/mixmonitor.h"
 #include "asterisk/audiohook.h"
 #include "asterisk/causes.h"
+#include "asterisk/beep.h"
 
 enum set_touch_variables_res {
 	SET_TOUCH_SUCCESS,
@@ -78,12 +79,13 @@
 	}
 }
 
-static enum set_touch_variables_res set_touch_variables(struct ast_channel *chan, int is_mixmonitor, char **touch_format, char **touch_monitor, char **touch_monitor_prefix)
+static enum set_touch_variables_res set_touch_variables(struct ast_channel *chan, int is_mixmonitor, char **touch_format, char **touch_monitor, char **touch_monitor_prefix, char **touch_monitor_beep)
 {
 	enum set_touch_variables_res res = SET_TOUCH_UNSET;
 	const char *var_format;
 	const char *var_monitor;
 	const char *var_prefix;
+	const char *var_beep;
 
 	SCOPED_CHANNELLOCK(lock, chan);
 
@@ -91,14 +93,17 @@
 		var_format = "TOUCH_MIXMONITOR_FORMAT";
 		var_monitor = "TOUCH_MIXMONITOR";
 		var_prefix = "TOUCH_MIXMONITOR_PREFIX";
+		var_beep = "TOUCH_MIXMONITOR_BEEP";
 	} else {
 		var_format = "TOUCH_MONITOR_FORMAT";
 		var_monitor = "TOUCH_MONITOR";
 		var_prefix = "TOUCH_MONITOR_PREFIX";
+		var_beep = "TOUCH_MONITOR_BEEP";
 	}
 	set_touch_variable(&res, chan, var_format, touch_format);
 	set_touch_variable(&res, chan, var_monitor, touch_monitor);
 	set_touch_variable(&res, chan, var_prefix, touch_monitor_prefix);
+	set_touch_variable(&res, chan, var_beep, touch_monitor_beep);
 
 	return res;
 }
@@ -141,20 +146,22 @@
 	char *touch_filename;
 	size_t len;
 	int x;
+	char beep_id[64] = "";
 	enum set_touch_variables_res set_touch_res;
 
 	RAII_VAR(char *, touch_format, NULL, ast_free);
 	RAII_VAR(char *, touch_monitor, NULL, ast_free);
 	RAII_VAR(char *, touch_monitor_prefix, NULL, ast_free);
+	RAII_VAR(char *, touch_monitor_beep, NULL, ast_free);
 
 	set_touch_res = set_touch_variables(bridge_channel->chan, 0, &touch_format,
-		&touch_monitor, &touch_monitor_prefix);
+		&touch_monitor, &touch_monitor_prefix, &touch_monitor_beep);
 	switch (set_touch_res) {
 	case SET_TOUCH_SUCCESS:
 		break;
 	case SET_TOUCH_UNSET:
 		set_touch_res = set_touch_variables(peer_chan, 0, &touch_format, &touch_monitor,
-			&touch_monitor_prefix);
+			&touch_monitor_prefix, &touch_monitor_beep);
 		if (set_touch_res == SET_TOUCH_ALLOC_FAILURE) {
 			return;
 		}
@@ -195,7 +202,28 @@
 
 	ast_verb(4, "AutoMonitor used to record call. Filename: %s\n", touch_filename);
 
-	if (ast_monitor_start(peer_chan, touch_format, touch_filename, 1, X_REC_IN | X_REC_OUT, NULL)) {
+	if (!ast_strlen_zero(touch_monitor_beep)) {
+		unsigned int interval = 15;
+		if (sscanf(touch_monitor_beep, "%30u", &interval) != 1) {
+			ast_log(LOG_WARNING, "Invalid interval '%s' for periodic beep. Using default of %u\n",
+						touch_monitor_beep, interval);
+		}
+
+		if (interval > 0) {
+			if (interval < 5) {
+				interval = 5;
+				ast_log(LOG_WARNING, "Interval '%s' too small for periodic beep. Using minimum of %u\n",
+						touch_monitor_beep, interval);
+			}
+
+			if (ast_beep_start(peer_chan, interval, beep_id, sizeof(beep_id))) {
+				ast_log(LOG_WARNING, "Unable to enable periodic beep, please ensure func_periodic_hook is loaded.\n");
+				return;
+			}
+		}
+	}
+
+	if (ast_monitor_start(peer_chan, touch_format, touch_filename, 1, X_REC_IN | X_REC_OUT, beep_id)) {
 		ast_verb(4, "AutoMonitor feature was tried by '%s' but monitor failed to start.\n",
 			ast_channel_name(bridge_channel->chan));
 		return;
@@ -322,7 +350,7 @@
 
 static void start_automixmonitor(struct ast_bridge_channel *bridge_channel, struct ast_channel *peer_chan, struct ast_features_general_config *features_cfg, const char *start_message)
 {
-	char *touch_filename;
+	char *touch_filename, mix_options[32] = "b";
 	size_t len;
 	int x;
 	enum set_touch_variables_res set_touch_res;
@@ -330,15 +358,16 @@
 	RAII_VAR(char *, touch_format, NULL, ast_free);
 	RAII_VAR(char *, touch_monitor, NULL, ast_free);
 	RAII_VAR(char *, touch_monitor_prefix, NULL, ast_free);
+	RAII_VAR(char *, touch_monitor_beep, NULL, ast_free);
 
 	set_touch_res = set_touch_variables(bridge_channel->chan, 1, &touch_format,
-		&touch_monitor, &touch_monitor_prefix);
+		&touch_monitor, &touch_monitor_prefix, &touch_monitor_beep);
 	switch (set_touch_res) {
 	case SET_TOUCH_SUCCESS:
 		break;
 	case SET_TOUCH_UNSET:
 		set_touch_res = set_touch_variables(peer_chan, 1, &touch_format, &touch_monitor,
-			&touch_monitor_prefix);
+			&touch_monitor_prefix, &touch_monitor_beep);
 		if (set_touch_res == SET_TOUCH_ALLOC_FAILURE) {
 			return;
 		}
@@ -381,7 +410,22 @@
 
 	ast_verb(4, "AutoMixMonitor used to record call. Filename: %s\n", touch_filename);
 
-	if (ast_start_mixmonitor(peer_chan, touch_filename, "b")) {
+	if (!ast_strlen_zero(touch_monitor_beep)) {
+		unsigned int interval = 15;
+		if (sscanf(touch_monitor_beep, "%30u", &interval) != 1) {
+			ast_log(LOG_WARNING, "Invalid interval '%s' for periodic beep. Using default of %u\n",
+						touch_monitor_beep, interval);
+		}
+
+		if (interval < 5) {
+			interval = 5;
+			ast_log(LOG_WARNING, "Interval '%s' too small for periodic beep. Using minimum of %u\n",
+					touch_monitor_beep, interval);
+		}
+		snprintf(mix_options, sizeof(mix_options), "bB(%d)", interval);
+	}
+
+	if (ast_start_mixmonitor(peer_chan, touch_filename, mix_options)) {
 		ast_verb(4, "AutoMixMonitor feature was tried by '%s' but MixMonitor failed to start.\n",
 			ast_channel_name(bridge_channel->chan));
 
diff --git a/doc/CHANGES-staging/bridge_builtin_features_beep_on_monitor.txt b/doc/CHANGES-staging/bridge_builtin_features_beep_on_monitor.txt
new file mode 100644
index 0000000..39bf9a7
--- /dev/null
+++ b/doc/CHANGES-staging/bridge_builtin_features_beep_on_monitor.txt
@@ -0,0 +1,12 @@
+Subject: bridge_builtin_features
+
+Add optional touch variable : TOUCH_MIXMONITOR_BEEP(interval)
+
+Setting TOUCH_MIXMONITOR_BEEP/TOUCH_MONITOR_BEEP to a valid
+interval in seconds will result in a periodic beep being
+played to the monitored channel upon MixMontior/Monitor
+feature start.
+
+If an interval less than 5 seconds is specified, the interval
+will default to 5 seconds.  If the value is set to an invalid
+interval, the default of 15 seconds will be used.
diff --git a/funcs/func_periodic_hook.c b/funcs/func_periodic_hook.c
index 6b90ee3..9592088 100644
--- a/funcs/func_periodic_hook.c
+++ b/funcs/func_periodic_hook.c
@@ -40,6 +40,7 @@
 #include "asterisk/pbx.h"
 #include "asterisk/app.h"
 #include "asterisk/audiohook.h"
+#include "asterisk/test.h"
 #define AST_API_MODULE
 #include "asterisk/beep.h"
 
@@ -343,6 +344,8 @@
 
 	ast_debug(1, "hook to %s@%s enabled on %s with interval of %u seconds\n",
 			args.exten, args.context, ast_channel_name(chan), interval);
+	ast_test_suite_event_notify("PERIODIC_HOOK_ENABLED", "Exten: %s\r\nChannel: %s\r\nInterval: %u\r\n",
+			args.exten, ast_channel_name(chan), interval);
 
 	return init_hook(chan, args.context, args.exten, interval, hook_id);
 }
diff --git a/main/features_config.c b/main/features_config.c
index 50ca69b..a0410d1 100644
--- a/main/features_config.c
+++ b/main/features_config.c
@@ -198,16 +198,27 @@
 						channel variable or <literal>auto</literal> if the variable is not set. The timestamp
 						is a UNIX timestamp. The filename is either the value of the <replaceable>TOUCH_MONITOR</replaceable>
 						channel variable or the callerID of the channels if the variable is not set.</para>
+						<para>To play a periodic beep while this call is being recorded, set the
+						<replaceable>TOUCH_MONITOR_BEEP</replaceable> to the interval in seconds. The interval will default
+						to 15 seconds if invalid.  The minimum interval is 5 seconds.</para>
 					</description>
 				</configOption>
 				<configOption name="automixmon">
 					<synopsis>DTMF sequence to start or stop mixmonitoring a call </synopsis>
 					<description>
-						<para>Operation of the automixmon is similar to the <literal> automon </literal>
-						feature, with the following exceptions:
-							<replaceable>TOUCH_MIXMONITOR</replaceable> is used in place of <replaceable>TOUCH_MONITOR</replaceable>
-							<replaceable>TOUCH_MIXMONITOR_FORMAT</replaceable> is used in place of <replaceable>TOUCH_MIXMONITOR</replaceable>
-							There is no equivalent for <replaceable>TOUCH_MONITOR_PREFIX</replaceable>. <literal>"auto"</literal> is always how the filename begins.</para>
+						<para>This will cause the channel that pressed the DTMF sequence
+						to be monitored by the <literal>MixMonitor</literal> application. The
+						format for the recording is determined by the <replaceable>TOUCH_MIXMONITOR_FORMAT</replaceable>
+						channel variable. If this variable is not specified, then <literal>wav</literal> is the
+						default. The filename is constructed in the following manner:</para>
+						<para>    prefix-timestamp-suffix.fmt</para>
+						<para>where prefix is either the value of the <replaceable>TOUCH_MIXMONITOR_PREFIX</replaceable>
+						channel variable or <literal>auto</literal> if the variable is not set. The timestamp
+						is a UNIX timestamp. The suffix is either the value of the <replaceable>TOUCH_MIXMONITOR</replaceable>
+						channel variable or the callerID of the channels if the variable is not set.</para>
+						<para>To play a periodic beep while this call is being recorded, set the
+						<replaceable>TOUCH_MIXMONITOR_BEEP</replaceable> to the interval in seconds. The interval will default
+						to 15 seconds if invalid.  The minimum interval is 5 seconds.</para>
 					</description>
 					<see-also><ref type="configOption">automon</ref></see-also>
 				</configOption>

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

Gerrit-Project: asterisk
Gerrit-Branch: certified/18.9
Gerrit-Change-Id: I800e494a789ba7a930bbdcd717e89d86040d6661
Gerrit-Change-Number: 19976
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230320/ac5f830a/attachment-0001.html>


More information about the asterisk-code-review mailing list