[svn-commits] irroot: branch irroot/distrotech-customers-trunk r339350 - /team/irroot/distr...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Oct 4 12:28:20 CDT 2011


Author: irroot
Date: Tue Oct  4 12:28:17 2011
New Revision: 339350

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=339350
Log:
FAX Detect FH remove noiselim allow setting mode

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=339350&r1=339349&r2=339350
==============================================================================
--- team/irroot/distrotech-customers-trunk/res/res_fax.c (original)
+++ team/irroot/distrotech-customers-trunk/res/res_fax.c Tue Oct  4 12:28:17 2011
@@ -193,7 +193,7 @@
 						<para>R/W T38 fax gateway, with optional fax activity timeout in seconds (yes[,timeout]/no)</para>
 					</enum>
 					<enum name="faxdetect">
-						<para>R/W Enable FAX detect with optional timeout in seconds (yes[,timeout]/no)</para>
+						<para>R/W Enable FAX detect with optional timeout in seconds (yes,t38,cng[,timeout]/no)</para>
 					</enum>
 					<enum name="pages">
 						<para>R/O Number of pages transferred.</para>
@@ -281,11 +281,16 @@
 	struct ast_dsp *dsp;
 	/*! \brief original audio formats */
 	struct ast_format orig_format;
-	/*! \brief Noise limit to end faxdetect */
-	int noiselim;
 	/*! \brief fax session details */
 	struct ast_fax_session_details *details;
+	/*! \brief mode */
+	int flags;
 };
+
+/*! \brief FAX Detect flags */
+#define FAX_DETECT_MODE_CNG	(1 << 0)
+#define FAX_DETECT_MODE_T38	(1 << 1)
+#define	FAX_DETECT_MODE_BOTH	(FAX_DETECT_MODE_CNG | FAX_DETECT_MODE_T38)
 
 static int fax_logger_level = -1;
 
@@ -3157,18 +3162,17 @@
 /*! \brief Create a new fax detect object.
  * \param chan the channel attaching to
  * \param timeout remove framehook in this time if set
- * \param noiselim end faxdetect when noiselim ms of noise is detected
- * \param dsp_detect_flag dsp faxmode detect flags
+ * \param flags required options
  * \return NULL or a fax gateway object
  */
-static struct fax_detect *fax_detect_new(struct ast_channel *chan, int timeout, int noiselim, int dsp_detect_flag)
+static struct fax_detect *fax_detect_new(struct ast_channel *chan, int timeout, int flags)
 {
 	struct fax_detect *faxdetect = ao2_alloc(sizeof(*faxdetect), destroy_faxdetect);
 	if (!faxdetect) {
 		return NULL;
 	}
 
-	faxdetect->noiselim = noiselim;
+	faxdetect->flags = flags;
 
 	if (timeout) {
 		faxdetect->timeout_start = ast_tvnow();
@@ -3177,15 +3181,16 @@
 		faxdetect->timeout_start.tv_usec = 0;
 	}
 
-	faxdetect->dsp = ast_dsp_new();
-	if (!faxdetect->dsp) {
-		ao2_ref(faxdetect, -1);
-		return NULL;
-	}
-
-	ast_dsp_set_features(faxdetect->dsp, DSP_FEATURE_FAX_DETECT);
-	ast_dsp_set_faxmode(faxdetect->dsp, dsp_detect_flag | DSP_FAXMODE_DETECT_SQUELCH);
-	ast_dsp_set_threshold(faxdetect->dsp, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE));
+	if (faxdetect->flags & FAX_DETECT_MODE_CNG) {
+		faxdetect->dsp = ast_dsp_new();
+		if (!faxdetect->dsp) {
+			ao2_ref(faxdetect, -1);
+			return NULL;
+		}
+		ast_dsp_set_features(faxdetect->dsp, DSP_FEATURE_FAX_DETECT);
+		ast_dsp_set_faxmode(faxdetect->dsp, DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_SQUELCH);
+	}
+
 	return faxdetect;
 }
 
@@ -3213,7 +3218,6 @@
 	struct ast_fax_session_details *details;
 	struct ast_control_t38_parameters *control_params;
 	struct ast_channel *peer;
-	int dspnoise;
 	int result = 0;
 
 	details = faxdetect->details;
@@ -3261,9 +3265,13 @@
 		return f;
 	}
 
-	/* only handle VOICE/DTMF and CONTROL frames*/
+	/* only handle VOICE and CONTROL frames*/
 	switch (f->frametype) {
 	case AST_FRAME_VOICE:
+		/* we have no DSP this means we not detecting CNG */
+		if (!faxdetect->dsp) {
+			break;
+		}
 		/* We can only process some formats*/
 		switch (f->subclass.format.id) {
 			case AST_FORMAT_SLINEAR:
@@ -3275,12 +3283,8 @@
 		}
 		break;
 	case AST_FRAME_CONTROL:
-		if (f->subclass.integer == AST_CONTROL_T38_PARAMETERS) {
-			break;
-		}
-		return f;
-	case AST_FRAME_DTMF:
-		if ((f->subclass.integer == 'f') || (f->subclass.integer == 'e')) {
+		if ((f->subclass.integer == AST_CONTROL_T38_PARAMETERS) &&
+		    (faxdetect->flags & FAX_DETECT_MODE_T38)) {
 			break;
 		}
 		return f;
@@ -3292,11 +3296,6 @@
 		f = ast_dsp_process(chan, faxdetect->dsp, f);
 		if (f->frametype == AST_FRAME_DTMF) {
 			result = f->subclass.integer;
-		} else if ((f->frametype == AST_FRAME_VOICE) && (faxdetect->noiselim > 0)) {
-			ast_dsp_noise(faxdetect->dsp, f, &dspnoise);
-			if (dspnoise > faxdetect->noiselim) {
-				result = 'n';
-			}
 		}
 	} else if ((f->frametype == AST_FRAME_CONTROL) && (f->datalen == sizeof(struct ast_control_t38_parameters))) {
 		control_params = f->data.ptr;
@@ -3308,8 +3307,6 @@
 		default:
 			break;
 		}
-	} else if (f->frametype == AST_FRAME_DTMF) {
-		result = f->subclass.integer;
 	}
 
 	if (result) {
@@ -3345,12 +3342,11 @@
 /*! \brief Attach a faxdetect framehook object to a channel.
  * \param chan the channel to attach to
  * \param timeout remove framehook in this time if set
- * \param noiselim end faxdetect when noiselim ms of noise is detected
- * \param dsp_detect_flag dsp faxmode detect flags
  * \return the faxdetect structure or NULL on error
+ * \param flags required options
  * \retval -1 error
  */
-static struct fax_detect* fax_detect_attach(struct ast_channel *chan, int timeout, int noiselim, int dsp_detect_flags)
+static struct fax_detect* fax_detect_attach(struct ast_channel *chan, int timeout, int flags)
 {
 	struct fax_detect *faxdetect;
 	struct ast_fax_session_details *details;
@@ -3366,7 +3362,7 @@
 	}
 
 	/* set up the frame hook*/
-	faxdetect = fax_detect_new(chan, timeout, noiselim, dsp_detect_flags);
+	faxdetect = fax_detect_new(chan, timeout, flags);
 	if (!faxdetect) {
 		ao2_ref(details, -1);
 		return NULL;
@@ -3906,19 +3902,32 @@
 		const char *val = ast_skip_blanks(value);
 		char *timeout = strchr(val, ',');
 		unsigned int fdtimeout = 0;
+		int flags;
 		struct fax_detect *faxdetect;
 
 		if (timeout) {
 			*timeout++ = '\0';
 		}
 
-		if (ast_true(val)) {
+		if (ast_true(val) || !strcasecmp(val, "t38") || !strcasecmp(val, "cng")) {
 			if (details->faxdetect_id < 0) {
 				if (timeout && (sscanf(timeout, "%u", &fdtimeout) == 1)) {
-					fdtimeout = fdtimeout * 1000;
+					if (fdtimeout > 0) {
+						fdtimeout = fdtimeout * 1000;
+					} else {
+						ast_log(LOG_WARNING, "Timeout cannot be negative ignoring timeout\n");
+					}
 				}
 
-				faxdetect = fax_detect_attach(chan, fdtimeout, 0, DSP_FAXMODE_DETECT_CNG);
+				if (!strcasecmp(val, "t38")) {
+					flags = FAX_DETECT_MODE_T38;
+				} else if (!strcasecmp(val, "cng")) {
+					flags = FAX_DETECT_MODE_CNG;
+				} else {
+					flags = FAX_DETECT_MODE_BOTH;
+				}
+
+				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);




More information about the svn-commits mailing list