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"
28 #include <ortp/telephonyevents.h>
37 /*#define UNSTANDART_GSM_11K 1*/
39 static const char *liblinphone_version=LIBLINPHONE_VERSION;
40 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable);
44 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result);
45 static void toggle_video_preview(LinphoneCore *lc, bool_t val);
47 /* relative path where is stored local ring*/
48 #define LOCAL_RING "rings/oldphone.wav"
49 /* same for remote ring (ringback)*/
50 #define REMOTE_RING "ringback.wav"
52 extern SalCallbacks linphone_sal_callbacks;
54 void lc_callback_obj_init(LCCallbackObj *obj,LinphoneCoreCbFunc func,void* ud)
60 int lc_callback_obj_invoke(LCCallbackObj *obj, LinphoneCore *lc){
61 if (obj->_func!=NULL) obj->_func(lc,obj->_user_data);
65 /*prevent a gcc bug with %c*/
66 static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm){
67 #if !defined(_WIN32_WCE)
68 return strftime(s, max, fmt, tm);
75 static void set_call_log_date(LinphoneCallLog *cl, const struct tm *loctime){
76 my_strftime(cl->start_date,sizeof(cl->start_date),"%c",loctime);
79 LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
80 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
84 #if !defined(_WIN32_WCE)
85 loctime=*localtime(&call->start_time);
89 localtime_r(&call->start_time,&loctime);
91 set_call_log_date(cl,&loctime);
97 static void call_logs_write_to_config_file(LinphoneCore *lc){
102 LpConfig *cfg=lc->config;
104 if (!lc->ready) return;
106 for(i=0,elem=lc->call_logs;elem!=NULL;elem=elem->next,++i){
107 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
108 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
109 lp_config_set_int(cfg,logsection,"dir",cl->dir);
110 lp_config_set_int(cfg,logsection,"status",cl->status);
111 tmp=linphone_address_as_string(cl->from);
112 lp_config_set_string(cfg,logsection,"from",tmp);
114 tmp=linphone_address_as_string(cl->to);
115 lp_config_set_string(cfg,logsection,"to",tmp);
117 lp_config_set_string(cfg,logsection,"start_date",cl->start_date);
118 lp_config_set_int(cfg,logsection,"duration",cl->duration);
119 if (cl->refkey) lp_config_set_string(cfg,logsection,"refkey",cl->refkey);
121 for(;i<lc->max_call_logs;++i){
122 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
123 lp_config_clean_section(cfg,logsection);
127 static void call_logs_read_from_config_file(LinphoneCore *lc){
131 LpConfig *cfg=lc->config;
133 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
134 if (lp_config_has_section(cfg,logsection)){
135 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
136 cl->dir=lp_config_get_int(cfg,logsection,"dir",0);
137 cl->status=lp_config_get_int(cfg,logsection,"status",0);
138 tmp=lp_config_get_string(cfg,logsection,"from",NULL);
139 if (tmp) cl->from=linphone_address_new(tmp);
140 tmp=lp_config_get_string(cfg,logsection,"to",NULL);
141 if (tmp) cl->to=linphone_address_new(tmp);
142 tmp=lp_config_get_string(cfg,logsection,"start_date",NULL);
143 if (tmp) strncpy(cl->start_date,tmp,sizeof(cl->start_date));
144 cl->duration=lp_config_get_int(cfg,logsection,"duration",0);
145 tmp=lp_config_get_string(cfg,logsection,"refkey",NULL);
146 if (tmp) cl->refkey=ms_strdup(tmp);
147 lc->call_logs=ms_list_append(lc->call_logs,cl);
153 void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call, LinphoneCallStatus status){
154 LinphoneCore *lc=call->core;
156 calllog->duration=time(NULL)-call->start_time;
158 if (status==LinphoneCallMissed){
161 info=ortp_strdup_printf(ngettext("You have missed %i call.",
162 "You have missed %i calls.", lc->missed_calls),
164 lc->vtable.display_status(lc,info);
166 }else calllog->status=status;
167 lc->call_logs=ms_list_prepend(lc->call_logs,(void *)calllog);
168 if (ms_list_size(lc->call_logs)>lc->max_call_logs){
169 MSList *elem,*prevelem=NULL;
170 /*find the last element*/
171 for(elem=lc->call_logs;elem!=NULL;elem=elem->next){
175 linphone_call_log_destroy((LinphoneCallLog*)elem->data);
176 lc->call_logs=ms_list_remove_link(lc->call_logs,elem);
178 if (lc->vtable.call_log_updated!=NULL){
179 lc->vtable.call_log_updated(lc,calllog);
181 call_logs_write_to_config_file(lc);
185 * @addtogroup call_logs
190 * Returns a human readable string describing the call.
192 * @note: the returned char* must be freed by the application (use ms_free()).
194 char * linphone_call_log_to_str(LinphoneCallLog *cl){
197 char *from=linphone_address_as_string (cl->from);
198 char *to=linphone_address_as_string (cl->to);
200 case LinphoneCallAborted:
203 case LinphoneCallSuccess:
204 status=_("completed");
206 case LinphoneCallMissed:
212 tmp=ortp_strdup_printf(_("%s at %s\nFrom: %s\nTo: %s\nStatus: %s\nDuration: %i mn %i sec\n"),
213 (cl->dir==LinphoneCallIncoming) ? _("Incoming call") : _("Outgoing call"),
225 void linphone_call_log_set_user_pointer(LinphoneCallLog *cl, void *up){
229 void *linphone_call_log_get_user_pointer(const LinphoneCallLog *cl){
230 return cl->user_pointer;
236 * Associate a persistent reference key to the call log.
238 * The reference key can be for example an id to an external database.
239 * It is stored in the config file, thus can survive to process exits/restarts.
242 void linphone_call_log_set_ref_key(LinphoneCallLog *cl, const char *refkey){
243 if (cl->refkey!=NULL){
247 if (refkey) cl->refkey=ms_strdup(refkey);
248 call_logs_write_to_config_file(cl->lc);
252 * Get the persistent reference key associated to the call log.
254 * The reference key can be for example an id to an external database.
255 * It is stored in the config file, thus can survive to process exits/restarts.
258 const char *linphone_call_log_get_ref_key(const LinphoneCallLog *cl){
264 void linphone_call_log_destroy(LinphoneCallLog *cl){
265 if (cl->from!=NULL) linphone_address_destroy(cl->from);
266 if (cl->to!=NULL) linphone_address_destroy(cl->to);
267 if (cl->refkey!=NULL) ms_free(cl->refkey);
272 * Returns TRUE if the LinphoneCall asked to autoanswer
275 bool_t linphone_call_asked_to_autoanswer(LinphoneCall *call){
276 //return TRUE if the unique(for the moment) incoming call asked to be autoanswered
278 return sal_call_autoanswer_asked(call->op);
283 int linphone_core_get_call_duration(LinphoneCall *call){
284 if (call==NULL) return 0;
285 if (call->media_start_time==0) return 0;
286 return time(NULL)-call->media_start_time;
289 int linphone_core_get_current_call_duration(const LinphoneCore *lc){
290 LinphoneCall *call=linphone_core_get_current_call((LinphoneCore *)lc);
291 return linphone_core_get_call_duration(call);
294 const LinphoneAddress *linphone_core_get_current_call_remote_address(struct _LinphoneCore *lc){
295 LinphoneCall *call=linphone_core_get_current_call(lc);
296 if (call==NULL) return 0;
297 return linphone_call_get_remote_address(call);
301 * Enable logs in supplied FILE*.
305 * @param file a C FILE* where to fprintf logs. If null stdout is used.
308 void linphone_core_enable_logs(FILE *file){
309 if (file==NULL) file=stdout;
310 ortp_set_log_file(file);
311 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
315 * Enable logs through the user's supplied log callback.
319 * @param logfunc The address of a OrtpLogFunc callback whose protoype is
320 * typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
323 void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc){
324 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
325 ortp_set_log_handler(logfunc);
329 * Entirely disable logging.
333 void linphone_core_disable_logs(){
334 ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
339 net_config_read (LinphoneCore *lc)
343 LpConfig *config=lc->config;
345 tmp=lp_config_get_int(config,"net","download_bw",0);
346 linphone_core_set_download_bandwidth(lc,tmp);
347 tmp=lp_config_get_int(config,"net","upload_bw",0);
348 linphone_core_set_upload_bandwidth(lc,tmp);
349 linphone_core_set_stun_server(lc,lp_config_get_string(config,"net","stun_server",NULL));
350 tmpstr=lp_config_get_string(lc->config,"net","nat_address",NULL);
351 if (tmpstr!=NULL && (strlen(tmpstr)<1)) tmpstr=NULL;
352 linphone_core_set_nat_address(lc,tmpstr);
353 tmp=lp_config_get_int(lc->config,"net","firewall_policy",0);
354 linphone_core_set_firewall_policy(lc,tmp);
355 tmp=lp_config_get_int(lc->config,"net","nat_sdp_only",0);
356 lc->net_conf.nat_sdp_only=tmp;
357 tmp=lp_config_get_int(lc->config,"net","mtu",0);
358 linphone_core_set_mtu(lc,tmp);
359 tmp=lp_config_get_int(lc->config,"net","download_ptime",0);
360 linphone_core_set_download_ptime(lc,tmp);
364 static void build_sound_devices_table(LinphoneCore *lc){
365 const char **devices;
369 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
370 ndev=ms_list_size(elem);
371 devices=ms_malloc((ndev+1)*sizeof(const char *));
372 for (i=0;elem!=NULL;elem=elem->next,i++){
373 devices[i]=ms_snd_card_get_string_id((MSSndCard *)elem->data);
376 old=lc->sound_conf.cards;
377 lc->sound_conf.cards=devices;
378 if (old!=NULL) ms_free(old);
381 static void sound_config_read(LinphoneCore *lc)
388 /*alsadev let the user use custom alsa device within linphone*/
389 devid=lp_config_get_string(lc->config,"sound","alsadev",NULL);
391 MSSndCard *card=ms_alsa_card_new_custom(devid,devid);
392 ms_snd_card_manager_add_card(ms_snd_card_manager_get(),card);
395 /* retrieve all sound devices */
396 build_sound_devices_table(lc);
398 devid=lp_config_get_string(lc->config,"sound","playback_dev_id",NULL);
399 linphone_core_set_playback_device(lc,devid);
401 devid=lp_config_get_string(lc->config,"sound","ringer_dev_id",NULL);
402 linphone_core_set_ringer_device(lc,devid);
404 devid=lp_config_get_string(lc->config,"sound","capture_dev_id",NULL);
405 linphone_core_set_capture_device(lc,devid);
408 tmp=lp_config_get_int(lc->config,"sound","play_lev",80);
409 linphone_core_set_play_level(lc,tmp);
410 tmp=lp_config_get_int(lc->config,"sound","ring_lev",80);
411 linphone_core_set_ring_level(lc,tmp);
412 tmp=lp_config_get_int(lc->config,"sound","rec_lev",80);
413 linphone_core_set_rec_level(lc,tmp);
414 tmpbuf=lp_config_get_string(lc->config,"sound","source","m");
415 linphone_core_set_sound_source(lc,tmpbuf[0]);
418 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
419 tmpbuf=lp_config_get_string(lc->config,"sound","local_ring",tmpbuf);
420 if (ortp_file_exist(tmpbuf)==-1) {
421 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
423 if (strstr(tmpbuf,".wav")==NULL){
424 /* it currently uses old sound files, so replace them */
425 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
428 linphone_core_set_ring(lc,tmpbuf);
430 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
431 tmpbuf=lp_config_get_string(lc->config,"sound","remote_ring",tmpbuf);
432 if (ortp_file_exist(tmpbuf)==-1){
433 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
435 if (strstr(tmpbuf,".wav")==NULL){
436 /* it currently uses old sound files, so replace them */
437 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
439 linphone_core_set_ringback(lc,tmpbuf);
440 check_sound_device(lc);
441 lc->sound_conf.latency=0;
443 linphone_core_enable_echo_cancellation(lc,
444 lp_config_get_int(lc->config,"sound","echocancelation",0) |
445 lp_config_get_int(lc->config,"sound","echocancellation",0)
448 linphone_core_enable_echo_limiter(lc,
449 lp_config_get_int(lc->config,"sound","echolimiter",0));
450 linphone_core_enable_agc(lc,
451 lp_config_get_int(lc->config,"sound","agc",0));
453 gain=lp_config_get_float(lc->config,"sound","soft_play_lev",0);
454 linphone_core_set_soft_play_level(lc,gain);
457 static void sip_config_read(LinphoneCore *lc)
464 port=lp_config_get_int(lc->config,"sip","use_info",0);
465 linphone_core_set_use_info_for_dtmf(lc,port);
467 port=lp_config_get_int(lc->config,"sip","use_rfc2833",0);
468 linphone_core_set_use_rfc2833_for_dtmf(lc,port);
470 ipv6=lp_config_get_int(lc->config,"sip","use_ipv6",-1);
473 if (host_has_ipv6_network()){
474 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"));
477 linphone_core_enable_ipv6(lc,ipv6);
478 port=lp_config_get_int(lc->config,"sip","sip_port",5060);
479 linphone_core_set_sip_port(lc,port);
481 tmpstr=lp_config_get_string(lc->config,"sip","contact",NULL);
482 if (tmpstr==NULL || linphone_core_set_primary_contact(lc,tmpstr)==-1) {
483 const char *hostname=NULL;
484 const char *username=NULL;
486 hostname=getenv("HOST");
487 username=getenv("USER");
488 if (hostname==NULL) hostname=getenv("HOSTNAME");
489 #endif /*HAVE_GETENV*/
491 hostname="unknown-host";
495 contact=ortp_strdup_printf("sip:%s@%s",username,hostname);
496 linphone_core_set_primary_contact(lc,contact);
500 tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
501 linphone_core_set_guess_hostname(lc,tmp);
504 tmp=lp_config_get_int(lc->config,"sip","inc_timeout",15);
505 linphone_core_set_inc_timeout(lc,tmp);
507 /* get proxies config */
509 LinphoneProxyConfig *cfg=linphone_proxy_config_new_from_config_file(lc->config,i);
511 linphone_core_add_proxy_config(lc,cfg);
516 /* get the default proxy */
517 tmp=lp_config_get_int(lc->config,"sip","default_proxy",-1);
518 linphone_core_set_default_proxy_index(lc,tmp);
520 /* read authentication information */
522 LinphoneAuthInfo *ai=linphone_auth_info_new_from_config_file(lc->config,i);
524 linphone_core_add_auth_info(lc,ai);
525 linphone_auth_info_destroy(ai);
531 /*for tuning or test*/
532 lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
533 lc->sip_conf.only_one_codec=lp_config_get_int(lc->config,"sip","only_one_codec",0);
534 lc->sip_conf.register_only_when_network_is_up=
535 lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",1);
536 lc->sip_conf.ping_with_options=lp_config_get_int(lc->config,"sip","ping_with_options",1);
537 lc->sip_conf.auto_net_state_mon=lp_config_get_int(lc->config,"sip","auto_net_state_mon",1);
540 static void rtp_config_read(LinphoneCore *lc)
545 port=lp_config_get_int(lc->config,"rtp","audio_rtp_port",7078);
546 linphone_core_set_audio_port(lc,port);
548 port=lp_config_get_int(lc->config,"rtp","video_rtp_port",9078);
549 if (port==0) port=9078;
550 linphone_core_set_video_port(lc,port);
552 jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
553 linphone_core_set_audio_jittcomp(lc,jitt_comp);
554 jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
555 nortp_timeout=lp_config_get_int(lc->config,"rtp","nortp_timeout",30);
556 linphone_core_set_nortp_timeout(lc,nortp_timeout);
559 static PayloadType * find_payload(RtpProfile *prof, const char *mime_type, int clock_rate, const char *recv_fmtp){
560 PayloadType *candidate=NULL;
564 it=rtp_profile_get_payload(prof,i);
565 if (it!=NULL && strcasecmp(mime_type,it->mime_type)==0
566 && (clock_rate==it->clock_rate || clock_rate<=0) ){
567 if ( (recv_fmtp && it->recv_fmtp && strstr(recv_fmtp,it->recv_fmtp)!=NULL) ||
568 (recv_fmtp==NULL && it->recv_fmtp==NULL) ){
570 if (recv_fmtp) payload_type_set_recv_fmtp(it,recv_fmtp);
574 if (it->recv_fmtp==NULL) candidate=it;
579 if (candidate && recv_fmtp){
580 payload_type_set_recv_fmtp(candidate,recv_fmtp);
585 static bool_t get_codec(LpConfig *config, char* type, int index, PayloadType **ret){
587 const char *mime,*fmtp;
592 snprintf(codeckey,50,"%s_%i",type,index);
593 mime=lp_config_get_string(config,codeckey,"mime",NULL);
594 if (mime==NULL || strlen(mime)==0 ) return FALSE;
596 rate=lp_config_get_int(config,codeckey,"rate",8000);
597 fmtp=lp_config_get_string(config,codeckey,"recv_fmtp",NULL);
598 enabled=lp_config_get_int(config,codeckey,"enabled",1);
599 pt=find_payload(&av_profile,mime,rate,fmtp);
600 if (pt && enabled ) pt->flags|=PAYLOAD_TYPE_ENABLED;
601 //ms_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
602 if (pt==NULL) ms_warning("Ignoring codec config %s/%i with fmtp=%s because unsupported",
603 mime,rate,fmtp ? fmtp : "");
608 static const char *codec_pref_order[]={
621 static int find_codec_rank(const char *mime){
623 for(i=0;codec_pref_order[i]!=NULL;++i){
624 if (strcasecmp(codec_pref_order[i],mime)==0)
630 static int codec_compare(const PayloadType *a, const PayloadType *b){
632 ra=find_codec_rank(a->mime_type);
633 rb=find_codec_rank(b->mime_type);
635 if (ra<rb) return -1;
639 static MSList *add_missing_codecs(SalStreamType mtype, MSList *l){
642 PayloadType *pt=rtp_profile_get_payload(&av_profile,i);
644 if (mtype==SalVideo && pt->type!=PAYLOAD_VIDEO)
646 else if (mtype==SalAudio && (pt->type!=PAYLOAD_AUDIO_PACKETIZED
647 && pt->type!=PAYLOAD_AUDIO_CONTINUOUS)){
650 if (pt && ms_filter_codec_supported(pt->mime_type)){
651 if (ms_list_find(l,pt)==NULL){
652 payload_type_set_flag(pt,PAYLOAD_TYPE_ENABLED);
653 ms_message("Adding new codec %s/%i with fmtp %s",
654 pt->mime_type,pt->clock_rate,pt->recv_fmtp ? pt->recv_fmtp : "");
655 l=ms_list_insert_sorted(l,pt,(int (*)(const void *, const void *))codec_compare);
663 static void codecs_config_read(LinphoneCore *lc)
667 MSList *audio_codecs=NULL;
668 MSList *video_codecs=NULL;
669 for (i=0;get_codec(lc->config,"audio_codec",i,&pt);i++){
671 if (!ms_filter_codec_supported(pt->mime_type)){
672 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
673 }else audio_codecs=ms_list_append(audio_codecs,pt);
676 audio_codecs=add_missing_codecs(SalAudio,audio_codecs);
677 for (i=0;get_codec(lc->config,"video_codec",i,&pt);i++){
679 if (!ms_filter_codec_supported(pt->mime_type)){
680 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
681 }else video_codecs=ms_list_append(video_codecs,(void *)pt);
684 video_codecs=add_missing_codecs(SalVideo,video_codecs);
685 linphone_core_set_audio_codecs(lc,audio_codecs);
686 linphone_core_set_video_codecs(lc,video_codecs);
687 linphone_core_update_allocated_audio_bandwidth(lc);
690 static void video_config_read(LinphoneCore *lc){
691 int capture, display, self_view;
695 const char **devices;
699 /* retrieve all video devices */
700 elem=ms_web_cam_manager_get_list(ms_web_cam_manager_get());
701 ndev=ms_list_size(elem);
702 devices=ms_malloc((ndev+1)*sizeof(const char *));
703 for (i=0;elem!=NULL;elem=elem->next,i++){
704 devices[i]=ms_web_cam_get_string_id((MSWebCam *)elem->data);
707 lc->video_conf.cams=devices;
709 str=lp_config_get_string(lc->config,"video","device",NULL);
710 if (str && str[0]==0) str=NULL;
711 linphone_core_set_video_device(lc,str);
713 linphone_core_set_preferred_video_size_by_name(lc,
714 lp_config_get_string(lc->config,"video","size","cif"));
716 enabled=lp_config_get_int(lc->config,"video","enabled",1);
717 capture=lp_config_get_int(lc->config,"video","capture",enabled);
718 display=lp_config_get_int(lc->config,"video","display",enabled);
719 self_view=lp_config_get_int(lc->config,"video","self_view",enabled);
721 linphone_core_enable_video(lc,capture,display);
722 linphone_core_enable_self_view(lc,self_view);
726 static void ui_config_read(LinphoneCore *lc)
730 for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
731 linphone_core_add_friend(lc,lf);
733 call_logs_read_from_config_file(lc);
737 static void autoreplier_config_init(LinphoneCore *lc)
739 autoreplier_config_t *config=&lc->autoreplier_conf;
740 config->enabled=lp_config_get_int(lc->config,"autoreplier","enabled",0);
741 config->after_seconds=lp_config_get_int(lc->config,"autoreplier","after_seconds",6);
742 config->max_users=lp_config_get_int(lc->config,"autoreplier","max_users",1);
743 config->max_rec_time=lp_config_get_int(lc->config,"autoreplier","max_rec_time",60);
744 config->max_rec_msg=lp_config_get_int(lc->config,"autoreplier","max_rec_msg",10);
745 config->message=lp_config_get_string(lc->config,"autoreplier","message",NULL);
750 * Sets maximum available download bandwidth
752 * @ingroup media_parameters
754 * This is IP bandwidth, in kbit/s.
755 * This information is used signaled to other parties during
756 * calls (within SDP messages) so that the remote end can have
757 * sufficient knowledge to properly configure its audio & video
758 * codec output bitrate to not overflow available bandwidth.
760 * @param lc the LinphoneCore object
761 * @param bw the bandwidth in kbits/s, 0 for infinite
763 void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
764 lc->net_conf.download_bw=bw;
765 if (bw==0){ /*infinite*/
769 lc->dw_audio_bw=MIN(lc->audio_bw,bw);
770 lc->dw_video_bw=MAX(bw-lc->dw_audio_bw-10,0);/*-10: security margin*/
775 * Sets maximum available upload bandwidth
777 * @ingroup media_parameters
779 * This is IP bandwidth, in kbit/s.
780 * This information is used by liblinphone together with remote
781 * side available bandwidth signaled in SDP messages to properly
782 * configure audio & video codec's output bitrate.
784 * @param lc the LinphoneCore object
785 * @param bw the bandwidth in kbits/s, 0 for infinite
787 void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
788 lc->net_conf.upload_bw=bw;
789 if (bw==0){ /*infinite*/
793 lc->up_audio_bw=MIN(lc->audio_bw,bw);
794 lc->up_video_bw=MAX(bw-lc->up_audio_bw-10,0);/*-10: security margin*/
799 * Retrieve the maximum available download bandwidth.
801 * @ingroup media_parameters
803 * This value was set by linphone_core_set_download_bandwidth().
806 int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
807 return lc->net_conf.download_bw;
811 * Retrieve the maximum available upload bandwidth.
813 * @ingroup media_parameters
815 * This value was set by linphone_core_set_upload_bandwidth().
818 int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
819 return lc->net_conf.upload_bw;
822 * set audio packetization time linphone expect to received from peer
824 void linphone_core_set_download_ptime(LinphoneCore *lc, int ptime) {
825 lc->net_conf.down_ptime=ptime;
828 int linphone_core_get_download_ptime(LinphoneCore *lc) {
829 return lc->net_conf.down_ptime;
834 * Returns liblinphone's version as a string.
839 const char * linphone_core_get_version(void){
840 return liblinphone_version;
844 static MSList *linphone_payload_types=NULL;
846 static void linphone_core_assign_payload_type(PayloadType *const_pt, int number, const char *recv_fmtp){
848 pt=payload_type_clone(const_pt);
849 payload_type_set_number(pt,number);
850 if (recv_fmtp!=NULL) payload_type_set_recv_fmtp(pt,recv_fmtp);
851 rtp_profile_set_payload(&av_profile,number,pt);
852 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
855 static void linphone_core_free_payload_types(void){
856 ms_list_for_each(linphone_payload_types,(void (*)(void*))payload_type_destroy);
857 ms_list_free(linphone_payload_types);
858 linphone_payload_types=NULL;
861 static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path,
862 const char *factory_config_path, void * userdata)
864 memset (lc, 0, sizeof (LinphoneCore));
867 memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
869 gstate_initialize(lc);
870 gstate_new_state(lc, GSTATE_POWER_STARTUP, NULL);
873 linphone_core_assign_payload_type(&payload_type_pcmu8000,0,NULL);
874 linphone_core_assign_payload_type(&payload_type_gsm,3,NULL);
875 linphone_core_assign_payload_type(&payload_type_pcma8000,8,NULL);
876 linphone_core_assign_payload_type(&payload_type_lpc1015,115,NULL);
877 linphone_core_assign_payload_type(&payload_type_speex_nb,110,"vbr=on");
878 linphone_core_assign_payload_type(&payload_type_speex_wb,111,"vbr=on");
879 linphone_core_assign_payload_type(&payload_type_speex_uwb,112,"vbr=on");
880 linphone_core_assign_payload_type(&payload_type_telephone_event,101,"0-11");
881 linphone_core_assign_payload_type(&payload_type_ilbc,113,"mode=30");
882 linphone_core_assign_payload_type(&payload_type_amr,114,"octet-align=1");
884 #ifdef ENABLE_NONSTANDARD_GSM
887 pt=payload_type_clone(&payload_type_gsm);
888 pt->clock_rate=11025;
889 rtp_profile_set_payload(&av_profile,114,pt);
890 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
891 pt=payload_type_clone(&payload_type_gsm);
892 pt->clock_rate=22050;
893 rtp_profile_set_payload(&av_profile,115,pt);
894 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
899 linphone_core_assign_payload_type(&payload_type_h263,34,NULL);
900 linphone_core_assign_payload_type(&payload_type_theora,97,NULL);
901 linphone_core_assign_payload_type(&payload_type_h263_1998,98,"CIF=1;QCIF=1");
902 linphone_core_assign_payload_type(&payload_type_mp4v,99,"profile-level-id=3");
903 linphone_core_assign_payload_type(&payload_type_x_snow,100,NULL);
904 linphone_core_assign_payload_type(&payload_type_h264,102,NULL);
905 linphone_core_assign_payload_type(&payload_type_h264,103,"packetization-mode=1");
910 lc->config=lp_config_new(config_path);
911 if (factory_config_path)
912 lp_config_read_file(lc->config,factory_config_path);
915 sal_set_user_pointer(lc->sal,lc);
916 sal_set_callbacks(lc->sal,&linphone_sal_callbacks);
917 if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
918 sal_use_session_timers(lc->sal,200);
920 sip_setup_register_all();
921 sound_config_read(lc);
924 codecs_config_read(lc);
925 sip_config_read(lc); /* this will start eXosip*/
926 video_config_read(lc);
927 //autoreplier_config_init(&lc->autoreplier_conf);
928 lc->prev_mode=LINPHONE_STATUS_ONLINE;
929 lc->presence_mode=LINPHONE_STATUS_ONLINE;
930 lc->max_call_logs=15;
932 lc->vtable.display_status(lc,_("Ready"));
933 gstate_new_state(lc, GSTATE_POWER_ON, NULL);
934 lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
940 * Instanciates a LinphoneCore object.
941 * @ingroup initializing
943 * The LinphoneCore object is the primary handle for doing all phone actions.
944 * It should be unique within your application.
945 * @param vtable a LinphoneCoreVTable structure holding your application callbacks
946 * @param config_path a path to a config file. If it does not exists it will be created.
947 * The config file is used to store all user settings, call logs, friends, proxies...
948 * @param factory_config_path a path to a read-only config file that can be used to
949 * to store hard-coded preference such as proxy settings or internal preferences.
950 * The settings in this factory file always override the one in the normal config file.
951 * It is OPTIONAL, use NULL if unneeded.
952 * @param userdata an opaque user pointer that can be retrieved at any time (for example in
953 * callbacks) using linphone_core_get_user_data().
956 LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
957 const char *config_path, const char *factory_config_path, void * userdata)
959 LinphoneCore *core=ms_new(LinphoneCore,1);
960 linphone_core_init(core,vtable,config_path, factory_config_path, userdata);
965 * Returns the list of available audio codecs.
967 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
968 * structure holding the codec information.
969 * It is possible to make copy of the list with ms_list_copy() in order to modify it
970 * (such as the order of codecs).
972 const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
974 return lc->codecs_conf.audio_codecs;
978 * Returns the list of available video codecs.
980 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
981 * structure holding the codec information.
982 * It is possible to make copy of the list with ms_list_copy() in order to modify it
983 * (such as the order of codecs).
985 const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
987 return lc->codecs_conf.video_codecs;
991 * Sets the local "from" identity.
994 * This data is used in absence of any proxy configuration or when no
995 * default proxy configuration is set. See LinphoneProxyConfig
997 int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact)
999 LinphoneAddress *ctt;
1001 if ((ctt=linphone_address_new(contact))==0) {
1002 ms_error("Bad contact url: %s",contact);
1005 if (lc->sip_conf.contact!=NULL) ms_free(lc->sip_conf.contact);
1006 lc->sip_conf.contact=ms_strdup(contact);
1007 if (lc->sip_conf.guessed_contact!=NULL){
1008 ms_free(lc->sip_conf.guessed_contact);
1009 lc->sip_conf.guessed_contact=NULL;
1011 linphone_address_destroy(ctt);
1016 /*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
1017 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
1018 if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
1019 strncpy(result,linphone_core_get_nat_address(lc),LINPHONE_IPADDR_SIZE);
1022 if (linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,dest,result)==0)
1024 /*else fallback to SAL routine that will attempt to find the most realistic interface */
1025 sal_get_default_local_ip(lc->sal,lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,result,LINPHONE_IPADDR_SIZE);
1028 static void update_primary_contact(LinphoneCore *lc){
1030 char tmp[LINPHONE_IPADDR_SIZE];
1032 LinphoneAddress *url;
1033 if (lc->sip_conf.guessed_contact!=NULL){
1034 ms_free(lc->sip_conf.guessed_contact);
1035 lc->sip_conf.guessed_contact=NULL;
1037 url=linphone_address_new(lc->sip_conf.contact);
1039 ms_error("Could not parse identity contact !");
1040 url=linphone_address_new("sip:unknown@unkwownhost");
1042 linphone_core_get_local_ip(lc, NULL, tmp);
1043 if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
1044 ms_warning("Local loopback network only !");
1045 lc->sip_conf.loopback_only=TRUE;
1046 }else lc->sip_conf.loopback_only=FALSE;
1047 linphone_address_set_domain(url,tmp);
1048 linphone_address_set_port_int(url,lc->sip_conf.sip_port);
1049 guessed=linphone_address_as_string(url);
1050 lc->sip_conf.guessed_contact=guessed;
1051 linphone_address_destroy(url);
1055 * Returns the default identity when no proxy configuration is used.
1059 const char *linphone_core_get_primary_contact(LinphoneCore *lc){
1062 if (lc->sip_conf.guess_hostname){
1063 if (lc->sip_conf.guessed_contact==NULL || lc->sip_conf.loopback_only){
1064 update_primary_contact(lc);
1066 identity=lc->sip_conf.guessed_contact;
1068 identity=lc->sip_conf.contact;
1074 * Tells LinphoneCore to guess local hostname automatically in primary contact.
1078 void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
1079 lc->sip_conf.guess_hostname=val;
1083 * Returns TRUE if hostname part of primary contact is guessed automatically.
1087 bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
1088 return lc->sip_conf.guess_hostname;
1092 * Same as linphone_core_get_primary_contact() but the result is a LinphoneAddress object
1093 * instead of const char*
1097 LinphoneAddress *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
1098 return linphone_address_new(linphone_core_get_primary_contact(lc));
1102 * Sets the list of audio codecs.
1104 * @ingroup media_parameters
1105 * The list is taken by the LinphoneCore thus the application should not free it.
1106 * This list is made of struct PayloadType describing the codec parameters.
1108 int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
1110 if (lc->codecs_conf.audio_codecs!=NULL) ms_list_free(lc->codecs_conf.audio_codecs);
1111 lc->codecs_conf.audio_codecs=codecs;
1116 * Sets the list of video codecs.
1118 * @ingroup media_parameters
1119 * The list is taken by the LinphoneCore thus the application should not free it.
1120 * This list is made of struct PayloadType describing the codec parameters.
1122 int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
1124 if (lc->codecs_conf.video_codecs!=NULL) ms_list_free(lc->codecs_conf.video_codecs);
1125 lc->codecs_conf.video_codecs=codecs;
1129 const MSList * linphone_core_get_friend_list(const LinphoneCore *lc)
1135 * Returns the nominal jitter buffer size in milliseconds.
1137 * @ingroup media_parameters
1139 int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
1141 return lc->rtp_conf.audio_jitt_comp;
1145 * Returns the UDP port used for audio streaming.
1147 * @ingroup network_parameters
1149 int linphone_core_get_audio_port(const LinphoneCore *lc)
1151 return lc->rtp_conf.audio_rtp_port;
1155 * Returns the UDP port used for video streaming.
1157 * @ingroup network_parameters
1159 int linphone_core_get_video_port(const LinphoneCore *lc){
1160 return lc->rtp_conf.video_rtp_port;
1165 * Returns the value in seconds of the no-rtp timeout.
1167 * @ingroup media_parameters
1168 * When no RTP or RTCP packets have been received for a while
1169 * LinphoneCore will consider the call is broken (remote end crashed or
1170 * disconnected from the network), and thus will terminate the call.
1171 * The no-rtp timeout is the duration above which the call is considered broken.
1173 int linphone_core_get_nortp_timeout(const LinphoneCore *lc){
1174 return lc->rtp_conf.nortp_timeout;
1178 * Sets the nominal audio jitter buffer size in milliseconds.
1180 * @ingroup media_parameters
1182 void linphone_core_set_audio_jittcomp(LinphoneCore *lc, int value)
1184 lc->rtp_conf.audio_jitt_comp=value;
1188 * Sets the UDP port used for audio streaming.
1190 * @ingroup network_parameters
1192 void linphone_core_set_audio_port(LinphoneCore *lc, int port)
1194 lc->rtp_conf.audio_rtp_port=port;
1198 * Sets the UDP port used for video streaming.
1200 * @ingroup network_parameters
1202 void linphone_core_set_video_port(LinphoneCore *lc, int port){
1203 lc->rtp_conf.video_rtp_port=port;
1207 * Sets the no-rtp timeout value in seconds.
1209 * @ingroup media_parameters
1210 * See linphone_core_get_nortp_timeout() for details.
1212 void linphone_core_set_nortp_timeout(LinphoneCore *lc, int nortp_timeout){
1213 lc->rtp_conf.nortp_timeout=nortp_timeout;
1217 * Indicates whether SIP INFO is used for sending digits.
1219 * @ingroup media_parameters
1221 bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
1223 return lc->sip_conf.use_info;
1227 * Sets whether SIP INFO is to be used for sending digits.
1229 * @ingroup media_parameters
1231 void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
1233 lc->sip_conf.use_info=use_info;
1237 * Indicates whether RFC2833 is used for sending digits.
1239 * @ingroup media_parameters
1241 bool_t linphone_core_get_use_rfc2833_for_dtmf(LinphoneCore *lc)
1243 return lc->sip_conf.use_rfc2833;
1247 * Sets whether RFC2833 is to be used for sending digits.
1249 * @ingroup media_parameters
1251 void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833)
1253 lc->sip_conf.use_rfc2833=use_rfc2833;
1257 * Returns the UDP port used by SIP.
1259 * @ingroup network_parameters
1261 int linphone_core_get_sip_port(LinphoneCore *lc)
1263 return lc->sip_conf.sip_port;
1266 static char _ua_name[64]="Linphone";
1267 static char _ua_version[64]=LINPHONE_VERSION;
1269 #ifdef HAVE_EXOSIP_GET_VERSION
1270 extern const char *eXosip_get_version();
1273 static void apply_user_agent(LinphoneCore *lc){
1274 char ua_string[256];
1275 snprintf(ua_string,sizeof(ua_string)-1,"%s/%s (eXosip2/%s)",_ua_name,_ua_version,
1276 #ifdef HAVE_EXOSIP_GET_VERSION
1277 eXosip_get_version()
1282 if (lc->sal) sal_set_user_agent(lc->sal,ua_string);
1286 * Sets the user agent string used in SIP messages.
1290 void linphone_core_set_user_agent(const char *name, const char *ver){
1291 strncpy(_ua_name,name,sizeof(_ua_name)-1);
1292 strncpy(_ua_version,ver,sizeof(_ua_version));
1296 * Sets the UDP port to be used by SIP.
1298 * @ingroup network_parameters
1300 void linphone_core_set_sip_port(LinphoneCore *lc,int port)
1302 const char *anyaddr;
1304 if (port==lc->sip_conf.sip_port) return;
1305 lc->sip_conf.sip_port=port;
1307 if (lc->sal==NULL) return;
1309 if (lc->sip_conf.ipv6_enabled)
1313 err=sal_listen_port (lc->sal,anyaddr,port, SalTransportDatagram,FALSE);
1315 char *msg=ortp_strdup_printf("UDP port %i seems already in use ! Cannot initialize.",port);
1317 lc->vtable.display_warning(lc,msg);
1321 apply_user_agent(lc);
1325 * Returns TRUE if IPv6 is enabled.
1327 * @ingroup network_parameters
1328 * See linphone_core_enable_ipv6() for more details on how IPv6 is supported in liblinphone.
1330 bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
1331 return lc->sip_conf.ipv6_enabled;
1335 * Turns IPv6 support on or off.
1337 * @ingroup network_parameters
1339 * @note IPv6 support is exclusive with IPv4 in liblinphone:
1340 * when IPv6 is turned on, IPv4 calls won't be possible anymore.
1341 * By default IPv6 support is off.
1343 void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
1344 if (lc->sip_conf.ipv6_enabled!=val){
1345 lc->sip_conf.ipv6_enabled=val;
1347 /* we need to restart eXosip */
1348 linphone_core_set_sip_port(lc, lc->sip_conf.sip_port);
1353 static void display_bandwidth(RtpSession *as, RtpSession *vs){
1354 ms_message("bandwidth usage: audio=[d=%.1f,u=%.1f] video=[d=%.1f,u=%.1f] kbit/sec",
1355 (as!=NULL) ? (rtp_session_compute_recv_bandwidth(as)*1e-3) : 0,
1356 (as!=NULL) ? (rtp_session_compute_send_bandwidth(as)*1e-3) : 0,
1357 (vs!=NULL) ? (rtp_session_compute_recv_bandwidth(vs)*1e-3) : 0,
1358 (vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0);
1361 static void linphone_core_disconnected(LinphoneCore *lc){
1362 lc->vtable.display_warning(lc,_("Remote end seems to have disconnected, the call is going to be closed."));
1363 linphone_core_terminate_call(lc,NULL);
1366 static void monitor_network_state(LinphoneCore *lc, time_t curtime){
1367 static time_t last_check=0;
1368 static bool_t last_status=FALSE;
1369 char result[LINPHONE_IPADDR_SIZE];
1370 bool_t new_status=last_status;
1372 /* only do the network up checking every five seconds */
1373 if (last_check==0 || (curtime-last_check)>=5){
1374 linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,NULL,result);
1375 if (strcmp(result,"::1")!=0 && strcmp(result,"127.0.0.1")!=0){
1377 }else new_status=FALSE;
1379 if (new_status!=last_status) {
1381 ms_message("New local ip address is %s",result);
1383 set_network_reachable(lc,new_status);
1384 last_status=new_status;
1389 static void proxy_update(LinphoneCore *lc){
1390 ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
1393 static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){
1394 LinphoneFriend *lf=linphone_core_get_friend_by_address(lc,info->sip_uri);
1397 ms_message("%s has a BuddyInfo assigned with image %p",info->sip_uri, info->image_data);
1398 if (lc->vtable.buddy_info_updated)
1399 lc->vtable.buddy_info_updated(lc,lf);
1401 ms_warning("Could not any friend with uri %s",info->sip_uri);
1405 static void analyze_buddy_lookup_results(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1407 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1408 for (elem=lc->bl_reqs;elem!=NULL;elem=ms_list_next(elem)){
1409 BuddyLookupRequest *req=(BuddyLookupRequest *)elem->data;
1410 if (req->status==BuddyLookupDone || req->status==BuddyLookupFailure){
1411 if (req->results!=NULL){
1412 BuddyInfo *i=(BuddyInfo*)req->results->data;
1413 ms_list_free(req->results);
1415 assign_buddy_info(lc,i);
1417 sip_setup_context_buddy_lookup_free(ctx,req);
1421 /*purge completed requests */
1422 while((elem=ms_list_find(lc->bl_reqs,NULL))!=NULL){
1423 lc->bl_reqs=ms_list_remove_link(lc->bl_reqs,elem);
1427 static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1429 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1430 for(elem=linphone_core_get_friend_list(lc);elem!=NULL;elem=elem->next){
1431 LinphoneFriend *lf=(LinphoneFriend*)elem->data;
1432 if (lf->info==NULL){
1433 if (linphone_core_lookup_known_proxy(lc,lf->uri)==cfg){
1434 if (linphone_address_get_username(lf->uri)!=NULL){
1435 BuddyLookupRequest *req;
1436 char *tmp=linphone_address_as_string_uri_only(lf->uri);
1437 req=sip_setup_context_create_buddy_lookup_request(ctx);
1438 buddy_lookup_request_set_key(req,tmp);
1439 buddy_lookup_request_set_max_results(req,1);
1440 sip_setup_context_buddy_lookup_submit(ctx,req);
1441 lc->bl_reqs=ms_list_append(lc->bl_reqs,req);
1449 static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
1450 LinphoneProxyConfig *cfg=NULL;
1451 linphone_core_get_default_proxy(lc,&cfg);
1453 if (lc->bl_refresh){
1454 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1455 if (ctx && (sip_setup_context_get_capabilities(ctx) & SIP_SETUP_CAP_BUDDY_LOOKUP)){
1456 linphone_core_grab_buddy_infos(lc,cfg);
1457 lc->bl_refresh=FALSE;
1460 if (lc->bl_reqs) analyze_buddy_lookup_results(lc,cfg);
1465 * Main loop function. It is crucial that your application call it periodically.
1467 * @ingroup initializing
1468 * linphone_core_iterate() performs various backgrounds tasks:
1469 * - receiving of SIP messages
1470 * - handles timers and timeout
1471 * - performs registration to proxies
1472 * - authentication retries
1473 * The application MUST call this function from periodically, in its main loop.
1474 * Be careful that this function must be call from the same thread as
1475 * other liblinphone methods. In not the case make sure all liblinphone calls are
1476 * serialized with a mutex.
1478 void linphone_core_iterate(LinphoneCore *lc){
1479 int disconnect_timeout = linphone_core_get_nortp_timeout(lc);
1480 time_t curtime=time(NULL);
1482 bool_t one_second_elapsed=FALSE;
1483 bool_t disconnected=FALSE;
1485 if (curtime-lc->prevtime>=1){
1486 lc->prevtime=curtime;
1487 one_second_elapsed=TRUE;
1490 if (lc->preview_finished){
1491 lc->preview_finished=0;
1492 ring_stop(lc->ringstream);
1493 lc->ringstream=NULL;
1494 lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
1497 sal_iterate(lc->sal);
1498 if (lc->auto_net_state_mon) monitor_network_state(lc,curtime);
1501 LinphoneCall *call = linphone_core_get_current_call(lc);
1503 if (call->state==LinphoneCallPreEstablishing && (curtime-call->start_time>=2)){
1504 /*start the call even if the OPTIONS reply did not arrive*/
1505 linphone_core_start_invite(lc,call,NULL);
1507 if (call->dir==LinphoneCallIncoming && call->state==LinphoneCallRinging){
1508 elapsed=curtime-call->start_time;
1509 ms_message("incoming call ringing for %i seconds",elapsed);
1510 if (elapsed>lc->sip_conf.inc_timeout){
1511 call->log->status=LinphoneCallMissed;
1512 linphone_core_terminate_call(lc,NULL);
1514 }else if (call->state==LinphoneCallAVRunning){
1515 if (one_second_elapsed){
1516 RtpSession *as=NULL,*vs=NULL;
1517 lc->prevtime=curtime;
1518 if (lc->audiostream!=NULL)
1519 as=lc->audiostream->session;
1520 if (lc->videostream!=NULL)
1521 vs=lc->videostream->session;
1522 display_bandwidth(as,vs);
1524 #ifdef VIDEO_ENABLED
1525 if (lc->videostream!=NULL)
1526 video_stream_iterate(lc->videostream);
1528 if (lc->audiostream!=NULL && disconnect_timeout>0)
1529 disconnected=!audio_stream_alive(lc->audiostream,disconnect_timeout);
1532 if (linphone_core_video_preview_enabled(lc)){
1533 if (lc->previewstream==NULL)
1534 toggle_video_preview(lc,TRUE);
1535 #ifdef VIDEO_ENABLED
1536 else video_stream_iterate(lc->previewstream);
1539 if (lc->previewstream!=NULL)
1540 toggle_video_preview(lc,FALSE);
1543 linphone_core_disconnected(lc);
1545 linphone_core_do_plugin_tasks(lc);
1547 if (one_second_elapsed && lp_config_needs_commit(lc->config)){
1548 lp_config_sync(lc->config);
1553 * Interpret a call destination as supplied by the user, and returns a fully qualified
1556 * A sip address should look like DisplayName <sip:username@domain:port> .
1557 * Basically this function performs the following tasks
1558 * - if a phone number is entered, prepend country prefix of the default proxy
1559 * configuration, eventually escape the '+' by 00.
1560 * - if no domain part is supplied, append the domain name of the default proxy
1561 * - if no sip: is present, prepend it
1563 * The result is a syntaxically correct SIP address.
1566 LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url){
1567 enum_lookup_res_t *enumres=NULL;
1568 char *enum_domain=NULL;
1569 LinphoneProxyConfig *proxy=lc->default_proxy;;
1571 LinphoneAddress *uri;
1573 if (is_enum(url,&enum_domain)){
1574 lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
1575 if (enum_lookup(enum_domain,&enumres)<0){
1576 lc->vtable.display_status(lc,_("Could not resolve this number."));
1577 if(lc->vtable.failure_recv)
1578 lc->vtable.failure_recv(lc,NULL,400);
1579 ms_free(enum_domain);
1582 ms_free(enum_domain);
1583 tmpurl=enumres->sip_address[0];
1584 uri=linphone_address_new(tmpurl);
1585 enum_lookup_res_free(enumres);
1588 /* check if we have a "sip:" */
1589 if (strstr(url,"sip:")==NULL){
1590 /* this doesn't look like a true sip uri */
1591 if (strchr(url,'@')!=NULL){
1592 /* seems like sip: is missing !*/
1593 tmpurl=ms_strdup_printf("sip:%s",url);
1594 uri=linphone_address_new(tmpurl);
1602 /* append the proxy domain suffix */
1603 const char *identity=linphone_proxy_config_get_identity(proxy);
1604 char normalized_username[128];
1605 uri=linphone_address_new(identity);
1609 linphone_address_set_display_name(uri,NULL);
1610 linphone_proxy_config_normalize_number(proxy,url,normalized_username,
1611 sizeof(normalized_username));
1612 linphone_address_set_username(uri,normalized_username);
1616 uri=linphone_address_new(url);
1620 /* else we could not do anything with url given by user, so display an error */
1621 if (lc->vtable.display_warning!=NULL){
1622 lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
1628 * Returns the default identity SIP address.
1631 * This is an helper function:
1633 * If no default proxy is set, this will return the primary contact (
1634 * see linphone_core_get_primary_contact() ). If a default proxy is set
1635 * it returns the registered identity on the proxy.
1637 const char * linphone_core_get_identity(LinphoneCore *lc){
1638 LinphoneProxyConfig *proxy=NULL;
1640 linphone_core_get_default_proxy(lc,&proxy);
1642 from=linphone_proxy_config_get_identity(proxy);
1643 }else from=linphone_core_get_primary_contact(lc);
1647 const char * linphone_core_get_route(LinphoneCore *lc){
1648 LinphoneProxyConfig *proxy=NULL;
1649 const char *route=NULL;
1650 linphone_core_get_default_proxy(lc,&proxy);
1652 route=linphone_proxy_config_get_route(proxy);
1657 bool_t linphone_core_is_in_communication_with(LinphoneCore *lc, const char *to)
1661 const LinphoneAddress *la=linphone_core_get_current_call_remote_address(lc);
1666 tmp = linphone_address_as_string(la);
1676 LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
1678 LinphoneProxyConfig *found_cfg=NULL;
1679 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=elem->next){
1680 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1681 const char *domain=linphone_proxy_config_get_domain(cfg);
1682 if (domain!=NULL && strcmp(domain,linphone_address_get_domain(uri))==0){
1690 static char *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){
1691 LinphoneAddress *ctt;
1692 const char *localip=call->localip;
1694 /* first use user's supplied ip address if asked*/
1695 if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
1696 ctt=linphone_core_get_primary_contact_parsed(lc);
1697 return ms_strdup_printf("sip:%s@%s",linphone_address_get_username(ctt),
1698 linphone_core_get_nat_address(lc));
1701 /* if already choosed, don't change it */
1702 if (call->op && sal_op_get_contact(call->op)!=NULL){
1705 /* if the ping OPTIONS request succeeded use the contact guessed from the
1708 const char *guessed=sal_op_get_contact(call->ping_op);
1710 ms_message("Contact has been fixed using OPTIONS to %s",guessed);
1711 return ms_strdup(guessed);
1715 /*if using a proxy, use the contact address as guessed with the REGISTERs*/
1716 if (dest_proxy && dest_proxy->op){
1717 const char *fixed_contact=sal_op_get_contact(dest_proxy->op);
1718 if (fixed_contact) {
1719 ms_message("Contact has been fixed using proxy to %s",fixed_contact);
1720 return ms_strdup(fixed_contact);
1724 ctt=linphone_core_get_primary_contact_parsed(lc);
1728 /*otherwise use supllied localip*/
1729 linphone_address_set_domain(ctt,localip);
1730 linphone_address_set_port_int(ctt,linphone_core_get_sip_port(lc));
1731 ret=linphone_address_as_string_uri_only(ctt);
1732 linphone_address_destroy(ctt);
1733 ms_message("Contact has been fixed using local ip to %s",ret);
1739 int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphoneProxyConfig *dest_proxy){
1742 char *real_url,*barmsg;
1744 /*try to be best-effort in giving real local or routable contact address */
1745 contact=get_fixed_contact(lc,call,dest_proxy);
1747 sal_op_set_contact(call->op, contact);
1750 call->state=LinphoneCallInit;
1751 linphone_core_init_media_streams(lc,call);
1752 if (!lc->sip_conf.sdp_200_ack){
1753 call->media_pending=TRUE;
1754 sal_call_set_local_media_description(call->op,call->localdesc);
1756 real_url=linphone_address_as_string(call->log->to);
1757 from=linphone_address_as_string(call->log->from);
1758 err=sal_call(call->op,from,real_url);
1760 if (lc->sip_conf.sdp_200_ack){
1761 call->media_pending=TRUE;
1762 sal_call_set_local_media_description(call->op,call->localdesc);
1764 barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
1765 lc->vtable.display_status(lc,barmsg);
1769 ms_warning("Could not initiate call.");
1770 lc->vtable.display_status(lc,_("could not call"));
1771 if(call == linphone_core_get_current_call(lc))
1772 linphone_core_stop_media_streams(lc,call);
1773 linphone_call_unref(call);
1774 }else gstate_new_state(lc, GSTATE_CALL_OUT_INVITE, real_url);
1781 * Initiates an outgoing call
1783 * @ingroup call_control
1784 * @param lc the LinphoneCore object
1785 * @param url the destination of the call (sip address, or phone number).
1787 LinphoneCall * linphone_core_invite(LinphoneCore *lc, const char *url){
1788 LinphoneAddress *addr=linphone_core_interpret_url(lc,url);
1791 call=linphone_core_invite_address(lc,addr);
1792 linphone_address_destroy(addr);
1799 * Initiates an outgoing call given a destination LinphoneAddress
1801 * @ingroup call_control
1802 * @param lc the LinphoneCore object
1803 * @param url the destination of the call (sip address).
1805 LinphoneCall * linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *real_parsed_url)
1808 const char *route=NULL;
1809 const char *from=NULL;
1810 LinphoneProxyConfig *proxy=NULL;
1811 LinphoneAddress *parsed_url2=NULL;
1812 char *real_url=NULL;
1813 LinphoneProxyConfig *dest_proxy=NULL;
1816 if (linphone_core_in_call(lc)){
1817 lc->vtable.display_warning(lc,_("Sorry, you have to pause or stop the current call first !"));
1820 if(!linphone_core_can_we_add_call(lc)){
1821 lc->vtable.display_warning(lc,_("Sorry, we have reached the maximum number of simultaneous calls"));
1824 linphone_core_get_default_proxy(lc,&proxy);
1825 route=linphone_core_get_route(lc);
1827 real_url=linphone_address_as_string(real_parsed_url);
1828 dest_proxy=linphone_core_lookup_known_proxy(lc,real_parsed_url);
1830 if (proxy!=dest_proxy && dest_proxy!=NULL) {
1831 ms_message("Overriding default proxy setting for this call:");
1832 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
1835 if (dest_proxy!=NULL)
1836 from=linphone_proxy_config_get_identity(dest_proxy);
1837 else if (proxy!=NULL)
1838 from=linphone_proxy_config_get_identity(proxy);
1840 /* if no proxy or no identity defined for this proxy, default to primary contact*/
1841 if (from==NULL) from=linphone_core_get_primary_contact(lc);
1843 parsed_url2=linphone_address_new(from);
1845 call=linphone_call_new_outgoing(lc,parsed_url2,linphone_address_clone(real_parsed_url));
1846 sal_op_set_route(call->op,route);
1848 if(linphone_core_add_call(lc,call)!= 0)
1850 ms_warning("we had a problem in adding the call into the invite ... weird\n");
1851 linphone_call_unref(call);
1854 linphone_core_set_as_current_call(lc,call);
1855 if (dest_proxy!=NULL || lc->sip_conf.ping_with_options==FALSE){
1856 err=linphone_core_start_invite(lc,call,dest_proxy);
1858 /*defer the start of the call after the OPTIONS ping*/
1859 call->state=LinphoneCallPreEstablishing;
1860 call->ping_op=sal_op_new(lc->sal);
1861 sal_ping(call->ping_op,from,real_url);
1862 call->start_time=time(NULL);
1865 if (real_url!=NULL) ms_free(real_url);
1869 int linphone_core_refer(LinphoneCore *lc, LinphoneCall *call, const char *url)
1871 char *real_url=NULL;
1872 LinphoneAddress *real_parsed_url=linphone_core_interpret_url(lc,url);
1874 if (!real_parsed_url){
1879 ms_warning("No established call to refer.");
1882 //lc->call=NULL; //Do not do that you will lose the call afterward . . .
1883 real_url=linphone_address_as_string (real_parsed_url);
1884 sal_refer(call->op,real_url);
1890 * Returns true if an incoming call is pending, ie waiting for being answered or declined.
1892 * @ingroup call_control
1894 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
1895 LinphoneCall *call = linphone_core_get_current_call(lc);
1898 if(call->dir==LinphoneCallIncoming)
1904 void linphone_core_init_media_streams(LinphoneCore *lc, LinphoneCall *call){
1905 SalMediaDescription *md=call->localdesc;
1906 lc->audiostream=audio_stream_new(md->streams[0].port,linphone_core_ipv6_enabled(lc));
1907 if (linphone_core_echo_limiter_enabled(lc)){
1908 const char *type=lp_config_get_string(lc->config,"sound","el_type","mic");
1909 if (strcasecmp(type,"mic")==0)
1910 audio_stream_enable_echo_limiter(lc->audiostream,ELControlMic);
1911 else if (strcasecmp(type,"speaker")==0)
1912 audio_stream_enable_echo_limiter(lc->audiostream,ELControlSpeaker);
1914 audio_stream_enable_gain_control(lc->audiostream,TRUE);
1915 if (linphone_core_echo_cancellation_enabled(lc)){
1916 int len,delay,framesize;
1917 len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
1918 delay=lp_config_get_int(lc->config,"sound","ec_delay",0);
1919 framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0);
1920 audio_stream_set_echo_canceller_params(lc->audiostream,len,delay,framesize);
1922 audio_stream_enable_automatic_gain_control(lc->audiostream,linphone_core_agc_enabled(lc));
1924 int enabled=lp_config_get_int(lc->config,"sound","noisegate",0);
1925 audio_stream_enable_noise_gate(lc->audiostream,enabled);
1928 rtp_session_set_transports(lc->audiostream->session,lc->a_rtp,lc->a_rtcp);
1930 #ifdef VIDEO_ENABLED
1931 if ((lc->video_conf.display || lc->video_conf.capture) && md->streams[1].port>0)
1932 lc->videostream=video_stream_new(md->streams[1].port,linphone_core_ipv6_enabled(lc));
1934 lc->videostream=NULL;
1938 static int dtmf_tab[16]={'0','1','2','3','4','5','6','7','8','9','*','#','A','B','C','D'};
1940 static void linphone_core_dtmf_received(RtpSession* s, int dtmf, void* user_data){
1941 LinphoneCore* lc = (LinphoneCore*)user_data;
1942 if (dtmf<0 || dtmf>15){
1943 ms_warning("Bad dtmf value %i",dtmf);
1946 if (lc->vtable.dtmf_received != NULL)
1947 lc->vtable.dtmf_received(lc, dtmf_tab[dtmf]);
1950 static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){
1952 MSFilter *f=st->equalizer;
1953 int enabled=lp_config_get_int(lc->config,"sound","eq_active",0);
1954 const char *gains=lp_config_get_string(lc->config,"sound","eq_gains",NULL);
1955 ms_filter_call_method(f,MS_EQUALIZER_SET_ACTIVE,&enabled);
1961 if (sscanf(gains,"%f:%f:%f %n",&g.frequency,&g.gain,&g.width,&bytes)==3){
1962 ms_message("Read equalizer gains: %f(~%f) --> %f",g.frequency,g.width,g.gain);
1963 ms_filter_call_method(f,MS_EQUALIZER_SET_GAIN,&g);
1972 static void post_configure_audio_streams(LinphoneCore *lc){
1973 AudioStream *st=lc->audiostream;
1974 float gain=lp_config_get_float(lc->config,"sound","mic_gain",-1);
1976 audio_stream_set_mic_gain(st,gain);
1977 float recv_gain = lc->sound_conf.soft_play_lev;
1978 if (recv_gain != 0) {
1979 linphone_core_set_soft_play_level(lc,recv_gain);
1981 if (linphone_core_echo_limiter_enabled(lc)){
1982 float speed=lp_config_get_float(lc->config,"sound","el_speed",-1);
1983 float thres=lp_config_get_float(lc->config,"sound","el_thres",-1);
1984 float force=lp_config_get_float(lc->config,"sound","el_force",-1);
1985 int sustain=lp_config_get_int(lc->config,"sound","el_sustain",-1);
1987 if (st->el_type==ELControlMic){
1989 if (speed==-1) speed=0.03;
1990 if (force==-1) force=10;
1992 else if (st->el_type==ELControlSpeaker){
1994 if (speed==-1) speed=0.02;
1995 if (force==-1) force=5;
1998 ms_filter_call_method(f,MS_VOLUME_SET_EA_SPEED,&speed);
2000 ms_filter_call_method(f,MS_VOLUME_SET_EA_THRESHOLD,&thres);
2002 ms_filter_call_method(f,MS_VOLUME_SET_EA_FORCE,&force);
2004 ms_filter_call_method(f,MS_VOLUME_SET_EA_SUSTAIN,&sustain);
2008 float ng_thres=lp_config_get_float(lc->config,"sound","ng_thres",0.05);
2009 float ng_floorgain=lp_config_get_float(lc->config,"sound","ng_floorgain",0);
2010 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_thres);
2011 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&ng_floorgain);
2013 parametrize_equalizer(lc,st);
2014 if (lc->vtable.dtmf_received!=NULL){
2015 /* replace by our default action*/
2016 audio_stream_play_received_dtmfs(lc->audiostream,FALSE);
2017 rtp_session_signal_connect(lc->audiostream->session,"telephone-event",(RtpCallback)linphone_core_dtmf_received,(unsigned long)lc);
2021 static RtpProfile *make_profile(LinphoneCore *lc, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){
2024 RtpProfile *prof=rtp_profile_new("Call profile");
2028 for(elem=desc->payloads;elem!=NULL;elem=elem->next){
2029 PayloadType *pt=(PayloadType*)elem->data;
2032 if (desc->type==SalAudio){
2033 linphone_core_update_allocated_audio_bandwidth_in_call(lc,pt);
2035 *used_pt=payload_type_get_number(pt);
2038 if (desc->bandwidth>0) remote_bw=desc->bandwidth;
2039 else if (md->bandwidth>0) {
2040 /*case where b=AS is given globally, not per stream*/
2041 remote_bw=md->bandwidth;
2042 if (desc->type==SalVideo){
2043 remote_bw-=lc->audio_bw;
2047 if (desc->type==SalAudio){
2048 bw=get_min_bandwidth(lc->up_audio_bw,remote_bw);
2049 }else bw=get_min_bandwidth(lc->up_video_bw,remote_bw);
2050 if (bw>0) pt->normal_bitrate=bw*1000;
2051 else if (desc->type==SalAudio){
2052 pt->normal_bitrate=-1;
2056 snprintf(tmp,sizeof(tmp),"ptime=%i",desc->ptime);
2057 payload_type_append_send_fmtp(pt,tmp);
2059 rtp_profile_set_payload(prof,payload_type_get_number(pt),pt);
2064 void linphone_core_start_media_streams(LinphoneCore *lc, LinphoneCall *call){
2065 LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
2066 const char *tool="linphone-" LINPHONE_VERSION;
2069 /* adjust rtp jitter compensation. It must be at least the latency of the sound card */
2070 int jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
2072 if (call->media_start_time==0) call->media_start_time=time(NULL);
2074 cname=linphone_address_as_string_uri_only(me);
2076 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
2077 SalProtoRtpAvp,SalAudio);
2079 call->audio_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
2080 if (!lc->use_files){
2081 MSSndCard *playcard=lc->sound_conf.play_sndcard;
2082 MSSndCard *captcard=lc->sound_conf.capt_sndcard;
2083 if (playcard==NULL) {
2084 ms_warning("No card defined for playback !");
2087 if (captcard==NULL) {
2088 ms_warning("No card defined for capture !");
2091 audio_stream_start_now(
2093 call->audio_profile,
2094 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
2101 linphone_core_echo_cancellation_enabled(lc));
2103 audio_stream_start_with_files(
2105 call->audio_profile,
2106 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
2114 post_configure_audio_streams(lc);
2115 audio_stream_set_rtcp_information(lc->audiostream, cname, tool);
2116 }else ms_warning("No audio stream defined ?");
2118 #ifdef VIDEO_ENABLED
2120 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
2121 SalProtoRtpAvp,SalVideo);
2122 /* shutdown preview */
2123 if (lc->previewstream!=NULL) {
2124 video_preview_stop(lc->previewstream);
2125 lc->previewstream=NULL;
2127 if (stream && (lc->video_conf.display || lc->video_conf.capture)) {
2128 const char *addr=stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr;
2129 call->video_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
2130 video_stream_set_sent_video_size(lc->videostream,linphone_core_get_preferred_video_size(lc));
2131 video_stream_enable_self_view(lc->videostream,lc->video_conf.selfview);
2132 if (lc->video_conf.display && lc->video_conf.capture)
2133 video_stream_start(lc->videostream,
2134 call->video_profile, addr, stream->port,
2136 used_pt, jitt_comp, lc->video_conf.device);
2137 else if (lc->video_conf.display)
2138 video_stream_recv_only_start(lc->videostream,
2139 call->video_profile, addr, stream->port,
2140 used_pt, jitt_comp);
2141 else if (lc->video_conf.capture)
2142 video_stream_send_only_start(lc->videostream,
2143 call->video_profile, addr, stream->port,
2145 used_pt, jitt_comp, lc->video_conf.device);
2146 video_stream_set_rtcp_information(lc->videostream, cname,tool);
2153 linphone_address_destroy(me);
2154 call->state=LinphoneCallAVRunning;
2157 void linphone_core_stop_media_streams(LinphoneCore *lc, LinphoneCall *call){
2158 if (lc->audiostream!=NULL) {
2159 audio_stream_stop(lc->audiostream);
2160 lc->audiostream=NULL;
2162 #ifdef VIDEO_ENABLED
2163 if (lc->videostream!=NULL){
2164 if (lc->video_conf.display && lc->video_conf.capture)
2165 video_stream_stop(lc->videostream);
2166 else if (lc->video_conf.display)
2167 video_stream_recv_only_stop(lc->videostream);
2168 else if (lc->video_conf.capture)
2169 video_stream_send_only_stop(lc->videostream);
2170 lc->videostream=NULL;
2172 if (linphone_core_video_preview_enabled(lc)){
2173 if (lc->previewstream==NULL){
2174 lc->previewstream=video_preview_start(lc->video_conf.device, lc->video_conf.vsize);
2178 if (call->audio_profile){
2179 rtp_profile_clear_all(call->audio_profile);
2180 rtp_profile_destroy(call->audio_profile);
2181 call->audio_profile=NULL;
2183 if (call->video_profile){
2184 rtp_profile_clear_all(call->video_profile);
2185 rtp_profile_destroy(call->video_profile);
2186 call->video_profile=NULL;
2191 * Accept an incoming call.
2193 * @ingroup call_control
2194 * Basically the application is notified of incoming calls within the
2195 * invite_recv callback of the #LinphoneCoreVTable structure.
2196 * The application can later respond positively to the call using
2198 * @param lc the LinphoneCore object
2199 * @param url the SIP address of the originator of the call, or NULL.
2200 * This argument is useful for managing multiple calls simulatenously,
2201 * however this feature is not supported yet.
2202 * Using NULL will accept the unique incoming call in progress.
2204 int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call)
2206 LinphoneProxyConfig *cfg=NULL;
2207 const char *contact=NULL;
2210 //if just one call is present answer the only one ...
2211 if(ms_list_size(linphone_core_get_calls(lc)) != 1)
2214 call = linphone_core_get_calls(lc)->data;
2217 if (call->state==LinphoneCallAVRunning){
2218 /*call already accepted*/
2223 if (lc->ringstream!=NULL) {
2224 ms_message("stop ringing");
2225 ring_stop(lc->ringstream);
2226 ms_message("ring stopped");
2227 lc->ringstream=NULL;
2229 if(linphone_core_set_as_current_call(lc,call)!=0)
2231 ms_message("another call is already in process\n");
2234 linphone_core_get_default_proxy(lc,&cfg);
2235 /*try to be best-effort in giving real local or routable contact address*/
2236 contact=get_fixed_contact(lc,call,cfg);
2238 sal_op_set_contact(call->op,contact);
2240 sal_call_accept(call->op);
2241 lc->vtable.display_status(lc,_("Connected."));
2242 gstate_new_state(lc, GSTATE_CALL_IN_CONNECTED, NULL);
2243 call->resultdesc=sal_call_get_final_media_description(call->op);
2244 if (call->resultdesc){
2245 sal_media_description_ref(call->resultdesc);
2246 if(call == linphone_core_get_current_call(lc))
2247 linphone_core_start_media_streams(lc, call);
2248 }else call->media_pending=TRUE;
2249 ms_message("call answered.");
2254 * Terminates a call.
2256 * @ingroup call_control
2257 * @param lc The LinphoneCore
2258 * @param url the destination of the call to be terminated, use NULL if there is
2259 * only one call (which is case in this version of liblinphone).
2261 int linphone_core_terminate_call(LinphoneCore *lc, LinphoneCall *the_call)
2264 if (the_call == NULL){
2265 call = linphone_core_get_current_call(lc);
2275 sal_call_terminate(call->op);
2278 if (lc->ringstream!=NULL) {
2279 ring_stop(lc->ringstream);
2280 lc->ringstream=NULL;
2282 if(call == linphone_core_get_current_call(lc))
2283 linphone_core_stop_media_streams(lc,call);
2284 lc->vtable.display_status(lc,_("Call ended") );
2285 gstate_new_state(lc, GSTATE_CALL_END, NULL);
2286 linphone_call_set_terminated(call);
2287 linphone_call_unref(call);
2292 * Terminates all the calls.
2294 * @ingroup call_control
2295 * @param lc The LinphoneCore
2297 int linphone_core_terminate_all_calls(LinphoneCore *lc){
2301 while(calls->next != NULL)
2303 linphone_core_terminate_call(lc,(LinphoneCall *)calls->data);
2304 calls = calls->next;
2306 ms_list_free(lc->calls);
2311 * Returns the calls MSList
2313 * @ingroup call_control
2315 MSList *linphone_core_get_calls(LinphoneCore *lc)
2317 return ms_list_copy(lc->calls);
2321 * Returns TRUE if there is a call running or pending.
2323 * @ingroup call_control
2325 bool_t linphone_core_in_call(const LinphoneCore *lc){
2326 return linphone_core_get_current_call((LinphoneCore *)lc)!=NULL;
2330 * Returns The _LinphoneCall struct of the current call if one is in call
2332 * @ingroup call_control
2334 LinphoneCall *linphone_core_get_current_call(LinphoneCore *lc)
2336 if(lc->current_call != NULL)
2337 return lc->current_call;
2342 * Permits to pause the call
2344 * @ingroup call_control
2346 int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *the_call)
2348 LinphoneCall *call = the_call;
2351 ms_error("LinphoneCore was null\n");
2356 if(linphone_core_in_call(lc))
2358 call = linphone_core_get_current_call(lc);
2362 ms_error("LinphoneCall was null\n");
2366 if(linphone_core_get_current_call(lc) != call)
2368 ms_error("The call asked to be paused was not the current on\n");
2371 sal_call_hold(call->op,TRUE);
2372 call->state = LinphoneCallPaused;
2373 linphone_core_unset_the_current_call(lc);
2374 linphone_core_stop_media_streams(lc,call);
2375 lc->vtable.display_status(lc,_("Pause the current call"));
2380 * Permits to resume the call
2382 * @ingroup call_control
2384 int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call)
2387 LinphoneCall *call = the_call;
2390 ms_error("LinphoneCore was null\n");
2395 MSList *calls = linphone_core_get_calls(lc);
2396 if(ms_list_size(calls) == 1)
2398 call = ((LinphoneCall *)calls->data);
2399 ms_list_free(calls);
2403 ms_error("LinphoneCall was null\n");
2404 ms_list_free(calls);
2408 if(linphone_core_get_current_call(lc) != NULL)
2410 ms_error("There is already a call in process pause or stop it first\n");
2413 linphone_core_init_media_streams(lc,call);
2414 sal_call_hold(call->op,FALSE);
2415 call->state = LinphoneCallAVRunning;
2416 linphone_core_set_as_current_call(lc,call);
2417 linphone_core_start_media_streams(lc,call);
2418 snprintf(temp,sizeof(temp),"Resume the call with %s",linphone_call_get_remote_address_as_string(call));
2419 lc->vtable.display_status(lc,temp);
2425 * Compare the remote address with the one in call
2428 * @param b the remote address to compare with
2429 * @return 0 if it's the good call else 1
2431 static int linphone_call_remote_address_compare(const void * a, const void * b)
2433 if(b == NULL || a ==NULL)
2435 char *the_remote_address = ((char *)b);
2436 LinphoneCall *call = ((LinphoneCall *)a);
2438 ms_message("the remote address:%s\n",the_remote_address);
2439 ms_message("the call:%p => %s\n",call,linphone_call_get_remote_address_as_string(call));
2441 if(!strcmp(linphone_call_get_remote_address_as_string(call),the_remote_address))
2449 * Get the call with the remote_address specified
2451 * @param remote_address
2452 * @return the LinphoneCall of the call if found
2454 LinphoneCall *linphone_core_get_call_by_remote_address(LinphoneCore *lc, const char *remote_address){
2456 MSList *the_call = ms_list_find_custom(lc->calls,linphone_call_remote_address_compare,(void *)remote_address);
2457 if(the_call != NULL)
2459 return ((LinphoneCall *)the_call->data);
2464 int linphone_core_send_publish(LinphoneCore *lc,
2465 LinphoneOnlineStatus presence_mode)
2468 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=ms_list_next(elem)){
2469 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2470 if (cfg->publish) linphone_proxy_config_send_publish(cfg,presence_mode);
2476 * Set the incoming call timeout in seconds.
2478 * @ingroup call_control
2479 * If an incoming call isn't answered for this timeout period, it is
2480 * automatically declined.
2482 void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
2483 lc->sip_conf.inc_timeout=seconds;
2487 * Returns the incoming call timeout
2489 * @ingroup call_control
2490 * See linphone_core_set_inc_timeout() for details.
2492 int linphone_core_get_inc_timeout(LinphoneCore *lc){
2493 return lc->sip_conf.inc_timeout;
2496 void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
2497 const char *contact,
2498 LinphoneOnlineStatus presence_mode)
2500 if (minutes_away>0) lc->minutes_away=minutes_away;
2502 if (lc->alt_contact!=NULL) {
2503 ms_free(lc->alt_contact);
2504 lc->alt_contact=NULL;
2506 if (contact) lc->alt_contact=ms_strdup(contact);
2507 if (lc->presence_mode!=presence_mode){
2508 linphone_core_notify_all_friends(lc,presence_mode);
2510 Improve the use of all LINPHONE_STATUS available.
2511 !TODO Do not mix "presence status" with "answer status code"..
2512 Use correct parameter to follow sip_if_match/sip_etag.
2514 linphone_core_send_publish(lc,presence_mode);
2516 lc->prev_mode=lc->presence_mode;
2517 lc->presence_mode=presence_mode;
2520 LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
2521 return lc->presence_mode;
2525 * Get playback sound level in 0-100 scale.
2527 * @ingroup media_parameters
2529 int linphone_core_get_play_level(LinphoneCore *lc)
2531 return lc->sound_conf.play_lev;
2535 * Get ring sound level in 0-100 scale
2537 * @ingroup media_parameters
2539 int linphone_core_get_ring_level(LinphoneCore *lc)
2541 return lc->sound_conf.ring_lev;
2545 * Get sound capture level in 0-100 scale
2547 * @ingroup media_parameters
2549 int linphone_core_get_rec_level(LinphoneCore *lc){
2550 return lc->sound_conf.rec_lev;
2554 * Set sound ring level in 0-100 scale
2556 * @ingroup media_parameters
2558 void linphone_core_set_ring_level(LinphoneCore *lc, int level){
2560 lc->sound_conf.ring_lev=level;
2561 sndcard=lc->sound_conf.ring_sndcard;
2562 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2566 void linphone_core_set_soft_play_level(LinphoneCore *lc, float level){
2568 lc->sound_conf.soft_play_lev=level;
2569 AudioStream *st=lc->audiostream;
2570 if (!st) return; /*just return*/
2573 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_DB_GAIN,&gain);
2574 }else ms_warning("Could not apply gain: gain control wasn't activated.");
2576 float linphone_core_get_soft_play_level(LinphoneCore *lc) {
2578 AudioStream *st=lc->audiostream;
2580 ms_filter_call_method(st->volrecv,MS_VOLUME_GET,&gain);
2581 }else ms_warning("Could not get gain: gain control wasn't activated.");
2587 * Set sound playback level in 0-100 scale
2589 * @ingroup media_parameters
2591 void linphone_core_set_play_level(LinphoneCore *lc, int level){
2593 lc->sound_conf.play_lev=level;
2594 sndcard=lc->sound_conf.play_sndcard;
2595 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2599 * Set sound capture level in 0-100 scale
2601 * @ingroup media_parameters
2603 void linphone_core_set_rec_level(LinphoneCore *lc, int level)
2606 lc->sound_conf.rec_lev=level;
2607 sndcard=lc->sound_conf.capt_sndcard;
2608 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_CAPTURE,level);
2611 static MSSndCard *get_card_from_string_id(const char *devid, unsigned int cap){
2612 MSSndCard *sndcard=NULL;
2614 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2615 if (sndcard!=NULL &&
2616 (ms_snd_card_get_capabilities(sndcard) & cap)==0 ){
2617 ms_warning("%s card does not have the %s capability, ignoring.",
2619 cap==MS_SND_CARD_CAP_CAPTURE ? "capture" : "playback");
2623 if (sndcard==NULL) {
2624 /* get a card that has read+write capabilities */
2625 sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
2626 /* otherwise refine to the first card having the right capability*/
2628 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2629 for(;elem!=NULL;elem=elem->next){
2630 sndcard=(MSSndCard*)elem->data;
2631 if (ms_snd_card_get_capabilities(sndcard) & cap) break;
2634 if (sndcard==NULL){/*looks like a bug! take the first one !*/
2635 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2636 if (elem) sndcard=(MSSndCard*)elem->data;
2639 if (sndcard==NULL) ms_error("Could not find a suitable soundcard !");
2644 * Returns true if the specified sound device can capture sound.
2646 * @ingroup media_parameters
2647 * @param devid the device name as returned by linphone_core_get_sound_devices()
2649 bool_t linphone_core_sound_device_can_capture(LinphoneCore *lc, const char *devid){
2651 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2652 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_CAPTURE)) return TRUE;
2657 * Returns true if the specified sound device can play sound.
2659 * @ingroup media_parameters
2660 * @param devid the device name as returned by linphone_core_get_sound_devices()
2662 bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *devid){
2664 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2665 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_PLAYBACK)) return TRUE;
2670 * Sets the sound device used for ringing.
2672 * @ingroup media_parameters
2673 * @param devid the device name as returned by linphone_core_get_sound_devices()
2675 int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
2676 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2677 lc->sound_conf.ring_sndcard=card;
2678 if (card && lc->ready)
2679 lp_config_set_string(lc->config,"sound","ringer_dev_id",ms_snd_card_get_string_id(card));
2684 * Sets the sound device used for playback.
2686 * @ingroup media_parameters
2687 * @param devid the device name as returned by linphone_core_get_sound_devices()
2689 int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
2690 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2691 lc->sound_conf.play_sndcard=card;
2692 if (card && lc->ready)
2693 lp_config_set_string(lc->config,"sound","playback_dev_id",ms_snd_card_get_string_id(card));
2698 * Sets the sound device used for capture.
2700 * @ingroup media_parameters
2701 * @param devid the device name as returned by linphone_core_get_sound_devices()
2703 int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
2704 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_CAPTURE);
2705 lc->sound_conf.capt_sndcard=card;
2706 if (card && lc->ready)
2707 lp_config_set_string(lc->config,"sound","capture_dev_id",ms_snd_card_get_string_id(card));
2712 * Returns the name of the currently assigned sound device for ringing.
2714 * @ingroup media_parameters
2716 const char * linphone_core_get_ringer_device(LinphoneCore *lc)
2718 if (lc->sound_conf.ring_sndcard) return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
2723 * Returns the name of the currently assigned sound device for playback.
2725 * @ingroup media_parameters
2727 const char * linphone_core_get_playback_device(LinphoneCore *lc)
2729 return lc->sound_conf.play_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.play_sndcard) : NULL;
2733 * Returns the name of the currently assigned sound device for capture.
2735 * @ingroup media_parameters
2737 const char * linphone_core_get_capture_device(LinphoneCore *lc)
2739 return lc->sound_conf.capt_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard) : NULL;
2743 * Returns an unmodifiable array of available sound devices.
2745 * @ingroup media_parameters
2746 * The array is NULL terminated.
2748 const char** linphone_core_get_sound_devices(LinphoneCore *lc){
2749 build_sound_devices_table(lc);
2750 return lc->sound_conf.cards;
2754 * Returns an unmodifiable array of available video capture devices.
2756 * @ingroup media_parameters
2757 * The array is NULL terminated.
2759 const char** linphone_core_get_video_devices(const LinphoneCore *lc){
2760 return lc->video_conf.cams;
2763 char linphone_core_get_sound_source(LinphoneCore *lc)
2765 return lc->sound_conf.source;
2768 void linphone_core_set_sound_source(LinphoneCore *lc, char source)
2770 MSSndCard *sndcard=lc->sound_conf.capt_sndcard;
2771 lc->sound_conf.source=source;
2772 if (!sndcard) return;
2775 ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
2778 ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
2786 * Sets the path to a wav file used for ringing.
2788 * The file must be a wav 16bit linear.
2790 * @ingroup media_parameters
2792 void linphone_core_set_ring(LinphoneCore *lc,const char *path){
2793 if (lc->sound_conf.local_ring!=0){
2794 ms_free(lc->sound_conf.local_ring);
2796 lc->sound_conf.local_ring=ms_strdup(path);
2797 if (lc->ready && lc->sound_conf.local_ring)
2798 lp_config_set_string(lc->config,"sound","local_ring",lc->sound_conf.local_ring);
2802 * Returns the path to the wav file used for ringing.
2804 * @ingroup media_parameters
2806 const char *linphone_core_get_ring(const LinphoneCore *lc){
2807 return lc->sound_conf.local_ring;
2810 static void notify_end_of_ring(void *ud ,unsigned int event, void * arg){
2811 LinphoneCore *lc=(LinphoneCore*)ud;
2812 lc->preview_finished=1;
2815 int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata)
2817 if (lc->ringstream!=0){
2818 ms_warning("Cannot start ring now,there's already a ring being played");
2821 lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
2822 lc->preview_finished=0;
2823 if (lc->sound_conf.ring_sndcard!=NULL){
2824 lc->ringstream=ring_start_with_cb(ring,2000,lc->sound_conf.ring_sndcard,notify_end_of_ring,(void *)lc);
2830 * Sets the path to a wav file used for ringing back.
2832 * Ringback means the ring that is heard when it's ringing at the remote party.
2833 * The file must be a wav 16bit linear.
2835 * @ingroup media_parameters
2837 void linphone_core_set_ringback(LinphoneCore *lc, const char *path){
2838 if (lc->sound_conf.remote_ring!=0){
2839 ms_free(lc->sound_conf.remote_ring);
2841 lc->sound_conf.remote_ring=ms_strdup(path);
2845 * Returns the path to the wav file used for ringing back.
2847 * @ingroup media_parameters
2849 const char * linphone_core_get_ringback(const LinphoneCore *lc){
2850 return lc->sound_conf.remote_ring;
2854 * Enables or disable echo cancellation.
2856 * @ingroup media_parameters
2858 void linphone_core_enable_echo_cancellation(LinphoneCore *lc, bool_t val){
2859 lc->sound_conf.ec=val;
2861 lp_config_set_int(lc->config,"sound","echocancellation",val);
2865 * Returns TRUE if echo cancellation is enabled.
2867 * @ingroup media_parameters
2869 bool_t linphone_core_echo_cancellation_enabled(LinphoneCore *lc){
2870 return lc->sound_conf.ec;
2873 void linphone_core_enable_echo_limiter(LinphoneCore *lc, bool_t val){
2874 lc->sound_conf.ea=val;
2877 bool_t linphone_core_echo_limiter_enabled(const LinphoneCore *lc){
2878 return lc->sound_conf.ea;
2882 * Mutes or unmutes the local microphone.
2884 * @ingroup media_parameters
2886 void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){
2887 if (lc->audiostream!=NULL){
2888 audio_stream_set_mic_gain(lc->audiostream,
2889 (val==TRUE) ? 0 : 1.0);
2893 bool_t linphone_core_is_mic_muted(LinphoneCore *lc) {
2895 if (lc->audiostream && lc->audiostream->volsend){
2896 ms_filter_call_method(lc->audiostream->volsend,MS_VOLUME_GET_GAIN,&gain);
2897 }else ms_warning("Could not get gain: gain control wasn't activated. ");
2902 void linphone_core_enable_agc(LinphoneCore *lc, bool_t val){
2903 lc->sound_conf.agc=val;
2906 bool_t linphone_core_agc_enabled(const LinphoneCore *lc){
2907 return lc->sound_conf.agc;
2911 * Send the specified dtmf.
2913 * @ingroup media_parameters
2914 * This function only works during calls. The dtmf is automatically played to the user.
2915 * @param lc The LinphoneCore object
2916 * @param dtmf The dtmf name specified as a char, such as '0', '#' etc...
2919 void linphone_core_send_dtmf(LinphoneCore *lc, char dtmf)
2921 /*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
2922 if (linphone_core_get_use_rfc2833_for_dtmf(lc)!=0 || linphone_core_get_use_info_for_dtmf(lc)==0)
2925 if (lc->audiostream!=NULL){
2926 audio_stream_send_dtmf(lc->audiostream,dtmf);
2930 ms_error("we cannot send RFC2833 dtmf when we are not in communication");
2933 if (linphone_core_get_use_info_for_dtmf(lc)!=0){
2934 /* Out of Band DTMF (use INFO method) */
2935 LinphoneCall *call=linphone_core_get_current_call(lc);
2939 sal_call_send_dtmf(call->op,dtmf);
2943 void linphone_core_set_stun_server(LinphoneCore *lc, const char *server){
2944 if (lc->net_conf.stun_server!=NULL)
2945 ms_free(lc->net_conf.stun_server);
2947 lc->net_conf.stun_server=ms_strdup(server);
2948 else lc->net_conf.stun_server=NULL;
2951 const char * linphone_core_get_stun_server(const LinphoneCore *lc){
2952 return lc->net_conf.stun_server;
2955 const char * linphone_core_get_relay_addr(const LinphoneCore *lc){
2956 return lc->net_conf.relay;
2959 int linphone_core_set_relay_addr(LinphoneCore *lc, const char *addr){
2960 if (lc->net_conf.relay!=NULL){
2961 ms_free(lc->net_conf.relay);
2962 lc->net_conf.relay=NULL;
2965 lc->net_conf.relay=ms_strdup(addr);
2970 void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
2972 if (lc->net_conf.nat_address!=NULL){
2973 ms_free(lc->net_conf.nat_address);
2975 if (addr!=NULL) lc->net_conf.nat_address=ms_strdup(addr);
2976 else lc->net_conf.nat_address=NULL;
2977 if (lc->sip_conf.contact) update_primary_contact(lc);
2980 const char *linphone_core_get_nat_address(const LinphoneCore *lc)
2982 return lc->net_conf.nat_address;
2985 void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
2986 lc->net_conf.firewall_policy=pol;
2987 if (lc->sip_conf.contact) update_primary_contact(lc);
2990 LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
2991 return lc->net_conf.firewall_policy;
2995 * Get the list of call logs (past calls).
2997 * @ingroup call_logs
2999 const MSList * linphone_core_get_call_logs(LinphoneCore *lc){
3001 return lc->call_logs;
3005 * Erase the call log.
3007 * @ingroup call_logs
3009 void linphone_core_clear_call_logs(LinphoneCore *lc){
3011 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3012 lc->call_logs=ms_list_free(lc->call_logs);
3013 call_logs_write_to_config_file(lc);
3016 static void toggle_video_preview(LinphoneCore *lc, bool_t val){
3017 #ifdef VIDEO_ENABLED
3018 if (lc->videostream==NULL){
3020 if (lc->previewstream==NULL){
3021 lc->previewstream=video_preview_start(lc->video_conf.device,
3022 lc->video_conf.vsize);
3025 if (lc->previewstream!=NULL){
3026 video_preview_stop(lc->previewstream);
3027 lc->previewstream=NULL;
3035 * Enables video globally.
3037 * @ingroup media_parameters
3038 * This function does not have any effect during calls. It just indicates LinphoneCore to
3039 * initiate future calls with video or not. The two boolean parameters indicate in which
3040 * direction video is enabled. Setting both to false disables video entirely.
3042 * @param vcap_enabled indicates whether video capture is enabled
3043 * @param display_enabled indicates whether video display should be shown
3046 void linphone_core_enable_video(LinphoneCore *lc, bool_t vcap_enabled, bool_t display_enabled){
3047 #ifndef VIDEO_ENABLED
3048 if (vcap_enabled || display_enabled)
3049 ms_warning("This version of linphone was built without video support.");
3051 lc->video_conf.capture=vcap_enabled;
3052 lc->video_conf.display=display_enabled;
3054 /* need to re-apply network bandwidth settings*/
3055 linphone_core_set_download_bandwidth(lc,
3056 linphone_core_get_download_bandwidth(lc));
3057 linphone_core_set_upload_bandwidth(lc,
3058 linphone_core_get_upload_bandwidth(lc));
3062 * Returns TRUE if video is enabled, FALSE otherwise.
3063 * @ingroup media_parameters
3065 bool_t linphone_core_video_enabled(LinphoneCore *lc){
3066 return (lc->video_conf.display || lc->video_conf.capture);
3070 * Controls video preview enablement.
3072 * @ingroup media_parameters
3073 * Video preview refers to the action of displaying the local webcam image
3074 * to the user while not in call.
3076 void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val){
3077 lc->video_conf.show_local=val;
3081 * Returns TRUE if video previewing is enabled.
3082 * @ingroup media_parameters
3084 bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
3085 return lc->video_conf.show_local;
3089 * Enables or disable self view during calls.
3091 * @ingroup media_parameters
3092 * Self-view refers to having local webcam image inserted in corner
3093 * of the video window during calls.
3094 * This function works at any time, including during calls.
3096 void linphone_core_enable_self_view(LinphoneCore *lc, bool_t val){
3097 lc->video_conf.selfview=val;
3098 #ifdef VIDEO_ENABLED
3099 if (lc->videostream){
3100 video_stream_enable_self_view(lc->videostream,val);
3106 * Returns TRUE if self-view is enabled, FALSE otherwise.
3108 * @ingroup media_parameters
3110 * Refer to linphone_core_enable_self_view() for details.
3112 bool_t linphone_core_self_view_enabled(const LinphoneCore *lc){
3113 return lc->video_conf.selfview;
3117 * Sets the active video device.
3119 * @ingroup media_parameters
3120 * @param id the name of the video device as returned by linphone_core_get_video_devices()
3122 int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
3123 MSWebCam *olddev=lc->video_conf.device;
3126 lc->video_conf.device=ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),id);
3127 if (lc->video_conf.device==NULL){
3128 ms_warning("Could not found video device %s",id);
3131 if (lc->video_conf.device==NULL)
3132 lc->video_conf.device=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());
3133 if (olddev!=NULL && olddev!=lc->video_conf.device){
3134 toggle_video_preview(lc,FALSE);/*restart the video local preview*/
3136 if (lc->ready && lc->video_conf.device){
3137 vd=ms_web_cam_get_string_id(lc->video_conf.device);
3138 if (vd && strstr(vd,"Static picture")!=NULL){
3141 lp_config_set_string(lc->config,"video","device",vd);
3147 * Returns the name of the currently active video device.
3149 * @ingroup media_parameters
3151 const char *linphone_core_get_video_device(const LinphoneCore *lc){
3152 if (lc->video_conf.device) return ms_web_cam_get_string_id(lc->video_conf.device);
3156 int linphone_core_set_static_picture(LinphoneCore *lc, const char *path) {
3157 #ifdef VIDEO_ENABLED
3158 VideoStream *vs = NULL;
3159 /* Select the video stream from the call in the first place */
3160 if (lc && lc->videostream) {
3161 vs = lc->videostream;
3163 /* If not in call, select the video stream from the preview */
3164 if (vs == NULL && lc && lc->previewstream) {
3165 vs = lc->previewstream;
3168 /* If we have a video stream (either preview, either from call), we
3169 have a source and it is using the static picture filter, then
3170 force the filter to use that picture. */
3171 if (vs && vs->source) {
3172 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3173 ms_filter_call_method(vs->source, MS_FILTER_SET_IMAGE,
3178 /* Tell the static image filter to use that image from now on so
3179 that the image will be used next time it has to be read */
3180 ms_static_image_set_default_image(path);
3182 ms_warning("Video support not compiled.");
3188 * Returns the native window handle of the video window, casted as an unsigned long.
3190 * @ingroup media_parameters
3192 unsigned long linphone_core_get_native_video_window_id(const LinphoneCore *lc){
3193 #ifdef VIDEO_ENABLED
3194 if (lc->videostream)
3195 return video_stream_get_native_window_id(lc->videostream);
3196 if (lc->previewstream)
3197 return video_stream_get_native_window_id(lc->previewstream);
3202 static MSVideoSizeDef supported_resolutions[]={
3203 { {MS_VIDEO_SIZE_SVGA_W,MS_VIDEO_SIZE_SVGA_H} , "svga" },
3204 { {MS_VIDEO_SIZE_4CIF_W,MS_VIDEO_SIZE_4CIF_H} , "4cif" },
3205 { {MS_VIDEO_SIZE_VGA_W,MS_VIDEO_SIZE_VGA_H} , "vga" },
3206 { {MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H} , "cif" },
3207 { {MS_VIDEO_SIZE_QVGA_W,MS_VIDEO_SIZE_QVGA_H} , "qvga" },
3208 { {MS_VIDEO_SIZE_QCIF_W,MS_VIDEO_SIZE_QCIF_H} , "qcif" },
3213 * Returns the zero terminated table of supported video resolutions.
3215 * @ingroup media_parameters
3217 const MSVideoSizeDef *linphone_core_get_supported_video_sizes(LinphoneCore *lc){
3218 return supported_resolutions;
3221 static MSVideoSize video_size_get_by_name(const char *name){
3222 MSVideoSizeDef *pdef=supported_resolutions;
3223 MSVideoSize null_vsize={0,0};
3224 for(;pdef->name!=NULL;pdef++){
3225 if (strcasecmp(name,pdef->name)==0){
3229 ms_warning("Video resolution %s is not supported in linphone.",name);
3233 static const char *video_size_get_name(MSVideoSize vsize){
3234 MSVideoSizeDef *pdef=supported_resolutions;
3235 for(;pdef->name!=NULL;pdef++){
3236 if (pdef->vsize.width==vsize.width && pdef->vsize.height==vsize.height){
3243 static bool_t video_size_supported(MSVideoSize vsize){
3244 if (video_size_get_name(vsize)) return TRUE;
3245 ms_warning("Video resolution %ix%i is not supported in linphone.",vsize.width,vsize.height);
3250 * Sets the preferred video size.
3252 * @ingroup media_parameters
3253 * This applies only to the stream that is captured and sent to the remote party,
3254 * since we accept all standard video size on the receive path.
3256 void linphone_core_set_preferred_video_size(LinphoneCore *lc, MSVideoSize vsize){
3257 if (video_size_supported(vsize)){
3258 MSVideoSize oldvsize=lc->video_conf.vsize;
3259 lc->video_conf.vsize=vsize;
3260 if (!ms_video_size_equal(oldvsize,vsize) && lc->previewstream!=NULL){
3261 toggle_video_preview(lc,FALSE);
3262 toggle_video_preview(lc,TRUE);
3265 lp_config_set_string(lc->config,"video","size",video_size_get_name(vsize));
3270 * Sets the preferred video size by its name.
3272 * @ingroup media_parameters
3273 * This is identical to linphone_core_set_preferred_video_size() except
3274 * that it takes the name of the video resolution as input.
3275 * Video resolution names are: qcif, svga, cif, vga, 4cif, svga ...
3277 void linphone_core_set_preferred_video_size_by_name(LinphoneCore *lc, const char *name){
3278 MSVideoSize vsize=video_size_get_by_name(name);
3279 MSVideoSize default_vsize={MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H};
3280 if (vsize.width!=0) linphone_core_set_preferred_video_size(lc,vsize);
3281 else linphone_core_set_preferred_video_size(lc,default_vsize);
3285 * Returns the current preferred video size for sending.
3287 * @ingroup media_parameters
3289 MSVideoSize linphone_core_get_preferred_video_size(LinphoneCore *lc){
3290 return lc->video_conf.vsize;
3293 void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
3294 lc->use_files=yesno;
3297 void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
3298 if (lc->play_file!=NULL){
3299 ms_free(lc->play_file);
3303 lc->play_file=ms_strdup(file);
3304 if (lc->audiostream->ticker)
3305 audio_stream_play(lc->audiostream,file);
3309 void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
3310 if (lc->rec_file!=NULL){
3311 ms_free(lc->rec_file);
3315 lc->rec_file=ms_strdup(file);
3316 if (lc->audiostream)
3317 audio_stream_record(lc->audiostream,file);
3322 * Retrieves the user pointer that was given to linphone_core_new()
3324 * @ingroup initializing
3326 void *linphone_core_get_user_data(LinphoneCore *lc){
3330 int linphone_core_get_mtu(const LinphoneCore *lc){
3331 return lc->net_conf.mtu;
3334 void linphone_core_set_mtu(LinphoneCore *lc, int mtu){
3335 lc->net_conf.mtu=mtu;
3338 ms_error("MTU too small !");
3342 ms_message("MTU is supposed to be %i, rtp payload max size will be %i",mtu, ms_get_payload_max_size());
3343 }else ms_set_mtu(0);//use mediastreamer2 default value
3346 void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context){
3348 lc->wait_ctx=user_context;
3351 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose){
3353 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingStart,purpose,0);
3357 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progress){
3359 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingProgress,purpose,progress);
3369 void linphone_core_stop_waiting(LinphoneCore *lc){
3371 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingFinished,NULL,0);
3375 void linphone_core_set_audio_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3380 void net_config_uninit(LinphoneCore *lc)
3382 net_config_t *config=&lc->net_conf;
3383 lp_config_set_int(lc->config,"net","download_bw",config->download_bw);
3384 lp_config_set_int(lc->config,"net","upload_bw",config->upload_bw);
3386 if (config->stun_server!=NULL){
3387 lp_config_set_string(lc->config,"net","stun_server",config->stun_server);
3388 ms_free(lc->net_conf.stun_server);
3390 if (config->nat_address!=NULL){
3391 lp_config_set_string(lc->config,"net","nat_address",config->nat_address);
3392 ms_free(lc->net_conf.nat_address);
3394 lp_config_set_int(lc->config,"net","firewall_policy",config->firewall_policy);
3395 lp_config_set_int(lc->config,"net","mtu",config->mtu);
3399 void sip_config_uninit(LinphoneCore *lc)
3403 sip_config_t *config=&lc->sip_conf;
3404 lp_config_set_int(lc->config,"sip","sip_port",config->sip_port);
3405 lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
3406 lp_config_set_string(lc->config,"sip","contact",config->contact);
3407 lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
3408 lp_config_set_int(lc->config,"sip","use_info",config->use_info);
3409 lp_config_set_int(lc->config,"sip","use_rfc2833",config->use_rfc2833);
3410 lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
3411 lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
3413 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
3415 for(elem=config->proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3416 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
3417 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
3418 linphone_proxy_config_edit(cfg); /* to unregister */
3424 sal_iterate(lc->sal);
3433 ms_list_for_each(config->proxies,(void (*)(void*)) linphone_proxy_config_destroy);
3434 ms_list_free(config->proxies);
3435 config->proxies=NULL;
3437 linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */
3439 for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3440 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
3441 linphone_auth_info_write_config(lc->config,ai,i);
3443 linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
3444 ms_list_for_each(lc->auth_info,(void (*)(void*))linphone_auth_info_destroy);
3445 ms_list_free(lc->auth_info);
3448 sal_uninit(lc->sal);
3451 if (lc->sip_conf.guessed_contact)
3452 ms_free(lc->sip_conf.guessed_contact);
3453 if (config->contact)
3454 ms_free(config->contact);
3458 void rtp_config_uninit(LinphoneCore *lc)
3460 rtp_config_t *config=&lc->rtp_conf;
3461 lp_config_set_int(lc->config,"rtp","audio_rtp_port",config->audio_rtp_port);
3462 lp_config_set_int(lc->config,"rtp","video_rtp_port",config->video_rtp_port);
3463 lp_config_set_int(lc->config,"rtp","audio_jitt_comp",config->audio_jitt_comp);
3464 lp_config_set_int(lc->config,"rtp","video_jitt_comp",config->video_jitt_comp);
3465 lp_config_set_int(lc->config,"rtp","nortp_timeout",config->nortp_timeout);
3468 void sound_config_uninit(LinphoneCore *lc)
3470 sound_config_t *config=&lc->sound_conf;
3471 ms_free(config->cards);
3473 lp_config_set_string(lc->config,"sound","remote_ring",config->remote_ring);
3475 if (config->local_ring) ms_free(config->local_ring);
3476 if (config->remote_ring) ms_free(config->remote_ring);
3477 ms_snd_card_manager_destroy();
3480 void video_config_uninit(LinphoneCore *lc)
3482 lp_config_set_int(lc->config,"video","enabled",linphone_core_video_enabled(lc));
3483 lp_config_set_string(lc->config,"video","size",video_size_get_name(linphone_core_get_preferred_video_size(lc)));
3484 lp_config_set_int(lc->config,"video","display",lc->video_conf.display);
3485 lp_config_set_int(lc->config,"video","capture",lc->video_conf.capture);
3486 lp_config_set_int(lc->config,"video","show_local",linphone_core_video_preview_enabled(lc));
3487 lp_config_set_int(lc->config,"video","self_view",linphone_core_self_view_enabled(lc));
3488 if (lc->video_conf.cams)
3489 ms_free(lc->video_conf.cams);
3492 void codecs_config_uninit(LinphoneCore *lc)
3495 codecs_config_t *config=&lc->codecs_conf;
3500 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
3501 pt=(PayloadType*)(node->data);
3502 sprintf(key,"audio_codec_%i",index);
3503 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3504 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3505 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3509 for(node=config->video_codecs;node!=NULL;node=ms_list_next(node)){
3510 pt=(PayloadType*)(node->data);
3511 sprintf(key,"video_codec_%i",index);
3512 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3513 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3514 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3515 lp_config_set_string(lc->config,key,"recv_fmtp",pt->recv_fmtp);
3518 ms_list_free(lc->codecs_conf.audio_codecs);
3519 ms_list_free(lc->codecs_conf.video_codecs);
3522 void ui_config_uninit(LinphoneCore* lc)
3525 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_destroy);
3526 ms_list_free(lc->friends);
3532 * Returns the LpConfig object used to manage the storage (config) file.
3535 * The application can use the LpConfig object to insert its own private
3536 * sections and pairs of key=value in the configuration file.
3539 LpConfig *linphone_core_get_config(LinphoneCore *lc){
3543 static void linphone_core_uninit(LinphoneCore *lc)
3545 if(linphone_core_get_calls_nb(lc)){
3547 linphone_core_terminate_all_calls(lc);
3554 linphone_core_iterate(lc);
3558 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions);
3559 gstate_new_state(lc, GSTATE_POWER_SHUTDOWN, NULL);
3560 #ifdef VIDEO_ENABLED
3561 if (lc->previewstream!=NULL){
3562 video_preview_stop(lc->previewstream);
3563 lc->previewstream=NULL;
3566 /* save all config */
3567 net_config_uninit(lc);
3568 sip_config_uninit(lc);
3569 rtp_config_uninit(lc);
3570 sound_config_uninit(lc);
3571 video_config_uninit(lc);
3572 codecs_config_uninit(lc);
3573 ui_config_uninit(lc);
3574 if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
3575 lp_config_destroy(lc->config);
3576 lc->config = NULL; /* Mark the config as NULL to block further calls */
3577 sip_setup_unregister_all();
3579 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3580 lc->call_logs=ms_list_free(lc->call_logs);
3582 linphone_core_free_payload_types();
3585 gstate_new_state(lc, GSTATE_POWER_OFF, NULL);
3588 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable){
3589 ms_message("Network state is now [%s]",isReachable?"UP":"DOWN");
3590 // second get the list of available proxies
3591 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3592 for(;elem!=NULL;elem=elem->next){
3593 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3594 if (linphone_proxy_config_register_enabled(cfg) ) {
3602 lc->network_reachable=isReachable;
3605 void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) {
3606 //first disable automatic mode
3607 if (lc->auto_net_state_mon) {
3608 ms_message("Disabling automatic network state monitoring");
3609 lc->auto_net_state_mon=FALSE;
3611 set_network_reachable(lc,isReachable);
3614 bool_t linphone_core_is_network_reachabled(LinphoneCore* lc) {
3615 return lc->network_reachable;
3617 ortp_socket_t linphone_core_get_sip_socket(LinphoneCore *lc){
3618 return sal_get_socket(lc->sal);
3621 * Destroys a LinphoneCore
3623 * @ingroup initializing
3625 void linphone_core_destroy(LinphoneCore *lc){
3626 linphone_core_uninit(lc);
3630 * Get the number of Call
3632 * @ingroup call_control
3634 int linphone_core_get_calls_nb(const LinphoneCore *lc)
3637 if(lc->calls == NULL)
3643 returned = ms_list_size(lc->calls);
3649 * Check if we do not have exceed the number of simultaneous call
3651 * @ingroup call_control
3653 bool_t linphone_core_can_we_add_call(LinphoneCore *lc)
3655 if(linphone_core_get_calls_nb(lc) < NB_MAX_CALLS)
3661 * Unset the current call
3663 * @ingroup call_control
3665 int linphone_core_unset_the_current_call(LinphoneCore *lc)
3667 if(lc->current_call == NULL)
3669 lc->current_call = NULL;
3670 ms_message("Current call unset\n");
3675 * Set the call in parameter as the new current call
3677 * @ingroup call_control
3679 int linphone_core_set_as_current_call(LinphoneCore *lc, LinphoneCall *call)
3681 if(lc->current_call != NULL)
3683 lc->current_call = call;
3688 * Add the call in the LinphoneCall list
3690 * @ingroup call_control
3692 int linphone_core_add_call( LinphoneCore *lc, LinphoneCall *call)
3694 if(linphone_core_can_we_add_call(lc))
3696 MSList *the_calls = lc->calls;
3697 the_calls = ms_list_append(the_calls,(void *)call);
3698 lc->calls = the_calls;
3705 * Add the call in the LinphoneCall list
3707 * @ingroup call_control
3709 int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call)
3713 MSList *the_calls = lc->calls;
3714 if(call == linphone_core_get_current_call(lc))
3716 linphone_core_unset_the_current_call(lc);
3718 it=ms_list_find(the_calls,call);
3721 the_calls = ms_list_remove_link(the_calls,it);
3725 ms_warning("could not find the call into the list\n");
3728 lc->calls = the_calls;