From 1cf049cabdea59c22b8ddbdbb53d7c3dbaea8687 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Fri, 12 Dec 2014 16:29:54 +0100 Subject: [PATCH] fix leak of RtpTransport when call is updated/paused. Fix reporting of bandwidth, which was displayed even if the stream was inactive. --- coreapi/linphonecall.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 9cf05f1a2..a1c3ad003 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -1550,6 +1550,8 @@ void linphone_call_init_audio_stream(LinphoneCall *call){ AudioStream *audiostream; const char *location; int dscp; + RtpTransport *meta_rtp=NULL; + RtpTransport *meta_rtcp=NULL; if (call->audiostream != NULL) return; if (call->sessions[0].rtp_session==NULL){ @@ -1600,12 +1602,11 @@ void linphone_call_init_audio_stream(LinphoneCall *call){ } audio_stream_set_features(audiostream,linphone_core_get_audio_features(lc)); - - if (lc->rtptf){ + rtp_session_get_transports(audiostream->ms.sessions.rtp_session,&meta_rtp,&meta_rtcp); + if (lc->rtptf && (meta_rtp==NULL && meta_rtcp==NULL)){ + /*the transport just need to be created once, then they are kept into the RtpSession, which is the same for the entire call duration.*/ RtpTransport *artp=lc->rtptf->audio_rtp_func(lc->rtptf->audio_rtp_func_data, call->media_ports[0].rtp_port); RtpTransport *artcp=lc->rtptf->audio_rtcp_func(lc->rtptf->audio_rtcp_func_data, call->media_ports[0].rtcp_port); - RtpTransport *meta_rtp; - RtpTransport *meta_rtcp; meta_rtp_transport_new(&meta_rtp,TRUE,artp, 0); meta_rtp_transport_new(&meta_rtcp,FALSE,artcp, 0); rtp_session_set_transports(audiostream->ms.sessions.rtp_session,meta_rtp,meta_rtcp); @@ -2781,14 +2782,17 @@ void linphone_call_stop_recording(LinphoneCall *call){ **/ static void report_bandwidth(LinphoneCall *call, MediaStream *as, MediaStream *vs){ - call->stats[LINPHONE_CALL_STATS_AUDIO].download_bandwidth=(as!=NULL) ? (media_stream_get_down_bw(as)*1e-3) : 0; - call->stats[LINPHONE_CALL_STATS_AUDIO].upload_bandwidth=(as!=NULL) ? (media_stream_get_up_bw(as)*1e-3) : 0; - call->stats[LINPHONE_CALL_STATS_VIDEO].download_bandwidth=(vs!=NULL) ? (media_stream_get_down_bw(vs)*1e-3) : 0; - call->stats[LINPHONE_CALL_STATS_VIDEO].upload_bandwidth=(vs!=NULL) ? (media_stream_get_up_bw(vs)*1e-3) : 0; - call->stats[LINPHONE_CALL_STATS_AUDIO].rtcp_download_bandwidth=(as!=NULL) ? (media_stream_get_rtcp_down_bw(as)*1e-3) : 0; - call->stats[LINPHONE_CALL_STATS_AUDIO].rtcp_upload_bandwidth=(as!=NULL) ? (media_stream_get_rtcp_up_bw(as)*1e-3) : 0; - call->stats[LINPHONE_CALL_STATS_VIDEO].rtcp_download_bandwidth=(vs!=NULL) ? (media_stream_get_rtcp_down_bw(vs)*1e-3) : 0; - call->stats[LINPHONE_CALL_STATS_VIDEO].rtcp_upload_bandwidth=(vs!=NULL) ? (media_stream_get_rtcp_up_bw(vs)*1e-3) : 0; + bool_t as_active = as ? (media_stream_get_state(as) == MSStreamStarted) : FALSE; + bool_t vs_active = vs ? (media_stream_get_state(vs) == MSStreamStarted) : FALSE; + + call->stats[LINPHONE_CALL_STATS_AUDIO].download_bandwidth=(as_active) ? (media_stream_get_down_bw(as)*1e-3) : 0; + call->stats[LINPHONE_CALL_STATS_AUDIO].upload_bandwidth=(as_active) ? (media_stream_get_up_bw(as)*1e-3) : 0; + call->stats[LINPHONE_CALL_STATS_VIDEO].download_bandwidth=(vs_active) ? (media_stream_get_down_bw(vs)*1e-3) : 0; + call->stats[LINPHONE_CALL_STATS_VIDEO].upload_bandwidth=(vs_active) ? (media_stream_get_up_bw(vs)*1e-3) : 0; + call->stats[LINPHONE_CALL_STATS_AUDIO].rtcp_download_bandwidth=(as_active) ? (media_stream_get_rtcp_down_bw(as)*1e-3) : 0; + call->stats[LINPHONE_CALL_STATS_AUDIO].rtcp_upload_bandwidth=as_active) ? (media_stream_get_rtcp_up_bw(as)*1e-3) : 0; + call->stats[LINPHONE_CALL_STATS_VIDEO].rtcp_download_bandwidth=(vs_active) ? (media_stream_get_rtcp_down_bw(vs)*1e-3) : 0; + call->stats[LINPHONE_CALL_STATS_VIDEO].rtcp_upload_bandwidth=(vs_active) ? (media_stream_get_rtcp_up_bw(vs)*1e-3) : 0; ms_message("Bandwidth usage for call [%p]: audio[ rtp]=[d=%.1f,u=%.1f], video[ rtp]=[d=%.1f,u=%.1f] kbit/sec", call,