Revision
15736
Author
crienzo
Date
2009-12-01 08:59:34 -0600 (Tue, 01 Dec 2009)

Log Message

fix for loquendo MRCPv2 - destroy session instead of removing channel

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c (15735 => 15736)


--- freeswitch/trunk/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c	2009-12-01 12:22:59 UTC (rev 15735)
+++ freeswitch/trunk/src/mod/asr_tts/mod_unimrcp/mod_unimrcp.c	2009-12-01 14:59:34 UTC (rev 15736)
@@ -308,6 +308,8 @@
 	speech_channel_state_t state;
 	/** UniMRCP <--> FreeSWITCH audio buffer */
 	audio_queue_t *audio_queue;
+	/** True, if channel was opened successfully */
+	int channel_opened;
 	/** rate */
 	uint16_t rate;
 	/** silence sample */
@@ -565,7 +567,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) unable to create audio queue buffer\n", laudio_queue->name);
 		status = SWITCH_STATUS_FALSE;
 		goto done;
-    }
+	}
 
 	if (switch_mutex_init(&laudio_queue->mutex, SWITCH_MUTEX_UNNESTED, pool) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) unable to create audio queue mutex\n", laudio_queue->name);
@@ -784,6 +786,7 @@
 	schan->params = NULL;
 	schan->rate = rate;
 	schan->silence = 0; /* L16 silence sample */
+	schan->channel_opened = 0;
 
 	if (switch_mutex_init(&schan->mutex, SWITCH_MUTEX_UNNESTED, pool) != SWITCH_STATUS_SUCCESS || 
 		switch_thread_cond_create(&schan->cond, pool) != SWITCH_STATUS_SUCCESS ||
@@ -816,7 +819,7 @@
 	/* destroy the channel and session if not already done */
 	switch_mutex_lock(schannel->mutex);
 	if (schannel->state != SPEECH_CHANNEL_CLOSED) {
-		mrcp_application_channel_remove(schannel->unimrcp_session, schannel->unimrcp_channel);
+		mrcp_application_session_terminate(schannel->unimrcp_session);
 		while(schannel->state != SPEECH_CHANNEL_CLOSED) {
 			if (switch_thread_cond_timedwait(schannel->cond, schannel->mutex, SPEECH_CHANNEL_TIMEOUT_USEC) == SWITCH_STATUS_TIMEOUT) {
 				break;
@@ -1667,8 +1670,24 @@
 static apt_bool_t speech_on_session_terminate(mrcp_application_t *application, mrcp_session_t *session, mrcp_sig_status_code_e status)
 {
 	speech_channel_t *schannel = (speech_channel_t *)mrcp_application_session_object_get(session);
+	switch_event_t *event = NULL;
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) Destroying MRCP session\n", schannel->name);
 	mrcp_application_session_destroy(session);
+
+	/* notify of channel close */
+	if (schannel->channel_opened && globals.enable_profile_events) {
+		switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_PROFILE_CLOSE);
+		if (event) {
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Profile", schannel->profile->name);
+			if (schannel->type == SPEECH_CHANNEL_SYNTHESIZER) {
+				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Resource-Type", "TTS");
+			} else {
+				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Resource-Type", "ASR");
+			}
+			switch_event_fire(&event);
+		}
+	}
+
 	speech_channel_set_state(schannel, SPEECH_CHANNEL_CLOSED);
 
 	return TRUE;
@@ -1718,6 +1737,7 @@
 			}
 			switch_event_fire(&event);
 		}
+		schannel->channel_opened = 1;
 	} else {
 		if (schannel) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "(%s) %s channel error!\n", schannel->name, speech_channel_type_to_string(schannel->type));
@@ -1745,25 +1765,10 @@
  */
 static apt_bool_t speech_on_channel_remove(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status)
 {
-	switch_event_t *event = NULL;
 	speech_channel_t *schannel = (speech_channel_t *)mrcp_application_channel_object_get(channel);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "(%s) %s channel is removed\n", schannel->name, speech_channel_type_to_string(schannel->type));
 	schannel->unimrcp_channel = NULL;
 
-	/* notify of channel close */
-	if (globals.enable_profile_events) {
-		switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_PROFILE_CLOSE);
-		if (event) {
-			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Profile", schannel->profile->name);
-			if (schannel->type == SPEECH_CHANNEL_SYNTHESIZER) {
-				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Resource-Type", "TTS");
-			} else {
-				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "MRCP-Resource-Type", "ASR");
-			}
-			switch_event_fire(&event);
-		}
-	}
-
 	if (session) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) Terminating MRCP session\n", schannel->name);
 		mrcp_application_session_terminate(session);