Ejemplo n.º 1
0
static apt_bool_t recog_request_stop(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_t *response_message;
	if(state_machine->state == RECOGNIZER_STATE_RECOGNIZING) {
		mrcp_request_id_list_t *request_id_list = NULL;
		mrcp_generic_header_t *generic_header = mrcp_generic_header_get(message);
		if(generic_header && mrcp_generic_header_property_check(message,GENERIC_HEADER_ACTIVE_REQUEST_ID_LIST) == TRUE) {
			if(generic_header->active_request_id_list.count) {
				/* selective STOP request */
				request_id_list = &generic_header->active_request_id_list;
			}
		}

		if(!request_id_list || active_request_id_list_find(generic_header,state_machine->recog->start_line.request_id) == TRUE) {
			/* found in-progress RECOGNIZE request, stop it */
			apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Found IN-PROGRESS RECOGNIZE Request "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]",
				MRCP_MESSAGE_SIDRES(message),
				message->start_line.request_id);
			return recog_request_dispatch(state_machine,message);
		}
	}
	else if(state_machine->state == RECOGNIZER_STATE_RECOGNIZED) {
		recog_state_change(state_machine,RECOGNIZER_STATE_IDLE,message);
	}

	/* found no in-progress RECOGNIZE request, sending immediate response */
	response_message = mrcp_response_create(message,message->pool);
	recog_pending_requests_remove(state_machine,message,response_message);
	return recog_response_dispatch(state_machine,response_message);
}
static apt_bool_t mrcp_client_message_send(mrcp_client_session_t *session, mrcp_channel_t *channel, mrcp_message_t *message)
{
	if(!session->base.id.length) {
		mrcp_message_t *response = mrcp_response_create(message,message->pool);
		response->start_line.status_code = MRCP_STATUS_CODE_METHOD_FAILED;
		apt_obj_log(APT_LOG_MARK,APT_PRIO_DEBUG,session->base.log_obj,"Raise App Failure MRCP Response "APT_NAMESID_FMT, 
			MRCP_SESSION_NAMESID(session));
		mrcp_app_control_message_raise(session,channel,response);
		return TRUE;
	}

	message->channel_id.session_id = session->base.id;
	message->start_line.request_id = ++session->base.last_request_id;
	apt_obj_log(APT_LOG_MARK,APT_PRIO_INFO,session->base.log_obj,"Send MRCP Request "APT_NAMESIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]",
					MRCP_SESSION_NAMESID(session),
					channel->resource->name.buf,
					message->start_line.request_id);

	if(channel->control_channel) {
		/* MRCPv2 */
		mrcp_client_control_message_send(channel->control_channel,message);
	}
	else {
		/* MRCPv1 */
		mrcp_session_control_request(channel->session,message);
	}

	return TRUE;
}
Ejemplo n.º 3
0
static apt_bool_t mrcp_client_message_send(mrcp_client_session_t *session, mrcp_channel_t *channel, mrcp_message_t *message)
{
	if(!session->base.id.length) {
		mrcp_message_t *response = mrcp_response_create(message,message->pool);
		response->start_line.status_code = MRCP_STATUS_CODE_METHOD_FAILED;
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Raise App Failure MRCP Response");
		mrcp_app_control_message_raise(session,channel,response);
		return TRUE;
	}

	message->channel_id.session_id = session->base.id;
	message->start_line.request_id = ++session->base.last_request_id;
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Send MRCP Request <%s@%s> [%d]",
					channel->resource_name->buf,
					session->base.id,
					message->start_line.request_id);

	if(channel->control_channel) {
		/* MRCPv2 */
		mrcp_client_control_message_send(channel->control_channel,message);
	}
	else {
		/* MRCPv1 */
		mrcp_session_control_request(channel->session,message);
	}

	return TRUE;
}
static apt_bool_t mrcp_app_failure_message_raise(mrcp_client_session_t *session)
{
	mrcp_app_message_t *response;
	const mrcp_app_message_t *request = session->active_request;
	if(!request) {
		return FALSE;
	}
	session->active_request = NULL;
	response = mrcp_client_app_response_create(request,session->status,session->base.pool);
	if(response->message_type == MRCP_APP_MESSAGE_TYPE_SIGNALING) {
		apt_obj_log(APT_LOG_MARK,APT_PRIO_INFO,session->base.log_obj,"Raise App Response "APT_NAMESID_FMT" [%d] %s [%d]",
			MRCP_SESSION_NAMESID(session),
			response->sig_message.command_id,
			session->status == MRCP_SIG_STATUS_CODE_SUCCESS ? "SUCCESS" : "FAILURE",
			session->status);
	}
	else if(response->control_message){
		mrcp_message_t *mrcp_response = mrcp_response_create(response->control_message,response->control_message->pool);
		mrcp_response->start_line.status_code = MRCP_STATUS_CODE_METHOD_FAILED;
		response->control_message = mrcp_response;
		apt_obj_log(APT_LOG_MARK,APT_PRIO_INFO,session->base.log_obj,"Raise App MRCP Response "APT_NAMESID_FMT, 
			MRCP_SESSION_NAMESID(session));
	}
	session->application->handler(response);
	return TRUE;
}
Ejemplo n.º 5
0
static apt_bool_t mrcp_server_message_handler(mrcp_connection_t *connection, mrcp_message_t *message, apt_message_status_e status)
{
	mrcp_connection_agent_t *agent = connection->agent;
	if(status == APT_MESSAGE_STATUS_COMPLETE) {
		/* message is completely parsed */
		mrcp_control_channel_t *channel = mrcp_connection_channel_associate(agent,connection,message);
		if(channel) {
			mrcp_connection_message_receive(agent->vtable,channel,message);
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Find Channel "APT_SIDRES_FMT" in Connection %s",
				MRCP_MESSAGE_SIDRES(message),
				connection->id);
		}
	}
	else if(status == APT_MESSAGE_STATUS_INVALID) {
		/* error case */
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Parse MRCPv2 Data");
		if(message && message->resource) {
			mrcp_message_t *response;
			response = mrcp_response_create(message,message->pool);
			response->start_line.status_code = MRCP_STATUS_CODE_UNRECOGNIZED_MESSAGE;
			if(mrcp_server_agent_messsage_send(agent,connection,response) == FALSE) {
				apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Send MRCPv2 Response");
			}
		}
	}
	return TRUE;
}
Ejemplo n.º 6
0
static apt_bool_t mrcp_server_message_handler(void *obj, mrcp_message_t *message, mrcp_stream_result_e result)
{
	mrcp_connection_t *connection = obj;
	mrcp_connection_agent_t *agent = connection->agent;
	if(result == MRCP_STREAM_MESSAGE_COMPLETE) {
		/* message is completely parsed */
		mrcp_control_channel_t *channel = mrcp_connection_channel_associate(agent,connection,message);
		if(channel) {
			mrcp_connection_message_receive(agent->vtable,channel,message);
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Find Channel <%s@%s> in Connection %s",
				message->channel_id.session_id.buf,
				message->channel_id.resource_name.buf,
				connection->id);
		}
	}
	else if(result == MRCP_STREAM_MESSAGE_INVALID) {
		/* error case */
		mrcp_message_t *response;
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Parse MRCPv2 Stream");
		response = mrcp_response_create(message,message->pool);
		response->start_line.status_code = MRCP_STATUS_CODE_UNRECOGNIZED_MESSAGE;
		if(mrcp_server_agent_messsage_send(agent,connection,response) == FALSE) {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Send MRCPv2 Response");
		}
	}
	return TRUE;
}
/* Create GET-PARAMS response */
static mrcp_message_t* get_params_response_create(mrcp_resource_factory_t *factory, mrcp_message_t *request)
{
	mrcp_message_t *response;
	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create GET-PARAMS Response");
	response = mrcp_response_create(request,request->pool);
	if(response) {
		apt_header_field_t *header_field;
		header_field = apt_header_field_create_c("Content-Id",SAMPLE_CONTENT_ID,response->pool);
		if(header_field) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s: %s",header_field->name.buf,header_field->value.buf);
			mrcp_message_header_field_add(response,header_field);
		}
		header_field = apt_header_field_create_c("Vendor-Specific-Params",SAMPLE_PARAM_NAME"="SAMPLE_PARAM_VALUE,response->pool);
		if(header_field) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s: %s",header_field->name.buf,header_field->value.buf);
			mrcp_message_header_field_add(response,header_field);
		}
		header_field = apt_header_field_create_c("Voice-Age",SAMPLE_VOICE_AGE,response->pool);
		if(header_field) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s: %s",header_field->name.buf,header_field->value.buf);
			mrcp_message_header_field_add(response,header_field);
		}	
	}
	return response;
}
static apt_bool_t synth_request_stop(mrcp_synth_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_t *response_message;
	if(state_machine->speaker) {
		mrcp_request_id_list_t *request_id_list = NULL;
		mrcp_generic_header_t *generic_header = mrcp_generic_header_get(message);
		if(generic_header && mrcp_generic_header_property_check(message,GENERIC_HEADER_ACTIVE_REQUEST_ID_LIST) == TRUE) {
			if(generic_header->active_request_id_list.ids && generic_header->active_request_id_list.count) {
				/* selective STOP request */
				request_id_list = &generic_header->active_request_id_list;
			}
		}

		if(!request_id_list || active_request_id_list_find(generic_header,state_machine->speaker->start_line.request_id) == TRUE) {
			/* found in-progress SPEAK request, stop it */
			apt_log(APT_PRIO_INFO,"Process STOP Request [%d]",message->start_line.request_id);
			return synth_request_dispatch(state_machine,message);
		}
	}

	/* found no in-progress SPEAK request, sending immediate response */
	response_message = mrcp_response_create(message,message->pool);
	synth_pending_requests_remove(state_machine,message,response_message);
	return synth_response_dispatch(state_machine,response_message);
}
Ejemplo n.º 9
0
/** Dispatch MRCP request */
static apt_bool_t demo_recog_channel_request_dispatch(mrcp_engine_channel_t *channel, mrcp_message_t *request)
{
	apt_bool_t processed = FALSE;
	mrcp_message_t *response = mrcp_response_create(request,request->pool);
	switch(request->start_line.method_id) {
		case RECOGNIZER_SET_PARAMS:
			break;
		case RECOGNIZER_GET_PARAMS:
			break;
		case RECOGNIZER_DEFINE_GRAMMAR:
			break;
		case RECOGNIZER_RECOGNIZE:
			processed = demo_recog_channel_recognize(channel,request,response);
			break;
		case RECOGNIZER_GET_RESULT:
			break;
		case RECOGNIZER_START_INPUT_TIMERS:
			processed = demo_recog_channel_timers_start(channel,request,response);
			break;
		case RECOGNIZER_STOP:
			processed = demo_recog_channel_stop(channel,request,response);
			break;
		default:
			break;
	}
	if(processed == FALSE) {
		/* send asynchronous response for not handled request */
		mrcp_engine_channel_message_send(channel,response);
	}
	return TRUE;
}
Ejemplo n.º 10
0
/** Process MRCP channel request (asynchronous response MUST be sent)*/
static apt_bool_t recorder_channel_request_process(mrcp_engine_channel_t *channel, mrcp_message_t *request)
{
	apt_bool_t processed = FALSE;
	recorder_channel_t *recorder_channel = channel->method_obj;
	mrcp_message_t *response = mrcp_response_create(request,request->pool);
	switch(request->start_line.method_id) {
		case RECORDER_SET_PARAMS:
			break;
		case RECORDER_GET_PARAMS:
			break;
		case RECORDER_RECORD:
			processed = recorder_channel_record(recorder_channel,request,response);
			break;
		case RECORDER_STOP:
			processed = recorder_channel_stop(recorder_channel,request,response);
			break;
		case RECORDER_START_INPUT_TIMERS:
			processed = recorder_channel_timers_start(recorder_channel,request,response);
			break;
		default:
			break;
	}
	if(processed == FALSE) {
		/* send asynchronous response for not handled request */
		mrcp_engine_channel_message_send(channel,response);
	}
	return TRUE;
}
Ejemplo n.º 11
0
static apt_bool_t mrcp_client_agent_request_cancel(mrcp_connection_agent_t *agent, mrcp_control_channel_t *channel, mrcp_message_t *message)
{
	mrcp_message_t *response;
	apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,channel->log_obj,"Cancel MRCP Request <%s@%s> [%d]",
		MRCP_MESSAGE_SIDRES(message),
		message->start_line.request_id);
	response = mrcp_response_create(message,message->pool);
	response->start_line.status_code = MRCP_STATUS_CODE_METHOD_FAILED;
	return mrcp_connection_message_receive(agent->vtable,channel,response);
}
Ejemplo n.º 12
0
/* Create SPEAK response */
static mrcp_message_t* speak_response_create(mrcp_resource_factory_t *factory, const mrcp_message_t *request)
{
    mrcp_message_t *response;
    apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create SPEAK Response");
    response = mrcp_response_create(request,request->pool);
    if(response) {
        /* set IN-PROGRESS state */
        response->start_line.request_state = MRCP_REQUEST_STATE_INPROGRESS;
    }
    return response;
}
static apt_bool_t synth_request_control(mrcp_synth_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_t *response_message;
	if(state_machine->state == SYNTHESIZER_STATE_SPEAKING) {
		apt_log(APT_PRIO_INFO,"Process CONTROL Request [%d]",message->start_line.request_id);
		return synth_request_dispatch(state_machine,message);
	}

	/* found no in-progress SPEAK request, sending immediate response */
	response_message = mrcp_response_create(message,message->pool);
	return synth_response_dispatch(state_machine,response_message);
}
Ejemplo n.º 14
0
static apt_bool_t recog_request_define_grammar(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	if(state_machine->state == RECOGNIZER_STATE_RECOGNIZING) {
		mrcp_message_t *response_message = mrcp_response_create(message,message->pool);
		response_message->start_line.status_code = MRCP_STATUS_CODE_METHOD_NOT_VALID;
		return recog_response_dispatch(state_machine,response_message);
	}
	else if(state_machine->state == RECOGNIZER_STATE_RECOGNIZED) {
		recog_state_change(state_machine,RECOGNIZER_STATE_IDLE,message);
	}

	return recog_request_dispatch(state_machine,message);
}
static apt_bool_t synth_request_define_lexicon(mrcp_synth_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_t *response_message;
	if(state_machine->state == SYNTHESIZER_STATE_IDLE) {
		apt_log(APT_PRIO_INFO,"Process DEFINE-LEXICON Request [%d]",message->start_line.request_id);
		return synth_request_dispatch(state_machine,message);
	}

	/* sending failuer response */
	response_message = mrcp_response_create(message,message->pool);
	response_message->start_line.status_code = MRCP_STATUS_CODE_METHOD_NOT_VALID;
	return synth_response_dispatch(state_machine,response_message);
}
static apt_bool_t synth_request_resume(mrcp_synth_state_machine_t *state_machine, mrcp_message_t *message)
{
	if(state_machine->speaker) {
		/* speaking or paused state */
		if(state_machine->state == SYNTHESIZER_STATE_PAUSED) {
			apt_log(APT_PRIO_INFO,"Process RESUME Request [%d]",state_machine->speaker->start_line.request_id);
			synth_request_dispatch(state_machine,message);
		}
		else {
			/* speaking state */
			mrcp_message_t *response_message = mrcp_response_create(message,message->pool);
			synth_response_dispatch(state_machine,response_message);
		}
	}
	else {
		/* idle state */
		mrcp_message_t *response_message = mrcp_response_create(message,message->pool);
		response_message->start_line.status_code = MRCP_STATUS_CODE_METHOD_NOT_VALID;
		synth_response_dispatch(state_machine,response_message);
	}
	return TRUE;
}
Ejemplo n.º 17
0
static apt_bool_t recog_request_recognition_start_timers(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_t *response_message;
	if(state_machine->state == RECOGNIZER_STATE_RECOGNIZING) {
		/* found in-progress request */
		return recog_request_dispatch(state_machine,message);
	}

	/* found no in-progress request */
	response_message = mrcp_response_create(message,message->pool);
	response_message->start_line.status_code = MRCP_STATUS_CODE_METHOD_NOT_VALID;
	return recog_response_dispatch(state_machine,response_message);
}
static apt_bool_t recog_request_get_result(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_t *response_message;
	if(state_machine->state == RECOGNIZER_STATE_RECOGNIZED) {
		/* found recognized request */
		apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Process GET-RESULT Request [%d]",message->start_line.request_id);
		return recog_request_dispatch(state_machine,message);
	}

	/* found no recognized request */
	response_message = mrcp_response_create(message,message->pool);
	response_message->start_line.status_code = MRCP_STATUS_CODE_METHOD_NOT_VALID;
	return recog_response_dispatch(state_machine,response_message);
}
static apt_bool_t recog_request_recognition_start_timers(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_t *response_message;
	if(state_machine->state == RECOGNIZER_STATE_RECOGNIZING) {
		/* found in-progress request */
		apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Process START-INPUT-TIMERS Request [%d]",message->start_line.request_id);
		return recog_request_dispatch(state_machine,message);
	}

	/* found no in-progress request */
	response_message = mrcp_response_create(message,message->pool);
	response_message->start_line.status_code = MRCP_STATUS_CODE_METHOD_NOT_VALID;
	return recog_response_dispatch(state_machine,response_message);
}
Ejemplo n.º 20
0
static apt_bool_t mrcp_unirtsp_on_announce_response(mrcp_unirtsp_agent_t *agent, mrcp_unirtsp_session_t *session, rtsp_message_t *message, const char *resource_name)
{
	mrcp_message_t *mrcp_message = NULL;

	if(!session || !resource_name) {
		return FALSE;
	}
	
	if(rtsp_header_property_check(&message->header,RTSP_HEADER_FIELD_CONTENT_TYPE) == TRUE &&
		message->header.content_type == RTSP_CONTENT_TYPE_MRCP &&
		rtsp_header_property_check(&message->header,RTSP_HEADER_FIELD_CONTENT_LENGTH) == TRUE &&
		message->header.content_length > 0) {

		apt_text_stream_t text_stream;
		mrcp_parser_t *parser;
		apt_str_t resource_name_str;

		text_stream.text = message->body;
		apt_text_stream_reset(&text_stream);
		apt_string_set(&resource_name_str,resource_name);

		parser = mrcp_parser_create(agent->sig_agent->resource_factory,session->mrcp_session->pool);
		mrcp_parser_resource_set(parser,&resource_name_str);
		if(mrcp_parser_run(parser,&text_stream,&mrcp_message) == APT_MESSAGE_STATUS_COMPLETE) {
			mrcp_message->channel_id.session_id = message->header.session_id;
		}
		else {
			/* error case */
			apt_log(RTSP_LOG_MARK,APT_PRIO_WARNING,"Failed to Parse MRCPv1 Message");
		}
	}
	else {
		/* error case */
		apt_log(RTSP_LOG_MARK,APT_PRIO_WARNING,"Failed to Determine MRCPv1 Message Content");
	}

	if(!mrcp_message) {
		if(!session->mrcp_message) {
			return FALSE;
		}
		mrcp_message = mrcp_response_create(session->mrcp_message,session->mrcp_session->pool);
		mrcp_message->start_line.status_code = MRCP_STATUS_CODE_METHOD_FAILED;
	}

	if(session->mrcp_message && mrcp_message->start_line.request_id == session->mrcp_message->start_line.request_id) {
		session->mrcp_message = NULL;
	}
	mrcp_session_control_response(session->mrcp_session,mrcp_message);
	return TRUE;
}
static apt_bool_t recog_request_define_grammar(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	if(state_machine->state == RECOGNIZER_STATE_RECOGNIZING) {
		mrcp_message_t *response_message = mrcp_response_create(message,message->pool);
		response_message->start_line.status_code = MRCP_STATUS_CODE_METHOD_NOT_VALID;
		return recog_response_dispatch(state_machine,response_message);
	}
	else if(state_machine->state == RECOGNIZER_STATE_RECOGNIZED) {
		recog_state_change(state_machine,RECOGNIZER_STATE_IDLE);
	}

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Process DEFINE-GRAMMAR Request [%d]",message->start_line.request_id);
	return recog_request_dispatch(state_machine,message);
}
Ejemplo n.º 22
0
static apt_bool_t mrcp_client_agent_messsage_send(mrcp_connection_agent_t *agent, mrcp_control_channel_t *channel, mrcp_message_t *message)
{
	apt_bool_t status = FALSE;
	mrcp_connection_t *connection = channel->connection;
	apt_text_stream_t *stream;
	mrcp_stream_result_e result;

	if(!connection || !connection->sock) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No MRCPv2 Connection");
		return FALSE;
	}
	stream = &connection->tx_stream;

	mrcp_generator_message_set(connection->generator,message);
	do {
		apt_text_stream_init(&connection->tx_stream,connection->tx_buffer,sizeof(connection->tx_buffer)-1);
		result = mrcp_generator_run(connection->generator,stream);
		if(result == MRCP_STREAM_MESSAGE_COMPLETE || result == MRCP_STREAM_MESSAGE_TRUNCATED) {
			stream->text.length = stream->pos - stream->text.buf;
			*stream->pos = '\0';

			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Send MRCPv2 Stream %s [%lu bytes]\n%s",
				connection->id,
				stream->text.length,
				stream->text.buf);
			if(apr_socket_send(connection->sock,stream->text.buf,&stream->text.length) == APR_SUCCESS) {
				status = TRUE;
			}
			else {
				apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Send MRCPv2 Stream");
			}
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Generate MRCPv2 Stream");
		}
	}
	while(result == MRCP_STREAM_MESSAGE_TRUNCATED);

	if(status == FALSE) {
		mrcp_message_t *response = mrcp_response_create(message,message->pool);
		response->start_line.method_id = message->start_line.method_id;
		response->start_line.method_name = message->start_line.method_name;
		response->start_line.status_code = MRCP_STATUS_CODE_METHOD_FAILED;
		mrcp_connection_message_receive(agent->vtable,channel,response);
	}
	return TRUE;
}
static apt_bool_t recog_request_recognize(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_header_inherit(&message->header,&state_machine->properties,message->pool);
	if(state_machine->state == RECOGNIZER_STATE_RECOGNIZING) {
		mrcp_message_t *response;
		apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Queue Up RECOGNIZE Request [%d]",message->start_line.request_id);
		message->start_line.request_state = MRCP_REQUEST_STATE_PENDING;
		apt_list_push_back(state_machine->queue,message,message->pool);
		
		response = mrcp_response_create(message,message->pool);
		response->start_line.request_state = MRCP_REQUEST_STATE_PENDING;
		return recog_response_dispatch(state_machine,response);
	}

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Process RECOGNIZE Request [%d]",message->start_line.request_id);
	return recog_request_dispatch(state_machine,message);
}
static apt_bool_t synth_request_speak(mrcp_synth_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_header_inherit(&message->header,&state_machine->properties,message->pool);
	if(state_machine->speaker) {
		mrcp_message_t *response;
		apt_log(APT_PRIO_INFO,"Queue Up SPEAK Request [%d]",message->start_line.request_id);
		message->start_line.request_state = MRCP_REQUEST_STATE_PENDING;
		apt_list_push_back(state_machine->queue,message);
		
		response = mrcp_response_create(message,message->pool);
		response->start_line.request_state = MRCP_REQUEST_STATE_PENDING;
		return synth_response_dispatch(state_machine,response);
	}

	apt_log(APT_PRIO_INFO,"Process SPEAK Request [%d]",message->start_line.request_id);
	return synth_request_dispatch(state_machine,message);
}
Ejemplo n.º 25
0
/** Dispatch MRCP request */
static apt_bool_t demo_verifier_channel_request_dispatch(mrcp_engine_channel_t *channel, mrcp_message_t *request)
{
	apt_bool_t processed = FALSE;
	mrcp_message_t *response = mrcp_response_create(request,request->pool);
	switch(request->start_line.method_id) {
		case VERIFIER_SET_PARAMS:
			break;
		case VERIFIER_GET_PARAMS:
			break;
		case VERIFIER_START_SESSION:
			break;
		case VERIFIER_END_SESSION:
			break;
		case VERIFIER_QUERY_VOICEPRINT:
			break;
		case VERIFIER_DELETE_VOICEPRINT:
			break;
		case VERIFIER_VERIFY:
			processed = demo_verifier_channel_verify(channel,request,response);
			break;
		case VERIFIER_VERIFY_FROM_BUFFER:
			break;
		case VERIFIER_VERIFY_ROLLBACK:
			break;
		case VERIFIER_STOP:
			processed = demo_verifier_channel_stop(channel,request,response);
			break;
		case VERIFIER_CLEAR_BUFFER:
			break;
		case VERIFIER_START_INPUT_TIMERS:
			processed = demo_verifier_channel_timers_start(channel,request,response);
			break;
		case VERIFIER_GET_INTERMIDIATE_RESULT:
			processed = demo_verifier_channel_get_result(channel,request,response);
			break;
			
		default:
			break;
	}
	if(processed == FALSE) {
		/* send asynchronous response for not handled request */
		mrcp_engine_channel_message_send(channel,response);
	}
	return TRUE;
}
Ejemplo n.º 26
0
static apt_bool_t recog_request_recognize(mrcp_recog_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_header_fields_inherit(&message->header,state_machine->properties,message->pool);
	if(state_machine->state == RECOGNIZER_STATE_RECOGNIZING) {
		mrcp_message_t *response;
		apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Queue Up RECOGNIZE Request "APT_SIDRES_FMT" [%"MRCP_REQUEST_ID_FMT"]",
			MRCP_MESSAGE_SIDRES(message),
			message->start_line.request_id);
		message->start_line.request_state = MRCP_REQUEST_STATE_PENDING;
		apt_list_push_back(state_machine->queue,message,message->pool);
		
		response = mrcp_response_create(message,message->pool);
		response->start_line.request_state = MRCP_REQUEST_STATE_PENDING;
		return recog_response_dispatch(state_machine,response);
	}

	return recog_request_dispatch(state_machine,message);
}
Ejemplo n.º 27
0
static apt_bool_t mrcp_client_agent_messsage_send(mrcp_connection_agent_t *agent, mrcp_control_channel_t *channel, mrcp_message_t *message)
{
	apt_bool_t status = FALSE;
	mrcp_connection_t *connection = channel->connection;
	if(connection && connection->sock) {
		char buffer[MRCP_MESSAGE_MAX_SIZE];
		apt_text_stream_t text_stream;
		
		text_stream.text.buf = buffer;
		text_stream.text.length = sizeof(buffer)-1;
		text_stream.pos = text_stream.text.buf;

		if(mrcp_message_generate(agent->resource_factory,message,&text_stream) == TRUE) {
			*text_stream.pos = '\0';
			apt_log(APT_PRIO_INFO,"Send MRCPv2 Message size=%lu\n%s",
				text_stream.text.length,text_stream.text.buf);
			if(apr_socket_send(connection->sock,text_stream.text.buf,&text_stream.text.length) == APR_SUCCESS) {
				status = TRUE;
			}
			else {
				apt_log(APT_PRIO_WARNING,"Failed to Send MRCPv2 Message");
			}
		}
		else {
			apt_log(APT_PRIO_WARNING,"Failed to Generate MRCPv2 Message");
		}
	}
	else {
		apt_log(APT_PRIO_WARNING,"No MRCPv2 Connection");
	}

	if(status == FALSE) {
		mrcp_message_t *response = mrcp_response_create(message,message->pool);
		response->start_line.method_id = message->start_line.method_id;
		response->start_line.method_name = message->start_line.method_name;
		response->start_line.status_code = MRCP_STATUS_CODE_METHOD_FAILED;
		mrcp_connection_message_receive(agent->vtable,channel,response);
	}
	return TRUE;
}
Ejemplo n.º 28
0
/** Dispatch MRCP request */
static apt_bool_t demo_synth_channel_request_dispatch(mrcp_engine_channel_t *channel, mrcp_message_t *request)
{
	apt_bool_t processed = FALSE;
	mrcp_message_t *response = mrcp_response_create(request,request->pool);
	switch(request->start_line.method_id) {
		case SYNTHESIZER_SET_PARAMS:
			processed = demo_synth_channel_set_params(channel,request,response);
			break;
		case SYNTHESIZER_GET_PARAMS:
			processed = demo_synth_channel_get_params(channel,request,response);
			break;
		case SYNTHESIZER_SPEAK:
			processed = demo_synth_channel_speak(channel,request,response);
			break;
		case SYNTHESIZER_STOP:
			processed = demo_synth_channel_stop(channel,request,response);
			break;
		case SYNTHESIZER_PAUSE:
			processed = demo_synth_channel_pause(channel,request,response);
			break;
		case SYNTHESIZER_RESUME:
			processed = demo_synth_channel_resume(channel,request,response);
			break;
		case SYNTHESIZER_BARGE_IN_OCCURRED:
			processed = demo_synth_channel_stop(channel,request,response);
			break;
		case SYNTHESIZER_CONTROL:
			break;
		case SYNTHESIZER_DEFINE_LEXICON:
			break;
		default:
			break;
	}
	if(processed == FALSE) {
		/* send asynchronous response for not handled request */
		mrcp_engine_channel_message_send(channel,response);
	}
	return TRUE;
}
static apt_bool_t synth_request_barge_in_occurred(mrcp_synth_state_machine_t *state_machine, mrcp_message_t *message)
{
	mrcp_message_t *response_message;
	if(state_machine->speaker) {
		apt_bool_t kill_on_barge_in = TRUE;
		mrcp_synth_header_t *synth_header = mrcp_resource_header_get(message);
		if(synth_header) {
			if(mrcp_resource_header_property_check(message,SYNTHESIZER_HEADER_KILL_ON_BARGE_IN) == TRUE) {
				kill_on_barge_in = synth_header->kill_on_barge_in;
			}
		}
	
		if(kill_on_barge_in == TRUE) {
			apt_log(APT_PRIO_INFO,"Process BARGE-IN Request [%d]",message->start_line.request_id);
			return synth_request_dispatch(state_machine,message);
		}
	}

	/* found no kill-on-bargein enabled in-progress SPEAK request, sending immediate response */
	response_message = mrcp_response_create(message,message->pool);
	return synth_response_dispatch(state_machine,response_message);
}
Ejemplo n.º 30
0
static apt_bool_t mrcp_server_agent_messsage_receive(mrcp_connection_agent_t *agent, mrcp_connection_t *connection)
{
	char buffer[MRCP_MESSAGE_MAX_SIZE];
	apt_bool_t more_messages_on_buffer = FALSE;
	apr_status_t status;
	apt_text_stream_t text_stream;
	mrcp_message_t *message;

	if(!connection || !connection->sock) {
		return FALSE;
	}
	
	text_stream.text.buf = buffer;
	text_stream.text.length = sizeof(buffer)-1;
	status = apr_socket_recv(connection->sock, text_stream.text.buf, &text_stream.text.length);
	if(status == APR_EOF || text_stream.text.length == 0) {
		return mrcp_server_agent_connection_close(agent,connection);
	}
	text_stream.text.buf[text_stream.text.length] = '\0';
	text_stream.pos = text_stream.text.buf;

	apt_log(APT_PRIO_INFO,"Receive MRCPv2 Message size=%lu\n%s",text_stream.text.length,text_stream.text.buf);
	do {
		message = mrcp_message_create(connection->pool);
		if(mrcp_message_parse(agent->resource_factory,message,&text_stream) == TRUE) {
			mrcp_control_channel_t *channel = mrcp_connection_channel_associate(agent,connection,message);
			if(channel) {
				mrcp_connection_message_receive(agent->vtable,channel,message);
			}
			else {
				apt_log(APT_PRIO_WARNING,"Failed to Find Channel <%s@%s>",
					message->channel_id.session_id.buf,
					message->channel_id.resource_name.buf);
			}
		}
		else {
			mrcp_message_t *response;
			apt_log(APT_PRIO_WARNING,"Failed to Parse MRCPv2 Message");
			if(message->start_line.version == MRCP_VERSION_2) {
				/* assume that at least message length field is valid */
				if(message->start_line.length <= text_stream.text.length) {
					/* skip to the end of the message */
					text_stream.pos = text_stream.text.buf + message->start_line.length;
				}
				else {
					/* skip to the end of the buffer (support incomplete) */
					text_stream.pos = text_stream.text.buf + text_stream.text.length;
				}
			}
			response = mrcp_response_create(message,message->pool);
			response->start_line.status_code = MRCP_STATUS_CODE_UNRECOGNIZED_MESSAGE;
			if(mrcp_server_agent_messsage_send(agent,connection,response) == FALSE) {
				apt_log(APT_PRIO_WARNING,"Failed to Send MRCPv2 Response");
			}
		}

		more_messages_on_buffer = FALSE;
		if(text_stream.text.length > (apr_size_t)(text_stream.pos - text_stream.text.buf)) {
			/* there are more MRCPv2 messages to signal */
			more_messages_on_buffer = TRUE;
			text_stream.text.length -= text_stream.pos - text_stream.text.buf;
			text_stream.text.buf = text_stream.pos;
			apt_log(APT_PRIO_DEBUG,"Saving Remaining Buffer for Next Message");
		}
	}
	while(more_messages_on_buffer);

	return TRUE;
}