Ejemplo n.º 1
0
/** Load RTP factory */
static apt_bool_t unimrcp_client_rtp_factory_load(unimrcp_client_loader_t *loader, const apr_xml_elem *root, const char *id)
{
	const apr_xml_elem *elem;
	char *rtp_ip = NULL;
	char *rtp_ext_ip = NULL;
	mpf_termination_factory_t *rtp_factory;
	mpf_rtp_config_t *rtp_config;

	rtp_config = mpf_rtp_config_alloc(loader->pool);
	rtp_config->rtp_port_min = DEFAULT_RTP_PORT_MIN;
	rtp_config->rtp_port_max = DEFAULT_RTP_PORT_MAX;

	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Loading RTP Factory <%s>",id);
	for(elem = root->first_child; elem; elem = elem->next) {
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Loading Element <%s>",elem->name);
		if(strcasecmp(elem->name,"rtp-ip") == 0) {
			rtp_ip = unimrcp_client_ip_address_get(loader,elem,loader->ip);
		}
		else if(strcasecmp(elem->name,"rtp-ext-ip") == 0) {
			rtp_ext_ip = unimrcp_client_ip_address_get(loader,elem,loader->ext_ip);
		}
		else if(strcasecmp(elem->name,"rtp-port-min") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				rtp_config->rtp_port_min = (apr_port_t)atol(cdata_text_get(elem));
			}
		}
		else if(strcasecmp(elem->name,"rtp-port-max") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				rtp_config->rtp_port_max = (apr_port_t)atol(cdata_text_get(elem));
			}
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Element <%s>",elem->name);
		}
	}    
	
	if(rtp_ip) {
		apt_string_set(&rtp_config->ip,rtp_ip);
	}
	else {
		apt_string_set(&rtp_config->ip,loader->ip);
	}
	if(rtp_ext_ip) {
		apt_string_set(&rtp_config->ext_ip,rtp_ext_ip);
	}
	else if(loader->ext_ip){
		apt_string_set(&rtp_config->ext_ip,loader->ext_ip);
	}

	rtp_factory = mpf_rtp_termination_factory_create(rtp_config,loader->pool);
	return mrcp_client_rtp_factory_register(loader->client,rtp_factory,id);
}
Ejemplo n.º 2
0
/* --- MRCP CLIENT --- */
static int load_profiles(mrcp_client_t *client, mrcp_connection_agent_t *shared_connection_agent, mpf_engine_t *shared_media_engine, apr_pool_t *pool)
{
	apr_hash_index_t *hi;

	for (hi = apr_hash_first(NULL, globals.profiles); hi; hi = apr_hash_next(hi)) {
		const char *k;
		ast_mrcp_profile_t *v;
		const void *key;
		void *val;

		apr_hash_this(hi, &key, NULL, &val);

		k = (const char *)key;
		v = (ast_mrcp_profile_t *)val;

		if (v == NULL) continue;

		ast_log(LOG_DEBUG, "Processing profile %s:%s\n", k, v->version);

		/* A profile is a signaling agent + termination factory + media engine + connection agent (MRCPv2 only). */
		mrcp_sig_agent_t *agent = NULL;
		mpf_termination_factory_t *termination_factory = NULL;
		mrcp_profile_t * mprofile = NULL;
		mpf_rtp_config_t *rtp_config = NULL;
		mpf_rtp_settings_t *rtp_settings = mpf_rtp_settings_alloc(pool);
		mrcp_sig_settings_t *sig_settings = mrcp_signaling_settings_alloc(pool);
		ast_mrcp_profile_t *mod_profile = NULL;
		mrcp_connection_agent_t *connection_agent = NULL;
		mpf_engine_t *media_engine = shared_media_engine;

		/* Get profile attributes. */
		const char *name = apr_pstrdup(pool, k);
		const char *version = apr_pstrdup(pool, v->version);

		if ((name == NULL) || (strlen(name) == 0) || (version == NULL) || (strlen(version) == 0)) {
			ast_log(LOG_ERROR, "Profile %s missing name or version attribute\n", k);
			return -1;
		}

		// i6net Get the profile set before from the configuration file.
    mod_profile = (ast_mrcp_profile_t *)apr_hash_get(globals.profiles, name, APR_HASH_KEY_STRING);

		/* Create RTP config, common to MRCPv1 and MRCPv2. */
		if ((rtp_config = mpf_rtp_config_alloc(pool)) == NULL) {
			ast_log(LOG_ERROR, "Unable to create RTP configuration\n");
			return -1;
		}

		rtp_config->rtp_port_min = DEFAULT_RTP_PORT_MIN;
		rtp_config->rtp_port_max = DEFAULT_RTP_PORT_MAX;
		apt_string_set(&rtp_config->ip, DEFAULT_LOCAL_IP_ADDRESS);

		if (strcmp("1", version) == 0) {
			/* MRCPv1 configuration. */
			rtsp_client_config_t *config = mrcp_unirtsp_client_config_alloc(pool);

			if (config == NULL) {
				ast_log(LOG_ERROR, "Unable to create RTSP configuration\n");
				return -1;
			}

			config->origin = DEFAULT_SDP_ORIGIN;
			if (globals.unimrcp_request_timeout != NULL) {
				config->request_timeout = (apr_size_t)atol(globals.unimrcp_request_timeout);
			}
			sig_settings->resource_location = DEFAULT_RESOURCE_LOCATION;

			ast_log(LOG_DEBUG, "Loading MRCPv1 profile: %s\n", name);

			apr_hash_index_t *hicfg;

			for (hicfg = apr_hash_first(NULL, v->cfg); hicfg; hicfg = apr_hash_next(hicfg)) {
				const char *param_name;
				const char *param_value;
				const void *keyc;
				void *valc;

				apr_hash_this(hicfg, &keyc, NULL, &valc);

				param_name = (const char *)keyc;
				param_value = (const char *)valc;

				if ((param_name != NULL) && (param_value != NULL)) {
					if (strlen(param_name) == 0) {
						ast_log(LOG_ERROR, "Missing parameter name\n");
						return -1;
					}

					ast_log(LOG_DEBUG, "Loading parameter %s:%s\n", param_name, param_value);

					if ((!process_mrcpv1_config(config, sig_settings, param_name, param_value, pool)) &&
						(!process_rtp_config(client, rtp_config, rtp_settings, param_name, param_value, pool)) &&
						(!process_profile_config(mod_profile, param_name, param_value, pool))) {
						ast_log(LOG_WARNING, "Unknown parameter %s\n", param_name);
					}
				}
			}

			agent = mrcp_unirtsp_client_agent_create(name, config, pool);
		} else if (strcmp("2", version) == 0) {
			/* MRCPv2 configuration. */
			mrcp_sofia_client_config_t *config = mrcp_sofiasip_client_config_alloc(pool);

			if (config == NULL) {
				ast_log(LOG_ERROR, "Unable to create SIP configuration\n");
				return -1;
			}

			config->local_ip = DEFAULT_LOCAL_IP_ADDRESS;
			config->local_port = DEFAULT_SIP_LOCAL_PORT;
			sig_settings->server_ip = DEFAULT_REMOTE_IP_ADDRESS;
			sig_settings->server_port = DEFAULT_SIP_REMOTE_PORT;
			config->ext_ip = NULL;
			config->user_agent_name = DEFAULT_SOFIASIP_UA_NAME;
			config->origin = DEFAULT_SDP_ORIGIN;

			ast_log(LOG_DEBUG, "Loading MRCPv2 profile: %s\n", name);

			apr_hash_index_t *hicfg;

			for (hicfg = apr_hash_first(NULL, v->cfg); hicfg; hicfg = apr_hash_next(hicfg)) {
				const char *param_name;
				const char *param_value;
				const void *keyc;
				void *valc;

				apr_hash_this(hicfg, &keyc, NULL, &valc);

				param_name = (const char *)keyc;
				param_value = (const char *)valc;

				if ((param_name != NULL) && (param_value != NULL)) {
					if (strlen(param_name) == 0) {
						ast_log(LOG_ERROR, "Missing parameter name\n");
						return -1;
					}

					ast_log(LOG_DEBUG, "Loading parameter %s:%s\n", param_name, param_value);

					if ((!process_mrcpv2_config(config, sig_settings, param_name, param_value, pool)) &&
						(!process_rtp_config(client, rtp_config, rtp_settings, param_name, param_value, pool)) &&
						(!process_profile_config(mod_profile, param_name, param_value, pool))) {
						ast_log(LOG_WARNING, "Unknown parameter %s\n", param_name);
					}
				}
			}

			agent = mrcp_sofiasip_client_agent_create(name, config, pool);
			connection_agent = shared_connection_agent;
		} else {
			ast_log(LOG_ERROR, "Version must be either \"1\" or \"2\"\n");
			return -1;
		}

		if ((termination_factory = mpf_rtp_termination_factory_create(rtp_config, pool)) != NULL)
			mrcp_client_rtp_factory_register(client, termination_factory, name);

		mrcp_client_rtp_settings_register(client, rtp_settings, "RTP-Settings");
		mrcp_client_signaling_settings_register(client, sig_settings, "Signalling-Settings");

		if (agent != NULL)
			mrcp_client_signaling_agent_register(client, agent);

		/* Create the profile and register it. */
		if ((mprofile = mrcp_client_profile_create(NULL, agent, connection_agent, media_engine, termination_factory, rtp_settings, sig_settings, pool)) != NULL) {
			if (!mrcp_client_profile_register(client, mprofile, name))
				ast_log(LOG_WARNING, "Unable to register MRCP client profile\n");
		}
	}

	return 0;
}
Ejemplo n.º 3
0
/** Run MPF test suite */
static apt_bool_t mpf_test_run(apt_test_suite_t *suite, int argc, const char * const *argv)
{
	mpf_suite_agent_t *agent;
	mpf_codec_manager_t *codec_manager;
	mpf_rtp_config_t *rtp_config;
	mpf_rtp_settings_t *rtp_settings;
	mpf_engine_t *engine;

	apt_task_t *task;
	apt_task_vtable_t *vtable;
	apt_task_msg_pool_t *msg_pool;

	agent = apr_palloc(suite->pool,sizeof(mpf_suite_agent_t));

	agent->dir_layout = apt_default_dir_layout_create(NULL,suite->pool);
	engine = mpf_engine_create("MPF-Engine",suite->pool);
	if(!engine) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create MPF Engine");
		return FALSE;
	}

	codec_manager = mpf_engine_codec_manager_create(suite->pool);
	if(!codec_manager) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Codec Manager");
		return FALSE;
	}
		
	mpf_engine_codec_manager_register(engine,codec_manager);
	agent->engine = engine;

	rtp_config = mpf_rtp_config_alloc(suite->pool);
	apt_string_set(&rtp_config->ip,"127.0.0.1");
	rtp_config->rtp_port_min = 5000;
	rtp_config->rtp_port_max = 6000;

	agent->rtp_config = rtp_config;

	rtp_settings = mpf_rtp_settings_alloc(suite->pool);
	rtp_settings->ptime = 20;
	rtp_settings->jb_config.adaptive = 1;
	rtp_settings->jb_config.time_skew_detection = 1;
	rtp_settings->jb_config.min_playout_delay = 0;
	rtp_settings->jb_config.initial_playout_delay = 50;
	rtp_settings->jb_config.max_playout_delay = 800;
	mpf_codec_manager_codec_list_load(codec_manager,&rtp_settings->codec_list,"PCMU",suite->pool);

	agent->rtp_settings = rtp_settings;

	agent->rtp_termination_factory = mpf_rtp_termination_factory_create(rtp_config,suite->pool);
	agent->file_termination_factory = mpf_file_termination_factory_create(suite->pool);

	agent->rx_session = NULL;
	agent->tx_session = NULL;

	msg_pool = apt_task_msg_pool_create_dynamic(sizeof(mpf_message_t),suite->pool);

	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create Consumer Task");
	agent->consumer_task = apt_consumer_task_create(agent,msg_pool,suite->pool);
	if(!agent->consumer_task) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Consumer Task");
		return FALSE;
	}
	task = apt_consumer_task_base_get(agent->consumer_task);
	apt_task_name_set(task,"MPF-Tester");
	vtable = apt_task_vtable_get(task);
	if(vtable) {
		vtable->process_msg = mpf_suite_task_msg_process;
		vtable->on_start_complete = mpf_suite_on_start_complete;
		vtable->on_terminate_complete = mpf_suite_on_terminate_complete;
	}

	apt_task_add(task,mpf_task_get(engine));

	apr_thread_mutex_create(&agent->wait_object_mutex,APR_THREAD_MUTEX_UNNESTED,suite->pool);
	apr_thread_cond_create(&agent->wait_object,suite->pool);

	if(apt_task_start(task) == FALSE) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Start Task");
		apt_task_destroy(task);
		return FALSE;
	}

	apr_thread_mutex_lock(agent->wait_object_mutex);
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Wait for Task to Complete");
	apr_thread_cond_wait(agent->wait_object,agent->wait_object_mutex);
	apr_thread_mutex_unlock(agent->wait_object_mutex);
	
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Terminate Task [wait till complete]");
	apt_task_terminate(task,TRUE);
	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Destroy Task");
	apt_task_destroy(task);

	apr_thread_cond_destroy(agent->wait_object);
	apr_thread_mutex_destroy(agent->wait_object_mutex);
	return TRUE;
}
Ejemplo n.º 4
0
/** Run MPF test suite */
static apt_bool_t mpf_test_run(apt_test_suite_t *suite, int argc, const char * const *argv)
{
	mpf_suite_engine_t *suite_engine;
	mpf_codec_manager_t *codec_manager;
	mpf_rtp_config_t *config;
	mpf_engine_t *engine;

	apt_task_t *task;
	apt_task_vtable_t *vtable;
	apt_task_msg_pool_t *msg_pool;

	suite_engine = apr_palloc(suite->pool,sizeof(mpf_suite_engine_t));

	engine = mpf_engine_create(suite->pool);
	if(!engine) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create MPF Engine");
		return FALSE;
	}
	codec_manager = mpf_engine_codec_manager_create(suite->pool);
	if(codec_manager) {
		mpf_engine_codec_manager_register(engine,codec_manager);
	}
	suite_engine->engine = engine;

	config = mpf_rtp_config_alloc(suite->pool);
	apt_string_set(&config->ip,"127.0.0.1");
	config->rtp_port_min = 5000;
	config->rtp_port_min = 6000;
	suite_engine->rtp_termination_factory = mpf_rtp_termination_factory_create(config,suite->pool);
	suite_engine->file_termination_factory = mpf_file_termination_factory_create(suite->pool);

	msg_pool = apt_task_msg_pool_create_dynamic(sizeof(mpf_message_t),suite->pool);

	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create Consumer Task");
	suite_engine->consumer_task = apt_consumer_task_create(suite_engine,msg_pool,suite->pool);
	if(!suite_engine->consumer_task) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Consumer Task");
		return FALSE;
	}
	task = apt_consumer_task_base_get(suite_engine->consumer_task);
	vtable = apt_task_vtable_get(task);
	if(vtable) {
		vtable->process_msg = mpf_suite_task_msg_process;
		vtable->on_start_complete = mpf_suite_on_start_complete;
		vtable->on_terminate_complete = mpf_suite_on_terminate_complete;
	}

	apt_task_add(task,mpf_task_get(engine));

	apr_thread_mutex_create(&suite_engine->wait_object_mutex,APR_THREAD_MUTEX_UNNESTED,suite->pool);
	apr_thread_cond_create(&suite_engine->wait_object,suite->pool);

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Start Task");
	if(apt_task_start(task) == FALSE) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Start Task");
		apt_task_destroy(task);
		return FALSE;
	}

	apr_thread_mutex_lock(suite_engine->wait_object_mutex);
	apr_thread_cond_wait(suite_engine->wait_object,suite_engine->wait_object_mutex);
	apr_thread_mutex_unlock(suite_engine->wait_object_mutex);
	
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Terminate Task [wait till complete]");
	apt_task_terminate(task,TRUE);
	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Destroy Task");
	apt_task_destroy(task);

	apr_thread_cond_destroy(suite_engine->wait_object);
	apr_thread_mutex_destroy(suite_engine->wait_object_mutex);
	return TRUE;
}