]> sjero.net Git - linphone/blobdiff - coreapi/linphonecore.c
Merge branch 'master' into dev_multicall
[linphone] / coreapi / linphonecore.c
index 6bb231242e5591a0198687c7bb3b788f1430cc46..5b4779680d2bb599af9506db83d79549586bc190 100644 (file)
@@ -62,151 +62,7 @@ int lc_callback_obj_invoke(LCCallbackObj *obj, LinphoneCore *lc){
        return 0;
 }
 
-
-static MSList *make_codec_list(LinphoneCore *lc, const MSList *codecs, bool_t only_one_codec){
-       MSList *l=NULL;
-       const MSList *it;
-       for(it=codecs;it!=NULL;it=it->next){
-               PayloadType *pt=(PayloadType*)it->data;
-               if ((pt->flags & PAYLOAD_TYPE_ENABLED) && linphone_core_check_payload_type_usability(lc,pt)){
-                       l=ms_list_append(l,payload_type_clone(pt));
-                       if (only_one_codec) break;
-               }
-       }
-       return l;
-}
-
-static SalMediaDescription *create_local_media_description(LinphoneCore *lc, 
-               const char *localip, const char *username, bool_t only_one_codec){
-       MSList *l;
-       PayloadType *pt;
-       SalMediaDescription *md=sal_media_description_new();
-       md->nstreams=1;
-       strncpy(md->addr,localip,sizeof(md->addr));
-       strncpy(md->username,username,sizeof(md->username));
-       md->bandwidth=linphone_core_get_download_bandwidth(lc);
-       /*set audio capabilities */
-       strncpy(md->streams[0].addr,localip,sizeof(md->streams[0].addr));
-       md->streams[0].port=linphone_core_get_audio_port(lc);
-       md->streams[0].proto=SalProtoRtpAvp;
-       md->streams[0].type=SalAudio;
-       md->streams[0].ptime=lc->net_conf.down_ptime;
-       l=make_codec_list(lc,lc->codecs_conf.audio_codecs,only_one_codec);
-       pt=payload_type_clone(rtp_profile_get_payload_from_mime(&av_profile,"telephone-event"));
-       l=ms_list_append(l,pt);
-       md->streams[0].payloads=l;
-       
-       if (lc->dw_audio_bw>0)
-               md->streams[0].bandwidth=lc->dw_audio_bw;
-
-       if (linphone_core_video_enabled (lc)){
-               md->nstreams++;
-               md->streams[1].port=linphone_core_get_video_port(lc);
-               md->streams[1].proto=SalProtoRtpAvp;
-               md->streams[1].type=SalVideo;
-               l=make_codec_list(lc,lc->codecs_conf.video_codecs,only_one_codec);
-               md->streams[1].payloads=l;
-               if (lc->dw_video_bw)
-                       md->streams[1].bandwidth=lc->dw_video_bw;
-       }
-       return md;
-}
-
-static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
-       call->state=LCStateInit;
-       call->start_time=time(NULL);
-       call->media_start_time=0;
-       call->log=linphone_call_log_new(call, from, to);
-       linphone_core_notify_all_friends(call->core,LINPHONE_STATUS_ONTHEPHONE);
-       if (linphone_core_get_firewall_policy(call->core)==LINPHONE_POLICY_USE_STUN)
-               linphone_core_run_stun_tests(call->core,call);
-}
-
-static void discover_mtu(LinphoneCore *lc, const char *remote){
-       int mtu;
-       if (lc->net_conf.mtu==0 ){
-               /*attempt to discover mtu*/
-               mtu=ms_discover_mtu(remote);
-               if (mtu>0){
-                       ms_set_mtu(mtu);
-                       ms_message("Discovered mtu is %i, RTP payload max size is %i",
-                               mtu, ms_get_payload_max_size());
-               }
-       }
-}
-
-LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to)
-{
-       LinphoneCall *call=ms_new0(LinphoneCall,1);
-       call->dir=LinphoneCallOutgoing;
-       call->op=sal_op_new(lc->sal);
-       sal_op_set_user_pointer(call->op,call);
-       call->core=lc;
-       linphone_core_get_local_ip(lc,linphone_address_get_domain(to),call->localip);
-       call->localdesc=create_local_media_description (lc,call->localip,
-               linphone_address_get_username(from),FALSE);
-       linphone_call_init_common(call,from,to);
-       discover_mtu(lc,linphone_address_get_domain (to));
-       return call;
-}
-
-LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){
-       LinphoneCall *call=ms_new0(LinphoneCall,1);
-       LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
-       char *to_str;
-       char *from_str;
-
-       call->dir=LinphoneCallIncoming;
-       sal_op_set_user_pointer(op,call);
-       call->op=op;
-       call->core=lc;
-
-       if (lc->sip_conf.ping_with_options){
-               /*the following sends an option request back to the caller so that
-                we get a chance to discover our nat'd address before answering.*/
-               call->ping_op=sal_op_new(lc->sal);
-               to_str=linphone_address_as_string(to);
-               from_str=linphone_address_as_string(from);
-               sal_op_set_route(call->ping_op,sal_op_get_network_origin(call->op));
-               sal_op_set_user_pointer(call->ping_op,call);
-               sal_ping(call->ping_op,to_str,from_str);
-               ms_free(to_str);
-               ms_free(from_str);
-       }
-       
-       linphone_address_clean(from);
-       linphone_core_get_local_ip(lc,linphone_address_get_domain(from),call->localip);
-       call->localdesc=create_local_media_description (lc,call->localip,
-           linphone_address_get_username(me),lc->sip_conf.only_one_codec);
-       linphone_call_init_common(call, from, to);
-       discover_mtu(lc,linphone_address_get_domain(from));
-       linphone_address_destroy(me);
-       return call;
-}
-
-void linphone_call_destroy(LinphoneCall *obj)
-{
-       linphone_core_notify_all_friends(obj->core,obj->core->prev_mode);
-       linphone_call_log_completed(obj->log,obj);
-       linphone_core_update_allocated_audio_bandwidth(obj->core);
-       if (obj->op!=NULL) {
-               sal_op_release(obj->op);
-               obj->op=NULL;
-       }
-       if (obj->resultdesc!=NULL) {
-               sal_media_description_unref(obj->resultdesc);
-               obj->resultdesc=NULL;
-       }
-       if (obj->localdesc!=NULL) {
-               sal_media_description_unref(obj->localdesc);
-               obj->localdesc=NULL;
-       }
-       if (obj->ping_op) {
-               sal_op_release(obj->ping_op);
-       }
-       ms_free(obj);
-}
-
+               
 /*prevent a gcc bug with %c*/
 static size_t my_strftime(char *s, size_t max, const char  *fmt,  const struct tm *tm){
 #if !defined(_WIN32_WCE)
@@ -295,32 +151,20 @@ static void call_logs_read_from_config_file(LinphoneCore *lc){
 }
 
 
-void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call){
+void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call, LinphoneCallStatus status){
        LinphoneCore *lc=call->core;
        
        calllog->duration=time(NULL)-call->start_time;
-       switch(call->state){
-               case LCStateInit:
-               case LCStatePreEstablishing:
-                       calllog->status=LinphoneCallAborted;
-                       break;
-               case LCStateRinging:
-                       if (calllog->dir==LinphoneCallIncoming){
-                               char *info;
-                               calllog->status=LinphoneCallMissed;
-                               lc->missed_calls++;
-                               info=ortp_strdup_printf(ngettext("You have missed %i call.",
-                            "You have missed %i calls.", lc->missed_calls),
-                        lc->missed_calls);
-                               lc->vtable.display_status(lc,info);
-                               ms_free(info);
-                       }
-                       else calllog->status=LinphoneCallAborted;
-                       break;
-               case LCStateAVRunning:
-                       calllog->status=LinphoneCallSuccess;
-                       break;
-       }
+       
+       if (status==LinphoneCallMissed){
+               char *info;
+               lc->missed_calls++;
+               info=ortp_strdup_printf(ngettext("You have missed %i call.",
+                    "You have missed %i calls.", lc->missed_calls),
+                lc->missed_calls);
+               lc->vtable.display_status(lc,info);
+               ms_free(info);
+       }else calllog->status=status;
        lc->call_logs=ms_list_prepend(lc->call_logs,(void *)calllog);
        if (ms_list_size(lc->call_logs)>lc->max_call_logs){
                MSList *elem,*prevelem=NULL;
@@ -437,17 +281,21 @@ bool_t linphone_call_asked_to_autoanswer(LinphoneCall *call){
                return FALSE;
 }
 
-int linphone_core_get_current_call_duration(const LinphoneCore *lc){
-       LinphoneCall *call=lc->call;
+int linphone_core_get_call_duration(LinphoneCall *call){
        if (call==NULL) return 0;
        if (call->media_start_time==0) return 0;
        return time(NULL)-call->media_start_time;
 }
 
-const LinphoneAddress *linphone_core_get_remote_uri(LinphoneCore *lc){
-       LinphoneCall *call=lc->call;
+int linphone_core_get_current_call_duration(const LinphoneCore *lc){
+       LinphoneCall *call=linphone_core_get_current_call((LinphoneCore *)lc);
+       return linphone_core_get_call_duration(call);
+}
+
+const LinphoneAddress *linphone_core_get_current_call_remote_address(struct _LinphoneCore *lc){
+       LinphoneCall *call=linphone_core_get_current_call(lc);
        if (call==NULL) return 0;
-       return call->dir==LinphoneCallIncoming ? call->log->from : call->log->to;
+       return linphone_call_get_remote_address(call);
 }
 
 /**
@@ -1651,20 +1499,20 @@ void linphone_core_iterate(LinphoneCore *lc){
        if (lc->auto_net_state_mon) monitor_network_state(lc,curtime);
 
        proxy_update(lc);
-
-       if (lc->call!=NULL){
-               LinphoneCall *call=lc->call;
-               if (call->state==LCStatePreEstablishing && (curtime-call->start_time>=2)){
+       LinphoneCall *call = linphone_core_get_current_call(lc);
+       if(call){
+               if (call->state==LinphoneCallPreEstablishing && (curtime-call->start_time>=2)){
                        /*start the call even if the OPTIONS reply did not arrive*/
                        linphone_core_start_invite(lc,call,NULL);
                }
-               if (call->dir==LinphoneCallIncoming && call->state==LCStateRinging){
+               if (call->dir==LinphoneCallIncoming && call->state==LinphoneCallRinging){
                        elapsed=curtime-call->start_time;
                        ms_message("incoming call ringing for %i seconds",elapsed);
                        if (elapsed>lc->sip_conf.inc_timeout){
+                               call->log->status=LinphoneCallMissed;
                                linphone_core_terminate_call(lc,NULL);
                        }
-               }else if (call->state==LCStateAVRunning){
+               }else if (call->state==LinphoneCallAVRunning){
                        if (one_second_elapsed){
                                RtpSession *as=NULL,*vs=NULL;
                                lc->prevtime=curtime;
@@ -1727,6 +1575,8 @@ LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url)
                lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
                if (enum_lookup(enum_domain,&enumres)<0){
                        lc->vtable.display_status(lc,_("Could not resolve this number."));
+                       if(lc->vtable.failure_recv)
+                               lc->vtable.failure_recv(lc,NULL,400);
                        ms_free(enum_domain);
                        return NULL;
                }
@@ -1809,7 +1659,7 @@ bool_t linphone_core_is_in_communication_with(LinphoneCore *lc, const char *to)
 {
        char *tmp;
        bool_t returned;
-       const LinphoneAddress *la=linphone_core_get_remote_uri(lc);
+       const LinphoneAddress *la=linphone_core_get_current_call_remote_address(lc);
        if(la == NULL)
        {
                return FALSE;
@@ -1853,7 +1703,6 @@ static char *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphonePr
        if (call->op && sal_op_get_contact(call->op)!=NULL){
                return NULL;
        }
-       
        /* if the ping OPTIONS request succeeded use the contact guessed from the
         received, rport*/
        if (call->ping_op){
@@ -1899,8 +1748,8 @@ int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphonePro
                sal_op_set_contact(call->op, contact);
                ms_free(contact);
        }
-       call->state=LCStateInit;
-       linphone_core_init_media_streams(lc,lc->call);
+       call->state=LinphoneCallInit;
+       linphone_core_init_media_streams(lc,call);
        if (!lc->sip_conf.sdp_200_ack){ 
                call->media_pending=TRUE;
                sal_call_set_local_media_description(call->op,call->localdesc);
@@ -1920,9 +1769,9 @@ int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphonePro
        if (err<0){
                ms_warning("Could not initiate call.");
                lc->vtable.display_status(lc,_("could not call"));
-               linphone_core_stop_media_streams(lc,call);
-               linphone_call_destroy(call);
-               lc->call=NULL;
+               if(call == linphone_core_get_current_call(lc))
+                       linphone_core_stop_media_streams(lc,call);
+               linphone_call_unref(call);
        }else gstate_new_state(lc, GSTATE_CALL_OUT_INVITE, real_url);
        ms_free(real_url);
        ms_free(from);
@@ -1936,15 +1785,15 @@ int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphonePro
  * @param lc the LinphoneCore object
  * @param url the destination of the call (sip address, or phone number).
 **/
-int linphone_core_invite(LinphoneCore *lc, const char *url){
+LinphoneCall * linphone_core_invite(LinphoneCore *lc, const char *url){
        LinphoneAddress *addr=linphone_core_interpret_url(lc,url);
        if (addr){
-               int err;
-               err=linphone_core_invite_address(lc,addr);
+               LinphoneCall *call;
+               call=linphone_core_invite_address(lc,addr);
                linphone_address_destroy(addr);
-               return err;
+               return call;
        }
-       return -1;
+       return NULL;
 }
 
 /**
@@ -1954,7 +1803,7 @@ int linphone_core_invite(LinphoneCore *lc, const char *url){
  * @param lc the LinphoneCore object
  * @param url the destination of the call (sip address).
 **/
-int linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *real_parsed_url)
+LinphoneCall * linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *real_parsed_url)
 {
        int err=0;
        const char *route=NULL;
@@ -1965,11 +1814,14 @@ int linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *real_p
        LinphoneProxyConfig *dest_proxy=NULL;
        LinphoneCall *call;
        
-       if (lc->call!=NULL){
-               lc->vtable.display_warning(lc,_("Sorry, having multiple simultaneous calls is not supported yet !"));
-               return -1;
+       if (linphone_core_in_call(lc)){
+               lc->vtable.display_warning(lc,_("Sorry, you have to pause or stop the current call first !"));
+               return NULL;
+       }
+       if(!linphone_core_can_we_add_call(lc)){
+               lc->vtable.display_warning(lc,_("Sorry, we have reached the maximum number of simultaneous calls"));
+               return NULL;
        }
-
        linphone_core_get_default_proxy(lc,&proxy);
        route=linphone_core_get_route(lc);
        
@@ -1994,32 +1846,36 @@ int linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *real_p
        call=linphone_call_new_outgoing(lc,parsed_url2,linphone_address_clone(real_parsed_url));
        sal_op_set_route(call->op,route);
        
-       lc->call=call;
+       if(linphone_core_add_call(lc,call)!= 0)
+       {
+               ms_warning("we had a problem in adding the call into the invite ... weird\n");
+               linphone_call_unref(call);
+               return NULL;
+       }
+       linphone_core_set_as_current_call(lc,call);
        if (dest_proxy!=NULL || lc->sip_conf.ping_with_options==FALSE){
                err=linphone_core_start_invite(lc,call,dest_proxy);
        }else{
                /*defer the start of the call after the OPTIONS ping*/
-               call->state=LCStatePreEstablishing;
+               call->state=LinphoneCallPreEstablishing;
                call->ping_op=sal_op_new(lc->sal);
                sal_ping(call->ping_op,from,real_url);
                call->start_time=time(NULL);
        }
        
        if (real_url!=NULL) ms_free(real_url);
-       return err;
+       return call;
 }
 
-int linphone_core_refer(LinphoneCore *lc, const char *url)
+int linphone_core_refer(LinphoneCore *lc, LinphoneCall *call, const char *url)
 {
        char *real_url=NULL;
        LinphoneAddress *real_parsed_url=linphone_core_interpret_url(lc,url);
-       LinphoneCall *call;
 
        if (!real_parsed_url){
                /* bad url */
                return -1;
        }
-       call=lc->call;
        if (call==NULL){
                ms_warning("No established call to refer.");
                return -1;
@@ -2032,13 +1888,16 @@ int linphone_core_refer(LinphoneCore *lc, const char *url)
 }
 
 /**
- * Returns true if in incoming call is pending, ie waiting for being answered or declined.
+ * Returns true if an incoming call is pending, ie waiting for being answered or declined.
  *
  * @ingroup call_control
 **/
 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
-       if (lc->call!=NULL && lc->call->dir==LinphoneCallIncoming){
-               return TRUE;
+       LinphoneCall *call = linphone_core_get_current_call(lc);
+       if(call != NULL)
+       {
+               if(call->dir==LinphoneCallIncoming)
+                       return TRUE;
        }
        return FALSE;
 }
@@ -2293,7 +2152,7 @@ void linphone_core_start_media_streams(LinphoneCore *lc, LinphoneCall *call){
        end:
                ms_free(cname);
                linphone_address_destroy(me);
-               lc->call->state=LCStateAVRunning;
+               call->state=LinphoneCallAVRunning;
 }
 
 void linphone_core_stop_media_streams(LinphoneCore *lc, LinphoneCall *call){
@@ -2343,17 +2202,20 @@ void linphone_core_stop_media_streams(LinphoneCore *lc, LinphoneCall *call){
  *            however this feature is not supported yet.
  *            Using NULL will accept the unique incoming call in progress.
 **/
-int linphone_core_accept_call(LinphoneCore *lc, const char *url)
+int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call)
 {
-       LinphoneCall *call=lc->call;
        LinphoneProxyConfig *cfg=NULL;
        const char *contact=NULL;
        
        if (call==NULL){
-               return -1;
+               //if just one call is present answer the only one ...
+               if(ms_list_size(linphone_core_get_calls(lc)) != 1)
+                       return -1;
+               else
+                       call = linphone_core_get_calls(lc)->data;
        }
 
-       if (call->state==LCStateAVRunning){
+       if (call->state==LinphoneCallAVRunning){
                /*call already accepted*/
                return -1;
        }
@@ -2365,7 +2227,11 @@ int linphone_core_accept_call(LinphoneCore *lc, const char *url)
                ms_message("ring stopped");
                lc->ringstream=NULL;
        }
-
+       if(linphone_core_set_as_current_call(lc,call)!=0)
+       {
+               ms_message("another call is already in process\n");
+       }
+       
        linphone_core_get_default_proxy(lc,&cfg);
        /*try to be best-effort in giving real local or routable contact address*/
        contact=get_fixed_contact(lc,call,cfg);
@@ -2378,7 +2244,8 @@ int linphone_core_accept_call(LinphoneCore *lc, const char *url)
        call->resultdesc=sal_call_get_final_media_description(call->op);
        if (call->resultdesc){
                sal_media_description_ref(call->resultdesc);
-               linphone_core_start_media_streams(lc, call);
+               if(call == linphone_core_get_current_call(lc))
+                       linphone_core_start_media_streams(lc, call);
        }else call->media_pending=TRUE;
        ms_message("call answered.");
        return 0;
@@ -2392,13 +2259,20 @@ int linphone_core_accept_call(LinphoneCore *lc, const char *url)
  * @param url the destination of the call to be terminated, use NULL if there is
  *            only one call (which is case in this version of liblinphone).
 **/
-int linphone_core_terminate_call(LinphoneCore *lc, const char *url)
+int linphone_core_terminate_call(LinphoneCore *lc, LinphoneCall *the_call)
 {
-       LinphoneCall *call=lc->call;
-       if (call==NULL){
-               return -1;
+       LinphoneCall *call;
+       if (the_call == NULL){
+               call = linphone_core_get_current_call(lc);
+               if(call == NULL)
+               {
+                       return -1;
+               }
+       }
+       else
+       {
+               call = the_call;
        }
-       lc->call=NULL;
        sal_call_terminate(call->op);
 
        /*stop ringing*/
@@ -2406,20 +2280,51 @@ int linphone_core_terminate_call(LinphoneCore *lc, const char *url)
                ring_stop(lc->ringstream);
                lc->ringstream=NULL;
        }
-       linphone_core_stop_media_streams(lc,call);
+       if(call == linphone_core_get_current_call(lc))
+               linphone_core_stop_media_streams(lc,call);
        lc->vtable.display_status(lc,_("Call ended") );
        gstate_new_state(lc, GSTATE_CALL_END, NULL);
-       linphone_call_destroy(call);
+       linphone_call_set_terminated(call);
+       linphone_call_unref(call);
        return 0;
 }
 
+/**
+ * Terminates all the calls.
+ *
+ * @ingroup call_control
+ * @param lc The LinphoneCore
+**/
+int linphone_core_terminate_all_calls(LinphoneCore *lc){
+       MSList *calls;
+
+       calls = lc->calls;
+       while(calls->next != NULL)
+       {
+               linphone_core_terminate_call(lc,(LinphoneCall *)calls->data);
+               calls = calls->next;
+       }
+       ms_list_free(lc->calls);
+       return -1;
+}
+
+/**
+ * Returns the calls MSList
+ *
+ * @ingroup call_control
+**/
+MSList *linphone_core_get_calls(LinphoneCore *lc)
+{
+       return ms_list_copy(lc->calls);
+}
+
 /**
  * Returns TRUE if there is a call running or pending.
  *
  * @ingroup call_control
 **/
 bool_t linphone_core_in_call(const LinphoneCore *lc){
-       return lc->call!=NULL;
+       return linphone_core_get_current_call((LinphoneCore *)lc)!=NULL;
 }
 
 /**
@@ -2427,12 +2332,134 @@ bool_t linphone_core_in_call(const LinphoneCore *lc){
  *
  * @ingroup call_control
 **/
-struct _LinphoneCall *linphone_core_get_current_call(LinphoneCore *lc)
+LinphoneCall *linphone_core_get_current_call(LinphoneCore *lc)
 {
-       if(linphone_core_in_call(lc))
-               return lc->call;
-       else
-               return NULL;
+       if(lc->current_call != NULL)
+               return lc->current_call;
+       return NULL;
+}
+
+/**
+ * Permits to pause the call
+ *
+ * @ingroup call_control
+**/
+int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *the_call)
+{
+       LinphoneCall *call = the_call;
+       if(lc == NULL)
+       {
+               ms_error("LinphoneCore was null\n");
+               return -1;
+       }
+       if(call == NULL)
+       {
+               if(linphone_core_in_call(lc))
+               {
+                       call = linphone_core_get_current_call(lc);
+               }
+               else
+               {
+                       ms_error("LinphoneCall was null\n");
+                       return -2;
+               }
+       }
+       if(linphone_core_get_current_call(lc) != call)
+       {
+               ms_error("The call asked to be paused was not the current on\n");
+               return -3;
+       }
+       sal_call_hold(call->op,TRUE);
+       call->state = LinphoneCallPaused;
+       linphone_core_unset_the_current_call(lc);
+       linphone_core_stop_media_streams(lc,call);
+       lc->vtable.display_status(lc,_("Pause the current call"));
+       return 0;
+}
+
+/**
+ * Permits to resume the call
+ *
+ * @ingroup call_control
+**/
+int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call)
+{
+       char temp[255];
+       LinphoneCall *call = the_call;
+       if(lc == NULL)
+       {
+               ms_error("LinphoneCore was null\n");
+               return -1;
+       }
+       if(call == NULL)
+       {
+               MSList *calls = linphone_core_get_calls(lc);
+               if(ms_list_size(calls) == 1)
+               {
+                       call = ((LinphoneCall *)calls->data);
+                       ms_list_free(calls);
+               }
+               else
+               {
+                       ms_error("LinphoneCall was null\n");
+                       ms_list_free(calls);
+                       return -2;
+               }
+       }
+       if(linphone_core_get_current_call(lc) != NULL)
+       {
+               ms_error("There is already a call in process pause or stop it first\n");
+               return -3;
+       }
+       linphone_core_init_media_streams(lc,call);
+       sal_call_hold(call->op,FALSE);
+       call->state = LinphoneCallAVRunning;
+       linphone_core_set_as_current_call(lc,call);
+       linphone_core_start_media_streams(lc,call);
+       snprintf(temp,sizeof(temp),"Resume the call with %s",linphone_call_get_remote_address_as_string(call));
+       lc->vtable.display_status(lc,temp);
+       
+       return 0;
+}
+
+/**
+ * Compare the remote address with the one in call
+ * 
+ * @param a the call
+ * @param b the remote address to compare with
+ * @return 0 if it's the good call else 1
+ */
+static int linphone_call_remote_address_compare(const void * a, const void * b)
+{
+       if(b == NULL || a ==NULL)
+               return 1;
+       char *the_remote_address = ((char *)b);
+       LinphoneCall *call = ((LinphoneCall *)a);
+#ifdef DEBUG 
+       ms_message("the remote address:%s\n",the_remote_address);
+       ms_message("the call:%p => %s\n",call,linphone_call_get_remote_address_as_string(call));
+#endif
+       if(!strcmp(linphone_call_get_remote_address_as_string(call),the_remote_address))
+       {
+               return 0;
+       }
+       return 1;
+}
+
+/**
+ * Get the call with the remote_address specified
+ * @param lc
+ * @param remote_address
+ * @return the LinphoneCall of the call if found
+ */
+LinphoneCall *linphone_core_get_call_by_remote_address(LinphoneCore *lc, const char *remote_address){
+
+       MSList *the_call = ms_list_find_custom(lc->calls,linphone_call_remote_address_compare,(void *)remote_address);
+       if(the_call != NULL)
+       {
+               return ((LinphoneCall *)the_call->data);
+       }
+       return NULL;
 }
 
 int linphone_core_send_publish(LinphoneCore *lc,
@@ -2906,7 +2933,7 @@ void linphone_core_send_dtmf(LinphoneCore *lc, char dtmf)
        }
        if (linphone_core_get_use_info_for_dtmf(lc)!=0){
                /* Out of Band DTMF (use INFO method) */
-               LinphoneCall *call=lc->call;
+               LinphoneCall *call=linphone_core_get_current_call(lc);
                if (call==NULL){
                        return;
                }
@@ -3516,9 +3543,9 @@ LpConfig *linphone_core_get_config(LinphoneCore *lc){
 
 static void linphone_core_uninit(LinphoneCore *lc)
 {
-       if (lc->call){
+       if(linphone_core_get_calls_nb(lc)){
                int i;
-               linphone_core_terminate_call(lc,NULL);
+               linphone_core_terminate_all_calls(lc);
                for(i=0;i<10;++i){
 #ifndef WIN32
                        usleep(50000);
@@ -3600,4 +3627,105 @@ void linphone_core_destroy(LinphoneCore *lc){
        linphone_core_uninit(lc);
        ms_free(lc);
 }
+/**
+ * Get the number of Call
+ *
+ * @ingroup call_control
+**/
+int linphone_core_get_calls_nb(const LinphoneCore *lc)
+{
+       int returned;
+       if(lc->calls == NULL)
+       {
+               returned = 0;
+       }
+       else
+       {
+               returned = ms_list_size(lc->calls);
+       }
+       return returned;
+}
+
+/**
+ * Check if we do not have exceed the number of simultaneous call
+ *
+ * @ingroup call_control
+**/
+bool_t linphone_core_can_we_add_call(LinphoneCore *lc)
+{
+       if(linphone_core_get_calls_nb(lc) < NB_MAX_CALLS)
+               return TRUE;
+       return FALSE;
+}
+
+/**
+ * Unset the current call
+ *
+ * @ingroup call_control
+**/
+int linphone_core_unset_the_current_call(LinphoneCore *lc)
+{
+       if(lc->current_call == NULL)
+               return -1;
+       lc->current_call = NULL;
+       ms_message("Current call unset\n");
+       return 0;
+}
 
+/**
+ * Set the call in parameter as the new current call
+ *
+ * @ingroup call_control
+**/
+int linphone_core_set_as_current_call(LinphoneCore *lc, LinphoneCall *call)
+{
+       if(lc->current_call != NULL)
+               return -1;
+       lc->current_call = call;
+       return 0;
+}
+
+/**
+ * Add the call in the LinphoneCall list
+ *
+ * @ingroup call_control
+**/
+int linphone_core_add_call( LinphoneCore *lc, LinphoneCall *call)
+{
+       if(linphone_core_can_we_add_call(lc))
+       {
+               MSList *the_calls = lc->calls;
+               the_calls = ms_list_append(the_calls,(void *)call);
+               lc->calls = the_calls;
+               return 0;
+       }
+       return -1;
+}
+
+/**
+ * Add the call in the LinphoneCall list
+ *
+ * @ingroup call_control
+**/
+int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call)
+{
+       MSList *it;
+
+       MSList *the_calls = lc->calls;
+       if(call == linphone_core_get_current_call(lc))
+       {
+               linphone_core_unset_the_current_call(lc);
+       }       
+       it=ms_list_find(the_calls,call);
+       if (it) 
+       {
+               the_calls = ms_list_remove_link(the_calls,it);
+       }
+       else
+       {
+               ms_warning("could not find the call into the list\n");
+               return -1;
+       }
+       lc->calls = the_calls;
+       return 0;
+}