[Freeswitch-svn] [commit] r5257 - in freeswitch/trunk/src: . include mod/applications/mod_dptools

Freeswitch SVN mikej at freeswitch.org
Mon Jun 4 18:10:42 EDT 2007


Author: mikej
Date: Mon Jun  4 18:10:42 2007
New Revision: 5257

Modified:
   freeswitch/trunk/src/include/switch_ivr.h
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/switch_ivr_async.c

Log:
merge patch from MODAPP-12, thanks Bret.

Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h	(original)
+++ freeswitch/trunk/src/include/switch_ivr.h	Mon Jun  4 18:10:42 2007
@@ -25,7 +25,7 @@
  * 
  * Anthony Minessale II <anthmct at yahoo.com>
  * Neal Horman <neal at wanlink dot com>
- *
+ * Bret McDanel <trixter AT 0xdecafbad dot com>
  *
  * switch_ivr.h -- IVR Library
  *
@@ -208,11 +208,44 @@
 */
 SWITCH_DECLARE(switch_status_t) switch_ivr_stop_record_session(switch_core_session_t *session, char *file);
 
+/*!
+  \brief Start looking for DTMF inband
+  \param session the session to start looking
+  \return SWITCH_STATUS_SUCCESS if all is well
+*/
 SWITCH_DECLARE(switch_status_t) switch_ivr_inband_dtmf_session(switch_core_session_t *session);
+
+/*!
+  \brief Stop looking for DTMF inband
+  \param session the session to stop looking
+  \return SWITCH_STATUS_SUCCESS if all is well
+*/
 SWITCH_DECLARE(switch_status_t) switch_ivr_stop_inband_dtmf_session(switch_core_session_t *session);
+
+/*!
+  \brief XXX DESCRIBE ME
+  \param session the session to act on
+  \return SWITCH_STATUS_SUCCESS if all is well - maybe more XXX FIXME
+*/
 SWITCH_DECLARE(void) switch_ivr_session_echo(switch_core_session_t *session);
 
 /*!
+  \brief Stop looking for FAX CNG
+  \param session the session to stop looking
+  \return SWITCH_STATUS_SUCCESS if all is well
+*/
+SWITCH_DECLARE(switch_status_t) switch_ivr_stop_fax_detect_session(switch_core_session_t *session);
+
+/*!
+  \brief Start looking for FAX CNG
+  \param session the session to start looking
+  \return SWITCH_STATUS_SUCCESS if all is well
+*/
+SWITCH_DECLARE(switch_status_t) switch_ivr_fax_detect_session(switch_core_session_t *session);
+
+
+
+/*!
   \brief play a file from the disk to the session
   \param session the session to play the file too
   \param fh file handle to use (NULL for builtin one)

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Mon Jun  4 18:10:42 2007
@@ -24,6 +24,7 @@
  * Contributor(s):
  * 
  * Anthony Minessale II <anthmct at yahoo.com>
+ * Bret McDanel <trixter AT 0xdecafbad dot com>
  *
  * switch_types.h -- Data Types
  *
@@ -832,6 +833,7 @@
 	SWITCH_EVENT_CODEC				- Codec Change
 	SWITCH_EVENT_BACKGROUND_JOB		- Background Job
 	SWITCH_EVENT_DETECTED_SPEECH	- Detected Speech
+	SWITCH_EVENT_DETECTED_FAX       - Detected Fax CNG Tone
 	SWITCH_EVENT_PRIVATE_COMMAND	- A private command event 
 	SWITCH_EVENT_HEARTBEAT			- Machine is alive
 	SWITCH_EVENT_TRAP				- Error Trap
@@ -881,6 +883,7 @@
 	SWITCH_EVENT_CODEC,
 	SWITCH_EVENT_BACKGROUND_JOB,
 	SWITCH_EVENT_DETECTED_SPEECH,
+	SWITCH_EVENT_DETECTED_FAX,
 	SWITCH_EVENT_PRIVATE_COMMAND,
 	SWITCH_EVENT_HEARTBEAT,
 	SWITCH_EVENT_TRAP,

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Mon Jun  4 18:10:42 2007
@@ -27,6 +27,7 @@
  * Ken Rice, Asteria Solutions Group, Inc <ken at asteriasgi.com>
  * Michael Murdock <mike at mmurdock dot org>
  * Neal Horman <neal at wanlink dot com>
+ * Bret McDanel <trixter AT 0xdecafbad dot com>
  *
  * mod_dptools.c -- Raw Audio File Streaming Application Module
  *
@@ -651,25 +652,28 @@
 
 static void dtm_session_function(switch_core_session_t *session, char *data)
 {
-	switch_channel_t *channel;
-
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
-
 	switch_ivr_inband_dtmf_session(session);
 }
 
 
 static void stop_dtmf_session_function(switch_core_session_t *session, char *data)
 {
-	switch_channel_t *channel;
+	switch_ivr_stop_inband_dtmf_session(session);
+}
 
-	channel = switch_core_session_get_channel(session);
-	assert(channel != NULL);
+static void fax_detect_session_function(switch_core_session_t *session, char *data)
+{
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Enabling fax detection\n");
+	switch_ivr_fax_detect_session(session);
+}
 
-	switch_ivr_stop_inband_dtmf_session(session);
+static void stop_fax_detect_session_function(switch_core_session_t *session, char *data)
+{
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Disabling fax detection\n");
+	switch_ivr_stop_fax_detect_session(session);
 }
 
+
 static const switch_api_interface_t strepoch_api_interface = {
 	/*.interface_name */ "strepoch",
 	/*.desc */ "Convert a date string into epoch time",
@@ -702,6 +706,27 @@
 	/*.next */ &dptools_api_interface
 };
 
+
+static const switch_application_interface_t fax_detect_application_interface = {
+	/*.interface_name */ "fax_detect",
+	/*.application_function */ fax_detect_session_function,
+	/* long_desc */ "Detect fax send tone",
+	/* short_desc */ "Detect faxes",
+	/* syntax */ "",
+	/* flags */ SAF_NONE,
+	/*.next */ NULL
+};
+
+static const switch_application_interface_t stop_fax_detect_application_interface = {
+	/*.interface_name */ "stop_fax_detect",
+	/*.application_function */ stop_fax_detect_session_function,
+	/* long_desc */ "Stop detecting fax send tones",
+	/* short_desc */ "stop detecting faxes",
+	/* syntax */ "",
+	/* flags */ SAF_NONE,
+	/* next */ &fax_detect_application_interface
+};
+
 static const switch_application_interface_t dtmf_application_interface = {
 	/*.interface_name */ "start_dtmf",
 	/*.application_function */ dtm_session_function,
@@ -709,7 +734,7 @@
 	/* short_desc */ "Detect dtmf",
 	/* syntax */ "",
 	/* flags */ SAF_NONE,
-	NULL
+	/* next */ &stop_fax_detect_application_interface
 };
 
 static const switch_application_interface_t stop_dtmf_application_interface = {
@@ -717,7 +742,7 @@
 	/*.application_function */ stop_dtmf_session_function,
 	/* long_desc */ "Stop detecting inband dtmf.",
 	/* short_desc */ "stop inband dtmf.",
-	/* syntax */ "<path>",
+	/* syntax */ "",
 	/* flags */ SAF_NONE,
 	&dtmf_application_interface
 };

Modified: freeswitch/trunk/src/switch_ivr_async.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_async.c	(original)
+++ freeswitch/trunk/src/switch_ivr_async.c	Mon Jun  4 18:10:42 2007
@@ -25,6 +25,7 @@
  * 
  * Anthony Minessale II <anthmct at yahoo.com>
  * Michael Jerris <mike at jerris.com>
+ * Bret McDanel <bret AT 0xdecafbad dot com>
  *
  * switch_ivr_async.c -- IVR Library (async operations)
  *
@@ -324,6 +325,122 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+
+typedef struct {
+  switch_core_session_t *session;
+  teletone_multi_tone_t mt;
+} switch_fax_detect_t;
+
+static switch_bool_t fax_detect_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
+{
+  switch_fax_detect_t *pvt = (switch_fax_detect_t *) user_data;
+  uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
+  switch_frame_t frame = { 0 };
+  //  switch_channel_t *channel = switch_core_session_get_channel(pvt->session);
+
+  //  assert(channel != NULL);
+  frame.data = data;
+  frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
+
+  switch (type) {
+  case SWITCH_ABC_TYPE_INIT:
+    break;
+  case SWITCH_ABC_TYPE_CLOSE:
+    break;
+  case SWITCH_ABC_TYPE_READ:
+    if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) {
+      if(teletone_multi_tone_detect(&pvt->mt, frame.data, frame.samples)) {
+	switch_event_t *event;
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FAX CNG DETECTED\n");
+
+	if (switch_event_create(&event, SWITCH_EVENT_DETECTED_FAX) == SWITCH_STATUS_SUCCESS) {
+	  switch_event_t *dup;
+
+	  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "fax", "detected");
+	    
+	  if (switch_event_dup(&dup, event) == SWITCH_STATUS_SUCCESS) {
+	    switch_event_fire(&dup);
+	  }
+	    
+
+	  if (switch_core_session_queue_event(pvt->session, &event) != SWITCH_STATUS_SUCCESS) {
+	    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Event queue failed!\n");
+	    switch_event_add_header(event, SWITCH_STACK_BOTTOM, "delivery-failure", "true");
+	    switch_event_fire(&event);
+	  }
+	}
+      }
+    }
+    break;
+  case SWITCH_ABC_TYPE_WRITE:
+  default:
+    break;
+  }
+  return SWITCH_TRUE;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_stop_fax_detect_session(switch_core_session_t *session)
+{
+  switch_media_bug_t *bug;
+  switch_channel_t *channel = switch_core_session_get_channel(session);
+
+  assert(channel != NULL);
+  if ((bug = switch_channel_get_private(channel, "fax"))) {
+    switch_channel_set_private(channel, "fax", NULL);
+    switch_core_media_bug_remove(session, &bug);
+    return SWITCH_STATUS_SUCCESS;
+  }
+
+  return SWITCH_STATUS_FALSE;
+
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_fax_detect_session(switch_core_session_t *session)
+{
+  switch_channel_t *channel;
+  switch_codec_t *read_codec;
+  switch_media_bug_t *bug;
+  switch_status_t status;
+  switch_fax_detect_t *pvt;
+  teletone_tone_map_t *map;
+  int i;
+
+  channel = switch_core_session_get_channel(session);
+  assert(channel != NULL);
+
+
+  read_codec = switch_core_session_get_read_codec(session);
+  assert(read_codec != NULL);
+
+  if (!(pvt = switch_core_session_alloc(session, sizeof(*pvt)))) {
+    return SWITCH_STATUS_MEMERR;
+  }
+
+  if (!(map = switch_core_session_alloc(session, sizeof(*map)))) {
+    return SWITCH_STATUS_MEMERR;
+  }
+
+  for(i=0;i<TELETONE_MAX_TONES;i++) {
+    map->freqs[i] = 1100.0;
+  }
+  pvt->mt.sample_rate = read_codec->implementation->samples_per_second;
+  pvt->session = session;
+
+  teletone_multi_tone_init(&pvt->mt, map);
+
+  switch_channel_answer(channel);
+
+  if ((status = switch_core_media_bug_add(session, fax_detect_callback, pvt, 0, SMBF_READ_STREAM, &bug)) != SWITCH_STATUS_SUCCESS) {
+    return status;
+  }
+
+  switch_channel_set_private(channel, "fax", bug);
+
+  return SWITCH_STATUS_SUCCESS;
+}
+
+
 struct speech_thread_handle {
 	switch_core_session_t *session;
 	switch_asr_handle_t *ah;



More information about the Freeswitch-svn mailing list