/** Load RTP termination factory */ static mpf_termination_factory_t* unimrcp_server_rtp_factory_load(mrcp_server_t *server, const apr_xml_elem *root, apr_pool_t *pool) { const apr_xml_elem *elem; char *rtp_ip = DEFAULT_IP_ADDRESS; mpf_rtp_config_t *rtp_config = mpf_rtp_config_create(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 Termination Factory"); for(elem = root->first_child; elem; elem = elem->next) { if(strcasecmp(elem->name,"param") == 0) { const apr_xml_attr *attr_name; const apr_xml_attr *attr_value; if(param_name_value_get(elem,&attr_name,&attr_value) == TRUE) { apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Loading Param %s:%s",attr_name->value,attr_value->value); if(strcasecmp(attr_name->value,"rtp-ip") == 0) { rtp_ip = ip_addr_get(attr_value->value,pool); } else if(strcasecmp(attr_name->value,"rtp-port-min") == 0) { rtp_config->rtp_port_min = (apr_port_t)atol(attr_value->value); } else if(strcasecmp(attr_name->value,"rtp-port-max") == 0) { rtp_config->rtp_port_max = (apr_port_t)atol(attr_value->value); } else if(strcasecmp(attr_name->value,"playout-delay") == 0) { rtp_config->jb_config.initial_playout_delay = atol(attr_value->value); } else if(strcasecmp(attr_name->value,"min-playout-delay") == 0) { rtp_config->jb_config.min_playout_delay = atol(attr_value->value); } else if(strcasecmp(attr_name->value,"max-playout-delay") == 0) { rtp_config->jb_config.max_playout_delay = atol(attr_value->value); } else if(strcasecmp(attr_name->value,"codecs") == 0) { const mpf_codec_manager_t *codec_manager = mrcp_server_codec_manager_get(server); if(codec_manager) { mpf_codec_manager_codec_list_load(codec_manager,&rtp_config->codec_list,attr_value->value,pool); } } else if(strcasecmp(attr_name->value,"ptime") == 0) { rtp_config->ptime = (apr_uint16_t)atol(attr_value->value); } else if(strcasecmp(attr_name->value,"own-preference") == 0) { rtp_config->own_preferrence = atoi(attr_value->value); } else { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Attribute <%s>",attr_name->value); } } } } apt_string_set(&rtp_config->ip,rtp_ip); return mpf_rtp_termination_factory_create(rtp_config,pool); }
/** Load RTP settings */ static apt_bool_t unimrcp_server_rtp_settings_load(unimrcp_server_loader_t *loader, const apr_xml_elem *root, const char *id) { const apr_xml_elem *elem; mpf_rtp_settings_t *rtp_settings = mpf_rtp_settings_alloc(loader->pool); apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Loading RTP Settings <%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,"jitter-buffer") == 0) { unimrcp_server_jb_settings_load(loader,&rtp_settings->jb_config,elem); } else if(strcasecmp(elem->name,"ptime") == 0) { if(is_cdata_valid(elem) == TRUE) { rtp_settings->ptime = (apr_uint16_t)atol(cdata_text_get(elem)); } } else if(strcasecmp(elem->name,"codecs") == 0) { const apr_xml_attr *attr; const mpf_codec_manager_t *codec_manager = mrcp_server_codec_manager_get(loader->server); if(is_cdata_valid(elem) == TRUE && codec_manager) { mpf_codec_manager_codec_list_load( codec_manager, &rtp_settings->codec_list, cdata_text_get(elem), loader->pool); } for(attr = elem->attr; attr; attr = attr->next) { if(strcasecmp(attr->name,"own-preference") == 0) { rtp_settings->own_preferrence = is_attr_enabled(attr); break; } } } else if(strcasecmp(elem->name,"rtcp") == 0) { unimrcp_server_rtcp_settings_load(loader,rtp_settings,elem); } else { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Element <%s>",elem->name); } } return mrcp_server_rtp_settings_register(loader->server,rtp_settings,id); }
/* Set RTP config struct with param, val pair. */ static int process_rtp_config(mrcp_client_t *client, mpf_rtp_config_t *rtp_config, mpf_rtp_settings_t *rtp_settings, const char *param, const char *val, apr_pool_t *pool) { int mine = 1; if ((client == NULL) || (rtp_config == NULL) || (rtp_settings == NULL) || (param == NULL) || (val == NULL) || (pool == NULL)) return mine; if (strcasecmp(param, "rtp-ip") == 0) apt_string_set(&rtp_config->ip, ip_addr_get(val, pool)); else if (strcasecmp(param, "rtp-ext-ip") == 0) apt_string_set(&rtp_config->ext_ip, ip_addr_get(val, pool)); else if (strcasecmp(param, "rtp-port-min") == 0) rtp_config->rtp_port_min = (apr_port_t)atol(val); else if (strcasecmp(param, "rtp-port-max") == 0) rtp_config->rtp_port_max = (apr_port_t)atol(val); else if (strcasecmp(param, "playout-delay") == 0) rtp_settings->jb_config.initial_playout_delay = atol(val); else if (strcasecmp(param, "min-playout-delay") == 0) rtp_settings->jb_config.min_playout_delay = atol(val); else if (strcasecmp(param, "max-playout-delay") == 0) rtp_settings->jb_config.max_playout_delay = atol(val); else if (strcasecmp(param, "codecs") == 0) { /* Make sure that /etc/mrcp.conf contains the desired codec first in the codecs parameter. */ const mpf_codec_manager_t *codec_manager = mrcp_client_codec_manager_get(client); if (codec_manager != NULL) { if (!mpf_codec_manager_codec_list_load(codec_manager, &rtp_settings->codec_list, val, pool)) ast_log(LOG_WARNING, "Unable to load codecs\n"); } } else if (strcasecmp(param, "ptime") == 0) rtp_settings->ptime = (apr_uint16_t)atol(val); else if (strcasecmp(param, "rtcp") == 0) rtp_settings->rtcp = atoi(val); else if (strcasecmp(param, "rtcp-bye") == 0) rtp_settings->rtcp_bye_policy = atoi(val); else if (strcasecmp(param, "rtcp-tx-interval") == 0) rtp_settings->rtcp_tx_interval = (apr_uint16_t)atoi(val); else if (strcasecmp(param, "rtcp-rx-resolution") == 0) rtp_settings->rtcp_rx_resolution = (apr_uint16_t)atol(val); else mine = 0; return mine; }
/** 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; }