Example #1
0
static void mpf_rtcp_tx_timer_proc(apt_timer_t *timer, void *obj)
{
	mpf_rtp_stream_t *rtp_stream = obj;

	/* generate and send RTCP compound report (SR/RR + SDES) */
	mpf_rtcp_report_send(rtp_stream);

	/* re-schedule timer */
	apt_timer_set(timer,rtp_stream->settings->rtcp_tx_interval);
}
static apt_bool_t mrcp_client_agent_messsage_send(mrcp_connection_agent_t *agent, mrcp_control_channel_t *channel, mrcp_message_t *message)
{
	apt_bool_t status = FALSE;
	mrcp_connection_t *connection = channel->connection;
	apt_text_stream_t stream;
	apt_message_status_e result;

	if(!connection || !connection->sock) {
		apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,channel->log_obj,"Null MRCPv2 Connection "APT_SIDRES_FMT,MRCP_MESSAGE_SIDRES(message));
		mrcp_client_agent_request_cancel(agent,channel,message);
		return FALSE;
	}

	do {
		apt_text_stream_init(&stream,connection->tx_buffer,connection->tx_buffer_size);
		result = mrcp_generator_run(connection->generator,message,&stream);
		if(result != APT_MESSAGE_STATUS_INVALID) {
			stream.text.length = stream.pos - stream.text.buf;
			*stream.pos = '\0';

			apt_obj_log(APT_LOG_MARK,APT_PRIO_INFO,channel->log_obj,"Send MRCPv2 Data %s [%"APR_SIZE_T_FMT" bytes]\n%.*s",
				connection->id,
				stream.text.length,
				connection->verbose == TRUE ? stream.text.length : 0,
				stream.text.buf);

			if(apr_socket_send(connection->sock,stream.text.buf,&stream.text.length) == APR_SUCCESS) {
				status = TRUE;
			}
			else {
				apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,channel->log_obj,"Failed to Send MRCPv2 Data %s",
					connection->id);
			}
		}
		else {
			apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,channel->log_obj,"Failed to Generate MRCPv2 Data %s",
				connection->id);
		}
	}
	while(result == APT_MESSAGE_STATUS_INCOMPLETE);

	if(status == TRUE) {
		channel->active_request = message;
		if(channel->request_timer && agent->request_timeout) {
			apt_timer_set(channel->request_timer,agent->request_timeout);
		}
	}
	else {
		mrcp_client_agent_request_cancel(agent,channel,message);
	}
	return status;
}
Example #3
0
static apt_bool_t rtsp_client_request_push(rtsp_client_connection_t *rtsp_connection, rtsp_client_session_t *session, rtsp_message_t *message)
{
	/* add request to inprogress request queue */
	apt_log(RTSP_LOG_MARK,APT_PRIO_INFO,"Push RTSP Request to In-Progress Queue " APT_PTRSID_FMT " CSeq:%"APR_SIZE_T_FMT,
		session,
		message->header.session_id.buf ? message->header.session_id.buf : "new",
		message->header.cseq);
	apt_list_push_back(rtsp_connection->inprogress_request_queue,session,session->pool);
	session->active_request = message;
	if(rtsp_connection->client->request_timeout) {
		apt_timer_set(session->request_timer,rtsp_connection->client->request_timeout);
	}
	return TRUE;
}
Example #4
0
static void mpf_rtcp_rx_timer_proc(apt_timer_t *timer, void *obj)
{
	mpf_rtp_stream_t *rtp_stream = obj;
	if(rtp_stream->rtcp_socket && rtp_stream->rtcp_l_sockaddr && rtp_stream->rtcp_r_sockaddr) {
		char buffer[MAX_RTCP_PACKET_SIZE];
		apr_size_t length = sizeof(buffer);
		
		if(apr_socket_recv(rtp_stream->rtcp_socket,buffer,&length) == APR_SUCCESS) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Receive Compound RTCP Packet [%"APR_SIZE_T_FMT" bytes] %s:%hu <- %s:%hu",
					length,
					rtp_stream->rtcp_l_sockaddr->hostname,
					rtp_stream->rtcp_l_sockaddr->port,
					rtp_stream->rtcp_r_sockaddr->hostname,
					rtp_stream->rtcp_r_sockaddr->port);
			mpf_rtcp_compound_packet_receive(rtp_stream,buffer,length);
		}
	}

	/* re-schedule timer */
	apt_timer_set(timer,rtp_stream->settings->rtcp_rx_resolution);
}
Example #5
0
static apt_bool_t mpf_rtp_stream_media_negotiate(mpf_rtp_stream_t *rtp_stream)
{
	mpf_rtp_media_descriptor_t *local_media = rtp_stream->local_media;
	mpf_rtp_media_descriptor_t *remote_media = rtp_stream->remote_media;
	if(!local_media || !remote_media) {
		return FALSE;
	}

	local_media->id = remote_media->id;
	local_media->mid = remote_media->mid;
	local_media->ptime = remote_media->ptime;

	if(rtp_stream->state == MPF_MEDIA_DISABLED && remote_media->state == MPF_MEDIA_ENABLED) {
		/* enable RTP/RTCP session */
		rtp_stream->state = MPF_MEDIA_ENABLED;
		if(rtp_stream->rtp_l_sockaddr) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Enable RTP Session %s:%hu",
				rtp_stream->rtp_l_sockaddr->hostname,
				rtp_stream->rtp_l_sockaddr->port);
		}

		if(rtp_stream->rtcp_tx_timer) {
			apt_timer_set(rtp_stream->rtcp_tx_timer,rtp_stream->settings->rtcp_tx_interval);
		}
		if(rtp_stream->rtcp_rx_timer) {
			apt_timer_set(rtp_stream->rtcp_rx_timer,rtp_stream->settings->rtcp_rx_resolution);
		}
	}
	else if(rtp_stream->state == MPF_MEDIA_ENABLED && remote_media->state == MPF_MEDIA_DISABLED) {
		/* disable RTP/RTCP session */
		rtp_stream->state = MPF_MEDIA_DISABLED;
		if(rtp_stream->rtp_l_sockaddr) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Disable RTP Session %s:%hu",
				rtp_stream->rtp_l_sockaddr->hostname,
				rtp_stream->rtp_l_sockaddr->port);
		}

		if(rtp_stream->rtcp_tx_timer) {
			apt_timer_kill(rtp_stream->rtcp_tx_timer);
		}
		if(rtp_stream->rtcp_rx_timer) {
			apt_timer_kill(rtp_stream->rtcp_rx_timer);
		}
		if(rtp_stream->settings->rtcp == TRUE && rtp_stream->settings->rtcp_bye_policy != RTCP_BYE_DISABLE) {
			apt_str_t reason = {RTCP_BYE_SESSION_ENDED, sizeof(RTCP_BYE_SESSION_ENDED)-1};
			mpf_rtcp_bye_send(rtp_stream,&reason);
		}
	}

	local_media->state = remote_media->state;
	local_media->direction = mpf_stream_reverse_direction_get(remote_media->direction);

	if(remote_media->state == MPF_MEDIA_ENABLED) {
		mpf_codec_list_t *codec_list1 = NULL;
		mpf_codec_list_t *codec_list2 = NULL;

		/* intersect local and remote codecs */
		if(rtp_stream->settings->own_preferrence == TRUE) {
			codec_list1 = &local_media->codec_list;
			codec_list2 = &remote_media->codec_list;
		}
		else {
			codec_list2 = &local_media->codec_list;
			codec_list1 = &remote_media->codec_list;
		}

		if(mpf_codec_lists_intersect(codec_list1,codec_list2) == FALSE) {
			/* reject RTP/RTCP session */
			rtp_stream->state = MPF_MEDIA_DISABLED;
			local_media->direction = STREAM_DIRECTION_NONE;
			local_media->state = MPF_MEDIA_DISABLED;
			if(rtp_stream->rtp_l_sockaddr) {
				apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Reject RTP Session %s:%hu no codecs matched",
					rtp_stream->rtp_l_sockaddr->hostname,
					rtp_stream->rtp_l_sockaddr->port);
			}

			if(rtp_stream->rtcp_tx_timer) {
				apt_timer_kill(rtp_stream->rtcp_tx_timer);
			}
			if(rtp_stream->rtcp_rx_timer) {
				apt_timer_kill(rtp_stream->rtcp_rx_timer);
			}
		}
	}

	rtp_stream->base->direction = local_media->direction;
	return TRUE;
}
Example #6
0
static apt_bool_t mpf_rtp_stream_media_negotiate(mpf_rtp_stream_t *rtp_stream)
{
	mpf_rtp_media_descriptor_t *local_media = rtp_stream->local_media;
	mpf_rtp_media_descriptor_t *remote_media = rtp_stream->remote_media;
	if(!local_media || !remote_media) {
		return FALSE;
	}

	local_media->id = remote_media->id;
	local_media->mid = remote_media->mid;
	local_media->ptime = remote_media->ptime;

	if(rtp_stream->state == MPF_MEDIA_DISABLED && remote_media->state == MPF_MEDIA_ENABLED) {
		/* enable RTP/RTCP session */
		rtp_stream->state = MPF_MEDIA_ENABLED;
		if(rtp_stream->rtp_l_sockaddr) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Enable RTP Session %s:%hu",
				rtp_stream->rtp_l_sockaddr->hostname,
				rtp_stream->rtp_l_sockaddr->port);
		}

		if(rtp_stream->rtcp_tx_timer) {
			apt_timer_set(rtp_stream->rtcp_tx_timer,rtp_stream->settings->rtcp_tx_interval);
		}
		if(rtp_stream->rtcp_rx_timer) {
			apt_timer_set(rtp_stream->rtcp_rx_timer,rtp_stream->settings->rtcp_rx_resolution);
		}
	}
	else if(rtp_stream->state == MPF_MEDIA_ENABLED && remote_media->state == MPF_MEDIA_DISABLED) {
		/* disable RTP/RTCP session */
		rtp_stream->state = MPF_MEDIA_DISABLED;
		if(rtp_stream->rtp_l_sockaddr) {
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Disable RTP Session %s:%hu",
				rtp_stream->rtp_l_sockaddr->hostname,
				rtp_stream->rtp_l_sockaddr->port);
		}

		if(rtp_stream->rtcp_tx_timer) {
			apt_timer_kill(rtp_stream->rtcp_tx_timer);
		}
		if(rtp_stream->rtcp_rx_timer) {
			apt_timer_kill(rtp_stream->rtcp_rx_timer);
		}
		if(rtp_stream->settings->rtcp == TRUE && rtp_stream->settings->rtcp_bye_policy != RTCP_BYE_DISABLE) {
			apt_str_t reason = {RTCP_BYE_SESSION_ENDED, sizeof(RTCP_BYE_SESSION_ENDED)-1};
			mpf_rtcp_bye_send(rtp_stream,&reason);
		}
	}

	local_media->state = remote_media->state;
	local_media->direction = mpf_stream_reverse_direction_get(remote_media->direction);
	rtp_stream->base->direction = local_media->direction;

	if(remote_media->state == MPF_MEDIA_ENABLED) {
		if(mpf_codec_list_is_empty(&remote_media->codec_list) == TRUE) {
			/* no remote codecs available, initialize them according to the local codecs  */
			mpf_codec_list_copy(&remote_media->codec_list,
								&local_media->codec_list,
								rtp_stream->pool);
		}

		/* intersect local and remote codecs */
		if(rtp_stream->settings->own_preferrence == TRUE) {
			mpf_codec_lists_intersect(
				&local_media->codec_list,
				&remote_media->codec_list);
		}
		else {
			mpf_codec_lists_intersect(
				&remote_media->codec_list,
				&local_media->codec_list);
		}
	}

	return TRUE;
}