Commit 2ef1e7c9 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Gather ICE candidates on incoming call.

parent 3020133c
......@@ -342,7 +342,10 @@ LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddr
linphone_core_get_local_ip(lc,linphone_address_get_domain(to),call->localip);
linphone_call_init_common(call,from,to);
call->params=*params;
if (linphone_core_get_firewall_policy(call->core) == LinphonePolicyUseIce) call->ice_session=ice_session_new();
if (linphone_core_get_firewall_policy(call->core) == LinphonePolicyUseIce) {
call->ice_session=ice_session_new();
ice_session_set_role(call->ice_session, IR_Controlling);
}
call->localdesc=create_local_media_description (lc,call);
call->camera_active=params->has_video;
switch (linphone_core_get_firewall_policy(call->core)) {
......@@ -388,11 +391,20 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro
linphone_call_init_common(call, from, to);
linphone_core_init_default_params(lc, &call->params);
call->params.has_video &= !!lc->video_policy.automatically_accept;
if (((SalOpBase *)op)->remote_media->streams[0].ice_check_list != NULL) call->ice_session=((SalOpBase *)op)->remote_media->streams[0].ice_check_list->session;
if (sal_call_get_remote_media_description(call->op)->streams[0].ice_check_list != NULL)
call->ice_session=sal_call_get_remote_media_description(call->op)->streams[0].ice_check_list->session;
call->localdesc=create_local_media_description (lc,call);
call->camera_active=call->params.has_video;
if (linphone_core_get_firewall_policy(call->core)==LinphonePolicyUseStun)
linphone_core_run_stun_tests(call->core,call);
switch (linphone_core_get_firewall_policy(call->core)) {
case LinphonePolicyUseStun:
linphone_core_run_stun_tests(call->core,call);
break;
case LinphonePolicyUseIce:
linphone_core_gather_ice_candidates(call->core, call);
break;
default:
break;
}
discover_mtu(lc,linphone_address_get_domain(from));
return call;
}
......
......@@ -574,6 +574,8 @@ void linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call)
bool_t video_responses[2];
IceCandidate *audio_ice_bases[2];
IceCandidate *video_ice_bases[2];
IceCheckList *audio_check_list;
IceCheckList *video_check_list;
struct sockaddr_storage ss;
socklen_t ss_len;
struct timeval init, cur;
......@@ -598,6 +600,14 @@ void linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call)
video_responses[0] = video_responses[1] = FALSE;
audio_ice_bases[0] = audio_ice_bases[1] = NULL;
video_ice_bases[0] = video_ice_bases[1] = NULL;
if (call->dir == LinphoneCallOutgoing) {
audio_check_list = call->localdesc->streams[0].ice_check_list;
video_check_list = call->localdesc->streams[1].ice_check_list;
} else {
SalMediaDescription *md = sal_call_get_remote_media_description(call->op);
audio_check_list = md->streams[0].ice_check_list;
video_check_list = md->streams[1].ice_check_list;
}
audio_socks[0] = create_socket(call->audio_port);
if (audio_socks[0] == -1) return;
audio_socks[1] = create_socket(call->audio_port + 1);
......@@ -614,16 +624,11 @@ void linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call)
ms_error("Fail to get local ip");
return;
}
if (call->dir == LinphoneCallOutgoing) {
ice_session_set_role(call->ice_session, IR_Controlling);
} else {
ice_session_set_role(call->ice_session, IR_Controlled);
}
audio_ice_bases[0] = ice_add_local_candidate(call->localdesc->streams[0].ice_check_list, "host", local_addr, call->audio_port, 1, NULL);
audio_ice_bases[1] = ice_add_local_candidate(call->localdesc->streams[0].ice_check_list, "host", local_addr, call->audio_port + 1, 2, NULL);
audio_ice_bases[0] = ice_add_local_candidate(audio_check_list, "host", local_addr, call->audio_port, 1, NULL);
audio_ice_bases[1] = ice_add_local_candidate(audio_check_list, "host", local_addr, call->audio_port + 1, 2, NULL);
if (call->params.has_video) {
video_ice_bases[0] = ice_add_local_candidate(call->localdesc->streams[1].ice_check_list, "host", local_addr, call->video_port, 1, NULL);
video_ice_bases[1] = ice_add_local_candidate(call->localdesc->streams[1].ice_check_list, "host", local_addr, call->video_port + 1, 2, NULL);
video_ice_bases[0] = ice_add_local_candidate(video_check_list, "host", local_addr, call->video_port, 1, NULL);
video_ice_bases[1] = ice_add_local_candidate(video_check_list, "host", local_addr, call->video_port + 1, 2, NULL);
}
gettimeofday(&init, NULL);
......@@ -644,20 +649,20 @@ void linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call)
#endif
if (recvStunResponse(audio_socks[0], addr, &port, &id) > 0) {
ice_add_local_candidate(call->localdesc->streams[0].ice_check_list, "srflx", addr, port, 1, audio_ice_bases[0]);
ice_add_local_candidate(audio_check_list, "srflx", addr, port, 1, audio_ice_bases[0]);
audio_responses[0] = TRUE;
}
if (recvStunResponse(audio_socks[1], addr, &port, &id) > 0) {
ice_add_local_candidate(call->localdesc->streams[0].ice_check_list, "srflx", addr, port, 2, audio_ice_bases[1]);
ice_add_local_candidate(audio_check_list, "srflx", addr, port, 2, audio_ice_bases[1]);
audio_responses[1] = TRUE;
}
if (call->params.has_video) {
if (recvStunResponse(video_socks[0], addr, &port, &id) > 0) {
ice_add_local_candidate(call->localdesc->streams[1].ice_check_list, "srflx", addr, port, 1, video_ice_bases[0]);
ice_add_local_candidate(video_check_list, "srflx", addr, port, 1, video_ice_bases[0]);
video_responses[0] = TRUE;
}
if (recvStunResponse(video_socks[1], addr, &port, &id) > 0) {
ice_add_local_candidate(call->localdesc->streams[1].ice_check_list, "srflx", addr, port, 2, video_ice_bases[1]);
ice_add_local_candidate(video_check_list, "srflx", addr, port, 2, video_ice_bases[1]);
video_responses[1] = TRUE;
}
}
......@@ -677,11 +682,11 @@ void linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call)
close_socket(audio_socks[0]);
close_socket(audio_socks[1]);
ice_dump_candidates(call->localdesc->streams[0].ice_check_list);
ice_dump_candidates(audio_check_list);
if (call->params.has_video) {
if (video_socks[0] != -1) close_socket(video_socks[0]);
if (video_socks[1] != -1) close_socket(video_socks[1]);
ice_dump_candidates(call->localdesc->streams[1].ice_check_list);
ice_dump_candidates(video_check_list);
}
}
......
......@@ -394,6 +394,7 @@ int sdp_to_media_description(sdp_message_t *msg, SalMediaDescription *desc){
sdp_bandwidth_t *sbw=NULL;
sdp_attribute_t *attr;
int media_attribute_nb;
bool_t ice_lite = FALSE;
addr=sdp_message_c_addr_get (msg, -1, 0);
if (addr)
......@@ -543,11 +544,20 @@ int sdp_to_media_description(sdp_message_t *msg, SalMediaDescription *desc){
ice_ufrag = attr->a_att_value;
} else if ((keywordcmp("ice-pwd", attr->a_att_field) == 0) && (attr->a_att_value != NULL)) {
ice_pwd = attr->a_att_value;
} else if (keywordcmp("ice-lite", attr->a_att_field) == 0) {
ice_lite = TRUE;
}
}
if ((ice_session != NULL) && (ice_ufrag != NULL) && (ice_pwd != NULL)) {
ice_session_set_remote_credentials(ice_session, ice_ufrag, ice_pwd);
ice_dump_session(ice_session);
if (ice_session != NULL) {
if (ice_lite == TRUE) {
ice_session_set_role(ice_session, IR_Controlling);
} else {
ice_session_set_role(ice_session, IR_Controlled);
}
if ((ice_ufrag != NULL) && (ice_pwd != NULL)) {
ice_session_set_remote_credentials(ice_session, ice_ufrag, ice_pwd);
ice_dump_session(ice_session);
}
}
desc->nstreams=i;
return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment