Skip to content

Commit 1bdb1a0

Browse files
committed
Handle on_terminate_event to stop recognition due to connection problems.
1 parent 4ea6938 commit 1bdb1a0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

mod_unimrcp.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,9 @@ static switch_status_t recog_channel_check_results(speech_channel_t *schannel)
25512551
if (!zstr(r->result)) {
25522552
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(schannel->session_uuid), SWITCH_LOG_DEBUG, "(%s) SUCCESS, have result\n", schannel->name);
25532553
status = SWITCH_STATUS_SUCCESS;
2554+
} else if (schannel->state == SPEECH_CHANNEL_CLOSED || schannel->state == SPEECH_CHANNEL_ERROR) {
2555+
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(schannel->session_uuid), SWITCH_LOG_WARNING, "Closing speech channel due to invalid state [%s]\n", speech_channel_state_to_string(schannel->state));
2556+
status = SWITCH_STATUS_FALSE;
25542557
}
25552558

25562559
switch_mutex_unlock(schannel->mutex);
@@ -3599,6 +3602,15 @@ static apt_bool_t recog_message_handler(const mrcp_app_message_t *app_message)
35993602
return mrcp_application_message_dispatch(&globals.recog.dispatcher, app_message);
36003603
}
36013604

3605+
static apt_bool_t recog_on_terminate_event(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel)
3606+
{
3607+
/* We may get this (terminate) event when the server disconnects. Terminating the session forces closing of
3608+
* the speech channel so we can stop recognition in recog_channel_check_results(). */
3609+
mrcp_application_session_terminate(session);
3610+
3611+
return TRUE;
3612+
}
3613+
36023614
/**
36033615
* Handle the MRCP responses/events
36043616
*/
@@ -3807,6 +3819,7 @@ static switch_status_t recog_load(switch_loadable_module_interface_t *module_int
38073819
globals.recog.dispatcher.on_channel_add = speech_on_channel_add;
38083820
globals.recog.dispatcher.on_channel_remove = speech_on_channel_remove;
38093821
globals.recog.dispatcher.on_message_receive = recog_on_message_receive;
3822+
globals.recog.dispatcher.on_terminate_event = recog_on_terminate_event;
38103823
globals.recog.audio_stream_vtable.destroy = NULL;
38113824
globals.recog.audio_stream_vtable.open_rx = recog_stream_open;
38123825
globals.recog.audio_stream_vtable.close_rx = NULL;

0 commit comments

Comments
 (0)