From: Ghislain MARY Date: Thu, 9 Aug 2012 10:00:39 +0000 (+0200) Subject: Refactor code to prevent changing linphone_core API. X-Git-Url: http://sjero.net/git/?p=linphone;a=commitdiff_plain;h=d0e7a66501d8476a483783dd35b61d8416e3a29a Refactor code to prevent changing linphone_core API. --- diff --git a/console/commands.c b/console/commands.c index 7bebdd82..47253179 100644 --- a/console/commands.c +++ b/console/commands.c @@ -2503,7 +2503,10 @@ static int lpc_cmd_camera(LinphoneCore *lc, char *args){ linphone_call_enable_camera(call,activated); if ((activated && !linphone_call_params_video_enabled (cp))){ /*update the call to add the video stream*/ - linphone_call_enable_video(call,TRUE); + LinphoneCallParams *ncp=linphone_call_params_copy(cp); + linphone_call_params_enable_video(ncp,TRUE); + linphone_core_update_call(lc,call,ncp); + linphone_call_params_destroy (ncp); linphonec_out("Trying to bring up video stream...\n"); } } diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index ccc5ad1e..4cd4a073 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -546,42 +546,6 @@ void linphone_call_set_state(LinphoneCall *call, LinphoneCallState cstate, const } } -void linphone_call_enable_video(LinphoneCall *call, bool_t enabled) -{ - LinphoneCore *lc=linphone_call_get_core(call); - LinphoneCallParams *params=linphone_call_params_copy(linphone_call_get_current_params(call)); - - linphone_call_params_enable_video(params, enabled); - if (enabled == TRUE) { - if (call->ice_session != NULL) { - /* Defer call update until the ICE candidates gathering process has finished. */ - ms_message("Defer call update to gather ICE candidates"); - call->params = *params; - update_local_media_description(lc, call); - linphone_call_init_video_stream(call); - video_stream_prepare_video(call->videostream); - linphone_core_gather_ice_candidates(lc, call); - } else { - if (linphone_call_get_state(call) == LinphoneCallUpdatedByRemote) { - linphone_core_accept_call_update(lc, call, params); - } else { - linphone_core_update_call(lc, call, params); - } - } - } else { - if ((call->ice_session != NULL) && (call->videostream != NULL)) { - ice_session_remove_check_list(call->ice_session, call->videostream->ice_check_list); - call->videostream->ice_check_list = NULL; - } - if (linphone_call_get_state(call) == LinphoneCallUpdatedByRemote) { - linphone_core_accept_call_update(lc, call, params); - } else { - linphone_core_update_call(lc, call, params); - } - } - linphone_call_params_destroy(params); -} - static void linphone_call_destroy(LinphoneCall *obj) { if (obj->op!=NULL) { @@ -1750,50 +1714,31 @@ static void handle_ice_events(LinphoneCall *call, OrtpEvent *ev){ break; } } else if (evt == ORTP_EVENT_ICE_GATHERING_FINISHED) { - LinphoneCallParams *params; + if (evd->info.ice_processing_successful==TRUE) { + ice_session_compute_candidates_foundations(call->ice_session); + ice_session_eliminate_redundant_candidates(call->ice_session); + ice_session_choose_default_candidates(call->ice_session); + } else { + linphone_call_delete_ice_session(call); + } switch (call->state) { case LinphoneCallStreamsRunning: + linphone_core_start_update_call(call->core, call); + break; case LinphoneCallUpdatedByRemote: - if (evd->info.ice_processing_successful==TRUE) { - ice_session_compute_candidates_foundations(call->ice_session); - ice_session_eliminate_redundant_candidates(call->ice_session); - ice_session_choose_default_candidates(call->ice_session); - } - params = linphone_call_params_copy(linphone_call_get_current_params(call)); - linphone_call_params_enable_video(params, TRUE); - if (call->state == LinphoneCallStreamsRunning) { - linphone_core_update_call(call->core, call, params); - } else { /* LinphoneCallUpdatedByRemote */ - linphone_core_accept_call_update(call->core, call, params); - } - linphone_call_params_destroy(params); + linphone_core_start_accept_call_update(call->core, call); break; case LinphoneCallOutgoingInit: + linphone_call_stop_media_streams(call); + linphone_core_start_invite(call->core, call, NULL); + break; default: linphone_call_stop_media_streams(call); - if (evd->info.ice_processing_successful==TRUE) { - ice_session_compute_candidates_foundations(call->ice_session); - ice_session_eliminate_redundant_candidates(call->ice_session); - ice_session_choose_default_candidates(call->ice_session); - } else { - linphone_call_delete_ice_session(call); - } - if (call->state==LinphoneCallOutgoingInit) { - linphone_core_start_invite(call->core,call,NULL); - } else { - linphone_core_notify_incoming_call(call->core,call); - } + linphone_core_notify_incoming_call(call->core, call); break; } } else if (evt == ORTP_EVENT_ICE_LOSING_PAIRS_COMPLETED) { - SalMediaDescription *md; - linphone_core_update_local_media_description_from_ice(call->localdesc, call->ice_session); - sal_call_set_local_media_description(call->op,call->localdesc); - sal_call_accept(call->op); - md=sal_call_get_final_media_description(call->op); - if (md && !sal_media_description_empty(md)) - linphone_core_update_streams (call->core,call,md); - linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)"); + linphone_core_start_accept_call_update(call->core, call); } else if (evt == ORTP_EVENT_ICE_RESTART_NEEDED) { ice_session_restart(call->ice_session); ice_session_set_role(call->ice_session, IR_Controlling); diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 00870f9b..b8911702 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2445,6 +2445,24 @@ void linphone_core_notify_incoming_call(LinphoneCore *lc, LinphoneCall *call){ ms_free(tmp); } +int linphone_core_start_update_call(LinphoneCore *lc, LinphoneCall *call){ + const char *subject; + call->camera_active=call->params.has_video; + update_local_media_description(lc,call); + if (call->ice_session != NULL) + linphone_core_update_local_media_description_from_ice(call->localdesc, call->ice_session); + + if (call->params.in_conference){ + subject="Conference"; + }else{ + subject="Media change"; + } + if (lc->vtable.display_status) + lc->vtable.display_status(lc,_("Modifying call parameters...")); + sal_call_set_local_media_description (call->op,call->localdesc); + return sal_call_update(call->op,subject); +} + /** * @ingroup call_control * Updates a running call according to supplied call parameters or parameters changed in the LinphoneCore. @@ -2462,22 +2480,25 @@ void linphone_core_notify_incoming_call(LinphoneCore *lc, LinphoneCall *call){ int linphone_core_update_call(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallParams *params){ int err=0; if (params!=NULL){ - const char *subject; - call->params=*params; - call->camera_active=call->params.has_video; - update_local_media_description(lc,call); - if (call->ice_session != NULL) - linphone_core_update_local_media_description_from_ice(call->localdesc, call->ice_session); - - if (params->in_conference){ - subject="Conference"; - }else{ - subject="Media change"; + if ((call->ice_session != NULL) && (call->videostream != NULL) && !params->has_video) { + ice_session_remove_check_list(call->ice_session, call->videostream->ice_check_list); + call->videostream->ice_check_list = NULL; + } + if ((call->ice_session != NULL) && ((ice_session_state(call->ice_session) != IS_Completed) || (call->params.has_video != params->has_video))) { + /* Defer call update until the ICE candidates gathering process has finished. */ + ms_message("Defer call update to gather ICE candidates"); + call->params = *params; + update_local_media_description(lc, call); + if (call->params.has_video) { + linphone_call_init_video_stream(call); + video_stream_prepare_video(call->videostream); + if (linphone_core_gather_ice_candidates(lc,call)<0) { + /* Ice candidates gathering failed, proceed with the call anyway. */ + linphone_call_delete_ice_session(call); + } else return err; + } } - if (lc->vtable.display_status) - lc->vtable.display_status(lc,_("Modifying call parameters...")); - sal_call_set_local_media_description (call->op,call->localdesc); - err=sal_call_update(call->op,subject); + err = linphone_core_start_update_call(lc, call); }else{ #ifdef VIDEO_ENABLED if (call->videostream!=NULL){ @@ -2515,6 +2536,24 @@ int linphone_core_defer_call_update(LinphoneCore *lc, LinphoneCall *call){ return -1; } +int linphone_core_start_accept_call_update(LinphoneCore *lc, LinphoneCall *call){ + SalMediaDescription *md; + if (call->ice_session != NULL) { + if (ice_session_nb_losing_pairs(call->ice_session) > 0) { + /* Defer the sending of the answer until there are no losing pairs left. */ + return 0; + } + linphone_core_update_local_media_description_from_ice(call->localdesc, call->ice_session); + } + sal_call_set_local_media_description(call->op,call->localdesc); + sal_call_accept(call->op); + md=sal_call_get_final_media_description(call->op); + if (md && !sal_media_description_empty(md)) + linphone_core_update_streams (lc,call,md); + linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)"); + return 0; +} + /** * @ingroup call_control * Accept call modifications initiated by other end. @@ -2535,7 +2574,7 @@ int linphone_core_defer_call_update(LinphoneCore *lc, LinphoneCall *call){ * @return 0 if sucessful, -1 otherwise (actually when this function call is performed outside ot #LinphoneCallUpdatedByRemote state). **/ int linphone_core_accept_call_update(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallParams *params){ - SalMediaDescription *md; + bool_t old_has_video = call->params.has_video; if (call->state!=LinphoneCallUpdatedByRemote){ ms_error("linphone_core_accept_update(): invalid state %s to call this function.", linphone_call_state_to_string(call->state)); @@ -2554,18 +2593,18 @@ int linphone_core_accept_call_update(LinphoneCore *lc, LinphoneCall *call, const update_local_media_description(lc,call); if (call->ice_session != NULL) { linphone_core_update_ice_from_remote_media_description(call, sal_call_get_remote_media_description(call->op)); - if (ice_session_nb_losing_pairs(call->ice_session) > 0) { - /* Defer the sending of the answer until there are no losing pairs left. */ - return 0; + if (!ice_session_candidates_gathered(call->ice_session)) { + if ((call->params.has_video) && (call->params.has_video != old_has_video)) { + linphone_call_init_video_stream(call); + video_stream_prepare_video(call->videostream); + if (linphone_core_gather_ice_candidates(lc,call)<0) { + /* Ice candidates gathering failed, proceed with the call anyway. */ + linphone_call_delete_ice_session(call); + } else return 0; + } } - linphone_core_update_local_media_description_from_ice(call->localdesc, call->ice_session); } - sal_call_set_local_media_description(call->op,call->localdesc); - sal_call_accept(call->op); - md=sal_call_get_final_media_description(call->op); - if (md && !sal_media_description_empty(md)) - linphone_core_update_streams (lc,call,md); - linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)"); + linphone_core_start_accept_call_update(lc, call); return 0; } diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index 6b00cbc0..10f6108c 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -390,15 +390,6 @@ void linphone_call_enable_echo_limiter(LinphoneCall *call, bool_t val); **/ bool_t linphone_call_echo_limiter_enabled(const LinphoneCall *call); -/** - * Enable or disable video for this call. - * @param call - * @param enabled - * - * @ingroup media_parameters - */ -void linphone_call_enable_video(LinphoneCall *call, bool_t enabled); - /*keep this in sync with mediastreamer2/msvolume.h*/ /** @@ -792,8 +783,6 @@ int linphone_core_transfer_call_to_another(LinphoneCore *lc, LinphoneCall *call, bool_t linphone_core_inc_invite_pending(LinphoneCore*lc); -void linphone_core_notify_incoming_call(LinphoneCore *lc, LinphoneCall *call); - bool_t linphone_core_in_call(const LinphoneCore *lc); LinphoneCall *linphone_core_get_current_call(const LinphoneCore *lc); diff --git a/coreapi/private.h b/coreapi/private.h index f6872547..05d5c3f1 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -261,7 +261,10 @@ void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float void linphone_core_stop_waiting(LinphoneCore *lc); int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphoneProxyConfig *dest_proxy); +int linphone_core_start_update_call(LinphoneCore *lc, LinphoneCall *call); +int linphone_core_start_accept_call_update(LinphoneCore *lc, LinphoneCall *call); void linphone_core_start_refered_call(LinphoneCore *lc, LinphoneCall *call); +void linphone_core_notify_incoming_call(LinphoneCore *lc, LinphoneCall *call); extern SalCallbacks linphone_sal_callbacks; void linphone_proxy_config_set_error(LinphoneProxyConfig *cfg, LinphoneReason error); bool_t linphone_core_rtcp_enabled(const LinphoneCore *lc); diff --git a/gtk/incall_view.c b/gtk/incall_view.c index 45e98609..7e8eb683 100644 --- a/gtk/incall_view.c +++ b/gtk/incall_view.c @@ -221,8 +221,12 @@ void linphone_gtk_create_in_call_view(LinphoneCall *call){ static void video_button_clicked(GtkWidget *button, LinphoneCall *call){ gboolean adding=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button),"adding_video")); + LinphoneCore *lc=linphone_call_get_core(call); + LinphoneCallParams *params=linphone_call_params_copy(linphone_call_get_current_params(call)); gtk_widget_set_sensitive(button,FALSE); - linphone_call_enable_video(call,adding); + linphone_call_params_enable_video(params,adding); + linphone_core_update_call(lc,call,params); + linphone_call_params_destroy(params); } void linphone_gtk_update_video_button(LinphoneCall *call){ diff --git a/gtk/main.c b/gtk/main.c index 05467765..2955b3ec 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1080,7 +1080,11 @@ static void linphone_gtk_notify(LinphoneCall *call, const char *msg){ static void on_call_updated_response(GtkWidget *dialog, gint responseid, LinphoneCall *call){ if (linphone_call_get_state(call)==LinphoneCallUpdatedByRemote){ - linphone_call_enable_video(call, responseid==GTK_RESPONSE_YES); + LinphoneCore *lc=linphone_call_get_core(call); + LinphoneCallParams *params=linphone_call_params_copy(linphone_call_get_current_params(call)); + linphone_call_params_enable_video(params,responseid==GTK_RESPONSE_YES); + linphone_core_accept_call_update(lc,call,params); + linphone_call_params_destroy(params); } linphone_call_unref(call); g_source_remove_by_user_data(dialog);