<p>Igor Goncharovsky has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12803">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_unistim: Fix code, causing all incoming DTMF sent back to asterisk<br><br>Current implementation of ast_channel_tech send_digit_begin hook uses<br>same function for tone playback as key press handler. This cause every<br>incoming dtmf send back to asterisk. In case of two unistim phones<br>connected to each other, it'll cause indefinite DTMF loop. Fix add<br>separate function for dtmf tone phone play.<br><br>Change-Id: I5795db468df552f0c89c7576b6b3858b26c4eab4<br>---<br>M channels/chan_unistim.c<br>1 file changed, 28 insertions(+), 29 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/03/12803/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_unistim.c b/channels/chan_unistim.c</span><br><span>index b846585..845766d 100644</span><br><span>--- a/channels/chan_unistim.c</span><br><span>+++ b/channels/chan_unistim.c</span><br><span>@@ -3332,22 +3332,12 @@</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static int unistim_do_senddigit(struct unistimsession *pte, char digit)</span><br><span style="color: hsl(120, 100%, 40%);">+static int send_dtmf_tone(struct unistimsession *pte, char digit)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_frame f = { .frametype = AST_FRAME_DTMF, .subclass.integer = digit, .src = "unistim" };</span><br><span style="color: hsl(0, 100%, 40%);">- struct unistim_subchannel *sub;</span><br><span style="color: hsl(0, 100%, 40%);">- int row, col;</span><br><span style="color: hsl(120, 100%, 40%);">+ int row, col;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- sub = get_sub(pte->device, SUB_REAL);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!sub || !sub->owner || sub->alreadygone) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Unable to find subchannel in dtmf senddigit\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- /* Send DTMF indication _before_ playing sounds */</span><br><span style="color: hsl(0, 100%, 40%);">- ast_queue_frame(sub->owner, &f);</span><br><span> if (unistimdebug) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_verb(0, "Send Digit %c (%i ms)\n", digit, pte->device->dtmfduration);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_verb(0, "Phone Play Digit %c\n", digit);</span><br><span> }</span><br><span> if (pte->device->dtmfduration > 0) {</span><br><span> row = (digit - '1') % 3;</span><br><span>@@ -3365,6 +3355,28 @@</span><br><span> } else {</span><br><span> send_tone(pte, 500, 2000);</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</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%);">+static int unistim_do_senddigit(struct unistimsession *pte, char digit)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_frame f = { .frametype = AST_FRAME_DTMF, .subclass.integer = digit, .src = "unistim" };</span><br><span style="color: hsl(120, 100%, 40%);">+ struct unistim_subchannel *sub;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ sub = get_sub(pte->device, SUB_REAL);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!sub || !sub->owner || sub->alreadygone) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Unable to find subchannel in dtmf senddigit\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return -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%);">+ /* Send DTMF indication _before_ playing sounds */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_queue_frame(sub->owner, &f);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (pte->device->dtmfduration > 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (unistimdebug) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_verb(0, "Send Digit %c (%i ms)\n", digit, pte->device->dtmfduration);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ send_dtmf_tone(pte, digit);</span><br><span> usleep(pte->device->dtmfduration * 1000); /* XXX Less than perfect, blocking an important thread is not a good idea */</span><br><span> send_tone(pte, 0, 0);</span><br><span> }</span><br><span>@@ -5507,34 +5519,21 @@</span><br><span> if (!pte) {</span><br><span> return -1;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- return unistim_do_senddigit(pte, digit);</span><br><span style="color: hsl(120, 100%, 40%);">+ return send_dtmf_tone(pte, digit);</span><br><span> }</span><br><span> </span><br><span> static int unistim_senddigit_end(struct ast_channel *ast, char digit, unsigned int duration)</span><br><span> {</span><br><span> struct unistimsession *pte = channel_to_session(ast);</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_frame f = { 0, };</span><br><span style="color: hsl(0, 100%, 40%);">- struct unistim_subchannel *sub;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- sub = get_sub(pte->device, SUB_REAL);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!sub || !sub->owner || sub->alreadygone) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_WARNING, "Unable to find subchannel in dtmf senddigit_end\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!pte) {</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span> if (unistimdebug) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_verb(0, "Send Digit off %c\n", digit);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (!pte) {</span><br><span style="color: hsl(0, 100%, 40%);">- return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_verb(0, "Send Digit off %c (duration %d)\n", digit, duration);</span><br><span> }</span><br><span> send_tone(pte, 0, 0);</span><br><span style="color: hsl(0, 100%, 40%);">- f.frametype = AST_FRAME_DTMF;</span><br><span style="color: hsl(0, 100%, 40%);">- f.subclass.integer = digit;</span><br><span style="color: hsl(0, 100%, 40%);">- f.src = "unistim";</span><br><span style="color: hsl(0, 100%, 40%);">- ast_queue_frame(sub->owner, &f);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12803">change 12803</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/+/12803"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I5795db468df552f0c89c7576b6b3858b26c4eab4 </div>
<div style="display:none"> Gerrit-Change-Number: 12803 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Igor Goncharovsky <igor.goncharovsky@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>