]> sjero.net Git - linphone/commitdiff
Merge branch 'master' into dev_multicall
authorSimon Morlat <simon.morlat@linphone.org>
Thu, 17 Jun 2010 10:35:47 +0000 (12:35 +0200)
committerSimon Morlat <simon.morlat@linphone.org>
Thu, 17 Jun 2010 10:35:47 +0000 (12:35 +0200)
Conflicts:
console/commands.c
coreapi/linphonecore.c
coreapi/linphonecore.h

24 files changed:
console/commands.c
console/linphonec.c
coreapi/Makefile.am
coreapi/callbacks.c
coreapi/chat.c
coreapi/exevents.c [deleted file]
coreapi/linphonecall.c [new file with mode: 0644]
coreapi/linphonecore.c
coreapi/linphonecore.h
coreapi/linphonecore_utils.h [new file with mode: 0644]
coreapi/lsd.c [new file with mode: 0644]
coreapi/presence.c
coreapi/private.h
coreapi/sal.h
coreapi/sal_eXosip2.c
coreapi/sal_eXosip2_sdp.c
coreapi/test_lsd.c [new file with mode: 0644]
gtk-glade/incall_view.c
gtk-glade/linphone.h
gtk-glade/main.c
gtk-glade/main.glade
pixmaps/Makefile.am
pixmaps/hold_off.png [new file with mode: 0644]
pixmaps/hold_on.png [new file with mode: 0644]

index 967e035786b5827e140b5b47afaeed586211b646..e6cdca2006e2a622ab862a036045c01dbfdc5e89 100644 (file)
@@ -78,6 +78,8 @@ static int lpc_cmd_ports(LinphoneCore *lc, char *args);
 static int lpc_cmd_speak(LinphoneCore *lc, char *args);
 static int lpc_cmd_codec(LinphoneCore *lc, char *args);
 static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args);
+static int lpc_cmd_pause(LinphoneCore *lc, char *args);
+static int lpc_cmd_resume(LinphoneCore *lc, char *args);
 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args);
 static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args);
 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args);
@@ -123,17 +125,21 @@ void linphonec_out(const char *fmt,...);
 LPC_COMMAND commands[] = {
        { "help", lpc_cmd_help, "Print commands help", NULL },
        { "call", lpc_cmd_call, "Call a SIP uri",
-               "'call <sip-url>' "
-               ": initiate a call to the specified destination."
+               "'call <sip-url>' \t: initiate a call to the specified destination.\n"
+               "'call show' \t: show all the current calls status.\n"
                },
        { "chat", lpc_cmd_chat, "Chat with a SIP uri",
                "'chat <sip-url> \"message\"' "
                ": send a chat message \"message\" to the specified destination."
                },
-       { "terminate", lpc_cmd_terminate, "Terminate the current call",
-               NULL },
+       { "terminate", lpc_cmd_terminate, "Terminate a call",
+               "'terminate' : Terminate the current call\n"
+               "'terminate <sip:XXX@XXX.XXX.XXX.XXX>' : Terminate the call with remote address\n"
+               "'terminate <all>' : Terminate all the current calls\n"
+               },
        { "answer", lpc_cmd_answer, "Answer a call",
-               "Accept an incoming call."
+               "'answer' : Answer the current incoming call\n"
+               "'answer <sip:XXX@XXX.XXX.XXX.XXX>' : Answer the call with remote address\n"
        },
        { "autoanswer", lpc_cmd_autoanswer, "Show/set auto-answer mode",
                "'autoanswer'       \t: show current autoanswer mode\n"
@@ -218,23 +224,28 @@ LPC_COMMAND commands[] = {
                        "'speak <voice name> <sentence>'        : speak a text using the specified espeak voice.\n"
                        "Example for english voice: 'speak default Hello my friend !'"
        },
-    { "codec", lpc_cmd_codec, "Codec configuration",
-            "'codec list' : list codecs\n"  
-            "'codec enable <index>' : enable available codec\n"  
-            "'codec disable <index>' : disable codecs" }, 
-    { "ec", lpc_cmd_echocancellation, "Echo cancellation",
-            "'ec on [<delay>] [<tail>] [<framesize>]' : turn EC on with given delay, tail length and framesize\n"
-            "'ec off' : turn echo cancellation (EC) off\n"
-            "'ec show' : show EC status" },
+       { "codec", lpc_cmd_codec, "Codec configuration",
+           "'codec list' : list codecs\n"  
+           "'codec enable <index>' : enable available codec\n"  
+           "'codec disable <index>' : disable codecs" }, 
+       { "ec", lpc_cmd_echocancellation, "Echo cancellation",
+           "'ec on [<delay>] [<tail>] [<framesize>]' : turn EC on with given delay, tail length and framesize\n"
+           "'ec off' : turn echo cancellation (EC) off\n"
+           "'ec show' : show EC status" },
+       { "pause", lpc_cmd_pause, "pause a call",
+               "'pause' : pause the current call\n"},
+       { "resume", lpc_cmd_resume, "resume a call",
+               "'resume' : resume the unique call\n"
+               "'resume <sip:XXX@XXX.XXX.XXX.XXX>' : hold off the call with cid <cid>\n"},
        { "mute", lpc_cmd_mute_mic, 
          "Mute microphone and suspend voice transmission."},
        { "unmute", lpc_cmd_unmute_mic, 
-         "Unmute microphone and resume voice transmission."},
+                 "Unmute microphone and resume voice transmission."},
        { "nortp-on-audio-mute", lpc_cmd_rtp_no_xmit_on_audio_mute,
-         "Set the rtp_no_xmit_on_audio_mute configuration parameter",
-         "   If set to 1 then rtp transmission will be muted when\n"
-         "   audio is muted , otherwise rtp is always sent."}, 
-       { (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
+                 "Set the rtp_no_xmit_on_audio_mute configuration parameter",
+                 "   If set to 1 then rtp transmission will be muted when\n"
+                 "   audio is muted , otherwise rtp is always sent."}, 
+    { (char *)NULL, (lpc_cmd_handler)NULL, (char *)NULL, (char *)NULL }
 };
 
 /***************************************************************************
@@ -385,14 +396,35 @@ lpc_cmd_call(LinphoneCore *lc, char *args)
        {
                return 0;
        }
-
-       if ( lc->call != NULL )
+       if(!strcmp(args,"show"))
        {
-               linphonec_out("Terminate current call first.\n");
+               MSList *calls = linphone_core_get_calls(lc);
+               if(calls)
+               {
+                       MSList *p_calls = calls;
+                       linphonec_out("<remote>\t\t\t\t<status>\r\n");
+                       while(p_calls != NULL)                  
+                       {
+                               linphonec_out("%s\t\t\t%s\r\n",
+                                               linphone_call_get_remote_address_as_string(p_calls->data),
+                                               (((LinphoneCall *)p_calls->data)==linphone_core_get_current_call(lc))?"yes":"no");
+                               p_calls = p_calls->next;
+                       }
+                       ms_list_free(calls);
+               }
+               else
+               {
+                       linphonec_out("No active call.\n");
+               }
        }
        else
        {
-               if ( -1 == linphone_core_invite(lc, args) )
+               if ( linphone_core_in_call(lc) )
+               {
+                       linphonec_out("Terminate or hold on the current call first.\n");
+                       return 1;
+               }
+               if ( NULL == linphone_core_invite(lc, args) )
                {
                        linphonec_out("Error from linphone_core_invite.\n");
                }
@@ -449,7 +481,7 @@ static int
 lpc_cmd_refer(LinphoneCore *lc, char *args)
 {
        if (args)
-               linphone_core_refer(lc, args);
+               linphone_core_refer(lc, linphone_core_get_current_call(lc), args);
        else{
                linphonec_out("refer needs an argument\n");
        }
@@ -459,21 +491,98 @@ lpc_cmd_refer(LinphoneCore *lc, char *args)
 static int
 lpc_cmd_terminate(LinphoneCore *lc, char *args)
 {
-       if ( -1 == linphone_core_terminate_call(lc, NULL) )
+       char *arg1 = args;
+       char *arg2 = NULL;
+       char *ptr = args;
+
+       if (!args)
        {
-               linphonec_out("No active call.\n");
+               if(linphone_core_in_call(lc))
+               {
+                       if ( -1 == linphone_core_terminate_call(lc, linphone_core_get_current_call(lc)) )
+                       {
+                               linphonec_out("Could not stop the active call.\n");
+                       }
+               }
+               else
+               {
+                       linphonec_out("No active call.\n");
+               }
+               return 1;
        }
-       return 1;
+       
+       /* Isolate first and second arg */
+       while(*ptr && !isspace(*ptr)) ++ptr;
+       if ( *ptr )
+       {
+               *ptr='\0';
+               arg2=ptr+1;
+               while(*arg2 && isspace(*arg2)) ++arg2;
+       }
+       if (arg1 != 0)
+       {
+               if(strcmp(arg1,"all")==0)
+               {
+                       linphonec_out("We are going to stop all the calls.\n");
+                       return (linphone_core_terminate_all_calls(lc)==0)?1:0;
+               }
+               else
+               {
+                       char the_remote_address[255];
+                       int n = sscanf(arg1, "%s", the_remote_address);
+                       if (n == 1)
+                       {
+                               if ( -1 == linphone_core_terminate_call(lc,linphone_core_get_call_by_remote_address(lc,the_remote_address)))
+                               {
+                                       linphonec_out("Cannot stop the call with %s.\n",the_remote_address);
+                               }
+                               return 1;
+                       }
+               }
+       }
+       return 0;
+       
 }
 
 static int
 lpc_cmd_answer(LinphoneCore *lc, char *args)
 {
-       if ( -1 == linphone_core_accept_call(lc, NULL) )
+       char *arg1 = args;
+       char *arg2 = NULL;
+       char *ptr = args;
+
+       if (!args)
+       {
+               //if just one call is present answer the only one in passing NULL to the linphone_core_accept_call ...
+               if ( -1 == linphone_core_accept_call(lc, NULL) )
+               {
+                       linphonec_out("No incoming call.\n");
+               }
+               return 1;
+       }
+
+       // Isolate first and second arg
+       while(*ptr && !isspace(*ptr)) ++ptr;
+       if ( *ptr )
        {
-               linphonec_out("No incoming call.\n");
+               *ptr='\0';
+               arg2=ptr+1;
+               while(*arg2 && isspace(*arg2)) ++arg2;
        }
-       return 1;
+       if (arg1 != 0)
+       {
+               char the_remote_address[256];
+               int n = sscanf(arg1, "%s", the_remote_address);
+               if (n == 1)
+               {
+                       if ( -1 == linphone_core_accept_call(lc, linphone_core_get_call_by_remote_address(lc,the_remote_address)) )
+                       {
+                               linphonec_out("Cannot answer the call from %s.\n",the_remote_address);
+                       }
+                       return 1;
+               }
+       }
+       return 0;
 }
 
 static int
@@ -1074,7 +1183,62 @@ lpc_cmd_staticpic(LinphoneCore *lc, char *args)
        return 0; /* Syntax error */
 }
 
+static int lpc_cmd_pause(LinphoneCore *lc, char *args){
 
+       if(linphone_core_in_call(lc))
+       {
+               linphone_core_pause_call(lc,linphone_core_get_current_call(lc));
+               return 1;
+       }
+       linphonec_out("you can only pause when a call is in process\n");
+    return 0;
+}
+
+static int lpc_cmd_resume(LinphoneCore *lc, char *args){
+       
+       if(linphone_core_in_call(lc))
+       {
+               linphonec_out("There is already a call in process pause or stop it first");
+       }
+       if (args)
+       {
+               char the_remote_address[255];
+               int n = sscanf(args, "%s", the_remote_address);
+               if (n == 1)
+               {
+                       if(linphone_core_resume_call(lc,linphone_core_get_call_by_remote_address(lc,the_remote_address)) < 0)
+                       {
+                               linphonec_out("There was a problem to resume the call check the remote address you gave %s\n",args);
+                               return 0;
+                       }
+                       else
+                       {
+                               return 1;
+                       }
+               }
+       }
+       else
+       {
+               int returned = 0;
+               MSList *calls = linphone_core_get_calls(lc);
+               if(ms_list_size(calls) == 1)
+               {
+                       if(linphone_core_resume_call(lc,calls->data) < 0)
+                       {
+                               linphonec_out("There was a problem to resume the unique call \n");
+                               returned = 0;
+                       }
+                       else
+                       {
+                               returned = 1;
+                       }
+                       ms_list_free(calls);
+                       return returned;
+               }
+       }
+       return 0;
+    
+}
 
 /***************************************************************************
  *
@@ -1835,16 +1999,13 @@ static int lpc_cmd_echocancellation(LinphoneCore *lc, char *args){
 
 static int lpc_cmd_mute_mic(LinphoneCore *lc, char *args)
 {
-  if ( lc->call != NULL )
-    linphone_core_mute_mic(lc, 1);
-  return 1;
+       linphone_core_mute_mic(lc, 1);
+       return 1;
 }
 
-static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args)
-{
-  if ( lc->call != NULL )
-    linphone_core_mute_mic(lc, 0);
-  return 1;
+static int lpc_cmd_unmute_mic(LinphoneCore *lc, char *args){
+       linphone_core_mute_mic(lc, 0);
+       return 1;
 }
 
 static int lpc_cmd_rtp_no_xmit_on_audio_mute(LinphoneCore *lc, char *args)
index 2d1ce98b31640c079acac2d24c5b4973fd20973b..024075cf06843a0f3e9f288fc9bff4e390b6dcf3 100644 (file)
@@ -112,25 +112,30 @@ static char **linephonec_readline_completion(const char *text,
 #endif
 
 /* These are callback for linphone core */
-static void linphonec_call_received(LinphoneCore *lc, const char *from);
+static void linphonec_call_received(LinphoneCore *lc, LinphoneCall *call);
+static void linphonec_paused_received(LinphoneCore *lc, LinphoneCall *call);
+static void linphonec_resumed_received(LinphoneCore *lc, LinphoneCall *call);
 static void linphonec_prompt_for_auth(LinphoneCore *lc, const char *realm,
        const char *username);
-static void linphonec_display_refer (LinphoneCore * lc,const char *refer_to);
+static void linphonec_display_refer (LinphoneCore * lc,LinphoneCall *call, const char *refer_to);
 static void linphonec_display_something (LinphoneCore * lc, const char *something);
 static void linphonec_display_url (LinphoneCore * lc, const char *something, const char *url);
 static void linphonec_display_warning (LinphoneCore * lc, const char *something);
 static void stub () {}
 static void linphonec_notify_received(LinphoneCore *lc,const char *from,const char *msg);
+static void linphonec_ack_paused_received(LinphoneCore *lc, LinphoneCall *call);
+static void linphonec_ack_resumed_received(LinphoneCore *lc, LinphoneCall *call);
 static void linphonec_notify_presence_received(LinphoneCore *lc,LinphoneFriend *fid);
 static void linphonec_new_unknown_subscriber(LinphoneCore *lc,
                LinphoneFriend *lf, const char *url);
-static void linphonec_bye_received(LinphoneCore *lc, const char *from);
+static void linphonec_bye_received(LinphoneCore *lc, LinphoneCall *call);
 static void linphonec_text_received(LinphoneCore *lc, LinphoneChatRoom *cr,
                const char *from, const char *msg);
 static void linphonec_display_status (LinphoneCore * lc, const char *something);
 static void linphonec_general_state (LinphoneCore * lc, LinphoneGeneralState *gstate);
 static void linphonec_dtmf_received(LinphoneCore *lc, int dtmf);
 static void print_prompt(LinphoneCore *opm);
+void linphonec_out(const char *fmt,...);
 /***************************************************************************
  *
  * Global variables
@@ -176,7 +181,14 @@ LinphoneCoreVTable linphonec_vtable
        .show =(ShowInterfaceCb) stub,
        .inv_recv = linphonec_call_received,
        .bye_recv = linphonec_bye_received,
+       .ringing_recv = (RingingReceivedCb) stub,
+       .connected_recv = (ConnectedReceivedCb) stub,
+       .failure_recv = (FailureReceivedCb) stub,
+       .paused_recv = linphonec_paused_received,
+       .resumed_recv = linphonec_resumed_received,
        .notify_recv = linphonec_notify_received,
+       .ack_paused_recv = linphonec_ack_paused_received,
+       .ack_resumed_recv = linphonec_ack_resumed_received,
        .notify_presence_recv = linphonec_notify_presence_received,
        .new_unknown_subscriber = linphonec_new_unknown_subscriber,
        .auth_info_requested = linphonec_prompt_for_auth,
@@ -209,7 +221,7 @@ LinphoneCoreVTable linphonec_vtable
  * Linphone core callback
  */
 static void
-linphonec_display_refer (LinphoneCore * lc,const char *refer_to)
+linphonec_display_refer (LinphoneCore * lc,LinphoneCall *call, const char *refer_to)
 {
        fprintf (stdout, "The distant end point asked to transfer the call to %s,don't forget to terminate the call if not\n%s", refer_to,prompt);
        fflush(stdout);
@@ -259,13 +271,43 @@ linphonec_display_url (LinphoneCore * lc, const char *something, const char *url
  * Linphone core callback
  */
 static void
-linphonec_call_received(LinphoneCore *lc, const char *from)
+linphonec_call_received(LinphoneCore *lc, LinphoneCall *call)
 {
+       char *from=linphone_call_get_remote_address_as_string(call);
        linphonec_set_caller(from);
+       ms_free(from);
        if ( auto_answer)  {
                answer_call=TRUE;
        }
 }
+/*
+ * Linphone core callback
+ */
+static void
+linphonec_paused_received(LinphoneCore *lc, LinphoneCall *call)
+{
+       char *from=linphone_call_get_remote_address_as_string(call);
+       if(from)
+       {
+               linphonec_out("the call from %s have been paused\n",from);
+               ms_free(from);
+       }
+}
+/*
+ * Linphone core callback
+ */
+static void
+linphonec_resumed_received(LinphoneCore *lc, LinphoneCall *call)
+{
+       char *from=linphone_call_get_remote_address_as_string(call);
+       if(from)
+       {
+               linphonec_out("the call from %s have been resumed\n",from);
+               ms_free(from);
+       }
+}
+
+
 
 /*
  * Linphone core callback
@@ -306,6 +348,34 @@ linphonec_notify_received(LinphoneCore *lc,const char *from,const char *msg)
        }
 }
 
+/*
+ * Linphone core callback
+ */
+static void
+linphonec_ack_paused_received(LinphoneCore *lc, LinphoneCall *call)
+{
+       char *from=linphone_call_get_remote_address_as_string(call);
+       if(from)
+       {
+               linphonec_out("the previous pause sent to %s has been acknowledged\n",from);
+               ms_free(from);
+       }
+}
+
+/*
+ * Linphone core callback
+ */
+static void
+linphonec_ack_resumed_received(LinphoneCore *lc, LinphoneCall *call)
+{
+       char *from=linphone_call_get_remote_address_as_string(call);
+       if(from)
+       {
+               linphonec_out("the previous resume sent to %s has been acknowledged\n",from);
+               ms_free(from);
+       }
+}
+
 /*
  * Linphone core callback
  */
@@ -336,13 +406,15 @@ linphonec_new_unknown_subscriber(LinphoneCore *lc, LinphoneFriend *lf,
  * Linphone core callback
  */
 static void
-linphonec_bye_received(LinphoneCore *lc, const char *from)
+linphonec_bye_received(LinphoneCore *lc, LinphoneCall *call)
 {
        // Should change prompt back to original maybe
 
        // printing this is unneeded as we'd get a "Communication ended"
        // message trough display_status callback anyway
-       //printf("Bye received from %s\n", from);
+       char *from=linphone_call_get_remote_address_as_string(call);
+       printf("Bye received from %s\n", from);
+       ms_free(from);
 }
 
 /*
index 014ae308e0398d154b22e3feabb51b6b1e7c6901..31094d71e651a692bcbf2e186dffea62d4327786 100644 (file)
@@ -6,7 +6,7 @@ EXTRA_DIST=linphonecore_jni.cc
 ## Process this file with automake to produce Makefile.in
 linphone_includedir=$(includedir)/linphone
 
-linphone_include_HEADERS=linphonecore.h ../config.h lpconfig.h sipsetup.h
+linphone_include_HEADERS=linphonecore.h linphonecore_utils.h ../config.h lpconfig.h sipsetup.h
 
 INCLUDES = \
        -I$(top_srcdir)\
@@ -33,8 +33,10 @@ liblinphone_la_SOURCES=\
        lpconfig.c lpconfig.h \
        chat.c \
        general_state.c \
+       linphonecall.c \
        sipsetup.c sipsetup.h \
-       siplogin.c
+       siplogin.c \
+       lsd.c linphonecore_utils.h
 
 
 liblinphone_la_LDFLAGS= -version-info $(LIBLINPHONE_SO_VERSION) -no-undefined
@@ -48,6 +50,11 @@ if BUILD_WIN32
 liblinphone_la_LIBADD+=$(top_builddir)/oRTP/src/libortp.la
 endif
 
+noinst_PROGRAMS=test_lsd
+
+test_lsd_SOURCES=test_lsd.c
+
+test_lsd_LDADD=liblinphone.la
 
 AM_CFLAGS=$(STRICT_OPTIONS)  -DIN_LINPHONE \
        $(ORTP_CFLAGS) \
index 531f4542e9a7b41061e5dbda7c847b064da04d4a..eb2589c71417f6974c74376d2afa25cae5bf2bb5 100644 (file)
@@ -30,12 +30,19 @@ static void linphone_connect_incoming(LinphoneCore *lc, LinphoneCall *call){
                lc->vtable.show(lc);
        if (lc->vtable.display_status)
                lc->vtable.display_status(lc,_("Connected."));
-       call->state=LCStateAVRunning;
+       if (lc->vtable.connected_recv)
+               lc->vtable.connected_recv(lc,call);
+       call->state=LinphoneCallAVRunning;
        if (lc->ringstream!=NULL){
                ring_stop(lc->ringstream);
                lc->ringstream=NULL;
        }
-       linphone_core_start_media_streams(lc,call);
+       if(!linphone_core_in_call(lc))
+       {
+               linphone_core_set_as_current_call(lc,call);
+       }
+       if(call == linphone_core_get_current_call(lc))
+               linphone_core_start_media_streams(lc,call);
 }
 
 static void call_received(SalOp *h){
@@ -66,7 +73,7 @@ static void call_received(SalOp *h){
                sal_op_release(h);
                return;
        }
-       if (lc->call!=NULL){/*busy*/
+       if (!linphone_core_can_we_add_call(lc)){/*busy*/
                sal_call_decline(h,SalReasonBusy,NULL);
                sal_op_release(h);
                return;
@@ -75,17 +82,24 @@ static void call_received(SalOp *h){
        to=sal_op_get_to(h);
        
        call=linphone_call_new_incoming(lc,linphone_address_new(from),linphone_address_new(to),h);
-       lc->call=call;
+       
+       if(linphone_core_get_current_call(lc)!=NULL) //we are already in call just inform that an incoming call is going on
+       {
+               char temp[256];
+               snprintf(temp,sizeof(temp)-1,"A new incoming call from %s during call",from);
+               lc->vtable.display_status(lc,temp);
+       }
        sal_call_set_local_media_description(h,call->localdesc);
        call->resultdesc=sal_call_get_final_media_description(h);
        if (call->resultdesc)
                sal_media_description_ref(call->resultdesc);
        if (call->resultdesc && sal_media_description_empty(call->resultdesc)){
                sal_call_decline(h,SalReasonMedia,NULL);
-               linphone_call_destroy(call);
-               lc->call=NULL;
+               linphone_call_unref(call);
                return;
        }
+       /* the call is acceptable so we can now add it to our list */
+       linphone_core_add_call(lc,call);
        
        from_parsed=linphone_address_new(sal_op_get_from(h));
        linphone_address_clean(from_parsed);
@@ -99,31 +113,41 @@ static void call_received(SalOp *h){
            lc->vtable.display_status(lc,barmesg);
 
        /* play the ring */
-       if (lc->sound_conf.ring_sndcard!=NULL){
-               ms_message("Starting local ring...");
-               lc->ringstream=ring_start(lc->sound_conf.local_ring,2000,lc->sound_conf.ring_sndcard);
+       if (lc->sound_conf.ring_sndcard!=NULL && !linphone_core_in_call(lc)){
+               if(lc->ringstream==NULL){
+                       MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
+                       ms_message("Starting local ring...");
+                       lc->ringstream=ring_start(lc->sound_conf.local_ring,2000,ringcard);
+               }
+               else
+               {
+                       ms_message("the local ring is already started");
+               }
        }
-       linphone_call_set_state(call,LCStateRinging);
+       call->state=LinphoneCallRinging;
        sal_call_notify_ringing(h);
-       linphone_core_init_media_streams(lc,lc->call);
-       if (lc->vtable.inv_recv) lc->vtable.inv_recv(lc,tmp);
+       linphone_core_init_media_streams(lc,call);
+       if (lc->vtable.inv_recv) lc->vtable.inv_recv(lc,call);
        ms_free(barmesg);
        ms_free(tmp);
 }
 
 static void call_ringing(SalOp *h){
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h));
-       LinphoneCall *call=lc->call;
+       LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(h);
        SalMediaDescription *md;
        if (call==NULL) return;
        if (lc->vtable.display_status)
                lc->vtable.display_status(lc,_("Remote ringing."));
+       if (lc->vtable.ringing_recv)
+               lc->vtable.ringing_recv(lc,call);
        md=sal_call_get_final_media_description(h);
        if (md==NULL){
                if (lc->ringstream!=NULL) return;       /*already ringing !*/
                if (lc->sound_conf.play_sndcard!=NULL){
+                       MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
                        ms_message("Remote ringing...");
-                       lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,lc->sound_conf.play_sndcard);
+                       lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,ringcard);
                        gstate_new_state(lc, GSTATE_CALL_OUT_RINGING, NULL);
                }
        }else{
@@ -144,30 +168,38 @@ static void call_ringing(SalOp *h){
                        lc->ringstream=NULL;
                }
                ms_message("Doing early media...");
-               linphone_core_start_media_streams(lc,call);
+               if(call == linphone_core_get_current_call(lc))
+                       linphone_core_start_media_streams(lc,call);
                call->media_pending=TRUE;
        }
-       call->state=LCStateRinging;
+       call->state=LinphoneCallRinging;
 }
 
+/*
+ * could be reach :
+ *  - when the call is accepted
+ *  - when a request is accepted (pause, resume)
+ */
 static void call_accepted(SalOp *op){
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
-       LinphoneCall *call=lc->call;
+       LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
        if (call==NULL){
                ms_warning("No call to accept.");
                return ;
        }
-       if (sal_op_get_user_pointer(op)!=lc->call){
-               ms_warning("call_accepted: ignoring.");
-               return;
-       }
-       if (call->state==LCStateAVRunning){
-               return ; /*already accepted*/
+       if (call->state==LinphoneCallAVRunning){
+               ms_message("GET ACK of resume\n");
+               if(lc->vtable.ack_resumed_recv)
+                       lc->vtable.ack_resumed_recv(lc,call);
+               return ; //already accepted
        }
-       if (lc->audiostream->ticker!=NULL){
+       if ((lc->audiostream!=NULL) && (lc->audiostream->ticker!=NULL)){
                /*case where we accepted early media */
-               linphone_core_stop_media_streams(lc,call);
-               linphone_core_init_media_streams(lc,call);
+               if(call == linphone_core_get_current_call(lc))
+               {
+                       linphone_core_stop_media_streams(lc,call);
+                       linphone_core_init_media_streams(lc,call);
+               }
        }
        if (call->resultdesc)
                sal_media_description_unref(call->resultdesc);
@@ -177,8 +209,19 @@ static void call_accepted(SalOp *op){
                call->media_pending=FALSE;
        }
        if (call->resultdesc && !sal_media_description_empty(call->resultdesc)){
-               gstate_new_state(lc, GSTATE_CALL_OUT_CONNECTED, NULL);
-               linphone_connect_incoming(lc,call);
+               //if we initiate a pause
+               if(call->state == LinphoneCallPaused)
+               {
+                       ms_message("GET ACK of pause\n");
+                       if(lc->vtable.ack_paused_recv)
+                               lc->vtable.ack_paused_recv(lc,call);
+               }//if there is an accepted incoming call
+               else
+               {
+                       linphone_core_set_as_current_call (lc,call);
+                       gstate_new_state(lc, GSTATE_CALL_OUT_CONNECTED, NULL);
+                       linphone_connect_incoming(lc,call);
+               }               
        }else{
                /*send a bye*/
                ms_error("Incompatible SDP offer received in 200Ok, need to abort the call");
@@ -188,20 +231,19 @@ static void call_accepted(SalOp *op){
 
 static void call_ack(SalOp *op){
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
-       LinphoneCall *call=lc->call;
+       LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
        if (call==NULL){
                ms_warning("No call to be ACK'd");
                return ;
        }
-       if (sal_op_get_user_pointer(op)!=lc->call){
-               ms_warning("call_ack: ignoring.");
-               return;
-       }
        if (call->media_pending){
                if (lc->audiostream->ticker!=NULL){
                        /*case where we accepted early media */
-                       linphone_core_stop_media_streams(lc,call);
-                       linphone_core_init_media_streams(lc,call);
+                       if(call == linphone_core_get_current_call(lc))
+                       {
+                               linphone_core_stop_media_streams(lc,call);
+                               linphone_core_init_media_streams(lc,call);
+                       }
                }
                if (call->resultdesc)
                        sal_media_description_unref(call->resultdesc);
@@ -223,14 +265,45 @@ static void call_ack(SalOp *op){
 static void call_updated(SalOp *op){
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
        LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
-       linphone_core_stop_media_streams(lc,call);
-       linphone_core_init_media_streams(lc,call);
        if (call->resultdesc)
                sal_media_description_unref(call->resultdesc);
        call->resultdesc=sal_call_get_final_media_description(op);
-       if (call->resultdesc){
+       if (call->resultdesc)
                sal_media_description_ref(call->resultdesc);
-               if (!sal_media_description_empty(call->resultdesc)){
+
+       if (call->resultdesc && !sal_media_description_empty(call->resultdesc))
+       {
+               if( (call->state == LinphoneCallPaused) && strcmp(call->resultdesc->addr,"0.0.0.0"))
+               {
+                       if(lc->vtable.display_status)
+                               lc->vtable.display_status(lc,"we have been resumed...");
+                       call->state = LinphoneCallAVRunning;
+                       lc->vtable.resumed_recv(lc,call);
+                       //we have to keep sending when holded
+                       //linphone_core_start_media_streams(lc,call);
+               }
+               else if( (call->state != LinphoneCallPaused) && !strcmp(call->resultdesc->addr,"0.0.0.0"))
+               {
+                       if(lc->vtable.display_status)
+                               lc->vtable.display_status(lc,"we have been paused...");
+                       call->state = LinphoneCallPaused;
+                       lc->vtable.paused_recv(lc,call);
+                       //we have to keep sending when holded
+                       /*
+                       if(call == linphone_core_get_current_call(lc))
+                       {
+                               linphone_core_stop_media_streams(lc,call);
+                               linphone_core_init_media_streams(lc,call);
+                       }
+                       */
+               }
+               else
+               {
+                       if(call == linphone_core_get_current_call(lc))
+                       {
+                               linphone_core_stop_media_streams(lc,call);
+                               linphone_core_init_media_streams(lc,call);
+                       }
                        linphone_connect_incoming(lc,call);
                }
        }
@@ -238,33 +311,39 @@ static void call_updated(SalOp *op){
 
 static void call_terminated(SalOp *op, const char *from){
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
-       if (sal_op_get_user_pointer(op)!=lc->call){
+       LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
+       if (linphone_call_get_state(call)==LinphoneCallTerminated){
                ms_warning("call_terminated: ignoring.");
                return;
        }
        ms_message("Current call terminated...");
-       if (lc->ringstream!=NULL) {
+       //we stop the call only if we have this current call or if we are in call
+       if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls)  == 1) || linphone_core_in_call(lc) )) {
                ring_stop(lc->ringstream);
                lc->ringstream=NULL;
        }
-       linphone_core_stop_media_streams(lc,lc->call);
-       lc->vtable.show(lc);
-       lc->vtable.display_status(lc,_("Call terminated."));
+       if(call == linphone_core_get_current_call(lc))
+               linphone_core_stop_media_streams(lc,call);
+       if (lc->vtable.show!=NULL)
+               lc->vtable.show(lc);
+       if (lc->vtable.display_status!=NULL)
+               lc->vtable.display_status(lc,_("Call terminated."));
+       call->state=LinphoneCallTerminated;
        gstate_new_state(lc, GSTATE_CALL_END, NULL);
        if (lc->vtable.bye_recv!=NULL){
                LinphoneAddress *addr=linphone_address_new(from);
                char *tmp;
                linphone_address_clean(addr);
                tmp=linphone_address_as_string(addr);
-               lc->vtable.bye_recv(lc,tmp);
+               if (lc->vtable.bye_recv!=NULL)
+                       lc->vtable.bye_recv(lc,call);
                ms_free(tmp);
                linphone_address_destroy(addr);
        }
-       linphone_call_destroy(lc->call);
-       lc->call=NULL;
+       linphone_call_set_terminated(call);
 }
 
-static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details){
+static void call_failure(SalOp *op, SalError error, SalReason sr, const char *details, int code){
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
        char *msg486=_("User is busy.");
        char *msg480=_("User is temporarily unavailable.");
@@ -272,12 +351,8 @@ static void call_failure(SalOp *op, SalError error, SalReason sr, const char *de
        char *msg600=_("User does not want to be disturbed.");
        char *msg603=_("Call declined.");
        char *msg=(char*)details;
-       LinphoneCall *call=lc->call;
+       LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
 
-       if (sal_op_get_user_pointer(op)!=lc->call){
-               ms_warning("call_failure: ignoring.");
-               return;
-       }
        if (lc->vtable.show) lc->vtable.show(lc);
 
        if (error==SalErrorNoResponse){
@@ -328,16 +403,18 @@ static void call_failure(SalOp *op, SalError error, SalReason sr, const char *de
                                        lc->vtable.display_status(lc,_("Call failed."));
                }
        }
+       if (lc->vtable.failure_recv)
+               lc->vtable.failure_recv(lc,call,code);
        if (lc->ringstream!=NULL) {
                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);
        if (call!=NULL) {
-               linphone_call_destroy(call);
                if (sr!=SalReasonDeclined) gstate_new_state(lc, GSTATE_CALL_ERROR, msg);
                else gstate_new_state(lc, GSTATE_CALL_END, NULL);
-               lc->call=NULL;
+               linphone_call_set_terminated(call);
        }
 }
 
@@ -406,8 +483,9 @@ static void dtmf_received(SalOp *op, char dtmf){
 
 static void refer_received(Sal *sal, SalOp *op, const char *referto){
        LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal);
+       LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op);
        if (lc->vtable.refer_received){
-               lc->vtable.refer_received(lc,referto);
+               lc->vtable.refer_received(lc,call,referto);
                if (op) sal_refer_accept(op);
        }
 }
@@ -450,10 +528,14 @@ static void ping_reply(SalOp *op){
        LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op);
        ms_message("ping reply !");
        if (call){
-               if (call->state==LCStatePreEstablishing){
+               if (call->state==LinphoneCallPreEstablishing){
                        linphone_core_start_invite(call->core,call,NULL);
                }
        }
+       else
+       {
+               ms_warning("ping reply without call attached...");
+       }
 }
 
 SalCallbacks linphone_sal_callbacks={
index 73a5f7c9a1ef08205c46d87613de7adbe253ab94..9ee70482c1b2e938d424582e9ef40c6953927628 100644 (file)
@@ -55,7 +55,7 @@ void linphone_chat_room_send_message(LinphoneChatRoom *cr, const char *msg){
        if(linphone_core_is_in_communication_with(cr->lc,cr->peer))
        {
                ms_message("send SIP message into the call\n");
-               op = cr->lc->call->op;
+               op = (linphone_core_get_current_call(cr->lc))->op;
        }
        else
        {
diff --git a/coreapi/exevents.c b/coreapi/exevents.c
deleted file mode 100644 (file)
index 24e8309..0000000
+++ /dev/null
@@ -1,1189 +0,0 @@
-/*
-linphone
-Copyright (C) 2000  Simon MORLAT (simon.morlat@free.fr)
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-*/
-
-#include "exevents.h"
-#include "linphonecore.h"
-#include "private.h"
-#include "mediastreamer2/mediastream.h"
-#include <eXosip2/eXosip.h>
-#include <osipparser2/osip_message.h>
-#include <osipparser2/osip_parser.h>
-
-static int linphone_answer_sdp(LinphoneCore *lc, eXosip_event_t *ev, sdp_message_t *sdp);
-
-static bool_t linphone_call_matches_event(LinphoneCall *call, eXosip_event_t *ev){
-       return call->cid==ev->cid;
-}
-
-static void linphone_call_proceeding(LinphoneCore *lc, eXosip_event_t *ev){
-       if (lc->call==NULL || (lc->call->cid!=-1 && !linphone_call_matches_event(lc->call,ev)) ) {
-               ms_warning("This call has been canceled: call=%p, call->cid=%i, ev->cid=%i",
-                                  lc->call,lc->call?lc->call->cid:-1,ev->cid);
-               eXosip_lock();
-               eXosip_call_terminate(ev->cid,ev->did);
-               eXosip_unlock();
-               return;
-       }
-       lc->call->cid=ev->cid;
-       lc->call->did=ev->did;
-       lc->call->tid=ev->tid;
-}
-
-static void linphone_connect_incoming(LinphoneCore *lc){
-       lc->vtable.show(lc);
-       lc->vtable.display_status(lc,_("Connected."));
-       lc->call->state=LCStateAVRunning;
-       if (lc->ringstream!=NULL){
-               ring_stop(lc->ringstream);
-               lc->ringstream=NULL;
-       }
-       if (lc->audiostream->ticker!=NULL){
-               /*case where we accepted early media */
-               linphone_core_stop_media_streams(lc);
-               linphone_core_init_media_streams(lc);
-       }
-       linphone_core_start_media_streams(lc,lc->call);
-}
-
-int linphone_call_accepted(LinphoneCore *lc, eXosip_event_t *ev)
-{
-       LinphoneCall *call=lc->call;
-       sdp_message_t *sdp;
-       const char *sdpanswer=NULL;
-       osip_message_t *msg=NULL;
-       int err;
-       if (call==NULL){
-               ms_warning("No call to accept.");
-               return 0;
-       }
-       linphone_call_proceeding(lc,ev);
-       if (!linphone_call_matches_event(lc->call,ev)) return 0;
-       call->auth_pending=FALSE;
-       if (call->state==LCStateAVRunning){
-               return 0; /*already accepted*/
-       }
-       linphone_call_init_media_params(call);
-       sdp=eXosip_get_sdp_info(ev->response);
-       if (!lc->sip_conf.sdp_200_ack){
-               err=0;
-               sdp_context_read_answer(call->sdpctx,sdp);
-       }else{
-               /*we receive a 200OK with an sdp offer*/
-               err=linphone_answer_sdp(lc,ev,sdp);
-               if (err==0) sdpanswer=call->sdpctx->answerstr;
-       }
-       if (err==0){
-               gstate_new_state(lc, GSTATE_CALL_OUT_CONNECTED, NULL);
-               linphone_connect_incoming(lc);
-       }
-       /*send the ack once streams are started*/
-       eXosip_call_build_ack(ev->did,&msg);
-       if (sdpanswer!=NULL) linphone_set_sdp(msg,sdpanswer);
-       eXosip_call_send_ack(ev->did,msg);
-       if (err!=0){
-               /*send a bye*/
-               ms_error("Incompatible SDP offer received in 200Ok, need to abort the call");
-               linphone_core_terminate_call(lc,NULL);
-       }
-       sdp_message_free(sdp);
-       return 0;
-}
-
-
-int linphone_call_terminated(LinphoneCore *lc, eXosip_event_t *ev)
-{
-       /*stop ringing if necessary*/
-       if (lc->call!=NULL){
-               if (lc->call->cid!=ev->cid){
-                       /* this is not current call */
-                       ms_message("call %i terminated, this was not current call.",ev->cid);
-                       return 0;
-               }
-       }
-
-       ms_message("Current call terminated...");
-       if (lc->ringstream!=NULL) {
-               ring_stop(lc->ringstream);
-               lc->ringstream=NULL;
-       }
-       linphone_core_stop_media_streams(lc);
-       lc->vtable.show(lc);
-       lc->vtable.display_status(lc,_("Call terminated."));
-       gstate_new_state(lc, GSTATE_CALL_END, NULL);
-       if (lc->vtable.bye_recv!=NULL){
-               char *from;
-               osip_from_to_str(ev->request->from,&from);
-               lc->vtable.bye_recv(lc,from);
-               osip_free(from);
-       }
-       if (lc->call!=NULL){
-               linphone_call_destroy(lc->call);
-               lc->call=NULL;
-       }
-       return 0;
-}
-
-
-int linphone_call_released(LinphoneCore *lc, int cid){
-       LinphoneCall *call=lc->call;
-       if (call!=NULL && call->cid==cid){
-
-               linphone_call_destroy(lc->call);
-               lc->call=NULL;
-               lc->vtable.display_status(lc,_("Could not reach destination."));
-               gstate_new_state(lc, GSTATE_CALL_ERROR, NULL);
-       }
-       return 0;
-}
-
-int linphone_call_failure(LinphoneCore *lc, eXosip_event_t *ev)
-{
-       const char *reason="";
-       char *msg486=_("User is busy.");
-       char *msg480=_("User is temporarily unavailable.");
-       char *msg487=_("Request Cancelled.");
-       /*char *retrymsg=_("%s. Retry after %i minute(s).");*/
-       char *msg600=_("User does not want to be disturbed.");
-       char *msg603=_("Call declined.");
-       char* tmpmsg=msg486;
-       int code;
-       LinphoneCall *call=lc->call;
-
-       if (call){
-               /*check that the faillure is related to this call, not an old one*/
-               if (!linphone_call_matches_event(call,ev)) {
-                       ms_warning("Failure reported for an old call.");
-                       return 0;
-               }
-       }
-
-       if (ev->response){
-               code=osip_message_get_status_code(ev->response);
-               reason=osip_message_get_reason_phrase(ev->response);
-       }else code=-110;
-       lc->vtable.show(lc);
-
-       switch(code)
-       {
-               case 401:
-               case 407:
-                       if (lc->call!=NULL)
-                               linphone_process_authentication(lc,ev);
-                       return 0;
-                       break;
-               case 400:
-                       lc->vtable.display_status(lc,_("Bad request"));
-               break;
-               case 404:
-                       lc->vtable.display_status(lc,_("User cannot be found at given address."));
-               break;
-               case 415:
-                       lc->vtable.display_status(lc,_("Remote user cannot support any of proposed codecs."));
-               break;
-               case 422:
-                       /*ignore: eXosip_automatic_action will do the job of retrying with a greater Session-Expires*/
-                       return 0;
-               break;
-               case 480:
-                       tmpmsg=msg480;
-               case 486:
-                       /*
-                       msg_header_getbyname(msg,"retry-after",0,&retry);
-                       if (retry!=NULL)
-                       {
-                               umsg=g_malloc(strlen(tmpmsg)+strlen(retrymsg)+13);
-                               sprintf(umsg,retrymsg,tmpmsg,atoi(retry->hvalue)/60);
-                               lc->vtable.display_message(lc,umsg);
-                               ms_free(umsg);
-                       }*/
-                       lc->vtable.display_message(lc,tmpmsg);
-               break;
-               case 487: /*request terminated*/
-                       lc->vtable.display_status(lc,msg487);
-               break;
-               case 600:
-                       lc->vtable.display_message(lc,msg600);
-               break;
-               case 603:
-                       lc->vtable.display_status(lc,msg603);
-               break;
-               case -110:  /* time out, call leg is lost */
-                       lc->vtable.display_status(lc,_("Timeout."));
-               break;
-               case -111:
-                       lc->vtable.display_status(lc,_("Remote host was found but refused connection."));
-               break;
-
-               default:
-                       if (code>0)
-                       {
-                               lc->vtable.display_status(lc,reason);
-                       }
-                       else ms_warning("failure_cb unknown code=%i\n",code);
-       }
-       if (lc->ringstream!=NULL) {
-               ring_stop(lc->ringstream);
-               lc->ringstream=NULL;
-       }
-       linphone_core_stop_media_streams(lc);
-       if (call!=NULL) {
-               linphone_call_destroy(call);
-               gstate_new_state(lc, GSTATE_CALL_ERROR, NULL);
-               lc->call=NULL;
-       }
-       return 0;
-}
-
-extern sdp_handler_t linphone_sdphandler;
-
-static int linphone_answer_sdp(LinphoneCore *lc, eXosip_event_t *ev, sdp_message_t *sdp){
-       int status=200;
-       sdp_context_t *ctx=NULL;
-
-       ctx=lc->call->sdpctx;
-       /* get the result of the negociation */
-       sdp_context_get_answer(ctx,sdp);
-       status=sdp_context_get_status(ctx);
-
-       if (status==200){
-               linphone_core_init_media_streams(lc);
-               return 0;
-       }else{
-               if (status==-1) status=415;
-       }
-       return -1;
-}
-
-int linphone_inc_new_call(LinphoneCore *lc, eXosip_event_t *ev)
-{
-       sdp_message_t *sdp=NULL;
-       osip_from_t *from_url=ev->request->from;
-       char *barmesg;
-       char *from;
-       char *to;
-       int err;
-
-       osip_from_to_str(ev->request->from,&from);
-       osip_to_to_str(ev->request->to,&to);
-
-       /* first check if we can answer successfully to this invite */
-       if (lc->presence_mode!=LINPHONE_STATUS_ONLINE){
-               ms_message("Not present !! presence mode : %d\n",lc->presence_mode);
-               eXosip_lock();
-               if (lc->presence_mode==LINPHONE_STATUS_BUSY)
-                       eXosip_call_send_answer(ev->tid,486,NULL);
-               else if (lc->presence_mode==LINPHONE_STATUS_AWAY
-                        ||lc->presence_mode==LINPHONE_STATUS_BERIGHTBACK
-                        ||lc->presence_mode==LINPHONE_STATUS_ONTHEPHONE
-                        ||lc->presence_mode==LINPHONE_STATUS_OUTTOLUNCH
-                        ||lc->presence_mode==LINPHONE_STATUS_OFFLINE)
-                 eXosip_call_send_answer(ev->tid,480,NULL);
-               else if (lc->presence_mode==LINPHONE_STATUS_NOT_DISTURB)
-                 eXosip_call_send_answer(ev->tid,480,NULL);
-               else if (lc->alt_contact!=NULL && lc->presence_mode==LINPHONE_STATUS_MOVED)
-                 {
-                       osip_message_t *msg;
-                       eXosip_call_build_answer(ev->tid,302,&msg);
-                       osip_message_set_contact(msg,lc->alt_contact);
-                       eXosip_call_send_answer(ev->tid,302,msg);
-                 }
-               else if (lc->alt_contact!=NULL && lc->presence_mode==LINPHONE_STATUS_ALT_SERVICE)
-                 {
-                       osip_message_t *msg;
-                       eXosip_call_build_answer(ev->tid,380,&msg);
-                       osip_message_set_contact(msg,lc->alt_contact);
-                       eXosip_call_send_answer(ev->tid,380,msg);
-                 }
-               else
-                 eXosip_call_send_answer(ev->tid,486,NULL);
-               eXosip_unlock();
-               goto end;
-       }
-       if (lc->call!=NULL){/*busy*/
-               eXosip_lock();
-               eXosip_call_send_answer(ev->tid,486,NULL);
-               eXosip_unlock();
-               goto end;
-       }
-       lc->call=linphone_call_new_incoming(lc,linphone_address_new(from),linphone_address_new(to),ev);
-
-       sdp=eXosip_get_sdp_info(ev->request);
-       if (sdp==NULL){
-               ms_message("No sdp body in invite, 200-ack scheme");
-               err=0;
-       }else{
-               err=linphone_answer_sdp(lc,ev,sdp);
-       }
-       if (!err){
-               char *tmp;
-               if (from_2char_without_params(from_url,&tmp)!=0){
-                       tmp=ms_strdup("Unknown user");
-               }
-               gstate_new_state(lc, GSTATE_CALL_IN_INVITE, tmp);
-               barmesg=ortp_strdup_printf("%s %s",tmp,_("is contacting you."));
-               lc->vtable.show(lc);
-               lc->vtable.display_status(lc,barmesg);
-
-               /* play the ring */
-               if (lc->sound_conf.ring_sndcard!=NULL){
-                       ms_message("Starting local ring...");
-                       lc->ringstream=ring_start(lc->sound_conf.local_ring,2000,lc->sound_conf.ring_sndcard);
-               }
-               linphone_call_set_state(lc->call,LCStateRinging);
-               eXosip_lock();
-               eXosip_call_send_answer(ev->tid,180,NULL);
-               eXosip_unlock();
-
-               lc->vtable.inv_recv(lc,tmp);
-               ms_free(barmesg);
-               osip_free(tmp);
-       }else{
-               ms_error("Error during sdp negociation. ");
-               eXosip_lock();
-               eXosip_call_send_answer(ev->tid,415,NULL);
-               eXosip_unlock();
-               linphone_call_destroy(lc->call);
-               lc->call=NULL;
-       }
-       end:
-       osip_free(from);
-       osip_free(to);
-       if (sdp) sdp_message_free(sdp);
-       return 0;
-}
-
-void linphone_handle_ack(LinphoneCore *lc, eXosip_event_t *ev){
-       sdp_message_t *sdp=eXosip_get_sdp_info(ev->ack);
-       if (sdp){
-               sdp_context_read_answer(lc->call->sdpctx,sdp);
-               linphone_connect_incoming(lc);
-               sdp_message_free(sdp);
-       }
-}
-
-void linphone_handle_reinvite(LinphoneCore *lc, eXosip_event_t *ev){
-       sdp_message_t *sdp=eXosip_get_sdp_info(ev->request);
-       sdp_context_t *ctx;
-       LinphoneCall *call=lc->call;
-       char *answer;
-       int status;
-       if (sdp==NULL){
-               ms_warning("No sdp in reinvite !");
-               eXosip_lock();
-               eXosip_call_send_answer(ev->tid,603,NULL);
-               eXosip_unlock();
-               return;
-       }
-       ctx=call->sdpctx;
-       /* get the result of the negociation */
-       linphone_call_init_media_params(call);
-       answer=sdp_context_get_answer(ctx,sdp);
-       status=sdp_context_get_status(ctx);
-       if (status==200){
-               osip_message_t *msg=NULL;
-               linphone_core_stop_media_streams(lc);
-               linphone_core_init_media_streams(lc);
-               eXosip_lock();
-               if (eXosip_call_build_answer(ev->tid,200,&msg)<0){
-                       ms_warning("Reinvite for closed call ?");
-                        eXosip_unlock();
-                        linphone_core_stop_media_streams(lc);
-                       sdp_message_free(sdp);
-                       return ;
-               }
-               answer=call->sdpctx->answerstr; /* takes the sdp already computed*/
-               linphone_set_sdp(msg,answer);
-               eXosip_call_send_answer(ev->tid,200,msg);
-               eXosip_unlock();
-               linphone_core_start_media_streams(lc,call);
-       }else{
-               eXosip_lock();
-               eXosip_call_send_answer(ev->tid,status,NULL);
-               eXosip_unlock();
-       }
-       sdp_message_free(sdp);
-}
-
-void linphone_do_automatic_redirect(LinphoneCore *lc, const char *contact){
-       char *msg=ortp_strdup_printf(_("Redirected to %s..."),contact);
-       lc->vtable.display_status(lc,msg);
-       ms_free(msg);
-       if (lc->call!=NULL) linphone_call_destroy(lc->call);
-       lc->call=NULL;
-       linphone_core_invite(lc,contact);
-}
-
-void linphone_call_redirected(LinphoneCore *lc, eXosip_event_t *ev){
-       int code=osip_message_get_status_code(ev->response);
-       char *contact=NULL;
-       osip_contact_t *ct;
-       osip_message_get_contact(ev->response,0,&ct);
-       if (ct) osip_contact_to_str(ct,&contact);
-       switch(code){
-               case 380:
-                       lc->vtable.display_url(lc,_("User is not reachable at the moment but he invites you\nto contact him using the following alternate resource:"),contact);
-                       if (lc->call!=NULL) linphone_call_destroy(lc->call);
-                       lc->call=NULL;
-                       break;
-               case 302:
-                       linphone_do_automatic_redirect(lc,contact);
-                       break;
-       }
-       if (contact) osip_free(contact);
-}
-
-
-/* these are the SdpHandler callbacks: we are called in to be aware of the content
-of the SDP messages exchanged */
-
-int linphone_set_audio_offer(sdp_context_t *ctx)
-{
-       LinphoneCall *call=(LinphoneCall*)sdp_context_get_user_pointer(ctx);
-       LinphoneCore *lc=call->core;
-       PayloadType *codec;
-       MSList *elem;
-       sdp_payload_t payload;
-
-
-       elem=lc->codecs_conf.audio_codecs;
-       while(elem!=NULL){
-               codec=(PayloadType*) elem->data;
-               if (linphone_core_check_payload_type_usability(lc,codec) && 
-                   linphone_core_payload_type_enabled(lc,codec)){
-                       sdp_payload_init(&payload);
-                       payload.a_rtpmap=ortp_strdup_printf("%s/%i/1",codec->mime_type,codec->clock_rate);
-                       payload.pt=rtp_profile_get_payload_number_from_rtpmap(lc->local_profile,payload.a_rtpmap);
-                       payload.localport=call->audio_params.natd_port > 0 ?
-                                               call->audio_params.natd_port : lc->rtp_conf.audio_rtp_port;
-                       sdp_context_add_audio_payload(ctx,&payload);
-                       ms_free(payload.a_rtpmap);
-               }
-               elem=ms_list_next(elem);
-       }
-       /* add telephone-event payload*/
-       sdp_payload_init(&payload);
-       payload.pt=rtp_profile_get_payload_number_from_mime(lc->local_profile,"telephone-event");
-       payload.a_rtpmap="telephone-event/8000";
-       payload.a_fmtp="0-11";
-       if (lc->dw_audio_bw>0) payload.b_as_bandwidth=lc->dw_audio_bw;
-       if (lc->down_ptime>0) {
-               payload.a_ptime=lc->down_ptime;
-               ms_message("ptime [%i]",payload.a_ptime);
-       }
-       sdp_context_add_audio_payload(ctx,&payload);
-       return 0;
-}
-
-static int find_payload_type_number(RtpProfile *prof, PayloadType *pt){
-       int candidate=-1,i;
-       PayloadType *it;
-       for(i=0;i<127;++i){
-               it=rtp_profile_get_payload(prof,i);
-               if (it!=NULL && strcasecmp(pt->mime_type,it->mime_type)==0
-                       && (pt->clock_rate==it->clock_rate || pt->clock_rate<=0) ){
-                       if ( (pt->recv_fmtp && it->recv_fmtp && strcasecmp(pt->recv_fmtp,it->recv_fmtp)==0) ||
-                               (pt->recv_fmtp==NULL && it->recv_fmtp==NULL) ){
-                               /*exact match*/
-                               return i;
-                       }else candidate=i;
-               }
-       }
-       if (candidate==-1) ms_fatal("Should not happen.");
-       return candidate;
-}
-
-static int find_payload_type_number_best_match(RtpProfile *prof, const char *rtpmap, const char *fmtp){
-       int localpt=rtp_profile_get_payload_number_from_rtpmap(prof,rtpmap);
-       PayloadType *pt;
-       char value[10];
-       if (localpt<0) return -1;
-       pt=rtp_profile_get_payload(prof,localpt);
-       if (strcasecmp(pt->mime_type,"H264")==0){
-               /*hack for H264: need to answer with same packetization-mode*/
-               PayloadType tmp;
-               memset(&tmp,0,sizeof(tmp));
-               tmp.mime_type="H264";
-               tmp.clock_rate=pt->clock_rate;
-               if (fmtp && fmtp_get_value(fmtp,"packetization-mode",value,sizeof(value))){
-                       tmp.recv_fmtp=(atoi(value)==1) ? "packetization-mode=1" : NULL;
-               }
-               localpt=find_payload_type_number(prof,&tmp);
-       }
-       return localpt;
-}
-
-int linphone_set_video_offer(sdp_context_t *ctx)
-{
-       LinphoneCall *call=(LinphoneCall*)sdp_context_get_user_pointer(ctx);
-       LinphoneCore *lc=call->core;
-       PayloadType *codec;
-       MSList *elem;
-       bool_t firsttime=TRUE;
-
-       if (!linphone_core_video_enabled(lc)) return -1;
-
-       for(elem=lc->codecs_conf.video_codecs;elem!=NULL;elem=ms_list_next(elem)){
-               codec=(PayloadType*) elem->data;
-               if (linphone_core_check_payload_type_usability(lc,codec) && 
-                   linphone_core_payload_type_enabled(lc,codec)){
-                       sdp_payload_t payload;
-                       sdp_payload_init(&payload);
-                       payload.line=1;
-                       payload.a_rtpmap=ortp_strdup_printf("%s/%i",codec->mime_type,codec->clock_rate);
-                       payload.localport=call->video_params.natd_port>0 ?
-                                       call->video_params.natd_port : lc->rtp_conf.video_rtp_port;
-                       payload.pt=find_payload_type_number(lc->local_profile,codec);
-                       payload.a_fmtp=codec->recv_fmtp;
-                       if(firsttime){
-                               firsttime=FALSE;
-                               if (lc->dw_video_bw>0)
-                                       payload.b_as_bandwidth=lc->dw_video_bw;
-                       }
-                       sdp_context_add_video_payload(ctx,&payload);
-                       ms_free(payload.a_rtpmap);
-               }
-       }
-       return 0;
-}
-
-typedef enum {
-       Unsupported,
-       Supported,
-       SupportedAndValid  /* valid= the presence of this codec is enough to make a call */
-}SupportLevel;
-
-SupportLevel linphone_payload_is_supported(LinphoneCore *lc, sdp_payload_t *payload,RtpProfile *local_profile,RtpProfile *dialog_profile, bool_t answering, PayloadType **local_payload_type)
-{
-       int localpt;
-       SupportLevel ret;
-       if (payload->a_rtpmap!=NULL){
-               localpt=find_payload_type_number_best_match(local_profile,payload->a_rtpmap,payload->a_fmtp);
-       }else{
-               localpt=payload->pt;
-               ms_warning("payload has no rtpmap.");
-       }
-
-       if (localpt>=0 && localpt <128 ){
-               /* this payload is understood, but does the user want to use it ?? */
-               PayloadType *rtppayload;
-               rtppayload=rtp_profile_get_payload(local_profile,localpt);
-               if (rtppayload==NULL) {
-                       ms_warning("strange error !!");
-                       return Unsupported;
-               }
-               *local_payload_type=rtppayload;
-               if (strcmp(rtppayload->mime_type,"telephone-event")!=0){
-                       if (answering && !linphone_core_check_payload_type_usability(lc,rtppayload) ){
-                               ms_warning("payload %s is not usable",rtppayload->mime_type);
-                               return Unsupported;
-                       }
-                       if ( !linphone_core_payload_type_enabled(lc,rtppayload)) {
-                               ms_warning("payload %s is not enabled.",rtppayload->mime_type);
-                               return Unsupported;
-                       }
-                       ret=SupportedAndValid;
-               }else ret=Supported;
-               if (dialog_profile!=NULL){
-                       int dbw,ubw;
-                       /* this payload is supported in our local rtp profile, so add it to the dialog rtp
-                       profile */
-                       rtppayload=payload_type_clone(rtppayload);
-                       if (rtp_profile_get_payload(dialog_profile,payload->pt)!=NULL){
-                               ms_error("Payload %s type already entered, should not happen !",rtppayload->mime_type);
-                       }
-                       rtp_profile_set_payload(dialog_profile,payload->pt,rtppayload);
-                       /* add to the rtp payload type some other parameters (bandwidth) */
-                       if (rtppayload->type==PAYLOAD_VIDEO){
-                               dbw=lc->dw_video_bw;
-                               ubw=lc->up_video_bw;
-                       }else{
-                               dbw=lc->dw_audio_bw;
-                               ubw=lc->up_audio_bw;
-                       }
-                       if (payload->b_as_bandwidth!=0){
-                               ms_message("Remote bandwidth constraint: %i",payload->b_as_bandwidth);
-                               /*obey to remote bandwidth constraint AND our own upbandwidth constraint*/
-                               rtppayload->normal_bitrate=1000*get_min_bandwidth(
-                                       payload->b_as_bandwidth, ubw);
-                       }else{
-                               /*limit to upload bandwidth if exist, else no limit*/
-                               if (ubw>0) rtppayload->normal_bitrate=1000*ubw;
-                               else {
-                                       if (rtppayload->type!=PAYLOAD_VIDEO){
-                                               rtppayload->normal_bitrate=-1; /*allow speex to use maximum bitrate*/
-                                       }
-                               }
-                       }
-                       if (payload->a_fmtp!=NULL){
-                               payload_type_set_send_fmtp(rtppayload,payload->a_fmtp);
-                       }
-                       payload->a_fmtp=rtppayload->recv_fmtp;
-                       if (payload->a_ptime>0){
-                               char tmp[30];
-                               snprintf(tmp,sizeof(tmp),"ptime=%i",payload->a_ptime);
-                               payload_type_append_send_fmtp(rtppayload,tmp);
-                               ms_message("%s attribute added to fmtp",tmp);
-                       }
-               }
-               return ret;
-       }
-       return Unsupported;
-}
-
-int linphone_accept_audio_offer(sdp_context_t *ctx,sdp_payload_t *payload)
-{
-       RtpProfile *remote_profile;
-       StreamParams *params;
-       SupportLevel supported;
-       LinphoneCall *call=(LinphoneCall*)sdp_context_get_user_pointer(ctx);
-       LinphoneCore *lc=call->core;
-       PayloadType *lpt=NULL;
-
-       params=&call->audio_params;
-       remote_profile=call->profile;
-       /* see if this codec is supported in our local rtp profile*/
-       supported=linphone_payload_is_supported(lc,payload,lc->local_profile,remote_profile,TRUE,&lpt);
-       if (supported==Unsupported) {
-               ms_message("Refusing audio codec %i (%s)",payload->pt,payload->a_rtpmap);
-               return -1;
-       }
-       if (lc->sip_conf.only_one_codec && params->initialized){
-               ms_message("Only one codec has to be accepted.");
-               return -1;
-       }
-       if (supported==SupportedAndValid) {
-               if (params->initialized==0){
-                       /* this is the first codec we accept, it is going to be used*/
-                       params->localport=lc->rtp_conf.audio_rtp_port;
-                       payload->localport=params->natd_port>0 ?
-                               params->natd_port : lc->rtp_conf.audio_rtp_port;
-                       params->line=payload->line;
-                       params->pt=payload->pt; /* remember the first payload accepted */
-                       if (payload->relay_host!=NULL){
-                               strncpy(params->remoteaddr,payload->relay_host,sizeof(params->remoteaddr)-1);
-                               params->remoteport=payload->relay_port;
-                               params->remotertcpport=payload->relay_port;
-                               params->relay_session_id=payload->relay_session_id;
-                       }else{
-                               strncpy(params->remoteaddr,payload->c_addr,sizeof(params->remoteaddr)-1);
-                               params->remoteport=payload->remoteport;
-                               params->remotertcpport=payload->remoteport+1;
-                       }
-                       params->initialized=1;
-                       /* we can now update the allocated bandwidth for audio, and then video*/
-                       linphone_core_update_allocated_audio_bandwidth_in_call(lc,lpt);
-                       /* give our download bandwidth constraint*/
-                       payload->b_as_bandwidth=(lc->dw_audio_bw>0) ? lc->dw_audio_bw : 0;
-               }else{
-                       /* refuse all other audio lines*/
-                       if(params->line!=payload->line) {
-                               ms_message("Only one audio line can be accepted.");
-#if !defined(_WIN32_WCE)
-                               abort();
-#endif /*_WIN32_WCE*/
-                               return -1;
-                       }
-               }
-       }
-       return 0;
-}
-
-int linphone_accept_video_offer(sdp_context_t *ctx,sdp_payload_t *payload)
-{
-       LinphoneCall *call=(LinphoneCall*)sdp_context_get_user_pointer(ctx);
-       LinphoneCore *lc=call->core;
-       RtpProfile *remote_profile;
-       StreamParams *params;
-       SupportLevel supported;
-       PayloadType *lpt=NULL;
-
-       if (!linphone_core_video_enabled(lc)) return -1;
-
-       if (payload->remoteport==0) {
-               ms_message("Video stream refused by remote.");
-               return 0;
-       }
-
-       params=&call->video_params;
-       remote_profile=call->profile;
-       /* see if this codec is supported in our local rtp profile*/
-       supported=linphone_payload_is_supported(lc,payload,lc->local_profile,remote_profile,TRUE,&lpt);
-       if (supported==Unsupported) {
-               ms_message("Refusing video codec %i (%s)",payload->pt,payload->a_rtpmap);
-               return -1;
-       }
-       if (lc->sip_conf.only_one_codec && params->initialized){
-               return -1;
-       }
-       if (supported==SupportedAndValid){
-               if (params->initialized==0){
-                       /* this is the first codec we may accept*/
-                       params->localport=lc->rtp_conf.video_rtp_port;
-                       payload->localport=params->natd_port>0 ? params->natd_port : lc->rtp_conf.video_rtp_port;
-                       params->line=payload->line;
-                       params->pt=payload->pt; /* remember the first payload accepted */
-                       if (payload->relay_host!=NULL){
-                               strncpy(params->remoteaddr,payload->relay_host,sizeof(params->remoteaddr)-1);
-                               params->remoteport=payload->relay_port;
-                               params->remotertcpport=payload->relay_port;
-                               params->relay_session_id=payload->relay_session_id;
-                       }else{
-                               strncpy(params->remoteaddr,payload->c_addr,sizeof(params->remoteaddr)-1);
-                               params->remoteport=payload->remoteport;
-                               params->remotertcpport=params->remoteport+1;
-                       }
-                       params->initialized=1;
-                       payload->b_as_bandwidth=(lc->dw_video_bw>0) ? lc->dw_video_bw : 0;
-               }else{
-                       /* refuse all other video lines*/
-                       if(params->line!=payload->line) return -1;
-               }
-       }
-       return 0;
-}
-
-int linphone_read_audio_answer(sdp_context_t *ctx,sdp_payload_t *payload)
-{
-       LinphoneCall *call=(LinphoneCall*)sdp_context_get_user_pointer(ctx);
-       LinphoneCore *lc=call->core;
-       StreamParams *params;
-       SupportLevel supported;
-       PayloadType *lpt=NULL;
-
-       /* paranoid check: see if this codec is supported in our local rtp profile*/
-       supported=linphone_payload_is_supported(lc, payload,lc->local_profile,call->profile,FALSE,&lpt);
-       if (supported==Unsupported) {
-               ms_warning("This remote sip phone did not answer properly to my sdp offer: rtpmap=%s",payload->a_rtpmap);
-               return 0;
-       }
-       if (supported==SupportedAndValid){
-               params=&call->audio_params;
-               if (params->initialized==0){
-                       /* this is the first codec we accept, this is the one that is going to be used (at least for sending
-                       data.*/
-                       params->localport=lc->rtp_conf.audio_rtp_port;
-                       params->line=payload->line;
-                       params->pt=payload->pt; /* remember the first payload accepted */
-                       if (payload->relay_host!=NULL){
-                               strncpy(params->remoteaddr,payload->relay_host,sizeof(params->remoteaddr)-1);
-                               params->remoteport=payload->relay_port;
-                               params->remotertcpport=payload->relay_port;
-                               params->relay_session_id=payload->relay_session_id;
-                       }else{
-                               strncpy(params->remoteaddr,payload->c_addr,sizeof(params->remoteaddr)-1);
-                               params->remoteport=payload->remoteport;
-                               params->remotertcpport=payload->remoteport+1;
-                       }
-                       params->initialized=1;
-                       /* we can now update the allocated bandwidth for audio, and then video*/
-                       linphone_core_update_allocated_audio_bandwidth_in_call(lc,lpt);
-               }
-       }
-       return 0;
-}
-
-int linphone_read_video_answer(sdp_context_t *ctx,sdp_payload_t *payload)
-{
-       LinphoneCall *call=(LinphoneCall*)sdp_context_get_user_pointer(ctx);
-       LinphoneCore *lc=call->core;
-       StreamParams *params;
-       SupportLevel supported;
-       PayloadType *lpt=NULL;
-
-       /* paranoid check: see if this codec is supported in our local rtp profile*/
-       supported=linphone_payload_is_supported(lc, payload,lc->local_profile,call->profile,FALSE,&lpt);
-       if (supported==Unsupported) {
-               ms_warning("This remote sip phone did not answer properly to my sdp offer: rtpmap=%s",payload->a_rtpmap);
-               return 0;
-       }
-       if (supported==SupportedAndValid){
-               params=&call->video_params;
-               if (params->initialized==0){
-                       /* this is the first codec we may accept*/
-                       params->localport=lc->rtp_conf.video_rtp_port;
-                       params->line=payload->line;
-                       params->pt=payload->pt; /* remember the first payload accepted */
-                       if (payload->relay_host!=NULL){
-                               strncpy(params->remoteaddr,payload->relay_host,sizeof(params->remoteaddr)-1);
-                               params->remoteport=payload->relay_port;
-                               params->remotertcpport=payload->relay_port;
-                               params->relay_session_id=payload->relay_session_id;
-                       }else{
-                               strncpy(params->remoteaddr,payload->c_addr,sizeof(params->remoteaddr)-1);
-                               params->remoteport=payload->remoteport;
-                               params->remotertcpport=payload->remoteport+1;
-                       }
-                       params->initialized=1;
-               }
-       }
-       return 0;
-}
-
-void linphone_call_ringing(LinphoneCore *lc, eXosip_event_t *ev){
-       sdp_message_t *sdp=eXosip_get_sdp_info(ev->response);
-       LinphoneCall *call=lc->call;
-
-       lc->vtable.display_status(lc,_("Remote ringing."));
-       linphone_call_proceeding(lc,ev);
-       if (call==NULL) return;
-       if (sdp==NULL){
-               if (lc->ringstream!=NULL) return;       /*already ringing !*/
-               if (lc->sound_conf.play_sndcard!=NULL){
-                       ms_message("Remote ringing...");
-                       lc->ringstream=ring_start(lc->sound_conf.remote_ring,2000,lc->sound_conf.play_sndcard);
-               }
-       }else{
-               /*accept early media */
-               StreamParams *audio_params;
-               if (call==NULL){
-                       ms_error("No call ?");
-                       goto end;
-               }
-               if (lc->audiostream->ticker!=NULL){
-                       /*streams already started */
-                       ms_message("Early media already started.");
-                       goto end;
-               }
-               audio_params=&call->audio_params;
-               sdp_context_read_answer(lc->call->sdpctx,sdp);
-               lc->vtable.show(lc);
-               lc->vtable.display_status(lc,_("Early media."));
-               gstate_new_state(lc, GSTATE_CALL_OUT_CONNECTED, NULL);
-               if (lc->ringstream!=NULL){
-                       ring_stop(lc->ringstream);
-                       lc->ringstream=NULL;
-               }
-               ms_message("Doing early media...");
-               linphone_core_start_media_streams(lc,call);
-       }
-       call->state=LCStateRinging;
-       goto end;
-       end:
-               sdp_message_free(sdp);
-
-}
-
-static void linphone_process_media_control_xml(LinphoneCore *lc, eXosip_event_t *ev){
-       osip_body_t *body=NULL;
-       osip_message_get_body(ev->request,0,&body);
-       if (body && body->body!=NULL &&
-               strstr(body->body,"picture_fast_update")){
-               osip_message_t *ans=NULL;
-               ms_message("Receiving VFU request !");
-#ifdef VIDEO_ENABLED
-               if (lc->videostream)
-                       video_stream_send_vfu(lc->videostream);
-#endif
-               eXosip_call_build_answer(ev->tid,200,&ans);
-               if (ans)
-                       eXosip_call_send_answer(ev->tid,200,ans);
-       }
-}
-
-static void linphone_process_dtmf_relay(LinphoneCore *lc, eXosip_event_t *ev){
-       osip_body_t *body=NULL;
-       osip_message_get_body(ev->request,0,&body);
-       if (body && body->body!=NULL){
-               osip_message_t *ans=NULL;
-               const char *name=strstr(body->body,"Signal");
-               if (name==NULL) name=strstr(body->body,"signal");
-               if (name==NULL) {
-                       ms_warning("Could not extract the dtmf name from the SIP INFO.");
-               }else{
-                       char tmp[2];
-                       name+=strlen("signal");
-                       if (sscanf(name," = %1s",tmp)==1){
-                               ms_message("Receiving dtmf %s via SIP INFO.",tmp);
-                               if (lc->vtable.dtmf_received != NULL)
-                                       lc->vtable.dtmf_received(lc, tmp[0]);
-                       }
-               }
-
-               eXosip_call_build_answer(ev->tid,200,&ans);
-               if (ans)
-                       eXosip_call_send_answer(ev->tid,200,ans);
-       }
-}
-
-void linphone_call_message_new(LinphoneCore *lc, eXosip_event_t *ev){
-       osip_message_t *ans=NULL;
-       if (ev->request){
-               if (MSG_IS_INFO(ev->request)){
-                       osip_content_type_t *ct;
-                       ct=osip_message_get_content_type(ev->request);
-                       if (ct && ct->subtype){
-                               if (strcmp(ct->subtype,"media_control+xml")==0)
-                                       linphone_process_media_control_xml(lc,ev);
-                               else if (strcmp(ct->subtype,"dtmf-relay")==0)
-                                       linphone_process_dtmf_relay(lc,ev);
-                               else {
-                                       ms_message("Unhandled SIP INFO.");
-                                       /*send an "Not implemented" answer*/
-                                       eXosip_call_build_answer(ev->tid,501,&ans);
-                                       if (ans)
-                                               eXosip_call_send_answer(ev->tid,501,ans);
-                               }
-                       }else{
-                               /*empty SIP INFO, probably to test we are alive. Send an empty answer*/
-                               eXosip_call_build_answer(ev->tid,200,&ans);
-                                       if (ans)
-                                               eXosip_call_send_answer(ev->tid,200,ans);
-                       }
-               }
-       }else ms_warning("linphone_call_message_new: No request ?");
-}
-
-void linphone_registration_faillure(LinphoneCore *lc, eXosip_event_t *ev){
-       int status_code=0;
-       char *msg;
-       const char *reason=NULL;
-       osip_uri_t *requri=osip_message_get_uri(ev->request);
-       char *ru;
-       LinphoneProxyConfig *cfg;
-
-       if (ev->response){
-               status_code=osip_message_get_status_code(ev->response);
-               reason=osip_message_get_reason_phrase(ev->response);
-       }
-       switch(status_code){
-               case 401:
-               case 407:
-                       linphone_process_authentication(lc,ev);
-                       break;
-               default:
-                       cfg=linphone_core_get_proxy_config_from_rid(lc,ev->rid);
-                       /* if contact is up to date, process the failure, otherwise resend a new register with
-                               updated contact first, just in case the faillure is due to incorrect contact */
-                       if (linphone_proxy_config_register_again_with_updated_contact(cfg,ev->request,ev->response))
-                               return; /*we are retrying with an updated contact*/
-                       linphone_proxy_config_process_authentication_failure(lc,status_code,ev);
-                       osip_uri_to_str(requri,&ru);
-                       msg=ortp_strdup_printf(_("Registration on %s failed: %s"),ru,(reason!=NULL) ? reason : _("no response timeout"));
-                       lc->vtable.display_status(lc,msg);
-                       gstate_new_state(lc, GSTATE_REG_FAILED, msg);
-                       ms_free(msg);
-                       osip_free(ru);
-       }
-}
-
-void linphone_registration_success(LinphoneCore *lc,eXosip_event_t *ev){
-       LinphoneProxyConfig *cfg;
-       osip_uri_t *requri=osip_message_get_uri(ev->request);
-       char *msg;
-       char *ru;
-       osip_header_t *h=NULL;
-
-       cfg=linphone_core_get_proxy_config_from_rid(lc,ev->rid);
-       ms_return_if_fail(cfg!=NULL);
-
-       osip_message_get_expires(ev->request,0,&h);
-       if (h!=NULL && atoi(h->hvalue)!=0){
-               cfg->registered=TRUE;
-               linphone_proxy_config_register_again_with_updated_contact(cfg,ev->request,ev->response);
-       }else cfg->registered=FALSE;
-       
-       gstate_new_state(lc, GSTATE_REG_OK, NULL);
-
-       osip_uri_to_str(requri,&ru);
-       if (cfg->registered) msg=ms_strdup_printf(_("Registration on %s successful."),ru);
-       else msg=ms_strdup_printf(_("Unregistration on %s done."),ru);
-       lc->vtable.display_status(lc,msg);
-       ms_free(msg);
-       osip_free(ru);
-}
-
-static bool_t comes_from_local_if(osip_message_t *msg){
-       osip_via_t *via=NULL;
-       osip_message_get_via(msg,0,&via);
-       if (via){
-               const char *host;
-               host=osip_via_get_host(via);
-               if (strcmp(host,"127.0.0.1")==0 || strcmp(host,"::1")==0){
-                       osip_generic_param_t *param=NULL;
-                       osip_via_param_get_byname(via,"received",&param);
-                       if (param==NULL) return TRUE;
-                       if (param->gvalue &&
-                               (strcmp(param->gvalue,"127.0.0.1")==0 || strcmp(param->gvalue,"::1")==0)){
-                               return TRUE;
-                       }
-               }
-       }
-       return FALSE;
-}
-
-static void linphone_inc_update(LinphoneCore *lc, eXosip_event_t *ev){
-       osip_message_t *msg=NULL;
-       ms_message("Processing incoming UPDATE");
-       eXosip_lock();
-       eXosip_message_build_answer(ev->tid,200,&msg);
-       if (msg!=NULL)
-               eXosip_message_send_answer(ev->tid,200,msg);
-       eXosip_unlock();
-}
-
-static void linphone_other_request(LinphoneCore *lc, eXosip_event_t *ev){
-       ms_message("in linphone_other_request");
-       if (ev->request==NULL) return;
-       if (strcmp(ev->request->sip_method,"MESSAGE")==0){
-               linphone_core_text_received(lc,ev);
-               eXosip_message_send_answer(ev->tid,200,NULL);
-       }else if (strcmp(ev->request->sip_method,"OPTIONS")==0){
-               osip_message_t *options=NULL;
-               eXosip_options_build_answer(ev->tid,200,&options);
-               osip_message_set_allow(options,"INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, SUBSCRIBE, NOTIFY, INFO");
-               osip_message_set_accept(options,"application/sdp");
-               eXosip_options_send_answer(ev->tid,200,options);
-       }else if (strcmp(ev->request->sip_method,"WAKEUP")==0
-               && comes_from_local_if(ev->request)) {
-               eXosip_message_send_answer(ev->tid,200,NULL);
-               ms_message("Receiving WAKEUP request !");
-               if (lc->vtable.show)
-                       lc->vtable.show(lc);
-       }else if (strncmp(ev->request->sip_method, "REFER", 5) == 0){
-               ms_message("Receiving REFER request !");
-               if (comes_from_local_if(ev->request)) {
-                       osip_header_t *h=NULL;
-                       osip_message_header_get_byname(ev->request,"Refer-To",0,&h);
-                       eXosip_message_send_answer(ev->tid,200,NULL);
-                       if (h){
-                               if (lc->vtable.refer_received)
-                                       lc->vtable.refer_received(lc,h->hvalue);
-                       }
-
-               }else ms_warning("Ignored REFER not coming from this local loopback interface.");
-       }else if (strncmp(ev->request->sip_method, "UPDATE", 6) == 0){
-               linphone_inc_update(lc,ev);
-       }else {
-               char *tmp=NULL;
-               size_t msglen=0;
-               osip_message_to_str(ev->request,&tmp,&msglen);
-               if (tmp){
-                       ms_message("Unsupported request received:\n%s",tmp);
-                       osip_free(tmp);
-               }
-               /*answer with a 501 Not implemented*/
-               eXosip_message_send_answer(ev->tid,501,NULL);
-       }
-}
-
-void linphone_core_process_event(LinphoneCore *lc,eXosip_event_t *ev)
-{
-       switch(ev->type){
-               case EXOSIP_CALL_ANSWERED:
-                       ms_message("CALL_ANSWERED\n");
-                       linphone_call_accepted(lc,ev);
-                       linphone_authentication_ok(lc,ev);
-                       break;
-               case EXOSIP_CALL_CLOSED:
-               case EXOSIP_CALL_CANCELLED:
-                       ms_message("CALL_CLOSED or CANCELLED\n");
-                       linphone_call_terminated(lc,ev);
-                       break;
-               case EXOSIP_CALL_TIMEOUT:
-               case EXOSIP_CALL_NOANSWER:
-                       ms_message("CALL_TIMEOUT or NOANSWER\n");
-                       linphone_call_failure(lc,ev);
-                       break;
-               case EXOSIP_CALL_REQUESTFAILURE:
-               case EXOSIP_CALL_GLOBALFAILURE:
-               case EXOSIP_CALL_SERVERFAILURE:
-                       ms_message("CALL_REQUESTFAILURE or GLOBALFAILURE or SERVERFAILURE\n");
-                       linphone_call_failure(lc,ev);
-                       break;
-               case EXOSIP_CALL_INVITE:
-                       ms_message("CALL_NEW\n");
-                       /* CALL_NEW is used twice in qos mode :
-                        * when you receive invite (textinfo = "With QoS" or "Without QoS")
-                        * and when you receive update (textinfo = "New Call") */
-                       linphone_inc_new_call(lc,ev);
-                       break;
-               case EXOSIP_CALL_REINVITE:
-                       linphone_handle_reinvite(lc,ev);
-                       break;
-               case EXOSIP_CALL_ACK:
-                       ms_message("CALL_ACK");
-                       linphone_handle_ack(lc,ev);
-                       break;
-               case EXOSIP_CALL_REDIRECTED:
-                       ms_message("CALL_REDIRECTED");
-                       linphone_call_redirected(lc,ev);
-                       break;
-               case EXOSIP_CALL_PROCEEDING:
-                       ms_message("CALL_PROCEEDING");
-                       linphone_call_proceeding(lc,ev);
-                       break;
-               case EXOSIP_CALL_RINGING:
-                       ms_message("CALL_RINGING");
-                       linphone_call_ringing(lc,ev);
-                       break;
-               case EXOSIP_CALL_MESSAGE_NEW:
-                       ms_message("EXOSIP_CALL_MESSAGE_NEW");
-                       linphone_call_message_new(lc,ev);
-                       break;
-               case EXOSIP_CALL_MESSAGE_REQUESTFAILURE:
-                       if (ev->did<0 && ev->response &&
-                               (ev->response->status_code==407 || ev->response->status_code==401)){
-                                eXosip_default_action(ev);
-                       }
-                       break;
-               case EXOSIP_IN_SUBSCRIPTION_NEW:
-                       ms_message("CALL_SUBSCRIPTION_NEW or UPDATE");
-                       linphone_subscription_new(lc,ev);
-                       break;
-               case EXOSIP_SUBSCRIPTION_UPDATE:
-                       break;
-               case EXOSIP_SUBSCRIPTION_NOTIFY:
-                       ms_message("CALL_SUBSCRIPTION_NOTIFY");
-                       linphone_notify_recv(lc,ev);
-                       break;
-               case EXOSIP_SUBSCRIPTION_ANSWERED:
-                       ms_message("EXOSIP_SUBSCRIPTION_ANSWERED, ev->sid=%i\n",ev->sid);
-                       linphone_subscription_answered(lc,ev);
-                       break;
-               case EXOSIP_SUBSCRIPTION_CLOSED:
-                       ms_message("EXOSIP_SUBSCRIPTION_CLOSED\n");
-                       linphone_subscription_closed(lc,ev);
-                       break;
-               case EXOSIP_CALL_RELEASED:
-                       ms_message("CALL_RELEASED\n");
-                       linphone_call_released(lc, ev->cid);
-                       break;
-               case EXOSIP_REGISTRATION_FAILURE:
-                       ms_message("REGISTRATION_FAILURE\n");
-                       linphone_registration_faillure(lc,ev);
-                       break;
-               case EXOSIP_REGISTRATION_SUCCESS:
-                       linphone_authentication_ok(lc,ev);
-                       linphone_registration_success(lc,ev);
-                       break;
-               case EXOSIP_MESSAGE_NEW:
-                       linphone_other_request(lc,ev);
-                       break;
-               case EXOSIP_MESSAGE_REQUESTFAILURE:
-                       if (ev->response && (ev->response->status_code == 407 || ev->response->status_code == 401)){
-                               /*the user is expected to have registered to the proxy, thus password is known*/
-                               eXosip_default_action(ev);
-                       }
-                       break;
-               default:
-                       ms_message("Unhandled exosip event !");
-                       break;
-       }
-       eXosip_event_free(ev);
-}
diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c
new file mode 100644 (file)
index 0000000..ac165a6
--- /dev/null
@@ -0,0 +1,295 @@
+
+/*
+linphone
+Copyright (C) 2010  Belledonne Communications SARL 
+ (simon.morlat@linphone.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+#ifdef WIN32
+#include <time.h>
+#endif
+#include "linphonecore.h"
+#include "sipsetup.h"
+#include "lpconfig.h"
+#include "private.h"
+
+
+
+
+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->refcnt=1;
+       call->state=LinphoneCallInit;
+       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;
+}
+
+/* this function is called internally to get rid of a call.
+ It performs the following tasks:
+ - remove the call from the internal list of calls
+ - unref the LinphoneCall object
+ - update the call logs accordingly
+*/
+
+void linphone_call_set_terminated(LinphoneCall *call){
+       LinphoneCallStatus status=LinphoneCallAborted;
+       LinphoneCore *lc=call->core;
+
+       if (ms_list_size(lc->calls)==0)
+               linphone_core_notify_all_friends(lc,lc->prev_mode);
+       
+       linphone_core_update_allocated_audio_bandwidth(lc);
+       if (call->state==LinphoneCallAVRunning){
+               status=LinphoneCallSuccess;
+               
+       }
+       linphone_call_log_completed(call->log,call, status);
+       call->state=LinphoneCallTerminated;
+       if (linphone_core_del_call(lc,call) != 0){
+               ms_error("could not remove the call from the list !!!");
+       }
+       if (call == linphone_core_get_current_call(lc)){
+               ms_message("destroying the current call\n");
+               linphone_core_unset_the_current_call(lc);
+       }
+       if (call->op!=NULL) {
+               /* so that we cannot have anymore upcalls for SAL
+                concerning this call*/
+               sal_op_release(call->op);
+               call->op=NULL;
+       }
+       linphone_call_unref(call);
+}
+
+static void linphone_call_destroy(LinphoneCall *obj)
+{
+       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);
+}
+
+/**
+ * @addtogroup calls
+ * @{
+**/
+
+/**
+ * Increments the call 's reference count.
+ * An application that wishes to retain a pointer to call object
+ * must use this function to unsure the pointer remains
+ * valid. Once the application no more needs this pointer,
+ * it must call linphone_call_unref().
+**/
+void linphone_call_ref(LinphoneCall *obj){
+       obj->refcnt++;
+}
+
+/**
+ * Decrements the call object reference count.
+ * See linphone_call_ref().
+**/
+void linphone_call_unref(LinphoneCall *obj){
+       obj->refcnt--;
+       if (obj->refcnt==0)
+               linphone_call_destroy(obj);
+}
+
+/**
+ * Returns true if the call is paused.
+**/
+bool_t linphone_call_paused(LinphoneCall *call){
+       return call->state==LinphoneCallPaused;
+}
+
+/**
+ * Returns the remote address associated to this call
+ *
+**/
+const LinphoneAddress * linphone_call_get_remote_address(const LinphoneCall *call){
+       return call->dir==LinphoneCallIncoming ? call->log->from : call->log->to;
+}
+
+/**
+ * Returns the remote address associated to this call as a string.
+ *
+ * The result string must be freed by user using ms_free().
+**/
+char *linphone_call_get_remote_address_as_string(const LinphoneCall *call){
+       return linphone_address_as_string(linphone_call_get_remote_address(call));
+}
+
+/**
+ * Retrieves the call's current state.
+**/
+LinphoneCallState linphone_call_get_state(const LinphoneCall *call){
+       return call->state;
+}
+
+/**
+ * Get the user_pointer in the LinphoneCall
+ *
+ * @ingroup call_control
+ *
+ * return user_pointer an opaque user pointer that can be retrieved at any time
+**/
+void *linphone_call_get_user_pointer(LinphoneCall *call)
+{
+       return call->user_pointer;
+}
+
+/**
+ * Set the user_pointer in the LinphoneCall
+ *
+ * @ingroup call_control
+ *
+ * the user_pointer is an opaque user pointer that can be retrieved at any time in the LinphoneCall
+**/
+void linphone_call_set_user_pointer(LinphoneCall *call, void *user_pointer)
+{
+       call->user_pointer = user_pointer;
+}
+
+/**
+ * @}
+**/
+
index a68acd244b62181519936cff96e211d6ad8fe160..3423dd87c968797d2684f763c10ffa9d281709bd 100644 (file)
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "mediastreamer2/mediastream.h"
 #include "mediastreamer2/msvolume.h"
 #include "mediastreamer2/msequalizer.h"
+#include "mediastreamer2/mseventqueue.h"
 
 #include <ortp/telephonyevents.h>
 
@@ -62,151 +63,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 +152,21 @@ 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);
+                               if (lc->vtable.display_status!=NULL)
+                                       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;
@@ -454,17 +300,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;
-       if (call==NULL) return 0;
-       return call->dir==LinphoneCallIncoming ? call->log->from : call->log->to;
+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 NULL;
+       return linphone_call_get_remote_address(call);
 }
 
 /**
@@ -621,7 +471,7 @@ static void sound_config_read(LinphoneCore *lc)
                lp_config_get_int(lc->config,"sound","agc",0));
 
        gain=lp_config_get_float(lc->config,"sound","soft_play_lev",0);
-               linphone_core_set_soft_play_level(lc,gain);
+       linphone_core_set_soft_play_level(lc,gain);
 }
 
 static void sip_config_read(LinphoneCore *lc)
@@ -631,9 +481,15 @@ static void sip_config_read(LinphoneCore *lc)
        LCSipTransports tr;
        int i,tmp;
        int ipv6;
+
        tmp=lp_config_get_int(lc->config,"sip","use_info",0);
        linphone_core_set_use_info_for_dtmf(lc,tmp);
 
+       if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
+               sal_use_session_timers(lc->sal,200);
+       }
+
+
        tmp=lp_config_get_int(lc->config,"sip","use_rfc2833",0);
        linphone_core_set_use_rfc2833_for_dtmf(lc,tmp);
 
@@ -641,7 +497,8 @@ static void sip_config_read(LinphoneCore *lc)
        if (ipv6==-1){
                ipv6=0;
                if (host_has_ipv6_network()){
-                       lc->vtable.display_message(lc,_("Your machine appears to be connected to an IPv6 network. By default linphone always uses IPv4. Please update your configuration if you want to use IPv6"));
+                       if (lc->vtable.display_message)
+                               lc->vtable.display_message(lc,_("Your machine appears to be connected to an IPv6 network. By default linphone always uses IPv4. Please update your configuration if you want to use IPv6"));
                }
        }
        linphone_core_enable_ipv6(lc,ipv6);
@@ -1098,6 +955,10 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
 #endif
 
        ms_init();
+       /* create a mediastreamer2 event queue and set it as global */
+       /* This allows to run event's callback in linphone_core_iterate() */
+       lc->msevq=ms_event_queue_new();
+       ms_set_global_event_queue(lc->msevq);
 
        lc->config=lp_config_new(config_path);
        if (factory_config_path)
@@ -1106,9 +967,7 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
        lc->sal=sal_init();
        sal_set_user_pointer(lc->sal,lc);
        sal_set_callbacks(lc->sal,&linphone_sal_callbacks);
-       if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
-               sal_use_session_timers(lc->sal,200);
-       }
+       
        sip_setup_register_all();
        sound_config_read(lc);
        net_config_read(lc);
@@ -1121,8 +980,9 @@ static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vta
        lc->presence_mode=LINPHONE_STATUS_ONLINE;
        lc->max_call_logs=15;
        ui_config_read(lc);
-       lc->vtable.display_status(lc,_("Ready"));
-        gstate_new_state(lc, GSTATE_POWER_ON, NULL);
+       if (lc->vtable.display_status)
+               lc->vtable.display_status(lc,_("Ready"));
+       gstate_new_state(lc, GSTATE_POWER_ON, NULL);
        lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
 
     lc->ready=TRUE;
@@ -1616,9 +1476,23 @@ static void display_bandwidth(RtpSession *as, RtpSession *vs){
        (vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0);
 }
 
-static void linphone_core_disconnected(LinphoneCore *lc){
-       lc->vtable.display_warning(lc,_("Remote end seems to have disconnected, the call is going to be closed."));
-       linphone_core_terminate_call(lc,NULL);
+static void linphone_core_disconnected(LinphoneCore *lc, LinphoneCall *call){
+       char temp[256];
+       char *from;
+       if(call)
+               from = linphone_call_get_remote_address_as_string(call);
+       if(from)
+       {
+               snprintf(temp,sizeof(temp),"Remote end %s seems to have disconnected, the call is going to be closed.",from);
+               free(from);
+       }               
+       else
+       {
+               snprintf(temp,sizeof(temp),"Remote end seems to have disconnected, the call is going to be closed.");
+       }
+       if (lc->vtable.display_warning!=NULL)
+       lc->vtable.display_warning(lc,temp);
+       linphone_core_terminate_call(lc,call);//TODO failure ??
 }
 
 static void monitor_network_state(LinphoneCore *lc, time_t curtime){
@@ -1744,6 +1618,8 @@ static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
  * serialized with a mutex.
 **/
 void linphone_core_iterate(LinphoneCore *lc){
+       MSList *calls;
+       LinphoneCall *call;
        int disconnect_timeout = linphone_core_get_nortp_timeout(lc);
        time_t curtime=time(NULL);
        int elapsed;
@@ -1763,24 +1639,39 @@ void linphone_core_iterate(LinphoneCore *lc){
        }
 
        sal_iterate(lc->sal);
+       ms_event_queue_pump(lc->msevq);
        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)){
-                       /*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){
-                       elapsed=curtime-call->start_time;
-                       ms_message("incoming call ringing for %i seconds",elapsed);
-                       if (elapsed>lc->sip_conf.inc_timeout){
-                               linphone_core_terminate_call(lc,NULL);
+       //we have to iterate for each call
+       calls= lc->calls;
+       while(calls!= NULL){
+               call = (LinphoneCall *)calls->data;
+                /* get immediately a reference to next one in case the one
+                we are going to examine is destroy and removed during
+                linphone_core_start_invite() */
+               calls=calls->next;
+               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);
                        }
-               }else if (call->state==LCStateAVRunning){
-                       if (one_second_elapsed){
+                       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,call);
+                               }
+                       }
+       }
+       call = linphone_core_get_current_call(lc);
+       if(call)
+       {
+               if (call->state==LinphoneCallAVRunning)
+               {
+                       if (one_second_elapsed)
+                       {
                                RtpSession *as=NULL,*vs=NULL;
                                lc->prevtime=curtime;
                                if (lc->audiostream!=NULL)
@@ -1808,7 +1699,7 @@ void linphone_core_iterate(LinphoneCore *lc){
                        toggle_video_preview(lc,FALSE);
        }
        if (disconnected)
-               linphone_core_disconnected(lc);
+               linphone_core_disconnected(lc,call);
 
        linphone_core_do_plugin_tasks(lc);
 
@@ -1839,9 +1730,13 @@ LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url)
        LinphoneAddress *uri;
        
        if (is_enum(url,&enum_domain)){
-               lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
+               if (lc->vtable.display_status!=NULL)
+                       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.display_status!=NULL)
+                               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;
                }
@@ -1924,7 +1819,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;
@@ -1968,7 +1863,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){
@@ -2014,8 +1908,10 @@ 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;
+       //TODO : should probably not be done here
+       if(!    linphone_core_in_call(lc) )
+               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);
@@ -2029,15 +1925,17 @@ int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphonePro
                sal_call_set_local_media_description(call->op,call->localdesc);
        }
        barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
-       lc->vtable.display_status(lc,barmsg);
+       if (lc->vtable.display_status!=NULL)
+               lc->vtable.display_status(lc,barmsg);
        ms_free(barmsg);
        
        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 (lc->vtable.display_status!=NULL)
+                       lc->vtable.display_status(lc,_("could not call"));
+               if(call == linphone_core_get_current_call(lc))
+                       linphone_core_stop_media_streams(lc,call);
+               linphone_call_set_terminated (call);
        }else gstate_new_state(lc, GSTATE_CALL_OUT_INVITE, real_url);
        ms_free(real_url);
        ms_free(from);
@@ -2051,15 +1949,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;
 }
 
 /**
@@ -2069,7 +1967,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;
@@ -2080,11 +1978,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);
        
@@ -2109,12 +2010,17 @@ 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;
+       }
        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);
                sal_op_set_user_pointer(call->ping_op,call);
@@ -2122,20 +2028,18 @@ int linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *real_p
        }
        
        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;
@@ -2148,13 +2052,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;
 }
@@ -2167,6 +2074,9 @@ static void rendercb(void *data, const MSPicture *local, const MSPicture *remote
 #endif
 
 void linphone_core_init_media_streams(LinphoneCore *lc, LinphoneCall *call){
+#ifdef PRINTF_DEBUG
+       printf("%s(%d)\n",__FUNCTION__,__LINE__);
+#endif
        SalMediaDescription *md=call->localdesc;
        lc->audiostream=audio_stream_new(md->streams[0].port,linphone_core_ipv6_enabled(lc));
        if (linphone_core_echo_limiter_enabled(lc)){
@@ -2337,6 +2247,15 @@ void linphone_core_start_media_streams(LinphoneCore *lc, LinphoneCall *call){
        const char *tool="linphone-" LINPHONE_VERSION;
        char *cname;
        int used_pt=-1;
+       if(lc->audiostream == NULL)
+       {
+               ms_warning("init media stream is needed before starting");
+               linphone_core_init_media_streams(lc,call);
+               /*
+                * example of problem :
+                * 2 incomings calls, you answer and pause one, afterward if you try to answer the other call you will get SEGFAULT
+                */
+       }
        /* adjust rtp jitter compensation. It must be at least the latency of the sound card */
        int jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
 
@@ -2349,7 +2268,8 @@ void linphone_core_start_media_streams(LinphoneCore *lc, LinphoneCall *call){
                if (stream && stream->port!=0){
                        call->audio_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
                        if (!lc->use_files){
-                               MSSndCard *playcard=lc->sound_conf.play_sndcard;
+                               MSSndCard *playcard=lc->sound_conf.lsd_card ? 
+                                       lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
                                MSSndCard *captcard=lc->sound_conf.capt_sndcard;
                                if (playcard==NULL) {
                                        ms_warning("No card defined for playback !");
@@ -2424,7 +2344,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;
 }
 
 static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
@@ -2432,6 +2352,9 @@ static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
 }
 
 void linphone_core_stop_media_streams(LinphoneCore *lc, LinphoneCall *call){
+#ifdef PRINTF_DEBUG
+       printf("%s(%d)\n",__FUNCTION__,__LINE__);
+#endif
        if (lc->audiostream!=NULL) {
                linphone_call_log_fill_stats (call->log,lc->audiostream);
                audio_stream_stop(lc->audiostream);
@@ -2479,17 +2402,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;
        }
@@ -2501,7 +2427,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);
@@ -2509,12 +2439,14 @@ int linphone_core_accept_call(LinphoneCore *lc, const char *url)
                sal_op_set_contact(call->op,contact);
        
        sal_call_accept(call->op);
-       lc->vtable.display_status(lc,_("Connected."));
+       if (lc->vtable.display_status!=NULL)
+               lc->vtable.display_status(lc,_("Connected."));
        gstate_new_state(lc, GSTATE_CALL_IN_CONNECTED, NULL);
        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;
@@ -2528,13 +2460,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){
+                       ms_warning("No currently active call to terminate !");
+                       return -1;
+               }
+       }
+       else
+       {
+               call = the_call;
        }
-       lc->call=NULL;
        sal_call_terminate(call->op);
 
        /*stop ringing*/
@@ -2542,20 +2481,48 @@ int linphone_core_terminate_call(LinphoneCore *lc, const char *url)
                ring_stop(lc->ringstream);
                lc->ringstream=NULL;
        }
-       linphone_core_stop_media_streams(lc,call);
-       lc->vtable.display_status(lc,_("Call ended") );
+       if(call == linphone_core_get_current_call(lc))
+               linphone_core_stop_media_streams(lc,call);
+       if (lc->vtable.display_status!=NULL)
+               lc->vtable.display_status(lc,_("Call ended") );
        gstate_new_state(lc, GSTATE_CALL_END, NULL);
-       linphone_call_destroy(call);
+       linphone_call_set_terminated(call);
        return 0;
 }
 
+/**
+ * Terminates all the calls.
+ *
+ * @ingroup call_control
+ * @param lc The LinphoneCore
+**/
+int linphone_core_terminate_all_calls(LinphoneCore *lc){
+       while(lc->calls)
+       {
+               LinphoneCall *the_call = lc->calls->data;
+               linphone_core_terminate_call(lc,the_call);
+       }
+       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;
 }
 
 /**
@@ -2563,12 +2530,147 @@ 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;
+       }
+       if(sal_call_hold(call->op,TRUE) != 0)
+       {
+               lc->vtable.display_warning(lc,_("Could not pause the call"));
+       }
+       call->state = LinphoneCallPaused;
+       linphone_core_unset_the_current_call(lc);
+       linphone_core_stop_media_streams(lc,call);
+       //have to be done ... because if another call is incoming before this pause, you will get sound on the end point paused
+       linphone_core_init_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(call->state ==  LinphoneCallInit || call->state ==  LinphoneCallPreEstablishing || call->state ==  LinphoneCallRinging )
+       {
+               ms_warning("we cannot resume a call when the communication is not established");
+               return -3;
+       }
+       if(linphone_core_get_current_call(lc) != NULL)
+       {
+               ms_error("There is already a call in process pause or stop it first\n");
+               return -4;
+       }
+       linphone_core_init_media_streams(lc,call);
+       if(sal_call_hold(call->op,FALSE) != 0)
+       {
+               lc->vtable.display_warning(lc,_("Could not resume the call"));
+       }
+       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,
@@ -2941,7 +3043,8 @@ int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCb
        lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
        lc->preview_finished=0;
        if (lc->sound_conf.ring_sndcard!=NULL){
-               lc->ringstream=ring_start_with_cb(ring,2000,lc->sound_conf.ring_sndcard,notify_end_of_ring,(void *)lc);
+               MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
+               lc->ringstream=ring_start_with_cb(ring,2000,ringcard,notify_end_of_ring,(void *)lc);
        }
        return 0;
 }
@@ -3074,7 +3177,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;
                }
@@ -3713,18 +3816,18 @@ LpConfig *linphone_core_get_config(LinphoneCore *lc){
 
 static void linphone_core_uninit(LinphoneCore *lc)
 {
-       if (lc->call){
-               int i;
-               linphone_core_terminate_call(lc,NULL);
-               for(i=0;i<10;++i){
-#ifndef WIN32
-                       usleep(50000);
+       while(lc->calls)
+       {
+               LinphoneCall *the_call = lc->calls->data;
+               linphone_core_terminate_call(lc,the_call);
+               linphone_core_iterate(lc);
+#ifdef WIN32
+               Sleep(50000);
 #else
-                       Sleep(50);
+               usleep(50000);
 #endif
-                       linphone_core_iterate(lc);
-               }
        }
+
        if (lc->friends)
                ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions);
        gstate_new_state(lc, GSTATE_POWER_SHUTDOWN, NULL);
@@ -3734,6 +3837,7 @@ static void linphone_core_uninit(LinphoneCore *lc)
                lc->previewstream=NULL;
        }
 #endif
+       ms_event_queue_destroy(lc->msevq);
        /* save all config */
        net_config_uninit(lc);
        sip_config_uninit(lc);
@@ -3797,4 +3901,106 @@ 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;
+       ms_error("Maximum amount of simultaneous calls reached !");
+       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,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;
+}
index b780956ff3cc5e796294b05dd193e55419e00116..f9dc69e63e27ec43686809d69467dd96750d886d 100644 (file)
@@ -103,8 +103,25 @@ struct _SipSetupContext;
 struct _LinphoneCall;
 typedef struct _LinphoneCall LinphoneCall;
 
-bool_t linphone_call_asked_to_autoanswer(struct _LinphoneCall *call);
-       
+typedef enum _LinphoneCallState{
+       LinphoneCallInit,
+       LinphoneCallPreEstablishing,
+       LinphoneCallRinging,
+       LinphoneCallAVRunning,
+       LinphoneCallPaused,
+       LinphoneCallTerminated
+}LinphoneCallState;
+
+LinphoneCallState linphone_call_get_state(const LinphoneCall *call);
+bool_t linphone_call_asked_to_autoanswer(LinphoneCall *call);
+bool_t linphone_call_paused(LinphoneCall *call);
+const LinphoneAddress * linphone_core_get_current_call_remote_address(struct _LinphoneCore *lc);
+const LinphoneAddress * linphone_call_get_remote_address(const LinphoneCall *call);
+char *linphone_call_get_remote_address_as_string(const LinphoneCall *call);
+void linphone_call_ref(LinphoneCall *call);
+void linphone_call_unref(LinphoneCall *call);
+
+
 /**
  * Enum representing the direction of a call.
  * @ingroup call_logs
@@ -401,9 +418,23 @@ void gstate_initialize(struct _LinphoneCore *lc) ;
 /** Callback prototype */
 typedef void (*ShowInterfaceCb)(struct _LinphoneCore *lc);
 /** Callback prototype */
-typedef void (*InviteReceivedCb)(struct _LinphoneCore *lc, const char *from);
+typedef void (*InviteReceivedCb)(struct _LinphoneCore *lc, LinphoneCall *call);
+/** Callback prototype */
+typedef void (*ByeReceivedCb)(struct _LinphoneCore *lc, LinphoneCall *call);
+/** Callback prototype */
+typedef void (*RingingReceivedCb)(struct _LinphoneCore *lc, LinphoneCall *call);
+/** Callback prototype */
+typedef void (*ConnectedReceivedCb)(struct _LinphoneCore *lc, LinphoneCall *call);
+/** Callback prototype */
+typedef void (*FailureReceivedCb)(struct _LinphoneCore *lc, LinphoneCall *call, int error_code);
+/** Callback prototype */
+typedef void (*PausedReceivedCb)(struct _LinphoneCore *lc, LinphoneCall *call);
 /** Callback prototype */
-typedef void (*ByeReceivedCb)(struct _LinphoneCore *lc, const char *from);
+typedef void (*ResumedReceivedCb)(struct _LinphoneCore *lc, LinphoneCall *call);
+/** Callback prototype */
+typedef void (*AckPausedReceivedCb)(struct _LinphoneCore *lc, LinphoneCall *call);
+/** Callback prototype */
+typedef void (*AckResumedReceivedCb)(struct _LinphoneCore *lc, LinphoneCall *call);
 /** Callback prototype */
 typedef void (*DisplayStatusCb)(struct _LinphoneCore *lc, const char *message);
 /** Callback prototype */
@@ -431,7 +462,7 @@ typedef void (*GeneralStateChange)(struct _LinphoneCore *lc, LinphoneGeneralStat
 /** Callback prototype */
 typedef void (*DtmfReceived)(struct _LinphoneCore* lc, int dtmf);
 /** Callback prototype */
-typedef void (*ReferReceived)(struct _LinphoneCore *lc, const char *refer_to);
+typedef void (*ReferReceived)(struct _LinphoneCore *lc, LinphoneCall *call, const char *refer_to);
 /** Callback prototype */
 typedef void (*BuddyInfoUpdated)(struct _LinphoneCore *lc, LinphoneFriend *lf);
 
@@ -444,6 +475,13 @@ typedef struct _LinphoneVTable
        ShowInterfaceCb show; /**< Notifies the application that it should show up*/
        InviteReceivedCb inv_recv; /**< Notifies incoming calls */
        ByeReceivedCb bye_recv; /**< Notify calls terminated by far end*/
+       RingingReceivedCb ringing_recv; /**< Notify that the distant phone is ringing*/
+       ConnectedReceivedCb connected_recv; /**< Notify that the distant phone answered the call*/
+       FailureReceivedCb failure_recv; /**< Notify that the call failed*/
+       PausedReceivedCb paused_recv; /**< Notify that the call has been paused*/
+       ResumedReceivedCb resumed_recv; /**< Notify that the call has been resumed*/
+       AckPausedReceivedCb ack_paused_recv;/**< Notify that the previous command pause sent to the call has been acknowledge*/
+       AckResumedReceivedCb ack_resumed_recv;/**< Notify that the previous command resumed sent to the call has been acknowledge*/     
        NotifyPresenceReceivedCb notify_presence_recv; /**< Notify received presence events*/
        NewUnknownSubscriberCb new_unknown_subscriber; /**< Notify about unknown subscriber */
        AuthInfoRequested auth_info_requested; /**< Ask the application some authentication information */
@@ -505,11 +543,11 @@ void linphone_core_iterate(LinphoneCore *lc);
 
 LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url);
 
-int linphone_core_invite(LinphoneCore *lc, const char *url);
+LinphoneCall * linphone_core_invite(LinphoneCore *lc, const char *url);
 
-int linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *addr);
+LinphoneCall * linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *addr);
 
-int linphone_core_refer(LinphoneCore *lc, const char *url);
+int linphone_core_refer(LinphoneCore *lc, LinphoneCall *call, const char *url);
 
 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc);
 
@@ -517,9 +555,17 @@ bool_t linphone_core_in_call(const LinphoneCore *lc);
 
 LinphoneCall *linphone_core_get_current_call(LinphoneCore *lc);
 
-int linphone_core_accept_call(LinphoneCore *lc, const char *url);
+int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call);
+
+int linphone_core_terminate_call(LinphoneCore *lc, LinphoneCall *call);
+
+int linphone_core_terminate_all_calls(LinphoneCore *lc);
+
+int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *call);
+
+int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *call);
 
-int linphone_core_terminate_call(LinphoneCore *lc, const char *url);
+LinphoneCall *linphone_core_get_call_by_remote_address(LinphoneCore *lc, const char *remote_address);
 
 void linphone_core_send_dtmf(LinphoneCore *lc,char dtmf);
 
@@ -775,7 +821,7 @@ void linphone_core_set_record_file(LinphoneCore *lc, const char *file);
 
 gstate_t linphone_core_get_state(const LinphoneCore *lc, gstate_group_t group);
 int linphone_core_get_current_call_duration(const LinphoneCore *lc);
-const LinphoneAddress *linphone_core_get_remote_uri(LinphoneCore *lc);
+const LinphoneAddress *linphone_core_get_remote_address(LinphoneCore *lc);
 
 int linphone_core_get_mtu(const LinphoneCore *lc);
 void linphone_core_set_mtu(LinphoneCore *lc, int mtu);
@@ -824,5 +870,8 @@ int linphone_core_get_current_call_stats(LinphoneCore *lc, rtp_stats_t *local, r
 #ifdef __cplusplus
 }
 #endif
+MSList *linphone_core_get_calls(LinphoneCore *lc);
+void *linphone_call_get_user_pointer(LinphoneCall *call);
+void linphone_call_set_user_pointer(LinphoneCall *call, void *user_pointer);
 
 #endif
diff --git a/coreapi/linphonecore_utils.h b/coreapi/linphonecore_utils.h
new file mode 100644 (file)
index 0000000..8c29ef1
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+linphone
+Copyright (C) 2010 Simon MORLAT (simon.morlat@linphone.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+#ifndef LINPHONECORE_UTILS_H
+#define LINPHONECORE_UTILS_H
+
+#ifdef IN_LINPHONE
+#include "linphonecore.h"
+#else
+#include "linphone/linphonecore.h"
+#endif
+
+typedef struct _LsdPlayer LsdPlayer;
+typedef struct _LinphoneSoundDaemon LinphoneSoundDaemon;
+
+typedef void (*LsdEndOfPlayCallback)(LsdPlayer *p);
+
+void lsd_player_set_callback(LsdPlayer *p, LsdEndOfPlayCallback cb);
+void lsd_player_set_user_pointer(LsdPlayer *p, void *up);
+void *lsd_player_get_user_pointer(const LsdPlayer *p);
+int lsd_player_play(LsdPlayer *p, const char *filename);
+int lsd_player_stop(LsdPlayer *p);
+void lsd_player_enable_loop(LsdPlayer *p, bool_t loopmode);
+bool_t lsd_player_loop_enabled(const LsdPlayer *p);
+void lsd_player_set_gain(LsdPlayer *p, float gain);
+LinphoneSoundDaemon *lsd_player_get_daemon(const LsdPlayer *p);
+
+LinphoneSoundDaemon * linphone_sound_daemon_new(const char *cardname, int rate, int nchannels);
+LsdPlayer * linphone_sound_daemon_get_player(LinphoneSoundDaemon *lsd);
+void linphone_sound_daemon_release_player(LinphoneSoundDaemon *lsd, LsdPlayer *lsdplayer);
+void linphone_sound_daemon_stop_all_players(LinphoneSoundDaemon *obj);
+void linphone_sound_daemon_release_all_players(LinphoneSoundDaemon *obj);
+void linphone_core_use_sound_daemon(LinphoneCore *lc, LinphoneSoundDaemon *lsd);
+void linphone_sound_daemon_destroy(LinphoneSoundDaemon *obj);
+
+#endif
diff --git a/coreapi/lsd.c b/coreapi/lsd.c
new file mode 100644 (file)
index 0000000..3772c89
--- /dev/null
@@ -0,0 +1,308 @@
+/*
+linphone
+Copyright (C) 2010 Simon MORLAT (simon.morlat@linphone.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+/* Linphone Sound Daemon: is a lightweight utility to play sounds to speaker during a conversation.
+ This is useful for embedded platforms, where sound apis are not performant enough to allow
+ simultaneous sound access.
+*/
+
+#include "linphonecore_utils.h"
+#include "private.h"
+#include "mediastreamer2/msticker.h"
+#include "mediastreamer2/mssndcard.h"
+#include "mediastreamer2/msaudiomixer.h"
+#include "mediastreamer2/mschanadapter.h"
+#include "mediastreamer2/msfileplayer.h"
+#include "mediastreamer2/msitc.h"
+
+
+static struct _MSSndCard *linphone_sound_daemon_get_proxy_card(LinphoneSoundDaemon *obj);
+
+#define MAX_BRANCHES 10
+
+
+struct _LsdPlayer{
+       struct _LinphoneSoundDaemon *lsd;
+       MSFilter *player;
+       MSFilter *rateconv;
+       MSFilter *chanadapter;
+       LsdEndOfPlayCallback eop_cb;
+       int mixer_pin;
+       void *user_data;
+       bool_t loop;
+       bool_t pad[3];
+};
+
+struct _LinphoneSoundDaemon {
+       int out_rate;
+       int out_nchans;
+       MSFilter *mixer;
+       MSFilter *soundout;
+       MSTicker *ticker;
+       MSSndCard *proxycard;
+       LsdPlayer branches[MAX_BRANCHES];
+};
+
+static MSFilter *create_writer(MSSndCard *c){
+       LinphoneSoundDaemon *lsd=(LinphoneSoundDaemon*)c->data;
+       MSFilter *itcsink=ms_filter_new(MS_ITC_SINK_ID);
+       ms_filter_call_method(itcsink,MS_ITC_SINK_CONNECT,lsd->branches[0].player);
+       return itcsink;
+}
+
+static MSSndCardDesc proxycard={
+       "Linphone Sound Daemon",
+       /*detect*/ NULL,
+       /*init*/ NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       /*create_reader*/ NULL,
+       create_writer,
+       /*uninit,*/
+};
+
+LsdPlayer *linphone_sound_daemon_get_player(LinphoneSoundDaemon *obj){
+       int i;
+       for(i=1;i<MAX_BRANCHES;++i){
+               LsdPlayer *b=&obj->branches[i];
+               MSFilter *p=b->player;
+               int state;
+               ms_filter_call_method(p,MS_PLAYER_GET_STATE,&state);
+               if (state==MSPlayerClosed){
+                       lsd_player_set_gain(b,1);
+                       lsd_player_enable_loop (b,FALSE);
+                       return b;
+               }
+       }
+       ms_warning("No more free players !");
+       return NULL;
+}
+
+void linphone_sound_daemon_release_player(LinphoneSoundDaemon *obj, LsdPlayer * player){
+       int state;
+       ms_filter_call_method(player->player,MS_PLAYER_GET_STATE,&state);
+       if (state!=MSPlayerClosed){
+               ms_filter_call_method(player->player,MS_PLAYER_CLOSE,&state);
+       }
+}
+
+LinphoneSoundDaemon *lsd_player_get_daemon(const LsdPlayer *p){
+       return p->lsd;
+}
+
+int lsd_player_stop(LsdPlayer *p){
+       ms_filter_call_method_noarg(p->player,MS_PLAYER_PAUSE);
+       return 0;
+}
+
+static void lsd_player_init(LsdPlayer *p, MSConnectionPoint mixer, MSFilterId playerid, LinphoneSoundDaemon *lsd){
+       MSConnectionHelper h;
+       p->player=ms_filter_new(playerid);
+       p->rateconv=ms_filter_new(MS_RESAMPLE_ID);
+       p->chanadapter=ms_filter_new(MS_CHANNEL_ADAPTER_ID);
+       
+       ms_connection_helper_start(&h);
+       ms_connection_helper_link(&h,p->player,-1,0);
+       ms_connection_helper_link(&h,p->rateconv,0,0);
+       ms_connection_helper_link(&h,p->chanadapter,0,0);
+       ms_connection_helper_link(&h,mixer.filter,mixer.pin,-1);
+       p->mixer_pin=mixer.pin;
+       p->loop=FALSE;
+       p->lsd=lsd;
+}
+
+static void lsd_player_uninit(LsdPlayer *p, MSConnectionPoint mixer){
+       MSConnectionHelper h;
+
+       ms_connection_helper_start(&h);
+       ms_connection_helper_unlink (&h,p->player,-1,0);
+       ms_connection_helper_unlink(&h,p->rateconv,0,0);
+       ms_connection_helper_unlink(&h,p->chanadapter,0,0);
+       ms_connection_helper_unlink(&h,mixer.filter,mixer.pin,-1);
+
+       ms_filter_destroy(p->player);
+       ms_filter_destroy(p->rateconv);
+       ms_filter_destroy(p->chanadapter);
+}
+
+void lsd_player_set_callback(LsdPlayer *p, LsdEndOfPlayCallback cb){
+       p->eop_cb=cb;
+}
+
+void lsd_player_set_user_pointer(LsdPlayer *p, void *up){
+       p->user_data=up;
+}
+
+void *lsd_player_get_user_pointer(const LsdPlayer *p){
+       return p->user_data;
+}
+
+static void lsd_player_on_eop(void * userdata, unsigned int id, void *arg){
+       LsdPlayer *p=(LsdPlayer *)userdata;
+       if (p->eop_cb!=NULL)
+               p->eop_cb(p);
+}
+
+static void lsd_player_configure(LsdPlayer *b){
+       int rate,chans;
+       LinphoneSoundDaemon *lsd=b->lsd;
+
+       if (ms_filter_get_id(b->player)==MS_ITC_SOURCE_ID)
+               ms_message("Configuring branch coming from audio call...");
+       
+       ms_filter_call_method(b->player,MS_FILTER_GET_SAMPLE_RATE,&rate);
+       ms_filter_call_method(b->player,MS_FILTER_GET_NCHANNELS,&chans);
+       
+       
+       ms_filter_call_method(b->rateconv,MS_FILTER_SET_SAMPLE_RATE,&rate);
+       ms_filter_call_method(b->rateconv,MS_FILTER_SET_NCHANNELS,&chans);
+       ms_filter_call_method(b->rateconv,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&lsd->out_rate);
+
+       ms_filter_call_method(b->chanadapter,MS_FILTER_SET_NCHANNELS,&chans);
+       ms_filter_call_method(b->chanadapter,MS_CHANNEL_ADAPTER_SET_OUTPUT_NCHANNELS,&lsd->out_nchans);
+       ms_message("player configured for rate=%i, channels=%i",rate,chans);
+}
+
+int lsd_player_play(LsdPlayer *b, const char *filename ){
+       int state;
+       
+       ms_filter_call_method(b->player,MS_PLAYER_GET_STATE,&state);
+       if (state!=MSPlayerClosed){
+               ms_filter_call_method_noarg(b->player,MS_PLAYER_CLOSE);
+       }
+       
+       if (ms_filter_call_method(b->player,MS_PLAYER_OPEN,(void*)filename)!=0){
+               ms_warning("Could not play %s",filename);
+               return -1;
+       }
+       ms_filter_set_notify_callback (b->player,lsd_player_on_eop,b);
+       lsd_player_configure(b);
+       ms_filter_call_method_noarg (b->player,MS_PLAYER_START);
+       return 0;
+}
+
+void lsd_player_enable_loop(LsdPlayer *p, bool_t loopmode){
+       if (ms_filter_get_id(p->player)==MS_FILE_PLAYER_ID){
+               int arg=loopmode ? 0 : -1;
+               ms_filter_call_method(p->player,MS_FILE_PLAYER_LOOP,&arg);
+               p->loop=loopmode;
+       }
+}
+
+bool_t lsd_player_loop_enabled(const LsdPlayer *p){
+       return p->loop;
+}
+
+void lsd_player_set_gain(LsdPlayer *p, float gain){
+       MSAudioMixerCtl gainctl;
+       gainctl.pin=p->mixer_pin;
+       gainctl.gain=gain;
+       ms_filter_call_method(p->lsd->mixer,MS_AUDIO_MIXER_SET_INPUT_GAIN,&gainctl);
+}
+
+LinphoneSoundDaemon * linphone_sound_daemon_new(const char *cardname, int rate, int nchannels){
+       int i;
+       MSConnectionPoint mp;
+       LinphoneSoundDaemon *lsd;
+       MSSndCard *card=ms_snd_card_manager_get_card(
+                                                    ms_snd_card_manager_get(),
+                                                    cardname);
+       if (card==NULL){
+               card=ms_snd_card_manager_get_default_playback_card (
+                                                                   ms_snd_card_manager_get());
+               if (card==NULL){
+                       ms_error("linphone_sound_daemon_new(): No playback soundcard available");
+                       return NULL;
+               }
+       }
+       
+       lsd=ms_new0(LinphoneSoundDaemon,1);
+       lsd->soundout=ms_snd_card_create_writer(card);
+       lsd->mixer=ms_filter_new(MS_AUDIO_MIXER_ID);
+       lsd->out_rate=rate;
+       lsd->out_nchans=nchannels;
+       ms_filter_call_method(lsd->soundout,MS_FILTER_SET_SAMPLE_RATE,&lsd->out_rate);
+       ms_filter_call_method(lsd->soundout,MS_FILTER_SET_NCHANNELS,&lsd->out_nchans);
+       ms_filter_call_method(lsd->mixer,MS_FILTER_SET_SAMPLE_RATE,&lsd->out_rate);
+       ms_filter_call_method(lsd->mixer,MS_FILTER_SET_NCHANNELS,&lsd->out_nchans);
+
+       mp.filter=lsd->mixer;
+       mp.pin=0;
+
+       lsd_player_init(&lsd->branches[0],mp,MS_ITC_SOURCE_ID,lsd);
+       ms_filter_set_notify_callback(lsd->branches[0].player,(MSFilterNotifyFunc)lsd_player_configure,&lsd->branches[0]);
+       ms_filter_enable_synchronous_notifcations (lsd->branches[0].player,TRUE);
+       for(i=1;i<MAX_BRANCHES;++i){
+               mp.pin=i;
+               lsd_player_init(&lsd->branches[i],mp,MS_FILE_PLAYER_ID,lsd);
+       }
+       ms_filter_link(lsd->mixer,0,lsd->soundout,0);
+       lsd->ticker=ms_ticker_new();
+       ms_ticker_attach(lsd->ticker,lsd->soundout);
+
+       lsd->proxycard=ms_snd_card_new(&proxycard);
+       lsd->proxycard->data=lsd;
+       ms_message("LinphoneSoundDaemon started with rate=%i, nchannels=%i",rate,nchannels);
+       return lsd;
+}
+
+void linphone_sound_daemon_stop_all_players(LinphoneSoundDaemon *obj){
+       int i;
+       for(i=1;i<MAX_BRANCHES;++i){
+               lsd_player_stop(&obj->branches[i]);
+       }
+}
+
+void linphone_sound_daemon_release_all_players(LinphoneSoundDaemon *obj){
+       int i;
+       for(i=1;i<MAX_BRANCHES;++i){
+               linphone_sound_daemon_release_player(obj,&obj->branches[i]);
+       }
+}
+
+void linphone_sound_daemon_destroy(LinphoneSoundDaemon *obj){
+       int i;
+       MSConnectionPoint mp;
+       ms_ticker_detach(obj->ticker,obj->soundout);
+       mp.filter=obj->mixer;
+       for(i=0;i<MAX_BRANCHES;++i){
+               mp.pin=i;
+               if (i!=0) linphone_sound_daemon_release_player(obj,&obj->branches[i]);
+               lsd_player_uninit (&obj->branches[i],mp);
+       }
+       ms_filter_unlink(obj->mixer,0,obj->soundout,0);
+       ms_ticker_destroy(obj->ticker);
+       ms_filter_destroy(obj->soundout);
+       ms_filter_destroy(obj->mixer);
+}
+
+MSSndCard *linphone_sound_daemon_get_proxy_card(LinphoneSoundDaemon *lsd){
+       return lsd->proxycard;
+}
+
+void linphone_core_use_sound_daemon(LinphoneCore *lc, LinphoneSoundDaemon *lsd){
+       if (lsd!=NULL){
+               lc->sound_conf.lsd_card=linphone_sound_daemon_get_proxy_card (lsd);
+       }else {
+               lc->sound_conf.lsd_card=NULL;
+       }
+}
index 8d9d39474525b66299b9f22de290376699b3bf6a..c56861d9df1a5ebcd1ea4c6d4b434b44e2e89798 100644 (file)
@@ -130,7 +130,8 @@ void linphone_notify_recv(LinphoneCore *lc, SalOp *op, SalSubscribeState ss, Sal
                tmp=linphone_address_as_string(friend);
                lf->status=estatus;
                lf->subscribe_active=TRUE;
-               lc->vtable.notify_presence_recv(lc,(LinphoneFriend*)lf);
+               if (lc->vtable.notify_presence_recv)
+                       lc->vtable.notify_presence_recv(lc,(LinphoneFriend*)lf);
                ms_free(tmp);
        }else{
                ms_message("But this person is not part of our friend list, so we don't care.");
index 43f4e0f083aba282141d2f413cdcc772f8642ff8..2a55b428f4272bf255155a3611f7a4ac312c5cdc 100644 (file)
 #endif
 #endif
 
-typedef enum _LCState{
-       LCStateInit,
-       LCStatePreEstablishing,
-       LCStateRinging,
-       LCStateAVRunning
-}LCState;
+
 
 
 struct _LinphoneCall
@@ -76,18 +71,19 @@ struct _LinphoneCall
        char localip[LINPHONE_IPADDR_SIZE]; /* our best guess for local ipaddress for this call */
        time_t start_time; /*time at which the call was initiated*/
        time_t media_start_time; /*time at which it was accepted, media streams established*/
-       LCState state;
+       LinphoneCallState       state;
+       int refcnt;
        bool_t media_pending;
+       void * user_pointer;
 };
 
 LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to);
 LinphoneCall * linphone_call_new_incoming(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op);
-#define linphone_call_set_state(lcall,st)      (lcall)->state=(st)
-void linphone_call_destroy(struct _LinphoneCall *obj);
+void linphone_call_set_terminated(LinphoneCall *call);
 
 /* private: */
 LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *local, LinphoneAddress * remote);
-void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call);
+void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call, LinphoneCallStatus status);
 void linphone_call_log_destroy(LinphoneCallLog *cl);
 
 
@@ -297,6 +293,7 @@ typedef struct sound_config
        struct _MSSndCard * ring_sndcard;       /* the playback sndcard currently used */
        struct _MSSndCard * play_sndcard;       /* the playback sndcard currently used */
        struct _MSSndCard * capt_sndcard; /* the capture sndcard currently used */
+       struct _MSSndCard * lsd_card; /* dummy playback card for Linphone Sound Daemon extension */
        const char **cards;
        int latency;    /* latency in samples of the current used sound device */
        char rec_lev;
@@ -365,7 +362,8 @@ struct _LinphoneCore
        MSList *auth_info;
        struct _RingStream *ringstream;
        LCCallbackObj preview_finished_cb;
-       struct _LinphoneCall *call;   /* the current call, in the future it will be a list of calls (conferencing)*/
+       LinphoneCall *current_call;   /* the current call */
+       MSList *calls;                          /* all the processed calls */
        MSList *queued_calls;   /* used by the autoreplier */
        MSList *call_logs;
        MSList *chatrooms;
@@ -374,6 +372,7 @@ struct _LinphoneCore
        struct _AudioStream *audiostream;  /**/
        struct _VideoStream *videostream;
        struct _VideoStream *previewstream;
+       struct _MSEventQueue *msevq;
        RtpTransport *a_rtp,*a_rtcp;
        MSList *bl_reqs;
        MSList *subscribers;    /* unknown subscribers */
@@ -405,4 +404,18 @@ struct _LinphoneCore
         bool_t audio_muted;
 };
 
+bool_t linphone_core_can_we_add_call(LinphoneCore *lc);
+int linphone_core_add_call( LinphoneCore *lc, LinphoneCall *call);
+int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call);
+int linphone_core_set_as_current_call(LinphoneCore *lc, LinphoneCall *call);
+int linphone_core_unset_the_current_call(LinphoneCore *lc);
+int linphone_core_get_calls_nb(const LinphoneCore *lc);
+
+#define HOLD_OFF       (0)
+#define HOLD_ON                (1)
+
+#ifndef NB_MAX_CALLS
+#define NB_MAX_CALLS   (10)
+#endif
+
 #endif /* _PRIVATE_H */
index d8d02edd99c6c0eab03af6ffee936893572b619f..c8ed11a49f583a786964fdd4f6fee6b4e9a433b8 100644 (file)
@@ -102,6 +102,7 @@ typedef struct SalStreamDescription{
        int bandwidth;
        int ptime;
        SalEndpointCandidate candidates[SAL_ENDPOINT_CANDIDATE_MAX];
+       bool_t notsending;
 } SalStreamDescription;
 
 #define SAL_MEDIA_DESCRIPTION_MAX_STREAMS 4
@@ -113,6 +114,7 @@ typedef struct SalMediaDescription{
        int nstreams;
        int bandwidth;
        SalStreamDescription streams[SAL_MEDIA_DESCRIPTION_MAX_STREAMS];
+       bool_t notsending;
 } SalMediaDescription;
 
 SalMediaDescription *sal_media_description_new();
@@ -179,7 +181,7 @@ typedef void (*SalOnCallAccepted)(SalOp *op);
 typedef void (*SalOnCallAck)(SalOp *op);
 typedef void (*SalOnCallUpdated)(SalOp *op);
 typedef void (*SalOnCallTerminated)(SalOp *op, const char *from);
-typedef void (*SalOnCallFailure)(SalOp *op, SalError error, SalReason reason, const char *details);
+typedef void (*SalOnCallFailure)(SalOp *op, SalError error, SalReason reason, const char *details, int code);
 typedef void (*SalOnAuthRequested)(SalOp *op, const char *realm, const char *username);
 typedef void (*SalOnAuthSuccess)(SalOp *op, const char *realm, const char *username);
 typedef void (*SalOnRegisterSuccess)(SalOp *op, bool_t registered);
@@ -265,6 +267,7 @@ int sal_call(SalOp *h, const char *from, const char *to);
 int sal_call_notify_ringing(SalOp *h);
 int sal_call_accept(SalOp*h);
 int sal_call_decline(SalOp *h, SalReason reason, const char *redirection /*optional*/);
+int sal_call_hold(SalOp *h, bool_t holdon);
 SalMediaDescription * sal_call_get_final_media_description(SalOp *h);
 int sal_refer(SalOp *h, const char *refer_to);
 int sal_refer_accept(SalOp *h);
@@ -306,5 +309,4 @@ void __sal_op_init(SalOp *b, Sal *sal);
 void __sal_op_set_network_origin(SalOp *op, const char *origin /*a sip uri*/);
 void __sal_op_free(SalOp *b);
 
-
 #endif
index bd3e7e664069bf47ef7ecec9e1762ea4ae136b8c..2a2c85516480425dfb747d8ce84918fc68514437 100644 (file)
@@ -421,6 +421,19 @@ static void set_sdp(osip_message_t *sip,sdp_message_t *msg){
        osip_free(sdp);
 }
 
+static void set_hold_status_to_desc(SalMediaDescription *desc, bool_t holdon)
+{
+       int i;
+       if(desc == NULL)
+               return;
+       desc->notsending = holdon;
+       for(i = 0; i < SAL_MEDIA_DESCRIPTION_MAX_STREAMS; i++)
+       {
+               if(desc->streams != NULL)
+                       desc->streams[i].notsending = holdon;//Audio
+       }
+}
+
 static void set_sdp_from_desc(osip_message_t *sip, const SalMediaDescription *desc){
        sdp_message_t *msg=media_description_to_sdp(desc);
        if (msg==NULL) {
@@ -654,9 +667,13 @@ int sal_call_send_dtmf(SalOp *h, char dtmf){
 }
 
 int sal_call_terminate(SalOp *h){
+       int err;
        eXosip_lock();
-       eXosip_call_terminate(h->cid,h->did);
+       err=eXosip_call_terminate(h->cid,h->did);
        eXosip_unlock();
+       if (err!=0){
+               ms_warning("Exosip could not terminate the call: cid=%i did=%i", h->cid,h->did);
+       }
        sal_remove_call(h->base.root,h);
        h->cid=-1;
        return 0;
@@ -855,7 +872,8 @@ static int call_proceeding(Sal *sal, eXosip_event_t *ev){
                eXosip_unlock();
                return -1;
        }
-       op->did=ev->did;
+       if (ev->did>0)
+               op->did=ev->did;
        op->tid=ev->tid;
        
        /* update contact if received and rport are set by the server
@@ -889,6 +907,9 @@ static void call_accepted(Sal *sal, eXosip_event_t *ev){
                ms_error("A closed call is accepted ?");
                return;
        }
+       if (op->did==-1){
+               op->did=ev->did;
+       }
        sdp=eXosip_get_sdp_info(ev->response);
        if (sdp){
                op->base.remote_media=sal_media_description_new();
@@ -935,7 +956,7 @@ static void call_released(Sal *sal, eXosip_event_t *ev){
        }
        op->cid=-1;
        if (op->did==-1) 
-               sal->callbacks.call_failure(op,SalErrorNoResponse,SalReasonUnknown,NULL);
+               sal->callbacks.call_failure(op,SalErrorNoResponse,SalReasonUnknown,NULL, 487);
 }
 
 static int get_auth_data_from_response(osip_message_t *resp, const char **realm, const char **username){
@@ -1097,7 +1118,7 @@ static bool_t call_failure(Sal *sal, eXosip_event_t *ev){
                                sr=SalReasonUnknown;
                        }else error=SalErrorNoResponse;
        }
-       sal->callbacks.call_failure(op,error,sr,reason);
+       sal->callbacks.call_failure(op,error,sr,reason,code);
        if (computedReason != NULL){
                ms_free(computedReason);
        }
@@ -1461,6 +1482,9 @@ static void other_request_reply(Sal *sal,eXosip_event_t *ev){
 }
 
 static bool_t process_event(Sal *sal, eXosip_event_t *ev){
+#ifdef PRINTF_DEBUG
+       printf("EVENT (%d)\n",ev->type);
+#endif
        ms_message("linphone process event get a message %d\n",ev->type);
        switch(ev->type){
                case EXOSIP_CALL_ANSWERED:
@@ -1774,3 +1798,38 @@ int sal_address_get_port_int(const SalAddress *uri) {
        }
 }
 
+/**
+ * Send a re-Invite used to hold the current call
+ *
+ * @ingroup call_control
+ * @param lc the LinphoneCore object
+ * @param url the destination of the call (sip address).
+**/
+int sal_call_hold(SalOp *h, bool_t holdon)
+{
+       int err=0;
+
+       osip_message_t *reinvite;
+       if(eXosip_call_build_request(h->did,"INVITE",&reinvite) != OSIP_SUCCESS)
+               return -1;
+       if(reinvite==NULL)
+               return -2;
+       osip_message_set_subject(reinvite,osip_strdup("Phone Call Hold"));
+       osip_message_set_allow(reinvite, "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
+       if (h->base.root->session_expires!=0){
+               osip_message_set_header(reinvite, "Session-expires", "200");
+               osip_message_set_supported(reinvite, "timer");
+       }
+       //add something to say that the distant sip phone will be in sendonly/sendrecv mode
+       if (h->base.local_media){
+               h->sdp_offering=TRUE;
+               set_hold_status_to_desc(h->base.local_media,holdon);
+               set_sdp_from_desc(reinvite,h->base.local_media);
+       }else h->sdp_offering=FALSE;
+       eXosip_lock();
+       err = eXosip_call_send_request(h->did, reinvite);
+       eXosip_unlock();
+       
+       return err;
+}
+
index 2165708b17711e0b31991891db5906a1c8d18798..2c27c523694b7991c3696b793bed979624659890 100644 (file)
@@ -121,12 +121,21 @@ static sdp_message_t *create_generic_sdp(const SalMediaDescription *desc)
                          osip_strdup ("IN"), inet6 ? osip_strdup("IP6") : osip_strdup ("IP4"),
                          osip_strdup (desc->addr));
        sdp_message_s_name_set (local, osip_strdup ("A conversation"));
-       sdp_message_c_connection_add (local, -1,
-                             osip_strdup ("IN"), inet6 ? osip_strdup ("IP6") : osip_strdup ("IP4"),
-                             osip_strdup (desc->addr), NULL, NULL);
+       if(!desc->notsending)
+       {
+               sdp_message_c_connection_add (local, -1,
+                               osip_strdup ("IN"), inet6 ? osip_strdup ("IP6") : osip_strdup ("IP4"),
+                                               osip_strdup (desc->addr), NULL, NULL);
+       }
+       else
+       {
+               sdp_message_c_connection_add (local, -1,
+                               osip_strdup ("IN"), inet6 ? osip_strdup ("IP6") : osip_strdup ("IP4"),
+                                               inet6 ? osip_strdup ("0.0.0.0.0.0") : osip_strdup ("0.0.0.0"), NULL, NULL);
+       }               
        sdp_message_t_time_descr_add (local, osip_strdup ("0"), osip_strdup ("0"));
        if (desc->bandwidth>0) sdp_message_b_bandwidth_add (local, -1, osip_strdup ("AS"),
-                                    int_2char(desc->bandwidth));
+                       int_2char(desc->bandwidth));
        return local;
 }
 
@@ -186,6 +195,10 @@ static void add_line(sdp_message_t *msg, int lineno, const SalStreamDescription
        for(elem=desc->payloads;elem!=NULL;elem=elem->next){
                add_payload(msg, lineno, (PayloadType*)elem->data);
        }
+       if(desc->notsending)//to hold the distant SIP endpoint
+               sdp_message_a_attribute_add (msg, lineno, osip_strdup ("sendonly"),NULL);
+       else
+               sdp_message_a_attribute_add (msg, lineno, osip_strdup ("sendrecv"),NULL);
 }
 
 sdp_message_t *media_description_to_sdp(const SalMediaDescription *desc){
diff --git a/coreapi/test_lsd.c b/coreapi/test_lsd.c
new file mode 100644 (file)
index 0000000..c362aa4
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+linphone
+Copyright (C) 2010 Simon MORLAT (simon.morlat@linphone.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+/* Linphone Sound Daemon: is a lightweight utility to play sounds to speaker during a conversation.
+ This is useful for embedded platforms, where sound apis are not performant enough to allow
+ simultaneous sound access.
+
+ This file is a test program that plays several sound files and places a call simultatenously.
+*/
+
+#include "linphonecore_utils.h"
+
+static void play_finished(LsdPlayer *p){
+       const char *filename=(const char *)lsd_player_get_user_pointer (p);
+       ms_message("Playing of %s is finished.",filename);
+       if (!lsd_player_loop_enabled (p)){
+               linphone_sound_daemon_release_player (lsd_player_get_daemon(p),p);
+       }
+}
+
+static void wait_a_bit(LinphoneCore *lc, int seconds){
+       time_t orig=time(NULL);
+       while(time(NULL)-orig<seconds){
+               /* we need to call iterate to receive notifications */
+               linphone_core_iterate(lc);
+               ms_usleep (50000);
+       }
+}
+
+int main(int argc, char *argv[]){
+       LinphoneCore *lc;
+       LinphoneCoreVTable vtable={0};
+       LinphoneSoundDaemon *lsd;
+       LsdPlayer *p;
+
+       linphone_core_enable_logs(stdout);
+       lc=linphone_core_new(&vtable,NULL,NULL,NULL);
+       lsd=linphone_sound_daemon_new (NULL,44100,1);
+
+       linphone_core_use_sound_daemon(lc,lsd);
+
+       /* start a play */
+       p=linphone_sound_daemon_get_player(lsd);
+       lsd_player_set_callback (p,play_finished);
+       lsd_player_set_user_pointer (p,"share/hello8000.wav");
+       lsd_player_play (p,"share/hello8000.wav");
+       wait_a_bit (lc,2);
+
+       /*start another one */
+       p=linphone_sound_daemon_get_player(lsd);
+       lsd_player_set_callback (p,play_finished);
+       lsd_player_set_user_pointer (p,"share/hello16000.wav");
+       lsd_player_enable_loop (p,TRUE);
+       lsd_player_play (p,"share/hello16000.wav");
+
+       /* after a few seconds decrease the volume */
+       wait_a_bit (lc,3);
+       lsd_player_set_gain (p,0.3);
+       wait_a_bit(lc,5);
+
+       /*now play some stereo music*/
+       p=linphone_sound_daemon_get_player(lsd);
+       lsd_player_set_callback (p,play_finished);
+       lsd_player_set_user_pointer (p,"share/rings/rock.wav");
+       lsd_player_play(p,"share/rings/rock.wav");
+       wait_a_bit(lc,2);
+
+       /*now play some stereo music at 22khz in order to test
+        stereo resampling */
+       p=linphone_sound_daemon_get_player(lsd);
+       lsd_player_set_callback (p,play_finished);
+       lsd_player_set_user_pointer (p,"share/rings/bigben.wav");
+       lsd_player_play(p,"share/rings/bigben.wav");
+       wait_a_bit(lc,6);
+
+       /* now place an outgoing call if sip address argument is given */
+       if (argc>1){
+               linphone_core_invite(lc,argv[1]);
+               wait_a_bit(lc,10);
+               linphone_core_terminate_call(lc,NULL);
+       }
+       linphone_core_use_sound_daemon(lc,NULL);
+       linphone_sound_daemon_destroy(lsd);
+       linphone_core_destroy(lc);
+       
+       return 0;
+}
index c0ddfcbbdd41db18baf142592496c64346b04afb..a17741ff4ae8f5ac5c04133854f140fa477a0d89 100644 (file)
@@ -124,7 +124,7 @@ void linphone_gtk_in_call_view_set_in_call(){
        GtkWidget *duration=linphone_gtk_get_widget(main_window,"in_call_duration");
        GtkWidget *animation=linphone_gtk_get_widget(main_window,"in_call_animation");
        GdkPixbufAnimation *pbuf=create_pixbuf_animation("incall_anim.gif");
-       const LinphoneAddress *uri=linphone_core_get_remote_uri(lc);
+       const LinphoneAddress *uri=linphone_core_get_current_call_remote_address(lc);
        char *tmp=linphone_address_as_string(uri);
        display_peer_name_in_label(callee,tmp);
        ms_free(tmp);
@@ -137,7 +137,9 @@ void linphone_gtk_in_call_view_set_in_call(){
                g_object_unref(G_OBJECT(pbuf));
        }else gtk_image_set_from_stock(GTK_IMAGE(animation),GTK_STOCK_INFO,GTK_ICON_SIZE_DIALOG);
        linphone_gtk_enable_mute_button(
-               GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(main_window,"incall_mute")),TRUE);
+                                       GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(main_window,"incall_mute")),TRUE);
+       linphone_gtk_enable_hold_button(
+               GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(main_window,"hold_call")),TRUE);
 }
 
 void linphone_gtk_in_call_view_update_duration(int duration){
@@ -175,6 +177,8 @@ void linphone_gtk_in_call_view_terminate(const char *error_msg){
        }
        linphone_gtk_enable_mute_button(
                GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(main_window,"incall_mute")),FALSE);
+       linphone_gtk_enable_hold_button(
+               GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(main_window,"hold_call")),FALSE);
        g_timeout_add_seconds(2,(GSourceFunc)in_call_view_terminated,NULL);
 }
 
@@ -202,7 +206,50 @@ void linphone_gtk_mute_toggled(GtkToggleButton *button){
        linphone_gtk_draw_mute_button(button,active);
 }
 
-void linphone_gtk_enable_mute_button(GtkToggleButton *button, gboolean sensitive){
+void linphone_gtk_enable_mute_button(GtkToggleButton *button, gboolean sensitive)
+{
        gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
        linphone_gtk_draw_mute_button(button,FALSE);
 }
+
+void linphone_gtk_draw_hold_button(GtkToggleButton *button, gboolean active){
+       GtkWidget *status=linphone_gtk_get_widget(linphone_gtk_get_main_window(),"in_call_status");
+       if (active){
+               GtkWidget *image=create_pixmap("hold_off.png");
+               gtk_button_set_label(GTK_BUTTON(button),_("HoldOff"));
+               gtk_label_set_markup(GTK_LABEL(status),_("<b>In call holded with</b>"));
+               if (image!=NULL) {
+                       gtk_button_set_image(GTK_BUTTON(button),image);
+                       gtk_widget_show(image);
+               }
+       }else{
+               GtkWidget *image=create_pixmap("hold_on.png");
+               gtk_button_set_label(GTK_BUTTON(button),_("HoldOn"));
+               gtk_label_set_markup(GTK_LABEL(status),_("<b>In call with</b>"));
+               if (image!=NULL) {
+                       gtk_button_set_image(GTK_BUTTON(button),image);
+                       gtk_widget_show(image);
+               }
+       }
+}
+
+void linphone_gtk_hold_toggled(GtkToggleButton *button){
+       GtkWidget *mw=linphone_gtk_get_main_window();
+       gboolean active=gtk_toggle_button_get_active(button);
+       if(active)
+       {
+               linphone_core_pause_call(linphone_gtk_get_core(),NULL);
+               gtk_widget_set_sensitive(linphone_gtk_get_widget(mw,"terminate_call"),FALSE);
+       }
+       else
+       {
+               linphone_core_resume_call(linphone_gtk_get_core(),NULL);
+               gtk_widget_set_sensitive(linphone_gtk_get_widget(mw,"terminate_call"),TRUE);
+       }
+       linphone_gtk_draw_hold_button(button,active);
+}
+
+void linphone_gtk_enable_hold_button(GtkToggleButton *button, gboolean sensitive){
+       gtk_widget_set_sensitive(GTK_WIDGET(button),sensitive);
+       linphone_gtk_hold_toggled(button);
+}
index b6dcd5df18212ed017f8ee329c3d643ff4dae467..85027715570c3572ece370ebb6bf27185f5e3f68 100644 (file)
@@ -92,6 +92,7 @@ void linphone_gtk_in_call_view_set_in_call(void);
 void linphone_gtk_in_call_view_update_duration(int duration);
 void linphone_gtk_in_call_view_terminate(const char *error_msg);
 void linphone_gtk_enable_mute_button(GtkToggleButton *button, gboolean sensitive);
+void linphone_gtk_enable_hold_button(GtkToggleButton *button, gboolean sensitive);
 
 void linphone_gtk_show_login_frame(LinphoneProxyConfig *cfg);
 
index 3ce841ad0bd2d97eb884375d921139e0e06c77e1..87db8fb2a4889c2c28e263003b6d981f056f0a4d 100644 (file)
@@ -42,8 +42,8 @@ static LinphoneCore *the_core=NULL;
 static GtkWidget *the_ui=NULL;
 
 static void linphone_gtk_show(LinphoneCore *lc);
-static void linphone_gtk_inv_recv(LinphoneCore *lc, const char *from);
-static void linphone_gtk_bye_recv(LinphoneCore *lc, const char *from);
+static void linphone_gtk_inv_recv(LinphoneCore *lc, LinphoneCall *call);
+static void linphone_gtk_bye_recv(LinphoneCore *lc, LinphoneCall *call);
 static void linphone_gtk_notify_recv(LinphoneCore *lc, LinphoneFriend * fid);
 static void linphone_gtk_new_unknown_subscriber(LinphoneCore *lc, LinphoneFriend *lf, const char *url);
 static void linphone_gtk_auth_info_requested(LinphoneCore *lc, const char *realm, const char *username);
@@ -54,7 +54,7 @@ static void linphone_gtk_display_url(LinphoneCore *lc, const char *msg, const ch
 static void linphone_gtk_display_question(LinphoneCore *lc, const char *question);
 static void linphone_gtk_call_log_updated(LinphoneCore *lc, LinphoneCallLog *cl);
 static void linphone_gtk_general_state(LinphoneCore *lc, LinphoneGeneralState *gstate);
-static void linphone_gtk_refer_received(LinphoneCore *lc, const char *refer_to);
+static void linphone_gtk_refer_received(LinphoneCore *lc, LinphoneCall *call, const char  *refer_to);
 static gboolean linphone_gtk_auto_answer(GtkWidget *incall_window);
 
 static LinphoneCoreVTable vtable={
@@ -390,7 +390,7 @@ static void set_video_window_decorations(GdkWindow *w){
                gdk_window_set_keep_above(w, FALSE);
        }else{
                LinphoneAddress *uri =
-                       linphone_address_clone(linphone_core_get_remote_uri(linphone_gtk_get_core()));
+                       linphone_address_clone(linphone_core_get_current_call_remote_address(linphone_gtk_get_core()));
                char *display_name;
 
                linphone_address_clean(uri);
@@ -588,7 +588,7 @@ static void linphone_gtk_call_started(GtkWidget *mw){
 
 static gboolean linphone_gtk_start_call_do(GtkWidget *uri_bar){
        const char *entered=gtk_entry_get_text(GTK_ENTRY(uri_bar));
-       if (linphone_core_invite(linphone_gtk_get_core(),entered)==0) {
+       if (linphone_core_invite(linphone_gtk_get_core(),entered)!=NULL) {
                completion_add_text(GTK_ENTRY(uri_bar),entered);
        }else{
                linphone_gtk_call_terminated(NULL);
@@ -704,10 +704,11 @@ static void linphone_gtk_show(LinphoneCore *lc){
        linphone_gtk_show_main_window();
 }
 
-static void linphone_gtk_inv_recv(LinphoneCore *lc, const char *from){
+static void linphone_gtk_inv_recv(LinphoneCore *lc, LinphoneCall *call){
        GtkWidget *w=linphone_gtk_create_window("incoming_call");
        GtkWidget *label;
        gchar *msg;
+       char *from=linphone_call_get_remote_address_as_string(call);
 
        if (auto_answer){
                g_timeout_add(2000,(GSourceFunc)linphone_gtk_auto_answer,w);
@@ -727,9 +728,10 @@ static void linphone_gtk_inv_recv(LinphoneCore *lc, const char *from){
        g_object_set_data(G_OBJECT(linphone_gtk_get_main_window()),"incoming_call",w);
        gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(linphone_gtk_get_main_window(),"uribar")),
                        from);
+       ms_free(from);
 }
 
-static void linphone_gtk_bye_recv(LinphoneCore *lc, const char *from){
+static void linphone_gtk_bye_recv(LinphoneCore *lc, LinphoneCall *call){
        
 }
 
@@ -1145,6 +1147,8 @@ static void linphone_gtk_init_main_window(){
                                        "main_mute")),FALSE);
        linphone_gtk_enable_mute_button(GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(main_window,
                                        "incall_mute")),FALSE);
+       linphone_gtk_enable_hold_button(GTK_TOGGLE_BUTTON(linphone_gtk_get_widget(main_window,
+                                       "hold_call")),FALSE);
        if (!linphone_gtk_use_in_call_view()) {
                gtk_widget_show(linphone_gtk_get_widget(main_window, "main_mute"));
        }
@@ -1206,7 +1210,7 @@ void linphone_gtk_log_handler(OrtpLogLevel lev, const char *fmt, va_list args){
 }
 
 
-static void linphone_gtk_refer_received(LinphoneCore *lc, const char *refer_to){
+static void linphone_gtk_refer_received(LinphoneCore *lc, LinphoneCall *call, const char *refer_to){
     GtkEntry * uri_bar =GTK_ENTRY(linphone_gtk_get_widget(
                linphone_gtk_get_main_window(), "uribar"));
        linphone_gtk_show_main_window();
index b858892fbddf963b593f5b7b7d155150eff240d0..67701fb238830f20818ce17956c243db7727d3ab 100644 (file)
@@ -1190,6 +1190,7 @@ Fiber Channel</property>
                                 <child>
                                   <widget class="GtkHButtonBox" id="hbuttonbox4">
                                     <property name="visible">True</property>
+                                    <property name="layout_style">spread</property>
                                     <child>
                                       <widget class="GtkToggleButton" id="incall_mute">
                                         <property name="label" translatable="yes">Mute</property>
@@ -1205,6 +1206,21 @@ Fiber Channel</property>
                                         <property name="position">0</property>
                                       </packing>
                                     </child>
+                                    <child>
+                                      <widget class="GtkToggleButton" id="hold_call">
+                                        <property name="label" translatable="yes">HoldOn</property>
+                                        <property name="visible">True</property>
+                                        <property name="sensitive">False</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">True</property>
+                                        <signal name="toggled" handler="linphone_gtk_hold_toggled"/>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
                                   </widget>
                                   <packing>
                                     <property name="expand">False</property>
index 6247f4d277e89b0a55484deac45ff07fbfc70ed7..47d2f51ab350d6eb3c4b5e17dad20b51d3267bcd 100644 (file)
@@ -3,6 +3,7 @@
 pixmapdir=$(datadir)/pixmaps/linphone
 
 pixmap_DATA= \
+hold_on.png hold_off.png \
 mic_muted.png mic_active.png \
 linphone-3-250x130.png linphone-3.png linphone2-57x57.png \
 linphone.png linphone-banner.png \
diff --git a/pixmaps/hold_off.png b/pixmaps/hold_off.png
new file mode 100644 (file)
index 0000000..61ab330
Binary files /dev/null and b/pixmaps/hold_off.png differ
diff --git a/pixmaps/hold_on.png b/pixmaps/hold_on.png
new file mode 100644 (file)
index 0000000..94469b2
Binary files /dev/null and b/pixmaps/hold_on.png differ