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 <eXosip2/eXosip.h>
28 #include "sdphandler.h"
30 #include <ortp/telephonyevents.h>
40 /*#define UNSTANDART_GSM_11K 1*/
42 static const char *liblinphone_version=LIBLINPHONE_VERSION;
46 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result);
47 static void apply_nat_settings(LinphoneCore *lc);
48 static void toggle_video_preview(LinphoneCore *lc, bool_t val);
50 /* relative path where is stored local ring*/
51 #define LOCAL_RING "rings/oldphone.wav"
52 /* same for remote ring (ringback)*/
53 #define REMOTE_RING "ringback.wav"
56 sdp_handler_t linphone_sdphandler={
57 linphone_accept_audio_offer, /*from remote sdp */
58 linphone_accept_video_offer, /*from remote sdp */
59 linphone_set_audio_offer, /*to local sdp */
60 linphone_set_video_offer, /*to local sdp */
61 linphone_read_audio_answer, /*from incoming answer */
62 linphone_read_video_answer /*from incoming answer */
65 void lc_callback_obj_init(LCCallbackObj *obj,LinphoneCoreCbFunc func,void* ud)
71 int lc_callback_obj_invoke(LCCallbackObj *obj, LinphoneCore *lc){
72 if (obj->_func!=NULL) obj->_func(lc,obj->_user_data);
76 static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
77 call->state=LCStateInit;
78 call->start_time=time(NULL);
79 call->media_start_time=0;
80 call->log=linphone_call_log_new(call, from, to);
81 linphone_core_notify_all_friends(call->core,LINPHONE_STATUS_ONTHEPHONE);
82 if (linphone_core_get_firewall_policy(call->core)==LINPHONE_POLICY_USE_STUN)
83 linphone_core_run_stun_tests(call->core,call);
84 call->profile=rtp_profile_new("Call RTP profile");
87 void linphone_call_init_media_params(LinphoneCall *call){
88 memset(&call->audio_params,0,sizeof(call->audio_params));
89 memset(&call->video_params,0,sizeof(call->video_params));
92 static void discover_mtu(LinphoneCore *lc, const char *remote){
94 if (lc->net_conf.mtu==0 ){
95 /*attempt to discover mtu*/
96 mtu=ms_discover_mtu(remote);
99 ms_message("Discovered mtu is %i, RTP payload max size is %i",
100 mtu, ms_get_payload_max_size());
105 LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to)
107 LinphoneCall *call=ms_new0(LinphoneCall,1);
108 call->dir=LinphoneCallOutgoing;
113 linphone_core_get_local_ip(lc,linphone_address_get_domain(to),call->localip);
114 linphone_call_init_common(call,from,to);
115 call->sdpctx=sdp_handler_create_context(&linphone_sdphandler,
116 call->audio_params.natd_port>0 ? call->audio_params.natd_addr : call->localip,
117 linphone_address_get_username (from),NULL);
118 sdp_context_set_user_pointer(call->sdpctx,(void*)call);
119 discover_mtu(lc,linphone_address_get_domain (to));
124 LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, eXosip_event_t *ev){
125 LinphoneCall *call=ms_new0(LinphoneCall,1);
126 LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
127 osip_header_t *h=NULL;
129 call->dir=LinphoneCallIncoming;
135 linphone_address_clean(from);
137 linphone_core_get_local_ip(lc,linphone_address_get_domain(from),call->localip);
138 linphone_call_init_common(call, from, to);
139 call->sdpctx=sdp_handler_create_context(&linphone_sdphandler,
140 call->audio_params.natd_port>0 ? call->audio_params.natd_addr : call->localip,
141 linphone_address_get_username (me),NULL);
142 sdp_context_set_user_pointer(call->sdpctx,(void*)call);
143 discover_mtu(lc,linphone_address_get_domain(from));
144 linphone_address_destroy(me);
145 osip_message_header_get_byname(ev->request,"Session-expires",0,&h);
146 if (h) call->supports_session_timers=TRUE;
150 void linphone_call_destroy(LinphoneCall *obj)
152 linphone_core_notify_all_friends(obj->core,obj->core->prev_mode);
153 linphone_call_log_completed(obj->log,obj);
154 linphone_core_update_allocated_audio_bandwidth(obj->core);
155 if (obj->profile!=NULL) rtp_profile_destroy(obj->profile);
156 if (obj->sdpctx!=NULL) sdp_context_free(obj->sdpctx);
160 /*prevent a gcc bug with %c*/
161 static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm){
162 #if !defined(_WIN32_WCE)
163 return strftime(s, max, fmt, tm);
167 #endif /*_WIN32_WCE*/
170 static void set_call_log_date(LinphoneCallLog *cl, const struct tm *loctime){
171 my_strftime(cl->start_date,sizeof(cl->start_date),"%c",loctime);
174 LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
175 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
179 #if !defined(_WIN32_WCE)
180 loctime=*localtime(&call->start_time);
182 #endif /*_WIN32_WCE*/
184 localtime_r(&call->start_time,&loctime);
186 set_call_log_date(cl,&loctime);
192 static void call_logs_write_to_config_file(LinphoneCore *lc){
197 LpConfig *cfg=lc->config;
199 if (!lc->ready) return;
201 for(i=0,elem=lc->call_logs;elem!=NULL;elem=elem->next,++i){
202 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
203 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
204 lp_config_set_int(cfg,logsection,"dir",cl->dir);
205 lp_config_set_int(cfg,logsection,"status",cl->status);
206 tmp=linphone_address_as_string(cl->from);
207 lp_config_set_string(cfg,logsection,"from",tmp);
209 tmp=linphone_address_as_string(cl->to);
210 lp_config_set_string(cfg,logsection,"to",tmp);
212 lp_config_set_string(cfg,logsection,"start_date",cl->start_date);
213 lp_config_set_int(cfg,logsection,"duration",cl->duration);
214 if (cl->refkey) lp_config_set_string(cfg,logsection,"refkey",cl->refkey);
216 for(;i<lc->max_call_logs;++i){
217 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
218 lp_config_clean_section(cfg,logsection);
222 static void call_logs_read_from_config_file(LinphoneCore *lc){
226 LpConfig *cfg=lc->config;
228 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
229 if (lp_config_has_section(cfg,logsection)){
230 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
231 cl->dir=lp_config_get_int(cfg,logsection,"dir",0);
232 cl->status=lp_config_get_int(cfg,logsection,"status",0);
233 tmp=lp_config_get_string(cfg,logsection,"from",NULL);
234 if (tmp) cl->from=linphone_address_new(tmp);
235 tmp=lp_config_get_string(cfg,logsection,"to",NULL);
236 if (tmp) cl->to=linphone_address_new(tmp);
237 tmp=lp_config_get_string(cfg,logsection,"start_date",NULL);
238 if (tmp) strncpy(cl->start_date,tmp,sizeof(cl->start_date));
239 cl->duration=lp_config_get_int(cfg,logsection,"duration",0);
240 tmp=lp_config_get_string(cfg,logsection,"refkey",NULL);
241 if (tmp) cl->refkey=ms_strdup(tmp);
242 lc->call_logs=ms_list_append(lc->call_logs,cl);
248 void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call){
249 LinphoneCore *lc=call->core;
251 calllog->duration=time(NULL)-call->start_time;
254 calllog->status=LinphoneCallAborted;
257 if (calllog->dir==LinphoneCallIncoming){
259 calllog->status=LinphoneCallMissed;
261 info=ortp_strdup_printf(ngettext("You have missed %i call.",
262 "You have missed %i calls.", lc->missed_calls),
264 lc->vtable.display_status(lc,info);
267 else calllog->status=LinphoneCallAborted;
269 case LCStateAVRunning:
270 calllog->status=LinphoneCallSuccess;
273 lc->call_logs=ms_list_prepend(lc->call_logs,(void *)calllog);
274 if (ms_list_size(lc->call_logs)>lc->max_call_logs){
275 MSList *elem,*prevelem=NULL;
276 /*find the last element*/
277 for(elem=lc->call_logs;elem!=NULL;elem=elem->next){
281 linphone_call_log_destroy((LinphoneCallLog*)elem->data);
282 lc->call_logs=ms_list_remove_link(lc->call_logs,elem);
284 if (lc->vtable.call_log_updated!=NULL){
285 lc->vtable.call_log_updated(lc,calllog);
287 call_logs_write_to_config_file(lc);
291 * @addtogroup call_logs
296 * Returns a human readable string describing the call.
298 * @note: the returned char* must be freed by the application (use ms_free()).
300 char * linphone_call_log_to_str(LinphoneCallLog *cl){
303 char *from=linphone_address_as_string (cl->from);
304 char *to=linphone_address_as_string (cl->to);
306 case LinphoneCallAborted:
309 case LinphoneCallSuccess:
310 status=_("completed");
312 case LinphoneCallMissed:
318 tmp=ortp_strdup_printf(_("%s at %s\nFrom: %s\nTo: %s\nStatus: %s\nDuration: %i mn %i sec\n"),
319 (cl->dir==LinphoneCallIncoming) ? _("Incoming call") : _("Outgoing call"),
331 void linphone_call_log_set_user_pointer(LinphoneCallLog *cl, void *up){
335 void *linphone_call_log_get_user_pointer(const LinphoneCallLog *cl){
336 return cl->user_pointer;
342 * Associate a persistent reference key to the call log.
344 * The reference key can be for example an id to an external database.
345 * It is stored in the config file, thus can survive to process exits/restarts.
348 void linphone_call_log_set_ref_key(LinphoneCallLog *cl, const char *refkey){
349 if (cl->refkey!=NULL){
353 if (refkey) cl->refkey=ms_strdup(refkey);
354 call_logs_write_to_config_file(cl->lc);
358 * Get the persistent reference key associated to the call log.
360 * The reference key can be for example an id to an external database.
361 * It is stored in the config file, thus can survive to process exits/restarts.
364 const char *linphone_call_log_get_ref_key(const LinphoneCallLog *cl){
370 void linphone_call_log_destroy(LinphoneCallLog *cl){
371 if (cl->from!=NULL) linphone_address_destroy(cl->from);
372 if (cl->to!=NULL) linphone_address_destroy(cl->to);
373 if (cl->refkey!=NULL) ms_free(cl->refkey);
377 int linphone_core_get_current_call_duration(const LinphoneCore *lc){
378 LinphoneCall *call=lc->call;
379 if (call==NULL) return 0;
380 if (call->media_start_time==0) return 0;
381 return time(NULL)-call->media_start_time;
384 const LinphoneAddress *linphone_core_get_remote_uri(LinphoneCore *lc){
385 LinphoneCall *call=lc->call;
386 if (call==NULL) return 0;
387 return call->dir==LinphoneCallIncoming ? call->log->from : call->log->to;
390 void _osip_trace_func(char *fi, int li, osip_trace_level_t level, char *chfr, va_list ap){
391 int ortp_level=ORTP_DEBUG;
397 ortp_level=ORTP_MESSAGE;
400 ortp_level=ORTP_WARNING;
404 ortp_level=ORTP_ERROR;
407 ortp_level=ORTP_FATAL;
409 case END_TRACE_LEVEL:
412 if (ortp_log_level_enabled(level)){
413 int len=strlen(chfr);
414 char *chfrdup=ortp_strdup(chfr);
415 /*need to remove endline*/
417 if (chfrdup[len-1]=='\n')
419 if (chfrdup[len-2]=='\r')
422 ortp_logv(ortp_level,chfrdup,ap);
428 * Enable logs in supplied FILE*.
432 * @param file a C FILE* where to fprintf logs. If null stdout is used.
435 void linphone_core_enable_logs(FILE *file){
436 if (file==NULL) file=stdout;
437 ortp_set_log_file(file);
438 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
439 osip_trace_initialize_func (OSIP_INFO4,&_osip_trace_func);
443 * Enable logs through the user's supplied log callback.
447 * @param logfunc The address of a OrtpLogFunc callback whose protoype is
448 * typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
451 void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc){
452 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
453 osip_trace_initialize_func (OSIP_INFO4,&_osip_trace_func);
454 ortp_set_log_handler(logfunc);
458 * Entirely disable logging.
462 void linphone_core_disable_logs(){
464 for (tl=0;tl<=OSIP_INFO4;tl++) osip_trace_disable_level(tl);
465 ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
470 net_config_read (LinphoneCore *lc)
474 LpConfig *config=lc->config;
476 tmp=lp_config_get_int(config,"net","download_bw",0);
477 linphone_core_set_download_bandwidth(lc,tmp);
478 tmp=lp_config_get_int(config,"net","upload_bw",0);
479 linphone_core_set_upload_bandwidth(lc,tmp);
480 linphone_core_set_stun_server(lc,lp_config_get_string(config,"net","stun_server",NULL));
481 tmpstr=lp_config_get_string(lc->config,"net","nat_address",NULL);
482 if (tmpstr!=NULL && (strlen(tmpstr)<1)) tmpstr=NULL;
483 linphone_core_set_nat_address(lc,tmpstr);
484 tmp=lp_config_get_int(lc->config,"net","firewall_policy",0);
485 linphone_core_set_firewall_policy(lc,tmp);
486 tmp=lp_config_get_int(lc->config,"net","nat_sdp_only",0);
487 lc->net_conf.nat_sdp_only=tmp;
488 tmp=lp_config_get_int(lc->config,"net","mtu",0);
489 linphone_core_set_mtu(lc,tmp);
492 static void build_sound_devices_table(LinphoneCore *lc){
493 const char **devices;
497 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
498 ndev=ms_list_size(elem);
499 devices=ms_malloc((ndev+1)*sizeof(const char *));
500 for (i=0;elem!=NULL;elem=elem->next,i++){
501 devices[i]=ms_snd_card_get_string_id((MSSndCard *)elem->data);
504 old=lc->sound_conf.cards;
505 lc->sound_conf.cards=devices;
506 if (old!=NULL) ms_free(old);
509 static void sound_config_read(LinphoneCore *lc)
515 /*alsadev let the user use custom alsa device within linphone*/
516 devid=lp_config_get_string(lc->config,"sound","alsadev",NULL);
518 MSSndCard *card=ms_alsa_card_new_custom(devid,devid);
519 ms_snd_card_manager_add_card(ms_snd_card_manager_get(),card);
522 /* retrieve all sound devices */
523 build_sound_devices_table(lc);
525 devid=lp_config_get_string(lc->config,"sound","playback_dev_id",NULL);
526 linphone_core_set_playback_device(lc,devid);
528 devid=lp_config_get_string(lc->config,"sound","ringer_dev_id",NULL);
529 linphone_core_set_ringer_device(lc,devid);
531 devid=lp_config_get_string(lc->config,"sound","capture_dev_id",NULL);
532 linphone_core_set_capture_device(lc,devid);
535 tmp=lp_config_get_int(lc->config,"sound","play_lev",80);
536 linphone_core_set_play_level(lc,tmp);
537 tmp=lp_config_get_int(lc->config,"sound","ring_lev",80);
538 linphone_core_set_ring_level(lc,tmp);
539 tmp=lp_config_get_int(lc->config,"sound","rec_lev",80);
540 linphone_core_set_rec_level(lc,tmp);
541 tmpbuf=lp_config_get_string(lc->config,"sound","source","m");
542 linphone_core_set_sound_source(lc,tmpbuf[0]);
545 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
546 tmpbuf=lp_config_get_string(lc->config,"sound","local_ring",tmpbuf);
547 if (ortp_file_exist(tmpbuf)==-1) {
548 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
550 if (strstr(tmpbuf,".wav")==NULL){
551 /* it currently uses old sound files, so replace them */
552 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
555 linphone_core_set_ring(lc,tmpbuf);
557 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
558 tmpbuf=lp_config_get_string(lc->config,"sound","remote_ring",tmpbuf);
559 if (ortp_file_exist(tmpbuf)==-1){
560 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
562 if (strstr(tmpbuf,".wav")==NULL){
563 /* it currently uses old sound files, so replace them */
564 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
566 linphone_core_set_ringback(lc,tmpbuf);
567 check_sound_device(lc);
568 lc->sound_conf.latency=0;
570 linphone_core_enable_echo_cancellation(lc,
571 lp_config_get_int(lc->config,"sound","echocancelation",0) |
572 lp_config_get_int(lc->config,"sound","echocancellation",0)
575 linphone_core_enable_echo_limiter(lc,
576 lp_config_get_int(lc->config,"sound","echolimiter",0));
577 linphone_core_enable_agc(lc,
578 lp_config_get_int(lc->config,"sound","agc",0));
581 static void sip_config_read(LinphoneCore *lc)
588 port=lp_config_get_int(lc->config,"sip","use_info",0);
589 linphone_core_set_use_info_for_dtmf(lc,port);
591 port=lp_config_get_int(lc->config,"sip","use_rfc2833",0);
592 linphone_core_set_use_rfc2833_for_dtmf(lc,port);
594 ipv6=lp_config_get_int(lc->config,"sip","use_ipv6",-1);
597 if (host_has_ipv6_network()){
598 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"));
601 linphone_core_enable_ipv6(lc,ipv6);
602 port=lp_config_get_int(lc->config,"sip","sip_port",5060);
603 linphone_core_set_sip_port(lc,port);
605 tmpstr=lp_config_get_string(lc->config,"sip","contact",NULL);
606 if (tmpstr==NULL || linphone_core_set_primary_contact(lc,tmpstr)==-1) {
607 const char *hostname=NULL;
608 const char *username=NULL;
610 hostname=getenv("HOST");
611 username=getenv("USER");
612 if (hostname==NULL) hostname=getenv("HOSTNAME");
613 #endif /*HAVE_GETENV*/
615 hostname="unknown-host";
619 contact=ortp_strdup_printf("sip:%s@%s",username,hostname);
620 linphone_core_set_primary_contact(lc,contact);
624 tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
625 linphone_core_set_guess_hostname(lc,tmp);
628 tmp=lp_config_get_int(lc->config,"sip","inc_timeout",15);
629 linphone_core_set_inc_timeout(lc,tmp);
631 /* get proxies config */
633 LinphoneProxyConfig *cfg=linphone_proxy_config_new_from_config_file(lc->config,i);
635 linphone_core_add_proxy_config(lc,cfg);
640 /* get the default proxy */
641 tmp=lp_config_get_int(lc->config,"sip","default_proxy",-1);
642 linphone_core_set_default_proxy_index(lc,tmp);
644 /* read authentication information */
646 LinphoneAuthInfo *ai=linphone_auth_info_new_from_config_file(lc->config,i);
648 linphone_core_add_auth_info(lc,ai);
655 lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
656 lc->sip_conf.only_one_codec=lp_config_get_int(lc->config,"sip","only_one_codec",0);
657 lc->sip_conf.register_only_when_network_is_up=
658 lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",1);
661 static void rtp_config_read(LinphoneCore *lc)
666 port=lp_config_get_int(lc->config,"rtp","audio_rtp_port",7078);
667 linphone_core_set_audio_port(lc,port);
669 port=lp_config_get_int(lc->config,"rtp","video_rtp_port",9078);
670 if (port==0) port=9078;
671 linphone_core_set_video_port(lc,port);
673 jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
674 linphone_core_set_audio_jittcomp(lc,jitt_comp);
675 jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
676 nortp_timeout=lp_config_get_int(lc->config,"rtp","nortp_timeout",30);
677 linphone_core_set_nortp_timeout(lc,nortp_timeout);
681 static PayloadType * get_codec(LpConfig *config, char* type,int index){
683 const char *mime,*fmtp;
687 snprintf(codeckey,50,"%s_%i",type,index);
688 mime=lp_config_get_string(config,codeckey,"mime",NULL);
689 if (mime==NULL || strlen(mime)==0 ) return NULL;
691 pt=payload_type_new();
692 pt->mime_type=ms_strdup(mime);
694 rate=lp_config_get_int(config,codeckey,"rate",8000);
696 fmtp=lp_config_get_string(config,codeckey,"recv_fmtp",NULL);
697 if (fmtp) pt->recv_fmtp=ms_strdup(fmtp);
698 enabled=lp_config_get_int(config,codeckey,"enabled",1);
699 if (enabled ) pt->flags|=PAYLOAD_TYPE_ENABLED;
700 //ms_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
704 static void codecs_config_read(LinphoneCore *lc)
708 MSList *audio_codecs=NULL;
709 MSList *video_codecs=NULL;
711 pt=get_codec(lc->config,"audio_codec",i);
713 audio_codecs=ms_list_append(audio_codecs,(void *)pt);
716 pt=get_codec(lc->config,"video_codec",i);
718 video_codecs=ms_list_append(video_codecs,(void *)pt);
720 linphone_core_set_audio_codecs(lc,audio_codecs);
721 linphone_core_set_video_codecs(lc,video_codecs);
722 linphone_core_setup_local_rtp_profile(lc);
725 static void video_config_read(LinphoneCore *lc)
727 int capture, display, self_view;
731 const char **devices;
735 /* retrieve all video devices */
736 elem=ms_web_cam_manager_get_list(ms_web_cam_manager_get());
737 ndev=ms_list_size(elem);
738 devices=ms_malloc((ndev+1)*sizeof(const char *));
739 for (i=0;elem!=NULL;elem=elem->next,i++){
740 devices[i]=ms_web_cam_get_string_id((MSWebCam *)elem->data);
743 lc->video_conf.cams=devices;
745 str=lp_config_get_string(lc->config,"video","device",NULL);
746 if (str && str[0]==0) str=NULL;
747 linphone_core_set_video_device(lc,str);
749 linphone_core_set_preferred_video_size_by_name(lc,
750 lp_config_get_string(lc->config,"video","size","cif"));
752 enabled=lp_config_get_int(lc->config,"video","enabled",1);
753 capture=lp_config_get_int(lc->config,"video","capture",enabled);
754 display=lp_config_get_int(lc->config,"video","display",enabled);
755 self_view=lp_config_get_int(lc->config,"video","self_view",enabled);
757 linphone_core_enable_video(lc,capture,display);
758 linphone_core_enable_self_view(lc,self_view);
762 static void ui_config_read(LinphoneCore *lc)
766 for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
767 linphone_core_add_friend(lc,lf);
769 call_logs_read_from_config_file(lc);
773 static void autoreplier_config_init(LinphoneCore *lc)
775 autoreplier_config_t *config=&lc->autoreplier_conf;
776 config->enabled=lp_config_get_int(lc->config,"autoreplier","enabled",0);
777 config->after_seconds=lp_config_get_int(lc->config,"autoreplier","after_seconds",6);
778 config->max_users=lp_config_get_int(lc->config,"autoreplier","max_users",1);
779 config->max_rec_time=lp_config_get_int(lc->config,"autoreplier","max_rec_time",60);
780 config->max_rec_msg=lp_config_get_int(lc->config,"autoreplier","max_rec_msg",10);
781 config->message=lp_config_get_string(lc->config,"autoreplier","message",NULL);
786 * Sets maximum available download bandwidth
788 * @ingroup media_parameters
790 * This is IP bandwidth, in kbit/s.
791 * This information is used signaled to other parties during
792 * calls (within SDP messages) so that the remote end can have
793 * sufficient knowledge to properly configure its audio & video
794 * codec output bitrate to not overflow available bandwidth.
796 * @param lc the LinphoneCore object
797 * @param bw the bandwidth in kbits/s, 0 for infinite
799 void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
800 lc->net_conf.download_bw=bw;
801 if (bw==0){ /*infinite*/
805 lc->dw_audio_bw=MIN(lc->audio_bw,bw);
806 lc->dw_video_bw=MAX(bw-lc->dw_audio_bw-10,0);/*-10: security margin*/
811 * Sets maximum available upload bandwidth
813 * @ingroup media_parameters
815 * This is IP bandwidth, in kbit/s.
816 * This information is used by liblinphone together with remote
817 * side available bandwidth signaled in SDP messages to properly
818 * configure audio & video codec's output bitrate.
820 * @param lc the LinphoneCore object
821 * @param bw the bandwidth in kbits/s, 0 for infinite
823 void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
824 lc->net_conf.upload_bw=bw;
825 if (bw==0){ /*infinite*/
829 lc->up_audio_bw=MIN(lc->audio_bw,bw);
830 lc->up_video_bw=MAX(bw-lc->up_audio_bw-10,0);/*-10: security margin*/
835 * Retrieve the maximum available download bandwidth.
837 * @ingroup media_parameters
839 * This value was set by linphone_core_set_download_bandwidth().
842 int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
843 return lc->net_conf.download_bw;
847 * Retrieve the maximum available upload bandwidth.
849 * @ingroup media_parameters
851 * This value was set by linphone_core_set_upload_bandwidth().
854 int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
855 return lc->net_conf.upload_bw;
859 * Returns liblinphone's version as a string.
864 const char * linphone_core_get_version(void){
865 return liblinphone_version;
869 static MSList *linphone_payload_types=NULL;
871 static void linphone_core_assign_payload_type(PayloadType *const_pt, int number, const char *recv_fmtp){
873 pt=payload_type_clone(const_pt);
874 if (recv_fmtp!=NULL) payload_type_set_recv_fmtp(pt,recv_fmtp);
875 rtp_profile_set_payload(&av_profile,number,pt);
876 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
879 static void linphone_core_free_payload_types(void){
880 ms_list_for_each(linphone_payload_types,(void (*)(void*))payload_type_destroy);
881 ms_list_free(linphone_payload_types);
882 linphone_payload_types=NULL;
885 static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path,
886 const char *factory_config_path, void * userdata)
888 memset (lc, 0, sizeof (LinphoneCore));
891 memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
893 gstate_initialize(lc);
894 gstate_new_state(lc, GSTATE_POWER_STARTUP, NULL);
897 linphone_core_assign_payload_type(&payload_type_lpc1015,115,NULL);
898 linphone_core_assign_payload_type(&payload_type_speex_nb,110,"vbr=on");
899 linphone_core_assign_payload_type(&payload_type_speex_wb,111,"vbr=on");
900 linphone_core_assign_payload_type(&payload_type_speex_uwb,112,"vbr=on");
901 linphone_core_assign_payload_type(&payload_type_telephone_event,101,NULL);
902 linphone_core_assign_payload_type(&payload_type_ilbc,113,"mode=30");
904 #ifdef ENABLE_NONSTANDARD_GSM
907 pt=payload_type_clone(&payload_type_gsm);
908 pt->clock_rate=11025;
909 rtp_profile_set_payload(&av_profile,114,pt);
910 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
911 pt=payload_type_clone(&payload_type_gsm);
912 pt->clock_rate=22050;
913 rtp_profile_set_payload(&av_profile,115,pt);
914 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
919 linphone_core_assign_payload_type(&payload_type_h263,34,NULL);
920 linphone_core_assign_payload_type(&payload_type_theora,97,NULL);
921 linphone_core_assign_payload_type(&payload_type_h263_1998,98,"CIF=1;QCIF=1");
922 linphone_core_assign_payload_type(&payload_type_mp4v,99,"profile-level-id=3");
923 linphone_core_assign_payload_type(&payload_type_x_snow,100,NULL);
924 linphone_core_assign_payload_type(&payload_type_h264,102,NULL);
925 linphone_core_assign_payload_type(&payload_type_h264,103,"packetization-mode=1");
930 lc->config=lp_config_new(config_path);
931 if (factory_config_path)
932 lp_config_read_file(lc->config,factory_config_path);
934 #ifdef VINCENT_MAURY_RSVP
935 /* default qos parameters : rsvp on, rpc off */
939 sip_setup_register_all();
940 sound_config_read(lc);
943 codecs_config_read(lc);
944 sip_config_read(lc); /* this will start eXosip*/
945 video_config_read(lc);
946 //autoreplier_config_init(&lc->autoreplier_conf);
947 lc->prev_mode=LINPHONE_STATUS_ONLINE;
948 lc->presence_mode=LINPHONE_STATUS_ONLINE;
949 lc->max_call_logs=15;
951 ms_mutex_init(&lc->lock,NULL);
952 lc->vtable.display_status(lc,_("Ready"));
953 gstate_new_state(lc, GSTATE_POWER_ON, NULL);
954 lc->auto_net_state_mon=TRUE;
959 * Instanciates a LinphoneCore object.
960 * @ingroup initializing
962 * The LinphoneCore object is the primary handle for doing all phone actions.
963 * It should be unique within your application.
964 * @param vtable a LinphoneCoreVTable structure holding your application callbacks
965 * @param config_path a path to a config file. If it does not exists it will be created.
966 * The config file is used to store all user settings, call logs, friends, proxies...
967 * @param factory_config_path a path to a read-only config file that can be used to
968 * to store hard-coded preference such as proxy settings or internal preferences.
969 * The settings in this factory file always override the one in the normal config file.
970 * It is OPTIONAL, use NULL if unneeded.
971 * @param userdata an opaque user pointer that can be retrieved at any time (for example in
972 * callbacks) using linphone_core_get_user_data().
975 LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
976 const char *config_path, const char *factory_config_path, void * userdata)
978 LinphoneCore *core=ms_new(LinphoneCore,1);
979 linphone_core_init(core,vtable,config_path, factory_config_path, userdata);
984 * Returns the list of available audio codecs.
986 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
987 * structure holding the codec information.
988 * It is possible to make copy of the list with ms_list_copy() in order to modify it
989 * (such as the order of codecs).
991 const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
993 return lc->codecs_conf.audio_codecs;
997 * Returns the list of available video codecs.
999 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1000 * structure holding the codec information.
1001 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1002 * (such as the order of codecs).
1004 const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
1006 return lc->codecs_conf.video_codecs;
1010 * Sets the local "from" identity.
1013 * This data is used in absence of any proxy configuration or when no
1014 * default proxy configuration is set. See LinphoneProxyConfig
1016 int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact)
1018 osip_from_t *ctt=NULL;
1019 osip_from_init(&ctt);
1020 if (osip_from_parse(ctt,contact)!=0){
1021 ms_error("Bad contact url: %s",contact);
1022 osip_from_free(ctt);
1025 if (lc->sip_conf.contact!=NULL) ms_free(lc->sip_conf.contact);
1026 lc->sip_conf.contact=ms_strdup(contact);
1027 if (lc->sip_conf.guessed_contact!=NULL){
1028 ms_free(lc->sip_conf.guessed_contact);
1029 lc->sip_conf.guessed_contact=NULL;
1031 osip_from_free(ctt);
1036 /*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
1037 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
1038 if (lc->apply_nat_settings){
1039 apply_nat_settings(lc);
1040 lc->apply_nat_settings=FALSE;
1042 if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
1043 strncpy(result,linphone_core_get_nat_address(lc),LINPHONE_IPADDR_SIZE);
1046 if (dest==NULL) dest="87.98.157.38"; /*a public IP address*/
1047 if (linphone_core_get_local_ip_for(dest,result)==0)
1049 /*else fallback to exosip routine that will attempt to find the most realistic interface */
1050 if (eXosip_guess_localip(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,result,LINPHONE_IPADDR_SIZE)<0){
1051 /*default to something */
1052 strncpy(result,lc->sip_conf.ipv6_enabled ? "::1" : "127.0.0.1",LINPHONE_IPADDR_SIZE);
1053 ms_error("Could not find default routable ip address !");
1058 * Returns the default identity when no proxy configuration is used.
1062 const char *linphone_core_get_primary_contact(LinphoneCore *lc)
1065 char tmp[LINPHONE_IPADDR_SIZE];
1066 if (lc->sip_conf.guess_hostname){
1067 if (lc->sip_conf.guessed_contact==NULL || lc->sip_conf.loopback_only){
1070 if (lc->sip_conf.guessed_contact!=NULL){
1071 ms_free(lc->sip_conf.guessed_contact);
1072 lc->sip_conf.guessed_contact=NULL;
1075 osip_from_init(&url);
1076 if (osip_from_parse(url,lc->sip_conf.contact)==0){
1078 }else ms_error("Could not parse identity contact !");
1079 linphone_core_get_local_ip(lc, NULL, tmp);
1080 if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
1081 ms_warning("Local loopback network only !");
1082 lc->sip_conf.loopback_only=TRUE;
1083 }else lc->sip_conf.loopback_only=FALSE;
1084 osip_free(url->url->host);
1085 url->url->host=osip_strdup(tmp);
1086 if (url->url->port!=NULL){
1087 osip_free(url->url->port);
1088 url->url->port=NULL;
1090 if (lc->sip_conf.sip_port!=5060){
1091 url->url->port=ortp_strdup_printf("%i",lc->sip_conf.sip_port);
1093 osip_from_to_str(url,&guessed);
1094 lc->sip_conf.guessed_contact=guessed;
1096 osip_from_free(url);
1099 identity=lc->sip_conf.guessed_contact;
1101 identity=lc->sip_conf.contact;
1107 * Tells LinphoneCore to guess local hostname automatically in primary contact.
1111 void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
1112 lc->sip_conf.guess_hostname=val;
1116 * Returns TRUE if hostname part of primary contact is guessed automatically.
1120 bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
1121 return lc->sip_conf.guess_hostname;
1125 * Same as linphone_core_get_primary_contact() but the result is a LinphoneAddress object
1126 * instead of const char*
1130 LinphoneAddress *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
1131 return linphone_address_new(linphone_core_get_primary_contact(lc));
1135 * Sets the list of audio codecs.
1137 * @ingroup media_parameters
1138 * The list is taken by the LinphoneCore thus the application should not free it.
1139 * This list is made of struct PayloadType describing the codec parameters.
1141 int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
1143 if (lc->codecs_conf.audio_codecs!=NULL) ms_list_free(lc->codecs_conf.audio_codecs);
1144 lc->codecs_conf.audio_codecs=codecs;
1149 * Sets the list of video codecs.
1151 * @ingroup media_parameters
1152 * The list is taken by the LinphoneCore thus the application should not free it.
1153 * This list is made of struct PayloadType describing the codec parameters.
1155 int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
1157 if (lc->codecs_conf.video_codecs!=NULL) ms_list_free(lc->codecs_conf.video_codecs);
1158 lc->codecs_conf.video_codecs=codecs;
1162 const MSList * linphone_core_get_friend_list(const LinphoneCore *lc)
1168 * Returns the nominal jitter buffer size in milliseconds.
1170 * @ingroup media_parameters
1172 int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
1174 return lc->rtp_conf.audio_jitt_comp;
1178 * Returns the UDP port used for audio streaming.
1180 * @ingroup network_parameters
1182 int linphone_core_get_audio_port(const LinphoneCore *lc)
1184 return lc->rtp_conf.audio_rtp_port;
1188 * Returns the UDP port used for video streaming.
1190 * @ingroup network_parameters
1192 int linphone_core_get_video_port(const LinphoneCore *lc){
1193 return lc->rtp_conf.video_rtp_port;
1198 * Returns the value in seconds of the no-rtp timeout.
1200 * @ingroup media_parameters
1201 * When no RTP or RTCP packets have been received for a while
1202 * LinphoneCore will consider the call is broken (remote end crashed or
1203 * disconnected from the network), and thus will terminate the call.
1204 * The no-rtp timeout is the duration above which the call is considered broken.
1206 int linphone_core_get_nortp_timeout(const LinphoneCore *lc){
1207 return lc->rtp_conf.nortp_timeout;
1211 * Sets the nominal audio jitter buffer size in milliseconds.
1213 * @ingroup media_parameters
1215 void linphone_core_set_audio_jittcomp(LinphoneCore *lc, int value)
1217 lc->rtp_conf.audio_jitt_comp=value;
1221 * Sets the UDP port used for audio streaming.
1223 * @ingroup network_parameters
1225 void linphone_core_set_audio_port(LinphoneCore *lc, int port)
1227 lc->rtp_conf.audio_rtp_port=port;
1231 * Sets the UDP port used for video streaming.
1233 * @ingroup network_parameters
1235 void linphone_core_set_video_port(LinphoneCore *lc, int port){
1236 lc->rtp_conf.video_rtp_port=port;
1240 * Sets the no-rtp timeout value in seconds.
1242 * @ingroup media_parameters
1243 * See linphone_core_get_nortp_timeout() for details.
1245 void linphone_core_set_nortp_timeout(LinphoneCore *lc, int nortp_timeout){
1246 lc->rtp_conf.nortp_timeout=nortp_timeout;
1250 * Indicates whether SIP INFO is used for sending digits.
1252 * @ingroup media_parameters
1254 bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
1256 return lc->sip_conf.use_info;
1260 * Sets whether SIP INFO is to be used for sending digits.
1262 * @ingroup media_parameters
1264 void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
1266 lc->sip_conf.use_info=use_info;
1270 * Indicates whether RFC2833 is used for sending digits.
1272 * @ingroup media_parameters
1274 bool_t linphone_core_get_use_rfc2833_for_dtmf(LinphoneCore *lc)
1276 return lc->sip_conf.use_rfc2833;
1280 * Sets whether RFC2833 is to be used for sending digits.
1282 * @ingroup media_parameters
1284 void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833)
1286 lc->sip_conf.use_rfc2833=use_rfc2833;
1290 * Returns the UDP port used by SIP.
1292 * @ingroup network_parameters
1294 int linphone_core_get_sip_port(LinphoneCore *lc)
1296 return lc->sip_conf.sip_port;
1299 static bool_t exosip_running=FALSE;
1300 static char _ua_name[64]="Linphone";
1301 static char _ua_version[64]=LINPHONE_VERSION;
1303 static void apply_user_agent(void){
1304 char ua_string[256];
1305 snprintf(ua_string,sizeof(ua_string),"%s/%s (eXosip2/%s)",_ua_name,_ua_version,
1306 #ifdef HAVE_EXOSIP_GET_VERSION
1307 eXosip_get_version()
1312 eXosip_set_user_agent(ua_string);
1316 * Sets the user agent string used in SIP messages.
1320 void linphone_core_set_user_agent(const char *name, const char *ver){
1321 strncpy(_ua_name,name,sizeof(_ua_name)-1);
1322 strncpy(_ua_version,ver,sizeof(_ua_version));
1326 * Sets the UDP port to be used by SIP.
1328 * @ingroup network_parameters
1330 void linphone_core_set_sip_port(LinphoneCore *lc,int port)
1332 const char *anyaddr;
1334 if (port==lc->sip_conf.sip_port) return;
1335 lc->sip_conf.sip_port=port;
1336 if (exosip_running) eXosip_quit();
1339 eXosip_set_option(13,&err); /*13=EXOSIP_OPT_SRV_WITH_NAPTR, as it is an enum value, we can't use it unless we are sure of the
1340 version of eXosip, which is not the case*/
1341 eXosip_enable_ipv6(lc->sip_conf.ipv6_enabled);
1342 if (lc->sip_conf.ipv6_enabled)
1346 err=eXosip_listen_addr (IPPROTO_UDP, anyaddr, port,
1347 lc->sip_conf.ipv6_enabled ? PF_INET6 : PF_INET, 0);
1349 char *msg=ortp_strdup_printf("UDP port %i seems already in use ! Cannot initialize.",port);
1351 lc->vtable.display_warning(lc,msg);
1355 #ifdef VINCENT_MAURY_RSVP
1356 /* tell exosip the qos settings according to default linphone parameters */
1357 eXosip_set_rsvp_mode (lc->rsvp_enable);
1358 eXosip_set_rpc_mode (lc->rpc_enable);
1361 exosip_running=TRUE;
1365 * Returns TRUE if IPv6 is enabled.
1367 * @ingroup network_parameters
1368 * See linphone_core_enable_ipv6() for more details on how IPv6 is supported in liblinphone.
1370 bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
1371 return lc->sip_conf.ipv6_enabled;
1375 * Turns IPv6 support on or off.
1377 * @ingroup network_parameters
1379 * @note IPv6 support is exclusive with IPv4 in liblinphone:
1380 * when IPv6 is turned on, IPv4 calls won't be possible anymore.
1381 * By default IPv6 support is off.
1383 void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
1384 if (lc->sip_conf.ipv6_enabled!=val){
1385 lc->sip_conf.ipv6_enabled=val;
1386 if (exosip_running){
1387 /* we need to restart eXosip */
1388 linphone_core_set_sip_port(lc, lc->sip_conf.sip_port);
1393 static void display_bandwidth(RtpSession *as, RtpSession *vs){
1394 ms_message("bandwidth usage: audio=[d=%.1f,u=%.1f] video=[d=%.1f,u=%.1f] kbit/sec",
1395 (as!=NULL) ? (rtp_session_compute_recv_bandwidth(as)*1e-3) : 0,
1396 (as!=NULL) ? (rtp_session_compute_send_bandwidth(as)*1e-3) : 0,
1397 (vs!=NULL) ? (rtp_session_compute_recv_bandwidth(vs)*1e-3) : 0,
1398 (vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0);
1401 static void linphone_core_disconnected(LinphoneCore *lc){
1402 lc->vtable.display_warning(lc,_("Remote end seems to have disconnected, the call is going to be closed."));
1403 linphone_core_terminate_call(lc,NULL);
1406 static void proxy_update(LinphoneCore *lc, time_t curtime){
1408 static time_t last_check=0;
1409 static bool_t last_status=FALSE;
1410 if (lc->sip_conf.register_only_when_network_is_up){
1411 char result[LINPHONE_IPADDR_SIZE];
1412 /* only do the network up checking every five seconds */
1413 if (last_check==0 || (curtime-last_check)>=5){
1414 if (eXosip_guess_localip(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,result,LINPHONE_IPADDR_SIZE)==0){
1415 if (strcmp(result,"::1")!=0 && strcmp(result,"127.0.0.1")!=0){
1417 ms_message("Network is up, registering now (%s)",result);
1418 }else last_status=FALSE;
1422 linphone_core_set_network_reachable(lc,last_status);
1424 ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
1428 static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){
1429 LinphoneFriend *lf=linphone_core_get_friend_by_uri(lc,info->sip_uri);
1432 ms_message("%s has a BuddyInfo assigned with image %p",info->sip_uri, info->image_data);
1433 if (lc->vtable.buddy_info_updated)
1434 lc->vtable.buddy_info_updated(lc,lf);
1436 ms_warning("Could not any friend with uri %s",info->sip_uri);
1440 static void analyze_buddy_lookup_results(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1442 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1443 for (elem=lc->bl_reqs;elem!=NULL;elem=ms_list_next(elem)){
1444 BuddyLookupRequest *req=(BuddyLookupRequest *)elem->data;
1445 if (req->status==BuddyLookupDone || req->status==BuddyLookupFailure){
1446 if (req->results!=NULL){
1447 BuddyInfo *i=(BuddyInfo*)req->results->data;
1448 ms_list_free(req->results);
1450 assign_buddy_info(lc,i);
1452 sip_setup_context_buddy_lookup_free(ctx,req);
1456 /*purge completed requests */
1457 while((elem=ms_list_find(lc->bl_reqs,NULL))!=NULL){
1458 lc->bl_reqs=ms_list_remove_link(lc->bl_reqs,elem);
1462 static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1464 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1465 for(elem=linphone_core_get_friend_list(lc);elem!=NULL;elem=elem->next){
1466 LinphoneFriend *lf=(LinphoneFriend*)elem->data;
1467 if (lf->info==NULL){
1468 if (linphone_core_lookup_known_proxy(lc,lf->uri)==cfg){
1469 if (linphone_address_get_username(lf->uri)!=NULL){
1470 BuddyLookupRequest *req;
1471 char *tmp=linphone_address_as_string_uri_only(lf->uri);
1472 req=sip_setup_context_create_buddy_lookup_request(ctx);
1473 buddy_lookup_request_set_key(req,tmp);
1474 buddy_lookup_request_set_max_results(req,1);
1475 sip_setup_context_buddy_lookup_submit(ctx,req);
1476 lc->bl_reqs=ms_list_append(lc->bl_reqs,req);
1484 static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
1485 LinphoneProxyConfig *cfg=NULL;
1486 linphone_core_get_default_proxy(lc,&cfg);
1488 if (lc->bl_refresh){
1489 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1490 if (ctx && (sip_setup_context_get_capabilities(ctx) & SIP_SETUP_CAP_BUDDY_LOOKUP)){
1491 linphone_core_grab_buddy_infos(lc,cfg);
1492 lc->bl_refresh=FALSE;
1495 if (lc->bl_reqs) analyze_buddy_lookup_results(lc,cfg);
1500 * Main loop function. It is crucial that your application call it periodically.
1502 * @ingroup initializing
1503 * linphone_core_iterate() performs various backgrounds tasks:
1504 * - receiving of SIP messages
1505 * - handles timers and timeout
1506 * - performs registration to proxies
1507 * - authentication retries
1508 * The application MUST call this function from periodically, in its main loop.
1509 * Be careful that this function must be call from the same thread as
1510 * other liblinphone methods. In not the case make sure all liblinphone calls are
1511 * serialized with a mutex.
1513 void linphone_core_iterate(LinphoneCore *lc)
1516 bool_t disconnected=FALSE;
1517 int disconnect_timeout = linphone_core_get_nortp_timeout(lc);
1518 time_t curtime=time(NULL);
1520 bool_t one_second_elapsed=FALSE;
1522 if (curtime-lc->prevtime>=1){
1523 lc->prevtime=curtime;
1524 one_second_elapsed=TRUE;
1527 if (lc->preview_finished){
1528 lc->preview_finished=0;
1529 ring_stop(lc->ringstream);
1530 lc->ringstream=NULL;
1531 lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
1534 if (exosip_running){
1535 while((ev=eXosip_event_wait(0,0))!=NULL){
1536 linphone_core_process_event(lc,ev);
1538 if (lc->automatic_action==0) {
1540 eXosip_automatic_action();
1545 proxy_update(lc,curtime);
1547 if (lc->call!=NULL){
1548 LinphoneCall *call=lc->call;
1550 if (call->dir==LinphoneCallIncoming && call->state==LCStateRinging){
1551 elapsed=curtime-call->start_time;
1552 ms_message("incoming call ringing for %i seconds",elapsed);
1553 if (elapsed>lc->sip_conf.inc_timeout){
1554 linphone_core_terminate_call(lc,NULL);
1556 }else if (call->state==LCStateAVRunning){
1557 if (one_second_elapsed){
1558 RtpSession *as=NULL,*vs=NULL;
1559 lc->prevtime=curtime;
1560 if (lc->audiostream!=NULL)
1561 as=lc->audiostream->session;
1562 if (lc->videostream!=NULL)
1563 vs=lc->videostream->session;
1564 display_bandwidth(as,vs);
1566 #ifdef VIDEO_ENABLED
1567 if (lc->videostream!=NULL)
1568 video_stream_iterate(lc->videostream);
1570 if (lc->audiostream!=NULL && disconnect_timeout>0)
1571 disconnected=!audio_stream_alive(lc->audiostream,disconnect_timeout);
1574 if (linphone_core_video_preview_enabled(lc)){
1575 if (lc->previewstream==NULL)
1576 toggle_video_preview(lc,TRUE);
1577 #ifdef VIDEO_ENABLED
1578 else video_stream_iterate(lc->previewstream);
1581 if (lc->previewstream!=NULL)
1582 toggle_video_preview(lc,FALSE);
1585 linphone_core_disconnected(lc);
1587 linphone_core_do_plugin_tasks(lc);
1589 if (one_second_elapsed && lp_config_needs_commit(lc->config)){
1590 lp_config_sync(lc->config);
1595 bool_t linphone_core_is_in_main_thread(LinphoneCore *lc){
1599 static char *guess_route_if_any(LinphoneCore *lc, osip_to_t *parsed_url){
1600 const MSList *elem=linphone_core_get_proxy_config_list(lc);
1601 for(;elem!=NULL;elem=elem->next){
1602 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1604 if (cfg->ssctx && sip_setup_context_get_proxy(cfg->ssctx,parsed_url->url->host,prx,sizeof(prx))==0){
1605 ms_message("We have a proxy for domain %s",parsed_url->url->host);
1606 if (strcmp(parsed_url->url->host,prx)!=0){
1609 osip_route_init(&rt);
1610 if (osip_route_parse(rt,prx)==0){
1612 osip_uri_uparam_add(rt->url,osip_strdup("lr"),NULL);
1613 osip_route_to_str(rt,&rtstr);
1614 route=ms_strdup(rtstr);
1617 osip_route_free(rt);
1618 ms_message("Adding a route: %s",route);
1626 bool_t linphone_core_interpret_url(LinphoneCore *lc, const char *url, LinphoneAddress **real_parsed_url, char **route){
1627 enum_lookup_res_t *enumres=NULL;
1628 osip_to_t *parsed_url=NULL;
1629 char *enum_domain=NULL;
1630 LinphoneProxyConfig *proxy=lc->default_proxy;;
1632 const char *tmproute;
1633 LinphoneAddress *uri;
1635 if (real_parsed_url!=NULL) *real_parsed_url=NULL;
1637 tmproute=linphone_core_get_route(lc);
1639 if (is_enum(url,&enum_domain)){
1640 lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
1641 if (enum_lookup(enum_domain,&enumres)<0){
1642 lc->vtable.display_status(lc,_("Could not resolve this number."));
1643 ms_free(enum_domain);
1646 ms_free(enum_domain);
1647 tmpurl=enumres->sip_address[0];
1648 if (real_parsed_url!=NULL) *real_parsed_url=linphone_address_new(tmpurl);
1649 enum_lookup_res_free(enumres);
1650 if (tmproute) *route=ms_strdup(tmproute);
1653 /* check if we have a "sip:" */
1654 if (strstr(url,"sip:")==NULL){
1655 /* this doesn't look like a true sip uri */
1656 if (strchr(url,'@')!=NULL){
1657 /* seems like sip: is missing !*/
1658 tmpurl=ms_strdup_printf("sip:%s",url);
1659 uri=linphone_address_new(tmpurl);
1662 if (real_parsed_url!=NULL) *real_parsed_url=uri;
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);
1680 if (real_parsed_url!=NULL) *real_parsed_url=uri;
1682 /*if the prompted uri was auto-suffixed with proxy domain,
1683 then automatically set a route so that the request goes
1685 if (tmproute==NULL){
1686 osip_route_t *rt=NULL;
1688 osip_route_init(&rt);
1689 if (osip_route_parse(rt,linphone_proxy_config_get_addr(proxy))==0){
1690 osip_uri_uparam_add(rt->url,osip_strdup("lr"),NULL);
1691 osip_route_to_str(rt,&rtstr);
1692 *route=ms_strdup(rtstr);
1695 ms_message("setting automatically a route to %s",*route);
1697 else *route=ms_strdup(tmproute);
1699 if (tmproute==NULL) *route=guess_route_if_any(lc,*real_parsed_url);
1700 if (tmproute) *route=ms_strdup(tmproute);
1705 parsed_url=linphone_address_new(url);
1706 if (parsed_url!=NULL){
1707 if (real_parsed_url!=NULL) *real_parsed_url=parsed_url;
1708 else linphone_address_destroy(parsed_url);
1709 if (tmproute) *route=ms_strdup(tmproute);
1710 else *route=guess_route_if_any(lc,*real_parsed_url);
1713 /* else we could not do anything with url given by user, so display an error */
1714 if (lc->vtable.display_warning!=NULL){
1715 lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
1721 * Returns the default identity SIP address.
1724 * This is an helper function:
1726 * If no default proxy is set, this will return the primary contact (
1727 * see linphone_core_get_primary_contact() ). If a default proxy is set
1728 * it returns the registered identity on the proxy.
1730 const char * linphone_core_get_identity(LinphoneCore *lc){
1731 LinphoneProxyConfig *proxy=NULL;
1733 linphone_core_get_default_proxy(lc,&proxy);
1735 from=linphone_proxy_config_get_identity(proxy);
1736 }else from=linphone_core_get_primary_contact(lc);
1740 const char * linphone_core_get_route(LinphoneCore *lc){
1741 LinphoneProxyConfig *proxy=NULL;
1742 const char *route=NULL;
1743 linphone_core_get_default_proxy(lc,&proxy);
1745 route=linphone_proxy_config_get_route(proxy);
1750 void linphone_set_sdp(osip_message_t *sip, const char *sdpmesg){
1751 int sdplen=strlen(sdpmesg);
1753 snprintf(clen,sizeof(clen),"%i",sdplen);
1754 osip_message_set_body(sip,sdpmesg,sdplen);
1755 osip_message_set_content_type(sip,"application/sdp");
1756 osip_message_set_content_length(sip,clen);
1759 LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
1761 LinphoneProxyConfig *found_cfg=NULL;
1762 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=elem->next){
1763 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1764 const char *domain=linphone_proxy_config_get_domain(cfg);
1765 if (domain!=NULL && strcmp(domain,linphone_address_get_domain(uri))==0){
1773 static void fix_contact(LinphoneCore *lc, osip_message_t *msg, const char *localip, LinphoneProxyConfig *dest_proxy){
1774 osip_contact_t *ctt=NULL;
1775 const char *ip=NULL;
1778 osip_message_get_contact(msg,0,&ctt);
1780 if (dest_proxy!=NULL){
1781 /* if we know the request will go to a known proxy for which we are registered,
1782 we can use the same contact address as in the register */
1783 linphone_proxy_config_get_contact(dest_proxy,&ip,&port);
1786 port=linphone_core_get_sip_port(lc);
1789 osip_free(ctt->url->host);
1790 ctt->url->host=osip_strdup(ip);
1795 snprintf(tmp,sizeof(tmp)-1,"%i",port);
1796 if (ctt->url->port!=NULL)
1797 osip_free(ctt->url->port);
1798 ctt->url->port=osip_strdup(tmp);
1799 osip_contact_to_str(ctt,&str);
1800 ms_message("Contact has been fixed to %s",str);
1807 * Initiates an outgoing call
1809 * @ingroup call_control
1810 * @param lc the LinphoneCore object
1811 * @param url the destination of the call (sip address).
1813 int linphone_core_invite(LinphoneCore *lc, const char *url)
1819 const char *from=NULL;
1820 osip_message_t *invite=NULL;
1821 sdp_context_t *ctx=NULL;
1822 LinphoneProxyConfig *proxy=NULL;
1823 LinphoneAddress *parsed_url2=NULL;
1824 LinphoneAddress *real_parsed_url=NULL;
1825 char *real_url=NULL;
1826 LinphoneProxyConfig *dest_proxy=NULL;
1828 if (lc->call!=NULL){
1829 lc->vtable.display_warning(lc,_("Sorry, having multiple simultaneous calls is not supported yet !"));
1833 linphone_core_get_default_proxy(lc,&proxy);
1834 if (!linphone_core_interpret_url(lc,url,&real_parsed_url,&route)){
1837 real_url=linphone_address_as_string(real_parsed_url);
1838 dest_proxy=linphone_core_lookup_known_proxy(lc,real_parsed_url);
1840 if (proxy!=dest_proxy && dest_proxy!=NULL) {
1841 ms_message("Overriding default proxy setting for this call:");
1842 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
1845 if (dest_proxy!=NULL)
1846 from=linphone_proxy_config_get_identity(dest_proxy);
1847 else if (proxy!=NULL)
1848 from=linphone_proxy_config_get_identity(proxy);
1850 /* if no proxy or no identity defined for this proxy, default to primary contact*/
1851 if (from==NULL) from=linphone_core_get_primary_contact(lc);
1853 err=eXosip_call_build_initial_invite(&invite,real_url,from,
1854 route,"Phone call");
1856 ms_warning("Could not build initial invite cause [%i]",err);
1859 if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
1860 osip_message_set_header(invite, "Session-expires", "200");
1861 osip_message_set_supported(invite, "timer");
1863 /* make sdp message */
1865 parsed_url2=linphone_address_new(from);
1867 lc->call=linphone_call_new_outgoing(lc,parsed_url2,real_parsed_url);
1868 /*try to be best-effort in giving real local or routable contact address,
1869 except when the user choosed to override the ipaddress */
1870 if (linphone_core_get_firewall_policy(lc)!=LINPHONE_POLICY_USE_NAT_ADDRESS)
1871 fix_contact(lc,invite,lc->call->localip,dest_proxy);
1873 barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
1874 lc->vtable.display_status(lc,barmsg);
1876 if (!lc->sip_conf.sdp_200_ack){
1877 ctx=lc->call->sdpctx;
1878 sdpmesg=sdp_context_get_offer(ctx);
1879 linphone_set_sdp(invite,sdpmesg);
1880 linphone_core_init_media_streams(lc);
1883 err=eXosip_call_send_initial_invite(invite);
1888 ms_warning("Could not initiate call.");
1889 lc->vtable.display_status(lc,_("could not call"));
1890 linphone_call_destroy(lc->call);
1892 linphone_core_stop_media_streams(lc);
1893 }else gstate_new_state(lc, GSTATE_CALL_OUT_INVITE, url);
1897 if (real_url!=NULL) ms_free(real_url);
1898 if (route!=NULL) ms_free(route);
1899 return (err<0) ? -1 : 0;
1902 int linphone_core_refer(LinphoneCore *lc, const char *url)
1904 char *real_url=NULL;
1905 LinphoneAddress *real_parsed_url=NULL;
1907 osip_message_t *msg=NULL;
1909 if (!linphone_core_interpret_url(lc,url,&real_parsed_url, &route)){
1913 if (route!=NULL) ms_free(route);
1916 ms_warning("No established call to refer.");
1920 real_url=linphone_address_as_string (real_parsed_url);
1921 eXosip_call_build_refer(call->did, real_url, &msg);
1924 eXosip_call_send_request(call->did, msg);
1930 * Returns true if in incoming call is pending, ie waiting for being answered or declined.
1932 * @ingroup call_control
1934 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
1935 if (lc->call!=NULL && lc->call->dir==LinphoneCallIncoming){
1941 #ifdef VINCENT_MAURY_RSVP
1942 /* on=1 for RPC_ENABLE=1...*/
1943 int linphone_core_set_rpc_mode(LinphoneCore *lc, int on)
1946 printf("RPC_ENABLE set on\n");
1948 printf("RPC_ENABLE set off\n");
1949 lc->rpc_enable = (on==1);
1950 /* need to tell eXosip the new setting */
1951 if (eXosip_set_rpc_mode (lc->rpc_enable)!=0)
1956 /* on=1 for RSVP_ENABLE=1...*/
1957 int linphone_core_set_rsvp_mode(LinphoneCore *lc, int on)
1960 printf("RSVP_ENABLE set on\n");
1962 printf("RSVP_ENABLE set off\n");
1963 lc->rsvp_enable = (on==1);
1964 /* need to tell eXosip the new setting */
1965 if (eXosip_set_rsvp_mode (lc->rsvp_enable)!=0)
1970 /* answer : 1 for yes, 0 for no */
1971 int linphone_core_change_qos(LinphoneCore *lc, int answer)
1974 if (lc->call==NULL){
1978 if (lc->rsvp_enable && answer==1)
1980 /* answer is yes, local setting is with qos, so
1981 * the user chose to continue with no qos ! */
1982 /* so switch in normal mode : ring and 180 */
1983 lc->rsvp_enable = 0; /* no more rsvp */
1984 eXosip_set_rsvp_mode (lc->rsvp_enable);
1987 eXosip_answer_call(lc->call->did,180,NULL);
1990 ms_message("Starting local ring...");
1991 lc->ringstream=ring_start(lc->sound_conf.local_ring,
1992 2000,ms_snd_card_manager_get_card(ms_snd_card_manager_get(),lc->sound_conf.ring_sndcard));
1994 else if (!lc->rsvp_enable && answer==1)
1996 /* switch to QoS mode on : answer 183 session progress */
1997 lc->rsvp_enable = 1;
1998 eXosip_set_rsvp_mode (lc->rsvp_enable);
1999 /* take the sdp already computed, see osipuacb.c */
2000 sdpmesg=lc->call->sdpctx->answerstr;
2002 eXosip_answer_call_with_body(lc->call->did,183,"application/sdp",sdpmesg);
2007 /* decline offer (603) */
2008 linphone_core_terminate_call(lc, NULL);
2014 void linphone_core_init_media_streams(LinphoneCore *lc){
2015 lc->audiostream=audio_stream_new(linphone_core_get_audio_port(lc),linphone_core_ipv6_enabled(lc));
2016 if (linphone_core_echo_limiter_enabled(lc)){
2017 const char *type=lp_config_get_string(lc->config,"sound","el_type","mic");
2018 if (strcasecmp(type,"mic")==0)
2019 audio_stream_enable_echo_limiter(lc->audiostream,ELControlMic);
2020 else if (strcasecmp(type,"speaker")==0)
2021 audio_stream_enable_echo_limiter(lc->audiostream,ELControlSpeaker);
2023 audio_stream_enable_gain_control(lc->audiostream,TRUE);
2024 if (linphone_core_echo_cancellation_enabled(lc)){
2025 int len,delay,framesize;
2026 len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
2027 delay=lp_config_get_int(lc->config,"sound","ec_delay",0);
2028 framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0);
2029 audio_stream_set_echo_canceller_params(lc->audiostream,len,delay,framesize);
2031 audio_stream_enable_automatic_gain_control(lc->audiostream,linphone_core_agc_enabled(lc));
2033 int enabled=lp_config_get_int(lc->config,"sound","noisegate",0);
2034 audio_stream_enable_noise_gate(lc->audiostream,enabled);
2037 rtp_session_set_transports(lc->audiostream->session,lc->a_rtp,lc->a_rtcp);
2039 #ifdef VIDEO_ENABLED
2040 if (lc->video_conf.display || lc->video_conf.capture)
2041 lc->videostream=video_stream_new(linphone_core_get_video_port(lc),linphone_core_ipv6_enabled(lc));
2043 lc->videostream=NULL;
2047 static void linphone_core_dtmf_received(RtpSession* s, int dtmf, void* user_data){
2048 LinphoneCore* lc = (LinphoneCore*)user_data;
2049 if (lc->vtable.dtmf_received != NULL)
2050 lc->vtable.dtmf_received(lc, dtmf);
2053 static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){
2055 MSFilter *f=st->equalizer;
2056 int enabled=lp_config_get_int(lc->config,"sound","eq_active",0);
2057 const char *gains=lp_config_get_string(lc->config,"sound","eq_gains",NULL);
2058 ms_filter_call_method(f,MS_EQUALIZER_SET_ACTIVE,&enabled);
2064 if (sscanf(gains,"%f:%f:%f %n",&g.frequency,&g.gain,&g.width,&bytes)==3){
2065 ms_message("Read equalizer gains: %f(~%f) --> %f",g.frequency,g.width,g.gain);
2066 ms_filter_call_method(f,MS_EQUALIZER_SET_GAIN,&g);
2075 static void post_configure_audio_streams(LinphoneCore *lc){
2076 AudioStream *st=lc->audiostream;
2077 float gain=lp_config_get_float(lc->config,"sound","mic_gain",-1);
2079 audio_stream_set_mic_gain(st,gain);
2080 if (linphone_core_echo_limiter_enabled(lc)){
2081 float speed=lp_config_get_float(lc->config,"sound","el_speed",-1);
2082 float thres=lp_config_get_float(lc->config,"sound","el_thres",-1);
2083 float force=lp_config_get_float(lc->config,"sound","el_force",-1);
2084 int sustain=lp_config_get_int(lc->config,"sound","el_sustain",-1);
2086 if (st->el_type==ELControlMic){
2088 if (speed==-1) speed=0.03;
2089 if (force==-1) force=10;
2091 else if (st->el_type==ELControlSpeaker){
2093 if (speed==-1) speed=0.02;
2094 if (force==-1) force=5;
2097 ms_filter_call_method(f,MS_VOLUME_SET_EA_SPEED,&speed);
2099 ms_filter_call_method(f,MS_VOLUME_SET_EA_THRESHOLD,&thres);
2101 ms_filter_call_method(f,MS_VOLUME_SET_EA_FORCE,&force);
2103 ms_filter_call_method(f,MS_VOLUME_SET_EA_SUSTAIN,&sustain);
2107 float ng_thres=lp_config_get_float(lc->config,"sound","ng_thres",0.05);
2108 float ng_floorgain=lp_config_get_float(lc->config,"sound","ng_floorgain",0);
2109 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_thres);
2110 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&ng_floorgain);
2112 parametrize_equalizer(lc,st);
2113 if (lc->vtable.dtmf_received!=NULL){
2114 /* replace by our default action*/
2115 audio_stream_play_received_dtmfs(lc->audiostream,FALSE);
2116 rtp_session_signal_connect(lc->audiostream->session,"telephone-event",(RtpCallback)linphone_core_dtmf_received,(unsigned long)lc);
2120 void linphone_core_start_media_streams(LinphoneCore *lc, LinphoneCall *call){
2121 LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
2122 const char *tool="linphone-" LINPHONE_VERSION;
2124 /* adjust rtp jitter compensation. It must be at least the latency of the sound card */
2125 int jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
2127 if (call->media_start_time==0) call->media_start_time=time(NULL);
2129 cname=ortp_strdup_printf("%s@%s",me->url->username,me->url->host);
2131 StreamParams *audio_params=&call->audio_params;
2132 if (!lc->use_files){
2133 MSSndCard *playcard=lc->sound_conf.play_sndcard;
2134 MSSndCard *captcard=lc->sound_conf.capt_sndcard;
2135 if (playcard==NULL) {
2136 ms_warning("No card defined for playback !");
2139 if (captcard==NULL) {
2140 ms_warning("No card defined for capture !");
2143 if (audio_params->relay_session_id!=NULL)
2144 audio_stream_set_relay_session_id(lc->audiostream,audio_params->relay_session_id);
2145 audio_stream_start_now(
2148 audio_params->remoteaddr,
2149 audio_params->remoteport,
2150 audio_params->remotertcpport,
2155 linphone_core_echo_cancellation_enabled(lc));
2157 audio_stream_start_with_files(
2160 audio_params->remoteaddr,
2161 audio_params->remoteport,
2162 audio_params->remotertcpport,
2168 post_configure_audio_streams(lc);
2169 audio_stream_set_rtcp_information(lc->audiostream, cname, tool);
2171 #ifdef VIDEO_ENABLED
2173 /* shutdown preview */
2174 if (lc->previewstream!=NULL) {
2175 video_preview_stop(lc->previewstream);
2176 lc->previewstream=NULL;
2178 if (lc->video_conf.display || lc->video_conf.capture) {
2179 StreamParams *video_params=&call->video_params;
2181 if (video_params->remoteport>0){
2182 if (video_params->relay_session_id!=NULL)
2183 video_stream_set_relay_session_id(lc->videostream,video_params->relay_session_id);
2184 video_stream_set_sent_video_size(lc->videostream,linphone_core_get_preferred_video_size(lc));
2185 video_stream_enable_self_view(lc->videostream,lc->video_conf.selfview);
2186 if (lc->video_conf.display && lc->video_conf.capture)
2187 video_stream_start(lc->videostream,
2188 call->profile, video_params->remoteaddr, video_params->remoteport,
2189 video_params->remotertcpport,
2190 video_params->pt, jitt_comp, lc->video_conf.device);
2191 else if (lc->video_conf.display)
2192 video_stream_recv_only_start(lc->videostream,
2193 call->profile, video_params->remoteaddr, video_params->remoteport,
2194 video_params->pt, jitt_comp);
2195 else if (lc->video_conf.capture)
2196 video_stream_send_only_start(lc->videostream,
2197 call->profile, video_params->remoteaddr, video_params->remoteport,
2198 video_params->remotertcpport,
2199 video_params->pt, jitt_comp, lc->video_conf.device);
2200 video_stream_set_rtcp_information(lc->videostream, cname,tool);
2208 linphone_address_destroy(me);
2209 lc->call->state=LCStateAVRunning;
2212 void linphone_core_stop_media_streams(LinphoneCore *lc){
2213 if (lc->audiostream!=NULL) {
2214 audio_stream_stop(lc->audiostream);
2215 lc->audiostream=NULL;
2217 #ifdef VIDEO_ENABLED
2218 if (lc->videostream!=NULL){
2219 if (lc->video_conf.display && lc->video_conf.capture)
2220 video_stream_stop(lc->videostream);
2221 else if (lc->video_conf.display)
2222 video_stream_recv_only_stop(lc->videostream);
2223 else if (lc->video_conf.capture)
2224 video_stream_send_only_stop(lc->videostream);
2225 lc->videostream=NULL;
2227 if (linphone_core_video_preview_enabled(lc)){
2228 if (lc->previewstream==NULL){
2229 lc->previewstream=video_preview_start(lc->video_conf.device, lc->video_conf.vsize);
2236 * Accept an incoming call.
2238 * @ingroup call_control
2239 * Basically the application is notified of incoming calls within the
2240 * invite_recv callback of the #LinphoneCoreVTable structure.
2241 * The application can later respond positively to the call using
2243 * @param lc the LinphoneCore object
2244 * @param url the SIP address of the originator of the call, or NULL.
2245 * This argument is useful for managing multiple calls simulatenously,
2246 * however this feature is not supported yet.
2247 * Using NULL will accept the unique incoming call in progress.
2249 int linphone_core_accept_call(LinphoneCore *lc, const char *url)
2252 osip_message_t *msg=NULL;
2253 LinphoneCall *call=lc->call;
2255 bool_t offering=FALSE;
2261 if (lc->call->state==LCStateAVRunning){
2262 /*call already accepted*/
2267 if (lc->ringstream!=NULL) {
2268 ms_message("stop ringing");
2269 ring_stop(lc->ringstream);
2270 ms_message("ring stopped");
2271 lc->ringstream=NULL;
2273 /* sends a 200 OK */
2274 err=eXosip_call_build_answer(call->tid,200,&msg);
2275 if (err<0 || msg==NULL){
2276 ms_error("Fail to build answer for call: err=%i",err);
2279 if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
2280 if (call->supports_session_timers) osip_message_set_supported(msg, "timer");
2282 /*try to be best-effort in giving real local or routable contact address,
2283 except when the user choosed to override the ipaddress */
2284 if (linphone_core_get_firewall_policy(lc)!=LINPHONE_POLICY_USE_NAT_ADDRESS)
2285 fix_contact(lc,msg,call->localip,NULL);
2286 /*if a sdp answer is computed, send it, else send an offer */
2287 sdpmesg=call->sdpctx->answerstr;
2290 ms_message("generating sdp offer");
2291 sdpmesg=sdp_context_get_offer(call->sdpctx);
2294 ms_error("fail to generate sdp offer !");
2297 linphone_set_sdp(msg,sdpmesg);
2298 linphone_core_init_media_streams(lc);
2300 linphone_set_sdp(msg,sdpmesg);
2303 eXosip_call_send_answer(call->tid,200,msg);
2305 lc->vtable.display_status(lc,_("Connected."));
2306 gstate_new_state(lc, GSTATE_CALL_IN_CONNECTED, NULL);
2308 if (!offering) linphone_core_start_media_streams(lc, lc->call);
2309 ms_message("call answered.");
2314 * Terminates a call.
2316 * @ingroup call_control
2317 * @param lc The LinphoneCore
2318 * @param url the destination of the call to be terminated, use NULL if there is
2319 * only one call (which is case in this version of liblinphone).
2321 int linphone_core_terminate_call(LinphoneCore *lc, const char *url)
2323 LinphoneCall *call=lc->call;
2330 eXosip_call_terminate(call->cid,call->did);
2334 if (lc->ringstream!=NULL) {
2335 ring_stop(lc->ringstream);
2336 lc->ringstream=NULL;
2338 linphone_core_stop_media_streams(lc);
2339 lc->vtable.display_status(lc,_("Call ended") );
2340 gstate_new_state(lc, GSTATE_CALL_END, NULL);
2341 linphone_call_destroy(call);
2346 * Returns TRUE if there is a call running or pending.
2348 * @ingroup call_control
2350 bool_t linphone_core_in_call(const LinphoneCore *lc){
2351 return lc->call!=NULL;
2354 int linphone_core_send_publish(LinphoneCore *lc,
2355 LinphoneOnlineStatus presence_mode)
2358 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=ms_list_next(elem)){
2359 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2360 if (cfg->publish) linphone_proxy_config_send_publish(cfg,presence_mode);
2366 * Set the incoming call timeout in seconds.
2368 * @ingroup call_control
2369 * If an incoming call isn't answered for this timeout period, it is
2370 * automatically declined.
2372 void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
2373 lc->sip_conf.inc_timeout=seconds;
2377 * Returns the incoming call timeout
2379 * @ingroup call_control
2380 * See linphone_core_set_inc_timeout() for details.
2382 int linphone_core_get_inc_timeout(LinphoneCore *lc){
2383 return lc->sip_conf.inc_timeout;
2386 void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
2387 const char *contact,
2388 LinphoneOnlineStatus presence_mode)
2391 if (minutes_away>0) lc->minutes_away=minutes_away;
2392 if (contact!=NULL) {
2394 osip_from_init(&url);
2395 contactok=osip_from_parse(url,contact);
2397 ms_message("contact url is correct.");
2399 osip_from_free(url);
2403 if (lc->alt_contact!=NULL) ms_free(lc->alt_contact);
2404 lc->alt_contact=ms_strdup(contact);
2406 if (lc->presence_mode!=presence_mode){
2407 linphone_core_notify_all_friends(lc,presence_mode);
2409 Improve the use of all LINPHONE_STATUS available.
2410 !TODO Do not mix "presence status" with "answer status code"..
2411 Use correct parameter to follow sip_if_match/sip_etag.
2413 linphone_core_send_publish(lc,presence_mode);
2415 lc->prev_mode=lc->presence_mode;
2416 lc->presence_mode=presence_mode;
2420 LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
2421 return lc->presence_mode;
2425 * Get playback sound level in 0-100 scale.
2427 * @ingroup media_parameters
2429 int linphone_core_get_play_level(LinphoneCore *lc)
2431 return lc->sound_conf.play_lev;
2435 * Get ring sound level in 0-100 scale
2437 * @ingroup media_parameters
2439 int linphone_core_get_ring_level(LinphoneCore *lc)
2441 return lc->sound_conf.ring_lev;
2445 * Get sound capture level in 0-100 scale
2447 * @ingroup media_parameters
2449 int linphone_core_get_rec_level(LinphoneCore *lc){
2450 return lc->sound_conf.rec_lev;
2454 * Set sound ring level in 0-100 scale
2456 * @ingroup media_parameters
2458 void linphone_core_set_ring_level(LinphoneCore *lc, int level){
2460 lc->sound_conf.ring_lev=level;
2461 sndcard=lc->sound_conf.ring_sndcard;
2462 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2466 * Set sound playback level in 0-100 scale
2468 * @ingroup media_parameters
2470 void linphone_core_set_play_level(LinphoneCore *lc, int level){
2472 lc->sound_conf.play_lev=level;
2473 sndcard=lc->sound_conf.play_sndcard;
2474 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2478 * Set sound capture level in 0-100 scale
2480 * @ingroup media_parameters
2482 void linphone_core_set_rec_level(LinphoneCore *lc, int level)
2485 lc->sound_conf.rec_lev=level;
2486 sndcard=lc->sound_conf.capt_sndcard;
2487 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_CAPTURE,level);
2490 static MSSndCard *get_card_from_string_id(const char *devid, unsigned int cap){
2491 MSSndCard *sndcard=NULL;
2493 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2494 if (sndcard!=NULL &&
2495 (ms_snd_card_get_capabilities(sndcard) & cap)==0 ){
2496 ms_warning("%s card does not have the %s capability, ignoring.",
2498 cap==MS_SND_CARD_CAP_CAPTURE ? "capture" : "playback");
2502 if (sndcard==NULL) {
2503 /* get a card that has read+write capabilities */
2504 sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
2505 /* otherwise refine to the first card having the right capability*/
2507 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2508 for(;elem!=NULL;elem=elem->next){
2509 sndcard=(MSSndCard*)elem->data;
2510 if (ms_snd_card_get_capabilities(sndcard) & cap) break;
2513 if (sndcard==NULL){/*looks like a bug! take the first one !*/
2514 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2515 sndcard=(MSSndCard*)elem->data;
2518 if (sndcard==NULL) ms_error("Could not find a suitable soundcard !");
2523 * Returns true if the specified sound device can capture sound.
2525 * @ingroup media_parameters
2526 * @param devid the device name as returned by linphone_core_get_sound_devices()
2528 bool_t linphone_core_sound_device_can_capture(LinphoneCore *lc, const char *devid){
2530 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2531 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_CAPTURE)) return TRUE;
2536 * Returns true if the specified sound device can play sound.
2538 * @ingroup media_parameters
2539 * @param devid the device name as returned by linphone_core_get_sound_devices()
2541 bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *devid){
2543 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2544 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_PLAYBACK)) return TRUE;
2549 * Sets the sound device used for ringing.
2551 * @ingroup media_parameters
2552 * @param devid the device name as returned by linphone_core_get_sound_devices()
2554 int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
2555 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2556 lc->sound_conf.ring_sndcard=card;
2557 if (card && lc->ready)
2558 lp_config_set_string(lc->config,"sound","ringer_dev_id",ms_snd_card_get_string_id(card));
2563 * Sets the sound device used for playback.
2565 * @ingroup media_parameters
2566 * @param devid the device name as returned by linphone_core_get_sound_devices()
2568 int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
2569 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2570 lc->sound_conf.play_sndcard=card;
2571 if (card && lc->ready)
2572 lp_config_set_string(lc->config,"sound","playback_dev_id",ms_snd_card_get_string_id(card));
2577 * Sets the sound device used for capture.
2579 * @ingroup media_parameters
2580 * @param devid the device name as returned by linphone_core_get_sound_devices()
2582 int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
2583 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_CAPTURE);
2584 lc->sound_conf.capt_sndcard=card;
2585 if (card && lc->ready)
2586 lp_config_set_string(lc->config,"sound","capture_dev_id",ms_snd_card_get_string_id(card));
2591 * Returns the name of the currently assigned sound device for ringing.
2593 * @ingroup media_parameters
2595 const char * linphone_core_get_ringer_device(LinphoneCore *lc)
2597 if (lc->sound_conf.ring_sndcard) return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
2602 * Returns the name of the currently assigned sound device for playback.
2604 * @ingroup media_parameters
2606 const char * linphone_core_get_playback_device(LinphoneCore *lc)
2608 return lc->sound_conf.play_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.play_sndcard) : NULL;
2612 * Returns the name of the currently assigned sound device for capture.
2614 * @ingroup media_parameters
2616 const char * linphone_core_get_capture_device(LinphoneCore *lc)
2618 return lc->sound_conf.capt_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard) : NULL;
2622 * Returns an unmodifiable array of available sound devices.
2624 * @ingroup media_parameters
2625 * The array is NULL terminated.
2627 const char** linphone_core_get_sound_devices(LinphoneCore *lc){
2628 build_sound_devices_table(lc);
2629 return lc->sound_conf.cards;
2633 * Returns an unmodifiable array of available video capture devices.
2635 * @ingroup media_parameters
2636 * The array is NULL terminated.
2638 const char** linphone_core_get_video_devices(const LinphoneCore *lc){
2639 return lc->video_conf.cams;
2642 char linphone_core_get_sound_source(LinphoneCore *lc)
2644 return lc->sound_conf.source;
2647 void linphone_core_set_sound_source(LinphoneCore *lc, char source)
2649 MSSndCard *sndcard=lc->sound_conf.capt_sndcard;
2650 lc->sound_conf.source=source;
2651 if (!sndcard) return;
2654 ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
2657 ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
2665 * Sets the path to a wav file used for ringing.
2667 * The file must be a wav 16bit linear.
2669 * @ingroup media_parameters
2671 void linphone_core_set_ring(LinphoneCore *lc,const char *path){
2672 if (lc->sound_conf.local_ring!=0){
2673 ms_free(lc->sound_conf.local_ring);
2675 lc->sound_conf.local_ring=ms_strdup(path);
2676 if (lc->ready && lc->sound_conf.local_ring)
2677 lp_config_set_string(lc->config,"sound","local_ring",lc->sound_conf.local_ring);
2681 * Returns the path to the wav file used for ringing.
2683 * @ingroup media_parameters
2685 const char *linphone_core_get_ring(const LinphoneCore *lc){
2686 return lc->sound_conf.local_ring;
2689 static void notify_end_of_ring(void *ud ,unsigned int event, void * arg){
2690 LinphoneCore *lc=(LinphoneCore*)ud;
2691 lc->preview_finished=1;
2694 int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata)
2696 if (lc->ringstream!=0){
2697 ms_warning("Cannot start ring now,there's already a ring being played");
2700 lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
2701 lc->preview_finished=0;
2702 if (lc->sound_conf.ring_sndcard!=NULL){
2703 lc->ringstream=ring_start_with_cb(ring,2000,lc->sound_conf.ring_sndcard,notify_end_of_ring,(void *)lc);
2709 * Sets the path to a wav file used for ringing back.
2711 * Ringback means the ring that is heard when it's ringing at the remote party.
2712 * The file must be a wav 16bit linear.
2714 * @ingroup media_parameters
2716 void linphone_core_set_ringback(LinphoneCore *lc, const char *path){
2717 if (lc->sound_conf.remote_ring!=0){
2718 ms_free(lc->sound_conf.remote_ring);
2720 lc->sound_conf.remote_ring=ms_strdup(path);
2724 * Returns the path to the wav file used for ringing back.
2726 * @ingroup media_parameters
2728 const char * linphone_core_get_ringback(const LinphoneCore *lc){
2729 return lc->sound_conf.remote_ring;
2733 * Enables or disable echo cancellation.
2735 * @ingroup media_parameters
2737 void linphone_core_enable_echo_cancellation(LinphoneCore *lc, bool_t val){
2738 lc->sound_conf.ec=val;
2740 lp_config_set_int(lc->config,"sound","echocancellation",val);
2744 * Returns TRUE if echo cancellation is enabled.
2746 * @ingroup media_parameters
2748 bool_t linphone_core_echo_cancellation_enabled(LinphoneCore *lc){
2749 return lc->sound_conf.ec;
2752 void linphone_core_enable_echo_limiter(LinphoneCore *lc, bool_t val){
2753 lc->sound_conf.ea=val;
2756 bool_t linphone_core_echo_limiter_enabled(const LinphoneCore *lc){
2757 return lc->sound_conf.ea;
2761 * Mutes or unmutes the local microphone.
2763 * @ingroup media_parameters
2765 void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){
2766 if (lc->audiostream!=NULL){
2767 audio_stream_set_mic_gain(lc->audiostream,
2768 (val==TRUE) ? 0 : 1.0);
2772 void linphone_core_enable_agc(LinphoneCore *lc, bool_t val){
2773 lc->sound_conf.agc=val;
2776 bool_t linphone_core_agc_enabled(const LinphoneCore *lc){
2777 return lc->sound_conf.agc;
2781 * Send the specified dtmf.
2783 * @ingroup media_parameters
2784 * This function only works during calls. The dtmf is automatically played to the user.
2785 * @param lc The LinphoneCore object
2786 * @param dtmf The dtmf name specified as a char, such as '0', '#' etc...
2789 void linphone_core_send_dtmf(LinphoneCore *lc,char dtmf)
2791 /*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
2792 if (linphone_core_get_use_rfc2833_for_dtmf(lc)!=0 || linphone_core_get_use_info_for_dtmf(lc)==0)
2795 if (lc->audiostream!=NULL){
2796 audio_stream_send_dtmf(lc->audiostream,dtmf);
2800 ms_error("we cannot send RFC2833 dtmf when we are not in communication");
2803 if (linphone_core_get_use_info_for_dtmf(lc)!=0)
2805 char dtmf_body[1000];
2807 osip_message_t *msg=NULL;
2808 /* Out of Band DTMF (use INFO method) */
2809 LinphoneCall *call=lc->call;
2813 eXosip_call_build_info(call->did,&msg);
2814 snprintf(dtmf_body, 999, "Signal=%c\r\nDuration=250\r\n", dtmf);
2815 osip_message_set_body(msg,dtmf_body,strlen(dtmf_body));
2816 osip_message_set_content_type(msg,"application/dtmf-relay");
2817 snprintf(clen,sizeof(clen),"%lu",(unsigned long)strlen(dtmf_body));
2818 osip_message_set_content_length(msg,clen);
2821 eXosip_call_send_request(call->did,msg);
2826 void linphone_core_set_stun_server(LinphoneCore *lc, const char *server){
2827 if (lc->net_conf.stun_server!=NULL)
2828 ms_free(lc->net_conf.stun_server);
2830 lc->net_conf.stun_server=ms_strdup(server);
2831 else lc->net_conf.stun_server=NULL;
2832 lc->apply_nat_settings=TRUE;
2835 const char * linphone_core_get_stun_server(const LinphoneCore *lc){
2836 return lc->net_conf.stun_server;
2839 const char * linphone_core_get_relay_addr(const LinphoneCore *lc){
2840 return lc->net_conf.relay;
2843 int linphone_core_set_relay_addr(LinphoneCore *lc, const char *addr){
2844 if (lc->net_conf.relay!=NULL){
2845 ms_free(lc->net_conf.relay);
2846 lc->net_conf.relay=NULL;
2849 lc->net_conf.relay=ms_strdup(addr);
2854 static void apply_nat_settings(LinphoneCore *lc){
2858 struct addrinfo hints,*res;
2859 const char *addr=lc->net_conf.nat_address;
2861 if (lc->net_conf.firewall_policy==LINPHONE_POLICY_USE_NAT_ADDRESS){
2862 if (addr==NULL || strlen(addr)==0){
2863 lc->vtable.display_warning(lc,_("No nat/firewall address supplied !"));
2864 linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_NO_FIREWALL);
2866 /*check the ip address given */
2867 memset(&hints,0,sizeof(struct addrinfo));
2868 if (lc->sip_conf.ipv6_enabled)
2869 hints.ai_family=AF_INET6;
2871 hints.ai_family=AF_INET;
2872 hints.ai_socktype = SOCK_DGRAM;
2873 err=getaddrinfo(addr,NULL,&hints,&res);
2875 wmsg=ortp_strdup_printf(_("Invalid nat address '%s' : %s"),
2876 addr, gai_strerror(err));
2877 ms_warning(wmsg); // what is this for ?
2878 lc->vtable.display_warning(lc, wmsg);
2880 linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_NO_FIREWALL);
2883 /*now get it as an numeric ip address */
2885 err=getnameinfo(res->ai_addr,res->ai_addrlen,tmp,50,NULL,0,NI_NUMERICHOST);
2887 wmsg=ortp_strdup_printf(_("Invalid nat address '%s' : %s"),
2888 addr, gai_strerror(err));
2889 ms_warning(wmsg); // what is this for ?
2890 lc->vtable.display_warning(lc, wmsg);
2894 linphone_core_set_firewall_policy(lc,LINPHONE_POLICY_NO_FIREWALL);
2900 if (lc->net_conf.firewall_policy==LINPHONE_POLICY_USE_NAT_ADDRESS){
2902 if (!lc->net_conf.nat_sdp_only){
2903 eXosip_set_option(EXOSIP_OPT_SET_IPV4_FOR_GATEWAY,tmp);
2904 /* the following does not work in all cases */
2906 eXosip_masquerade_contact(tmp,lc->sip_conf.sip_port);
2912 eXosip_set_option(EXOSIP_OPT_SET_IPV4_FOR_GATEWAY,NULL);
2913 eXosip_masquerade_contact("",0);
2917 eXosip_set_option(EXOSIP_OPT_SET_IPV4_FOR_GATEWAY,NULL);
2918 eXosip_masquerade_contact("",0);
2923 void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
2925 if (lc->net_conf.nat_address!=NULL){
2926 ms_free(lc->net_conf.nat_address);
2928 if (addr!=NULL) lc->net_conf.nat_address=ms_strdup(addr);
2929 else lc->net_conf.nat_address=NULL;
2930 lc->apply_nat_settings=TRUE;
2933 const char *linphone_core_get_nat_address(const LinphoneCore *lc)
2935 return lc->net_conf.nat_address;
2938 void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
2939 lc->net_conf.firewall_policy=pol;
2940 lc->apply_nat_settings=TRUE;
2943 LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
2944 return lc->net_conf.firewall_policy;
2948 * Get the list of call logs (past calls).
2950 * @ingroup call_logs
2952 const MSList * linphone_core_get_call_logs(LinphoneCore *lc){
2954 return lc->call_logs;
2958 * Erase the call log.
2960 * @ingroup call_logs
2962 void linphone_core_clear_call_logs(LinphoneCore *lc){
2964 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
2965 lc->call_logs=ms_list_free(lc->call_logs);
2966 call_logs_write_to_config_file(lc);
2969 static void toggle_video_preview(LinphoneCore *lc, bool_t val){
2970 #ifdef VIDEO_ENABLED
2971 if (lc->videostream==NULL){
2973 if (lc->previewstream==NULL){
2974 lc->previewstream=video_preview_start(lc->video_conf.device,
2975 lc->video_conf.vsize);
2978 if (lc->previewstream!=NULL){
2979 video_preview_stop(lc->previewstream);
2980 lc->previewstream=NULL;
2988 * Enables video globally.
2990 * @ingroup media_parameters
2991 * This function does not have any effect during calls. It just indicates LinphoneCore to
2992 * initiate future calls with video or not. The two boolean parameters indicate in which
2993 * direction video is enabled. Setting both to false disables video entirely.
2995 * @param vcap_enabled indicates whether video capture is enabled
2996 * @param display_enabled indicates whether video display should be shown
2999 void linphone_core_enable_video(LinphoneCore *lc, bool_t vcap_enabled, bool_t display_enabled){
3000 #ifndef VIDEO_ENABLED
3001 if (vcap_enabled || display_enabled)
3002 ms_warning("This version of linphone was built without video support.");
3004 lc->video_conf.capture=vcap_enabled;
3005 lc->video_conf.display=display_enabled;
3007 /* need to re-apply network bandwidth settings*/
3008 linphone_core_set_download_bandwidth(lc,
3009 linphone_core_get_download_bandwidth(lc));
3010 linphone_core_set_upload_bandwidth(lc,
3011 linphone_core_get_upload_bandwidth(lc));
3015 * Returns TRUE if video is enabled, FALSE otherwise.
3016 * @ingroup media_parameters
3018 bool_t linphone_core_video_enabled(LinphoneCore *lc){
3019 return (lc->video_conf.display || lc->video_conf.capture);
3023 * Controls video preview enablement.
3025 * @ingroup media_parameters
3026 * Video preview refers to the action of displaying the local webcam image
3027 * to the user while not in call.
3029 void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val){
3030 lc->video_conf.show_local=val;
3034 * Returns TRUE if video previewing is enabled.
3035 * @ingroup media_parameters
3037 bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
3038 return lc->video_conf.show_local;
3042 * Enables or disable self view during calls.
3044 * @ingroup media_parameters
3045 * Self-view refers to having local webcam image inserted in corner
3046 * of the video window during calls.
3047 * This function works at any time, including during calls.
3049 void linphone_core_enable_self_view(LinphoneCore *lc, bool_t val){
3050 lc->video_conf.selfview=val;
3051 #ifdef VIDEO_ENABLED
3052 if (lc->videostream){
3053 video_stream_enable_self_view(lc->videostream,val);
3059 * Returns TRUE if self-view is enabled, FALSE otherwise.
3061 * @ingroup media_parameters
3063 * Refer to linphone_core_enable_self_view() for details.
3065 bool_t linphone_core_self_view_enabled(const LinphoneCore *lc){
3066 return lc->video_conf.selfview;
3070 * Sets the active video device.
3072 * @ingroup media_parameters
3073 * @param id the name of the video device as returned by linphone_core_get_video_devices()
3075 int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
3076 MSWebCam *olddev=lc->video_conf.device;
3079 lc->video_conf.device=ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),id);
3080 if (lc->video_conf.device==NULL){
3081 ms_warning("Could not found video device %s",id);
3084 if (lc->video_conf.device==NULL)
3085 lc->video_conf.device=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());
3086 if (olddev!=NULL && olddev!=lc->video_conf.device){
3087 toggle_video_preview(lc,FALSE);/*restart the video local preview*/
3089 if (lc->ready && lc->video_conf.device){
3090 vd=ms_web_cam_get_string_id(lc->video_conf.device);
3091 if (vd && strstr(vd,"Static picture")!=NULL){
3094 lp_config_set_string(lc->config,"video","device",vd);
3100 * Returns the name of the currently active video device.
3102 * @ingroup media_parameters
3104 const char *linphone_core_get_video_device(const LinphoneCore *lc){
3105 if (lc->video_conf.device) return ms_web_cam_get_string_id(lc->video_conf.device);
3110 * Returns the native window handle of the video window, casted as an unsigned long.
3112 * @ingroup media_parameters
3114 unsigned long linphone_core_get_native_video_window_id(const LinphoneCore *lc){
3115 #ifdef VIDEO_ENABLED
3116 if (lc->videostream)
3117 return video_stream_get_native_window_id(lc->videostream);
3118 if (lc->previewstream)
3119 return video_stream_get_native_window_id(lc->previewstream);
3124 static MSVideoSizeDef supported_resolutions[]={
3125 { {MS_VIDEO_SIZE_SVGA_W,MS_VIDEO_SIZE_SVGA_H} , "svga" },
3126 { {MS_VIDEO_SIZE_4CIF_W,MS_VIDEO_SIZE_4CIF_H} , "4cif" },
3127 { {MS_VIDEO_SIZE_VGA_W,MS_VIDEO_SIZE_VGA_H} , "vga" },
3128 { {MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H} , "cif" },
3129 { {MS_VIDEO_SIZE_QVGA_W,MS_VIDEO_SIZE_QVGA_H} , "qvga" },
3130 { {MS_VIDEO_SIZE_QCIF_W,MS_VIDEO_SIZE_QCIF_H} , "qcif" },
3135 * Returns the zero terminated table of supported video resolutions.
3137 * @ingroup media_parameters
3139 const MSVideoSizeDef *linphone_core_get_supported_video_sizes(LinphoneCore *lc){
3140 return supported_resolutions;
3143 static MSVideoSize video_size_get_by_name(const char *name){
3144 MSVideoSizeDef *pdef=supported_resolutions;
3145 MSVideoSize null_vsize={0,0};
3146 for(;pdef->name!=NULL;pdef++){
3147 if (strcasecmp(name,pdef->name)==0){
3151 ms_warning("Video resolution %s is not supported in linphone.",name);
3155 static const char *video_size_get_name(MSVideoSize vsize){
3156 MSVideoSizeDef *pdef=supported_resolutions;
3157 for(;pdef->name!=NULL;pdef++){
3158 if (pdef->vsize.width==vsize.width && pdef->vsize.height==vsize.height){
3165 static bool_t video_size_supported(MSVideoSize vsize){
3166 if (video_size_get_name(vsize)) return TRUE;
3167 ms_warning("Video resolution %ix%i is not supported in linphone.",vsize.width,vsize.height);
3172 * Sets the preferred video size.
3174 * @ingroup media_parameters
3175 * This applies only to the stream that is captured and sent to the remote party,
3176 * since we accept all standard video size on the receive path.
3178 void linphone_core_set_preferred_video_size(LinphoneCore *lc, MSVideoSize vsize){
3179 if (video_size_supported(vsize)){
3180 MSVideoSize oldvsize=lc->video_conf.vsize;
3181 lc->video_conf.vsize=vsize;
3182 if (!ms_video_size_equal(oldvsize,vsize) && lc->previewstream!=NULL){
3183 toggle_video_preview(lc,FALSE);
3184 toggle_video_preview(lc,TRUE);
3187 lp_config_set_string(lc->config,"video","size",video_size_get_name(vsize));
3192 * Sets the preferred video size by its name.
3194 * @ingroup media_parameters
3195 * This is identical to linphone_core_set_preferred_video_size() except
3196 * that it takes the name of the video resolution as input.
3197 * Video resolution names are: qcif, svga, cif, vga, 4cif, svga ...
3199 void linphone_core_set_preferred_video_size_by_name(LinphoneCore *lc, const char *name){
3200 MSVideoSize vsize=video_size_get_by_name(name);
3201 MSVideoSize default_vsize={MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H};
3202 if (vsize.width!=0) linphone_core_set_preferred_video_size(lc,vsize);
3203 else linphone_core_set_preferred_video_size(lc,default_vsize);
3207 * Returns the current preferred video size for sending.
3209 * @ingroup media_parameters
3211 MSVideoSize linphone_core_get_preferred_video_size(LinphoneCore *lc){
3212 return lc->video_conf.vsize;
3215 void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
3216 lc->use_files=yesno;
3219 void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
3220 if (lc->play_file!=NULL){
3221 ms_free(lc->play_file);
3225 lc->play_file=ms_strdup(file);
3226 if (lc->audiostream)
3227 audio_stream_play(lc->audiostream,file);
3231 void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
3232 if (lc->rec_file!=NULL){
3233 ms_free(lc->rec_file);
3237 lc->rec_file=ms_strdup(file);
3238 if (lc->audiostream)
3239 audio_stream_record(lc->audiostream,file);
3244 * Retrieves the user pointer that was given to linphone_core_new()
3246 * @ingroup initializing
3248 void *linphone_core_get_user_data(LinphoneCore *lc){
3252 int linphone_core_get_mtu(const LinphoneCore *lc){
3253 return lc->net_conf.mtu;
3256 void linphone_core_set_mtu(LinphoneCore *lc, int mtu){
3257 lc->net_conf.mtu=mtu;
3260 ms_error("MTU too small !");
3264 ms_message("MTU is supposed to be %i, rtp payload max size will be %i",mtu, ms_get_payload_max_size());
3265 }else ms_set_mtu(0);//use mediastreamer2 default value
3268 void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context){
3270 lc->wait_ctx=user_context;
3273 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose){
3275 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingStart,purpose,0);
3279 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progress){
3281 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingProgress,purpose,progress);
3291 void linphone_core_stop_waiting(LinphoneCore *lc){
3293 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingFinished,NULL,0);
3297 void linphone_core_set_audio_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3302 void net_config_uninit(LinphoneCore *lc)
3304 net_config_t *config=&lc->net_conf;
3305 lp_config_set_int(lc->config,"net","download_bw",config->download_bw);
3306 lp_config_set_int(lc->config,"net","upload_bw",config->upload_bw);
3308 if (config->stun_server!=NULL)
3309 lp_config_set_string(lc->config,"net","stun_server",config->stun_server);
3310 if (config->nat_address!=NULL)
3311 lp_config_set_string(lc->config,"net","nat_address",config->nat_address);
3312 lp_config_set_int(lc->config,"net","firewall_policy",config->firewall_policy);
3313 lp_config_set_int(lc->config,"net","mtu",config->mtu);
3314 if (lc->net_conf.stun_server!=NULL)
3315 ms_free(lc->net_conf.stun_server);
3319 void sip_config_uninit(LinphoneCore *lc)
3323 sip_config_t *config=&lc->sip_conf;
3324 lp_config_set_int(lc->config,"sip","sip_port",config->sip_port);
3325 lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
3326 lp_config_set_string(lc->config,"sip","contact",config->contact);
3327 lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
3328 lp_config_set_int(lc->config,"sip","use_info",config->use_info);
3329 lp_config_set_int(lc->config,"sip","use_rfc2833",config->use_rfc2833);
3330 lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
3331 lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
3332 for(elem=config->proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3333 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
3334 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
3335 linphone_proxy_config_edit(cfg); /* to unregister */
3344 while((ev=eXosip_event_wait(0,0))!=NULL){
3345 linphone_core_process_event(lc,ev);
3347 eXosip_automatic_action();
3356 linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */
3358 for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3359 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
3360 linphone_auth_info_write_config(lc->config,ai,i);
3362 linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
3365 void rtp_config_uninit(LinphoneCore *lc)
3367 rtp_config_t *config=&lc->rtp_conf;
3368 lp_config_set_int(lc->config,"rtp","audio_rtp_port",config->audio_rtp_port);
3369 lp_config_set_int(lc->config,"rtp","video_rtp_port",config->video_rtp_port);
3370 lp_config_set_int(lc->config,"rtp","audio_jitt_comp",config->audio_jitt_comp);
3371 lp_config_set_int(lc->config,"rtp","video_jitt_comp",config->video_jitt_comp);
3372 lp_config_set_int(lc->config,"rtp","nortp_timeout",config->nortp_timeout);
3375 void sound_config_uninit(LinphoneCore *lc)
3377 sound_config_t *config=&lc->sound_conf;
3378 ms_free(config->cards);
3380 lp_config_set_string(lc->config,"sound","remote_ring",config->remote_ring);
3382 if (config->local_ring) ms_free(config->local_ring);
3383 if (config->remote_ring) ms_free(config->remote_ring);
3384 ms_snd_card_manager_destroy();
3387 void video_config_uninit(LinphoneCore *lc)
3389 lp_config_set_int(lc->config,"video","enabled",linphone_core_video_enabled(lc));
3390 lp_config_set_string(lc->config,"video","size",video_size_get_name(linphone_core_get_preferred_video_size(lc)));
3391 lp_config_set_int(lc->config,"video","display",lc->video_conf.display);
3392 lp_config_set_int(lc->config,"video","capture",lc->video_conf.capture);
3393 lp_config_set_int(lc->config,"video","show_local",linphone_core_video_preview_enabled(lc));
3394 lp_config_set_int(lc->config,"video","self_view",linphone_core_self_view_enabled(lc));
3397 void codecs_config_uninit(LinphoneCore *lc)
3400 codecs_config_t *config=&lc->codecs_conf;
3405 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
3406 pt=(PayloadType*)(node->data);
3407 sprintf(key,"audio_codec_%i",index);
3408 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3409 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3410 lp_config_set_int(lc->config,key,"enabled",payload_type_enabled(pt));
3414 for(node=config->video_codecs;node!=NULL;node=ms_list_next(node)){
3415 pt=(PayloadType*)(node->data);
3416 sprintf(key,"video_codec_%i",index);
3417 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3418 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3419 lp_config_set_int(lc->config,key,"enabled",payload_type_enabled(pt));
3420 lp_config_set_string(lc->config,key,"recv_fmtp",pt->recv_fmtp);
3423 if (lc->local_profile){
3424 rtp_profile_destroy(lc->local_profile);
3425 lc->local_profile=NULL;
3429 void ui_config_uninit(LinphoneCore* lc)
3432 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_destroy);
3433 ms_list_free(lc->friends);
3439 * Returns the LpConfig object used to manage the storage (config) file.
3442 * The application can use the LpConfig object to insert its own private
3443 * sections and pairs of key=value in the configuration file.
3446 LpConfig *linphone_core_get_config(LinphoneCore *lc){
3450 static void linphone_core_uninit(LinphoneCore *lc)
3454 linphone_core_terminate_call(lc,NULL);
3461 linphone_core_iterate(lc);
3464 gstate_new_state(lc, GSTATE_POWER_SHUTDOWN, NULL);
3465 #ifdef VIDEO_ENABLED
3466 if (lc->previewstream!=NULL){
3467 video_preview_stop(lc->previewstream);
3468 lc->previewstream=NULL;
3471 /* save all config */
3472 net_config_uninit(lc);
3473 sip_config_uninit(lc);
3474 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
3475 rtp_config_uninit(lc);
3476 sound_config_uninit(lc);
3477 video_config_uninit(lc);
3478 codecs_config_uninit(lc);
3479 ui_config_uninit(lc);
3480 if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
3481 lp_config_destroy(lc->config);
3482 lc->config = NULL; /* Mark the config as NULL to block further calls */
3483 sip_setup_unregister_all();
3485 linphone_core_free_payload_types();
3489 exosip_running=FALSE;
3490 gstate_new_state(lc, GSTATE_POWER_OFF, NULL);
3493 void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) {
3494 //first disable automatic mode
3495 if (lc->auto_net_state_mon) {
3496 ms_message("Disabling automatic network state monitoring");
3497 lc->auto_net_state_mon=FALSE;
3499 ms_message("Network state is now [%s]",isReachable?"UP":"DOWN");
3500 // second get the list of available proxies
3501 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3502 for(;elem!=NULL;elem=elem->next){
3503 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3504 if (linphone_proxy_config_register_enabled(cfg) ) {
3509 linphone_proxy_config_update(cfg);
3517 * Destroys a LinphoneCore
3519 * @ingroup initializing
3521 void linphone_core_destroy(LinphoneCore *lc){
3522 linphone_core_uninit(lc);