[asterisk-commits] irroot: branch irroot/distrotech-customers-1.8 r333495 - in /team/irroot/dist...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Aug 27 05:40:13 CDT 2011


Author: irroot
Date: Sat Aug 27 05:40:09 2011
New Revision: 333495

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=333495
Log:
Add gwtimeout option and use CED and v.21 tone detection

Modified:
    team/irroot/distrotech-customers-1.8/include/asterisk/res_fax.h
    team/irroot/distrotech-customers-1.8/res/res_fax.c

Modified: team/irroot/distrotech-customers-1.8/include/asterisk/res_fax.h
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-1.8/include/asterisk/res_fax.h?view=diff&rev=333495&r1=333494&r2=333495
==============================================================================
--- team/irroot/distrotech-customers-1.8/include/asterisk/res_fax.h (original)
+++ team/irroot/distrotech-customers-1.8/include/asterisk/res_fax.h Sat Aug 27 05:40:09 2011
@@ -172,6 +172,8 @@
 	struct ast_fax_t38_parameters their_t38_parameters;
 	/*! the id of the t.38 gateway framehook for this channel */
 	int gateway_id;
+	/*! the timeout for this gateway in seconds */
+	int gateway_timeout;
 };
 
 struct ast_fax_tech;

Modified: team/irroot/distrotech-customers-1.8/res/res_fax.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-1.8/res/res_fax.c?view=diff&rev=333495&r1=333494&r2=333495
==============================================================================
--- team/irroot/distrotech-customers-1.8/res/res_fax.c (original)
+++ team/irroot/distrotech-customers-1.8/res/res_fax.c Sat Aug 27 05:40:09 2011
@@ -186,6 +186,9 @@
 					<enum name="gateway">
 						<para>R/W T38 Gateway Enabled (yes/no)</para>
 					</enum>
+					<enum name="gwtimeout">
+						<para>R/W Gateway fax activity timeout in seconds (yes/no/seconds)</para>
+					</enum>
 					<enum name="pages">
 						<para>R/O Number of pages transferred.</para>
 					</enum>
@@ -467,6 +470,7 @@
 	d->minrate = general_options.minrate;
 	d->maxrate = general_options.maxrate;
 	d->gateway_id = -1;
+	d->gateway_timeout = FAX_GATEWAY_TIMEOUT;
 
 	return d;
 }
@@ -2501,10 +2505,10 @@
 	gateway->framehook = -1;
 
 	ast_dsp_set_features(gateway->chan_dsp, DSP_FEATURE_FAX_DETECT);
-	ast_dsp_set_faxmode(gateway->chan_dsp, DSP_FAXMODE_DETECT_V21);
+	ast_dsp_set_faxmode(gateway->chan_dsp, DSP_FAXMODE_DETECT_V21 | DSP_FAXMODE_DETECT_CED);
 
 	ast_dsp_set_features(gateway->peer_dsp, DSP_FEATURE_FAX_DETECT);
-	ast_dsp_set_faxmode(gateway->peer_dsp, DSP_FAXMODE_DETECT_V21);
+	ast_dsp_set_faxmode(gateway->peer_dsp, DSP_FAXMODE_DETECT_V21 | DSP_FAXMODE_DETECT_CED);
 
 	details->caps = AST_FAX_TECH_GATEWAY;
 	if (!(gateway->s = fax_session_reserve(details, &gateway->token))) {
@@ -2614,7 +2618,7 @@
 		return f;
 	}
 
-	if (dfr->frametype == AST_FRAME_DTMF && dfr->subclass.integer == 'g') {
+	if (dfr->frametype == AST_FRAME_DTMF && ((dfr->subclass.integer == 'e') || (dfr->subclass.integer == 'g'))) {
 		gateway->detected_v21 = 1;
 		if (ast_channel_get_t38_state(other) == T38_STATE_UNKNOWN) {
 			ast_debug(1, "detected v21 preamble from %s\n", active->name);
@@ -2898,10 +2902,23 @@
 static struct ast_frame *fax_gateway_framehook(struct ast_channel *chan, struct ast_frame *f, enum ast_framehook_event event, void *data) {
 	struct fax_gateway *gateway = data;
 	struct ast_channel *peer, *active;
+	struct ast_fax_session_details *details;
+
+	if (gateway->s) {
+		details = gateway->s->details;
+		ao2_ref(details, 1);
+	} else {
+		if (!(details = find_details(chan))) {
+			ast_log(LOG_ERROR, "no FAX session details found on chan %s for T.38 gateway session, odd\n", chan->name);
+			ast_framehook_detach(chan, gateway->framehook);
+			details->gateway_id = -1;
+			return f;
+		}
+	}
 
 	/* restore audio formats when we are detached */
 	if (event == AST_FRAMEHOOK_EVENT_DETACHED) {
-		set_channel_variables(chan, gateway->s->details);
+		set_channel_variables(chan, details);
 
 		if (gateway->bridged) {
 			ast_set_read_format(chan, gateway->chan_read_format);
@@ -2914,20 +2931,24 @@
 			}
 		}
 
+		ao2_ref(details, -1);
 		return NULL;
 	}
 
 	if (!f || (event == AST_FRAMEHOOK_EVENT_ATTACHED)) {
+		ao2_ref(details, -1);
 		return NULL;
 	};
 
 	/* this frame was generated by the fax gateway, pass it on */
 	if (ast_test_flag(f, AST_FAX_FRFLAG_GATEWAY)) {
+		ao2_ref(details, -1);
 		return f;
 	}
 
 	if (!(peer = ast_bridged_channel(chan))) {
 		/* not bridged, don't do anything */
+		ao2_ref(details, -1);
 		return f;
 	}
 
@@ -2936,12 +2957,13 @@
 		if (ast_channel_get_t38_state(chan) == T38_STATE_UNAVAILABLE && ast_channel_get_t38_state(peer) == T38_STATE_UNAVAILABLE) {
 			ast_debug(1, "not starting gateway for %s and %s; neither channel supports T.38\n", chan->name, peer->name);
 			ast_framehook_detach(chan, gateway->framehook);
-			gateway->s->details->gateway_id = -1;
-
-			ast_string_field_set(gateway->s->details, result, "FAILED");
-			ast_string_field_set(gateway->s->details, resultstr, "neither channel supports T.38");
-			ast_string_field_set(gateway->s->details, error, "T38_NEG_ERROR");
-			set_channel_variables(chan, gateway->s->details);
+			details->gateway_id = -1;
+
+			ast_string_field_set(details, result, "FAILED");
+			ast_string_field_set(details, resultstr, "neither channel supports T.38");
+			ast_string_field_set(details, error, "T38_NEG_ERROR");
+			set_channel_variables(chan, details);
+			ao2_ref(details, -1);
 			return f;
 		}
 
@@ -2965,16 +2987,17 @@
 		gateway->bridged = 1;
 	}
 
-	if (gateway->bridged && !ast_tvzero(gateway->timeout_start)) {
-		if (ast_tvdiff_ms(ast_tvnow(), gateway->timeout_start) > FAX_GATEWAY_TIMEOUT) {
-			ast_debug(1, "no fax activity between %s and %s after %d ms, disabling gateway\n", chan->name, peer->name, FAX_GATEWAY_TIMEOUT);
+	if (details->gateway_timeout && gateway->bridged && !ast_tvzero(gateway->timeout_start)) {
+		if (ast_tvdiff_ms(ast_tvnow(), gateway->timeout_start) > details->gateway_timeout) {
+			ast_debug(1, "no fax activity between %s and %s after %d ms, disabling gateway\n", chan->name, peer->name, details->gateway_timeout);
 			ast_framehook_detach(chan, gateway->framehook);
-			gateway->s->details->gateway_id = -1;
-
-			ast_string_field_set(gateway->s->details, result, "FAILED");
-			ast_string_field_build(gateway->s->details, resultstr, "no fax activity after %d ms", FAX_GATEWAY_TIMEOUT);
-			ast_string_field_set(gateway->s->details, error, "TIMEOUT");
-			set_channel_variables(chan, gateway->s->details);
+			details->gateway_id = -1;
+
+			ast_string_field_set(details, result, "FAILED");
+			ast_string_field_build(details, resultstr, "no fax activity after %d ms", details->gateway_timeout);
+			ast_string_field_set(details, error, "TIMEOUT");
+			set_channel_variables(chan, details);
+			ao2_ref(details, -1);
 			return f;
 		}
 	}
@@ -2988,6 +3011,7 @@
 		case AST_FORMAT_ULAW:
 			break;
 		default:
+			ao2_ref(details, -1);
 			return f;
 		}
 		break;
@@ -2995,13 +3019,16 @@
 		if (f->subclass.integer == AST_MODEM_T38) {
 			break;
 		}
+		ao2_ref(details, -1);
 		return f;
 	case AST_FRAME_CONTROL:
 		if (f->subclass.integer == AST_CONTROL_T38_PARAMETERS) {
 			break;
 		}
+		ao2_ref(details, -1);
 		return f;
 	default:
+		ao2_ref(details, -1);
 		return f;
 	}
 
@@ -3015,17 +3042,20 @@
 		break;
 	default:
 		ast_log(LOG_WARNING, "unhandled framehook event %i\n", event);
+		ao2_ref(details, -1);
 		return f;
 	}
 
 	/* handle control frames */
 	if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_T38_PARAMETERS) {
+		ao2_ref(details, -1);
 		return fax_gateway_detect_t38(gateway, chan, peer, active, f);
 	}
 
 	if (!gateway->detected_v21 && gateway->t38_state == T38_STATE_UNAVAILABLE && f->frametype == AST_FRAME_VOICE) {
 		/* not in gateway mode and have not detected v21 yet, listen
 		 * for v21 */
+		ao2_ref(details, -1);
 		return fax_gateway_detect_v21(gateway, chan, peer, active, f);
 	}
 
@@ -3036,6 +3066,7 @@
 		if ((f->frametype == AST_FRAME_VOICE) && (f->subclass.codec != AST_FORMAT_SLINEAR)) {
 			if (active->readtrans && (f = ast_translate(active->readtrans, f, 1)) == NULL) {
 				f = &ast_null_frame;
+				ao2_ref(details, -1);
 				return f;
 			}
 		}
@@ -3046,6 +3077,7 @@
 		 * now we'll just ignore the return value. */
 		gateway->s->tech->write(gateway->s, f);
 		f = &ast_null_frame;
+		ao2_ref(details, -1);
 		return f;
 	}
 
@@ -3062,12 +3094,15 @@
 			};
 			memset(silence_buf, 0, sizeof(silence_buf));
 
+			ao2_ref(details, -1);
 			return ast_frisolate(&silence_frame);
 		} else {
+			ao2_ref(details, -1);
 			return &ast_null_frame;
 		}
 	}
 
+	ao2_ref(details, -1);
 	return f;
 }
 
@@ -3709,6 +3744,8 @@
 	} else if (!strcasecmp(data, "t38gateway") || !strcasecmp(data, "gateway") ||
 		   !strcasecmp(data, "t38_gateway") || !strcasecmp(data, "faxgateway")) {
 		ast_copy_string(buf, details->gateway_id != -1 ? "yes" : "no", len);
+	} else if (!strcasecmp(data, "gwtimeout")) {
+		snprintf(buf, len, "%d", details->gateway_timeout / 1000);
 	} else if (!strcasecmp(data, "error")) {
 		ast_copy_string(buf, details->error, len);
 	} else if (!strcasecmp(data, "filename")) {
@@ -3804,6 +3841,18 @@
 		} else {
 			ast_log(LOG_WARNING, "Unsupported value '%s' passed to FAXOPT(%s).\n", value, data);
 		}
+	} else if (!strcasecmp(data, "gwtimeout")) {
+		const char *val = ast_skip_blanks(value);
+		int timeout;
+		if (ast_true(val)) {
+			details->gateway_timeout = FAX_GATEWAY_TIMEOUT;
+		} else if (ast_false(val)) {
+			details->gateway_timeout = 0;
+		} else if (sscanf(val, "%d", &timeout) == 1 && timeout > 0) {
+			details->gateway_timeout = timeout * 1000;
+		} else {
+			ast_log(LOG_WARNING, "Unsupported value '%s' passed to FAXOPT(%s).\n", value, data);
+		}
 	} else if (!strcasecmp(data, "headerinfo")) {
 		ast_string_field_set(details, headerinfo, value);
 	} else if (!strcasecmp(data, "localstationid")) {




More information about the asterisk-commits mailing list