[prev in list] [next in list] [prev in thread] [next in thread] 

List:       asterisk-dev
Subject:    Re: [asterisk-dev] [Code Review] 3362: func_periodic_hook: New function for periodic hooks.
From:       "Russell Bryant" <reviewboard () asterisk ! org>
Date:       2014-03-31 21:29:29
Message-ID: 20140331212929.19876.62401 () sonic ! digium ! api
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


> On March 31, 2014, 5:58 p.m., Corey Farrell wrote:
> > /trunk/funcs/func_periodic_hook.c, lines 141-143
> > <https://reviewboard.asterisk.org/r/3362/diff/6/?file=56951#file56951line141>
> > 
> > Macro is deprecated, why not use Gosub?
> 
> Russell Bryant wrote:
> I tried that.  GoSub() doesn't actually work in this case.  Perhaps because there's \
> no PBX running on the channel?  In any case, that's why. 
> rmudgett wrote:
> I haven't checked, but would calling this be appropriate here to avoid the adding \
> the need for Macro back into the code: int ast_app_exec_sub(struct ast_channel \
> *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int \
> ignore_hangup) 

Awesome. That sounds like the API call needed here. 


- Russell


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/3362/#review11455
-----------------------------------------------------------


On March 31, 2014, 8:33 p.m., Russell Bryant wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/3362/
> -----------------------------------------------------------
> 
> (Updated March 31, 2014, 8:33 p.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Repository: Asterisk
> 
> 
> Description
> -------
> 
> This commit introduces a new dialplan function, PERIODIC_HOOK().
> It allows you run to a dialplan hook on a channel periodically.  The
> original use case that inspired this was the ability to play a beep
> periodically into a call being recorded.  The implementation is much
> more generic though and could be used for many other things.
> 
> The implementation makes heavy use of existing Asterisk components.
> It uses a combination of Local channels and ChanSpy() to run some
> custom dialplan and inject any audio it generates into an active call.
> 
> The other important bit of the implementation is how it figures out
> when to trigger the beep playback.  This implementation uses the
> audiohook API, even though it's not actually touching the audio in any
> way.  It's a convenient way to get a callback and check if it's time
> to kick off another beep.  It would be nice if this was timer event
> based instead of polling based, but unfortunately I don't see a way to
> do it that won't interfere with other things.
> 
> 
> Diffs
> -----
> 
> /trunk/funcs/func_periodic_hook.c PRE-CREATION 
> /trunk/CHANGES 411572 
> 
> Diff: https://reviewboard.asterisk.org/r/3362/diff/
> 
> 
> Testing
> -------
> 
> Called the following extension (100@test), both letting it run all the way through, \
> as well as hanging up at various points in the middle. 
> 
> [macro-beep]
> 
> exten => s,1,Answer()
> same => n,Verbose(1,Channel name: ${ARG1})
> same => n,Verbose(1,Hook ID: ${ARG2})
> same => n,Playback(beep)
> 
> [test]
> 
> exten => 100,1,Answer()
> same => n,Set(BEEP_ID=${PERIODIC_HOOK(beep,5)})
> same => n,Wait(20)
> same => n,Set(PERIODIC_HOOK(${BEEP_ID})=off)
> same => n,Wait(20)
> same => n,Set(PERIODIC_HOOK(${BEEP_ID})=on)
> same => n,Wait(20)
> same => n,Hangup()
> 
> 
> Thanks,
> 
> Russell Bryant
> 
> 


[Attachment #5 (text/html)]

<html>
 <body>
  <div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
   <table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 \
solid;">  <tr>
     <td>
      This is an automatically generated e-mail. To reply, visit:
      <a href="https://reviewboard.asterisk.org/r/3362/">https://reviewboard.asterisk.org/r/3362/</a>
  </td>
    </tr>
   </table>
   <br />










<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;">  <p style="margin-top: 0;">On March 31st, 2014, 5:58 p.m. UTC, <b>Corey \
Farrell</b> wrote:</p>  <blockquote style="margin-left: 1em; border-left: 2px solid \
#d0d0d0; padding-left: 10px;">  



<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;">  <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;">  <a \
href="https://reviewboard.asterisk.org/r/3362/diff/6/?file=56951#file56951line141" \
style="color: black; font-weight: bold; text-decoration: \
underline;">/trunk/funcs/func_periodic_hook.c</a>  <span style="font-weight: \
normal;">

     (Diff revision 6)

    </span>
   </th>
  </tr>
 </thead>



 
 

 <tbody>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th>  <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>  <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">141</font></th>  <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="tb">	</span>ast_pbx_outgoing_app(&quot;Local&quot;, NULL, FULL_EXTEN_NAME, \
60,</pre></td>  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th>  <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>  <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">142</font></th>  <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="tb">	</span><span class="tb">	</span><span \
class="tb">	</span>&quot;Macro&quot;, macro_arg, NULL, 0, NULL, NULL, \
&amp;chan_name_var,</pre></td>  </tr>

  <tr>
    <th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2"></font></th>  <td bgcolor="#c5ffc4" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>  <th \
bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">143</font></th>  <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="tb">	</span><span class="tb">	</span><span class="tb">	</span>NULL, NULL, \
NULL);</pre></td>  </tr>

 </tbody>

</table>

  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Macro is deprecated, why \
not use Gosub?</pre>  </blockquote>



 <p>On March 31st, 2014, 8:31 p.m. UTC, <b>Russell Bryant</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;">  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">I tried that.  GoSub() \
doesn&#39;t actually work in this case.  Perhaps because there&#39;s no PBX running \
on the channel?  In any case, that&#39;s why.</pre>  </blockquote>





 <p>On March 31st, 2014, 8:47 p.m. UTC, <b>rmudgett</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;">  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">I haven&#39;t checked, \
but would calling this be appropriate here to avoid the adding the need for Macro \
back into the code: int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct \
ast_channel *sub_chan, const char *sub_args, int ignore_hangup) </pre>
 </blockquote>







</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Awesome. \
That sounds like the API call needed here. </pre> <br />




<p>- Russell</p>


<br />
<p>On March 31st, 2014, 8:33 p.m. UTC, Russell Bryant wrote:</p>








<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" \
style="background-image: \
url('https://reviewboard.asterisk.org/static/rb/images/review_request_box_top_bg.ab6f3b1072c9.png'); \
background-position: left top; background-repeat: repeat-x; border: 1px black \
solid;">  <tr>
  <td>

<div>Review request for Asterisk Developers.</div>
<div>By Russell Bryant.</div>


<p style="color: grey;"><i>Updated March 31, 2014, 8:33 p.m.</i></p>









<div style="margin-top: 1.5em;">
 <b style="color: #575012; font-size: 10pt;">Repository: </b>
Asterisk
</div>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
 <table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" \
style="border: 1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">    This commit introduces a new dialplan function, PERIODIC_HOOK().  It \
allows you run to a dialplan hook on a channel periodically.  The  original use case \
that inspired this was the ability to play a beep  periodically into a call being \
recorded.  The implementation is much  more generic though and could be used for many \
other things.  
    The implementation makes heavy use of existing Asterisk components.
    It uses a combination of Local channels and ChanSpy() to run some
    custom dialplan and inject any audio it generates into an active call.
    
    The other important bit of the implementation is how it figures out
    when to trigger the beep playback.  This implementation uses the
    audiohook API, even though it&#39;s not actually touching the audio in any
    way.  It&#39;s a convenient way to get a callback and check if it&#39;s time
    to kick off another beep.  It would be nice if this was timer event
    based instead of polling based, but unfortunately I don&#39;t see a way to
    do it that won&#39;t interfere with other things.
</pre>
  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: \
1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">Called the following extension (100@test), both letting it run all the \
way through, as well as hanging up at various points in the middle.



[macro-beep]

exten =&gt; s,1,Answer()
    same =&gt; n,Verbose(1,Channel name: ${ARG1})
    same =&gt; n,Verbose(1,Hook ID: ${ARG2})
    same =&gt; n,Playback(beep)

[test]

exten =&gt; 100,1,Answer()
    same =&gt; n,Set(BEEP_ID=${PERIODIC_HOOK(beep,5)})
    same =&gt; n,Wait(20)
    same =&gt; n,Set(PERIODIC_HOOK(${BEEP_ID})=off)
    same =&gt; n,Wait(20)
    same =&gt; n,Set(PERIODIC_HOOK(${BEEP_ID})=on)
    same =&gt; n,Wait(20)
    same =&gt; n,Hangup()
</pre>
  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">

 <li>/trunk/funcs/func_periodic_hook.c <span style="color: \
grey">(PRE-CREATION)</span></li>

 <li>/trunk/CHANGES <span style="color: grey">(411572)</span></li>

</ul>

<p><a href="https://reviewboard.asterisk.org/r/3362/diff/" style="margin-left: \
3em;">View Diff</a></p>







  </td>
 </tr>
</table>








  </div>
 </body>
</html>



-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic