[Freeswitch-svn] [commit] r3485 - in freeswitch/trunk/src: . include mod/languages/mod_spidermonkey

Freeswitch SVN anthm at freeswitch.org
Wed Nov 29 12:10:41 EST 2006


Author: anthm
Date: Wed Nov 29 12:10:40 2006
New Revision: 3485

Modified:
   freeswitch/trunk/src/include/switch_module_interfaces.h
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/trunk/src/switch_event.c
   freeswitch/trunk/src/switch_ivr.c

Log:
api tweaks

Modified: freeswitch/trunk/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/trunk/src/include/switch_module_interfaces.h	(original)
+++ freeswitch/trunk/src/include/switch_module_interfaces.h	Wed Nov 29 12:10:40 2006
@@ -313,6 +313,8 @@
 	void *private_info;
 	int64_t pos;
 	switch_buffer_t *audio_buffer;
+    uint32_t thresh;
+    uint32_t silence_hits;
 };
 
 /*! \brief Abstract interface to an asr module */

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Wed Nov 29 12:10:40 2006
@@ -828,7 +828,7 @@
 	int len = 0;
 	switch_input_callback_function_t dtmf_func = NULL;
 	struct input_callback_state cb_state = {0};
-	switch_file_handle_t fh;
+	switch_file_handle_t fh = {0};
 	JSFunction *function;
     int32 limit = 0;
 
@@ -860,9 +860,21 @@
         if (argc > 3) {
             JS_ValueToInt32(cx, argv[3], &limit);
         }
+
+        if (argc > 4) {
+            int32_t thresh;
+            JS_ValueToInt32(cx, argv[4], &thresh);
+            fh.thresh = thresh;
+        }
+
+        if (argc > 5) {
+            int32_t silence_hits;
+            JS_ValueToInt32(cx, argv[5], &silence_hits);
+            fh.silence_hits = silence_hits;
+        }
 	}
 
-	memset(&fh, 0, sizeof(fh));
+    
 	cb_state.extra = &fh;
 	cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
 	switch_ivr_record_file(jss->session, &fh, file_name, dtmf_func, bp, len, limit);
@@ -925,7 +937,7 @@
 	int len = 0;
 	switch_input_callback_function_t dtmf_func = NULL;
 	struct input_callback_state cb_state = {0};
-	switch_file_handle_t fh;
+	switch_file_handle_t fh = {0};
 	JSFunction *function;
 
 	channel = switch_core_session_get_channel(jss->session);
@@ -963,12 +975,10 @@
 
     if (argc > 4) {
         int32 samps;
-        uint32_t pos = 0;
         JS_ValueToInt32(cx, argv[4], &samps);
-        switch_core_file_seek(&fh, &pos, samps, SEEK_CUR);
+        fh.samples = samps;
     }
 
-	memset(&fh, 0, sizeof(fh));
 	cb_state.extra = &fh;
 	cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
 	switch_ivr_play_file(jss->session, &fh, file_name, timer_name, dtmf_func, bp, len);

Modified: freeswitch/trunk/src/switch_event.c
==============================================================================
--- freeswitch/trunk/src/switch_event.c	(original)
+++ freeswitch/trunk/src/switch_event.c	Wed Nov 29 12:10:40 2006
@@ -606,7 +606,9 @@
 	
 	*str = NULL;
 
-	if (!(buf = malloc(blocksize))) {
+	dlen = blocksize * 2;
+
+	if (!(buf = malloc(dlen))) {
 		return SWITCH_STATUS_MEMERR;
 	}
 
@@ -615,9 +617,7 @@
         return SWITCH_STATUS_MEMERR;
     }
 
-	dlen = blocksize;
-
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hit serialze!.\n");
+    //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hit serialze!.\n");
 	for (hp = event->headers; hp; hp = hp->next) {
         /*
          * grab enough memory to store 3x the string (url encode takes one char and turns it into %XX)
@@ -628,7 +628,7 @@
          */
         if(encode_len < ((strlen(hp->value) * 3) + 1)) {
             char* tmp;
-	        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Allocing %d was %d.\n", ((strlen(hp->value) * 3) + 1), encode_len);
+	        //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Allocing %d was %d.\n", ((strlen(hp->value) * 3) + 1), encode_len);
             /* we can use realloc for initial alloc as well, if encode_buf is zero it treats it as a malloc */
             if(!(tmp = realloc(encode_buf, ((strlen(hp->value) * 3) + 1)))) {
                 /* oh boy, ram's gone, give back what little we grabbed and bail */

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Wed Nov 29 12:10:40 2006
@@ -428,6 +428,12 @@
         start = time(NULL);
     }
 
+    if (fh->thresh) {
+        if (!fh->silence_hits) {
+            fh->silence_hits = 20;
+        }
+    }
+
 	while(switch_channel_ready(channel)) {
 		switch_size_t len;
 		switch_event_t *event;
@@ -477,6 +483,26 @@
 		if (!SWITCH_READ_ACCEPTABLE(status)) {
 			break;
 		}
+
+        if (fh->thresh) {
+            int16_t *fdata = (int16_t *) read_frame->data;
+            uint32_t samples = read_frame->datalen / sizeof(*fdata);
+            uint32_t score, count = 0, j = 0;
+            double energy = 0;
+
+            for (count = 0; count < samples; count++) {
+                energy += abs(fdata[j]);
+                j += read_codec->implementation->number_of_channels;
+            }
+		
+            score = energy / samples;
+            if (score < fh->thresh) {
+                if (!--fh->silence_hits) {
+                    break;
+                }
+            }
+        }
+
 		if (!switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
 			len = (switch_size_t) read_frame->datalen / 2;
 			switch_core_file_write(fh, read_frame->data, &len);
@@ -983,6 +1009,10 @@
 	write_frame.data = abuf;
 	write_frame.buflen = sizeof(abuf);
 
+    if (fh->samples) {
+        uint32_t pos = 0;
+        switch_core_file_seek(fh, &pos, fh->samples, SEEK_CUR);
+    }
 	
 	if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_TITLE, &p) == SWITCH_STATUS_SUCCESS) {
 		title = (char *) switch_core_session_strdup(session, (char *)p);



More information about the Freeswitch-svn mailing list