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

Freeswitch SVN anthm at freeswitch.org
Sat Jan 12 15:30:48 EST 2008


Author: anthm
Date: Sat Jan 12 15:30:48 2008
New Revision: 7193

Modified:
   freeswitch/trunk/src/include/switch_channel.h
   freeswitch/trunk/src/include/switch_core.h
   freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/switch_channel.c
   freeswitch/trunk/src/switch_core_io.c

Log:
Formatting DTMF as a string

a '+' separated list of DTMF strings

Each element in the list can contain an @ followed by
a duration in ms.

e.g.
1234 at 250+4321@500

sends the digits 1 2 3 4 at a rate of 250ms then
4 3 2 1 at a rate of 500




Modified: freeswitch/trunk/src/include/switch_channel.h
==============================================================================
--- freeswitch/trunk/src/include/switch_channel.h	(original)
+++ freeswitch/trunk/src/include/switch_channel.h	Sat Jan 12 15:30:48 2008
@@ -427,6 +427,7 @@
   \return SWITCH_STATUS_SUCCESS if successful
 */
 SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *channel, const switch_dtmf_t *dtmf);
+SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_t *channel, const char *dtmf_string);
 
 /*!
   \brief Retrieve DTMF digits from a given channel

Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Sat Jan 12 15:30:48 2008
@@ -845,6 +845,7 @@
   \return SWITCH_STATUS_SUCCESS if the dtmf was written
 */
 SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(_In_ switch_core_session_t *session, const switch_dtmf_t *dtmf);
+SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core_session_t *session, const char *dtmf_string);
 
 /*! 
   \brief RECV DTMF on a session

Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	Sat Jan 12 15:30:48 2008
@@ -2647,20 +2647,6 @@
 {
 	switch_event_t *event;
 	char *dtmf = (char *) data;
-	char *p;
-	switch_dtmf_t _dtmf = { 0, SWITCH_DEFAULT_DTMF_DURATION };
-	int tmp;
-
-	if ((p = strchr(dtmf, '+'))) {
-		tmp = atoi(p);
-		if (tmp > 0) {
-			if (member->orig_read_codec && member->orig_read_codec->implementation) {
-				_dtmf.duration = tmp * (member->orig_read_codec->implementation->samples_per_second / 1000);
-			} else {
-				_dtmf.duration = tmp * (member->conference->rate / 1000);
-			}
-		}
-	}
 	
 	if (member == NULL) {
 		stream->write_function(stream, "Invalid member!\n");
@@ -2676,12 +2662,7 @@
 	switch_mutex_lock(member->flag_mutex);
 	switch_core_session_kill_channel(member->session, SWITCH_SIG_BREAK);
 
-	p = dtmf;
-	while(p && *p && is_dtmf(*p)) {
-		_dtmf.digit = *p;
-		switch_core_session_send_dtmf(member->session, &_dtmf);
-		p++;
-	}
+	switch_core_session_send_dtmf_string(member->session, (char *)data);
 
 	switch_mutex_unlock(member->flag_mutex);
 	

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	Sat Jan 12 15:30:48 2008
@@ -181,17 +181,15 @@
 SWITCH_STANDARD_APP(queue_dtmf_function)
 {
 	switch_channel_t *channel;
-	char *p;
-	switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
+	channel = switch_core_session_get_channel(session);
+	switch_channel_queue_dtmf_string(channel, (const char *) data);
+	
+}
 
-	if (!switch_strlen_zero(data)) {
-		channel = switch_core_session_get_channel(session);
-		switch_assert(channel != NULL);
-		for (p = (char *)data; p && *p; p++) {
-			dtmf.digit = *p;
-			switch_channel_queue_dtmf(channel, &dtmf);
-		}
-	}
+
+SWITCH_STANDARD_APP(send_dtmf_function)
+{
+	switch_core_session_send_dtmf_string(session, (const char *) data);
 }
 
 SWITCH_STANDARD_APP(transfer_function)
@@ -1583,6 +1581,7 @@
 	SWITCH_ADD_APP(app_interface, "deflect", "Send call deflect", "Send a call deflect.", deflect_function, "<deflect_data>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "reject", "Send session reject (depricated)", "Send a respond message to a session.", respond_function, "<respond_data>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "queue_dtmf", "Queue dtmf to be sent", "Queue dtmf to be sent from a session", queue_dtmf_function, "<dtmf_data>", SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "send_dtmf", "Send dtmf to be sent", "Send dtmf to be sent from a session", send_dtmf_function, "<dtmf_data>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "sched_hangup", SCHED_HANGUP_DESCR, SCHED_HANGUP_DESCR, sched_hangup_function, "[+]<time> [<cause>]", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function, "[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function, "[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Sat Jan 12 15:30:48 2008
@@ -249,6 +249,51 @@
 }
 
 
+SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(switch_channel_t *channel, const char *dtmf_string)
+{
+	char *p;
+	switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
+	int sent = 0, dur;
+	char *string;
+	int i, argc;
+	char *argv[256];
+	
+
+	switch_assert(channel != NULL);
+
+	if (switch_strlen_zero(dtmf_string)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	string = switch_core_session_strdup(channel->session, dtmf_string);
+	argc = switch_separate_string(string, '+', argv, (sizeof(argv) / sizeof(argv[0])));
+	
+	for(i = 0; i < argc; i++) {
+		dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
+		dur = SWITCH_DEFAULT_DTMF_DURATION / 8;
+		if ((p = strchr(argv[i], '@'))) {
+			*p++ = '\0';
+			if ((dur = atoi(p)) > 50) {
+				dtmf.duration = dur * 8;
+			}
+		}
+
+		for (p = argv[i]; p && *p; p++) {
+			if (is_dtmf(*p)) {
+				dtmf.digit = *p;
+				if (switch_channel_queue_dtmf(channel, &dtmf) == SWITCH_STATUS_SUCCESS) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Queue dtmf\ndigit=%c ms=%u samples=%u\n",
+									  switch_channel_get_name(channel), dtmf.digit, dur, dtmf.duration);
+					sent++;
+				}
+			}
+		}
+		
+	}
+
+	return sent ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(switch_channel_t *channel, switch_dtmf_t *dtmf)
 {
 	switch_event_t *event;

Modified: freeswitch/trunk/src/switch_core_io.c
==============================================================================
--- freeswitch/trunk/src/switch_core_io.c	(original)
+++ freeswitch/trunk/src/switch_core_io.c	Sat Jan 12 15:30:48 2008
@@ -954,3 +954,54 @@
 
 	return status;
 }
+
+
+
+SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf_string(switch_core_session_t *session, const char *dtmf_string)
+{
+	char *p;
+	switch_dtmf_t dtmf = {0, SWITCH_DEFAULT_DTMF_DURATION};
+	int sent = 0, dur;
+	char *string;
+	int i, argc;
+	char *argv[256];
+	
+
+	switch_assert(session != NULL);
+
+	if (switch_strlen_zero(dtmf_string)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	string = switch_core_session_strdup(session, dtmf_string);
+	argc = switch_separate_string(string, '+', argv, (sizeof(argv) / sizeof(argv[0])));
+	
+	if (argc) {
+		switch_channel_pre_answer(session->channel);
+	}
+
+	for(i = 0; i < argc; i++) {
+		dtmf.duration = SWITCH_DEFAULT_DTMF_DURATION;
+		dur = SWITCH_DEFAULT_DTMF_DURATION / 8;
+		if ((p = strchr(argv[i], '@'))) {
+			*p++ = '\0';
+			if ((dur = atoi(p)) > 50) {
+				dtmf.duration = dur * 8;
+			}
+		}
+
+		for (p = argv[i]; p && *p; p++) {
+			if (is_dtmf(*p)) {
+				dtmf.digit = *p;
+				if (switch_core_session_send_dtmf(session, &dtmf) == SWITCH_STATUS_SUCCESS) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s send dtmf\ndigit=%c ms=%u samples=%u\n",
+									  switch_channel_get_name(session->channel), dtmf.digit, dur, dtmf.duration);
+					sent++;
+				}
+			}
+		}
+		
+	}
+
+	return sent ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
+}



More information about the Freeswitch-svn mailing list