[Freeswitch-svn] [commit] r5594 - freeswitch/branches/greenlizard/src/mod/asr_tts/mod_openmrcp

Freeswitch SVN greenlizard at freeswitch.org
Mon Aug 13 17:40:49 EDT 2007


Author: greenlizard
Date: Mon Aug 13 17:40:48 2007
New Revision: 5594

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

Log:
sync up Makefile to what was checked into trunk.  tts audio sounding ok, going to deal with channel close events from tts source

Modified: freeswitch/branches/greenlizard/src/mod/asr_tts/mod_openmrcp/Makefile
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/asr_tts/mod_openmrcp/Makefile	(original)
+++ freeswitch/branches/greenlizard/src/mod/asr_tts/mod_openmrcp/Makefile	Mon Aug 13 17:40:48 2007
@@ -11,18 +11,15 @@
 # - re-enable the -Werror flag after openmrcp compilation warnings are fixed
 # - needs to compile/link against the _freeswitch_ sofia libs (see FIXME)
 # - Should this download and build openmrcp?  What's the plan? (see FIXME)
+# - somehow consolidate libs and includes into less files
 
 # FIXME!!!  
 OPENMRCP_DIR=/usr/src/openmrcp_trunk
 
 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/
 
-OPENMRCP_LIBS_TRUNK=$(OPENMRCP_DIR)/platform/openmrcpclient/.libs/libopenmrcpclient.a $(OPENMRCP_DIR)/platform/openmrcpserver/.libs/libopenmrcpserver.a $(OPENMRCP_DIR)/mrcpcore/client/.libs/libmrcpclient.a $(OPENMRCP_DIR)/mediaframe/.libs/libmediaframe.a $(OPENMRCP_DIR)/mrcpcore/engine/.libs/libmrcpengine.a $(OPENMRCP_DIR)/mrcpcore/parser/.libs/libmrcpparser.a $(OPENMRCP_DIR)/mrcpcore/server/.libs/libmrcpserver.a $(OPENMRCP_DIR)/mrcpcore/media/.libs/libmrcpmedia.a $(OPENMRCP_DIR)/mrcpcore/util/.libs/libmrcputil.a $(OPENMRCP_DIR)/mrcpcore/util/.libs/libmrcputil.a $(OPENMRCP_DIR)/mrcpcore/resource/.libs/libmrcpresource.a $(OPENMRCP_DIR)/module/plugin/demo/.libs/libdemoplugin.a $(OPENMRCP_DIR)/module/mrcpv2agent/.libs/libmrcpv2agent.a $(OPENMRCP_DIR)/module/mrcpmediaframe/.libs/libmrcpmediaframe.a $(OPENMRCP_DIR)/module/mrcpsofiasip/.libs/libmrcpsofiasip.a $(OPENMRCP_DIR)/mrcpcore/.libs/libmrcpcore.a
+OPENMRCP_LIBS=$(OPENMRCP_DIR)/platform/openmrcpclient/.libs/libopenmrcpclient.a $(OPENMRCP_DIR)/platform/openmrcpserver/.libs/libopenmrcpserver.a $(OPENMRCP_DIR)/mrcpcore/client/.libs/libmrcpclient.a $(OPENMRCP_DIR)/mediaframe/.libs/libmediaframe.a $(OPENMRCP_DIR)/mrcpcore/engine/.libs/libmrcpengine.a $(OPENMRCP_DIR)/mrcpcore/parser/.libs/libmrcpparser.a $(OPENMRCP_DIR)/mrcpcore/server/.libs/libmrcpserver.a $(OPENMRCP_DIR)/mrcpcore/media/.libs/libmrcpmedia.a $(OPENMRCP_DIR)/mrcpcore/util/.libs/libmrcputil.a $(OPENMRCP_DIR)/mrcpcore/util/.libs/libmrcputil.a $(OPENMRCP_DIR)/mrcpcore/resource/.libs/libmrcpresource.a $(OPENMRCP_DIR)/module/plugin/demo/.libs/libdemoplugin.a $(OPENMRCP_DIR)/module/mrcpv2agent/.libs/libmrcpv2agent.a $(OPENMRCP_DIR)/module/mrcpmediaframe/.libs/libmrcpmediaframe.a $(OPENMRCP_DIR)/module/mrcpsofiasip/.libs/libmrcpsofiasip.a $(OPENMRCP_DIR)/mrcpcore/.libs/libmrcpcore.a
 
-# can remove this .. 
-OPENMRCP_LIBS_STABLE=$(OPENMRCP_DIR)/platform/openmrcpclient/.libs/libopenmrcpclient.a $(OPENMRCP_DIR)/platform/openmrcpserver/.libs/libopenmrcpserver.a $(OPENMRCP_DIR)/mrcpcore/client/.libs/libmrcpclient.a $(OPENMRCP_DIR)/mediaframe/.libs/libmediaframe.a $(OPENMRCP_DIR)/mrcpcore/engine/.libs/libmrcpengine.a $(OPENMRCP_DIR)/mrcpcore/parser/.libs/libmrcpparser.a $(OPENMRCP_DIR)/mrcpcore/server/.libs/libmrcpserver.a $(OPENMRCP_DIR)/mrcpcore/media/.libs/libmrcpmedia.a $(OPENMRCP_DIR)/mrcpcore/util/.libs/libmrcputil.a $(OPENMRCP_DIR)/mrcpcore/util/.libs/libmrcputil.a $(OPENMRCP_DIR)/mrcpcore/resource/.libs/libmrcpresource.a $(OPENMRCP_DIR)/module/plugin/demo/.libs/libdemoplugin.a $(OPENMRCP_DIR)/module/mrcpv2agent/.libs/libmrcpv2agent.a $(OPENMRCP_DIR)/module/mrcplivemedia/.libs/libmrcplivemedia.a $(OPENMRCP_DIR)/module/mrcpsofiasip/.libs/libmrcpsofiasip.a $(OPENMRCP_DIR)/mrcpcore/.libs/libmrcpcore.a
-
-OPENMRCP_LIBS=$(OPENMRCP_LIBS_TRUNK)
 MRCP_APR_INCLUDES =  -I../../../../libs/apr/include
 MRCP_APU_INCLUDES =  -I../../../../libs/apr-util/include
 MRCP_SOFIA_INCLUDES = -I/usr/local/include/sofia-sip-1.12  # FIXME!!

Modified: freeswitch/branches/greenlizard/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c	(original)
+++ freeswitch/branches/greenlizard/src/mod/asr_tts/mod_openmrcp/mod_openmrcp.c	Mon Aug 13 17:40:48 2007
@@ -87,7 +87,7 @@
 #include <switch.h>
 	
 #define OPENMRCP_WAIT_TIMEOUT 5000
-#define MY_BUF_LEN 1024 * 32
+#define MY_BUF_LEN 1024 * 128
 #define MY_BLOCK_SIZE MY_BUF_LEN
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_openmrcp_load);
@@ -261,6 +261,8 @@
 		return MRCP_STATUS_FAILURE;
 	}
 
+	switch_buffer_destroy(&tts_session->audio_buffer);
+
 	if(tts_session->pool) {
 		apr_pool_destroy(tts_session->pool);
 		tts_session->pool = NULL;
@@ -585,54 +587,39 @@
  * Called back by openmrcp client thread every time it receives audio 
  * from the TTS server we are connected to.  Puts audio in a queueu
  * and it will be pulled out from read_tts
-
+ */
 static apr_status_t openmrcp_tts_write_frame_NEW(audio_sink_t *sink, media_frame_t *frame)
 {
 	tts_session_t *tts_session = sink->object;	
 	media_frame_t *media_frame;
 	switch_byte_t *buffer;
 	size_t len;
+	apr_status_t status = MRCP_STATUS_SUCCESS;
 
 	len = frame->codec_frame.size;
 
-	// create new media frame 
-	media_frame = (media_frame_t *) switch_core_alloc(tts_session->pool, sizeof(media_frame_t));
-	if (!media_frame) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "media_frame creation failed\n");
-		return SWITCH_STATUS_MEMERR;
-	}
-	
 	// since *frame might get freed by caller (true or false?), allocate a
 	// new buffer and copy *data into it.
 	buffer = (switch_byte_t *) switch_core_alloc(tts_session->pool, sizeof(switch_byte_t)*len);
 	if (!buffer) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate buffer\n");
-		return SWITCH_STATUS_MEMERR;
+		return MRCP_STATUS_FAILURE;
 	}
-	buffer = memcpy(buffer, frame->codec_frame.buffer, len);
-	media_frame->codec_frame.buffer = buffer;
-	media_frame->codec_frame.size = len;  
-	media_frame->type = MEDIA_FRAME_TYPE_AUDIO;
-
 
-	// add audio to buffer 
+	// push audio to buffer 
 	switch_mutex_lock(tts_session->audio_lock);
 	if (switch_buffer_write(tts_session->audio_buffer, buffer, len) == 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not write to buffer\n");
+		status = MRCP_STATUS_FAILURE;
 	}
-	switch_mutex_unlock(tts_session->audio_lock);
-
-	switch_mutex_unlock(tts_session->audio_lock);
-
-	if (switch_queue_trypush(tts_session->audio_queue, (void *) media_frame)) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "could not push audio to queue\n");
-		return MRCP_STATUS_FAILURE;
+	else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "wrote %d bytes to buffer\n", len);
 	}
+	switch_mutex_unlock(tts_session->audio_lock);
 
-	return MRCP_STATUS_SUCCESS;
+	return status;
 
 }
-*/
 
 
 /** 
@@ -1140,6 +1127,8 @@
 	synth_stop(tts_client_context,tts_session); // TODO
 	wait_for_event(tts_session->event_queue,OPENMRCP_EVENT_CHANNEL_MODIFY,5000);
 
+	
+
 	/* terminate tts session */
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Terminate tts_session\n");
 	mrcp_client_context_session_terminate(tts_client_context,tts_session->client_session);
@@ -1187,7 +1176,7 @@
  * TODO: check the blocking flag passed in flags and act accordingly  
  *       (see mod_cepstral.c)
  */
-static switch_status_t openmrcp_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags)
+static switch_status_t openmrcp_read_tts_OLD(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags)
 {
 	media_frame_t *queue_frame = NULL;
 	tts_session_t *tts_session = (tts_session_t *) sh->private_info;
@@ -1205,6 +1194,87 @@
 
 }
 
+static switch_status_t openmrcp_read_tts(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags)
+{
+	media_frame_t *queue_frame = NULL;
+	tts_session_t *tts_session = (tts_session_t *) sh->private_info;
+	size_t return_len=0;
+	size_t amt2copy=0;
+	size_t desired = *datalen;
+
+
+	while(return_len < desired) {
+
+		if (switch_queue_pop(tts_session->audio_queue, (void *) &queue_frame)) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "could not pop from queue\n");
+			break;
+		}
+		else {
+			if (queue_frame->codec_frame.size >= desired) {
+				amt2copy = desired;
+			}
+			else {
+				// limit the amt we copy to data to be LTE datalen
+				// if the queue frame has _more_, just ignore it (TODO: fix this!)
+				amt2copy = queue_frame->codec_frame.size;
+			}
+			memcpy(data, queue_frame->codec_frame.buffer, amt2copy);
+			return_len += amt2copy;
+			*datalen = return_len;
+			data += amt2copy;  // move pointer forward
+			*rate = 8000;
+		}
+
+	}
+
+	// double check we actually read something
+	if (*datalen == 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "no data read from buffer\n");
+		return SWITCH_STATUS_FALSE;	
+	}
+	else if (datalen < desired) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "return_len: (%d) < desired: (%d)\n", return_len, desired);
+	}
+
+	return SWITCH_STATUS_SUCCESS;	
+}
+
+static switch_status_t openmrcp_read_tts_NEW(switch_speech_handle_t *sh, void *data, size_t *datalen, uint32_t *rate, switch_speech_flag_t *flags)
+{
+	media_frame_t *queue_frame = NULL;
+	tts_session_t *tts_session = (tts_session_t *) sh->private_info;
+	switch_status_t status = SWITCH_STATUS_FALSE;
+	size_t used, padding = 0;
+	size_t desired = *datalen;
+
+	*rate = 8000;
+
+	switch_mutex_lock(tts_session->audio_lock);
+	used = switch_buffer_inuse(tts_session->audio_buffer);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "used: %d\n", used);
+	switch_mutex_unlock(tts_session->audio_lock);
+
+	if (used == 0) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "used == 0\n");
+		//*datalen = 0;
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	if (used < desired) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "used < desired (%d)\n", desired);
+		//*datalen = 0;
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	switch_mutex_lock(tts_session->audio_lock);
+	*datalen = switch_buffer_read(tts_session->audio_buffer, data, desired);
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "successfully read %d bytes into data buffer\n", *datalen);
+	switch_mutex_unlock(tts_session->audio_lock);
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+
 
 static void openmrcp_flush_tts(switch_speech_handle_t *sh)
 {



More information about the Freeswitch-svn mailing list