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"
25 #include <ortp/telephonyevents.h>
26 #include "mediastreamer2/mediastream.h"
27 #include "mediastreamer2/mseventqueue.h"
28 #include "mediastreamer2/msvolume.h"
29 #include "mediastreamer2/msequalizer.h"
30 #include "mediastreamer2/dtmfgen.h"
38 /*#define UNSTANDART_GSM_11K 1*/
40 static const char *liblinphone_version=LIBLINPHONE_VERSION;
41 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t curtime);
45 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result);
46 static void toggle_video_preview(LinphoneCore *lc, bool_t val);
48 /* relative path where is stored local ring*/
49 #define LOCAL_RING "rings/oldphone.wav"
50 /* same for remote ring (ringback)*/
51 #define REMOTE_RING "ringback.wav"
52 #define HOLD_MUSIC "rings/toy-mono.wav"
55 extern SalCallbacks linphone_sal_callbacks;
58 void lc_callback_obj_init(LCCallbackObj *obj,LinphoneCoreCbFunc func,void* ud)
64 int lc_callback_obj_invoke(LCCallbackObj *obj, LinphoneCore *lc){
65 if (obj->_func!=NULL) obj->_func(lc,obj->_user_data);
70 /*prevent a gcc bug with %c*/
71 static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm){
72 #if !defined(_WIN32_WCE)
73 return strftime(s, max, fmt, tm);
80 static void set_call_log_date(LinphoneCallLog *cl, const struct tm *loctime){
81 my_strftime(cl->start_date,sizeof(cl->start_date),"%c",loctime);
84 LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
85 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
89 #if !defined(_WIN32_WCE)
90 loctime=*localtime(&call->start_time);
94 localtime_r(&call->start_time,&loctime);
96 set_call_log_date(cl,&loctime);
102 static void call_logs_write_to_config_file(LinphoneCore *lc){
107 LpConfig *cfg=lc->config;
109 if (linphone_core_get_global_state (lc)==LinphoneGlobalStartup) return;
111 for(i=0,elem=lc->call_logs;elem!=NULL;elem=elem->next,++i){
112 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
113 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
114 lp_config_set_int(cfg,logsection,"dir",cl->dir);
115 lp_config_set_int(cfg,logsection,"status",cl->status);
116 tmp=linphone_address_as_string(cl->from);
117 lp_config_set_string(cfg,logsection,"from",tmp);
119 tmp=linphone_address_as_string(cl->to);
120 lp_config_set_string(cfg,logsection,"to",tmp);
122 lp_config_set_string(cfg,logsection,"start_date",cl->start_date);
123 lp_config_set_int(cfg,logsection,"duration",cl->duration);
124 if (cl->refkey) lp_config_set_string(cfg,logsection,"refkey",cl->refkey);
126 for(;i<lc->max_call_logs;++i){
127 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
128 lp_config_clean_section(cfg,logsection);
132 static void call_logs_read_from_config_file(LinphoneCore *lc){
136 LpConfig *cfg=lc->config;
138 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
139 if (lp_config_has_section(cfg,logsection)){
140 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
141 cl->dir=lp_config_get_int(cfg,logsection,"dir",0);
142 cl->status=lp_config_get_int(cfg,logsection,"status",0);
143 tmp=lp_config_get_string(cfg,logsection,"from",NULL);
144 if (tmp) cl->from=linphone_address_new(tmp);
145 tmp=lp_config_get_string(cfg,logsection,"to",NULL);
146 if (tmp) cl->to=linphone_address_new(tmp);
147 tmp=lp_config_get_string(cfg,logsection,"start_date",NULL);
148 if (tmp) strncpy(cl->start_date,tmp,sizeof(cl->start_date));
149 cl->duration=lp_config_get_int(cfg,logsection,"duration",0);
150 tmp=lp_config_get_string(cfg,logsection,"refkey",NULL);
151 if (tmp) cl->refkey=ms_strdup(tmp);
152 lc->call_logs=ms_list_append(lc->call_logs,cl);
158 void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call, LinphoneCallStatus status){
159 LinphoneCore *lc=call->core;
161 calllog->duration=time(NULL)-call->start_time;
163 if (status==LinphoneCallMissed){
166 info=ortp_strdup_printf(ngettext("You have missed %i call.",
167 "You have missed %i calls.", lc->missed_calls),
169 if (lc->vtable.display_status!=NULL)
170 lc->vtable.display_status(lc,info);
172 }else calllog->status=status;
173 lc->call_logs=ms_list_prepend(lc->call_logs,(void *)calllog);
174 if (ms_list_size(lc->call_logs)>lc->max_call_logs){
175 MSList *elem,*prevelem=NULL;
176 /*find the last element*/
177 for(elem=lc->call_logs;elem!=NULL;elem=elem->next){
181 linphone_call_log_destroy((LinphoneCallLog*)elem->data);
182 lc->call_logs=ms_list_remove_link(lc->call_logs,elem);
184 if (lc->vtable.call_log_updated!=NULL){
185 lc->vtable.call_log_updated(lc,calllog);
187 call_logs_write_to_config_file(lc);
191 * @addtogroup call_logs
196 * Returns a human readable string describing the call.
198 * @note: the returned char* must be freed by the application (use ms_free()).
200 char * linphone_call_log_to_str(LinphoneCallLog *cl){
203 char *from=linphone_address_as_string (cl->from);
204 char *to=linphone_address_as_string (cl->to);
206 case LinphoneCallAborted:
209 case LinphoneCallSuccess:
210 status=_("completed");
212 case LinphoneCallMissed:
218 tmp=ortp_strdup_printf(_("%s at %s\nFrom: %s\nTo: %s\nStatus: %s\nDuration: %i mn %i sec\n"),
219 (cl->dir==LinphoneCallIncoming) ? _("Incoming call") : _("Outgoing call"),
232 * Returns RTP statistics computed locally regarding the call.
235 const rtp_stats_t *linphone_call_log_get_local_stats(const LinphoneCallLog *cl){
236 return &cl->local_stats;
240 * Returns RTP statistics computed by remote end and sent back via RTCP.
242 * @note Not implemented yet.
244 const rtp_stats_t *linphone_call_log_get_remote_stats(const LinphoneCallLog *cl){
245 return &cl->remote_stats;
248 void linphone_call_log_set_user_pointer(LinphoneCallLog *cl, void *up){
252 void *linphone_call_log_get_user_pointer(const LinphoneCallLog *cl){
253 return cl->user_pointer;
259 * Associate a persistent reference key to the call log.
261 * The reference key can be for example an id to an external database.
262 * It is stored in the config file, thus can survive to process exits/restarts.
265 void linphone_call_log_set_ref_key(LinphoneCallLog *cl, const char *refkey){
266 if (cl->refkey!=NULL){
270 if (refkey) cl->refkey=ms_strdup(refkey);
271 call_logs_write_to_config_file(cl->lc);
275 * Get the persistent reference key associated to the call log.
277 * The reference key can be for example an id to an external database.
278 * It is stored in the config file, thus can survive to process exits/restarts.
281 const char *linphone_call_log_get_ref_key(const LinphoneCallLog *cl){
287 void linphone_call_log_destroy(LinphoneCallLog *cl){
288 if (cl->from!=NULL) linphone_address_destroy(cl->from);
289 if (cl->to!=NULL) linphone_address_destroy(cl->to);
290 if (cl->refkey!=NULL) ms_free(cl->refkey);
295 * Returns TRUE if the LinphoneCall asked to autoanswer
298 bool_t linphone_call_asked_to_autoanswer(LinphoneCall *call){
299 //return TRUE if the unique(for the moment) incoming call asked to be autoanswered
301 return sal_call_autoanswer_asked(call->op);
306 int linphone_core_get_current_call_duration(const LinphoneCore *lc){
307 LinphoneCall *call=linphone_core_get_current_call((LinphoneCore *)lc);
308 if (call) return linphone_call_get_duration(call);
312 const LinphoneAddress *linphone_core_get_current_call_remote_address(struct _LinphoneCore *lc){
313 LinphoneCall *call=linphone_core_get_current_call(lc);
314 if (call==NULL) return NULL;
315 return linphone_call_get_remote_address(call);
319 * Enable logs in supplied FILE*.
323 * @param file a C FILE* where to fprintf logs. If null stdout is used.
326 void linphone_core_enable_logs(FILE *file){
327 if (file==NULL) file=stdout;
328 ortp_set_log_file(file);
329 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
333 * Enable logs through the user's supplied log callback.
337 * @param logfunc The address of a OrtpLogFunc callback whose protoype is
338 * typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
341 void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc){
342 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
343 ortp_set_log_handler(logfunc);
347 * Entirely disable logging.
351 void linphone_core_disable_logs(){
352 ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
356 static void net_config_read (LinphoneCore *lc)
360 LpConfig *config=lc->config;
362 tmp=lp_config_get_int(config,"net","download_bw",0);
363 linphone_core_set_download_bandwidth(lc,tmp);
364 tmp=lp_config_get_int(config,"net","upload_bw",0);
365 linphone_core_set_upload_bandwidth(lc,tmp);
366 linphone_core_set_stun_server(lc,lp_config_get_string(config,"net","stun_server",NULL));
367 tmpstr=lp_config_get_string(lc->config,"net","nat_address",NULL);
368 if (tmpstr!=NULL && (strlen(tmpstr)<1)) tmpstr=NULL;
369 linphone_core_set_nat_address(lc,tmpstr);
370 tmp=lp_config_get_int(lc->config,"net","firewall_policy",0);
371 linphone_core_set_firewall_policy(lc,tmp);
372 tmp=lp_config_get_int(lc->config,"net","nat_sdp_only",0);
373 lc->net_conf.nat_sdp_only=tmp;
374 tmp=lp_config_get_int(lc->config,"net","mtu",0);
375 linphone_core_set_mtu(lc,tmp);
376 tmp=lp_config_get_int(lc->config,"net","download_ptime",0);
377 linphone_core_set_download_ptime(lc,tmp);
381 static void build_sound_devices_table(LinphoneCore *lc){
382 const char **devices;
386 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
387 ndev=ms_list_size(elem);
388 devices=ms_malloc((ndev+1)*sizeof(const char *));
389 for (i=0;elem!=NULL;elem=elem->next,i++){
390 devices[i]=ms_snd_card_get_string_id((MSSndCard *)elem->data);
393 old=lc->sound_conf.cards;
394 lc->sound_conf.cards=devices;
395 if (old!=NULL) ms_free(old);
398 static void sound_config_read(LinphoneCore *lc)
405 /*alsadev let the user use custom alsa device within linphone*/
406 devid=lp_config_get_string(lc->config,"sound","alsadev",NULL);
408 MSSndCard *card=ms_alsa_card_new_custom(devid,devid);
409 ms_snd_card_manager_add_card(ms_snd_card_manager_get(),card);
412 /* retrieve all sound devices */
413 build_sound_devices_table(lc);
415 devid=lp_config_get_string(lc->config,"sound","playback_dev_id",NULL);
416 linphone_core_set_playback_device(lc,devid);
418 devid=lp_config_get_string(lc->config,"sound","ringer_dev_id",NULL);
419 linphone_core_set_ringer_device(lc,devid);
421 devid=lp_config_get_string(lc->config,"sound","capture_dev_id",NULL);
422 linphone_core_set_capture_device(lc,devid);
425 tmp=lp_config_get_int(lc->config,"sound","play_lev",80);
426 linphone_core_set_play_level(lc,tmp);
427 tmp=lp_config_get_int(lc->config,"sound","ring_lev",80);
428 linphone_core_set_ring_level(lc,tmp);
429 tmp=lp_config_get_int(lc->config,"sound","rec_lev",80);
430 linphone_core_set_rec_level(lc,tmp);
431 tmpbuf=lp_config_get_string(lc->config,"sound","source","m");
432 linphone_core_set_sound_source(lc,tmpbuf[0]);
435 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
436 tmpbuf=lp_config_get_string(lc->config,"sound","local_ring",tmpbuf);
437 if (ortp_file_exist(tmpbuf)==-1) {
438 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
440 if (strstr(tmpbuf,".wav")==NULL){
441 /* it currently uses old sound files, so replace them */
442 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
445 linphone_core_set_ring(lc,tmpbuf);
447 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
448 tmpbuf=lp_config_get_string(lc->config,"sound","remote_ring",tmpbuf);
449 if (ortp_file_exist(tmpbuf)==-1){
450 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
452 if (strstr(tmpbuf,".wav")==NULL){
453 /* it currently uses old sound files, so replace them */
454 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
456 linphone_core_set_ringback(lc,tmpbuf);
458 linphone_core_set_play_file(lc,lp_config_get_string(lc->config,"sound","hold_music",PACKAGE_SOUND_DIR "/" HOLD_MUSIC));
459 check_sound_device(lc);
460 lc->sound_conf.latency=0;
462 linphone_core_enable_echo_cancellation(lc,
463 lp_config_get_int(lc->config,"sound","echocancelation",0) |
464 lp_config_get_int(lc->config,"sound","echocancellation",0)
467 linphone_core_enable_echo_limiter(lc,
468 lp_config_get_int(lc->config,"sound","echolimiter",0));
469 linphone_core_enable_agc(lc,
470 lp_config_get_int(lc->config,"sound","agc",0));
472 gain=lp_config_get_float(lc->config,"sound","playback_gain_db",0);
473 linphone_core_set_playback_gain_db (lc,gain);
475 linphone_core_set_remote_ringback_tone (lc,lp_config_get_string(lc->config,"sound","ringback_tone",NULL));
478 static void sip_config_read(LinphoneCore *lc)
486 tmp=lp_config_get_int(lc->config,"sip","use_info",0);
487 linphone_core_set_use_info_for_dtmf(lc,tmp);
489 if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
490 sal_use_session_timers(lc->sal,200);
493 tmp=lp_config_get_int(lc->config,"sip","use_rfc2833",0);
494 linphone_core_set_use_rfc2833_for_dtmf(lc,tmp);
496 ipv6=lp_config_get_int(lc->config,"sip","use_ipv6",-1);
499 if (host_has_ipv6_network()){
500 if (lc->vtable.display_message)
501 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"));
504 linphone_core_enable_ipv6(lc,ipv6);
505 memset(&tr,0,sizeof(tr));
506 if (lp_config_get_int(lc->config,"sip","sip_random_port",0)) {
507 tr.udp_port=(0xDFF&+random())+1024;
509 tr.udp_port=lp_config_get_int(lc->config,"sip","sip_port",5060);
511 if (lp_config_get_int(lc->config,"sip","sip_tcp_random_port",0)) {
512 tr.tcp_port=(0xDFF&+random())+1024;
514 tr.tcp_port=lp_config_get_int(lc->config,"sip","sip_tcp_port",0);
516 /*start listening on ports*/
517 linphone_core_set_sip_transports(lc,&tr);
519 tmpstr=lp_config_get_string(lc->config,"sip","contact",NULL);
520 if (tmpstr==NULL || linphone_core_set_primary_contact(lc,tmpstr)==-1) {
521 const char *hostname=NULL;
522 const char *username=NULL;
524 hostname=getenv("HOST");
525 username=getenv("USER");
526 if (hostname==NULL) hostname=getenv("HOSTNAME");
527 #endif /*HAVE_GETENV*/
529 hostname="unknown-host";
533 contact=ortp_strdup_printf("sip:%s@%s",username,hostname);
534 linphone_core_set_primary_contact(lc,contact);
538 tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
539 linphone_core_set_guess_hostname(lc,tmp);
542 tmp=lp_config_get_int(lc->config,"sip","inc_timeout",15);
543 linphone_core_set_inc_timeout(lc,tmp);
545 /* get proxies config */
547 LinphoneProxyConfig *cfg=linphone_proxy_config_new_from_config_file(lc->config,i);
549 linphone_core_add_proxy_config(lc,cfg);
554 /* get the default proxy */
555 tmp=lp_config_get_int(lc->config,"sip","default_proxy",-1);
556 linphone_core_set_default_proxy_index(lc,tmp);
558 /* read authentication information */
560 LinphoneAuthInfo *ai=linphone_auth_info_new_from_config_file(lc->config,i);
562 linphone_core_add_auth_info(lc,ai);
563 linphone_auth_info_destroy(ai);
569 /*for tuning or test*/
570 lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
571 lc->sip_conf.register_only_when_network_is_up=
572 lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",1);
573 lc->sip_conf.ping_with_options=lp_config_get_int(lc->config,"sip","ping_with_options",1);
574 lc->sip_conf.auto_net_state_mon=lp_config_get_int(lc->config,"sip","auto_net_state_mon",1);
575 lc->sip_conf.keepalive_period=lp_config_get_int(lc->config,"sip","keepalive_period",10000);
576 sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
577 sal_use_one_matching_codec_policy(lc->sal,lp_config_get_int(lc->config,"sip","only_one_codec",0));
578 sal_use_double_registrations(lc->sal,lp_config_get_int(lc->config,"sip","use_double_registrations",1));
581 static void rtp_config_read(LinphoneCore *lc)
586 bool_t rtp_no_xmit_on_audio_mute;
588 port=lp_config_get_int(lc->config,"rtp","audio_rtp_port",7078);
589 linphone_core_set_audio_port(lc,port);
591 port=lp_config_get_int(lc->config,"rtp","video_rtp_port",9078);
592 if (port==0) port=9078;
593 linphone_core_set_video_port(lc,port);
595 jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
596 linphone_core_set_audio_jittcomp(lc,jitt_comp);
597 jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
598 if (jitt_comp==0) jitt_comp=60;
599 lc->rtp_conf.video_jitt_comp=jitt_comp;
600 nortp_timeout=lp_config_get_int(lc->config,"rtp","nortp_timeout",30);
601 linphone_core_set_nortp_timeout(lc,nortp_timeout);
602 rtp_no_xmit_on_audio_mute=lp_config_get_int(lc->config,"rtp","rtp_no_xmit_on_audio_mute",FALSE);
603 linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_no_xmit_on_audio_mute);
606 static PayloadType * find_payload(RtpProfile *prof, const char *mime_type, int clock_rate, const char *recv_fmtp){
607 PayloadType *candidate=NULL;
611 it=rtp_profile_get_payload(prof,i);
612 if (it!=NULL && strcasecmp(mime_type,it->mime_type)==0
613 && (clock_rate==it->clock_rate || clock_rate<=0) ){
614 if ( (recv_fmtp && it->recv_fmtp && strstr(recv_fmtp,it->recv_fmtp)!=NULL) ||
615 (recv_fmtp==NULL && it->recv_fmtp==NULL) ){
617 if (recv_fmtp) payload_type_set_recv_fmtp(it,recv_fmtp);
621 if (it->recv_fmtp==NULL) candidate=it;
626 if (candidate && recv_fmtp){
627 payload_type_set_recv_fmtp(candidate,recv_fmtp);
632 static bool_t get_codec(LpConfig *config, const char* type, int index, PayloadType **ret){
634 const char *mime,*fmtp;
639 snprintf(codeckey,50,"%s_%i",type,index);
640 mime=lp_config_get_string(config,codeckey,"mime",NULL);
641 if (mime==NULL || strlen(mime)==0 ) return FALSE;
643 rate=lp_config_get_int(config,codeckey,"rate",8000);
644 fmtp=lp_config_get_string(config,codeckey,"recv_fmtp",NULL);
645 enabled=lp_config_get_int(config,codeckey,"enabled",1);
646 pt=find_payload(&av_profile,mime,rate,fmtp);
647 if (pt && enabled ) pt->flags|=PAYLOAD_TYPE_ENABLED;
648 //ms_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
649 if (pt==NULL) ms_warning("Ignoring codec config %s/%i with fmtp=%s because unsupported",
650 mime,rate,fmtp ? fmtp : "");
655 static const char *codec_pref_order[]={
668 static int find_codec_rank(const char *mime){
670 for(i=0;codec_pref_order[i]!=NULL;++i){
671 if (strcasecmp(codec_pref_order[i],mime)==0)
677 static int codec_compare(const PayloadType *a, const PayloadType *b){
679 ra=find_codec_rank(a->mime_type);
680 rb=find_codec_rank(b->mime_type);
682 if (ra<rb) return -1;
686 static MSList *add_missing_codecs(SalStreamType mtype, MSList *l){
689 PayloadType *pt=rtp_profile_get_payload(&av_profile,i);
691 if (mtype==SalVideo && pt->type!=PAYLOAD_VIDEO)
693 else if (mtype==SalAudio && (pt->type!=PAYLOAD_AUDIO_PACKETIZED
694 && pt->type!=PAYLOAD_AUDIO_CONTINUOUS)){
697 if (pt && ms_filter_codec_supported(pt->mime_type)){
698 if (ms_list_find(l,pt)==NULL){
699 payload_type_set_flag(pt,PAYLOAD_TYPE_ENABLED);
700 ms_message("Adding new codec %s/%i with fmtp %s",
701 pt->mime_type,pt->clock_rate,pt->recv_fmtp ? pt->recv_fmtp : "");
702 l=ms_list_insert_sorted(l,pt,(int (*)(const void *, const void *))codec_compare);
710 static MSList *codec_append_if_new(MSList *l, PayloadType *pt){
712 for (elem=l;elem!=NULL;elem=elem->next){
713 PayloadType *ept=(PayloadType*)elem->data;
717 l=ms_list_append(l,pt);
721 static void codecs_config_read(LinphoneCore *lc)
725 MSList *audio_codecs=NULL;
726 MSList *video_codecs=NULL;
727 for (i=0;get_codec(lc->config,"audio_codec",i,&pt);i++){
729 if (!ms_filter_codec_supported(pt->mime_type)){
730 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
731 }else audio_codecs=codec_append_if_new(audio_codecs,pt);
734 audio_codecs=add_missing_codecs(SalAudio,audio_codecs);
735 for (i=0;get_codec(lc->config,"video_codec",i,&pt);i++){
737 if (!ms_filter_codec_supported(pt->mime_type)){
738 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
739 }else video_codecs=codec_append_if_new(video_codecs,(void *)pt);
742 video_codecs=add_missing_codecs(SalVideo,video_codecs);
743 linphone_core_set_audio_codecs(lc,audio_codecs);
744 linphone_core_set_video_codecs(lc,video_codecs);
745 linphone_core_update_allocated_audio_bandwidth(lc);
748 static void video_config_read(LinphoneCore *lc){
749 int capture, display, self_view;
753 const char **devices;
757 /* retrieve all video devices */
758 elem=ms_web_cam_manager_get_list(ms_web_cam_manager_get());
759 ndev=ms_list_size(elem);
760 devices=ms_malloc((ndev+1)*sizeof(const char *));
761 for (i=0;elem!=NULL;elem=elem->next,i++){
762 devices[i]=ms_web_cam_get_string_id((MSWebCam *)elem->data);
765 lc->video_conf.cams=devices;
767 str=lp_config_get_string(lc->config,"video","device",NULL);
768 if (str && str[0]==0) str=NULL;
769 linphone_core_set_video_device(lc,str);
771 linphone_core_set_preferred_video_size_by_name(lc,
772 lp_config_get_string(lc->config,"video","size","cif"));
774 enabled=lp_config_get_int(lc->config,"video","enabled",1);
775 capture=lp_config_get_int(lc->config,"video","capture",enabled);
776 display=lp_config_get_int(lc->config,"video","display",enabled);
777 self_view=lp_config_get_int(lc->config,"video","self_view",enabled);
778 lc->video_conf.displaytype=lp_config_get_string(lc->config,"video","displaytype",NULL);
779 if(lc->video_conf.displaytype)
780 ms_message("we are using a specific display:%s\n",lc->video_conf.displaytype);
782 linphone_core_enable_video(lc,capture,display);
783 linphone_core_enable_self_view(lc,self_view);
787 static void ui_config_read(LinphoneCore *lc)
791 for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
792 linphone_core_add_friend(lc,lf);
794 call_logs_read_from_config_file(lc);
798 static void autoreplier_config_init(LinphoneCore *lc)
800 autoreplier_config_t *config=&lc->autoreplier_conf;
801 config->enabled=lp_config_get_int(lc->config,"autoreplier","enabled",0);
802 config->after_seconds=lp_config_get_int(lc->config,"autoreplier","after_seconds",6);
803 config->max_users=lp_config_get_int(lc->config,"autoreplier","max_users",1);
804 config->max_rec_time=lp_config_get_int(lc->config,"autoreplier","max_rec_time",60);
805 config->max_rec_msg=lp_config_get_int(lc->config,"autoreplier","max_rec_msg",10);
806 config->message=lp_config_get_string(lc->config,"autoreplier","message",NULL);
811 * Sets maximum available download bandwidth
813 * @ingroup media_parameters
815 * This is IP bandwidth, in kbit/s.
816 * This information is used signaled to other parties during
817 * calls (within SDP messages) so that the remote end can have
818 * sufficient knowledge to properly configure its audio & video
819 * codec output bitrate to not overflow available bandwidth.
821 * @param lc the LinphoneCore object
822 * @param bw the bandwidth in kbits/s, 0 for infinite
824 void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
825 lc->net_conf.download_bw=bw;
829 * Sets maximum available upload bandwidth
831 * @ingroup media_parameters
833 * This is IP bandwidth, in kbit/s.
834 * This information is used by liblinphone together with remote
835 * side available bandwidth signaled in SDP messages to properly
836 * configure audio & video codec's output bitrate.
838 * @param lc the LinphoneCore object
839 * @param bw the bandwidth in kbits/s, 0 for infinite
841 void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
842 lc->net_conf.upload_bw=bw;
846 * Retrieve the maximum available download bandwidth.
848 * @ingroup media_parameters
850 * This value was set by linphone_core_set_download_bandwidth().
853 int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
854 return lc->net_conf.download_bw;
858 * Retrieve the maximum available upload bandwidth.
860 * @ingroup media_parameters
862 * This value was set by linphone_core_set_upload_bandwidth().
865 int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
866 return lc->net_conf.upload_bw;
869 * set audio packetization time linphone expect to received from peer
871 void linphone_core_set_download_ptime(LinphoneCore *lc, int ptime) {
872 lc->net_conf.down_ptime=ptime;
875 int linphone_core_get_download_ptime(LinphoneCore *lc) {
876 return lc->net_conf.down_ptime;
881 * Returns liblinphone's version as a string.
886 const char * linphone_core_get_version(void){
887 return liblinphone_version;
891 static MSList *linphone_payload_types=NULL;
893 static void linphone_core_assign_payload_type(PayloadType *const_pt, int number, const char *recv_fmtp){
895 pt=payload_type_clone(const_pt);
896 payload_type_set_number(pt,number);
897 if (recv_fmtp!=NULL) payload_type_set_recv_fmtp(pt,recv_fmtp);
898 rtp_profile_set_payload(&av_profile,number,pt);
899 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
902 static void linphone_core_free_payload_types(void){
903 ms_list_for_each(linphone_payload_types,(void (*)(void*))payload_type_destroy);
904 ms_list_free(linphone_payload_types);
905 linphone_payload_types=NULL;
908 void linphone_core_set_state(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message){
910 if (lc->vtable.global_state_changed){
911 lc->vtable.global_state_changed(lc,gstate,message);
915 static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path,
916 const char *factory_config_path, void * userdata)
918 memset (lc, 0, sizeof (LinphoneCore));
921 memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
923 linphone_core_set_state(lc,LinphoneGlobalStartup,"Starting up");
925 linphone_core_assign_payload_type(&payload_type_pcmu8000,0,NULL);
926 linphone_core_assign_payload_type(&payload_type_gsm,3,NULL);
927 linphone_core_assign_payload_type(&payload_type_pcma8000,8,NULL);
928 linphone_core_assign_payload_type(&payload_type_lpc1015,115,NULL);
929 linphone_core_assign_payload_type(&payload_type_speex_nb,110,"vbr=on");
930 linphone_core_assign_payload_type(&payload_type_speex_wb,111,"vbr=on");
931 linphone_core_assign_payload_type(&payload_type_speex_uwb,112,"vbr=on");
932 linphone_core_assign_payload_type(&payload_type_telephone_event,101,"0-11");
933 linphone_core_assign_payload_type(&payload_type_ilbc,113,"mode=30");
934 linphone_core_assign_payload_type(&payload_type_amr,114,"octet-align=1");
936 #if defined(ANDROID) || defined (__IPHONE_OS_VERSION_MIN_REQUIRED)
937 /*shorten the DNS lookup time and send more retransmissions on mobiles:
938 - to workaround potential packet losses
939 - to avoid hanging for 30 seconds when the network doesn't work despite the phone thinks it does.
941 _linphone_core_configure_resolver();
944 #ifdef ENABLE_NONSTANDARD_GSM
947 pt=payload_type_clone(&payload_type_gsm);
948 pt->clock_rate=11025;
949 rtp_profile_set_payload(&av_profile,114,pt);
950 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
951 pt=payload_type_clone(&payload_type_gsm);
952 pt->clock_rate=22050;
953 rtp_profile_set_payload(&av_profile,115,pt);
954 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
959 linphone_core_assign_payload_type(&payload_type_h263,34,NULL);
960 linphone_core_assign_payload_type(&payload_type_theora,97,NULL);
961 linphone_core_assign_payload_type(&payload_type_h263_1998,98,"CIF=1;QCIF=1");
962 linphone_core_assign_payload_type(&payload_type_mp4v,99,"profile-level-id=3");
963 linphone_core_assign_payload_type(&payload_type_x_snow,100,NULL);
964 linphone_core_assign_payload_type(&payload_type_h264,102,"profile-level-id=428014");
965 linphone_core_assign_payload_type(&payload_type_h264,103,"packetization-mode=1;profile-level-id=428014");
969 /* create a mediastreamer2 event queue and set it as global */
970 /* This allows to run event's callback in linphone_core_iterate() */
971 lc->msevq=ms_event_queue_new();
972 ms_set_global_event_queue(lc->msevq);
974 lc->config=lp_config_new(config_path);
975 if (factory_config_path)
976 lp_config_read_file(lc->config,factory_config_path);
979 sal_set_user_pointer(lc->sal,lc);
980 sal_set_callbacks(lc->sal,&linphone_sal_callbacks);
982 sip_setup_register_all();
983 sound_config_read(lc);
986 codecs_config_read(lc);
987 sip_config_read(lc); /* this will start eXosip*/
988 video_config_read(lc);
989 //autoreplier_config_init(&lc->autoreplier_conf);
990 lc->presence_mode=LinphoneStatusOnline;
991 lc->max_call_logs=15;
993 if (lc->vtable.display_status)
994 lc->vtable.display_status(lc,_("Ready"));
995 lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
996 linphone_core_set_state(lc,LinphoneGlobalOn,"Ready");
1000 * Instanciates a LinphoneCore object.
1001 * @ingroup initializing
1003 * The LinphoneCore object is the primary handle for doing all phone actions.
1004 * It should be unique within your application.
1005 * @param vtable a LinphoneCoreVTable structure holding your application callbacks
1006 * @param config_path a path to a config file. If it does not exists it will be created.
1007 * The config file is used to store all settings, call logs, friends, proxies... so that all these settings
1008 * become persistent over the life of the LinphoneCore object.
1009 * It is allowed to set a NULL config file. In that case LinphoneCore will not store any settings.
1010 * @param factory_config_path a path to a read-only config file that can be used to
1011 * to store hard-coded preference such as proxy settings or internal preferences.
1012 * The settings in this factory file always override the one in the normal config file.
1013 * It is OPTIONAL, use NULL if unneeded.
1014 * @param userdata an opaque user pointer that can be retrieved at any time (for example in
1015 * callbacks) using linphone_core_get_user_data().
1018 LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
1019 const char *config_path, const char *factory_config_path, void * userdata)
1021 LinphoneCore *core=ms_new(LinphoneCore,1);
1022 linphone_core_init(core,vtable,config_path, factory_config_path, userdata);
1027 * Returns the list of available audio codecs.
1029 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1030 * structure holding the codec information.
1031 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1032 * (such as the order of codecs).
1034 const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
1036 return lc->codecs_conf.audio_codecs;
1040 * Returns the list of available video codecs.
1042 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1043 * structure holding the codec information.
1044 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1045 * (such as the order of codecs).
1047 const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
1049 return lc->codecs_conf.video_codecs;
1053 * Sets the local "from" identity.
1056 * This data is used in absence of any proxy configuration or when no
1057 * default proxy configuration is set. See LinphoneProxyConfig
1059 int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact)
1061 LinphoneAddress *ctt;
1063 if ((ctt=linphone_address_new(contact))==0) {
1064 ms_error("Bad contact url: %s",contact);
1067 if (lc->sip_conf.contact!=NULL) ms_free(lc->sip_conf.contact);
1068 lc->sip_conf.contact=ms_strdup(contact);
1069 if (lc->sip_conf.guessed_contact!=NULL){
1070 ms_free(lc->sip_conf.guessed_contact);
1071 lc->sip_conf.guessed_contact=NULL;
1073 linphone_address_destroy(ctt);
1078 /*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
1079 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
1080 if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress
1081 && linphone_core_get_nat_address(lc)!=NULL){
1082 strncpy(result,linphone_core_get_nat_address(lc),LINPHONE_IPADDR_SIZE);
1085 if (linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,dest,result)==0)
1087 /*else fallback to SAL routine that will attempt to find the most realistic interface */
1088 sal_get_default_local_ip(lc->sal,lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,result,LINPHONE_IPADDR_SIZE);
1091 static void update_primary_contact(LinphoneCore *lc){
1093 char tmp[LINPHONE_IPADDR_SIZE];
1095 LinphoneAddress *url;
1096 if (lc->sip_conf.guessed_contact!=NULL){
1097 ms_free(lc->sip_conf.guessed_contact);
1098 lc->sip_conf.guessed_contact=NULL;
1100 url=linphone_address_new(lc->sip_conf.contact);
1102 ms_error("Could not parse identity contact !");
1103 url=linphone_address_new("sip:unknown@unkwownhost");
1105 linphone_core_get_local_ip(lc, NULL, tmp);
1106 if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
1107 ms_warning("Local loopback network only !");
1108 lc->sip_conf.loopback_only=TRUE;
1109 }else lc->sip_conf.loopback_only=FALSE;
1110 linphone_address_set_domain(url,tmp);
1111 linphone_address_set_port_int(url,linphone_core_get_sip_port (lc));
1112 guessed=linphone_address_as_string(url);
1113 lc->sip_conf.guessed_contact=guessed;
1114 linphone_address_destroy(url);
1118 * Returns the default identity when no proxy configuration is used.
1122 const char *linphone_core_get_primary_contact(LinphoneCore *lc){
1125 if (lc->sip_conf.guess_hostname){
1126 if (lc->sip_conf.guessed_contact==NULL || lc->sip_conf.loopback_only){
1127 update_primary_contact(lc);
1129 identity=lc->sip_conf.guessed_contact;
1131 identity=lc->sip_conf.contact;
1137 * Tells LinphoneCore to guess local hostname automatically in primary contact.
1141 void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
1142 lc->sip_conf.guess_hostname=val;
1146 * Returns TRUE if hostname part of primary contact is guessed automatically.
1150 bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
1151 return lc->sip_conf.guess_hostname;
1155 * Same as linphone_core_get_primary_contact() but the result is a LinphoneAddress object
1156 * instead of const char*
1160 LinphoneAddress *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
1161 return linphone_address_new(linphone_core_get_primary_contact(lc));
1165 * Sets the list of audio codecs.
1167 * @ingroup media_parameters
1168 * The list is taken by the LinphoneCore thus the application should not free it.
1169 * This list is made of struct PayloadType describing the codec parameters.
1171 int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
1173 if (lc->codecs_conf.audio_codecs!=NULL) ms_list_free(lc->codecs_conf.audio_codecs);
1174 lc->codecs_conf.audio_codecs=codecs;
1179 * Sets the list of video codecs.
1181 * @ingroup media_parameters
1182 * The list is taken by the LinphoneCore thus the application should not free it.
1183 * This list is made of struct PayloadType describing the codec parameters.
1185 int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
1187 if (lc->codecs_conf.video_codecs!=NULL) ms_list_free(lc->codecs_conf.video_codecs);
1188 lc->codecs_conf.video_codecs=codecs;
1192 const MSList * linphone_core_get_friend_list(const LinphoneCore *lc)
1198 * Returns the nominal jitter buffer size in milliseconds.
1200 * @ingroup media_parameters
1202 int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
1204 return lc->rtp_conf.audio_jitt_comp;
1208 * Returns the UDP port used for audio streaming.
1210 * @ingroup network_parameters
1212 int linphone_core_get_audio_port(const LinphoneCore *lc)
1214 return lc->rtp_conf.audio_rtp_port;
1218 * Returns the UDP port used for video streaming.
1220 * @ingroup network_parameters
1222 int linphone_core_get_video_port(const LinphoneCore *lc){
1223 return lc->rtp_conf.video_rtp_port;
1228 * Returns the value in seconds of the no-rtp timeout.
1230 * @ingroup media_parameters
1231 * When no RTP or RTCP packets have been received for a while
1232 * LinphoneCore will consider the call is broken (remote end crashed or
1233 * disconnected from the network), and thus will terminate the call.
1234 * The no-rtp timeout is the duration above which the call is considered broken.
1236 int linphone_core_get_nortp_timeout(const LinphoneCore *lc){
1237 return lc->rtp_conf.nortp_timeout;
1240 bool_t linphone_core_get_rtp_no_xmit_on_audio_mute(const LinphoneCore *lc){
1241 return lc->rtp_conf.rtp_no_xmit_on_audio_mute;
1245 * Sets the nominal audio jitter buffer size in milliseconds.
1247 * @ingroup media_parameters
1249 void linphone_core_set_audio_jittcomp(LinphoneCore *lc, int value)
1251 lc->rtp_conf.audio_jitt_comp=value;
1254 void linphone_core_set_rtp_no_xmit_on_audio_mute(LinphoneCore *lc,bool_t rtp_no_xmit_on_audio_mute){
1255 lc->rtp_conf.rtp_no_xmit_on_audio_mute=rtp_no_xmit_on_audio_mute;
1259 * Sets the UDP port used for audio streaming.
1261 * @ingroup network_parameters
1263 void linphone_core_set_audio_port(LinphoneCore *lc, int port)
1265 lc->rtp_conf.audio_rtp_port=port;
1269 * Sets the UDP port used for video streaming.
1271 * @ingroup network_parameters
1273 void linphone_core_set_video_port(LinphoneCore *lc, int port){
1274 lc->rtp_conf.video_rtp_port=port;
1278 * Sets the no-rtp timeout value in seconds.
1280 * @ingroup media_parameters
1281 * See linphone_core_get_nortp_timeout() for details.
1283 void linphone_core_set_nortp_timeout(LinphoneCore *lc, int nortp_timeout){
1284 lc->rtp_conf.nortp_timeout=nortp_timeout;
1288 * Indicates whether SIP INFO is used for sending digits.
1290 * @ingroup media_parameters
1292 bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
1294 return lc->sip_conf.use_info;
1298 * Sets whether SIP INFO is to be used for sending digits.
1300 * @ingroup media_parameters
1302 void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
1304 lc->sip_conf.use_info=use_info;
1308 * Indicates whether RFC2833 is used for sending digits.
1310 * @ingroup media_parameters
1312 bool_t linphone_core_get_use_rfc2833_for_dtmf(LinphoneCore *lc)
1314 return lc->sip_conf.use_rfc2833;
1318 * Sets whether RFC2833 is to be used for sending digits.
1320 * @ingroup media_parameters
1322 void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833)
1324 lc->sip_conf.use_rfc2833=use_rfc2833;
1328 * Returns the UDP port used by SIP.
1330 * Deprecated: use linphone_core_get_sip_transports() instead.
1331 * @ingroup network_parameters
1333 int linphone_core_get_sip_port(LinphoneCore *lc)
1335 LCSipTransports *tr=&lc->sip_conf.transports;
1336 return tr->udp_port>0 ? tr->udp_port : tr->tcp_port;
1339 static char _ua_name[64]="Linphone";
1340 static char _ua_version[64]=LINPHONE_VERSION;
1342 #ifdef HAVE_EXOSIP_GET_VERSION
1343 extern const char *eXosip_get_version();
1346 static void apply_user_agent(LinphoneCore *lc){
1347 char ua_string[256];
1348 snprintf(ua_string,sizeof(ua_string)-1,"%s/%s (eXosip2/%s)",_ua_name,_ua_version,
1349 #ifdef HAVE_EXOSIP_GET_VERSION
1350 eXosip_get_version()
1355 if (lc->sal) sal_set_user_agent(lc->sal,ua_string);
1359 * Sets the user agent string used in SIP messages.
1363 void linphone_core_set_user_agent(const char *name, const char *ver){
1364 strncpy(_ua_name,name,sizeof(_ua_name)-1);
1365 strncpy(_ua_version,ver,sizeof(_ua_version));
1368 static void transport_error(LinphoneCore *lc, const char* transport, int port){
1369 char *msg=ortp_strdup_printf("Could not start %s transport on port %i, maybe this port is already used.",transport,port);
1371 if (lc->vtable.display_warning)
1372 lc->vtable.display_warning(lc,msg);
1376 static bool_t transports_unchanged(const LCSipTransports * tr1, const LCSipTransports * tr2){
1378 tr2->udp_port==tr1->udp_port &&
1379 tr2->tcp_port==tr1->tcp_port &&
1380 tr2->dtls_port==tr1->dtls_port &&
1381 tr2->tls_port==tr1->tls_port;
1384 static int apply_transports(LinphoneCore *lc){
1386 const char *anyaddr;
1387 LCSipTransports *tr=&lc->sip_conf.transports;
1389 if (lc->sip_conf.ipv6_enabled)
1394 sal_unlisten_ports (sal);
1395 if (tr->udp_port>0){
1396 if (sal_listen_port (sal,anyaddr,tr->udp_port,SalTransportDatagram,FALSE)!=0){
1397 transport_error(lc,"UDP",tr->udp_port);
1401 if (tr->tcp_port>0){
1402 if (sal_listen_port (sal,anyaddr,tr->tcp_port,SalTransportStream,FALSE)!=0){
1403 transport_error(lc,"TCP",tr->tcp_port);
1406 apply_user_agent(lc);
1411 * Sets the ports to be used for each of transport (UDP or TCP)
1413 * A zero value port for a given transport means the transport
1416 * @ingroup network_parameters
1418 int linphone_core_set_sip_transports(LinphoneCore *lc, const LCSipTransports * tr){
1420 if (transports_unchanged(tr,&lc->sip_conf.transports))
1422 memcpy(&lc->sip_conf.transports,tr,sizeof(*tr));
1424 if (lc->sal==NULL) return 0;
1425 return apply_transports(lc);
1429 * Retrieves the ports used for each transport (udp, tcp).
1430 * A zero value port for a given transport means the transport
1432 * @ingroup network_parameters
1434 int linphone_core_get_sip_transports(LinphoneCore *lc, LCSipTransports *tr){
1435 memcpy(tr,&lc->sip_conf.transports,sizeof(*tr));
1440 * Sets the UDP port to be used by SIP.
1442 * Deprecated: use linphone_core_set_sip_transports() instead.
1443 * @ingroup network_parameters
1445 void linphone_core_set_sip_port(LinphoneCore *lc,int port)
1448 memset(&tr,0,sizeof(tr));
1450 linphone_core_set_sip_transports (lc,&tr);
1454 * Returns TRUE if IPv6 is enabled.
1456 * @ingroup network_parameters
1457 * See linphone_core_enable_ipv6() for more details on how IPv6 is supported in liblinphone.
1459 bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
1460 return lc->sip_conf.ipv6_enabled;
1464 * Turns IPv6 support on or off.
1466 * @ingroup network_parameters
1468 * @note IPv6 support is exclusive with IPv4 in liblinphone:
1469 * when IPv6 is turned on, IPv4 calls won't be possible anymore.
1470 * By default IPv6 support is off.
1472 void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
1473 if (lc->sip_conf.ipv6_enabled!=val){
1474 lc->sip_conf.ipv6_enabled=val;
1476 /* we need to restart eXosip */
1477 apply_transports(lc);
1482 static void display_bandwidth(RtpSession *as, RtpSession *vs){
1483 ms_message("bandwidth usage: audio=[d=%.1f,u=%.1f] video=[d=%.1f,u=%.1f] kbit/sec",
1484 (as!=NULL) ? (rtp_session_compute_recv_bandwidth(as)*1e-3) : 0,
1485 (as!=NULL) ? (rtp_session_compute_send_bandwidth(as)*1e-3) : 0,
1486 (vs!=NULL) ? (rtp_session_compute_recv_bandwidth(vs)*1e-3) : 0,
1487 (vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0);
1490 static void linphone_core_disconnected(LinphoneCore *lc, LinphoneCall *call){
1494 from = linphone_call_get_remote_address_as_string(call);
1497 snprintf(temp,sizeof(temp),"Remote end %s seems to have disconnected, the call is going to be closed.",from);
1502 snprintf(temp,sizeof(temp),"Remote end seems to have disconnected, the call is going to be closed.");
1504 if (lc->vtable.display_warning!=NULL)
1505 lc->vtable.display_warning(lc,temp);
1506 linphone_core_terminate_call(lc,call);
1509 static void monitor_network_state(LinphoneCore *lc, time_t curtime){
1510 static time_t last_check=0;
1511 static bool_t last_status=FALSE;
1512 char result[LINPHONE_IPADDR_SIZE];
1513 bool_t new_status=last_status;
1515 /* only do the network up checking every five seconds */
1516 if (last_check==0 || (curtime-last_check)>=5){
1517 linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,NULL,result);
1518 if (strcmp(result,"::1")!=0 && strcmp(result,"127.0.0.1")!=0){
1520 }else new_status=FALSE;
1522 if (new_status!=last_status) {
1524 ms_message("New local ip address is %s",result);
1526 set_network_reachable(lc,new_status, curtime);
1527 last_status=new_status;
1532 static void proxy_update(LinphoneCore *lc){
1533 ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
1534 MSList* list=ms_list_copy(lc->sip_conf.deleted_proxies);
1535 for(;list!=NULL;list=list->next){
1536 LinphoneProxyConfig* cfg = (LinphoneProxyConfig*) list->data;
1537 if (ms_time(NULL) - cfg->deletion_date > 5) {
1538 lc->sip_conf.deleted_proxies =ms_list_remove(lc->sip_conf.deleted_proxies,(void *)cfg);
1539 ms_message("clearing proxy config for [%s]",linphone_proxy_config_get_addr(cfg));
1540 linphone_proxy_config_destroy(cfg);
1546 static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){
1547 LinphoneFriend *lf=linphone_core_get_friend_by_address(lc,info->sip_uri);
1550 ms_message("%s has a BuddyInfo assigned with image %p",info->sip_uri, info->image_data);
1551 if (lc->vtable.buddy_info_updated)
1552 lc->vtable.buddy_info_updated(lc,lf);
1554 ms_warning("Could not any friend with uri %s",info->sip_uri);
1558 static void analyze_buddy_lookup_results(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1560 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1561 for (elem=lc->bl_reqs;elem!=NULL;elem=ms_list_next(elem)){
1562 BuddyLookupRequest *req=(BuddyLookupRequest *)elem->data;
1563 if (req->status==BuddyLookupDone || req->status==BuddyLookupFailure){
1564 if (req->results!=NULL){
1565 BuddyInfo *i=(BuddyInfo*)req->results->data;
1566 ms_list_free(req->results);
1568 assign_buddy_info(lc,i);
1570 sip_setup_context_buddy_lookup_free(ctx,req);
1574 /*purge completed requests */
1575 while((elem=ms_list_find(lc->bl_reqs,NULL))!=NULL){
1576 lc->bl_reqs=ms_list_remove_link(lc->bl_reqs,elem);
1580 static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1582 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1583 for(elem=linphone_core_get_friend_list(lc);elem!=NULL;elem=elem->next){
1584 LinphoneFriend *lf=(LinphoneFriend*)elem->data;
1585 if (lf->info==NULL){
1586 if (linphone_core_lookup_known_proxy(lc,lf->uri)==cfg){
1587 if (linphone_address_get_username(lf->uri)!=NULL){
1588 BuddyLookupRequest *req;
1589 char *tmp=linphone_address_as_string_uri_only(lf->uri);
1590 req=sip_setup_context_create_buddy_lookup_request(ctx);
1591 buddy_lookup_request_set_key(req,tmp);
1592 buddy_lookup_request_set_max_results(req,1);
1593 sip_setup_context_buddy_lookup_submit(ctx,req);
1594 lc->bl_reqs=ms_list_append(lc->bl_reqs,req);
1602 static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
1603 LinphoneProxyConfig *cfg=NULL;
1604 linphone_core_get_default_proxy(lc,&cfg);
1606 if (lc->bl_refresh){
1607 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1608 if (ctx && (sip_setup_context_get_capabilities(ctx) & SIP_SETUP_CAP_BUDDY_LOOKUP)){
1609 linphone_core_grab_buddy_infos(lc,cfg);
1610 lc->bl_refresh=FALSE;
1613 if (lc->bl_reqs) analyze_buddy_lookup_results(lc,cfg);
1618 * Main loop function. It is crucial that your application call it periodically.
1620 * @ingroup initializing
1621 * linphone_core_iterate() performs various backgrounds tasks:
1622 * - receiving of SIP messages
1623 * - handles timers and timeout
1624 * - performs registration to proxies
1625 * - authentication retries
1626 * The application MUST call this function periodically, in its main loop.
1627 * Be careful that this function must be called from the same thread as
1628 * other liblinphone methods. If it is not the case make sure all liblinphone calls are
1629 * serialized with a mutex.
1631 void linphone_core_iterate(LinphoneCore *lc){
1634 int disconnect_timeout = linphone_core_get_nortp_timeout(lc);
1635 time_t curtime=time(NULL);
1637 bool_t one_second_elapsed=FALSE;
1638 bool_t disconnected=FALSE;
1640 if (curtime-lc->prevtime>=1){
1641 lc->prevtime=curtime;
1642 one_second_elapsed=TRUE;
1646 LinphoneEcCalibratorStatus ecs=ec_calibrator_get_status(lc->ecc);
1647 if (ecs!=LinphoneEcCalibratorInProgress){
1649 lc->ecc->cb(lc,ecs,lc->ecc->delay,lc->ecc->cb_data);
1650 if (ecs==LinphoneEcCalibratorDone){
1651 lp_config_set_int(lc->config, "sound", "ec_delay",MAX(lc->ecc->delay-10,0));
1653 ec_calibrator_destroy(lc->ecc);
1658 if (lc->preview_finished){
1659 lc->preview_finished=0;
1660 ring_stop(lc->ringstream);
1661 lc->ringstream=NULL;
1662 lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
1665 if (lc->ringstream && lc->dmfs_playing_start_time!=0
1666 && (curtime-lc->dmfs_playing_start_time)>5){
1667 ring_stop(lc->ringstream);
1668 lc->ringstream=NULL;
1669 lc->dmfs_playing_start_time=0;
1672 sal_iterate(lc->sal);
1673 if (lc->msevq) ms_event_queue_pump(lc->msevq);
1674 if (lc->auto_net_state_mon) monitor_network_state(lc,curtime);
1678 //we have to iterate for each call
1680 while(calls!= NULL){
1681 call = (LinphoneCall *)calls->data;
1682 /* get immediately a reference to next one in case the one
1683 we are going to examine is destroy and removed during
1684 linphone_core_start_invite() */
1686 if (call->state==LinphoneCallOutgoingInit && (curtime-call->start_time>=2)){
1687 /*start the call even if the OPTIONS reply did not arrive*/
1688 linphone_core_start_invite(lc,call,NULL);
1690 if (call->dir==LinphoneCallIncoming && call->state==LinphoneCallOutgoingRinging){
1691 elapsed=curtime-call->start_time;
1692 ms_message("incoming call ringing for %i seconds",elapsed);
1693 if (elapsed>lc->sip_conf.inc_timeout){
1694 call->log->status=LinphoneCallMissed;
1695 linphone_core_terminate_call(lc,call);
1699 call = linphone_core_get_current_call(lc);
1702 if (call->state==LinphoneCallStreamsRunning && one_second_elapsed)
1704 RtpSession *as=NULL,*vs=NULL;
1705 lc->prevtime=curtime;
1706 if (call->audiostream!=NULL)
1707 as=call->audiostream->session;
1708 if (call->videostream!=NULL)
1709 vs=call->videostream->session;
1710 display_bandwidth(as,vs);
1712 #ifdef VIDEO_ENABLED
1713 if (call->videostream!=NULL)
1714 video_stream_iterate(call->videostream);
1716 if (call->audiostream!=NULL && disconnect_timeout>0)
1717 disconnected=!audio_stream_alive(call->audiostream,disconnect_timeout);
1719 if (linphone_core_video_preview_enabled(lc)){
1720 if (lc->previewstream==NULL && lc->calls==NULL)
1721 toggle_video_preview(lc,TRUE);
1722 #ifdef VIDEO_ENABLED
1723 if (lc->previewstream) video_stream_iterate(lc->previewstream);
1726 if (lc->previewstream!=NULL)
1727 toggle_video_preview(lc,FALSE);
1730 linphone_core_disconnected(lc,call);
1732 linphone_core_do_plugin_tasks(lc);
1734 if (lc->initial_subscribes_sent==FALSE && lc->netup_time!=0 &&
1735 (curtime-lc->netup_time)>3){
1736 linphone_core_send_initial_subscribes(lc);
1737 lc->initial_subscribes_sent=TRUE;
1740 if (one_second_elapsed && lp_config_needs_commit(lc->config)){
1741 lp_config_sync(lc->config);
1746 * Interpret a call destination as supplied by the user, and returns a fully qualified
1749 * A sip address should look like DisplayName <sip:username@domain:port> .
1750 * Basically this function performs the following tasks
1751 * - if a phone number is entered, prepend country prefix of the default proxy
1752 * configuration, eventually escape the '+' by 00.
1753 * - if no domain part is supplied, append the domain name of the default proxy
1754 * - if no sip: is present, prepend it
1756 * The result is a syntaxically correct SIP address.
1759 LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url){
1760 enum_lookup_res_t *enumres=NULL;
1761 char *enum_domain=NULL;
1762 LinphoneProxyConfig *proxy=lc->default_proxy;;
1764 LinphoneAddress *uri;
1766 if (is_enum(url,&enum_domain)){
1767 if (lc->vtable.display_status!=NULL)
1768 lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
1769 if (enum_lookup(enum_domain,&enumres)<0){
1770 if (lc->vtable.display_status!=NULL)
1771 lc->vtable.display_status(lc,_("Could not resolve this number."));
1772 ms_free(enum_domain);
1775 ms_free(enum_domain);
1776 tmpurl=enumres->sip_address[0];
1777 uri=linphone_address_new(tmpurl);
1778 enum_lookup_res_free(enumres);
1781 /* check if we have a "sip:" */
1782 if (strstr(url,"sip:")==NULL){
1783 /* this doesn't look like a true sip uri */
1784 if (strchr(url,'@')!=NULL){
1785 /* seems like sip: is missing !*/
1786 tmpurl=ms_strdup_printf("sip:%s",url);
1787 uri=linphone_address_new(tmpurl);
1795 /* append the proxy domain suffix */
1796 const char *identity=linphone_proxy_config_get_identity(proxy);
1797 char normalized_username[128];
1798 uri=linphone_address_new(identity);
1802 linphone_address_set_display_name(uri,NULL);
1803 linphone_proxy_config_normalize_number(proxy,url,normalized_username,
1804 sizeof(normalized_username));
1805 linphone_address_set_username(uri,normalized_username);
1809 uri=linphone_address_new(url);
1813 /* else we could not do anything with url given by user, so display an error */
1814 if (lc->vtable.display_warning!=NULL){
1815 lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
1821 * Returns the default identity SIP address.
1824 * This is an helper function:
1826 * If no default proxy is set, this will return the primary contact (
1827 * see linphone_core_get_primary_contact() ). If a default proxy is set
1828 * it returns the registered identity on the proxy.
1830 const char * linphone_core_get_identity(LinphoneCore *lc){
1831 LinphoneProxyConfig *proxy=NULL;
1833 linphone_core_get_default_proxy(lc,&proxy);
1835 from=linphone_proxy_config_get_identity(proxy);
1836 }else from=linphone_core_get_primary_contact(lc);
1840 const char * linphone_core_get_route(LinphoneCore *lc){
1841 LinphoneProxyConfig *proxy=NULL;
1842 const char *route=NULL;
1843 linphone_core_get_default_proxy(lc,&proxy);
1845 route=linphone_proxy_config_get_route(proxy);
1850 void linphone_core_start_refered_call(LinphoneCore *lc, LinphoneCall *call){
1851 if (call->refer_pending){
1852 LinphoneCallParams *cp=linphone_core_create_default_call_parameters(lc);
1854 ms_message("Starting new call to refered address %s",call->refer_to);
1855 call->refer_pending=FALSE;
1856 linphone_core_invite_with_params(lc,call->refer_to,cp);
1857 linphone_call_params_destroy(cp);
1861 LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
1863 LinphoneProxyConfig *found_cfg=NULL;
1864 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=elem->next){
1865 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1866 const char *domain=linphone_proxy_config_get_domain(cfg);
1867 if (domain!=NULL && strcmp(domain,linphone_address_get_domain(uri))==0){
1875 const char *linphone_core_find_best_identity(LinphoneCore *lc, const LinphoneAddress *to, const char **route){
1876 LinphoneProxyConfig *cfg=linphone_core_lookup_known_proxy(lc,to);
1878 linphone_core_get_default_proxy (lc,&cfg);
1880 *route=linphone_proxy_config_get_route(cfg);
1881 return linphone_proxy_config_get_identity (cfg);
1883 return linphone_core_get_primary_contact (lc);
1886 static char *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){
1887 LinphoneAddress *ctt;
1888 const char *localip=call->localip;
1890 /* first use user's supplied ip address if asked*/
1891 if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress){
1892 ctt=linphone_core_get_primary_contact_parsed(lc);
1893 return ms_strdup_printf("sip:%s@%s",linphone_address_get_username(ctt),
1894 linphone_core_get_nat_address(lc));
1897 /* if already choosed, don't change it */
1898 if (call->op && sal_op_get_contact(call->op)!=NULL){
1901 /* if the ping OPTIONS request succeeded use the contact guessed from the
1904 const char *guessed=sal_op_get_contact(call->ping_op);
1906 ms_message("Contact has been fixed using OPTIONS to %s",guessed);
1907 return ms_strdup(guessed);
1911 /*if using a proxy, use the contact address as guessed with the REGISTERs*/
1912 if (dest_proxy && dest_proxy->op){
1913 const char *fixed_contact=sal_op_get_contact(dest_proxy->op);
1914 if (fixed_contact) {
1915 ms_message("Contact has been fixed using proxy to %s",fixed_contact);
1916 return ms_strdup(fixed_contact);
1920 ctt=linphone_core_get_primary_contact_parsed(lc);
1924 /*otherwise use supllied localip*/
1925 linphone_address_set_domain(ctt,localip);
1926 linphone_address_set_port_int(ctt,linphone_core_get_sip_port(lc));
1927 ret=linphone_address_as_string_uri_only(ctt);
1928 linphone_address_destroy(ctt);
1929 ms_message("Contact has been fixed using local ip to %s",ret);
1935 int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphoneProxyConfig *dest_proxy){
1938 char *real_url,*barmsg;
1941 /*try to be best-effort in giving real local or routable contact address */
1942 contact=get_fixed_contact(lc,call,dest_proxy);
1944 sal_op_set_contact(call->op, contact);
1948 //TODO : should probably not be done here
1949 linphone_call_init_media_streams(call);
1950 if (!lc->sip_conf.sdp_200_ack){
1951 call->media_pending=TRUE;
1952 sal_call_set_local_media_description(call->op,call->localdesc);
1954 real_url=linphone_address_as_string(call->log->to);
1955 from=linphone_address_as_string(call->log->from);
1956 err=sal_call(call->op,from,real_url);
1958 if (lc->sip_conf.sdp_200_ack){
1959 call->media_pending=TRUE;
1960 sal_call_set_local_media_description(call->op,call->localdesc);
1962 barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
1963 if (lc->vtable.display_status!=NULL)
1964 lc->vtable.display_status(lc,barmsg);
1968 if (lc->vtable.display_status!=NULL)
1969 lc->vtable.display_status(lc,_("Could not call"));
1970 linphone_call_stop_media_streams(call);
1971 linphone_call_set_state(call,LinphoneCallError,"Call failed");
1973 linphone_call_set_state(call,LinphoneCallOutgoingProgress,"Outgoing call in progress");
1981 * Initiates an outgoing call
1983 * @ingroup call_control
1984 * @param lc the LinphoneCore object
1985 * @param url the destination of the call (sip address, or phone number).
1987 * The application doesn't own a reference to the returned LinphoneCall object.
1988 * Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
1990 * @return a LinphoneCall object or NULL in case of failure
1992 LinphoneCall * linphone_core_invite(LinphoneCore *lc, const char *url){
1994 LinphoneCallParams *p=linphone_core_create_default_call_parameters (lc);
1995 call=linphone_core_invite_with_params(lc,url,p);
1996 linphone_call_params_destroy(p);
2002 * Initiates an outgoing call according to supplied call parameters
2004 * @ingroup call_control
2005 * @param lc the LinphoneCore object
2006 * @param url the destination of the call (sip address, or phone number).
2007 * @param p call parameters
2009 * The application doesn't own a reference to the returned LinphoneCall object.
2010 * Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
2012 * @return a LinphoneCall object or NULL in case of failure
2014 LinphoneCall * linphone_core_invite_with_params(LinphoneCore *lc, const char *url, const LinphoneCallParams *p){
2015 LinphoneAddress *addr=linphone_core_interpret_url(lc,url);
2018 call=linphone_core_invite_address_with_params(lc,addr,p);
2019 linphone_address_destroy(addr);
2026 * Initiates an outgoing call given a destination LinphoneAddress
2028 * @ingroup call_control
2029 * @param lc the LinphoneCore object
2030 * @param addr the destination of the call (sip address).
2032 * The LinphoneAddress can be constructed directly using linphone_address_new(), or
2033 * created by linphone_core_interpret_url().
2034 * The application doesn't own a reference to the returned LinphoneCall object.
2035 * Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
2037 * @return a LinphoneCall object or NULL in case of failure
2039 LinphoneCall * linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *addr){
2041 LinphoneCallParams *p=linphone_core_create_default_call_parameters (lc);
2042 call=linphone_core_invite_address_with_params (lc,addr,p);
2043 linphone_call_params_destroy(p);
2049 * Initiates an outgoing call given a destination LinphoneAddress
2051 * @ingroup call_control
2052 * @param lc the LinphoneCore object
2053 * @param addr the destination of the call (sip address).
2054 @param params call parameters
2056 * The LinphoneAddress can be constructed directly using linphone_address_new(), or
2057 * created by linphone_core_interpret_url().
2058 * The application doesn't own a reference to the returned LinphoneCall object.
2059 * Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
2061 * @return a LinphoneCall object or NULL in case of failure
2063 LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const LinphoneAddress *addr, const LinphoneCallParams *params)
2066 const char *route=NULL;
2067 const char *from=NULL;
2068 LinphoneProxyConfig *proxy=NULL;
2069 LinphoneAddress *parsed_url2=NULL;
2070 char *real_url=NULL;
2071 LinphoneProxyConfig *dest_proxy=NULL;
2074 if (linphone_core_in_call(lc)){
2075 if (lc->vtable.display_warning)
2076 lc->vtable.display_warning(lc,_("Sorry, you have to pause or stop the current call first !"));
2079 if(!linphone_core_can_we_add_call(lc)){
2080 if (lc->vtable.display_warning)
2081 lc->vtable.display_warning(lc,_("Sorry, we have reached the maximum number of simultaneous calls"));
2084 linphone_core_get_default_proxy(lc,&proxy);
2085 route=linphone_core_get_route(lc);
2087 real_url=linphone_address_as_string(addr);
2088 dest_proxy=linphone_core_lookup_known_proxy(lc,addr);
2090 if (proxy!=dest_proxy && dest_proxy!=NULL) {
2091 ms_message("Overriding default proxy setting for this call:");
2092 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
2095 if (dest_proxy!=NULL)
2096 from=linphone_proxy_config_get_identity(dest_proxy);
2097 else if (proxy!=NULL)
2098 from=linphone_proxy_config_get_identity(proxy);
2100 /* if no proxy or no identity defined for this proxy, default to primary contact*/
2101 if (from==NULL) from=linphone_core_get_primary_contact(lc);
2103 parsed_url2=linphone_address_new(from);
2105 call=linphone_call_new_outgoing(lc,parsed_url2,linphone_address_clone(addr),params);
2106 sal_op_set_route(call->op,route);
2108 if(linphone_core_add_call(lc,call)!= 0)
2110 ms_warning("we had a problem in adding the call into the invite ... weird");
2111 linphone_call_unref(call);
2114 /* this call becomes now the current one*/
2115 lc->current_call=call;
2116 linphone_call_set_state (call,LinphoneCallOutgoingInit,"Starting outgoing call");
2117 if (dest_proxy!=NULL || lc->sip_conf.ping_with_options==FALSE){
2118 err=linphone_core_start_invite(lc,call,dest_proxy);
2120 /*defer the start of the call after the OPTIONS ping*/
2121 call->ping_op=sal_op_new(lc->sal);
2122 sal_ping(call->ping_op,from,real_url);
2123 sal_op_set_user_pointer(call->ping_op,call);
2124 call->start_time=time(NULL);
2127 if (real_url!=NULL) ms_free(real_url);
2132 * Performs a simple call transfer to the specified destination.
2134 * The remote endpoint is expected to issue a new call to the specified destination.
2135 * The current call remains active and thus can be later paused or terminated.
2137 int linphone_core_transfer_call(LinphoneCore *lc, LinphoneCall *call, const char *url)
2139 char *real_url=NULL;
2140 LinphoneAddress *real_parsed_url=linphone_core_interpret_url(lc,url);
2142 if (!real_parsed_url){
2147 ms_warning("No established call to refer.");
2150 //lc->call=NULL; //Do not do that you will lose the call afterward . . .
2151 real_url=linphone_address_as_string (real_parsed_url);
2152 sal_call_refer(call->op,real_url);
2154 linphone_address_destroy(real_parsed_url);
2159 * Transfer a call to destination of another running call. This is used for "attended transfer" scenarios.
2160 * @param lc linphone core object
2161 * @param call a running call you want to transfer
2162 * @param dest a running call whose remote person will receive the transfer
2164 * The transfered call is supposed to be in paused state, so that it is able to accept the transfer immediately.
2165 * The destination call is a call previously established to introduce the transfered person.
2166 * This method will send a transfer request to the transfered person. The phone of the transfered is then
2167 * expected to automatically call to the destination of the transfer. The receiver of the transfer will then automatically
2168 * close the call with us (the 'dest' call).
2170 int linphone_core_transfer_call_to_another(LinphoneCore *lc, LinphoneCall *call, LinphoneCall *dest){
2171 return sal_call_refer_with_replaces (call->op,dest->op);
2174 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
2175 LinphoneCall *call = linphone_core_get_current_call(lc);
2178 if(call->dir==LinphoneCallIncoming
2179 && (call->state == LinphoneCallIncomingReceived || call->state == LinphoneCallIncomingEarlyMedia))
2186 * Updates a running call according to supplied call parameters or parameters changed in the LinphoneCore.
2188 * In this version this is limited to the following use cases:
2189 * - setting up/down the video stream according to the video parameter of the LinphoneCallParams (see linphone_call_params_enable_video() ).
2190 * - changing the size of the transmitted video after calling linphone_core_set_preferred_video_size()
2192 * In case no changes are requested through the LinphoneCallParams argument, then this argument can be ommitted and set to NULL.
2194 * @return 0 if successful, -1 otherwise.
2196 int linphone_core_update_call(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallParams *params){
2199 if (call->localdesc)
2200 sal_media_description_unref(call->localdesc);
2201 call->params=*params;
2202 call->localdesc=create_local_media_description (lc,call);
2203 call->camera_active=params->has_video;
2204 if (lc->vtable.display_status)
2205 lc->vtable.display_status(lc,_("Modifying call parameters..."));
2206 sal_call_set_local_media_description (call->op,call->localdesc);
2207 err=sal_call_update(call->op);
2209 #ifdef VIDEO_ENABLED
2210 if (call->videostream!=NULL){
2211 video_stream_set_sent_video_size(call->videostream,linphone_core_get_preferred_video_size(lc));
2212 video_stream_update_video_params (call->videostream);
2222 * Accept an incoming call.
2224 * @ingroup call_control
2225 * Basically the application is notified of incoming calls within the
2226 * call_state_changed callback of the #LinphoneCoreVTable structure, where it will receive
2227 * a LinphoneCallIncoming event with the associated LinphoneCall object.
2228 * The application can later accept the call using
2230 * @param lc the LinphoneCore object
2231 * @param call the LinphoneCall object representing the call to be answered.
2234 int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call)
2236 LinphoneProxyConfig *cfg=NULL,*dest_proxy=NULL;
2237 const char *contact=NULL;
2239 SalMediaDescription *new_md;
2242 //if just one call is present answer the only one ...
2243 if(linphone_core_get_calls_nb (lc) != 1)
2246 call = (LinphoneCall*)linphone_core_get_calls(lc)->data;
2249 if (call->state==LinphoneCallConnected){
2250 /*call already accepted*/
2254 /* check if this call is supposed to replace an already running one*/
2255 replaced=sal_call_get_replaces(call->op);
2257 LinphoneCall *rc=(LinphoneCall*)sal_op_get_user_pointer (replaced);
2259 ms_message("Call %p replaces call %p. This last one is going to be terminated automatically.",
2261 linphone_core_terminate_call (lc,rc);
2265 if (lc->current_call!=NULL && lc->current_call!=call){
2266 ms_warning("Cannot accept this call, there is already one running.");
2270 /*can accept a new call only if others are on hold */
2273 for(elem=lc->calls;elem!=NULL;elem=elem->next){
2274 LinphoneCall *c=(LinphoneCall*)elem->data;
2275 if (c!=call && (c->state!=LinphoneCallPaused && c->state!=LinphoneCallPausing)){
2276 ms_warning("Cannot accept this call as another one is running, pause it before.");
2283 if (lc->ringstream!=NULL) {
2284 ms_message("stop ringing");
2285 ring_stop(lc->ringstream);
2286 ms_message("ring stopped");
2287 lc->ringstream=NULL;
2290 linphone_core_get_default_proxy(lc,&cfg);
2292 dest_proxy=linphone_core_lookup_known_proxy(lc,call->log->to);
2294 if (cfg!=dest_proxy && dest_proxy!=NULL) {
2295 ms_message("Overriding default proxy setting for this call:");
2296 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
2298 /*try to be best-effort in giving real local or routable contact address*/
2299 contact=get_fixed_contact(lc,call,dest_proxy);
2301 sal_op_set_contact(call->op,contact);
2303 if (call->audiostream==NULL)
2304 linphone_call_init_media_streams(call);
2306 sal_call_accept(call->op);
2307 if (lc->vtable.display_status!=NULL)
2308 lc->vtable.display_status(lc,_("Connected."));
2309 lc->current_call=call;
2310 linphone_call_set_state(call,LinphoneCallConnected,"Connected");
2311 new_md=sal_call_get_final_media_description(call->op);
2312 linphone_core_update_streams(lc, call, new_md);
2314 linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
2315 }else call->media_pending=TRUE;
2317 ms_message("call answered.");
2321 int linphone_core_abort_call(LinphoneCore *lc, LinphoneCall *call, const char *error){
2322 sal_call_terminate(call->op);
2325 if (lc->ringstream!=NULL) {
2326 ring_stop(lc->ringstream);
2327 lc->ringstream=NULL;
2329 linphone_call_stop_media_streams(call);
2330 if (lc->vtable.display_status!=NULL)
2331 lc->vtable.display_status(lc,_("Call aborted") );
2332 linphone_call_set_state(call,LinphoneCallError,error);
2338 * Terminates a call.
2340 * @ingroup call_control
2341 * @param lc the LinphoneCore
2342 * @param the_call the LinphoneCall object representing the call to be terminated.
2344 int linphone_core_terminate_call(LinphoneCore *lc, LinphoneCall *the_call)
2347 if (the_call == NULL){
2348 call = linphone_core_get_current_call(lc);
2349 if (ms_list_size(lc->calls)==1){
2350 call=(LinphoneCall*)lc->calls->data;
2352 ms_warning("No unique call to terminate !");
2360 sal_call_terminate(call->op);
2361 if (call->state==LinphoneCallIncomingReceived){
2362 call->reason=LinphoneReasonDeclined;
2365 if (lc->ringstream!=NULL) {
2366 ring_stop(lc->ringstream);
2367 lc->ringstream=NULL;
2369 linphone_call_stop_media_streams(call);
2370 if (lc->vtable.display_status!=NULL)
2371 lc->vtable.display_status(lc,_("Call ended") );
2372 linphone_call_set_state(call,LinphoneCallEnd,"Call terminated");
2377 * Terminates all the calls.
2379 * @ingroup call_control
2380 * @param lc The LinphoneCore
2382 int linphone_core_terminate_all_calls(LinphoneCore *lc){
2385 LinphoneCall *the_call = lc->calls->data;
2386 linphone_core_terminate_call(lc,the_call);
2388 ms_list_free(lc->calls);
2393 * Returns the current list of calls.
2395 * Note that this list is read-only and might be changed by the core after a function call to linphone_core_iterate().
2396 * Similarly the LinphoneCall objects inside it might be destroyed without prior notice.
2397 * To hold references to LinphoneCall object into your program, you must use linphone_call_ref().
2399 * @ingroup call_control
2401 const MSList *linphone_core_get_calls(LinphoneCore *lc)
2407 * Returns TRUE if there is a call running.
2409 * @ingroup call_control
2411 bool_t linphone_core_in_call(const LinphoneCore *lc){
2412 return linphone_core_get_current_call((LinphoneCore *)lc)!=NULL;
2416 * Returns The _LinphoneCall struct of the current call if one is in call
2418 * @ingroup call_control
2420 LinphoneCall *linphone_core_get_current_call(const LinphoneCore *lc)
2422 return lc->current_call;
2426 * Pauses the call. If a music file has been setup using linphone_core_set_play_file(),
2427 * this file will be played to the remote user.
2429 * @ingroup call_control
2431 int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *the_call)
2433 LinphoneCall *call = the_call;
2435 if (call->state!=LinphoneCallStreamsRunning && call->state!=LinphoneCallPausedByRemote){
2436 ms_warning("Cannot pause this call, it is not active.");
2440 if (sal_call_hold(call->op,TRUE) != 0)
2442 if (lc->vtable.display_warning)
2443 lc->vtable.display_warning(lc,_("Could not pause the call"));
2445 linphone_call_set_state(call,LinphoneCallPausing,"Pausing call");
2446 if (lc->vtable.display_status)
2447 lc->vtable.display_status(lc,_("Pausing the current call..."));
2448 lc->current_call=NULL;
2449 if (call->audiostream || call->videostream)
2450 linphone_call_stop_media_streams (call);
2455 * Pause all currently running calls.
2457 int linphone_core_pause_all_calls(LinphoneCore *lc){
2459 for(elem=lc->calls;elem!=NULL;elem=elem->next){
2460 LinphoneCall *call=(LinphoneCall *)elem->data;
2461 LinphoneCallState cs=linphone_call_get_state(call);
2462 if (cs==LinphoneCallStreamsRunning || cs==LinphoneCallPausedByRemote){
2463 linphone_core_pause_call(lc,call);
2472 * @ingroup call_control
2474 int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call)
2477 LinphoneCall *call = the_call;
2479 if(call->state!=LinphoneCallPaused ){
2480 ms_warning("we cannot resume a call that has not been established and paused before");
2483 if(linphone_core_get_current_call(lc) != NULL){
2484 ms_warning("There is already a call in process, pause or stop it first.");
2485 if (lc->vtable.display_warning)
2486 lc->vtable.display_warning(lc,_("There is already a call in process, pause or stop it first."));
2489 ms_message("Resuming call %p",call);
2490 if(sal_call_hold(call->op,FALSE) != 0){
2493 linphone_call_set_state (call,LinphoneCallResuming,"Resuming");
2494 snprintf(temp,sizeof(temp)-1,"Resuming the call with %s",linphone_call_get_remote_address_as_string(call));
2495 if (lc->vtable.display_status)
2496 lc->vtable.display_status(lc,temp);
2497 lc->current_call=call;
2501 static int remote_address_compare(LinphoneCall *call, const LinphoneAddress *raddr){
2502 const LinphoneAddress *addr=linphone_call_get_remote_address (call);
2503 return !linphone_address_weak_equal (addr,raddr);
2507 * Get the call with the remote_address specified
2509 * @param remote_address
2510 * @return the LinphoneCall of the call if found
2512 LinphoneCall *linphone_core_get_call_by_remote_address(LinphoneCore *lc, const char *remote_address){
2513 LinphoneAddress *raddr=linphone_address_new(remote_address);
2514 MSList *elem=ms_list_find_custom(lc->calls,(int (*)(const void*,const void *))remote_address_compare,raddr);
2515 if (elem) return (LinphoneCall*) elem->data;
2519 int linphone_core_send_publish(LinphoneCore *lc,
2520 LinphoneOnlineStatus presence_mode)
2523 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=ms_list_next(elem)){
2524 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2525 if (cfg->publish) linphone_proxy_config_send_publish(cfg,presence_mode);
2531 * Set the incoming call timeout in seconds.
2533 * @ingroup call_control
2534 * If an incoming call isn't answered for this timeout period, it is
2535 * automatically declined.
2537 void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
2538 lc->sip_conf.inc_timeout=seconds;
2542 * Returns the incoming call timeout
2544 * @ingroup call_control
2545 * See linphone_core_set_inc_timeout() for details.
2547 int linphone_core_get_inc_timeout(LinphoneCore *lc){
2548 return lc->sip_conf.inc_timeout;
2551 void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
2552 const char *contact,
2553 LinphoneOnlineStatus presence_mode)
2555 if (minutes_away>0) lc->minutes_away=minutes_away;
2557 if (lc->alt_contact!=NULL) {
2558 ms_free(lc->alt_contact);
2559 lc->alt_contact=NULL;
2561 if (contact) lc->alt_contact=ms_strdup(contact);
2562 if (lc->presence_mode!=presence_mode){
2563 linphone_core_notify_all_friends(lc,presence_mode);
2565 Improve the use of all LINPHONE_STATUS available.
2566 !TODO Do not mix "presence status" with "answer status code"..
2567 Use correct parameter to follow sip_if_match/sip_etag.
2569 linphone_core_send_publish(lc,presence_mode);
2571 lc->presence_mode=presence_mode;
2574 LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
2575 return lc->presence_mode;
2579 * Get playback sound level in 0-100 scale.
2581 * @ingroup media_parameters
2583 int linphone_core_get_play_level(LinphoneCore *lc)
2585 return lc->sound_conf.play_lev;
2589 * Get ring sound level in 0-100 scale
2591 * @ingroup media_parameters
2593 int linphone_core_get_ring_level(LinphoneCore *lc)
2595 return lc->sound_conf.ring_lev;
2599 * Get sound capture level in 0-100 scale
2601 * @ingroup media_parameters
2603 int linphone_core_get_rec_level(LinphoneCore *lc){
2604 return lc->sound_conf.rec_lev;
2608 * Set sound ring level in 0-100 scale
2610 * @ingroup media_parameters
2612 void linphone_core_set_ring_level(LinphoneCore *lc, int level){
2614 lc->sound_conf.ring_lev=level;
2615 sndcard=lc->sound_conf.ring_sndcard;
2616 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2620 * Allow to control play level before entering sound card: gain in db
2622 * @ingroup media_parameters
2624 void linphone_core_set_playback_gain_db (LinphoneCore *lc, float gaindb){
2626 LinphoneCall *call=linphone_core_get_current_call (lc);
2629 lc->sound_conf.soft_play_lev=gaindb;
2631 if (call==NULL || (st=call->audiostream)==NULL){
2632 ms_message("linphone_core_set_playback_gain_db(): no active call.");
2636 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_DB_GAIN,&gain);
2637 }else ms_warning("Could not apply gain: gain control wasn't activated.");
2641 * Get playback gain in db before entering sound card.
2643 * @ingroup media_parameters
2645 float linphone_core_get_playback_gain_db(LinphoneCore *lc) {
2646 return lc->sound_conf.soft_play_lev;
2650 * Set sound playback level in 0-100 scale
2652 * @ingroup media_parameters
2654 void linphone_core_set_play_level(LinphoneCore *lc, int level){
2656 lc->sound_conf.play_lev=level;
2657 sndcard=lc->sound_conf.play_sndcard;
2658 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2662 * Set sound capture level in 0-100 scale
2664 * @ingroup media_parameters
2666 void linphone_core_set_rec_level(LinphoneCore *lc, int level)
2669 lc->sound_conf.rec_lev=level;
2670 sndcard=lc->sound_conf.capt_sndcard;
2671 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_CAPTURE,level);
2674 static MSSndCard *get_card_from_string_id(const char *devid, unsigned int cap){
2675 MSSndCard *sndcard=NULL;
2677 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2678 if (sndcard!=NULL &&
2679 (ms_snd_card_get_capabilities(sndcard) & cap)==0 ){
2680 ms_warning("%s card does not have the %s capability, ignoring.",
2682 cap==MS_SND_CARD_CAP_CAPTURE ? "capture" : "playback");
2686 if (sndcard==NULL) {
2687 /* get a card that has read+write capabilities */
2688 sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
2689 /* otherwise refine to the first card having the right capability*/
2691 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2692 for(;elem!=NULL;elem=elem->next){
2693 sndcard=(MSSndCard*)elem->data;
2694 if (ms_snd_card_get_capabilities(sndcard) & cap) break;
2697 if (sndcard==NULL){/*looks like a bug! take the first one !*/
2698 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2699 if (elem) sndcard=(MSSndCard*)elem->data;
2702 if (sndcard==NULL) ms_error("Could not find a suitable soundcard !");
2707 * Returns true if the specified sound device can capture sound.
2709 * @ingroup media_parameters
2710 * @param devid the device name as returned by linphone_core_get_sound_devices()
2712 bool_t linphone_core_sound_device_can_capture(LinphoneCore *lc, const char *devid){
2714 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2715 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_CAPTURE)) return TRUE;
2720 * Returns true if the specified sound device can play sound.
2722 * @ingroup media_parameters
2723 * @param devid the device name as returned by linphone_core_get_sound_devices()
2725 bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *devid){
2727 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2728 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_PLAYBACK)) return TRUE;
2733 * Sets the sound device used for ringing.
2735 * @ingroup media_parameters
2736 * @param devid the device name as returned by linphone_core_get_sound_devices()
2738 int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
2739 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2740 lc->sound_conf.ring_sndcard=card;
2741 if (card && linphone_core_ready(lc))
2742 lp_config_set_string(lc->config,"sound","ringer_dev_id",ms_snd_card_get_string_id(card));
2747 * Sets the sound device used for playback.
2749 * @ingroup media_parameters
2750 * @param devid the device name as returned by linphone_core_get_sound_devices()
2752 int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
2753 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2754 lc->sound_conf.play_sndcard=card;
2755 if (card && linphone_core_ready(lc))
2756 lp_config_set_string(lc->config,"sound","playback_dev_id",ms_snd_card_get_string_id(card));
2761 * Sets the sound device used for capture.
2763 * @ingroup media_parameters
2764 * @param devid the device name as returned by linphone_core_get_sound_devices()
2766 int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
2767 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_CAPTURE);
2768 lc->sound_conf.capt_sndcard=card;
2769 if (card && linphone_core_ready(lc))
2770 lp_config_set_string(lc->config,"sound","capture_dev_id",ms_snd_card_get_string_id(card));
2775 * Returns the name of the currently assigned sound device for ringing.
2777 * @ingroup media_parameters
2779 const char * linphone_core_get_ringer_device(LinphoneCore *lc)
2781 if (lc->sound_conf.ring_sndcard) return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
2786 * Returns the name of the currently assigned sound device for playback.
2788 * @ingroup media_parameters
2790 const char * linphone_core_get_playback_device(LinphoneCore *lc)
2792 return lc->sound_conf.play_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.play_sndcard) : NULL;
2796 * Returns the name of the currently assigned sound device for capture.
2798 * @ingroup media_parameters
2800 const char * linphone_core_get_capture_device(LinphoneCore *lc)
2802 return lc->sound_conf.capt_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard) : NULL;
2806 * Returns an unmodifiable array of available sound devices.
2808 * @ingroup media_parameters
2809 * The array is NULL terminated.
2811 const char** linphone_core_get_sound_devices(LinphoneCore *lc){
2812 build_sound_devices_table(lc);
2813 return lc->sound_conf.cards;
2817 * Returns an unmodifiable array of available video capture devices.
2819 * @ingroup media_parameters
2820 * The array is NULL terminated.
2822 const char** linphone_core_get_video_devices(const LinphoneCore *lc){
2823 return lc->video_conf.cams;
2826 char linphone_core_get_sound_source(LinphoneCore *lc)
2828 return lc->sound_conf.source;
2831 void linphone_core_set_sound_source(LinphoneCore *lc, char source)
2833 MSSndCard *sndcard=lc->sound_conf.capt_sndcard;
2834 lc->sound_conf.source=source;
2835 if (!sndcard) return;
2838 ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
2841 ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
2849 * Sets the path to a wav file used for ringing.
2851 * @param path The file must be a wav 16bit linear. Local ring is disabled if null
2853 * @ingroup media_parameters
2855 void linphone_core_set_ring(LinphoneCore *lc,const char *path){
2856 if (lc->sound_conf.local_ring!=0){
2857 ms_free(lc->sound_conf.local_ring);
2859 lc->sound_conf.local_ring=ms_strdup(path);
2860 if ( linphone_core_ready(lc) && lc->sound_conf.local_ring)
2861 lp_config_set_string(lc->config,"sound","local_ring",lc->sound_conf.local_ring);
2865 * Returns the path to the wav file used for ringing.
2867 * @ingroup media_parameters
2869 const char *linphone_core_get_ring(const LinphoneCore *lc){
2870 return lc->sound_conf.local_ring;
2873 static void notify_end_of_ring(void *ud, MSFilter *f, unsigned int event, void *arg){
2874 LinphoneCore *lc=(LinphoneCore*)ud;
2875 lc->preview_finished=1;
2878 int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata)
2880 if (lc->ringstream!=0){
2881 ms_warning("Cannot start ring now,there's already a ring being played");
2884 lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
2885 lc->preview_finished=0;
2886 if (lc->sound_conf.ring_sndcard!=NULL){
2887 MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
2888 lc->ringstream=ring_start_with_cb(ring,2000,ringcard,notify_end_of_ring,(void *)lc);
2894 * Sets the path to a wav file used for ringing back.
2896 * Ringback means the ring that is heard when it's ringing at the remote party.
2897 * The file must be a wav 16bit linear.
2899 * @ingroup media_parameters
2901 void linphone_core_set_ringback(LinphoneCore *lc, const char *path){
2902 if (lc->sound_conf.remote_ring!=0){
2903 ms_free(lc->sound_conf.remote_ring);
2905 lc->sound_conf.remote_ring=ms_strdup(path);
2909 * Returns the path to the wav file used for ringing back.
2911 * @ingroup media_parameters
2913 const char * linphone_core_get_ringback(const LinphoneCore *lc){
2914 return lc->sound_conf.remote_ring;
2918 * Enables or disable echo cancellation. Value is saved an used for subsequent calls
2920 * @ingroup media_parameters
2922 void linphone_core_enable_echo_cancellation(LinphoneCore *lc, bool_t val){
2923 lc->sound_conf.ec=val;
2924 if ( linphone_core_ready(lc))
2925 lp_config_set_int(lc->config,"sound","echocancellation",val);
2930 * Returns TRUE if echo cancellation is enabled.
2932 * @ingroup media_parameters
2934 bool_t linphone_core_echo_cancellation_enabled(LinphoneCore *lc){
2935 return lc->sound_conf.ec;
2938 void linphone_core_enable_echo_limiter(LinphoneCore *lc, bool_t val){
2939 lc->sound_conf.ea=val;
2942 bool_t linphone_core_echo_limiter_enabled(const LinphoneCore *lc){
2943 return lc->sound_conf.ea;
2947 * Mutes or unmutes the local microphone.
2949 * @ingroup media_parameters
2951 void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){
2952 LinphoneCall *call=linphone_core_get_current_call(lc);
2954 ms_warning("linphone_core_mute_mic(): No current call !");
2957 if (call->audiostream!=NULL){
2958 audio_stream_set_mic_gain(call->audiostream,
2959 (val==TRUE) ? 0 : lp_config_get_float(lc->config,"sound","mic_gain",1));
2960 if ( linphone_core_get_rtp_no_xmit_on_audio_mute(lc) ){
2961 audio_stream_mute_rtp(call->audiostream,val);
2963 call->audio_muted=val;
2967 bool_t linphone_core_is_mic_muted(LinphoneCore *lc) {
2968 LinphoneCall *call=linphone_core_get_current_call(lc);
2970 ms_warning("linphone_core_is_mic_muted(): No current call !");
2973 return call->audio_muted;
2976 // returns rtp transmission status for an active stream
2977 // if audio is muted and config parameter rtp_no_xmit_on_audio_mute
2978 // was set on then rtp transmission is also muted
2979 bool_t linphone_core_is_rtp_muted(LinphoneCore *lc){
2980 LinphoneCall *call=linphone_core_get_current_call(lc);
2982 ms_warning("linphone_core_is_mic_muted(): No current call !");
2985 if( linphone_core_get_rtp_no_xmit_on_audio_mute(lc)){
2986 return call->audio_muted;
2991 void linphone_core_enable_agc(LinphoneCore *lc, bool_t val){
2992 lc->sound_conf.agc=val;
2995 bool_t linphone_core_agc_enabled(const LinphoneCore *lc){
2996 return lc->sound_conf.agc;
3000 * Send the specified dtmf.
3002 * @ingroup media_parameters
3003 * This function only works during calls. The dtmf is automatically played to the user.
3004 * @param lc The LinphoneCore object
3005 * @param dtmf The dtmf name specified as a char, such as '0', '#' etc...
3008 void linphone_core_send_dtmf(LinphoneCore *lc, char dtmf)
3010 LinphoneCall *call=linphone_core_get_current_call(lc);
3012 ms_warning("linphone_core_send_dtmf(): no active call");
3015 /*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
3016 if (linphone_core_get_use_rfc2833_for_dtmf(lc)!=0 || linphone_core_get_use_info_for_dtmf(lc)==0)
3019 if (call->audiostream!=NULL){
3020 audio_stream_send_dtmf(call->audiostream,dtmf);
3024 ms_error("we cannot send RFC2833 dtmf when we are not in communication");
3027 if (linphone_core_get_use_info_for_dtmf(lc)!=0){
3028 /* Out of Band DTMF (use INFO method) */
3029 sal_call_send_dtmf(call->op,dtmf);
3033 void linphone_core_set_stun_server(LinphoneCore *lc, const char *server){
3034 if (lc->net_conf.stun_server!=NULL)
3035 ms_free(lc->net_conf.stun_server);
3037 lc->net_conf.stun_server=ms_strdup(server);
3038 else lc->net_conf.stun_server=NULL;
3041 const char * linphone_core_get_stun_server(const LinphoneCore *lc){
3042 return lc->net_conf.stun_server;
3045 const char * linphone_core_get_relay_addr(const LinphoneCore *lc){
3046 return lc->net_conf.relay;
3049 int linphone_core_set_relay_addr(LinphoneCore *lc, const char *addr){
3050 if (lc->net_conf.relay!=NULL){
3051 ms_free(lc->net_conf.relay);
3052 lc->net_conf.relay=NULL;
3055 lc->net_conf.relay=ms_strdup(addr);
3060 void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
3062 if (lc->net_conf.nat_address!=NULL){
3063 ms_free(lc->net_conf.nat_address);
3065 if (addr!=NULL) lc->net_conf.nat_address=ms_strdup(addr);
3066 else lc->net_conf.nat_address=NULL;
3067 if (lc->sip_conf.contact) update_primary_contact(lc);
3070 const char *linphone_core_get_nat_address(const LinphoneCore *lc)
3072 return lc->net_conf.nat_address;
3075 void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
3076 lc->net_conf.firewall_policy=pol;
3077 if (lc->sip_conf.contact) update_primary_contact(lc);
3080 LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
3081 return lc->net_conf.firewall_policy;
3085 * Get the list of call logs (past calls).
3087 * @ingroup call_logs
3089 const MSList * linphone_core_get_call_logs(LinphoneCore *lc){
3091 return lc->call_logs;
3095 * Erase the call log.
3097 * @ingroup call_logs
3099 void linphone_core_clear_call_logs(LinphoneCore *lc){
3101 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3102 lc->call_logs=ms_list_free(lc->call_logs);
3103 call_logs_write_to_config_file(lc);
3106 static void toggle_video_preview(LinphoneCore *lc, bool_t val){
3107 #ifdef VIDEO_ENABLED
3109 if (lc->previewstream==NULL){
3110 lc->previewstream=video_preview_new();
3111 video_preview_set_size(lc->previewstream,lc->video_conf.vsize);
3112 if (lc->video_conf.displaytype)
3113 video_preview_set_display_filter_name(lc->previewstream,lc->video_conf.displaytype);
3114 if (lc->preview_window_id!=0)
3115 video_preview_set_native_window_id(lc->previewstream,lc->preview_window_id);
3116 video_preview_start(lc->previewstream,lc->video_conf.device);
3119 if (lc->previewstream!=NULL){
3120 video_preview_stop(lc->previewstream);
3121 lc->previewstream=NULL;
3128 * Enables video globally.
3130 * @ingroup media_parameters
3131 * This function does not have any effect during calls. It just indicates LinphoneCore to
3132 * initiate future calls with video or not. The two boolean parameters indicate in which
3133 * direction video is enabled. Setting both to false disables video entirely.
3135 * @param vcap_enabled indicates whether video capture is enabled
3136 * @param display_enabled indicates whether video display should be shown
3139 void linphone_core_enable_video(LinphoneCore *lc, bool_t vcap_enabled, bool_t display_enabled){
3140 #ifndef VIDEO_ENABLED
3141 if (vcap_enabled || display_enabled)
3142 ms_warning("This version of linphone was built without video support.");
3144 lc->video_conf.capture=vcap_enabled;
3145 lc->video_conf.display=display_enabled;
3147 /* need to re-apply network bandwidth settings*/
3148 linphone_core_set_download_bandwidth(lc,
3149 linphone_core_get_download_bandwidth(lc));
3150 linphone_core_set_upload_bandwidth(lc,
3151 linphone_core_get_upload_bandwidth(lc));
3155 * Returns TRUE if video is enabled, FALSE otherwise.
3156 * @ingroup media_parameters
3158 bool_t linphone_core_video_enabled(LinphoneCore *lc){
3159 return (lc->video_conf.display || lc->video_conf.capture);
3163 * Controls video preview enablement.
3165 * @ingroup media_parameters
3166 * Video preview refers to the action of displaying the local webcam image
3167 * to the user while not in call.
3169 void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val){
3170 lc->video_conf.show_local=val;
3174 * Returns TRUE if video previewing is enabled.
3175 * @ingroup media_parameters
3177 bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
3178 return lc->video_conf.show_local;
3182 * Enables or disable self view during calls.
3184 * @ingroup media_parameters
3185 * Self-view refers to having local webcam image inserted in corner
3186 * of the video window during calls.
3187 * This function works at any time, including during calls.
3189 void linphone_core_enable_self_view(LinphoneCore *lc, bool_t val){
3190 #ifdef VIDEO_ENABLED
3191 LinphoneCall *call=linphone_core_get_current_call (lc);
3192 lc->video_conf.selfview=val;
3193 if (call && call->videostream){
3194 video_stream_enable_self_view(call->videostream,val);
3200 * Returns TRUE if self-view is enabled, FALSE otherwise.
3202 * @ingroup media_parameters
3204 * Refer to linphone_core_enable_self_view() for details.
3206 bool_t linphone_core_self_view_enabled(const LinphoneCore *lc){
3207 return lc->video_conf.selfview;
3211 * Sets the active video device.
3213 * @ingroup media_parameters
3214 * @param id the name of the video device as returned by linphone_core_get_video_devices()
3216 int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
3217 MSWebCam *olddev=lc->video_conf.device;
3220 lc->video_conf.device=ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),id);
3221 if (lc->video_conf.device==NULL){
3222 ms_warning("Could not found video device %s",id);
3225 if (lc->video_conf.device==NULL)
3226 lc->video_conf.device=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());
3227 if (olddev!=NULL && olddev!=lc->video_conf.device){
3228 toggle_video_preview(lc,FALSE);/*restart the video local preview*/
3230 if ( linphone_core_ready(lc) && lc->video_conf.device){
3231 vd=ms_web_cam_get_string_id(lc->video_conf.device);
3232 if (vd && strstr(vd,"Static picture")!=NULL){
3235 lp_config_set_string(lc->config,"video","device",vd);
3241 * Returns the name of the currently active video device.
3243 * @ingroup media_parameters
3245 const char *linphone_core_get_video_device(const LinphoneCore *lc){
3246 if (lc->video_conf.device) return ms_web_cam_get_string_id(lc->video_conf.device);
3250 #ifdef VIDEO_ENABLED
3251 static VideoStream * get_active_video_stream(LinphoneCore *lc){
3252 VideoStream *vs = NULL;
3253 LinphoneCall *call=linphone_core_get_current_call (lc);
3254 /* Select the video stream from the call in the first place */
3255 if (call && call->videostream) {
3256 vs = call->videostream;
3258 /* If not in call, select the video stream from the preview */
3259 if (vs == NULL && lc->previewstream) {
3260 vs = lc->previewstream;
3266 int linphone_core_set_static_picture(LinphoneCore *lc, const char *path) {
3267 #ifdef VIDEO_ENABLED
3268 VideoStream *vs=get_active_video_stream(lc);
3269 /* If we have a video stream (either preview, either from call), we
3270 have a source and it is using the static picture filter, then
3271 force the filter to use that picture. */
3272 if (vs && vs->source) {
3273 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3274 ms_filter_call_method(vs->source, MS_STATIC_IMAGE_SET_IMAGE,
3278 /* Tell the static image filter to use that image from now on so
3279 that the image will be used next time it has to be read */
3280 ms_static_image_set_default_image(path);
3282 ms_warning("Video support not compiled.");
3287 int linphone_core_set_static_picture_fps(LinphoneCore *lc, float fps) {
3288 #ifdef VIDEO_ENABLED
3289 VideoStream *vs = NULL;
3291 vs=get_active_video_stream(lc);
3293 /* If we have a video stream (either preview, either from call), we
3294 have a source and it is using the static picture filter, then
3295 force the filter to use that picture. */
3296 if (vs && vs->source) {
3297 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3298 ms_filter_call_method(vs->source, MS_FILTER_SET_FPS,(void *)&fps);
3302 ms_warning("Video support not compiled.");
3307 float linphone_core_get_static_picture_fps(LinphoneCore *lc) {
3308 #ifdef VIDEO_ENABLED
3309 VideoStream *vs = NULL;
3310 vs=get_active_video_stream(lc);
3311 /* If we have a video stream (either preview, either from call), we
3312 have a source and it is using the static picture filter, then
3313 force the filter to use that picture. */
3314 if (vs && vs->source) {
3315 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3319 ms_filter_call_method(vs->source, MS_FILTER_GET_FPS,(void *)&fps);
3324 ms_warning("Video support not compiled.");
3330 * Returns the native window handle of the video window, casted as an unsigned long.
3332 * @ingroup media_parameters
3334 unsigned long linphone_core_get_native_video_window_id(const LinphoneCore *lc){
3335 #ifdef VIDEO_ENABLED
3336 LinphoneCall *call=linphone_core_get_current_call (lc);
3337 if (call && call->videostream)
3338 return video_stream_get_native_window_id(call->videostream);
3339 if (lc->previewstream)
3340 return video_stream_get_native_window_id(lc->previewstream);
3342 return lc->video_window_id;
3346 * Set the native video window id where the video is to be displayed.
3347 * If not set the core will create its own window.
3349 void linphone_core_set_native_video_window_id(LinphoneCore *lc, unsigned long id){
3350 #ifdef VIDEO_ENABLED
3351 LinphoneCall *call=linphone_core_get_current_call(lc);
3352 lc->video_window_id=id;
3353 if (call!=NULL && call->videostream){
3354 video_stream_set_native_window_id(call->videostream,id);
3360 * Returns the native window handle of the video preview window, casted as an unsigned long.
3362 * @ingroup media_parameters
3364 unsigned long linphone_core_get_native_preview_window_id(const LinphoneCore *lc){
3365 #ifdef VIDEO_ENABLED
3366 LinphoneCall *call=linphone_core_get_current_call (lc);
3367 if (call && call->videostream)
3368 return video_stream_get_native_preview_window_id(call->videostream);
3369 if (lc->previewstream)
3370 return video_preview_get_native_window_id(lc->previewstream);
3372 return lc->preview_window_id;
3376 * Set the native window id where the preview video (local camera) is to be displayed.
3377 * This has to be used in conjonction with linphone_core_use_preview_window().
3378 * If not set the core will create its own window.
3380 void linphone_core_set_native_preview_window_id(LinphoneCore *lc, unsigned long id){
3381 lc->preview_window_id=id;
3385 * Tells the core to use a separate window for local camera preview video, instead of
3386 * inserting local view within the remote video window.
3389 void linphone_core_use_preview_window(LinphoneCore *lc, bool_t yesno){
3390 lc->use_preview_window=yesno;
3393 static MSVideoSizeDef supported_resolutions[]={
3394 { {MS_VIDEO_SIZE_SVGA_W,MS_VIDEO_SIZE_SVGA_H} , "svga" },
3395 { {MS_VIDEO_SIZE_4CIF_W,MS_VIDEO_SIZE_4CIF_H} , "4cif" },
3396 { {MS_VIDEO_SIZE_VGA_W,MS_VIDEO_SIZE_VGA_H} , "vga" },
3397 { {MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H} , "cif" },
3398 { {MS_VIDEO_SIZE_QVGA_W,MS_VIDEO_SIZE_QVGA_H} , "qvga" },
3399 { {MS_VIDEO_SIZE_QVGA_H,MS_VIDEO_SIZE_QVGA_W} , "qvga-portrait" },
3400 { {MS_VIDEO_SIZE_QCIF_W,MS_VIDEO_SIZE_QCIF_H} , "qcif" },
3401 { {MS_VIDEO_SIZE_QCIF_H,MS_VIDEO_SIZE_QCIF_W} , "qcif-portrait" },
3406 * Returns the zero terminated table of supported video resolutions.
3408 * @ingroup media_parameters
3410 const MSVideoSizeDef *linphone_core_get_supported_video_sizes(LinphoneCore *lc){
3411 return supported_resolutions;
3414 static MSVideoSize video_size_get_by_name(const char *name){
3415 MSVideoSizeDef *pdef=supported_resolutions;
3416 MSVideoSize null_vsize={0,0};
3417 for(;pdef->name!=NULL;pdef++){
3418 if (strcasecmp(name,pdef->name)==0){
3422 ms_warning("Video resolution %s is not supported in linphone.",name);
3426 static const char *video_size_get_name(MSVideoSize vsize){
3427 MSVideoSizeDef *pdef=supported_resolutions;
3428 for(;pdef->name!=NULL;pdef++){
3429 if (pdef->vsize.width==vsize.width && pdef->vsize.height==vsize.height){
3436 static bool_t video_size_supported(MSVideoSize vsize){
3437 if (video_size_get_name(vsize)) return TRUE;
3438 ms_warning("Video resolution %ix%i is not supported in linphone.",vsize.width,vsize.height);
3443 * Sets the preferred video size.
3445 * @ingroup media_parameters
3446 * This applies only to the stream that is captured and sent to the remote party,
3447 * since we accept all standard video size on the receive path.
3449 void linphone_core_set_preferred_video_size(LinphoneCore *lc, MSVideoSize vsize){
3450 if (video_size_supported(vsize)){
3451 MSVideoSize oldvsize=lc->video_conf.vsize;
3452 lc->video_conf.vsize=vsize;
3453 if (!ms_video_size_equal(oldvsize,vsize) && lc->previewstream!=NULL){
3454 toggle_video_preview(lc,FALSE);
3455 toggle_video_preview(lc,TRUE);
3457 if ( linphone_core_ready(lc))
3458 lp_config_set_string(lc->config,"video","size",video_size_get_name(vsize));
3463 * Sets the preferred video size by its name.
3465 * @ingroup media_parameters
3466 * This is identical to linphone_core_set_preferred_video_size() except
3467 * that it takes the name of the video resolution as input.
3468 * Video resolution names are: qcif, svga, cif, vga, 4cif, svga ...
3470 void linphone_core_set_preferred_video_size_by_name(LinphoneCore *lc, const char *name){
3471 MSVideoSize vsize=video_size_get_by_name(name);
3472 MSVideoSize default_vsize={MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H};
3473 if (vsize.width!=0) linphone_core_set_preferred_video_size(lc,vsize);
3474 else linphone_core_set_preferred_video_size(lc,default_vsize);
3478 * Returns the current preferred video size for sending.
3480 * @ingroup media_parameters
3482 MSVideoSize linphone_core_get_preferred_video_size(LinphoneCore *lc){
3483 return lc->video_conf.vsize;
3487 * Ask the core to stream audio from and to files, instead of using the soundcard.
3489 void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
3490 lc->use_files=yesno;
3494 * Sets a wav file to be played when putting somebody on hold,
3495 * or when files are used instead of soundcards (see linphone_core_use_files()).
3497 * The file must be a 16 bit linear wav file.
3499 void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
3500 LinphoneCall *call=linphone_core_get_current_call(lc);
3501 if (lc->play_file!=NULL){
3502 ms_free(lc->play_file);
3506 lc->play_file=ms_strdup(file);
3507 if (call && call->audiostream && call->audiostream->ticker)
3508 audio_stream_play(call->audiostream,file);
3514 * Sets a wav file where incoming stream is to be recorded,
3515 * when files are used instead of soundcards (see linphone_core_use_files()).
3517 * The file must be a 16 bit linear wav file.
3519 void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
3520 LinphoneCall *call=linphone_core_get_current_call(lc);
3521 if (lc->rec_file!=NULL){
3522 ms_free(lc->rec_file);
3526 lc->rec_file=ms_strdup(file);
3527 if (call && call->audiostream)
3528 audio_stream_record(call->audiostream,file);
3533 static MSFilter *get_dtmf_gen(LinphoneCore *lc){
3534 LinphoneCall *call=linphone_core_get_current_call (lc);
3536 AudioStream *stream=call->audiostream;
3538 return stream->dtmfgen;
3541 if (lc->ringstream==NULL){
3542 MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
3543 lc->ringstream=ring_start(NULL,0,ringcard);
3544 lc->dmfs_playing_start_time=time(NULL);
3546 if (lc->dmfs_playing_start_time!=0)
3547 lc->dmfs_playing_start_time=time(NULL);
3549 return lc->ringstream->gendtmf;
3553 * Plays a dtmf to the local user.
3555 void linphone_core_play_dtmf(LinphoneCore *lc, char dtmf, int duration_ms){
3556 MSFilter *f=get_dtmf_gen(lc);
3558 ms_error("No dtmf generator at this time !");
3562 ms_filter_call_method(f, MS_DTMF_GEN_PLAY, &dtmf);
3563 else ms_filter_call_method(f, MS_DTMF_GEN_START, &dtmf);
3567 * Stops playing a dtmf started by linphone_core_play_dtmf().
3569 void linphone_core_stop_dtmf(LinphoneCore *lc){
3570 MSFilter *f=get_dtmf_gen(lc);
3572 ms_filter_call_method_noarg (f, MS_DTMF_GEN_STOP);
3578 * Retrieves the user pointer that was given to linphone_core_new()
3580 * @ingroup initializing
3582 void *linphone_core_get_user_data(LinphoneCore *lc){
3586 int linphone_core_get_mtu(const LinphoneCore *lc){
3587 return lc->net_conf.mtu;
3590 void linphone_core_set_mtu(LinphoneCore *lc, int mtu){
3591 lc->net_conf.mtu=mtu;
3594 ms_error("MTU too small !");
3598 ms_message("MTU is supposed to be %i, rtp payload max size will be %i",mtu, ms_get_payload_max_size());
3599 }else ms_set_mtu(0);//use mediastreamer2 default value
3602 void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context){
3604 lc->wait_ctx=user_context;
3607 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose){
3609 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingStart,purpose,0);
3613 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progress){
3615 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingProgress,purpose,progress);
3625 void linphone_core_stop_waiting(LinphoneCore *lc){
3627 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingFinished,NULL,0);
3631 void linphone_core_set_audio_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3637 * Retrieve RTP statistics regarding current call.
3638 * @param local RTP statistics computed locally.
3639 * @param remote RTP statistics computed by far end (obtained via RTCP feedback).
3641 * @note Remote RTP statistics is not implemented yet.
3643 * @returns 0 or -1 if no call is running.
3646 int linphone_core_get_current_call_stats(LinphoneCore *lc, rtp_stats_t *local, rtp_stats_t *remote){
3647 LinphoneCall *call=linphone_core_get_current_call (lc);
3649 if (call->audiostream!=NULL){
3650 memset(remote,0,sizeof(*remote));
3651 audio_stream_get_local_rtp_stats (call->audiostream,local);
3658 void net_config_uninit(LinphoneCore *lc)
3660 net_config_t *config=&lc->net_conf;
3661 lp_config_set_int(lc->config,"net","download_bw",config->download_bw);
3662 lp_config_set_int(lc->config,"net","upload_bw",config->upload_bw);
3664 if (config->stun_server!=NULL){
3665 lp_config_set_string(lc->config,"net","stun_server",config->stun_server);
3666 ms_free(lc->net_conf.stun_server);
3668 if (config->nat_address!=NULL){
3669 lp_config_set_string(lc->config,"net","nat_address",config->nat_address);
3670 ms_free(lc->net_conf.nat_address);
3672 lp_config_set_int(lc->config,"net","firewall_policy",config->firewall_policy);
3673 lp_config_set_int(lc->config,"net","mtu",config->mtu);
3677 void sip_config_uninit(LinphoneCore *lc)
3681 sip_config_t *config=&lc->sip_conf;
3682 lp_config_set_int(lc->config,"sip","sip_port",config->transports.udp_port);
3683 lp_config_set_int(lc->config,"sip","sip_tcp_port",config->transports.tcp_port);
3684 lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
3685 lp_config_set_string(lc->config,"sip","contact",config->contact);
3686 lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
3687 lp_config_set_int(lc->config,"sip","use_info",config->use_info);
3688 lp_config_set_int(lc->config,"sip","use_rfc2833",config->use_rfc2833);
3689 lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
3690 lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
3693 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
3695 for(elem=config->proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3696 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
3697 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
3698 linphone_proxy_config_edit(cfg); /* to unregister */
3700 /*to ensure remove configs are erased:*/
3701 linphone_proxy_config_write_to_config_file(lc->config,NULL,i);
3704 sal_iterate(lc->sal);
3712 ms_list_for_each(config->proxies,(void (*)(void*)) linphone_proxy_config_destroy);
3713 ms_list_free(config->proxies);
3714 config->proxies=NULL;
3716 linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */
3718 for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3719 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
3720 linphone_auth_info_write_config(lc->config,ai,i);
3722 linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
3723 ms_list_for_each(lc->auth_info,(void (*)(void*))linphone_auth_info_destroy);
3724 ms_list_free(lc->auth_info);
3727 sal_uninit(lc->sal);
3730 if (lc->sip_conf.guessed_contact)
3731 ms_free(lc->sip_conf.guessed_contact);
3732 if (config->contact)
3733 ms_free(config->contact);
3737 void rtp_config_uninit(LinphoneCore *lc)
3739 rtp_config_t *config=&lc->rtp_conf;
3740 lp_config_set_int(lc->config,"rtp","audio_rtp_port",config->audio_rtp_port);
3741 lp_config_set_int(lc->config,"rtp","video_rtp_port",config->video_rtp_port);
3742 lp_config_set_int(lc->config,"rtp","audio_jitt_comp",config->audio_jitt_comp);
3743 lp_config_set_int(lc->config,"rtp","video_jitt_comp",config->video_jitt_comp);
3744 lp_config_set_int(lc->config,"rtp","nortp_timeout",config->nortp_timeout);
3747 void sound_config_uninit(LinphoneCore *lc)
3749 sound_config_t *config=&lc->sound_conf;
3750 ms_free(config->cards);
3752 lp_config_set_string(lc->config,"sound","remote_ring",config->remote_ring);
3754 if (config->local_ring) ms_free(config->local_ring);
3755 if (config->remote_ring) ms_free(config->remote_ring);
3756 ms_snd_card_manager_destroy();
3759 void video_config_uninit(LinphoneCore *lc)
3761 lp_config_set_int(lc->config,"video","enabled",linphone_core_video_enabled(lc));
3762 lp_config_set_string(lc->config,"video","size",video_size_get_name(linphone_core_get_preferred_video_size(lc)));
3763 lp_config_set_int(lc->config,"video","display",lc->video_conf.display);
3764 lp_config_set_int(lc->config,"video","capture",lc->video_conf.capture);
3765 lp_config_set_int(lc->config,"video","show_local",linphone_core_video_preview_enabled(lc));
3766 lp_config_set_int(lc->config,"video","self_view",linphone_core_self_view_enabled(lc));
3767 if (lc->video_conf.cams)
3768 ms_free(lc->video_conf.cams);
3771 void codecs_config_uninit(LinphoneCore *lc)
3774 codecs_config_t *config=&lc->codecs_conf;
3779 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
3780 pt=(PayloadType*)(node->data);
3781 sprintf(key,"audio_codec_%i",index);
3782 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3783 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3784 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3787 sprintf(key,"audio_codec_%i",index);
3788 lp_config_clean_section (lc->config,key);
3791 for(node=config->video_codecs;node!=NULL;node=ms_list_next(node)){
3792 pt=(PayloadType*)(node->data);
3793 sprintf(key,"video_codec_%i",index);
3794 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3795 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3796 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3797 lp_config_set_string(lc->config,key,"recv_fmtp",pt->recv_fmtp);
3800 sprintf(key,"video_codec_%i",index);
3801 lp_config_clean_section (lc->config,key);
3803 ms_list_free(lc->codecs_conf.audio_codecs);
3804 ms_list_free(lc->codecs_conf.video_codecs);
3807 void ui_config_uninit(LinphoneCore* lc)
3810 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_destroy);
3811 ms_list_free(lc->friends);
3817 * Returns the LpConfig object used to manage the storage (config) file.
3820 * The application can use the LpConfig object to insert its own private
3821 * sections and pairs of key=value in the configuration file.
3824 LpConfig *linphone_core_get_config(LinphoneCore *lc){
3828 static void linphone_core_uninit(LinphoneCore *lc)
3832 LinphoneCall *the_call = lc->calls->data;
3833 linphone_core_terminate_call(lc,the_call);
3834 linphone_core_iterate(lc);
3843 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions);
3844 linphone_core_set_state(lc,LinphoneGlobalShutdown,"Shutting down");
3845 #ifdef VIDEO_ENABLED
3846 if (lc->previewstream!=NULL){
3847 video_preview_stop(lc->previewstream);
3848 lc->previewstream=NULL;
3851 ms_event_queue_destroy(lc->msevq);
3853 /* save all config */
3854 net_config_uninit(lc);
3855 sip_config_uninit(lc);
3856 rtp_config_uninit(lc);
3857 sound_config_uninit(lc);
3858 video_config_uninit(lc);
3859 codecs_config_uninit(lc);
3860 ui_config_uninit(lc);
3861 if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
3862 lp_config_destroy(lc->config);
3863 lc->config = NULL; /* Mark the config as NULL to block further calls */
3864 sip_setup_unregister_all();
3866 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3867 lc->call_logs=ms_list_free(lc->call_logs);
3869 linphone_core_free_payload_types();
3872 linphone_core_set_state(lc,LinphoneGlobalOff,"Off");
3875 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t curtime){
3876 ms_message("Network state is now [%s]",isReachable?"UP":"DOWN");
3877 // second get the list of available proxies
3878 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3879 for(;elem!=NULL;elem=elem->next){
3880 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3881 if (linphone_proxy_config_register_enabled(cfg) ) {
3889 lc->netup_time=curtime;
3890 lc->network_reachable=isReachable;
3893 void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) {
3894 //first disable automatic mode
3895 if (lc->auto_net_state_mon) {
3896 ms_message("Disabling automatic network state monitoring");
3897 lc->auto_net_state_mon=FALSE;
3899 set_network_reachable(lc,isReachable, ms_time(NULL));
3902 bool_t linphone_core_is_network_reachabled(LinphoneCore* lc) {
3903 return lc->network_reachable;
3905 ortp_socket_t linphone_core_get_sip_socket(LinphoneCore *lc){
3906 return sal_get_socket(lc->sal);
3909 * Destroys a LinphoneCore
3911 * @ingroup initializing
3913 void linphone_core_destroy(LinphoneCore *lc){
3914 linphone_core_uninit(lc);
3918 * Get the number of Call
3920 * @ingroup call_control
3922 int linphone_core_get_calls_nb(const LinphoneCore *lc){
3923 return ms_list_size(lc->calls);;
3927 * Check if we do not have exceed the number of simultaneous call
3929 * @ingroup call_control
3931 bool_t linphone_core_can_we_add_call(LinphoneCore *lc)
3933 if(linphone_core_get_calls_nb(lc) < NB_MAX_CALLS)
3935 ms_error("Maximum amount of simultaneous calls reached !");
3940 int linphone_core_add_call( LinphoneCore *lc, LinphoneCall *call)
3942 if(linphone_core_can_we_add_call(lc))
3944 lc->calls = ms_list_append(lc->calls,call);
3950 int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call)
3953 MSList *the_calls = lc->calls;
3955 it=ms_list_find(the_calls,call);
3958 the_calls = ms_list_remove_link(the_calls,it);
3962 ms_warning("could not find the call into the list\n");
3965 lc->calls = the_calls;
3970 * Specifiies a ring back tone to be played to far end during incoming calls.
3972 void linphone_core_set_remote_ringback_tone(LinphoneCore *lc, const char *file){
3973 if (lc->sound_conf.ringback_tone){
3974 ms_free(lc->sound_conf.ringback_tone);
3975 lc->sound_conf.ringback_tone=NULL;
3978 lc->sound_conf.ringback_tone=ms_strdup(file);
3982 * Returns the ring back tone played to far end during incoming calls.
3984 const char *linphone_core_get_remote_ringback_tone(const LinphoneCore *lc){
3985 return lc->sound_conf.ringback_tone;
3988 static PayloadType* find_payload_type_from_list(const char* type, int rate,const MSList* from) {
3990 for(elem=from;elem!=NULL;elem=elem->next){
3991 PayloadType *pt=(PayloadType*)elem->data;
3992 if ((strcmp((char*)type, payload_type_get_mime(pt)) == 0) && (rate == -1 || rate==pt->clock_rate)) {
4000 * Get payload type from mime type and clock rate
4001 * @ingroup media_parameters
4002 * This function searches in audio and video codecs for the given payload type name and clockrate.
4003 * Returns NULL if not found.
4005 PayloadType* linphone_core_find_payload_type(LinphoneCore* lc, const char* type, int rate) {
4006 PayloadType* result = find_payload_type_from_list(type, rate, linphone_core_get_audio_codecs(lc));
4010 result = find_payload_type_from_list(type, rate, linphone_core_get_video_codecs(lc));
4019 const char *linphone_global_state_to_string(LinphoneGlobalState gs){
4021 case LinphoneGlobalOff:
4022 return "LinphoneGlobalOff";
4024 case LinphoneGlobalOn:
4025 return "LinphoneGlobalOn";
4027 case LinphoneGlobalStartup:
4028 return "LinphoneGlobalStartup";
4030 case LinphoneGlobalShutdown:
4031 return "LinphoneGlobalShutdown";
4037 LinphoneGlobalState linphone_core_get_global_state(const LinphoneCore *lc){
4041 LinphoneCallParams *linphone_core_create_default_call_parameters(LinphoneCore *lc){
4042 LinphoneCallParams *p=ms_new0(LinphoneCallParams,1);
4043 p->has_video=linphone_core_video_enabled(lc);
4047 const char *linphone_error_to_string(LinphoneReason err){
4049 case LinphoneReasonNone:
4051 case LinphoneReasonNoResponse:
4052 return "No response";
4053 case LinphoneReasonBadCredentials:
4054 return "Bad credentials";
4055 case LinphoneReasonDeclined:
4056 return "Call declined";
4058 return "unknown error";
4061 * enable signaling keep alive
4063 void linphone_core_enable_keep_alive(LinphoneCore* lc,bool_t enable) {
4065 sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
4067 sal_set_keepalive_period(lc->sal,0);
4071 * Is signaling keep alive
4073 bool_t linphone_core_keep_alive_enabled(LinphoneCore* lc) {
4074 return sal_get_keepalive_period(lc->sal) > 0;