/** Register media engine */ MRCP_DECLARE(apt_bool_t) mrcp_server_media_engine_register(mrcp_server_t *server, mpf_engine_t *media_engine, const char *name) { if(!media_engine || !name) { return FALSE; } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Register Media Engine [%s]",name); mpf_engine_codec_manager_register(media_engine,server->codec_manager); apr_hash_set(server->media_engine_table,name,APR_HASH_KEY_STRING,media_engine); mpf_engine_task_msg_type_set(media_engine,MRCP_SERVER_MEDIA_TASK_MSG); if(server->task) { apt_task_t *media_task = mpf_task_get(media_engine); apt_task_t *task = apt_consumer_task_base_get(server->task); apt_task_add(task,media_task); } return TRUE; }
/** Register MRCP signaling agent */ MRCP_DECLARE(apt_bool_t) mrcp_client_signaling_agent_register(mrcp_client_t *client, mrcp_sig_agent_t *signaling_agent, const char *name) { if(!signaling_agent || !name) { return FALSE; } apt_log(APT_PRIO_INFO,"Register Signaling Agent [%s]",name); signaling_agent->msg_pool = apt_task_msg_pool_create_dynamic(sizeof(sig_agent_task_msg_data_t),client->pool); signaling_agent->parent = client; signaling_agent->resource_factory = client->resource_factory; apr_hash_set(client->sig_agent_table,name,APR_HASH_KEY_STRING,signaling_agent); if(client->task) { apt_task_t *task = apt_consumer_task_base_get(client->task); apt_task_add(task,signaling_agent->task); } return TRUE; }
/** Register MRCP connection agent (MRCPv2 only) */ MRCP_DECLARE(apt_bool_t) mrcp_server_connection_agent_register(mrcp_server_t *server, mrcp_connection_agent_t *connection_agent, const char *name) { if(!connection_agent || !name) { return FALSE; } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Register Connection Agent [%s]",name); mrcp_server_connection_resource_factory_set(connection_agent,server->resource_factory); mrcp_server_connection_agent_handler_set(connection_agent,server,&connection_method_vtable); server->connection_msg_pool = apt_task_msg_pool_create_dynamic(sizeof(connection_agent_task_msg_data_t),server->pool); apr_hash_set(server->cnt_agent_table,name,APR_HASH_KEY_STRING,connection_agent); if(server->task) { apt_task_t *task = apt_consumer_task_base_get(server->task); apt_task_t *connection_task = mrcp_server_connection_agent_task_get(connection_agent); apt_task_add(task,connection_task); } return TRUE; }
/** Register MRCP signaling agent */ MRCP_DECLARE(apt_bool_t) mrcp_server_signaling_agent_register(mrcp_server_t *server, mrcp_sig_agent_t *signaling_agent, const char *name) { if(!signaling_agent || !name) { return FALSE; } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Register Signaling Agent [%s]",name); signaling_agent->parent = server; signaling_agent->resource_factory = server->resource_factory; signaling_agent->create_server_session = mrcp_server_sig_agent_session_create; signaling_agent->msg_pool = apt_task_msg_pool_create_dynamic(sizeof(mrcp_signaling_message_t*),server->pool); apr_hash_set(server->sig_agent_table,name,APR_HASH_KEY_STRING,signaling_agent); if(server->task) { apt_task_t *task = apt_consumer_task_base_get(server->task); apt_task_add(task,signaling_agent->task); } return TRUE; }
/** Register media engine */ MRCP_DECLARE(apt_bool_t) mrcp_client_media_engine_register(mrcp_client_t *client, mpf_engine_t *media_engine) { const char *id; if(!media_engine) { return FALSE; } id = mpf_engine_id_get(media_engine); if(!id) { return FALSE; } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Register Media Engine [%s]",id); mpf_engine_codec_manager_register(media_engine,client->codec_manager); apr_hash_set(client->media_engine_table,id,APR_HASH_KEY_STRING,media_engine); mpf_engine_task_msg_type_set(media_engine,MRCP_CLIENT_MEDIA_TASK_MSG); if(client->task) { apt_task_t *media_task = mpf_task_get(media_engine); apt_task_t *task = apt_consumer_task_base_get(client->task); apt_task_add(task,media_task); } return TRUE; }
/** 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; }
/** 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; }