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));
469 sal_reuse_authorization(lc->sal, lp_config_get_int(lc->config,"sip","reuse_authorization",0));
471 tmp=lp_config_get_int(lc->config,"sip","use_rfc2833",0);
472 linphone_core_set_use_rfc2833_for_dtmf(lc,tmp);
474 ipv6=lp_config_get_int(lc->config,"sip","use_ipv6",-1);
478 linphone_core_enable_ipv6(lc,ipv6);
479 memset(&tr,0,sizeof(tr));
480 if (lp_config_get_int(lc->config,"sip","sip_random_port",0)) {
481 tr.udp_port=(0xDFF&+random())+1024;
483 tr.udp_port=lp_config_get_int(lc->config,"sip","sip_port",5060);
485 if (lp_config_get_int(lc->config,"sip","sip_tcp_random_port",0)) {
486 tr.tcp_port=(0xDFF&+random())+1024;
488 tr.tcp_port=lp_config_get_int(lc->config,"sip","sip_tcp_port",0);
490 /*start listening on ports*/
491 linphone_core_set_sip_transports(lc,&tr);
493 tmpstr=lp_config_get_string(lc->config,"sip","contact",NULL);
494 if (tmpstr==NULL || linphone_core_set_primary_contact(lc,tmpstr)==-1) {
495 const char *hostname=NULL;
496 const char *username=NULL;
498 hostname=getenv("HOST");
499 username=getenv("USER");
500 if (hostname==NULL) hostname=getenv("HOSTNAME");
501 #endif /*HAVE_GETENV*/
503 hostname="unknown-host";
507 contact=ortp_strdup_printf("sip:%s@%s",username,hostname);
508 linphone_core_set_primary_contact(lc,contact);
512 tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
513 linphone_core_set_guess_hostname(lc,tmp);
516 tmp=lp_config_get_int(lc->config,"sip","inc_timeout",15);
517 linphone_core_set_inc_timeout(lc,tmp);
519 /* get proxies config */
521 LinphoneProxyConfig *cfg=linphone_proxy_config_new_from_config_file(lc->config,i);
523 linphone_core_add_proxy_config(lc,cfg);
528 /* get the default proxy */
529 tmp=lp_config_get_int(lc->config,"sip","default_proxy",-1);
530 linphone_core_set_default_proxy_index(lc,tmp);
532 /* read authentication information */
534 LinphoneAuthInfo *ai=linphone_auth_info_new_from_config_file(lc->config,i);
536 linphone_core_add_auth_info(lc,ai);
537 linphone_auth_info_destroy(ai);
543 /*for tuning or test*/
544 lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
545 lc->sip_conf.register_only_when_network_is_up=
546 lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",1);
547 lc->sip_conf.ping_with_options=lp_config_get_int(lc->config,"sip","ping_with_options",1);
548 lc->sip_conf.auto_net_state_mon=lp_config_get_int(lc->config,"sip","auto_net_state_mon",1);
549 lc->sip_conf.keepalive_period=lp_config_get_int(lc->config,"sip","keepalive_period",10000);
550 sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
551 sal_use_one_matching_codec_policy(lc->sal,lp_config_get_int(lc->config,"sip","only_one_codec",0));
552 sal_use_double_registrations(lc->sal,lp_config_get_int(lc->config,"sip","use_double_registrations",1));
555 static void rtp_config_read(LinphoneCore *lc)
560 bool_t rtp_no_xmit_on_audio_mute;
562 port=lp_config_get_int(lc->config,"rtp","audio_rtp_port",7078);
563 linphone_core_set_audio_port(lc,port);
565 port=lp_config_get_int(lc->config,"rtp","video_rtp_port",9078);
566 if (port==0) port=9078;
567 linphone_core_set_video_port(lc,port);
569 jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
570 linphone_core_set_audio_jittcomp(lc,jitt_comp);
571 jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
572 if (jitt_comp==0) jitt_comp=60;
573 lc->rtp_conf.video_jitt_comp=jitt_comp;
574 nortp_timeout=lp_config_get_int(lc->config,"rtp","nortp_timeout",30);
575 linphone_core_set_nortp_timeout(lc,nortp_timeout);
576 rtp_no_xmit_on_audio_mute=lp_config_get_int(lc->config,"rtp","rtp_no_xmit_on_audio_mute",FALSE);
577 linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_no_xmit_on_audio_mute);
580 static PayloadType * find_payload(RtpProfile *prof, const char *mime_type, int clock_rate, const char *recv_fmtp){
581 PayloadType *candidate=NULL;
585 it=rtp_profile_get_payload(prof,i);
586 if (it!=NULL && strcasecmp(mime_type,it->mime_type)==0
587 && (clock_rate==it->clock_rate || clock_rate<=0) ){
588 if ( (recv_fmtp && it->recv_fmtp && strstr(recv_fmtp,it->recv_fmtp)!=NULL) ||
589 (recv_fmtp==NULL && it->recv_fmtp==NULL) ){
591 if (recv_fmtp) payload_type_set_recv_fmtp(it,recv_fmtp);
595 if (it->recv_fmtp==NULL) candidate=it;
600 if (candidate && recv_fmtp){
601 payload_type_set_recv_fmtp(candidate,recv_fmtp);
606 static bool_t get_codec(LpConfig *config, const char* type, int index, PayloadType **ret){
608 const char *mime,*fmtp;
613 snprintf(codeckey,50,"%s_%i",type,index);
614 mime=lp_config_get_string(config,codeckey,"mime",NULL);
615 if (mime==NULL || strlen(mime)==0 ) return FALSE;
617 rate=lp_config_get_int(config,codeckey,"rate",8000);
618 fmtp=lp_config_get_string(config,codeckey,"recv_fmtp",NULL);
619 enabled=lp_config_get_int(config,codeckey,"enabled",1);
620 pt=find_payload(&av_profile,mime,rate,fmtp);
621 if (pt && enabled ) pt->flags|=PAYLOAD_TYPE_ENABLED;
622 //ms_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
623 if (pt==NULL) ms_warning("Ignoring codec config %s/%i with fmtp=%s because unsupported",
624 mime,rate,fmtp ? fmtp : "");
629 static const char *codec_pref_order[]={
643 static int find_codec_rank(const char *mime){
645 for(i=0;codec_pref_order[i]!=NULL;++i){
646 if (strcasecmp(codec_pref_order[i],mime)==0)
652 static int codec_compare(const PayloadType *a, const PayloadType *b){
654 ra=find_codec_rank(a->mime_type);
655 rb=find_codec_rank(b->mime_type);
657 if (ra<rb) return -1;
661 static MSList *add_missing_codecs(SalStreamType mtype, MSList *l){
664 PayloadType *pt=rtp_profile_get_payload(&av_profile,i);
666 if (mtype==SalVideo && pt->type!=PAYLOAD_VIDEO)
668 else if (mtype==SalAudio && (pt->type!=PAYLOAD_AUDIO_PACKETIZED
669 && pt->type!=PAYLOAD_AUDIO_CONTINUOUS)){
672 if (pt && ms_filter_codec_supported(pt->mime_type)){
673 if (ms_list_find(l,pt)==NULL){
674 /*do not enable old or experimental codecs by default*/
675 if (strcasecmp(pt->mime_type,"H263")!=0 && strcasecmp(pt->mime_type,"x-snow")!=0){
676 payload_type_set_flag(pt,PAYLOAD_TYPE_ENABLED);
678 ms_message("Adding new codec %s/%i with fmtp %s",
679 pt->mime_type,pt->clock_rate,pt->recv_fmtp ? pt->recv_fmtp : "");
680 l=ms_list_insert_sorted(l,pt,(int (*)(const void *, const void *))codec_compare);
688 static MSList *codec_append_if_new(MSList *l, PayloadType *pt){
690 for (elem=l;elem!=NULL;elem=elem->next){
691 PayloadType *ept=(PayloadType*)elem->data;
695 l=ms_list_append(l,pt);
699 static void codecs_config_read(LinphoneCore *lc)
703 MSList *audio_codecs=NULL;
704 MSList *video_codecs=NULL;
705 for (i=0;get_codec(lc->config,"audio_codec",i,&pt);i++){
707 if (!ms_filter_codec_supported(pt->mime_type)){
708 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
709 }else audio_codecs=codec_append_if_new(audio_codecs,pt);
712 audio_codecs=add_missing_codecs(SalAudio,audio_codecs);
713 for (i=0;get_codec(lc->config,"video_codec",i,&pt);i++){
715 if (!ms_filter_codec_supported(pt->mime_type)){
716 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
717 }else video_codecs=codec_append_if_new(video_codecs,(void *)pt);
720 video_codecs=add_missing_codecs(SalVideo,video_codecs);
721 linphone_core_set_audio_codecs(lc,audio_codecs);
722 linphone_core_set_video_codecs(lc,video_codecs);
723 linphone_core_update_allocated_audio_bandwidth(lc);
726 static void video_config_read(LinphoneCore *lc){
727 int capture, display, self_view;
730 const char **devices;
734 /* retrieve all video devices */
735 elem=ms_web_cam_manager_get_list(ms_web_cam_manager_get());
736 ndev=ms_list_size(elem);
737 devices=ms_malloc((ndev+1)*sizeof(const char *));
738 for (i=0;elem!=NULL;elem=elem->next,i++){
739 devices[i]=ms_web_cam_get_string_id((MSWebCam *)elem->data);
742 lc->video_conf.cams=devices;
744 str=lp_config_get_string(lc->config,"video","device",NULL);
745 if (str && str[0]==0) str=NULL;
746 linphone_core_set_video_device(lc,str);
748 linphone_core_set_preferred_video_size_by_name(lc,
749 lp_config_get_string(lc->config,"video","size","cif"));
751 capture=lp_config_get_int(lc->config,"video","capture",1);
752 display=lp_config_get_int(lc->config,"video","display",1);
753 self_view=lp_config_get_int(lc->config,"video","self_view",1);
754 lc->video_conf.displaytype=lp_config_get_string(lc->config,"video","displaytype",NULL);
755 if(lc->video_conf.displaytype)
756 ms_message("we are using a specific display:%s\n",lc->video_conf.displaytype);
758 linphone_core_enable_video(lc,capture,display);
759 linphone_core_enable_self_view(lc,self_view);
763 static void ui_config_read(LinphoneCore *lc)
767 for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
768 linphone_core_add_friend(lc,lf);
770 call_logs_read_from_config_file(lc);
774 static void autoreplier_config_init(LinphoneCore *lc)
776 autoreplier_config_t *config=&lc->autoreplier_conf;
777 config->enabled=lp_config_get_int(lc->config,"autoreplier","enabled",0);
778 config->after_seconds=lp_config_get_int(lc->config,"autoreplier","after_seconds",6);
779 config->max_users=lp_config_get_int(lc->config,"autoreplier","max_users",1);
780 config->max_rec_time=lp_config_get_int(lc->config,"autoreplier","max_rec_time",60);
781 config->max_rec_msg=lp_config_get_int(lc->config,"autoreplier","max_rec_msg",10);
782 config->message=lp_config_get_string(lc->config,"autoreplier","message",NULL);
787 * Enable adaptive rate control (experimental feature, audio-only).
789 * Adaptive rate control consists in using RTCP feedback provided information to dynamically
790 * control the output bitrate of the encoders, so that we can adapt to the network conditions and
791 * available bandwidth.
793 void linphone_core_enable_adaptive_rate_control(LinphoneCore *lc, bool_t enabled){
794 lp_config_set_int(lc->config,"net","adaptive_rate_control",(int)enabled);
798 * Returns whether adaptive rate control is enabled.
800 * See linphone_core_enable_adaptive_rate_control().
802 bool_t linphone_core_adaptive_rate_control_enabled(const LinphoneCore *lc){
803 return lp_config_get_int(lc->config,"net","adaptive_rate_control",FALSE);
807 * Sets maximum available download bandwidth
809 * @ingroup media_parameters
811 * This is IP bandwidth, in kbit/s.
812 * This information is used signaled to other parties during
813 * calls (within SDP messages) so that the remote end can have
814 * sufficient knowledge to properly configure its audio & video
815 * codec output bitrate to not overflow available bandwidth.
817 * @param lc the LinphoneCore object
818 * @param bw the bandwidth in kbits/s, 0 for infinite
820 void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
821 lc->net_conf.download_bw=bw;
825 * Sets maximum available upload bandwidth
827 * @ingroup media_parameters
829 * This is IP bandwidth, in kbit/s.
830 * This information is used by liblinphone together with remote
831 * side available bandwidth signaled in SDP messages to properly
832 * configure audio & video codec's output bitrate.
834 * @param lc the LinphoneCore object
835 * @param bw the bandwidth in kbits/s, 0 for infinite
837 void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
838 lc->net_conf.upload_bw=bw;
842 * Retrieve the maximum available download bandwidth.
844 * @ingroup media_parameters
846 * This value was set by linphone_core_set_download_bandwidth().
849 int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
850 return lc->net_conf.download_bw;
854 * Retrieve the maximum available upload bandwidth.
856 * @ingroup media_parameters
858 * This value was set by linphone_core_set_upload_bandwidth().
861 int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
862 return lc->net_conf.upload_bw;
865 * Set audio packetization time linphone expects to receive from peer
867 void linphone_core_set_download_ptime(LinphoneCore *lc, int ptime) {
868 lc->net_conf.down_ptime=ptime;
872 * Get audio packetization time linphone expects to receive from peer
874 int linphone_core_get_download_ptime(LinphoneCore *lc) {
875 return lc->net_conf.down_ptime;
879 * Set audio packetization time linphone will send (in absence of requirement from peer)
880 * A value of 0 stands for the current codec default packetization time.
883 void linphone_core_set_upload_ptime(LinphoneCore *lc, int ptime){
884 lp_config_set_int(lc->config,"rtp","up_ptime",ptime);
888 * Set audio packetization time linphone will send (in absence of requirement from peer)
889 * A value of 0 stands for the current codec default packetization time.
892 int linphone_core_get_upload_ptime(LinphoneCore *lc){
893 return lp_config_get_int(lc->config,"rtp","up_ptime",0);
899 * Returns liblinphone's version as a string.
904 const char * linphone_core_get_version(void){
905 return liblinphone_version;
909 static MSList *linphone_payload_types=NULL;
911 static void linphone_core_assign_payload_type(PayloadType *const_pt, int number, const char *recv_fmtp){
913 pt=payload_type_clone(const_pt);
914 payload_type_set_number(pt,number);
915 if (recv_fmtp!=NULL) payload_type_set_recv_fmtp(pt,recv_fmtp);
916 rtp_profile_set_payload(&av_profile,number,pt);
917 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
920 static void linphone_core_free_payload_types(void){
921 ms_list_for_each(linphone_payload_types,(void (*)(void*))payload_type_destroy);
922 ms_list_free(linphone_payload_types);
923 linphone_payload_types=NULL;
926 void linphone_core_set_state(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message){
928 if (lc->vtable.global_state_changed){
929 lc->vtable.global_state_changed(lc,gstate,message);
932 static void misc_config_read (LinphoneCore *lc) {
933 LpConfig *config=lc->config;
934 lc->max_call_logs=lp_config_get_int(config,"misc","history_max_size",15);
937 static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path,
938 const char *factory_config_path, void * userdata)
940 memset (lc, 0, sizeof (LinphoneCore));
942 lc->ringstream_autorelease=TRUE;
944 memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
946 linphone_core_set_state(lc,LinphoneGlobalStartup,"Starting up");
948 linphone_core_assign_payload_type(&payload_type_pcmu8000,0,NULL);
949 linphone_core_assign_payload_type(&payload_type_gsm,3,NULL);
950 linphone_core_assign_payload_type(&payload_type_pcma8000,8,NULL);
951 linphone_core_assign_payload_type(&payload_type_lpc1015,115,NULL);
952 linphone_core_assign_payload_type(&payload_type_speex_nb,110,"vbr=on");
953 linphone_core_assign_payload_type(&payload_type_speex_wb,111,"vbr=on");
954 linphone_core_assign_payload_type(&payload_type_speex_uwb,112,"vbr=on");
955 linphone_core_assign_payload_type(&payload_type_telephone_event,101,"0-11");
956 linphone_core_assign_payload_type(&payload_type_ilbc,113,"mode=30");
957 linphone_core_assign_payload_type(&payload_type_amr,114,"octet-align=1");
959 #if defined(ANDROID) || defined (__IPHONE_OS_VERSION_MIN_REQUIRED)
960 /*shorten the DNS lookup time and send more retransmissions on mobiles:
961 - to workaround potential packet losses
962 - to avoid hanging for 30 seconds when the network doesn't work despite the phone thinks it does.
964 _linphone_core_configure_resolver();
967 #ifdef ENABLE_NONSTANDARD_GSM
970 pt=payload_type_clone(&payload_type_gsm);
971 pt->clock_rate=11025;
972 rtp_profile_set_payload(&av_profile,114,pt);
973 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
974 pt=payload_type_clone(&payload_type_gsm);
975 pt->clock_rate=22050;
976 rtp_profile_set_payload(&av_profile,115,pt);
977 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
982 linphone_core_assign_payload_type(&payload_type_h263,34,NULL);
983 linphone_core_assign_payload_type(&payload_type_theora,97,NULL);
984 linphone_core_assign_payload_type(&payload_type_h263_1998,98,"CIF=1;QCIF=1");
985 linphone_core_assign_payload_type(&payload_type_mp4v,99,"profile-level-id=3");
986 linphone_core_assign_payload_type(&payload_type_x_snow,100,NULL);
987 linphone_core_assign_payload_type(&payload_type_h264,102,"profile-level-id=428014");
988 /* due to limited space in SDP, we have to disable this h264 line which is normally no more necessary */
989 /* linphone_core_assign_payload_type(&payload_type_h264,103,"packetization-mode=1;profile-level-id=428014");*/
993 /* create a mediastreamer2 event queue and set it as global */
994 /* This allows to run event's callback in linphone_core_iterate() */
995 lc->msevq=ms_event_queue_new();
996 ms_set_global_event_queue(lc->msevq);
998 lc->config=lp_config_new(config_path);
999 if (factory_config_path)
1000 lp_config_read_file(lc->config,factory_config_path);
1003 sal_set_user_pointer(lc->sal,lc);
1004 sal_set_callbacks(lc->sal,&linphone_sal_callbacks);
1006 sip_setup_register_all();
1007 sound_config_read(lc);
1008 net_config_read(lc);
1009 rtp_config_read(lc);
1010 codecs_config_read(lc);
1011 sip_config_read(lc); /* this will start eXosip*/
1012 video_config_read(lc);
1013 //autoreplier_config_init(&lc->autoreplier_conf);
1014 lc->presence_mode=LinphoneStatusOnline;
1015 misc_config_read(lc);
1017 if (lc->vtable.display_status)
1018 lc->vtable.display_status(lc,_("Ready"));
1019 lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
1020 linphone_core_set_state(lc,LinphoneGlobalOn,"Ready");
1024 * Instanciates a LinphoneCore object.
1025 * @ingroup initializing
1027 * The LinphoneCore object is the primary handle for doing all phone actions.
1028 * It should be unique within your application.
1029 * @param vtable a LinphoneCoreVTable structure holding your application callbacks
1030 * @param config_path a path to a config file. If it does not exists it will be created.
1031 * The config file is used to store all settings, call logs, friends, proxies... so that all these settings
1032 * become persistent over the life of the LinphoneCore object.
1033 * It is allowed to set a NULL config file. In that case LinphoneCore will not store any settings.
1034 * @param factory_config_path a path to a read-only config file that can be used to
1035 * to store hard-coded preference such as proxy settings or internal preferences.
1036 * The settings in this factory file always override the one in the normal config file.
1037 * It is OPTIONAL, use NULL if unneeded.
1038 * @param userdata an opaque user pointer that can be retrieved at any time (for example in
1039 * callbacks) using linphone_core_get_user_data().
1042 LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
1043 const char *config_path, const char *factory_config_path, void * userdata)
1045 LinphoneCore *core=ms_new(LinphoneCore,1);
1046 linphone_core_init(core,vtable,config_path, factory_config_path, userdata);
1051 * Returns the list of available audio codecs.
1053 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1054 * structure holding the codec information.
1055 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1056 * (such as the order of codecs).
1058 const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
1060 return lc->codecs_conf.audio_codecs;
1064 * Returns the list of available video codecs.
1066 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1067 * structure holding the codec information.
1068 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1069 * (such as the order of codecs).
1071 const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
1073 return lc->codecs_conf.video_codecs;
1077 * Sets the local "from" identity.
1080 * This data is used in absence of any proxy configuration or when no
1081 * default proxy configuration is set. See LinphoneProxyConfig
1083 int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact)
1085 LinphoneAddress *ctt;
1087 if ((ctt=linphone_address_new(contact))==0) {
1088 ms_error("Bad contact url: %s",contact);
1091 if (lc->sip_conf.contact!=NULL) ms_free(lc->sip_conf.contact);
1092 lc->sip_conf.contact=ms_strdup(contact);
1093 if (lc->sip_conf.guessed_contact!=NULL){
1094 ms_free(lc->sip_conf.guessed_contact);
1095 lc->sip_conf.guessed_contact=NULL;
1097 linphone_address_destroy(ctt);
1102 /*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
1103 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
1105 if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress
1106 && (ip=linphone_core_get_nat_address_resolved(lc))!=NULL){
1107 strncpy(result,ip,LINPHONE_IPADDR_SIZE);
1110 if (linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,dest,result)==0)
1112 /*else fallback to SAL routine that will attempt to find the most realistic interface */
1113 sal_get_default_local_ip(lc->sal,lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,result,LINPHONE_IPADDR_SIZE);
1116 static void update_primary_contact(LinphoneCore *lc){
1118 char tmp[LINPHONE_IPADDR_SIZE];
1120 LinphoneAddress *url;
1121 if (lc->sip_conf.guessed_contact!=NULL){
1122 ms_free(lc->sip_conf.guessed_contact);
1123 lc->sip_conf.guessed_contact=NULL;
1125 url=linphone_address_new(lc->sip_conf.contact);
1127 ms_error("Could not parse identity contact !");
1128 url=linphone_address_new("sip:unknown@unkwownhost");
1130 linphone_core_get_local_ip(lc, NULL, tmp);
1131 if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
1132 ms_warning("Local loopback network only !");
1133 lc->sip_conf.loopback_only=TRUE;
1134 }else lc->sip_conf.loopback_only=FALSE;
1135 linphone_address_set_domain(url,tmp);
1136 linphone_address_set_port_int(url,linphone_core_get_sip_port (lc));
1137 guessed=linphone_address_as_string(url);
1138 lc->sip_conf.guessed_contact=guessed;
1139 linphone_address_destroy(url);
1143 * Returns the default identity when no proxy configuration is used.
1147 const char *linphone_core_get_primary_contact(LinphoneCore *lc){
1150 if (lc->sip_conf.guess_hostname){
1151 if (lc->sip_conf.guessed_contact==NULL || lc->sip_conf.loopback_only){
1152 update_primary_contact(lc);
1154 identity=lc->sip_conf.guessed_contact;
1156 identity=lc->sip_conf.contact;
1162 * Tells LinphoneCore to guess local hostname automatically in primary contact.
1166 void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
1167 lc->sip_conf.guess_hostname=val;
1171 * Returns TRUE if hostname part of primary contact is guessed automatically.
1175 bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
1176 return lc->sip_conf.guess_hostname;
1180 * Same as linphone_core_get_primary_contact() but the result is a LinphoneAddress object
1181 * instead of const char*
1185 LinphoneAddress *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
1186 return linphone_address_new(linphone_core_get_primary_contact(lc));
1190 * Sets the list of audio codecs.
1192 * @ingroup media_parameters
1193 * The list is taken by the LinphoneCore thus the application should not free it.
1194 * This list is made of struct PayloadType describing the codec parameters.
1196 int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
1198 if (lc->codecs_conf.audio_codecs!=NULL) ms_list_free(lc->codecs_conf.audio_codecs);
1199 lc->codecs_conf.audio_codecs=codecs;
1204 * Sets the list of video codecs.
1206 * @ingroup media_parameters
1207 * The list is taken by the LinphoneCore thus the application should not free it.
1208 * This list is made of struct PayloadType describing the codec parameters.
1210 int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
1212 if (lc->codecs_conf.video_codecs!=NULL) ms_list_free(lc->codecs_conf.video_codecs);
1213 lc->codecs_conf.video_codecs=codecs;
1217 const MSList * linphone_core_get_friend_list(const LinphoneCore *lc)
1223 * Returns the nominal jitter buffer size in milliseconds.
1225 * @ingroup media_parameters
1227 int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
1229 return lc->rtp_conf.audio_jitt_comp;
1233 * Returns the UDP port used for audio streaming.
1235 * @ingroup network_parameters
1237 int linphone_core_get_audio_port(const LinphoneCore *lc)
1239 return lc->rtp_conf.audio_rtp_port;
1243 * Returns the UDP port used for video streaming.
1245 * @ingroup network_parameters
1247 int linphone_core_get_video_port(const LinphoneCore *lc){
1248 return lc->rtp_conf.video_rtp_port;
1253 * Returns the value in seconds of the no-rtp timeout.
1255 * @ingroup media_parameters
1256 * When no RTP or RTCP packets have been received for a while
1257 * LinphoneCore will consider the call is broken (remote end crashed or
1258 * disconnected from the network), and thus will terminate the call.
1259 * The no-rtp timeout is the duration above which the call is considered broken.
1261 int linphone_core_get_nortp_timeout(const LinphoneCore *lc){
1262 return lc->rtp_conf.nortp_timeout;
1265 bool_t linphone_core_get_rtp_no_xmit_on_audio_mute(const LinphoneCore *lc){
1266 return lc->rtp_conf.rtp_no_xmit_on_audio_mute;
1270 * Sets the nominal audio jitter buffer size in milliseconds.
1272 * @ingroup media_parameters
1274 void linphone_core_set_audio_jittcomp(LinphoneCore *lc, int value)
1276 lc->rtp_conf.audio_jitt_comp=value;
1279 void linphone_core_set_rtp_no_xmit_on_audio_mute(LinphoneCore *lc,bool_t rtp_no_xmit_on_audio_mute){
1280 lc->rtp_conf.rtp_no_xmit_on_audio_mute=rtp_no_xmit_on_audio_mute;
1284 * Sets the UDP port used for audio streaming.
1286 * @ingroup network_parameters
1288 void linphone_core_set_audio_port(LinphoneCore *lc, int port)
1290 lc->rtp_conf.audio_rtp_port=port;
1294 * Sets the UDP port used for video streaming.
1296 * @ingroup network_parameters
1298 void linphone_core_set_video_port(LinphoneCore *lc, int port){
1299 lc->rtp_conf.video_rtp_port=port;
1303 * Sets the no-rtp timeout value in seconds.
1305 * @ingroup media_parameters
1306 * See linphone_core_get_nortp_timeout() for details.
1308 void linphone_core_set_nortp_timeout(LinphoneCore *lc, int nortp_timeout){
1309 lc->rtp_conf.nortp_timeout=nortp_timeout;
1313 * Indicates whether SIP INFO is used for sending digits.
1315 * @ingroup media_parameters
1317 bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
1319 return lc->sip_conf.use_info;
1323 * Sets whether SIP INFO is to be used for sending digits.
1325 * @ingroup media_parameters
1327 void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
1329 lc->sip_conf.use_info=use_info;
1333 * Indicates whether RFC2833 is used for sending digits.
1335 * @ingroup media_parameters
1337 bool_t linphone_core_get_use_rfc2833_for_dtmf(LinphoneCore *lc)
1339 return lc->sip_conf.use_rfc2833;
1343 * Sets whether RFC2833 is to be used for sending digits.
1345 * @ingroup media_parameters
1347 void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833)
1349 lc->sip_conf.use_rfc2833=use_rfc2833;
1353 * Returns the UDP port used by SIP.
1355 * Deprecated: use linphone_core_get_sip_transports() instead.
1356 * @ingroup network_parameters
1358 int linphone_core_get_sip_port(LinphoneCore *lc)
1360 LCSipTransports *tr=&lc->sip_conf.transports;
1361 return tr->udp_port>0 ? tr->udp_port : tr->tcp_port;
1364 static char _ua_name[64]="Linphone";
1365 static char _ua_version[64]=LINPHONE_VERSION;
1367 #ifdef HAVE_EXOSIP_GET_VERSION
1368 extern const char *eXosip_get_version();
1371 static void apply_user_agent(LinphoneCore *lc){
1372 char ua_string[256];
1373 snprintf(ua_string,sizeof(ua_string)-1,"%s/%s (eXosip2/%s)",_ua_name,_ua_version,
1374 #ifdef HAVE_EXOSIP_GET_VERSION
1375 eXosip_get_version()
1380 if (lc->sal) sal_set_user_agent(lc->sal,ua_string);
1384 * Sets the user agent string used in SIP messages.
1388 void linphone_core_set_user_agent(const char *name, const char *ver){
1389 strncpy(_ua_name,name,sizeof(_ua_name)-1);
1390 strncpy(_ua_version,ver,sizeof(_ua_version));
1393 static void transport_error(LinphoneCore *lc, const char* transport, int port){
1394 char *msg=ortp_strdup_printf("Could not start %s transport on port %i, maybe this port is already used.",transport,port);
1396 if (lc->vtable.display_warning)
1397 lc->vtable.display_warning(lc,msg);
1401 static bool_t transports_unchanged(const LCSipTransports * tr1, const LCSipTransports * tr2){
1403 tr2->udp_port==tr1->udp_port &&
1404 tr2->tcp_port==tr1->tcp_port &&
1405 tr2->dtls_port==tr1->dtls_port &&
1406 tr2->tls_port==tr1->tls_port;
1409 static int apply_transports(LinphoneCore *lc){
1411 const char *anyaddr;
1412 LCSipTransports *tr=&lc->sip_conf.transports;
1414 if (lc->sip_conf.ipv6_enabled)
1419 sal_unlisten_ports (sal);
1420 if (tr->udp_port>0){
1421 if (sal_listen_port (sal,anyaddr,tr->udp_port,SalTransportUDP,FALSE)!=0){
1422 transport_error(lc,"UDP",tr->udp_port);
1426 if (tr->tcp_port>0){
1427 if (sal_listen_port (sal,anyaddr,tr->tcp_port,SalTransportTCP,FALSE)!=0){
1428 transport_error(lc,"TCP",tr->tcp_port);
1431 apply_user_agent(lc);
1436 * Sets the ports to be used for each of transport (UDP or TCP)
1438 * A zero value port for a given transport means the transport
1441 * @ingroup network_parameters
1443 int linphone_core_set_sip_transports(LinphoneCore *lc, const LCSipTransports * tr){
1445 if (transports_unchanged(tr,&lc->sip_conf.transports))
1447 memcpy(&lc->sip_conf.transports,tr,sizeof(*tr));
1449 if (lc->sal==NULL) return 0;
1450 return apply_transports(lc);
1454 * Retrieves the ports used for each transport (udp, tcp).
1455 * A zero value port for a given transport means the transport
1457 * @ingroup network_parameters
1459 int linphone_core_get_sip_transports(LinphoneCore *lc, LCSipTransports *tr){
1460 memcpy(tr,&lc->sip_conf.transports,sizeof(*tr));
1465 * Sets the UDP port to be used by SIP.
1467 * Deprecated: use linphone_core_set_sip_transports() instead.
1468 * @ingroup network_parameters
1470 void linphone_core_set_sip_port(LinphoneCore *lc,int port)
1473 memset(&tr,0,sizeof(tr));
1475 linphone_core_set_sip_transports (lc,&tr);
1479 * Returns TRUE if IPv6 is enabled.
1481 * @ingroup network_parameters
1482 * See linphone_core_enable_ipv6() for more details on how IPv6 is supported in liblinphone.
1484 bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
1485 return lc->sip_conf.ipv6_enabled;
1489 * Turns IPv6 support on or off.
1491 * @ingroup network_parameters
1493 * @note IPv6 support is exclusive with IPv4 in liblinphone:
1494 * when IPv6 is turned on, IPv4 calls won't be possible anymore.
1495 * By default IPv6 support is off.
1497 void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
1498 if (lc->sip_conf.ipv6_enabled!=val){
1499 lc->sip_conf.ipv6_enabled=val;
1501 /* we need to restart eXosip */
1502 apply_transports(lc);
1508 static void monitor_network_state(LinphoneCore *lc, time_t curtime){
1509 static time_t last_check=0;
1510 static bool_t last_status=FALSE;
1511 char result[LINPHONE_IPADDR_SIZE];
1512 bool_t new_status=last_status;
1514 /* only do the network up checking every five seconds */
1515 if (last_check==0 || (curtime-last_check)>=5){
1516 linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,NULL,result);
1517 if (strcmp(result,"::1")!=0 && strcmp(result,"127.0.0.1")!=0){
1519 }else new_status=FALSE;
1521 if (new_status!=last_status) {
1523 ms_message("New local ip address is %s",result);
1525 set_network_reachable(lc,new_status, curtime);
1526 last_status=new_status;
1531 static void proxy_update(LinphoneCore *lc){
1532 ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
1533 MSList* list=ms_list_copy(lc->sip_conf.deleted_proxies);
1534 for(;list!=NULL;list=list->next){
1535 LinphoneProxyConfig* cfg = (LinphoneProxyConfig*) list->data;
1536 if (ms_time(NULL) - cfg->deletion_date > 5) {
1537 lc->sip_conf.deleted_proxies =ms_list_remove(lc->sip_conf.deleted_proxies,(void *)cfg);
1538 ms_message("clearing proxy config for [%s]",linphone_proxy_config_get_addr(cfg));
1539 linphone_proxy_config_destroy(cfg);
1545 static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){
1546 LinphoneFriend *lf=linphone_core_get_friend_by_address(lc,info->sip_uri);
1549 ms_message("%s has a BuddyInfo assigned with image %p",info->sip_uri, info->image_data);
1550 if (lc->vtable.buddy_info_updated)
1551 lc->vtable.buddy_info_updated(lc,lf);
1553 ms_warning("Could not any friend with uri %s",info->sip_uri);
1557 static void analyze_buddy_lookup_results(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1559 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1560 for (elem=lc->bl_reqs;elem!=NULL;elem=ms_list_next(elem)){
1561 BuddyLookupRequest *req=(BuddyLookupRequest *)elem->data;
1562 if (req->status==BuddyLookupDone || req->status==BuddyLookupFailure){
1563 if (req->results!=NULL){
1564 BuddyInfo *i=(BuddyInfo*)req->results->data;
1565 ms_list_free(req->results);
1567 assign_buddy_info(lc,i);
1569 sip_setup_context_buddy_lookup_free(ctx,req);
1573 /*purge completed requests */
1574 while((elem=ms_list_find(lc->bl_reqs,NULL))!=NULL){
1575 lc->bl_reqs=ms_list_remove_link(lc->bl_reqs,elem);
1579 static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1581 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1582 for(elem=linphone_core_get_friend_list(lc);elem!=NULL;elem=elem->next){
1583 LinphoneFriend *lf=(LinphoneFriend*)elem->data;
1584 if (lf->info==NULL){
1585 if (linphone_core_lookup_known_proxy(lc,lf->uri)==cfg){
1586 if (linphone_address_get_username(lf->uri)!=NULL){
1587 BuddyLookupRequest *req;
1588 char *tmp=linphone_address_as_string_uri_only(lf->uri);
1589 req=sip_setup_context_create_buddy_lookup_request(ctx);
1590 buddy_lookup_request_set_key(req,tmp);
1591 buddy_lookup_request_set_max_results(req,1);
1592 sip_setup_context_buddy_lookup_submit(ctx,req);
1593 lc->bl_reqs=ms_list_append(lc->bl_reqs,req);
1601 static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
1602 LinphoneProxyConfig *cfg=NULL;
1603 linphone_core_get_default_proxy(lc,&cfg);
1605 if (lc->bl_refresh){
1606 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1607 if (ctx && (sip_setup_context_get_capabilities(ctx) & SIP_SETUP_CAP_BUDDY_LOOKUP)){
1608 linphone_core_grab_buddy_infos(lc,cfg);
1609 lc->bl_refresh=FALSE;
1612 if (lc->bl_reqs) analyze_buddy_lookup_results(lc,cfg);
1617 * Main loop function. It is crucial that your application call it periodically.
1619 * @ingroup initializing
1620 * linphone_core_iterate() performs various backgrounds tasks:
1621 * - receiving of SIP messages
1622 * - handles timers and timeout
1623 * - performs registration to proxies
1624 * - authentication retries
1625 * The application MUST call this function periodically, in its main loop.
1626 * Be careful that this function must be called from the same thread as
1627 * other liblinphone methods. If it is not the case make sure all liblinphone calls are
1628 * serialized with a mutex.
1630 void linphone_core_iterate(LinphoneCore *lc){
1633 time_t curtime=time(NULL);
1635 bool_t one_second_elapsed=FALSE;
1637 if (curtime-lc->prevtime>=1){
1638 lc->prevtime=curtime;
1639 one_second_elapsed=TRUE;
1643 LinphoneEcCalibratorStatus ecs=ec_calibrator_get_status(lc->ecc);
1644 if (ecs!=LinphoneEcCalibratorInProgress){
1646 lc->ecc->cb(lc,ecs,lc->ecc->delay,lc->ecc->cb_data);
1647 if (ecs==LinphoneEcCalibratorDone){
1648 lp_config_set_int(lc->config, "sound", "ec_delay",MAX(lc->ecc->delay-10,0));
1650 ec_calibrator_destroy(lc->ecc);
1655 if (lc->preview_finished){
1656 lc->preview_finished=0;
1657 ring_stop(lc->ringstream);
1658 lc->ringstream=NULL;
1659 lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
1662 if (lc->ringstream && lc->ringstream_autorelease && lc->dmfs_playing_start_time!=0
1663 && (curtime-lc->dmfs_playing_start_time)>5){
1664 ring_stop(lc->ringstream);
1665 lc->ringstream=NULL;
1666 lc->dmfs_playing_start_time=0;
1669 sal_iterate(lc->sal);
1670 if (lc->msevq) ms_event_queue_pump(lc->msevq);
1671 if (lc->auto_net_state_mon) monitor_network_state(lc,curtime);
1675 //we have to iterate for each call
1677 while(calls!= NULL){
1678 call = (LinphoneCall *)calls->data;
1679 /* get immediately a reference to next one in case the one
1680 we are going to examine is destroy and removed during
1681 linphone_core_start_invite() */
1683 if (call->state==LinphoneCallOutgoingInit && (curtime-call->start_time>=2)){
1684 /*start the call even if the OPTIONS reply did not arrive*/
1685 linphone_core_start_invite(lc,call,NULL);
1687 if (call->dir==LinphoneCallIncoming && call->state==LinphoneCallOutgoingRinging){
1688 elapsed=curtime-call->start_time;
1689 ms_message("incoming call ringing for %i seconds",elapsed);
1690 if (elapsed>lc->sip_conf.inc_timeout){
1691 call->log->status=LinphoneCallMissed;
1692 linphone_core_terminate_call(lc,call);
1696 call = linphone_core_get_current_call(lc);
1698 linphone_call_background_tasks(call,one_second_elapsed);
1699 if (linphone_core_video_preview_enabled(lc)){
1700 if (lc->previewstream==NULL && lc->calls==NULL)
1701 toggle_video_preview(lc,TRUE);
1702 #ifdef VIDEO_ENABLED
1703 if (lc->previewstream) video_stream_iterate(lc->previewstream);
1706 if (lc->previewstream!=NULL)
1707 toggle_video_preview(lc,FALSE);
1710 linphone_core_run_hooks(lc);
1711 linphone_core_do_plugin_tasks(lc);
1713 if (lc->initial_subscribes_sent==FALSE && lc->netup_time!=0 &&
1714 (curtime-lc->netup_time)>3){
1715 linphone_core_send_initial_subscribes(lc);
1716 lc->initial_subscribes_sent=TRUE;
1719 if (one_second_elapsed && lp_config_needs_commit(lc->config)){
1720 lp_config_sync(lc->config);
1725 * Interpret a call destination as supplied by the user, and returns a fully qualified
1728 * A sip address should look like DisplayName <sip:username@domain:port> .
1729 * Basically this function performs the following tasks
1730 * - if a phone number is entered, prepend country prefix of the default proxy
1731 * configuration, eventually escape the '+' by 00.
1732 * - if no domain part is supplied, append the domain name of the default proxy
1733 * - if no sip: is present, prepend it
1735 * The result is a syntaxically correct SIP address.
1738 LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url){
1739 enum_lookup_res_t *enumres=NULL;
1740 char *enum_domain=NULL;
1741 LinphoneProxyConfig *proxy=lc->default_proxy;;
1743 LinphoneAddress *uri;
1745 if (is_enum(url,&enum_domain)){
1746 if (lc->vtable.display_status!=NULL)
1747 lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
1748 if (enum_lookup(enum_domain,&enumres)<0){
1749 if (lc->vtable.display_status!=NULL)
1750 lc->vtable.display_status(lc,_("Could not resolve this number."));
1751 ms_free(enum_domain);
1754 ms_free(enum_domain);
1755 tmpurl=enumres->sip_address[0];
1756 uri=linphone_address_new(tmpurl);
1757 enum_lookup_res_free(enumres);
1760 /* check if we have a "sip:" */
1761 if (strstr(url,"sip:")==NULL){
1762 /* this doesn't look like a true sip uri */
1763 if (strchr(url,'@')!=NULL){
1764 /* seems like sip: is missing !*/
1765 tmpurl=ms_strdup_printf("sip:%s",url);
1766 uri=linphone_address_new(tmpurl);
1774 /* append the proxy domain suffix */
1775 const char *identity=linphone_proxy_config_get_identity(proxy);
1776 char normalized_username[128];
1777 uri=linphone_address_new(identity);
1781 linphone_address_set_display_name(uri,NULL);
1782 linphone_proxy_config_normalize_number(proxy,url,normalized_username,
1783 sizeof(normalized_username));
1784 linphone_address_set_username(uri,normalized_username);
1788 uri=linphone_address_new(url);
1792 /* else we could not do anything with url given by user, so display an error */
1793 if (lc->vtable.display_warning!=NULL){
1794 lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
1800 * Returns the default identity SIP address.
1803 * This is an helper function:
1805 * If no default proxy is set, this will return the primary contact (
1806 * see linphone_core_get_primary_contact() ). If a default proxy is set
1807 * it returns the registered identity on the proxy.
1809 const char * linphone_core_get_identity(LinphoneCore *lc){
1810 LinphoneProxyConfig *proxy=NULL;
1812 linphone_core_get_default_proxy(lc,&proxy);
1814 from=linphone_proxy_config_get_identity(proxy);
1815 }else from=linphone_core_get_primary_contact(lc);
1819 const char * linphone_core_get_route(LinphoneCore *lc){
1820 LinphoneProxyConfig *proxy=NULL;
1821 const char *route=NULL;
1822 linphone_core_get_default_proxy(lc,&proxy);
1824 route=linphone_proxy_config_get_route(proxy);
1829 void linphone_core_start_refered_call(LinphoneCore *lc, LinphoneCall *call){
1830 if (call->refer_pending){
1831 LinphoneCallParams *cp=linphone_core_create_default_call_parameters(lc);
1833 ms_message("Starting new call to refered address %s",call->refer_to);
1834 call->refer_pending=FALSE;
1835 linphone_core_invite_with_params(lc,call->refer_to,cp);
1836 linphone_call_params_destroy(cp);
1840 LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
1842 LinphoneProxyConfig *found_cfg=NULL;
1843 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=elem->next){
1844 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1845 const char *domain=linphone_proxy_config_get_domain(cfg);
1846 if (domain!=NULL && strcmp(domain,linphone_address_get_domain(uri))==0){
1854 const char *linphone_core_find_best_identity(LinphoneCore *lc, const LinphoneAddress *to, const char **route){
1855 LinphoneProxyConfig *cfg=linphone_core_lookup_known_proxy(lc,to);
1857 linphone_core_get_default_proxy (lc,&cfg);
1859 if (route) *route=linphone_proxy_config_get_route(cfg);
1860 return linphone_proxy_config_get_identity (cfg);
1862 return linphone_core_get_primary_contact (lc);
1865 static char *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){
1866 LinphoneAddress *ctt;
1867 const char *localip=call->localip;
1869 /* first use user's supplied ip address if asked*/
1870 if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress){
1871 ctt=linphone_core_get_primary_contact_parsed(lc);
1872 return ms_strdup_printf("sip:%s@%s",linphone_address_get_username(ctt),
1873 linphone_core_get_nat_address_resolved(lc));
1876 /* if already choosed, don't change it */
1877 if (call->op && sal_op_get_contact(call->op)!=NULL){
1880 /* if the ping OPTIONS request succeeded use the contact guessed from the
1883 const char *guessed=sal_op_get_contact(call->ping_op);
1885 ms_message("Contact has been fixed using OPTIONS to %s",guessed);
1886 return ms_strdup(guessed);
1890 /*if using a proxy, use the contact address as guessed with the REGISTERs*/
1891 if (dest_proxy && dest_proxy->op){
1892 const char *fixed_contact=sal_op_get_contact(dest_proxy->op);
1893 if (fixed_contact) {
1894 ms_message("Contact has been fixed using proxy to %s",fixed_contact);
1895 return ms_strdup(fixed_contact);
1899 ctt=linphone_core_get_primary_contact_parsed(lc);
1903 /*otherwise use supllied localip*/
1904 linphone_address_set_domain(ctt,localip);
1905 linphone_address_set_port_int(ctt,linphone_core_get_sip_port(lc));
1906 ret=linphone_address_as_string_uri_only(ctt);
1907 linphone_address_destroy(ctt);
1908 ms_message("Contact has been fixed using local ip to %s",ret);
1914 int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphoneProxyConfig *dest_proxy){
1917 char *real_url,*barmsg;
1920 /*try to be best-effort in giving real local or routable contact address */
1921 contact=get_fixed_contact(lc,call,dest_proxy);
1923 sal_op_set_contact(call->op, contact);
1927 //TODO : should probably not be done here
1928 linphone_call_init_media_streams(call);
1929 if (!lc->sip_conf.sdp_200_ack){
1930 call->media_pending=TRUE;
1931 sal_call_set_local_media_description(call->op,call->localdesc);
1933 real_url=linphone_address_as_string(call->log->to);
1934 from=linphone_address_as_string(call->log->from);
1935 err=sal_call(call->op,from,real_url);
1937 if (lc->sip_conf.sdp_200_ack){
1938 call->media_pending=TRUE;
1939 sal_call_set_local_media_description(call->op,call->localdesc);
1941 barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
1942 if (lc->vtable.display_status!=NULL)
1943 lc->vtable.display_status(lc,barmsg);
1947 if (lc->vtable.display_status!=NULL)
1948 lc->vtable.display_status(lc,_("Could not call"));
1949 linphone_call_stop_media_streams(call);
1950 linphone_call_set_state(call,LinphoneCallError,"Call failed");
1952 linphone_call_set_state(call,LinphoneCallOutgoingProgress,"Outgoing call in progress");
1960 * Initiates an outgoing call
1962 * @ingroup call_control
1963 * @param lc the LinphoneCore object
1964 * @param url the destination of the call (sip address, or phone number).
1966 * The application doesn't own a reference to the returned LinphoneCall object.
1967 * Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
1969 * @return a LinphoneCall object or NULL in case of failure
1971 LinphoneCall * linphone_core_invite(LinphoneCore *lc, const char *url){
1973 LinphoneCallParams *p=linphone_core_create_default_call_parameters (lc);
1974 call=linphone_core_invite_with_params(lc,url,p);
1975 linphone_call_params_destroy(p);
1981 * Initiates an outgoing call according to supplied call parameters
1983 * @ingroup call_control
1984 * @param lc the LinphoneCore object
1985 * @param url the destination of the call (sip address, or phone number).
1986 * @param p call parameters
1988 * The application doesn't own a reference to the returned LinphoneCall object.
1989 * Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
1991 * @return a LinphoneCall object or NULL in case of failure
1993 LinphoneCall * linphone_core_invite_with_params(LinphoneCore *lc, const char *url, const LinphoneCallParams *p){
1994 LinphoneAddress *addr=linphone_core_interpret_url(lc,url);
1997 call=linphone_core_invite_address_with_params(lc,addr,p);
1998 linphone_address_destroy(addr);
2005 * Initiates an outgoing call given a destination LinphoneAddress
2007 * @ingroup call_control
2008 * @param lc the LinphoneCore object
2009 * @param addr the destination of the call (sip address).
2011 * The LinphoneAddress can be constructed directly using linphone_address_new(), or
2012 * created by linphone_core_interpret_url().
2013 * The application doesn't own a reference to the returned LinphoneCall object.
2014 * Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
2016 * @return a LinphoneCall object or NULL in case of failure
2018 LinphoneCall * linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *addr){
2020 LinphoneCallParams *p=linphone_core_create_default_call_parameters (lc);
2021 call=linphone_core_invite_address_with_params (lc,addr,p);
2022 linphone_call_params_destroy(p);
2028 * Initiates an outgoing call given a destination LinphoneAddress
2030 * @ingroup call_control
2031 * @param lc the LinphoneCore object
2032 * @param addr the destination of the call (sip address).
2033 @param params call parameters
2035 * The LinphoneAddress can be constructed directly using linphone_address_new(), or
2036 * created by linphone_core_interpret_url().
2037 * The application doesn't own a reference to the returned LinphoneCall object.
2038 * Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
2040 * @return a LinphoneCall object or NULL in case of failure
2042 LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const LinphoneAddress *addr, const LinphoneCallParams *params)
2044 const char *route=NULL;
2045 const char *from=NULL;
2046 LinphoneProxyConfig *proxy=NULL;
2047 LinphoneAddress *parsed_url2=NULL;
2048 char *real_url=NULL;
2049 LinphoneProxyConfig *dest_proxy=NULL;
2052 if (linphone_core_in_call(lc)){
2053 if (lc->vtable.display_warning)
2054 lc->vtable.display_warning(lc,_("Sorry, you have to pause or stop the current call first !"));
2057 if(!linphone_core_can_we_add_call(lc)){
2058 if (lc->vtable.display_warning)
2059 lc->vtable.display_warning(lc,_("Sorry, we have reached the maximum number of simultaneous calls"));
2062 linphone_core_get_default_proxy(lc,&proxy);
2063 route=linphone_core_get_route(lc);
2065 real_url=linphone_address_as_string(addr);
2066 dest_proxy=linphone_core_lookup_known_proxy(lc,addr);
2068 if (proxy!=dest_proxy && dest_proxy!=NULL) {
2069 ms_message("Overriding default proxy setting for this call:");
2070 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
2073 if (dest_proxy!=NULL)
2074 from=linphone_proxy_config_get_identity(dest_proxy);
2075 else if (proxy!=NULL)
2076 from=linphone_proxy_config_get_identity(proxy);
2078 /* if no proxy or no identity defined for this proxy, default to primary contact*/
2079 if (from==NULL) from=linphone_core_get_primary_contact(lc);
2081 parsed_url2=linphone_address_new(from);
2083 call=linphone_call_new_outgoing(lc,parsed_url2,linphone_address_clone(addr),params);
2084 sal_op_set_route(call->op,route);
2086 if(linphone_core_add_call(lc,call)!= 0)
2088 ms_warning("we had a problem in adding the call into the invite ... weird");
2089 linphone_call_unref(call);
2092 /* this call becomes now the current one*/
2093 lc->current_call=call;
2094 linphone_call_set_state (call,LinphoneCallOutgoingInit,"Starting outgoing call");
2095 if (dest_proxy!=NULL || lc->sip_conf.ping_with_options==FALSE){
2096 linphone_core_start_invite(lc,call,dest_proxy);
2098 /*defer the start of the call after the OPTIONS ping*/
2099 call->ping_op=sal_op_new(lc->sal);
2100 sal_ping(call->ping_op,from,real_url);
2101 sal_op_set_user_pointer(call->ping_op,call);
2102 call->start_time=time(NULL);
2105 if (real_url!=NULL) ms_free(real_url);
2110 * Performs a simple call transfer to the specified destination.
2112 * The remote endpoint is expected to issue a new call to the specified destination.
2113 * The current call remains active and thus can be later paused or terminated.
2115 int linphone_core_transfer_call(LinphoneCore *lc, LinphoneCall *call, const char *url)
2117 char *real_url=NULL;
2118 LinphoneAddress *real_parsed_url=linphone_core_interpret_url(lc,url);
2120 if (!real_parsed_url){
2125 ms_warning("No established call to refer.");
2128 //lc->call=NULL; //Do not do that you will lose the call afterward . . .
2129 real_url=linphone_address_as_string (real_parsed_url);
2130 sal_call_refer(call->op,real_url);
2132 linphone_address_destroy(real_parsed_url);
2137 * Transfer a call to destination of another running call. This is used for "attended transfer" scenarios.
2138 * @param lc linphone core object
2139 * @param call a running call you want to transfer
2140 * @param dest a running call whose remote person will receive the transfer
2142 * The transfered call is supposed to be in paused state, so that it is able to accept the transfer immediately.
2143 * The destination call is a call previously established to introduce the transfered person.
2144 * This method will send a transfer request to the transfered person. The phone of the transfered is then
2145 * expected to automatically call to the destination of the transfer. The receiver of the transfer will then automatically
2146 * close the call with us (the 'dest' call).
2148 int linphone_core_transfer_call_to_another(LinphoneCore *lc, LinphoneCall *call, LinphoneCall *dest){
2149 return sal_call_refer_with_replaces (call->op,dest->op);
2152 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
2153 LinphoneCall *call = linphone_core_get_current_call(lc);
2156 if(call->dir==LinphoneCallIncoming
2157 && (call->state == LinphoneCallIncomingReceived || call->state == LinphoneCallIncomingEarlyMedia))
2164 * Updates a running call according to supplied call parameters or parameters changed in the LinphoneCore.
2166 * In this version this is limited to the following use cases:
2167 * - setting up/down the video stream according to the video parameter of the LinphoneCallParams (see linphone_call_params_enable_video() ).
2168 * - changing the size of the transmitted video after calling linphone_core_set_preferred_video_size()
2170 * In case no changes are requested through the LinphoneCallParams argument, then this argument can be ommitted and set to NULL.
2172 * @return 0 if successful, -1 otherwise.
2174 int linphone_core_update_call(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallParams *params){
2177 call->params=*params;
2178 update_local_media_description(lc,call,&call->localdesc);
2179 call->camera_active=params->has_video;
2180 if (lc->vtable.display_status)
2181 lc->vtable.display_status(lc,_("Modifying call parameters..."));
2182 sal_call_set_local_media_description (call->op,call->localdesc);
2183 err=sal_call_update(call->op,"Media parameters update");
2185 #ifdef VIDEO_ENABLED
2186 if (call->videostream!=NULL){
2187 video_stream_set_sent_video_size(call->videostream,linphone_core_get_preferred_video_size(lc));
2188 video_stream_update_video_params (call->videostream);
2198 * Accept an incoming call.
2200 * @ingroup call_control
2201 * Basically the application is notified of incoming calls within the
2202 * call_state_changed callback of the #LinphoneCoreVTable structure, where it will receive
2203 * a LinphoneCallIncoming event with the associated LinphoneCall object.
2204 * The application can later accept the call using
2206 * @param lc the LinphoneCore object
2207 * @param call the LinphoneCall object representing the call to be answered.
2210 int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call)
2212 LinphoneProxyConfig *cfg=NULL,*dest_proxy=NULL;
2213 const char *contact=NULL;
2215 SalMediaDescription *new_md;
2218 //if just one call is present answer the only one ...
2219 if(linphone_core_get_calls_nb (lc) != 1)
2222 call = (LinphoneCall*)linphone_core_get_calls(lc)->data;
2225 if (call->state==LinphoneCallConnected){
2226 /*call already accepted*/
2230 /* check if this call is supposed to replace an already running one*/
2231 replaced=sal_call_get_replaces(call->op);
2233 LinphoneCall *rc=(LinphoneCall*)sal_op_get_user_pointer (replaced);
2235 ms_message("Call %p replaces call %p. This last one is going to be terminated automatically.",
2237 linphone_core_terminate_call (lc,rc);
2241 if (lc->current_call!=NULL && lc->current_call!=call){
2242 ms_warning("Cannot accept this call, there is already one running.");
2246 /*can accept a new call only if others are on hold */
2249 for(elem=lc->calls;elem!=NULL;elem=elem->next){
2250 LinphoneCall *c=(LinphoneCall*)elem->data;
2251 if (c!=call && (c->state!=LinphoneCallPaused && c->state!=LinphoneCallPausing)){
2252 ms_warning("Cannot accept this call as another one is running, pause it before.");
2259 if (lc->ringstream!=NULL) {
2260 ms_message("stop ringing");
2261 ring_stop(lc->ringstream);
2262 ms_message("ring stopped");
2263 lc->ringstream=NULL;
2266 linphone_core_get_default_proxy(lc,&cfg);
2268 dest_proxy=linphone_core_lookup_known_proxy(lc,call->log->to);
2270 if (cfg!=dest_proxy && dest_proxy!=NULL) {
2271 ms_message("Overriding default proxy setting for this call:");
2272 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
2274 /*try to be best-effort in giving real local or routable contact address*/
2275 contact=get_fixed_contact(lc,call,dest_proxy);
2277 sal_op_set_contact(call->op,contact);
2279 if (call->audiostream==NULL)
2280 linphone_call_init_media_streams(call);
2282 sal_call_accept(call->op);
2283 if (lc->vtable.display_status!=NULL)
2284 lc->vtable.display_status(lc,_("Connected."));
2285 lc->current_call=call;
2286 linphone_call_set_state(call,LinphoneCallConnected,"Connected");
2287 new_md=sal_call_get_final_media_description(call->op);
2288 linphone_core_update_streams(lc, call, new_md);
2290 linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
2291 }else call->media_pending=TRUE;
2293 ms_message("call answered.");
2297 int linphone_core_abort_call(LinphoneCore *lc, LinphoneCall *call, const char *error){
2298 sal_call_terminate(call->op);
2301 if (lc->ringstream!=NULL) {
2302 ring_stop(lc->ringstream);
2303 lc->ringstream=NULL;
2305 linphone_call_stop_media_streams(call);
2306 if (lc->vtable.display_status!=NULL)
2307 lc->vtable.display_status(lc,_("Call aborted") );
2308 linphone_call_set_state(call,LinphoneCallError,error);
2312 static void terminate_call(LinphoneCore *lc, LinphoneCall *call){
2313 if (call->state==LinphoneCallIncomingReceived){
2314 call->reason=LinphoneReasonDeclined;
2317 if (lc->ringstream!=NULL) {
2318 ring_stop(lc->ringstream);
2319 lc->ringstream=NULL;
2321 linphone_call_stop_media_streams(call);
2322 if (lc->vtable.display_status!=NULL)
2323 lc->vtable.display_status(lc,_("Call ended") );
2326 int linphone_core_redirect_call(LinphoneCore *lc, LinphoneCall *call, const char *redirect_uri){
2327 if (call->state==LinphoneCallIncomingReceived){
2328 sal_call_decline(call->op,SalReasonRedirect,redirect_uri);
2329 call->reason=LinphoneReasonDeclined;
2330 terminate_call(lc,call);
2331 linphone_call_set_state(call,LinphoneCallEnd,"Call terminated");
2333 ms_error("Bad state for call redirection.");
2341 * Terminates a call.
2343 * @ingroup call_control
2344 * @param lc the LinphoneCore
2345 * @param the_call the LinphoneCall object representing the call to be terminated.
2347 int linphone_core_terminate_call(LinphoneCore *lc, LinphoneCall *the_call)
2350 if (the_call == NULL){
2351 call = linphone_core_get_current_call(lc);
2352 if (ms_list_size(lc->calls)==1){
2353 call=(LinphoneCall*)lc->calls->data;
2355 ms_warning("No unique call to terminate !");
2363 sal_call_terminate(call->op);
2364 terminate_call(lc,call);
2366 linphone_call_set_state(call,LinphoneCallEnd,"Call terminated");
2371 * Terminates all the calls.
2373 * @ingroup call_control
2374 * @param lc The LinphoneCore
2376 int linphone_core_terminate_all_calls(LinphoneCore *lc){
2379 LinphoneCall *the_call = lc->calls->data;
2380 linphone_core_terminate_call(lc,the_call);
2382 ms_list_free(lc->calls);
2387 * Returns the current list of calls.
2389 * Note that this list is read-only and might be changed by the core after a function call to linphone_core_iterate().
2390 * Similarly the LinphoneCall objects inside it might be destroyed without prior notice.
2391 * To hold references to LinphoneCall object into your program, you must use linphone_call_ref().
2393 * @ingroup call_control
2395 const MSList *linphone_core_get_calls(LinphoneCore *lc)
2401 * Returns TRUE if there is a call running.
2403 * @ingroup call_control
2405 bool_t linphone_core_in_call(const LinphoneCore *lc){
2406 return linphone_core_get_current_call((LinphoneCore *)lc)!=NULL;
2410 * Returns The _LinphoneCall struct of the current call if one is in call
2412 * @ingroup call_control
2414 LinphoneCall *linphone_core_get_current_call(const LinphoneCore *lc)
2416 return lc->current_call;
2420 * Pauses the call. If a music file has been setup using linphone_core_set_play_file(),
2421 * this file will be played to the remote user.
2423 * @ingroup call_control
2425 int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *the_call)
2427 LinphoneCall *call = the_call;
2428 const char *subject=NULL;
2430 if (call->state!=LinphoneCallStreamsRunning && call->state!=LinphoneCallPausedByRemote){
2431 ms_warning("Cannot pause this call, it is not active.");
2434 if (sal_media_description_has_dir(call->resultdesc,SalStreamSendRecv)){
2435 sal_media_description_set_dir(call->localdesc,SalStreamSendOnly);
2436 subject="Call on hold";
2437 }else if (sal_media_description_has_dir(call->resultdesc,SalStreamRecvOnly)){
2438 sal_media_description_set_dir(call->localdesc,SalStreamSendOnly);
2439 subject="Call on hold for me too";
2441 ms_error("No reason to pause this call, it is already paused or inactive.");
2444 if (sal_call_update(call->op,subject) != 0)
2446 if (lc->vtable.display_warning)
2447 lc->vtable.display_warning(lc,_("Could not pause the call"));
2449 linphone_call_set_state(call,LinphoneCallPausing,"Pausing call");
2450 if (lc->vtable.display_status)
2451 lc->vtable.display_status(lc,_("Pausing the current call..."));
2452 lc->current_call=NULL;
2453 if (call->audiostream || call->videostream)
2454 linphone_call_stop_media_streams (call);
2459 * Pause all currently running calls.
2461 int linphone_core_pause_all_calls(LinphoneCore *lc){
2463 for(elem=lc->calls;elem!=NULL;elem=elem->next){
2464 LinphoneCall *call=(LinphoneCall *)elem->data;
2465 LinphoneCallState cs=linphone_call_get_state(call);
2466 if (cs==LinphoneCallStreamsRunning || cs==LinphoneCallPausedByRemote){
2467 linphone_core_pause_call(lc,call);
2476 * @ingroup call_control
2478 int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call)
2481 LinphoneCall *call = the_call;
2483 if(call->state!=LinphoneCallPaused ){
2484 ms_warning("we cannot resume a call that has not been established and paused before");
2487 if(linphone_core_get_current_call(lc) != NULL){
2488 ms_warning("There is already a call in process, pause or stop it first.");
2489 if (lc->vtable.display_warning)
2490 lc->vtable.display_warning(lc,_("There is already a call in process, pause or stop it first."));
2493 ms_message("Resuming call %p",call);
2494 sal_media_description_set_dir(call->localdesc,SalStreamSendRecv);
2495 if(sal_call_update(call->op,"Call resuming") != 0){
2498 linphone_call_set_state (call,LinphoneCallResuming,"Resuming");
2499 snprintf(temp,sizeof(temp)-1,"Resuming the call with %s",linphone_call_get_remote_address_as_string(call));
2500 if (lc->vtable.display_status)
2501 lc->vtable.display_status(lc,temp);
2505 static int remote_address_compare(LinphoneCall *call, const LinphoneAddress *raddr){
2506 const LinphoneAddress *addr=linphone_call_get_remote_address (call);
2507 return !linphone_address_weak_equal (addr,raddr);
2511 * Get the call with the remote_address specified
2513 * @param remote_address
2514 * @return the LinphoneCall of the call if found
2516 LinphoneCall *linphone_core_get_call_by_remote_address(LinphoneCore *lc, const char *remote_address){
2517 LinphoneAddress *raddr=linphone_address_new(remote_address);
2518 MSList *elem=ms_list_find_custom(lc->calls,(int (*)(const void*,const void *))remote_address_compare,raddr);
2519 if (elem) return (LinphoneCall*) elem->data;
2523 int linphone_core_send_publish(LinphoneCore *lc,
2524 LinphoneOnlineStatus presence_mode)
2527 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=ms_list_next(elem)){
2528 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2529 if (cfg->publish) linphone_proxy_config_send_publish(cfg,presence_mode);
2535 * Set the incoming call timeout in seconds.
2537 * @ingroup call_control
2538 * If an incoming call isn't answered for this timeout period, it is
2539 * automatically declined.
2541 void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
2542 lc->sip_conf.inc_timeout=seconds;
2546 * Returns the incoming call timeout
2548 * @ingroup call_control
2549 * See linphone_core_set_inc_timeout() for details.
2551 int linphone_core_get_inc_timeout(LinphoneCore *lc){
2552 return lc->sip_conf.inc_timeout;
2555 void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
2556 const char *contact,
2557 LinphoneOnlineStatus presence_mode)
2559 if (minutes_away>0) lc->minutes_away=minutes_away;
2561 if (lc->alt_contact!=NULL) {
2562 ms_free(lc->alt_contact);
2563 lc->alt_contact=NULL;
2565 if (contact) lc->alt_contact=ms_strdup(contact);
2566 if (lc->presence_mode!=presence_mode){
2567 linphone_core_notify_all_friends(lc,presence_mode);
2569 Improve the use of all LINPHONE_STATUS available.
2570 !TODO Do not mix "presence status" with "answer status code"..
2571 Use correct parameter to follow sip_if_match/sip_etag.
2573 linphone_core_send_publish(lc,presence_mode);
2575 lc->presence_mode=presence_mode;
2578 LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
2579 return lc->presence_mode;
2583 * Get playback sound level in 0-100 scale.
2585 * @ingroup media_parameters
2587 int linphone_core_get_play_level(LinphoneCore *lc)
2589 return lc->sound_conf.play_lev;
2593 * Get ring sound level in 0-100 scale
2595 * @ingroup media_parameters
2597 int linphone_core_get_ring_level(LinphoneCore *lc)
2599 return lc->sound_conf.ring_lev;
2603 * Get sound capture level in 0-100 scale
2605 * @ingroup media_parameters
2607 int linphone_core_get_rec_level(LinphoneCore *lc){
2608 return lc->sound_conf.rec_lev;
2612 * Set sound ring level in 0-100 scale
2614 * @ingroup media_parameters
2616 void linphone_core_set_ring_level(LinphoneCore *lc, int level){
2618 lc->sound_conf.ring_lev=level;
2619 sndcard=lc->sound_conf.ring_sndcard;
2620 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2624 * Allow to control play level before entering sound card: gain in db
2626 * @ingroup media_parameters
2628 void linphone_core_set_playback_gain_db (LinphoneCore *lc, float gaindb){
2630 LinphoneCall *call=linphone_core_get_current_call (lc);
2633 lc->sound_conf.soft_play_lev=gaindb;
2635 if (call==NULL || (st=call->audiostream)==NULL){
2636 ms_message("linphone_core_set_playback_gain_db(): no active call.");
2640 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_DB_GAIN,&gain);
2641 }else ms_warning("Could not apply gain: gain control wasn't activated.");
2645 * Get playback gain in db before entering sound card.
2647 * @ingroup media_parameters
2649 float linphone_core_get_playback_gain_db(LinphoneCore *lc) {
2650 return lc->sound_conf.soft_play_lev;
2654 * Set sound playback level in 0-100 scale
2656 * @ingroup media_parameters
2658 void linphone_core_set_play_level(LinphoneCore *lc, int level){
2660 lc->sound_conf.play_lev=level;
2661 sndcard=lc->sound_conf.play_sndcard;
2662 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2666 * Set sound capture level in 0-100 scale
2668 * @ingroup media_parameters
2670 void linphone_core_set_rec_level(LinphoneCore *lc, int level)
2673 lc->sound_conf.rec_lev=level;
2674 sndcard=lc->sound_conf.capt_sndcard;
2675 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_CAPTURE,level);
2678 static MSSndCard *get_card_from_string_id(const char *devid, unsigned int cap){
2679 MSSndCard *sndcard=NULL;
2681 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2682 if (sndcard!=NULL &&
2683 (ms_snd_card_get_capabilities(sndcard) & cap)==0 ){
2684 ms_warning("%s card does not have the %s capability, ignoring.",
2686 cap==MS_SND_CARD_CAP_CAPTURE ? "capture" : "playback");
2690 if (sndcard==NULL) {
2691 /* get a card that has read+write capabilities */
2692 sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
2693 /* otherwise refine to the first card having the right capability*/
2695 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2696 for(;elem!=NULL;elem=elem->next){
2697 sndcard=(MSSndCard*)elem->data;
2698 if (ms_snd_card_get_capabilities(sndcard) & cap) break;
2701 if (sndcard==NULL){/*looks like a bug! take the first one !*/
2702 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2703 if (elem) sndcard=(MSSndCard*)elem->data;
2706 if (sndcard==NULL) ms_error("Could not find a suitable soundcard !");
2711 * Returns true if the specified sound device can capture sound.
2713 * @ingroup media_parameters
2714 * @param lc The LinphoneCore object
2715 * @param devid the device name as returned by linphone_core_get_sound_devices()
2717 bool_t linphone_core_sound_device_can_capture(LinphoneCore *lc, const char *devid){
2719 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2720 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_CAPTURE)) return TRUE;
2725 * Returns true if the specified sound device can play sound.
2727 * @ingroup media_parameters
2728 * @param lc The LinphoneCore object
2729 * @param devid the device name as returned by linphone_core_get_sound_devices()
2731 bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *devid){
2733 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2734 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_PLAYBACK)) return TRUE;
2739 * Sets the sound device used for ringing.
2741 * @ingroup media_parameters
2742 * @param lc The LinphoneCore object
2743 * @param devid the device name as returned by linphone_core_get_sound_devices()
2745 int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
2746 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2747 lc->sound_conf.ring_sndcard=card;
2748 if (card && linphone_core_ready(lc))
2749 lp_config_set_string(lc->config,"sound","ringer_dev_id",ms_snd_card_get_string_id(card));
2754 * Sets the sound device used for playback.
2756 * @ingroup media_parameters
2757 * @param lc The LinphoneCore object
2758 * @param devid the device name as returned by linphone_core_get_sound_devices()
2760 int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
2761 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2762 lc->sound_conf.play_sndcard=card;
2763 if (card && linphone_core_ready(lc))
2764 lp_config_set_string(lc->config,"sound","playback_dev_id",ms_snd_card_get_string_id(card));
2769 * Sets the sound device used for capture.
2771 * @ingroup media_parameters
2772 * @param lc The LinphoneCore object
2773 * @param devid the device name as returned by linphone_core_get_sound_devices()
2775 int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
2776 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_CAPTURE);
2777 lc->sound_conf.capt_sndcard=card;
2778 if (card && linphone_core_ready(lc))
2779 lp_config_set_string(lc->config,"sound","capture_dev_id",ms_snd_card_get_string_id(card));
2784 * Returns the name of the currently assigned sound device for ringing.
2786 * @ingroup media_parameters
2787 * @param lc The LinphoneCore object
2789 const char * linphone_core_get_ringer_device(LinphoneCore *lc)
2791 if (lc->sound_conf.ring_sndcard) return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
2796 * Returns the name of the currently assigned sound device for playback.
2798 * @ingroup media_parameters
2799 * @param lc The LinphoneCore object
2801 const char * linphone_core_get_playback_device(LinphoneCore *lc)
2803 return lc->sound_conf.play_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.play_sndcard) : NULL;
2807 * Returns the name of the currently assigned sound device for capture.
2809 * @ingroup media_parameters
2810 * @param lc The LinphoneCore object
2812 const char * linphone_core_get_capture_device(LinphoneCore *lc)
2814 return lc->sound_conf.capt_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard) : NULL;
2818 * Returns an unmodifiable array of available sound devices.
2820 * The array is NULL terminated.
2822 * @ingroup media_parameters
2823 * @param lc The LinphoneCore object
2825 const char** linphone_core_get_sound_devices(LinphoneCore *lc){
2826 build_sound_devices_table(lc);
2827 return lc->sound_conf.cards;
2831 * Returns an unmodifiable array of available video capture devices.
2833 * @ingroup media_parameters
2834 * The array is NULL terminated.
2836 const char** linphone_core_get_video_devices(const LinphoneCore *lc){
2837 return lc->video_conf.cams;
2840 char linphone_core_get_sound_source(LinphoneCore *lc)
2842 return lc->sound_conf.source;
2845 void linphone_core_set_sound_source(LinphoneCore *lc, char source)
2847 MSSndCard *sndcard=lc->sound_conf.capt_sndcard;
2848 lc->sound_conf.source=source;
2849 if (!sndcard) return;
2852 ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
2855 ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
2863 * Sets the path to a wav file used for ringing.
2865 * @param path The file must be a wav 16bit linear. Local ring is disabled if null
2866 * @param lc The LinphoneCore object
2868 * @ingroup media_parameters
2870 void linphone_core_set_ring(LinphoneCore *lc,const char *path){
2871 if (lc->sound_conf.local_ring!=0){
2872 ms_free(lc->sound_conf.local_ring);
2873 lc->sound_conf.local_ring=NULL;
2876 lc->sound_conf.local_ring=ms_strdup(path);
2877 if ( linphone_core_ready(lc) && lc->sound_conf.local_ring)
2878 lp_config_set_string(lc->config,"sound","local_ring",lc->sound_conf.local_ring);
2882 * Returns the path to the wav file used for ringing.
2884 * @param lc The LinphoneCore object
2885 * @ingroup media_parameters
2887 const char *linphone_core_get_ring(const LinphoneCore *lc){
2888 return lc->sound_conf.local_ring;
2891 static void notify_end_of_ring(void *ud, MSFilter *f, unsigned int event, void *arg){
2892 LinphoneCore *lc=(LinphoneCore*)ud;
2893 lc->preview_finished=1;
2896 int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata)
2898 if (lc->ringstream!=0){
2899 ms_warning("Cannot start ring now,there's already a ring being played");
2902 lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
2903 lc->preview_finished=0;
2904 if (lc->sound_conf.ring_sndcard!=NULL){
2905 MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
2906 lc->ringstream=ring_start_with_cb(ring,2000,ringcard,notify_end_of_ring,(void *)lc);
2912 * Sets the path to a wav file used for ringing back.
2914 * Ringback means the ring that is heard when it's ringing at the remote party.
2915 * The file must be a wav 16bit linear.
2917 * @ingroup media_parameters
2919 void linphone_core_set_ringback(LinphoneCore *lc, const char *path){
2920 if (lc->sound_conf.remote_ring!=0){
2921 ms_free(lc->sound_conf.remote_ring);
2923 lc->sound_conf.remote_ring=ms_strdup(path);
2927 * Returns the path to the wav file used for ringing back.
2929 * @ingroup media_parameters
2931 const char * linphone_core_get_ringback(const LinphoneCore *lc){
2932 return lc->sound_conf.remote_ring;
2936 * Enables or disable echo cancellation. Value is saved an used for subsequent calls
2938 * @ingroup media_parameters
2940 void linphone_core_enable_echo_cancellation(LinphoneCore *lc, bool_t val){
2941 lc->sound_conf.ec=val;
2942 if ( linphone_core_ready(lc))
2943 lp_config_set_int(lc->config,"sound","echocancellation",val);
2948 * Returns TRUE if echo cancellation is enabled.
2950 * @ingroup media_parameters
2952 bool_t linphone_core_echo_cancellation_enabled(LinphoneCore *lc){
2953 return lc->sound_conf.ec;
2956 void linphone_core_enable_echo_limiter(LinphoneCore *lc, bool_t val){
2957 lc->sound_conf.ea=val;
2960 bool_t linphone_core_echo_limiter_enabled(const LinphoneCore *lc){
2961 return lc->sound_conf.ea;
2965 * Mutes or unmutes the local microphone.
2967 * @ingroup media_parameters
2969 void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){
2970 LinphoneCall *call=linphone_core_get_current_call(lc);
2972 ms_warning("linphone_core_mute_mic(): No current call !");
2975 if (call->audiostream!=NULL){
2976 audio_stream_set_mic_gain(call->audiostream,
2977 (val==TRUE) ? 0 : lp_config_get_float(lc->config,"sound","mic_gain",1));
2978 if ( linphone_core_get_rtp_no_xmit_on_audio_mute(lc) ){
2979 audio_stream_mute_rtp(call->audiostream,val);
2981 call->audio_muted=val;
2985 bool_t linphone_core_is_mic_muted(LinphoneCore *lc) {
2986 LinphoneCall *call=linphone_core_get_current_call(lc);
2988 ms_warning("linphone_core_is_mic_muted(): No current call !");
2991 return call->audio_muted;
2994 // returns rtp transmission status for an active stream
2995 // if audio is muted and config parameter rtp_no_xmit_on_audio_mute
2996 // was set on then rtp transmission is also muted
2997 bool_t linphone_core_is_rtp_muted(LinphoneCore *lc){
2998 LinphoneCall *call=linphone_core_get_current_call(lc);
3000 ms_warning("linphone_core_is_mic_muted(): No current call !");
3003 if( linphone_core_get_rtp_no_xmit_on_audio_mute(lc)){
3004 return call->audio_muted;
3009 void linphone_core_enable_agc(LinphoneCore *lc, bool_t val){
3010 lc->sound_conf.agc=val;
3013 bool_t linphone_core_agc_enabled(const LinphoneCore *lc){
3014 return lc->sound_conf.agc;
3018 * Send the specified dtmf.
3020 * @ingroup media_parameters
3021 * This function only works during calls. The dtmf is automatically played to the user.
3022 * @param lc The LinphoneCore object
3023 * @param dtmf The dtmf name specified as a char, such as '0', '#' etc...
3026 void linphone_core_send_dtmf(LinphoneCore *lc, char dtmf)
3028 LinphoneCall *call=linphone_core_get_current_call(lc);
3030 ms_warning("linphone_core_send_dtmf(): no active call");
3033 /*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
3034 if (linphone_core_get_use_rfc2833_for_dtmf(lc)!=0 || linphone_core_get_use_info_for_dtmf(lc)==0)
3037 if (call->audiostream!=NULL){
3038 audio_stream_send_dtmf(call->audiostream,dtmf);
3042 ms_error("we cannot send RFC2833 dtmf when we are not in communication");
3045 if (linphone_core_get_use_info_for_dtmf(lc)!=0){
3046 /* Out of Band DTMF (use INFO method) */
3047 sal_call_send_dtmf(call->op,dtmf);
3051 void linphone_core_set_stun_server(LinphoneCore *lc, const char *server){
3052 if (lc->net_conf.stun_server!=NULL)
3053 ms_free(lc->net_conf.stun_server);
3055 lc->net_conf.stun_server=ms_strdup(server);
3056 else lc->net_conf.stun_server=NULL;
3059 const char * linphone_core_get_stun_server(const LinphoneCore *lc){
3060 return lc->net_conf.stun_server;
3063 const char * linphone_core_get_relay_addr(const LinphoneCore *lc){
3064 return lc->net_conf.relay;
3067 int linphone_core_set_relay_addr(LinphoneCore *lc, const char *addr){
3068 if (lc->net_conf.relay!=NULL){
3069 ms_free(lc->net_conf.relay);
3070 lc->net_conf.relay=NULL;
3073 lc->net_conf.relay=ms_strdup(addr);
3078 void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
3080 if (lc->net_conf.nat_address!=NULL){
3081 ms_free(lc->net_conf.nat_address);
3083 if (addr!=NULL) lc->net_conf.nat_address=ms_strdup(addr);
3084 else lc->net_conf.nat_address=NULL;
3085 if (lc->sip_conf.contact) update_primary_contact(lc);
3088 const char *linphone_core_get_nat_address(const LinphoneCore *lc) {
3089 return lc->net_conf.nat_address;
3092 const char *linphone_core_get_nat_address_resolved(LinphoneCore *lc)
3094 struct sockaddr_storage ss;
3097 char ipstring [INET6_ADDRSTRLEN];
3099 if (parse_hostname_to_addr (lc->net_conf.nat_address, &ss, &ss_len)<0) {
3100 return lc->net_conf.nat_address;
3103 error = getnameinfo((struct sockaddr *)&ss, ss_len,
3104 ipstring, sizeof(ipstring), NULL, 0, NI_NUMERICHOST);
3106 return lc->net_conf.nat_address;
3109 if (lc->net_conf.nat_address_ip!=NULL){
3110 ms_free(lc->net_conf.nat_address_ip);
3112 lc->net_conf.nat_address_ip = ms_strdup (ipstring);
3113 return lc->net_conf.nat_address_ip;
3116 void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
3117 lc->net_conf.firewall_policy=pol;
3118 if (lc->sip_conf.contact) update_primary_contact(lc);
3121 LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
3122 return lc->net_conf.firewall_policy;
3126 * Get the list of call logs (past calls).
3128 * @ingroup call_logs
3130 const MSList * linphone_core_get_call_logs(LinphoneCore *lc){
3132 return lc->call_logs;
3136 * Erase the call log.
3138 * @ingroup call_logs
3140 void linphone_core_clear_call_logs(LinphoneCore *lc){
3142 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3143 lc->call_logs=ms_list_free(lc->call_logs);
3144 call_logs_write_to_config_file(lc);
3147 static void toggle_video_preview(LinphoneCore *lc, bool_t val){
3148 #ifdef VIDEO_ENABLED
3150 if (lc->previewstream==NULL){
3151 lc->previewstream=video_preview_new();
3152 video_preview_set_size(lc->previewstream,lc->video_conf.vsize);
3153 if (lc->video_conf.displaytype)
3154 video_preview_set_display_filter_name(lc->previewstream,lc->video_conf.displaytype);
3155 if (lc->preview_window_id!=0)
3156 video_preview_set_native_window_id(lc->previewstream,lc->preview_window_id);
3157 video_preview_start(lc->previewstream,lc->video_conf.device);
3160 if (lc->previewstream!=NULL){
3161 video_preview_stop(lc->previewstream);
3162 lc->previewstream=NULL;
3169 * Enables video globally.
3171 * @ingroup media_parameters
3172 * This function does not have any effect during calls. It just indicates LinphoneCore to
3173 * initiate future calls with video or not. The two boolean parameters indicate in which
3174 * direction video is enabled. Setting both to false disables video entirely.
3176 * @param lc The LinphoneCore object
3177 * @param vcap_enabled indicates whether video capture is enabled
3178 * @param display_enabled indicates whether video display should be shown
3181 void linphone_core_enable_video(LinphoneCore *lc, bool_t vcap_enabled, bool_t display_enabled){
3182 #ifndef VIDEO_ENABLED
3183 if (vcap_enabled || display_enabled)
3184 ms_warning("This version of linphone was built without video support.");
3186 lc->video_conf.capture=vcap_enabled;
3187 lc->video_conf.display=display_enabled;
3189 /* need to re-apply network bandwidth settings*/
3190 linphone_core_set_download_bandwidth(lc,
3191 linphone_core_get_download_bandwidth(lc));
3192 linphone_core_set_upload_bandwidth(lc,
3193 linphone_core_get_upload_bandwidth(lc));
3197 * Returns TRUE if video is enabled, FALSE otherwise.
3198 * @ingroup media_parameters
3200 bool_t linphone_core_video_enabled(LinphoneCore *lc){
3201 return (lc->video_conf.display || lc->video_conf.capture);
3205 * Controls video preview enablement.
3207 * @ingroup media_parameters
3208 * Video preview refers to the action of displaying the local webcam image
3209 * to the user while not in call.
3211 void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val){
3212 lc->video_conf.show_local=val;
3216 * Returns TRUE if video previewing is enabled.
3217 * @ingroup media_parameters
3219 bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
3220 return lc->video_conf.show_local;
3224 * Enables or disable self view during calls.
3226 * @ingroup media_parameters
3227 * Self-view refers to having local webcam image inserted in corner
3228 * of the video window during calls.
3229 * This function works at any time, including during calls.
3231 void linphone_core_enable_self_view(LinphoneCore *lc, bool_t val){
3232 #ifdef VIDEO_ENABLED
3233 LinphoneCall *call=linphone_core_get_current_call (lc);
3234 lc->video_conf.selfview=val;
3235 if (call && call->videostream){
3236 video_stream_enable_self_view(call->videostream,val);
3242 * Returns TRUE if self-view is enabled, FALSE otherwise.
3244 * @ingroup media_parameters
3246 * Refer to linphone_core_enable_self_view() for details.
3248 bool_t linphone_core_self_view_enabled(const LinphoneCore *lc){
3249 return lc->video_conf.selfview;
3253 * Sets the active video device.
3255 * @ingroup media_parameters
3256 * @param lc The LinphoneCore object
3257 * @param id the name of the video device as returned by linphone_core_get_video_devices()
3259 int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
3260 MSWebCam *olddev=lc->video_conf.device;
3263 lc->video_conf.device=ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),id);
3264 if (lc->video_conf.device==NULL){
3265 ms_warning("Could not found video device %s",id);
3268 if (lc->video_conf.device==NULL)
3269 lc->video_conf.device=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());
3270 if (olddev!=NULL && olddev!=lc->video_conf.device){
3271 toggle_video_preview(lc,FALSE);/*restart the video local preview*/
3273 if ( linphone_core_ready(lc) && lc->video_conf.device){
3274 vd=ms_web_cam_get_string_id(lc->video_conf.device);
3275 if (vd && strstr(vd,"Static picture")!=NULL){
3278 lp_config_set_string(lc->config,"video","device",vd);
3284 * Returns the name of the currently active video device.
3286 * @param lc The LinphoneCore object
3287 * @ingroup media_parameters
3289 const char *linphone_core_get_video_device(const LinphoneCore *lc){
3290 if (lc->video_conf.device) return ms_web_cam_get_string_id(lc->video_conf.device);
3294 #ifdef VIDEO_ENABLED
3295 static VideoStream * get_active_video_stream(LinphoneCore *lc){
3296 VideoStream *vs = NULL;
3297 LinphoneCall *call=linphone_core_get_current_call (lc);
3298 /* Select the video stream from the call in the first place */
3299 if (call && call->videostream) {
3300 vs = call->videostream;
3302 /* If not in call, select the video stream from the preview */
3303 if (vs == NULL && lc->previewstream) {
3304 vs = lc->previewstream;
3310 int linphone_core_set_static_picture(LinphoneCore *lc, const char *path) {
3311 #ifdef VIDEO_ENABLED
3312 VideoStream *vs=get_active_video_stream(lc);
3313 /* If we have a video stream (either preview, either from call), we
3314 have a source and it is using the static picture filter, then
3315 force the filter to use that picture. */
3316 if (vs && vs->source) {
3317 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3318 ms_filter_call_method(vs->source, MS_STATIC_IMAGE_SET_IMAGE,
3322 /* Tell the static image filter to use that image from now on so
3323 that the image will be used next time it has to be read */
3324 ms_static_image_set_default_image(path);
3326 ms_warning("Video support not compiled.");
3331 int linphone_core_set_static_picture_fps(LinphoneCore *lc, float fps) {
3332 #ifdef VIDEO_ENABLED
3333 VideoStream *vs = NULL;
3335 vs=get_active_video_stream(lc);
3337 /* If we have a video stream (either preview, either from call), we
3338 have a source and it is using the static picture filter, then
3339 force the filter to use that picture. */
3340 if (vs && vs->source) {
3341 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3342 ms_filter_call_method(vs->source, MS_FILTER_SET_FPS,(void *)&fps);
3346 ms_warning("Video support not compiled.");
3351 float linphone_core_get_static_picture_fps(LinphoneCore *lc) {
3352 #ifdef VIDEO_ENABLED
3353 VideoStream *vs = NULL;
3354 vs=get_active_video_stream(lc);
3355 /* If we have a video stream (either preview, either from call), we
3356 have a source and it is using the static picture filter, then
3357 force the filter to use that picture. */
3358 if (vs && vs->source) {
3359 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3363 ms_filter_call_method(vs->source, MS_FILTER_GET_FPS,(void *)&fps);
3368 ms_warning("Video support not compiled.");
3374 * Returns the native window handle of the video window, casted as an unsigned long.
3376 * @ingroup media_parameters
3378 unsigned long linphone_core_get_native_video_window_id(const LinphoneCore *lc){
3379 #ifdef VIDEO_ENABLED
3380 LinphoneCall *call=linphone_core_get_current_call (lc);
3381 if (call && call->videostream)
3382 return video_stream_get_native_window_id(call->videostream);
3383 if (lc->previewstream)
3384 return video_stream_get_native_window_id(lc->previewstream);
3386 return lc->video_window_id;
3390 * Set the native video window id where the video is to be displayed.
3391 * If not set the core will create its own window.
3393 void linphone_core_set_native_video_window_id(LinphoneCore *lc, unsigned long id){
3394 #ifdef VIDEO_ENABLED
3395 LinphoneCall *call=linphone_core_get_current_call(lc);
3396 lc->video_window_id=id;
3397 if (call!=NULL && call->videostream){
3398 video_stream_set_native_window_id(call->videostream,id);
3404 * Returns the native window handle of the video preview window, casted as an unsigned long.
3406 * @ingroup media_parameters
3408 unsigned long linphone_core_get_native_preview_window_id(const LinphoneCore *lc){
3409 #ifdef VIDEO_ENABLED
3410 LinphoneCall *call=linphone_core_get_current_call (lc);
3411 if (call && call->videostream)
3412 return video_stream_get_native_preview_window_id(call->videostream);
3413 if (lc->previewstream)
3414 return video_preview_get_native_window_id(lc->previewstream);
3416 return lc->preview_window_id;
3420 * Set the native window id where the preview video (local camera) is to be displayed.
3421 * This has to be used in conjonction with linphone_core_use_preview_window().
3422 * If not set the core will create its own window.
3424 void linphone_core_set_native_preview_window_id(LinphoneCore *lc, unsigned long id){
3425 lc->preview_window_id=id;
3429 * Tells the core to use a separate window for local camera preview video, instead of
3430 * inserting local view within the remote video window.
3433 void linphone_core_use_preview_window(LinphoneCore *lc, bool_t yesno){
3434 lc->use_preview_window=yesno;
3437 static MSVideoSizeDef supported_resolutions[]={
3439 { {MS_VIDEO_SIZE_1080P_W,MS_VIDEO_SIZE_1080P_H} , "1080p" },
3440 { {MS_VIDEO_SIZE_720P_W,MS_VIDEO_SIZE_720P_H} , "1080p" },
3442 { {MS_VIDEO_SIZE_SVGA_W,MS_VIDEO_SIZE_SVGA_H} , "svga" },
3443 { {MS_VIDEO_SIZE_4CIF_W,MS_VIDEO_SIZE_4CIF_H} , "4cif" },
3444 { {MS_VIDEO_SIZE_VGA_W,MS_VIDEO_SIZE_VGA_H} , "vga" },
3445 { {MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H} , "cif" },
3446 { {MS_VIDEO_SIZE_QVGA_W,MS_VIDEO_SIZE_QVGA_H} , "qvga" },
3447 { {MS_VIDEO_SIZE_QVGA_H,MS_VIDEO_SIZE_QVGA_W} , "qvga-portrait" },
3448 { {MS_VIDEO_SIZE_QCIF_W,MS_VIDEO_SIZE_QCIF_H} , "qcif" },
3449 { {MS_VIDEO_SIZE_QCIF_H,MS_VIDEO_SIZE_QCIF_W} , "qcif-portrait" },
3454 * Returns the zero terminated table of supported video resolutions.
3456 * @ingroup media_parameters
3458 const MSVideoSizeDef *linphone_core_get_supported_video_sizes(LinphoneCore *lc){
3459 return supported_resolutions;
3462 static MSVideoSize video_size_get_by_name(const char *name){
3463 MSVideoSizeDef *pdef=supported_resolutions;
3464 MSVideoSize null_vsize={0,0};
3465 for(;pdef->name!=NULL;pdef++){
3466 if (strcasecmp(name,pdef->name)==0){
3470 ms_warning("Video resolution %s is not supported in linphone.",name);
3474 static const char *video_size_get_name(MSVideoSize vsize){
3475 MSVideoSizeDef *pdef=supported_resolutions;
3476 for(;pdef->name!=NULL;pdef++){
3477 if (pdef->vsize.width==vsize.width && pdef->vsize.height==vsize.height){
3484 static bool_t video_size_supported(MSVideoSize vsize){
3485 if (video_size_get_name(vsize)) return TRUE;
3486 ms_warning("Video resolution %ix%i is not supported in linphone.",vsize.width,vsize.height);
3491 * Sets the preferred video size.
3493 * @ingroup media_parameters
3494 * This applies only to the stream that is captured and sent to the remote party,
3495 * since we accept all standard video size on the receive path.
3497 void linphone_core_set_preferred_video_size(LinphoneCore *lc, MSVideoSize vsize){
3498 if (video_size_supported(vsize)){
3499 MSVideoSize oldvsize=lc->video_conf.vsize;
3500 lc->video_conf.vsize=vsize;
3501 if (!ms_video_size_equal(oldvsize,vsize) && lc->previewstream!=NULL){
3502 toggle_video_preview(lc,FALSE);
3503 toggle_video_preview(lc,TRUE);
3505 if ( linphone_core_ready(lc))
3506 lp_config_set_string(lc->config,"video","size",video_size_get_name(vsize));
3511 * Sets the preferred video size by its name.
3513 * @ingroup media_parameters
3514 * This is identical to linphone_core_set_preferred_video_size() except
3515 * that it takes the name of the video resolution as input.
3516 * Video resolution names are: qcif, svga, cif, vga, 4cif, svga ...
3518 void linphone_core_set_preferred_video_size_by_name(LinphoneCore *lc, const char *name){
3519 MSVideoSize vsize=video_size_get_by_name(name);
3520 MSVideoSize default_vsize={MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H};
3521 if (vsize.width!=0) linphone_core_set_preferred_video_size(lc,vsize);
3522 else linphone_core_set_preferred_video_size(lc,default_vsize);
3526 * Returns the current preferred video size for sending.
3528 * @ingroup media_parameters
3530 MSVideoSize linphone_core_get_preferred_video_size(LinphoneCore *lc){
3531 return lc->video_conf.vsize;
3535 * Ask the core to stream audio from and to files, instead of using the soundcard.
3537 void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
3538 lc->use_files=yesno;
3542 * Sets a wav file to be played when putting somebody on hold,
3543 * or when files are used instead of soundcards (see linphone_core_use_files()).
3545 * The file must be a 16 bit linear wav file.
3547 void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
3548 LinphoneCall *call=linphone_core_get_current_call(lc);
3549 if (lc->play_file!=NULL){
3550 ms_free(lc->play_file);
3554 lc->play_file=ms_strdup(file);
3555 if (call && call->audiostream && call->audiostream->ticker)
3556 audio_stream_play(call->audiostream,file);
3562 * Sets a wav file where incoming stream is to be recorded,
3563 * when files are used instead of soundcards (see linphone_core_use_files()).
3565 * The file must be a 16 bit linear wav file.
3567 void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
3568 LinphoneCall *call=linphone_core_get_current_call(lc);
3569 if (lc->rec_file!=NULL){
3570 ms_free(lc->rec_file);
3574 lc->rec_file=ms_strdup(file);
3575 if (call && call->audiostream)
3576 audio_stream_record(call->audiostream,file);
3581 static MSFilter *get_dtmf_gen(LinphoneCore *lc){
3582 LinphoneCall *call=linphone_core_get_current_call (lc);
3584 AudioStream *stream=call->audiostream;
3586 return stream->dtmfgen;
3589 if (lc->ringstream==NULL){
3591 MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
3592 lc->ringstream=ring_start(NULL,0,ringcard);
3593 ms_filter_call_method(lc->ringstream->gendtmf,MS_DTMF_GEN_SET_DEFAULT_AMPLITUDE,&);
3594 lc->dmfs_playing_start_time=time(NULL);
3596 if (lc->dmfs_playing_start_time!=0)
3597 lc->dmfs_playing_start_time=time(NULL);
3599 return lc->ringstream->gendtmf;
3603 * @ingroup media_parameters
3604 * Plays a dtmf sound to the local user.
3605 * @param lc #LinphoneCore
3606 * @param dtmf DTMF to play ['0'..'16'] | '#' | '#'
3607 * @param duration_ms duration in ms, -1 means play until next further call to #linphone_core_stop_dtmf()
3609 void linphone_core_play_dtmf(LinphoneCore *lc, char dtmf, int duration_ms){
3610 MSFilter *f=get_dtmf_gen(lc);
3612 ms_error("No dtmf generator at this time !");
3617 ms_filter_call_method(f, MS_DTMF_GEN_PLAY, &dtmf);
3618 else ms_filter_call_method(f, MS_DTMF_GEN_START, &dtmf);
3622 * @ingroup media_parameters
3624 * Stops playing a dtmf started by linphone_core_play_dtmf().
3626 void linphone_core_stop_dtmf(LinphoneCore *lc){
3627 MSFilter *f=get_dtmf_gen(lc);
3629 ms_filter_call_method_noarg (f, MS_DTMF_GEN_STOP);
3635 * Retrieves the user pointer that was given to linphone_core_new()
3637 * @ingroup initializing
3639 void *linphone_core_get_user_data(LinphoneCore *lc){
3643 int linphone_core_get_mtu(const LinphoneCore *lc){
3644 return lc->net_conf.mtu;
3647 void linphone_core_set_mtu(LinphoneCore *lc, int mtu){
3648 lc->net_conf.mtu=mtu;
3651 ms_error("MTU too small !");
3655 ms_message("MTU is supposed to be %i, rtp payload max size will be %i",mtu, ms_get_payload_max_size());
3656 }else ms_set_mtu(0);//use mediastreamer2 default value
3659 void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context){
3661 lc->wait_ctx=user_context;
3664 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose){
3666 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingStart,purpose,0);
3670 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progress){
3672 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingProgress,purpose,progress);
3682 void linphone_core_stop_waiting(LinphoneCore *lc){
3684 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingFinished,NULL,0);
3688 void linphone_core_set_audio_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3693 void linphone_core_set_video_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3699 * Retrieve RTP statistics regarding current call.
3700 * @param local RTP statistics computed locally.
3701 * @param remote RTP statistics computed by far end (obtained via RTCP feedback).
3703 * @note Remote RTP statistics is not implemented yet.
3705 * @returns 0 or -1 if no call is running.
3708 int linphone_core_get_current_call_stats(LinphoneCore *lc, rtp_stats_t *local, rtp_stats_t *remote){
3709 LinphoneCall *call=linphone_core_get_current_call (lc);
3711 if (call->audiostream!=NULL){
3712 memset(remote,0,sizeof(*remote));
3713 audio_stream_get_local_rtp_stats (call->audiostream,local);
3720 void net_config_uninit(LinphoneCore *lc)
3722 net_config_t *config=&lc->net_conf;
3723 lp_config_set_int(lc->config,"net","download_bw",config->download_bw);
3724 lp_config_set_int(lc->config,"net","upload_bw",config->upload_bw);
3726 if (config->stun_server!=NULL){
3727 lp_config_set_string(lc->config,"net","stun_server",config->stun_server);
3728 ms_free(lc->net_conf.stun_server);
3730 if (config->nat_address!=NULL){
3731 lp_config_set_string(lc->config,"net","nat_address",config->nat_address);
3732 ms_free(lc->net_conf.nat_address);
3734 if (lc->net_conf.nat_address_ip !=NULL){
3735 ms_free(lc->net_conf.nat_address_ip);
3737 lp_config_set_int(lc->config,"net","firewall_policy",config->firewall_policy);
3738 lp_config_set_int(lc->config,"net","mtu",config->mtu);
3742 void sip_config_uninit(LinphoneCore *lc)
3746 sip_config_t *config=&lc->sip_conf;
3747 lp_config_set_int(lc->config,"sip","sip_port",config->transports.udp_port);
3748 lp_config_set_int(lc->config,"sip","sip_tcp_port",config->transports.tcp_port);
3749 lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
3750 lp_config_set_string(lc->config,"sip","contact",config->contact);
3751 lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
3752 lp_config_set_int(lc->config,"sip","use_info",config->use_info);
3753 lp_config_set_int(lc->config,"sip","use_rfc2833",config->use_rfc2833);
3754 lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
3755 lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
3758 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
3760 for(elem=config->proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3761 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
3762 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
3763 linphone_proxy_config_edit(cfg); /* to unregister */
3765 /*to ensure remove configs are erased:*/
3766 linphone_proxy_config_write_to_config_file(lc->config,NULL,i);
3769 sal_iterate(lc->sal);
3777 ms_list_for_each(config->proxies,(void (*)(void*)) linphone_proxy_config_destroy);
3778 ms_list_free(config->proxies);
3779 config->proxies=NULL;
3781 linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */
3783 for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3784 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
3785 linphone_auth_info_write_config(lc->config,ai,i);
3787 linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
3788 ms_list_for_each(lc->auth_info,(void (*)(void*))linphone_auth_info_destroy);
3789 ms_list_free(lc->auth_info);
3792 sal_uninit(lc->sal);
3795 if (lc->sip_conf.guessed_contact)
3796 ms_free(lc->sip_conf.guessed_contact);
3797 if (config->contact)
3798 ms_free(config->contact);
3802 void rtp_config_uninit(LinphoneCore *lc)
3804 rtp_config_t *config=&lc->rtp_conf;
3805 lp_config_set_int(lc->config,"rtp","audio_rtp_port",config->audio_rtp_port);
3806 lp_config_set_int(lc->config,"rtp","video_rtp_port",config->video_rtp_port);
3807 lp_config_set_int(lc->config,"rtp","audio_jitt_comp",config->audio_jitt_comp);
3808 lp_config_set_int(lc->config,"rtp","video_jitt_comp",config->video_jitt_comp);
3809 lp_config_set_int(lc->config,"rtp","nortp_timeout",config->nortp_timeout);
3812 void sound_config_uninit(LinphoneCore *lc)
3814 sound_config_t *config=&lc->sound_conf;
3815 ms_free(config->cards);
3817 lp_config_set_string(lc->config,"sound","remote_ring",config->remote_ring);
3819 if (config->local_ring) ms_free(config->local_ring);
3820 if (config->remote_ring) ms_free(config->remote_ring);
3821 ms_snd_card_manager_destroy();
3824 void video_config_uninit(LinphoneCore *lc)
3826 lp_config_set_string(lc->config,"video","size",video_size_get_name(linphone_core_get_preferred_video_size(lc)));
3827 lp_config_set_int(lc->config,"video","display",lc->video_conf.display);
3828 lp_config_set_int(lc->config,"video","capture",lc->video_conf.capture);
3829 lp_config_set_int(lc->config,"video","show_local",linphone_core_video_preview_enabled(lc));
3830 lp_config_set_int(lc->config,"video","self_view",linphone_core_self_view_enabled(lc));
3831 if (lc->video_conf.cams)
3832 ms_free(lc->video_conf.cams);
3835 void codecs_config_uninit(LinphoneCore *lc)
3838 codecs_config_t *config=&lc->codecs_conf;
3843 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
3844 pt=(PayloadType*)(node->data);
3845 sprintf(key,"audio_codec_%i",index);
3846 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3847 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3848 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3851 sprintf(key,"audio_codec_%i",index);
3852 lp_config_clean_section (lc->config,key);
3855 for(node=config->video_codecs;node!=NULL;node=ms_list_next(node)){
3856 pt=(PayloadType*)(node->data);
3857 sprintf(key,"video_codec_%i",index);
3858 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3859 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3860 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3861 lp_config_set_string(lc->config,key,"recv_fmtp",pt->recv_fmtp);
3864 sprintf(key,"video_codec_%i",index);
3865 lp_config_clean_section (lc->config,key);
3867 ms_list_free(lc->codecs_conf.audio_codecs);
3868 ms_list_free(lc->codecs_conf.video_codecs);
3871 void ui_config_uninit(LinphoneCore* lc)
3874 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_destroy);
3875 ms_list_free(lc->friends);
3881 * Returns the LpConfig object used to manage the storage (config) file.
3884 * The application can use the LpConfig object to insert its own private
3885 * sections and pairs of key=value in the configuration file.
3888 LpConfig *linphone_core_get_config(LinphoneCore *lc){
3892 static void linphone_core_uninit(LinphoneCore *lc)
3894 linphone_core_free_hooks(lc);
3897 LinphoneCall *the_call = lc->calls->data;
3898 linphone_core_terminate_call(lc,the_call);
3899 linphone_core_iterate(lc);
3907 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions);
3908 linphone_core_set_state(lc,LinphoneGlobalShutdown,"Shutting down");
3909 #ifdef VIDEO_ENABLED
3910 if (lc->previewstream!=NULL){
3911 video_preview_stop(lc->previewstream);
3912 lc->previewstream=NULL;
3915 ms_event_queue_destroy(lc->msevq);
3917 /* save all config */
3918 net_config_uninit(lc);
3919 rtp_config_uninit(lc);
3920 if (lc->ringstream) ring_stop(lc->ringstream);
3921 sound_config_uninit(lc);
3922 video_config_uninit(lc);
3923 codecs_config_uninit(lc);
3924 ui_config_uninit(lc);
3925 sip_config_uninit(lc);
3926 if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
3927 lp_config_destroy(lc->config);
3928 lc->config = NULL; /* Mark the config as NULL to block further calls */
3929 sip_setup_unregister_all();
3931 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3932 lc->call_logs=ms_list_free(lc->call_logs);
3934 linphone_core_free_payload_types();
3936 linphone_core_set_state(lc,LinphoneGlobalOff,"Off");
3939 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t curtime){
3940 ms_message("Network state is now [%s]",isReachable?"UP":"DOWN");
3941 // second get the list of available proxies
3942 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3943 for(;elem!=NULL;elem=elem->next){
3944 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3945 if (linphone_proxy_config_register_enabled(cfg) ) {
3953 lc->netup_time=curtime;
3954 lc->network_reachable=isReachable;
3956 sal_unlisten_ports (lc->sal);
3958 apply_transports(lc);
3962 void linphone_core_refresh_registers(LinphoneCore* lc) {
3963 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3964 for(;elem!=NULL;elem=elem->next){
3965 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3966 if (linphone_proxy_config_register_enabled(cfg) ) {
3967 linphone_proxy_config_refresh_register(cfg);
3972 void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) {
3973 //first disable automatic mode
3974 if (lc->auto_net_state_mon) {
3975 ms_message("Disabling automatic network state monitoring");
3976 lc->auto_net_state_mon=FALSE;
3978 set_network_reachable(lc,isReachable, ms_time(NULL));
3981 bool_t linphone_core_is_network_reachabled(LinphoneCore* lc) {
3982 return lc->network_reachable;
3984 ortp_socket_t linphone_core_get_sip_socket(LinphoneCore *lc){
3985 return sal_get_socket(lc->sal);
3988 * Destroys a LinphoneCore
3990 * @ingroup initializing
3992 void linphone_core_destroy(LinphoneCore *lc){
3993 linphone_core_uninit(lc);
3997 * Get the number of Call
3999 * @ingroup call_control
4001 int linphone_core_get_calls_nb(const LinphoneCore *lc){
4002 return ms_list_size(lc->calls);;
4006 * Check if we do not have exceed the number of simultaneous call
4008 * @ingroup call_control
4010 bool_t linphone_core_can_we_add_call(LinphoneCore *lc)
4012 if(linphone_core_get_calls_nb(lc) < NB_MAX_CALLS)
4014 ms_error("Maximum amount of simultaneous calls reached !");
4019 int linphone_core_add_call( LinphoneCore *lc, LinphoneCall *call)
4021 if(linphone_core_can_we_add_call(lc))
4023 lc->calls = ms_list_append(lc->calls,call);
4029 int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call)
4032 MSList *the_calls = lc->calls;
4034 it=ms_list_find(the_calls,call);
4037 the_calls = ms_list_remove_link(the_calls,it);
4041 ms_warning("could not find the call into the list\n");
4044 lc->calls = the_calls;
4049 * Specifiies a ring back tone to be played to far end during incoming calls.
4051 void linphone_core_set_remote_ringback_tone(LinphoneCore *lc, const char *file){
4052 if (lc->sound_conf.ringback_tone){
4053 ms_free(lc->sound_conf.ringback_tone);
4054 lc->sound_conf.ringback_tone=NULL;
4057 lc->sound_conf.ringback_tone=ms_strdup(file);
4061 * Returns the ring back tone played to far end during incoming calls.
4063 const char *linphone_core_get_remote_ringback_tone(const LinphoneCore *lc){
4064 return lc->sound_conf.ringback_tone;
4067 static PayloadType* find_payload_type_from_list(const char* type, int rate,const MSList* from) {
4069 for(elem=from;elem!=NULL;elem=elem->next){
4070 PayloadType *pt=(PayloadType*)elem->data;
4071 if ((strcmp((char*)type, payload_type_get_mime(pt)) == 0) && (rate == -1 || rate==pt->clock_rate)) {
4079 * Get payload type from mime type and clock rate
4080 * @ingroup media_parameters
4081 * This function searches in audio and video codecs for the given payload type name and clockrate.
4082 * Returns NULL if not found.
4084 PayloadType* linphone_core_find_payload_type(LinphoneCore* lc, const char* type, int rate) {
4085 PayloadType* result = find_payload_type_from_list(type, rate, linphone_core_get_audio_codecs(lc));
4089 result = find_payload_type_from_list(type, rate, linphone_core_get_video_codecs(lc));
4098 const char *linphone_global_state_to_string(LinphoneGlobalState gs){
4100 case LinphoneGlobalOff:
4101 return "LinphoneGlobalOff";
4103 case LinphoneGlobalOn:
4104 return "LinphoneGlobalOn";
4106 case LinphoneGlobalStartup:
4107 return "LinphoneGlobalStartup";
4109 case LinphoneGlobalShutdown:
4110 return "LinphoneGlobalShutdown";
4116 LinphoneGlobalState linphone_core_get_global_state(const LinphoneCore *lc){
4120 LinphoneCallParams *linphone_core_create_default_call_parameters(LinphoneCore *lc){
4121 LinphoneCallParams *p=ms_new0(LinphoneCallParams,1);
4122 p->has_video=linphone_core_video_enabled(lc);
4126 const char *linphone_reason_to_string(LinphoneReason err){
4128 case LinphoneReasonNone:
4130 case LinphoneReasonNoResponse:
4131 return "No response";
4132 case LinphoneReasonBadCredentials:
4133 return "Bad credentials";
4134 case LinphoneReasonDeclined:
4135 return "Call declined";
4137 return "unknown error";
4140 const char *linphone_error_to_string(LinphoneReason err){
4141 return linphone_reason_to_string(err);
4144 * Enables signaling keep alive
4146 void linphone_core_enable_keep_alive(LinphoneCore* lc,bool_t enable) {
4148 sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
4150 sal_set_keepalive_period(lc->sal,0);
4154 * Is signaling keep alive enabled
4156 bool_t linphone_core_keep_alive_enabled(LinphoneCore* lc) {
4157 return sal_get_keepalive_period(lc->sal) > 0;
4160 void linphone_core_start_dtmf_stream(LinphoneCore* lc) {
4161 get_dtmf_gen(lc); /*make sure ring stream is started*/
4162 lc->ringstream_autorelease=FALSE; /*disable autorelease mode*/
4165 void linphone_core_stop_dtmf_stream(LinphoneCore* lc) {
4166 if (lc->ringstream) ring_stop(lc->ringstream);
4167 lc->ringstream=NULL;
4170 typedef struct Hook{
4171 LinphoneCoreIterateHook fun;
4175 static Hook *hook_new(LinphoneCoreIterateHook hook, void *hook_data){
4176 Hook *h=ms_new(Hook,1);
4182 static void hook_invoke(Hook *h){
4186 void linphone_core_add_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data){
4187 lc->hooks=ms_list_append(lc->hooks,hook_new(hook,hook_data));
4190 static void linphone_core_run_hooks(LinphoneCore *lc){
4191 ms_list_for_each(lc->hooks,(void (*)(void*))hook_invoke);
4194 static void linphone_core_free_hooks(LinphoneCore *lc){
4195 ms_list_for_each(lc->hooks,(void (*)(void*))ms_free);
4196 ms_list_free(lc->hooks);
4200 void linphone_core_remove_iterate_hook(LinphoneCore *lc, LinphoneCoreIterateHook hook, void *hook_data){
4202 for(elem=lc->hooks;elem!=NULL;elem=elem->next){
4203 Hook *h=(Hook*)elem->data;
4204 if (h->fun==hook && h->data==hook_data){
4205 ms_list_remove_link(lc->hooks,elem);
4210 ms_error("linphone_core_remove_iterate_hook(): No such hook found.");