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 bool_t rtp_no_xmit_on_audio_mute;
735 port=lp_config_get_int(lc->config,"rtp","audio_rtp_port",7078);
736 linphone_core_set_audio_port(lc,port);
738 port=lp_config_get_int(lc->config,"rtp","video_rtp_port",9078);
739 if (port==0) port=9078;
740 linphone_core_set_video_port(lc,port);
742 jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
743 linphone_core_set_audio_jittcomp(lc,jitt_comp);
744 jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
745 nortp_timeout=lp_config_get_int(lc->config,"rtp","nortp_timeout",30);
746 linphone_core_set_nortp_timeout(lc,nortp_timeout);
747 rtp_no_xmit_on_audio_mute=lp_config_get_int(lc->config,"rtp","rtp_no_xmit_on_audio_mute",FALSE);
748 linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_no_xmit_on_audio_mute);
751 static PayloadType * find_payload(RtpProfile *prof, const char *mime_type, int clock_rate, const char *recv_fmtp){
752 PayloadType *candidate=NULL;
756 it=rtp_profile_get_payload(prof,i);
757 if (it!=NULL && strcasecmp(mime_type,it->mime_type)==0
758 && (clock_rate==it->clock_rate || clock_rate<=0) ){
759 if ( (recv_fmtp && it->recv_fmtp && strstr(recv_fmtp,it->recv_fmtp)!=NULL) ||
760 (recv_fmtp==NULL && it->recv_fmtp==NULL) ){
762 if (recv_fmtp) payload_type_set_recv_fmtp(it,recv_fmtp);
766 if (it->recv_fmtp==NULL) candidate=it;
771 if (candidate && recv_fmtp){
772 payload_type_set_recv_fmtp(candidate,recv_fmtp);
777 static bool_t get_codec(LpConfig *config, char* type, int index, PayloadType **ret){
779 const char *mime,*fmtp;
784 snprintf(codeckey,50,"%s_%i",type,index);
785 mime=lp_config_get_string(config,codeckey,"mime",NULL);
786 if (mime==NULL || strlen(mime)==0 ) return FALSE;
788 rate=lp_config_get_int(config,codeckey,"rate",8000);
789 fmtp=lp_config_get_string(config,codeckey,"recv_fmtp",NULL);
790 enabled=lp_config_get_int(config,codeckey,"enabled",1);
791 pt=find_payload(&av_profile,mime,rate,fmtp);
792 if (pt && enabled ) pt->flags|=PAYLOAD_TYPE_ENABLED;
793 //ms_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
794 if (pt==NULL) ms_warning("Ignoring codec config %s/%i with fmtp=%s because unsupported",
795 mime,rate,fmtp ? fmtp : "");
800 static const char *codec_pref_order[]={
813 static int find_codec_rank(const char *mime){
815 for(i=0;codec_pref_order[i]!=NULL;++i){
816 if (strcasecmp(codec_pref_order[i],mime)==0)
822 static int codec_compare(const PayloadType *a, const PayloadType *b){
824 ra=find_codec_rank(a->mime_type);
825 rb=find_codec_rank(b->mime_type);
827 if (ra<rb) return -1;
831 static MSList *add_missing_codecs(SalStreamType mtype, MSList *l){
834 PayloadType *pt=rtp_profile_get_payload(&av_profile,i);
836 if (mtype==SalVideo && pt->type!=PAYLOAD_VIDEO)
838 else if (mtype==SalAudio && (pt->type!=PAYLOAD_AUDIO_PACKETIZED
839 && pt->type!=PAYLOAD_AUDIO_CONTINUOUS)){
842 if (pt && ms_filter_codec_supported(pt->mime_type)){
843 if (ms_list_find(l,pt)==NULL){
844 payload_type_set_flag(pt,PAYLOAD_TYPE_ENABLED);
845 ms_message("Adding new codec %s/%i with fmtp %s",
846 pt->mime_type,pt->clock_rate,pt->recv_fmtp ? pt->recv_fmtp : "");
847 l=ms_list_insert_sorted(l,pt,(int (*)(const void *, const void *))codec_compare);
855 static void codecs_config_read(LinphoneCore *lc)
859 MSList *audio_codecs=NULL;
860 MSList *video_codecs=NULL;
861 for (i=0;get_codec(lc->config,"audio_codec",i,&pt);i++){
863 if (!ms_filter_codec_supported(pt->mime_type)){
864 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
865 }else audio_codecs=ms_list_append(audio_codecs,pt);
868 audio_codecs=add_missing_codecs(SalAudio,audio_codecs);
869 for (i=0;get_codec(lc->config,"video_codec",i,&pt);i++){
871 if (!ms_filter_codec_supported(pt->mime_type)){
872 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
873 }else video_codecs=ms_list_append(video_codecs,(void *)pt);
876 video_codecs=add_missing_codecs(SalVideo,video_codecs);
877 linphone_core_set_audio_codecs(lc,audio_codecs);
878 linphone_core_set_video_codecs(lc,video_codecs);
879 linphone_core_update_allocated_audio_bandwidth(lc);
882 static void video_config_read(LinphoneCore *lc){
883 int capture, display, self_view;
887 const char **devices;
891 /* retrieve all video devices */
892 elem=ms_web_cam_manager_get_list(ms_web_cam_manager_get());
893 ndev=ms_list_size(elem);
894 devices=ms_malloc((ndev+1)*sizeof(const char *));
895 for (i=0;elem!=NULL;elem=elem->next,i++){
896 devices[i]=ms_web_cam_get_string_id((MSWebCam *)elem->data);
899 lc->video_conf.cams=devices;
901 str=lp_config_get_string(lc->config,"video","device",NULL);
902 if (str && str[0]==0) str=NULL;
903 linphone_core_set_video_device(lc,str);
905 linphone_core_set_preferred_video_size_by_name(lc,
906 lp_config_get_string(lc->config,"video","size","cif"));
908 enabled=lp_config_get_int(lc->config,"video","enabled",1);
909 capture=lp_config_get_int(lc->config,"video","capture",enabled);
910 display=lp_config_get_int(lc->config,"video","display",enabled);
911 self_view=lp_config_get_int(lc->config,"video","self_view",enabled);
913 linphone_core_enable_video(lc,capture,display);
914 linphone_core_enable_self_view(lc,self_view);
918 static void ui_config_read(LinphoneCore *lc)
922 for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
923 linphone_core_add_friend(lc,lf);
925 call_logs_read_from_config_file(lc);
929 static void autoreplier_config_init(LinphoneCore *lc)
931 autoreplier_config_t *config=&lc->autoreplier_conf;
932 config->enabled=lp_config_get_int(lc->config,"autoreplier","enabled",0);
933 config->after_seconds=lp_config_get_int(lc->config,"autoreplier","after_seconds",6);
934 config->max_users=lp_config_get_int(lc->config,"autoreplier","max_users",1);
935 config->max_rec_time=lp_config_get_int(lc->config,"autoreplier","max_rec_time",60);
936 config->max_rec_msg=lp_config_get_int(lc->config,"autoreplier","max_rec_msg",10);
937 config->message=lp_config_get_string(lc->config,"autoreplier","message",NULL);
942 * Sets maximum available download bandwidth
944 * @ingroup media_parameters
946 * This is IP bandwidth, in kbit/s.
947 * This information is used signaled to other parties during
948 * calls (within SDP messages) so that the remote end can have
949 * sufficient knowledge to properly configure its audio & video
950 * codec output bitrate to not overflow available bandwidth.
952 * @param lc the LinphoneCore object
953 * @param bw the bandwidth in kbits/s, 0 for infinite
955 void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
956 lc->net_conf.download_bw=bw;
957 if (bw==0){ /*infinite*/
961 lc->dw_audio_bw=MIN(lc->audio_bw,bw);
962 lc->dw_video_bw=MAX(bw-lc->dw_audio_bw-10,0);/*-10: security margin*/
967 * Sets maximum available upload bandwidth
969 * @ingroup media_parameters
971 * This is IP bandwidth, in kbit/s.
972 * This information is used by liblinphone together with remote
973 * side available bandwidth signaled in SDP messages to properly
974 * configure audio & video codec's output bitrate.
976 * @param lc the LinphoneCore object
977 * @param bw the bandwidth in kbits/s, 0 for infinite
979 void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
980 lc->net_conf.upload_bw=bw;
981 if (bw==0){ /*infinite*/
985 lc->up_audio_bw=MIN(lc->audio_bw,bw);
986 lc->up_video_bw=MAX(bw-lc->up_audio_bw-10,0);/*-10: security margin*/
991 * Retrieve the maximum available download bandwidth.
993 * @ingroup media_parameters
995 * This value was set by linphone_core_set_download_bandwidth().
998 int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
999 return lc->net_conf.download_bw;
1003 * Retrieve the maximum available upload bandwidth.
1005 * @ingroup media_parameters
1007 * This value was set by linphone_core_set_upload_bandwidth().
1010 int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
1011 return lc->net_conf.upload_bw;
1014 * set audio packetization time linphone expect to received from peer
1016 void linphone_core_set_download_ptime(LinphoneCore *lc, int ptime) {
1017 lc->net_conf.down_ptime=ptime;
1020 int linphone_core_get_download_ptime(LinphoneCore *lc) {
1021 return lc->net_conf.down_ptime;
1026 * Returns liblinphone's version as a string.
1031 const char * linphone_core_get_version(void){
1032 return liblinphone_version;
1036 static MSList *linphone_payload_types=NULL;
1038 static void linphone_core_assign_payload_type(PayloadType *const_pt, int number, const char *recv_fmtp){
1040 pt=payload_type_clone(const_pt);
1041 payload_type_set_number(pt,number);
1042 if (recv_fmtp!=NULL) payload_type_set_recv_fmtp(pt,recv_fmtp);
1043 rtp_profile_set_payload(&av_profile,number,pt);
1044 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
1047 static void linphone_core_free_payload_types(void){
1048 ms_list_for_each(linphone_payload_types,(void (*)(void*))payload_type_destroy);
1049 ms_list_free(linphone_payload_types);
1050 linphone_payload_types=NULL;
1053 static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path,
1054 const char *factory_config_path, void * userdata)
1056 memset (lc, 0, sizeof (LinphoneCore));
1059 memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
1061 gstate_initialize(lc);
1062 gstate_new_state(lc, GSTATE_POWER_STARTUP, NULL);
1065 linphone_core_assign_payload_type(&payload_type_pcmu8000,0,NULL);
1066 linphone_core_assign_payload_type(&payload_type_gsm,3,NULL);
1067 linphone_core_assign_payload_type(&payload_type_pcma8000,8,NULL);
1068 linphone_core_assign_payload_type(&payload_type_lpc1015,115,NULL);
1069 linphone_core_assign_payload_type(&payload_type_speex_nb,110,"vbr=on");
1070 linphone_core_assign_payload_type(&payload_type_speex_wb,111,"vbr=on");
1071 linphone_core_assign_payload_type(&payload_type_speex_uwb,112,"vbr=on");
1072 linphone_core_assign_payload_type(&payload_type_telephone_event,101,"0-11");
1073 linphone_core_assign_payload_type(&payload_type_ilbc,113,"mode=30");
1074 linphone_core_assign_payload_type(&payload_type_amr,114,"octet-align=1");
1076 #ifdef ENABLE_NONSTANDARD_GSM
1079 pt=payload_type_clone(&payload_type_gsm);
1080 pt->clock_rate=11025;
1081 rtp_profile_set_payload(&av_profile,114,pt);
1082 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
1083 pt=payload_type_clone(&payload_type_gsm);
1084 pt->clock_rate=22050;
1085 rtp_profile_set_payload(&av_profile,115,pt);
1086 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
1090 #ifdef VIDEO_ENABLED
1091 linphone_core_assign_payload_type(&payload_type_h263,34,NULL);
1092 linphone_core_assign_payload_type(&payload_type_theora,97,NULL);
1093 linphone_core_assign_payload_type(&payload_type_h263_1998,98,"CIF=1;QCIF=1");
1094 linphone_core_assign_payload_type(&payload_type_mp4v,99,"profile-level-id=3");
1095 linphone_core_assign_payload_type(&payload_type_x_snow,100,NULL);
1096 linphone_core_assign_payload_type(&payload_type_h264,102,NULL);
1097 linphone_core_assign_payload_type(&payload_type_h264,103,"packetization-mode=1");
1102 lc->config=lp_config_new(config_path);
1103 if (factory_config_path)
1104 lp_config_read_file(lc->config,factory_config_path);
1107 sal_set_user_pointer(lc->sal,lc);
1108 sal_set_callbacks(lc->sal,&linphone_sal_callbacks);
1109 if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
1110 sal_use_session_timers(lc->sal,200);
1112 sip_setup_register_all();
1113 sound_config_read(lc);
1114 net_config_read(lc);
1115 rtp_config_read(lc);
1116 codecs_config_read(lc);
1117 sip_config_read(lc); /* this will start eXosip*/
1118 video_config_read(lc);
1119 //autoreplier_config_init(&lc->autoreplier_conf);
1120 lc->prev_mode=LINPHONE_STATUS_ONLINE;
1121 lc->presence_mode=LINPHONE_STATUS_ONLINE;
1122 lc->max_call_logs=15;
1124 lc->vtable.display_status(lc,_("Ready"));
1125 gstate_new_state(lc, GSTATE_POWER_ON, NULL);
1126 lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
1132 * Instanciates a LinphoneCore object.
1133 * @ingroup initializing
1135 * The LinphoneCore object is the primary handle for doing all phone actions.
1136 * It should be unique within your application.
1137 * @param vtable a LinphoneCoreVTable structure holding your application callbacks
1138 * @param config_path a path to a config file. If it does not exists it will be created.
1139 * The config file is used to store all user settings, call logs, friends, proxies...
1140 * @param factory_config_path a path to a read-only config file that can be used to
1141 * to store hard-coded preference such as proxy settings or internal preferences.
1142 * The settings in this factory file always override the one in the normal config file.
1143 * It is OPTIONAL, use NULL if unneeded.
1144 * @param userdata an opaque user pointer that can be retrieved at any time (for example in
1145 * callbacks) using linphone_core_get_user_data().
1148 LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
1149 const char *config_path, const char *factory_config_path, void * userdata)
1151 LinphoneCore *core=ms_new(LinphoneCore,1);
1152 linphone_core_init(core,vtable,config_path, factory_config_path, userdata);
1157 * Returns the list of available audio codecs.
1159 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1160 * structure holding the codec information.
1161 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1162 * (such as the order of codecs).
1164 const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
1166 return lc->codecs_conf.audio_codecs;
1170 * Returns the list of available video codecs.
1172 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1173 * structure holding the codec information.
1174 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1175 * (such as the order of codecs).
1177 const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
1179 return lc->codecs_conf.video_codecs;
1183 * Sets the local "from" identity.
1186 * This data is used in absence of any proxy configuration or when no
1187 * default proxy configuration is set. See LinphoneProxyConfig
1189 int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact)
1191 LinphoneAddress *ctt;
1193 if ((ctt=linphone_address_new(contact))==0) {
1194 ms_error("Bad contact url: %s",contact);
1197 if (lc->sip_conf.contact!=NULL) ms_free(lc->sip_conf.contact);
1198 lc->sip_conf.contact=ms_strdup(contact);
1199 if (lc->sip_conf.guessed_contact!=NULL){
1200 ms_free(lc->sip_conf.guessed_contact);
1201 lc->sip_conf.guessed_contact=NULL;
1203 linphone_address_destroy(ctt);
1208 /*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
1209 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
1210 if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
1211 strncpy(result,linphone_core_get_nat_address(lc),LINPHONE_IPADDR_SIZE);
1214 if (linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,dest,result)==0)
1216 /*else fallback to SAL routine that will attempt to find the most realistic interface */
1217 sal_get_default_local_ip(lc->sal,lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,result,LINPHONE_IPADDR_SIZE);
1220 static void update_primary_contact(LinphoneCore *lc){
1222 char tmp[LINPHONE_IPADDR_SIZE];
1224 LinphoneAddress *url;
1225 if (lc->sip_conf.guessed_contact!=NULL){
1226 ms_free(lc->sip_conf.guessed_contact);
1227 lc->sip_conf.guessed_contact=NULL;
1229 url=linphone_address_new(lc->sip_conf.contact);
1231 ms_error("Could not parse identity contact !");
1232 url=linphone_address_new("sip:unknown@unkwownhost");
1234 linphone_core_get_local_ip(lc, NULL, tmp);
1235 if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
1236 ms_warning("Local loopback network only !");
1237 lc->sip_conf.loopback_only=TRUE;
1238 }else lc->sip_conf.loopback_only=FALSE;
1239 linphone_address_set_domain(url,tmp);
1240 linphone_address_set_port_int(url,lc->sip_conf.sip_port);
1241 guessed=linphone_address_as_string(url);
1242 lc->sip_conf.guessed_contact=guessed;
1243 linphone_address_destroy(url);
1247 * Returns the default identity when no proxy configuration is used.
1251 const char *linphone_core_get_primary_contact(LinphoneCore *lc){
1254 if (lc->sip_conf.guess_hostname){
1255 if (lc->sip_conf.guessed_contact==NULL || lc->sip_conf.loopback_only){
1256 update_primary_contact(lc);
1258 identity=lc->sip_conf.guessed_contact;
1260 identity=lc->sip_conf.contact;
1266 * Tells LinphoneCore to guess local hostname automatically in primary contact.
1270 void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
1271 lc->sip_conf.guess_hostname=val;
1275 * Returns TRUE if hostname part of primary contact is guessed automatically.
1279 bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
1280 return lc->sip_conf.guess_hostname;
1284 * Same as linphone_core_get_primary_contact() but the result is a LinphoneAddress object
1285 * instead of const char*
1289 LinphoneAddress *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
1290 return linphone_address_new(linphone_core_get_primary_contact(lc));
1294 * Sets the list of audio codecs.
1296 * @ingroup media_parameters
1297 * The list is taken by the LinphoneCore thus the application should not free it.
1298 * This list is made of struct PayloadType describing the codec parameters.
1300 int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
1302 if (lc->codecs_conf.audio_codecs!=NULL) ms_list_free(lc->codecs_conf.audio_codecs);
1303 lc->codecs_conf.audio_codecs=codecs;
1308 * Sets the list of video codecs.
1310 * @ingroup media_parameters
1311 * The list is taken by the LinphoneCore thus the application should not free it.
1312 * This list is made of struct PayloadType describing the codec parameters.
1314 int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
1316 if (lc->codecs_conf.video_codecs!=NULL) ms_list_free(lc->codecs_conf.video_codecs);
1317 lc->codecs_conf.video_codecs=codecs;
1321 const MSList * linphone_core_get_friend_list(const LinphoneCore *lc)
1327 * Returns the nominal jitter buffer size in milliseconds.
1329 * @ingroup media_parameters
1331 int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
1333 return lc->rtp_conf.audio_jitt_comp;
1337 * Returns the UDP port used for audio streaming.
1339 * @ingroup network_parameters
1341 int linphone_core_get_audio_port(const LinphoneCore *lc)
1343 return lc->rtp_conf.audio_rtp_port;
1347 * Returns the UDP port used for video streaming.
1349 * @ingroup network_parameters
1351 int linphone_core_get_video_port(const LinphoneCore *lc){
1352 return lc->rtp_conf.video_rtp_port;
1357 * Returns the value in seconds of the no-rtp timeout.
1359 * @ingroup media_parameters
1360 * When no RTP or RTCP packets have been received for a while
1361 * LinphoneCore will consider the call is broken (remote end crashed or
1362 * disconnected from the network), and thus will terminate the call.
1363 * The no-rtp timeout is the duration above which the call is considered broken.
1365 int linphone_core_get_nortp_timeout(const LinphoneCore *lc){
1366 return lc->rtp_conf.nortp_timeout;
1369 bool_t linphone_core_get_rtp_no_xmit_on_audio_mute(const LinphoneCore *lc){
1370 return lc->rtp_conf.rtp_no_xmit_on_audio_mute;
1374 * Sets the nominal audio jitter buffer size in milliseconds.
1376 * @ingroup media_parameters
1378 void linphone_core_set_audio_jittcomp(LinphoneCore *lc, int value)
1380 lc->rtp_conf.audio_jitt_comp=value;
1383 void linphone_core_set_rtp_no_xmit_on_audio_mute(LinphoneCore *lc,bool_t rtp_no_xmit_on_audio_mute){
1384 lc->rtp_conf.rtp_no_xmit_on_audio_mute=rtp_no_xmit_on_audio_mute;
1388 * Sets the UDP port used for audio streaming.
1390 * @ingroup network_parameters
1392 void linphone_core_set_audio_port(LinphoneCore *lc, int port)
1394 lc->rtp_conf.audio_rtp_port=port;
1398 * Sets the UDP port used for video streaming.
1400 * @ingroup network_parameters
1402 void linphone_core_set_video_port(LinphoneCore *lc, int port){
1403 lc->rtp_conf.video_rtp_port=port;
1407 * Sets the no-rtp timeout value in seconds.
1409 * @ingroup media_parameters
1410 * See linphone_core_get_nortp_timeout() for details.
1412 void linphone_core_set_nortp_timeout(LinphoneCore *lc, int nortp_timeout){
1413 lc->rtp_conf.nortp_timeout=nortp_timeout;
1417 * Indicates whether SIP INFO is used for sending digits.
1419 * @ingroup media_parameters
1421 bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
1423 return lc->sip_conf.use_info;
1427 * Sets whether SIP INFO is to be used for sending digits.
1429 * @ingroup media_parameters
1431 void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
1433 lc->sip_conf.use_info=use_info;
1437 * Indicates whether RFC2833 is used for sending digits.
1439 * @ingroup media_parameters
1441 bool_t linphone_core_get_use_rfc2833_for_dtmf(LinphoneCore *lc)
1443 return lc->sip_conf.use_rfc2833;
1447 * Sets whether RFC2833 is to be used for sending digits.
1449 * @ingroup media_parameters
1451 void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833)
1453 lc->sip_conf.use_rfc2833=use_rfc2833;
1457 * Returns the UDP port used by SIP.
1459 * @ingroup network_parameters
1461 int linphone_core_get_sip_port(LinphoneCore *lc)
1463 return lc->sip_conf.sip_port;
1466 static char _ua_name[64]="Linphone";
1467 static char _ua_version[64]=LINPHONE_VERSION;
1469 #ifdef HAVE_EXOSIP_GET_VERSION
1470 extern const char *eXosip_get_version();
1473 static void apply_user_agent(LinphoneCore *lc){
1474 char ua_string[256];
1475 snprintf(ua_string,sizeof(ua_string)-1,"%s/%s (eXosip2/%s)",_ua_name,_ua_version,
1476 #ifdef HAVE_EXOSIP_GET_VERSION
1477 eXosip_get_version()
1482 if (lc->sal) sal_set_user_agent(lc->sal,ua_string);
1486 * Sets the user agent string used in SIP messages.
1490 void linphone_core_set_user_agent(const char *name, const char *ver){
1491 strncpy(_ua_name,name,sizeof(_ua_name)-1);
1492 strncpy(_ua_version,ver,sizeof(_ua_version));
1496 * Sets the UDP port to be used by SIP.
1498 * @ingroup network_parameters
1500 void linphone_core_set_sip_port(LinphoneCore *lc,int port)
1502 const char *anyaddr;
1504 if (port==lc->sip_conf.sip_port) return;
1505 lc->sip_conf.sip_port=port;
1507 if (lc->sal==NULL) return;
1509 if (lc->sip_conf.ipv6_enabled)
1515 err=sal_listen_port (lc->sal,anyaddr,port, lc->sip_conf.transport,FALSE);
1517 char *msg=ortp_strdup_printf("Port %i seems already in use ! Cannot initialize.",port);
1519 lc->vtable.display_warning(lc,msg);
1523 apply_user_agent(lc);
1527 * Returns TRUE if IPv6 is enabled.
1529 * @ingroup network_parameters
1530 * See linphone_core_enable_ipv6() for more details on how IPv6 is supported in liblinphone.
1532 bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
1533 return lc->sip_conf.ipv6_enabled;
1537 * Turns IPv6 support on or off.
1539 * @ingroup network_parameters
1541 * @note IPv6 support is exclusive with IPv4 in liblinphone:
1542 * when IPv6 is turned on, IPv4 calls won't be possible anymore.
1543 * By default IPv6 support is off.
1545 void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
1546 if (lc->sip_conf.ipv6_enabled!=val){
1547 lc->sip_conf.ipv6_enabled=val;
1549 /* we need to restart eXosip */
1550 linphone_core_set_sip_port(lc, lc->sip_conf.sip_port);
1555 static void display_bandwidth(RtpSession *as, RtpSession *vs){
1556 ms_message("bandwidth usage: audio=[d=%.1f,u=%.1f] video=[d=%.1f,u=%.1f] kbit/sec",
1557 (as!=NULL) ? (rtp_session_compute_recv_bandwidth(as)*1e-3) : 0,
1558 (as!=NULL) ? (rtp_session_compute_send_bandwidth(as)*1e-3) : 0,
1559 (vs!=NULL) ? (rtp_session_compute_recv_bandwidth(vs)*1e-3) : 0,
1560 (vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0);
1563 static void linphone_core_disconnected(LinphoneCore *lc){
1564 lc->vtable.display_warning(lc,_("Remote end seems to have disconnected, the call is going to be closed."));
1565 linphone_core_terminate_call(lc,NULL);
1568 static void monitor_network_state(LinphoneCore *lc, time_t curtime){
1569 static time_t last_check=0;
1570 static bool_t last_status=FALSE;
1571 char result[LINPHONE_IPADDR_SIZE];
1572 bool_t new_status=last_status;
1574 /* only do the network up checking every five seconds */
1575 if (last_check==0 || (curtime-last_check)>=5){
1576 linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,NULL,result);
1577 if (strcmp(result,"::1")!=0 && strcmp(result,"127.0.0.1")!=0){
1579 }else new_status=FALSE;
1581 if (new_status!=last_status) {
1583 ms_message("New local ip address is %s",result);
1585 set_network_reachable(lc,new_status);
1586 last_status=new_status;
1591 static void proxy_update(LinphoneCore *lc){
1592 ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
1595 static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){
1596 LinphoneFriend *lf=linphone_core_get_friend_by_address(lc,info->sip_uri);
1599 ms_message("%s has a BuddyInfo assigned with image %p",info->sip_uri, info->image_data);
1600 if (lc->vtable.buddy_info_updated)
1601 lc->vtable.buddy_info_updated(lc,lf);
1603 ms_warning("Could not any friend with uri %s",info->sip_uri);
1607 static void analyze_buddy_lookup_results(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1609 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1610 for (elem=lc->bl_reqs;elem!=NULL;elem=ms_list_next(elem)){
1611 BuddyLookupRequest *req=(BuddyLookupRequest *)elem->data;
1612 if (req->status==BuddyLookupDone || req->status==BuddyLookupFailure){
1613 if (req->results!=NULL){
1614 BuddyInfo *i=(BuddyInfo*)req->results->data;
1615 ms_list_free(req->results);
1617 assign_buddy_info(lc,i);
1619 sip_setup_context_buddy_lookup_free(ctx,req);
1623 /*purge completed requests */
1624 while((elem=ms_list_find(lc->bl_reqs,NULL))!=NULL){
1625 lc->bl_reqs=ms_list_remove_link(lc->bl_reqs,elem);
1629 static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1631 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1632 for(elem=linphone_core_get_friend_list(lc);elem!=NULL;elem=elem->next){
1633 LinphoneFriend *lf=(LinphoneFriend*)elem->data;
1634 if (lf->info==NULL){
1635 if (linphone_core_lookup_known_proxy(lc,lf->uri)==cfg){
1636 if (linphone_address_get_username(lf->uri)!=NULL){
1637 BuddyLookupRequest *req;
1638 char *tmp=linphone_address_as_string_uri_only(lf->uri);
1639 req=sip_setup_context_create_buddy_lookup_request(ctx);
1640 buddy_lookup_request_set_key(req,tmp);
1641 buddy_lookup_request_set_max_results(req,1);
1642 sip_setup_context_buddy_lookup_submit(ctx,req);
1643 lc->bl_reqs=ms_list_append(lc->bl_reqs,req);
1651 static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
1652 LinphoneProxyConfig *cfg=NULL;
1653 linphone_core_get_default_proxy(lc,&cfg);
1655 if (lc->bl_refresh){
1656 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1657 if (ctx && (sip_setup_context_get_capabilities(ctx) & SIP_SETUP_CAP_BUDDY_LOOKUP)){
1658 linphone_core_grab_buddy_infos(lc,cfg);
1659 lc->bl_refresh=FALSE;
1662 if (lc->bl_reqs) analyze_buddy_lookup_results(lc,cfg);
1667 * Main loop function. It is crucial that your application call it periodically.
1669 * @ingroup initializing
1670 * linphone_core_iterate() performs various backgrounds tasks:
1671 * - receiving of SIP messages
1672 * - handles timers and timeout
1673 * - performs registration to proxies
1674 * - authentication retries
1675 * The application MUST call this function from periodically, in its main loop.
1676 * Be careful that this function must be call from the same thread as
1677 * other liblinphone methods. In not the case make sure all liblinphone calls are
1678 * serialized with a mutex.
1680 void linphone_core_iterate(LinphoneCore *lc){
1681 int disconnect_timeout = linphone_core_get_nortp_timeout(lc);
1682 time_t curtime=time(NULL);
1684 bool_t one_second_elapsed=FALSE;
1685 bool_t disconnected=FALSE;
1687 if (curtime-lc->prevtime>=1){
1688 lc->prevtime=curtime;
1689 one_second_elapsed=TRUE;
1692 if (lc->preview_finished){
1693 lc->preview_finished=0;
1694 ring_stop(lc->ringstream);
1695 lc->ringstream=NULL;
1696 lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
1699 sal_iterate(lc->sal);
1700 if (lc->auto_net_state_mon) monitor_network_state(lc,curtime);
1704 if (lc->call!=NULL){
1705 LinphoneCall *call=lc->call;
1706 if (call->state==LCStatePreEstablishing && (curtime-call->start_time>=2)){
1707 /*start the call even if the OPTIONS reply did not arrive*/
1708 linphone_core_start_invite(lc,call,NULL);
1710 if (call->dir==LinphoneCallIncoming && call->state==LCStateRinging){
1711 elapsed=curtime-call->start_time;
1712 ms_message("incoming call ringing for %i seconds",elapsed);
1713 if (elapsed>lc->sip_conf.inc_timeout){
1714 linphone_core_terminate_call(lc,NULL);
1716 }else if (call->state==LCStateAVRunning){
1717 if (one_second_elapsed){
1718 RtpSession *as=NULL,*vs=NULL;
1719 lc->prevtime=curtime;
1720 if (lc->audiostream!=NULL)
1721 as=lc->audiostream->session;
1722 if (lc->videostream!=NULL)
1723 vs=lc->videostream->session;
1724 display_bandwidth(as,vs);
1726 #ifdef VIDEO_ENABLED
1727 if (lc->videostream!=NULL)
1728 video_stream_iterate(lc->videostream);
1730 if (lc->audiostream!=NULL && disconnect_timeout>0)
1731 disconnected=!audio_stream_alive(lc->audiostream,disconnect_timeout);
1734 if (linphone_core_video_preview_enabled(lc)){
1735 if (lc->previewstream==NULL)
1736 toggle_video_preview(lc,TRUE);
1737 #ifdef VIDEO_ENABLED
1738 else video_stream_iterate(lc->previewstream);
1741 if (lc->previewstream!=NULL)
1742 toggle_video_preview(lc,FALSE);
1745 linphone_core_disconnected(lc);
1747 linphone_core_do_plugin_tasks(lc);
1749 if (one_second_elapsed && lp_config_needs_commit(lc->config)){
1750 lp_config_sync(lc->config);
1755 * Interpret a call destination as supplied by the user, and returns a fully qualified
1758 * A sip address should look like DisplayName <sip:username@domain:port> .
1759 * Basically this function performs the following tasks
1760 * - if a phone number is entered, prepend country prefix of the default proxy
1761 * configuration, eventually escape the '+' by 00.
1762 * - if no domain part is supplied, append the domain name of the default proxy
1763 * - if no sip: is present, prepend it
1765 * The result is a syntaxically correct SIP address.
1768 LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url){
1769 enum_lookup_res_t *enumres=NULL;
1770 char *enum_domain=NULL;
1771 LinphoneProxyConfig *proxy=lc->default_proxy;;
1773 LinphoneAddress *uri;
1775 if (is_enum(url,&enum_domain)){
1776 lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
1777 if (enum_lookup(enum_domain,&enumres)<0){
1778 lc->vtable.display_status(lc,_("Could not resolve this number."));
1779 ms_free(enum_domain);
1782 ms_free(enum_domain);
1783 tmpurl=enumres->sip_address[0];
1784 uri=linphone_address_new(tmpurl);
1785 enum_lookup_res_free(enumres);
1788 /* check if we have a "sip:" */
1789 if (strstr(url,"sip:")==NULL){
1790 /* this doesn't look like a true sip uri */
1791 if (strchr(url,'@')!=NULL){
1792 /* seems like sip: is missing !*/
1793 tmpurl=ms_strdup_printf("sip:%s",url);
1794 uri=linphone_address_new(tmpurl);
1802 /* append the proxy domain suffix */
1803 const char *identity=linphone_proxy_config_get_identity(proxy);
1804 char normalized_username[128];
1805 uri=linphone_address_new(identity);
1809 linphone_address_set_display_name(uri,NULL);
1810 linphone_proxy_config_normalize_number(proxy,url,normalized_username,
1811 sizeof(normalized_username));
1812 linphone_address_set_username(uri,normalized_username);
1816 uri=linphone_address_new(url);
1820 /* else we could not do anything with url given by user, so display an error */
1821 if (lc->vtable.display_warning!=NULL){
1822 lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
1828 * Returns the default identity SIP address.
1831 * This is an helper function:
1833 * If no default proxy is set, this will return the primary contact (
1834 * see linphone_core_get_primary_contact() ). If a default proxy is set
1835 * it returns the registered identity on the proxy.
1837 const char * linphone_core_get_identity(LinphoneCore *lc){
1838 LinphoneProxyConfig *proxy=NULL;
1840 linphone_core_get_default_proxy(lc,&proxy);
1842 from=linphone_proxy_config_get_identity(proxy);
1843 }else from=linphone_core_get_primary_contact(lc);
1847 const char * linphone_core_get_route(LinphoneCore *lc){
1848 LinphoneProxyConfig *proxy=NULL;
1849 const char *route=NULL;
1850 linphone_core_get_default_proxy(lc,&proxy);
1852 route=linphone_proxy_config_get_route(proxy);
1857 bool_t linphone_core_is_in_communication_with(LinphoneCore *lc, const char *to)
1861 const LinphoneAddress *la=linphone_core_get_remote_uri(lc);
1866 tmp = linphone_address_as_string(la);
1876 LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
1878 LinphoneProxyConfig *found_cfg=NULL;
1879 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=elem->next){
1880 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1881 const char *domain=linphone_proxy_config_get_domain(cfg);
1882 if (domain!=NULL && strcmp(domain,linphone_address_get_domain(uri))==0){
1890 static char *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){
1891 LinphoneAddress *ctt;
1892 const char *localip=call->localip;
1894 /* first use user's supplied ip address if asked*/
1895 if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
1896 ctt=linphone_core_get_primary_contact_parsed(lc);
1897 return ms_strdup_printf("sip:%s@%s",linphone_address_get_username(ctt),
1898 linphone_core_get_nat_address(lc));
1901 /* if already choosed, don't change it */
1902 if (call->op && sal_op_get_contact(call->op)!=NULL){
1906 /* if the ping OPTIONS request succeeded use the contact guessed from the
1909 const char *guessed=sal_op_get_contact(call->ping_op);
1911 ms_message("Contact has been fixed using OPTIONS to %s",guessed);
1912 return ms_strdup(guessed);
1916 /*if using a proxy, use the contact address as guessed with the REGISTERs*/
1917 if (dest_proxy && dest_proxy->op){
1918 const char *fixed_contact=sal_op_get_contact(dest_proxy->op);
1919 if (fixed_contact) {
1920 ms_message("Contact has been fixed using proxy to %s",fixed_contact);
1921 return ms_strdup(fixed_contact);
1925 ctt=linphone_core_get_primary_contact_parsed(lc);
1929 /*otherwise use supllied localip*/
1930 linphone_address_set_domain(ctt,localip);
1931 linphone_address_set_port_int(ctt,linphone_core_get_sip_port(lc));
1932 ret=linphone_address_as_string_uri_only(ctt);
1933 linphone_address_destroy(ctt);
1934 ms_message("Contact has been fixed using local ip to %s",ret);
1940 int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphoneProxyConfig *dest_proxy){
1943 char *real_url,*barmsg;
1945 /*try to be best-effort in giving real local or routable contact address */
1946 contact=get_fixed_contact(lc,call,dest_proxy);
1948 sal_op_set_contact(call->op, contact);
1951 call->state=LCStateInit;
1952 linphone_core_init_media_streams(lc,lc->call);
1953 if (!lc->sip_conf.sdp_200_ack){
1954 call->media_pending=TRUE;
1955 sal_call_set_local_media_description(call->op,call->localdesc);
1957 real_url=linphone_address_as_string(call->log->to);
1958 from=linphone_address_as_string(call->log->from);
1959 err=sal_call(call->op,from,real_url);
1961 if (lc->sip_conf.sdp_200_ack){
1962 call->media_pending=TRUE;
1963 sal_call_set_local_media_description(call->op,call->localdesc);
1965 barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
1966 lc->vtable.display_status(lc,barmsg);
1970 ms_warning("Could not initiate call.");
1971 lc->vtable.display_status(lc,_("could not call"));
1972 linphone_core_stop_media_streams(lc,call);
1973 linphone_call_destroy(call);
1975 }else gstate_new_state(lc, GSTATE_CALL_OUT_INVITE, real_url);
1982 * Initiates an outgoing call
1984 * @ingroup call_control
1985 * @param lc the LinphoneCore object
1986 * @param url the destination of the call (sip address, or phone number).
1988 int linphone_core_invite(LinphoneCore *lc, const char *url){
1989 LinphoneAddress *addr=linphone_core_interpret_url(lc,url);
1992 err=linphone_core_invite_address(lc,addr);
1993 linphone_address_destroy(addr);
2000 * Initiates an outgoing call given a destination LinphoneAddress
2002 * @ingroup call_control
2003 * @param lc the LinphoneCore object
2004 * @param url the destination of the call (sip address).
2006 int linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *real_parsed_url)
2009 const char *route=NULL;
2010 const char *from=NULL;
2011 LinphoneProxyConfig *proxy=NULL;
2012 LinphoneAddress *parsed_url2=NULL;
2013 char *real_url=NULL;
2014 LinphoneProxyConfig *dest_proxy=NULL;
2017 if (lc->call!=NULL){
2018 lc->vtable.display_warning(lc,_("Sorry, having multiple simultaneous calls is not supported yet !"));
2022 linphone_core_get_default_proxy(lc,&proxy);
2023 route=linphone_core_get_route(lc);
2025 real_url=linphone_address_as_string(real_parsed_url);
2026 dest_proxy=linphone_core_lookup_known_proxy(lc,real_parsed_url);
2028 if (proxy!=dest_proxy && dest_proxy!=NULL) {
2029 ms_message("Overriding default proxy setting for this call:");
2030 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
2033 if (dest_proxy!=NULL)
2034 from=linphone_proxy_config_get_identity(dest_proxy);
2035 else if (proxy!=NULL)
2036 from=linphone_proxy_config_get_identity(proxy);
2038 /* if no proxy or no identity defined for this proxy, default to primary contact*/
2039 if (from==NULL) from=linphone_core_get_primary_contact(lc);
2041 parsed_url2=linphone_address_new(from);
2043 call=linphone_call_new_outgoing(lc,parsed_url2,linphone_address_clone(real_parsed_url));
2044 sal_op_set_route(call->op,route);
2047 if (dest_proxy!=NULL || lc->sip_conf.ping_with_options==FALSE){
2048 err=linphone_core_start_invite(lc,call,dest_proxy);
2050 /*defer the start of the call after the OPTIONS ping*/
2051 call->state=LCStatePreEstablishing;
2052 call->ping_op=sal_op_new(lc->sal);
2053 sal_ping(call->ping_op,from,real_url);
2054 sal_op_set_user_pointer(call->ping_op,call);
2055 call->start_time=time(NULL);
2058 if (real_url!=NULL) ms_free(real_url);
2062 int linphone_core_refer(LinphoneCore *lc, const char *url)
2064 char *real_url=NULL;
2065 LinphoneAddress *real_parsed_url=linphone_core_interpret_url(lc,url);
2068 if (!real_parsed_url){
2074 ms_warning("No established call to refer.");
2077 //lc->call=NULL; //Do not do that you will lose the call afterward . . .
2078 real_url=linphone_address_as_string (real_parsed_url);
2079 sal_refer(call->op,real_url);
2085 * Returns true if in incoming call is pending, ie waiting for being answered or declined.
2087 * @ingroup call_control
2089 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
2090 if (lc->call!=NULL && lc->call->dir==LinphoneCallIncoming){
2096 void linphone_core_init_media_streams(LinphoneCore *lc, LinphoneCall *call){
2097 SalMediaDescription *md=call->localdesc;
2098 lc->audiostream=audio_stream_new(md->streams[0].port,linphone_core_ipv6_enabled(lc));
2099 if (linphone_core_echo_limiter_enabled(lc)){
2100 const char *type=lp_config_get_string(lc->config,"sound","el_type","mic");
2101 if (strcasecmp(type,"mic")==0)
2102 audio_stream_enable_echo_limiter(lc->audiostream,ELControlMic);
2103 else if (strcasecmp(type,"speaker")==0)
2104 audio_stream_enable_echo_limiter(lc->audiostream,ELControlSpeaker);
2106 audio_stream_enable_gain_control(lc->audiostream,TRUE);
2107 if (linphone_core_echo_cancellation_enabled(lc)){
2108 int len,delay,framesize;
2109 len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
2110 delay=lp_config_get_int(lc->config,"sound","ec_delay",0);
2111 framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0);
2112 audio_stream_set_echo_canceller_params(lc->audiostream,len,delay,framesize);
2114 audio_stream_enable_automatic_gain_control(lc->audiostream,linphone_core_agc_enabled(lc));
2116 int enabled=lp_config_get_int(lc->config,"sound","noisegate",0);
2117 audio_stream_enable_noise_gate(lc->audiostream,enabled);
2120 rtp_session_set_transports(lc->audiostream->session,lc->a_rtp,lc->a_rtcp);
2122 #ifdef VIDEO_ENABLED
2123 if ((lc->video_conf.display || lc->video_conf.capture) && md->streams[1].port>0)
2124 lc->videostream=video_stream_new(md->streams[1].port,linphone_core_ipv6_enabled(lc));
2126 lc->videostream=NULL;
2130 static int dtmf_tab[16]={'0','1','2','3','4','5','6','7','8','9','*','#','A','B','C','D'};
2132 static void linphone_core_dtmf_received(RtpSession* s, int dtmf, void* user_data){
2133 LinphoneCore* lc = (LinphoneCore*)user_data;
2134 if (dtmf<0 || dtmf>15){
2135 ms_warning("Bad dtmf value %i",dtmf);
2138 if (lc->vtable.dtmf_received != NULL)
2139 lc->vtable.dtmf_received(lc, dtmf_tab[dtmf]);
2142 static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){
2144 MSFilter *f=st->equalizer;
2145 int enabled=lp_config_get_int(lc->config,"sound","eq_active",0);
2146 const char *gains=lp_config_get_string(lc->config,"sound","eq_gains",NULL);
2147 ms_filter_call_method(f,MS_EQUALIZER_SET_ACTIVE,&enabled);
2153 if (sscanf(gains,"%f:%f:%f %n",&g.frequency,&g.gain,&g.width,&bytes)==3){
2154 ms_message("Read equalizer gains: %f(~%f) --> %f",g.frequency,g.width,g.gain);
2155 ms_filter_call_method(f,MS_EQUALIZER_SET_GAIN,&g);
2164 static void post_configure_audio_streams(LinphoneCore *lc){
2165 AudioStream *st=lc->audiostream;
2166 float gain=lp_config_get_float(lc->config,"sound","mic_gain",-1);
2168 audio_stream_set_mic_gain(st,gain);
2169 lc->audio_muted=FALSE;
2170 float recv_gain = lc->sound_conf.soft_play_lev;
2171 if (recv_gain != 0) {
2172 linphone_core_set_soft_play_level(lc,recv_gain);
2174 if (linphone_core_echo_limiter_enabled(lc)){
2175 float speed=lp_config_get_float(lc->config,"sound","el_speed",-1);
2176 float thres=lp_config_get_float(lc->config,"sound","el_thres",-1);
2177 float force=lp_config_get_float(lc->config,"sound","el_force",-1);
2178 int sustain=lp_config_get_int(lc->config,"sound","el_sustain",-1);
2180 if (st->el_type==ELControlMic){
2182 if (speed==-1) speed=0.03;
2183 if (force==-1) force=10;
2185 else if (st->el_type==ELControlSpeaker){
2187 if (speed==-1) speed=0.02;
2188 if (force==-1) force=5;
2191 ms_filter_call_method(f,MS_VOLUME_SET_EA_SPEED,&speed);
2193 ms_filter_call_method(f,MS_VOLUME_SET_EA_THRESHOLD,&thres);
2195 ms_filter_call_method(f,MS_VOLUME_SET_EA_FORCE,&force);
2197 ms_filter_call_method(f,MS_VOLUME_SET_EA_SUSTAIN,&sustain);
2201 float ng_thres=lp_config_get_float(lc->config,"sound","ng_thres",0.05);
2202 float ng_floorgain=lp_config_get_float(lc->config,"sound","ng_floorgain",0);
2203 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_thres);
2204 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&ng_floorgain);
2206 parametrize_equalizer(lc,st);
2207 if (lc->vtable.dtmf_received!=NULL){
2208 /* replace by our default action*/
2209 audio_stream_play_received_dtmfs(lc->audiostream,FALSE);
2210 rtp_session_signal_connect(lc->audiostream->session,"telephone-event",(RtpCallback)linphone_core_dtmf_received,(unsigned long)lc);
2214 static RtpProfile *make_profile(LinphoneCore *lc, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){
2217 RtpProfile *prof=rtp_profile_new("Call profile");
2222 for(elem=desc->payloads;elem!=NULL;elem=elem->next){
2223 PayloadType *pt=(PayloadType*)elem->data;
2226 if (desc->type==SalAudio){
2227 linphone_core_update_allocated_audio_bandwidth_in_call(lc,pt);
2229 *used_pt=payload_type_get_number(pt);
2232 if (desc->bandwidth>0) remote_bw=desc->bandwidth;
2233 else if (md->bandwidth>0) {
2234 /*case where b=AS is given globally, not per stream*/
2235 remote_bw=md->bandwidth;
2236 if (desc->type==SalVideo){
2237 remote_bw-=lc->audio_bw;
2241 if (desc->type==SalAudio){
2242 bw=get_min_bandwidth(lc->up_audio_bw,remote_bw);
2243 }else bw=get_min_bandwidth(lc->up_video_bw,remote_bw);
2244 if (bw>0) pt->normal_bitrate=bw*1000;
2245 else if (desc->type==SalAudio){
2246 pt->normal_bitrate=-1;
2250 snprintf(tmp,sizeof(tmp),"ptime=%i",desc->ptime);
2251 payload_type_append_send_fmtp(pt,tmp);
2253 rtp_profile_set_payload(prof,payload_type_get_number(pt),pt);
2258 void linphone_core_start_media_streams(LinphoneCore *lc, LinphoneCall *call){
2259 LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
2260 const char *tool="linphone-" LINPHONE_VERSION;
2263 /* adjust rtp jitter compensation. It must be at least the latency of the sound card */
2264 int jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
2266 if (call->media_start_time==0) call->media_start_time=time(NULL);
2268 cname=linphone_address_as_string_uri_only(me);
2270 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
2271 SalProtoRtpAvp,SalAudio);
2272 if (stream && stream->port!=0){
2273 call->audio_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
2274 if (!lc->use_files){
2275 MSSndCard *playcard=lc->sound_conf.play_sndcard;
2276 MSSndCard *captcard=lc->sound_conf.capt_sndcard;
2277 if (playcard==NULL) {
2278 ms_warning("No card defined for playback !");
2281 if (captcard==NULL) {
2282 ms_warning("No card defined for capture !");
2285 audio_stream_start_now(
2287 call->audio_profile,
2288 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
2295 linphone_core_echo_cancellation_enabled(lc));
2297 audio_stream_start_with_files(
2299 call->audio_profile,
2300 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
2308 post_configure_audio_streams(lc);
2309 audio_stream_set_rtcp_information(lc->audiostream, cname, tool);
2310 }else ms_warning("No audio stream defined ?");
2312 #ifdef VIDEO_ENABLED
2314 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
2315 SalProtoRtpAvp,SalVideo);
2316 /* shutdown preview */
2317 if (lc->previewstream!=NULL) {
2318 video_preview_stop(lc->previewstream);
2319 lc->previewstream=NULL;
2321 if (stream && stream->port!=0 && (lc->video_conf.display || lc->video_conf.capture)) {
2322 const char *addr=stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr;
2323 call->video_profile=make_profile(lc,call->resultdesc,stream,&used_pt);
2324 video_stream_set_sent_video_size(lc->videostream,linphone_core_get_preferred_video_size(lc));
2325 video_stream_enable_self_view(lc->videostream,lc->video_conf.selfview);
2326 if (lc->video_conf.display && lc->video_conf.capture)
2327 video_stream_start(lc->videostream,
2328 call->video_profile, addr, stream->port,
2330 used_pt, jitt_comp, lc->video_conf.device);
2331 else if (lc->video_conf.display)
2332 video_stream_recv_only_start(lc->videostream,
2333 call->video_profile, addr, stream->port,
2334 used_pt, jitt_comp);
2335 else if (lc->video_conf.capture)
2336 video_stream_send_only_start(lc->videostream,
2337 call->video_profile, addr, stream->port,
2339 used_pt, jitt_comp, lc->video_conf.device);
2340 video_stream_set_rtcp_information(lc->videostream, cname,tool);
2342 ms_warning("No valid video stream defined.");
2349 linphone_address_destroy(me);
2350 lc->call->state=LCStateAVRunning;
2353 static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
2354 audio_stream_get_local_rtp_stats (st,&log->local_stats);
2357 void linphone_core_stop_media_streams(LinphoneCore *lc, LinphoneCall *call){
2358 if (lc->audiostream!=NULL) {
2359 linphone_call_log_fill_stats (call->log,lc->audiostream);
2360 audio_stream_stop(lc->audiostream);
2361 lc->audiostream=NULL;
2363 #ifdef VIDEO_ENABLED
2364 if (lc->videostream!=NULL){
2365 if (lc->video_conf.display && lc->video_conf.capture)
2366 video_stream_stop(lc->videostream);
2367 else if (lc->video_conf.display)
2368 video_stream_recv_only_stop(lc->videostream);
2369 else if (lc->video_conf.capture)
2370 video_stream_send_only_stop(lc->videostream);
2371 lc->videostream=NULL;
2373 if (linphone_core_video_preview_enabled(lc)){
2374 if (lc->previewstream==NULL){
2375 lc->previewstream=video_preview_start(lc->video_conf.device, lc->video_conf.vsize);
2379 if (call->audio_profile){
2380 rtp_profile_clear_all(call->audio_profile);
2381 rtp_profile_destroy(call->audio_profile);
2382 call->audio_profile=NULL;
2384 if (call->video_profile){
2385 rtp_profile_clear_all(call->video_profile);
2386 rtp_profile_destroy(call->video_profile);
2387 call->video_profile=NULL;
2392 * Accept an incoming call.
2394 * @ingroup call_control
2395 * Basically the application is notified of incoming calls within the
2396 * invite_recv callback of the #LinphoneCoreVTable structure.
2397 * The application can later respond positively to the call using
2399 * @param lc the LinphoneCore object
2400 * @param url the SIP address of the originator of the call, or NULL.
2401 * This argument is useful for managing multiple calls simulatenously,
2402 * however this feature is not supported yet.
2403 * Using NULL will accept the unique incoming call in progress.
2405 int linphone_core_accept_call(LinphoneCore *lc, const char *url)
2407 LinphoneCall *call=lc->call;
2408 LinphoneProxyConfig *cfg=NULL;
2409 const char *contact=NULL;
2415 if (call->state==LCStateAVRunning){
2416 /*call already accepted*/
2421 if (lc->ringstream!=NULL) {
2422 ms_message("stop ringing");
2423 ring_stop(lc->ringstream);
2424 ms_message("ring stopped");
2425 lc->ringstream=NULL;
2428 linphone_core_get_default_proxy(lc,&cfg);
2429 /*try to be best-effort in giving real local or routable contact address*/
2430 contact=get_fixed_contact(lc,call,cfg);
2432 sal_op_set_contact(call->op,contact);
2434 sal_call_accept(call->op);
2435 lc->vtable.display_status(lc,_("Connected."));
2436 gstate_new_state(lc, GSTATE_CALL_IN_CONNECTED, NULL);
2437 call->resultdesc=sal_call_get_final_media_description(call->op);
2438 if (call->resultdesc){
2439 sal_media_description_ref(call->resultdesc);
2440 linphone_core_start_media_streams(lc, call);
2441 }else call->media_pending=TRUE;
2442 ms_message("call answered.");
2447 * Terminates a call.
2449 * @ingroup call_control
2450 * @param lc The LinphoneCore
2451 * @param url the destination of the call to be terminated, use NULL if there is
2452 * only one call (which is case in this version of liblinphone).
2454 int linphone_core_terminate_call(LinphoneCore *lc, const char *url)
2456 LinphoneCall *call=lc->call;
2461 sal_call_terminate(call->op);
2464 if (lc->ringstream!=NULL) {
2465 ring_stop(lc->ringstream);
2466 lc->ringstream=NULL;
2468 linphone_core_stop_media_streams(lc,call);
2469 lc->vtable.display_status(lc,_("Call ended") );
2470 gstate_new_state(lc, GSTATE_CALL_END, NULL);
2471 linphone_call_destroy(call);
2476 * Returns TRUE if there is a call running or pending.
2478 * @ingroup call_control
2480 bool_t linphone_core_in_call(const LinphoneCore *lc){
2481 return lc->call!=NULL;
2485 * Returns The _LinphoneCall struct of the current call if one is in call
2487 * @ingroup call_control
2489 struct _LinphoneCall *linphone_core_get_current_call(LinphoneCore *lc)
2491 if(linphone_core_in_call(lc))
2497 int linphone_core_send_publish(LinphoneCore *lc,
2498 LinphoneOnlineStatus presence_mode)
2501 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=ms_list_next(elem)){
2502 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2503 if (cfg->publish) linphone_proxy_config_send_publish(cfg,presence_mode);
2509 * Set the incoming call timeout in seconds.
2511 * @ingroup call_control
2512 * If an incoming call isn't answered for this timeout period, it is
2513 * automatically declined.
2515 void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
2516 lc->sip_conf.inc_timeout=seconds;
2520 * Returns the incoming call timeout
2522 * @ingroup call_control
2523 * See linphone_core_set_inc_timeout() for details.
2525 int linphone_core_get_inc_timeout(LinphoneCore *lc){
2526 return lc->sip_conf.inc_timeout;
2529 void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
2530 const char *contact,
2531 LinphoneOnlineStatus presence_mode)
2533 if (minutes_away>0) lc->minutes_away=minutes_away;
2535 if (lc->alt_contact!=NULL) {
2536 ms_free(lc->alt_contact);
2537 lc->alt_contact=NULL;
2539 if (contact) lc->alt_contact=ms_strdup(contact);
2540 if (lc->presence_mode!=presence_mode){
2541 linphone_core_notify_all_friends(lc,presence_mode);
2543 Improve the use of all LINPHONE_STATUS available.
2544 !TODO Do not mix "presence status" with "answer status code"..
2545 Use correct parameter to follow sip_if_match/sip_etag.
2547 linphone_core_send_publish(lc,presence_mode);
2549 lc->prev_mode=lc->presence_mode;
2550 lc->presence_mode=presence_mode;
2553 LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
2554 return lc->presence_mode;
2558 * Get playback sound level in 0-100 scale.
2560 * @ingroup media_parameters
2562 int linphone_core_get_play_level(LinphoneCore *lc)
2564 return lc->sound_conf.play_lev;
2568 * Get ring sound level in 0-100 scale
2570 * @ingroup media_parameters
2572 int linphone_core_get_ring_level(LinphoneCore *lc)
2574 return lc->sound_conf.ring_lev;
2578 * Get sound capture level in 0-100 scale
2580 * @ingroup media_parameters
2582 int linphone_core_get_rec_level(LinphoneCore *lc){
2583 return lc->sound_conf.rec_lev;
2587 * Set sound ring level in 0-100 scale
2589 * @ingroup media_parameters
2591 void linphone_core_set_ring_level(LinphoneCore *lc, int level){
2593 lc->sound_conf.ring_lev=level;
2594 sndcard=lc->sound_conf.ring_sndcard;
2595 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2599 void linphone_core_set_soft_play_level(LinphoneCore *lc, float level){
2601 lc->sound_conf.soft_play_lev=level;
2602 AudioStream *st=lc->audiostream;
2603 if (!st) return; /*just return*/
2606 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_DB_GAIN,&gain);
2607 }else ms_warning("Could not apply gain: gain control wasn't activated.");
2609 float linphone_core_get_soft_play_level(LinphoneCore *lc) {
2611 AudioStream *st=lc->audiostream;
2613 ms_filter_call_method(st->volrecv,MS_VOLUME_GET,&gain);
2614 }else ms_warning("Could not get gain: gain control wasn't activated.");
2620 * Set sound playback level in 0-100 scale
2622 * @ingroup media_parameters
2624 void linphone_core_set_play_level(LinphoneCore *lc, int level){
2626 lc->sound_conf.play_lev=level;
2627 sndcard=lc->sound_conf.play_sndcard;
2628 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2632 * Set sound capture level in 0-100 scale
2634 * @ingroup media_parameters
2636 void linphone_core_set_rec_level(LinphoneCore *lc, int level)
2639 lc->sound_conf.rec_lev=level;
2640 sndcard=lc->sound_conf.capt_sndcard;
2641 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_CAPTURE,level);
2644 static MSSndCard *get_card_from_string_id(const char *devid, unsigned int cap){
2645 MSSndCard *sndcard=NULL;
2647 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2648 if (sndcard!=NULL &&
2649 (ms_snd_card_get_capabilities(sndcard) & cap)==0 ){
2650 ms_warning("%s card does not have the %s capability, ignoring.",
2652 cap==MS_SND_CARD_CAP_CAPTURE ? "capture" : "playback");
2656 if (sndcard==NULL) {
2657 /* get a card that has read+write capabilities */
2658 sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
2659 /* otherwise refine to the first card having the right capability*/
2661 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2662 for(;elem!=NULL;elem=elem->next){
2663 sndcard=(MSSndCard*)elem->data;
2664 if (ms_snd_card_get_capabilities(sndcard) & cap) break;
2667 if (sndcard==NULL){/*looks like a bug! take the first one !*/
2668 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2669 if (elem) sndcard=(MSSndCard*)elem->data;
2672 if (sndcard==NULL) ms_error("Could not find a suitable soundcard !");
2677 * Returns true if the specified sound device can capture 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_capture(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_CAPTURE)) return TRUE;
2690 * Returns true if the specified sound device can play sound.
2692 * @ingroup media_parameters
2693 * @param devid the device name as returned by linphone_core_get_sound_devices()
2695 bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *devid){
2697 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2698 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_PLAYBACK)) return TRUE;
2703 * Sets the sound device used for ringing.
2705 * @ingroup media_parameters
2706 * @param devid the device name as returned by linphone_core_get_sound_devices()
2708 int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
2709 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2710 lc->sound_conf.ring_sndcard=card;
2711 if (card && lc->ready)
2712 lp_config_set_string(lc->config,"sound","ringer_dev_id",ms_snd_card_get_string_id(card));
2717 * Sets the sound device used for playback.
2719 * @ingroup media_parameters
2720 * @param devid the device name as returned by linphone_core_get_sound_devices()
2722 int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
2723 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2724 lc->sound_conf.play_sndcard=card;
2725 if (card && lc->ready)
2726 lp_config_set_string(lc->config,"sound","playback_dev_id",ms_snd_card_get_string_id(card));
2731 * Sets the sound device used for capture.
2733 * @ingroup media_parameters
2734 * @param devid the device name as returned by linphone_core_get_sound_devices()
2736 int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
2737 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_CAPTURE);
2738 lc->sound_conf.capt_sndcard=card;
2739 if (card && lc->ready)
2740 lp_config_set_string(lc->config,"sound","capture_dev_id",ms_snd_card_get_string_id(card));
2745 * Returns the name of the currently assigned sound device for ringing.
2747 * @ingroup media_parameters
2749 const char * linphone_core_get_ringer_device(LinphoneCore *lc)
2751 if (lc->sound_conf.ring_sndcard) return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
2756 * Returns the name of the currently assigned sound device for playback.
2758 * @ingroup media_parameters
2760 const char * linphone_core_get_playback_device(LinphoneCore *lc)
2762 return lc->sound_conf.play_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.play_sndcard) : NULL;
2766 * Returns the name of the currently assigned sound device for capture.
2768 * @ingroup media_parameters
2770 const char * linphone_core_get_capture_device(LinphoneCore *lc)
2772 return lc->sound_conf.capt_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard) : NULL;
2776 * Returns an unmodifiable array of available sound devices.
2778 * @ingroup media_parameters
2779 * The array is NULL terminated.
2781 const char** linphone_core_get_sound_devices(LinphoneCore *lc){
2782 build_sound_devices_table(lc);
2783 return lc->sound_conf.cards;
2787 * Returns an unmodifiable array of available video capture devices.
2789 * @ingroup media_parameters
2790 * The array is NULL terminated.
2792 const char** linphone_core_get_video_devices(const LinphoneCore *lc){
2793 return lc->video_conf.cams;
2796 char linphone_core_get_sound_source(LinphoneCore *lc)
2798 return lc->sound_conf.source;
2801 void linphone_core_set_sound_source(LinphoneCore *lc, char source)
2803 MSSndCard *sndcard=lc->sound_conf.capt_sndcard;
2804 lc->sound_conf.source=source;
2805 if (!sndcard) return;
2808 ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
2811 ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
2819 * Sets the path to a wav file used for ringing.
2821 * The file must be a wav 16bit linear.
2823 * @ingroup media_parameters
2825 void linphone_core_set_ring(LinphoneCore *lc,const char *path){
2826 if (lc->sound_conf.local_ring!=0){
2827 ms_free(lc->sound_conf.local_ring);
2829 lc->sound_conf.local_ring=ms_strdup(path);
2830 if (lc->ready && lc->sound_conf.local_ring)
2831 lp_config_set_string(lc->config,"sound","local_ring",lc->sound_conf.local_ring);
2835 * Returns the path to the wav file used for ringing.
2837 * @ingroup media_parameters
2839 const char *linphone_core_get_ring(const LinphoneCore *lc){
2840 return lc->sound_conf.local_ring;
2843 static void notify_end_of_ring(void *ud ,unsigned int event, void * arg){
2844 LinphoneCore *lc=(LinphoneCore*)ud;
2845 lc->preview_finished=1;
2848 int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata)
2850 if (lc->ringstream!=0){
2851 ms_warning("Cannot start ring now,there's already a ring being played");
2854 lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
2855 lc->preview_finished=0;
2856 if (lc->sound_conf.ring_sndcard!=NULL){
2857 lc->ringstream=ring_start_with_cb(ring,2000,lc->sound_conf.ring_sndcard,notify_end_of_ring,(void *)lc);
2863 * Sets the path to a wav file used for ringing back.
2865 * Ringback means the ring that is heard when it's ringing at the remote party.
2866 * The file must be a wav 16bit linear.
2868 * @ingroup media_parameters
2870 void linphone_core_set_ringback(LinphoneCore *lc, const char *path){
2871 if (lc->sound_conf.remote_ring!=0){
2872 ms_free(lc->sound_conf.remote_ring);
2874 lc->sound_conf.remote_ring=ms_strdup(path);
2878 * Returns the path to the wav file used for ringing back.
2880 * @ingroup media_parameters
2882 const char * linphone_core_get_ringback(const LinphoneCore *lc){
2883 return lc->sound_conf.remote_ring;
2887 * Enables or disable echo cancellation.
2889 * @ingroup media_parameters
2891 void linphone_core_enable_echo_cancellation(LinphoneCore *lc, bool_t val){
2892 lc->sound_conf.ec=val;
2894 lp_config_set_int(lc->config,"sound","echocancellation",val);
2898 * Returns TRUE if echo cancellation is enabled.
2900 * @ingroup media_parameters
2902 bool_t linphone_core_echo_cancellation_enabled(LinphoneCore *lc){
2903 return lc->sound_conf.ec;
2906 void linphone_core_enable_echo_limiter(LinphoneCore *lc, bool_t val){
2907 lc->sound_conf.ea=val;
2910 bool_t linphone_core_echo_limiter_enabled(const LinphoneCore *lc){
2911 return lc->sound_conf.ea;
2915 * Mutes or unmutes the local microphone.
2917 * @ingroup media_parameters
2919 void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){
2920 if (lc->audiostream!=NULL){
2921 audio_stream_set_mic_gain(lc->audiostream,
2922 (val==TRUE) ? 0 : 1.0);
2923 if ( linphone_core_get_rtp_no_xmit_on_audio_mute(lc) ){
2924 audio_stream_mute_rtp(lc->audiostream,val);
2926 lc->audio_muted=val;
2930 bool_t linphone_core_is_mic_muted(LinphoneCore *lc) {
2932 if (lc->audiostream && lc->audiostream->volsend){
2933 ms_filter_call_method(lc->audiostream->volsend,MS_VOLUME_GET_GAIN,&gain);
2934 }else ms_warning("Could not get gain: gain control wasn't activated. ");
2939 // returns audio mute status for active stream
2940 bool_t linphone_core_is_audio_muted(LinphoneCore *lc){
2941 if( lc->audiostream != NULL )
2942 return (lc->audio_muted);
2946 // returns rtp transmission status for an active stream
2947 // if audio is muted and config parameter rtp_no_xmit_on_audio_mute
2948 // was set on then rtp transmission is also muted
2949 bool_t linphone_core_is_rtp_muted(LinphoneCore *lc){
2950 if( (lc->audiostream != NULL) &&
2951 linphone_core_get_rtp_no_xmit_on_audio_mute(lc)){
2952 return lc->audio_muted;
2957 void linphone_core_enable_agc(LinphoneCore *lc, bool_t val){
2958 lc->sound_conf.agc=val;
2961 bool_t linphone_core_agc_enabled(const LinphoneCore *lc){
2962 return lc->sound_conf.agc;
2966 * Send the specified dtmf.
2968 * @ingroup media_parameters
2969 * This function only works during calls. The dtmf is automatically played to the user.
2970 * @param lc The LinphoneCore object
2971 * @param dtmf The dtmf name specified as a char, such as '0', '#' etc...
2974 void linphone_core_send_dtmf(LinphoneCore *lc, char dtmf)
2976 /*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
2977 if (linphone_core_get_use_rfc2833_for_dtmf(lc)!=0 || linphone_core_get_use_info_for_dtmf(lc)==0)
2980 if (lc->audiostream!=NULL){
2981 audio_stream_send_dtmf(lc->audiostream,dtmf);
2985 ms_error("we cannot send RFC2833 dtmf when we are not in communication");
2988 if (linphone_core_get_use_info_for_dtmf(lc)!=0){
2989 /* Out of Band DTMF (use INFO method) */
2990 LinphoneCall *call=lc->call;
2994 sal_call_send_dtmf(call->op,dtmf);
2998 void linphone_core_set_stun_server(LinphoneCore *lc, const char *server){
2999 if (lc->net_conf.stun_server!=NULL)
3000 ms_free(lc->net_conf.stun_server);
3002 lc->net_conf.stun_server=ms_strdup(server);
3003 else lc->net_conf.stun_server=NULL;
3006 const char * linphone_core_get_stun_server(const LinphoneCore *lc){
3007 return lc->net_conf.stun_server;
3010 const char * linphone_core_get_relay_addr(const LinphoneCore *lc){
3011 return lc->net_conf.relay;
3014 int linphone_core_set_relay_addr(LinphoneCore *lc, const char *addr){
3015 if (lc->net_conf.relay!=NULL){
3016 ms_free(lc->net_conf.relay);
3017 lc->net_conf.relay=NULL;
3020 lc->net_conf.relay=ms_strdup(addr);
3025 void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
3027 if (lc->net_conf.nat_address!=NULL){
3028 ms_free(lc->net_conf.nat_address);
3030 if (addr!=NULL) lc->net_conf.nat_address=ms_strdup(addr);
3031 else lc->net_conf.nat_address=NULL;
3032 if (lc->sip_conf.contact) update_primary_contact(lc);
3035 const char *linphone_core_get_nat_address(const LinphoneCore *lc)
3037 return lc->net_conf.nat_address;
3040 void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
3041 lc->net_conf.firewall_policy=pol;
3042 if (lc->sip_conf.contact) update_primary_contact(lc);
3045 LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
3046 return lc->net_conf.firewall_policy;
3050 * Get the list of call logs (past calls).
3052 * @ingroup call_logs
3054 const MSList * linphone_core_get_call_logs(LinphoneCore *lc){
3056 return lc->call_logs;
3060 * Erase the call log.
3062 * @ingroup call_logs
3064 void linphone_core_clear_call_logs(LinphoneCore *lc){
3066 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3067 lc->call_logs=ms_list_free(lc->call_logs);
3068 call_logs_write_to_config_file(lc);
3071 static void toggle_video_preview(LinphoneCore *lc, bool_t val){
3072 #ifdef VIDEO_ENABLED
3073 if (lc->videostream==NULL){
3075 if (lc->previewstream==NULL){
3076 lc->previewstream=video_preview_start(lc->video_conf.device,
3077 lc->video_conf.vsize);
3080 if (lc->previewstream!=NULL){
3081 video_preview_stop(lc->previewstream);
3082 lc->previewstream=NULL;
3090 * Enables video globally.
3092 * @ingroup media_parameters
3093 * This function does not have any effect during calls. It just indicates LinphoneCore to
3094 * initiate future calls with video or not. The two boolean parameters indicate in which
3095 * direction video is enabled. Setting both to false disables video entirely.
3097 * @param vcap_enabled indicates whether video capture is enabled
3098 * @param display_enabled indicates whether video display should be shown
3101 void linphone_core_enable_video(LinphoneCore *lc, bool_t vcap_enabled, bool_t display_enabled){
3102 #ifndef VIDEO_ENABLED
3103 if (vcap_enabled || display_enabled)
3104 ms_warning("This version of linphone was built without video support.");
3106 lc->video_conf.capture=vcap_enabled;
3107 lc->video_conf.display=display_enabled;
3109 /* need to re-apply network bandwidth settings*/
3110 linphone_core_set_download_bandwidth(lc,
3111 linphone_core_get_download_bandwidth(lc));
3112 linphone_core_set_upload_bandwidth(lc,
3113 linphone_core_get_upload_bandwidth(lc));
3117 * Returns TRUE if video is enabled, FALSE otherwise.
3118 * @ingroup media_parameters
3120 bool_t linphone_core_video_enabled(LinphoneCore *lc){
3121 return (lc->video_conf.display || lc->video_conf.capture);
3125 * Controls video preview enablement.
3127 * @ingroup media_parameters
3128 * Video preview refers to the action of displaying the local webcam image
3129 * to the user while not in call.
3131 void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val){
3132 lc->video_conf.show_local=val;
3136 * Returns TRUE if video previewing is enabled.
3137 * @ingroup media_parameters
3139 bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
3140 return lc->video_conf.show_local;
3144 * Enables or disable self view during calls.
3146 * @ingroup media_parameters
3147 * Self-view refers to having local webcam image inserted in corner
3148 * of the video window during calls.
3149 * This function works at any time, including during calls.
3151 void linphone_core_enable_self_view(LinphoneCore *lc, bool_t val){
3152 lc->video_conf.selfview=val;
3153 #ifdef VIDEO_ENABLED
3154 if (lc->videostream){
3155 video_stream_enable_self_view(lc->videostream,val);
3161 * Returns TRUE if self-view is enabled, FALSE otherwise.
3163 * @ingroup media_parameters
3165 * Refer to linphone_core_enable_self_view() for details.
3167 bool_t linphone_core_self_view_enabled(const LinphoneCore *lc){
3168 return lc->video_conf.selfview;
3172 * Sets the active video device.
3174 * @ingroup media_parameters
3175 * @param id the name of the video device as returned by linphone_core_get_video_devices()
3177 int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
3178 MSWebCam *olddev=lc->video_conf.device;
3181 lc->video_conf.device=ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),id);
3182 if (lc->video_conf.device==NULL){
3183 ms_warning("Could not found video device %s",id);
3186 if (lc->video_conf.device==NULL)
3187 lc->video_conf.device=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());
3188 if (olddev!=NULL && olddev!=lc->video_conf.device){
3189 toggle_video_preview(lc,FALSE);/*restart the video local preview*/
3191 if (lc->ready && lc->video_conf.device){
3192 vd=ms_web_cam_get_string_id(lc->video_conf.device);
3193 if (vd && strstr(vd,"Static picture")!=NULL){
3196 lp_config_set_string(lc->config,"video","device",vd);
3202 * Returns the name of the currently active video device.
3204 * @ingroup media_parameters
3206 const char *linphone_core_get_video_device(const LinphoneCore *lc){
3207 if (lc->video_conf.device) return ms_web_cam_get_string_id(lc->video_conf.device);
3211 int linphone_core_set_static_picture(LinphoneCore *lc, const char *path) {
3212 #ifdef VIDEO_ENABLED
3213 VideoStream *vs = NULL;
3214 /* Select the video stream from the call in the first place */
3215 if (lc && lc->videostream) {
3216 vs = lc->videostream;
3218 /* If not in call, select the video stream from the preview */
3219 if (vs == NULL && lc && lc->previewstream) {
3220 vs = lc->previewstream;
3223 /* If we have a video stream (either preview, either from call), we
3224 have a source and it is using the static picture filter, then
3225 force the filter to use that picture. */
3226 if (vs && vs->source) {
3227 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3228 ms_filter_call_method(vs->source, MS_FILTER_SET_IMAGE,
3233 /* Tell the static image filter to use that image from now on so
3234 that the image will be used next time it has to be read */
3235 ms_static_image_set_default_image(path);
3237 ms_warning("Video support not compiled.");
3243 * Returns the native window handle of the video window, casted as an unsigned long.
3245 * @ingroup media_parameters
3247 unsigned long linphone_core_get_native_video_window_id(const LinphoneCore *lc){
3248 #ifdef VIDEO_ENABLED
3249 if (lc->videostream)
3250 return video_stream_get_native_window_id(lc->videostream);
3251 if (lc->previewstream)
3252 return video_stream_get_native_window_id(lc->previewstream);
3257 static MSVideoSizeDef supported_resolutions[]={
3258 { {MS_VIDEO_SIZE_SVGA_W,MS_VIDEO_SIZE_SVGA_H} , "svga" },
3259 { {MS_VIDEO_SIZE_4CIF_W,MS_VIDEO_SIZE_4CIF_H} , "4cif" },
3260 { {MS_VIDEO_SIZE_VGA_W,MS_VIDEO_SIZE_VGA_H} , "vga" },
3261 { {MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H} , "cif" },
3262 { {MS_VIDEO_SIZE_QVGA_W,MS_VIDEO_SIZE_QVGA_H} , "qvga" },
3263 { {MS_VIDEO_SIZE_QCIF_W,MS_VIDEO_SIZE_QCIF_H} , "qcif" },
3268 * Returns the zero terminated table of supported video resolutions.
3270 * @ingroup media_parameters
3272 const MSVideoSizeDef *linphone_core_get_supported_video_sizes(LinphoneCore *lc){
3273 return supported_resolutions;
3276 static MSVideoSize video_size_get_by_name(const char *name){
3277 MSVideoSizeDef *pdef=supported_resolutions;
3278 MSVideoSize null_vsize={0,0};
3279 for(;pdef->name!=NULL;pdef++){
3280 if (strcasecmp(name,pdef->name)==0){
3284 ms_warning("Video resolution %s is not supported in linphone.",name);
3288 static const char *video_size_get_name(MSVideoSize vsize){
3289 MSVideoSizeDef *pdef=supported_resolutions;
3290 for(;pdef->name!=NULL;pdef++){
3291 if (pdef->vsize.width==vsize.width && pdef->vsize.height==vsize.height){
3298 static bool_t video_size_supported(MSVideoSize vsize){
3299 if (video_size_get_name(vsize)) return TRUE;
3300 ms_warning("Video resolution %ix%i is not supported in linphone.",vsize.width,vsize.height);
3305 * Sets the preferred video size.
3307 * @ingroup media_parameters
3308 * This applies only to the stream that is captured and sent to the remote party,
3309 * since we accept all standard video size on the receive path.
3311 void linphone_core_set_preferred_video_size(LinphoneCore *lc, MSVideoSize vsize){
3312 if (video_size_supported(vsize)){
3313 MSVideoSize oldvsize=lc->video_conf.vsize;
3314 lc->video_conf.vsize=vsize;
3315 if (!ms_video_size_equal(oldvsize,vsize) && lc->previewstream!=NULL){
3316 toggle_video_preview(lc,FALSE);
3317 toggle_video_preview(lc,TRUE);
3320 lp_config_set_string(lc->config,"video","size",video_size_get_name(vsize));
3325 * Sets the preferred video size by its name.
3327 * @ingroup media_parameters
3328 * This is identical to linphone_core_set_preferred_video_size() except
3329 * that it takes the name of the video resolution as input.
3330 * Video resolution names are: qcif, svga, cif, vga, 4cif, svga ...
3332 void linphone_core_set_preferred_video_size_by_name(LinphoneCore *lc, const char *name){
3333 MSVideoSize vsize=video_size_get_by_name(name);
3334 MSVideoSize default_vsize={MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H};
3335 if (vsize.width!=0) linphone_core_set_preferred_video_size(lc,vsize);
3336 else linphone_core_set_preferred_video_size(lc,default_vsize);
3340 * Returns the current preferred video size for sending.
3342 * @ingroup media_parameters
3344 MSVideoSize linphone_core_get_preferred_video_size(LinphoneCore *lc){
3345 return lc->video_conf.vsize;
3348 void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
3349 lc->use_files=yesno;
3352 void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
3353 if (lc->play_file!=NULL){
3354 ms_free(lc->play_file);
3358 lc->play_file=ms_strdup(file);
3359 if (lc->audiostream->ticker)
3360 audio_stream_play(lc->audiostream,file);
3364 void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
3365 if (lc->rec_file!=NULL){
3366 ms_free(lc->rec_file);
3370 lc->rec_file=ms_strdup(file);
3371 if (lc->audiostream)
3372 audio_stream_record(lc->audiostream,file);
3377 * Retrieves the user pointer that was given to linphone_core_new()
3379 * @ingroup initializing
3381 void *linphone_core_get_user_data(LinphoneCore *lc){
3385 int linphone_core_get_mtu(const LinphoneCore *lc){
3386 return lc->net_conf.mtu;
3389 void linphone_core_set_mtu(LinphoneCore *lc, int mtu){
3390 lc->net_conf.mtu=mtu;
3393 ms_error("MTU too small !");
3397 ms_message("MTU is supposed to be %i, rtp payload max size will be %i",mtu, ms_get_payload_max_size());
3398 }else ms_set_mtu(0);//use mediastreamer2 default value
3401 void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context){
3403 lc->wait_ctx=user_context;
3406 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose){
3408 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingStart,purpose,0);
3412 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progress){
3414 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingProgress,purpose,progress);
3424 void linphone_core_stop_waiting(LinphoneCore *lc){
3426 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingFinished,NULL,0);
3430 void linphone_core_set_audio_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3436 * Retrieve RTP statistics regarding current call.
3437 * @param local RTP statistics computed locally.
3438 * @param remote RTP statistics computed by far end (obtained via RTCP feedback).
3440 * @note Remote RTP statistics is not implemented yet.
3442 * @returns 0 or -1 if no call is running.
3445 int linphone_core_get_current_call_stats(LinphoneCore *lc, rtp_stats_t *local, rtp_stats_t *remote){
3446 LinphoneCall *call=linphone_core_get_current_call (lc);
3448 if (lc->audiostream!=NULL){
3449 memset(remote,0,sizeof(*remote));
3450 audio_stream_get_local_rtp_stats (lc->audiostream,local);
3457 void net_config_uninit(LinphoneCore *lc)
3459 net_config_t *config=&lc->net_conf;
3460 lp_config_set_int(lc->config,"net","download_bw",config->download_bw);
3461 lp_config_set_int(lc->config,"net","upload_bw",config->upload_bw);
3463 if (config->stun_server!=NULL){
3464 lp_config_set_string(lc->config,"net","stun_server",config->stun_server);
3465 ms_free(lc->net_conf.stun_server);
3467 if (config->nat_address!=NULL){
3468 lp_config_set_string(lc->config,"net","nat_address",config->nat_address);
3469 ms_free(lc->net_conf.nat_address);
3471 lp_config_set_int(lc->config,"net","firewall_policy",config->firewall_policy);
3472 lp_config_set_int(lc->config,"net","mtu",config->mtu);
3476 void sip_config_uninit(LinphoneCore *lc)
3480 sip_config_t *config=&lc->sip_conf;
3481 lp_config_set_int(lc->config,"sip","sip_port",config->sip_port);
3482 lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
3483 lp_config_set_string(lc->config,"sip","contact",config->contact);
3484 lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
3485 lp_config_set_int(lc->config,"sip","use_info",config->use_info);
3486 lp_config_set_int(lc->config,"sip","use_rfc2833",config->use_rfc2833);
3487 lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
3488 lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
3491 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
3493 for(elem=config->proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3494 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
3495 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
3496 linphone_proxy_config_edit(cfg); /* to unregister */
3502 sal_iterate(lc->sal);
3511 ms_list_for_each(config->proxies,(void (*)(void*)) linphone_proxy_config_destroy);
3512 ms_list_free(config->proxies);
3513 config->proxies=NULL;
3515 linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */
3517 for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3518 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
3519 linphone_auth_info_write_config(lc->config,ai,i);
3521 linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
3522 ms_list_for_each(lc->auth_info,(void (*)(void*))linphone_auth_info_destroy);
3523 ms_list_free(lc->auth_info);
3526 sal_uninit(lc->sal);
3529 if (lc->sip_conf.guessed_contact)
3530 ms_free(lc->sip_conf.guessed_contact);
3531 if (config->contact)
3532 ms_free(config->contact);
3536 void rtp_config_uninit(LinphoneCore *lc)
3538 rtp_config_t *config=&lc->rtp_conf;
3539 lp_config_set_int(lc->config,"rtp","audio_rtp_port",config->audio_rtp_port);
3540 lp_config_set_int(lc->config,"rtp","video_rtp_port",config->video_rtp_port);
3541 lp_config_set_int(lc->config,"rtp","audio_jitt_comp",config->audio_jitt_comp);
3542 lp_config_set_int(lc->config,"rtp","video_jitt_comp",config->video_jitt_comp);
3543 lp_config_set_int(lc->config,"rtp","nortp_timeout",config->nortp_timeout);
3546 void sound_config_uninit(LinphoneCore *lc)
3548 sound_config_t *config=&lc->sound_conf;
3549 ms_free(config->cards);
3551 lp_config_set_string(lc->config,"sound","remote_ring",config->remote_ring);
3553 if (config->local_ring) ms_free(config->local_ring);
3554 if (config->remote_ring) ms_free(config->remote_ring);
3555 ms_snd_card_manager_destroy();
3558 void video_config_uninit(LinphoneCore *lc)
3560 lp_config_set_int(lc->config,"video","enabled",linphone_core_video_enabled(lc));
3561 lp_config_set_string(lc->config,"video","size",video_size_get_name(linphone_core_get_preferred_video_size(lc)));
3562 lp_config_set_int(lc->config,"video","display",lc->video_conf.display);
3563 lp_config_set_int(lc->config,"video","capture",lc->video_conf.capture);
3564 lp_config_set_int(lc->config,"video","show_local",linphone_core_video_preview_enabled(lc));
3565 lp_config_set_int(lc->config,"video","self_view",linphone_core_self_view_enabled(lc));
3566 if (lc->video_conf.cams)
3567 ms_free(lc->video_conf.cams);
3570 void codecs_config_uninit(LinphoneCore *lc)
3573 codecs_config_t *config=&lc->codecs_conf;
3578 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
3579 pt=(PayloadType*)(node->data);
3580 sprintf(key,"audio_codec_%i",index);
3581 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3582 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3583 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3586 sprintf(key,"audio_codec_%i",index);
3587 lp_config_clean_section (lc->config,key);
3590 for(node=config->video_codecs;node!=NULL;node=ms_list_next(node)){
3591 pt=(PayloadType*)(node->data);
3592 sprintf(key,"video_codec_%i",index);
3593 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3594 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3595 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3596 lp_config_set_string(lc->config,key,"recv_fmtp",pt->recv_fmtp);
3599 sprintf(key,"video_codec_%i",index);
3600 lp_config_clean_section (lc->config,key);
3602 ms_list_free(lc->codecs_conf.audio_codecs);
3603 ms_list_free(lc->codecs_conf.video_codecs);
3606 void ui_config_uninit(LinphoneCore* lc)
3609 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_destroy);
3610 ms_list_free(lc->friends);
3616 * Returns the LpConfig object used to manage the storage (config) file.
3619 * The application can use the LpConfig object to insert its own private
3620 * sections and pairs of key=value in the configuration file.
3623 LpConfig *linphone_core_get_config(LinphoneCore *lc){
3627 static void linphone_core_uninit(LinphoneCore *lc)
3631 linphone_core_terminate_call(lc,NULL);
3638 linphone_core_iterate(lc);
3642 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions);
3643 gstate_new_state(lc, GSTATE_POWER_SHUTDOWN, NULL);
3644 #ifdef VIDEO_ENABLED
3645 if (lc->previewstream!=NULL){
3646 video_preview_stop(lc->previewstream);
3647 lc->previewstream=NULL;
3650 /* save all config */
3651 net_config_uninit(lc);
3652 sip_config_uninit(lc);
3653 rtp_config_uninit(lc);
3654 sound_config_uninit(lc);
3655 video_config_uninit(lc);
3656 codecs_config_uninit(lc);
3657 ui_config_uninit(lc);
3658 if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
3659 lp_config_destroy(lc->config);
3660 lc->config = NULL; /* Mark the config as NULL to block further calls */
3661 sip_setup_unregister_all();
3663 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3664 lc->call_logs=ms_list_free(lc->call_logs);
3666 linphone_core_free_payload_types();
3669 gstate_new_state(lc, GSTATE_POWER_OFF, NULL);
3672 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable){
3673 ms_message("Network state is now [%s]",isReachable?"UP":"DOWN");
3674 // second get the list of available proxies
3675 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3676 for(;elem!=NULL;elem=elem->next){
3677 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3678 if (linphone_proxy_config_register_enabled(cfg) ) {
3686 lc->network_reachable=isReachable;
3689 void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) {
3690 //first disable automatic mode
3691 if (lc->auto_net_state_mon) {
3692 ms_message("Disabling automatic network state monitoring");
3693 lc->auto_net_state_mon=FALSE;
3695 set_network_reachable(lc,isReachable);
3698 bool_t linphone_core_is_network_reachabled(LinphoneCore* lc) {
3699 return lc->network_reachable;
3701 ortp_socket_t linphone_core_get_sip_socket(LinphoneCore *lc){
3702 return sal_get_socket(lc->sal);
3705 * Destroys a LinphoneCore
3707 * @ingroup initializing
3709 void linphone_core_destroy(LinphoneCore *lc){
3710 linphone_core_uninit(lc);