From 405ca6abbdbda30457aa7890c3c81f295753b0f9 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 17 Sep 2015 11:35:57 +0200 Subject: [PATCH] Fix stream indexes computed too late --- .gitignore | 2 ++ coreapi/linphonecall.c | 46 ++++++++++++++++++++++++------------------ coreapi/misc.c | 8 ++++++++ coreapi/offeranswer.c | 2 +- coreapi/private.h | 2 ++ coreapi/sal.c | 7 ++++--- 6 files changed, 43 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 36ee91daf..77767ee34 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,8 @@ coreapi/help/chatroom coreapi/help/doc/ coreapi/help/helloworld coreapi/help/registration +coreapi/help/realtimetext_receiver +coreapi/help/realtimetext_sender coreapi/test_ecc coreapi/test_lsd gtk/version_date.h diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 82e71db9e..eccae3c86 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -750,8 +750,8 @@ void linphone_call_make_local_media_description(LinphoneCall *call) { /* Deactivate inactive streams. */ for (i = 0; i < SAL_MEDIA_DESCRIPTION_MAX_STREAMS; i++) { - if (md->streams[i].dir == SalStreamInactive) { - md->streams[i].rtp_port = 0; + if (md->streams[i].rtp_port == 0) { + md->streams[i].dir = SalStreamInactive; md->streams[i].rtcp_port = 0; if (call->biggestdesc && i < call->biggestdesc->nb_streams) { md->streams[i].proto = call->biggestdesc->streams[i].proto; @@ -1022,7 +1022,7 @@ LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddr call->main_audio_stream_index = LINPHONE_CALL_STATS_AUDIO; call->main_video_stream_index = LINPHONE_CALL_STATS_VIDEO; - call->main_text_stream_index = params->realtimetext_enabled ? LINPHONE_CALL_STATS_TEXT : -1; + call->main_text_stream_index = params->realtimetext_enabled ? LINPHONE_CALL_STATS_TEXT : STREAM_INDEX_UNKNOWN; call->dir=LinphoneCallOutgoing; call->core=lc; @@ -1088,15 +1088,32 @@ void linphone_call_set_compatible_incoming_call_parameters(LinphoneCall *call, c } +static void linphone_call_compute_streams_indexes(LinphoneCall *call, SalMediaDescription *md) { + int i; + for (i = 0; i < SAL_MEDIA_DESCRIPTION_MAX_STREAMS; i++) { + if (!sal_stream_description_active(&md->streams[i])) continue; + if (md->streams[i].type == SalAudio && call->main_audio_stream_index == STREAM_INDEX_UNKNOWN) { + call->main_audio_stream_index = i; + ms_message("audio stream index updated: %i", i); + } else if (md->streams[i].type == SalVideo && call->main_video_stream_index == STREAM_INDEX_UNKNOWN) { + call->main_video_stream_index = i; + ms_message("video stream index updated: %i", i); + } else if (md->streams[i].type == SalText && call->main_text_stream_index == STREAM_INDEX_UNKNOWN) { + call->main_text_stream_index = i; + ms_message("text stream index updated: %i", i); + } + } +} + LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){ LinphoneCall *call = belle_sip_object_new(LinphoneCall); SalMediaDescription *md; LinphoneFirewallPolicy fpol; int i; - call->main_audio_stream_index = -1; - call->main_video_stream_index = -1; - call->main_text_stream_index = -1; + call->main_audio_stream_index = STREAM_INDEX_UNKNOWN; + call->main_video_stream_index = STREAM_INDEX_UNKNOWN; + call->main_text_stream_index = STREAM_INDEX_UNKNOWN; call->dir=LinphoneCallIncoming; sal_op_set_user_pointer(op,call); @@ -1106,6 +1123,9 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro linphone_call_incoming_select_ip_version(call); sal_op_cnx_ip_to_0000_if_sendonly_enable(op,lp_config_get_default_int(lc->config,"sip","cnx_ip_to_0000_if_sendonly_enabled",0)); + + md = sal_call_get_remote_media_description(op); + linphone_call_compute_streams_indexes(call, md); if (lc->sip_conf.ping_with_options){ #ifdef BUILD_UPNP @@ -1142,7 +1162,6 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro /*set privacy*/ call->current_params->privacy=(LinphonePrivacyMask)sal_op_get_privacy(call->op); /*set video support */ - md=sal_call_get_remote_media_description(op); call->params->has_video = linphone_core_video_enabled(lc) && lc->video_policy.automatically_accept; if (md) { // It is licit to receive an INVITE without SDP @@ -1159,19 +1178,6 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro md->streams[i].multicast_role = SalMulticastReceiver; strncpy(call->media_ports[i].multicast_ip,md->streams[i].rtp_addr,sizeof(call->media_ports[i].multicast_ip)); } - - if (sal_stream_description_active(&md->streams[i])) { - if (md->streams[i].type == SalAudio) { - call->main_audio_stream_index = i; - ms_message("audio stream index updated: %i", i); - } else if (md->streams[i].type == SalVideo) { - call->main_video_stream_index = i; - ms_message("video stream index updated: %i", i); - } else if (md->streams[i].type == SalText) { - call->main_text_stream_index = i; - ms_message("text stream index updated: %i", i); - } - } } } } diff --git a/coreapi/misc.c b/coreapi/misc.c index 6cad3002b..6ee4ab77e 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -627,11 +627,13 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call) const struct addrinfo *ai; IceCheckList *audio_check_list; IceCheckList *video_check_list; + IceCheckList *text_check_list; const char *server = linphone_core_get_stun_server(lc); if ((server == NULL) || (call->ice_session == NULL)) return -1; audio_check_list = ice_session_check_list(call->ice_session, 0); video_check_list = ice_session_check_list(call->ice_session, 1); + text_check_list = ice_session_check_list(call->ice_session, 2); if (audio_check_list == NULL) return -1; if (call->af==AF_INET6){ @@ -661,6 +663,12 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call) ice_add_local_candidate(video_check_list, "host", local_addr, call->media_ports[call->main_video_stream_index].rtcp_port, 2, NULL); call->stats[LINPHONE_CALL_STATS_VIDEO].ice_state = LinphoneIceStateInProgress; } + if (call->params->realtimetext_enabled && (text_check_list != NULL) + && (ice_check_list_state(text_check_list) != ICL_Completed) && (ice_check_list_candidates_gathered(text_check_list) == FALSE)) { + ice_add_local_candidate(text_check_list, "host", local_addr, call->media_ports[call->main_text_stream_index].rtp_port, 1, NULL); + ice_add_local_candidate(text_check_list, "host", local_addr, call->media_ports[call->main_text_stream_index].rtcp_port, 2, NULL); + call->stats[LINPHONE_CALL_STATS_TEXT].ice_state = LinphoneIceStateInProgress; + } ms_message("ICE: gathering candidate from [%s]",server); /* Gather local srflx candidates. */ diff --git a/coreapi/offeranswer.c b/coreapi/offeranswer.c index f36f002a7..36adfbbc1 100644 --- a/coreapi/offeranswer.c +++ b/coreapi/offeranswer.c @@ -544,7 +544,7 @@ static bool_t proto_compatible(SalMediaProto local, SalMediaProto remote) { } static const SalStreamDescription *find_local_matching_stream(const SalMediaDescription *result, const SalMediaDescription *local_capabilities, const SalStreamDescription *remote_stream){ - int i; + int i; for(i=0;istreams[i]; if (!sal_stream_description_active(ss)) continue; diff --git a/coreapi/private.h b/coreapi/private.h index ee2f2b8e1..db684e281 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -240,6 +240,8 @@ typedef struct _PortConfig{ int rtcp_port; }PortConfig; +#define STREAM_INDEX_UNKNOWN -1 + struct _LinphoneCall{ belle_sip_object_t base; void *user_data; diff --git a/coreapi/sal.c b/coreapi/sal.c index 78d1af051..b164b2b48 100644 --- a/coreapi/sal.c +++ b/coreapi/sal.c @@ -57,8 +57,10 @@ SalMediaDescription *sal_media_description_new(){ SalMediaDescription *md=ms_new0(SalMediaDescription,1); int i; md->refcount=1; - for(i=0;istreams[i].dir=SalStreamInactive; + md->streams[i].rtp_port = 0; + md->streams[i].rtcp_port = 0; } return md; } @@ -86,8 +88,7 @@ void sal_media_description_unref(SalMediaDescription *md){ } } -SalStreamDescription *sal_media_description_find_stream(SalMediaDescription *md, - SalMediaProto proto, SalStreamType type){ +SalStreamDescription *sal_media_description_find_stream(SalMediaDescription *md, SalMediaProto proto, SalStreamType type){ int i; for(i=0;istreams[i];