[asterisk-commits] irroot: branch irroot/t38gateway-1.8 r327409 - in /team/irroot/t38gateway-1.8...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jul 10 09:20:28 CDT 2011


Author: irroot
Date: Sun Jul 10 09:20:24 2011
New Revision: 327409

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=327409
Log:
Changes to chan_ooh323 to fully backport changes to trunk

Modified:
    team/irroot/t38gateway-1.8/addons/chan_ooh323.c
    team/irroot/t38gateway-1.8/configs/chan_ooh323.conf.sample

Modified: team/irroot/t38gateway-1.8/addons/chan_ooh323.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/t38gateway-1.8/addons/chan_ooh323.c?view=diff&rev=327409&r1=327408&r2=327409
==============================================================================
--- team/irroot/t38gateway-1.8/addons/chan_ooh323.c (original)
+++ team/irroot/t38gateway-1.8/addons/chan_ooh323.c Sun Jul 10 09:20:24 2011
@@ -84,6 +84,9 @@
 #define T38_DISABLED 0
 #define T38_ENABLED 1
 #define T38_FAXGW 1
+
+#define FAXDETECT_CNG	1
+#define FAXDETECT_T38	2
 
 /* Channel description */
 static const char type[] = "OOH323";
@@ -334,7 +337,7 @@
 static struct ast_codec_pref gPrefs;
 static int  gDTMFMode = H323_DTMF_RFC2833;
 static int  gDTMFCodec = 101;
-static int  gFAXdetect = 1;
+static int  gFAXdetect = FAXDETECT_CNG;
 static int  gT38Support = T38_FAXGW;
 static char gGatekeeper[100];
 static enum RasGatekeeperMode gRasGkMode = RasNoGatekeeper;
@@ -432,7 +435,7 @@
 		ast_module_ref(myself);
 
 		/* Allocate dsp for in-band DTMF support */
-		if ((i->dtmfmode & H323_DTMF_INBAND) || i->faxdetect) {
+		if ((i->dtmfmode & H323_DTMF_INBAND) || (i->faxdetect & FAXDETECT_CNG)) {
 			i->vad = ast_dsp_new();
 		}
 
@@ -445,7 +448,7 @@
 		}
 
 		/* fax detection*/
-		if (i->faxdetect) {
+		if (i->faxdetect & FAXDETECT_CNG) {
 			features |= DSP_FEATURE_FAX_DETECT;
 			ast_dsp_set_faxmode(i->vad,
 					DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED);
@@ -2370,9 +2373,23 @@
 				user->dtmfcodec = atoi(v->value);
 			} else if (!strcasecmp(v->name, "faxdetect")) {
 				if (ast_true(v->value)) {
-					user->faxdetect = 1;
+					user->faxdetect = FAXDETECT_CNG | FAXDETECT_T38;
+				} else if (ast_false(v->value)) {
+					user->faxdetect = 0;
 				} else {
+					char *buf = ast_strdupa(v->value);
+					char *word, *next = buf;
 					user->faxdetect = 0;
+					while ((word = strsep(&next, ","))) {
+						if (!strcasecmp(word, "cng")) {
+							user->faxdetect |= FAXDETECT_CNG;
+						} else if (!strcasecmp(word, "t38")) {
+							user->faxdetect |= FAXDETECT_T38;
+						} else {
+							ast_log(LOG_WARNING, "Unknown faxdetect mode '%s' on line %d.\n", word, v->lineno);
+						}
+					}
+
 				}
 			} else if (!strcasecmp(v->name, "t38support")) {
 				if (!strcasecmp(v->value, "disabled"))
@@ -2516,9 +2533,23 @@
 				peer->dtmfcodec = atoi(v->value);
 			} else if (!strcasecmp(v->name, "faxdetect")) {
 				if (ast_true(v->value)) {
-					peer->faxdetect = 1;
+					peer->faxdetect = FAXDETECT_CNG | FAXDETECT_T38;
+				} else if (ast_false(v->value)) {
+					peer->faxdetect = 0;
 				} else {
+					char *buf = ast_strdupa(v->value);
+					char *word, *next = buf;
 					peer->faxdetect = 0;
+					while ((word = strsep(&next, ","))) {
+						if (!strcasecmp(word, "cng")) {
+							peer->faxdetect |= FAXDETECT_CNG;
+						} else if (!strcasecmp(word, "t38")) {
+							peer->faxdetect |= FAXDETECT_T38;
+						} else {
+							ast_log(LOG_WARNING, "Unknown faxdetect mode '%s' on line %d.\n", word, v->lineno);
+						}
+					}
+
 				}
 			} else if (!strcasecmp(v->name, "t38support")) {
 				if (!strcasecmp(v->value, "disabled"))
@@ -2641,7 +2672,7 @@
 	memset(&gPrefs, 0, sizeof(struct ast_codec_pref));
 	gDTMFMode = H323_DTMF_RFC2833;
 	gDTMFCodec = 101;
-	gFAXdetect = 1;
+	gFAXdetect = FAXDETECT_CNG;
 	gT38Support = T38_FAXGW;
 	gTRCLVL = OOTRCLVLERR;
 	gRasGkMode = RasNoGatekeeper;
@@ -2840,9 +2871,23 @@
 			gDTMFCodec = atoi(v->value);
 		} else if (!strcasecmp(v->name, "faxdetect")) {
 			if (ast_true(v->value)) {
-				gFAXdetect = 1;
+				gFAXdetect = FAXDETECT_CNG | FAXDETECT_T38;
+			} else if (ast_false(v->value)) {
+				gFAXdetect = 0;
 			} else {
+				char *buf = ast_strdupa(v->value);
+				char *word, *next = buf;
 				gFAXdetect = 0;
+				while ((word = strsep(&next, ","))) {
+					if (!strcasecmp(word, "cng")) {
+						gFAXdetect |= FAXDETECT_CNG;
+					} else if (!strcasecmp(word, "t38")) {
+						gFAXdetect |= FAXDETECT_T38;
+					} else {
+						ast_log(LOG_WARNING, "Unknown faxdetect mode '%s' on line %d.\n", word, v->lineno);
+					}
+				}
+
 			}
 		} else if (!strcasecmp(v->name, "t38support")) {
 			if (!strcasecmp(v->value, "disabled"))
@@ -2978,7 +3023,16 @@
 		} else if (peer->t38support == T38_FAXGW) {
 			ast_cli(a->fd, "%s\n", "faxgw/chan_sip compatible");
 		}
-		ast_cli(a->fd,"%-15s%s\n", "FAX Detect:", (peer->faxdetect) ? "Yes" : "No");
+		if (peer->faxdetect == (FAXDETECT_CNG | FAXDETECT_T38)) {
+			ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "Yes");
+		} else if (peer->faxdetect & FAXDETECT_CNG) {
+			ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "Cng");
+		} else if (peer->faxdetect & FAXDETECT_T38) {
+			ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "T.38");
+		} else {
+			ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "No");
+		}
+
 		ast_cli(a->fd, "%-15.15s%s\n", "AccountCode: ", peer->accountcode);
 		ast_cli(a->fd, "%-15.15s%s\n", "AMA flags: ", ast_cdr_flags2str(peer->amaflags));
 		ast_cli(a->fd, "%-15.15s%s\n", "IP:Port: ", ip_port);
@@ -3125,7 +3179,16 @@
 		} else if (user->t38support == T38_FAXGW) {
 			ast_cli(a->fd, "%s\n", "faxgw/chan_sip compatible");
 		}
-		ast_cli(a->fd,"%-15s%s\n", "FAX Detect:", (user->faxdetect) ? "Yes" : "No");
+		if (user->faxdetect == (FAXDETECT_CNG | FAXDETECT_T38)) {
+			ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "Yes");
+		} else if (user->faxdetect & FAXDETECT_CNG) {
+			ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "Cng");
+		} else if (user->faxdetect & FAXDETECT_T38) {
+			ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "T.38");
+		} else {
+			ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "No");
+		}
+
 		ast_cli(a->fd, "%-15.15s%s\n", "AccountCode: ", user->accountcode);
 		ast_cli(a->fd, "%-15.15s%s\n", "AMA flags: ", ast_cdr_flags2str(user->amaflags));
 		ast_cli(a->fd, "%-15.15s%s\n", "Context: ", user->context);
@@ -3298,7 +3361,15 @@
 	} else if (gT38Support == T38_FAXGW) {
 		ast_cli(a->fd, "%s\n", "faxgw/chan_sip compatible");
 	}
-	ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", (gFAXdetect) ? "Yes" : "No");
+	if (gFAXdetect == (FAXDETECT_CNG | FAXDETECT_T38)) {
+		ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "Yes");
+	} else if (gFAXdetect & FAXDETECT_CNG) {
+		ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "Cng");
+	} else if (gFAXdetect & FAXDETECT_T38) {
+		ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "T.38");
+	} else {
+		ast_cli(a->fd,"%-20s%s\n", "FAX Detect:", "No");
+	}
 
 	if (gRTDRCount && gRTDRInterval) {
 		ast_cli(a->fd, "%-20.15s%d,%d\n", "RoundTrip: ", gRTDRCount, gRTDRInterval);
@@ -3340,11 +3411,19 @@
 {
 	struct ooh323_pvt *p = chan->tech_pvt;
 
+	ast_channel_lock(chan);
+	if (!p) {
+		ast_channel_unlock(chan);
+		return -1;
+	}
+
 	if (strcmp(chan->tech->type, "OOH323")) {
-		ast_log(LOG_ERROR, "This function is only supported on OOH323 channels Channel is %s\n", chan->tech->type);
+		ast_log(LOG_ERROR, "This function is only supported on OOH323 channels, Channel is %s\n", chan->tech->type);
+		ast_channel_unlock(chan);
 		return -1;
 	}
 
+	ast_mutex_lock(&p->lock);
 	if (!strcasecmp(data, "faxdetect")) {
 		ast_copy_string(buf, p->faxdetect ? "1" : "0", len);
 	} else if (!strcasecmp(data, "t38support")) {
@@ -3366,6 +3445,9 @@
 	} else if (!strcasecmp(data, "callee_url")) {
 		ast_copy_string(buf, p->callee_url, len);
 	}
+	ast_mutex_unlock(&p->lock);
+
+	ast_channel_unlock(chan);
 	return 0;
 }
 
@@ -3373,11 +3455,18 @@
 static int function_ooh323_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
 {
 	struct ooh323_pvt *p = chan->tech_pvt;
-
 	int res = -1;
+
+	ast_channel_lock(chan);
+	if (!p) {
+		ast_channel_unlock(chan);
+		return -1;
+	}
+
 	if (strcmp(chan->tech->type, "OOH323")) {
-		ast_log(LOG_ERROR, "This function is only supported on OOH323 channels Channel is %s\n", chan->tech->type);
-		return res;
+		ast_log(LOG_ERROR, "This function is only supported on OOH323 channels, Channel is %s\n", chan->tech->type);
+		ast_channel_unlock(chan);
+		return -1;
 	}
 
 	ast_mutex_lock(&p->lock);
@@ -3385,9 +3474,25 @@
 		if (ast_true(value)) {
 			p->faxdetect = 1;
 			res = 0;
-		} else {
+		} else if (ast_false(value)) {
 			p->faxdetect = 0;
 			res = 0;
+		} else {
+			char *buf = ast_strdupa(value);
+			char *word, *next = buf;
+			p->faxdetect = 0;
+			res = 0;
+			while ((word = strsep(&next, ","))) {
+				if (!strcasecmp(word, "cng")) {
+					p->faxdetect |= FAXDETECT_CNG;
+				} else if (!strcasecmp(word, "t38")) {
+					p->faxdetect |= FAXDETECT_T38;
+				} else {
+					ast_log(LOG_WARNING, "Unknown faxdetect mode '%s'.\n", word);
+					res = -1;
+				}
+			}
+
 		}
 	} else if (!strcasecmp(data, "t38support")) {
 		if (ast_true(value)) {
@@ -3399,6 +3504,7 @@
 		}
 	}
 	ast_mutex_unlock(&p->lock);
+	ast_channel_unlock(chan);
 
 	return res;
 }
@@ -4460,7 +4566,7 @@
 			ast_set_read_format(p->owner, p->owner->readformat);
 			ast_set_write_format(p->owner, p->owner->writeformat);
 		}
-		if (((p->dtmfmode & H323_DTMF_INBAND) || p->faxdetect) && p->vad &&
+		if (((p->dtmfmode & H323_DTMF_INBAND) || (p->faxdetect && FAXDETECT_CNG)) && p->vad &&
 		    (f->subclass.codec == AST_FORMAT_SLINEAR || f->subclass.codec == AST_FORMAT_ALAW ||
 		     f->subclass.codec == AST_FORMAT_ULAW)) {
 			dfr = ast_frdup(f);
@@ -4478,12 +4584,8 @@
 			if (gH323Debug)
 				ast_verbose("request to change %s to t.38 because fax ced\n", p->callToken);
 			p->chmodepend = 1;
+			p->faxdetected = 1;
 			ooRequestChangeMode(p->callToken, 1);
-			p->faxdetect = 0;
-			if (!(p->dtmfmode & H323_DTMF_INBAND)) {
-				ast_dsp_free(p->vad);
-				p->vad = NULL;
-			}
 		} else if ((dfr->subclass.integer == 'f') && !p->faxdetected) {
 			const char *target_context = S_OR(p->owner->macrocontext, p->owner->context);
 			if ((strcmp(p->owner->exten, "fax")) &&
@@ -4495,6 +4597,9 @@
 					ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", p->owner->name,target_context);
 				}
 				p->faxdetected = 1;
+				if (dfr) {
+					ast_frfree(dfr);
+				}
 				return &ast_null_frame;
 			}
 		}
@@ -4555,10 +4660,26 @@
 
 
 		if (p->t38support == T38_ENABLED) {
+			struct ast_control_t38_parameters parameters = { .request_response = 0 };
+
+			if ((p->faxdetect & FAXDETECT_T38) && !p->faxdetected) {
+                       		const char *target_context;
+				ast_debug(1, "* Detected T.38 Request\n");
+				target_context = S_OR(p->owner->macrocontext, p->owner->context);
+                        	if ((strcmp(p->owner->exten, "fax")) &&
+                            		(ast_exists_extension(p->owner, target_context, "fax", 1,
+                            		S_COR(p->owner->caller.id.number.valid, p->owner->caller.id.number.str, NULL)))) {
+                                	ast_verb(2, "Redirecting '%s' to fax extension due to CNG detection\n", p->owner->name);
+                                	pbx_builtin_setvar_helper(p->owner, "FAXEXTEN", p->owner->exten);
+                                	if (ast_async_goto(p->owner, target_context, "fax", 1)) {
+                                        	ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", p->owner->name,target_context);
+					}
+                                }
+                                p->faxdetected = 1;
+			}
 
 /* AST_T38_CONTROL mode */
 
-			struct ast_control_t38_parameters parameters = { .request_response = 0 };
 			parameters.request_response = AST_T38_REQUEST_NEGOTIATE;
 			if (call->T38FarMaxDatagram) {
 				ast_udptl_set_far_max_datagram(p->udptl, call->T38FarMaxDatagram);
@@ -4574,6 +4695,7 @@
 							&parameters, sizeof(parameters));
 			p->faxmode = 1;
 
+
 		}
 	} else {
 		if (p->t38support == T38_ENABLED) {
@@ -4585,6 +4707,7 @@
 							&parameters, sizeof(parameters));
 		}
 		p->faxmode = 0;
+		p->faxdetected = 0;
 		p->t38_init = 0;
 	}
 

Modified: team/irroot/t38gateway-1.8/configs/chan_ooh323.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/irroot/t38gateway-1.8/configs/chan_ooh323.conf.sample?view=diff&rev=327409&r1=327408&r2=327409
==============================================================================
--- team/irroot/t38gateway-1.8/configs/chan_ooh323.conf.sample (original)
+++ team/irroot/t38gateway-1.8/configs/chan_ooh323.conf.sample Sun Jul 10 09:20:24 2011
@@ -122,6 +122,18 @@
 ;
 ;roundtrip=x,y
 
+;
+; FAX detection will cause the OOH323 channel to jump to the 'fax' extension (if it exists)
+; based one or more events being detected. The events that can be detected are an incoming
+; CNG tone or an incoming T.38 RequestMode packet
+;
+; yes - enable both detection (CNG & T.38)
+; no - disable both 
+; cng - enable CNG detection (default)
+; t38 - enable T.38 request detection
+;
+faxdetect = cng
+
 ; User/peer/friend definitions:
 ; User config options                    Peer config options
 ; ------------------                     -------------------




More information about the asterisk-commits mailing list