[asterisk-commits] irroot: branch irroot/distrotech-customers-trunk r339462 - /team/irroot/distr...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 5 01:24:23 CDT 2011


Author: irroot
Date: Wed Oct  5 01:24:17 2011
New Revision: 339462

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=339462
Log:
Add generic faxdetect framehook to res_fax

Added func FAXOPT(faxdetect)=yes,cng,t38[,timeout]/no
to enable dialplan faxdetect allowing more flexibility.

as soon as a fax tone is detected the framehook is removed.
there is a penalty involved in running this framehook on
non G711 channels as they will be transcoded.

CNG tone is suppresed using the SQUELCH flag to allow
WaitForNoise to be run on the channel to detect Voice.

This patch also fixes a race condition ending in segfault
the caps in the gateway must not be changed till the sesion
is destroyed.

(Closes issue ASTERISK-18569)
Reported by: Myself
Reviewed by: Matthew Nicholson, Kevin Fleming

Review: https://reviewboard.asterisk.org/r/1116/

Modified:
    team/irroot/distrotech-customers-trunk/res/res_fax.c

Modified: team/irroot/distrotech-customers-trunk/res/res_fax.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-trunk/res/res_fax.c?view=diff&rev=339462&r1=339461&r2=339462
==============================================================================
--- team/irroot/distrotech-customers-trunk/res/res_fax.c (original)
+++ team/irroot/distrotech-customers-trunk/res/res_fax.c Wed Oct  5 01:24:17 2011
@@ -851,6 +851,9 @@
 	}
 
 	if (s->details) {
+		if (s->details->caps & AST_FAX_TECH_GATEWAY) {
+			s->details->caps &= ~AST_FAX_TECH_GATEWAY;
+		}
 		ao2_ref(s->details, -1);
 	}
 	
@@ -1729,7 +1732,7 @@
 	ast_string_field_set(details, error, "INIT_ERROR");
 	set_channel_variables(chan, details);
 
-	if ((details->caps & AST_FAX_TECH_GATEWAY) && (details->gateway_id > 0)) {
+	if (details->gateway_id > 0) {
 		ast_string_field_set(details, resultstr, "can't receive a fax on a channel with a T.38 gateway");
 		set_channel_variables(chan, details);
 		ast_log(LOG_ERROR, "executing ReceiveFAX on a channel with a T.38 Gateway is not supported\n");
@@ -2199,7 +2202,7 @@
 	ast_string_field_set(details, error, "INIT_ERROR");
 	set_channel_variables(chan, details);
 
-	if ((details->caps & AST_FAX_TECH_GATEWAY) && (details->gateway_id > 0)) {
+	if (details->gateway_id > 0) {
 		ast_string_field_set(details, resultstr, "can't send a fax on a channel with a T.38 gateway");
 		set_channel_variables(chan, details);
 		ast_log(LOG_ERROR, "executing SendFAX on a channel with a T.38 Gateway is not supported\n");
@@ -2456,7 +2459,6 @@
 	if (gateway->s) {
 		fax_session_release(gateway->s, gateway->token);
 		gateway->token = NULL;
-		gateway->s->details->caps &= ~AST_FAX_TECH_GATEWAY;
 
 		ao2_lock(faxregistry.container);
 		ao2_unlink(faxregistry.container, gateway->s);
@@ -3189,6 +3191,8 @@
 		}
 		ast_dsp_set_features(faxdetect->dsp, DSP_FEATURE_FAX_DETECT);
 		ast_dsp_set_faxmode(faxdetect->dsp, DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_SQUELCH);
+	} else {
+		faxdetect->dsp = NULL;
 	}
 
 	return faxdetect;
@@ -3328,8 +3332,8 @@
 				f = &ast_null_frame;
 			} else {
 				ast_channel_lock(chan);
-				ast_log(LOG_NOTICE, "FAX %s detected but no fax extension\n",
-					(result == 'f') ? "CNG" : "T38");
+				ast_log(LOG_NOTICE, "FAX %s detected but no fax extension in context (%s)\n",
+					(result == 'f') ? "CNG" : "T38", target_context);
 			}
 		}
 		ast_framehook_detach(chan, details->faxdetect_id);
@@ -3346,7 +3350,7 @@
  * \param flags required options
  * \retval -1 error
  */
-static struct fax_detect* fax_detect_attach(struct ast_channel *chan, int timeout, int flags)
+static int fax_detect_attach(struct ast_channel *chan, int timeout, int flags)
 {
 	struct fax_detect *faxdetect;
 	struct ast_fax_session_details *details;
@@ -3358,14 +3362,14 @@
 
 	if (!(details = find_or_create_details(chan))) {
 		ast_log(LOG_ERROR, "System cannot provide memory for session requirements.\n");
-		return NULL;
+		return -1;
 	}
 
 	/* set up the frame hook*/
 	faxdetect = fax_detect_new(chan, timeout, flags);
 	if (!faxdetect) {
 		ao2_ref(details, -1);
-		return NULL;
+		return -1;
 	}
 
 	fr_hook.data = faxdetect;
@@ -3376,12 +3380,9 @@
 
 	if (details->faxdetect_id < 0) {
 		ao2_ref(faxdetect, -1);
-		return NULL;
-	}
-
-	/* return it with ref held in framhook and return*/
-	ao2_ref(faxdetect, 1);
-	return faxdetect;
+	}
+
+	return details->faxdetect_id;
 }
 
 /*! \brief hash callback for ao2 */
@@ -3903,7 +3904,7 @@
 		char *timeout = strchr(val, ',');
 		unsigned int fdtimeout = 0;
 		int flags;
-		struct fax_detect *faxdetect;
+		int faxdetect;
 
 		if (timeout) {
 			*timeout++ = '\0';
@@ -3928,14 +3929,12 @@
 				}
 
 				faxdetect = fax_detect_attach(chan, fdtimeout, flags);
-
-				if (faxdetect && (details->faxdetect_id >= 0)) {
-					ast_debug(1, "Attached FAX detect to channel %s.\n", chan->name);
-				} else {
+				if (faxdetect < 0) {
 					ast_log(LOG_ERROR, "Error attaching FAX detect to channel %s.\n", chan->name);
 					res = -1;
+				} else {
+					ast_debug(1, "Attached FAX detect to channel %s.\n", chan->name);
 				}
-				ao2_ref(faxdetect, -1);
 			} else {
 				ast_log(LOG_WARNING, "Attempt to attach a FAX detect on channel (%s) with FAX detect already running.\n", chan->name);
 			}




More information about the asterisk-commits mailing list