Exemplo n.º 1
0
/** Process MPF event  */
static apt_bool_t mpf_suite_event_process(mpf_suite_agent_t *agent, const mpf_message_t *mpf_message)
{
	mpf_task_msg_t *task_msg = NULL;
	mpf_suite_session_t *session;
	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process MPF Event");
	if(mpf_message->termination) {
		session = mpf_termination_object_get(mpf_message->termination);
		/* first destroy existing topology */
		mpf_engine_topology_message_add(
					agent->engine,
					MPF_DESTROY_TOPOLOGY,session->context,
					&task_msg);

		if(session->file_termination) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Subtract Termination [File]");
			mpf_engine_termination_message_add(
				agent->engine,
				MPF_SUBTRACT_TERMINATION,session->context,session->file_termination,NULL,
				&task_msg);
		}
		if(session->rtp_termination) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Subtract Termination [RTP]");
			mpf_engine_termination_message_add(
				agent->engine,
				MPF_SUBTRACT_TERMINATION,session->context,session->rtp_termination,NULL,
				&task_msg);
		}
	}
	return mpf_engine_message_send(agent->engine,&task_msg);
}
Exemplo n.º 2
0
/** Start execution of MPF test suite scenario  */
static void mpf_suite_on_start_complete(apt_task_t *task)
{
	mpf_suite_session_t *session;
	apt_task_t *consumer_task;
	mpf_suite_engine_t *suite_engine;
	mpf_task_msg_t *task_msg = NULL;
	void *descriptor;
	apr_pool_t *pool = NULL;

	consumer_task = apt_task_object_get(task);
	suite_engine = apt_task_object_get(consumer_task);

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"On MPF Suite Start");
	pool = apt_pool_create();
	session = apr_palloc(pool,sizeof(mpf_suite_session_t));
	session->pool = pool;
	session->context = NULL;
	session->termination1 = NULL;
	session->termination2 = NULL;
	session->rtp_mode = TRUE;

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Create MPF Context");
	session->context = mpf_engine_context_create(suite_engine->engine,session,2,pool);

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Create Termination [1]");
	session->termination1 = mpf_termination_create(suite_engine->file_termination_factory,session,session->pool);

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Add Termination [1]");
	descriptor = mpf_file_reader_descriptor_create(session);
	mpf_engine_termination_message_add(
			suite_engine->engine,
			MPF_ADD_TERMINATION,session->context,session->termination1,descriptor,
			&task_msg);

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Create Termination [2]");
	if(session->rtp_mode == TRUE) {
		session->termination2 = mpf_termination_create(suite_engine->rtp_termination_factory,session,session->pool);
	}
	else {
		session->termination2 = mpf_termination_create(suite_engine->file_termination_factory,session,session->pool);
	}

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Add Termination [2]");
	descriptor = NULL;
	if(session->rtp_mode == TRUE) {
		descriptor = mpf_rtp_local_descriptor_create(session);
	}
	else {
		descriptor = mpf_file_writer_descriptor_create(session);
	}

	mpf_engine_termination_message_add(
			suite_engine->engine,
			MPF_ADD_TERMINATION,session->context,session->termination2,descriptor,
			&task_msg);

	mpf_engine_message_send(suite_engine->engine,&task_msg);
}
Exemplo n.º 3
0
static apt_bool_t mrcp_server_resource_offer_process(mrcp_server_session_t *session, mrcp_session_descriptor_t *descriptor)
{
	if(descriptor->resource_state == TRUE) {
		/* setup */
		mrcp_channel_t *channel;
		int count = session->channels->nelts;
		channel = mrcp_server_channel_find(session,&descriptor->resource_name);
		if(channel) {
			/* channel already exists */
			return TRUE;
		}
		/* create new MRCP channel instance */
		channel = mrcp_server_channel_create(session,&descriptor->resource_name,count,NULL);
		if(!channel || !channel->resource) {
			return FALSE;
		}
		/* add to channel array */
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Add Control Channel "APT_NAMESIDRES_FMT" [%d]",
			MRCP_SESSION_NAMESID(session),
			channel->resource->name.buf,
			count);
		APR_ARRAY_PUSH(session->channels,mrcp_channel_t*) = channel;
		if(channel->engine_channel && channel->engine_channel->termination) {
			mpf_termination_t *termination = channel->engine_channel->termination;
			/* send add termination request (add to media context) */
			if(mpf_engine_termination_message_add(
					session->profile->media_engine,
					MPF_ADD_TERMINATION,session->context,termination,NULL,
					&session->mpf_task_msg) == TRUE) {
				channel->waiting_for_termination = TRUE;
				mrcp_server_session_subrequest_add(session);
			}
		}
	}
Exemplo n.º 4
0
/** Process MPF response  */
static apt_bool_t mpf_suite_response_process(mpf_suite_agent_t *agent, const mpf_message_t *mpf_message)
{
	mpf_task_msg_t *task_msg = NULL;
	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process MPF Response");
	if(mpf_message->command_id == MPF_ADD_TERMINATION) {
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"On Add Termination");
		if(mpf_message->termination) {
			mpf_suite_session_t *session;
			session = mpf_termination_object_get(mpf_message->termination);
			if(session->rtp_termination == mpf_message->termination) {
				mpf_rtp_stream_descriptor_t *descriptor = NULL;
				if(session == agent->rx_session) {
					descriptor = mpf_rtp_rx_remote_descriptor_create(agent,session);
				}
				if(session == agent->tx_session) {
					descriptor = mpf_rtp_tx_remote_descriptor_create(agent,session);
				}

				if(descriptor) {
					mpf_engine_termination_message_add(
						agent->engine,
						MPF_MODIFY_TERMINATION,session->context,session->rtp_termination,descriptor,
						&task_msg);
				}

				mpf_engine_assoc_message_add(
						agent->engine,
						MPF_ADD_ASSOCIATION,session->context,session->file_termination,session->rtp_termination,
						&task_msg);

				mpf_engine_topology_message_add(
						agent->engine,
						MPF_APPLY_TOPOLOGY,session->context,
						&task_msg);
			}
		}
	}
	else if(mpf_message->command_id == MPF_SUBTRACT_TERMINATION) {
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"On Subtract Termination");
		if(mpf_message->termination) {
			mpf_suite_session_t *session;
			session = mpf_termination_object_get(mpf_message->termination);
			if(session->file_termination == mpf_message->termination) {
				session->file_termination = NULL;
			}
			else if(session->rtp_termination == mpf_message->termination) {
				session->rtp_termination = NULL;
			}
			mpf_termination_destroy(mpf_message->termination);

			if(!session->file_termination && !session->rtp_termination) {
				mpf_suite_session_destroy(agent,session);
			}
		}
	}
	return mpf_engine_message_send(agent->engine,&task_msg);
}
static apt_bool_t mrcp_client_av_media_answer_process(mrcp_client_session_t *session, mrcp_session_descriptor_t *descriptor)
{
	rtp_termination_slot_t *slot;
	int i;
	int count = session->terminations->nelts;
	if(count != descriptor->audio_media_arr->nelts) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Number of terminations [%d] != Number of audio media in answer [%d]",
			count,descriptor->audio_media_arr->nelts);
		count = descriptor->audio_media_arr->nelts;
	}
	
	/* update existing terminations */
	for(i=0; i<count; i++) {
		mpf_rtp_media_descriptor_t *remote_media;
		mpf_rtp_termination_descriptor_t *rtp_descriptor;
		/* get existing termination */
		slot = &APR_ARRAY_IDX(session->terminations,i,rtp_termination_slot_t);
		if(!slot) continue;

		remote_media = mrcp_session_audio_media_get(descriptor,i);
		if(slot->descriptor) {
			slot->descriptor->audio.remote = remote_media;
		}
		if(slot->termination) {
			/* construct termination descriptor */
			rtp_descriptor = apr_palloc(session->base.pool,sizeof(mpf_rtp_termination_descriptor_t));
			mpf_rtp_termination_descriptor_init(rtp_descriptor);
			rtp_descriptor->audio.local = NULL;
			rtp_descriptor->audio.remote = remote_media;

			/* send modify termination request */
			apt_obj_log(APT_LOG_MARK,APT_PRIO_DEBUG,session->base.log_obj,"Modify Media Termination "APT_NAMESIDRES_FMT, 
				MRCP_SESSION_NAMESID(session),
				mpf_termination_name_get(slot->termination));
			if(mpf_engine_termination_message_add(
					session->profile->media_engine,
					MPF_MODIFY_TERMINATION,session->context,slot->termination,rtp_descriptor,
					&session->mpf_task_msg) == TRUE) {
				slot->waiting = TRUE;
				mrcp_client_session_subrequest_add(session);
			}
			if(slot->channel && slot->channel->termination) {
				if(mpf_engine_assoc_message_add(
						session->profile->media_engine,
						MPF_ADD_ASSOCIATION,session->context,slot->termination,slot->channel->termination,
						&session->mpf_task_msg) == TRUE) {
					mrcp_client_session_subrequest_add(session);
				}
			}
		}
	}
	return TRUE;
}
Exemplo n.º 6
0
static mpf_suite_session_t* mpf_suite_tx_session_create(const mpf_suite_agent_t *agent)
{
	mpf_task_msg_t *task_msg = NULL;
	void *descriptor;
	apr_pool_t *pool;
	mpf_suite_session_t *session;

	pool = apt_pool_create();
	session = apr_palloc(pool,sizeof(mpf_suite_session_t));
	session->pool = pool;
	session->context = NULL;
	session->file_termination = NULL;
	session->rtp_termination = NULL;

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Create MPF Context [Tx]");
	session->context = mpf_engine_context_create(agent->engine,NULL,session,2,pool);

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Create Termination [File Reader]");
	session->file_termination = mpf_termination_create(agent->file_termination_factory,session,session->pool);

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Add Termination [File Reader]");
	descriptor = mpf_file_reader_descriptor_create(agent,session);
	mpf_engine_termination_message_add(
			agent->engine,
			MPF_ADD_TERMINATION,session->context,session->file_termination,descriptor,
			&task_msg);

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Create Termination [RTP Tx]");
	session->rtp_termination = mpf_termination_create(agent->rtp_termination_factory,session,session->pool);

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Add Termination [RTP Tx]");
	descriptor = mpf_rtp_tx_local_descriptor_create(agent,session);
	mpf_engine_termination_message_add(
			agent->engine,
			MPF_ADD_TERMINATION,session->context,session->rtp_termination,descriptor,
			&task_msg);

	mpf_engine_message_send(agent->engine,&task_msg);
	return session;
}
Exemplo n.º 7
0
/** Process MPF event  */
static apt_bool_t mpf_suite_event_process(mpf_suite_engine_t *suite_engine, const mpf_message_t *mpf_message)
{
	mpf_task_msg_t *task_msg = NULL;
	mpf_suite_session_t *session;
	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process MPF Event");
	if(mpf_message->termination) {
		session = mpf_termination_object_get(mpf_message->termination);
		if(session->termination1) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Subtract Termination [1]");
			mpf_engine_termination_message_add(
				suite_engine->engine,
				MPF_SUBTRACT_TERMINATION,session->context,session->termination1,NULL,
				&task_msg);
		}
		if(session->termination2) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Subtract Termination [2]");
			mpf_engine_termination_message_add(
				suite_engine->engine,
				MPF_SUBTRACT_TERMINATION,session->context,session->termination2,NULL,
				&task_msg);
		}
	}
	return mpf_engine_message_send(suite_engine->engine,&task_msg);
}
Exemplo n.º 8
0
static apt_bool_t mrcp_server_resource_offer_process(mrcp_server_session_t *session, mrcp_session_descriptor_t *descriptor)
{
	if(descriptor->resource_state == TRUE) {
		/* setup */
		mrcp_channel_t *channel;
		int count = session->channels->nelts;
		channel = mrcp_server_channel_find(session,&descriptor->resource_name);
		if(channel) {
			/* channel already exists */
			return TRUE;
		}
		/* create new MRCP channel instance */
		channel = mrcp_server_channel_create(session,&descriptor->resource_name,count,NULL);
		if(!channel || !channel->resource) {
			return FALSE;
		}
		/* add to channel array */
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Add Control Channel [%d]",count);
		APR_ARRAY_PUSH(session->channels,mrcp_channel_t*) = channel;
		if(channel->engine_channel && channel->engine_channel->termination) {
			mpf_termination_t *termination = channel->engine_channel->termination;
			/* send add termination request (add to media context) */
			if(mpf_engine_termination_message_add(
					session->profile->media_engine,
					MPF_ADD_TERMINATION,session->context,termination,NULL,
					&session->mpf_task_msg) == TRUE) {
				channel->waiting_for_termination = TRUE;
				mrcp_server_session_subrequest_add(session);
			}

			if(termination->audio_stream) {
				mpf_rtp_media_descriptor_t *rtp_media_descriptor = mrcp_session_audio_media_get(descriptor,0);
				if(rtp_media_descriptor) {
					/* some implementations erroneously indicate sendonly stream,
					   implicitly modify the descriptor, 
					   assuming stream SHOULD not be disabled on initial offer */
					mpf_stream_direction_e direction = termination->audio_stream->direction;
					rtp_media_descriptor->direction |= direction;
					if(rtp_media_descriptor->state == MPF_MEDIA_DISABLED) {
						rtp_media_descriptor->state = MPF_MEDIA_ENABLED;
					}
				}
			}
		}
	}
Exemplo n.º 9
0
/** Process MPF response  */
static apt_bool_t mpf_suite_response_process(mpf_suite_engine_t *suite_engine, const mpf_message_t *mpf_message)
{
	mpf_task_msg_t *task_msg = NULL;
	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process MPF Response");
	if(mpf_message->command_id == MPF_ADD_TERMINATION) {
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"On Add Termination");
		if(mpf_message->termination) {
			mpf_suite_session_t *session;
			session = mpf_termination_object_get(mpf_message->termination);
			if(session->termination2 == mpf_message->termination && session->rtp_mode == TRUE) {
				void *descriptor = mpf_rtp_remote_descriptor_create(session);
				mpf_engine_termination_message_add(
					suite_engine->engine,
					MPF_MODIFY_TERMINATION,session->context,session->termination2,descriptor,
					&task_msg);
			}
		}
	}
	else if(mpf_message->command_id == MPF_SUBTRACT_TERMINATION) {
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"On Subtract Termination");
		if(mpf_message->termination) {
			mpf_suite_session_t *session;
			session = mpf_termination_object_get(mpf_message->termination);
			if(session->termination1 == mpf_message->termination) {
				session->termination1 = NULL;
			}
			if(session->termination2 == mpf_message->termination) {
				session->termination2 = NULL;
			}
			mpf_termination_destroy(mpf_message->termination);

			if(!session->termination1 && !session->termination2) {
				mpf_engine_context_destroy(session->context);
				session->context = NULL;
				apr_pool_destroy(session->pool);

				apr_thread_mutex_lock(suite_engine->wait_object_mutex);
				apr_thread_cond_signal(suite_engine->wait_object);
				apr_thread_mutex_unlock(suite_engine->wait_object_mutex);
			}
		}
	}
	return mpf_engine_message_send(suite_engine->engine,&task_msg);
}
Exemplo n.º 10
0
static apt_bool_t mrcp_server_session_terminate_process(mrcp_server_session_t *session)
{
	mrcp_channel_t *channel;
	mrcp_termination_slot_t *slot;
	int i;
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Receive Terminate Request "APT_SID_FMT,MRCP_SESSION_SID(&session->base));

	mrcp_server_session_state_set(session,SESSION_STATE_TERMINATING);

	if(session->context) {
		/* first, destroy existing topology */
		if(mpf_engine_topology_message_add(
					session->profile->media_engine,
					MPF_RESET_ASSOCIATIONS,session->context,
					&session->mpf_task_msg) == TRUE){
			mrcp_server_session_subrequest_add(session);
		}
	}

	for(i=0; i<session->channels->nelts; i++) {
		channel = APR_ARRAY_IDX(session->channels,i,mrcp_channel_t*);
		if(!channel) continue;

		/* send remove channel request */
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Remove Control Channel [%d]",i);
		if(channel->control_channel) {
			if(mrcp_server_control_channel_remove(channel->control_channel) == TRUE) {
				channel->waiting_for_channel = TRUE;
				mrcp_server_session_subrequest_add(session);
			}
		}

		if(channel->engine_channel) {
			mpf_termination_t *termination = channel->engine_channel->termination;
			/* send subtract termination request */
			if(termination) {
				apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Subtract Channel Termination");
				if(mpf_engine_termination_message_add(
							session->profile->media_engine,
							MPF_SUBTRACT_TERMINATION,session->context,termination,NULL,
							&session->mpf_task_msg) == TRUE) {
					channel->waiting_for_termination = TRUE;
					mrcp_server_session_subrequest_add(session);
				}
			}

			/* close engine channel */
			if(mrcp_engine_channel_virtual_close(channel->engine_channel) == TRUE) {
				mrcp_server_session_subrequest_add(session);
			}
		}
	}
	for(i=0; i<session->terminations->nelts; i++) {
		/* get existing termination */
		slot = &APR_ARRAY_IDX(session->terminations,i,mrcp_termination_slot_t);
		if(!slot || !slot->termination) continue;

		/* send subtract termination request */
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Subtract RTP Termination [%d]",i);
		if(mpf_engine_termination_message_add(
				session->profile->media_engine,
				MPF_SUBTRACT_TERMINATION,session->context,slot->termination,NULL,
				&session->mpf_task_msg) == TRUE) {
			slot->waiting = TRUE;
			mrcp_server_session_subrequest_add(session);
		}
	}

	if(session->context) {
		mpf_engine_message_send(session->profile->media_engine,&session->mpf_task_msg);
	}

	mrcp_server_session_remove(session);

	if(!session->subrequest_count) {
		mrcp_server_session_terminate_send(session);
	}

	return TRUE;
}
static apt_bool_t mrcp_client_session_terminate(mrcp_client_session_t *session)
{
	mrcp_profile_t *profile;
	mrcp_channel_t *channel;
	rtp_termination_slot_t *slot;
	int i;
	
	apt_obj_log(APT_LOG_MARK,APT_PRIO_INFO,session->base.log_obj,"Terminate Session "APT_NAMESID_FMT, 
		MRCP_SESSION_NAMESID(session));
	profile = session->profile;

	mrcp_client_session_state_set(session,SESSION_STATE_TERMINATING);
	if(session->context) {
		/* first destroy existing topology */
		if(mpf_engine_topology_message_add(
					session->profile->media_engine,
					MPF_DESTROY_TOPOLOGY,session->context,
					&session->mpf_task_msg) == TRUE){
			mrcp_client_session_subrequest_add(session);
		}
	}
	/* remove existing control channels */
	for(i=0; i<session->channels->nelts; i++) {
		/* get existing channel */
		channel = APR_ARRAY_IDX(session->channels,i,mrcp_channel_t*);
		if(!channel) continue;

		if(channel->control_channel) {
			/* remove channel */
			apt_obj_log(APT_LOG_MARK,APT_PRIO_DEBUG,session->base.log_obj,"Remove Control Channel "APT_NAMESID_FMT, 
				MRCP_SESSION_NAMESID(session));
			if(mrcp_client_control_channel_remove(channel->control_channel) == TRUE) {
				channel->waiting_for_channel = TRUE;
				mrcp_client_session_subrequest_add(session);
			}
		}

		/* send subtract termination request */
		if(channel->termination) {
			apt_obj_log(APT_LOG_MARK,APT_PRIO_DEBUG,session->base.log_obj,"Subtract Media Termination "APT_NAMESIDRES_FMT, 
				MRCP_SESSION_NAMESID(session),
				mpf_termination_name_get(channel->termination));
			if(mpf_engine_termination_message_add(
					profile->media_engine,
					MPF_SUBTRACT_TERMINATION,session->context,channel->termination,NULL,
					&session->mpf_task_msg) == TRUE) {
				channel->waiting_for_termination = TRUE;
				mrcp_client_session_subrequest_add(session);
			}
		}
	}

	if(session->context) {
		/* subtract existing terminations */
		for(i=0; i<session->terminations->nelts; i++) {
			/* get existing termination */
			slot = &APR_ARRAY_IDX(session->terminations,i,rtp_termination_slot_t);
			if(!slot || !slot->termination) continue;

			/* send subtract termination request */
			apt_obj_log(APT_LOG_MARK,APT_PRIO_DEBUG,session->base.log_obj,"Subtract Media Termination "APT_NAMESIDRES_FMT, 
				MRCP_SESSION_NAMESID(session),
				mpf_termination_name_get(slot->termination));
			if(mpf_engine_termination_message_add(
					profile->media_engine,
					MPF_SUBTRACT_TERMINATION,session->context,slot->termination,NULL,
					&session->mpf_task_msg) == TRUE) {
				slot->waiting = TRUE;
				mrcp_client_session_subrequest_add(session);
			}
		}

		mpf_engine_message_send(profile->media_engine,&session->mpf_task_msg);
	}

	mrcp_client_session_subrequest_add(session);
	mrcp_session_terminate_request(&session->base);
	return TRUE;
}
static apt_bool_t mrcp_client_channel_add(mrcp_client_session_t *session, mrcp_channel_t *channel)
{
	mpf_rtp_termination_descriptor_t *rtp_descriptor = NULL;
	rtp_termination_slot_t *slot;
	apr_pool_t *pool = session->base.pool;
	mrcp_profile_t *profile = session->profile;
	if(mrcp_client_channel_find(session,channel,NULL) == TRUE) {
		/* update */
		return mrcp_client_channel_modify(session,channel,TRUE);
	}

	if(!session->offer) {
		session->offer = mrcp_session_descriptor_create(pool);
	}
	
	mrcp_client_session_state_set(session,SESSION_STATE_GENERATING_OFFER);

	if(mrcp_session_version_get(session) == MRCP_VERSION_1) {
		session->offer->resource_name = channel->resource->name;
		session->offer->resource_state = TRUE;
	}
	else {
		mrcp_control_descriptor_t *control_media;
		if(!channel->control_channel) {
			channel->control_channel = mrcp_client_control_channel_create(profile->connection_agent,channel,pool);
			mrcp_client_control_channel_log_obj_set(channel->control_channel,session->base.log_obj);
		}
		control_media = mrcp_control_offer_create(pool);
		control_media->id = mrcp_session_control_media_add(session->offer,control_media);
		mrcp_cmid_add(control_media->cmid_arr,session->offer->control_media_arr->nelts);
		control_media->resource_name = channel->resource->name;
		if(mrcp_client_control_channel_add(channel->control_channel,control_media) == TRUE) {
			channel->waiting_for_channel = TRUE;
			mrcp_client_session_subrequest_add(session);
		}
	}

	apt_obj_log(APT_LOG_MARK,APT_PRIO_NOTICE,session->base.log_obj,"Add Control Channel "APT_NAMESIDRES_FMT,
					MRCP_SESSION_NAMESID(session),
					channel->resource->name.buf);
	/* add control channel */
	APR_ARRAY_PUSH(session->channels,mrcp_channel_t*) = channel;

	/* add rtp termination slot */
	slot = apr_array_push(session->terminations);
	slot->waiting = FALSE;
	slot->termination = NULL;
	slot->descriptor = NULL;
	slot->channel = channel;
	slot->id = 0;

	if(channel->termination) {
		/* media termination mode */
		mpf_termination_t *termination;
		mpf_audio_stream_t *audio_stream;

		if(!session->context) {
			/* create media context first */
			session->context = mpf_engine_context_create(
				profile->media_engine,
				session->base.name,
				session,5,pool);
		}
		apt_obj_log(APT_LOG_MARK,APT_PRIO_DEBUG,session->base.log_obj,"Add Media Termination "APT_NAMESIDRES_FMT,
			MRCP_SESSION_NAMESID(session),
			mpf_termination_name_get(channel->termination));
		if(mpf_engine_termination_message_add(
				profile->media_engine,
				MPF_ADD_TERMINATION,session->context,channel->termination,NULL,
				&session->mpf_task_msg) == TRUE) {
			channel->waiting_for_termination = TRUE;
			mrcp_client_session_subrequest_add(session);
		}

		/* initialize rtp descriptor */
		rtp_descriptor = apr_palloc(pool,sizeof(mpf_rtp_termination_descriptor_t));
		mpf_rtp_termination_descriptor_init(rtp_descriptor);
		rtp_descriptor->audio.settings = profile->rtp_settings;
		audio_stream = mpf_termination_audio_stream_get(channel->termination);
		if(audio_stream) {
			mpf_rtp_media_descriptor_t *media;
			media = apr_palloc(pool,sizeof(mpf_rtp_media_descriptor_t));
			mpf_rtp_media_descriptor_init(media);
			media->state = MPF_MEDIA_ENABLED;
			media->direction = mpf_stream_reverse_direction_get(audio_stream->direction);
			rtp_descriptor->audio.local = media;
			if(audio_stream->capabilities) {
				rtp_descriptor->audio.capabilities = mpf_stream_capabilities_clone(audio_stream->capabilities,pool);
				rtp_descriptor->audio.capabilities->direction = media->direction;
			}
		}

		/* create rtp termination */
		termination = mpf_termination_create(profile->rtp_termination_factory,session,pool);
		slot->termination = termination;
		apt_obj_log(APT_LOG_MARK,APT_PRIO_DEBUG,session->base.log_obj,"Add Media Termination "APT_NAMESIDRES_FMT, 
			MRCP_SESSION_NAMESID(session),
			mpf_termination_name_get(termination));

		/* send add termination request (add to media context) */
		if(mpf_engine_termination_message_add(
				profile->media_engine,
				MPF_ADD_TERMINATION,session->context,termination,rtp_descriptor,
				&session->mpf_task_msg) == TRUE) {
			slot->waiting = TRUE;
			mrcp_client_session_subrequest_add(session);
		}
		mpf_engine_message_send(profile->media_engine,&session->mpf_task_msg);
	}
	else {
		/* bypass media mode */
		if(channel->rtp_termination_slot) {
			rtp_descriptor = channel->rtp_termination_slot->descriptor;
			if(rtp_descriptor) {
				if(rtp_descriptor->audio.local) {
					session->offer->ip = rtp_descriptor->audio.local->ip;
					session->offer->ext_ip = rtp_descriptor->audio.local->ext_ip;
					rtp_descriptor->audio.local->id = mrcp_session_audio_media_add(session->offer,rtp_descriptor->audio.local);
					rtp_descriptor->audio.local->mid = session->offer->audio_media_arr->nelts;
					slot->id = session->offer->audio_media_arr->nelts - 1;
				}
			}
		}
	}

	slot->descriptor = rtp_descriptor;
	channel->rtp_termination_slot = slot;

	if(!session->subrequest_count) {
		/* send offer to server */
		mrcp_client_session_offer_send(session);
	}
	return TRUE;
}