/* Handle the UniMRCP responses sent to channel add requests. */ static apt_bool_t speech_on_channel_add(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status) { speech_channel_t *schannel; if (channel != NULL) schannel = (speech_channel_t *)mrcp_application_channel_object_get(channel); else schannel = NULL; ast_log(LOG_DEBUG, "(%s) speech_on_channel_add\n", schannel->name); if ((schannel != NULL) && (application != NULL) && (session != NULL) && (channel != NULL)) { if ((session != NULL) && (status == MRCP_SIG_STATUS_CODE_SUCCESS)) { const mpf_codec_descriptor_t *descriptor = descriptor = mrcp_application_sink_descriptor_get(channel); if (!descriptor) { ast_log(LOG_ERROR, "(%s) Unable to determine codec descriptor\n", schannel->name); speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR); ast_log(LOG_DEBUG, "(%s) Terminating MRCP session\n", schannel->name); if (!mrcp_application_session_terminate(session)) ast_log(LOG_WARNING, "(%s) Unable to terminate application session\n", schannel->name); return FALSE; } schannel->rate = descriptor->sampling_rate; const char *codec_name = NULL; if (descriptor->name.length > 0) codec_name = descriptor->name.buf; else codec_name = "unknown"; ast_log(LOG_NOTICE, "(%s) Channel ready, codec=%s, sample rate=%d\n", schannel->name, codec_name, schannel->rate); speech_channel_set_state(schannel, SPEECH_CHANNEL_READY); } else { ast_log(LOG_ERROR, "(%s) Channel error!\n", schannel->name); if (session != NULL) { ast_log(LOG_DEBUG, "(%s) Terminating MRCP session\n", schannel->name); speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR); if (!mrcp_application_session_terminate(session)) ast_log(LOG_WARNING, "(%s) Unable to terminate application session\n", schannel->name); } } } else ast_log(LOG_ERROR, "(unknown) channel error!\n"); return TRUE; }
/* Handle the UniMRCP responses sent to channel add requests. */ static apt_bool_t speech_on_channel_add(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_sig_status_code_e status) { speech_channel_t *schannel = get_speech_channel(session); if (!schannel || !channel) { ast_log(LOG_ERROR, "speech_on_channel_add: unknown channel error!\n"); return FALSE; } ast_log(LOG_DEBUG, "(%s) speech_on_channel_add\n", schannel->name); if (status == MRCP_SIG_STATUS_CODE_SUCCESS) { const mpf_codec_descriptor_t *descriptor = mrcp_application_sink_descriptor_get(channel); if (!descriptor) { ast_log(LOG_ERROR, "(%s) Unable to determine codec descriptor\n", schannel->name); speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR); return FALSE; } schannel->rate = descriptor->sampling_rate; const char *codec_name = NULL; if (descriptor->name.length > 0) codec_name = descriptor->name.buf; else codec_name = "unknown"; ast_log(LOG_NOTICE, "(%s) Channel ready, codec=%s, sample rate=%d\n", schannel->name, codec_name, schannel->rate); speech_channel_set_state(schannel, SPEECH_CHANNEL_READY); } else { int rc = mrcp_application_session_response_code_get(session); ast_log(LOG_ERROR, "(%s) Channel error status=%d, response code=%d!\n", schannel->name, status, rc); speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR); } return TRUE; }
/* Handle the UniMRCP responses sent to session terminate requests. */ 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 = get_speech_channel(session); if (!schannel) { ast_log(LOG_ERROR, "speech_on_session_terminate: unknown channel error!\n"); return FALSE; } ast_log(LOG_DEBUG, "(%s) speech_on_session_terminate\n", schannel->name); ast_log(LOG_DEBUG, "(%s) Destroying MRCP session\n", schannel->name); if (!mrcp_application_session_destroy(session)) ast_log(LOG_WARNING, "(%s) Unable to destroy application session\n", schannel->name); speech_channel_set_state(schannel, SPEECH_CHANNEL_CLOSED); return TRUE; }
/* Handle the UniMRCP responses sent to session terminate requests. */ 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; if (session != NULL) schannel = (speech_channel_t *)mrcp_application_session_object_get(session); else schannel = NULL; ast_log(LOG_DEBUG, "(%s) speech_on_session_terminate\n", schannel->name); if (schannel != NULL) { ast_log(LOG_DEBUG, "(%s) Destroying MRCP session\n", schannel->name); if (!mrcp_application_session_destroy(session)) ast_log(LOG_WARNING, "(%s) Unable to destroy application session\n", schannel->name); speech_channel_set_state(schannel, SPEECH_CHANNEL_CLOSED); } else ast_log(LOG_ERROR, "(unknown) channel error!\n"); return TRUE; }
/* Handle the MRCP synthesizer responses/events from UniMRCP. */ static apt_bool_t synth_on_message_receive(mrcp_application_t *application, mrcp_session_t *session, mrcp_channel_t *channel, mrcp_message_t *message) { speech_channel_t *schannel = get_speech_channel(session); if (!schannel || !message) { ast_log(LOG_ERROR, "synth_on_message_receive: unknown channel error!\n"); return FALSE; } if (message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) { /* Received MRCP response. */ if (message->start_line.method_id == SYNTHESIZER_SPEAK) { /* received the response to SPEAK request */ if (message->start_line.request_state == MRCP_REQUEST_STATE_INPROGRESS) { /* Waiting for SPEAK-COMPLETE event. */ ast_log(LOG_DEBUG, "(%s) REQUEST IN PROGRESS\n", schannel->name); speech_channel_set_state(schannel, SPEECH_CHANNEL_PROCESSING); } else { /* Received unexpected request_state. */ ast_log(LOG_DEBUG, "(%s) Unexpected SPEAK response, request_state = %d\n", schannel->name, message->start_line.request_state); speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR); } } else if (message->start_line.method_id == SYNTHESIZER_STOP) { /* Received response to the STOP request. */ if (message->start_line.request_state == MRCP_REQUEST_STATE_COMPLETE) { /* Got COMPLETE. */ ast_log(LOG_DEBUG, "(%s) COMPLETE\n", schannel->name); speech_channel_set_state(schannel, SPEECH_CHANNEL_READY); } else { /* Received unexpected request state. */ ast_log(LOG_DEBUG, "(%s) Unexpected STOP response, request_state = %d\n", schannel->name, message->start_line.request_state); speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR); } } else if (message->start_line.method_id == SYNTHESIZER_BARGE_IN_OCCURRED) { /* Received response to the BARGE_IN_OCCURRED request. */ if (message->start_line.request_state == MRCP_REQUEST_STATE_COMPLETE) { /* Got COMPLETE. */ ast_log(LOG_DEBUG, "(%s) COMPLETE\n", schannel->name); speech_channel_set_state(schannel, SPEECH_CHANNEL_READY); } else { /* Received unexpected request state. */ ast_log(LOG_DEBUG, "(%s) Unexpected BARGE-IN-OCCURRED response, request_state = %d\n", schannel->name, message->start_line.request_state); speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR); } } else { /* Received unexpected response. */ ast_log(LOG_DEBUG, "(%s) Unexpected response, method_id = %d\n", schannel->name, (int)message->start_line.method_id); speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR); } } else if (message->start_line.message_type == MRCP_MESSAGE_TYPE_EVENT) { /* Received MRCP event. */ if (message->start_line.method_id == SYNTHESIZER_SPEAK_COMPLETE) { /* Got SPEAK-COMPLETE. */ ast_log(LOG_DEBUG, "(%s) SPEAK-COMPLETE\n", schannel->name); speech_channel_set_state(schannel, SPEECH_CHANNEL_READY); } else { ast_log(LOG_DEBUG, "(%s) Unexpected event, method_id = %d\n", schannel->name, (int)message->start_line.method_id); speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR); } } else { ast_log(LOG_DEBUG, "(%s) Unexpected message type, message_type = %d\n", schannel->name, message->start_line.message_type); speech_channel_set_state(schannel, SPEECH_CHANNEL_ERROR); } return TRUE; }