Exemplo n.º 1
0
/** Get associated audio stream */
MRCP_DECLARE(const mpf_audio_stream_t*) mrcp_application_audio_stream_get(const mrcp_channel_t *channel)
{
	if(!channel || !channel->termination) {
		return NULL;
	}

	return mpf_termination_audio_stream_get(channel->termination);
}
Exemplo n.º 2
0
/** Get codec descriptor of the audio sink stream */
const mpf_codec_descriptor_t* mrcp_engine_sink_stream_codec_get(mrcp_engine_channel_t *channel)
{
	if(channel && channel->termination) {
		mpf_audio_stream_t *audio_stream = mpf_termination_audio_stream_get(channel->termination);
		if(audio_stream) {
			return audio_stream->tx_descriptor;
		}
	}
	return NULL;
}
Exemplo n.º 3
0
/** Get codec descriptor of sink stream */
MRCP_DECLARE(const mpf_codec_descriptor_t*) mrcp_application_sink_descriptor_get(const mrcp_channel_t *channel)
{
	mpf_audio_stream_t *audio_stream;
	if(!channel || !channel->termination) {
		return NULL;
	}
	audio_stream = mpf_termination_audio_stream_get(channel->termination);
	if(!audio_stream) {
		return NULL;
	}
	return audio_stream->tx_descriptor;
}
static apt_bool_t mrcp_client_channel_modify(mrcp_client_session_t *session, mrcp_channel_t *channel, apt_bool_t enable)
{
	int index;
	if(!session->offer) {
		return FALSE;
	}
	if(!channel->resource) {
		return FALSE;
	}

	apt_obj_log(APT_LOG_MARK,APT_PRIO_NOTICE,session->base.log_obj,"Modify Control Channel "APT_NAMESIDRES_FMT" [%d]",
					MRCP_SESSION_NAMESID(session),
					channel->resource->name.buf,
					enable);
	if(mrcp_client_channel_find(session,channel,&index) == TRUE) {
		mrcp_control_descriptor_t *control_media = mrcp_session_control_media_get(session->offer,(apr_size_t)index);
		if(control_media) {
			control_media->port = (enable == TRUE) ? TCP_DISCARD_PORT : 0;
		}
		if(channel->termination && channel->rtp_termination_slot) {
			mpf_audio_stream_t *audio_stream = mpf_termination_audio_stream_get(
														channel->termination);
			mpf_rtp_media_descriptor_t *audio_media = mrcp_session_audio_media_get(
														session->offer,
														channel->rtp_termination_slot->id);
			if(audio_media && audio_stream) {
				mpf_stream_direction_e direction = mpf_stream_reverse_direction_get(audio_stream->direction);
				if(enable == TRUE) {
					audio_media->direction |= direction;
				}
				else {
					audio_media->direction &= ~direction;
				}
				audio_media->state = (audio_media->direction != STREAM_DIRECTION_NONE) ? MPF_MEDIA_ENABLED : MPF_MEDIA_DISABLED;
			}
		}
	}

	session->offer->resource_name = channel->resource->name;
	session->offer->resource_state = enable;
	return mrcp_client_session_offer_send(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;
}