<p>Michael Bradeen has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/20004">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">bridge_builtin_features: add beep via touch variable<br><br>Add periodic beep option to one-touch recording by setting<br>the touch variable TOUCH_MONITOR_BEEP or<br>TOUCH_MIXMONITOR_BEEP to the desired interval in seconds.<br><br>If the interval is less than 5 seconds, a minimum of 5<br>seconds will be imposed.  If the interval is set to an<br>invalid value, it will default to 15 seconds.<br><br>A new test event PERIODIC_HOOK_ENABLED was added to the<br>func_periodic_hook hook_on function to indicate when<br>a hook is started.  This is so we can test that the touch<br>variable starts the hook as expected.<br><br>ASTERISK-30446<br><br>Change-Id: I800e494a789ba7a930bbdcd717e89d86040d6661<br>---<br>M bridges/bridge_builtin_features.c<br>A doc/CHANGES-staging/bridge_builtin_features_beep_on_monitor.txt<br>M funcs/func_periodic_hook.c<br>M main/features_config.c<br>4 files changed, 97 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/04/20004/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/bridges/bridge_builtin_features.c b/bridges/bridge_builtin_features.c</span><br><span>index 671cfb9..9f8143e 100644</span><br><span>--- a/bridges/bridge_builtin_features.c</span><br><span>+++ b/bridges/bridge_builtin_features.c</span><br><span>@@ -53,6 +53,7 @@</span><br><span> #include "asterisk/mixmonitor.h"</span><br><span> #include "asterisk/audiohook.h"</span><br><span> #include "asterisk/causes.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/beep.h"</span><br><span> </span><br><span> enum set_touch_variables_res {</span><br><span>     SET_TOUCH_SUCCESS,</span><br><span>@@ -78,12 +79,13 @@</span><br><span>     }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-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)</span><br><span style="color: hsl(120, 100%, 40%);">+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)</span><br><span> {</span><br><span>         enum set_touch_variables_res res = SET_TOUCH_UNSET;</span><br><span>  const char *var_format;</span><br><span>      const char *var_monitor;</span><br><span>     const char *var_prefix;</span><br><span style="color: hsl(120, 100%, 40%);">+       const char *var_beep;</span><br><span> </span><br><span>    SCOPED_CHANNELLOCK(lock, chan);</span><br><span> </span><br><span>@@ -91,14 +93,17 @@</span><br><span>            var_format = "TOUCH_MIXMONITOR_FORMAT";</span><br><span>            var_monitor = "TOUCH_MIXMONITOR";</span><br><span>          var_prefix = "TOUCH_MIXMONITOR_PREFIX";</span><br><span style="color: hsl(120, 100%, 40%);">+             var_beep = "TOUCH_MIXMONITOR_BEEP";</span><br><span>        } else {</span><br><span>             var_format = "TOUCH_MONITOR_FORMAT";</span><br><span>               var_monitor = "TOUCH_MONITOR";</span><br><span>             var_prefix = "TOUCH_MONITOR_PREFIX";</span><br><span style="color: hsl(120, 100%, 40%);">+                var_beep = "TOUCH_MONITOR_BEEP";</span><br><span>   }</span><br><span>    set_touch_variable(&res, chan, var_format, touch_format);</span><br><span>        set_touch_variable(&res, chan, var_monitor, touch_monitor);</span><br><span>      set_touch_variable(&res, chan, var_prefix, touch_monitor_prefix);</span><br><span style="color: hsl(120, 100%, 40%);">+ set_touch_variable(&res, chan, var_beep, touch_monitor_beep);</span><br><span> </span><br><span>        return res;</span><br><span> }</span><br><span>@@ -141,20 +146,22 @@</span><br><span>     char *touch_filename;</span><br><span>        size_t len;</span><br><span>  int x;</span><br><span style="color: hsl(120, 100%, 40%);">+        char beep_id[64] = "";</span><br><span>     enum set_touch_variables_res set_touch_res;</span><br><span> </span><br><span>      RAII_VAR(char *, touch_format, NULL, ast_free);</span><br><span>      RAII_VAR(char *, touch_monitor, NULL, ast_free);</span><br><span>     RAII_VAR(char *, touch_monitor_prefix, NULL, ast_free);</span><br><span style="color: hsl(120, 100%, 40%);">+       RAII_VAR(char *, touch_monitor_beep, NULL, ast_free);</span><br><span> </span><br><span>    set_touch_res = set_touch_variables(bridge_channel->chan, 0, &touch_format,</span><br><span style="color: hsl(0, 100%, 40%);">-              &touch_monitor, &touch_monitor_prefix);</span><br><span style="color: hsl(120, 100%, 40%);">+               &touch_monitor, &touch_monitor_prefix, &touch_monitor_beep);</span><br><span>     switch (set_touch_res) {</span><br><span>     case SET_TOUCH_SUCCESS:</span><br><span>              break;</span><br><span>       case SET_TOUCH_UNSET:</span><br><span>                set_touch_res = set_touch_variables(peer_chan, 0, &touch_format, &touch_monitor,</span><br><span style="color: hsl(0, 100%, 40%);">-                        &touch_monitor_prefix);</span><br><span style="color: hsl(120, 100%, 40%);">+                   &touch_monitor_prefix, &touch_monitor_beep);</span><br><span>                 if (set_touch_res == SET_TOUCH_ALLOC_FAILURE) {</span><br><span>                      return;</span><br><span>              }</span><br><span>@@ -195,7 +202,28 @@</span><br><span> </span><br><span>         ast_verb(4, "AutoMonitor used to record call. Filename: %s\n", touch_filename);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   if (ast_monitor_start(peer_chan, touch_format, touch_filename, 1, X_REC_IN | X_REC_OUT, NULL)) {</span><br><span style="color: hsl(120, 100%, 40%);">+      if (!ast_strlen_zero(touch_monitor_beep)) {</span><br><span style="color: hsl(120, 100%, 40%);">+           unsigned int interval = 15;</span><br><span style="color: hsl(120, 100%, 40%);">+           if (sscanf(touch_monitor_beep, "%30u", &interval) != 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+                       ast_log(LOG_WARNING, "Invalid interval '%s' for periodic beep. Using default of %u\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                                              touch_monitor_beep, interval);</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 (interval > 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                        if (interval < 5) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                interval = 5;</span><br><span style="color: hsl(120, 100%, 40%);">+                         ast_log(LOG_WARNING, "Interval '%s' too small for periodic beep. Using minimum of %u\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                                            touch_monitor_beep, interval);</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 (ast_beep_start(peer_chan, interval, beep_id, sizeof(beep_id))) {</span><br><span style="color: hsl(120, 100%, 40%);">+                          ast_log(LOG_WARNING, "Unable to enable periodic beep, please ensure func_periodic_hook is loaded.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+                              return;</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%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (ast_monitor_start(peer_chan, touch_format, touch_filename, 1, X_REC_IN | X_REC_OUT, beep_id)) {</span><br><span>          ast_verb(4, "AutoMonitor feature was tried by '%s' but monitor failed to start.\n",</span><br><span>                        ast_channel_name(bridge_channel->chan));</span><br><span>          return;</span><br><span>@@ -322,7 +350,7 @@</span><br><span> </span><br><span> 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)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-       char *touch_filename;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *touch_filename, mix_options[32] = "b";</span><br><span>       size_t len;</span><br><span>  int x;</span><br><span>       enum set_touch_variables_res set_touch_res;</span><br><span>@@ -330,15 +358,16 @@</span><br><span>  RAII_VAR(char *, touch_format, NULL, ast_free);</span><br><span>      RAII_VAR(char *, touch_monitor, NULL, ast_free);</span><br><span>     RAII_VAR(char *, touch_monitor_prefix, NULL, ast_free);</span><br><span style="color: hsl(120, 100%, 40%);">+       RAII_VAR(char *, touch_monitor_beep, NULL, ast_free);</span><br><span> </span><br><span>    set_touch_res = set_touch_variables(bridge_channel->chan, 1, &touch_format,</span><br><span style="color: hsl(0, 100%, 40%);">-              &touch_monitor, &touch_monitor_prefix);</span><br><span style="color: hsl(120, 100%, 40%);">+               &touch_monitor, &touch_monitor_prefix, &touch_monitor_beep);</span><br><span>     switch (set_touch_res) {</span><br><span>     case SET_TOUCH_SUCCESS:</span><br><span>              break;</span><br><span>       case SET_TOUCH_UNSET:</span><br><span>                set_touch_res = set_touch_variables(peer_chan, 1, &touch_format, &touch_monitor,</span><br><span style="color: hsl(0, 100%, 40%);">-                        &touch_monitor_prefix);</span><br><span style="color: hsl(120, 100%, 40%);">+                   &touch_monitor_prefix, &touch_monitor_beep);</span><br><span>                 if (set_touch_res == SET_TOUCH_ALLOC_FAILURE) {</span><br><span>                      return;</span><br><span>              }</span><br><span>@@ -381,7 +410,22 @@</span><br><span> </span><br><span>         ast_verb(4, "AutoMixMonitor used to record call. Filename: %s\n", touch_filename);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-        if (ast_start_mixmonitor(peer_chan, touch_filename, "b")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(touch_monitor_beep)) {</span><br><span style="color: hsl(120, 100%, 40%);">+           unsigned int interval = 15;</span><br><span style="color: hsl(120, 100%, 40%);">+           if (sscanf(touch_monitor_beep, "%30u", &interval) != 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+                       ast_log(LOG_WARNING, "Invalid interval '%s' for periodic beep. Using default of %u\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                                              touch_monitor_beep, interval);</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 (interval < 5) {</span><br><span style="color: hsl(120, 100%, 40%);">+                        interval = 5;</span><br><span style="color: hsl(120, 100%, 40%);">+                 ast_log(LOG_WARNING, "Interval '%s' too small for periodic beep. Using minimum of %u\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                                    touch_monitor_beep, interval);</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+             snprintf(mix_options, sizeof(mix_options), "bB(%d)", interval);</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 (ast_start_mixmonitor(peer_chan, touch_filename, mix_options)) {</span><br><span>          ast_verb(4, "AutoMixMonitor feature was tried by '%s' but MixMonitor failed to start.\n",</span><br><span>                  ast_channel_name(bridge_channel->chan));</span><br><span> </span><br><span>diff --git a/doc/CHANGES-staging/bridge_builtin_features_beep_on_monitor.txt b/doc/CHANGES-staging/bridge_builtin_features_beep_on_monitor.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..39bf9a7</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/bridge_builtin_features_beep_on_monitor.txt</span><br><span>@@ -0,0 +1,12 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: bridge_builtin_features</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Add optional touch variable : TOUCH_MIXMONITOR_BEEP(interval)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Setting TOUCH_MIXMONITOR_BEEP/TOUCH_MONITOR_BEEP to a valid</span><br><span style="color: hsl(120, 100%, 40%);">+interval in seconds will result in a periodic beep being</span><br><span style="color: hsl(120, 100%, 40%);">+played to the monitored channel upon MixMontior/Monitor</span><br><span style="color: hsl(120, 100%, 40%);">+feature start.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+If an interval less than 5 seconds is specified, the interval</span><br><span style="color: hsl(120, 100%, 40%);">+will default to 5 seconds.  If the value is set to an invalid</span><br><span style="color: hsl(120, 100%, 40%);">+interval, the default of 15 seconds will be used.</span><br><span>diff --git a/funcs/func_periodic_hook.c b/funcs/func_periodic_hook.c</span><br><span>index 3c7b93e..ec4b9ba 100644</span><br><span>--- a/funcs/func_periodic_hook.c</span><br><span>+++ b/funcs/func_periodic_hook.c</span><br><span>@@ -40,6 +40,7 @@</span><br><span> #include "asterisk/pbx.h"</span><br><span> #include "asterisk/app.h"</span><br><span> #include "asterisk/audiohook.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/test.h"</span><br><span> #define AST_API_MODULE</span><br><span> #include "asterisk/beep.h"</span><br><span> </span><br><span>@@ -343,6 +344,8 @@</span><br><span> </span><br><span>        ast_debug(1, "hook to %s@%s enabled on %s with interval of %u seconds\n",</span><br><span>                  args.exten, args.context, ast_channel_name(chan), interval);</span><br><span style="color: hsl(120, 100%, 40%);">+  ast_test_suite_event_notify("PERIODIC_HOOK_ENABLED", "Exten: %s\r\nChannel: %s\r\nInterval: %u\r\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                      args.exten, ast_channel_name(chan), interval);</span><br><span> </span><br><span>   return init_hook(chan, args.context, args.exten, interval, hook_id);</span><br><span> }</span><br><span>diff --git a/main/features_config.c b/main/features_config.c</span><br><span>index ba2f905..97ace55 100644</span><br><span>--- a/main/features_config.c</span><br><span>+++ b/main/features_config.c</span><br><span>@@ -199,6 +199,9 @@</span><br><span>                                                 channel variable or <literal>auto</literal> if the variable is not set. The timestamp</span><br><span>                                            is a UNIX timestamp. The suffix is either the value of the <replaceable>TOUCH_MONITOR</replaceable></span><br><span>                                              channel variable or the callerID of the channels if the variable is not set.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                             <para>To play a periodic beep while this call is being recorded, set the</span><br><span style="color: hsl(120, 100%, 40%);">+                                                <replaceable>TOUCH_MONITOR_BEEP</replaceable> to the interval in seconds. The interval will default</span><br><span style="color: hsl(120, 100%, 40%);">+                                               to 15 seconds if invalid.  The minimum interval is 5 seconds.</para></span><br><span>                                   </description></span><br><span>                                         <see-also><ref type="configOption">automixmon</ref></see-also></span><br><span>                             </configOption></span><br><span>@@ -215,6 +218,9 @@</span><br><span>                                          channel variable or <literal>auto</literal> if the variable is not set. The timestamp</span><br><span>                                            is a UNIX timestamp. The suffix is either the value of the <replaceable>TOUCH_MIXMONITOR</replaceable></span><br><span>                                           channel variable or the callerID of the channels if the variable is not set.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                             <para>To play a periodic beep while this call is being recorded, set the</span><br><span style="color: hsl(120, 100%, 40%);">+                                                <replaceable>TOUCH_MIXMONITOR_BEEP</replaceable> to the interval in seconds. The interval will default</span><br><span style="color: hsl(120, 100%, 40%);">+                                            to 15 seconds if invalid.  The minimum interval is 5 seconds.</para></span><br><span>                                   </description></span><br><span>                                         <see-also><ref type="configOption">automon</ref></see-also></span><br><span>                                </configOption></span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/20004">change 20004</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/+/20004"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 20 </div>
<div style="display:none"> Gerrit-Change-Id: I800e494a789ba7a930bbdcd717e89d86040d6661 </div>
<div style="display:none"> Gerrit-Change-Number: 20004 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Michael Bradeen <mbradeen@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>