3 Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org)
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "linphonecore.h"
24 #include "mediastreamer2/mediastream.h"
25 #include "mediastreamer2/msvolume.h"
26 #include "mediastreamer2/msequalizer.h"
28 #include <ortp/telephonyevents.h>
37 /*#define UNSTANDART_GSM_11K 1*/
39 static const char *liblinphone_version=LIBLINPHONE_VERSION;
40 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable);
44 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result);
45 static void toggle_video_preview(LinphoneCore *lc, bool_t val);
47 /* relative path where is stored local ring*/
48 #define LOCAL_RING "rings/oldphone.wav"
49 /* same for remote ring (ringback)*/
50 #define REMOTE_RING "ringback.wav"
52 extern SalCallbacks linphone_sal_callbacks;
54 void lc_callback_obj_init(LCCallbackObj *obj,LinphoneCoreCbFunc func,void* ud)
60 int lc_callback_obj_invoke(LCCallbackObj *obj, LinphoneCore *lc){
61 if (obj->_func!=NULL) obj->_func(lc,obj->_user_data);
66 static MSList *make_codec_list(LinphoneCore *lc, const MSList *codecs, bool_t only_one_codec){
69 for(it=codecs;it!=NULL;it=it->next){
70 PayloadType *pt=(PayloadType*)it->data;
71 if ((pt->flags & PAYLOAD_TYPE_ENABLED) && linphone_core_check_payload_type_usability(lc,pt)){
72 l=ms_list_append(l,payload_type_clone(pt));
73 if (only_one_codec) break;
79 static SalMediaDescription *create_local_media_description(LinphoneCore *lc,
80 const char *localip, const char *username, bool_t only_one_codec){
83 SalMediaDescription *md=sal_media_description_new();
85 strncpy(md->addr,localip,sizeof(md->addr));
86 strncpy(md->username,username,sizeof(md->username));
87 md->bandwidth=linphone_core_get_download_bandwidth(lc);
88 /*set audio capabilities */
89 strncpy(md->streams[0].addr,localip,sizeof(md->streams[0].addr));
90 md->streams[0].port=linphone_core_get_audio_port(lc);
91 md->streams[0].proto=SalProtoRtpAvp;
92 md->streams[0].type=SalAudio;
93 md->streams[0].ptime=lc->net_conf.down_ptime;
94 l=make_codec_list(lc,lc->codecs_conf.audio_codecs,only_one_codec);
95 pt=payload_type_clone(rtp_profile_get_payload_from_mime(&av_profile,"telephone-event"));
96 l=ms_list_append(l,pt);
97 md->streams[0].payloads=l;
99 if (lc->dw_audio_bw>0)
100 md->streams[0].bandwidth=lc->dw_audio_bw;
102 if (linphone_core_video_enabled (lc)){
104 md->streams[1].port=linphone_core_get_video_port(lc);
105 md->streams[1].proto=SalProtoRtpAvp;
106 md->streams[1].type=SalVideo;
107 l=make_codec_list(lc,lc->codecs_conf.video_codecs,only_one_codec);
108 md->streams[1].payloads=l;
110 md->streams[1].bandwidth=lc->dw_video_bw;
115 static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
116 call->state=LCStateInit;
117 call->start_time=time(NULL);
118 call->media_start_time=0;
119 call->log=linphone_call_log_new(call, from, to);
120 linphone_core_notify_all_friends(call->core,LINPHONE_STATUS_ONTHEPHONE);
121 if (linphone_core_get_firewall_policy(call->core)==LINPHONE_POLICY_USE_STUN)
122 linphone_core_run_stun_tests(call->core,call);
125 static void discover_mtu(LinphoneCore *lc, const char *remote){
127 if (lc->net_conf.mtu==0 ){
128 /*attempt to discover mtu*/
129 mtu=ms_discover_mtu(remote);
132 ms_message("Discovered mtu is %i, RTP payload max size is %i",
133 mtu, ms_get_payload_max_size());
138 LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to)
140 LinphoneCall *call=ms_new0(LinphoneCall,1);
141 call->dir=LinphoneCallOutgoing;
142 call->op=sal_op_new(lc->sal);
143 sal_op_set_user_pointer(call->op,call);
145 linphone_core_get_local_ip(lc,linphone_address_get_domain(to),call->localip);
146 call->localdesc=create_local_media_description (lc,call->localip,
147 linphone_address_get_username(from),FALSE);
148 linphone_call_init_common(call,from,to);
149 discover_mtu(lc,linphone_address_get_domain (to));
153 LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){
154 LinphoneCall *call=ms_new0(LinphoneCall,1);
155 LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
159 call->dir=LinphoneCallIncoming;
160 sal_op_set_user_pointer(op,call);
164 if (lc->sip_conf.ping_with_options){
165 /*the following sends an option request back to the caller so that
166 we get a chance to discover our nat'd address before answering.*/
167 call->ping_op=sal_op_new(lc->sal);
168 to_str=linphone_address_as_string(to);
169 from_str=linphone_address_as_string(from);
170 sal_op_set_route(call->ping_op,sal_op_get_network_origin(call->op));
171 sal_op_set_user_pointer(call->ping_op,call);
172 sal_ping(call->ping_op,to_str,from_str);
177 linphone_address_clean(from);
178 linphone_core_get_local_ip(lc,linphone_address_get_domain(from),call->localip);
179 call->localdesc=create_local_media_description (lc,call->localip,
180 linphone_address_get_username(me),lc->sip_conf.only_one_codec);
181 linphone_call_init_common(call, from, to);
182 discover_mtu(lc,linphone_address_get_domain(from));
183 linphone_address_destroy(me);
187 void linphone_call_destroy(LinphoneCall *obj)
189 linphone_core_notify_all_friends(obj->core,obj->core->prev_mode);
190 linphone_call_log_completed(obj->log,obj);
191 linphone_core_update_allocated_audio_bandwidth(obj->core);
193 sal_op_release(obj->op);
196 if (obj->resultdesc!=NULL) {
197 sal_media_description_unref(obj->resultdesc);
198 obj->resultdesc=NULL;
200 if (obj->localdesc!=NULL) {
201 sal_media_description_unref(obj->localdesc);
205 sal_op_release(obj->ping_op);
210 /*prevent a gcc bug with %c*/
211 static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm){
212 #if !defined(_WIN32_WCE)
213 return strftime(s, max, fmt, tm);
217 #endif /*_WIN32_WCE*/
220 static void set_call_log_date(LinphoneCallLog *cl, const struct tm *loctime){
221 my_strftime(cl->start_date,sizeof(cl->start_date),"%c",loctime);
224 LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
225 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
229 #if !defined(_WIN32_WCE)
230 loctime=*localtime(&call->start_time);
232 #endif /*_WIN32_WCE*/
234 localtime_r(&call->start_time,&loctime);
236 set_call_log_date(cl,&loctime);
242 static void call_logs_write_to_config_file(LinphoneCore *lc){
247 LpConfig *cfg=lc->config;
249 if (!lc->ready) return;
251 for(i=0,elem=lc->call_logs;elem!=NULL;elem=elem->next,++i){
252 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
253 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
254 lp_config_set_int(cfg,logsection,"dir",cl->dir);
255 lp_config_set_int(cfg,logsection,"status",cl->status);
256 tmp=linphone_address_as_string(cl->from);
257 lp_config_set_string(cfg,logsection,"from",tmp);
259 tmp=linphone_address_as_string(cl->to);
260 lp_config_set_string(cfg,logsection,"to",tmp);
262 lp_config_set_string(cfg,logsection,"start_date",cl->start_date);
263 lp_config_set_int(cfg,logsection,"duration",cl->duration);
264 if (cl->refkey) lp_config_set_string(cfg,logsection,"refkey",cl->refkey);
266 for(;i<lc->max_call_logs;++i){
267 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
268 lp_config_clean_section(cfg,logsection);
272 static void call_logs_read_from_config_file(LinphoneCore *lc){
276 LpConfig *cfg=lc->config;
278 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
279 if (lp_config_has_section(cfg,logsection)){
280 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
281 cl->dir=lp_config_get_int(cfg,logsection,"dir",0);
282 cl->status=lp_config_get_int(cfg,logsection,"status",0);
283 tmp=lp_config_get_string(cfg,logsection,"from",NULL);
284 if (tmp) cl->from=linphone_address_new(tmp);
285 tmp=lp_config_get_string(cfg,logsection,"to",NULL);
286 if (tmp) cl->to=linphone_address_new(tmp);
287 tmp=lp_config_get_string(cfg,logsection,"start_date",NULL);
288 if (tmp) strncpy(cl->start_date,tmp,sizeof(cl->start_date));
289 cl->duration=lp_config_get_int(cfg,logsection,"duration",0);
290 tmp=lp_config_get_string(cfg,logsection,"refkey",NULL);
291 if (tmp) cl->refkey=ms_strdup(tmp);
292 lc->call_logs=ms_list_append(lc->call_logs,cl);
298 void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call){
299 LinphoneCore *lc=call->core;
301 calllog->duration=time(NULL)-call->start_time;
304 case LCStatePreEstablishing:
305 calllog->status=LinphoneCallAborted;
308 if (calllog->dir==LinphoneCallIncoming){
310 calllog->status=LinphoneCallMissed;
312 info=ortp_strdup_printf(ngettext("You have missed %i call.",
313 "You have missed %i calls.", lc->missed_calls),
315 lc->vtable.display_status(lc,info);
318 else calllog->status=LinphoneCallAborted;
320 case LCStateAVRunning:
321 calllog->status=LinphoneCallSuccess;
324 lc->call_logs=ms_list_prepend(lc->call_logs,(void *)calllog);
325 if (ms_list_size(lc->call_logs)>lc->max_call_logs){
326 MSList *elem,*prevelem=NULL;
327 /*find the last element*/
328 for(elem=lc->call_logs;elem!=NULL;elem=elem->next){
332 linphone_call_log_destroy((LinphoneCallLog*)elem->data);
333 lc->call_logs=ms_list_remove_link(lc->call_logs,elem);
335 if (lc->vtable.call_log_updated!=NULL){
336 lc->vtable.call_log_updated(lc,calllog);
338 call_logs_write_to_config_file(lc);
342 * @addtogroup call_logs
347 * Returns a human readable string describing the call.
349 * @note: the returned char* must be freed by the application (use ms_free()).
351 char * linphone_call_log_to_str(LinphoneCallLog *cl){
354 char *from=linphone_address_as_string (cl->from);
355 char *to=linphone_address_as_string (cl->to);
357 case LinphoneCallAborted:
360 case LinphoneCallSuccess:
361 status=_("completed");
363 case LinphoneCallMissed:
369 tmp=ortp_strdup_printf(_("%s at %s\nFrom: %s\nTo: %s\nStatus: %s\nDuration: %i mn %i sec\n"),
370 (cl->dir==LinphoneCallIncoming) ? _("Incoming call") : _("Outgoing call"),
383 * Returns RTP statistics computed locally regarding the call.
386 const rtp_stats_t *linphone_call_log_get_local_stats(const LinphoneCallLog *cl){
387 return &cl->local_stats;
391 * Returns RTP statistics computed by remote end and sent back via RTCP.
393 * @note Not implemented yet.
395 const rtp_stats_t *linphone_call_log_get_remote_stats(const LinphoneCallLog *cl){
396 return &cl->remote_stats;
399 void linphone_call_log_set_user_pointer(LinphoneCallLog *cl, void *up){
403 void *linphone_call_log_get_user_pointer(const LinphoneCallLog *cl){
404 return cl->user_pointer;
410 * Associate a persistent reference key to the call log.
412 * The reference key can be for example an id to an external database.
413 * It is stored in the config file, thus can survive to process exits/restarts.
416 void linphone_call_log_set_ref_key(LinphoneCallLog *cl, const char *refkey){
417 if (cl->refkey!=NULL){
421 if (refkey) cl->refkey=ms_strdup(refkey);
422 call_logs_write_to_config_file(cl->lc);
426 * Get the persistent reference key associated to the call log.
428 * The reference key can be for example an id to an external database.
429 * It is stored in the config file, thus can survive to process exits/restarts.
432 const char *linphone_call_log_get_ref_key(const LinphoneCallLog *cl){
438 void linphone_call_log_destroy(LinphoneCallLog *cl){
439 if (cl->from!=NULL) linphone_address_destroy(cl->from);
440 if (cl->to!=NULL) linphone_address_destroy(cl->to);
441 if (cl->refkey!=NULL) ms_free(cl->refkey);
446 * Returns TRUE if the LinphoneCall asked to autoanswer
449 bool_t linphone_call_asked_to_autoanswer(LinphoneCall *call){
450 //return TRUE if the unique(for the moment) incoming call asked to be autoanswered
452 return sal_call_autoanswer_asked(call->op);
457 int linphone_core_get_current_call_duration(const LinphoneCore *lc){
458 LinphoneCall *call=lc->call;
459 if (call==NULL) return 0;
460 if (call->media_start_time==0) return 0;
461 return time(NULL)-call->media_start_time;
464 const LinphoneAddress *linphone_core_get_remote_uri(LinphoneCore *lc){
465 LinphoneCall *call=lc->call;
466 if (call==NULL) return 0;
467 return call->dir==LinphoneCallIncoming ? call->log->from : call->log->to;
471 * Enable logs in supplied FILE*.
475 * @param file a C FILE* where to fprintf logs. If null stdout is used.
478 void linphone_core_enable_logs(FILE *file){
479 if (file==NULL) file=stdout;
480 ortp_set_log_file(file);
481 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
485 * Enable logs through the user's supplied log callback.
489 * @param logfunc The address of a OrtpLogFunc callback whose protoype is
490 * typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
493 void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc){
494 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
495 ortp_set_log_handler(logfunc);
499 * Entirely disable logging.
503 void linphone_core_disable_logs(){
504 ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
509 net_config_read (LinphoneCore *lc)
513 LpConfig *config=lc->config;
515 tmp=lp_config_get_int(config,"net","download_bw",0);
516 linphone_core_set_download_bandwidth(lc,tmp);
517 tmp=lp_config_get_int(config,"net","upload_bw",0);
518 linphone_core_set_upload_bandwidth(lc,tmp);
519 linphone_core_set_stun_server(lc,lp_config_get_string(config,"net","stun_server",NULL));
520 tmpstr=lp_config_get_string(lc->config,"net","nat_address",NULL);
521 if (tmpstr!=NULL && (strlen(tmpstr)<1)) tmpstr=NULL;
522 linphone_core_set_nat_address(lc,tmpstr);
523 tmp=lp_config_get_int(lc->config,"net","firewall_policy",0);
524 linphone_core_set_firewall_policy(lc,tmp);
525 tmp=lp_config_get_int(lc->config,"net","nat_sdp_only",0);
526 lc->net_conf.nat_sdp_only=tmp;
527 tmp=lp_config_get_int(lc->config,"net","mtu",0);
528 linphone_core_set_mtu(lc,tmp);
529 tmp=lp_config_get_int(lc->config,"net","download_ptime",0);
530 linphone_core_set_download_ptime(lc,tmp);
534 static void build_sound_devices_table(LinphoneCore *lc){
535 const char **devices;
539 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
540 ndev=ms_list_size(elem);
541 devices=ms_malloc((ndev+1)*sizeof(const char *));
542 for (i=0;elem!=NULL;elem=elem->next,i++){
543 devices[i]=ms_snd_card_get_string_id((MSSndCard *)elem->data);
546 old=lc->sound_conf.cards;
547 lc->sound_conf.cards=devices;
548 if (old!=NULL) ms_free(old);
551 static void sound_config_read(LinphoneCore *lc)
558 /*alsadev let the user use custom alsa device within linphone*/
559 devid=lp_config_get_string(lc->config,"sound","alsadev",NULL);
561 MSSndCard *card=ms_alsa_card_new_custom(devid,devid);
562 ms_snd_card_manager_add_card(ms_snd_card_manager_get(),card);
565 /* retrieve all sound devices */
566 build_sound_devices_table(lc);
568 devid=lp_config_get_string(lc->config,"sound","playback_dev_id",NULL);
569 linphone_core_set_playback_device(lc,devid);
571 devid=lp_config_get_string(lc->config,"sound","ringer_dev_id",NULL);
572 linphone_core_set_ringer_device(lc,devid);
574 devid=lp_config_get_string(lc->config,"sound","capture_dev_id",NULL);
575 linphone_core_set_capture_device(lc,devid);
578 tmp=lp_config_get_int(lc->config,"sound","play_lev",80);
579 linphone_core_set_play_level(lc,tmp);
580 tmp=lp_config_get_int(lc->config,"sound","ring_lev",80);
581 linphone_core_set_ring_level(lc,tmp);
582 tmp=lp_config_get_int(lc->config,"sound","rec_lev",80);
583 linphone_core_set_rec_level(lc,tmp);
584 tmpbuf=lp_config_get_string(lc->config,"sound","source","m");
585 linphone_core_set_sound_source(lc,tmpbuf[0]);
588 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
589 tmpbuf=lp_config_get_string(lc->config,"sound","local_ring",tmpbuf);
590 if (ortp_file_exist(tmpbuf)==-1) {
591 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
593 if (strstr(tmpbuf,".wav")==NULL){
594 /* it currently uses old sound files, so replace them */
595 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
598 linphone_core_set_ring(lc,tmpbuf);
600 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
601 tmpbuf=lp_config_get_string(lc->config,"sound","remote_ring",tmpbuf);
602 if (ortp_file_exist(tmpbuf)==-1){
603 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
605 if (strstr(tmpbuf,".wav")==NULL){
606 /* it currently uses old sound files, so replace them */
607 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
609 linphone_core_set_ringback(lc,tmpbuf);
610 check_sound_device(lc);
611 lc->sound_conf.latency=0;
613 linphone_core_enable_echo_cancellation(lc,
614 lp_config_get_int(lc->config,"sound","echocancelation",0) |
615 lp_config_get_int(lc->config,"sound","echocancellation",0)
618 linphone_core_enable_echo_limiter(lc,
619 lp_config_get_int(lc->config,"sound","echolimiter",0));
620 linphone_core_enable_agc(lc,
621 lp_config_get_int(lc->config,"sound","agc",0));
623 gain=lp_config_get_float(lc->config,"sound","soft_play_lev",0);
624 linphone_core_set_soft_play_level(lc,gain);
627 static void sip_config_read(LinphoneCore *lc)
634 port=lp_config_get_int(lc->config,"sip","use_info",0);
635 linphone_core_set_use_info_for_dtmf(lc,port);
637 port=lp_config_get_int(lc->config,"sip","use_rfc2833",0);
638 linphone_core_set_use_rfc2833_for_dtmf(lc,port);
640 ipv6=lp_config_get_int(lc->config,"sip","use_ipv6",-1);
643 if (host_has_ipv6_network()){
644 lc->vtable.display_message(lc,_("Your machine appears to be connected to an IPv6 network. By default linphone always uses IPv4. Please update your configuration if you want to use IPv6"));
647 linphone_core_enable_ipv6(lc,ipv6);
648 port=lp_config_get_int(lc->config,"sip","sip_port",5060);
650 tmpstr=lp_config_get_string(lc->config,"sip","transport","udp");
651 if (strcmp("udp",tmpstr) == 0 ) {
652 lc->sip_conf.transport=SalTransportDatagram;
653 } else if (strcmp("tcp",tmpstr) == 0) {
654 lc->sip_conf.transport=SalTransportStream;
656 lc->sip_conf.transport=SalTransportDatagram;
657 ms_warning("unsupported transport, using udp");
659 /*start listening on port*/
660 linphone_core_set_sip_port(lc,port);
662 tmpstr=lp_config_get_string(lc->config,"sip","contact",NULL);
663 if (tmpstr==NULL || linphone_core_set_primary_contact(lc,tmpstr)==-1) {
664 const char *hostname=NULL;
665 const char *username=NULL;
667 hostname=getenv("HOST");
668 username=getenv("USER");
669 if (hostname==NULL) hostname=getenv("HOSTNAME");
670 #endif /*HAVE_GETENV*/
672 hostname="unknown-host";
676 contact=ortp_strdup_printf("sip:%s@%s",username,hostname);
677 linphone_core_set_primary_contact(lc,contact);
681 tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
682 linphone_core_set_guess_hostname(lc,tmp);
685 tmp=lp_config_get_int(lc->config,"sip","inc_timeout",15);
686 linphone_core_set_inc_timeout(lc,tmp);
688 /* get proxies config */
690 LinphoneProxyConfig *cfg=linphone_proxy_config_new_from_config_file(lc->config,i);
692 linphone_core_add_proxy_config(lc,cfg);
697 /* get the default proxy */
698 tmp=lp_config_get_int(lc->config,"sip","default_proxy",-1);
699 linphone_core_set_default_proxy_index(lc,tmp);
701 /* read authentication information */
703 LinphoneAuthInfo *ai=linphone_auth_info_new_from_config_file(lc->config,i);
705 linphone_core_add_auth_info(lc,ai);
706 linphone_auth_info_destroy(ai);
715 lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
717 /*for tuning or test*/
718 lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
719 lc->sip_conf.only_one_codec=lp_config_get_int(lc->config,"sip","only_one_codec",0);
720 lc->sip_conf.register_only_when_network_is_up=
721 lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",1);
722 lc->sip_conf.ping_with_options=lp_config_get_int(lc->config,"sip","ping_with_options",1);
723 lc->sip_conf.auto_net_state_mon=lp_config_get_int(lc->config,"sip","auto_net_state_mon",1);
724 lc->sip_conf.keepalive_period=lp_config_get_int(lc->config,"sip","keepalive_period",10000);
725 sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
728 static void rtp_config_read(LinphoneCore *lc)
733 port=lp_config_get_int(lc->config,"rtp","audio_rtp_port",7078);
734 linphone_core_set_audio_port(lc,port);
736 port=lp_config_get_int(lc->config,"rtp","video_rtp_port",9078);
737 if (port==0) port=9078;
738 linphone_core_set_video_port(lc,port);
740 jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
741 linphone_core_set_audio_jittcomp(lc,jitt_comp);
742 jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
743 nortp_timeout=lp_config_get_int(lc->config,"rtp","nortp_timeout",30);
744 linphone_core_set_nortp_timeout(lc,nortp_timeout);
747 static PayloadType * find_payload(RtpProfile *prof, const char *mime_type, int clock_rate, const char *recv_fmtp){
748 PayloadType *candidate=NULL;
752 it=rtp_profile_get_payload(prof,i);
753 if (it!=NULL && strcasecmp(mime_type,it->mime_type)==0
754 && (clock_rate==it->clock_rate || clock_rate<=0) ){
755 if ( (recv_fmtp && it->recv_fmtp && strstr(recv_fmtp,it->recv_fmtp)!=NULL) ||
756 (recv_fmtp==NULL && it->recv_fmtp==NULL) ){
758 if (recv_fmtp) payload_type_set_recv_fmtp(it,recv_fmtp);
762 if (it->recv_fmtp==NULL) candidate=it;
767 if (candidate && recv_fmtp){
768 payload_type_set_recv_fmtp(candidate,recv_fmtp);
773 static bool_t get_codec(LpConfig *config, char* type, int index, PayloadType **ret){
775 const char *mime,*fmtp;
780 snprintf(codeckey,50,"%s_%i",type,index);
781 mime=lp_config_get_string(config,codeckey,"mime",NULL);
782 if (mime==NULL || strlen(mime)==0 ) return FALSE;
784 rate=lp_config_get_int(config,codeckey,"rate",8000);
785 fmtp=lp_config_get_string(config,codeckey,"recv_fmtp",NULL);
786 enabled=lp_config_get_int(config,codeckey,"enabled",1);
787 pt=find_payload(&av_profile,mime,rate,fmtp);
788 if (pt && enabled ) pt->flags|=PAYLOAD_TYPE_ENABLED;
789 //ms_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
790 if (pt==NULL) ms_warning("Ignoring codec config %s/%i with fmtp=%s because unsupported",
791 mime,rate,fmtp ? fmtp : "");
796 static const char *codec_pref_order[]={
809 static int find_codec_rank(const char *mime){
811 for(i=0;codec_pref_order[i]!=NULL;++i){
812 if (strcasecmp(codec_pref_order[i],mime)==0)
818 static int codec_compare(const PayloadType *a, const PayloadType *b){
820 ra=find_codec_rank(a->mime_type);
821 rb=find_codec_rank(b->mime_type);
823 if (ra<rb) return -1;
827 static MSList *add_missing_codecs(SalStreamType mtype, MSList *l){
830 PayloadType *pt=rtp_profile_get_payload(&av_profile,i);
832 if (mtype==SalVideo && pt->type!=PAYLOAD_VIDEO)
834 else if (mtype==SalAudio && (pt->type!=PAYLOAD_AUDIO_PACKETIZED
835 && pt->type!=PAYLOAD_AUDIO_CONTINUOUS)){
838 if (pt && ms_filter_codec_supported(pt->mime_type)){
839 if (ms_list_find(l,pt)==NULL){
840 payload_type_set_flag(pt,PAYLOAD_TYPE_ENABLED);
841 ms_message("Adding new codec %s/%i with fmtp %s",
842 pt->mime_type,pt->clock_rate,pt->recv_fmtp ? pt->recv_fmtp : "");
843 l=ms_list_insert_sorted(l,pt,(int (*)(const void *, const void *))codec_compare);
851 static void codecs_config_read(LinphoneCore *lc)
855 MSList *audio_codecs=NULL;
856 MSList *video_codecs=NULL;
857 for (i=0;get_codec(lc->config,"audio_codec",i,&pt);i++){
859 if (!ms_filter_codec_supported(pt->mime_type)){
860 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
861 }else audio_codecs=ms_list_append(audio_codecs,pt);
864 audio_codecs=add_missing_codecs(SalAudio,audio_codecs);
865 for (i=0;get_codec(lc->config,"video_codec",i,&pt);i++){
867 if (!ms_filter_codec_supported(pt->mime_type)){
868 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
869 }else video_codecs=ms_list_append(video_codecs,(void *)pt);
872 video_codecs=add_missing_codecs(SalVideo,video_codecs);
873 linphone_core_set_audio_codecs(lc,audio_codecs);
874 linphone_core_set_video_codecs(lc,video_codecs);
875 linphone_core_update_allocated_audio_bandwidth(lc);
878 static void video_config_read(LinphoneCore *lc){
879 int capture, display, self_view;
883 const char **devices;
887 /* retrieve all video devices */
888 elem=ms_web_cam_manager_get_list(ms_web_cam_manager_get());
889 ndev=ms_list_size(elem);
890 devices=ms_malloc((ndev+1)*sizeof(const char *));
891 for (i=0;elem!=NULL;elem=elem->next,i++){
892 devices[i]=ms_web_cam_get_string_id((MSWebCam *)elem->data);
895 lc->video_conf.cams=devices;
897 str=lp_config_get_string(lc->config,"video","device",NULL);
898 if (str && str[0]==0) str=NULL;
899 linphone_core_set_video_device(lc,str);
901 linphone_core_set_preferred_video_size_by_name(lc,
902 lp_config_get_string(lc->config,"video","size","cif"));
904 enabled=lp_config_get_int(lc->config,"video","enabled",1);
905 capture=lp_config_get_int(lc->config,"video","capture",enabled);
906 display=lp_config_get_int(lc->config,"video","display",enabled);
907 self_view=lp_config_get_int(lc->config,"video","self_view",enabled);
909 linphone_core_enable_video(lc,capture,display);
910 linphone_core_enable_self_view(lc,self_view);
914 static void ui_config_read(LinphoneCore *lc)
918 for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
919 linphone_core_add_friend(lc,lf);
921 call_logs_read_from_config_file(lc);
925 static void autoreplier_config_init(LinphoneCore *lc)
927 autoreplier_config_t *config=&lc->autoreplier_conf;
928 config->enabled=lp_config_get_int(lc->config,"autoreplier","enabled",0);
929 config->after_seconds=lp_config_get_int(lc->config,"autoreplier","after_seconds",6);
930 config->max_users=lp_config_get_int(lc->config,"autoreplier","max_users",1);
931 config->max_rec_time=lp_config_get_int(lc->config,"autoreplier","max_rec_time",60);
932 config->max_rec_msg=lp_config_get_int(lc->config,"autoreplier","max_rec_msg",10);
933 config->message=lp_config_get_string(lc->config,"autoreplier","message",NULL);
938 * Sets maximum available download bandwidth
940 * @ingroup media_parameters
942 * This is IP bandwidth, in kbit/s.
943 * This information is used signaled to other parties during
944 * calls (within SDP messages) so that the remote end can have
945 * sufficient knowledge to properly configure its audio & video
946 * codec output bitrate to not overflow available bandwidth.
948 * @param lc the LinphoneCore object
949 * @param bw the bandwidth in kbits/s, 0 for infinite
951 void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
952 lc->net_conf.download_bw=bw;
953 if (bw==0){ /*infinite*/
957 lc->dw_audio_bw=MIN(lc->audio_bw,bw);
958 lc->dw_video_bw=MAX(bw-lc->dw_audio_bw-10,0);/*-10: security margin*/
963 * Sets maximum available upload bandwidth
965 * @ingroup media_parameters
967 * This is IP bandwidth, in kbit/s.
968 * This information is used by liblinphone together with remote
969 * side available bandwidth signaled in SDP messages to properly
970 * configure audio & video codec's output bitrate.
972 * @param lc the LinphoneCore object
973 * @param bw the bandwidth in kbits/s, 0 for infinite
975 void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
976 lc->net_conf.upload_bw=bw;
977 if (bw==0){ /*infinite*/
981 lc->up_audio_bw=MIN(lc->audio_bw,bw);
982 lc->up_video_bw=MAX(bw-lc->up_audio_bw-10,0);/*-10: security margin*/
987 * Retrieve the maximum available download bandwidth.
989 * @ingroup media_parameters
991 * This value was set by linphone_core_set_download_bandwidth().
994 int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
995 return lc->net_conf.download_bw;
999 * Retrieve the maximum available upload bandwidth.
1001 * @ingroup media_parameters
1003 * This value was set by linphone_core_set_upload_bandwidth().
1006 int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
1007 return lc->net_conf.upload_bw;
1010 * set audio packetization time linphone expect to received from peer
1012 void linphone_core_set_download_ptime(LinphoneCore *lc, int ptime) {
1013 lc->net_conf.down_ptime=ptime;
1016 int linphone_core_get_download_ptime(LinphoneCore *lc) {
1017 return lc->net_conf.down_ptime;
1022 * Returns liblinphone's version as a string.
1027 const char * linphone_core_get_version(void){
1028 return liblinphone_version;
1032 static MSList *linphone_payload_types=NULL;
1034 static void linphone_core_assign_payload_type(PayloadType *const_pt, int number, const char *recv_fmtp){
1036 pt=payload_type_clone(const_pt);
1037 payload_type_set_number(pt,number);
1038 if (recv_fmtp!=NULL) payload_type_set_recv_fmtp(pt,recv_fmtp);
1039 rtp_profile_set_payload(&av_profile,number,pt);
1040 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
1043 static void linphone_core_free_payload_types(void){
1044 ms_list_for_each(linphone_payload_types,(void (*)(void*))payload_type_destroy);
1045 ms_list_free(linphone_payload_types);
1046 linphone_payload_types=NULL;
1049 static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path,
1050 const char *factory_config_path, void * userdata)
1052 memset (lc, 0, sizeof (LinphoneCore));
1055 memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
1057 gstate_initialize(lc);
1058 gstate_new_state(lc, GSTATE_POWER_STARTUP, NULL);
1061 linphone_core_assign_payload_type(&payload_type_pcmu8000,0,NULL);
1062 linphone_core_assign_payload_type(&payload_type_gsm,3,NULL);
1063 linphone_core_assign_payload_type(&payload_type_pcma8000,8,NULL);
1064 linphone_core_assign_payload_type(&payload_type_lpc1015,115,NULL);
1065 linphone_core_assign_payload_type(&payload_type_speex_nb,110,"vbr=on");
1066 linphone_core_assign_payload_type(&payload_type_speex_wb,111,"vbr=on");
1067 linphone_core_assign_payload_type(&payload_type_speex_uwb,112,"vbr=on");
1068 linphone_core_assign_payload_type(&payload_type_telephone_event,101,"0-11");
1069 linphone_core_assign_payload_type(&payload_type_ilbc,113,"mode=30");
1070 linphone_core_assign_payload_type(&payload_type_amr,114,"octet-align=1");
1072 #ifdef ENABLE_NONSTANDARD_GSM
1075 pt=payload_type_clone(&payload_type_gsm);
1076 pt->clock_rate=11025;
1077 rtp_profile_set_payload(&av_profile,114,pt);
1078 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
1079 pt=payload_type_clone(&payload_type_gsm);
1080 pt->clock_rate=22050;
1081 rtp_profile_set_payload(&av_profile,115,pt);
1082 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
1086 #ifdef VIDEO_ENABLED
1087 linphone_core_assign_payload_type(&payload_type_h263,34,NULL);
1088 linphone_core_assign_payload_type(&payload_type_theora,97,NULL);
1089 linphone_core_assign_payload_type(&payload_type_h263_1998,98,"CIF=1;QCIF=1");
1090 linphone_core_assign_payload_type(&payload_type_mp4v,99,"profile-level-id=3");
1091 linphone_core_assign_payload_type(&payload_type_x_snow,100,NULL);
1092 linphone_core_assign_payload_type(&payload_type_h264,102,NULL);
1093 linphone_core_assign_payload_type(&payload_type_h264,103,"packetization-mode=1");
1098 lc->config=lp_config_new(config_path);
1099 if (factory_config_path)
1100 lp_config_read_file(lc->config,factory_config_path);
1103 sal_set_user_pointer(lc->sal,lc);
1104 sal_set_callbacks(lc->sal,&linphone_sal_callbacks);
1105 if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
1106 sal_use_session_timers(lc->sal,200);
1108 sip_setup_register_all();
1109 sound_config_read(lc);
1110 net_config_read(lc);
1111 rtp_config_read(lc);
1112 codecs_config_read(lc);
1113 sip_config_read(lc); /* this will start eXosip*/
1114 video_config_read(lc);
1115 //autoreplier_config_init(&lc->autoreplier_conf);
1116 lc->prev_mode=LINPHONE_STATUS_ONLINE;
1117 lc->presence_mode=LINPHONE_STATUS_ONLINE;
1118 lc->max_call_logs=15;
1120 lc->vtable.display_status(lc,_("Ready"));
1121 gstate_new_state(lc, GSTATE_POWER_ON, NULL);
1122 lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
1128 * Instanciates a LinphoneCore object.
1129 * @ingroup initializing
1131 * The LinphoneCore object is the primary handle for doing all phone actions.
1132 * It should be unique within your application.
1133 * @param vtable a LinphoneCoreVTable structure holding your application callbacks
1134 * @param config_path a path to a config file. If it does not exists it will be created.
1135 * The config file is used to store all user settings, call logs, friends, proxies...
1136 * @param factory_config_path a path to a read-only config file that can be used to
1137 * to store hard-coded preference such as proxy settings or internal preferences.
1138 * The settings in this factory file always override the one in the normal config file.
1139 * It is OPTIONAL, use NULL if unneeded.
1140 * @param userdata an opaque user pointer that can be retrieved at any time (for example in
1141 * callbacks) using linphone_core_get_user_data().
1144 LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
1145 const char *config_path, const char *factory_config_path, void * userdata)
1147 LinphoneCore *core=ms_new(LinphoneCore,1);
1148 linphone_core_init(core,vtable,config_path, factory_config_path, userdata);
1153 * Returns the list of available audio codecs.
1155 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1156 * structure holding the codec information.
1157 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1158 * (such as the order of codecs).
1160 const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
1162 return lc->codecs_conf.audio_codecs;
1166 * Returns the list of available video codecs.
1168 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1169 * structure holding the codec information.
1170 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1171 * (such as the order of codecs).
1173 const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
1175 return lc->codecs_conf.video_codecs;
1179 * Sets the local "from" identity.
1182 * This data is used in absence of any proxy configuration or when no
1183 * default proxy configuration is set. See LinphoneProxyConfig
1185 int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact)
1187 LinphoneAddress *ctt;
1189 if ((ctt=linphone_address_new(contact))==0) {
1190 ms_error("Bad contact url: %s",contact);
1193 if (lc->sip_conf.contact!=NULL) ms_free(lc->sip_conf.contact);
1194 lc->sip_conf.contact=ms_strdup(contact);
1195 if (lc->sip_conf.guessed_contact!=NULL){
1196 ms_free(lc->sip_conf.guessed_contact);
1197 lc->sip_conf.guessed_contact=NULL;
1199 linphone_address_destroy(ctt);
1204 /*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
1205 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
1206 if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
1207 strncpy(result,linphone_core_get_nat_address(lc),LINPHONE_IPADDR_SIZE);
1210 if (linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,dest,result)==0)
1212 /*else fallback to SAL routine that will attempt to find the most realistic interface */
1213 sal_get_default_local_ip(lc->sal,lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,result,LINPHONE_IPADDR_SIZE);
1216 static void update_primary_contact(LinphoneCore *lc){
1218 char tmp[LINPHONE_IPADDR_SIZE];
1220 LinphoneAddress *url;
1221 if (lc->sip_conf.guessed_contact!=NULL){
1222 ms_free(lc->sip_conf.guessed_contact);
1223 lc->sip_conf.guessed_contact=NULL;
1225 url=linphone_address_new(lc->sip_conf.contact);
1227 ms_error("Could not parse identity contact !");
1228 url=linphone_address_new("sip:unknown@unkwownhost");
1230 linphone_core_get_local_ip(lc, NULL, tmp);
1231 if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
1232 ms_warning("Local loopback network only !");
1233 lc->sip_conf.loopback_only=TRUE;
1234 }else lc->sip_conf.loopback_only=FALSE;
1235 linphone_address_set_domain(url,tmp);
1236 linphone_address_set_port_int(url,lc->sip_conf.sip_port);
1237 guessed=linphone_address_as_string(url);
1238 lc->sip_conf.guessed_contact=guessed;
1239 linphone_address_destroy(url);
1243 * Returns the default identity when no proxy configuration is used.
1247 const char *linphone_core_get_primary_contact(LinphoneCore *lc){
1250 if (lc->sip_conf.guess_hostname){
1251 if (lc->sip_conf.guessed_contact==NULL || lc->sip_conf.loopback_only){
1252 update_primary_contact(lc);
1254 identity=lc->sip_conf.guessed_contact;
1256 identity=lc->sip_conf.contact;
1262 * Tells LinphoneCore to guess local hostname automatically in primary contact.
1266 void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
1267 lc->sip_conf.guess_hostname=val;
1271 * Returns TRUE if hostname part of primary contact is guessed automatically.
1275 bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
1276 return lc->sip_conf.guess_hostname;
1280 * Same as linphone_core_get_primary_contact() but the result is a LinphoneAddress object
1281 * instead of const char*
1285 LinphoneAddress *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
1286 return linphone_address_new(linphone_core_get_primary_contact(lc));
1290 * Sets the list of audio codecs.
1292 * @ingroup media_parameters
1293 * The list is taken by the LinphoneCore thus the application should not free it.
1294 * This list is made of struct PayloadType describing the codec parameters.
1296 int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
1298 if (lc->codecs_conf.audio_codecs!=NULL) ms_list_free(lc->codecs_conf.audio_codecs);
1299 lc->codecs_conf.audio_codecs=codecs;
1304 * Sets the list of video codecs.
1306 * @ingroup media_parameters
1307 * The list is taken by the LinphoneCore thus the application should not free it.
1308 * This list is made of struct PayloadType describing the codec parameters.
1310 int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
1312 if (lc->codecs_conf.video_codecs!=NULL) ms_list_free(lc->codecs_conf.video_codecs);
1313 lc->codecs_conf.video_codecs=codecs;
1317 const MSList * linphone_core_get_friend_list(const LinphoneCore *lc)
1323 * Returns the nominal jitter buffer size in milliseconds.
1325 * @ingroup media_parameters
1327 int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
1329 return lc->rtp_conf.audio_jitt_comp;
1333 * Returns the UDP port used for audio streaming.
1335 * @ingroup network_parameters
1337 int linphone_core_get_audio_port(const LinphoneCore *lc)
1339 return lc->rtp_conf.audio_rtp_port;
1343 * Returns the UDP port used for video streaming.
1345 * @ingroup network_parameters
1347 int linphone_core_get_video_port(const LinphoneCore *lc){
1348 return lc->rtp_conf.video_rtp_port;
1353 * Returns the value in seconds of the no-rtp timeout.
1355 * @ingroup media_parameters
1356 * When no RTP or RTCP packets have been received for a while
1357 * LinphoneCore will consider the call is broken (remote end crashed or
1358 * disconnected from the network), and thus will terminate the call.
1359 * The no-rtp timeout is the duration above which the call is considered broken.
1361 int linphone_core_get_nortp_timeout(const LinphoneCore *lc){
1362 return lc->rtp_conf.nortp_timeout;
1366 * Sets the nominal audio jitter buffer size in milliseconds.
1368 * @ingroup media_parameters
1370 void linphone_core_set_audio_jittcomp(LinphoneCore *lc, int value)
1372 lc->rtp_conf.audio_jitt_comp=value;
1376 * Sets the UDP port used for audio streaming.
1378 * @ingroup network_parameters
1380 void linphone_core_set_audio_port(LinphoneCore *lc, int port)
1382 lc->rtp_conf.audio_rtp_port=port;
1386 * Sets the UDP port used for video streaming.
1388 * @ingroup network_parameters
1390 void linphone_core_set_video_port(LinphoneCore *lc, int port){
1391 lc->rtp_conf.video_rtp_port=port;
1395 * Sets the no-rtp timeout value in seconds.
1397 * @ingroup media_parameters
1398 * See linphone_core_get_nortp_timeout() for details.
1400 void linphone_core_set_nortp_timeout(LinphoneCore *lc, int nortp_timeout){
1401 lc->rtp_conf.nortp_timeout=nortp_timeout;
1405 * Indicates whether SIP INFO is used for sending digits.
1407 * @ingroup media_parameters
1409 bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
1411 return lc->sip_conf.use_info;
1415 * Sets whether SIP INFO is to be used for sending digits.
1417 * @ingroup media_parameters
1419 void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
1421 lc->sip_conf.use_info=use_info;
1425 * Indicates whether RFC2833 is used for sending digits.
1427 * @ingroup media_parameters
1429 bool_t linphone_core_get_use_rfc2833_for_dtmf(LinphoneCore *lc)
1431 return lc->sip_conf.use_rfc2833;
1435 * Sets whether RFC2833 is to be used for sending digits.
1437 * @ingroup media_parameters
1439 void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833)
1441 lc->sip_conf.use_rfc2833=use_rfc2833;
1445 * Returns the UDP port used by SIP.
1447 * @ingroup network_parameters
1449 int linphone_core_get_sip_port(LinphoneCore *lc)
1451 return lc->sip_conf.sip_port;
1454 static char _ua_name[64]="Linphone";
1455 static char _ua_version[64]=LINPHONE_VERSION;
1457 #ifdef HAVE_EXOSIP_GET_VERSION
1458 extern const char *eXosip_get_version();
1461 static void apply_user_agent(LinphoneCore *lc){
1462 char ua_string[256];
1463 snprintf(ua_string,sizeof(ua_string)-1,"%s/%s (eXosip2/%s)",_ua_name,_ua_version,
1464 #ifdef HAVE_EXOSIP_GET_VERSION
1465 eXosip_get_version()
1470 if (lc->sal) sal_set_user_agent(lc->sal,ua_string);
1474 * Sets the user agent string used in SIP messages.
1478 void linphone_core_set_user_agent(const char *name, const char *ver){
1479 strncpy(_ua_name,name,sizeof(_ua_name)-1);
1480 strncpy(_ua_version,ver,sizeof(_ua_version));
1484 * Sets the UDP port to be used by SIP.
1486 * @ingroup network_parameters
1488 void linphone_core_set_sip_port(LinphoneCore *lc,int port)
1490 const char *anyaddr;
1492 if (port==lc->sip_conf.sip_port) return;
1493 lc->sip_conf.sip_port=port;
1495 if (lc->sal==NULL) return;
1497 if (lc->sip_conf.ipv6_enabled)
1503 err=sal_listen_port (lc->sal,anyaddr,port, lc->sip_conf.transport,FALSE);
1505 char *msg=ortp_strdup_printf("Port %i seems already in use ! Cannot initialize.",port);
1507 lc->vtable.display_warning(lc,msg);
1511 apply_user_agent(lc);
1515 * Returns TRUE if IPv6 is enabled.
1517 * @ingroup network_parameters
1518 * See linphone_core_enable_ipv6() for more details on how IPv6 is supported in liblinphone.
1520 bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
1521 return lc->sip_conf.ipv6_enabled;
1525 * Turns IPv6 support on or off.
1527 * @ingroup network_parameters
1529 * @note IPv6 support is exclusive with IPv4 in liblinphone:
1530 * when IPv6 is turned on, IPv4 calls won't be possible anymore.
1531 * By default IPv6 support is off.
1533 void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
1534 if (lc->sip_conf.ipv6_enabled!=val){
1535 lc->sip_conf.ipv6_enabled=val;
1537 /* we need to restart eXosip */
1538 linphone_core_set_sip_port(lc, lc->sip_conf.sip_port);
1543 static void display_bandwidth(RtpSession *as, RtpSession *vs){
1544 ms_message("bandwidth usage: audio=[d=%.1f,u=%.1f] video=[d=%.1f,u=%.1f] kbit/sec",
1545 (as!=NULL) ? (rtp_session_compute_recv_bandwidth(as)*1e-3) : 0,
1546 (as!=NULL) ? (rtp_session_compute_send_bandwidth(as)*1e-3) : 0,
1547 (vs!=NULL) ? (rtp_session_compute_recv_bandwidth(vs)*1e-3) : 0,
1548 (vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0);
1551 static void linphone_core_disconnected(LinphoneCore *lc){
1552 lc->vtable.display_warning(lc,_("Remote end seems to have disconnected, the call is going to be closed."));
1553 linphone_core_terminate_call(lc,NULL);
1556 static void monitor_network_state(LinphoneCore *lc, time_t curtime){
1557 static time_t last_check=0;
1558 static bool_t last_status=FALSE;
1559 char result[LINPHONE_IPADDR_SIZE];
1560 bool_t new_status=last_status;
1562 /* only do the network up checking every five seconds */
1563 if (last_check==0 || (curtime-last_check)>=5){
1564 linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,NULL,result);
1565 if (strcmp(result,"::1")!=0 && strcmp(result,"127.0.0.1")!=0){
1567 }else new_status=FALSE;
1569 if (new_status!=last_status) {
1571 ms_message("New local ip address is %s",result);
1573 set_network_reachable(lc,new_status);
1574 last_status=new_status;
1579 static void proxy_update(LinphoneCore *lc){
1580 ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
1583 static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){
1584 LinphoneFriend *lf=linphone_core_get_friend_by_address(lc,info->sip_uri);
1587 ms_message("%s has a BuddyInfo assigned with image %p",info->sip_uri, info->image_data);
1588 if (lc->vtable.buddy_info_updated)
1589 lc->vtable.buddy_info_updated(lc,lf);
1591 ms_warning("Could not any friend with uri %s",info->sip_uri);
1595 static void analyze_buddy_lookup_results(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1597 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1598 for (elem=lc->bl_reqs;elem!=NULL;elem=ms_list_next(elem)){
1599 BuddyLookupRequest *req=(BuddyLookupRequest *)elem->data;
1600 if (req->status==BuddyLookupDone || req->status==BuddyLookupFailure){
1601 if (req->results!=NULL){
1602 BuddyInfo *i=(BuddyInfo*)req->results->data;
1603 ms_list_free(req->results);
1605 assign_buddy_info(lc,i);
1607 sip_setup_context_buddy_lookup_free(ctx,req);
1611 /*purge completed requests */
1612 while((elem=ms_list_find(lc->bl_reqs,NULL))!=NULL){
1613 lc->bl_reqs=ms_list_remove_link(lc->bl_reqs,elem);
1617 static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1619 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1620 for(elem=linphone_core_get_friend_list(lc);elem!=NULL;elem=elem->next){
1621 LinphoneFriend *lf=(LinphoneFriend*)elem->data;
1622 if (lf->info==NULL){
1623 if (linphone_core_lookup_known_proxy(lc,lf->uri)==cfg){
1624 if (linphone_address_get_username(lf->uri)!=NULL){
1625 BuddyLookupRequest *req;
1626 char *tmp=linphone_address_as_string_uri_only(lf->uri);
1627 req=sip_setup_context_create_buddy_lookup_request(ctx);
1628 buddy_lookup_request_set_key(req,tmp);
1629 buddy_lookup_request_set_max_results(req,1);
1630 sip_setup_context_buddy_lookup_submit(ctx,req);
1631 lc->bl_reqs=ms_list_append(lc->bl_reqs,req);
1639 static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
1640 LinphoneProxyConfig *cfg=NULL;
1641 linphone_core_get_default_proxy(lc,&cfg);
1643 if (lc->bl_refresh){
1644 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1645 if (ctx && (sip_setup_context_get_capabilities(ctx) & SIP_SETUP_CAP_BUDDY_LOOKUP)){
1646 linphone_core_grab_buddy_infos(lc,cfg);
1647 lc->bl_refresh=FALSE;
1650 if (lc->bl_reqs) analyze_buddy_lookup_results(lc,cfg);
1655 * Main loop function. It is crucial that your application call it periodically.
1657 * @ingroup initializing
1658 * linphone_core_iterate() performs various backgrounds tasks:
1659 * - receiving of SIP messages
1660 * - handles timers and timeout
1661 * - performs registration to proxies
1662 * - authentication retries
1663 * The application MUST call this function from periodically, in its main loop.
1664 * Be careful that this function must be call from the same thread as
1665 * other liblinphone methods. In not the case make sure all liblinphone calls are
1666 * serialized with a mutex.
1668 void linphone_core_iterate(LinphoneCore *lc){
1669 int disconnect_timeout = linphone_core_get_nortp_timeout(lc);
1670 time_t curtime=time(NULL);
1672 bool_t one_second_elapsed=FALSE;
1673 bool_t disconnected=FALSE;
1675 if (curtime-lc->prevtime>=1){
1676 lc->prevtime=curtime;
1677 one_second_elapsed=TRUE;
1680 if (lc->preview_finished){
1681 lc->preview_finished=0;
1682 ring_stop(lc->ringstream);
1683 lc->ringstream=NULL;
1684 lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
1687 sal_iterate(lc->sal);
1688 if (lc->auto_net_state_mon) monitor_network_state(lc,curtime);
1692 if (lc->call!=NULL){
1693 LinphoneCall *call=lc->call;
1694 if (call->state==LCStatePreEstablishing && (curtime-call->start_time>=2)){
1695 /*start the call even if the OPTIONS reply did not arrive*/
1696 linphone_core_start_invite(lc,call,NULL);
1698 if (call->dir==LinphoneCallIncoming && call->state==LCStateRinging){
1699 elapsed=curtime-call->start_time;
1700 ms_message("incoming call ringing for %i seconds",elapsed);
1701 if (elapsed>lc->sip_conf.inc_timeout){
1702 linphone_core_terminate_call(lc,NULL);
1704 }else if (call->state==LCStateAVRunning){
1705 if (one_second_elapsed){
1706 RtpSession *as=NULL,*vs=NULL;
1707 lc->prevtime=curtime;
1708 if (lc->audiostream!=NULL)
1709 as=lc->audiostream->session;
1710 if (lc->videostream!=NULL)
1711 vs=lc->videostream->session;
1712 display_bandwidth(as,vs);
1714 #ifdef VIDEO_ENABLED
1715 if (lc->videostream!=NULL)
1716 video_stream_iterate(lc->videostream);
1718 if (lc->audiostream!=NULL && disconnect_timeout>0)
1719 disconnected=!audio_stream_alive(lc->audiostream,disconnect_timeout);
1722 if (linphone_core_video_preview_enabled(lc)){
1723 if (lc->previewstream==NULL)
1724 toggle_video_preview(lc,TRUE);
1725 #ifdef VIDEO_ENABLED
1726 else video_stream_iterate(lc->previewstream);
1729 if (lc->previewstream!=NULL)
1730 toggle_video_preview(lc,FALSE);
1733 linphone_core_disconnected(lc);
1735 linphone_core_do_plugin_tasks(lc);
1737 if (one_second_elapsed && lp_config_needs_commit(lc->config)){
1738 lp_config_sync(lc->config);
1743 * Interpret a call destination as supplied by the user, and returns a fully qualified
1746 * A sip address should look like DisplayName <sip:username@domain:port> .
1747 * Basically this function performs the following tasks
1748 * - if a phone number is entered, prepend country prefix of the default proxy
1749 * configuration, eventually escape the '+' by 00.
1750 * - if no domain part is supplied, append the domain name of the default proxy
1751 * - if no sip: is present, prepend it
1753 * The result is a syntaxically correct SIP address.
1756 LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url){
1757 enum_lookup_res_t *enumres=NULL;
1758 char *enum_domain=NULL;
1759 LinphoneProxyConfig *proxy=lc->default_proxy;;
1761 LinphoneAddress *uri;
1763 if (is_enum(url,&enum_domain)){
1764 lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
1765 if (enum_lookup(enum_domain,&enumres)<0){
1766 lc->vtable.display_status(lc,_("Could not resolve this number."));
1767 ms_free(enum_domain);
1770 ms_free(enum_domain);
1771 tmpurl=enumres->sip_address[0];
1772 uri=linphone_address_new(tmpurl);
1773 enum_lookup_res_free(enumres);
1776 /* check if we have a "sip:" */
1777 if (strstr(url,"sip:")==NULL){
1778 /* this doesn't look like a true sip uri */
1779 if (strchr(url,'@')!=NULL){
1780 /* seems like sip: is missing !*/
1781 tmpurl=ms_strdup_printf("sip:%s",url);
1782 uri=linphone_address_new(tmpurl);
1790 /* append the proxy domain suffix */
1791 const char *identity=linphone_proxy_config_get_identity(proxy);
1792 char normalized_username[128];
1793 uri=linphone_address_new(identity);
1797 linphone_address_set_display_name(uri,NULL);
1798 linphone_proxy_config_normalize_number(proxy,url,normalized_username,
1799 sizeof(normalized_username));
1800 linphone_address_set_username(uri,normalized_username);
1804 uri=linphone_address_new(url);
1808 /* else we could not do anything with url given by user, so display an error */
1809 if (lc->vtable.display_warning!=NULL){
1810 lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
1816 * Returns the default identity SIP address.
1819 * This is an helper function:
1821 * If no default proxy is set, this will return the primary contact (
1822 * see linphone_core_get_primary_contact() ). If a default proxy is set
1823 * it returns the registered identity on the proxy.
1825 const char * linphone_core_get_identity(LinphoneCore *lc){
1826 LinphoneProxyConfig *proxy=NULL;
1828 linphone_core_get_default_proxy(lc,&proxy);
1830 from=linphone_proxy_config_get_identity(proxy);
1831 }else from=linphone_core_get_primary_contact(lc);
1835 const char * linphone_core_get_route(LinphoneCore *lc){
1836 LinphoneProxyConfig *proxy=NULL;
1837 const char *route=NULL;
1838 linphone_core_get_default_proxy(lc,&proxy);
1840 route=linphone_proxy_config_get_route(proxy);
1845 bool_t linphone_core_is_in_communication_with(LinphoneCore *lc, const char *to)
1849 const LinphoneAddress *la=linphone_core_get_remote_uri(lc);
1854 tmp = linphone_address_as_string(la);
1864 LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
1866 LinphoneProxyConfig *found_cfg=NULL;
1867 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=elem->next){
1868 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1869 const char *domain=linphone_proxy_config_get_domain(cfg);
1870 if (domain!=NULL && strcmp(domain,linphone_address_get_domain(uri))==0){
1878 static char *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){
1879 LinphoneAddress *ctt;
1880 const char *localip=call->localip;
1882 /* first use user's supplied ip address if asked*/
1883 if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
1884 ctt=linphone_core_get_primary_contact_parsed(lc);
1885 return ms_strdup_printf("sip:%s@%s",linphone_address_get_username(ctt),
1886 linphone_core_get_nat_address(lc));
1889 /* if already choosed, don't change it */
1890 if (call->op && sal_op_get_contact(call->op)!=NULL){
1894 /* if the ping OPTIONS request succeeded use the contact guessed from the
1897 const char *guessed=sal_op_get_contact(call->ping_op);
1899 ms_message("Contact has been fixed using OPTIONS to %s",guessed);
1900 return ms_strdup(guessed);
1904 /*if using a proxy, use the contact address as guessed with the REGISTERs*/
1905 if (dest_proxy && dest_proxy->op){
1906 const char *fixed_contact=sal_op_get_contact(dest_proxy->op);
1907 if (fixed_contact) {
1908 ms_message("Contact has been fixed using proxy to %s",fixed_contact);
1909 return ms_strdup(fixed_contact);
1913 ctt=linphone_core_get_primary_contact_parsed(lc);
1917 /*otherwise use supllied localip*/
1918 linphone_address_set_domain(ctt,localip);
1919 linphone_address_set_port_int(ctt,linphone_core_get_sip_port(lc));
1920 ret=linphone_address_as_string_uri_only(ctt);
1921 linphone_address_destroy(ctt);
1922 ms_message("Contact has been fixed using local ip to %s",ret);
1928 int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphoneProxyConfig *dest_proxy){
1931 char *real_url,*barmsg;
1933 /*try to be best-effort in giving real local or routable contact address */
1934 contact=get_fixed_contact(lc,call,dest_proxy);
1936 sal_op_set_contact(call->op, contact);
1939 call->state=LCStateInit;
1940 linphone_core_init_media_streams(lc,lc->call);
1941 if (!lc->sip_conf.sdp_200_ack){
1942 call->media_pending=TRUE;
1943 sal_call_set_local_media_description(call->op,call->localdesc);
1945 real_url=linphone_address_as_string(call->log->to);
1946 from=linphone_address_as_string(call->log->from);
1947 err=sal_call(call->op,from,real_url);
1949 if (lc->sip_conf.sdp_200_ack){
1950 call->media_pending=TRUE;
1951 sal_call_set_local_media_description(call->op,call->localdesc);
1953 barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
1954 lc->vtable.display_status(lc,barmsg);
1958 ms_warning("Could not initiate call.");
1959 lc->vtable.display_status(lc,_("could not call"));
1960 linphone_core_stop_media_streams(lc,call);
1961 linphone_call_destroy(call);
1963 }else gstate_new_state(lc, GSTATE_CALL_OUT_INVITE, real_url);
1970 * Initiates an outgoing call
1972 * @ingroup call_control
1973 * @param lc the LinphoneCore object
1974 * @param url the destination of the call (sip address, or phone number).
1976 int linphone_core_invite(LinphoneCore *lc, const char *url){
1977 LinphoneAddress *addr=linphone_core_interpret_url(lc,url);
1980 err=linphone_core_invite_address(lc,addr);
1981 linphone_address_destroy(addr);
1988 * Initiates an outgoing call given a destination LinphoneAddress
1990 * @ingroup call_control
1991 * @param lc the LinphoneCore object
1992 * @param url the destination of the call (sip address).
1994 int linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *real_parsed_url)
1997 const char *route=NULL;
1998 const char *from=NULL;
1999 LinphoneProxyConfig *proxy=NULL;
2000 LinphoneAddress *parsed_url2=NULL;
2001 char *real_url=NULL;
2002 LinphoneProxyConfig *dest_proxy=NULL;
2005 if (lc->call!=NULL){
2006 lc->vtable.display_warning(lc,_("Sorry, having multiple simultaneous calls is not supported yet !"));
2010 linphone_core_get_default_proxy(lc,&proxy);
2011 route=linphone_core_get_route(lc);
2013 real_url=linphone_address_as_string(real_parsed_url);
2014 dest_proxy=linphone_core_lookup_known_proxy(lc,real_parsed_url);
2016 if (proxy!=dest_proxy && dest_proxy!=NULL) {
2017 ms_message("Overriding default proxy setting for this call:");
2018 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
2021 if (dest_proxy!=NULL)
2022 from=linphone_proxy_config_get_identity(dest_proxy);
2023 else if (proxy!=NULL)
2024 from=linphone_proxy_config_get_identity(proxy);
2026 /* if no proxy or no identity defined for this proxy, default to primary contact*/
2027 if (from==NULL) from=linphone_core_get_primary_contact(lc);
2029 parsed_url2=linphone_address_new(from);
2031 call=linphone_call_new_outgoing(lc,parsed_url2,linphone_address_clone(real_parsed_url));
2032 sal_op_set_route(call->op,route);
2035 if (dest_proxy!=NULL || lc->sip_conf.ping_with_options==FALSE){
2036 err=linphone_core_start_invite(lc,call,dest_proxy);
2038 /*defer the start of the call after the OPTIONS ping*/
2039 call->state=LCStatePreEstablishing;
2040 call->ping_op=sal_op_new(lc->sal);
2041 sal_ping(call->ping_op,from,real_url);
2042 sal_op_set_user_pointer(call->ping_op,call);
2043 call->start_time=time(NULL);
2046 if (real_url!=NULL) ms_free(real_url);
2050 int linphone_core_refer(LinphoneCore *lc, const char *url)
2052 char *real_url=NULL;
2053 LinphoneAddress *real_parsed_url=linphone_core_interpret_url(lc,url);
2056 if (!real_parsed_url){
2062 ms_warning("No established call to refer.");
2065 //lc->call=NULL; //Do not do that you will lose the call afterward . . .
2066 real_url=linphone_address_as_string (real_parsed_url);
2067 sal_refer(call->op,real_url);
2073 * Returns true if in incoming call is pending, ie waiting for being answered or declined.
2075 * @ingroup call_control
2077 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
2078 if (lc->call!=NULL && lc->call->dir==LinphoneCallIncoming){
2084 void linphone_core_init_media_streams(LinphoneCore *lc, LinphoneCall *call){
2085 SalMediaDescription *md=call->localdesc;
2086 lc->audiostream=audio_stream_new(md->streams[0].port,linphone_core_ipv6_enabled(lc));
2087 if (linphone_core_echo_limiter_enabled(lc)){
2088 const char *type=lp_config_get_string(lc->config,"sound","el_type","mic");
2089 if (strcasecmp(type,"mic")==0)
2090 audio_stream_enable_echo_limiter(lc->audiostream,ELControlMic);
2091 else if (strcasecmp(type,"speaker")==0)
2092 audio_stream_enable_echo_limiter(lc->audiostream,ELControlSpeaker);
2094 audio_stream_enable_gain_control(lc->audiostream,TRUE);
2095 if (linphone_core_echo_cancellation_enabled(lc)){
2096 int len,delay,framesize;
2097 len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
2098 delay=lp_config_get_int(lc->config,"sound","ec_delay",0);
2099 framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0);
2100 audio_stream_set_echo_canceller_params(lc->audiostream,len,delay,framesize);
2102 audio_stream_enable_automatic_gain_control(lc->audiostream,linphone_core_agc_enabled(lc));
2104 int enabled=lp_config_get_int(lc->config,"sound","noisegate",0);
2105 audio_stream_enable_noise_gate(lc->audiostream,enabled);
2108 rtp_session_set_transports(lc->audiostream->session,lc->a_rtp,lc->a_rtcp);
2110 #ifdef VIDEO_ENABLED
2111 if ((lc->video_conf.display || lc->video_conf.capture) && md->streams[1].port>0)
2112 lc->videostream=video_stream_new(md->streams[1].port,linphone_core_ipv6_enabled(lc));
2114 lc->videostream=NULL;
2118 static int dtmf_tab[16]={'0','1','2','3','4','5','6','7','8','9','*','#','A','B','C','D'};
2120 static void linphone_core_dtmf_received(RtpSession* s, int dtmf, void* user_data){
2121 LinphoneCore* lc = (LinphoneCore*)user_data;
2122 if (dtmf<0 || dtmf>15){
2123 ms_warning("Bad dtmf value %i",dtmf);
2126 if (lc->vtable.dtmf_received != NULL)
2127 lc->vtable.dtmf_received(lc, dtmf_tab[dtmf]);
2130 static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){
2132 MSFilter *f=st->equalizer;
2133 int enabled=lp_config_get_int(lc->config,"sound","eq_active",0);
2134 const char *gains=lp_config_get_string(lc->config,"sound","eq_gains",NULL);
2135 ms_filter_call_method(f,MS_EQUALIZER_SET_ACTIVE,&enabled);
2141 if (sscanf(gains,"%f:%f:%f %n",&g.frequency,&g.gain,&g.width,&bytes)==3){
2142 ms_message("Read equalizer gains: %f(~%f) --> %f",g.frequency,g.width,g.gain);
2143 ms_filter_call_method(f,MS_EQUALIZER_SET_GAIN,&g);
2152 static void post_configure_audio_streams(LinphoneCore *lc){
2153 AudioStream *st=lc->audiostream;
2154 float gain=lp_config_get_float(lc->config,"sound","mic_gain",-1);
2156 audio_stream_set_mic_gain(st,gain);
2157 float recv_gain = lc->sound_conf.soft_play_lev;
2158 if (recv_gain != 0) {
2159 linphone_core_set_soft_play_level(lc,recv_gain);
2161 if (linphone_core_echo_limiter_enabled(lc)){
2162 float speed=lp_config_get_float(lc->config,"sound","el_speed",-1);
2163 float thres=lp_config_get_float(lc->config,"sound","el_thres",-1);
2164 float force=lp_config_get_float(lc->config,"sound","el_force",-1);
2165 int sustain=lp_config_get_int(lc->config,"sound","el_sustain",-1);
2167 if (st->el_type==ELControlMic){
2169 if (speed==-1) speed=0.03;
2170 if (force==-1) force=10;
2172 else if (st->el_type==ELControlSpeaker){
2174 if (speed==-1) speed=0.02;
2175 if (force==-1) force=5;
2178 ms_filter_call_method(f,MS_VOLUME_SET_EA_SPEED,&speed);
2180 ms_filter_call_method(f,MS_VOLUME_SET_EA_THRESHOLD,&thres);
2182 ms_filter_call_method(f,MS_VOLUME_SET_EA_FORCE,&force);
2184 ms_filter_call_method(f,MS_VOLUME_SET_EA_SUSTAIN,&sustain);
2188 float ng_thres=lp_config_get_float(lc->config,"sound","ng_thres",0.05);
2189 float ng_floorgain=lp_config_get_float(lc->config,"sound","ng_floorgain",0);
2190 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_thres);
2191 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&ng_floorgain);
2193 parametrize_equalizer(lc,st);
2194 if (lc->vtable.dtmf_received!=NULL){
2195 /* replace by our default action*/
2196 audio_stream_play_received_dtmfs(lc->audiostream,FALSE);
2197 rtp_session_signal_connect(lc->audiostream->session,"telephone-event",(RtpCallback)linphone_core_dtmf_received,(unsigned long)lc);
2201 static RtpProfile *make_profile(LinphoneCore *lc, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){
2204 RtpProfile *prof=rtp_profile_new("Call profile");
2209 for(elem=desc->payloads;elem!=NULL;elem=elem->next){
2210 PayloadType *pt=(PayloadType*)elem->data;
2213 if (desc->type==SalAudio){
2214 linphone_core_update_allocated_audio_bandwidth_in_call(lc,pt);
2216 *used_pt=payload_type_get_number(pt);
2219 if (desc->bandwidth>0) remote_bw=desc->bandwidth;
2220 else if (md->bandwidth>0) {
2221 /*case where b=AS is given globally, not per stream*/
2222 remote_bw=md->bandwidth;
2223 if (desc->type==SalVideo){
2224 remote_bw-=lc->audio_bw;
2228 if (desc->type==SalAudio){
2229 bw=get_min_bandwidth(lc->up_audio_bw,remote_bw);
2230 }else bw=get_min_bandwidth(lc->up_video_bw,remote_bw);
2231 if (bw>0) pt->normal_bitrate=bw*1000;
2232 else if (desc->type==SalAudio){
2233 pt->normal_bitrate=-1;
2237 snprintf(tmp,sizeof(tmp),"ptime=%i",desc->ptime);
2238 payload_type_append_send_fmtp(pt,tmp);
2240 rtp_profile_set_payload(prof,payload_type_get_number(pt),pt);
2245 void linphone_core_start_media_streams(LinphoneCore *lc, LinphoneCall *call){
2246 LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
2247 const char *tool="linphone-" LINPHONE_VERSION;
2250 /* adjust rtp jitter compensation. It must be at least the latency of the sound card */
2251 int jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
2253 if (call->media_start_time==0) call->media_start_time=time(NULL);
2255 cname=linphone_address_as_string_uri_only(me);
2257 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
2258 SalProtoRtpAvp,SalAudio);
2259 if (stream && stream->port!=0){
2260 call->audio_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
2261 if (!lc->use_files){
2262 MSSndCard *playcard=lc->sound_conf.play_sndcard;
2263 MSSndCard *captcard=lc->sound_conf.capt_sndcard;
2264 if (playcard==NULL) {
2265 ms_warning("No card defined for playback !");
2268 if (captcard==NULL) {
2269 ms_warning("No card defined for capture !");
2272 audio_stream_start_now(
2274 call->audio_profile,
2275 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
2282 linphone_core_echo_cancellation_enabled(lc));
2284 audio_stream_start_with_files(
2286 call->audio_profile,
2287 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
2295 post_configure_audio_streams(lc);
2296 audio_stream_set_rtcp_information(lc->audiostream, cname, tool);
2297 }else ms_warning("No audio stream defined ?");
2299 #ifdef VIDEO_ENABLED
2301 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
2302 SalProtoRtpAvp,SalVideo);
2303 /* shutdown preview */
2304 if (lc->previewstream!=NULL) {
2305 video_preview_stop(lc->previewstream);
2306 lc->previewstream=NULL;
2308 if (stream && stream->port!=0 && (lc->video_conf.display || lc->video_conf.capture)) {
2309 const char *addr=stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr;
2310 call->video_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
2311 video_stream_set_sent_video_size(lc->videostream,linphone_core_get_preferred_video_size(lc));
2312 video_stream_enable_self_view(lc->videostream,lc->video_conf.selfview);
2313 if (lc->video_conf.display && lc->video_conf.capture)
2314 video_stream_start(lc->videostream,
2315 call->video_profile, addr, stream->port,
2317 used_pt, jitt_comp, lc->video_conf.device);
2318 else if (lc->video_conf.display)
2319 video_stream_recv_only_start(lc->videostream,
2320 call->video_profile, addr, stream->port,
2321 used_pt, jitt_comp);
2322 else if (lc->video_conf.capture)
2323 video_stream_send_only_start(lc->videostream,
2324 call->video_profile, addr, stream->port,
2326 used_pt, jitt_comp, lc->video_conf.device);
2327 video_stream_set_rtcp_information(lc->videostream, cname,tool);
2329 ms_warning("No valid video stream defined.");
2336 linphone_address_destroy(me);
2337 lc->call->state=LCStateAVRunning;
2340 static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
2341 audio_stream_get_local_rtp_stats (st,&log->local_stats);
2344 void linphone_core_stop_media_streams(LinphoneCore *lc, LinphoneCall *call){
2345 if (lc->audiostream!=NULL) {
2346 linphone_call_log_fill_stats (call->log,lc->audiostream);
2347 audio_stream_stop(lc->audiostream);
2348 lc->audiostream=NULL;
2350 #ifdef VIDEO_ENABLED
2351 if (lc->videostream!=NULL){
2352 if (lc->video_conf.display && lc->video_conf.capture)
2353 video_stream_stop(lc->videostream);
2354 else if (lc->video_conf.display)
2355 video_stream_recv_only_stop(lc->videostream);
2356 else if (lc->video_conf.capture)
2357 video_stream_send_only_stop(lc->videostream);
2358 lc->videostream=NULL;
2360 if (linphone_core_video_preview_enabled(lc)){
2361 if (lc->previewstream==NULL){
2362 lc->previewstream=video_preview_start(lc->video_conf.device, lc->video_conf.vsize);
2366 if (call->audio_profile){
2367 rtp_profile_clear_all(call->audio_profile);
2368 rtp_profile_destroy(call->audio_profile);
2369 call->audio_profile=NULL;
2371 if (call->video_profile){
2372 rtp_profile_clear_all(call->video_profile);
2373 rtp_profile_destroy(call->video_profile);
2374 call->video_profile=NULL;
2379 * Accept an incoming call.
2381 * @ingroup call_control
2382 * Basically the application is notified of incoming calls within the
2383 * invite_recv callback of the #LinphoneCoreVTable structure.
2384 * The application can later respond positively to the call using
2386 * @param lc the LinphoneCore object
2387 * @param url the SIP address of the originator of the call, or NULL.
2388 * This argument is useful for managing multiple calls simulatenously,
2389 * however this feature is not supported yet.
2390 * Using NULL will accept the unique incoming call in progress.
2392 int linphone_core_accept_call(LinphoneCore *lc, const char *url)
2394 LinphoneCall *call=lc->call;
2395 LinphoneProxyConfig *cfg=NULL;
2396 const char *contact=NULL;
2402 if (call->state==LCStateAVRunning){
2403 /*call already accepted*/
2408 if (lc->ringstream!=NULL) {
2409 ms_message("stop ringing");
2410 ring_stop(lc->ringstream);
2411 ms_message("ring stopped");
2412 lc->ringstream=NULL;
2415 linphone_core_get_default_proxy(lc,&cfg);
2416 /*try to be best-effort in giving real local or routable contact address*/
2417 contact=get_fixed_contact(lc,call,cfg);
2419 sal_op_set_contact(call->op,contact);
2421 sal_call_accept(call->op);
2422 lc->vtable.display_status(lc,_("Connected."));
2423 gstate_new_state(lc, GSTATE_CALL_IN_CONNECTED, NULL);
2424 call->resultdesc=sal_call_get_final_media_description(call->op);
2425 if (call->resultdesc){
2426 sal_media_description_ref(call->resultdesc);
2427 linphone_core_start_media_streams(lc, call);
2428 }else call->media_pending=TRUE;
2429 ms_message("call answered.");
2434 * Terminates a call.
2436 * @ingroup call_control
2437 * @param lc The LinphoneCore
2438 * @param url the destination of the call to be terminated, use NULL if there is
2439 * only one call (which is case in this version of liblinphone).
2441 int linphone_core_terminate_call(LinphoneCore *lc, const char *url)
2443 LinphoneCall *call=lc->call;
2448 sal_call_terminate(call->op);
2451 if (lc->ringstream!=NULL) {
2452 ring_stop(lc->ringstream);
2453 lc->ringstream=NULL;
2455 linphone_core_stop_media_streams(lc,call);
2456 lc->vtable.display_status(lc,_("Call ended") );
2457 gstate_new_state(lc, GSTATE_CALL_END, NULL);
2458 linphone_call_destroy(call);
2463 * Returns TRUE if there is a call running or pending.
2465 * @ingroup call_control
2467 bool_t linphone_core_in_call(const LinphoneCore *lc){
2468 return lc->call!=NULL;
2472 * Returns The _LinphoneCall struct of the current call if one is in call
2474 * @ingroup call_control
2476 struct _LinphoneCall *linphone_core_get_current_call(LinphoneCore *lc)
2478 if(linphone_core_in_call(lc))
2484 int linphone_core_send_publish(LinphoneCore *lc,
2485 LinphoneOnlineStatus presence_mode)
2488 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=ms_list_next(elem)){
2489 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2490 if (cfg->publish) linphone_proxy_config_send_publish(cfg,presence_mode);
2496 * Set the incoming call timeout in seconds.
2498 * @ingroup call_control
2499 * If an incoming call isn't answered for this timeout period, it is
2500 * automatically declined.
2502 void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
2503 lc->sip_conf.inc_timeout=seconds;
2507 * Returns the incoming call timeout
2509 * @ingroup call_control
2510 * See linphone_core_set_inc_timeout() for details.
2512 int linphone_core_get_inc_timeout(LinphoneCore *lc){
2513 return lc->sip_conf.inc_timeout;
2516 void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
2517 const char *contact,
2518 LinphoneOnlineStatus presence_mode)
2520 if (minutes_away>0) lc->minutes_away=minutes_away;
2522 if (lc->alt_contact!=NULL) {
2523 ms_free(lc->alt_contact);
2524 lc->alt_contact=NULL;
2526 if (contact) lc->alt_contact=ms_strdup(contact);
2527 if (lc->presence_mode!=presence_mode){
2528 linphone_core_notify_all_friends(lc,presence_mode);
2530 Improve the use of all LINPHONE_STATUS available.
2531 !TODO Do not mix "presence status" with "answer status code"..
2532 Use correct parameter to follow sip_if_match/sip_etag.
2534 linphone_core_send_publish(lc,presence_mode);
2536 lc->prev_mode=lc->presence_mode;
2537 lc->presence_mode=presence_mode;
2540 LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
2541 return lc->presence_mode;
2545 * Get playback sound level in 0-100 scale.
2547 * @ingroup media_parameters
2549 int linphone_core_get_play_level(LinphoneCore *lc)
2551 return lc->sound_conf.play_lev;
2555 * Get ring sound level in 0-100 scale
2557 * @ingroup media_parameters
2559 int linphone_core_get_ring_level(LinphoneCore *lc)
2561 return lc->sound_conf.ring_lev;
2565 * Get sound capture level in 0-100 scale
2567 * @ingroup media_parameters
2569 int linphone_core_get_rec_level(LinphoneCore *lc){
2570 return lc->sound_conf.rec_lev;
2574 * Set sound ring level in 0-100 scale
2576 * @ingroup media_parameters
2578 void linphone_core_set_ring_level(LinphoneCore *lc, int level){
2580 lc->sound_conf.ring_lev=level;
2581 sndcard=lc->sound_conf.ring_sndcard;
2582 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2586 void linphone_core_set_soft_play_level(LinphoneCore *lc, float level){
2588 lc->sound_conf.soft_play_lev=level;
2589 AudioStream *st=lc->audiostream;
2590 if (!st) return; /*just return*/
2593 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_DB_GAIN,&gain);
2594 }else ms_warning("Could not apply gain: gain control wasn't activated.");
2596 float linphone_core_get_soft_play_level(LinphoneCore *lc) {
2598 AudioStream *st=lc->audiostream;
2600 ms_filter_call_method(st->volrecv,MS_VOLUME_GET,&gain);
2601 }else ms_warning("Could not get gain: gain control wasn't activated.");
2607 * Set sound playback level in 0-100 scale
2609 * @ingroup media_parameters
2611 void linphone_core_set_play_level(LinphoneCore *lc, int level){
2613 lc->sound_conf.play_lev=level;
2614 sndcard=lc->sound_conf.play_sndcard;
2615 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2619 * Set sound capture level in 0-100 scale
2621 * @ingroup media_parameters
2623 void linphone_core_set_rec_level(LinphoneCore *lc, int level)
2626 lc->sound_conf.rec_lev=level;
2627 sndcard=lc->sound_conf.capt_sndcard;
2628 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_CAPTURE,level);
2631 static MSSndCard *get_card_from_string_id(const char *devid, unsigned int cap){
2632 MSSndCard *sndcard=NULL;
2634 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2635 if (sndcard!=NULL &&
2636 (ms_snd_card_get_capabilities(sndcard) & cap)==0 ){
2637 ms_warning("%s card does not have the %s capability, ignoring.",
2639 cap==MS_SND_CARD_CAP_CAPTURE ? "capture" : "playback");
2643 if (sndcard==NULL) {
2644 /* get a card that has read+write capabilities */
2645 sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
2646 /* otherwise refine to the first card having the right capability*/
2648 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2649 for(;elem!=NULL;elem=elem->next){
2650 sndcard=(MSSndCard*)elem->data;
2651 if (ms_snd_card_get_capabilities(sndcard) & cap) break;
2654 if (sndcard==NULL){/*looks like a bug! take the first one !*/
2655 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2656 if (elem) sndcard=(MSSndCard*)elem->data;
2659 if (sndcard==NULL) ms_error("Could not find a suitable soundcard !");
2664 * Returns true if the specified sound device can capture sound.
2666 * @ingroup media_parameters
2667 * @param devid the device name as returned by linphone_core_get_sound_devices()
2669 bool_t linphone_core_sound_device_can_capture(LinphoneCore *lc, const char *devid){
2671 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2672 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_CAPTURE)) return TRUE;
2677 * Returns true if the specified sound device can play sound.
2679 * @ingroup media_parameters
2680 * @param devid the device name as returned by linphone_core_get_sound_devices()
2682 bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *devid){
2684 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2685 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_PLAYBACK)) return TRUE;
2690 * Sets the sound device used for ringing.
2692 * @ingroup media_parameters
2693 * @param devid the device name as returned by linphone_core_get_sound_devices()
2695 int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
2696 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2697 lc->sound_conf.ring_sndcard=card;
2698 if (card && lc->ready)
2699 lp_config_set_string(lc->config,"sound","ringer_dev_id",ms_snd_card_get_string_id(card));
2704 * Sets the sound device used for playback.
2706 * @ingroup media_parameters
2707 * @param devid the device name as returned by linphone_core_get_sound_devices()
2709 int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
2710 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2711 lc->sound_conf.play_sndcard=card;
2712 if (card && lc->ready)
2713 lp_config_set_string(lc->config,"sound","playback_dev_id",ms_snd_card_get_string_id(card));
2718 * Sets the sound device used for capture.
2720 * @ingroup media_parameters
2721 * @param devid the device name as returned by linphone_core_get_sound_devices()
2723 int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
2724 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_CAPTURE);
2725 lc->sound_conf.capt_sndcard=card;
2726 if (card && lc->ready)
2727 lp_config_set_string(lc->config,"sound","capture_dev_id",ms_snd_card_get_string_id(card));
2732 * Returns the name of the currently assigned sound device for ringing.
2734 * @ingroup media_parameters
2736 const char * linphone_core_get_ringer_device(LinphoneCore *lc)
2738 if (lc->sound_conf.ring_sndcard) return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
2743 * Returns the name of the currently assigned sound device for playback.
2745 * @ingroup media_parameters
2747 const char * linphone_core_get_playback_device(LinphoneCore *lc)
2749 return lc->sound_conf.play_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.play_sndcard) : NULL;
2753 * Returns the name of the currently assigned sound device for capture.
2755 * @ingroup media_parameters
2757 const char * linphone_core_get_capture_device(LinphoneCore *lc)
2759 return lc->sound_conf.capt_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard) : NULL;
2763 * Returns an unmodifiable array of available sound devices.
2765 * @ingroup media_parameters
2766 * The array is NULL terminated.
2768 const char** linphone_core_get_sound_devices(LinphoneCore *lc){
2769 build_sound_devices_table(lc);
2770 return lc->sound_conf.cards;
2774 * Returns an unmodifiable array of available video capture devices.
2776 * @ingroup media_parameters
2777 * The array is NULL terminated.
2779 const char** linphone_core_get_video_devices(const LinphoneCore *lc){
2780 return lc->video_conf.cams;
2783 char linphone_core_get_sound_source(LinphoneCore *lc)
2785 return lc->sound_conf.source;
2788 void linphone_core_set_sound_source(LinphoneCore *lc, char source)
2790 MSSndCard *sndcard=lc->sound_conf.capt_sndcard;
2791 lc->sound_conf.source=source;
2792 if (!sndcard) return;
2795 ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
2798 ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
2806 * Sets the path to a wav file used for ringing.
2808 * The file must be a wav 16bit linear.
2810 * @ingroup media_parameters
2812 void linphone_core_set_ring(LinphoneCore *lc,const char *path){
2813 if (lc->sound_conf.local_ring!=0){
2814 ms_free(lc->sound_conf.local_ring);
2816 lc->sound_conf.local_ring=ms_strdup(path);
2817 if (lc->ready && lc->sound_conf.local_ring)
2818 lp_config_set_string(lc->config,"sound","local_ring",lc->sound_conf.local_ring);
2822 * Returns the path to the wav file used for ringing.
2824 * @ingroup media_parameters
2826 const char *linphone_core_get_ring(const LinphoneCore *lc){
2827 return lc->sound_conf.local_ring;
2830 static void notify_end_of_ring(void *ud ,unsigned int event, void * arg){
2831 LinphoneCore *lc=(LinphoneCore*)ud;
2832 lc->preview_finished=1;
2835 int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata)
2837 if (lc->ringstream!=0){
2838 ms_warning("Cannot start ring now,there's already a ring being played");
2841 lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
2842 lc->preview_finished=0;
2843 if (lc->sound_conf.ring_sndcard!=NULL){
2844 lc->ringstream=ring_start_with_cb(ring,2000,lc->sound_conf.ring_sndcard,notify_end_of_ring,(void *)lc);
2850 * Sets the path to a wav file used for ringing back.
2852 * Ringback means the ring that is heard when it's ringing at the remote party.
2853 * The file must be a wav 16bit linear.
2855 * @ingroup media_parameters
2857 void linphone_core_set_ringback(LinphoneCore *lc, const char *path){
2858 if (lc->sound_conf.remote_ring!=0){
2859 ms_free(lc->sound_conf.remote_ring);
2861 lc->sound_conf.remote_ring=ms_strdup(path);
2865 * Returns the path to the wav file used for ringing back.
2867 * @ingroup media_parameters
2869 const char * linphone_core_get_ringback(const LinphoneCore *lc){
2870 return lc->sound_conf.remote_ring;
2874 * Enables or disable echo cancellation.
2876 * @ingroup media_parameters
2878 void linphone_core_enable_echo_cancellation(LinphoneCore *lc, bool_t val){
2879 lc->sound_conf.ec=val;
2881 lp_config_set_int(lc->config,"sound","echocancellation",val);
2885 * Returns TRUE if echo cancellation is enabled.
2887 * @ingroup media_parameters
2889 bool_t linphone_core_echo_cancellation_enabled(LinphoneCore *lc){
2890 return lc->sound_conf.ec;
2893 void linphone_core_enable_echo_limiter(LinphoneCore *lc, bool_t val){
2894 lc->sound_conf.ea=val;
2897 bool_t linphone_core_echo_limiter_enabled(const LinphoneCore *lc){
2898 return lc->sound_conf.ea;
2902 * Mutes or unmutes the local microphone.
2904 * @ingroup media_parameters
2906 void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){
2907 if (lc->audiostream!=NULL){
2908 audio_stream_set_mic_gain(lc->audiostream,
2909 (val==TRUE) ? 0 : 1.0);
2913 bool_t linphone_core_is_mic_muted(LinphoneCore *lc) {
2915 if (lc->audiostream && lc->audiostream->volsend){
2916 ms_filter_call_method(lc->audiostream->volsend,MS_VOLUME_GET_GAIN,&gain);
2917 }else ms_warning("Could not get gain: gain control wasn't activated. ");
2922 void linphone_core_enable_agc(LinphoneCore *lc, bool_t val){
2923 lc->sound_conf.agc=val;
2926 bool_t linphone_core_agc_enabled(const LinphoneCore *lc){
2927 return lc->sound_conf.agc;
2931 * Send the specified dtmf.
2933 * @ingroup media_parameters
2934 * This function only works during calls. The dtmf is automatically played to the user.
2935 * @param lc The LinphoneCore object
2936 * @param dtmf The dtmf name specified as a char, such as '0', '#' etc...
2939 void linphone_core_send_dtmf(LinphoneCore *lc, char dtmf)
2941 /*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
2942 if (linphone_core_get_use_rfc2833_for_dtmf(lc)!=0 || linphone_core_get_use_info_for_dtmf(lc)==0)
2945 if (lc->audiostream!=NULL){
2946 audio_stream_send_dtmf(lc->audiostream,dtmf);
2950 ms_error("we cannot send RFC2833 dtmf when we are not in communication");
2953 if (linphone_core_get_use_info_for_dtmf(lc)!=0){
2954 /* Out of Band DTMF (use INFO method) */
2955 LinphoneCall *call=lc->call;
2959 sal_call_send_dtmf(call->op,dtmf);
2963 void linphone_core_set_stun_server(LinphoneCore *lc, const char *server){
2964 if (lc->net_conf.stun_server!=NULL)
2965 ms_free(lc->net_conf.stun_server);
2967 lc->net_conf.stun_server=ms_strdup(server);
2968 else lc->net_conf.stun_server=NULL;
2971 const char * linphone_core_get_stun_server(const LinphoneCore *lc){
2972 return lc->net_conf.stun_server;
2975 const char * linphone_core_get_relay_addr(const LinphoneCore *lc){
2976 return lc->net_conf.relay;
2979 int linphone_core_set_relay_addr(LinphoneCore *lc, const char *addr){
2980 if (lc->net_conf.relay!=NULL){
2981 ms_free(lc->net_conf.relay);
2982 lc->net_conf.relay=NULL;
2985 lc->net_conf.relay=ms_strdup(addr);
2990 void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
2992 if (lc->net_conf.nat_address!=NULL){
2993 ms_free(lc->net_conf.nat_address);
2995 if (addr!=NULL) lc->net_conf.nat_address=ms_strdup(addr);
2996 else lc->net_conf.nat_address=NULL;
2997 if (lc->sip_conf.contact) update_primary_contact(lc);
3000 const char *linphone_core_get_nat_address(const LinphoneCore *lc)
3002 return lc->net_conf.nat_address;
3005 void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
3006 lc->net_conf.firewall_policy=pol;
3007 if (lc->sip_conf.contact) update_primary_contact(lc);
3010 LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
3011 return lc->net_conf.firewall_policy;
3015 * Get the list of call logs (past calls).
3017 * @ingroup call_logs
3019 const MSList * linphone_core_get_call_logs(LinphoneCore *lc){
3021 return lc->call_logs;
3025 * Erase the call log.
3027 * @ingroup call_logs
3029 void linphone_core_clear_call_logs(LinphoneCore *lc){
3031 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3032 lc->call_logs=ms_list_free(lc->call_logs);
3033 call_logs_write_to_config_file(lc);
3036 static void toggle_video_preview(LinphoneCore *lc, bool_t val){
3037 #ifdef VIDEO_ENABLED
3038 if (lc->videostream==NULL){
3040 if (lc->previewstream==NULL){
3041 lc->previewstream=video_preview_start(lc->video_conf.device,
3042 lc->video_conf.vsize);
3045 if (lc->previewstream!=NULL){
3046 video_preview_stop(lc->previewstream);
3047 lc->previewstream=NULL;
3055 * Enables video globally.
3057 * @ingroup media_parameters
3058 * This function does not have any effect during calls. It just indicates LinphoneCore to
3059 * initiate future calls with video or not. The two boolean parameters indicate in which
3060 * direction video is enabled. Setting both to false disables video entirely.
3062 * @param vcap_enabled indicates whether video capture is enabled
3063 * @param display_enabled indicates whether video display should be shown
3066 void linphone_core_enable_video(LinphoneCore *lc, bool_t vcap_enabled, bool_t display_enabled){
3067 #ifndef VIDEO_ENABLED
3068 if (vcap_enabled || display_enabled)
3069 ms_warning("This version of linphone was built without video support.");
3071 lc->video_conf.capture=vcap_enabled;
3072 lc->video_conf.display=display_enabled;
3074 /* need to re-apply network bandwidth settings*/
3075 linphone_core_set_download_bandwidth(lc,
3076 linphone_core_get_download_bandwidth(lc));
3077 linphone_core_set_upload_bandwidth(lc,
3078 linphone_core_get_upload_bandwidth(lc));
3082 * Returns TRUE if video is enabled, FALSE otherwise.
3083 * @ingroup media_parameters
3085 bool_t linphone_core_video_enabled(LinphoneCore *lc){
3086 return (lc->video_conf.display || lc->video_conf.capture);
3090 * Controls video preview enablement.
3092 * @ingroup media_parameters
3093 * Video preview refers to the action of displaying the local webcam image
3094 * to the user while not in call.
3096 void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val){
3097 lc->video_conf.show_local=val;
3101 * Returns TRUE if video previewing is enabled.
3102 * @ingroup media_parameters
3104 bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
3105 return lc->video_conf.show_local;
3109 * Enables or disable self view during calls.
3111 * @ingroup media_parameters
3112 * Self-view refers to having local webcam image inserted in corner
3113 * of the video window during calls.
3114 * This function works at any time, including during calls.
3116 void linphone_core_enable_self_view(LinphoneCore *lc, bool_t val){
3117 lc->video_conf.selfview=val;
3118 #ifdef VIDEO_ENABLED
3119 if (lc->videostream){
3120 video_stream_enable_self_view(lc->videostream,val);
3126 * Returns TRUE if self-view is enabled, FALSE otherwise.
3128 * @ingroup media_parameters
3130 * Refer to linphone_core_enable_self_view() for details.
3132 bool_t linphone_core_self_view_enabled(const LinphoneCore *lc){
3133 return lc->video_conf.selfview;
3137 * Sets the active video device.
3139 * @ingroup media_parameters
3140 * @param id the name of the video device as returned by linphone_core_get_video_devices()
3142 int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
3143 MSWebCam *olddev=lc->video_conf.device;
3146 lc->video_conf.device=ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),id);
3147 if (lc->video_conf.device==NULL){
3148 ms_warning("Could not found video device %s",id);
3151 if (lc->video_conf.device==NULL)
3152 lc->video_conf.device=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());
3153 if (olddev!=NULL && olddev!=lc->video_conf.device){
3154 toggle_video_preview(lc,FALSE);/*restart the video local preview*/
3156 if (lc->ready && lc->video_conf.device){
3157 vd=ms_web_cam_get_string_id(lc->video_conf.device);
3158 if (vd && strstr(vd,"Static picture")!=NULL){
3161 lp_config_set_string(lc->config,"video","device",vd);
3167 * Returns the name of the currently active video device.
3169 * @ingroup media_parameters
3171 const char *linphone_core_get_video_device(const LinphoneCore *lc){
3172 if (lc->video_conf.device) return ms_web_cam_get_string_id(lc->video_conf.device);
3176 int linphone_core_set_static_picture(LinphoneCore *lc, const char *path) {
3177 #ifdef VIDEO_ENABLED
3178 VideoStream *vs = NULL;
3179 /* Select the video stream from the call in the first place */
3180 if (lc && lc->videostream) {
3181 vs = lc->videostream;
3183 /* If not in call, select the video stream from the preview */
3184 if (vs == NULL && lc && lc->previewstream) {
3185 vs = lc->previewstream;
3188 /* If we have a video stream (either preview, either from call), we
3189 have a source and it is using the static picture filter, then
3190 force the filter to use that picture. */
3191 if (vs && vs->source) {
3192 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3193 ms_filter_call_method(vs->source, MS_FILTER_SET_IMAGE,
3198 /* Tell the static image filter to use that image from now on so
3199 that the image will be used next time it has to be read */
3200 ms_static_image_set_default_image(path);
3202 ms_warning("Video support not compiled.");
3208 * Returns the native window handle of the video window, casted as an unsigned long.
3210 * @ingroup media_parameters
3212 unsigned long linphone_core_get_native_video_window_id(const LinphoneCore *lc){
3213 #ifdef VIDEO_ENABLED
3214 if (lc->videostream)
3215 return video_stream_get_native_window_id(lc->videostream);
3216 if (lc->previewstream)
3217 return video_stream_get_native_window_id(lc->previewstream);
3222 static MSVideoSizeDef supported_resolutions[]={
3223 { {MS_VIDEO_SIZE_SVGA_W,MS_VIDEO_SIZE_SVGA_H} , "svga" },
3224 { {MS_VIDEO_SIZE_4CIF_W,MS_VIDEO_SIZE_4CIF_H} , "4cif" },
3225 { {MS_VIDEO_SIZE_VGA_W,MS_VIDEO_SIZE_VGA_H} , "vga" },
3226 { {MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H} , "cif" },
3227 { {MS_VIDEO_SIZE_QVGA_W,MS_VIDEO_SIZE_QVGA_H} , "qvga" },
3228 { {MS_VIDEO_SIZE_QCIF_W,MS_VIDEO_SIZE_QCIF_H} , "qcif" },
3233 * Returns the zero terminated table of supported video resolutions.
3235 * @ingroup media_parameters
3237 const MSVideoSizeDef *linphone_core_get_supported_video_sizes(LinphoneCore *lc){
3238 return supported_resolutions;
3241 static MSVideoSize video_size_get_by_name(const char *name){
3242 MSVideoSizeDef *pdef=supported_resolutions;
3243 MSVideoSize null_vsize={0,0};
3244 for(;pdef->name!=NULL;pdef++){
3245 if (strcasecmp(name,pdef->name)==0){
3249 ms_warning("Video resolution %s is not supported in linphone.",name);
3253 static const char *video_size_get_name(MSVideoSize vsize){
3254 MSVideoSizeDef *pdef=supported_resolutions;
3255 for(;pdef->name!=NULL;pdef++){
3256 if (pdef->vsize.width==vsize.width && pdef->vsize.height==vsize.height){
3263 static bool_t video_size_supported(MSVideoSize vsize){
3264 if (video_size_get_name(vsize)) return TRUE;
3265 ms_warning("Video resolution %ix%i is not supported in linphone.",vsize.width,vsize.height);
3270 * Sets the preferred video size.
3272 * @ingroup media_parameters
3273 * This applies only to the stream that is captured and sent to the remote party,
3274 * since we accept all standard video size on the receive path.
3276 void linphone_core_set_preferred_video_size(LinphoneCore *lc, MSVideoSize vsize){
3277 if (video_size_supported(vsize)){
3278 MSVideoSize oldvsize=lc->video_conf.vsize;
3279 lc->video_conf.vsize=vsize;
3280 if (!ms_video_size_equal(oldvsize,vsize) && lc->previewstream!=NULL){
3281 toggle_video_preview(lc,FALSE);
3282 toggle_video_preview(lc,TRUE);
3285 lp_config_set_string(lc->config,"video","size",video_size_get_name(vsize));
3290 * Sets the preferred video size by its name.
3292 * @ingroup media_parameters
3293 * This is identical to linphone_core_set_preferred_video_size() except
3294 * that it takes the name of the video resolution as input.
3295 * Video resolution names are: qcif, svga, cif, vga, 4cif, svga ...
3297 void linphone_core_set_preferred_video_size_by_name(LinphoneCore *lc, const char *name){
3298 MSVideoSize vsize=video_size_get_by_name(name);
3299 MSVideoSize default_vsize={MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H};
3300 if (vsize.width!=0) linphone_core_set_preferred_video_size(lc,vsize);
3301 else linphone_core_set_preferred_video_size(lc,default_vsize);
3305 * Returns the current preferred video size for sending.
3307 * @ingroup media_parameters
3309 MSVideoSize linphone_core_get_preferred_video_size(LinphoneCore *lc){
3310 return lc->video_conf.vsize;
3313 void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
3314 lc->use_files=yesno;
3317 void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
3318 if (lc->play_file!=NULL){
3319 ms_free(lc->play_file);
3323 lc->play_file=ms_strdup(file);
3324 if (lc->audiostream->ticker)
3325 audio_stream_play(lc->audiostream,file);
3329 void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
3330 if (lc->rec_file!=NULL){
3331 ms_free(lc->rec_file);
3335 lc->rec_file=ms_strdup(file);
3336 if (lc->audiostream)
3337 audio_stream_record(lc->audiostream,file);
3342 * Retrieves the user pointer that was given to linphone_core_new()
3344 * @ingroup initializing
3346 void *linphone_core_get_user_data(LinphoneCore *lc){
3350 int linphone_core_get_mtu(const LinphoneCore *lc){
3351 return lc->net_conf.mtu;
3354 void linphone_core_set_mtu(LinphoneCore *lc, int mtu){
3355 lc->net_conf.mtu=mtu;
3358 ms_error("MTU too small !");
3362 ms_message("MTU is supposed to be %i, rtp payload max size will be %i",mtu, ms_get_payload_max_size());
3363 }else ms_set_mtu(0);//use mediastreamer2 default value
3366 void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context){
3368 lc->wait_ctx=user_context;
3371 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose){
3373 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingStart,purpose,0);
3377 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progress){
3379 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingProgress,purpose,progress);
3389 void linphone_core_stop_waiting(LinphoneCore *lc){
3391 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingFinished,NULL,0);
3395 void linphone_core_set_audio_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3401 * Retrieve RTP statistics regarding current call.
3402 * @param local RTP statistics computed locally.
3403 * @param remote RTP statistics computed by far end (obtained via RTCP feedback).
3405 * @note Remote RTP statistics is not implemented yet.
3407 * @returns 0 or -1 if no call is running.
3410 int linphone_core_get_current_call_stats(LinphoneCore *lc, rtp_stats_t *local, rtp_stats_t *remote){
3411 LinphoneCall *call=linphone_core_get_current_call (lc);
3413 if (lc->audiostream!=NULL){
3414 memset(remote,0,sizeof(*remote));
3415 audio_stream_get_local_rtp_stats (lc->audiostream,local);
3422 void net_config_uninit(LinphoneCore *lc)
3424 net_config_t *config=&lc->net_conf;
3425 lp_config_set_int(lc->config,"net","download_bw",config->download_bw);
3426 lp_config_set_int(lc->config,"net","upload_bw",config->upload_bw);
3428 if (config->stun_server!=NULL){
3429 lp_config_set_string(lc->config,"net","stun_server",config->stun_server);
3430 ms_free(lc->net_conf.stun_server);
3432 if (config->nat_address!=NULL){
3433 lp_config_set_string(lc->config,"net","nat_address",config->nat_address);
3434 ms_free(lc->net_conf.nat_address);
3436 lp_config_set_int(lc->config,"net","firewall_policy",config->firewall_policy);
3437 lp_config_set_int(lc->config,"net","mtu",config->mtu);
3441 void sip_config_uninit(LinphoneCore *lc)
3445 sip_config_t *config=&lc->sip_conf;
3446 lp_config_set_int(lc->config,"sip","sip_port",config->sip_port);
3447 lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
3448 lp_config_set_string(lc->config,"sip","contact",config->contact);
3449 lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
3450 lp_config_set_int(lc->config,"sip","use_info",config->use_info);
3451 lp_config_set_int(lc->config,"sip","use_rfc2833",config->use_rfc2833);
3452 lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
3453 lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
3456 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
3458 for(elem=config->proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3459 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
3460 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
3461 linphone_proxy_config_edit(cfg); /* to unregister */
3467 sal_iterate(lc->sal);
3476 ms_list_for_each(config->proxies,(void (*)(void*)) linphone_proxy_config_destroy);
3477 ms_list_free(config->proxies);
3478 config->proxies=NULL;
3480 linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */
3482 for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3483 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
3484 linphone_auth_info_write_config(lc->config,ai,i);
3486 linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
3487 ms_list_for_each(lc->auth_info,(void (*)(void*))linphone_auth_info_destroy);
3488 ms_list_free(lc->auth_info);
3491 sal_uninit(lc->sal);
3494 if (lc->sip_conf.guessed_contact)
3495 ms_free(lc->sip_conf.guessed_contact);
3496 if (config->contact)
3497 ms_free(config->contact);
3501 void rtp_config_uninit(LinphoneCore *lc)
3503 rtp_config_t *config=&lc->rtp_conf;
3504 lp_config_set_int(lc->config,"rtp","audio_rtp_port",config->audio_rtp_port);
3505 lp_config_set_int(lc->config,"rtp","video_rtp_port",config->video_rtp_port);
3506 lp_config_set_int(lc->config,"rtp","audio_jitt_comp",config->audio_jitt_comp);
3507 lp_config_set_int(lc->config,"rtp","video_jitt_comp",config->video_jitt_comp);
3508 lp_config_set_int(lc->config,"rtp","nortp_timeout",config->nortp_timeout);
3511 void sound_config_uninit(LinphoneCore *lc)
3513 sound_config_t *config=&lc->sound_conf;
3514 ms_free(config->cards);
3516 lp_config_set_string(lc->config,"sound","remote_ring",config->remote_ring);
3518 if (config->local_ring) ms_free(config->local_ring);
3519 if (config->remote_ring) ms_free(config->remote_ring);
3520 ms_snd_card_manager_destroy();
3523 void video_config_uninit(LinphoneCore *lc)
3525 lp_config_set_int(lc->config,"video","enabled",linphone_core_video_enabled(lc));
3526 lp_config_set_string(lc->config,"video","size",video_size_get_name(linphone_core_get_preferred_video_size(lc)));
3527 lp_config_set_int(lc->config,"video","display",lc->video_conf.display);
3528 lp_config_set_int(lc->config,"video","capture",lc->video_conf.capture);
3529 lp_config_set_int(lc->config,"video","show_local",linphone_core_video_preview_enabled(lc));
3530 lp_config_set_int(lc->config,"video","self_view",linphone_core_self_view_enabled(lc));
3531 if (lc->video_conf.cams)
3532 ms_free(lc->video_conf.cams);
3535 void codecs_config_uninit(LinphoneCore *lc)
3538 codecs_config_t *config=&lc->codecs_conf;
3543 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
3544 pt=(PayloadType*)(node->data);
3545 sprintf(key,"audio_codec_%i",index);
3546 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3547 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3548 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3551 sprintf(key,"audio_codec_%i",index);
3552 lp_config_clean_section (lc->config,key);
3555 for(node=config->video_codecs;node!=NULL;node=ms_list_next(node)){
3556 pt=(PayloadType*)(node->data);
3557 sprintf(key,"video_codec_%i",index);
3558 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3559 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3560 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3561 lp_config_set_string(lc->config,key,"recv_fmtp",pt->recv_fmtp);
3564 sprintf(key,"video_codec_%i",index);
3565 lp_config_clean_section (lc->config,key);
3567 ms_list_free(lc->codecs_conf.audio_codecs);
3568 ms_list_free(lc->codecs_conf.video_codecs);
3571 void ui_config_uninit(LinphoneCore* lc)
3574 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_destroy);
3575 ms_list_free(lc->friends);
3581 * Returns the LpConfig object used to manage the storage (config) file.
3584 * The application can use the LpConfig object to insert its own private
3585 * sections and pairs of key=value in the configuration file.
3588 LpConfig *linphone_core_get_config(LinphoneCore *lc){
3592 static void linphone_core_uninit(LinphoneCore *lc)
3596 linphone_core_terminate_call(lc,NULL);
3603 linphone_core_iterate(lc);
3607 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions);
3608 gstate_new_state(lc, GSTATE_POWER_SHUTDOWN, NULL);
3609 #ifdef VIDEO_ENABLED
3610 if (lc->previewstream!=NULL){
3611 video_preview_stop(lc->previewstream);
3612 lc->previewstream=NULL;
3615 /* save all config */
3616 net_config_uninit(lc);
3617 sip_config_uninit(lc);
3618 rtp_config_uninit(lc);
3619 sound_config_uninit(lc);
3620 video_config_uninit(lc);
3621 codecs_config_uninit(lc);
3622 ui_config_uninit(lc);
3623 if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
3624 lp_config_destroy(lc->config);
3625 lc->config = NULL; /* Mark the config as NULL to block further calls */
3626 sip_setup_unregister_all();
3628 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3629 lc->call_logs=ms_list_free(lc->call_logs);
3631 linphone_core_free_payload_types();
3634 gstate_new_state(lc, GSTATE_POWER_OFF, NULL);
3637 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable){
3638 ms_message("Network state is now [%s]",isReachable?"UP":"DOWN");
3639 // second get the list of available proxies
3640 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3641 for(;elem!=NULL;elem=elem->next){
3642 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3643 if (linphone_proxy_config_register_enabled(cfg) ) {
3651 lc->network_reachable=isReachable;
3654 void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) {
3655 //first disable automatic mode
3656 if (lc->auto_net_state_mon) {
3657 ms_message("Disabling automatic network state monitoring");
3658 lc->auto_net_state_mon=FALSE;
3660 set_network_reachable(lc,isReachable);
3663 bool_t linphone_core_is_network_reachabled(LinphoneCore* lc) {
3664 return lc->network_reachable;
3666 ortp_socket_t linphone_core_get_sip_socket(LinphoneCore *lc){
3667 return sal_get_socket(lc->sal);
3670 * Destroys a LinphoneCore
3672 * @ingroup initializing
3674 void linphone_core_destroy(LinphoneCore *lc){
3675 linphone_core_uninit(lc);