[Freeswitch-svn] [commit] r5584 - freeswitch/branches/greenlizard/src/mod/asr_tts/mod_mrcprec

Freeswitch SVN greenlizard at freeswitch.org
Fri Aug 10 14:24:42 EDT 2007


Author: greenlizard
Date: Fri Aug 10 14:24:42 2007
New Revision: 5584

Modified:
   freeswitch/branches/greenlizard/src/mod/asr_tts/mod_mrcprec/Makefile
   freeswitch/branches/greenlizard/src/mod/asr_tts/mod_mrcprec/mod_mrcprec.c

Log:
Use configuration file instead of hardcoding parameters

Modified: freeswitch/branches/greenlizard/src/mod/asr_tts/mod_mrcprec/Makefile
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/asr_tts/mod_mrcprec/Makefile	(original)
+++ freeswitch/branches/greenlizard/src/mod/asr_tts/mod_mrcprec/Makefile	Fri Aug 10 14:24:42 2007
@@ -3,12 +3,18 @@
 
 # and define these variables to impact your build
 
+# TO GET THIS TO COMPILE
+# hack ../../../../build/modmake.rules and remove the
+# -Werror from the ALL_CFLAGS variable.  
+
 # TODO
-# - needs to compile/link against the freeswitch sofia libs
-# - tie up these includes somehow so there isn't so many
-# - ditto for the .a library files
+# - fix all the code that is causing warnings (We are currently working with Joe Stenbrenner from Division Management to have this task outsourced to Bangalore)
+# - re-enable the -Werror flag (see above)
+# - needs to compile/link against the _freeswitch_ sofia libs (see FIXME)
+# - is there an openmrcp dir in the fs tree yet?  (see FIXME)
 
-OPENMRCP_DIR=/usr/src/openmrcp_stable  # FIXME!!!
+# FIXME!!!  
+OPENMRCP_DIR=/usr/src/openmrcp_stable
 
 OPENMRCP_INCLUDE=-I$(OPENMRCP_DIR)/mrcpcore/client/include/ -I$(OPENMRCP_DIR)/platform/openmrcpclient/include/ -I$(OPENMRCP_DIR)/mediaframe/include/ -I$(OPENMRCP_DIR)/mrcpcore/engine/include/ -I$(OPENMRCP_DIR)/mrcpcore/include/ -I$(OPENMRCP_DIR)/mrcpcore/parser/include/ -I$(OPENMRCP_DIR)/mrcpcore/server/include/ -I$(OPENMRCP_DIR)/mrcpcore/media/include/ -I$(OPENMRCP_DIR)/mrcpcore/util/include -I$(OPENMRCP_DIR)/mrcpcore/resource/include/
 

Modified: freeswitch/branches/greenlizard/src/mod/asr_tts/mod_mrcprec/mod_mrcprec.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/asr_tts/mod_mrcprec/mod_mrcprec.c	(original)
+++ freeswitch/branches/greenlizard/src/mod/asr_tts/mod_mrcprec/mod_mrcprec.c	Fri Aug 10 14:24:42 2007
@@ -67,6 +67,16 @@
 SWITCH_MODULE_DEFINITION(mod_mrcprec, mod_mrcprec_load, 
 						 mod_mrcprec_shutdown, NULL);
 
+static struct {
+	char *client_ip;
+	char *server_ip;
+	uint32_t client_port;
+	uint32_t server_port;
+	uint32_t rtp_port_min;
+	uint32_t rtp_port_max;
+} globals;
+
+
 typedef enum {
 	OPENMRCP_EVENT_NONE,
 	OPENMRCP_EVENT_SESSION_INITIATE,
@@ -194,24 +204,18 @@
 	openmrcp_event_t *popped_event = NULL;
 	size_t sleep_ms = 100;
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "openmrcp_session_wait_for_event()\n");
 
 	if(openmrcp_session->event_queue) {
 		if (switch_queue_trypop(openmrcp_session->event_queue, &popped_event)) {
-			// most likely this failed because queue is empty.  how about we sleep for
-			// timeout seconds and try again?
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "did not pop anything from event queue\n");
-
+			// most likely this failed because queue is empty.  sleep for timeout seconds and try again?
 			if (timeout > 0) {
-
 				if (timeout < sleep_ms) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sleeping %d millieconds\n", timeout);
-					switch_sleep(timeout * 1000);  // convert milliseconds -> microseconds
+					switch_sleep(timeout * 1000);  // ms->us
 					timeout = 0;  
 				}
 				else {
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sleeping %d millieconds\n", sleep_ms);
-					switch_sleep(sleep_ms * 1000);  // convert milliseconds -> microseconds
+					switch_sleep(sleep_ms * 1000);  // ms->us
 					timeout -= sleep_ms;  
 				}
 
@@ -355,39 +359,20 @@
 }
 
 
-/* this needs to be moved to a config file */
+
 static apr_status_t set_default_options(openmrcp_client_options_t *options)
 {
-	options->client_ip = NULL;
-	options->client_port = 0;
-	options->server_ip = NULL;
-	options->server_port = 0;
-	options->rtp_port_min = 0;
-	options->rtp_port_max = 0;
 	mrcp_logger.priority = MRCP_PRIO_INFO;
-
-	if(options->client_ip == NULL) {
-		options->client_ip = "127.0.0.1";
-	}
-	if(options->client_port == 0) {
-		options->client_port = 8062;
-	}
-	if(options->server_ip == NULL) {
-		options->server_ip = "127.0.0.1";
-	}
-	if(options->server_port == 0) {
-		options->server_port = 8060;
-	}
-	if(options->rtp_port_min == 0) {
-		options->rtp_port_min = 4000;
-	}
-	if(options->rtp_port_max == 0) {
-		options->rtp_port_max = 6000;
-	}
-
+	options->client_ip = globals.client_ip;
+	options->server_ip = globals.server_ip;
+	options->client_port = globals.client_port;
+	options->server_port = globals.server_port;
+	options->rtp_port_min = globals.rtp_port_min;
+	options->rtp_port_max = globals.rtp_port_max;
 	return APR_SUCCESS;
 }
 
+
 /** 
  * Called back by openmcp client thread every time its ready for more audio 
  * Reads data that was put into a shared fifo queue upon receiving audio frames
@@ -487,22 +472,24 @@
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "asr_open called, codec: %s, rate: %d\n", codec, rate);
 
 	/*! 
-	  sanity checking regarding codec/rate - NOTE: some of the other codecs and rates might
-	  actually work, but since they have not been tested yet, they are currently not
-	  allowed.  forcing MRCP to use 20 as the CODEC_FRAME_TIME_BASE effectively ensures
+	  NOTE: According to the current FS media bugs design, the media bug can only feed audio
+	  data in SLIN (L16) format.  So we dont need to worry about other codecs.
+
+	  NOTE: forcing MRCP to use 20 as the CODEC_FRAME_TIME_BASE effectively ensures
 	  that it matches with 16-bit audio at 8kz with 320 byte frames.  in testing, leaving
 	  CODEC_FRAME_TIME_BASE at 10 and using pop (instead of trypop) in 
 	  openmrcp_recognizer_read_frame() actually produces clean audio, however it causes 
       other problems as the full channel/session cleanup never completes in openmrcp, most 
 	  likely due to a thread being blocked on a pop call from audio queue.  but with trypop 
 	  (to avoid the cleanup problem), it only produces clean audio when CODEC_FRAME_TIME_BASE 
-	  is set to 20.
+	  is set to 20. 
 	 */
 	if (strcmp(codec,"L16")) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sorry, only L16 codec supported\n");
 		return SWITCH_STATUS_GENERR;		
 	}
 	if (rate != 8000) {
+		// TODO: look into supporting other sample rates
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Sorry, only 8kz supported\n");
 		return SWITCH_STATUS_GENERR;		
 	}
@@ -619,8 +606,14 @@
 		return SWITCH_STATUS_MEMERR;
 	}
 	
-	/** since *data buffer might get freed by caller (true or false?), allocate a
-		new buffer and copy *data into it **/
+	/**
+	 * since *data buffer might get freed by caller (true or false?), allocate a
+	 * new buffer and copy *data into it.
+	 *
+	 * MAJOR DESIGN ISSUE!!  It is way too expensive to be calling malloc on every audio frame,
+	 * this needs to send the packet directly.  OpenMrcp will need a way to disable their own
+	 * timer so that the fs timer is the only one driving the media.
+	 **/
 	buffer = (switch_byte_t *) switch_core_alloc(openmrcp_session->pool, sizeof(switch_byte_t)*len);
 	if (!buffer) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate buffer\n");
@@ -810,6 +803,45 @@
 };
 
 
+static switch_status_t do_config(void)
+{
+	char *cf = "mod_openmrcp.conf";
+	switch_xml_t cfg, xml, settings, param;
+
+	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
+		return SWITCH_STATUS_TERM;
+	}
+
+	memset(&globals,0,sizeof(globals));
+
+	if ((settings = switch_xml_child(cfg, "settings"))) {
+		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
+			char *var = (char *) switch_xml_attr_soft(param, "name");
+			char *val = (char *) switch_xml_attr_soft(param, "value");
+
+			if (!strcasecmp(var, "client_ip")) {
+				globals.client_ip = val;
+			} else if (!strcasecmp(var, "server_ip")) {
+				globals.server_ip = val;
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.server_ip: %s\n", globals.server_ip);
+			} else if (!strcasecmp(var, "client_port")) {
+				globals.client_port = (uint32_t) atoi(val);
+			} else if (!strcasecmp(var, "server_port")) {
+				globals.server_port = (uint32_t) atoi(val);
+			} else if (!strcasecmp(var, "rtp_port_min")) {
+				globals.rtp_port_min = (uint32_t) atoi(val);
+			} else if (!strcasecmp(var, "rtp_port_max")) {
+				globals.rtp_port_max = (uint32_t) atoi(val);
+			}
+
+		}
+	}
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+
 static switch_status_t mrcp_init()
 {
 	/*!
@@ -860,6 +892,9 @@
 
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &mrcprec_module_interface;
+
+	/* read config */
+	do_config();
 	
 	/* initialize openmrcp */
 	mrcp_global_init();



More information about the Freeswitch-svn mailing list