#include "sipsetup.h"
#include "lpconfig.h"
#include "private.h"
+
+#include <ortp/telephonyevents.h>
#include "mediastreamer2/mediastream.h"
+#include "mediastreamer2/mseventqueue.h"
#include "mediastreamer2/msvolume.h"
#include "mediastreamer2/msequalizer.h"
#include "mediastreamer2/dtmfgen.h"
-#include <ortp/telephonyevents.h>
-
-
#ifdef INET6
#ifndef WIN32
#include <netdb.h>
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)
}
-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;
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);
}
/**
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);
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);
linphone_payload_types=NULL;
}
+void linphone_core_set_state(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message){
+ if (lc->vtable.global_state_changed){
+ lc->vtable.global_state_changed(lc,gstate,message);
+ }
+}
+
static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path,
const char *factory_config_path, void * userdata)
{
memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
- gstate_initialize(lc);
- gstate_new_state(lc, GSTATE_POWER_STARTUP, NULL);
-
+ linphone_core_set_state(lc,LinphoneGlobalStartup,"Starting up");
ortp_init();
linphone_core_assign_payload_type(&payload_type_pcmu8000,0,NULL);
linphone_core_assign_payload_type(&payload_type_gsm,3,NULL);
#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)
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);
sip_config_read(lc); /* this will start eXosip*/
video_config_read(lc);
//autoreplier_config_init(&lc->autoreplier_conf);
- lc->prev_mode=LINPHONE_STATUS_ONLINE;
- lc->presence_mode=LINPHONE_STATUS_ONLINE;
+ lc->presence_mode=LinphoneStatusOnline;
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"));
+ linphone_core_set_state(lc,LinphoneGlobalOn,"Ready");
lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
lc->ready=TRUE;
* It should be unique within your application.
* @param vtable a LinphoneCoreVTable structure holding your application callbacks
* @param config_path a path to a config file. If it does not exists it will be created.
- * The config file is used to store all user settings, call logs, friends, proxies...
+ * The config file is used to store all settings, call logs, friends, proxies... so that all these settings
+ * become persistent over the life of the LinphoneCore object.
+ * It is allowed to set a NULL config file. In that case LinphoneCore will not store any settings.
* @param factory_config_path a path to a read-only config file that can be used to
* to store hard-coded preference such as proxy settings or internal preferences.
* The settings in this factory file always override the one in the normal config file.
/*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
- if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS
+ if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress
&& linphone_core_get_nat_address(lc)!=NULL){
strncpy(result,linphone_core_get_nat_address(lc),LINPHONE_IPADDR_SIZE);
return;
(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=NULL;
+ 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);
}
static void monitor_network_state(LinphoneCore *lc, time_t curtime){
* 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;
}
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==LinphoneCallOutgoingInit && (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){
- RtpSession *as=NULL,*vs=NULL;
- lc->prevtime=curtime;
- if (lc->audiostream!=NULL)
- as=lc->audiostream->session;
- if (lc->videostream!=NULL)
- vs=lc->videostream->session;
- display_bandwidth(as,vs);
+ if (call->dir==LinphoneCallIncoming && call->state==LinphoneCallOutgoingRinging){
+ 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==LinphoneCallStreamsRunning && one_second_elapsed)
+ {
+ RtpSession *as=NULL,*vs=NULL;
+ lc->prevtime=curtime;
+ if (call->audiostream!=NULL)
+ as=call->audiostream->session;
+ if (call->videostream!=NULL)
+ vs=call->videostream->session;
+ display_bandwidth(as,vs);
+ }
#ifdef VIDEO_ENABLED
- if (lc->videostream!=NULL)
- video_stream_iterate(lc->videostream);
+ if (call->videostream!=NULL)
+ video_stream_iterate(call->videostream);
#endif
- if (lc->audiostream!=NULL && disconnect_timeout>0)
- disconnected=!audio_stream_alive(lc->audiostream,disconnect_timeout);
- }
+ if (call->audiostream!=NULL && disconnect_timeout>0)
+ disconnected=!audio_stream_alive(call->audiostream,disconnect_timeout);
}
if (linphone_core_video_preview_enabled(lc)){
- if (lc->previewstream==NULL)
+ if (lc->previewstream==NULL && lc->calls==NULL)
toggle_video_preview(lc,TRUE);
#ifdef VIDEO_ENABLED
else video_stream_iterate(lc->previewstream);
toggle_video_preview(lc,FALSE);
}
if (disconnected)
- linphone_core_disconnected(lc);
+ linphone_core_disconnected(lc,call);
linphone_core_do_plugin_tasks(lc);
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."));
ms_free(enum_domain);
return NULL;
}
{
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;
return returned;
}
+void linphone_core_start_pending_refered_calls(LinphoneCore *lc){
+ MSList *elem;
+ for(elem=lc->calls;elem!=NULL;elem=elem->next){
+ LinphoneCall *call=(LinphoneCall*)elem->data;
+ if (call->refer_pending){
+ ms_message("Starting new call to refered address %s",call->refer_to);
+ call->refer_pending=FALSE;
+ linphone_core_invite(lc,call->refer_to);
+ break;
+ }
+ }
+}
+
LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
const MSList *elem;
LinphoneProxyConfig *found_cfg=NULL;
const char *localip=call->localip;
/* first use user's supplied ip address if asked*/
- if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
+ if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress){
ctt=linphone_core_get_primary_contact_parsed(lc);
return ms_strdup_printf("sip:%s@%s",linphone_address_get_username(ctt),
linphone_core_get_nat_address(lc));
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){
char *contact;
char *real_url,*barmsg;
char *from;
+
/*try to be best-effort in giving real local or routable contact address */
contact=get_fixed_contact(lc,call,dest_proxy);
if (contact){
sal_op_set_contact(call->op, contact);
ms_free(contact);
}
- call->state=LCStateInit;
- linphone_core_init_media_streams(lc,lc->call);
+
+ //TODO : should probably not be done here
+ linphone_call_init_media_streams(call);
if (!lc->sip_conf.sdp_200_ack){
call->media_pending=TRUE;
sal_call_set_local_media_description(call->op,call->localdesc);
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;
- }else gstate_new_state(lc, GSTATE_CALL_OUT_INVITE, real_url);
+ if (lc->vtable.display_status!=NULL)
+ lc->vtable.display_status(lc,_("Could not call"));
+ linphone_call_stop_media_streams(call);
+ linphone_call_set_state(call,LinphoneCallError,"Call failed");
+ }else {
+ linphone_call_set_state(call,LinphoneCallOutgoingProgress,"Outgoing call in progress");
+ }
ms_free(real_url);
ms_free(from);
return err;
* @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;
}
/**
*
* @ingroup call_control
* @param lc the LinphoneCore object
- * @param url the destination of the call (sip address).
+ * @param real_parsed_url the destination of the call (sip address).
+ *
+ * The LinphoneAddress can be constructed directly using linphone_address_new(), or
+ * created by linphone_core_interpret_url().
**/
-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;
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)){
+ if (lc->vtable.display_warning)
+ 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)){
+ if (lc->vtable.display_warning)
+ 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);
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");
+ linphone_call_unref(call);
+ return NULL;
+ }
+ /* this call becomes now the current one*/
+ lc->current_call=call;
+ linphone_call_set_state (call,LinphoneCallOutgoingInit,"Starting outgoing call");
if (dest_proxy!=NULL || lc->sip_conf.ping_with_options==FALSE){
err=linphone_core_start_invite(lc,call,dest_proxy);
}else{
/*defer the start of the call after the OPTIONS ping*/
- call->state=LCStatePreEstablishing;
call->ping_op=sal_op_new(lc->sal);
sal_ping(call->ping_op,from,real_url);
sal_op_set_user_pointer(call->ping_op,call);
}
if (real_url!=NULL) ms_free(real_url);
- return err;
+ return call;
}
-int linphone_core_refer(LinphoneCore *lc, const char *url)
+/**
+ * Performs a simple call transfer to the specified destination.
+ *
+ * The remote endpoint is expected to issue a new call to the specified destination.
+ * The current call remains active and thus can be later paused or terminated.
+**/
+int linphone_core_transfer_call(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;
real_url=linphone_address_as_string (real_parsed_url);
sal_refer(call->op,real_url);
ms_free(real_url);
+ linphone_address_destroy(real_parsed_url);
return 0;
}
-/**
- * Returns true if in 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;
- }
- return FALSE;
-}
-
-#ifdef TEST_EXT_RENDERER
-static void rendercb(void *data, const MSPicture *local, const MSPicture *remote){
- ms_message("rendercb, local buffer=%p, remote buffer=%p",
- local ? local->planes[0] : NULL, remote? remote->planes[0] : NULL);
-}
-#endif
-
-void linphone_core_init_media_streams(LinphoneCore *lc, LinphoneCall *call){
- 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)){
- const char *type=lp_config_get_string(lc->config,"sound","el_type","mic");
- if (strcasecmp(type,"mic")==0)
- audio_stream_enable_echo_limiter(lc->audiostream,ELControlMic);
- else if (strcasecmp(type,"full")==0)
- audio_stream_enable_echo_limiter(lc->audiostream,ELControlFull);
- }
- audio_stream_enable_gain_control(lc->audiostream,TRUE);
- if (linphone_core_echo_cancellation_enabled(lc)){
- int len,delay,framesize;
- len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
- delay=lp_config_get_int(lc->config,"sound","ec_delay",0);
- framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0);
- audio_stream_set_echo_canceller_params(lc->audiostream,len,delay,framesize);
- }
- audio_stream_enable_automatic_gain_control(lc->audiostream,linphone_core_agc_enabled(lc));
- {
- int enabled=lp_config_get_int(lc->config,"sound","noisegate",0);
- audio_stream_enable_noise_gate(lc->audiostream,enabled);
- }
- if (lc->a_rtp)
- rtp_session_set_transports(lc->audiostream->session,lc->a_rtp,lc->a_rtcp);
-
-#ifdef VIDEO_ENABLED
- if ((lc->video_conf.display || lc->video_conf.capture) && md->streams[1].port>0){
- lc->videostream=video_stream_new(md->streams[1].port,linphone_core_ipv6_enabled(lc));
-#ifdef TEST_EXT_RENDERER
- video_stream_set_render_callback(lc->videostream,rendercb,NULL);
-#endif
- }
-#else
- lc->videostream=NULL;
-#endif
-}
-
-static int dtmf_tab[16]={'0','1','2','3','4','5','6','7','8','9','*','#','A','B','C','D'};
-
-static void linphone_core_dtmf_received(RtpSession* s, int dtmf, void* user_data){
- LinphoneCore* lc = (LinphoneCore*)user_data;
- if (dtmf<0 || dtmf>15){
- ms_warning("Bad dtmf value %i",dtmf);
- return;
- }
- if (lc->vtable.dtmf_received != NULL)
- lc->vtable.dtmf_received(lc, dtmf_tab[dtmf]);
-}
-
-static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){
- if (st->equalizer){
- MSFilter *f=st->equalizer;
- int enabled=lp_config_get_int(lc->config,"sound","eq_active",0);
- const char *gains=lp_config_get_string(lc->config,"sound","eq_gains",NULL);
- ms_filter_call_method(f,MS_EQUALIZER_SET_ACTIVE,&enabled);
- if (enabled){
- if (gains){
- do{
- int bytes;
- MSEqualizerGain g;
- if (sscanf(gains,"%f:%f:%f %n",&g.frequency,&g.gain,&g.width,&bytes)==3){
- ms_message("Read equalizer gains: %f(~%f) --> %f",g.frequency,g.width,g.gain);
- ms_filter_call_method(f,MS_EQUALIZER_SET_GAIN,&g);
- gains+=bytes;
- }else break;
- }while(1);
- }
- }
- }
-}
-
-static void post_configure_audio_streams(LinphoneCore *lc){
- AudioStream *st=lc->audiostream;
- float mic_gain=lp_config_get_float(lc->config,"sound","mic_gain",1);
- float thres = 0;
- float recv_gain;
- float ng_thres=lp_config_get_float(lc->config,"sound","ng_thres",0.05);
- float ng_floorgain=lp_config_get_float(lc->config,"sound","ng_floorgain",0);
- int dc_removal=lp_config_get_int(lc->config,"sound","dc_removal",0);
-
- if (mic_gain!=-1)
- audio_stream_set_mic_gain(st,mic_gain);
- lc->audio_muted=FALSE;
-
- recv_gain = lc->sound_conf.soft_play_lev;
- if (recv_gain != 0) {
- linphone_core_set_playback_gain_db (lc,recv_gain);
- }
- if (st->volsend){
- ms_filter_call_method(st->volsend,MS_VOLUME_REMOVE_DC,&dc_removal);
- }
- if (linphone_core_echo_limiter_enabled(lc)){
- float speed=lp_config_get_float(lc->config,"sound","el_speed",-1);
- thres=lp_config_get_float(lc->config,"sound","el_thres",-1);
- float force=lp_config_get_float(lc->config,"sound","el_force",-1);
- int sustain=lp_config_get_int(lc->config,"sound","el_sustain",-1);
- MSFilter *f=NULL;
- if (st->el_type!=ELInactive){
- f=st->volsend;
- if (speed==-1) speed=0.03;
- if (force==-1) force=25;
- ms_filter_call_method(f,MS_VOLUME_SET_EA_SPEED,&speed);
- ms_filter_call_method(f,MS_VOLUME_SET_EA_FORCE,&force);
- if (thres!=-1)
- ms_filter_call_method(f,MS_VOLUME_SET_EA_THRESHOLD,&thres);
- if (sustain!=-1)
- ms_filter_call_method(f,MS_VOLUME_SET_EA_SUSTAIN,&sustain);
- }
- }
-
- if (st->volsend){
- ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_thres);
- ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&ng_floorgain);
- }
- if (st->volrecv){
- /* parameters for a limited noise-gate effect, using echo limiter threshold */
- float floorgain = 1/mic_gain;
- ms_filter_call_method(st->volrecv,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&thres);
- ms_filter_call_method(st->volrecv,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&floorgain);
- }
- parametrize_equalizer(lc,st);
- if (lc->vtable.dtmf_received!=NULL){
- /* replace by our default action*/
- audio_stream_play_received_dtmfs(lc->audiostream,FALSE);
- rtp_session_signal_connect(lc->audiostream->session,"telephone-event",(RtpCallback)linphone_core_dtmf_received,(unsigned long)lc);
- }
-}
-
-static RtpProfile *make_profile(LinphoneCore *lc, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){
- int bw;
- const MSList *elem;
- RtpProfile *prof=rtp_profile_new("Call profile");
- bool_t first=TRUE;
- int remote_bw=0;
- *used_pt=-1;
-
- for(elem=desc->payloads;elem!=NULL;elem=elem->next){
- PayloadType *pt=(PayloadType*)elem->data;
-
- if (first) {
- if (desc->type==SalAudio){
- linphone_core_update_allocated_audio_bandwidth_in_call(lc,pt);
- }
- *used_pt=payload_type_get_number(pt);
- first=FALSE;
- }
- if (desc->bandwidth>0) remote_bw=desc->bandwidth;
- else if (md->bandwidth>0) {
- /*case where b=AS is given globally, not per stream*/
- remote_bw=md->bandwidth;
- if (desc->type==SalVideo){
- remote_bw-=lc->audio_bw;
- }
- }
-
- if (desc->type==SalAudio){
- bw=get_min_bandwidth(lc->up_audio_bw,remote_bw);
- }else bw=get_min_bandwidth(lc->up_video_bw,remote_bw);
- if (bw>0) pt->normal_bitrate=bw*1000;
- else if (desc->type==SalAudio){
- pt->normal_bitrate=-1;
- }
- if (desc->ptime>0){
- char tmp[40];
- snprintf(tmp,sizeof(tmp),"ptime=%i",desc->ptime);
- payload_type_append_send_fmtp(pt,tmp);
- }
- rtp_profile_set_payload(prof,payload_type_get_number(pt),pt);
- }
- return prof;
-}
-
-void linphone_core_start_media_streams(LinphoneCore *lc, LinphoneCall *call){
- LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
- const char *tool="linphone-" LINPHONE_VERSION;
- char *cname;
- int used_pt=-1;
- /* 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);
-
- if (call->media_start_time==0) call->media_start_time=time(NULL);
-
- cname=linphone_address_as_string_uri_only(me);
+ LinphoneCall *call = linphone_core_get_current_call(lc);
+ if(call != NULL)
{
- const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
- SalProtoRtpAvp,SalAudio);
- 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 *captcard=lc->sound_conf.capt_sndcard;
- if (playcard==NULL) {
- ms_warning("No card defined for playback !");
- goto end;
- }
- if (captcard==NULL) {
- ms_warning("No card defined for capture !");
- goto end;
- }
- audio_stream_start_now(
- lc->audiostream,
- call->audio_profile,
- stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
- stream->port,
- stream->port+1,
- used_pt,
- jitt_comp,
- playcard,
- captcard,
- linphone_core_echo_cancellation_enabled(lc));
- }else{
- audio_stream_start_with_files(
- lc->audiostream,
- call->audio_profile,
- stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
- stream->port,
- stream->port+1,
- used_pt,
- 100,
- lc->play_file,
- lc->rec_file);
- }
- post_configure_audio_streams(lc);
- audio_stream_set_rtcp_information(lc->audiostream, cname, tool);
- }else ms_warning("No audio stream defined ?");
+ if(call->dir==LinphoneCallIncoming)
+ return TRUE;
}
-#ifdef VIDEO_ENABLED
- {
- const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
- SalProtoRtpAvp,SalVideo);
- /* shutdown preview */
- if (lc->previewstream!=NULL) {
- video_preview_stop(lc->previewstream);
- lc->previewstream=NULL;
- }
- if (stream && stream->port!=0 && (lc->video_conf.display || lc->video_conf.capture)) {
- const char *addr=stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr;
- call->video_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
- video_stream_set_sent_video_size(lc->videostream,linphone_core_get_preferred_video_size(lc));
- video_stream_enable_self_view(lc->videostream,lc->video_conf.selfview);
- if (lc->video_conf.display && lc->video_conf.capture)
- video_stream_start(lc->videostream,
- call->video_profile, addr, stream->port,
- stream->port+1,
- used_pt, jitt_comp, lc->video_conf.device);
- else if (lc->video_conf.display)
- video_stream_recv_only_start(lc->videostream,
- call->video_profile, addr, stream->port,
- used_pt, jitt_comp);
- else if (lc->video_conf.capture)
- video_stream_send_only_start(lc->videostream,
- call->video_profile, addr, stream->port,
- stream->port+1,
- used_pt, jitt_comp, lc->video_conf.device);
- video_stream_set_rtcp_information(lc->videostream, cname,tool);
- }else{
- ms_warning("No valid video stream defined.");
- }
- }
-#endif
- goto end;
- end:
- ms_free(cname);
- linphone_address_destroy(me);
- lc->call->state=LCStateAVRunning;
+ return FALSE;
}
-static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
- audio_stream_get_local_rtp_stats (st,&log->local_stats);
-}
-
-void linphone_core_stop_media_streams(LinphoneCore *lc, LinphoneCall *call){
- if (lc->audiostream!=NULL) {
- linphone_call_log_fill_stats (call->log,lc->audiostream);
- audio_stream_stop(lc->audiostream);
- lc->audiostream=NULL;
- }
-#ifdef VIDEO_ENABLED
- if (lc->videostream!=NULL){
- if (lc->video_conf.display && lc->video_conf.capture)
- video_stream_stop(lc->videostream);
- else if (lc->video_conf.display)
- video_stream_recv_only_stop(lc->videostream);
- else if (lc->video_conf.capture)
- video_stream_send_only_stop(lc->videostream);
- lc->videostream=NULL;
- }
- if (linphone_core_video_preview_enabled(lc)){
- if (lc->previewstream==NULL){
- lc->previewstream=video_preview_start(lc->video_conf.device, lc->video_conf.vsize);
- }
- }
-#endif
- if (call->audio_profile){
- rtp_profile_clear_all(call->audio_profile);
- rtp_profile_destroy(call->audio_profile);
- call->audio_profile=NULL;
- }
- if (call->video_profile){
- rtp_profile_clear_all(call->video_profile);
- rtp_profile_destroy(call->video_profile);
- call->video_profile=NULL;
- }
-}
/**
* Accept an incoming call.
*
* @ingroup call_control
* Basically the application is notified of incoming calls within the
- * invite_recv callback of the #LinphoneCoreVTable structure.
- * The application can later respond positively to the call using
+ * call_state_changed callback of the #LinphoneCoreVTable structure, where it will receive
+ * a LinphoneCallIncoming event with the associated LinphoneCall object.
+ * The application can later accept the call using
* this method.
* @param lc the LinphoneCore object
- * @param url the SIP address of the originator of the call, or NULL.
- * This argument is useful for managing multiple calls simulatenously,
- * however this feature is not supported yet.
- * Using NULL will accept the unique incoming call in progress.
+ * @param call the LinphoneCall object representing the call to be answered.
+ *
**/
-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(linphone_core_get_calls_nb (lc) != 1)
+ return -1;
+ else
+ call = (LinphoneCall*)linphone_core_get_calls(lc)->data;
}
- if (call->state==LCStateAVRunning){
+ if (lc->current_call){
+ ms_warning("Cannot accept this call, there is already one running.");
+ return -1;
+ }
+
+ if (call->state==LinphoneCallConnected){
/*call already accepted*/
return -1;
}
+ /*can accept a new call only if others are on hold */
+ {
+ MSList *elem;
+ for(elem=lc->calls;elem!=NULL;elem=elem->next){
+ LinphoneCall *c=(LinphoneCall*)elem->data;
+ if (c!=call && (c->state!=LinphoneCallPaused)){
+ ms_warning("Cannot accept this call as another one is running, pause it before.");
+ return -1;
+ }
+ }
+ }
+
/*stop ringing */
if (lc->ringstream!=NULL) {
ms_message("stop ringing");
ms_message("ring stopped");
lc->ringstream=NULL;
}
-
+
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);
if (contact)
sal_op_set_contact(call->op,contact);
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
- linphone_core_init_media_streams(lc,call);
+ linphone_call_init_media_streams(call);
#endif
sal_call_accept(call->op);
- lc->vtable.display_status(lc,_("Connected."));
- gstate_new_state(lc, GSTATE_CALL_IN_CONNECTED, NULL);
+ if (lc->vtable.display_status!=NULL)
+ lc->vtable.display_status(lc,_("Connected."));
+ lc->current_call=call;
+ linphone_call_set_state(call,LinphoneCallConnected,"Connected");
call->resultdesc=sal_call_get_final_media_description(call->op);
if (call->resultdesc){
+ linphone_call_start_media_streams(call);
+ linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
sal_media_description_ref(call->resultdesc);
- linphone_core_start_media_streams(lc, call);
}else call->media_pending=TRUE;
ms_message("call answered.");
return 0;
}
+int linphone_core_abort_call(LinphoneCore *lc, LinphoneCall *call, const char *error){
+ sal_call_terminate(call->op);
+
+ /*stop ringing*/
+ if (lc->ringstream!=NULL) {
+ ring_stop(lc->ringstream);
+ lc->ringstream=NULL;
+ }
+ linphone_call_stop_media_streams(call);
+ if (lc->vtable.display_status!=NULL)
+ lc->vtable.display_status(lc,_("Call aborted") );
+ linphone_call_set_state(call,LinphoneCallError,error);
+ return 0;
+}
+
+
/**
* Terminates a call.
*
* @ingroup call_control
- * @param lc The LinphoneCore
- * @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).
+ * @param lc the LinphoneCore
+ * @param the_call the LinphoneCall object representing the call to be terminated.
**/
-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 (ms_list_size(lc->calls)==1){
+ call=(LinphoneCall*)lc->calls->data;
+ }else{
+ ms_warning("No unique call to terminate !");
+ return -1;
+ }
+ }
+ else
+ {
+ call = the_call;
}
- lc->call=NULL;
sal_call_terminate(call->op);
/*stop ringing*/
ring_stop(lc->ringstream);
lc->ringstream=NULL;
}
- linphone_core_stop_media_streams(lc,call);
- lc->vtable.display_status(lc,_("Call ended") );
- gstate_new_state(lc, GSTATE_CALL_END, NULL);
- linphone_call_destroy(call);
+ linphone_call_stop_media_streams(call);
+ if (lc->vtable.display_status!=NULL)
+ lc->vtable.display_status(lc,_("Call ended") );
+ linphone_call_set_state(call,LinphoneCallEnd,"Call terminated");
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 current list of calls.
+ *
+ * Note that this list is read-only and might be changed by the core after a function call to linphone_core_iterate().
+ * Similarly the LinphoneCall objects inside it might be destroyed without prior notice.
+ * To hold references to LinphoneCall object into your program, you must use linphone_call_ref().
+ *
+ * @ingroup call_control
+**/
+const MSList *linphone_core_get_calls(LinphoneCore *lc)
+{
+ return 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;
}
/**
*
* @ingroup call_control
**/
-struct _LinphoneCall *linphone_core_get_current_call(LinphoneCore *lc)
+LinphoneCall *linphone_core_get_current_call(const LinphoneCore *lc)
{
- if(linphone_core_in_call(lc))
- return lc->call;
- else
- return NULL;
+ return lc->current_call;
+}
+
+/**
+ * Pauses the call. If a music file has been setup using linphone_core_set_play_file(),
+ * this file will be played to the remote user.
+ *
+ * @ingroup call_control
+**/
+int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *the_call)
+{
+ LinphoneCall *call = the_call;
+
+ if(linphone_core_get_current_call(lc) != call)
+ {
+ ms_error("The call asked to be paused was not the current on");
+ return -1;
+ }
+ if (sal_call_hold(call->op,TRUE) != 0)
+ {
+ if (lc->vtable.display_warning)
+ lc->vtable.display_warning(lc,_("Could not pause the call"));
+ }
+ linphone_call_set_state(call,LinphoneCallPausing,"Pausing call");
+ if (lc->vtable.display_status)
+ lc->vtable.display_status(lc,_("Pausing the current call..."));
+ lc->current_call=NULL;
+ linphone_core_start_pending_refered_calls(lc);
+ return 0;
+}
+
+/**
+ * Resumes the call.
+ *
+ * @ingroup call_control
+**/
+int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call)
+{
+ char temp[255]={0};
+ LinphoneCall *call = the_call;
+
+ if(call->state!=LinphoneCallPaused ){
+ ms_warning("we cannot resume a call when the communication is not established");
+ return -1;
+ }
+ if(linphone_core_get_current_call(lc) != NULL){
+ if (lc->vtable.display_warning)
+ lc->vtable.display_warning(lc,_("There is already a call in process, pause or stop it first."));
+ return -1;
+ }
+ if(sal_call_hold(call->op,FALSE) != 0){
+ return -1;
+ }
+ linphone_call_set_state (call,LinphoneCallResuming,"Resuming");
+ snprintf(temp,sizeof(temp)-1,"Resuming the call with %s",linphone_call_get_remote_address_as_string(call));
+ if (lc->vtable.display_status)
+ lc->vtable.display_status(lc,temp);
+ lc->current_call=call;
+ 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,
*/
linphone_core_send_publish(lc,presence_mode);
}
- lc->prev_mode=lc->presence_mode;
lc->presence_mode=presence_mode;
}
**/
void linphone_core_set_playback_gain_db (LinphoneCore *lc, float gaindb){
float gain=gaindb;
+ LinphoneCall *call=linphone_core_get_current_call (lc);
+ AudioStream *st;
+
lc->sound_conf.soft_play_lev=gaindb;
- AudioStream *st=lc->audiostream;
- if (!st) return; /*just return*/
+ if (call==NULL || (st=call->audiostream)==NULL){
+ ms_message("linphone_core_set_playback_gain_db(): no active call.");
+ return;
+ }
if (st->volrecv){
ms_filter_call_method(st->volrecv,MS_VOLUME_SET_DB_GAIN,&gain);
}else ms_warning("Could not apply gain: gain control wasn't activated.");
* @ingroup media_parameters
**/
float linphone_core_get_playback_gain_db(LinphoneCore *lc) {
- float gain=0;
- AudioStream *st=lc->audiostream;
- if (st->volrecv){
- ms_filter_call_method(st->volrecv,MS_VOLUME_GET_GAIN_DB,&gain);
- }else ms_warning("Could not get gain: gain control wasn't activated.");
-
- return gain;
+ return lc->sound_conf.soft_play_lev;
}
/**
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;
}
* @ingroup media_parameters
**/
void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){
- if (lc->audiostream!=NULL){
- audio_stream_set_mic_gain(lc->audiostream,
- (val==TRUE) ? 0 : 1.0); // REVISIT: take mic_gain value
- if ( linphone_core_get_rtp_no_xmit_on_audio_mute(lc) ){
- audio_stream_mute_rtp(lc->audiostream,val);
- }
- lc->audio_muted=val;
+ LinphoneCall *call=linphone_core_get_current_call(lc);
+ if (call==NULL){
+ ms_warning("linphone_core_mute_mic(): No current call !");
+ return;
+ }
+ if (call->audiostream!=NULL){
+ audio_stream_set_mic_gain(call->audiostream,
+ (val==TRUE) ? 0 : lp_config_get_float(lc->config,"sound","mic_gain",1));
+ if ( linphone_core_get_rtp_no_xmit_on_audio_mute(lc) ){
+ audio_stream_mute_rtp(call->audiostream,val);
+ }
+ call->audio_muted=val;
}
}
bool_t linphone_core_is_mic_muted(LinphoneCore *lc) {
float gain=1.0;
- if (lc->audiostream && lc->audiostream->volsend){
- ms_filter_call_method(lc->audiostream->volsend,MS_VOLUME_GET_GAIN,&gain);
+ LinphoneCall *call=linphone_core_get_current_call(lc);
+ if (call==NULL){
+ ms_warning("linphone_core_is_mic_muted(): No current call !");
+ return FALSE;
+ }
+ if (call->audiostream && call->audiostream->volsend){
+ ms_filter_call_method(call->audiostream->volsend,MS_VOLUME_GET_GAIN,&gain);
}else ms_warning("Could not get gain: gain control wasn't activated. ");
- return gain==0;
-}
-
-// returns audio mute status for active stream
-bool_t linphone_core_is_audio_muted(LinphoneCore *lc){
- if( lc->audiostream != NULL )
- return (lc->audio_muted);
- return FALSE;
+ return gain==0 || call->audio_muted;
}
// returns rtp transmission status for an active stream
// if audio is muted and config parameter rtp_no_xmit_on_audio_mute
// was set on then rtp transmission is also muted
bool_t linphone_core_is_rtp_muted(LinphoneCore *lc){
- if( (lc->audiostream != NULL) &&
- linphone_core_get_rtp_no_xmit_on_audio_mute(lc)){
- return lc->audio_muted;
+ LinphoneCall *call=linphone_core_get_current_call(lc);
+ if (call==NULL){
+ ms_warning("linphone_core_is_mic_muted(): No current call !");
+ return FALSE;
+ }
+ if( linphone_core_get_rtp_no_xmit_on_audio_mute(lc)){
+ return call->audio_muted;
}
return FALSE;
}
**/
void linphone_core_send_dtmf(LinphoneCore *lc, char dtmf)
{
+ LinphoneCall *call=linphone_core_get_current_call(lc);
+ if (call==NULL){
+ ms_warning("linphone_core_send_dtmf(): no active call");
+ return;
+ }
/*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
if (linphone_core_get_use_rfc2833_for_dtmf(lc)!=0 || linphone_core_get_use_info_for_dtmf(lc)==0)
{
/* In Band DTMF */
- if (lc->audiostream!=NULL){
- audio_stream_send_dtmf(lc->audiostream,dtmf);
+ if (call->audiostream!=NULL){
+ audio_stream_send_dtmf(call->audiostream,dtmf);
}
else
{
}
if (linphone_core_get_use_info_for_dtmf(lc)!=0){
/* Out of Band DTMF (use INFO method) */
- LinphoneCall *call=lc->call;
- if (call==NULL){
- return;
- }
sal_call_send_dtmf(call->op,dtmf);
}
}
static void toggle_video_preview(LinphoneCore *lc, bool_t val){
#ifdef VIDEO_ENABLED
- if (lc->videostream==NULL){
- if (val){
- if (lc->previewstream==NULL){
- lc->previewstream=video_preview_start(lc->video_conf.device,
- lc->video_conf.vsize);
- }
- }else{
- if (lc->previewstream!=NULL){
- video_preview_stop(lc->previewstream);
- lc->previewstream=NULL;
- }
+ if (val){
+ if (lc->previewstream==NULL){
+ lc->previewstream=video_preview_start(lc->video_conf.device,
+ lc->video_conf.vsize);
+ }
+ }else{
+ if (lc->previewstream!=NULL){
+ video_preview_stop(lc->previewstream);
+ lc->previewstream=NULL;
}
}
#endif
* This function works at any time, including during calls.
**/
void linphone_core_enable_self_view(LinphoneCore *lc, bool_t val){
- lc->video_conf.selfview=val;
#ifdef VIDEO_ENABLED
- if (lc->videostream){
- video_stream_enable_self_view(lc->videostream,val);
+ LinphoneCall *call=linphone_core_get_current_call (lc);
+ lc->video_conf.selfview=val;
+ if (call && call->videostream){
+ video_stream_enable_self_view(call->videostream,val);
}
#endif
}
int linphone_core_set_static_picture(LinphoneCore *lc, const char *path) {
#ifdef VIDEO_ENABLED
VideoStream *vs = NULL;
+ LinphoneCall *call=linphone_core_get_current_call (lc);
/* Select the video stream from the call in the first place */
- if (lc && lc->videostream) {
- vs = lc->videostream;
+ if (call && call->videostream) {
+ vs = call->videostream;
}
/* If not in call, select the video stream from the preview */
- if (vs == NULL && lc && lc->previewstream) {
+ if (vs == NULL && lc->previewstream) {
vs = lc->previewstream;
}
**/
unsigned long linphone_core_get_native_video_window_id(const LinphoneCore *lc){
#ifdef VIDEO_ENABLED
- if (lc->videostream)
- return video_stream_get_native_window_id(lc->videostream);
+ LinphoneCall *call=linphone_core_get_current_call (lc);
+ if (call && call->videostream)
+ return video_stream_get_native_window_id(call->videostream);
if (lc->previewstream)
return video_stream_get_native_window_id(lc->previewstream);
#endif
return lc->video_conf.vsize;
}
+/**
+ * Ask the core to stream audio from and to files, instead of using the soundcard.
+**/
void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
lc->use_files=yesno;
}
+/**
+ * Sets a wav file to be played when putting somebody on hold,
+ * or when files are used instead of soundcards (see linphone_core_use_files()).
+ *
+ * The file must be a 16 bit linear wav file.
+**/
void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
+ LinphoneCall *call=linphone_core_get_current_call(lc);
if (lc->play_file!=NULL){
ms_free(lc->play_file);
lc->play_file=NULL;
}
if (file!=NULL) {
lc->play_file=ms_strdup(file);
- if (lc->audiostream->ticker)
- audio_stream_play(lc->audiostream,file);
+ if (call && call->audiostream && call->audiostream->ticker)
+ audio_stream_play(call->audiostream,file);
}
}
+
+/**
+ * Sets a wav file where incoming stream is to be recorded,
+ * when files are used instead of soundcards (see linphone_core_use_files()).
+ *
+ * The file must be a 16 bit linear wav file.
+**/
void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
+ LinphoneCall *call=linphone_core_get_current_call(lc);
if (lc->rec_file!=NULL){
ms_free(lc->rec_file);
lc->rec_file=NULL;
}
if (file!=NULL) {
lc->rec_file=ms_strdup(file);
- if (lc->audiostream)
- audio_stream_record(lc->audiostream,file);
+ if (call && call->audiostream)
+ audio_stream_record(call->audiostream,file);
}
}
+
static MSFilter *get_dtmf_gen(LinphoneCore *lc){
LinphoneCall *call=linphone_core_get_current_call (lc);
if (call){
- AudioStream *stream=lc->audiostream;
+ AudioStream *stream=call->audiostream;
if (stream){
return stream->dtmfgen;
}
}
if (lc->ringstream==NULL){
- MSSndCard *ringcard= lc->sound_conf.ring_sndcard;
+ MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
lc->ringstream=ring_start(NULL,0,ringcard);
lc->dmfs_playing_start_time=time(NULL);
}else{
int linphone_core_get_current_call_stats(LinphoneCore *lc, rtp_stats_t *local, rtp_stats_t *remote){
LinphoneCall *call=linphone_core_get_current_call (lc);
if (call!=NULL){
- if (lc->audiostream!=NULL){
+ if (call->audiostream!=NULL){
memset(remote,0,sizeof(*remote));
- audio_stream_get_local_rtp_stats (lc->audiostream,local);
+ audio_stream_get_local_rtp_stats (call->audiostream,local);
return 0;
}
}
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);
+ linphone_core_set_state(lc,LinphoneGlobalShutdown,"Shutting down");
#ifdef VIDEO_ENABLED
if (lc->previewstream!=NULL){
video_preview_stop(lc->previewstream);
lc->previewstream=NULL;
}
#endif
+ ms_event_queue_destroy(lc->msevq);
/* save all config */
net_config_uninit(lc);
sip_config_uninit(lc);
linphone_core_free_payload_types();
ortp_exit();
- gstate_new_state(lc, GSTATE_POWER_OFF, NULL);
+ linphone_core_set_state(lc,LinphoneGlobalOff,"Off");
}
static void set_network_reachable(LinphoneCore* lc,bool_t isReachable){
linphone_core_uninit(lc);
ms_free(lc);
}
+/**
+ * Get the number of Call
+ *
+ * @ingroup call_control
+**/
+int linphone_core_get_calls_nb(const LinphoneCore *lc){
+ return ms_list_size(lc->calls);;
+}
+
+/**
+ * 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;
+}
+
+
+int linphone_core_add_call( LinphoneCore *lc, LinphoneCall *call)
+{
+ if(linphone_core_can_we_add_call(lc))
+ {
+ lc->calls = ms_list_append(lc->calls,call);
+ return 0;
+ }
+ return -1;
+}
+
+int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call)
+{
+ MSList *it;
+ MSList *the_calls = lc->calls;
+
+ 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;
+}
static PayloadType* find_payload_type_from_list(const char* type, int rate,const MSList* from) {
const MSList *elem;
return NULL;
}
+/**
+ * Get payload type from mime type and clock rate
+ * @ingroup media_parameters
+ * This function searches in audio and video codecs for the given payload type name and clockrate.
+ * Returns NULL if not found.
+ */
PayloadType* linphone_core_find_payload_type(LinphoneCore* lc, const char* type, int rate) {
PayloadType* result = find_payload_type_from_list(type, rate, linphone_core_get_audio_codecs(lc));
if (result) {
return result;
}
}
- //not found
+ /*not found*/
return NULL;
}