Restoring some code to sig_pri. Not sure if it is really needed.
[asterisk/asterisk.git] / channels / sig_pri.c
index 4e824c7..6d9bf66 100644 (file)
@@ -192,6 +192,22 @@ static inline int pri_grab(struct sig_pri_chan *p, struct sig_pri_pri *pri)
        return 0;
 }
 
+/*!
+ * \internal
+ * \brief Reset DTMF detector.
+ * \since 1.6.3
+ *
+ * \param p sig_pri channel structure.
+ *
+ * \return Nothing
+ */
+static void sig_pri_dsp_reset_and_flush_digits(struct sig_pri_chan *p)
+{
+       if (p->calls->dsp_reset_and_flush_digits) {
+               p->calls->dsp_reset_and_flush_digits(p->chan_pvt);
+       }
+}
+
 static int sig_pri_set_echocanceller(struct sig_pri_chan *p, int enable)
 {
        if (p->calls->set_echocanceller)
@@ -601,11 +617,16 @@ static void *pri_ss_thread(void *data)
        int len;
        int timeout;
 
+       if (!chan) {
+               /* We lost the owner before we could get started. */
+               return NULL;
+       }
+
        /*
         * In the bizarre case where the channel has become a zombie before we
         * even get started here, abort safely.
         */
-       if (!p) {
+       if (!chan->tech_pvt) {
                ast_log(LOG_WARNING, "Channel became a zombie before simple switch could be started (%s)\n", chan->name);
                ast_hangup(chan);
                return NULL;
@@ -613,6 +634,8 @@ static void *pri_ss_thread(void *data)
 
        ast_verb(3, "Starting simple switch on '%s'\n", chan->name);
 
+       sig_pri_dsp_reset_and_flush_digits(p);
+
        /* Now loop looking for an extension */
        ast_copy_string(exten, p->exten, sizeof(exten));
        len = strlen(exten);
@@ -647,6 +670,7 @@ static void *pri_ss_thread(void *data)
        if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num)) {
                /* Start the real PBX */
                ast_copy_string(chan->exten, exten, sizeof(chan->exten));
+               sig_pri_dsp_reset_and_flush_digits(p);
                sig_pri_set_echocanceller(p, 1);
                ast_setstate(chan, AST_STATE_RING);
                res = ast_pbx_run(chan);
@@ -666,7 +690,7 @@ static void *pri_ss_thread(void *data)
 exit:
        res = sig_pri_play_tone(p, SIG_PRI_TONE_CONGESTION);
        if (res < 0)
-                       ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
+               ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
        ast_hangup(chan);
        return NULL;
 }
@@ -1261,7 +1285,11 @@ static void *pri_dchannel(void *vpri)
                                                         * so other threads can send D channel messages.
                                                         */
                                                        ast_mutex_unlock(&pri->lock);
-                                                       c = sig_pri_new_ast_channel(pri->pvts[chanpos], AST_STATE_RESERVED, 0, (e->ring.layer1 = PRI_LAYER_1_ALAW) ? SIG_PRI_ALAW : SIG_PRI_ULAW, e->ring.ctype, pri->pvts[chanpos]->exten, NULL);
+                                                       c = sig_pri_new_ast_channel(pri->pvts[chanpos],
+                                                               AST_STATE_RESERVED, 0,
+                                                               (e->ring.layer1 == PRI_LAYER_1_ALAW)
+                                                                       ? SIG_PRI_ALAW : SIG_PRI_ULAW,
+                                                               e->ring.ctype, pri->pvts[chanpos]->exten, NULL);
                                                        ast_mutex_lock(&pri->lock);
                                                        if (c) {
                                                                if (!ast_strlen_zero(e->ring.callingsubaddr)) {
@@ -1306,7 +1334,11 @@ static void *pri_dchannel(void *vpri)
                                                         * so other threads can send D channel messages.
                                                         */
                                                        ast_mutex_unlock(&pri->lock);
-                                                       c = sig_pri_new_ast_channel(pri->pvts[chanpos], AST_STATE_RING, 0, (e->ring.layer1 == PRI_LAYER_1_ALAW) ? SIG_PRI_ALAW : SIG_PRI_ULAW, e->ring.ctype, pri->pvts[chanpos]->exten, NULL);
+                                                       c = sig_pri_new_ast_channel(pri->pvts[chanpos],
+                                                               AST_STATE_RING, 0,
+                                                               (e->ring.layer1 == PRI_LAYER_1_ALAW)
+                                                                       ? SIG_PRI_ALAW : SIG_PRI_ULAW, e->ring.ctype,
+                                                               pri->pvts[chanpos]->exten, NULL);
                                                        ast_mutex_lock(&pri->lock);
                                                        if (c) {
                                                                /*