static void handle_queue_events(stream_manager_t * stream_mgr) {
	OrtpEvent *ev;
	while (NULL != (ev=ortp_ev_queue_get(stream_mgr->evq))){
		OrtpEventType evt=ortp_event_get_type(ev);
		OrtpEventData *evd=ortp_event_get_data(ev);

		if (evt == ORTP_EVENT_RTCP_PACKET_RECEIVED) {
			const report_block_t *rb=NULL;
			if (rtcp_is_SR(evd->packet)){
				rb=rtcp_SR_get_report_block(evd->packet,0);
			}else if (rtcp_is_RR(evd->packet)){
				rb=rtcp_RR_get_report_block(evd->packet,0);
			}

			if (rb){
				stream_mgr->rtcp_count++;

				if (stream_mgr->type==VideoStreamType&&stream_mgr->video_stream->ms.use_rc){
					const MSQosAnalyzer *analyzer=ms_bitrate_controller_get_qos_analyzer(stream_mgr->video_stream->ms.rc);
					if (analyzer->type==Stateful){
						const MSStatefulQosAnalyzer *stateful_analyzer=((const MSStatefulQosAnalyzer*)analyzer);
						stream_mgr->adaptive_stats.network_state=stateful_analyzer->network_state;
						stream_mgr->adaptive_stats.loss_estim =100*stateful_analyzer->network_loss_rate;
						stream_mgr->adaptive_stats.congestion_bw_estim =stateful_analyzer->congestion_bandwidth;
					}
				}
			}
		}
		ortp_event_destroy(ev);
	}
}
Example #2
0
void VodWnd::process_rtcp()
{
    if (evq_) {
        OrtpEvent *ev = ortp_ev_queue_get(evq_);
        while (ev) {
            // TODO: ..
            OrtpEventType type = ortp_event_get_type(ev);
            if (type == ORTP_EVENT_RTCP_PACKET_RECEIVED) {
                first_rtcp_ = false;
            }

            ortp_event_destroy(ev);
            ev = ortp_ev_queue_get(evq_);
        }
    }
}
void media_stream_iterate(MediaStream *stream){
	time_t curtime=ms_time(NULL);

	if (stream->ice_check_list) ice_check_list_process(stream->ice_check_list,stream->sessions.rtp_session);
	/*we choose to update the quality indicator as much as possible, since local statistics can be computed realtime. */
	if (stream->state==MSStreamStarted){
		if (stream->qi && curtime>stream->last_iterate_time) ms_quality_indicator_update_local(stream->qi);
	}
	stream->last_iterate_time=curtime;

	if (stream->rc) ms_bitrate_controller_update(stream->rc);

	if (stream->evq){
		OrtpEvent *ev=NULL;

		while ((ev=ortp_ev_queue_get(stream->evq))!=NULL){
			OrtpEventType evt=ortp_event_get_type(ev);
			if (evt==ORTP_EVENT_RTCP_PACKET_RECEIVED){
				mblk_t *m=ortp_event_get_data(ev)->packet;
				media_stream_process_rtcp(stream,m,curtime);
			}else if (evt==ORTP_EVENT_RTCP_PACKET_EMITTED){
				ms_message("%s_stream_iterate[%p]: local statistics available\n\tLocal's current jitter buffer size:%f ms",
					media_stream_type_str(stream), stream, rtp_session_get_jitter_stats(stream->sessions.rtp_session)->jitter_buffer_size_ms);
			}else if ((evt==ORTP_EVENT_STUN_PACKET_RECEIVED)&&(stream->ice_check_list)){
				ice_handle_stun_packet(stream->ice_check_list,stream->sessions.rtp_session,ortp_event_get_data(ev));
			} else if (evt == ORTP_EVENT_ZRTP_ENCRYPTION_CHANGED) {
				OrtpEventData *evd=ortp_event_get_data(ev);
				stream->sessions.is_secured=evd->info.zrtp_stream_encrypted;
				ms_message("%s_stream_iterate[%p]: is %s ",media_stream_type_str(stream) , stream, stream->sessions.is_secured ? "encrypted" : "not encrypted");
			}
			ortp_event_destroy(ev);
		}
	}
}
static void event_queue_cb(MediaStream *ms, void *user_pointer) {
	stats_t *st = (stats_t *)user_pointer;
	OrtpEvent *ev = NULL;

	if (st->q != NULL) {
		while ((ev = ortp_ev_queue_get(st->q)) != NULL) {
			OrtpEventType evt = ortp_event_get_type(ev);
			OrtpEventData *d = ortp_event_get_data(ev);
			if (evt == ORTP_EVENT_TMMBR_RECEIVED) {
				do {
					if (rtcp_is_RTPFB(d->packet)) {
						switch (rtcp_RTPFB_get_type(d->packet)) {
							case RTCP_RTPFB_TMMBR:
								st->number_of_TMMBR++;
								break;
							default:
								break;
						}
					}
				} while (rtcp_next_packet(d->packet));
			}
			ortp_event_destroy(ev);
		}
	}
}
static void event_queue_cb(MediaStream *ms, void *user_pointer) {
	LossRateEstimatorCtx *ctx = (LossRateEstimatorCtx*)user_pointer;
	if (ctx->q != NULL) {
		OrtpEvent *ev = NULL;
		while ((ev = ortp_ev_queue_get(ctx->q)) != NULL) {
			OrtpEventType evt = ortp_event_get_type(ev);
			OrtpEventData *evd = ortp_event_get_data(ev);
			if (evt == ORTP_EVENT_RTCP_PACKET_RECEIVED) {
				do {
					const report_block_t *rb=NULL;
					if (rtcp_is_SR(evd->packet)){
						rb=rtcp_SR_get_report_block(evd->packet,0);
					}else if (rtcp_is_RR(evd->packet)){
						rb=rtcp_RR_get_report_block(evd->packet,0);
					}

					if (rb&&ortp_loss_rate_estimator_process_report_block(ctx->estimator,&ms->sessions.rtp_session->rtp,rb)){
						float diff = fabs(ortp_loss_rate_estimator_get_value(ctx->estimator) - ctx->loss_rate);
						CU_ASSERT_IN_RANGE(diff, 0, 10);
					}
				} while (rtcp_next_packet(evd->packet));
			}
			ortp_event_destroy(ev);
		}
	}
}
Example #6
0
bool_t audio_stream_alive(AudioStream * stream, int timeout){
	RtpSession *session=stream->session;
	const rtp_stats_t *stats=rtp_session_get_stats(session);
	if (stats->recv!=0){
		if (stream->evq){
			OrtpEvent *ev=ortp_ev_queue_get(stream->evq);
			if (ev!=NULL){
				if (ortp_event_get_type(ev)==ORTP_EVENT_RTCP_PACKET_RECEIVED){
					stream->last_packet_time=ms_time(NULL);
				}
				ortp_event_destroy(ev);
			}
		}
		if (stats->recv!=stream->last_packet_count){
			stream->last_packet_count=stats->recv;
			stream->last_packet_time=ms_time(NULL);
		}else{
			if (ms_time(NULL)-stream->last_packet_time>timeout){
				/* more than timeout seconds of inactivity*/
				return FALSE;
			}
		}
	}
	return TRUE;
}
void audio_stream_iterate(AudioStream *stream){

	if (stream->evq!=NULL){
		OrtpEvent *ev=ortp_ev_queue_get(stream->evq);
		if (ev!=NULL){
			if (ortp_event_get_type(ev)==ORTP_EVENT_RTCP_PACKET_RECEIVED){
				OrtpEventData *evd=ortp_event_get_data(ev);
				audio_steam_process_rtcp(stream,evd->packet);
			}
			ortp_event_destroy(ev);
		}
	}
}
static void parse_events(OrtpEvQueue *q){
	OrtpEvent *ev;
	while((ev=ortp_ev_queue_get(q))!=NULL){
		OrtpEventData *d=ortp_event_get_data(ev);
		switch(ortp_event_get_type(ev)){
			case ORTP_EVENT_RTCP_PACKET_RECEIVED:
				parse_rtcp(d->packet);
			break;
			default:
				ms_warning("Unhandled ortp event.");
		}
		ortp_event_destroy(ev);
	}
}
Example #9
0
void video_stream_iterate(VideoStream *stream){
	if (stream->output!=NULL)
		ms_filter_call_method_noarg(stream->output,
			MS_VIDEO_OUT_HANDLE_RESIZING);
	if (stream->evq){
		OrtpEvent *ev=ortp_ev_queue_get(stream->evq);
		if (ev!=NULL){
			if (ortp_event_get_type(ev)==ORTP_EVENT_RTCP_PACKET_RECEIVED){
				OrtpEventData *evd=ortp_event_get_data(ev);
				video_steam_process_rtcp(stream,evd->packet);
			}
			ortp_event_destroy(ev);
		}
	}
}
static void event_queue_cb(MediaStream *ms, void *user_pointer) {
	text_stream_tester_t *tst = (text_stream_tester_t *)user_pointer;
	if (tst->stats.q != NULL) {
		OrtpEvent *ev = NULL;
		while ((ev = ortp_ev_queue_get(tst->stats.q)) != NULL) {
			OrtpEventType evt = ortp_event_get_type(ev);
			OrtpEventData *evd = ortp_event_get_data(ev);
			if (evt == ORTP_EVENT_RTT_CHARACTER_RECEIVED) {
				ms_message("Received RTT char: %lu, %c", (unsigned long)evd->info.received_rtt_character, (char)evd->info.received_rtt_character);
				tst->stats.received_chars[tst->stats.number_of_received_char++] = (char)evd->info.received_rtt_character;
			}
			ortp_event_destroy(ev);
		}
	}
}
void audio_stream_iterate(AudioStream *stream){
	if (stream->ms.evq){
		OrtpEvent *ev=ortp_ev_queue_get(stream->ms.evq);
		if (ev!=NULL){
			OrtpEventType evt=ortp_event_get_type(ev);
			if (evt==ORTP_EVENT_RTCP_PACKET_RECEIVED){
				audio_stream_process_rtcp(stream,ortp_event_get_data(ev)->packet);
				stream->last_packet_time=ms_time(NULL);
			}else if (evt==ORTP_EVENT_RTCP_PACKET_EMITTED){
				ms_message("audio_stream_iterate(): local statistics available\n\tLocal's current jitter buffer size:%f ms",rtp_session_get_jitter_stats(stream->ms.session)->jitter_buffer_size_ms);
			}else if ((evt==ORTP_EVENT_STUN_PACKET_RECEIVED)&&(stream->ms.ice_check_list)){
				ice_handle_stun_packet(stream->ms.ice_check_list,stream->ms.session,ortp_event_get_data(ev));
			}
			ortp_event_destroy(ev);
		}
	}
	media_stream_iterate(&stream->ms);
}
Example #12
0
void video_stream_iterate(VideoStream *stream){
	/*
	if (stream->output!=NULL)
		ms_filter_call_method_noarg(stream->output,
			MS_VIDEO_OUT_HANDLE_RESIZING);
	*/
	if (stream->ms.evq){
		OrtpEvent *ev;
		while (NULL != (ev=ortp_ev_queue_get(stream->ms.evq))) {
			OrtpEventType evt=ortp_event_get_type(ev);
			if (evt == ORTP_EVENT_RTCP_PACKET_RECEIVED){
				OrtpEventData *evd=ortp_event_get_data(ev);
				video_steam_process_rtcp(stream,evd->packet);
			}else if ((evt == ORTP_EVENT_STUN_PACKET_RECEIVED) && (stream->ms.ice_check_list)) {
				ice_handle_stun_packet(stream->ms.ice_check_list,stream->ms.session,ortp_event_get_data(ev));
			}
			ortp_event_destroy(ev);
		}
	}
	media_stream_iterate(&stream->ms);
}
static void event_queue_cb(MediaStream *ms, void *user_pointer) {
	video_stream_tester_stats_t *st = (video_stream_tester_stats_t *)user_pointer;
	OrtpEvent *ev = NULL;

	if (st->q != NULL) {
		while ((ev = ortp_ev_queue_get(st->q)) != NULL) {
			OrtpEventType evt = ortp_event_get_type(ev);
			OrtpEventData *d = ortp_event_get_data(ev);
			if (evt == ORTP_EVENT_RTCP_PACKET_EMITTED) {
				do {
					if (rtcp_is_RR(d->packet)) {
						st->number_of_RR++;
					} else if (rtcp_is_SR(d->packet)) {
						st->number_of_SR++;
					} else if (rtcp_is_SDES(d->packet)) {
						st->number_of_SDES++;
					} else if (rtcp_is_PSFB(d->packet)) {
						switch (rtcp_PSFB_get_type(d->packet)) {
							case RTCP_PSFB_PLI:
								st->number_of_PLI++;
								break;
							case RTCP_PSFB_SLI:
								st->number_of_SLI++;
								break;
							case RTCP_PSFB_RPSI:
								st->number_of_RPSI++;
								break;
							default:
								break;
						}
					}
				} while (rtcp_next_packet(d->packet));
			}
			ortp_event_destroy(ev);
		}
	}
}
Example #14
0
void ortp_ev_queue_flush(OrtpEvQueue * qp){
	OrtpEvent *ev;
	while((ev=ortp_ev_queue_get(qp))!=NULL){
		ortp_event_destroy(ev);
	}
}
Example #15
0
void linphone_call_background_tasks(LinphoneCall *call, bool_t one_second_elapsed){
	int disconnect_timeout = linphone_core_get_nortp_timeout(call->core);
	bool_t disconnected=FALSE;
	
	if (call->state==LinphoneCallStreamsRunning && one_second_elapsed){
		RtpSession *as=NULL,*vs=NULL;
		float audio_load=0, video_load=0;
		if (call->audiostream!=NULL){
			as=call->audiostream->session;
			if (call->audiostream->ticker)
				audio_load=ms_ticker_get_average_load(call->audiostream->ticker);
		}
		if (call->videostream!=NULL){
			if (call->videostream->ticker)
				video_load=ms_ticker_get_average_load(call->videostream->ticker);
			vs=call->videostream->session;
		}
		display_bandwidth(as,vs);
		ms_message("Thread processing load: audio=%f\tvideo=%f",audio_load,video_load);
	}
#ifdef VIDEO_ENABLED
	if (call->videostream!=NULL) {
		// Beware that the application queue should not depend on treatments fron the
		// mediastreamer queue.
		video_stream_iterate(call->videostream);

		if (call->videostream_app_evq){
			OrtpEvent *ev;
			while (NULL != (ev=ortp_ev_queue_get(call->videostream_app_evq))){
				OrtpEventType evt=ortp_event_get_type(ev);
				if (evt == ORTP_EVENT_ZRTP_ENCRYPTION_CHANGED){
					OrtpEventData *evd=ortp_event_get_data(ev);
					linphone_call_videostream_encryption_changed(call, evd->info.zrtp_stream_encrypted);
				}
				ortp_event_destroy(ev);
			}
		}
	}
#endif
	if (call->audiostream!=NULL) {
		// Beware that the application queue should not depend on treatments fron the
		// mediastreamer queue.
		audio_stream_iterate(call->audiostream);

		if (call->audiostream->evq){
			OrtpEvent *ev;
			while (NULL != (ev=ortp_ev_queue_get(call->audiostream_app_evq))){
				OrtpEventType evt=ortp_event_get_type(ev);
				if (evt == ORTP_EVENT_ZRTP_ENCRYPTION_CHANGED){
					OrtpEventData *evd=ortp_event_get_data(ev);
					linphone_call_audiostream_encryption_changed(call, evd->info.zrtp_stream_encrypted);
				} else if (evt == ORTP_EVENT_ZRTP_SAS_READY) {
					OrtpEventData *evd=ortp_event_get_data(ev);
					linphone_call_audiostream_auth_token_ready(call, evd->info.zrtp_sas.sas, evd->info.zrtp_sas.verified);
				}
				ortp_event_destroy(ev);
			}
		}
	}
	if (one_second_elapsed && call->audiostream!=NULL && disconnect_timeout>0 )
		disconnected=!audio_stream_alive(call->audiostream,disconnect_timeout);
	if (disconnected)
		linphone_core_disconnected(call->core,call);
}