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);
42 static void linphone_core_run_hooks(LinphoneCore *lc);
43 static void linphone_core_free_hooks(LinphoneCore *lc);
46 const char *linphone_core_get_nat_address_resolved(LinphoneCore *lc);
47 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result);
48 static void toggle_video_preview(LinphoneCore *lc, bool_t val);
50 /* relative path where is stored local ring*/
51 #define LOCAL_RING "rings/oldphone.wav"
52 /* same for remote ring (ringback)*/
53 #define REMOTE_RING "ringback.wav"
54 #define HOLD_MUSIC "rings/toy-mono.wav"
57 extern SalCallbacks linphone_sal_callbacks;
59 void lc_callback_obj_init(LCCallbackObj *obj,LinphoneCoreCbFunc func,void* ud)
65 int lc_callback_obj_invoke(LCCallbackObj *obj, LinphoneCore *lc){
66 if (obj->_func!=NULL) obj->_func(lc,obj->_user_data);
71 /*prevent a gcc bug with %c*/
72 static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm){
73 #if !defined(_WIN32_WCE)
74 return strftime(s, max, fmt, tm);
81 static void set_call_log_date(LinphoneCallLog *cl, const struct tm *loctime){
82 my_strftime(cl->start_date,sizeof(cl->start_date),"%c",loctime);
85 LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
86 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
90 #if !defined(_WIN32_WCE)
91 loctime=*localtime(&call->start_time);
95 localtime_r(&call->start_time,&loctime);
97 set_call_log_date(cl,&loctime);
100 cl->status=LinphoneCallAborted; /*default status*/
104 void call_logs_write_to_config_file(LinphoneCore *lc){
109 LpConfig *cfg=lc->config;
111 if (linphone_core_get_global_state (lc)==LinphoneGlobalStartup) return;
113 for(i=0,elem=lc->call_logs;elem!=NULL;elem=elem->next,++i){
114 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
115 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
116 lp_config_set_int(cfg,logsection,"dir",cl->dir);
117 lp_config_set_int(cfg,logsection,"status",cl->status);
118 tmp=linphone_address_as_string(cl->from);
119 lp_config_set_string(cfg,logsection,"from",tmp);
121 tmp=linphone_address_as_string(cl->to);
122 lp_config_set_string(cfg,logsection,"to",tmp);
124 lp_config_set_string(cfg,logsection,"start_date",cl->start_date);
125 lp_config_set_int(cfg,logsection,"duration",cl->duration);
126 if (cl->refkey) lp_config_set_string(cfg,logsection,"refkey",cl->refkey);
127 lp_config_set_float(cfg,logsection,"quality",cl->quality);
129 for(;i<lc->max_call_logs;++i){
130 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
131 lp_config_clean_section(cfg,logsection);
135 static void call_logs_read_from_config_file(LinphoneCore *lc){
139 LpConfig *cfg=lc->config;
141 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
142 if (lp_config_has_section(cfg,logsection)){
143 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
144 cl->dir=lp_config_get_int(cfg,logsection,"dir",0);
145 cl->status=lp_config_get_int(cfg,logsection,"status",0);
146 tmp=lp_config_get_string(cfg,logsection,"from",NULL);
147 if (tmp) cl->from=linphone_address_new(tmp);
148 tmp=lp_config_get_string(cfg,logsection,"to",NULL);
149 if (tmp) cl->to=linphone_address_new(tmp);
150 tmp=lp_config_get_string(cfg,logsection,"start_date",NULL);
151 if (tmp) strncpy(cl->start_date,tmp,sizeof(cl->start_date));
152 cl->duration=lp_config_get_int(cfg,logsection,"duration",0);
153 tmp=lp_config_get_string(cfg,logsection,"refkey",NULL);
154 if (tmp) cl->refkey=ms_strdup(tmp);
155 cl->quality=lp_config_get_float(cfg,logsection,"quality",-1);
156 lc->call_logs=ms_list_append(lc->call_logs,cl);
164 * @addtogroup call_logs
169 * Returns a human readable string describing the call.
171 * @note: the returned char* must be freed by the application (use ms_free()).
173 char * linphone_call_log_to_str(LinphoneCallLog *cl){
176 char *from=linphone_address_as_string (cl->from);
177 char *to=linphone_address_as_string (cl->to);
179 case LinphoneCallAborted:
182 case LinphoneCallSuccess:
183 status=_("completed");
185 case LinphoneCallMissed:
191 tmp=ortp_strdup_printf(_("%s at %s\nFrom: %s\nTo: %s\nStatus: %s\nDuration: %i mn %i sec\n"),
192 (cl->dir==LinphoneCallIncoming) ? _("Incoming call") : _("Outgoing call"),
205 * Returns RTP statistics computed locally regarding the call.
208 const rtp_stats_t *linphone_call_log_get_local_stats(const LinphoneCallLog *cl){
209 return &cl->local_stats;
213 * Returns RTP statistics computed by remote end and sent back via RTCP.
215 * @note Not implemented yet.
217 const rtp_stats_t *linphone_call_log_get_remote_stats(const LinphoneCallLog *cl){
218 return &cl->remote_stats;
221 void linphone_call_log_set_user_pointer(LinphoneCallLog *cl, void *up){
225 void *linphone_call_log_get_user_pointer(const LinphoneCallLog *cl){
226 return cl->user_pointer;
232 * Associate a persistent reference key to the call log.
234 * The reference key can be for example an id to an external database.
235 * It is stored in the config file, thus can survive to process exits/restarts.
238 void linphone_call_log_set_ref_key(LinphoneCallLog *cl, const char *refkey){
239 if (cl->refkey!=NULL){
243 if (refkey) cl->refkey=ms_strdup(refkey);
247 * Get the persistent reference key associated to the call log.
249 * The reference key can be for example an id to an external database.
250 * It is stored in the config file, thus can survive to process exits/restarts.
253 const char *linphone_call_log_get_ref_key(const LinphoneCallLog *cl){
259 void linphone_call_log_destroy(LinphoneCallLog *cl){
260 if (cl->from!=NULL) linphone_address_destroy(cl->from);
261 if (cl->to!=NULL) linphone_address_destroy(cl->to);
262 if (cl->refkey!=NULL) ms_free(cl->refkey);
267 * Returns TRUE if the LinphoneCall asked to autoanswer
270 bool_t linphone_call_asked_to_autoanswer(LinphoneCall *call){
271 //return TRUE if the unique(for the moment) incoming call asked to be autoanswered
273 return sal_call_autoanswer_asked(call->op);
278 int linphone_core_get_current_call_duration(const LinphoneCore *lc){
279 LinphoneCall *call=linphone_core_get_current_call((LinphoneCore *)lc);
280 if (call) return linphone_call_get_duration(call);
284 const LinphoneAddress *linphone_core_get_current_call_remote_address(struct _LinphoneCore *lc){
285 LinphoneCall *call=linphone_core_get_current_call(lc);
286 if (call==NULL) return NULL;
287 return linphone_call_get_remote_address(call);
291 * Enable logs in supplied FILE*.
295 * @param file a C FILE* where to fprintf logs. If null stdout is used.
298 void linphone_core_enable_logs(FILE *file){
299 if (file==NULL) file=stdout;
300 ortp_set_log_file(file);
301 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
305 * Enable logs through the user's supplied log callback.
309 * @param logfunc The address of a OrtpLogFunc callback whose protoype is
310 * typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
313 void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc){
314 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
315 ortp_set_log_handler(logfunc);
319 * Entirely disable logging.
323 void linphone_core_disable_logs(){
324 ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
328 static void net_config_read (LinphoneCore *lc)
332 LpConfig *config=lc->config;
334 lc->net_conf.nat_address_ip = NULL;
335 tmp=lp_config_get_int(config,"net","download_bw",0);
336 linphone_core_set_download_bandwidth(lc,tmp);
337 tmp=lp_config_get_int(config,"net","upload_bw",0);
338 linphone_core_set_upload_bandwidth(lc,tmp);
339 linphone_core_set_stun_server(lc,lp_config_get_string(config,"net","stun_server",NULL));
340 tmpstr=lp_config_get_string(lc->config,"net","nat_address",NULL);
341 if (tmpstr!=NULL && (strlen(tmpstr)<1)) tmpstr=NULL;
342 linphone_core_set_nat_address(lc,tmpstr);
343 tmp=lp_config_get_int(lc->config,"net","firewall_policy",0);
344 linphone_core_set_firewall_policy(lc,tmp);
345 tmp=lp_config_get_int(lc->config,"net","nat_sdp_only",0);
346 lc->net_conf.nat_sdp_only=tmp;
347 tmp=lp_config_get_int(lc->config,"net","mtu",0);
348 linphone_core_set_mtu(lc,tmp);
349 tmp=lp_config_get_int(lc->config,"net","download_ptime",0);
350 linphone_core_set_download_ptime(lc,tmp);
354 static void build_sound_devices_table(LinphoneCore *lc){
355 const char **devices;
359 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
360 ndev=ms_list_size(elem);
361 devices=ms_malloc((ndev+1)*sizeof(const char *));
362 for (i=0;elem!=NULL;elem=elem->next,i++){
363 devices[i]=ms_snd_card_get_string_id((MSSndCard *)elem->data);
366 old=lc->sound_conf.cards;
367 lc->sound_conf.cards=devices;
368 if (old!=NULL) ms_free(old);
371 static void sound_config_read(LinphoneCore *lc)
378 /*alsadev let the user use custom alsa device within linphone*/
379 devid=lp_config_get_string(lc->config,"sound","alsadev",NULL);
381 MSSndCard *card=ms_alsa_card_new_custom(devid,devid);
382 ms_snd_card_manager_add_card(ms_snd_card_manager_get(),card);
385 /* retrieve all sound devices */
386 build_sound_devices_table(lc);
388 devid=lp_config_get_string(lc->config,"sound","playback_dev_id",NULL);
389 linphone_core_set_playback_device(lc,devid);
391 devid=lp_config_get_string(lc->config,"sound","ringer_dev_id",NULL);
392 linphone_core_set_ringer_device(lc,devid);
394 devid=lp_config_get_string(lc->config,"sound","capture_dev_id",NULL);
395 linphone_core_set_capture_device(lc,devid);
398 tmp=lp_config_get_int(lc->config,"sound","play_lev",80);
399 linphone_core_set_play_level(lc,tmp);
400 tmp=lp_config_get_int(lc->config,"sound","ring_lev",80);
401 linphone_core_set_ring_level(lc,tmp);
402 tmp=lp_config_get_int(lc->config,"sound","rec_lev",80);
403 linphone_core_set_rec_level(lc,tmp);
404 tmpbuf=lp_config_get_string(lc->config,"sound","source","m");
405 linphone_core_set_sound_source(lc,tmpbuf[0]);
408 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
409 tmpbuf=lp_config_get_string(lc->config,"sound","local_ring",tmpbuf);
410 if (ortp_file_exist(tmpbuf)==-1) {
411 ms_warning("%s does not exist",tmpbuf);
412 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
414 if (strstr(tmpbuf,".wav")==NULL){
415 /* it currently uses old sound files, so replace them */
416 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
418 linphone_core_set_ring(lc,tmpbuf);
420 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
421 tmpbuf=lp_config_get_string(lc->config,"sound","remote_ring",tmpbuf);
422 if (ortp_file_exist(tmpbuf)==-1){
423 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
425 if (strstr(tmpbuf,".wav")==NULL){
426 /* it currently uses old sound files, so replace them */
427 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
429 linphone_core_set_ringback(lc,tmpbuf);
431 linphone_core_set_play_file(lc,lp_config_get_string(lc->config,"sound","hold_music",PACKAGE_SOUND_DIR "/" HOLD_MUSIC));
432 check_sound_device(lc);
433 lc->sound_conf.latency=0;
434 #if !defined(TARGET_OS_IPHONE) && !defined(ANDROID)
439 tmp=lp_config_get_int(lc->config,"sound","echocancellation",tmp);
440 linphone_core_enable_echo_cancellation(lc,tmp);
441 linphone_core_enable_echo_limiter(lc,
442 lp_config_get_int(lc->config,"sound","echolimiter",0));
443 linphone_core_enable_agc(lc,
444 lp_config_get_int(lc->config,"sound","agc",0));
446 gain=lp_config_get_float(lc->config,"sound","playback_gain_db",0);
447 linphone_core_set_playback_gain_db (lc,gain);
449 linphone_core_set_remote_ringback_tone (lc,lp_config_get_string(lc->config,"sound","ringback_tone",NULL));
452 static void sip_config_read(LinphoneCore *lc)
460 tmp=lp_config_get_int(lc->config,"sip","use_info",0);
461 linphone_core_set_use_info_for_dtmf(lc,tmp);
463 if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
464 sal_use_session_timers(lc->sal,200);
467 sal_use_rport(lc->sal,lp_config_get_int(lc->config,"sip","use_rport",1));
468 sal_use_101(lc->sal,lp_config_get_int(lc->config,"sip","use_101",1));
470 tmp=lp_config_get_int(lc->config,"sip","use_rfc2833",0);
471 linphone_core_set_use_rfc2833_for_dtmf(lc,tmp);
473 ipv6=lp_config_get_int(lc->config,"sip","use_ipv6",-1);
477 linphone_core_enable_ipv6(lc,ipv6);
478 memset(&tr,0,sizeof(tr));
479 if (lp_config_get_int(lc->config,"sip","sip_random_port",0)) {
480 tr.udp_port=(0xDFF&+random())+1024;
482 tr.udp_port=lp_config_get_int(lc->config,"sip","sip_port",5060);
484 if (lp_config_get_int(lc->config,"sip","sip_tcp_random_port",0)) {
485 tr.tcp_port=(0xDFF&+random())+1024;
487 tr.tcp_port=lp_config_get_int(lc->config,"sip","sip_tcp_port",0);
489 /*start listening on ports*/
490 linphone_core_set_sip_transports(lc,&tr);
492 tmpstr=lp_config_get_string(lc->config,"sip","contact",NULL);
493 if (tmpstr==NULL || linphone_core_set_primary_contact(lc,tmpstr)==-1) {
494 const char *hostname=NULL;
495 const char *username=NULL;
497 hostname=getenv("HOST");
498 username=getenv("USER");
499 if (hostname==NULL) hostname=getenv("HOSTNAME");
500 #endif /*HAVE_GETENV*/
502 hostname="unknown-host";
506 contact=ortp_strdup_printf("sip:%s@%s",username,hostname);
507 linphone_core_set_primary_contact(lc,contact);
511 tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
512 linphone_core_set_guess_hostname(lc,tmp);
515 tmp=lp_config_get_int(lc->config,"sip","inc_timeout",15);
516 linphone_core_set_inc_timeout(lc,tmp);
518 /* get proxies config */
520 LinphoneProxyConfig *cfg=linphone_proxy_config_new_from_config_file(lc->config,i);
522 linphone_core_add_proxy_config(lc,cfg);
527 /* get the default proxy */
528 tmp=lp_config_get_int(lc->config,"sip","default_proxy",-1);
529 linphone_core_set_default_proxy_index(lc,tmp);
531 /* read authentication information */
533 LinphoneAuthInfo *ai=linphone_auth_info_new_from_config_file(lc->config,i);
535 linphone_core_add_auth_info(lc,ai);
536 linphone_auth_info_destroy(ai);
542 /*for tuning or test*/
543 lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
544 lc->sip_conf.register_only_when_network_is_up=
545 lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",1);
546 lc->sip_conf.ping_with_options=lp_config_get_int(lc->config,"sip","ping_with_options",1);
547 lc->sip_conf.auto_net_state_mon=lp_config_get_int(lc->config,"sip","auto_net_state_mon",1);
548 lc->sip_conf.keepalive_period=lp_config_get_int(lc->config,"sip","keepalive_period",10000);
549 sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
550 sal_use_one_matching_codec_policy(lc->sal,lp_config_get_int(lc->config,"sip","only_one_codec",0));
551 sal_use_double_registrations(lc->sal,lp_config_get_int(lc->config,"sip","use_double_registrations",1));
554 static void rtp_config_read(LinphoneCore *lc)
559 bool_t rtp_no_xmit_on_audio_mute;
561 port=lp_config_get_int(lc->config,"rtp","audio_rtp_port",7078);
562 linphone_core_set_audio_port(lc,port);
564 port=lp_config_get_int(lc->config,"rtp","video_rtp_port",9078);
565 if (port==0) port=9078;
566 linphone_core_set_video_port(lc,port);
568 jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
569 linphone_core_set_audio_jittcomp(lc,jitt_comp);
570 jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
571 if (jitt_comp==0) jitt_comp=60;
572 lc->rtp_conf.video_jitt_comp=jitt_comp;
573 nortp_timeout=lp_config_get_int(lc->config,"rtp","nortp_timeout",30);
574 linphone_core_set_nortp_timeout(lc,nortp_timeout);
575 rtp_no_xmit_on_audio_mute=lp_config_get_int(lc->config,"rtp","rtp_no_xmit_on_audio_mute",FALSE);
576 linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_no_xmit_on_audio_mute);
579 static PayloadType * find_payload(RtpProfile *prof, const char *mime_type, int clock_rate, const char *recv_fmtp){
580 PayloadType *candidate=NULL;
584 it=rtp_profile_get_payload(prof,i);
585 if (it!=NULL && strcasecmp(mime_type,it->mime_type)==0
586 && (clock_rate==it->clock_rate || clock_rate<=0) ){
587 if ( (recv_fmtp && it->recv_fmtp && strstr(recv_fmtp,it->recv_fmtp)!=NULL) ||
588 (recv_fmtp==NULL && it->recv_fmtp==NULL) ){
590 if (recv_fmtp) payload_type_set_recv_fmtp(it,recv_fmtp);
594 if (it->recv_fmtp==NULL) candidate=it;
599 if (candidate && recv_fmtp){
600 payload_type_set_recv_fmtp(candidate,recv_fmtp);
605 static bool_t get_codec(LpConfig *config, const char* type, int index, PayloadType **ret){
607 const char *mime,*fmtp;
612 snprintf(codeckey,50,"%s_%i",type,index);
613 mime=lp_config_get_string(config,codeckey,"mime",NULL);
614 if (mime==NULL || strlen(mime)==0 ) return FALSE;
616 rate=lp_config_get_int(config,codeckey,"rate",8000);
617 fmtp=lp_config_get_string(config,codeckey,"recv_fmtp",NULL);
618 enabled=lp_config_get_int(config,codeckey,"enabled",1);
619 pt=find_payload(&av_profile,mime,rate,fmtp);
620 if (pt && enabled ) pt->flags|=PAYLOAD_TYPE_ENABLED;
621 //ms_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
622 if (pt==NULL) ms_warning("Ignoring codec config %s/%i with fmtp=%s because unsupported",
623 mime,rate,fmtp ? fmtp : "");
628 static const char *codec_pref_order[]={
642 static int find_codec_rank(const char *mime){
644 for(i=0;codec_pref_order[i]!=NULL;++i){
645 if (strcasecmp(codec_pref_order[i],mime)==0)
651 static int codec_compare(const PayloadType *a, const PayloadType *b){
653 ra=find_codec_rank(a->mime_type);
654 rb=find_codec_rank(b->mime_type);
656 if (ra<rb) return -1;
660 static MSList *add_missing_codecs(SalStreamType mtype, MSList *l){
663 PayloadType *pt=rtp_profile_get_payload(&av_profile,i);
665 if (mtype==SalVideo && pt->type!=PAYLOAD_VIDEO)
667 else if (mtype==SalAudio && (pt->type!=PAYLOAD_AUDIO_PACKETIZED
668 && pt->type!=PAYLOAD_AUDIO_CONTINUOUS)){
671 if (pt && ms_filter_codec_supported(pt->mime_type)){
672 if (ms_list_find(l,pt)==NULL){
673 /*do not enable old or experimental codecs by default*/
674 if (strcasecmp(pt->mime_type,"H263")!=0 && strcasecmp(pt->mime_type,"x-snow")!=0){
675 payload_type_set_flag(pt,PAYLOAD_TYPE_ENABLED);
677 ms_message("Adding new codec %s/%i with fmtp %s",
678 pt->mime_type,pt->clock_rate,pt->recv_fmtp ? pt->recv_fmtp : "");
679 l=ms_list_insert_sorted(l,pt,(int (*)(const void *, const void *))codec_compare);
687 static MSList *codec_append_if_new(MSList *l, PayloadType *pt){
689 for (elem=l;elem!=NULL;elem=elem->next){
690 PayloadType *ept=(PayloadType*)elem->data;
694 l=ms_list_append(l,pt);
698 static void codecs_config_read(LinphoneCore *lc)
702 MSList *audio_codecs=NULL;
703 MSList *video_codecs=NULL;
704 for (i=0;get_codec(lc->config,"audio_codec",i,&pt);i++){
706 if (!ms_filter_codec_supported(pt->mime_type)){
707 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
708 }else audio_codecs=codec_append_if_new(audio_codecs,pt);
711 audio_codecs=add_missing_codecs(SalAudio,audio_codecs);
712 for (i=0;get_codec(lc->config,"video_codec",i,&pt);i++){
714 if (!ms_filter_codec_supported(pt->mime_type)){
715 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
716 }else video_codecs=codec_append_if_new(video_codecs,(void *)pt);
719 video_codecs=add_missing_codecs(SalVideo,video_codecs);
720 linphone_core_set_audio_codecs(lc,audio_codecs);
721 linphone_core_set_video_codecs(lc,video_codecs);
722 linphone_core_update_allocated_audio_bandwidth(lc);
725 static void video_config_read(LinphoneCore *lc){
726 int capture, display, self_view;
729 const char **devices;
733 /* retrieve all video devices */
734 elem=ms_web_cam_manager_get_list(ms_web_cam_manager_get());
735 ndev=ms_list_size(elem);
736 devices=ms_malloc((ndev+1)*sizeof(const char *));
737 for (i=0;elem!=NULL;elem=elem->next,i++){
738 devices[i]=ms_web_cam_get_string_id((MSWebCam *)elem->data);
741 lc->video_conf.cams=devices;
743 str=lp_config_get_string(lc->config,"video","device",NULL);
744 if (str && str[0]==0) str=NULL;
745 linphone_core_set_video_device(lc,str);
747 linphone_core_set_preferred_video_size_by_name(lc,
748 lp_config_get_string(lc->config,"video","size","cif"));
750 capture=lp_config_get_int(lc->config,"video","capture",1);
751 display=lp_config_get_int(lc->config,"video","display",1);
752 self_view=lp_config_get_int(lc->config,"video","self_view",1);
753 lc->video_conf.displaytype=lp_config_get_string(lc->config,"video","displaytype",NULL);
754 if(lc->video_conf.displaytype)
755 ms_message("we are using a specific display:%s\n",lc->video_conf.displaytype);
757 linphone_core_enable_video(lc,capture,display);
758 linphone_core_enable_self_view(lc,self_view);
762 static void ui_config_read(LinphoneCore *lc)
766 for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
767 linphone_core_add_friend(lc,lf);
769 call_logs_read_from_config_file(lc);
773 static void autoreplier_config_init(LinphoneCore *lc)
775 autoreplier_config_t *config=&lc->autoreplier_conf;
776 config->enabled=lp_config_get_int(lc->config,"autoreplier","enabled",0);
777 config->after_seconds=lp_config_get_int(lc->config,"autoreplier","after_seconds",6);
778 config->max_users=lp_config_get_int(lc->config,"autoreplier","max_users",1);
779 config->max_rec_time=lp_config_get_int(lc->config,"autoreplier","max_rec_time",60);
780 config->max_rec_msg=lp_config_get_int(lc->config,"autoreplier","max_rec_msg",10);
781 config->message=lp_config_get_string(lc->config,"autoreplier","message",NULL);
786 * Enable adaptive rate control (experimental feature, audio-only).
788 * Adaptive rate control consists in using RTCP feedback provided information to dynamically
789 * control the output bitrate of the encoders, so that we can adapt to the network conditions and
790 * available bandwidth.
792 void linphone_core_enable_adaptive_rate_control(LinphoneCore *lc, bool_t enabled){
793 lp_config_set_int(lc->config,"net","adaptive_rate_control",(int)enabled);
797 * Returns whether adaptive rate control is enabled.
799 * See linphone_core_enable_adaptive_rate_control().
801 bool_t linphone_core_adaptive_rate_control_enabled(const LinphoneCore *lc){
802 return lp_config_get_int(lc->config,"net","adaptive_rate_control",FALSE);
806 * Sets maximum available download bandwidth
808 * @ingroup media_parameters
810 * This is IP bandwidth, in kbit/s.
811 * This information is used signaled to other parties during
812 * calls (within SDP messages) so that the remote end can have
813 * sufficient knowledge to properly configure its audio & video
814 * codec output bitrate to not overflow available bandwidth.
816 * @param lc the LinphoneCore object
817 * @param bw the bandwidth in kbits/s, 0 for infinite
819 void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
820 lc->net_conf.download_bw=bw;
824 * Sets maximum available upload bandwidth
826 * @ingroup media_parameters
828 * This is IP bandwidth, in kbit/s.
829 * This information is used by liblinphone together with remote
830 * side available bandwidth signaled in SDP messages to properly
831 * configure audio & video codec's output bitrate.
833 * @param lc the LinphoneCore object
834 * @param bw the bandwidth in kbits/s, 0 for infinite
836 void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
837 lc->net_conf.upload_bw=bw;
841 * Retrieve the maximum available download bandwidth.
843 * @ingroup media_parameters
845 * This value was set by linphone_core_set_download_bandwidth().
848 int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
849 return lc->net_conf.download_bw;
853 * Retrieve the maximum available upload bandwidth.
855 * @ingroup media_parameters
857 * This value was set by linphone_core_set_upload_bandwidth().
860 int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
861 return lc->net_conf.upload_bw;
864 * Set audio packetization time linphone expects to receive from peer
866 void linphone_core_set_download_ptime(LinphoneCore *lc, int ptime) {
867 lc->net_conf.down_ptime=ptime;
871 * Get audio packetization time linphone expects to receive from peer
873 int linphone_core_get_download_ptime(LinphoneCore *lc) {
874 return lc->net_conf.down_ptime;
878 * Set audio packetization time linphone will send (in absence of requirement from peer)
879 * A value of 0 stands for the current codec default packetization time.
882 void linphone_core_set_upload_ptime(LinphoneCore *lc, int ptime){
883 lp_config_set_int(lc->config,"rtp","up_ptime",ptime);
887 * Set audio packetization time linphone will send (in absence of requirement from peer)
888 * A value of 0 stands for the current codec default packetization time.
891 int linphone_core_get_upload_ptime(LinphoneCore *lc){
892 return lp_config_get_int(lc->config,"rtp","up_ptime",0);
898 * Returns liblinphone's version as a string.
903 const char * linphone_core_get_version(void){
904 return liblinphone_version;
908 static MSList *linphone_payload_types=NULL;
910 static void linphone_core_assign_payload_type(PayloadType *const_pt, int number, const char *recv_fmtp){
912 pt=payload_type_clone(const_pt);
913 payload_type_set_number(pt,number);
914 if (recv_fmtp!=NULL) payload_type_set_recv_fmtp(pt,recv_fmtp);
915 rtp_profile_set_payload(&av_profile,number,pt);
916 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
919 static void linphone_core_free_payload_types(void){
920 ms_list_for_each(linphone_payload_types,(void (*)(void*))payload_type_destroy);
921 ms_list_free(linphone_payload_types);
922 linphone_payload_types=NULL;
925 void linphone_core_set_state(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message){
927 if (lc->vtable.global_state_changed){
928 lc->vtable.global_state_changed(lc,gstate,message);
931 static void misc_config_read (LinphoneCore *lc) {
932 LpConfig *config=lc->config;
933 lc->max_call_logs=lp_config_get_int(config,"misc","history_max_size",15);
936 static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path,
937 const char *factory_config_path, void * userdata)
939 memset (lc, 0, sizeof (LinphoneCore));
941 lc->ringstream_autorelease=TRUE;
943 memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
945 linphone_core_set_state(lc,LinphoneGlobalStartup,"Starting up");
947 linphone_core_assign_payload_type(&payload_type_pcmu8000,0,NULL);
948 linphone_core_assign_payload_type(&payload_type_gsm,3,NULL);
949 linphone_core_assign_payload_type(&payload_type_pcma8000,8,NULL);
950 linphone_core_assign_payload_type(&payload_type_lpc1015,115,NULL);
951 linphone_core_assign_payload_type(&payload_type_speex_nb,110,"vbr=on");
952 linphone_core_assign_payload_type(&payload_type_speex_wb,111,"vbr=on");
953 linphone_core_assign_payload_type(&payload_type_speex_uwb,112,"vbr=on");
954 linphone_core_assign_payload_type(&payload_type_telephone_event,101,"0-11");
955 linphone_core_assign_payload_type(&payload_type_ilbc,113,"mode=30");
956 linphone_core_assign_payload_type(&payload_type_amr,114,"octet-align=1");
958 #if defined(ANDROID) || defined (__IPHONE_OS_VERSION_MIN_REQUIRED)
959 /*shorten the DNS lookup time and send more retransmissions on mobiles:
960 - to workaround potential packet losses
961 - to avoid hanging for 30 seconds when the network doesn't work despite the phone thinks it does.
963 _linphone_core_configure_resolver();
966 #ifdef ENABLE_NONSTANDARD_GSM
969 pt=payload_type_clone(&payload_type_gsm);
970 pt->clock_rate=11025;
971 rtp_profile_set_payload(&av_profile,114,pt);
972 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
973 pt=payload_type_clone(&payload_type_gsm);
974 pt->clock_rate=22050;
975 rtp_profile_set_payload(&av_profile,115,pt);
976 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
981 linphone_core_assign_payload_type(&payload_type_h263,34,NULL);
982 linphone_core_assign_payload_type(&payload_type_theora,97,NULL);
983 linphone_core_assign_payload_type(&payload_type_h263_1998,98,"CIF=1;QCIF=1");
984 linphone_core_assign_payload_type(&payload_type_mp4v,99,"profile-level-id=3");
985 linphone_core_assign_payload_type(&payload_type_x_snow,100,NULL);
986 linphone_core_assign_payload_type(&payload_type_h264,102,"profile-level-id=428014");
987 /* due to limited space in SDP, we have to disable this h264 line which is normally no more necessary */
988 /* linphone_core_assign_payload_type(&payload_type_h264,103,"packetization-mode=1;profile-level-id=428014");*/
992 /* create a mediastreamer2 event queue and set it as global */
993 /* This allows to run event's callback in linphone_core_iterate() */
994 lc->msevq=ms_event_queue_new();
995 ms_set_global_event_queue(lc->msevq);
997 lc->config=lp_config_new(config_path);
998 if (factory_config_path)
999 lp_config_read_file(lc->config,factory_config_path);
1002 sal_set_user_pointer(lc->sal,lc);
1003 sal_set_callbacks(lc->sal,&linphone_sal_callbacks);
1005 sip_setup_register_all();
1006 sound_config_read(lc);
1007 net_config_read(lc);
1008 rtp_config_read(lc);
1009 codecs_config_read(lc);
1010 sip_config_read(lc); /* this will start eXosip*/
1011 video_config_read(lc);
1012 //autoreplier_config_init(&lc->autoreplier_conf);
1013 lc->presence_mode=LinphoneStatusOnline;
1014 misc_config_read(lc);
1016 if (lc->vtable.display_status)
1017 lc->vtable.display_status(lc,_("Ready"));
1018 lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
1019 linphone_core_set_state(lc,LinphoneGlobalOn,"Ready");
1023 * Instanciates a LinphoneCore object.
1024 * @ingroup initializing
1026 * The LinphoneCore object is the primary handle for doing all phone actions.
1027 * It should be unique within your application.
1028 * @param vtable a LinphoneCoreVTable structure holding your application callbacks
1029 * @param config_path a path to a config file. If it does not exists it will be created.
1030 * The config file is used to store all settings, call logs, friends, proxies... so that all these settings
1031 * become persistent over the life of the LinphoneCore object.
1032 * It is allowed to set a NULL config file. In that case LinphoneCore will not store any settings.
1033 * @param factory_config_path a path to a read-only config file that can be used to
1034 * to store hard-coded preference such as proxy settings or internal preferences.
1035 * The settings in this factory file always override the one in the normal config file.
1036 * It is OPTIONAL, use NULL if unneeded.
1037 * @param userdata an opaque user pointer that can be retrieved at any time (for example in
1038 * callbacks) using linphone_core_get_user_data().
1041 LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
1042 const char *config_path, const char *factory_config_path, void * userdata)
1044 LinphoneCore *core=ms_new(LinphoneCore,1);
1045 linphone_core_init(core,vtable,config_path, factory_config_path, userdata);
1050 * Returns the list of available audio codecs.
1052 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1053 * structure holding the codec information.
1054 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1055 * (such as the order of codecs).
1057 const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
1059 return lc->codecs_conf.audio_codecs;
1063 * Returns the list of available video codecs.
1065 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1066 * structure holding the codec information.
1067 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1068 * (such as the order of codecs).
1070 const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
1072 return lc->codecs_conf.video_codecs;
1076 * Sets the local "from" identity.
1079 * This data is used in absence of any proxy configuration or when no
1080 * default proxy configuration is set. See LinphoneProxyConfig
1082 int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact)
1084 LinphoneAddress *ctt;
1086 if ((ctt=linphone_address_new(contact))==0) {
1087 ms_error("Bad contact url: %s",contact);
1090 if (lc->sip_conf.contact!=NULL) ms_free(lc->sip_conf.contact);
1091 lc->sip_conf.contact=ms_strdup(contact);
1092 if (lc->sip_conf.guessed_contact!=NULL){
1093 ms_free(lc->sip_conf.guessed_contact);
1094 lc->sip_conf.guessed_contact=NULL;
1096 linphone_address_destroy(ctt);
1101 /*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
1102 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
1104 if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress
1105 && (ip=linphone_core_get_nat_address_resolved(lc))!=NULL){
1106 strncpy(result,ip,LINPHONE_IPADDR_SIZE);
1109 if (linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,dest,result)==0)
1111 /*else fallback to SAL routine that will attempt to find the most realistic interface */
1112 sal_get_default_local_ip(lc->sal,lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,result,LINPHONE_IPADDR_SIZE);
1115 static void update_primary_contact(LinphoneCore *lc){
1117 char tmp[LINPHONE_IPADDR_SIZE];
1119 LinphoneAddress *url;
1120 if (lc->sip_conf.guessed_contact!=NULL){
1121 ms_free(lc->sip_conf.guessed_contact);
1122 lc->sip_conf.guessed_contact=NULL;
1124 url=linphone_address_new(lc->sip_conf.contact);
1126 ms_error("Could not parse identity contact !");
1127 url=linphone_address_new("sip:unknown@unkwownhost");
1129 linphone_core_get_local_ip(lc, NULL, tmp);
1130 if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
1131 ms_warning("Local loopback network only !");
1132 lc->sip_conf.loopback_only=TRUE;
1133 }else lc->sip_conf.loopback_only=FALSE;
1134 linphone_address_set_domain(url,tmp);
1135 linphone_address_set_port_int(url,linphone_core_get_sip_port (lc));
1136 guessed=linphone_address_as_string(url);
1137 lc->sip_conf.guessed_contact=guessed;
1138 linphone_address_destroy(url);
1142 * Returns the default identity when no proxy configuration is used.
1146 const char *linphone_core_get_primary_contact(LinphoneCore *lc){
1149 if (lc->sip_conf.guess_hostname){
1150 if (lc->sip_conf.guessed_contact==NULL || lc->sip_conf.loopback_only){
1151 update_primary_contact(lc);
1153 identity=lc->sip_conf.guessed_contact;
1155 identity=lc->sip_conf.contact;
1161 * Tells LinphoneCore to guess local hostname automatically in primary contact.
1165 void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
1166 lc->sip_conf.guess_hostname=val;
1170 * Returns TRUE if hostname part of primary contact is guessed automatically.
1174 bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
1175 return lc->sip_conf.guess_hostname;
1179 * Same as linphone_core_get_primary_contact() but the result is a LinphoneAddress object
1180 * instead of const char*
1184 LinphoneAddress *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
1185 return linphone_address_new(linphone_core_get_primary_contact(lc));
1189 * Sets the list of audio codecs.
1191 * @ingroup media_parameters
1192 * The list is taken by the LinphoneCore thus the application should not free it.
1193 * This list is made of struct PayloadType describing the codec parameters.
1195 int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
1197 if (lc->codecs_conf.audio_codecs!=NULL) ms_list_free(lc->codecs_conf.audio_codecs);
1198 lc->codecs_conf.audio_codecs=codecs;
1203 * Sets the list of video codecs.
1205 * @ingroup media_parameters
1206 * The list is taken by the LinphoneCore thus the application should not free it.
1207 * This list is made of struct PayloadType describing the codec parameters.
1209 int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
1211 if (lc->codecs_conf.video_codecs!=NULL) ms_list_free(lc->codecs_conf.video_codecs);
1212 lc->codecs_conf.video_codecs=codecs;
1216 const MSList * linphone_core_get_friend_list(const LinphoneCore *lc)
1222 * Returns the nominal jitter buffer size in milliseconds.
1224 * @ingroup media_parameters
1226 int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
1228 return lc->rtp_conf.audio_jitt_comp;
1232 * Returns the UDP port used for audio streaming.
1234 * @ingroup network_parameters
1236 int linphone_core_get_audio_port(const LinphoneCore *lc)
1238 return lc->rtp_conf.audio_rtp_port;
1242 * Returns the UDP port used for video streaming.
1244 * @ingroup network_parameters
1246 int linphone_core_get_video_port(const LinphoneCore *lc){
1247 return lc->rtp_conf.video_rtp_port;
1252 * Returns the value in seconds of the no-rtp timeout.
1254 * @ingroup media_parameters
1255 * When no RTP or RTCP packets have been received for a while
1256 * LinphoneCore will consider the call is broken (remote end crashed or
1257 * disconnected from the network), and thus will terminate the call.
1258 * The no-rtp timeout is the duration above which the call is considered broken.
1260 int linphone_core_get_nortp_timeout(const LinphoneCore *lc){
1261 return lc->rtp_conf.nortp_timeout;
1264 bool_t linphone_core_get_rtp_no_xmit_on_audio_mute(const LinphoneCore *lc){
1265 return lc->rtp_conf.rtp_no_xmit_on_audio_mute;
1269 * Sets the nominal audio jitter buffer size in milliseconds.
1271 * @ingroup media_parameters
1273 void linphone_core_set_audio_jittcomp(LinphoneCore *lc, int value)
1275 lc->rtp_conf.audio_jitt_comp=value;
1278 void linphone_core_set_rtp_no_xmit_on_audio_mute(LinphoneCore *lc,bool_t rtp_no_xmit_on_audio_mute){
1279 lc->rtp_conf.rtp_no_xmit_on_audio_mute=rtp_no_xmit_on_audio_mute;
1283 * Sets the UDP port used for audio streaming.
1285 * @ingroup network_parameters
1287 void linphone_core_set_audio_port(LinphoneCore *lc, int port)
1289 lc->rtp_conf.audio_rtp_port=port;
1293 * Sets the UDP port used for video streaming.
1295 * @ingroup network_parameters
1297 void linphone_core_set_video_port(LinphoneCore *lc, int port){
1298 lc->rtp_conf.video_rtp_port=port;
1302 * Sets the no-rtp timeout value in seconds.
1304 * @ingroup media_parameters
1305 * See linphone_core_get_nortp_timeout() for details.
1307 void linphone_core_set_nortp_timeout(LinphoneCore *lc, int nortp_timeout){
1308 lc->rtp_conf.nortp_timeout=nortp_timeout;
1312 * Indicates whether SIP INFO is used for sending digits.
1314 * @ingroup media_parameters
1316 bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
1318 return lc->sip_conf.use_info;
1322 * Sets whether SIP INFO is to be used for sending digits.
1324 * @ingroup media_parameters
1326 void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
1328 lc->sip_conf.use_info=use_info;
1332 * Indicates whether RFC2833 is used for sending digits.
1334 * @ingroup media_parameters
1336 bool_t linphone_core_get_use_rfc2833_for_dtmf(LinphoneCore *lc)
1338 return lc->sip_conf.use_rfc2833;
1342 * Sets whether RFC2833 is to be used for sending digits.
1344 * @ingroup media_parameters
1346 void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833)
1348 lc->sip_conf.use_rfc2833=use_rfc2833;
1352 * Returns the UDP port used by SIP.
1354 * Deprecated: use linphone_core_get_sip_transports() instead.
1355 * @ingroup network_parameters
1357 int linphone_core_get_sip_port(LinphoneCore *lc)
1359 LCSipTransports *tr=&lc->sip_conf.transports;
1360 return tr->udp_port>0 ? tr->udp_port : tr->tcp_port;
1363 static char _ua_name[64]="Linphone";
1364 static char _ua_version[64]=LINPHONE_VERSION;
1366 #ifdef HAVE_EXOSIP_GET_VERSION
1367 extern const char *eXosip_get_version();
1370 static void apply_user_agent(LinphoneCore *lc){
1371 char ua_string[256];
1372 snprintf(ua_string,sizeof(ua_string)-1,"%s/%s (eXosip2/%s)",_ua_name,_ua_version,
1373 #ifdef HAVE_EXOSIP_GET_VERSION
1374 eXosip_get_version()
1379 if (lc->sal) sal_set_user_agent(lc->sal,ua_string);
1383 * Sets the user agent string used in SIP messages.
1387 void linphone_core_set_user_agent(const char *name, const char *ver){
1388 strncpy(_ua_name,name,sizeof(_ua_name)-1);
1389 strncpy(_ua_version,ver,sizeof(_ua_version));
1392 static void transport_error(LinphoneCore *lc, const char* transport, int port){
1393 char *msg=ortp_strdup_printf("Could not start %s transport on port %i, maybe this port is already used.",transport,port);
1395 if (lc->vtable.display_warning)
1396 lc->vtable.display_warning(lc,msg);
1400 static bool_t transports_unchanged(const LCSipTransports * tr1, const LCSipTransports * tr2){
1402 tr2->udp_port==tr1->udp_port &&
1403 tr2->tcp_port==tr1->tcp_port &&
1404 tr2->dtls_port==tr1->dtls_port &&
1405 tr2->tls_port==tr1->tls_port;
1408 static int apply_transports(LinphoneCore *lc){
1410 const char *anyaddr;
1411 LCSipTransports *tr=&lc->sip_conf.transports;
1413 if (lc->sip_conf.ipv6_enabled)
1418 sal_unlisten_ports (sal);
1419 if (tr->udp_port>0){
1420 if (sal_listen_port (sal,anyaddr,tr->udp_port,SalTransportUDP,FALSE)!=0){
1421 transport_error(lc,"UDP",tr->udp_port);
1425 if (tr->tcp_port>0){
1426 if (sal_listen_port (sal,anyaddr,tr->tcp_port,SalTransportTCP,FALSE)!=0){
1427 transport_error(lc,"TCP",tr->tcp_port);
1430 apply_user_agent(lc);
1435 * Sets the ports to be used for each of transport (UDP or TCP)
1437 * A zero value port for a given transport means the transport
1440 * @ingroup network_parameters
1442 int linphone_core_set_sip_transports(LinphoneCore *lc, const LCSipTransports * tr){
1444 if (transports_unchanged(tr,&lc->sip_conf.transports))
1446 memcpy(&lc->sip_conf.transports,tr,sizeof(*tr));
1448 if (lc->sal==NULL) return 0;
1449 return apply_transports(lc);
1453 * Retrieves the ports used for each transport (udp, tcp).
1454 * A zero value port for a given transport means the transport
1456 * @ingroup network_parameters
1458 int linphone_core_get_sip_transports(LinphoneCore *lc, LCSipTransports *tr){
1459 memcpy(tr,&lc->sip_conf.transports,sizeof(*tr));
1464 * Sets the UDP port to be used by SIP.
1466 * Deprecated: use linphone_core_set_sip_transports() instead.
1467 * @ingroup network_parameters
1469 void linphone_core_set_sip_port(LinphoneCore *lc,int port)
1472 memset(&tr,0,sizeof(tr));
1474 linphone_core_set_sip_transports (lc,&tr);
1478 * Returns TRUE if IPv6 is enabled.
1480 * @ingroup network_parameters
1481 * See linphone_core_enable_ipv6() for more details on how IPv6 is supported in liblinphone.
1483 bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
1484 return lc->sip_conf.ipv6_enabled;
1488 * Turns IPv6 support on or off.
1490 * @ingroup network_parameters
1492 * @note IPv6 support is exclusive with IPv4 in liblinphone:
1493 * when IPv6 is turned on, IPv4 calls won't be possible anymore.
1494 * By default IPv6 support is off.
1496 void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
1497 if (lc->sip_conf.ipv6_enabled!=val){
1498 lc->sip_conf.ipv6_enabled=val;
1500 /* we need to restart eXosip */
1501 apply_transports(lc);
1507 static void monitor_network_state(LinphoneCore *lc, time_t curtime){
1508 static time_t last_check=0;
1509 static bool_t last_status=FALSE;
1510 char result[LINPHONE_IPADDR_SIZE];
1511 bool_t new_status=last_status;
1513 /* only do the network up checking every five seconds */
1514 if (last_check==0 || (curtime-last_check)>=5){
1515 linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,NULL,result);
1516 if (strcmp(result,"::1")!=0 && strcmp(result,"127.0.0.1")!=0){
1518 }else new_status=FALSE;
1520 if (new_status!=last_status) {
1522 ms_message("New local ip address is %s",result);
1524 set_network_reachable(lc,new_status, curtime);
1525 last_status=new_status;
1530 static void proxy_update(LinphoneCore *lc){
1531 ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
1532 MSList* list=ms_list_copy(lc->sip_conf.deleted_proxies);
1533 for(;list!=NULL;list=list->next){
1534 LinphoneProxyConfig* cfg = (LinphoneProxyConfig*) list->data;
1535 if (ms_time(NULL) - cfg->deletion_date > 5) {
1536 lc->sip_conf.deleted_proxies =ms_list_remove(lc->sip_conf.deleted_proxies,(void *)cfg);
1537 ms_message("clearing proxy config for [%s]",linphone_proxy_config_get_addr(cfg));
1538 linphone_proxy_config_destroy(cfg);
1544 static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){
1545 LinphoneFriend *lf=linphone_core_get_friend_by_address(lc,info->sip_uri);
1548 ms_message("%s has a BuddyInfo assigned with image %p",info->sip_uri, info->image_data);
1549 if (lc->vtable.buddy_info_updated)
1550 lc->vtable.buddy_info_updated(lc,lf);
1552 ms_warning("Could not any friend with uri %s",info->sip_uri);
1556 static void analyze_buddy_lookup_results(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1558 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1559 for (elem=lc->bl_reqs;elem!=NULL;elem=ms_list_next(elem)){
1560 BuddyLookupRequest *req=(BuddyLookupRequest *)elem->data;
1561 if (req->status==BuddyLookupDone || req->status==BuddyLookupFailure){
1562 if (req->results!=NULL){
1563 BuddyInfo *i=(BuddyInfo*)req->results->data;
1564 ms_list_free(req->results);
1566 assign_buddy_info(lc,i);
1568 sip_setup_context_buddy_lookup_free(ctx,req);
1572 /*purge completed requests */
1573 while((elem=ms_list_find(lc->bl_reqs,NULL))!=NULL){
1574 lc->bl_reqs=ms_list_remove_link(lc->bl_reqs,elem);
1578 static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1580 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1581 for(elem=linphone_core_get_friend_list(lc);elem!=NULL;elem=elem->next){
1582 LinphoneFriend *lf=(LinphoneFriend*)elem->data;
1583 if (lf->info==NULL){
1584 if (linphone_core_lookup_known_proxy(lc,lf->uri)==cfg){
1585 if (linphone_address_get_username(lf->uri)!=NULL){
1586 BuddyLookupRequest *req;
1587 char *tmp=linphone_address_as_string_uri_only(lf->uri);
1588 req=sip_setup_context_create_buddy_lookup_request(ctx);
1589 buddy_lookup_request_set_key(req,tmp);
1590 buddy_lookup_request_set_max_results(req,1);
1591 sip_setup_context_buddy_lookup_submit(ctx,req);
1592 lc->bl_reqs=ms_list_append(lc->bl_reqs,req);
1600 static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
1601 LinphoneProxyConfig *cfg=NULL;
1602 linphone_core_get_default_proxy(lc,&cfg);
1604 if (lc->bl_refresh){
1605 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1606 if (ctx && (sip_setup_context_get_capabilities(ctx) & SIP_SETUP_CAP_BUDDY_LOOKUP)){
1607 linphone_core_grab_buddy_infos(lc,cfg);
1608 lc->bl_refresh=FALSE;
1611 if (lc->bl_reqs) analyze_buddy_lookup_results(lc,cfg);
1616 * Main loop function. It is crucial that your application call it periodically.
1618 * @ingroup initializing
1619 * linphone_core_iterate() performs various backgrounds tasks:
1620 * - receiving of SIP messages
1621 * - handles timers and timeout
1622 * - performs registration to proxies
1623 * - authentication retries
1624 * The application MUST call this function periodically, in its main loop.
1625 * Be careful that this function must be called from the same thread as
1626 * other liblinphone methods. If it is not the case make sure all liblinphone calls are
1627 * serialized with a mutex.
1629 void linphone_core_iterate(LinphoneCore *lc){
1632 time_t curtime=time(NULL);
1634 bool_t one_second_elapsed=FALSE;
1636 if (curtime-lc->prevtime>=1){
1637 lc->prevtime=curtime;
1638 one_second_elapsed=TRUE;
1642 LinphoneEcCalibratorStatus ecs=ec_calibrator_get_status(lc->ecc);
1643 if (ecs!=LinphoneEcCalibratorInProgress){
1645 lc->ecc->cb(lc,ecs,lc->ecc->delay,lc->ecc->cb_data);
1646 if (ecs==LinphoneEcCalibratorDone){
1647 lp_config_set_int(lc->config, "sound", "ec_delay",MAX(lc->ecc->delay-10,0));
1649 ec_calibrator_destroy(lc->ecc);
1654 if (lc->preview_finished){
1655 lc->preview_finished=0;
1656 ring_stop(lc->ringstream);
1657 lc->ringstream=NULL;
1658 lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
1661 if (lc->ringstream && lc->ringstream_autorelease && lc->dmfs_playing_start_time!=0
1662 && (curtime-lc->dmfs_playing_start_time)>5){
1663 ring_stop(lc->ringstream);
1664 lc->ringstream=NULL;
1665 lc->dmfs_playing_start_time=0;
1668 sal_iterate(lc->sal);
1669 if (lc->msevq) ms_event_queue_pump(lc->msevq);
1670 if (lc->auto_net_state_mon) monitor_network_state(lc,curtime);
1674 //we have to iterate for each call
1676 while(calls!= NULL){
1677 call = (LinphoneCall *)calls->data;
1678 /* get immediately a reference to next one in case the one
1679 we are going to examine is destroy and removed during
1680 linphone_core_start_invite() */
1682 if (call->state==LinphoneCallOutgoingInit && (curtime-call->start_time>=2)){
1683 /*start the call even if the OPTIONS reply did not arrive*/
1684 linphone_core_start_invite(lc,call,NULL);
1686 if (call->dir==LinphoneCallIncoming && call->state==LinphoneCallOutgoingRinging){
1687 elapsed=curtime-call->start_time;
1688 ms_message("incoming call ringing for %i seconds",elapsed);
1689 if (elapsed>lc->sip_conf.inc_timeout){
1690 call->log->status=LinphoneCallMissed;
1691 linphone_core_terminate_call(lc,call);
1695 call = linphone_core_get_current_call(lc);
1697 linphone_call_background_tasks(call,one_second_elapsed);
1698 if (linphone_core_video_preview_enabled(lc)){
1699 if (lc->previewstream==NULL && lc->calls==NULL)
1700 toggle_video_preview(lc,TRUE);
1701 #ifdef VIDEO_ENABLED
1702 if (lc->previewstream) video_stream_iterate(lc->previewstream);
1705 if (lc->previewstream!=NULL)
1706 toggle_video_preview(lc,FALSE);
1709 linphone_core_run_hooks(lc);
1710 linphone_core_do_plugin_tasks(lc);
1712 if (lc->initial_subscribes_sent==FALSE && lc->netup_time!=0 &&
1713 (curtime-lc->netup_time)>3){
1714 linphone_core_send_initial_subscribes(lc);
1715 lc->initial_subscribes_sent=TRUE;
1718 if (one_second_elapsed && lp_config_needs_commit(lc->config)){
1719 lp_config_sync(lc->config);
1724 * Interpret a call destination as supplied by the user, and returns a fully qualified
1727 * A sip address should look like DisplayName <sip:username@domain:port> .
1728 * Basically this function performs the following tasks
1729 * - if a phone number is entered, prepend country prefix of the default proxy
1730 * configuration, eventually escape the '+' by 00.
1731 * - if no domain part is supplied, append the domain name of the default proxy
1732 * - if no sip: is present, prepend it
1734 * The result is a syntaxically correct SIP address.
1737 LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url){
1738 enum_lookup_res_t *enumres=NULL;
1739 char *enum_domain=NULL;
1740 LinphoneProxyConfig *proxy=lc->default_proxy;;
1742 LinphoneAddress *uri;
1744 if (is_enum(url,&enum_domain)){
1745 if (lc->vtable.display_status!=NULL)
1746 lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
1747 if (enum_lookup(enum_domain,&enumres)<0){
1748 if (lc->vtable.display_status!=NULL)
1749 lc->vtable.display_status(lc,_("Could not resolve this number."));
1750 ms_free(enum_domain);
1753 ms_free(enum_domain);
1754 tmpurl=enumres->sip_address[0];
1755 uri=linphone_address_new(tmpurl);
1756 enum_lookup_res_free(enumres);
1759 /* check if we have a "sip:" */
1760 if (strstr(url,"sip:")==NULL){
1761 /* this doesn't look like a true sip uri */
1762 if (strchr(url,'@')!=NULL){
1763 /* seems like sip: is missing !*/
1764 tmpurl=ms_strdup_printf("sip:%s",url);
1765 uri=linphone_address_new(tmpurl);
1773 /* append the proxy domain suffix */
1774 const char *identity=linphone_proxy_config_get_identity(proxy);
1775 char normalized_username[128];
1776 uri=linphone_address_new(identity);
1780 linphone_address_set_display_name(uri,NULL);
1781 linphone_proxy_config_normalize_number(proxy,url,normalized_username,
1782 sizeof(normalized_username));
1783 linphone_address_set_username(uri,normalized_username);
1787 uri=linphone_address_new(url);
1791 /* else we could not do anything with url given by user, so display an error */
1792 if (lc->vtable.display_warning!=NULL){
1793 lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
1799 * Returns the default identity SIP address.
1802 * This is an helper function:
1804 * If no default proxy is set, this will return the primary contact (
1805 * see linphone_core_get_primary_contact() ). If a default proxy is set
1806 * it returns the registered identity on the proxy.
1808 const char * linphone_core_get_identity(LinphoneCore *lc){
1809 LinphoneProxyConfig *proxy=NULL;
1811 linphone_core_get_default_proxy(lc,&proxy);
1813 from=linphone_proxy_config_get_identity(proxy);
1814 }else from=linphone_core_get_primary_contact(lc);
1818 const char * linphone_core_get_route(LinphoneCore *lc){
1819 LinphoneProxyConfig *proxy=NULL;
1820 const char *route=NULL;
1821 linphone_core_get_default_proxy(lc,&proxy);
1823 route=linphone_proxy_config_get_route(proxy);
1828 void linphone_core_start_refered_call(LinphoneCore *lc, LinphoneCall *call){
1829 if (call->refer_pending){
1830 LinphoneCallParams *cp=linphone_core_create_default_call_parameters(lc);
1832 ms_message("Starting new call to refered address %s",call->refer_to);
1833 call->refer_pending=FALSE;
1834 linphone_core_invite_with_params(lc,call->refer_to,cp);
1835 linphone_call_params_destroy(cp);
1839 LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
1841 LinphoneProxyConfig *found_cfg=NULL;
1842 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=elem->next){
1843 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1844 const char *domain=linphone_proxy_config_get_domain(cfg);
1845 if (domain!=NULL && strcmp(domain,linphone_address_get_domain(uri))==0){
1853 const char *linphone_core_find_best_identity(LinphoneCore *lc, const LinphoneAddress *to, const char **route){
1854 LinphoneProxyConfig *cfg=linphone_core_lookup_known_proxy(lc,to);
1856 linphone_core_get_default_proxy (lc,&cfg);
1858 if (route) *route=linphone_proxy_config_get_route(cfg);
1859 return linphone_proxy_config_get_identity (cfg);
1861 return linphone_core_get_primary_contact (lc);
1864 static char *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){
1865 LinphoneAddress *ctt;
1866 const char *localip=call->localip;
1868 /* first use user's supplied ip address if asked*/
1869 if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress){
1870 ctt=linphone_core_get_primary_contact_parsed(lc);
1871 return ms_strdup_printf("sip:%s@%s",linphone_address_get_username(ctt),
1872 linphone_core_get_nat_address_resolved(lc));
1875 /* if already choosed, don't change it */
1876 if (call->op && sal_op_get_contact(call->op)!=NULL){
1879 /* if the ping OPTIONS request succeeded use the contact guessed from the
1882 const char *guessed=sal_op_get_contact(call->ping_op);
1884 ms_message("Contact has been fixed using OPTIONS to %s",guessed);
1885 return ms_strdup(guessed);
1889 /*if using a proxy, use the contact address as guessed with the REGISTERs*/
1890 if (dest_proxy && dest_proxy->op){
1891 const char *fixed_contact=sal_op_get_contact(dest_proxy->op);
1892 if (fixed_contact) {
1893 ms_message("Contact has been fixed using proxy to %s",fixed_contact);
1894 return ms_strdup(fixed_contact);
1898 ctt=linphone_core_get_primary_contact_parsed(lc);
1902 /*otherwise use supllied localip*/
1903 linphone_address_set_domain(ctt,localip);
1904 linphone_address_set_port_int(ctt,linphone_core_get_sip_port(lc));
1905 ret=linphone_address_as_string_uri_only(ctt);
1906 linphone_address_destroy(ctt);
1907 ms_message("Contact has been fixed using local ip to %s",ret);
1913 int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphoneProxyConfig *dest_proxy){
1916 char *real_url,*barmsg;
1919 /*try to be best-effort in giving real local or routable contact address */
1920 contact=get_fixed_contact(lc,call,dest_proxy);
1922 sal_op_set_contact(call->op, contact);
1926 //TODO : should probably not be done here
1927 linphone_call_init_media_streams(call);
1928 if (!lc->sip_conf.sdp_200_ack){
1929 call->media_pending=TRUE;
1930 sal_call_set_local_media_description(call->op,call->localdesc);
1932 real_url=linphone_address_as_string(call->log->to);
1933 from=linphone_address_as_string(call->log->from);
1934 err=sal_call(call->op,from,real_url);
1936 if (lc->sip_conf.sdp_200_ack){
1937 call->media_pending=TRUE;
1938 sal_call_set_local_media_description(call->op,call->localdesc);
1940 barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
1941 if (lc->vtable.display_status!=NULL)
1942 lc->vtable.display_status(lc,barmsg);
1946 if (lc->vtable.display_status!=NULL)
1947 lc->vtable.display_status(lc,_("Could not call"));
1948 linphone_call_stop_media_streams(call);
1949 linphone_call_set_state(call,LinphoneCallError,"Call failed");
1951 linphone_call_set_state(call,LinphoneCallOutgoingProgress,"Outgoing call in progress");
1959 * Initiates an outgoing call
1961 * @ingroup call_control
1962 * @param lc the LinphoneCore object
1963 * @param url the destination of the call (sip address, or phone number).
1965 * The application doesn't own a reference to the returned LinphoneCall object.
1966 * Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
1968 * @return a LinphoneCall object or NULL in case of failure
1970 LinphoneCall * linphone_core_invite(LinphoneCore *lc, const char *url){
1972 LinphoneCallParams *p=linphone_core_create_default_call_parameters (lc);
1973 call=linphone_core_invite_with_params(lc,url,p);
1974 linphone_call_params_destroy(p);
1980 * Initiates an outgoing call according to supplied call parameters
1982 * @ingroup call_control
1983 * @param lc the LinphoneCore object
1984 * @param url the destination of the call (sip address, or phone number).
1985 * @param p call parameters
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_with_params(LinphoneCore *lc, const char *url, const LinphoneCallParams *p){
1993 LinphoneAddress *addr=linphone_core_interpret_url(lc,url);
1996 call=linphone_core_invite_address_with_params(lc,addr,p);
1997 linphone_address_destroy(addr);
2004 * Initiates an outgoing call given a destination LinphoneAddress
2006 * @ingroup call_control
2007 * @param lc the LinphoneCore object
2008 * @param addr the destination of the call (sip address).
2010 * The LinphoneAddress can be constructed directly using linphone_address_new(), or
2011 * created by linphone_core_interpret_url().
2012 * The application doesn't own a reference to the returned LinphoneCall object.
2013 * Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
2015 * @return a LinphoneCall object or NULL in case of failure
2017 LinphoneCall * linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *addr){
2019 LinphoneCallParams *p=linphone_core_create_default_call_parameters (lc);
2020 call=linphone_core_invite_address_with_params (lc,addr,p);
2021 linphone_call_params_destroy(p);
2027 * Initiates an outgoing call given a destination LinphoneAddress
2029 * @ingroup call_control
2030 * @param lc the LinphoneCore object
2031 * @param addr the destination of the call (sip address).
2032 @param params call parameters
2034 * The LinphoneAddress can be constructed directly using linphone_address_new(), or
2035 * created by linphone_core_interpret_url().
2036 * The application doesn't own a reference to the returned LinphoneCall object.
2037 * Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
2039 * @return a LinphoneCall object or NULL in case of failure
2041 LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const LinphoneAddress *addr, const LinphoneCallParams *params)
2043 const char *route=NULL;
2044 const char *from=NULL;
2045 LinphoneProxyConfig *proxy=NULL;
2046 LinphoneAddress *parsed_url2=NULL;
2047 char *real_url=NULL;
2048 LinphoneProxyConfig *dest_proxy=NULL;
2051 if (linphone_core_in_call(lc)){
2052 if (lc->vtable.display_warning)
2053 lc->vtable.display_warning(lc,_("Sorry, you have to pause or stop the current call first !"));
2056 if(!linphone_core_can_we_add_call(lc)){
2057 if (lc->vtable.display_warning)
2058 lc->vtable.display_warning(lc,_("Sorry, we have reached the maximum number of simultaneous calls"));
2061 linphone_core_get_default_proxy(lc,&proxy);
2062 route=linphone_core_get_route(lc);
2064 real_url=linphone_address_as_string(addr);
2065 dest_proxy=linphone_core_lookup_known_proxy(lc,addr);
2067 if (proxy!=dest_proxy && dest_proxy!=NULL) {
2068 ms_message("Overriding default proxy setting for this call:");
2069 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
2072 if (dest_proxy!=NULL)
2073 from=linphone_proxy_config_get_identity(dest_proxy);
2074 else if (proxy!=NULL)
2075 from=linphone_proxy_config_get_identity(proxy);
2077 /* if no proxy or no identity defined for this proxy, default to primary contact*/
2078 if (from==NULL) from=linphone_core_get_primary_contact(lc);
2080 parsed_url2=linphone_address_new(from);
2082 call=linphone_call_new_outgoing(lc,parsed_url2,linphone_address_clone(addr),params);
2083 sal_op_set_route(call->op,route);
2085 if(linphone_core_add_call(lc,call)!= 0)
2087 ms_warning("we had a problem in adding the call into the invite ... weird");
2088 linphone_call_unref(call);
2091 /* this call becomes now the current one*/
2092 lc->current_call=call;
2093 linphone_call_set_state (call,LinphoneCallOutgoingInit,"Starting outgoing call");
2094 if (dest_proxy!=NULL || lc->sip_conf.ping_with_options==FALSE){
2095 linphone_core_start_invite(lc,call,dest_proxy);
2097 /*defer the start of the call after the OPTIONS ping*/
2098 call->ping_op=sal_op_new(lc->sal);
2099 sal_ping(call->ping_op,from,real_url);
2100 sal_op_set_user_pointer(call->ping_op,call);
2101 call->start_time=time(NULL);
2104 if (real_url!=NULL) ms_free(real_url);
2109 * Performs a simple call transfer to the specified destination.
2111 * The remote endpoint is expected to issue a new call to the specified destination.
2112 * The current call remains active and thus can be later paused or terminated.
2114 int linphone_core_transfer_call(LinphoneCore *lc, LinphoneCall *call, const char *url)
2116 char *real_url=NULL;
2117 LinphoneAddress *real_parsed_url=linphone_core_interpret_url(lc,url);
2119 if (!real_parsed_url){
2124 ms_warning("No established call to refer.");
2127 //lc->call=NULL; //Do not do that you will lose the call afterward . . .
2128 real_url=linphone_address_as_string (real_parsed_url);
2129 sal_call_refer(call->op,real_url);
2131 linphone_address_destroy(real_parsed_url);
2136 * Transfer a call to destination of another running call. This is used for "attended transfer" scenarios.
2137 * @param lc linphone core object
2138 * @param call a running call you want to transfer
2139 * @param dest a running call whose remote person will receive the transfer
2141 * The transfered call is supposed to be in paused state, so that it is able to accept the transfer immediately.
2142 * The destination call is a call previously established to introduce the transfered person.
2143 * This method will send a transfer request to the transfered person. The phone of the transfered is then
2144 * expected to automatically call to the destination of the transfer. The receiver of the transfer will then automatically
2145 * close the call with us (the 'dest' call).
2147 int linphone_core_transfer_call_to_another(LinphoneCore *lc, LinphoneCall *call, LinphoneCall *dest){
2148 return sal_call_refer_with_replaces (call->op,dest->op);
2151 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
2152 LinphoneCall *call = linphone_core_get_current_call(lc);
2155 if(call->dir==LinphoneCallIncoming
2156 && (call->state == LinphoneCallIncomingReceived || call->state == LinphoneCallIncomingEarlyMedia))
2163 * Updates a running call according to supplied call parameters or parameters changed in the LinphoneCore.
2165 * In this version this is limited to the following use cases:
2166 * - setting up/down the video stream according to the video parameter of the LinphoneCallParams (see linphone_call_params_enable_video() ).
2167 * - changing the size of the transmitted video after calling linphone_core_set_preferred_video_size()
2169 * In case no changes are requested through the LinphoneCallParams argument, then this argument can be ommitted and set to NULL.
2171 * @return 0 if successful, -1 otherwise.
2173 int linphone_core_update_call(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallParams *params){
2176 call->params=*params;
2177 update_local_media_description(lc,call,&call->localdesc);
2178 call->camera_active=params->has_video;
2179 if (lc->vtable.display_status)
2180 lc->vtable.display_status(lc,_("Modifying call parameters..."));
2181 sal_call_set_local_media_description (call->op,call->localdesc);
2182 err=sal_call_update(call->op,"Media parameters update");
2184 #ifdef VIDEO_ENABLED
2185 if (call->videostream!=NULL){
2186 video_stream_set_sent_video_size(call->videostream,linphone_core_get_preferred_video_size(lc));
2187 video_stream_update_video_params (call->videostream);
2197 * Accept an incoming call.
2199 * @ingroup call_control
2200 * Basically the application is notified of incoming calls within the
2201 * call_state_changed callback of the #LinphoneCoreVTable structure, where it will receive
2202 * a LinphoneCallIncoming event with the associated LinphoneCall object.
2203 * The application can later accept the call using
2205 * @param lc the LinphoneCore object
2206 * @param call the LinphoneCall object representing the call to be answered.
2209 int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call)
2211 LinphoneProxyConfig *cfg=NULL,*dest_proxy=NULL;
2212 const char *contact=NULL;
2214 SalMediaDescription *new_md;
2217 //if just one call is present answer the only one ...
2218 if(linphone_core_get_calls_nb (lc) != 1)
2221 call = (LinphoneCall*)linphone_core_get_calls(lc)->data;
2224 if (call->state==LinphoneCallConnected){
2225 /*call already accepted*/
2229 /* check if this call is supposed to replace an already running one*/
2230 replaced=sal_call_get_replaces(call->op);
2232 LinphoneCall *rc=(LinphoneCall*)sal_op_get_user_pointer (replaced);
2234 ms_message("Call %p replaces call %p. This last one is going to be terminated automatically.",
2236 linphone_core_terminate_call (lc,rc);
2240 if (lc->current_call!=NULL && lc->current_call!=call){
2241 ms_warning("Cannot accept this call, there is already one running.");
2245 /*can accept a new call only if others are on hold */
2248 for(elem=lc->calls;elem!=NULL;elem=elem->next){
2249 LinphoneCall *c=(LinphoneCall*)elem->data;
2250 if (c!=call && (c->state!=LinphoneCallPaused && c->state!=LinphoneCallPausing)){
2251 ms_warning("Cannot accept this call as another one is running, pause it before.");
2258 if (lc->ringstream!=NULL) {
2259 ms_message("stop ringing");
2260 ring_stop(lc->ringstream);
2261 ms_message("ring stopped");
2262 lc->ringstream=NULL;
2265 linphone_core_get_default_proxy(lc,&cfg);
2267 dest_proxy=linphone_core_lookup_known_proxy(lc,call->log->to);
2269 if (cfg!=dest_proxy && dest_proxy!=NULL) {
2270 ms_message("Overriding default proxy setting for this call:");
2271 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
2273 /*try to be best-effort in giving real local or routable contact address*/
2274 contact=get_fixed_contact(lc,call,dest_proxy);
2276 sal_op_set_contact(call->op,contact);
2278 if (call->audiostream==NULL)
2279 linphone_call_init_media_streams(call);
2281 sal_call_accept(call->op);
2282 if (lc->vtable.display_status!=NULL)
2283 lc->vtable.display_status(lc,_("Connected."));
2284 lc->current_call=call;
2285 linphone_call_set_state(call,LinphoneCallConnected,"Connected");
2286 new_md=sal_call_get_final_media_description(call->op);
2287 linphone_core_update_streams(lc, call, new_md);
2289 linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
2290 }else call->media_pending=TRUE;
2292 ms_message("call answered.");
2296 int linphone_core_abort_call(LinphoneCore *lc, LinphoneCall *call, const char *error){
2297 sal_call_terminate(call->op);
2300 if (lc->ringstream!=NULL) {
2301 ring_stop(lc->ringstream);
2302 lc->ringstream=NULL;
2304 linphone_call_stop_media_streams(call);
2305 if (lc->vtable.display_status!=NULL)
2306 lc->vtable.display_status(lc,_("Call aborted") );
2307 linphone_call_set_state(call,LinphoneCallError,error);
2311 static void terminate_call(LinphoneCore *lc, LinphoneCall *call){
2312 if (call->state==LinphoneCallIncomingReceived){
2313 call->reason=LinphoneReasonDeclined;
2316 if (lc->ringstream!=NULL) {
2317 ring_stop(lc->ringstream);
2318 lc->ringstream=NULL;
2320 linphone_call_stop_media_streams(call);
2321 if (lc->vtable.display_status!=NULL)
2322 lc->vtable.display_status(lc,_("Call ended") );
2325 int linphone_core_redirect_call(LinphoneCore *lc, LinphoneCall *call, const char *redirect_uri){
2326 if (call->state==LinphoneCallIncomingReceived){
2327 sal_call_decline(call->op,SalReasonRedirect,redirect_uri);
2328 call->reason=LinphoneReasonDeclined;
2329 terminate_call(lc,call);
2330 linphone_call_set_state(call,LinphoneCallEnd,"Call terminated");
2332 ms_error("Bad state for call redirection.");
2340 * Terminates a call.
2342 * @ingroup call_control
2343 * @param lc the LinphoneCore
2344 * @param the_call the LinphoneCall object representing the call to be terminated.
2346 int linphone_core_terminate_call(LinphoneCore *lc, LinphoneCall *the_call)
2349 if (the_call == NULL){
2350 call = linphone_core_get_current_call(lc);
2351 if (ms_list_size(lc->calls)==1){
2352 call=(LinphoneCall*)lc->calls->data;
2354 ms_warning("No unique call to terminate !");
2362 sal_call_terminate(call->op);
2363 terminate_call(lc,call);
2365 linphone_call_set_state(call,LinphoneCallEnd,"Call terminated");
2370 * Terminates all the calls.
2372 * @ingroup call_control
2373 * @param lc The LinphoneCore
2375 int linphone_core_terminate_all_calls(LinphoneCore *lc){
2378 LinphoneCall *the_call = lc->calls->data;
2379 linphone_core_terminate_call(lc,the_call);
2381 ms_list_free(lc->calls);
2386 * Returns the current list of calls.
2388 * Note that this list is read-only and might be changed by the core after a function call to linphone_core_iterate().
2389 * Similarly the LinphoneCall objects inside it might be destroyed without prior notice.
2390 * To hold references to LinphoneCall object into your program, you must use linphone_call_ref().
2392 * @ingroup call_control
2394 const MSList *linphone_core_get_calls(LinphoneCore *lc)
2400 * Returns TRUE if there is a call running.
2402 * @ingroup call_control
2404 bool_t linphone_core_in_call(const LinphoneCore *lc){
2405 return linphone_core_get_current_call((LinphoneCore *)lc)!=NULL;
2409 * Returns The _LinphoneCall struct of the current call if one is in call
2411 * @ingroup call_control
2413 LinphoneCall *linphone_core_get_current_call(const LinphoneCore *lc)
2415 return lc->current_call;
2419 * Pauses the call. If a music file has been setup using linphone_core_set_play_file(),
2420 * this file will be played to the remote user.
2422 * @ingroup call_control
2424 int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *the_call)
2426 LinphoneCall *call = the_call;
2427 const char *subject=NULL;
2429 if (call->state!=LinphoneCallStreamsRunning && call->state!=LinphoneCallPausedByRemote){
2430 ms_warning("Cannot pause this call, it is not active.");
2433 if (sal_media_description_has_dir(call->resultdesc,SalStreamSendRecv)){
2434 sal_media_description_set_dir(call->localdesc,SalStreamSendOnly);
2435 subject="Call on hold";
2436 }else if (sal_media_description_has_dir(call->resultdesc,SalStreamRecvOnly)){
2437 sal_media_description_set_dir(call->localdesc,SalStreamSendOnly);
2438 subject="Call on hold for me too";
2440 ms_error("No reason to pause this call, it is already paused or inactive.");
2443 if (sal_call_update(call->op,subject) != 0)
2445 if (lc->vtable.display_warning)
2446 lc->vtable.display_warning(lc,_("Could not pause the call"));
2448 linphone_call_set_state(call,LinphoneCallPausing,"Pausing call");
2449 if (lc->vtable.display_status)
2450 lc->vtable.display_status(lc,_("Pausing the current call..."));
2451 lc->current_call=NULL;
2452 if (call->audiostream || call->videostream)
2453 linphone_call_stop_media_streams (call);
2458 * Pause all currently running calls.
2460 int linphone_core_pause_all_calls(LinphoneCore *lc){
2462 for(elem=lc->calls;elem!=NULL;elem=elem->next){
2463 LinphoneCall *call=(LinphoneCall *)elem->data;
2464 LinphoneCallState cs=linphone_call_get_state(call);
2465 if (cs==LinphoneCallStreamsRunning || cs==LinphoneCallPausedByRemote){
2466 linphone_core_pause_call(lc,call);
2475 * @ingroup call_control
2477 int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call)
2480 LinphoneCall *call = the_call;
2482 if(call->state!=LinphoneCallPaused ){
2483 ms_warning("we cannot resume a call that has not been established and paused before");
2486 if(linphone_core_get_current_call(lc) != NULL){
2487 ms_warning("There is already a call in process, pause or stop it first.");
2488 if (lc->vtable.display_warning)
2489 lc->vtable.display_warning(lc,_("There is already a call in process, pause or stop it first."));
2492 ms_message("Resuming call %p",call);
2493 sal_media_description_set_dir(call->localdesc,SalStreamSendRecv);
2494 if(sal_call_update(call->op,"Call resuming") != 0){
2497 linphone_call_set_state (call,LinphoneCallResuming,"Resuming");
2498 snprintf(temp,sizeof(temp)-1,"Resuming the call with %s",linphone_call_get_remote_address_as_string(call));
2499 if (lc->vtable.display_status)
2500 lc->vtable.display_status(lc,temp);
2504 static int remote_address_compare(LinphoneCall *call, const LinphoneAddress *raddr){
2505 const LinphoneAddress *addr=linphone_call_get_remote_address (call);
2506 return !linphone_address_weak_equal (addr,raddr);
2510 * Get the call with the remote_address specified
2512 * @param remote_address
2513 * @return the LinphoneCall of the call if found
2515 LinphoneCall *linphone_core_get_call_by_remote_address(LinphoneCore *lc, const char *remote_address){
2516 LinphoneAddress *raddr=linphone_address_new(remote_address);
2517 MSList *elem=ms_list_find_custom(lc->calls,(int (*)(const void*,const void *))remote_address_compare,raddr);
2518 if (elem) return (LinphoneCall*) elem->data;
2522 int linphone_core_send_publish(LinphoneCore *lc,
2523 LinphoneOnlineStatus presence_mode)
2526 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=ms_list_next(elem)){
2527 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2528 if (cfg->publish) linphone_proxy_config_send_publish(cfg,presence_mode);
2534 * Set the incoming call timeout in seconds.
2536 * @ingroup call_control
2537 * If an incoming call isn't answered for this timeout period, it is
2538 * automatically declined.
2540 void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
2541 lc->sip_conf.inc_timeout=seconds;
2545 * Returns the incoming call timeout
2547 * @ingroup call_control
2548 * See linphone_core_set_inc_timeout() for details.
2550 int linphone_core_get_inc_timeout(LinphoneCore *lc){
2551 return lc->sip_conf.inc_timeout;
2554 void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
2555 const char *contact,
2556 LinphoneOnlineStatus presence_mode)
2558 if (minutes_away>0) lc->minutes_away=minutes_away;
2560 if (lc->alt_contact!=NULL) {
2561 ms_free(lc->alt_contact);
2562 lc->alt_contact=NULL;
2564 if (contact) lc->alt_contact=ms_strdup(contact);
2565 if (lc->presence_mode!=presence_mode){
2566 linphone_core_notify_all_friends(lc,presence_mode);
2568 Improve the use of all LINPHONE_STATUS available.
2569 !TODO Do not mix "presence status" with "answer status code"..
2570 Use correct parameter to follow sip_if_match/sip_etag.
2572 linphone_core_send_publish(lc,presence_mode);
2574 lc->presence_mode=presence_mode;
2577 LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
2578 return lc->presence_mode;
2582 * Get playback sound level in 0-100 scale.
2584 * @ingroup media_parameters
2586 int linphone_core_get_play_level(LinphoneCore *lc)
2588 return lc->sound_conf.play_lev;
2592 * Get ring sound level in 0-100 scale
2594 * @ingroup media_parameters
2596 int linphone_core_get_ring_level(LinphoneCore *lc)
2598 return lc->sound_conf.ring_lev;
2602 * Get sound capture level in 0-100 scale
2604 * @ingroup media_parameters
2606 int linphone_core_get_rec_level(LinphoneCore *lc){
2607 return lc->sound_conf.rec_lev;
2611 * Set sound ring level in 0-100 scale
2613 * @ingroup media_parameters
2615 void linphone_core_set_ring_level(LinphoneCore *lc, int level){
2617 lc->sound_conf.ring_lev=level;
2618 sndcard=lc->sound_conf.ring_sndcard;
2619 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2623 * Allow to control play level before entering sound card: gain in db
2625 * @ingroup media_parameters
2627 void linphone_core_set_playback_gain_db (LinphoneCore *lc, float gaindb){
2629 LinphoneCall *call=linphone_core_get_current_call (lc);
2632 lc->sound_conf.soft_play_lev=gaindb;
2634 if (call==NULL || (st=call->audiostream)==NULL){
2635 ms_message("linphone_core_set_playback_gain_db(): no active call.");
2639 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_DB_GAIN,&gain);
2640 }else ms_warning("Could not apply gain: gain control wasn't activated.");
2644 * Get playback gain in db before entering sound card.
2646 * @ingroup media_parameters
2648 float linphone_core_get_playback_gain_db(LinphoneCore *lc) {
2649 return lc->sound_conf.soft_play_lev;
2653 * Set sound playback level in 0-100 scale
2655 * @ingroup media_parameters
2657 void linphone_core_set_play_level(LinphoneCore *lc, int level){
2659 lc->sound_conf.play_lev=level;
2660 sndcard=lc->sound_conf.play_sndcard;
2661 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2665 * Set sound capture level in 0-100 scale
2667 * @ingroup media_parameters
2669 void linphone_core_set_rec_level(LinphoneCore *lc, int level)
2672 lc->sound_conf.rec_lev=level;
2673 sndcard=lc->sound_conf.capt_sndcard;
2674 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_CAPTURE,level);
2677 static MSSndCard *get_card_from_string_id(const char *devid, unsigned int cap){
2678 MSSndCard *sndcard=NULL;
2680 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2681 if (sndcard!=NULL &&
2682 (ms_snd_card_get_capabilities(sndcard) & cap)==0 ){
2683 ms_warning("%s card does not have the %s capability, ignoring.",
2685 cap==MS_SND_CARD_CAP_CAPTURE ? "capture" : "playback");
2689 if (sndcard==NULL) {
2690 /* get a card that has read+write capabilities */
2691 sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
2692 /* otherwise refine to the first card having the right capability*/
2694 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2695 for(;elem!=NULL;elem=elem->next){
2696 sndcard=(MSSndCard*)elem->data;
2697 if (ms_snd_card_get_capabilities(sndcard) & cap) break;
2700 if (sndcard==NULL){/*looks like a bug! take the first one !*/
2701 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2702 if (elem) sndcard=(MSSndCard*)elem->data;
2705 if (sndcard==NULL) ms_error("Could not find a suitable soundcard !");
2710 * Returns true if the specified sound device can capture sound.
2712 * @ingroup media_parameters
2713 * @param lc The LinphoneCore object
2714 * @param devid the device name as returned by linphone_core_get_sound_devices()
2716 bool_t linphone_core_sound_device_can_capture(LinphoneCore *lc, const char *devid){
2718 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2719 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_CAPTURE)) return TRUE;
2724 * Returns true if the specified sound device can play sound.
2726 * @ingroup media_parameters
2727 * @param lc The LinphoneCore object
2728 * @param devid the device name as returned by linphone_core_get_sound_devices()
2730 bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *devid){
2732 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2733 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_PLAYBACK)) return TRUE;
2738 * Sets the sound device used for ringing.
2740 * @ingroup media_parameters
2741 * @param lc The LinphoneCore object
2742 * @param devid the device name as returned by linphone_core_get_sound_devices()
2744 int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
2745 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2746 lc->sound_conf.ring_sndcard=card;
2747 if (card && linphone_core_ready(lc))
2748 lp_config_set_string(lc->config,"sound","ringer_dev_id",ms_snd_card_get_string_id(card));
2753 * Sets the sound device used for playback.
2755 * @ingroup media_parameters
2756 * @param lc The LinphoneCore object
2757 * @param devid the device name as returned by linphone_core_get_sound_devices()
2759 int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
2760 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2761 lc->sound_conf.play_sndcard=card;
2762 if (card && linphone_core_ready(lc))
2763 lp_config_set_string(lc->config,"sound","playback_dev_id",ms_snd_card_get_string_id(card));
2768 * Sets the sound device used for capture.
2770 * @ingroup media_parameters
2771 * @param lc The LinphoneCore object
2772 * @param devid the device name as returned by linphone_core_get_sound_devices()
2774 int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
2775 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_CAPTURE);
2776 lc->sound_conf.capt_sndcard=card;
2777 if (card && linphone_core_ready(lc))
2778 lp_config_set_string(lc->config,"sound","capture_dev_id",ms_snd_card_get_string_id(card));
2783 * Returns the name of the currently assigned sound device for ringing.
2785 * @ingroup media_parameters
2786 * @param lc The LinphoneCore object
2788 const char * linphone_core_get_ringer_device(LinphoneCore *lc)
2790 if (lc->sound_conf.ring_sndcard) return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
2795 * Returns the name of the currently assigned sound device for playback.
2797 * @ingroup media_parameters
2798 * @param lc The LinphoneCore object
2800 const char * linphone_core_get_playback_device(LinphoneCore *lc)
2802 return lc->sound_conf.play_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.play_sndcard) : NULL;
2806 * Returns the name of the currently assigned sound device for capture.
2808 * @ingroup media_parameters
2809 * @param lc The LinphoneCore object
2811 const char * linphone_core_get_capture_device(LinphoneCore *lc)
2813 return lc->sound_conf.capt_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard) : NULL;
2817 * Returns an unmodifiable array of available sound devices.
2819 * The array is NULL terminated.
2821 * @ingroup media_parameters
2822 * @param lc The LinphoneCore object
2824 const char** linphone_core_get_sound_devices(LinphoneCore *lc){
2825 build_sound_devices_table(lc);
2826 return lc->sound_conf.cards;
2830 * Returns an unmodifiable array of available video capture devices.
2832 * @ingroup media_parameters
2833 * The array is NULL terminated.
2835 const char** linphone_core_get_video_devices(const LinphoneCore *lc){
2836 return lc->video_conf.cams;
2839 char linphone_core_get_sound_source(LinphoneCore *lc)
2841 return lc->sound_conf.source;
2844 void linphone_core_set_sound_source(LinphoneCore *lc, char source)
2846 MSSndCard *sndcard=lc->sound_conf.capt_sndcard;
2847 lc->sound_conf.source=source;
2848 if (!sndcard) return;
2851 ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
2854 ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
2862 * Sets the path to a wav file used for ringing.
2864 * @param path The file must be a wav 16bit linear. Local ring is disabled if null
2865 * @param lc The LinphoneCore object
2867 * @ingroup media_parameters
2869 void linphone_core_set_ring(LinphoneCore *lc,const char *path){
2870 if (lc->sound_conf.local_ring!=0){
2871 ms_free(lc->sound_conf.local_ring);
2872 lc->sound_conf.local_ring=NULL;
2875 lc->sound_conf.local_ring=ms_strdup(path);
2876 if ( linphone_core_ready(lc) && lc->sound_conf.local_ring)
2877 lp_config_set_string(lc->config,"sound","local_ring",lc->sound_conf.local_ring);
2881 * Returns the path to the wav file used for ringing.
2883 * @param lc The LinphoneCore object
2884 * @ingroup media_parameters
2886 const char *linphone_core_get_ring(const LinphoneCore *lc){
2887 return lc->sound_conf.local_ring;
2890 static void notify_end_of_ring(void *ud, MSFilter *f, unsigned int event, void *arg){
2891 LinphoneCore *lc=(LinphoneCore*)ud;
2892 lc->preview_finished=1;
2895 int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata)
2897 if (lc->ringstream!=0){
2898 ms_warning("Cannot start ring now,there's already a ring being played");
2901 lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
2902 lc->preview_finished=0;
2903 if (lc->sound_conf.ring_sndcard!=NULL){
2904 MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
2905 lc->ringstream=ring_start_with_cb(ring,2000,ringcard,notify_end_of_ring,(void *)lc);
2911 * Sets the path to a wav file used for ringing back.
2913 * Ringback means the ring that is heard when it's ringing at the remote party.
2914 * The file must be a wav 16bit linear.
2916 * @ingroup media_parameters
2918 void linphone_core_set_ringback(LinphoneCore *lc, const char *path){
2919 if (lc->sound_conf.remote_ring!=0){
2920 ms_free(lc->sound_conf.remote_ring);
2922 lc->sound_conf.remote_ring=ms_strdup(path);
2926 * Returns the path to the wav file used for ringing back.
2928 * @ingroup media_parameters
2930 const char * linphone_core_get_ringback(const LinphoneCore *lc){
2931 return lc->sound_conf.remote_ring;
2935 * Enables or disable echo cancellation. Value is saved an used for subsequent calls
2937 * @ingroup media_parameters
2939 void linphone_core_enable_echo_cancellation(LinphoneCore *lc, bool_t val){
2940 lc->sound_conf.ec=val;
2941 if ( linphone_core_ready(lc))
2942 lp_config_set_int(lc->config,"sound","echocancellation",val);
2947 * Returns TRUE if echo cancellation is enabled.
2949 * @ingroup media_parameters
2951 bool_t linphone_core_echo_cancellation_enabled(LinphoneCore *lc){
2952 return lc->sound_conf.ec;
2955 void linphone_core_enable_echo_limiter(LinphoneCore *lc, bool_t val){
2956 lc->sound_conf.ea=val;
2959 bool_t linphone_core_echo_limiter_enabled(const LinphoneCore *lc){
2960 return lc->sound_conf.ea;
2964 * Mutes or unmutes the local microphone.
2966 * @ingroup media_parameters
2968 void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){
2969 LinphoneCall *call=linphone_core_get_current_call(lc);
2971 ms_warning("linphone_core_mute_mic(): No current call !");
2974 if (call->audiostream!=NULL){
2975 audio_stream_set_mic_gain(call->audiostream,
2976 (val==TRUE) ? 0 : lp_config_get_float(lc->config,"sound","mic_gain",1));
2977 if ( linphone_core_get_rtp_no_xmit_on_audio_mute(lc) ){
2978 audio_stream_mute_rtp(call->audiostream,val);
2980 call->audio_muted=val;
2984 bool_t linphone_core_is_mic_muted(LinphoneCore *lc) {
2985 LinphoneCall *call=linphone_core_get_current_call(lc);
2987 ms_warning("linphone_core_is_mic_muted(): No current call !");
2990 return call->audio_muted;
2993 // returns rtp transmission status for an active stream
2994 // if audio is muted and config parameter rtp_no_xmit_on_audio_mute
2995 // was set on then rtp transmission is also muted
2996 bool_t linphone_core_is_rtp_muted(LinphoneCore *lc){
2997 LinphoneCall *call=linphone_core_get_current_call(lc);
2999 ms_warning("linphone_core_is_mic_muted(): No current call !");
3002 if( linphone_core_get_rtp_no_xmit_on_audio_mute(lc)){
3003 return call->audio_muted;
3008 void linphone_core_enable_agc(LinphoneCore *lc, bool_t val){
3009 lc->sound_conf.agc=val;
3012 bool_t linphone_core_agc_enabled(const LinphoneCore *lc){
3013 return lc->sound_conf.agc;
3017 * Send the specified dtmf.
3019 * @ingroup media_parameters
3020 * This function only works during calls. The dtmf is automatically played to the user.
3021 * @param lc The LinphoneCore object
3022 * @param dtmf The dtmf name specified as a char, such as '0', '#' etc...
3025 void linphone_core_send_dtmf(LinphoneCore *lc, char dtmf)
3027 LinphoneCall *call=linphone_core_get_current_call(lc);
3029 ms_warning("linphone_core_send_dtmf(): no active call");
3032 /*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
3033 if (linphone_core_get_use_rfc2833_for_dtmf(lc)!=0 || linphone_core_get_use_info_for_dtmf(lc)==0)
3036 if (call->audiostream!=NULL){
3037 audio_stream_send_dtmf(call->audiostream,dtmf);
3041 ms_error("we cannot send RFC2833 dtmf when we are not in communication");
3044 if (linphone_core_get_use_info_for_dtmf(lc)!=0){
3045 /* Out of Band DTMF (use INFO method) */
3046 sal_call_send_dtmf(call->op,dtmf);
3050 void linphone_core_set_stun_server(LinphoneCore *lc, const char *server){
3051 if (lc->net_conf.stun_server!=NULL)
3052 ms_free(lc->net_conf.stun_server);
3054 lc->net_conf.stun_server=ms_strdup(server);
3055 else lc->net_conf.stun_server=NULL;
3058 const char * linphone_core_get_stun_server(const LinphoneCore *lc){
3059 return lc->net_conf.stun_server;
3062 const char * linphone_core_get_relay_addr(const LinphoneCore *lc){
3063 return lc->net_conf.relay;
3066 int linphone_core_set_relay_addr(LinphoneCore *lc, const char *addr){
3067 if (lc->net_conf.relay!=NULL){
3068 ms_free(lc->net_conf.relay);
3069 lc->net_conf.relay=NULL;
3072 lc->net_conf.relay=ms_strdup(addr);
3077 void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
3079 if (lc->net_conf.nat_address!=NULL){
3080 ms_free(lc->net_conf.nat_address);
3082 if (addr!=NULL) lc->net_conf.nat_address=ms_strdup(addr);
3083 else lc->net_conf.nat_address=NULL;
3084 if (lc->sip_conf.contact) update_primary_contact(lc);
3087 const char *linphone_core_get_nat_address(const LinphoneCore *lc) {
3088 return lc->net_conf.nat_address;
3091 const char *linphone_core_get_nat_address_resolved(LinphoneCore *lc)
3093 struct sockaddr_storage ss;
3096 char ipstring [INET6_ADDRSTRLEN];
3098 if (parse_hostname_to_addr (lc->net_conf.nat_address, &ss, &ss_len)<0) {
3099 return lc->net_conf.nat_address;
3102 error = getnameinfo((struct sockaddr *)&ss, ss_len,
3103 ipstring, sizeof(ipstring), NULL, 0, NI_NUMERICHOST);
3105 return lc->net_conf.nat_address;
3108 if (lc->net_conf.nat_address_ip!=NULL){
3109 ms_free(lc->net_conf.nat_address_ip);
3111 lc->net_conf.nat_address_ip = ms_strdup (ipstring);
3112 return lc->net_conf.nat_address_ip;
3115 void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
3116 lc->net_conf.firewall_policy=pol;
3117 if (lc->sip_conf.contact) update_primary_contact(lc);
3120 LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
3121 return lc->net_conf.firewall_policy;
3125 * Get the list of call logs (past calls).
3127 * @ingroup call_logs
3129 const MSList * linphone_core_get_call_logs(LinphoneCore *lc){
3131 return lc->call_logs;
3135 * Erase the call log.
3137 * @ingroup call_logs
3139 void linphone_core_clear_call_logs(LinphoneCore *lc){
3141 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3142 lc->call_logs=ms_list_free(lc->call_logs);
3143 call_logs_write_to_config_file(lc);
3146 static void toggle_video_preview(LinphoneCore *lc, bool_t val){
3147 #ifdef VIDEO_ENABLED
3149 if (lc->previewstream==NULL){
3150 lc->previewstream=video_preview_new();
3151 video_preview_set_size(lc->previewstream,lc->video_conf.vsize);
3152 if (lc->video_conf.displaytype)
3153 video_preview_set_display_filter_name(lc->previewstream,lc->video_conf.displaytype);
3154 if (lc->preview_window_id!=0)
3155 video_preview_set_native_window_id(lc->previewstream,lc->preview_window_id);
3156 video_preview_start(lc->previewstream,lc->video_conf.device);
3159 if (lc->previewstream!=NULL){
3160 video_preview_stop(lc->previewstream);
3161 lc->previewstream=NULL;
3168 * Enables video globally.
3170 * @ingroup media_parameters
3171 * This function does not have any effect during calls. It just indicates LinphoneCore to
3172 * initiate future calls with video or not. The two boolean parameters indicate in which
3173 * direction video is enabled. Setting both to false disables video entirely.
3175 * @param lc The LinphoneCore object
3176 * @param vcap_enabled indicates whether video capture is enabled
3177 * @param display_enabled indicates whether video display should be shown
3180 void linphone_core_enable_video(LinphoneCore *lc, bool_t vcap_enabled, bool_t display_enabled){
3181 #ifndef VIDEO_ENABLED
3182 if (vcap_enabled || display_enabled)
3183 ms_warning("This version of linphone was built without video support.");
3185 lc->video_conf.capture=vcap_enabled;
3186 lc->video_conf.display=display_enabled;
3188 /* need to re-apply network bandwidth settings*/
3189 linphone_core_set_download_bandwidth(lc,
3190 linphone_core_get_download_bandwidth(lc));
3191 linphone_core_set_upload_bandwidth(lc,
3192 linphone_core_get_upload_bandwidth(lc));
3196 * Returns TRUE if video is enabled, FALSE otherwise.
3197 * @ingroup media_parameters
3199 bool_t linphone_core_video_enabled(LinphoneCore *lc){
3200 return (lc->video_conf.display || lc->video_conf.capture);
3204 * Controls video preview enablement.
3206 * @ingroup media_parameters
3207 * Video preview refers to the action of displaying the local webcam image
3208 * to the user while not in call.
3210 void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val){
3211 lc->video_conf.show_local=val;
3215 * Returns TRUE if video previewing is enabled.
3216 * @ingroup media_parameters
3218 bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
3219 return lc->video_conf.show_local;
3223 * Enables or disable self view during calls.
3225 * @ingroup media_parameters
3226 * Self-view refers to having local webcam image inserted in corner
3227 * of the video window during calls.
3228 * This function works at any time, including during calls.
3230 void linphone_core_enable_self_view(LinphoneCore *lc, bool_t val){
3231 #ifdef VIDEO_ENABLED
3232 LinphoneCall *call=linphone_core_get_current_call (lc);
3233 lc->video_conf.selfview=val;
3234 if (call && call->videostream){
3235 video_stream_enable_self_view(call->videostream,val);
3241 * Returns TRUE if self-view is enabled, FALSE otherwise.
3243 * @ingroup media_parameters
3245 * Refer to linphone_core_enable_self_view() for details.
3247 bool_t linphone_core_self_view_enabled(const LinphoneCore *lc){
3248 return lc->video_conf.selfview;
3252 * Sets the active video device.
3254 * @ingroup media_parameters
3255 * @param lc The LinphoneCore object
3256 * @param id the name of the video device as returned by linphone_core_get_video_devices()
3258 int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
3259 MSWebCam *olddev=lc->video_conf.device;
3262 lc->video_conf.device=ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),id);
3263 if (lc->video_conf.device==NULL){
3264 ms_warning("Could not found video device %s",id);
3267 if (lc->video_conf.device==NULL)
3268 lc->video_conf.device=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());
3269 if (olddev!=NULL && olddev!=lc->video_conf.device){
3270 toggle_video_preview(lc,FALSE);/*restart the video local preview*/
3272 if ( linphone_core_ready(lc) && lc->video_conf.device){
3273 vd=ms_web_cam_get_string_id(lc->video_conf.device);
3274 if (vd && strstr(vd,"Static picture")!=NULL){
3277 lp_config_set_string(lc->config,"video","device",vd);
3283 * Returns the name of the currently active video device.
3285 * @param lc The LinphoneCore object
3286 * @ingroup media_parameters
3288 const char *linphone_core_get_video_device(const LinphoneCore *lc){
3289 if (lc->video_conf.device) return ms_web_cam_get_string_id(lc->video_conf.device);
3293 #ifdef VIDEO_ENABLED
3294 static VideoStream * get_active_video_stream(LinphoneCore *lc){
3295 VideoStream *vs = NULL;
3296 LinphoneCall *call=linphone_core_get_current_call (lc);
3297 /* Select the video stream from the call in the first place */
3298 if (call && call->videostream) {
3299 vs = call->videostream;
3301 /* If not in call, select the video stream from the preview */
3302 if (vs == NULL && lc->previewstream) {
3303 vs = lc->previewstream;
3309 int linphone_core_set_static_picture(LinphoneCore *lc, const char *path) {
3310 #ifdef VIDEO_ENABLED
3311 VideoStream *vs=get_active_video_stream(lc);
3312 /* If we have a video stream (either preview, either from call), we
3313 have a source and it is using the static picture filter, then
3314 force the filter to use that picture. */
3315 if (vs && vs->source) {
3316 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3317 ms_filter_call_method(vs->source, MS_STATIC_IMAGE_SET_IMAGE,
3321 /* Tell the static image filter to use that image from now on so
3322 that the image will be used next time it has to be read */
3323 ms_static_image_set_default_image(path);
3325 ms_warning("Video support not compiled.");
3330 int linphone_core_set_static_picture_fps(LinphoneCore *lc, float fps) {
3331 #ifdef VIDEO_ENABLED
3332 VideoStream *vs = NULL;
3334 vs=get_active_video_stream(lc);
3336 /* If we have a video stream (either preview, either from call), we
3337 have a source and it is using the static picture filter, then
3338 force the filter to use that picture. */
3339 if (vs && vs->source) {
3340 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3341 ms_filter_call_method(vs->source, MS_FILTER_SET_FPS,(void *)&fps);
3345 ms_warning("Video support not compiled.");
3350 float linphone_core_get_static_picture_fps(LinphoneCore *lc) {
3351 #ifdef VIDEO_ENABLED
3352 VideoStream *vs = NULL;
3353 vs=get_active_video_stream(lc);
3354 /* If we have a video stream (either preview, either from call), we
3355 have a source and it is using the static picture filter, then
3356 force the filter to use that picture. */
3357 if (vs && vs->source) {
3358 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3362 ms_filter_call_method(vs->source, MS_FILTER_GET_FPS,(void *)&fps);
3367 ms_warning("Video support not compiled.");
3373 * Returns the native window handle of the video window, casted as an unsigned long.
3375 * @ingroup media_parameters
3377 unsigned long linphone_core_get_native_video_window_id(const LinphoneCore *lc){
3378 #ifdef VIDEO_ENABLED
3379 LinphoneCall *call=linphone_core_get_current_call (lc);
3380 if (call && call->videostream)
3381 return video_stream_get_native_window_id(call->videostream);
3382 if (lc->previewstream)
3383 return video_stream_get_native_window_id(lc->previewstream);
3385 return lc->video_window_id;
3389 * Set the native video window id where the video is to be displayed.
3390 * If not set the core will create its own window.
3392 void linphone_core_set_native_video_window_id(LinphoneCore *lc, unsigned long id){
3393 #ifdef VIDEO_ENABLED
3394 LinphoneCall *call=linphone_core_get_current_call(lc);
3395 lc->video_window_id=id;
3396 if (call!=NULL && call->videostream){
3397 video_stream_set_native_window_id(call->videostream,id);
3403 * Returns the native window handle of the video preview window, casted as an unsigned long.
3405 * @ingroup media_parameters
3407 unsigned long linphone_core_get_native_preview_window_id(const LinphoneCore *lc){
3408 #ifdef VIDEO_ENABLED
3409 LinphoneCall *call=linphone_core_get_current_call (lc);
3410 if (call && call->videostream)
3411 return video_stream_get_native_preview_window_id(call->videostream);
3412 if (lc->previewstream)
3413 return video_preview_get_native_window_id(lc->previewstream);
3415 return lc->preview_window_id;
3419 * Set the native window id where the preview video (local camera) is to be displayed.
3420 * This has to be used in conjonction with linphone_core_use_preview_window().
3421 * If not set the core will create its own window.
3423 void linphone_core_set_native_preview_window_id(LinphoneCore *lc, unsigned long id){
3424 lc->preview_window_id=id;
3428 * Tells the core to use a separate window for local camera preview video, instead of
3429 * inserting local view within the remote video window.
3432 void linphone_core_use_preview_window(LinphoneCore *lc, bool_t yesno){
3433 lc->use_preview_window=yesno;
3436 static MSVideoSizeDef supported_resolutions[]={
3438 { {MS_VIDEO_SIZE_1080P_W,MS_VIDEO_SIZE_1080P_H} , "1080p" },
3439 { {MS_VIDEO_SIZE_720P_W,MS_VIDEO_SIZE_720P_H} , "1080p" },
3441 { {MS_VIDEO_SIZE_SVGA_W,MS_VIDEO_SIZE_SVGA_H} , "svga" },
3442 { {MS_VIDEO_SIZE_4CIF_W,MS_VIDEO_SIZE_4CIF_H} , "4cif" },
3443 { {MS_VIDEO_SIZE_VGA_W,MS_VIDEO_SIZE_VGA_H} , "vga" },
3444 { {MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H} , "cif" },
3445 { {MS_VIDEO_SIZE_QVGA_W,MS_VIDEO_SIZE_QVGA_H} , "qvga" },
3446 { {MS_VIDEO_SIZE_QVGA_H,MS_VIDEO_SIZE_QVGA_W} , "qvga-portrait" },
3447 { {MS_VIDEO_SIZE_QCIF_W,MS_VIDEO_SIZE_QCIF_H} , "qcif" },
3448 { {MS_VIDEO_SIZE_QCIF_H,MS_VIDEO_SIZE_QCIF_W} , "qcif-portrait" },
3453 * Returns the zero terminated table of supported video resolutions.
3455 * @ingroup media_parameters
3457 const MSVideoSizeDef *linphone_core_get_supported_video_sizes(LinphoneCore *lc){
3458 return supported_resolutions;
3461 static MSVideoSize video_size_get_by_name(const char *name){
3462 MSVideoSizeDef *pdef=supported_resolutions;
3463 MSVideoSize null_vsize={0,0};
3464 for(;pdef->name!=NULL;pdef++){
3465 if (strcasecmp(name,pdef->name)==0){
3469 ms_warning("Video resolution %s is not supported in linphone.",name);
3473 static const char *video_size_get_name(MSVideoSize vsize){
3474 MSVideoSizeDef *pdef=supported_resolutions;
3475 for(;pdef->name!=NULL;pdef++){
3476 if (pdef->vsize.width==vsize.width && pdef->vsize.height==vsize.height){
3483 static bool_t video_size_supported(MSVideoSize vsize){
3484 if (video_size_get_name(vsize)) return TRUE;
3485 ms_warning("Video resolution %ix%i is not supported in linphone.",vsize.width,vsize.height);
3490 * Sets the preferred video size.
3492 * @ingroup media_parameters
3493 * This applies only to the stream that is captured and sent to the remote party,
3494 * since we accept all standard video size on the receive path.
3496 void linphone_core_set_preferred_video_size(LinphoneCore *lc, MSVideoSize vsize){
3497 if (video_size_supported(vsize)){
3498 MSVideoSize oldvsize=lc->video_conf.vsize;
3499 lc->video_conf.vsize=vsize;
3500 if (!ms_video_size_equal(oldvsize,vsize) && lc->previewstream!=NULL){
3501 toggle_video_preview(lc,FALSE);
3502 toggle_video_preview(lc,TRUE);
3504 if ( linphone_core_ready(lc))
3505 lp_config_set_string(lc->config,"video","size",video_size_get_name(vsize));
3510 * Sets the preferred video size by its name.
3512 * @ingroup media_parameters
3513 * This is identical to linphone_core_set_preferred_video_size() except
3514 * that it takes the name of the video resolution as input.
3515 * Video resolution names are: qcif, svga, cif, vga, 4cif, svga ...
3517 void linphone_core_set_preferred_video_size_by_name(LinphoneCore *lc, const char *name){
3518 MSVideoSize vsize=video_size_get_by_name(name);
3519 MSVideoSize default_vsize={MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H};
3520 if (vsize.width!=0) linphone_core_set_preferred_video_size(lc,vsize);
3521 else linphone_core_set_preferred_video_size(lc,default_vsize);
3525 * Returns the current preferred video size for sending.
3527 * @ingroup media_parameters
3529 MSVideoSize linphone_core_get_preferred_video_size(LinphoneCore *lc){
3530 return lc->video_conf.vsize;
3534 * Ask the core to stream audio from and to files, instead of using the soundcard.
3536 void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
3537 lc->use_files=yesno;
3541 * Sets a wav file to be played when putting somebody on hold,
3542 * or when files are used instead of soundcards (see linphone_core_use_files()).
3544 * The file must be a 16 bit linear wav file.
3546 void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
3547 LinphoneCall *call=linphone_core_get_current_call(lc);
3548 if (lc->play_file!=NULL){
3549 ms_free(lc->play_file);
3553 lc->play_file=ms_strdup(file);
3554 if (call && call->audiostream && call->audiostream->ticker)
3555 audio_stream_play(call->audiostream,file);
3561 * Sets a wav file where incoming stream is to be recorded,
3562 * when files are used instead of soundcards (see linphone_core_use_files()).
3564 * The file must be a 16 bit linear wav file.
3566 void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
3567 LinphoneCall *call=linphone_core_get_current_call(lc);
3568 if (lc->rec_file!=NULL){
3569 ms_free(lc->rec_file);
3573 lc->rec_file=ms_strdup(file);
3574 if (call && call->audiostream)
3575 audio_stream_record(call->audiostream,file);
3580 static MSFilter *get_dtmf_gen(LinphoneCore *lc){
3581 LinphoneCall *call=linphone_core_get_current_call (lc);
3583 AudioStream *stream=call->audiostream;
3585 return stream->dtmfgen;
3588 if (lc->ringstream==NULL){
3590 MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
3591 lc->ringstream=ring_start(NULL,0,ringcard);
3592 ms_filter_call_method(lc->ringstream->gendtmf,MS_DTMF_GEN_SET_DEFAULT_AMPLITUDE,&);
3593 lc->dmfs_playing_start_time=time(NULL);
3595 if (lc->dmfs_playing_start_time!=0)
3596 lc->dmfs_playing_start_time=time(NULL);
3598 return lc->ringstream->gendtmf;
3602 * @ingroup media_parameters
3603 * Plays a dtmf sound to the local user.
3604 * @param lc #LinphoneCore
3605 * @param dtmf DTMF to play ['0'..'16'] | '#' | '#'
3606 * @param duration_ms duration in ms, -1 means play until next further call to #linphone_core_stop_dtmf()
3608 void linphone_core_play_dtmf(LinphoneCore *lc, char dtmf, int duration_ms){
3609 MSFilter *f=get_dtmf_gen(lc);
3611 ms_error("No dtmf generator at this time !");
3616 ms_filter_call_method(f, MS_DTMF_GEN_PLAY, &dtmf);
3617 else ms_filter_call_method(f, MS_DTMF_GEN_START, &dtmf);
3621 * @ingroup media_parameters
3623 * Stops playing a dtmf started by linphone_core_play_dtmf().
3625 void linphone_core_stop_dtmf(LinphoneCore *lc){
3626 MSFilter *f=get_dtmf_gen(lc);
3628 ms_filter_call_method_noarg (f, MS_DTMF_GEN_STOP);
3634 * Retrieves the user pointer that was given to linphone_core_new()
3636 * @ingroup initializing
3638 void *linphone_core_get_user_data(LinphoneCore *lc){
3642 int linphone_core_get_mtu(const LinphoneCore *lc){
3643 return lc->net_conf.mtu;
3646 void linphone_core_set_mtu(LinphoneCore *lc, int mtu){
3647 lc->net_conf.mtu=mtu;
3650 ms_error("MTU too small !");
3654 ms_message("MTU is supposed to be %i, rtp payload max size will be %i",mtu, ms_get_payload_max_size());
3655 }else ms_set_mtu(0);//use mediastreamer2 default value
3658 void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context){
3660 lc->wait_ctx=user_context;
3663 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose){
3665 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingStart,purpose,0);
3669 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progress){
3671 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingProgress,purpose,progress);
3681 void linphone_core_stop_waiting(LinphoneCore *lc){
3683 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingFinished,NULL,0);
3687 void linphone_core_set_audio_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3692 void linphone_core_set_video_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3698 * Retrieve RTP statistics regarding current call.
3699 * @param local RTP statistics computed locally.
3700 * @param remote RTP statistics computed by far end (obtained via RTCP feedback).
3702 * @note Remote RTP statistics is not implemented yet.
3704 * @returns 0 or -1 if no call is running.
3707 int linphone_core_get_current_call_stats(LinphoneCore *lc, rtp_stats_t *local, rtp_stats_t *remote){
3708 LinphoneCall *call=linphone_core_get_current_call (lc);
3710 if (call->audiostream!=NULL){
3711 memset(remote,0,sizeof(*remote));
3712 audio_stream_get_local_rtp_stats (call->audiostream,local);
3719 void net_config_uninit(LinphoneCore *lc)
3721 net_config_t *config=&lc->net_conf;
3722 lp_config_set_int(lc->config,"net","download_bw",config->download_bw);
3723 lp_config_set_int(lc->config,"net","upload_bw",config->upload_bw);
3725 if (config->stun_server!=NULL){
3726 lp_config_set_string(lc->config,"net","stun_server",config->stun_server);
3727 ms_free(lc->net_conf.stun_server);
3729 if (config->nat_address!=NULL){
3730 lp_config_set_string(lc->config,"net","nat_address",config->nat_address);
3731 ms_free(lc->net_conf.nat_address);
3733 if (lc->net_conf.nat_address_ip !=NULL){
3734 ms_free(lc->net_conf.nat_address_ip);
3736 lp_config_set_int(lc->config,"net","firewall_policy",config->firewall_policy);
3737 lp_config_set_int(lc->config,"net","mtu",config->mtu);
3741 void sip_config_uninit(LinphoneCore *lc)
3745 sip_config_t *config=&lc->sip_conf;
3746 lp_config_set_int(lc->config,"sip","sip_port",config->transports.udp_port);
3747 lp_config_set_int(lc->config,"sip","sip_tcp_port",config->transports.tcp_port);
3748 lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
3749 lp_config_set_string(lc->config,"sip","contact",config->contact);
3750 lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
3751 lp_config_set_int(lc->config,"sip","use_info",config->use_info);
3752 lp_config_set_int(lc->config,"sip","use_rfc2833",config->use_rfc2833);
3753 lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
3754 lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
3757 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
3759 for(elem=config->proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3760 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
3761 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
3762 linphone_proxy_config_edit(cfg); /* to unregister */
3764 /*to ensure remove configs are erased:*/
3765 linphone_proxy_config_write_to_config_file(lc->config,NULL,i);
3768 sal_iterate(lc->sal);
3776 ms_list_for_each(config->proxies,(void (*)(void*)) linphone_proxy_config_destroy);
3777 ms_list_free(config->proxies);
3778 config->proxies=NULL;
3780 linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */
3782 for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3783 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
3784 linphone_auth_info_write_config(lc->config,ai,i);
3786 linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
3787 ms_list_for_each(lc->auth_info,(void (*)(void*))linphone_auth_info_destroy);
3788 ms_list_free(lc->auth_info);
3791 sal_uninit(lc->sal);
3794 if (lc->sip_conf.guessed_contact)
3795 ms_free(lc->sip_conf.guessed_contact);
3796 if (config->contact)
3797 ms_free(config->contact);
3801 void rtp_config_uninit(LinphoneCore *lc)
3803 rtp_config_t *config=&lc->rtp_conf;
3804 lp_config_set_int(lc->config,"rtp","audio_rtp_port",config->audio_rtp_port);
3805 lp_config_set_int(lc->config,"rtp","video_rtp_port",config->video_rtp_port);
3806 lp_config_set_int(lc->config,"rtp","audio_jitt_comp",config->audio_jitt_comp);
3807 lp_config_set_int(lc->config,"rtp","video_jitt_comp",config->video_jitt_comp);
3808 lp_config_set_int(lc->config,"rtp","nortp_timeout",config->nortp_timeout);
3811 void sound_config_uninit(LinphoneCore *lc)
3813 sound_config_t *config=&lc->sound_conf;
3814 ms_free(config->cards);
3816 lp_config_set_string(lc->config,"sound","remote_ring",config->remote_ring);
3818 if (config->local_ring) ms_free(config->local_ring);
3819 if (config->remote_ring) ms_free(config->remote_ring);
3820 ms_snd_card_manager_destroy();
3823 void video_config_uninit(LinphoneCore *lc)
3825 lp_config_set_string(lc->config,"video","size",video_size_get_name(linphone_core_get_preferred_video_size(lc)));
3826 lp_config_set_int(lc->config,"video","display",lc->video_conf.display);
3827 lp_config_set_int(lc->config,"video","capture",lc->video_conf.capture);
3828 lp_config_set_int(lc->config,"video","show_local",linphone_core_video_preview_enabled(lc));
3829 lp_config_set_int(lc->config,"video","self_view",linphone_core_self_view_enabled(lc));
3830 if (lc->video_conf.cams)
3831 ms_free(lc->video_conf.cams);
3834 void codecs_config_uninit(LinphoneCore *lc)
3837 codecs_config_t *config=&lc->codecs_conf;
3842 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
3843 pt=(PayloadType*)(node->data);
3844 sprintf(key,"audio_codec_%i",index);
3845 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3846 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3847 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3850 sprintf(key,"audio_codec_%i",index);
3851 lp_config_clean_section (lc->config,key);
3854 for(node=config->video_codecs;node!=NULL;node=ms_list_next(node)){
3855 pt=(PayloadType*)(node->data);
3856 sprintf(key,"video_codec_%i",index);
3857 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3858 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3859 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3860 lp_config_set_string(lc->config,key,"recv_fmtp",pt->recv_fmtp);
3863 sprintf(key,"video_codec_%i",index);
3864 lp_config_clean_section (lc->config,key);
3866 ms_list_free(lc->codecs_conf.audio_codecs);
3867 ms_list_free(lc->codecs_conf.video_codecs);
3870 void ui_config_uninit(LinphoneCore* lc)
3873 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_destroy);
3874 ms_list_free(lc->friends);
3880 * Returns the LpConfig object used to manage the storage (config) file.
3883 * The application can use the LpConfig object to insert its own private
3884 * sections and pairs of key=value in the configuration file.
3887 LpConfig *linphone_core_get_config(LinphoneCore *lc){
3891 static void linphone_core_uninit(LinphoneCore *lc)
3893 linphone_core_free_hooks(lc);
3896 LinphoneCall *the_call = lc->calls->data;
3897 linphone_core_terminate_call(lc,the_call);
3898 linphone_core_iterate(lc);
3906 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions);
3907 linphone_core_set_state(lc,LinphoneGlobalShutdown,"Shutting down");
3908 #ifdef VIDEO_ENABLED
3909 if (lc->previewstream!=NULL){
3910 video_preview_stop(lc->previewstream);
3911 lc->previewstream=NULL;
3914 ms_event_queue_destroy(lc->msevq);
3916 /* save all config */
3917 net_config_uninit(lc);
3918 rtp_config_uninit(lc);
3919 if (lc->ringstream) ring_stop(lc->ringstream);
3920 sound_config_uninit(lc);
3921 video_config_uninit(lc);
3922 codecs_config_uninit(lc);
3923 ui_config_uninit(lc);
3924 sip_config_uninit(lc);
3925 if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
3926 lp_config_destroy(lc->config);
3927 lc->config = NULL; /* Mark the config as NULL to block further calls */
3928 sip_setup_unregister_all();
3930 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3931 lc->call_logs=ms_list_free(lc->call_logs);
3933 linphone_core_free_payload_types();
3935 linphone_core_set_state(lc,LinphoneGlobalOff,"Off");
3938 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t curtime){
3939 ms_message("Network state is now [%s]",isReachable?"UP":"DOWN");
3940 // second get the list of available proxies
3941 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3942 for(;elem!=NULL;elem=elem->next){
3943 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3944 if (linphone_proxy_config_register_enabled(cfg) ) {
3952 lc->netup_time=curtime;
3953 lc->network_reachable=isReachable;
3955 sal_unlisten_ports (lc->sal);
3957 apply_transports(lc);
3961 void linphone_core_refresh_registers(LinphoneCore* lc) {
3962 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3963 for(;elem!=NULL;elem=elem->next){
3964 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3965 if (linphone_proxy_config_register_enabled(cfg) ) {
3966 linphone_proxy_config_refresh_register(cfg);
3971 void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) {
3972 //first disable automatic mode
3973 if (lc->auto_net_state_mon) {
3974 ms_message("Disabling automatic network state monitoring");
3975 lc->auto_net_state_mon=FALSE;
3977 set_network_reachable(lc,isReachable, ms_time(NULL));
3980 bool_t linphone_core_is_network_reachabled(LinphoneCore* lc) {
3981 return lc->network_reachable;
3983 ortp_socket_t linphone_core_get_sip_socket(LinphoneCore *lc){
3984 return sal_get_socket(lc->sal);
3987 * Destroys a LinphoneCore
3989 * @ingroup initializing
3991 void linphone_core_destroy(LinphoneCore *lc){
3992 linphone_core_uninit(lc);
3996 * Get the number of Call
3998 * @ingroup call_control
4000 int linphone_core_get_calls_nb(const LinphoneCore *lc){
4001 return ms_list_size(lc->calls);;
4005 * Check if we do not have exceed the number of simultaneous call
4007 * @ingroup call_control
4009 bool_t linphone_core_can_we_add_call(LinphoneCore *lc)
4011 if(linphone_core_get_calls_nb(lc) < NB_MAX_CALLS)
4013 ms_error("Maximum amount of simultaneous calls reached !");
4018 int linphone_core_add_call( LinphoneCore *lc, LinphoneCall *call)
4020 if(linphone_core_can_we_add_call(lc))
4022 lc->calls = ms_list_append(lc->calls,call);
4028 int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call)
4031 MSList *the_calls = lc->calls;
4033 it=ms_list_find(the_calls,call);
4036 the_calls = ms_list_remove_link(the_calls,it);
4040 ms_warning("could not find the call into the list\n");
4043 lc->calls = the_calls;
4048 * Specifiies a ring back tone to be played to far end during incoming calls.
4050 void linphone_core_set_remote_ringback_tone(LinphoneCore *lc, const char *file){
4051 if (lc->sound_conf.ringback_tone){
4052 ms_free(lc->sound_conf.ringback_tone);
4053 lc->sound_conf.ringback_tone=NULL;
4056 lc->sound_conf.ringback_tone=ms_strdup(file);
4060 * Returns the ring back tone played to far end during incoming calls.
4062 const char *linphone_core_get_remote_ringback_tone(const LinphoneCore *lc){
4063 return lc->sound_conf.ringback_tone;
4066 static PayloadType* find_payload_type_from_list(const char* type, int rate,const MSList* from) {
4068 for(elem=from;elem!=NULL;elem=elem->next){
4069 PayloadType *pt=(PayloadType*)elem->data;
4070 if ((strcmp((char*)type, payload_type_get_mime(pt)) == 0) && (rate == -1 || rate==pt->clock_rate)) {
4078 * Get payload type from mime type and clock rate
4079 * @ingroup media_parameters
4080 * This function searches in audio and video codecs for the given payload type name and clockrate.
4081 * Returns NULL if not found.
4083 PayloadType* linphone_core_find_payload_type(LinphoneCore* lc, const char* type, int rate) {
4084 PayloadType* result = find_payload_type_from_list(type, rate, linphone_core_get_audio_codecs(lc));
4088 result = find_payload_type_from_list(type, rate, linphone_core_get_video_codecs(lc));
4097 const char *linphone_global_state_to_string(LinphoneGlobalState gs){
4099 case LinphoneGlobalOff:
4100 return "LinphoneGlobalOff";
4102 case LinphoneGlobalOn:
4103 return "LinphoneGlobalOn";
4105 case LinphoneGlobalStartup:
4106 return "LinphoneGlobalStartup";
4108 case LinphoneGlobalShutdown:
4109 return "LinphoneGlobalShutdown";
4115 LinphoneGlobalState linphone_core_get_global_state(const LinphoneCore *lc){
4119 LinphoneCallParams *linphone_core_create_default_call_parameters(LinphoneCore *lc){
4120 LinphoneCallParams *p=ms_new0(LinphoneCallParams,1);
4121 p->has_video=linphone_core_video_enabled(lc);
4125 const char *linphone_reason_to_string(LinphoneReason err){
4127 case LinphoneReasonNone:
4129 case LinphoneReasonNoResponse:
4130 return "No response";
4131 case LinphoneReasonBadCredentials:
4132 return "Bad credentials";
4133 case LinphoneReasonDeclined:
4134 return "Call declined";
4136 return "unknown error";
4139 const char *linphone_error_to_string(LinphoneReason err){
4140 return linphone_reason_to_string(err);
4143 * Enables signaling keep alive
4145 void linphone_core_enable_keep_alive(LinphoneCore* lc,bool_t enable) {
4147 sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
4149 sal_set_keepalive_period(lc->sal,0);
4153 * Is signaling keep alive enabled
4155 bool_t linphone_core_keep_alive_enabled(LinphoneCore* lc) {
4156 return sal_get_keepalive_period(lc->sal) > 0;
4159 void linphone_core_start_dtmf_stream(LinphoneCore* lc) {
4160 get_dtmf_gen(lc); /*make sure ring stream is started*/
4161 lc->ringstream_autorelease=FALSE; /*disable autorelease mode*/
4164 void linphone_core_stop_dtmf_stream(LinphoneCore* lc) {
4165 if (lc->ringstream) ring_stop(lc->ringstream);
4166 lc->ringstream=NULL;
4169 typedef struct Hook{
4170 LinphoneCoreIterateHook fun;
4174 static Hook *hook_new(LinphoneCoreIterateHook hook, void *hook_data){
4175 Hook *h=ms_new(Hook,1);
4181 static void hook_invoke(Hook *h){
4185 void linphone_core_add_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data){
4186 lc->hooks=ms_list_append(lc->hooks,hook_new(hook,hook_data));
4189 static void linphone_core_run_hooks(LinphoneCore *lc){
4190 ms_list_for_each(lc->hooks,(void (*)(void*))hook_invoke);
4193 static void linphone_core_free_hooks(LinphoneCore *lc){
4194 ms_list_for_each(lc->hooks,(void (*)(void*))ms_free);
4195 ms_list_free(lc->hooks);
4199 void linphone_core_remove_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data){
4201 for(elem=lc->hooks;elem!=NULL;elem=elem->next){
4202 Hook *h=(Hook*)elem->data;
4203 if (h->fun==hook && h->data==hook_data){
4204 ms_list_remove_link(lc->hooks,elem);
4209 ms_error("linphone_core_remove_iterate_hook(): No such hook found.");