static apt_bool_t mrcp_client_resource_discover(mrcp_client_session_t *session)
{
	mrcp_session_descriptor_t *descriptor = NULL;
	
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Discover Resources "APT_PTR_FMT, MRCP_SESSION_PTR(&session->base));
	session->answer = NULL;
	mrcp_client_session_state_set(session,SESSION_STATE_DISCOVERING);

	if(mrcp_session_version_get(session) == MRCP_VERSION_1) {
		mrcp_resource_t *resource;
		mrcp_resource_id i;

		for(i=0; i<MRCP_RESOURCE_TYPE_COUNT; i++) {
			resource = mrcp_resource_get(session->profile->resource_factory,i);
			if(!resource) continue;
		
			descriptor = mrcp_session_descriptor_create(session->base.pool);
			apt_string_copy(&descriptor->resource_name,&resource->name,session->base.pool);
			if(mrcp_session_discover_request(&session->base,descriptor) == TRUE) {
				mrcp_client_session_subrequest_add(session);
			}
		}
	}
	else {
		if(mrcp_session_discover_request(&session->base,descriptor) == TRUE) {
			mrcp_client_session_subrequest_add(session);
		}
	}

	if(session->subrequest_count == 0) {
		session->status = MRCP_SIG_STATUS_CODE_FAILURE;
		mrcp_app_sig_response_raise(session,TRUE);
	}
	return TRUE;
}
示例#2
0
/* Create SPEAK request */
static mrcp_message_t* speak_request_create(mrcp_resource_factory_t *factory, apr_pool_t *pool)
{
    mrcp_message_t *message;
    mrcp_resource_t *resource = mrcp_resource_get(factory,MRCP_SYNTHESIZER_RESOURCE);
    if(!resource) {
        return NULL;
    }
    apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create SPEAK Request");
    message = mrcp_request_create(resource,MRCP_VERSION_2,SYNTHESIZER_SPEAK,pool);
    if(message) {
        mrcp_generic_header_t *generic_header;
        mrcp_synth_header_t *synth_header;
        /* get/allocate generic header */
        generic_header = mrcp_generic_header_prepare(message);
        if(generic_header) {
            /* set generic header fields */
            apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set Content-Type: %s",SAMPLE_CONTENT_TYPE);
            apt_string_assign(&generic_header->content_type,SAMPLE_CONTENT_TYPE,message->pool);
            mrcp_generic_header_property_add(message,GENERIC_HEADER_CONTENT_TYPE);
        }
        /* get/allocate synthesizer header */
        synth_header = mrcp_resource_header_prepare(message);
        if(synth_header) {
            /* set synthesizer header fields */
            apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set Voice-Age: %d",SAMPLE_VOICE_AGE);
            synth_header->voice_param.age = SAMPLE_VOICE_AGE;
            mrcp_resource_header_property_add(message,SYNTHESIZER_HEADER_VOICE_AGE);
        }
        /* set message body */
        apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set Body: %s",SAMPLE_CONTENT);
        apt_string_assign(&message->body,SAMPLE_CONTENT,message->pool);
    }
    return message;
}
/* Create SPEAK request */
static mrcp_message_t* speak_request_create(mrcp_resource_factory_t *factory, apr_pool_t *pool)
{
	mrcp_message_t *message;
	mrcp_resource_t *resource = mrcp_resource_get(factory,MRCP_SYNTHESIZER_RESOURCE);
	if(!resource) {
		return NULL;
	}
	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create SPEAK Request");
	message = mrcp_request_create(resource,MRCP_VERSION_2,SYNTHESIZER_SPEAK,pool);
	if(message) {
		/* set transparent header fields */
		apt_header_field_t *header_field;
		header_field = apt_header_field_create_c("Content-Type",SAMPLE_CONTENT_TYPE,message->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(message,header_field);
		}

		header_field = apt_header_field_create_c("Voice-Age",SAMPLE_VOICE_AGE,message->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(message,header_field);
		}

		/* set message body */
		apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set Body: %s",SAMPLE_CONTENT);
		apt_string_assign(&message->body,SAMPLE_CONTENT,message->pool);
	}
	return message;
}
/* Create GET-PARAMS request */
static mrcp_message_t* get_params_request_create(mrcp_resource_factory_t *factory, apr_pool_t *pool)
{
	mrcp_message_t *message;
	mrcp_resource_t *resource = mrcp_resource_get(factory,MRCP_SYNTHESIZER_RESOURCE);
	if(!resource) {
		return NULL;
	}
	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create GET-PARAMS Request");
	message = mrcp_request_create(resource,MRCP_VERSION_2,SYNTHESIZER_GET_PARAMS,pool);
	if(message) {
		apt_header_field_t *header_field;
		header_field = apt_header_field_create_c("Content-Id","",message->pool);
		if(header_field) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s:",header_field->name.buf);
			mrcp_message_header_field_add(message,header_field);
		}
		header_field = apt_header_field_create_c("Vendor-Specific-Params",SAMPLE_PARAM_NAME,message->pool);
		if(header_field) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s:",header_field->name.buf);
			mrcp_message_header_field_add(message,header_field);
		}
		header_field = apt_header_field_create_c("Voice-Age","",message->pool);
		if(header_field) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set %s:",header_field->name.buf);
			mrcp_message_header_field_add(message,header_field);
		}
	}
	return message;
}
/** Associate MRCP resource specific data by resource name */
MRCP_DECLARE(apt_bool_t) mrcp_message_resourcify_by_name(mrcp_resource_factory_t *resource_factory, mrcp_message_t *message)
{
	mrcp_resource_t *resource;
	/* associate resource_name and resource_id */
	const apt_str_t *name = &message->channel_id.resource_name;
	message->channel_id.resource_id = mrcp_resource_id_find(resource_factory,name);
	resource = mrcp_resource_get(resource_factory,message->channel_id.resource_id);
	if(!resource) {
		return FALSE;
	}

	mrcp_generic_header_accessor_set(message);
	return resource->resourcify_message_by_name(resource,message);
}
示例#6
0
/** Create control channel */
MRCP_DECLARE(mrcp_channel_t*) mrcp_application_channel_create(
									mrcp_session_t *session, 
									mrcp_resource_id resource_id, 
									mpf_termination_t *termination, 
									mpf_rtp_termination_descriptor_t *rtp_descriptor, 
									void *obj)
{
	mrcp_resource_t *resource;
	mrcp_profile_t *profile;
	mrcp_client_session_t *client_session = (mrcp_client_session_t*)session;
	if(!client_session || !client_session->profile) {
		/* Invalid params */
		return FALSE;
	}
	profile = client_session->profile;

	if(!profile->resource_factory) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Channel: invalid profile");
		return FALSE;
	}
	resource = mrcp_resource_get(profile->resource_factory,resource_id);
	if(!resource) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Channel: no such resource");
		return FALSE;
	}

	if(termination) {
		/* Media engine and RTP factory must be specified in this case */
		if(!profile->mpf_factory || !profile->rtp_termination_factory) {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Channel: invalid profile");
			return FALSE;
		}
	}
	else {
		/* Either termination or rtp_descriptor must be specified */
		if(!rtp_descriptor) {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Channel: missing both termination and RTP descriptor");
			return FALSE;
		}
	}

	return mrcp_client_channel_create(client_session,resource,termination,rtp_descriptor,obj);
}
示例#7
0
/* Create GET-PARAMS request */
static mrcp_message_t* get_params_request_create(mrcp_resource_factory_t *factory, apr_pool_t *pool)
{
    mrcp_message_t *message;
    mrcp_resource_t *resource = mrcp_resource_get(factory,MRCP_SYNTHESIZER_RESOURCE);
    if(!resource) {
        return NULL;
    }
    apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create GET-PARAMS Request");
    message = mrcp_request_create(resource,MRCP_VERSION_2,SYNTHESIZER_GET_PARAMS,pool);
    if(message) {
        apt_str_t param_name;
        apt_str_t param_value;
        mrcp_generic_header_t *generic_header;
        mrcp_synth_header_t *synth_header;
        /* get/allocate generic header */
        generic_header = mrcp_generic_header_prepare(message);
        if(generic_header) {
            /* set content id empty header */
            apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set Content-ID: <empty>");
            mrcp_generic_header_name_property_add(message,GENERIC_HEADER_CONTENT_ID);

            /* set vendor specific params header */
            generic_header->vendor_specific_params = apt_pair_array_create(1,pool);
            apt_string_set(&param_name,SAMPLE_PARAM_NAME);
            apt_string_reset(&param_value);
            apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set Vendor-Specific-Params: %s",param_name.buf);
            apt_pair_array_append(generic_header->vendor_specific_params,&param_name,&param_value,pool);
            mrcp_generic_header_property_add(message,GENERIC_HEADER_VENDOR_SPECIFIC_PARAMS);
        }
        /* get/allocate synthesizer header */
        synth_header = mrcp_resource_header_prepare(message);
        if(synth_header) {
            /* set voice age empty header */
            apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Set Voice-Age: <empty>");
            mrcp_resource_header_name_property_add(message,SYNTHESIZER_HEADER_VOICE_AGE);
        }
    }
    return message;
}
示例#8
0
static apt_bool_t mrcp_server_engine_table_make(mrcp_server_t *server, mrcp_profile_t *profile, apr_table_t *plugin_map)
{
	int i;
	mrcp_resource_t *resource;
	const char *plugin_name = NULL;
	mrcp_engine_t *engine;

	profile->engine_table = apr_hash_make(server->pool);
	for(i=0; i<MRCP_RESOURCE_TYPE_COUNT; i++) {
		resource = mrcp_resource_get(server->resource_factory,i);
		if(!resource) continue;
		
		engine = NULL;
		/* first, try to find engine by name specified in plugin map (if available) */
		if(plugin_map) {
			plugin_name = apr_table_get(plugin_map,resource->name.buf);
			if(plugin_name) {
				engine = mrcp_engine_factory_engine_get(server->engine_factory,plugin_name);
			}
		}

		/* next, if no engine found or specified, try to find the first available one */
		if(!engine) {
			engine = mrcp_engine_factory_engine_find(server->engine_factory,i);
		}
		
		if(engine) {
			if(engine->id) {
				apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Assign MRCP Engine [%s] [%s]",resource->name.buf,engine->id);
			}
			apr_hash_set(profile->engine_table,resource->name.buf,resource->name.length,engine);
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No MRCP Engine Available [%s]",resource->name.buf);
		}
	}

	return TRUE;
}
示例#9
0
static mrcp_channel_t* mrcp_server_channel_create(mrcp_server_session_t *session, const apt_str_t *resource_name, apr_size_t id, apr_array_header_t *cmid_arr)
{
	mrcp_channel_t *channel;
	apr_pool_t *pool = session->base.pool;

	channel = apr_palloc(pool,sizeof(mrcp_channel_t));
	channel->pool = pool;
	channel->session = &session->base;
	channel->resource = NULL;
	channel->control_channel = NULL;
	channel->state_machine = NULL;
	channel->engine_channel = NULL;
	channel->id = id;
	channel->cmid_arr = cmid_arr;
	channel->waiting_for_channel = FALSE;
	channel->waiting_for_termination = FALSE;
	apt_string_reset(&channel->resource_name);

	if(resource_name && resource_name->buf) {
		mrcp_resource_id resource_id;
		mrcp_resource_t *resource;
		mrcp_engine_channel_t *engine_channel;
		channel->resource_name = *resource_name;
		resource_id = mrcp_resource_id_find(
								session->profile->resource_factory,
								resource_name);
		resource = mrcp_resource_get(session->profile->resource_factory,resource_id);
		if(resource) {
			channel->resource = resource;
			if(mrcp_session_version_get(session) == MRCP_VERSION_2) {
				channel->control_channel = mrcp_server_control_channel_create(
									session->profile->connection_agent,
									channel,
									pool);
			}
			channel->state_machine = resource->create_server_state_machine(
								channel,
								mrcp_session_version_get(session),
								pool);
			if(channel->state_machine) {
				channel->state_machine->on_dispatch = state_machine_on_message_dispatch;
				channel->state_machine->on_deactivate = state_machine_on_deactivate;
			}

			engine_channel = mrcp_server_engine_channel_create(session,resource_name);
			if(engine_channel) {
				engine_channel->id = session->base.id;
				engine_channel->event_obj = channel;
				engine_channel->event_vtable = &engine_channel_vtable;
				channel->engine_channel = engine_channel;
			}
			else {
				apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Engine Channel [%s]",resource_name->buf);
				session->answer->status = MRCP_SESSION_STATUS_UNACCEPTABLE_RESOURCE;
			}
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No Such Resource [%s]",resource_name->buf);
			session->answer->status = MRCP_SESSION_STATUS_NO_SUCH_RESOURCE;
		}
	}
	else {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Invalid Resource Identifier");
		session->answer->status = MRCP_SESSION_STATUS_NO_SUCH_RESOURCE;
	}

	return channel;
}
示例#10
0
static apt_bool_t mrcp_client_channel_add(mrcp_client_session_t *session, mrcp_channel_t *channel)
{
	mrcp_channel_t **channel_slot;
	mrcp_control_descriptor_t *control_media;
	mpf_rtp_termination_descriptor_t *rtp_descriptor = NULL;
	rtp_termination_slot_t *termination_slot;
	apr_pool_t *pool = session->base.pool;
	mrcp_profile_t *profile = session->profile;
	if(mrcp_client_channel_find(session,channel,NULL) == TRUE) {
		/* update */
		return mrcp_client_channel_modify(session,channel,TRUE);
	}

	if(!session->offer) {
		session->base.signaling_agent = profile->signaling_agent;
		session->base.signaling_agent->create_client_session(&session->base);

		session->offer = mrcp_session_descriptor_create(pool);
		session->context = mpf_context_create(session,5,pool);
	}
	if(!channel->resource) {
		channel->resource = mrcp_resource_get(profile->resource_factory,channel->resource_id);
		if(!channel->resource) {
			return FALSE;
		}
		channel->resource_name = mrcp_resource_name_get(profile->resource_factory,channel->resource_id);
		if(!channel->resource_name) {
			return FALSE;
		}
	}
	if(session->base.signaling_agent->mrcp_version == MRCP_VERSION_1) {
		session->offer->resource_name = *channel->resource_name;
		session->offer->resource_state = TRUE;
	}
	else {
		if(!channel->control_channel) {
			channel->control_channel = mrcp_client_control_channel_create(profile->connection_agent,channel,pool);
		}
		control_media = mrcp_control_offer_create(pool);
		control_media->id = mrcp_session_control_media_add(session->offer,control_media);
		control_media->cmid = session->offer->control_media_arr->nelts;
		control_media->resource_name = *channel->resource_name;
		if(mrcp_client_control_channel_add(channel->control_channel,control_media) == TRUE) {
			channel->waiting_for_channel = TRUE;
			session->offer_flag_count++;
		}
	}

	/* add to channel array */
	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Add Control Channel <%s@%s>",
					mrcp_session_str(session),
					channel->resource_name->buf);
	channel_slot = apr_array_push(session->channels);
	*channel_slot = channel;

	if(channel->termination) {
		if(mrcp_client_mpf_request_send(profile->media_engine,MPF_COMMAND_ADD,session->context,channel->termination,NULL) == TRUE) {
			channel->waiting_for_termination = TRUE;
			session->offer_flag_count++;
		}
	}

	if(channel->rtp_termination_slot) {
		rtp_descriptor = channel->rtp_termination_slot->descriptor;
	}	
	/* add to rtp termination array */
	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Add RTP Termination");
	termination_slot = apr_array_push(session->terminations);
	termination_slot->waiting = FALSE;
	termination_slot->termination = NULL;
	termination_slot->descriptor = NULL;
	if(rtp_descriptor) {
		if(rtp_descriptor->audio.local) {
			session->offer->ip = rtp_descriptor->audio.local->base.ip;
			rtp_descriptor->audio.local->base.id = mrcp_session_audio_media_add(session->offer,rtp_descriptor->audio.local);
			rtp_descriptor->audio.local->mid = session->offer->audio_media_arr->nelts;
		}
	}
	else {
		/* create rtp termination */
		mpf_termination_t *termination = mpf_termination_create(profile->rtp_termination_factory,session,session->base.pool);
		termination_slot->termination = termination;

		/* initialize rtp descriptor */
		rtp_descriptor = apr_palloc(pool,sizeof(mpf_rtp_termination_descriptor_t));
		mpf_rtp_termination_descriptor_init(rtp_descriptor);
		if(channel->termination && channel->termination->audio_stream) {
			mpf_rtp_media_descriptor_t *media;
			media = apr_palloc(pool,sizeof(mpf_rtp_media_descriptor_t));
			mpf_rtp_media_descriptor_init(media);
			media->base.state = MPF_MEDIA_ENABLED;
			media->mode = mpf_stream_mode_negotiate(channel->termination->audio_stream->mode);
			rtp_descriptor->audio.local = media;
		}
		/* send add termination request (add to media context) */
		if(mrcp_client_mpf_request_send(profile->media_engine,MPF_COMMAND_ADD,session->context,termination,rtp_descriptor) == TRUE) {
			termination_slot->waiting = TRUE;
			session->offer_flag_count++;
		}
	}
	termination_slot->descriptor = rtp_descriptor;
	channel->rtp_termination_slot = termination_slot;

	if(!session->offer_flag_count) {
		/* send offer to server */
		mrcp_client_session_offer_send(session);
	}
	return TRUE;
}