Пример #1
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);
}
Пример #2
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;
}
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;
}
Пример #4
0
static apt_bool_t mrcp_client_channel_add(mrcp_client_session_t *session, mrcp_channel_t *channel)
{
	mrcp_channel_t **channel_slot;
	mrcp_control_descriptor_t *control_media;
	mpf_rtp_termination_descriptor_t *rtp_descriptor = NULL;
	rtp_termination_slot_t *termination_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->base.signaling_agent = profile->signaling_agent;
		session->base.signaling_agent->create_client_session(&session->base);

		session->offer = mrcp_session_descriptor_create(pool);
		session->context = mpf_context_create(session,5,pool);
	}
	if(!channel->resource) {
		channel->resource = mrcp_resource_get(profile->resource_factory,channel->resource_id);
		if(!channel->resource) {
			return FALSE;
		}
		channel->resource_name = mrcp_resource_name_get(profile->resource_factory,channel->resource_id);
		if(!channel->resource_name) {
			return FALSE;
		}
	}
	if(session->base.signaling_agent->mrcp_version == MRCP_VERSION_1) {
		session->offer->resource_name = *channel->resource_name;
		session->offer->resource_state = TRUE;
	}
	else {
		if(!channel->control_channel) {
			channel->control_channel = mrcp_client_control_channel_create(profile->connection_agent,channel,pool);
		}
		control_media = mrcp_control_offer_create(pool);
		control_media->id = mrcp_session_control_media_add(session->offer,control_media);
		control_media->cmid = 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;
			session->offer_flag_count++;
		}
	}

	/* add to channel array */
	apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Add Control Channel <%s@%s>",
					mrcp_session_str(session),
					channel->resource_name->buf);
	channel_slot = apr_array_push(session->channels);
	*channel_slot = channel;

	if(channel->termination) {
		if(mrcp_client_mpf_request_send(profile->media_engine,MPF_COMMAND_ADD,session->context,channel->termination,NULL) == TRUE) {
			channel->waiting_for_termination = TRUE;
			session->offer_flag_count++;
		}
	}

	if(channel->rtp_termination_slot) {
		rtp_descriptor = channel->rtp_termination_slot->descriptor;
	}	
	/* add to rtp termination array */
	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Add RTP Termination");
	termination_slot = apr_array_push(session->terminations);
	termination_slot->waiting = FALSE;
	termination_slot->termination = NULL;
	termination_slot->descriptor = NULL;
	if(rtp_descriptor) {
		if(rtp_descriptor->audio.local) {
			session->offer->ip = rtp_descriptor->audio.local->base.ip;
			rtp_descriptor->audio.local->base.id = mrcp_session_audio_media_add(session->offer,rtp_descriptor->audio.local);
			rtp_descriptor->audio.local->mid = session->offer->audio_media_arr->nelts;
		}
	}
	else {
		/* create rtp termination */
		mpf_termination_t *termination = mpf_termination_create(profile->rtp_termination_factory,session,session->base.pool);
		termination_slot->termination = termination;

		/* initialize rtp descriptor */
		rtp_descriptor = apr_palloc(pool,sizeof(mpf_rtp_termination_descriptor_t));
		mpf_rtp_termination_descriptor_init(rtp_descriptor);
		if(channel->termination && channel->termination->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->base.state = MPF_MEDIA_ENABLED;
			media->mode = mpf_stream_mode_negotiate(channel->termination->audio_stream->mode);
			rtp_descriptor->audio.local = media;
		}
		/* send add termination request (add to media context) */
		if(mrcp_client_mpf_request_send(profile->media_engine,MPF_COMMAND_ADD,session->context,termination,rtp_descriptor) == TRUE) {
			termination_slot->waiting = TRUE;
			session->offer_flag_count++;
		}
	}
	termination_slot->descriptor = rtp_descriptor;
	channel->rtp_termination_slot = termination_slot;

	if(!session->offer_flag_count) {
		/* send offer to server */
		mrcp_client_session_offer_send(session);
	}
	return TRUE;
}
Пример #5
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;
	apt_task_msg_t *msg;
	mpf_message_t *mpf_message;
	apr_pool_t *pool = NULL;

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

	apt_log(APT_PRIO_INFO,"On MPF Suite Start");
	apr_pool_create(&pool,NULL);
	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_PRIO_INFO,"Create MPF Context");
	session->context = mpf_context_create(session,2,pool);

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

	apt_log(APT_PRIO_INFO,"Add Termination [1]");
	msg = apt_task_msg_get(task);
	msg->type = TASK_MSG_USER;
	mpf_message = (mpf_message_t*) msg->data;

	mpf_message->message_type = MPF_MESSAGE_TYPE_REQUEST;
	mpf_message->command_id = MPF_COMMAND_ADD;
	mpf_message->context = session->context;
	mpf_message->termination = session->termination1;
	mpf_message->descriptor = mpf_file_reader_descriptor_create(session);
	apt_task_msg_signal(suite_engine->engine_task,msg);

	apt_log(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_PRIO_INFO,"Add Termination [2]");
	msg = apt_task_msg_get(task);
	msg->type = TASK_MSG_USER;
	mpf_message = (mpf_message_t*) msg->data;

	mpf_message->message_type = MPF_MESSAGE_TYPE_REQUEST;
	mpf_message->command_id = MPF_COMMAND_ADD;
	mpf_message->context = session->context;
	mpf_message->termination = session->termination2;
	if(session->rtp_mode == TRUE) {
		mpf_message->descriptor = mpf_rtp_local_descriptor_create(session);
	}
	else {
		mpf_message->descriptor = mpf_file_writer_descriptor_create(session);
	}
	apt_task_msg_signal(suite_engine->engine_task,msg);
}
Пример #6
0
static apt_bool_t mrcp_server_av_media_offer_process(mrcp_server_session_t *session, mrcp_session_descriptor_t *descriptor)
{
	mrcp_termination_slot_t *slot;
	int i;
	int count = session->terminations->nelts;
	if(!descriptor->audio_media_arr->nelts) {
		/* no media to process */
		return TRUE;
	}
	if(count > descriptor->audio_media_arr->nelts) {
		apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Number of Terminations [%d] > Number of Audio Media in Offer [%d]",
			count,descriptor->audio_media_arr->nelts);
		count = descriptor->audio_media_arr->nelts;
	}
	
	/* update existing terminations */
	for(i=0; i<count; i++) {
		mpf_rtp_termination_descriptor_t *rtp_descriptor;
		/* get existing termination */
		slot = &((mrcp_termination_slot_t*)session->terminations->elts)[i];
		if(!slot || !slot->termination) continue;

		/* 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 = mrcp_session_audio_media_get(descriptor,i);

		/* send modify termination request */
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Modify RTP Termination [%d]",i);
		if(mrcp_server_mpf_request_send(session,MPF_COMMAND_MODIFY,session->context,slot->termination,rtp_descriptor) == TRUE) {
			slot->waiting = TRUE;
			session->answer_flag_count++;
		}
	}
	
	/* add new terminations */
	for(; i<descriptor->audio_media_arr->nelts; i++) {
		mpf_rtp_termination_descriptor_t *rtp_descriptor;
		mpf_termination_t *termination;
		/* create new RTP termination instance */
		termination = mpf_termination_create(session->profile->rtp_termination_factory,session,session->base.pool);
		/* add to termination array */
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Add RTP Termination [%d]",i);
		slot = apr_array_push(session->terminations);
		slot->id = i;
		slot->waiting = FALSE;
		slot->termination = 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 = mrcp_session_audio_media_get(descriptor,i);

		/* send add termination request (add to media context) */
		if(mrcp_server_mpf_request_send(session,MPF_COMMAND_ADD,session->context,termination,rtp_descriptor) == TRUE) {
			slot->waiting = TRUE;
			session->answer_flag_count++;
		}
	}
	return TRUE;
}