3 Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org)
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "linphonecore.h"
24 #include "mediastreamer2/mediastream.h"
25 #include "mediastreamer2/msvolume.h"
26 #include "mediastreamer2/msequalizer.h"
27 #include "mediastreamer2/mseventqueue.h"
29 #include <ortp/telephonyevents.h>
38 /*#define UNSTANDART_GSM_11K 1*/
40 static const char *liblinphone_version=LIBLINPHONE_VERSION;
41 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable);
45 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result);
46 static void toggle_video_preview(LinphoneCore *lc, bool_t val);
48 /* relative path where is stored local ring*/
49 #define LOCAL_RING "rings/oldphone.wav"
50 /* same for remote ring (ringback)*/
51 #define REMOTE_RING "ringback.wav"
53 extern SalCallbacks linphone_sal_callbacks;
55 void lc_callback_obj_init(LCCallbackObj *obj,LinphoneCoreCbFunc func,void* ud)
61 int lc_callback_obj_invoke(LCCallbackObj *obj, LinphoneCore *lc){
62 if (obj->_func!=NULL) obj->_func(lc,obj->_user_data);
67 /*prevent a gcc bug with %c*/
68 static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm){
69 #if !defined(_WIN32_WCE)
70 return strftime(s, max, fmt, tm);
77 static void set_call_log_date(LinphoneCallLog *cl, const struct tm *loctime){
78 my_strftime(cl->start_date,sizeof(cl->start_date),"%c",loctime);
81 LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
82 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
86 #if !defined(_WIN32_WCE)
87 loctime=*localtime(&call->start_time);
91 localtime_r(&call->start_time,&loctime);
93 set_call_log_date(cl,&loctime);
99 static void call_logs_write_to_config_file(LinphoneCore *lc){
104 LpConfig *cfg=lc->config;
106 if (!lc->ready) return;
108 for(i=0,elem=lc->call_logs;elem!=NULL;elem=elem->next,++i){
109 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
110 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
111 lp_config_set_int(cfg,logsection,"dir",cl->dir);
112 lp_config_set_int(cfg,logsection,"status",cl->status);
113 tmp=linphone_address_as_string(cl->from);
114 lp_config_set_string(cfg,logsection,"from",tmp);
116 tmp=linphone_address_as_string(cl->to);
117 lp_config_set_string(cfg,logsection,"to",tmp);
119 lp_config_set_string(cfg,logsection,"start_date",cl->start_date);
120 lp_config_set_int(cfg,logsection,"duration",cl->duration);
121 if (cl->refkey) lp_config_set_string(cfg,logsection,"refkey",cl->refkey);
123 for(;i<lc->max_call_logs;++i){
124 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
125 lp_config_clean_section(cfg,logsection);
129 static void call_logs_read_from_config_file(LinphoneCore *lc){
133 LpConfig *cfg=lc->config;
135 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
136 if (lp_config_has_section(cfg,logsection)){
137 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
138 cl->dir=lp_config_get_int(cfg,logsection,"dir",0);
139 cl->status=lp_config_get_int(cfg,logsection,"status",0);
140 tmp=lp_config_get_string(cfg,logsection,"from",NULL);
141 if (tmp) cl->from=linphone_address_new(tmp);
142 tmp=lp_config_get_string(cfg,logsection,"to",NULL);
143 if (tmp) cl->to=linphone_address_new(tmp);
144 tmp=lp_config_get_string(cfg,logsection,"start_date",NULL);
145 if (tmp) strncpy(cl->start_date,tmp,sizeof(cl->start_date));
146 cl->duration=lp_config_get_int(cfg,logsection,"duration",0);
147 tmp=lp_config_get_string(cfg,logsection,"refkey",NULL);
148 if (tmp) cl->refkey=ms_strdup(tmp);
149 lc->call_logs=ms_list_append(lc->call_logs,cl);
155 void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call, LinphoneCallStatus status){
156 LinphoneCore *lc=call->core;
158 calllog->duration=time(NULL)-call->start_time;
160 if (status==LinphoneCallMissed){
163 info=ortp_strdup_printf(ngettext("You have missed %i call.",
164 "You have missed %i calls.", lc->missed_calls),
166 if (lc->vtable.display_status!=NULL)
167 lc->vtable.display_status(lc,info);
169 }else calllog->status=status;
170 lc->call_logs=ms_list_prepend(lc->call_logs,(void *)calllog);
171 if (ms_list_size(lc->call_logs)>lc->max_call_logs){
172 MSList *elem,*prevelem=NULL;
173 /*find the last element*/
174 for(elem=lc->call_logs;elem!=NULL;elem=elem->next){
178 linphone_call_log_destroy((LinphoneCallLog*)elem->data);
179 lc->call_logs=ms_list_remove_link(lc->call_logs,elem);
181 if (lc->vtable.call_log_updated!=NULL){
182 lc->vtable.call_log_updated(lc,calllog);
184 call_logs_write_to_config_file(lc);
188 * @addtogroup call_logs
193 * Returns a human readable string describing the call.
195 * @note: the returned char* must be freed by the application (use ms_free()).
197 char * linphone_call_log_to_str(LinphoneCallLog *cl){
200 char *from=linphone_address_as_string (cl->from);
201 char *to=linphone_address_as_string (cl->to);
203 case LinphoneCallAborted:
206 case LinphoneCallSuccess:
207 status=_("completed");
209 case LinphoneCallMissed:
215 tmp=ortp_strdup_printf(_("%s at %s\nFrom: %s\nTo: %s\nStatus: %s\nDuration: %i mn %i sec\n"),
216 (cl->dir==LinphoneCallIncoming) ? _("Incoming call") : _("Outgoing call"),
229 * Returns RTP statistics computed locally regarding the call.
232 const rtp_stats_t *linphone_call_log_get_local_stats(const LinphoneCallLog *cl){
233 return &cl->local_stats;
237 * Returns RTP statistics computed by remote end and sent back via RTCP.
239 * @note Not implemented yet.
241 const rtp_stats_t *linphone_call_log_get_remote_stats(const LinphoneCallLog *cl){
242 return &cl->remote_stats;
245 void linphone_call_log_set_user_pointer(LinphoneCallLog *cl, void *up){
249 void *linphone_call_log_get_user_pointer(const LinphoneCallLog *cl){
250 return cl->user_pointer;
256 * Associate a persistent reference key to the call log.
258 * The reference key can be for example an id to an external database.
259 * It is stored in the config file, thus can survive to process exits/restarts.
262 void linphone_call_log_set_ref_key(LinphoneCallLog *cl, const char *refkey){
263 if (cl->refkey!=NULL){
267 if (refkey) cl->refkey=ms_strdup(refkey);
268 call_logs_write_to_config_file(cl->lc);
272 * Get the persistent reference key associated to the call log.
274 * The reference key can be for example an id to an external database.
275 * It is stored in the config file, thus can survive to process exits/restarts.
278 const char *linphone_call_log_get_ref_key(const LinphoneCallLog *cl){
284 void linphone_call_log_destroy(LinphoneCallLog *cl){
285 if (cl->from!=NULL) linphone_address_destroy(cl->from);
286 if (cl->to!=NULL) linphone_address_destroy(cl->to);
287 if (cl->refkey!=NULL) ms_free(cl->refkey);
292 * Returns TRUE if the LinphoneCall asked to autoanswer
295 bool_t linphone_call_asked_to_autoanswer(LinphoneCall *call){
296 //return TRUE if the unique(for the moment) incoming call asked to be autoanswered
298 return sal_call_autoanswer_asked(call->op);
303 int linphone_core_get_call_duration(LinphoneCall *call){
304 if (call==NULL) return 0;
305 if (call->media_start_time==0) return 0;
306 return time(NULL)-call->media_start_time;
309 int linphone_core_get_current_call_duration(const LinphoneCore *lc){
310 LinphoneCall *call=linphone_core_get_current_call((LinphoneCore *)lc);
311 return linphone_core_get_call_duration(call);
314 const LinphoneAddress *linphone_core_get_current_call_remote_address(struct _LinphoneCore *lc){
315 LinphoneCall *call=linphone_core_get_current_call(lc);
316 if (call==NULL) return NULL;
317 return linphone_call_get_remote_address(call);
321 * Enable logs in supplied FILE*.
325 * @param file a C FILE* where to fprintf logs. If null stdout is used.
328 void linphone_core_enable_logs(FILE *file){
329 if (file==NULL) file=stdout;
330 ortp_set_log_file(file);
331 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
335 * Enable logs through the user's supplied log callback.
339 * @param logfunc The address of a OrtpLogFunc callback whose protoype is
340 * typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
343 void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc){
344 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
345 ortp_set_log_handler(logfunc);
349 * Entirely disable logging.
353 void linphone_core_disable_logs(){
354 ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
359 net_config_read (LinphoneCore *lc)
363 LpConfig *config=lc->config;
365 tmp=lp_config_get_int(config,"net","download_bw",0);
366 linphone_core_set_download_bandwidth(lc,tmp);
367 tmp=lp_config_get_int(config,"net","upload_bw",0);
368 linphone_core_set_upload_bandwidth(lc,tmp);
369 linphone_core_set_stun_server(lc,lp_config_get_string(config,"net","stun_server",NULL));
370 tmpstr=lp_config_get_string(lc->config,"net","nat_address",NULL);
371 if (tmpstr!=NULL && (strlen(tmpstr)<1)) tmpstr=NULL;
372 linphone_core_set_nat_address(lc,tmpstr);
373 tmp=lp_config_get_int(lc->config,"net","firewall_policy",0);
374 linphone_core_set_firewall_policy(lc,tmp);
375 tmp=lp_config_get_int(lc->config,"net","nat_sdp_only",0);
376 lc->net_conf.nat_sdp_only=tmp;
377 tmp=lp_config_get_int(lc->config,"net","mtu",0);
378 linphone_core_set_mtu(lc,tmp);
379 tmp=lp_config_get_int(lc->config,"net","download_ptime",0);
380 linphone_core_set_download_ptime(lc,tmp);
384 static void build_sound_devices_table(LinphoneCore *lc){
385 const char **devices;
389 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
390 ndev=ms_list_size(elem);
391 devices=ms_malloc((ndev+1)*sizeof(const char *));
392 for (i=0;elem!=NULL;elem=elem->next,i++){
393 devices[i]=ms_snd_card_get_string_id((MSSndCard *)elem->data);
396 old=lc->sound_conf.cards;
397 lc->sound_conf.cards=devices;
398 if (old!=NULL) ms_free(old);
401 static void sound_config_read(LinphoneCore *lc)
408 /*alsadev let the user use custom alsa device within linphone*/
409 devid=lp_config_get_string(lc->config,"sound","alsadev",NULL);
411 MSSndCard *card=ms_alsa_card_new_custom(devid,devid);
412 ms_snd_card_manager_add_card(ms_snd_card_manager_get(),card);
415 /* retrieve all sound devices */
416 build_sound_devices_table(lc);
418 devid=lp_config_get_string(lc->config,"sound","playback_dev_id",NULL);
419 linphone_core_set_playback_device(lc,devid);
421 devid=lp_config_get_string(lc->config,"sound","ringer_dev_id",NULL);
422 linphone_core_set_ringer_device(lc,devid);
424 devid=lp_config_get_string(lc->config,"sound","capture_dev_id",NULL);
425 linphone_core_set_capture_device(lc,devid);
428 tmp=lp_config_get_int(lc->config,"sound","play_lev",80);
429 linphone_core_set_play_level(lc,tmp);
430 tmp=lp_config_get_int(lc->config,"sound","ring_lev",80);
431 linphone_core_set_ring_level(lc,tmp);
432 tmp=lp_config_get_int(lc->config,"sound","rec_lev",80);
433 linphone_core_set_rec_level(lc,tmp);
434 tmpbuf=lp_config_get_string(lc->config,"sound","source","m");
435 linphone_core_set_sound_source(lc,tmpbuf[0]);
438 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
439 tmpbuf=lp_config_get_string(lc->config,"sound","local_ring",tmpbuf);
440 if (ortp_file_exist(tmpbuf)==-1) {
441 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
443 if (strstr(tmpbuf,".wav")==NULL){
444 /* it currently uses old sound files, so replace them */
445 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
448 linphone_core_set_ring(lc,tmpbuf);
450 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
451 tmpbuf=lp_config_get_string(lc->config,"sound","remote_ring",tmpbuf);
452 if (ortp_file_exist(tmpbuf)==-1){
453 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
455 if (strstr(tmpbuf,".wav")==NULL){
456 /* it currently uses old sound files, so replace them */
457 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
459 linphone_core_set_ringback(lc,tmpbuf);
460 check_sound_device(lc);
461 lc->sound_conf.latency=0;
463 linphone_core_enable_echo_cancellation(lc,
464 lp_config_get_int(lc->config,"sound","echocancelation",0) |
465 lp_config_get_int(lc->config,"sound","echocancellation",0)
468 linphone_core_enable_echo_limiter(lc,
469 lp_config_get_int(lc->config,"sound","echolimiter",0));
470 linphone_core_enable_agc(lc,
471 lp_config_get_int(lc->config,"sound","agc",0));
473 gain=lp_config_get_float(lc->config,"sound","soft_play_lev",0);
474 linphone_core_set_soft_play_level(lc,gain);
477 static void sip_config_read(LinphoneCore *lc)
485 if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
486 sal_use_session_timers(lc->sal,200);
489 port=lp_config_get_int(lc->config,"sip","use_info",0);
490 linphone_core_set_use_info_for_dtmf(lc,port);
492 port=lp_config_get_int(lc->config,"sip","use_rfc2833",0);
493 linphone_core_set_use_rfc2833_for_dtmf(lc,port);
495 ipv6=lp_config_get_int(lc->config,"sip","use_ipv6",-1);
498 if (host_has_ipv6_network()){
499 if (lc->vtable.display_message)
500 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"));
503 linphone_core_enable_ipv6(lc,ipv6);
504 port=lp_config_get_int(lc->config,"sip","sip_port",5060);
505 linphone_core_set_sip_port(lc,port);
507 tmpstr=lp_config_get_string(lc->config,"sip","contact",NULL);
508 if (tmpstr==NULL || linphone_core_set_primary_contact(lc,tmpstr)==-1) {
509 const char *hostname=NULL;
510 const char *username=NULL;
512 hostname=getenv("HOST");
513 username=getenv("USER");
514 if (hostname==NULL) hostname=getenv("HOSTNAME");
515 #endif /*HAVE_GETENV*/
517 hostname="unknown-host";
521 contact=ortp_strdup_printf("sip:%s@%s",username,hostname);
522 linphone_core_set_primary_contact(lc,contact);
526 tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
527 linphone_core_set_guess_hostname(lc,tmp);
530 tmp=lp_config_get_int(lc->config,"sip","inc_timeout",15);
531 linphone_core_set_inc_timeout(lc,tmp);
533 /* get proxies config */
535 LinphoneProxyConfig *cfg=linphone_proxy_config_new_from_config_file(lc->config,i);
537 linphone_core_add_proxy_config(lc,cfg);
542 /* get the default proxy */
543 tmp=lp_config_get_int(lc->config,"sip","default_proxy",-1);
544 linphone_core_set_default_proxy_index(lc,tmp);
546 /* read authentication information */
548 LinphoneAuthInfo *ai=linphone_auth_info_new_from_config_file(lc->config,i);
550 linphone_core_add_auth_info(lc,ai);
551 linphone_auth_info_destroy(ai);
557 /*for tuning or test*/
558 lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
559 lc->sip_conf.only_one_codec=lp_config_get_int(lc->config,"sip","only_one_codec",0);
560 lc->sip_conf.register_only_when_network_is_up=
561 lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",1);
562 lc->sip_conf.ping_with_options=lp_config_get_int(lc->config,"sip","ping_with_options",1);
563 lc->sip_conf.auto_net_state_mon=lp_config_get_int(lc->config,"sip","auto_net_state_mon",1);
564 lc->sip_conf.keepalive_period=lp_config_get_int(lc->config,"sip","keepalive_period",10000);
565 sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
568 static void rtp_config_read(LinphoneCore *lc)
573 port=lp_config_get_int(lc->config,"rtp","audio_rtp_port",7078);
574 linphone_core_set_audio_port(lc,port);
576 port=lp_config_get_int(lc->config,"rtp","video_rtp_port",9078);
577 if (port==0) port=9078;
578 linphone_core_set_video_port(lc,port);
580 jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
581 linphone_core_set_audio_jittcomp(lc,jitt_comp);
582 jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
583 nortp_timeout=lp_config_get_int(lc->config,"rtp","nortp_timeout",30);
584 linphone_core_set_nortp_timeout(lc,nortp_timeout);
587 static PayloadType * find_payload(RtpProfile *prof, const char *mime_type, int clock_rate, const char *recv_fmtp){
588 PayloadType *candidate=NULL;
592 it=rtp_profile_get_payload(prof,i);
593 if (it!=NULL && strcasecmp(mime_type,it->mime_type)==0
594 && (clock_rate==it->clock_rate || clock_rate<=0) ){
595 if ( (recv_fmtp && it->recv_fmtp && strstr(recv_fmtp,it->recv_fmtp)!=NULL) ||
596 (recv_fmtp==NULL && it->recv_fmtp==NULL) ){
598 if (recv_fmtp) payload_type_set_recv_fmtp(it,recv_fmtp);
602 if (it->recv_fmtp==NULL) candidate=it;
607 if (candidate && recv_fmtp){
608 payload_type_set_recv_fmtp(candidate,recv_fmtp);
613 static bool_t get_codec(LpConfig *config, char* type, int index, PayloadType **ret){
615 const char *mime,*fmtp;
620 snprintf(codeckey,50,"%s_%i",type,index);
621 mime=lp_config_get_string(config,codeckey,"mime",NULL);
622 if (mime==NULL || strlen(mime)==0 ) return FALSE;
624 rate=lp_config_get_int(config,codeckey,"rate",8000);
625 fmtp=lp_config_get_string(config,codeckey,"recv_fmtp",NULL);
626 enabled=lp_config_get_int(config,codeckey,"enabled",1);
627 pt=find_payload(&av_profile,mime,rate,fmtp);
628 if (pt && enabled ) pt->flags|=PAYLOAD_TYPE_ENABLED;
629 //ms_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
630 if (pt==NULL) ms_warning("Ignoring codec config %s/%i with fmtp=%s because unsupported",
631 mime,rate,fmtp ? fmtp : "");
636 static const char *codec_pref_order[]={
649 static int find_codec_rank(const char *mime){
651 for(i=0;codec_pref_order[i]!=NULL;++i){
652 if (strcasecmp(codec_pref_order[i],mime)==0)
658 static int codec_compare(const PayloadType *a, const PayloadType *b){
660 ra=find_codec_rank(a->mime_type);
661 rb=find_codec_rank(b->mime_type);
663 if (ra<rb) return -1;
667 static MSList *add_missing_codecs(SalStreamType mtype, MSList *l){
670 PayloadType *pt=rtp_profile_get_payload(&av_profile,i);
672 if (mtype==SalVideo && pt->type!=PAYLOAD_VIDEO)
674 else if (mtype==SalAudio && (pt->type!=PAYLOAD_AUDIO_PACKETIZED
675 && pt->type!=PAYLOAD_AUDIO_CONTINUOUS)){
678 if (pt && ms_filter_codec_supported(pt->mime_type)){
679 if (ms_list_find(l,pt)==NULL){
680 payload_type_set_flag(pt,PAYLOAD_TYPE_ENABLED);
681 ms_message("Adding new codec %s/%i with fmtp %s",
682 pt->mime_type,pt->clock_rate,pt->recv_fmtp ? pt->recv_fmtp : "");
683 l=ms_list_insert_sorted(l,pt,(int (*)(const void *, const void *))codec_compare);
691 static void codecs_config_read(LinphoneCore *lc)
695 MSList *audio_codecs=NULL;
696 MSList *video_codecs=NULL;
697 for (i=0;get_codec(lc->config,"audio_codec",i,&pt);i++){
699 if (!ms_filter_codec_supported(pt->mime_type)){
700 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
701 }else audio_codecs=ms_list_append(audio_codecs,pt);
704 audio_codecs=add_missing_codecs(SalAudio,audio_codecs);
705 for (i=0;get_codec(lc->config,"video_codec",i,&pt);i++){
707 if (!ms_filter_codec_supported(pt->mime_type)){
708 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
709 }else video_codecs=ms_list_append(video_codecs,(void *)pt);
712 video_codecs=add_missing_codecs(SalVideo,video_codecs);
713 linphone_core_set_audio_codecs(lc,audio_codecs);
714 linphone_core_set_video_codecs(lc,video_codecs);
715 linphone_core_update_allocated_audio_bandwidth(lc);
718 static void video_config_read(LinphoneCore *lc){
719 int capture, display, self_view;
723 const char **devices;
727 /* retrieve all video devices */
728 elem=ms_web_cam_manager_get_list(ms_web_cam_manager_get());
729 ndev=ms_list_size(elem);
730 devices=ms_malloc((ndev+1)*sizeof(const char *));
731 for (i=0;elem!=NULL;elem=elem->next,i++){
732 devices[i]=ms_web_cam_get_string_id((MSWebCam *)elem->data);
735 lc->video_conf.cams=devices;
737 str=lp_config_get_string(lc->config,"video","device",NULL);
738 if (str && str[0]==0) str=NULL;
739 linphone_core_set_video_device(lc,str);
741 linphone_core_set_preferred_video_size_by_name(lc,
742 lp_config_get_string(lc->config,"video","size","cif"));
744 enabled=lp_config_get_int(lc->config,"video","enabled",1);
745 capture=lp_config_get_int(lc->config,"video","capture",enabled);
746 display=lp_config_get_int(lc->config,"video","display",enabled);
747 self_view=lp_config_get_int(lc->config,"video","self_view",enabled);
749 linphone_core_enable_video(lc,capture,display);
750 linphone_core_enable_self_view(lc,self_view);
754 static void ui_config_read(LinphoneCore *lc)
758 for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
759 linphone_core_add_friend(lc,lf);
761 call_logs_read_from_config_file(lc);
765 static void autoreplier_config_init(LinphoneCore *lc)
767 autoreplier_config_t *config=&lc->autoreplier_conf;
768 config->enabled=lp_config_get_int(lc->config,"autoreplier","enabled",0);
769 config->after_seconds=lp_config_get_int(lc->config,"autoreplier","after_seconds",6);
770 config->max_users=lp_config_get_int(lc->config,"autoreplier","max_users",1);
771 config->max_rec_time=lp_config_get_int(lc->config,"autoreplier","max_rec_time",60);
772 config->max_rec_msg=lp_config_get_int(lc->config,"autoreplier","max_rec_msg",10);
773 config->message=lp_config_get_string(lc->config,"autoreplier","message",NULL);
778 * Sets maximum available download bandwidth
780 * @ingroup media_parameters
782 * This is IP bandwidth, in kbit/s.
783 * This information is used signaled to other parties during
784 * calls (within SDP messages) so that the remote end can have
785 * sufficient knowledge to properly configure its audio & video
786 * codec output bitrate to not overflow available bandwidth.
788 * @param lc the LinphoneCore object
789 * @param bw the bandwidth in kbits/s, 0 for infinite
791 void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
792 lc->net_conf.download_bw=bw;
793 if (bw==0){ /*infinite*/
797 lc->dw_audio_bw=MIN(lc->audio_bw,bw);
798 lc->dw_video_bw=MAX(bw-lc->dw_audio_bw-10,0);/*-10: security margin*/
803 * Sets maximum available upload bandwidth
805 * @ingroup media_parameters
807 * This is IP bandwidth, in kbit/s.
808 * This information is used by liblinphone together with remote
809 * side available bandwidth signaled in SDP messages to properly
810 * configure audio & video codec's output bitrate.
812 * @param lc the LinphoneCore object
813 * @param bw the bandwidth in kbits/s, 0 for infinite
815 void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
816 lc->net_conf.upload_bw=bw;
817 if (bw==0){ /*infinite*/
821 lc->up_audio_bw=MIN(lc->audio_bw,bw);
822 lc->up_video_bw=MAX(bw-lc->up_audio_bw-10,0);/*-10: security margin*/
827 * Retrieve the maximum available download bandwidth.
829 * @ingroup media_parameters
831 * This value was set by linphone_core_set_download_bandwidth().
834 int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
835 return lc->net_conf.download_bw;
839 * Retrieve the maximum available upload bandwidth.
841 * @ingroup media_parameters
843 * This value was set by linphone_core_set_upload_bandwidth().
846 int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
847 return lc->net_conf.upload_bw;
850 * set audio packetization time linphone expect to received from peer
852 void linphone_core_set_download_ptime(LinphoneCore *lc, int ptime) {
853 lc->net_conf.down_ptime=ptime;
856 int linphone_core_get_download_ptime(LinphoneCore *lc) {
857 return lc->net_conf.down_ptime;
862 * Returns liblinphone's version as a string.
867 const char * linphone_core_get_version(void){
868 return liblinphone_version;
872 static MSList *linphone_payload_types=NULL;
874 static void linphone_core_assign_payload_type(PayloadType *const_pt, int number, const char *recv_fmtp){
876 pt=payload_type_clone(const_pt);
877 payload_type_set_number(pt,number);
878 if (recv_fmtp!=NULL) payload_type_set_recv_fmtp(pt,recv_fmtp);
879 rtp_profile_set_payload(&av_profile,number,pt);
880 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
883 static void linphone_core_free_payload_types(void){
884 ms_list_for_each(linphone_payload_types,(void (*)(void*))payload_type_destroy);
885 ms_list_free(linphone_payload_types);
886 linphone_payload_types=NULL;
889 static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path,
890 const char *factory_config_path, void * userdata)
892 memset (lc, 0, sizeof (LinphoneCore));
895 memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
897 gstate_initialize(lc);
898 gstate_new_state(lc, GSTATE_POWER_STARTUP, NULL);
901 linphone_core_assign_payload_type(&payload_type_pcmu8000,0,NULL);
902 linphone_core_assign_payload_type(&payload_type_gsm,3,NULL);
903 linphone_core_assign_payload_type(&payload_type_pcma8000,8,NULL);
904 linphone_core_assign_payload_type(&payload_type_lpc1015,115,NULL);
905 linphone_core_assign_payload_type(&payload_type_speex_nb,110,"vbr=on");
906 linphone_core_assign_payload_type(&payload_type_speex_wb,111,"vbr=on");
907 linphone_core_assign_payload_type(&payload_type_speex_uwb,112,"vbr=on");
908 linphone_core_assign_payload_type(&payload_type_telephone_event,101,"0-11");
909 linphone_core_assign_payload_type(&payload_type_ilbc,113,"mode=30");
910 linphone_core_assign_payload_type(&payload_type_amr,114,"octet-align=1");
912 #ifdef ENABLE_NONSTANDARD_GSM
915 pt=payload_type_clone(&payload_type_gsm);
916 pt->clock_rate=11025;
917 rtp_profile_set_payload(&av_profile,114,pt);
918 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
919 pt=payload_type_clone(&payload_type_gsm);
920 pt->clock_rate=22050;
921 rtp_profile_set_payload(&av_profile,115,pt);
922 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
927 linphone_core_assign_payload_type(&payload_type_h263,34,NULL);
928 linphone_core_assign_payload_type(&payload_type_theora,97,NULL);
929 linphone_core_assign_payload_type(&payload_type_h263_1998,98,"CIF=1;QCIF=1");
930 linphone_core_assign_payload_type(&payload_type_mp4v,99,"profile-level-id=3");
931 linphone_core_assign_payload_type(&payload_type_x_snow,100,NULL);
932 linphone_core_assign_payload_type(&payload_type_h264,102,NULL);
933 linphone_core_assign_payload_type(&payload_type_h264,103,"packetization-mode=1");
937 /* create a mediastreamer2 event queue and set it as global */
938 /* This allows to run event's callback in linphone_core_iterate() */
939 lc->msevq=ms_event_queue_new();
940 ms_set_global_event_queue(lc->msevq);
942 lc->config=lp_config_new(config_path);
943 if (factory_config_path)
944 lp_config_read_file(lc->config,factory_config_path);
947 sal_set_user_pointer(lc->sal,lc);
948 sal_set_callbacks(lc->sal,&linphone_sal_callbacks);
950 sip_setup_register_all();
951 sound_config_read(lc);
954 codecs_config_read(lc);
955 sip_config_read(lc); /* this will start eXosip*/
956 video_config_read(lc);
957 //autoreplier_config_init(&lc->autoreplier_conf);
958 lc->prev_mode=LINPHONE_STATUS_ONLINE;
959 lc->presence_mode=LINPHONE_STATUS_ONLINE;
960 lc->max_call_logs=15;
962 if (lc->vtable.display_status)
963 lc->vtable.display_status(lc,_("Ready"));
964 gstate_new_state(lc, GSTATE_POWER_ON, NULL);
965 lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
971 * Instanciates a LinphoneCore object.
972 * @ingroup initializing
974 * The LinphoneCore object is the primary handle for doing all phone actions.
975 * It should be unique within your application.
976 * @param vtable a LinphoneCoreVTable structure holding your application callbacks
977 * @param config_path a path to a config file. If it does not exists it will be created.
978 * The config file is used to store all user settings, call logs, friends, proxies...
979 * @param factory_config_path a path to a read-only config file that can be used to
980 * to store hard-coded preference such as proxy settings or internal preferences.
981 * The settings in this factory file always override the one in the normal config file.
982 * It is OPTIONAL, use NULL if unneeded.
983 * @param userdata an opaque user pointer that can be retrieved at any time (for example in
984 * callbacks) using linphone_core_get_user_data().
987 LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
988 const char *config_path, const char *factory_config_path, void * userdata)
990 LinphoneCore *core=ms_new(LinphoneCore,1);
991 linphone_core_init(core,vtable,config_path, factory_config_path, userdata);
996 * Returns the list of available audio codecs.
998 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
999 * structure holding the codec information.
1000 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1001 * (such as the order of codecs).
1003 const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
1005 return lc->codecs_conf.audio_codecs;
1009 * Returns the list of available video codecs.
1011 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1012 * structure holding the codec information.
1013 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1014 * (such as the order of codecs).
1016 const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
1018 return lc->codecs_conf.video_codecs;
1022 * Sets the local "from" identity.
1025 * This data is used in absence of any proxy configuration or when no
1026 * default proxy configuration is set. See LinphoneProxyConfig
1028 int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact)
1030 LinphoneAddress *ctt;
1032 if ((ctt=linphone_address_new(contact))==0) {
1033 ms_error("Bad contact url: %s",contact);
1036 if (lc->sip_conf.contact!=NULL) ms_free(lc->sip_conf.contact);
1037 lc->sip_conf.contact=ms_strdup(contact);
1038 if (lc->sip_conf.guessed_contact!=NULL){
1039 ms_free(lc->sip_conf.guessed_contact);
1040 lc->sip_conf.guessed_contact=NULL;
1042 linphone_address_destroy(ctt);
1047 /*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
1048 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
1049 if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
1050 strncpy(result,linphone_core_get_nat_address(lc),LINPHONE_IPADDR_SIZE);
1053 if (linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,dest,result)==0)
1055 /*else fallback to SAL routine that will attempt to find the most realistic interface */
1056 sal_get_default_local_ip(lc->sal,lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,result,LINPHONE_IPADDR_SIZE);
1059 static void update_primary_contact(LinphoneCore *lc){
1061 char tmp[LINPHONE_IPADDR_SIZE];
1063 LinphoneAddress *url;
1064 if (lc->sip_conf.guessed_contact!=NULL){
1065 ms_free(lc->sip_conf.guessed_contact);
1066 lc->sip_conf.guessed_contact=NULL;
1068 url=linphone_address_new(lc->sip_conf.contact);
1070 ms_error("Could not parse identity contact !");
1071 url=linphone_address_new("sip:unknown@unkwownhost");
1073 linphone_core_get_local_ip(lc, NULL, tmp);
1074 if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
1075 ms_warning("Local loopback network only !");
1076 lc->sip_conf.loopback_only=TRUE;
1077 }else lc->sip_conf.loopback_only=FALSE;
1078 linphone_address_set_domain(url,tmp);
1079 linphone_address_set_port_int(url,lc->sip_conf.sip_port);
1080 guessed=linphone_address_as_string(url);
1081 lc->sip_conf.guessed_contact=guessed;
1082 linphone_address_destroy(url);
1086 * Returns the default identity when no proxy configuration is used.
1090 const char *linphone_core_get_primary_contact(LinphoneCore *lc){
1093 if (lc->sip_conf.guess_hostname){
1094 if (lc->sip_conf.guessed_contact==NULL || lc->sip_conf.loopback_only){
1095 update_primary_contact(lc);
1097 identity=lc->sip_conf.guessed_contact;
1099 identity=lc->sip_conf.contact;
1105 * Tells LinphoneCore to guess local hostname automatically in primary contact.
1109 void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
1110 lc->sip_conf.guess_hostname=val;
1114 * Returns TRUE if hostname part of primary contact is guessed automatically.
1118 bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
1119 return lc->sip_conf.guess_hostname;
1123 * Same as linphone_core_get_primary_contact() but the result is a LinphoneAddress object
1124 * instead of const char*
1128 LinphoneAddress *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
1129 return linphone_address_new(linphone_core_get_primary_contact(lc));
1133 * Sets the list of audio codecs.
1135 * @ingroup media_parameters
1136 * The list is taken by the LinphoneCore thus the application should not free it.
1137 * This list is made of struct PayloadType describing the codec parameters.
1139 int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
1141 if (lc->codecs_conf.audio_codecs!=NULL) ms_list_free(lc->codecs_conf.audio_codecs);
1142 lc->codecs_conf.audio_codecs=codecs;
1147 * Sets the list of video codecs.
1149 * @ingroup media_parameters
1150 * The list is taken by the LinphoneCore thus the application should not free it.
1151 * This list is made of struct PayloadType describing the codec parameters.
1153 int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
1155 if (lc->codecs_conf.video_codecs!=NULL) ms_list_free(lc->codecs_conf.video_codecs);
1156 lc->codecs_conf.video_codecs=codecs;
1160 const MSList * linphone_core_get_friend_list(const LinphoneCore *lc)
1166 * Returns the nominal jitter buffer size in milliseconds.
1168 * @ingroup media_parameters
1170 int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
1172 return lc->rtp_conf.audio_jitt_comp;
1176 * Returns the UDP port used for audio streaming.
1178 * @ingroup network_parameters
1180 int linphone_core_get_audio_port(const LinphoneCore *lc)
1182 return lc->rtp_conf.audio_rtp_port;
1186 * Returns the UDP port used for video streaming.
1188 * @ingroup network_parameters
1190 int linphone_core_get_video_port(const LinphoneCore *lc){
1191 return lc->rtp_conf.video_rtp_port;
1196 * Returns the value in seconds of the no-rtp timeout.
1198 * @ingroup media_parameters
1199 * When no RTP or RTCP packets have been received for a while
1200 * LinphoneCore will consider the call is broken (remote end crashed or
1201 * disconnected from the network), and thus will terminate the call.
1202 * The no-rtp timeout is the duration above which the call is considered broken.
1204 int linphone_core_get_nortp_timeout(const LinphoneCore *lc){
1205 return lc->rtp_conf.nortp_timeout;
1209 * Sets the nominal audio jitter buffer size in milliseconds.
1211 * @ingroup media_parameters
1213 void linphone_core_set_audio_jittcomp(LinphoneCore *lc, int value)
1215 lc->rtp_conf.audio_jitt_comp=value;
1219 * Sets the UDP port used for audio streaming.
1221 * @ingroup network_parameters
1223 void linphone_core_set_audio_port(LinphoneCore *lc, int port)
1225 lc->rtp_conf.audio_rtp_port=port;
1229 * Sets the UDP port used for video streaming.
1231 * @ingroup network_parameters
1233 void linphone_core_set_video_port(LinphoneCore *lc, int port){
1234 lc->rtp_conf.video_rtp_port=port;
1238 * Sets the no-rtp timeout value in seconds.
1240 * @ingroup media_parameters
1241 * See linphone_core_get_nortp_timeout() for details.
1243 void linphone_core_set_nortp_timeout(LinphoneCore *lc, int nortp_timeout){
1244 lc->rtp_conf.nortp_timeout=nortp_timeout;
1248 * Indicates whether SIP INFO is used for sending digits.
1250 * @ingroup media_parameters
1252 bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
1254 return lc->sip_conf.use_info;
1258 * Sets whether SIP INFO is to be used for sending digits.
1260 * @ingroup media_parameters
1262 void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
1264 lc->sip_conf.use_info=use_info;
1268 * Indicates whether RFC2833 is used for sending digits.
1270 * @ingroup media_parameters
1272 bool_t linphone_core_get_use_rfc2833_for_dtmf(LinphoneCore *lc)
1274 return lc->sip_conf.use_rfc2833;
1278 * Sets whether RFC2833 is to be used for sending digits.
1280 * @ingroup media_parameters
1282 void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833)
1284 lc->sip_conf.use_rfc2833=use_rfc2833;
1288 * Returns the UDP port used by SIP.
1290 * @ingroup network_parameters
1292 int linphone_core_get_sip_port(LinphoneCore *lc)
1294 return lc->sip_conf.sip_port;
1297 static char _ua_name[64]="Linphone";
1298 static char _ua_version[64]=LINPHONE_VERSION;
1300 #ifdef HAVE_EXOSIP_GET_VERSION
1301 extern const char *eXosip_get_version();
1304 static void apply_user_agent(LinphoneCore *lc){
1305 char ua_string[256];
1306 snprintf(ua_string,sizeof(ua_string)-1,"%s/%s (eXosip2/%s)",_ua_name,_ua_version,
1307 #ifdef HAVE_EXOSIP_GET_VERSION
1308 eXosip_get_version()
1313 if (lc->sal) sal_set_user_agent(lc->sal,ua_string);
1317 * Sets the user agent string used in SIP messages.
1321 void linphone_core_set_user_agent(const char *name, const char *ver){
1322 strncpy(_ua_name,name,sizeof(_ua_name)-1);
1323 strncpy(_ua_version,ver,sizeof(_ua_version));
1327 * Sets the UDP port to be used by SIP.
1329 * @ingroup network_parameters
1331 int linphone_core_set_sip_port(LinphoneCore *lc,int port)
1333 const char *anyaddr;
1335 if (port==lc->sip_conf.sip_port) return 0;
1336 lc->sip_conf.sip_port=port;
1338 if (lc->sal==NULL) return -1;
1340 if (lc->sip_conf.ipv6_enabled)
1344 err=sal_listen_port (lc->sal,anyaddr,port, SalTransportDatagram,FALSE);
1346 char *msg=ortp_strdup_printf("UDP port %i seems already in use ! Cannot initialize.",port);
1348 if (lc->vtable.display_warning)
1349 lc->vtable.display_warning(lc,msg);
1353 apply_user_agent(lc);
1358 * Returns TRUE if IPv6 is enabled.
1360 * @ingroup network_parameters
1361 * See linphone_core_enable_ipv6() for more details on how IPv6 is supported in liblinphone.
1363 bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
1364 return lc->sip_conf.ipv6_enabled;
1368 * Turns IPv6 support on or off.
1370 * @ingroup network_parameters
1372 * @note IPv6 support is exclusive with IPv4 in liblinphone:
1373 * when IPv6 is turned on, IPv4 calls won't be possible anymore.
1374 * By default IPv6 support is off.
1376 void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
1377 if (lc->sip_conf.ipv6_enabled!=val){
1378 lc->sip_conf.ipv6_enabled=val;
1380 /* we need to restart eXosip */
1381 linphone_core_set_sip_port(lc, lc->sip_conf.sip_port);
1386 static void display_bandwidth(RtpSession *as, RtpSession *vs){
1387 ms_message("bandwidth usage: audio=[d=%.1f,u=%.1f] video=[d=%.1f,u=%.1f] kbit/sec",
1388 (as!=NULL) ? (rtp_session_compute_recv_bandwidth(as)*1e-3) : 0,
1389 (as!=NULL) ? (rtp_session_compute_send_bandwidth(as)*1e-3) : 0,
1390 (vs!=NULL) ? (rtp_session_compute_recv_bandwidth(vs)*1e-3) : 0,
1391 (vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0);
1394 static void linphone_core_disconnected(LinphoneCore *lc, LinphoneCall *call){
1398 from = linphone_call_get_remote_address_as_string(call);
1401 snprintf(temp,sizeof(temp),"Remote end %s seems to have disconnected, the call is going to be closed.",from);
1406 snprintf(temp,sizeof(temp),"Remote end seems to have disconnected, the call is going to be closed.");
1408 if (lc->vtable.display_warning!=NULL)
1409 lc->vtable.display_warning(lc,temp);
1410 linphone_core_terminate_call(lc,call);//TODO failure ??
1413 static void monitor_network_state(LinphoneCore *lc, time_t curtime){
1414 static time_t last_check=0;
1415 static bool_t last_status=FALSE;
1416 char result[LINPHONE_IPADDR_SIZE];
1417 bool_t new_status=last_status;
1419 /* only do the network up checking every five seconds */
1420 if (last_check==0 || (curtime-last_check)>=5){
1421 linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,NULL,result);
1422 if (strcmp(result,"::1")!=0 && strcmp(result,"127.0.0.1")!=0){
1424 }else new_status=FALSE;
1426 if (new_status!=last_status) {
1428 ms_message("New local ip address is %s",result);
1430 set_network_reachable(lc,new_status);
1431 last_status=new_status;
1436 static void proxy_update(LinphoneCore *lc){
1437 ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
1440 static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){
1441 LinphoneFriend *lf=linphone_core_get_friend_by_address(lc,info->sip_uri);
1444 ms_message("%s has a BuddyInfo assigned with image %p",info->sip_uri, info->image_data);
1445 if (lc->vtable.buddy_info_updated)
1446 lc->vtable.buddy_info_updated(lc,lf);
1448 ms_warning("Could not any friend with uri %s",info->sip_uri);
1452 static void analyze_buddy_lookup_results(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1454 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1455 for (elem=lc->bl_reqs;elem!=NULL;elem=ms_list_next(elem)){
1456 BuddyLookupRequest *req=(BuddyLookupRequest *)elem->data;
1457 if (req->status==BuddyLookupDone || req->status==BuddyLookupFailure){
1458 if (req->results!=NULL){
1459 BuddyInfo *i=(BuddyInfo*)req->results->data;
1460 ms_list_free(req->results);
1462 assign_buddy_info(lc,i);
1464 sip_setup_context_buddy_lookup_free(ctx,req);
1468 /*purge completed requests */
1469 while((elem=ms_list_find(lc->bl_reqs,NULL))!=NULL){
1470 lc->bl_reqs=ms_list_remove_link(lc->bl_reqs,elem);
1474 static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1476 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1477 for(elem=linphone_core_get_friend_list(lc);elem!=NULL;elem=elem->next){
1478 LinphoneFriend *lf=(LinphoneFriend*)elem->data;
1479 if (lf->info==NULL){
1480 if (linphone_core_lookup_known_proxy(lc,lf->uri)==cfg){
1481 if (linphone_address_get_username(lf->uri)!=NULL){
1482 BuddyLookupRequest *req;
1483 char *tmp=linphone_address_as_string_uri_only(lf->uri);
1484 req=sip_setup_context_create_buddy_lookup_request(ctx);
1485 buddy_lookup_request_set_key(req,tmp);
1486 buddy_lookup_request_set_max_results(req,1);
1487 sip_setup_context_buddy_lookup_submit(ctx,req);
1488 lc->bl_reqs=ms_list_append(lc->bl_reqs,req);
1496 static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
1497 LinphoneProxyConfig *cfg=NULL;
1498 linphone_core_get_default_proxy(lc,&cfg);
1500 if (lc->bl_refresh){
1501 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1502 if (ctx && (sip_setup_context_get_capabilities(ctx) & SIP_SETUP_CAP_BUDDY_LOOKUP)){
1503 linphone_core_grab_buddy_infos(lc,cfg);
1504 lc->bl_refresh=FALSE;
1507 if (lc->bl_reqs) analyze_buddy_lookup_results(lc,cfg);
1512 * Main loop function. It is crucial that your application call it periodically.
1514 * @ingroup initializing
1515 * linphone_core_iterate() performs various backgrounds tasks:
1516 * - receiving of SIP messages
1517 * - handles timers and timeout
1518 * - performs registration to proxies
1519 * - authentication retries
1520 * The application MUST call this function from periodically, in its main loop.
1521 * Be careful that this function must be call from the same thread as
1522 * other liblinphone methods. In not the case make sure all liblinphone calls are
1523 * serialized with a mutex.
1525 void linphone_core_iterate(LinphoneCore *lc){
1528 int disconnect_timeout = linphone_core_get_nortp_timeout(lc);
1529 time_t curtime=time(NULL);
1531 bool_t one_second_elapsed=FALSE;
1532 bool_t disconnected=FALSE;
1534 if (curtime-lc->prevtime>=1){
1535 lc->prevtime=curtime;
1536 one_second_elapsed=TRUE;
1539 if (lc->preview_finished){
1540 lc->preview_finished=0;
1541 ring_stop(lc->ringstream);
1542 lc->ringstream=NULL;
1543 lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
1546 sal_iterate(lc->sal);
1547 ms_event_queue_pump(lc->msevq);
1548 if (lc->auto_net_state_mon) monitor_network_state(lc,curtime);
1552 //we have to iterate for each call
1554 while(calls!= NULL){
1555 call = (LinphoneCall *)calls->data;
1556 /* get immediately a reference to next one in case the one
1557 we are going to examine is destroy and removed during
1558 linphone_core_start_invite() */
1560 if (call->state==LinphoneCallPreEstablishing && (curtime-call->start_time>=2)){
1561 /*start the call even if the OPTIONS reply did not arrive*/
1562 linphone_core_start_invite(lc,call,NULL);
1564 if (call->dir==LinphoneCallIncoming && call->state==LinphoneCallRinging){
1565 elapsed=curtime-call->start_time;
1566 ms_message("incoming call ringing for %i seconds",elapsed);
1567 if (elapsed>lc->sip_conf.inc_timeout){
1568 call->log->status=LinphoneCallMissed;
1569 linphone_core_terminate_call(lc,call);
1573 call = linphone_core_get_current_call(lc);
1576 if (call->state==LinphoneCallAVRunning)
1578 if (one_second_elapsed)
1580 RtpSession *as=NULL,*vs=NULL;
1581 lc->prevtime=curtime;
1582 if (lc->audiostream!=NULL)
1583 as=lc->audiostream->session;
1584 if (lc->videostream!=NULL)
1585 vs=lc->videostream->session;
1586 display_bandwidth(as,vs);
1588 #ifdef VIDEO_ENABLED
1589 if (lc->videostream!=NULL)
1590 video_stream_iterate(lc->videostream);
1592 if (lc->audiostream!=NULL && disconnect_timeout>0)
1593 disconnected=!audio_stream_alive(lc->audiostream,disconnect_timeout);
1596 if (linphone_core_video_preview_enabled(lc)){
1597 if (lc->previewstream==NULL)
1598 toggle_video_preview(lc,TRUE);
1599 #ifdef VIDEO_ENABLED
1600 else video_stream_iterate(lc->previewstream);
1603 if (lc->previewstream!=NULL)
1604 toggle_video_preview(lc,FALSE);
1607 linphone_core_disconnected(lc,call);
1609 linphone_core_do_plugin_tasks(lc);
1611 if (one_second_elapsed && lp_config_needs_commit(lc->config)){
1612 lp_config_sync(lc->config);
1617 * Interpret a call destination as supplied by the user, and returns a fully qualified
1620 * A sip address should look like DisplayName <sip:username@domain:port> .
1621 * Basically this function performs the following tasks
1622 * - if a phone number is entered, prepend country prefix of the default proxy
1623 * configuration, eventually escape the '+' by 00.
1624 * - if no domain part is supplied, append the domain name of the default proxy
1625 * - if no sip: is present, prepend it
1627 * The result is a syntaxically correct SIP address.
1630 LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url){
1631 enum_lookup_res_t *enumres=NULL;
1632 char *enum_domain=NULL;
1633 LinphoneProxyConfig *proxy=lc->default_proxy;;
1635 LinphoneAddress *uri;
1637 if (is_enum(url,&enum_domain)){
1638 if (lc->vtable.display_status!=NULL)
1639 lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
1640 if (enum_lookup(enum_domain,&enumres)<0){
1641 if (lc->vtable.display_status!=NULL)
1642 lc->vtable.display_status(lc,_("Could not resolve this number."));
1643 if(lc->vtable.failure_recv)
1644 lc->vtable.failure_recv(lc,NULL,400);
1645 ms_free(enum_domain);
1648 ms_free(enum_domain);
1649 tmpurl=enumres->sip_address[0];
1650 uri=linphone_address_new(tmpurl);
1651 enum_lookup_res_free(enumres);
1654 /* check if we have a "sip:" */
1655 if (strstr(url,"sip:")==NULL){
1656 /* this doesn't look like a true sip uri */
1657 if (strchr(url,'@')!=NULL){
1658 /* seems like sip: is missing !*/
1659 tmpurl=ms_strdup_printf("sip:%s",url);
1660 uri=linphone_address_new(tmpurl);
1668 /* append the proxy domain suffix */
1669 const char *identity=linphone_proxy_config_get_identity(proxy);
1670 char normalized_username[128];
1671 uri=linphone_address_new(identity);
1675 linphone_address_set_display_name(uri,NULL);
1676 linphone_proxy_config_normalize_number(proxy,url,normalized_username,
1677 sizeof(normalized_username));
1678 linphone_address_set_username(uri,normalized_username);
1682 uri=linphone_address_new(url);
1686 /* else we could not do anything with url given by user, so display an error */
1687 if (lc->vtable.display_warning!=NULL){
1688 lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
1694 * Returns the default identity SIP address.
1697 * This is an helper function:
1699 * If no default proxy is set, this will return the primary contact (
1700 * see linphone_core_get_primary_contact() ). If a default proxy is set
1701 * it returns the registered identity on the proxy.
1703 const char * linphone_core_get_identity(LinphoneCore *lc){
1704 LinphoneProxyConfig *proxy=NULL;
1706 linphone_core_get_default_proxy(lc,&proxy);
1708 from=linphone_proxy_config_get_identity(proxy);
1709 }else from=linphone_core_get_primary_contact(lc);
1713 const char * linphone_core_get_route(LinphoneCore *lc){
1714 LinphoneProxyConfig *proxy=NULL;
1715 const char *route=NULL;
1716 linphone_core_get_default_proxy(lc,&proxy);
1718 route=linphone_proxy_config_get_route(proxy);
1723 bool_t linphone_core_is_in_communication_with(LinphoneCore *lc, const char *to)
1727 const LinphoneAddress *la=linphone_core_get_current_call_remote_address(lc);
1732 tmp = linphone_address_as_string(la);
1742 LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
1744 LinphoneProxyConfig *found_cfg=NULL;
1745 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=elem->next){
1746 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1747 const char *domain=linphone_proxy_config_get_domain(cfg);
1748 if (domain!=NULL && strcmp(domain,linphone_address_get_domain(uri))==0){
1756 static char *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){
1757 LinphoneAddress *ctt;
1758 const char *localip=call->localip;
1760 /* first use user's supplied ip address if asked*/
1761 if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
1762 ctt=linphone_core_get_primary_contact_parsed(lc);
1763 return ms_strdup_printf("sip:%s@%s",linphone_address_get_username(ctt),
1764 linphone_core_get_nat_address(lc));
1767 /* if already choosed, don't change it */
1768 if (call->op && sal_op_get_contact(call->op)!=NULL){
1771 /* if the ping OPTIONS request succeeded use the contact guessed from the
1774 const char *guessed=sal_op_get_contact(call->ping_op);
1776 ms_message("Contact has been fixed using OPTIONS to %s",guessed);
1777 return ms_strdup(guessed);
1781 /*if using a proxy, use the contact address as guessed with the REGISTERs*/
1782 if (dest_proxy && dest_proxy->op){
1783 const char *fixed_contact=sal_op_get_contact(dest_proxy->op);
1784 if (fixed_contact) {
1785 ms_message("Contact has been fixed using proxy to %s",fixed_contact);
1786 return ms_strdup(fixed_contact);
1790 ctt=linphone_core_get_primary_contact_parsed(lc);
1794 /*otherwise use supllied localip*/
1795 linphone_address_set_domain(ctt,localip);
1796 linphone_address_set_port_int(ctt,linphone_core_get_sip_port(lc));
1797 ret=linphone_address_as_string_uri_only(ctt);
1798 linphone_address_destroy(ctt);
1799 ms_message("Contact has been fixed using local ip to %s",ret);
1805 int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphoneProxyConfig *dest_proxy){
1808 char *real_url,*barmsg;
1810 /*try to be best-effort in giving real local or routable contact address */
1811 contact=get_fixed_contact(lc,call,dest_proxy);
1813 sal_op_set_contact(call->op, contact);
1816 call->state=LinphoneCallInit;
1817 //TODO : should probably not be done here
1818 if(! linphone_core_in_call(lc) )
1819 linphone_core_init_media_streams(lc,call);
1820 if (!lc->sip_conf.sdp_200_ack){
1821 call->media_pending=TRUE;
1822 sal_call_set_local_media_description(call->op,call->localdesc);
1824 real_url=linphone_address_as_string(call->log->to);
1825 from=linphone_address_as_string(call->log->from);
1826 err=sal_call(call->op,from,real_url);
1828 if (lc->sip_conf.sdp_200_ack){
1829 call->media_pending=TRUE;
1830 sal_call_set_local_media_description(call->op,call->localdesc);
1832 barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
1833 if (lc->vtable.display_status!=NULL)
1834 lc->vtable.display_status(lc,barmsg);
1838 ms_warning("Could not initiate call.");
1839 if (lc->vtable.display_status!=NULL)
1840 lc->vtable.display_status(lc,_("could not call"));
1841 if(call == linphone_core_get_current_call(lc))
1842 linphone_core_stop_media_streams(lc,call);
1843 linphone_call_set_terminated (call);
1844 }else gstate_new_state(lc, GSTATE_CALL_OUT_INVITE, real_url);
1851 * Initiates an outgoing call
1853 * @ingroup call_control
1854 * @param lc the LinphoneCore object
1855 * @param url the destination of the call (sip address, or phone number).
1857 LinphoneCall * linphone_core_invite(LinphoneCore *lc, const char *url){
1858 LinphoneAddress *addr=linphone_core_interpret_url(lc,url);
1861 call=linphone_core_invite_address(lc,addr);
1862 linphone_address_destroy(addr);
1869 * Initiates an outgoing call given a destination LinphoneAddress
1871 * @ingroup call_control
1872 * @param lc the LinphoneCore object
1873 * @param url the destination of the call (sip address).
1875 LinphoneCall * linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *real_parsed_url)
1878 const char *route=NULL;
1879 const char *from=NULL;
1880 LinphoneProxyConfig *proxy=NULL;
1881 LinphoneAddress *parsed_url2=NULL;
1882 char *real_url=NULL;
1883 LinphoneProxyConfig *dest_proxy=NULL;
1886 if (linphone_core_in_call(lc)){
1887 lc->vtable.display_warning(lc,_("Sorry, you have to pause or stop the current call first !"));
1890 if(!linphone_core_can_we_add_call(lc)){
1891 lc->vtable.display_warning(lc,_("Sorry, we have reached the maximum number of simultaneous calls"));
1894 linphone_core_get_default_proxy(lc,&proxy);
1895 route=linphone_core_get_route(lc);
1897 real_url=linphone_address_as_string(real_parsed_url);
1898 dest_proxy=linphone_core_lookup_known_proxy(lc,real_parsed_url);
1900 if (proxy!=dest_proxy && dest_proxy!=NULL) {
1901 ms_message("Overriding default proxy setting for this call:");
1902 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
1905 if (dest_proxy!=NULL)
1906 from=linphone_proxy_config_get_identity(dest_proxy);
1907 else if (proxy!=NULL)
1908 from=linphone_proxy_config_get_identity(proxy);
1910 /* if no proxy or no identity defined for this proxy, default to primary contact*/
1911 if (from==NULL) from=linphone_core_get_primary_contact(lc);
1913 parsed_url2=linphone_address_new(from);
1915 call=linphone_call_new_outgoing(lc,parsed_url2,linphone_address_clone(real_parsed_url));
1916 sal_op_set_route(call->op,route);
1918 if(linphone_core_add_call(lc,call)!= 0)
1920 ms_warning("we had a problem in adding the call into the invite ... weird\n");
1921 linphone_call_unref(call);
1924 if (dest_proxy!=NULL || lc->sip_conf.ping_with_options==FALSE){
1925 err=linphone_core_start_invite(lc,call,dest_proxy);
1927 /*defer the start of the call after the OPTIONS ping*/
1928 call->state=LinphoneCallPreEstablishing;
1929 call->ping_op=sal_op_new(lc->sal);
1930 sal_ping(call->ping_op,from,real_url);
1931 sal_op_set_user_pointer(call->ping_op,call);
1932 call->start_time=time(NULL);
1935 if (real_url!=NULL) ms_free(real_url);
1939 int linphone_core_refer(LinphoneCore *lc, LinphoneCall *call, const char *url)
1941 char *real_url=NULL;
1942 LinphoneAddress *real_parsed_url=linphone_core_interpret_url(lc,url);
1944 if (!real_parsed_url){
1949 ms_warning("No established call to refer.");
1952 //lc->call=NULL; //Do not do that you will lose the call afterward . . .
1953 real_url=linphone_address_as_string (real_parsed_url);
1954 sal_refer(call->op,real_url);
1960 * Returns true if an incoming call is pending, ie waiting for being answered or declined.
1962 * @ingroup call_control
1964 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
1965 LinphoneCall *call = linphone_core_get_current_call(lc);
1968 if(call->dir==LinphoneCallIncoming)
1974 void linphone_core_init_media_streams(LinphoneCore *lc, LinphoneCall *call){
1976 printf("%s(%d)\n",__FUNCTION__,__LINE__);
1978 SalMediaDescription *md=call->localdesc;
1979 lc->audiostream=audio_stream_new(md->streams[0].port,linphone_core_ipv6_enabled(lc));
1980 if (linphone_core_echo_limiter_enabled(lc)){
1981 const char *type=lp_config_get_string(lc->config,"sound","el_type","mic");
1982 if (strcasecmp(type,"mic")==0)
1983 audio_stream_enable_echo_limiter(lc->audiostream,ELControlMic);
1984 else if (strcasecmp(type,"speaker")==0)
1985 audio_stream_enable_echo_limiter(lc->audiostream,ELControlSpeaker);
1987 audio_stream_enable_gain_control(lc->audiostream,TRUE);
1988 if (linphone_core_echo_cancellation_enabled(lc)){
1989 int len,delay,framesize;
1990 len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
1991 delay=lp_config_get_int(lc->config,"sound","ec_delay",0);
1992 framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0);
1993 audio_stream_set_echo_canceller_params(lc->audiostream,len,delay,framesize);
1995 audio_stream_enable_automatic_gain_control(lc->audiostream,linphone_core_agc_enabled(lc));
1997 int enabled=lp_config_get_int(lc->config,"sound","noisegate",0);
1998 audio_stream_enable_noise_gate(lc->audiostream,enabled);
2001 rtp_session_set_transports(lc->audiostream->session,lc->a_rtp,lc->a_rtcp);
2003 #ifdef VIDEO_ENABLED
2004 if ((lc->video_conf.display || lc->video_conf.capture) && md->streams[1].port>0)
2005 lc->videostream=video_stream_new(md->streams[1].port,linphone_core_ipv6_enabled(lc));
2007 lc->videostream=NULL;
2011 static int dtmf_tab[16]={'0','1','2','3','4','5','6','7','8','9','*','#','A','B','C','D'};
2013 static void linphone_core_dtmf_received(RtpSession* s, int dtmf, void* user_data){
2014 LinphoneCore* lc = (LinphoneCore*)user_data;
2015 if (dtmf<0 || dtmf>15){
2016 ms_warning("Bad dtmf value %i",dtmf);
2019 if (lc->vtable.dtmf_received != NULL)
2020 lc->vtable.dtmf_received(lc, dtmf_tab[dtmf]);
2023 static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){
2025 MSFilter *f=st->equalizer;
2026 int enabled=lp_config_get_int(lc->config,"sound","eq_active",0);
2027 const char *gains=lp_config_get_string(lc->config,"sound","eq_gains",NULL);
2028 ms_filter_call_method(f,MS_EQUALIZER_SET_ACTIVE,&enabled);
2034 if (sscanf(gains,"%f:%f:%f %n",&g.frequency,&g.gain,&g.width,&bytes)==3){
2035 ms_message("Read equalizer gains: %f(~%f) --> %f",g.frequency,g.width,g.gain);
2036 ms_filter_call_method(f,MS_EQUALIZER_SET_GAIN,&g);
2045 static void post_configure_audio_streams(LinphoneCore *lc){
2046 AudioStream *st=lc->audiostream;
2047 float gain=lp_config_get_float(lc->config,"sound","mic_gain",-1);
2049 audio_stream_set_mic_gain(st,gain);
2050 float recv_gain = lc->sound_conf.soft_play_lev;
2051 if (recv_gain != 0) {
2052 linphone_core_set_soft_play_level(lc,recv_gain);
2054 if (linphone_core_echo_limiter_enabled(lc)){
2055 float speed=lp_config_get_float(lc->config,"sound","el_speed",-1);
2056 float thres=lp_config_get_float(lc->config,"sound","el_thres",-1);
2057 float force=lp_config_get_float(lc->config,"sound","el_force",-1);
2058 int sustain=lp_config_get_int(lc->config,"sound","el_sustain",-1);
2060 if (st->el_type==ELControlMic){
2062 if (speed==-1) speed=0.03;
2063 if (force==-1) force=10;
2065 else if (st->el_type==ELControlSpeaker){
2067 if (speed==-1) speed=0.02;
2068 if (force==-1) force=5;
2071 ms_filter_call_method(f,MS_VOLUME_SET_EA_SPEED,&speed);
2073 ms_filter_call_method(f,MS_VOLUME_SET_EA_THRESHOLD,&thres);
2075 ms_filter_call_method(f,MS_VOLUME_SET_EA_FORCE,&force);
2077 ms_filter_call_method(f,MS_VOLUME_SET_EA_SUSTAIN,&sustain);
2081 float ng_thres=lp_config_get_float(lc->config,"sound","ng_thres",0.05);
2082 float ng_floorgain=lp_config_get_float(lc->config,"sound","ng_floorgain",0);
2083 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_thres);
2084 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&ng_floorgain);
2086 parametrize_equalizer(lc,st);
2087 if (lc->vtable.dtmf_received!=NULL){
2088 /* replace by our default action*/
2089 audio_stream_play_received_dtmfs(lc->audiostream,FALSE);
2090 rtp_session_signal_connect(lc->audiostream->session,"telephone-event",(RtpCallback)linphone_core_dtmf_received,(unsigned long)lc);
2094 static RtpProfile *make_profile(LinphoneCore *lc, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){
2097 RtpProfile *prof=rtp_profile_new("Call profile");
2101 for(elem=desc->payloads;elem!=NULL;elem=elem->next){
2102 PayloadType *pt=(PayloadType*)elem->data;
2105 if (desc->type==SalAudio){
2106 linphone_core_update_allocated_audio_bandwidth_in_call(lc,pt);
2108 *used_pt=payload_type_get_number(pt);
2111 if (desc->bandwidth>0) remote_bw=desc->bandwidth;
2112 else if (md->bandwidth>0) {
2113 /*case where b=AS is given globally, not per stream*/
2114 remote_bw=md->bandwidth;
2115 if (desc->type==SalVideo){
2116 remote_bw-=lc->audio_bw;
2120 if (desc->type==SalAudio){
2121 bw=get_min_bandwidth(lc->up_audio_bw,remote_bw);
2122 }else bw=get_min_bandwidth(lc->up_video_bw,remote_bw);
2123 if (bw>0) pt->normal_bitrate=bw*1000;
2124 else if (desc->type==SalAudio){
2125 pt->normal_bitrate=-1;
2129 snprintf(tmp,sizeof(tmp),"ptime=%i",desc->ptime);
2130 payload_type_append_send_fmtp(pt,tmp);
2132 rtp_profile_set_payload(prof,payload_type_get_number(pt),pt);
2137 void linphone_core_start_media_streams(LinphoneCore *lc, LinphoneCall *call){
2138 LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
2139 const char *tool="linphone-" LINPHONE_VERSION;
2142 if(lc->audiostream == NULL)
2144 ms_warning("init media stream is needed before starting");
2145 linphone_core_init_media_streams(lc,call);
2147 * example of problem :
2148 * 2 incomings calls, you answer and pause one, afterward if you try to answer the other call you will get SEGFAULT
2151 /* adjust rtp jitter compensation. It must be at least the latency of the sound card */
2152 int jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
2154 if (call->media_start_time==0) call->media_start_time=time(NULL);
2156 cname=linphone_address_as_string_uri_only(me);
2158 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
2159 SalProtoRtpAvp,SalAudio);
2161 call->audio_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
2162 if (!lc->use_files){
2163 MSSndCard *playcard=lc->sound_conf.lsd_card ?
2164 lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
2165 MSSndCard *captcard=lc->sound_conf.capt_sndcard;
2166 if (playcard==NULL) {
2167 ms_warning("No card defined for playback !");
2170 if (captcard==NULL) {
2171 ms_warning("No card defined for capture !");
2174 audio_stream_start_now(
2176 call->audio_profile,
2177 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
2184 linphone_core_echo_cancellation_enabled(lc));
2186 audio_stream_start_with_files(
2188 call->audio_profile,
2189 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
2197 post_configure_audio_streams(lc);
2198 audio_stream_set_rtcp_information(lc->audiostream, cname, tool);
2199 }else ms_warning("No audio stream defined ?");
2201 #ifdef VIDEO_ENABLED
2203 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
2204 SalProtoRtpAvp,SalVideo);
2205 /* shutdown preview */
2206 if (lc->previewstream!=NULL) {
2207 video_preview_stop(lc->previewstream);
2208 lc->previewstream=NULL;
2210 if (stream && (lc->video_conf.display || lc->video_conf.capture)) {
2211 const char *addr=stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr;
2212 call->video_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
2213 video_stream_set_sent_video_size(lc->videostream,linphone_core_get_preferred_video_size(lc));
2214 video_stream_enable_self_view(lc->videostream,lc->video_conf.selfview);
2215 if (lc->video_conf.display && lc->video_conf.capture)
2216 video_stream_start(lc->videostream,
2217 call->video_profile, addr, stream->port,
2219 used_pt, jitt_comp, lc->video_conf.device);
2220 else if (lc->video_conf.display)
2221 video_stream_recv_only_start(lc->videostream,
2222 call->video_profile, addr, stream->port,
2223 used_pt, jitt_comp);
2224 else if (lc->video_conf.capture)
2225 video_stream_send_only_start(lc->videostream,
2226 call->video_profile, addr, stream->port,
2228 used_pt, jitt_comp, lc->video_conf.device);
2229 video_stream_set_rtcp_information(lc->videostream, cname,tool);
2236 linphone_address_destroy(me);
2237 call->state=LinphoneCallAVRunning;
2240 static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
2241 audio_stream_get_local_rtp_stats (st,&log->local_stats);
2244 void linphone_core_stop_media_streams(LinphoneCore *lc, LinphoneCall *call){
2246 printf("%s(%d)\n",__FUNCTION__,__LINE__);
2248 if (lc->audiostream!=NULL) {
2249 linphone_call_log_fill_stats (call->log,lc->audiostream);
2250 audio_stream_stop(lc->audiostream);
2251 lc->audiostream=NULL;
2253 #ifdef VIDEO_ENABLED
2254 if (lc->videostream!=NULL){
2255 if (lc->video_conf.display && lc->video_conf.capture)
2256 video_stream_stop(lc->videostream);
2257 else if (lc->video_conf.display)
2258 video_stream_recv_only_stop(lc->videostream);
2259 else if (lc->video_conf.capture)
2260 video_stream_send_only_stop(lc->videostream);
2261 lc->videostream=NULL;
2263 if (linphone_core_video_preview_enabled(lc)){
2264 if (lc->previewstream==NULL){
2265 lc->previewstream=video_preview_start(lc->video_conf.device, lc->video_conf.vsize);
2269 if (call->audio_profile){
2270 rtp_profile_clear_all(call->audio_profile);
2271 rtp_profile_destroy(call->audio_profile);
2272 call->audio_profile=NULL;
2274 if (call->video_profile){
2275 rtp_profile_clear_all(call->video_profile);
2276 rtp_profile_destroy(call->video_profile);
2277 call->video_profile=NULL;
2282 * Accept an incoming call.
2284 * @ingroup call_control
2285 * Basically the application is notified of incoming calls within the
2286 * invite_recv callback of the #LinphoneCoreVTable structure.
2287 * The application can later respond positively to the call using
2289 * @param lc the LinphoneCore object
2290 * @param url the SIP address of the originator of the call, or NULL.
2291 * This argument is useful for managing multiple calls simulatenously,
2292 * however this feature is not supported yet.
2293 * Using NULL will accept the unique incoming call in progress.
2295 int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call)
2297 LinphoneProxyConfig *cfg=NULL;
2298 const char *contact=NULL;
2301 //if just one call is present answer the only one ...
2302 if(ms_list_size(linphone_core_get_calls(lc)) != 1)
2305 call = linphone_core_get_calls(lc)->data;
2308 if (call->state==LinphoneCallAVRunning){
2309 /*call already accepted*/
2314 if (lc->ringstream!=NULL) {
2315 ms_message("stop ringing");
2316 ring_stop(lc->ringstream);
2317 ms_message("ring stopped");
2318 lc->ringstream=NULL;
2320 if(linphone_core_set_as_current_call(lc,call)!=0)
2322 ms_message("another call is already in process\n");
2325 linphone_core_get_default_proxy(lc,&cfg);
2326 /*try to be best-effort in giving real local or routable contact address*/
2327 contact=get_fixed_contact(lc,call,cfg);
2329 sal_op_set_contact(call->op,contact);
2331 sal_call_accept(call->op);
2332 if (lc->vtable.display_status!=NULL)
2333 lc->vtable.display_status(lc,_("Connected."));
2334 gstate_new_state(lc, GSTATE_CALL_IN_CONNECTED, NULL);
2335 call->resultdesc=sal_call_get_final_media_description(call->op);
2336 if (call->resultdesc){
2337 sal_media_description_ref(call->resultdesc);
2338 if(call == linphone_core_get_current_call(lc))
2339 linphone_core_start_media_streams(lc, call);
2340 }else call->media_pending=TRUE;
2341 ms_message("call answered.");
2346 * Terminates a call.
2348 * @ingroup call_control
2349 * @param lc The LinphoneCore
2350 * @param url the destination of the call to be terminated, use NULL if there is
2351 * only one call (which is case in this version of liblinphone).
2353 int linphone_core_terminate_call(LinphoneCore *lc, LinphoneCall *the_call)
2356 if (the_call == NULL){
2357 call = linphone_core_get_current_call(lc);
2367 sal_call_terminate(call->op);
2370 if (lc->ringstream!=NULL) {
2371 ring_stop(lc->ringstream);
2372 lc->ringstream=NULL;
2374 if(call == linphone_core_get_current_call(lc))
2375 linphone_core_stop_media_streams(lc,call);
2376 if (lc->vtable.display_status!=NULL)
2377 lc->vtable.display_status(lc,_("Call ended") );
2378 gstate_new_state(lc, GSTATE_CALL_END, NULL);
2379 linphone_call_set_terminated(call);
2384 * Terminates all the calls.
2386 * @ingroup call_control
2387 * @param lc The LinphoneCore
2389 int linphone_core_terminate_all_calls(LinphoneCore *lc){
2392 LinphoneCall *the_call = lc->calls->data;
2393 linphone_core_terminate_call(lc,the_call);
2395 ms_list_free(lc->calls);
2400 * Returns the calls MSList
2402 * @ingroup call_control
2404 MSList *linphone_core_get_calls(LinphoneCore *lc)
2406 return ms_list_copy(lc->calls);
2410 * Returns TRUE if there is a call running or pending.
2412 * @ingroup call_control
2414 bool_t linphone_core_in_call(const LinphoneCore *lc){
2415 return linphone_core_get_current_call((LinphoneCore *)lc)!=NULL;
2419 * Returns The _LinphoneCall struct of the current call if one is in call
2421 * @ingroup call_control
2423 LinphoneCall *linphone_core_get_current_call(LinphoneCore *lc)
2425 if(lc->current_call != NULL)
2426 return lc->current_call;
2431 * Permits to pause the call
2433 * @ingroup call_control
2435 int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *the_call)
2437 LinphoneCall *call = the_call;
2440 ms_error("LinphoneCore was null\n");
2445 if(linphone_core_in_call(lc))
2447 call = linphone_core_get_current_call(lc);
2451 ms_error("LinphoneCall was null\n");
2455 if(linphone_core_get_current_call(lc) != call)
2457 ms_error("The call asked to be paused was not the current on\n");
2460 if(sal_call_hold(call->op,TRUE) != 0)
2462 lc->vtable.display_warning(lc,_("Could not pause the call"));
2464 call->state = LinphoneCallPaused;
2465 linphone_core_unset_the_current_call(lc);
2466 linphone_core_stop_media_streams(lc,call);
2467 //have to be done ... because if another call is incoming before this pause, you will get sound on the end point paused
2468 linphone_core_init_media_streams(lc,call);
2469 lc->vtable.display_status(lc,_("Pause the current call"));
2474 * Permits to resume the call
2476 * @ingroup call_control
2478 int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call)
2481 LinphoneCall *call = the_call;
2484 ms_error("LinphoneCore was null\n");
2489 MSList *calls = linphone_core_get_calls(lc);
2490 if(ms_list_size(calls) == 1)
2492 call = ((LinphoneCall *)calls->data);
2493 ms_list_free(calls);
2497 ms_error("LinphoneCall was null\n");
2498 ms_list_free(calls);
2502 if(call->state == LinphoneCallInit || call->state == LinphoneCallPreEstablishing || call->state == LinphoneCallRinging )
2504 ms_warning("we cannot resume a call when the communication is not established");
2507 if(linphone_core_get_current_call(lc) != NULL)
2509 ms_error("There is already a call in process pause or stop it first\n");
2512 linphone_core_init_media_streams(lc,call);
2513 if(sal_call_hold(call->op,FALSE) != 0)
2515 lc->vtable.display_warning(lc,_("Could not resume the call"));
2517 call->state = LinphoneCallAVRunning;
2518 linphone_core_set_as_current_call(lc,call);
2519 linphone_core_start_media_streams(lc,call);
2520 snprintf(temp,sizeof(temp),"Resume the call with %s",linphone_call_get_remote_address_as_string(call));
2521 lc->vtable.display_status(lc,temp);
2527 * Compare the remote address with the one in call
2530 * @param b the remote address to compare with
2531 * @return 0 if it's the good call else 1
2533 static int linphone_call_remote_address_compare(const void * a, const void * b)
2535 if(b == NULL || a ==NULL)
2537 char *the_remote_address = ((char *)b);
2538 LinphoneCall *call = ((LinphoneCall *)a);
2540 ms_message("the remote address:%s\n",the_remote_address);
2541 ms_message("the call:%p => %s\n",call,linphone_call_get_remote_address_as_string(call));
2543 if(!strcmp(linphone_call_get_remote_address_as_string(call),the_remote_address))
2551 * Get the call with the remote_address specified
2553 * @param remote_address
2554 * @return the LinphoneCall of the call if found
2556 LinphoneCall *linphone_core_get_call_by_remote_address(LinphoneCore *lc, const char *remote_address){
2558 MSList *the_call = ms_list_find_custom(lc->calls,linphone_call_remote_address_compare,(void *)remote_address);
2559 if(the_call != NULL)
2561 return ((LinphoneCall *)the_call->data);
2566 int linphone_core_send_publish(LinphoneCore *lc,
2567 LinphoneOnlineStatus presence_mode)
2570 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=ms_list_next(elem)){
2571 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2572 if (cfg->publish) linphone_proxy_config_send_publish(cfg,presence_mode);
2578 * Set the incoming call timeout in seconds.
2580 * @ingroup call_control
2581 * If an incoming call isn't answered for this timeout period, it is
2582 * automatically declined.
2584 void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
2585 lc->sip_conf.inc_timeout=seconds;
2589 * Returns the incoming call timeout
2591 * @ingroup call_control
2592 * See linphone_core_set_inc_timeout() for details.
2594 int linphone_core_get_inc_timeout(LinphoneCore *lc){
2595 return lc->sip_conf.inc_timeout;
2598 void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
2599 const char *contact,
2600 LinphoneOnlineStatus presence_mode)
2602 if (minutes_away>0) lc->minutes_away=minutes_away;
2604 if (lc->alt_contact!=NULL) {
2605 ms_free(lc->alt_contact);
2606 lc->alt_contact=NULL;
2608 if (contact) lc->alt_contact=ms_strdup(contact);
2609 if (lc->presence_mode!=presence_mode){
2610 linphone_core_notify_all_friends(lc,presence_mode);
2612 Improve the use of all LINPHONE_STATUS available.
2613 !TODO Do not mix "presence status" with "answer status code"..
2614 Use correct parameter to follow sip_if_match/sip_etag.
2616 linphone_core_send_publish(lc,presence_mode);
2618 lc->prev_mode=lc->presence_mode;
2619 lc->presence_mode=presence_mode;
2622 LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
2623 return lc->presence_mode;
2627 * Get playback sound level in 0-100 scale.
2629 * @ingroup media_parameters
2631 int linphone_core_get_play_level(LinphoneCore *lc)
2633 return lc->sound_conf.play_lev;
2637 * Get ring sound level in 0-100 scale
2639 * @ingroup media_parameters
2641 int linphone_core_get_ring_level(LinphoneCore *lc)
2643 return lc->sound_conf.ring_lev;
2647 * Get sound capture level in 0-100 scale
2649 * @ingroup media_parameters
2651 int linphone_core_get_rec_level(LinphoneCore *lc){
2652 return lc->sound_conf.rec_lev;
2656 * Set sound ring level in 0-100 scale
2658 * @ingroup media_parameters
2660 void linphone_core_set_ring_level(LinphoneCore *lc, int level){
2662 lc->sound_conf.ring_lev=level;
2663 sndcard=lc->sound_conf.ring_sndcard;
2664 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2668 void linphone_core_set_soft_play_level(LinphoneCore *lc, float level){
2670 lc->sound_conf.soft_play_lev=level;
2671 AudioStream *st=lc->audiostream;
2672 if (!st) return; /*just return*/
2675 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_DB_GAIN,&gain);
2676 }else ms_warning("Could not apply gain: gain control wasn't activated.");
2678 float linphone_core_get_soft_play_level(LinphoneCore *lc) {
2680 AudioStream *st=lc->audiostream;
2682 ms_filter_call_method(st->volrecv,MS_VOLUME_GET,&gain);
2683 }else ms_warning("Could not get gain: gain control wasn't activated.");
2689 * Set sound playback level in 0-100 scale
2691 * @ingroup media_parameters
2693 void linphone_core_set_play_level(LinphoneCore *lc, int level){
2695 lc->sound_conf.play_lev=level;
2696 sndcard=lc->sound_conf.play_sndcard;
2697 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2701 * Set sound capture level in 0-100 scale
2703 * @ingroup media_parameters
2705 void linphone_core_set_rec_level(LinphoneCore *lc, int level)
2708 lc->sound_conf.rec_lev=level;
2709 sndcard=lc->sound_conf.capt_sndcard;
2710 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_CAPTURE,level);
2713 static MSSndCard *get_card_from_string_id(const char *devid, unsigned int cap){
2714 MSSndCard *sndcard=NULL;
2716 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2717 if (sndcard!=NULL &&
2718 (ms_snd_card_get_capabilities(sndcard) & cap)==0 ){
2719 ms_warning("%s card does not have the %s capability, ignoring.",
2721 cap==MS_SND_CARD_CAP_CAPTURE ? "capture" : "playback");
2725 if (sndcard==NULL) {
2726 /* get a card that has read+write capabilities */
2727 sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
2728 /* otherwise refine to the first card having the right capability*/
2730 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2731 for(;elem!=NULL;elem=elem->next){
2732 sndcard=(MSSndCard*)elem->data;
2733 if (ms_snd_card_get_capabilities(sndcard) & cap) break;
2736 if (sndcard==NULL){/*looks like a bug! take the first one !*/
2737 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2738 if (elem) sndcard=(MSSndCard*)elem->data;
2741 if (sndcard==NULL) ms_error("Could not find a suitable soundcard !");
2746 * Returns true if the specified sound device can capture sound.
2748 * @ingroup media_parameters
2749 * @param devid the device name as returned by linphone_core_get_sound_devices()
2751 bool_t linphone_core_sound_device_can_capture(LinphoneCore *lc, const char *devid){
2753 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2754 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_CAPTURE)) return TRUE;
2759 * Returns true if the specified sound device can play sound.
2761 * @ingroup media_parameters
2762 * @param devid the device name as returned by linphone_core_get_sound_devices()
2764 bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *devid){
2766 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2767 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_PLAYBACK)) return TRUE;
2772 * Sets the sound device used for ringing.
2774 * @ingroup media_parameters
2775 * @param devid the device name as returned by linphone_core_get_sound_devices()
2777 int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
2778 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2779 lc->sound_conf.ring_sndcard=card;
2780 if (card && lc->ready)
2781 lp_config_set_string(lc->config,"sound","ringer_dev_id",ms_snd_card_get_string_id(card));
2786 * Sets the sound device used for playback.
2788 * @ingroup media_parameters
2789 * @param devid the device name as returned by linphone_core_get_sound_devices()
2791 int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
2792 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2793 lc->sound_conf.play_sndcard=card;
2794 if (card && lc->ready)
2795 lp_config_set_string(lc->config,"sound","playback_dev_id",ms_snd_card_get_string_id(card));
2800 * Sets the sound device used for capture.
2802 * @ingroup media_parameters
2803 * @param devid the device name as returned by linphone_core_get_sound_devices()
2805 int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
2806 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_CAPTURE);
2807 lc->sound_conf.capt_sndcard=card;
2808 if (card && lc->ready)
2809 lp_config_set_string(lc->config,"sound","capture_dev_id",ms_snd_card_get_string_id(card));
2814 * Returns the name of the currently assigned sound device for ringing.
2816 * @ingroup media_parameters
2818 const char * linphone_core_get_ringer_device(LinphoneCore *lc)
2820 if (lc->sound_conf.ring_sndcard) return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
2825 * Returns the name of the currently assigned sound device for playback.
2827 * @ingroup media_parameters
2829 const char * linphone_core_get_playback_device(LinphoneCore *lc)
2831 return lc->sound_conf.play_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.play_sndcard) : NULL;
2835 * Returns the name of the currently assigned sound device for capture.
2837 * @ingroup media_parameters
2839 const char * linphone_core_get_capture_device(LinphoneCore *lc)
2841 return lc->sound_conf.capt_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard) : NULL;
2845 * Returns an unmodifiable array of available sound devices.
2847 * @ingroup media_parameters
2848 * The array is NULL terminated.
2850 const char** linphone_core_get_sound_devices(LinphoneCore *lc){
2851 build_sound_devices_table(lc);
2852 return lc->sound_conf.cards;
2856 * Returns an unmodifiable array of available video capture devices.
2858 * @ingroup media_parameters
2859 * The array is NULL terminated.
2861 const char** linphone_core_get_video_devices(const LinphoneCore *lc){
2862 return lc->video_conf.cams;
2865 char linphone_core_get_sound_source(LinphoneCore *lc)
2867 return lc->sound_conf.source;
2870 void linphone_core_set_sound_source(LinphoneCore *lc, char source)
2872 MSSndCard *sndcard=lc->sound_conf.capt_sndcard;
2873 lc->sound_conf.source=source;
2874 if (!sndcard) return;
2877 ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
2880 ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
2888 * Sets the path to a wav file used for ringing.
2890 * The file must be a wav 16bit linear.
2892 * @ingroup media_parameters
2894 void linphone_core_set_ring(LinphoneCore *lc,const char *path){
2895 if (lc->sound_conf.local_ring!=0){
2896 ms_free(lc->sound_conf.local_ring);
2898 lc->sound_conf.local_ring=ms_strdup(path);
2899 if (lc->ready && lc->sound_conf.local_ring)
2900 lp_config_set_string(lc->config,"sound","local_ring",lc->sound_conf.local_ring);
2904 * Returns the path to the wav file used for ringing.
2906 * @ingroup media_parameters
2908 const char *linphone_core_get_ring(const LinphoneCore *lc){
2909 return lc->sound_conf.local_ring;
2912 static void notify_end_of_ring(void *ud ,unsigned int event, void * arg){
2913 LinphoneCore *lc=(LinphoneCore*)ud;
2914 lc->preview_finished=1;
2917 int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata)
2919 if (lc->ringstream!=0){
2920 ms_warning("Cannot start ring now,there's already a ring being played");
2923 lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
2924 lc->preview_finished=0;
2925 if (lc->sound_conf.ring_sndcard!=NULL){
2926 MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
2927 lc->ringstream=ring_start_with_cb(ring,2000,ringcard,notify_end_of_ring,(void *)lc);
2933 * Sets the path to a wav file used for ringing back.
2935 * Ringback means the ring that is heard when it's ringing at the remote party.
2936 * The file must be a wav 16bit linear.
2938 * @ingroup media_parameters
2940 void linphone_core_set_ringback(LinphoneCore *lc, const char *path){
2941 if (lc->sound_conf.remote_ring!=0){
2942 ms_free(lc->sound_conf.remote_ring);
2944 lc->sound_conf.remote_ring=ms_strdup(path);
2948 * Returns the path to the wav file used for ringing back.
2950 * @ingroup media_parameters
2952 const char * linphone_core_get_ringback(const LinphoneCore *lc){
2953 return lc->sound_conf.remote_ring;
2957 * Enables or disable echo cancellation.
2959 * @ingroup media_parameters
2961 void linphone_core_enable_echo_cancellation(LinphoneCore *lc, bool_t val){
2962 lc->sound_conf.ec=val;
2964 lp_config_set_int(lc->config,"sound","echocancellation",val);
2968 * Returns TRUE if echo cancellation is enabled.
2970 * @ingroup media_parameters
2972 bool_t linphone_core_echo_cancellation_enabled(LinphoneCore *lc){
2973 return lc->sound_conf.ec;
2976 void linphone_core_enable_echo_limiter(LinphoneCore *lc, bool_t val){
2977 lc->sound_conf.ea=val;
2980 bool_t linphone_core_echo_limiter_enabled(const LinphoneCore *lc){
2981 return lc->sound_conf.ea;
2985 * Mutes or unmutes the local microphone.
2987 * @ingroup media_parameters
2989 void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){
2990 if (lc->audiostream!=NULL){
2991 audio_stream_set_mic_gain(lc->audiostream,
2992 (val==TRUE) ? 0 : 1.0);
2996 bool_t linphone_core_is_mic_muted(LinphoneCore *lc) {
2998 if (lc->audiostream && lc->audiostream->volsend){
2999 ms_filter_call_method(lc->audiostream->volsend,MS_VOLUME_GET_GAIN,&gain);
3000 }else ms_warning("Could not get gain: gain control wasn't activated. ");
3005 void linphone_core_enable_agc(LinphoneCore *lc, bool_t val){
3006 lc->sound_conf.agc=val;
3009 bool_t linphone_core_agc_enabled(const LinphoneCore *lc){
3010 return lc->sound_conf.agc;
3014 * Send the specified dtmf.
3016 * @ingroup media_parameters
3017 * This function only works during calls. The dtmf is automatically played to the user.
3018 * @param lc The LinphoneCore object
3019 * @param dtmf The dtmf name specified as a char, such as '0', '#' etc...
3022 void linphone_core_send_dtmf(LinphoneCore *lc, char dtmf)
3024 /*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
3025 if (linphone_core_get_use_rfc2833_for_dtmf(lc)!=0 || linphone_core_get_use_info_for_dtmf(lc)==0)
3028 if (lc->audiostream!=NULL){
3029 audio_stream_send_dtmf(lc->audiostream,dtmf);
3033 ms_error("we cannot send RFC2833 dtmf when we are not in communication");
3036 if (linphone_core_get_use_info_for_dtmf(lc)!=0){
3037 /* Out of Band DTMF (use INFO method) */
3038 LinphoneCall *call=linphone_core_get_current_call(lc);
3042 sal_call_send_dtmf(call->op,dtmf);
3046 void linphone_core_set_stun_server(LinphoneCore *lc, const char *server){
3047 if (lc->net_conf.stun_server!=NULL)
3048 ms_free(lc->net_conf.stun_server);
3050 lc->net_conf.stun_server=ms_strdup(server);
3051 else lc->net_conf.stun_server=NULL;
3054 const char * linphone_core_get_stun_server(const LinphoneCore *lc){
3055 return lc->net_conf.stun_server;
3058 const char * linphone_core_get_relay_addr(const LinphoneCore *lc){
3059 return lc->net_conf.relay;
3062 int linphone_core_set_relay_addr(LinphoneCore *lc, const char *addr){
3063 if (lc->net_conf.relay!=NULL){
3064 ms_free(lc->net_conf.relay);
3065 lc->net_conf.relay=NULL;
3068 lc->net_conf.relay=ms_strdup(addr);
3073 void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
3075 if (lc->net_conf.nat_address!=NULL){
3076 ms_free(lc->net_conf.nat_address);
3078 if (addr!=NULL) lc->net_conf.nat_address=ms_strdup(addr);
3079 else lc->net_conf.nat_address=NULL;
3080 if (lc->sip_conf.contact) update_primary_contact(lc);
3083 const char *linphone_core_get_nat_address(const LinphoneCore *lc)
3085 return lc->net_conf.nat_address;
3088 void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
3089 lc->net_conf.firewall_policy=pol;
3090 if (lc->sip_conf.contact) update_primary_contact(lc);
3093 LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
3094 return lc->net_conf.firewall_policy;
3098 * Get the list of call logs (past calls).
3100 * @ingroup call_logs
3102 const MSList * linphone_core_get_call_logs(LinphoneCore *lc){
3104 return lc->call_logs;
3108 * Erase the call log.
3110 * @ingroup call_logs
3112 void linphone_core_clear_call_logs(LinphoneCore *lc){
3114 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3115 lc->call_logs=ms_list_free(lc->call_logs);
3116 call_logs_write_to_config_file(lc);
3119 static void toggle_video_preview(LinphoneCore *lc, bool_t val){
3120 #ifdef VIDEO_ENABLED
3121 if (lc->videostream==NULL){
3123 if (lc->previewstream==NULL){
3124 lc->previewstream=video_preview_start(lc->video_conf.device,
3125 lc->video_conf.vsize);
3128 if (lc->previewstream!=NULL){
3129 video_preview_stop(lc->previewstream);
3130 lc->previewstream=NULL;
3138 * Enables video globally.
3140 * @ingroup media_parameters
3141 * This function does not have any effect during calls. It just indicates LinphoneCore to
3142 * initiate future calls with video or not. The two boolean parameters indicate in which
3143 * direction video is enabled. Setting both to false disables video entirely.
3145 * @param vcap_enabled indicates whether video capture is enabled
3146 * @param display_enabled indicates whether video display should be shown
3149 void linphone_core_enable_video(LinphoneCore *lc, bool_t vcap_enabled, bool_t display_enabled){
3150 #ifndef VIDEO_ENABLED
3151 if (vcap_enabled || display_enabled)
3152 ms_warning("This version of linphone was built without video support.");
3154 lc->video_conf.capture=vcap_enabled;
3155 lc->video_conf.display=display_enabled;
3157 /* need to re-apply network bandwidth settings*/
3158 linphone_core_set_download_bandwidth(lc,
3159 linphone_core_get_download_bandwidth(lc));
3160 linphone_core_set_upload_bandwidth(lc,
3161 linphone_core_get_upload_bandwidth(lc));
3165 * Returns TRUE if video is enabled, FALSE otherwise.
3166 * @ingroup media_parameters
3168 bool_t linphone_core_video_enabled(LinphoneCore *lc){
3169 return (lc->video_conf.display || lc->video_conf.capture);
3173 * Controls video preview enablement.
3175 * @ingroup media_parameters
3176 * Video preview refers to the action of displaying the local webcam image
3177 * to the user while not in call.
3179 void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val){
3180 lc->video_conf.show_local=val;
3184 * Returns TRUE if video previewing is enabled.
3185 * @ingroup media_parameters
3187 bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
3188 return lc->video_conf.show_local;
3192 * Enables or disable self view during calls.
3194 * @ingroup media_parameters
3195 * Self-view refers to having local webcam image inserted in corner
3196 * of the video window during calls.
3197 * This function works at any time, including during calls.
3199 void linphone_core_enable_self_view(LinphoneCore *lc, bool_t val){
3200 lc->video_conf.selfview=val;
3201 #ifdef VIDEO_ENABLED
3202 if (lc->videostream){
3203 video_stream_enable_self_view(lc->videostream,val);
3209 * Returns TRUE if self-view is enabled, FALSE otherwise.
3211 * @ingroup media_parameters
3213 * Refer to linphone_core_enable_self_view() for details.
3215 bool_t linphone_core_self_view_enabled(const LinphoneCore *lc){
3216 return lc->video_conf.selfview;
3220 * Sets the active video device.
3222 * @ingroup media_parameters
3223 * @param id the name of the video device as returned by linphone_core_get_video_devices()
3225 int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
3226 MSWebCam *olddev=lc->video_conf.device;
3229 lc->video_conf.device=ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),id);
3230 if (lc->video_conf.device==NULL){
3231 ms_warning("Could not found video device %s",id);
3234 if (lc->video_conf.device==NULL)
3235 lc->video_conf.device=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());
3236 if (olddev!=NULL && olddev!=lc->video_conf.device){
3237 toggle_video_preview(lc,FALSE);/*restart the video local preview*/
3239 if (lc->ready && lc->video_conf.device){
3240 vd=ms_web_cam_get_string_id(lc->video_conf.device);
3241 if (vd && strstr(vd,"Static picture")!=NULL){
3244 lp_config_set_string(lc->config,"video","device",vd);
3250 * Returns the name of the currently active video device.
3252 * @ingroup media_parameters
3254 const char *linphone_core_get_video_device(const LinphoneCore *lc){
3255 if (lc->video_conf.device) return ms_web_cam_get_string_id(lc->video_conf.device);
3259 int linphone_core_set_static_picture(LinphoneCore *lc, const char *path) {
3260 #ifdef VIDEO_ENABLED
3261 VideoStream *vs = NULL;
3262 /* Select the video stream from the call in the first place */
3263 if (lc && lc->videostream) {
3264 vs = lc->videostream;
3266 /* If not in call, select the video stream from the preview */
3267 if (vs == NULL && lc && lc->previewstream) {
3268 vs = lc->previewstream;
3271 /* If we have a video stream (either preview, either from call), we
3272 have a source and it is using the static picture filter, then
3273 force the filter to use that picture. */
3274 if (vs && vs->source) {
3275 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3276 ms_filter_call_method(vs->source, MS_FILTER_SET_IMAGE,
3281 /* Tell the static image filter to use that image from now on so
3282 that the image will be used next time it has to be read */
3283 ms_static_image_set_default_image(path);
3285 ms_warning("Video support not compiled.");
3291 * Returns the native window handle of the video window, casted as an unsigned long.
3293 * @ingroup media_parameters
3295 unsigned long linphone_core_get_native_video_window_id(const LinphoneCore *lc){
3296 #ifdef VIDEO_ENABLED
3297 if (lc->videostream)
3298 return video_stream_get_native_window_id(lc->videostream);
3299 if (lc->previewstream)
3300 return video_stream_get_native_window_id(lc->previewstream);
3305 static MSVideoSizeDef supported_resolutions[]={
3306 { {MS_VIDEO_SIZE_SVGA_W,MS_VIDEO_SIZE_SVGA_H} , "svga" },
3307 { {MS_VIDEO_SIZE_4CIF_W,MS_VIDEO_SIZE_4CIF_H} , "4cif" },
3308 { {MS_VIDEO_SIZE_VGA_W,MS_VIDEO_SIZE_VGA_H} , "vga" },
3309 { {MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H} , "cif" },
3310 { {MS_VIDEO_SIZE_QVGA_W,MS_VIDEO_SIZE_QVGA_H} , "qvga" },
3311 { {MS_VIDEO_SIZE_QCIF_W,MS_VIDEO_SIZE_QCIF_H} , "qcif" },
3316 * Returns the zero terminated table of supported video resolutions.
3318 * @ingroup media_parameters
3320 const MSVideoSizeDef *linphone_core_get_supported_video_sizes(LinphoneCore *lc){
3321 return supported_resolutions;
3324 static MSVideoSize video_size_get_by_name(const char *name){
3325 MSVideoSizeDef *pdef=supported_resolutions;
3326 MSVideoSize null_vsize={0,0};
3327 for(;pdef->name!=NULL;pdef++){
3328 if (strcasecmp(name,pdef->name)==0){
3332 ms_warning("Video resolution %s is not supported in linphone.",name);
3336 static const char *video_size_get_name(MSVideoSize vsize){
3337 MSVideoSizeDef *pdef=supported_resolutions;
3338 for(;pdef->name!=NULL;pdef++){
3339 if (pdef->vsize.width==vsize.width && pdef->vsize.height==vsize.height){
3346 static bool_t video_size_supported(MSVideoSize vsize){
3347 if (video_size_get_name(vsize)) return TRUE;
3348 ms_warning("Video resolution %ix%i is not supported in linphone.",vsize.width,vsize.height);
3353 * Sets the preferred video size.
3355 * @ingroup media_parameters
3356 * This applies only to the stream that is captured and sent to the remote party,
3357 * since we accept all standard video size on the receive path.
3359 void linphone_core_set_preferred_video_size(LinphoneCore *lc, MSVideoSize vsize){
3360 if (video_size_supported(vsize)){
3361 MSVideoSize oldvsize=lc->video_conf.vsize;
3362 lc->video_conf.vsize=vsize;
3363 if (!ms_video_size_equal(oldvsize,vsize) && lc->previewstream!=NULL){
3364 toggle_video_preview(lc,FALSE);
3365 toggle_video_preview(lc,TRUE);
3368 lp_config_set_string(lc->config,"video","size",video_size_get_name(vsize));
3373 * Sets the preferred video size by its name.
3375 * @ingroup media_parameters
3376 * This is identical to linphone_core_set_preferred_video_size() except
3377 * that it takes the name of the video resolution as input.
3378 * Video resolution names are: qcif, svga, cif, vga, 4cif, svga ...
3380 void linphone_core_set_preferred_video_size_by_name(LinphoneCore *lc, const char *name){
3381 MSVideoSize vsize=video_size_get_by_name(name);
3382 MSVideoSize default_vsize={MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H};
3383 if (vsize.width!=0) linphone_core_set_preferred_video_size(lc,vsize);
3384 else linphone_core_set_preferred_video_size(lc,default_vsize);
3388 * Returns the current preferred video size for sending.
3390 * @ingroup media_parameters
3392 MSVideoSize linphone_core_get_preferred_video_size(LinphoneCore *lc){
3393 return lc->video_conf.vsize;
3396 void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
3397 lc->use_files=yesno;
3400 void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
3401 if (lc->play_file!=NULL){
3402 ms_free(lc->play_file);
3406 lc->play_file=ms_strdup(file);
3407 if (lc->audiostream->ticker)
3408 audio_stream_play(lc->audiostream,file);
3412 void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
3413 if (lc->rec_file!=NULL){
3414 ms_free(lc->rec_file);
3418 lc->rec_file=ms_strdup(file);
3419 if (lc->audiostream)
3420 audio_stream_record(lc->audiostream,file);
3425 * Retrieves the user pointer that was given to linphone_core_new()
3427 * @ingroup initializing
3429 void *linphone_core_get_user_data(LinphoneCore *lc){
3433 int linphone_core_get_mtu(const LinphoneCore *lc){
3434 return lc->net_conf.mtu;
3437 void linphone_core_set_mtu(LinphoneCore *lc, int mtu){
3438 lc->net_conf.mtu=mtu;
3441 ms_error("MTU too small !");
3445 ms_message("MTU is supposed to be %i, rtp payload max size will be %i",mtu, ms_get_payload_max_size());
3446 }else ms_set_mtu(0);//use mediastreamer2 default value
3449 void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context){
3451 lc->wait_ctx=user_context;
3454 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose){
3456 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingStart,purpose,0);
3460 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progress){
3462 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingProgress,purpose,progress);
3472 void linphone_core_stop_waiting(LinphoneCore *lc){
3474 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingFinished,NULL,0);
3478 void linphone_core_set_audio_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3484 * Retrieve RTP statistics regarding current call.
3485 * @param local RTP statistics computed locally.
3486 * @param remote RTP statistics computed by far end (obtained via RTCP feedback).
3488 * @note Remote RTP statistics is not implemented yet.
3490 * @returns 0 or -1 if no call is running.
3493 int linphone_core_get_current_call_stats(LinphoneCore *lc, rtp_stats_t *local, rtp_stats_t *remote){
3494 LinphoneCall *call=linphone_core_get_current_call (lc);
3496 if (lc->audiostream!=NULL){
3497 memset(remote,0,sizeof(*remote));
3498 audio_stream_get_local_rtp_stats (lc->audiostream,local);
3505 void net_config_uninit(LinphoneCore *lc)
3507 net_config_t *config=&lc->net_conf;
3508 lp_config_set_int(lc->config,"net","download_bw",config->download_bw);
3509 lp_config_set_int(lc->config,"net","upload_bw",config->upload_bw);
3511 if (config->stun_server!=NULL){
3512 lp_config_set_string(lc->config,"net","stun_server",config->stun_server);
3513 ms_free(lc->net_conf.stun_server);
3515 if (config->nat_address!=NULL){
3516 lp_config_set_string(lc->config,"net","nat_address",config->nat_address);
3517 ms_free(lc->net_conf.nat_address);
3519 lp_config_set_int(lc->config,"net","firewall_policy",config->firewall_policy);
3520 lp_config_set_int(lc->config,"net","mtu",config->mtu);
3524 void sip_config_uninit(LinphoneCore *lc)
3528 sip_config_t *config=&lc->sip_conf;
3529 lp_config_set_int(lc->config,"sip","sip_port",config->sip_port);
3530 lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
3531 lp_config_set_string(lc->config,"sip","contact",config->contact);
3532 lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
3533 lp_config_set_int(lc->config,"sip","use_info",config->use_info);
3534 lp_config_set_int(lc->config,"sip","use_rfc2833",config->use_rfc2833);
3535 lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
3536 lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
3539 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
3541 for(elem=config->proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3542 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
3543 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
3544 linphone_proxy_config_edit(cfg); /* to unregister */
3550 sal_iterate(lc->sal);
3559 ms_list_for_each(config->proxies,(void (*)(void*)) linphone_proxy_config_destroy);
3560 ms_list_free(config->proxies);
3561 config->proxies=NULL;
3563 linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */
3565 for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3566 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
3567 linphone_auth_info_write_config(lc->config,ai,i);
3569 linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
3570 ms_list_for_each(lc->auth_info,(void (*)(void*))linphone_auth_info_destroy);
3571 ms_list_free(lc->auth_info);
3574 sal_uninit(lc->sal);
3577 if (lc->sip_conf.guessed_contact)
3578 ms_free(lc->sip_conf.guessed_contact);
3579 if (config->contact)
3580 ms_free(config->contact);
3584 void rtp_config_uninit(LinphoneCore *lc)
3586 rtp_config_t *config=&lc->rtp_conf;
3587 lp_config_set_int(lc->config,"rtp","audio_rtp_port",config->audio_rtp_port);
3588 lp_config_set_int(lc->config,"rtp","video_rtp_port",config->video_rtp_port);
3589 lp_config_set_int(lc->config,"rtp","audio_jitt_comp",config->audio_jitt_comp);
3590 lp_config_set_int(lc->config,"rtp","video_jitt_comp",config->video_jitt_comp);
3591 lp_config_set_int(lc->config,"rtp","nortp_timeout",config->nortp_timeout);
3594 void sound_config_uninit(LinphoneCore *lc)
3596 sound_config_t *config=&lc->sound_conf;
3597 ms_free(config->cards);
3599 lp_config_set_string(lc->config,"sound","remote_ring",config->remote_ring);
3601 if (config->local_ring) ms_free(config->local_ring);
3602 if (config->remote_ring) ms_free(config->remote_ring);
3603 ms_snd_card_manager_destroy();
3606 void video_config_uninit(LinphoneCore *lc)
3608 lp_config_set_int(lc->config,"video","enabled",linphone_core_video_enabled(lc));
3609 lp_config_set_string(lc->config,"video","size",video_size_get_name(linphone_core_get_preferred_video_size(lc)));
3610 lp_config_set_int(lc->config,"video","display",lc->video_conf.display);
3611 lp_config_set_int(lc->config,"video","capture",lc->video_conf.capture);
3612 lp_config_set_int(lc->config,"video","show_local",linphone_core_video_preview_enabled(lc));
3613 lp_config_set_int(lc->config,"video","self_view",linphone_core_self_view_enabled(lc));
3614 if (lc->video_conf.cams)
3615 ms_free(lc->video_conf.cams);
3618 void codecs_config_uninit(LinphoneCore *lc)
3621 codecs_config_t *config=&lc->codecs_conf;
3626 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
3627 pt=(PayloadType*)(node->data);
3628 sprintf(key,"audio_codec_%i",index);
3629 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3630 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3631 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3634 sprintf(key,"audio_codec_%i",index);
3635 lp_config_clean_section (lc->config,key);
3638 for(node=config->video_codecs;node!=NULL;node=ms_list_next(node)){
3639 pt=(PayloadType*)(node->data);
3640 sprintf(key,"video_codec_%i",index);
3641 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3642 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3643 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3644 lp_config_set_string(lc->config,key,"recv_fmtp",pt->recv_fmtp);
3647 sprintf(key,"video_codec_%i",index);
3648 lp_config_clean_section (lc->config,key);
3650 ms_list_free(lc->codecs_conf.audio_codecs);
3651 ms_list_free(lc->codecs_conf.video_codecs);
3654 void ui_config_uninit(LinphoneCore* lc)
3657 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_destroy);
3658 ms_list_free(lc->friends);
3664 * Returns the LpConfig object used to manage the storage (config) file.
3667 * The application can use the LpConfig object to insert its own private
3668 * sections and pairs of key=value in the configuration file.
3671 LpConfig *linphone_core_get_config(LinphoneCore *lc){
3675 static void linphone_core_uninit(LinphoneCore *lc)
3679 LinphoneCall *the_call = lc->calls->data;
3680 linphone_core_terminate_call(lc,the_call);
3681 linphone_core_iterate(lc);
3690 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions);
3691 gstate_new_state(lc, GSTATE_POWER_SHUTDOWN, NULL);
3692 #ifdef VIDEO_ENABLED
3693 if (lc->previewstream!=NULL){
3694 video_preview_stop(lc->previewstream);
3695 lc->previewstream=NULL;
3698 ms_event_queue_destroy(lc->msevq);
3699 /* save all config */
3700 net_config_uninit(lc);
3701 sip_config_uninit(lc);
3702 rtp_config_uninit(lc);
3703 sound_config_uninit(lc);
3704 video_config_uninit(lc);
3705 codecs_config_uninit(lc);
3706 ui_config_uninit(lc);
3707 if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
3708 lp_config_destroy(lc->config);
3709 lc->config = NULL; /* Mark the config as NULL to block further calls */
3710 sip_setup_unregister_all();
3712 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3713 lc->call_logs=ms_list_free(lc->call_logs);
3715 linphone_core_free_payload_types();
3718 gstate_new_state(lc, GSTATE_POWER_OFF, NULL);
3721 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable){
3722 ms_message("Network state is now [%s]",isReachable?"UP":"DOWN");
3723 // second get the list of available proxies
3724 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3725 for(;elem!=NULL;elem=elem->next){
3726 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3727 if (linphone_proxy_config_register_enabled(cfg) ) {
3735 lc->network_reachable=isReachable;
3738 void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) {
3739 //first disable automatic mode
3740 if (lc->auto_net_state_mon) {
3741 ms_message("Disabling automatic network state monitoring");
3742 lc->auto_net_state_mon=FALSE;
3744 set_network_reachable(lc,isReachable);
3747 bool_t linphone_core_is_network_reachabled(LinphoneCore* lc) {
3748 return lc->network_reachable;
3750 ortp_socket_t linphone_core_get_sip_socket(LinphoneCore *lc){
3751 return sal_get_socket(lc->sal);
3754 * Destroys a LinphoneCore
3756 * @ingroup initializing
3758 void linphone_core_destroy(LinphoneCore *lc){
3759 linphone_core_uninit(lc);
3763 * Get the number of Call
3765 * @ingroup call_control
3767 int linphone_core_get_calls_nb(const LinphoneCore *lc)
3770 if(lc->calls == NULL)
3776 returned = ms_list_size(lc->calls);
3782 * Check if we do not have exceed the number of simultaneous call
3784 * @ingroup call_control
3786 bool_t linphone_core_can_we_add_call(LinphoneCore *lc)
3788 if(linphone_core_get_calls_nb(lc) < NB_MAX_CALLS)
3790 ms_error("Maximum amount of simultaneous calls reached !");
3795 * Unset the current call
3797 * @ingroup call_control
3799 int linphone_core_unset_the_current_call(LinphoneCore *lc)
3801 if(lc->current_call == NULL)
3803 lc->current_call = NULL;
3804 ms_message("Current call unset\n");
3809 * Set the call in parameter as the new current call
3811 * @ingroup call_control
3813 int linphone_core_set_as_current_call(LinphoneCore *lc, LinphoneCall *call)
3815 if(lc->current_call != NULL)
3817 lc->current_call = call;
3822 * Add the call in the LinphoneCall list
3824 * @ingroup call_control
3826 int linphone_core_add_call( LinphoneCore *lc, LinphoneCall *call)
3828 if(linphone_core_can_we_add_call(lc))
3830 MSList *the_calls = lc->calls;
3831 the_calls = ms_list_append(the_calls,call);
3832 lc->calls = the_calls;
3839 * Add the call in the LinphoneCall list
3841 * @ingroup call_control
3843 int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call)
3847 MSList *the_calls = lc->calls;
3848 if(call == linphone_core_get_current_call(lc))
3850 linphone_core_unset_the_current_call(lc);
3852 it=ms_list_find(the_calls,call);
3855 the_calls = ms_list_remove_link(the_calls,it);
3859 ms_warning("could not find the call into the list\n");
3862 lc->calls = the_calls;