[Freeswitch-branches] [commit] r5395 - in freeswitch/branches/greenlizard: . build src src/include src/mod/applications/mod_conference src/mod/applications/mod_dptools src/mod/endpoints/mod_sofia src/mod/event_handlers/mod_radius_cdr src/mod/languages/mod_spidermonkey

Freeswitch SVN greenlizard at freeswitch.org
Tue Jun 19 19:32:05 EDT 2007


Author: greenlizard
Date: Tue Jun 19 19:32:04 2007
New Revision: 5395

Modified:
   freeswitch/branches/greenlizard/build/modules.conf.in
   freeswitch/branches/greenlizard/configure.in
   freeswitch/branches/greenlizard/src/include/switch_ivr.h
   freeswitch/branches/greenlizard/src/include/switch_stun.h
   freeswitch/branches/greenlizard/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/branches/greenlizard/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/branches/greenlizard/src/mod/event_handlers/mod_radius_cdr/README
   freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h
   freeswitch/branches/greenlizard/src/switch_core_media_bug.c
   freeswitch/branches/greenlizard/src/switch_ivr_async.c
   freeswitch/branches/greenlizard/src/switch_ivr_originate.c
   freeswitch/branches/greenlizard/src/switch_ivr_play_say.c

Log:
merge trunk version 5382 to 5394

Modified: freeswitch/branches/greenlizard/build/modules.conf.in
==============================================================================
--- freeswitch/branches/greenlizard/build/modules.conf.in	(original)
+++ freeswitch/branches/greenlizard/build/modules.conf.in	Tue Jun 19 19:32:04 2007
@@ -31,6 +31,7 @@
 #event_handlers/mod_cdr
 #event_handlers/mod_event_multicast
 event_handlers/mod_event_socket
+#event_handlers/mod_radius_cdr
 #event_handlers/mod_event_test
 #event_handlers/mod_xmpp_event
 #event_handlers/mod_zeroconf

Modified: freeswitch/branches/greenlizard/configure.in
==============================================================================
--- freeswitch/branches/greenlizard/configure.in	(original)
+++ freeswitch/branches/greenlizard/configure.in	Tue Jun 19 19:32:04 2007
@@ -334,6 +334,7 @@
                 src/mod/Makefile
                 src/mod/event_handlers/mod_cdr/Makefile
                 src/mod/endpoints/mod_sofia/Makefile
+                src/mod/event_handlers/mod_radius_cdr/Makefile
                 src/include/switch_am_config.h
                 build/getlib.sh
                 build/modmake.rules])

Modified: freeswitch/branches/greenlizard/src/include/switch_ivr.h
==============================================================================
--- freeswitch/branches/greenlizard/src/include/switch_ivr.h	(original)
+++ freeswitch/branches/greenlizard/src/include/switch_ivr.h	Tue Jun 19 19:32:04 2007
@@ -267,6 +267,7 @@
 */
 SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, char *file, switch_input_args_t *args);
 
+SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *session, char *script, int32_t loops, switch_input_args_t *args);
 
 /*!
   \brief record a file from the session to a file

Modified: freeswitch/branches/greenlizard/src/include/switch_stun.h
==============================================================================
--- freeswitch/branches/greenlizard/src/include/switch_stun.h	(original)
+++ freeswitch/branches/greenlizard/src/include/switch_stun.h	Tue Jun 19 19:32:04 2007
@@ -106,12 +106,12 @@
 typedef struct {
 	int16_t type;
 	uint16_t length;
-	char value[1];
+	char value[];
 } switch_stun_packet_attribute_t;
 
 typedef struct {
 	switch_stun_packet_header_t header;
-	uint8_t first_attribute[1];
+	uint8_t first_attribute[];
 } switch_stun_packet_t;
 
 typedef struct {
@@ -228,7 +228,7 @@
   \param packet the packet in question
   \return the size in bytes (host order) of the entire packet
 */
-#define switch_stun_packet_length(packet) ntohs(packet->header.length) + sizeof(switch_stun_packet_header_t)
+#define switch_stun_packet_length(packet) ntohs(packet->header.length) + (sizeof(switch_stun_packet_header_t))
 ///\}
 
 SWITCH_END_EXTERN_C

Modified: freeswitch/branches/greenlizard/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/branches/greenlizard/src/mod/applications/mod_conference/mod_conference.c	Tue Jun 19 19:32:04 2007
@@ -2118,7 +2118,7 @@
 	char *dfile = NULL, *expanded = NULL;
 
 	if (member != NULL && file != NULL) {
-		conference_file_node_t *fnode, *nptr;
+		conference_file_node_t *fnode, *nptr = NULL;
 		switch_memory_pool_t *pool;
 
 		if ((expanded = switch_channel_expand_variables(switch_core_session_get_channel(member->session), file)) != file) {
@@ -2128,7 +2128,7 @@
 		}
 
 		if (!strncasecmp(file, "say:", 4)) {
-			status = conference_say(member->conference, file + 4, leadin);
+			status = conference_member_say(member, file + 4, leadin);
 			goto done;
 		}
 
@@ -2139,7 +2139,7 @@
 				}
 				file = dfile;
 			} else {
-				status = conference_say(member->conference, file, leadin);
+				status = conference_member_say(member, file, leadin);
 				goto done;
 			}
 		}

Modified: freeswitch/branches/greenlizard/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/branches/greenlizard/src/mod/applications/mod_dptools/mod_dptools.c	Tue Jun 19 19:32:04 2007
@@ -820,6 +820,35 @@
 
 }
 
+static void gentones_function(switch_core_session_t *session, char *data)
+{
+	switch_channel_t *channel;
+	char *tone_script = NULL;
+	switch_input_args_t args = { 0 };
+	char *l;
+	int32_t loops = 0;
+
+	tone_script = switch_core_session_strdup(session, data);
+
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
+	
+	switch_channel_pre_answer(channel);
+
+	if ((l = strchr(tone_script, '|'))) {
+		*l++ = '\0';
+		loops = atoi(l);
+
+		if (loops < 0) {
+			loops = -1;
+		}
+	}
+
+	args.input_callback = on_dtmf;
+	switch_ivr_gentones(session, tone_script, loops, &args);
+
+}
+
 static void displace_session_function(switch_core_session_t *session, char *data)
 {
 	switch_channel_t *channel;
@@ -1064,7 +1093,7 @@
 };
 
 static switch_application_interface_t displace_application_interface = {
-	/*.interface_name */ "displace",
+	/*.interface_name */ "displace_session",
 	/*.application_function */ displace_session_function,
 	/* long_desc */ "Displace audio from a file to the channels input",
 	/* short_desc */ "Displace File",
@@ -1074,7 +1103,7 @@
 };
 
 static switch_application_interface_t stop_displace_application_interface = {
-	/*.interface_name */ "displace",
+	/*.interface_name */ "stop_displace_session",
 	/*.application_function */ stop_displace_session_function,
 	/* long_desc */ "Stop Displacing to a file",
 	/* short_desc */ "Stop Displace File",
@@ -1124,6 +1153,17 @@
 	/* flags */ SAF_NONE,
 	/*.next */ &stop_record_session_application_interface
 };
+
+static switch_application_interface_t gentones_application_interface = {
+	/*.interface_name */ "gentones",
+	/*.application_function */ gentones_function,
+	/* long_desc */ "Generate tones to the channel",
+	/* short_desc */ "Generate Tones",
+	/* syntax */ "<tgml_script>[|<loops>]",
+	/* flags */ SAF_NONE,
+	/*.next */ &playback_application_interface
+};
+
 static switch_application_interface_t park_application_interface = {
 	/*.interface_name */ "park",
 	/*.application_function */ park_function,
@@ -1131,7 +1171,7 @@
 	/* short_desc */ NULL,
 	/* syntax */ NULL,
 	/* flags */ SAF_NONE,
-	/*.next */ &playback_application_interface
+	/*.next */ &gentones_application_interface
 };
 
 static switch_application_interface_t echo_application_interface = {

Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_sofia/mod_sofia.c	Tue Jun 19 19:32:04 2007
@@ -227,6 +227,8 @@
 		switch_core_session_rwunlock(a_session);
 	}
 
+	switch_mutex_lock(tech_pvt->profile->flag_mutex);
+
 	if (tech_pvt->nh) {
 		if (!switch_test_flag(tech_pvt, TFLAG_BYE)) {
 			if (switch_test_flag(tech_pvt, TFLAG_ANS)) {
@@ -241,13 +243,11 @@
 					nua_cancel(tech_pvt->nh, TAG_END());
 				}
 			}
-			switch_set_flag_locked(tech_pvt, TFLAG_BYE);
+			switch_set_flag(tech_pvt, TFLAG_BYE);
 		}
 	}
 
-	switch_clear_flag_locked(tech_pvt, TFLAG_IO);
-
-
+	switch_clear_flag(tech_pvt, TFLAG_IO);
 	tech_pvt->profile->inuse--;
 	switch_mutex_unlock(tech_pvt->profile->flag_mutex);
 

Modified: freeswitch/branches/greenlizard/src/mod/event_handlers/mod_radius_cdr/README
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/event_handlers/mod_radius_cdr/README	(original)
+++ freeswitch/branches/greenlizard/src/mod/event_handlers/mod_radius_cdr/README	Tue Jun 19 19:32:04 2007
@@ -28,17 +28,31 @@
 
 1) Compile and install freeradius-client library.
 
-2) Edit the top-level 'modules.conf'.  Add the following entry:
+2) Edit the top level 'configure.in'.  At approx line 336 you need to add:
+
+---
+AC_CONFIG_FILES([Makefile
+                src/Makefile
+                src/mod/Makefile
+                src/mod/event_handlers/mod_cdr/Makefile
++               src/mod/event_handlers/mod_radius_cdr/Makefile
+                src/mod/endpoints/mod_sofia/Makefile
+                src/include/switch_am_config.h
+                build/getlib.sh
+                build/modmake.rules])
+---
+
+3) Rerun bootstrap, re-run configure
+
+4) Edit the top-level 'modules.conf'.  Add the following entry:
 
 ...
 event_handlers/mod_radius_cdr
 ...
 
-3) Re-run configure ??? ( does this need to be done???)
-
-4) Run make, and make install.  Make sure the module is built and installed.
+5) Run make, and make install.  Make sure the module is built and installed.
 
-5) Configure FreeSWITCH to load it
+6) Configure FreeSWITCH to load mod_radius_cdr
 
    - Copy the 'mod_radius_cdr.conf.xml' file to the FreeSWITCH conf directory
    - Copy the 'radius/' directory to the FreeSWITCH conf directory

Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Tue Jun 19 19:32:04 2007
@@ -63,6 +63,7 @@
 static void session_destroy(JSContext * cx, JSObject * obj);
 static JSBool session_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval);
 static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval);
+static JSBool session_set_callerdata(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval);
 static switch_api_interface_t js_run_interface;
 static switch_api_interface_t jsapi_interface;
 
@@ -80,7 +81,7 @@
 
 static JSClass global_class = {
 	"Global", JSCLASS_HAS_PRIVATE,
-	JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, DEFAULT_SET_PROPERTY,
+	JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
 };
 
@@ -1994,6 +1995,7 @@
 
 static JSFunctionSpec session_methods[] = {
 	{"originate", session_originate, 2},
+	{"setCallerData", session_set_callerdata, 2},
 	{"setHangupHook", session_hanguphook, 1},
 	{"setAutoHangup", session_autohangup, 1},
 	{"sayPhrase", session_sayphrase, 1},
@@ -2173,6 +2175,51 @@
 	return JS_TRUE;
 }
 
+static JSBool session_set_callerdata(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
+{
+	struct js_session *jss = NULL;
+	jss = JS_GetPrivate(cx, obj);
+	*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
+
+	if (argc > 1) {
+		char *var, *val, **toset = NULL;
+		var = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
+		val = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
+		
+		if (!strcasecmp(var, "dialplan")) {
+			toset = &jss->dialplan;
+		} else if (!strcasecmp(var, "username")) {
+			toset = &jss->username;
+		} else if (!strcasecmp(var, "caller_id_name")) {
+			toset = &jss->caller_id_name;
+		} else if (!strcasecmp(var, "ani")) {
+			toset = &jss->ani;
+		} else if (!strcasecmp(var, "aniii")) {
+			toset = &jss->aniii;
+		} else if (!strcasecmp(var, "caller_id_number")) {
+			toset = &jss->caller_id_number;
+		} else if (!strcasecmp(var, "network_addr")) {
+			toset = &jss->network_addr;
+		} else if (!strcasecmp(var, "rdnis")) {
+			toset = &jss->rdnis;
+		} else if (!strcasecmp(var, "destination_number")) {
+			toset = &jss->destination_number;
+		} else if (!strcasecmp(var, "context")) {
+			toset = &jss->context;
+		} 
+		
+		if (toset) {
+			switch_safe_free(*toset);
+			*toset = strdup(val);
+		}
+
+	}
+	
+	return JS_TRUE;
+
+}
+
+
 static JSBool session_originate(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
 {
 	struct js_session *jss = NULL;
@@ -2196,7 +2243,8 @@
 		char *context = "";
 		char *username = NULL;
 		char *to = NULL;
-
+		char *tmp;
+			
 		*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
 
 		if (JS_ValueToObject(cx, argv[0], &session_obj)) {
@@ -2215,6 +2263,15 @@
 			}
 		}
 
+		if (!switch_strlen_zero(jss->dialplan)) dialplan = jss->dialplan;
+		if (!switch_strlen_zero(jss->caller_id_name)) cid_name = jss->caller_id_name;
+		if (!switch_strlen_zero(jss->caller_id_number)) cid_num = jss->caller_id_number;
+		if (!switch_strlen_zero(jss->ani)) ani = jss->ani;
+		if (!switch_strlen_zero(jss->aniii)) aniii = jss->aniii;
+		if (!switch_strlen_zero(jss->rdnis)) rdnis = jss->rdnis;
+		if (!switch_strlen_zero(jss->context)) context = jss->context;
+		if (!switch_strlen_zero(jss->username)) username = jss->username;
+
 		dest = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
 
 		if (!strchr(dest, '/')) {
@@ -2223,36 +2280,12 @@
 		}
 
 		if (argc > 2) {
-			dialplan = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
+			tmp = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
+			if (!switch_strlen_zero(tmp)) {
+				to = tmp;
+			}	
 		}
-		if (argc > 3) {
-			context = JS_GetStringBytes(JS_ValueToString(cx, argv[3]));
-		}
-		if (argc > 4) {
-			cid_name = JS_GetStringBytes(JS_ValueToString(cx, argv[4]));
-		}
-		if (argc > 5) {
-			cid_num = JS_GetStringBytes(JS_ValueToString(cx, argv[5]));
-		}
-		if (argc > 6) {
-			network_addr = JS_GetStringBytes(JS_ValueToString(cx, argv[6]));
-		}
-		if (argc > 7) {
-			ani = JS_GetStringBytes(JS_ValueToString(cx, argv[7]));
-		}
-		if (argc > 8) {
-			aniii = JS_GetStringBytes(JS_ValueToString(cx, argv[8]));
-		}
-		if (argc > 9) {
-			rdnis = JS_GetStringBytes(JS_ValueToString(cx, argv[9]));
-		}
-		if (argc > 10) {
-			username = JS_GetStringBytes(JS_ValueToString(cx, argv[10]));
-		}
-		if (argc > 11) {
-			to = JS_GetStringBytes(JS_ValueToString(cx, argv[11]));
-		}
-
+		
 		if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
 			return JS_FALSE;
@@ -2293,18 +2326,28 @@
 			if (jss->session) {
 				channel = switch_core_session_get_channel(jss->session);
 				switch_channel_set_private(channel, "jss", NULL);
-			}
+				switch_core_event_hook_remove_state_change(jss->session, hanguphook);
 
-			switch_core_event_hook_remove_state_change(jss->session, hanguphook);
-			
-			if (channel && switch_test_flag(jss, S_HUP)) {
-				switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
-			}
+				if (switch_test_flag(jss, S_HUP)) {
+					switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+				}
+
+				if (switch_test_flag(jss, S_RDLOCK)) {
+					switch_core_session_rwunlock(jss->session);
+				}
 
-			if (jss->session && switch_test_flag(jss, S_RDLOCK)) {
-				switch_core_session_rwunlock(jss->session);
+				switch_safe_free(jss->dialplan);
+				switch_safe_free(jss->username);
+				switch_safe_free(jss->caller_id_name);
+				switch_safe_free(jss->ani);
+				switch_safe_free(jss->aniii);
+				switch_safe_free(jss->caller_id_number);
+				switch_safe_free(jss->network_addr);
+				switch_safe_free(jss->rdnis);
+				switch_safe_free(jss->destination_number);
+				switch_safe_free(jss->context);
 			}
-			
+
 			if (switch_test_flag(jss, S_FREE)) {
 				free(jss);
 			}

Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h	(original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey/mod_spidermonkey.h	Tue Jun 19 19:32:04 2007
@@ -131,6 +131,16 @@
 	JSFunction *on_hangup;
 	int stack_depth;
 	switch_channel_state_t hook_state;
+	char *destination_number;
+	char *dialplan;
+	char *caller_id_name;
+	char *caller_id_number;
+	char *network_addr;
+	char *ani;
+	char *aniii;
+	char *rdnis;
+	char *context;
+	char *username;
 };
 
 JSBool DEFAULT_SET_PROPERTY(JSContext * cx, JSObject *obj, jsval id, jsval *vp)

Modified: freeswitch/branches/greenlizard/src/switch_core_media_bug.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_core_media_bug.c	(original)
+++ freeswitch/branches/greenlizard/src/switch_core_media_bug.c	Tue Jun 19 19:32:04 2007
@@ -156,10 +156,11 @@
 														  switch_media_bug_callback_t callback,
 														  void *user_data, time_t stop_time, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug)
 {
-	switch_media_bug_t *bug, *bp;
+	switch_media_bug_t *bug;//, *bp;
 	switch_size_t bytes;
 
 	if (flags & SMBF_WRITE_REPLACE) {
+#if 0
 		switch_thread_rwlock_wrlock(session->bug_rwlock);
 		for (bp = session->bugs; bp; bp = bp->next) {
 			if (switch_test_flag(bp, SMBF_WRITE_REPLACE)) {
@@ -169,9 +170,11 @@
 			}
 		}
 		switch_thread_rwlock_unlock(session->bug_rwlock);
+#endif
 	}
 
 	if (flags & SMBF_READ_REPLACE) {
+#if 0
 		switch_thread_rwlock_wrlock(session->bug_rwlock);
 		for (bp = session->bugs; bp; bp = bp->next) {
 			if (switch_test_flag(bp, SMBF_READ_REPLACE)) {
@@ -181,6 +184,7 @@
 			}
 		}
 		switch_thread_rwlock_unlock(session->bug_rwlock);
+#endif
 	}
 
 	if (!(bug = switch_core_session_alloc(session, sizeof(*bug)))) {

Modified: freeswitch/branches/greenlizard/src/switch_ivr_async.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_ivr_async.c	(original)
+++ freeswitch/branches/greenlizard/src/switch_ivr_async.c	Tue Jun 19 19:32:04 2007
@@ -605,7 +605,7 @@
 	  }
 
 	  for(i = 0; i < cont->index; i++) {
-		  if (!strcasecmp(key, cont->list[cont->index].key )) {
+		  if (!switch_strlen_zero(cont->list[cont->index].key) && !strcasecmp(key, cont->list[cont->index].key)) {
 			  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Renabling %s\n", key);
 			  cont->list[cont->index].up = 1;
 			  teletone_multi_tone_init(&cont->list[i].mt, &cont->list[i].map);
@@ -663,7 +663,7 @@
   teletone_multi_tone_init(&cont->list[cont->index].mt, &cont->list[cont->index].map);
   cont->session = session;
   
-  switch_channel_answer(channel);
+  switch_channel_pre_answer(channel);
   
   if (switch_strlen_zero(flags)) {
 	  bflags = SMBF_READ_REPLACE;

Modified: freeswitch/branches/greenlizard/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_ivr_originate.c	(original)
+++ freeswitch/branches/greenlizard/src/switch_ivr_originate.c	Tue Jun 19 19:32:04 2007
@@ -663,6 +663,7 @@
 
 							} else {
 								teletone_init_session(&ringback.ts, 0, teletone_handler, &ringback);
+								ringback.ts.rate = read_codec->implementation->samples_per_second;
 								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Play Ringback Tone [%s]\n", ringback_data);
 								//ringback.ts.debug = 1;
 								//ringback.ts.debug_stream = switch_core_get_console();

Modified: freeswitch/branches/greenlizard/src/switch_ivr_play_say.c
==============================================================================
--- freeswitch/branches/greenlizard/src/switch_ivr_play_say.c	(original)
+++ freeswitch/branches/greenlizard/src/switch_ivr_play_say.c	Tue Jun 19 19:32:04 2007
@@ -477,6 +477,94 @@
 	return status;
 }
 
+static int teletone_handler(teletone_generation_session_t * ts, teletone_tone_map_t * map)
+{
+	switch_buffer_t *audio_buffer = ts->user_data;
+	int wrote;
+
+	if (!audio_buffer) {
+		return -1;
+	}
+
+	wrote = teletone_mux_tones(ts, map);
+	switch_buffer_write(audio_buffer, ts->buffer, wrote * 2);
+
+	return 0;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_gentones(switch_core_session_t *session, char *script, int32_t loops, switch_input_args_t *args)
+{
+	teletone_generation_session_t ts;
+	switch_buffer_t *audio_buffer;
+	switch_frame_t *read_frame = NULL;
+	switch_codec_t *read_codec = NULL, write_codec;
+	switch_frame_t write_frame;
+	switch_byte_t data[1024];
+	switch_channel_t *channel;
+
+	assert(session != NULL);
+
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
+
+	switch_channel_pre_answer(channel);
+	read_codec = switch_core_session_get_read_codec(session);
+
+	if (switch_core_codec_init(&write_codec,
+							   "L16",
+							   NULL,
+							   read_codec->implementation->samples_per_second,
+							   read_codec->implementation->microseconds_per_frame / 1000,
+							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, 
+							   NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+
+		return SWITCH_STATUS_FALSE;
+	}
+
+	write_frame.codec = &write_codec;
+	write_frame.data = data;
+
+	switch_buffer_create_dynamic(&audio_buffer, 512, 1024, 0);
+	teletone_init_session(&ts, 0, teletone_handler, audio_buffer);
+	ts.rate = read_codec->implementation->samples_per_second;
+
+	teletone_run(&ts, script);
+
+	if (loops) {
+		switch_buffer_set_loops(audio_buffer, loops);
+	}
+
+	while(switch_channel_ready(channel)) {
+		switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
+		
+		if (!SWITCH_READ_ACCEPTABLE(status)) {
+			break;
+		}
+
+		if (read_frame->datalen < 2 || switch_test_flag(read_frame, SFF_CNG)) {
+			continue;
+		}
+
+		if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(audio_buffer, write_frame.data,
+																	  read_frame->codec->implementation->bytes_per_frame)) <= 0) {
+			break;
+		}
+
+		write_frame.samples = write_frame.datalen / 2;
+		
+		if (switch_core_session_write_frame(session, &write_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
+			break;
+		}
+	}
+
+	switch_core_codec_destroy(&write_codec);
+	switch_buffer_destroy(&audio_buffer);
+	teletone_destroy_session(&ts);
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+
 #define FILE_STARTSAMPLES 1024 * 32
 #define FILE_BLOCKSIZE 1024 * 8
 #define FILE_BUFSIZE 1024 * 64



More information about the Freeswitch-branches mailing list