]> sjero.net Git - linphone/commitdiff
Refactor code to prevent changing linphone_core API.
authorGhislain MARY <ghislain.mary@belledonne-communications.com>
Thu, 9 Aug 2012 10:00:39 +0000 (12:00 +0200)
committerGhislain MARY <ghislain.mary@belledonne-communications.com>
Thu, 9 Aug 2012 11:04:19 +0000 (13:04 +0200)
console/commands.c
coreapi/linphonecall.c
coreapi/linphonecore.c
coreapi/linphonecore.h
coreapi/private.h
gtk/incall_view.c
gtk/main.c

index 7bebdd82b43b66a306d9c5ebf0739902a959a0cb..472531795efa2d9655afdcc0412226533586d9ee 100644 (file)
@@ -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");
                        }
                }
index ccc5ad1e30174cac2d6325c2a5c499372bfc351d..4cd4a07347a864d54ff110a43a96c559859299b0 100644 (file)
@@ -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);
index 00870f9b2c6d8d21614e6a7fc4b942ac3a1e3285..b8911702b68f7c56d9fc9f3ef9079a5bee44598e 100644 (file)
@@ -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;
 }
 
index 6b00cbc09f2eb3af57ee3be59a782d1ed2ed45e6..10f6108c9ba3102c108199700454312b3988839f 100644 (file)
@@ -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);
index f68725473534da3b70e8f75d2c95a005f7a78148..05d5c3f13961a747d07f4d95dc67ad7ed1428e5a 100644 (file)
@@ -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);
index 45e98609b9b96f263df90cb2043b4809c3dce31b..7e8eb683f84c8ee7efc78fdfe5d8055a73465ddb 100644 (file)
@@ -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){
index 054677654554366c3c175b42924641cb9e01bf1c..2955b3ecc81493aa57330b608772f3e1e63137dd 100644 (file)
@@ -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);