Index: channels/chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.399
diff -u -r1.399 chan_zap.c
--- channels/chan_zap.c	15 Jan 2005 21:51:37 -0000	1.399
+++ channels/chan_zap.c	17 Jan 2005 12:07:29 -0000
@@ -582,6 +582,7 @@
 	int alreadyhungup;
 	int proceeding;
 	int setup_ack;		/* wheter we received SETUP_ACKNOWLEDGE or not */
+	int dsp_features;
 #endif	
 #ifdef ZAPATA_R2
 	int r2prot;
@@ -4468,6 +4469,7 @@
 	pbx_builtin_setvar_helper(chan, "CALLTYPE", s);
 }
 #endif
+
 static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int index, int law, int ctype)
 {
 	struct ast_channel *tmp;
@@ -4543,6 +4545,15 @@
 			} else {
 				i->dsp = ast_dsp_new();
 				if (i->dsp) {
+#ifdef ZAPATA_PRI
+					/* We cannot do progress detection until receives PROGRESS message */
+					if (i->outgoing && (i->sig == SIG_PRI)) {
+						/* Remember requested DSP features, don't treat
+						   talking as ANSWER */
+						i->dsp_features = features & ~DSP_PROGRESS_TALK;
+						features = 0;
+					}
+#endif
 					ast_dsp_set_features(i->dsp, features);
 					ast_dsp_digitmode(i->dsp, DSP_DIGITMODE_DTMF | i->dtmfrelax);
 					if (!ast_strlen_zero(progzone))
@@ -7869,6 +7880,18 @@
 							pri->pvts[chanpos]->proceeding=2;
 						} else
 							ast_log(LOG_DEBUG, "Deferring ringing notification because of extra digits to dial...\n");
+#ifdef PRI_PROGRESS_MASK
+						if (e->ringing.progressmask & PRI_PROG_INBAND_AVAILABLE) {
+#else
+						if (e->ringing.progress == 8) {
+#endif
+							/* Now we can do call progress detection */
+							if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
+								/* RINGING detection isn't required because we got ALERTING signal */
+								ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features & ~DSP_PROGRESS_RINGING);
+								pri->pvts[chanpos]->dsp_features = 0;
+							}
+						}
 						ast_mutex_unlock(&pri->pvts[chanpos]->lock);
 					}
 				}
@@ -7883,7 +7906,18 @@
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
 						ast_log(LOG_DEBUG, "Queuing frame from PRI_EVENT_PROGRESS on channel %d/%d span %d\n",
 								pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset,pri->span);
-							zap_queue_frame(pri->pvts[chanpos], &f, pri);
+						zap_queue_frame(pri->pvts[chanpos], &f, pri);
+#ifdef PRI_PROGRESS_MASK
+						if (e->proceeding.progressmask & PRI_PROG_INBAND_AVAILABLE) {
+#else
+						if (e->proceeding.progress == 8) {
+#endif
+							/* Now we can do call progress detection */
+							if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
+								ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
+								pri->pvts[chanpos]->dsp_features = 0;
+							}
+						}
 						ast_mutex_unlock(&pri->pvts[chanpos]->lock);
 					}
 				}
@@ -7901,6 +7935,17 @@
 						f.subclass = AST_CONTROL_PROCEEDING;
 						zap_queue_frame(pri->pvts[chanpos], &f, pri);
 						pri->pvts[chanpos]->proceeding=2;
+#ifdef PRI_PROGRESS_MASK
+						if (e->proceeding.progressmask & PRI_PROG_INBAND_AVAILABLE) {
+#else
+						if (e->proceeding.progress == 8) {
+#endif
+							/* Now we can do call progress detection */
+							if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
+								ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
+								pri->pvts[chanpos]->dsp_features = 0;
+							}
+						}
 						ast_mutex_unlock(&pri->pvts[chanpos]->lock);
 					}
 				}
@@ -7944,6 +7989,17 @@
 						chanpos = -1;
 					} else {
 						ast_mutex_lock(&pri->pvts[chanpos]->lock);
+#ifdef PRI_PROGRESS_MASK
+						if (e->answer.progressmask & PRI_PROG_INBAND_AVAILABLE) {
+#else
+						if (e->answer.progress == 8) {
+#endif
+							/* Now we can do call progress detection */
+							if(pri->pvts[chanpos]->dsp && pri->pvts[chanpos]->dsp_features) {
+								ast_dsp_set_features(pri->pvts[chanpos]->dsp, pri->pvts[chanpos]->dsp_features);
+								pri->pvts[chanpos]->dsp_features = 0;
+							}
+						}
 						if (pri->pvts[chanpos]->realcall && (pri->pvts[chanpos]->realcall->sig == SIG_FXSKS)) {
 							ast_log(LOG_DEBUG, "Starting up GR-303 trunk now that we got CONNECT...\n");
 							x = ZT_START;
