Ejemplo n.º 1
0
/** Load components */
static apt_bool_t unimrcp_client_components_load(unimrcp_client_loader_t *loader, const apr_xml_elem *root)
{
	const apr_xml_elem *elem;
	const apr_xml_attr *id_attr;
	const apr_xml_attr *enable_attr;
	const char *id;

	/* Create codec manager first (probably it should be loaded from config either) */
	mpf_codec_manager_t *codec_manager = mpf_engine_codec_manager_create(loader->pool);
	if(codec_manager) {
		mrcp_client_codec_manager_register(loader->client,codec_manager);
	}

	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Loading Components");
	for(elem = root->first_child; elem; elem = elem->next) {
		if(strcasecmp(elem->name,"resource-factory") == 0) {
			unimrcp_client_resource_factory_load(loader,elem);
			continue;
		}
		
		/* get common "id" and "enable" attributes */
		if(header_attribs_get(elem,&id_attr,&enable_attr) == FALSE) {
			/* invalid id */
			continue;
		}
		if(is_attr_enabled(enable_attr) == FALSE) {
			/* disabled element, just skip it */
			continue;
		}
		id = apr_pstrdup(loader->pool,id_attr->value);

		if(strcasecmp(elem->name,"sip-uac") == 0) {
			unimrcp_client_sip_uac_load(loader,elem,id);
		}
		else if(strcasecmp(elem->name,"rtsp-uac") == 0) {
			unimrcp_client_rtsp_uac_load(loader,elem,id);
		}
		else if(strcasecmp(elem->name,"mrcpv2-uac") == 0) {
			unimrcp_client_mrcpv2_uac_load(loader,elem,id);
		}
		else if(strcasecmp(elem->name,"media-engine") == 0) {
			unimrcp_client_media_engine_load(loader,elem,id);
		}
		else if(strcasecmp(elem->name,"rtp-factory") == 0) {
			unimrcp_client_rtp_factory_load(loader,elem,id);
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Element <%s>",elem->name);
		}
	}    
	return TRUE;
}
Ejemplo n.º 2
0
/* Create an MRCP client.
 *
 * Some code and ideas borrowed from unimrcp-client.c
 * Please check $unimrcp_dir$/platforms/libunimrcp-client/src/unimrcp_client.c
 * when upgrading the UniMRCP library to ensure nothing new needs to be set up.
 */
mrcp_client_t *mod_unimrcp_client_create(apr_pool_t *mod_pool)
{
	mrcp_client_t *client = NULL;
	apt_dir_layout_t *dir_layout = NULL;
	apr_pool_t *pool = NULL;
	mrcp_resource_factory_t *resource_factory = NULL;
	mpf_codec_manager_t *codec_manager = NULL;
	apr_size_t max_connection_count = 0;
	apt_bool_t offer_new_connection = FALSE;
	mrcp_connection_agent_t *shared_connection_agent = NULL;
	mpf_engine_t *shared_media_engine = NULL;

	if (!globals.profiles) {
		ast_log(LOG_ERROR, "Profiles hash is NULL\n");
		return NULL;
	}

	/* Create the client. */
	if ((dir_layout = apt_default_dir_layout_create("../", mod_pool)) == NULL) {
		ast_log(LOG_ERROR, "Unable to create directory layout\n");
		return NULL;
	}

	if ((client = mrcp_client_create(dir_layout)) == NULL) {
		ast_log(LOG_ERROR, "Unable to create MRCP client stack\n");
		return NULL;
	}

	if ((pool = mrcp_client_memory_pool_get(client)) == NULL) {
		ast_log(LOG_ERROR, "MRCP client pool is NULL\n");
		return NULL;
	}

	mrcp_resource_loader_t *resource_loader = mrcp_resource_loader_create(FALSE, pool);
	if (resource_loader == NULL) {
		ast_log(LOG_ERROR, "Unable to create MRCP resource loader.\n");
		return NULL;
	}

	apt_str_t resource_class_synth;
	apt_str_t resource_class_recog;
	apt_string_set(&resource_class_synth, "speechsynth");
	apt_string_set(&resource_class_recog, "speechrecog");
	mrcp_resource_load(resource_loader, &resource_class_synth);
	mrcp_resource_load(resource_loader, &resource_class_recog);

	resource_factory = mrcp_resource_factory_get(resource_loader);

	if (!mrcp_client_resource_factory_register(client, resource_factory))
		ast_log(LOG_WARNING, "Unable to register MRCP client resource factory\n");

	if ((codec_manager = mpf_engine_codec_manager_create(pool)) != NULL) {
		if (!mrcp_client_codec_manager_register(client, codec_manager))
			ast_log(LOG_WARNING, "Unable to register MRCP client codec manager\n");
	}

	/* Set up MRCPv2 connection agent that will be shared with all profiles. */
	if ((globals.unimrcp_max_connection_count != NULL) && (strlen(globals.unimrcp_max_connection_count) > 0))
		max_connection_count = atoi(globals.unimrcp_max_connection_count);

	if (max_connection_count <= 0)
		max_connection_count = DEFAULT_UNIMRCP_MAX_CONNECTION_COUNT;

	if (globals.unimrcp_offer_new_connection != NULL) {
		if (strcasecmp(globals.unimrcp_offer_new_connection, "true") == 0 || atoi(globals.unimrcp_offer_new_connection) == 1)
			offer_new_connection = TRUE;
	}
	else {
		offer_new_connection = DEFAULT_UNIMRCP_OFFER_NEW_CONNECTION;
	}

	if ((shared_connection_agent = mrcp_client_connection_agent_create("MRCPv2ConnectionAgent", max_connection_count, offer_new_connection, pool)) != NULL) {
		if (shared_connection_agent != NULL) {
 			if (globals.unimrcp_rx_buffer_size != NULL) {
				apr_size_t rx_buffer_size = (apr_size_t)atol(globals.unimrcp_rx_buffer_size);
				if (rx_buffer_size > 0) {
	 				mrcp_client_connection_rx_size_set(shared_connection_agent, rx_buffer_size);
				}
 			}
 			if (globals.unimrcp_tx_buffer_size != NULL) {
				apr_size_t tx_buffer_size = (apr_size_t)atol(globals.unimrcp_tx_buffer_size);
				if (tx_buffer_size > 0) {
	 				mrcp_client_connection_tx_size_set(shared_connection_agent, tx_buffer_size);
				}
 			}
			if (globals.unimrcp_request_timeout != NULL) {
				apr_size_t request_timeout = (apr_size_t)atol(globals.unimrcp_request_timeout);
				if (request_timeout > 0) {
	 				mrcp_client_connection_timeout_set(shared_connection_agent, request_timeout);
				}
			}
 		}

		if (!mrcp_client_connection_agent_register(client, shared_connection_agent))
			ast_log(LOG_WARNING, "Unable to register MRCP client connection agent\n");
	}

	/* Set up the media engine that will be shared with all profiles. */
	if ((shared_media_engine = mpf_engine_create("MediaEngine", pool)) != NULL) {
		unsigned long realtime_rate = 1;

		if (!mpf_engine_scheduler_rate_set(shared_media_engine, realtime_rate))
			ast_log(LOG_WARNING, "Unable to set scheduler rate for MRCP client media engine\n");

		if (!mrcp_client_media_engine_register(client, shared_media_engine))
			ast_log(LOG_WARNING, "Unable to register MRCP client media engine\n");
	}

	if (globals.profiles) {
		if(load_profiles(client, shared_connection_agent, shared_media_engine, pool) !=0)
			return NULL;
	}

	return client;
}