>From 97e92bd397b9a35f73b000368774968e89edf431 Mon Sep 17 00:00:00 2001 From: Pedro Sanchez Date: Fri, 11 Feb 2011 15:02:13 -0500 Subject: [PATCH] Make RTP traffic timer start when SIP negotiation starts. --- mediastreamer2/src/audiostream.c | 54 +++++++++++++++++++++---------------- 1 files changed, 31 insertions(+), 23 deletions(-) diff --git a/mediastreamer2/src/audiostream.c b/mediastreamer2/src/audiostream.c index 5ca1c9e..a2123b0 100644 --- a/mediastreamer2/src/audiostream.c +++ b/mediastreamer2/src/audiostream.c @@ -144,27 +144,30 @@ ms_time (time_t *t) } #endif +static void _reset_rtp_alive_info(AudioStream * stream){ + stream->last_packet_count=0; + stream->last_packet_time=time(NULL); +} + 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->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; - } + } + 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; @@ -206,6 +209,7 @@ static void payload_type_changed(RtpSession *session, unsigned long data){ AudioStream *stream=(AudioStream*)data; int pt=rtp_session_get_recv_payload_type(stream->session); audio_stream_change_decoder(stream,pt); + _reset_rtp_alive_info(stream); } int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char *remip,int remport, @@ -379,6 +383,9 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char ms_ticker_attach(stream->ticker,stream->soundread); ms_ticker_attach(stream->ticker,stream->rtprecv); + _reset_rtp_alive_info(stream); + + return 0; } @@ -463,6 +470,7 @@ AudioStream *audio_stream_new(int locport, bool_t ipv6){ stream->use_gc=FALSE; stream->use_agc=FALSE; stream->use_ng=FALSE; + _reset_rtp_alive_info(stream); ms_filter_enable_statistics(TRUE); ms_filter_reset_statistics(); return stream; @@ -586,7 +594,7 @@ void audio_stream_stop(AudioStream * stream) } RingStream * ring_start(const char *file, int interval, MSSndCard *sndcard){ - return ring_start_with_cb(file,interval,sndcard,NULL,NULL); + return ring_start_with_cb(file,interval,sndcard,NULL,NULL); } RingStream * ring_start_with_cb(const char *file,int interval,MSSndCard *sndcard, MSFilterNotifyFunc func,void * user_data) @@ -687,10 +695,10 @@ void audio_stream_get_local_rtp_stats(AudioStream *stream, rtp_stats_t *lstats){ void audio_stream_mute_rtp(AudioStream *stream, bool_t val) { - if (stream->rtpsend){ - if (val) - ms_filter_call_method(stream->rtpsend,MS_RTP_SEND_MUTE_MIC,&val); - else - ms_filter_call_method(stream->rtpsend,MS_RTP_SEND_UNMUTE_MIC,&val); - } + if (stream->rtpsend){ + if (val) + ms_filter_call_method(stream->rtpsend,MS_RTP_SEND_MUTE_MIC,&val); + else + ms_filter_call_method(stream->rtpsend,MS_RTP_SEND_UNMUTE_MIC,&val); + } } -- 1.7.0.4