Commit 85ad456a authored by Ghislain MARY's avatar Ghislain MARY

Prevent deleting streams (and therefore RTP sessions) when switching form ICE...

Prevent deleting streams (and therefore RTP sessions) when switching form ICE gathering to the call.

This prevents losing the first ICE connectivity checks if the restart of
the streams is slow.
parent e0f19725
...@@ -413,6 +413,7 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro ...@@ -413,6 +413,7 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro
linphone_call_init_common(call, from, to); linphone_call_init_common(call, from, to);
linphone_core_init_default_params(lc, &call->params); linphone_core_init_default_params(lc, &call->params);
call->params.has_video &= !!lc->video_policy.automatically_accept; call->params.has_video &= !!lc->video_policy.automatically_accept;
call->params.has_video &= linphone_core_media_description_contains_video_stream(sal_call_get_remote_media_description(op));
switch (linphone_core_get_firewall_policy(call->core)) { switch (linphone_core_get_firewall_policy(call->core)) {
case LinphonePolicyUseIce: case LinphonePolicyUseIce:
call->ice_session = ice_session_new(); call->ice_session = ice_session_new();
...@@ -424,7 +425,7 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro ...@@ -424,7 +425,7 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro
if (linphone_core_gather_ice_candidates(call->core,call)<0) { if (linphone_core_gather_ice_candidates(call->core,call)<0) {
/* Ice candidates gathering failed, proceed with the call anyway. */ /* Ice candidates gathering failed, proceed with the call anyway. */
linphone_call_delete_ice_session(call); linphone_call_delete_ice_session(call);
linphone_call_stop_media_streams(call); linphone_call_stop_media_streams_for_ice_gathering(call);
} }
} }
break; break;
...@@ -965,9 +966,11 @@ void linphone_call_set_next_video_frame_decoded_callback(LinphoneCall *call, Lin ...@@ -965,9 +966,11 @@ void linphone_call_set_next_video_frame_decoded_callback(LinphoneCall *call, Lin
void linphone_call_init_audio_stream(LinphoneCall *call){ void linphone_call_init_audio_stream(LinphoneCall *call){
LinphoneCore *lc=call->core; LinphoneCore *lc=call->core;
AudioStream *audiostream; AudioStream *audiostream;
int dscp=linphone_core_get_audio_dscp(lc); int dscp;
if (call->audiostream != NULL) return;
call->audiostream=audiostream=audio_stream_new(call->audio_port,call->audio_port+1,linphone_core_ipv6_enabled(lc)); call->audiostream=audiostream=audio_stream_new(call->audio_port,call->audio_port+1,linphone_core_ipv6_enabled(lc));
dscp=linphone_core_get_audio_dscp(lc);
if (dscp!=-1) if (dscp!=-1)
audio_stream_set_dscp(audiostream,dscp); audio_stream_set_dscp(audiostream,dscp);
if (linphone_core_echo_limiter_enabled(lc)){ if (linphone_core_echo_limiter_enabled(lc)){
...@@ -1020,6 +1023,11 @@ void linphone_call_init_video_stream(LinphoneCall *call){ ...@@ -1020,6 +1023,11 @@ void linphone_call_init_video_stream(LinphoneCall *call){
#ifdef VIDEO_ENABLED #ifdef VIDEO_ENABLED
LinphoneCore *lc=call->core; LinphoneCore *lc=call->core;
if (!call->params.has_video) {
linphone_call_stop_video_stream(call);
return;
}
if (call->videostream != NULL) return;
if ((lc->video_conf.display || lc->video_conf.capture) && call->params.has_video){ if ((lc->video_conf.display || lc->video_conf.capture) && call->params.has_video){
int video_recv_buf_size=lp_config_get_int(lc->config,"video","recv_buf_size",0); int video_recv_buf_size=lp_config_get_int(lc->config,"video","recv_buf_size",0);
int dscp=linphone_core_get_video_dscp(lc); int dscp=linphone_core_get_video_dscp(lc);
...@@ -1535,6 +1543,15 @@ void linphone_call_start_media_streams_for_ice_gathering(LinphoneCall *call){ ...@@ -1535,6 +1543,15 @@ void linphone_call_start_media_streams_for_ice_gathering(LinphoneCall *call){
#endif #endif
} }
void linphone_call_stop_media_streams_for_ice_gathering(LinphoneCall *call){
audio_stream_unprepare_sound(call->audiostream);
#ifdef VIDEO_ENABLED
if (call->videostream) {
video_stream_unprepare_video(call->videostream);
}
#endif
}
void linphone_call_delete_ice_session(LinphoneCall *call){ void linphone_call_delete_ice_session(LinphoneCall *call){
if (call->ice_session != NULL) { if (call->ice_session != NULL) {
ice_session_destroy(call->ice_session); ice_session_destroy(call->ice_session);
...@@ -1551,7 +1568,7 @@ static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){ ...@@ -1551,7 +1568,7 @@ static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
log->quality=audio_stream_get_average_quality_rating(st); log->quality=audio_stream_get_average_quality_rating(st);
} }
void linphone_call_stop_media_streams(LinphoneCall *call){ void linphone_call_stop_audio_stream(LinphoneCall *call) {
if (call->audiostream!=NULL) { if (call->audiostream!=NULL) {
call->audiostream->ice_check_list = NULL; call->audiostream->ice_check_list = NULL;
rtp_session_unregister_event_queue(call->audiostream->session,call->audiostream_app_evq); rtp_session_unregister_event_queue(call->audiostream->session,call->audiostream_app_evq);
...@@ -1574,8 +1591,9 @@ void linphone_call_stop_media_streams(LinphoneCall *call){ ...@@ -1574,8 +1591,9 @@ void linphone_call_stop_media_streams(LinphoneCall *call){
audio_stream_stop(call->audiostream); audio_stream_stop(call->audiostream);
call->audiostream=NULL; call->audiostream=NULL;
} }
}
void linphone_call_stop_video_stream(LinphoneCall *call) {
#ifdef VIDEO_ENABLED #ifdef VIDEO_ENABLED
if (call->videostream!=NULL){ if (call->videostream!=NULL){
call->videostream->ice_check_list = NULL; call->videostream->ice_check_list = NULL;
...@@ -1587,6 +1605,11 @@ void linphone_call_stop_media_streams(LinphoneCall *call){ ...@@ -1587,6 +1605,11 @@ void linphone_call_stop_media_streams(LinphoneCall *call){
call->videostream=NULL; call->videostream=NULL;
} }
#endif #endif
}
void linphone_call_stop_media_streams(LinphoneCall *call){
linphone_call_stop_audio_stream(call);
linphone_call_stop_video_stream(call);
ms_event_queue_skip(call->core->msevq); ms_event_queue_skip(call->core->msevq);
if (call->audio_profile){ if (call->audio_profile){
...@@ -1812,11 +1835,11 @@ static void handle_ice_events(LinphoneCall *call, OrtpEvent *ev){ ...@@ -1812,11 +1835,11 @@ static void handle_ice_events(LinphoneCall *call, OrtpEvent *ev){
linphone_core_start_accept_call_update(call->core, call); linphone_core_start_accept_call_update(call->core, call);
break; break;
case LinphoneCallOutgoingInit: case LinphoneCallOutgoingInit:
linphone_call_stop_media_streams(call); linphone_call_stop_media_streams_for_ice_gathering(call);
linphone_core_proceed_with_invite_if_ready(call->core, call, NULL); linphone_core_proceed_with_invite_if_ready(call->core, call, NULL);
break; break;
default: default:
linphone_call_stop_media_streams(call); linphone_call_stop_media_streams_for_ice_gathering(call);
linphone_core_notify_incoming_call(call->core, call); linphone_core_notify_incoming_call(call->core, call);
break; break;
} }
......
...@@ -1916,7 +1916,7 @@ void linphone_core_iterate(LinphoneCore *lc){ ...@@ -1916,7 +1916,7 @@ void linphone_core_iterate(LinphoneCore *lc){
ms_warning("ICE candidates gathering from [%s] has not finished yet, proceed with the call without ICE anyway." ms_warning("ICE candidates gathering from [%s] has not finished yet, proceed with the call without ICE anyway."
,linphone_core_get_stun_server(lc)); ,linphone_core_get_stun_server(lc));
linphone_call_delete_ice_session(call); linphone_call_delete_ice_session(call);
linphone_call_stop_media_streams(call); linphone_call_stop_media_streams_for_ice_gathering(call);
} }
linphone_core_start_invite(lc,call); linphone_core_start_invite(lc,call);
} }
...@@ -2379,7 +2379,7 @@ LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const ...@@ -2379,7 +2379,7 @@ LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const
if (linphone_core_gather_ice_candidates(lc,call)<0) { if (linphone_core_gather_ice_candidates(lc,call)<0) {
/* Ice candidates gathering failed, proceed with the call anyway. */ /* Ice candidates gathering failed, proceed with the call anyway. */
linphone_call_delete_ice_session(call); linphone_call_delete_ice_session(call);
linphone_call_stop_media_streams(call); linphone_call_stop_media_streams_for_ice_gathering(call);
} else { } else {
use_ice = TRUE; use_ice = TRUE;
} }
...@@ -2678,6 +2678,7 @@ int linphone_core_accept_call_update(LinphoneCore *lc, LinphoneCall *call, const ...@@ -2678,6 +2678,7 @@ int linphone_core_accept_call_update(LinphoneCore *lc, LinphoneCall *call, const
ms_warning("Video isn't supported in conference"); ms_warning("Video isn't supported in conference");
call->params.has_video = FALSE; call->params.has_video = FALSE;
} }
call->params.has_video &= linphone_core_media_description_contains_video_stream(sal_call_get_remote_media_description(call->op));
call->camera_active=call->params.has_video; call->camera_active=call->params.has_video;
update_local_media_description(lc,call); update_local_media_description(lc,call);
if (call->ice_session != NULL) { if (call->ice_session != NULL) {
...@@ -2791,19 +2792,20 @@ int linphone_core_accept_call_with_params(LinphoneCore *lc, LinphoneCall *call, ...@@ -2791,19 +2792,20 @@ int linphone_core_accept_call_with_params(LinphoneCore *lc, LinphoneCall *call,
if (contact) if (contact)
sal_op_set_contact(call->op,contact); sal_op_set_contact(call->op,contact);
if (call->audiostream==NULL)
linphone_call_init_media_streams(call);
if (!was_ringing && call->audiostream->ticker==NULL){
audio_stream_prepare_sound(call->audiostream,lc->sound_conf.play_sndcard,lc->sound_conf.capt_sndcard);
}
if (params){ if (params){
call->params=*params; call->params=*params;
call->params.has_video &= linphone_core_media_description_contains_video_stream(sal_call_get_remote_media_description(call->op));
call->camera_active=call->params.has_video; call->camera_active=call->params.has_video;
update_local_media_description(lc,call); update_local_media_description(lc,call);
sal_call_set_local_media_description(call->op,call->localdesc); sal_call_set_local_media_description(call->op,call->localdesc);
} }
if (call->audiostream==NULL)
linphone_call_init_media_streams(call);
if (!was_ringing && call->audiostream->ticker==NULL){
audio_stream_prepare_sound(call->audiostream,lc->sound_conf.play_sndcard,lc->sound_conf.capt_sndcard);
}
sal_call_accept(call->op); sal_call_accept(call->op);
if (lc->vtable.display_status!=NULL) if (lc->vtable.display_status!=NULL)
lc->vtable.display_status(lc,_("Connected.")); lc->vtable.display_status(lc,_("Connected."));
......
...@@ -904,6 +904,17 @@ void linphone_core_update_ice_from_remote_media_description(LinphoneCall *call, ...@@ -904,6 +904,17 @@ void linphone_core_update_ice_from_remote_media_description(LinphoneCall *call,
} }
} }
bool_t linphone_core_media_description_contains_video_stream(const SalMediaDescription *md)
{
int i;
for (i = 0; i < md->nstreams; i++) {
if ((md->streams[i].type == SalVideo) && (md->streams[i].rtp_port != 0))
return TRUE;
}
return FALSE;
}
void linphone_core_deactivate_ice_for_deactivated_media_streams(LinphoneCall *call, const SalMediaDescription *md) void linphone_core_deactivate_ice_for_deactivated_media_streams(LinphoneCall *call, const SalMediaDescription *md)
{ {
int i; int i;
......
...@@ -251,6 +251,7 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call); ...@@ -251,6 +251,7 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call);
void linphone_core_update_ice_state_in_call_stats(LinphoneCall *call); void linphone_core_update_ice_state_in_call_stats(LinphoneCall *call);
void linphone_core_update_local_media_description_from_ice(SalMediaDescription *desc, IceSession *session); void linphone_core_update_local_media_description_from_ice(SalMediaDescription *desc, IceSession *session);
void linphone_core_update_ice_from_remote_media_description(LinphoneCall *call, const SalMediaDescription *md); void linphone_core_update_ice_from_remote_media_description(LinphoneCall *call, const SalMediaDescription *md);
bool_t linphone_core_media_description_contains_video_stream(const SalMediaDescription *md);
void linphone_core_deactivate_ice_for_deactivated_media_streams(LinphoneCall *call, const SalMediaDescription *md); void linphone_core_deactivate_ice_for_deactivated_media_streams(LinphoneCall *call, const SalMediaDescription *md);
void linphone_core_send_initial_subscribes(LinphoneCore *lc); void linphone_core_send_initial_subscribes(LinphoneCore *lc);
...@@ -280,8 +281,11 @@ void linphone_call_init_video_stream(LinphoneCall *call); ...@@ -280,8 +281,11 @@ void linphone_call_init_video_stream(LinphoneCall *call);
void linphone_call_init_media_streams(LinphoneCall *call); void linphone_call_init_media_streams(LinphoneCall *call);
void linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_muted, bool_t send_ringbacktone); void linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_muted, bool_t send_ringbacktone);
void linphone_call_start_media_streams_for_ice_gathering(LinphoneCall *call); void linphone_call_start_media_streams_for_ice_gathering(LinphoneCall *call);
void linphone_call_stop_audio_stream(LinphoneCall *call);
void linphone_call_stop_video_stream(LinphoneCall *call);
void linphone_call_stop_media_streams(LinphoneCall *call); void linphone_call_stop_media_streams(LinphoneCall *call);
void linphone_call_delete_ice_session(LinphoneCall *call); void linphone_call_delete_ice_session(LinphoneCall *call);
void linphone_call_stop_media_streams_for_ice_gathering(LinphoneCall *call);
const char * linphone_core_get_identity(LinphoneCore *lc); const char * linphone_core_get_identity(LinphoneCore *lc);
const char * linphone_core_get_route(LinphoneCore *lc); const char * linphone_core_get_route(LinphoneCore *lc);
......
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