/** Initialize client -- common to unimrcp_client_create and unimrcp_client_create2 */ static unimrcp_client_loader_t* unimrcp_client_init(apt_dir_layout_t *dir_layout) { apr_pool_t *pool; mrcp_client_t *client; unimrcp_client_loader_t *loader; apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"UniMRCP Client ["UNI_VERSION_STRING"] [r"UNI_REVISION_STRING"]"); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"APR ["APR_VERSION_STRING"]"); client = mrcp_client_create(dir_layout); if(!client) { return NULL; } pool = mrcp_client_memory_pool_get(client); if(!pool) { return NULL; } loader = apr_palloc(pool,sizeof(unimrcp_client_loader_t)); loader->dir_layout = dir_layout; loader->doc = NULL; loader->client = client; loader->pool = pool; loader->ip = NULL; loader->ext_ip = NULL; loader->server_ip = NULL; loader->auto_ip = NULL; return loader; }
/** Create and load UniMRCP client */ MRCP_DECLARE(mrcp_client_t*) unimrcp_client_create(apt_dir_layout_t *dir_layout) { apr_pool_t *pool; mrcp_client_t *client; const char *dir_path; unimrcp_client_loader_t *loader; if(!dir_layout) { return NULL; } apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"UniMRCP Client ["UNI_VERSION_STRING"]"); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"APR ["APR_VERSION_STRING"]"); client = mrcp_client_create(dir_layout); if(!client) { return NULL; } pool = mrcp_client_memory_pool_get(client); if(!pool) { return NULL; } loader = apr_palloc(pool,sizeof(unimrcp_client_loader_t)); loader->doc = NULL; loader->client = client; loader->pool = pool; loader->ip = NULL; loader->ext_ip = NULL; loader->server_ip = NULL; loader->auto_ip = NULL; dir_path = dir_layout->conf_dir_path; if(!dir_path) { dir_path = DEFAULT_CONF_DIR_PATH; } if(unimrcp_client_load(loader,dir_path,CONF_FILE_NAME,pool) == FALSE) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Load UniMRCP Client Document"); } return client; }
/* 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; }