From 9b95f24fc31e17cb7e2bbcc8818fd46a61394aed Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Thu, 5 Feb 2015 00:09:46 +0100 Subject: [PATCH] avoid multiple warnings due to ms_is_multicast() not used correctly, make code stream type agnostic --- coreapi/callbacks.c | 5 ++-- coreapi/linphonecall.c | 63 ++++++++++++++++++++++++------------------ coreapi/offeranswer.c | 4 +-- coreapi/private.h | 3 +- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index 85217b576..99e23f777 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -380,8 +380,9 @@ static void try_early_media_forking(LinphoneCall *call, SalMediaDescription *md) RtpSession *session=ms->sessions.rtp_session; const char *rtp_addr=new_stream->rtp_addr[0]!='\0' ? new_stream->rtp_addr : md->addr; const char *rtcp_addr=new_stream->rtcp_addr[0]!='\0' ? new_stream->rtcp_addr : md->addr; - if (ms_is_multicast(new_stream->rtp_addr)) - ms_message("Multicast addr [%s/%i] does not need auxiliary rtp's destination for call [%p]",new_stream->rtp_addr,new_stream->rtp_port,call); + if (ms_is_multicast(rtp_addr)) + ms_message("Multicast addr [%s/%i] does not need auxiliary rtp's destination for call [%p]", + rtp_addr,new_stream->rtp_port,call); else rtp_session_add_aux_remote_addr_full(session,rtp_addr,new_stream->rtp_port,rtcp_addr,new_stream->rtcp_port); } diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 8491c7b12..713dd9f44 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -538,6 +538,14 @@ static void transfer_already_assigned_payload_types(SalMediaDescription *old, Sa } } +static const char *linphone_call_get_bind_ip_for_stream(LinphoneCall *call, int stream_index){ + const char *bind_ip=call->af==AF_INET6 ? "::0" : "0.0.0.0"; + + if (stream_index<2 && call->media_ports[stream_index].multicast_ip[0]!='\0') + bind_ip=call->media_ports[stream_index].multicast_ip; + return bind_ip; +} + void linphone_call_make_local_media_description(LinphoneCore *lc, LinphoneCall *call){ MSList *l; SalMediaDescription *old_md=call->localdesc; @@ -783,9 +791,7 @@ static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, linphone_call_init_stats(&call->stats[LINPHONE_CALL_STATS_AUDIO], LINPHONE_CALL_STATS_AUDIO); linphone_call_init_stats(&call->stats[LINPHONE_CALL_STATS_VIDEO], LINPHONE_CALL_STATS_VIDEO); - /*by default local_audio_ip=local_video_ip=local_ip*/ - strncpy(call->local_audio_ip,call->localip,sizeof(call->local_audio_ip)); - strncpy(call->local_video_ip,call->localip,sizeof(call->local_video_ip)); + #ifdef ANDROID ms_message("Call [%p] acquires both wifi and multicast lock",call); linphone_core_wifi_lock_acquire(call->core); @@ -945,6 +951,7 @@ static void linphone_call_incoming_select_ip_version(LinphoneCall *call){ * Fix call parameters on incoming call to eg. enable AVPF if the incoming call propose it and it is not enabled locally. */ void linphone_call_set_compatible_incoming_call_parameters(LinphoneCall *call, const SalMediaDescription *md) { + int i; call->params->has_video &= linphone_core_media_description_contains_video_stream(md); /* Handle AVPF, SRTP and DTLS. */ @@ -963,18 +970,14 @@ void linphone_call_set_compatible_incoming_call_parameters(LinphoneCall *call, c call->params->media_encryption = LinphoneMediaEncryptionSRTP; } - //set both local audio & video - if (ms_is_multicast(md->streams[0].rtp_addr)) { - strncpy(call->local_audio_ip,md->streams[0].rtp_addr,sizeof(call->local_audio_ip)); - ms_message("Disabling audio rtcp on call [%p] because of multicast",call); - call->media_ports[0].rtp_port=md->streams[0].rtp_port; - call->media_ports[0].rtcp_port=0; - } - if (ms_is_multicast(md->streams[1].rtp_addr)) { - strncpy(call->local_video_ip,md->streams[1].rtp_addr,sizeof(call->local_video_ip)); - call->media_ports[1].rtp_port=md->streams[1].rtp_port; - call->media_ports[1].rtcp_port=0; - ms_message("Disabling video rtcp on call [%p] because of multicast",call); + /* set both local audio & video multicast ip address if any*/ + for (i=0;i<2;++i){ + if (md->streams[i].rtp_addr[i]!='\0' && ms_is_multicast(md->streams[i].rtp_addr)) { + strncpy(call->media_ports[i].multicast_ip,md->streams[i].rtp_addr,sizeof(call->media_ports[i].multicast_ip)); + ms_message("Disabling rtcp on call [%p], stream [%i] because of multicast",call,i); + call->media_ports[i].rtp_port=md->streams[i].rtp_port; + call->media_ports[i].rtcp_port=0; + } } } @@ -1806,6 +1809,8 @@ int linphone_call_prepare_ice(LinphoneCall *call, bool_t incoming_offer){ return 0; } + + void linphone_call_init_audio_stream(LinphoneCall *call){ LinphoneCore *lc=call->core; AudioStream *audiostream; @@ -1818,7 +1823,8 @@ void linphone_call_init_audio_stream(LinphoneCall *call){ if (call->audiostream != NULL) return; if (call->sessions[0].rtp_session==NULL){ - call->audiostream=audiostream=audio_stream_new2(call->local_audio_ip,call->media_ports[0].rtp_port,call->media_ports[0].rtcp_port); + call->audiostream=audiostream=audio_stream_new2(linphone_call_get_bind_ip_for_stream(call,0), + call->media_ports[0].rtp_port, call->media_ports[0].rtcp_port); cname = linphone_address_as_string_uri_only(call->me); audio_stream_set_rtcp_information(call->audiostream, cname, rtcp_tool); ms_free(cname); @@ -1923,7 +1929,8 @@ void linphone_call_init_video_stream(LinphoneCall *call){ const char *display_filter=linphone_core_get_video_display_filter(lc); if (call->sessions[1].rtp_session==NULL){ - call->videostream=video_stream_new2(call->local_video_ip,call->media_ports[1].rtp_port,call->media_ports[1].rtcp_port); + call->videostream=video_stream_new2(linphone_call_get_bind_ip_for_stream(call,1), + call->media_ports[1].rtp_port,call->media_ports[1].rtcp_port); cname = linphone_address_as_string_uri_only(call->me); video_stream_set_rtcp_information(call->videostream, cname, rtcp_tool); ms_free(cname); @@ -2289,13 +2296,15 @@ static void linphone_call_start_audio_stream(LinphoneCall *call, bool_t muted, b stream = sal_media_description_find_best_stream(call->resultdesc, SalAudio); if (stream && stream->dir!=SalStreamInactive && stream->rtp_port!=0){ + const char *rtp_addr=stream->rtp_addr[0]!='\0' ? stream->rtp_addr : call->resultdesc->addr; + bool_t is_multicast=ms_is_multicast(rtp_addr); playcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard; captcard=lc->sound_conf.capt_sndcard; playfile=lc->play_file; recfile=lc->rec_file; call->audio_profile=make_profile(call,call->resultdesc,stream,&used_pt); - + if (used_pt!=-1){ call->current_params->audio_codec = rtp_profile_get_payload(call->audio_profile, used_pt); if (playcard==NULL) { @@ -2308,7 +2317,7 @@ static void linphone_call_start_audio_stream(LinphoneCall *call, bool_t muted, b when placed in recvonly or sendonly mode*/ if (stream->rtp_port==0 || stream->dir==SalStreamRecvOnly - || (stream->multicast_role == SalMulticastRoleReceiver && ms_is_multicast(stream->rtp_addr))){ + || (stream->multicast_role == SalMulticastRoleReceiver && is_multicast)){ captcard=NULL; playfile=NULL; }else if (stream->dir==SalStreamSendOnly){ @@ -2364,16 +2373,16 @@ static void linphone_call_start_audio_stream(LinphoneCall *call, bool_t muted, b } } configure_rtp_session_for_rtcp_xr(lc, call, SalAudio); - if (ms_is_multicast(stream->rtp_addr)) + if (is_multicast) rtp_session_set_multicast_ttl(call->audiostream->ms.sessions.rtp_session,stream->ttl); - + audio_stream_start_full( call->audiostream, call->audio_profile, - stream->rtp_addr[0]!='\0' ? stream->rtp_addr : call->resultdesc->addr, + rtp_addr, stream->rtp_port, stream->rtcp_addr[0]!='\0' ? stream->rtcp_addr : call->resultdesc->addr, - (linphone_core_rtcp_enabled(lc) && !ms_is_multicast(stream->rtp_addr)) ? (stream->rtcp_port ? stream->rtcp_port : stream->rtp_port+1) : 0, + (linphone_core_rtcp_enabled(lc) && !is_multicast) ? (stream->rtcp_port ? stream->rtcp_port : stream->rtp_port+1) : 0, used_pt, linphone_core_get_audio_jittcomp(lc), playfile, @@ -2425,7 +2434,7 @@ static void linphone_call_start_video_stream(LinphoneCall *call, bool_t all_inpu const char *rtp_addr=vstream->rtp_addr[0]!='\0' ? vstream->rtp_addr : call->resultdesc->addr; const char *rtcp_addr=vstream->rtcp_addr[0]!='\0' ? vstream->rtcp_addr : call->resultdesc->addr; const SalStreamDescription *local_st_desc=sal_media_description_find_stream(call->localdesc,vstream->proto,SalVideo); - + bool_t is_multicast=ms_is_multicast(rtp_addr); call->video_profile=make_profile(call,call->resultdesc,vstream,&used_pt); if (used_pt!=-1){ @@ -2454,7 +2463,7 @@ static void linphone_call_start_video_stream(LinphoneCall *call, bool_t all_inpu video_stream_set_native_preview_window_id (call->videostream,lc->preview_window_id); video_stream_use_preview_video_window (call->videostream,lc->use_preview_window); - if (ms_is_multicast(vstream->rtp_addr)){ + if (is_multicast){ if (vstream->multicast_role == SalMulticastRoleReceiver) dir=VideoStreamRecvOnly; else @@ -2497,7 +2506,7 @@ static void linphone_call_start_video_stream(LinphoneCall *call, bool_t all_inpu ms_message("%s lc rotation:%d\n", __FUNCTION__, lc->device_rotation); video_stream_set_device_rotation(call->videostream, lc->device_rotation); video_stream_set_freeze_on_error(call->videostream, lp_config_get_int(lc->config, "video", "freeze_on_error", 0)); - if (ms_is_multicast(vstream->rtp_addr)) + if (is_multicast) rtp_session_set_multicast_ttl(call->videostream->ms.sessions.rtp_session,vstream->ttl); if( lc->video_conf.reuse_preview_source && source ){ @@ -2512,7 +2521,7 @@ static void linphone_call_start_video_stream(LinphoneCall *call, bool_t all_inpu video_stream_start(call->videostream, call->video_profile, rtp_addr, vstream->rtp_port, rtcp_addr, - (linphone_core_rtcp_enabled(lc) && !ms_is_multicast(vstream->rtp_addr)) ? (vstream->rtcp_port ? vstream->rtcp_port : vstream->rtp_port+1) : 0, + (linphone_core_rtcp_enabled(lc) && !is_multicast) ? (vstream->rtcp_port ? vstream->rtcp_port : vstream->rtp_port+1) : 0, used_pt, linphone_core_get_video_jittcomp(lc), cam); } } diff --git a/coreapi/offeranswer.c b/coreapi/offeranswer.c index 4c7147db4..b3fde6b3c 100644 --- a/coreapi/offeranswer.c +++ b/coreapi/offeranswer.c @@ -307,7 +307,7 @@ static void initiate_outgoing(const SalStreamDescription *local_offer, result->proto=remote_answer->proto; result->type=local_offer->type; - if (ms_is_multicast(local_offer->rtp_addr)) { + if (local_offer->rtp_addr[0]!='\0' && ms_is_multicast(local_offer->rtp_addr)) { /*6.2 Multicast Streams ... If a multicast stream is accepted, the address and port information @@ -408,7 +408,7 @@ static void initiate_incoming(const SalStreamDescription *local_cap, result->rtp_port=0; return; } - if (ms_is_multicast(remote_offer->rtp_addr)) { + if (remote_offer->rtp_addr[0]!='\0' && ms_is_multicast(remote_offer->rtp_addr)) { if (sal_stream_description_has_srtp(result) == TRUE) { ms_message("SAVP not supported for multicast address for remote stream [%p]",remote_offer); result->rtp_port=0; diff --git a/coreapi/private.h b/coreapi/private.h index f5b378008..9abdd9ee6 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -202,6 +202,7 @@ typedef struct StunCandidate{ typedef struct _PortConfig{ + char multicast_ip[LINPHONE_IPADDR_SIZE]; int rtp_port; int rtcp_port; }PortConfig; @@ -223,8 +224,6 @@ struct _LinphoneCall{ SalOp *op; SalOp *ping_op; char localip[LINPHONE_IPADDR_SIZE]; /* our best guess for local ipaddress for this call */ - char local_audio_ip[LINPHONE_IPADDR_SIZE]; /* our best guess for local ipaddress for this call or what proposed in sdp in case of multicast*/ - char local_video_ip[LINPHONE_IPADDR_SIZE]; /* our best guess for local ipaddress for this call or what proposed in sdp in case of multicast*/ LinphoneCallState state; LinphoneCallState prevstate; LinphoneCallState transfer_state; /*idle if no transfer*/