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(const MSList *codecs){
69 for(it=codecs;it!=NULL;it=it->next){
70 PayloadType *pt=(PayloadType*)it->data;
71 if (pt->flags & PAYLOAD_TYPE_ENABLED){
72 l=ms_list_append(l,payload_type_clone(pt));
78 static SalMediaDescription *create_local_media_description(LinphoneCore *lc,
79 const char *localip, const char *username){
82 SalMediaDescription *md=sal_media_description_new();
84 strncpy(md->addr,localip,sizeof(md->addr));
85 strncpy(md->username,username,sizeof(md->username));
86 /*set audio capabilities */
87 strncpy(md->streams[0].addr,localip,sizeof(md->streams[0].addr));
88 md->streams[0].port=linphone_core_get_audio_port(lc);
89 md->streams[0].proto=SalProtoRtpAvp;
90 md->streams[0].type=SalAudio;
91 l=make_codec_list(lc->codecs_conf.audio_codecs);
92 pt=payload_type_clone(rtp_profile_get_payload_from_mime(&av_profile,"telephone-event"));
93 l=ms_list_append(l,pt);
94 md->streams[0].payloads=l;
96 if (lc->dw_audio_bw>0)
97 md->streams[0].bandwidth=lc->dw_audio_bw;
99 if (linphone_core_video_enabled (lc)){
101 md->streams[1].port=linphone_core_get_video_port(lc);
102 md->streams[1].proto=SalProtoRtpAvp;
103 md->streams[1].type=SalVideo;
104 l=make_codec_list(lc->codecs_conf.video_codecs);
105 md->streams[1].payloads=l;
107 md->streams[1].bandwidth=lc->dw_video_bw;
112 static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
113 call->state=LCStateInit;
114 call->start_time=time(NULL);
115 call->media_start_time=0;
116 call->log=linphone_call_log_new(call, from, to);
117 linphone_core_notify_all_friends(call->core,LINPHONE_STATUS_ONTHEPHONE);
118 if (linphone_core_get_firewall_policy(call->core)==LINPHONE_POLICY_USE_STUN)
119 linphone_core_run_stun_tests(call->core,call);
122 static void discover_mtu(LinphoneCore *lc, const char *remote){
124 if (lc->net_conf.mtu==0 ){
125 /*attempt to discover mtu*/
126 mtu=ms_discover_mtu(remote);
129 ms_message("Discovered mtu is %i, RTP payload max size is %i",
130 mtu, ms_get_payload_max_size());
135 LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to)
137 LinphoneCall *call=ms_new0(LinphoneCall,1);
138 call->dir=LinphoneCallOutgoing;
139 call->op=sal_op_new(lc->sal);
140 sal_op_set_user_pointer(call->op,call);
142 linphone_core_get_local_ip(lc,linphone_address_get_domain(to),call->localip);
143 call->localdesc=create_local_media_description (lc,call->localip,
144 linphone_address_get_username(from));
145 linphone_call_init_common(call,from,to);
146 discover_mtu(lc,linphone_address_get_domain (to));
150 LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){
151 LinphoneCall *call=ms_new0(LinphoneCall,1);
152 LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
154 call->dir=LinphoneCallIncoming;
155 sal_op_set_user_pointer(op,call);
159 linphone_address_clean(from);
160 linphone_core_get_local_ip(lc,linphone_address_get_domain(from),call->localip);
161 call->localdesc=create_local_media_description (lc,call->localip,
162 linphone_address_get_username(me));
163 linphone_call_init_common(call, from, to);
164 discover_mtu(lc,linphone_address_get_domain(from));
165 linphone_address_destroy(me);
169 void linphone_call_destroy(LinphoneCall *obj)
171 linphone_core_notify_all_friends(obj->core,obj->core->prev_mode);
172 linphone_call_log_completed(obj->log,obj);
173 linphone_core_update_allocated_audio_bandwidth(obj->core);
174 if (obj->op!=NULL) sal_op_release(obj->op);
175 if (obj->resultdesc!=NULL) sal_media_description_unref(obj->resultdesc);
176 if (obj->localdesc!=NULL) sal_media_description_unref(obj->localdesc);
180 /*prevent a gcc bug with %c*/
181 static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm){
182 #if !defined(_WIN32_WCE)
183 return strftime(s, max, fmt, tm);
187 #endif /*_WIN32_WCE*/
190 static void set_call_log_date(LinphoneCallLog *cl, const struct tm *loctime){
191 my_strftime(cl->start_date,sizeof(cl->start_date),"%c",loctime);
194 LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
195 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
199 #if !defined(_WIN32_WCE)
200 loctime=*localtime(&call->start_time);
202 #endif /*_WIN32_WCE*/
204 localtime_r(&call->start_time,&loctime);
206 set_call_log_date(cl,&loctime);
212 static void call_logs_write_to_config_file(LinphoneCore *lc){
217 LpConfig *cfg=lc->config;
219 if (!lc->ready) return;
221 for(i=0,elem=lc->call_logs;elem!=NULL;elem=elem->next,++i){
222 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
223 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
224 lp_config_set_int(cfg,logsection,"dir",cl->dir);
225 lp_config_set_int(cfg,logsection,"status",cl->status);
226 tmp=linphone_address_as_string(cl->from);
227 lp_config_set_string(cfg,logsection,"from",tmp);
229 tmp=linphone_address_as_string(cl->to);
230 lp_config_set_string(cfg,logsection,"to",tmp);
232 lp_config_set_string(cfg,logsection,"start_date",cl->start_date);
233 lp_config_set_int(cfg,logsection,"duration",cl->duration);
234 if (cl->refkey) lp_config_set_string(cfg,logsection,"refkey",cl->refkey);
236 for(;i<lc->max_call_logs;++i){
237 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
238 lp_config_clean_section(cfg,logsection);
242 static void call_logs_read_from_config_file(LinphoneCore *lc){
246 LpConfig *cfg=lc->config;
248 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
249 if (lp_config_has_section(cfg,logsection)){
250 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
251 cl->dir=lp_config_get_int(cfg,logsection,"dir",0);
252 cl->status=lp_config_get_int(cfg,logsection,"status",0);
253 tmp=lp_config_get_string(cfg,logsection,"from",NULL);
254 if (tmp) cl->from=linphone_address_new(tmp);
255 tmp=lp_config_get_string(cfg,logsection,"to",NULL);
256 if (tmp) cl->to=linphone_address_new(tmp);
257 tmp=lp_config_get_string(cfg,logsection,"start_date",NULL);
258 if (tmp) strncpy(cl->start_date,tmp,sizeof(cl->start_date));
259 cl->duration=lp_config_get_int(cfg,logsection,"duration",0);
260 tmp=lp_config_get_string(cfg,logsection,"refkey",NULL);
261 if (tmp) cl->refkey=ms_strdup(tmp);
262 lc->call_logs=ms_list_append(lc->call_logs,cl);
268 void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call){
269 LinphoneCore *lc=call->core;
271 calllog->duration=time(NULL)-call->start_time;
274 calllog->status=LinphoneCallAborted;
277 if (calllog->dir==LinphoneCallIncoming){
279 calllog->status=LinphoneCallMissed;
281 info=ortp_strdup_printf(ngettext("You have missed %i call.",
282 "You have missed %i calls.", lc->missed_calls),
284 lc->vtable.display_status(lc,info);
287 else calllog->status=LinphoneCallAborted;
289 case LCStateAVRunning:
290 calllog->status=LinphoneCallSuccess;
293 lc->call_logs=ms_list_prepend(lc->call_logs,(void *)calllog);
294 if (ms_list_size(lc->call_logs)>lc->max_call_logs){
295 MSList *elem,*prevelem=NULL;
296 /*find the last element*/
297 for(elem=lc->call_logs;elem!=NULL;elem=elem->next){
301 linphone_call_log_destroy((LinphoneCallLog*)elem->data);
302 lc->call_logs=ms_list_remove_link(lc->call_logs,elem);
304 if (lc->vtable.call_log_updated!=NULL){
305 lc->vtable.call_log_updated(lc,calllog);
307 call_logs_write_to_config_file(lc);
311 * @addtogroup call_logs
316 * Returns a human readable string describing the call.
318 * @note: the returned char* must be freed by the application (use ms_free()).
320 char * linphone_call_log_to_str(LinphoneCallLog *cl){
323 char *from=linphone_address_as_string (cl->from);
324 char *to=linphone_address_as_string (cl->to);
326 case LinphoneCallAborted:
329 case LinphoneCallSuccess:
330 status=_("completed");
332 case LinphoneCallMissed:
338 tmp=ortp_strdup_printf(_("%s at %s\nFrom: %s\nTo: %s\nStatus: %s\nDuration: %i mn %i sec\n"),
339 (cl->dir==LinphoneCallIncoming) ? _("Incoming call") : _("Outgoing call"),
351 void linphone_call_log_set_user_pointer(LinphoneCallLog *cl, void *up){
355 void *linphone_call_log_get_user_pointer(const LinphoneCallLog *cl){
356 return cl->user_pointer;
362 * Associate a persistent reference key to the call log.
364 * The reference key can be for example an id to an external database.
365 * It is stored in the config file, thus can survive to process exits/restarts.
368 void linphone_call_log_set_ref_key(LinphoneCallLog *cl, const char *refkey){
369 if (cl->refkey!=NULL){
373 if (refkey) cl->refkey=ms_strdup(refkey);
374 call_logs_write_to_config_file(cl->lc);
378 * Get the persistent reference key associated to the call log.
380 * The reference key can be for example an id to an external database.
381 * It is stored in the config file, thus can survive to process exits/restarts.
384 const char *linphone_call_log_get_ref_key(const LinphoneCallLog *cl){
390 void linphone_call_log_destroy(LinphoneCallLog *cl){
391 if (cl->from!=NULL) linphone_address_destroy(cl->from);
392 if (cl->to!=NULL) linphone_address_destroy(cl->to);
393 if (cl->refkey!=NULL) ms_free(cl->refkey);
397 int linphone_core_get_current_call_duration(const LinphoneCore *lc){
398 LinphoneCall *call=lc->call;
399 if (call==NULL) return 0;
400 if (call->media_start_time==0) return 0;
401 return time(NULL)-call->media_start_time;
404 const LinphoneAddress *linphone_core_get_remote_uri(LinphoneCore *lc){
405 LinphoneCall *call=lc->call;
406 if (call==NULL) return 0;
407 return call->dir==LinphoneCallIncoming ? call->log->from : call->log->to;
411 * Enable logs in supplied FILE*.
415 * @param file a C FILE* where to fprintf logs. If null stdout is used.
418 void linphone_core_enable_logs(FILE *file){
419 if (file==NULL) file=stdout;
420 ortp_set_log_file(file);
421 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
425 * Enable logs through the user's supplied log callback.
429 * @param logfunc The address of a OrtpLogFunc callback whose protoype is
430 * typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
433 void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc){
434 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
435 ortp_set_log_handler(logfunc);
439 * Entirely disable logging.
443 void linphone_core_disable_logs(){
444 ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
449 net_config_read (LinphoneCore *lc)
453 LpConfig *config=lc->config;
455 tmp=lp_config_get_int(config,"net","download_bw",0);
456 linphone_core_set_download_bandwidth(lc,tmp);
457 tmp=lp_config_get_int(config,"net","upload_bw",0);
458 linphone_core_set_upload_bandwidth(lc,tmp);
459 linphone_core_set_stun_server(lc,lp_config_get_string(config,"net","stun_server",NULL));
460 tmpstr=lp_config_get_string(lc->config,"net","nat_address",NULL);
461 if (tmpstr!=NULL && (strlen(tmpstr)<1)) tmpstr=NULL;
462 linphone_core_set_nat_address(lc,tmpstr);
463 tmp=lp_config_get_int(lc->config,"net","firewall_policy",0);
464 linphone_core_set_firewall_policy(lc,tmp);
465 tmp=lp_config_get_int(lc->config,"net","nat_sdp_only",0);
466 lc->net_conf.nat_sdp_only=tmp;
467 tmp=lp_config_get_int(lc->config,"net","mtu",0);
468 linphone_core_set_mtu(lc,tmp);
471 static void build_sound_devices_table(LinphoneCore *lc){
472 const char **devices;
476 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
477 ndev=ms_list_size(elem);
478 devices=ms_malloc((ndev+1)*sizeof(const char *));
479 for (i=0;elem!=NULL;elem=elem->next,i++){
480 devices[i]=ms_snd_card_get_string_id((MSSndCard *)elem->data);
483 old=lc->sound_conf.cards;
484 lc->sound_conf.cards=devices;
485 if (old!=NULL) ms_free(old);
488 static void sound_config_read(LinphoneCore *lc)
494 /*alsadev let the user use custom alsa device within linphone*/
495 devid=lp_config_get_string(lc->config,"sound","alsadev",NULL);
497 MSSndCard *card=ms_alsa_card_new_custom(devid,devid);
498 ms_snd_card_manager_add_card(ms_snd_card_manager_get(),card);
501 /* retrieve all sound devices */
502 build_sound_devices_table(lc);
504 devid=lp_config_get_string(lc->config,"sound","playback_dev_id",NULL);
505 linphone_core_set_playback_device(lc,devid);
507 devid=lp_config_get_string(lc->config,"sound","ringer_dev_id",NULL);
508 linphone_core_set_ringer_device(lc,devid);
510 devid=lp_config_get_string(lc->config,"sound","capture_dev_id",NULL);
511 linphone_core_set_capture_device(lc,devid);
514 tmp=lp_config_get_int(lc->config,"sound","play_lev",80);
515 linphone_core_set_play_level(lc,tmp);
516 tmp=lp_config_get_int(lc->config,"sound","ring_lev",80);
517 linphone_core_set_ring_level(lc,tmp);
518 tmp=lp_config_get_int(lc->config,"sound","rec_lev",80);
519 linphone_core_set_rec_level(lc,tmp);
520 tmpbuf=lp_config_get_string(lc->config,"sound","source","m");
521 linphone_core_set_sound_source(lc,tmpbuf[0]);
524 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
525 tmpbuf=lp_config_get_string(lc->config,"sound","local_ring",tmpbuf);
526 if (ortp_file_exist(tmpbuf)==-1) {
527 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
529 if (strstr(tmpbuf,".wav")==NULL){
530 /* it currently uses old sound files, so replace them */
531 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
534 linphone_core_set_ring(lc,tmpbuf);
536 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
537 tmpbuf=lp_config_get_string(lc->config,"sound","remote_ring",tmpbuf);
538 if (ortp_file_exist(tmpbuf)==-1){
539 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
541 if (strstr(tmpbuf,".wav")==NULL){
542 /* it currently uses old sound files, so replace them */
543 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
545 linphone_core_set_ringback(lc,tmpbuf);
546 check_sound_device(lc);
547 lc->sound_conf.latency=0;
549 linphone_core_enable_echo_cancellation(lc,
550 lp_config_get_int(lc->config,"sound","echocancelation",0) |
551 lp_config_get_int(lc->config,"sound","echocancellation",0)
554 linphone_core_enable_echo_limiter(lc,
555 lp_config_get_int(lc->config,"sound","echolimiter",0));
556 linphone_core_enable_agc(lc,
557 lp_config_get_int(lc->config,"sound","agc",0));
560 static void sip_config_read(LinphoneCore *lc)
567 port=lp_config_get_int(lc->config,"sip","use_info",0);
568 linphone_core_set_use_info_for_dtmf(lc,port);
570 port=lp_config_get_int(lc->config,"sip","use_rfc2833",0);
571 linphone_core_set_use_rfc2833_for_dtmf(lc,port);
573 ipv6=lp_config_get_int(lc->config,"sip","use_ipv6",-1);
576 if (host_has_ipv6_network()){
577 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"));
580 linphone_core_enable_ipv6(lc,ipv6);
581 port=lp_config_get_int(lc->config,"sip","sip_port",5060);
582 linphone_core_set_sip_port(lc,port);
584 tmpstr=lp_config_get_string(lc->config,"sip","contact",NULL);
585 if (tmpstr==NULL || linphone_core_set_primary_contact(lc,tmpstr)==-1) {
586 const char *hostname=NULL;
587 const char *username=NULL;
589 hostname=getenv("HOST");
590 username=getenv("USER");
591 if (hostname==NULL) hostname=getenv("HOSTNAME");
592 #endif /*HAVE_GETENV*/
594 hostname="unknown-host";
598 contact=ortp_strdup_printf("sip:%s@%s",username,hostname);
599 linphone_core_set_primary_contact(lc,contact);
603 tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
604 linphone_core_set_guess_hostname(lc,tmp);
607 tmp=lp_config_get_int(lc->config,"sip","inc_timeout",15);
608 linphone_core_set_inc_timeout(lc,tmp);
610 /* get proxies config */
612 LinphoneProxyConfig *cfg=linphone_proxy_config_new_from_config_file(lc->config,i);
614 linphone_core_add_proxy_config(lc,cfg);
619 /* get the default proxy */
620 tmp=lp_config_get_int(lc->config,"sip","default_proxy",-1);
621 linphone_core_set_default_proxy_index(lc,tmp);
623 /* read authentication information */
625 LinphoneAuthInfo *ai=linphone_auth_info_new_from_config_file(lc->config,i);
627 linphone_core_add_auth_info(lc,ai);
634 lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
635 lc->sip_conf.only_one_codec=lp_config_get_int(lc->config,"sip","only_one_codec",0);
636 lc->sip_conf.register_only_when_network_is_up=
637 lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",1);
640 static void rtp_config_read(LinphoneCore *lc)
645 port=lp_config_get_int(lc->config,"rtp","audio_rtp_port",7078);
646 linphone_core_set_audio_port(lc,port);
648 port=lp_config_get_int(lc->config,"rtp","video_rtp_port",9078);
649 if (port==0) port=9078;
650 linphone_core_set_video_port(lc,port);
652 jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
653 linphone_core_set_audio_jittcomp(lc,jitt_comp);
654 jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
655 nortp_timeout=lp_config_get_int(lc->config,"rtp","nortp_timeout",30);
656 linphone_core_set_nortp_timeout(lc,nortp_timeout);
659 static PayloadType * find_payload(RtpProfile *prof, const char *mime_type, int clock_rate, const char *recv_fmtp){
660 PayloadType *candidate=NULL;
664 it=rtp_profile_get_payload(prof,i);
665 if (it!=NULL && strcasecmp(mime_type,it->mime_type)==0
666 && (clock_rate==it->clock_rate || clock_rate<=0) ){
667 if ( (recv_fmtp && it->recv_fmtp && strcasecmp(recv_fmtp,it->recv_fmtp)==0) ||
668 (recv_fmtp==NULL && it->recv_fmtp==NULL) ){
677 static bool_t get_codec(LpConfig *config, char* type, int index, PayloadType **ret){
679 const char *mime,*fmtp;
684 snprintf(codeckey,50,"%s_%i",type,index);
685 mime=lp_config_get_string(config,codeckey,"mime",NULL);
686 if (mime==NULL || strlen(mime)==0 ) return FALSE;
688 rate=lp_config_get_int(config,codeckey,"rate",8000);
689 fmtp=lp_config_get_string(config,codeckey,"recv_fmtp",NULL);
690 enabled=lp_config_get_int(config,codeckey,"enabled",1);
691 pt=find_payload(&av_profile,mime,rate,fmtp);
692 if (pt && enabled ) pt->flags|=PAYLOAD_TYPE_ENABLED;
693 //ms_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
694 if (pt==NULL) ms_warning("Ignoring codec config %s/%i with fmtp=%s because unsupported",
695 mime,rate,fmtp ? fmtp : "");
700 static const char *codec_pref_order[]={
713 static int find_codec_rank(const char *mime){
715 for(i=0;codec_pref_order[i]!=NULL;++i){
716 if (strcasecmp(codec_pref_order[i],mime)==0)
722 static int codec_compare(const PayloadType *a, const PayloadType *b){
724 ra=find_codec_rank(a->mime_type);
725 rb=find_codec_rank(b->mime_type);
727 if (ra<rb) return -1;
731 static MSList *add_missing_codecs(SalStreamType mtype, MSList *l){
734 PayloadType *pt=rtp_profile_get_payload(&av_profile,i);
736 if (mtype==SalVideo && pt->type!=PAYLOAD_VIDEO)
738 else if (mtype==SalAudio && (pt->type!=PAYLOAD_AUDIO_PACKETIZED
739 && pt->type!=PAYLOAD_AUDIO_CONTINUOUS)){
742 if (pt && ms_filter_codec_supported(pt->mime_type)){
743 if (ms_list_find(l,pt)==NULL){
744 payload_type_set_flag(pt,PAYLOAD_TYPE_ENABLED);
745 ms_message("Adding new codec %s/%i with fmtp %s",
746 pt->mime_type,pt->clock_rate,pt->recv_fmtp ? pt->recv_fmtp : "");
747 l=ms_list_insert_sorted(l,pt,(int (*)(const void *, const void *))codec_compare);
755 static void codecs_config_read(LinphoneCore *lc)
759 MSList *audio_codecs=NULL;
760 MSList *video_codecs=NULL;
761 for (i=0;get_codec(lc->config,"audio_codec",i,&pt);i++){
763 if (!ms_filter_codec_supported(pt->mime_type)){
764 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
765 }else audio_codecs=ms_list_append(audio_codecs,pt);
768 audio_codecs=add_missing_codecs(SalAudio,audio_codecs);
769 for (i=0;get_codec(lc->config,"video_codec",i,&pt);i++){
771 if (!ms_filter_codec_supported(pt->mime_type)){
772 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
773 }else video_codecs=ms_list_append(video_codecs,(void *)pt);
776 video_codecs=add_missing_codecs(SalVideo,video_codecs);
777 linphone_core_set_audio_codecs(lc,audio_codecs);
778 linphone_core_set_video_codecs(lc,video_codecs);
779 linphone_core_update_allocated_audio_bandwidth(lc);
782 static void video_config_read(LinphoneCore *lc){
783 int capture, display, self_view;
787 const char **devices;
791 /* retrieve all video devices */
792 elem=ms_web_cam_manager_get_list(ms_web_cam_manager_get());
793 ndev=ms_list_size(elem);
794 devices=ms_malloc((ndev+1)*sizeof(const char *));
795 for (i=0;elem!=NULL;elem=elem->next,i++){
796 devices[i]=ms_web_cam_get_string_id((MSWebCam *)elem->data);
799 lc->video_conf.cams=devices;
801 str=lp_config_get_string(lc->config,"video","device",NULL);
802 if (str && str[0]==0) str=NULL;
803 linphone_core_set_video_device(lc,str);
805 linphone_core_set_preferred_video_size_by_name(lc,
806 lp_config_get_string(lc->config,"video","size","cif"));
808 enabled=lp_config_get_int(lc->config,"video","enabled",1);
809 capture=lp_config_get_int(lc->config,"video","capture",enabled);
810 display=lp_config_get_int(lc->config,"video","display",enabled);
811 self_view=lp_config_get_int(lc->config,"video","self_view",enabled);
813 linphone_core_enable_video(lc,capture,display);
814 linphone_core_enable_self_view(lc,self_view);
818 static void ui_config_read(LinphoneCore *lc)
822 for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
823 linphone_core_add_friend(lc,lf);
825 call_logs_read_from_config_file(lc);
829 static void autoreplier_config_init(LinphoneCore *lc)
831 autoreplier_config_t *config=&lc->autoreplier_conf;
832 config->enabled=lp_config_get_int(lc->config,"autoreplier","enabled",0);
833 config->after_seconds=lp_config_get_int(lc->config,"autoreplier","after_seconds",6);
834 config->max_users=lp_config_get_int(lc->config,"autoreplier","max_users",1);
835 config->max_rec_time=lp_config_get_int(lc->config,"autoreplier","max_rec_time",60);
836 config->max_rec_msg=lp_config_get_int(lc->config,"autoreplier","max_rec_msg",10);
837 config->message=lp_config_get_string(lc->config,"autoreplier","message",NULL);
842 * Sets maximum available download bandwidth
844 * @ingroup media_parameters
846 * This is IP bandwidth, in kbit/s.
847 * This information is used signaled to other parties during
848 * calls (within SDP messages) so that the remote end can have
849 * sufficient knowledge to properly configure its audio & video
850 * codec output bitrate to not overflow available bandwidth.
852 * @param lc the LinphoneCore object
853 * @param bw the bandwidth in kbits/s, 0 for infinite
855 void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
856 lc->net_conf.download_bw=bw;
857 if (bw==0){ /*infinite*/
861 lc->dw_audio_bw=MIN(lc->audio_bw,bw);
862 lc->dw_video_bw=MAX(bw-lc->dw_audio_bw-10,0);/*-10: security margin*/
867 * Sets maximum available upload bandwidth
869 * @ingroup media_parameters
871 * This is IP bandwidth, in kbit/s.
872 * This information is used by liblinphone together with remote
873 * side available bandwidth signaled in SDP messages to properly
874 * configure audio & video codec's output bitrate.
876 * @param lc the LinphoneCore object
877 * @param bw the bandwidth in kbits/s, 0 for infinite
879 void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
880 lc->net_conf.upload_bw=bw;
881 if (bw==0){ /*infinite*/
885 lc->up_audio_bw=MIN(lc->audio_bw,bw);
886 lc->up_video_bw=MAX(bw-lc->up_audio_bw-10,0);/*-10: security margin*/
891 * Retrieve the maximum available download bandwidth.
893 * @ingroup media_parameters
895 * This value was set by linphone_core_set_download_bandwidth().
898 int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
899 return lc->net_conf.download_bw;
903 * Retrieve the maximum available upload bandwidth.
905 * @ingroup media_parameters
907 * This value was set by linphone_core_set_upload_bandwidth().
910 int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
911 return lc->net_conf.upload_bw;
915 * Returns liblinphone's version as a string.
920 const char * linphone_core_get_version(void){
921 return liblinphone_version;
925 static MSList *linphone_payload_types=NULL;
927 static void linphone_core_assign_payload_type(PayloadType *const_pt, int number, const char *recv_fmtp){
929 pt=payload_type_clone(const_pt);
930 payload_type_set_number(pt,number);
931 if (recv_fmtp!=NULL) payload_type_set_recv_fmtp(pt,recv_fmtp);
932 rtp_profile_set_payload(&av_profile,number,pt);
933 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
936 static void linphone_core_free_payload_types(void){
937 ms_list_for_each(linphone_payload_types,(void (*)(void*))payload_type_destroy);
938 ms_list_free(linphone_payload_types);
939 linphone_payload_types=NULL;
942 static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path,
943 const char *factory_config_path, void * userdata)
945 memset (lc, 0, sizeof (LinphoneCore));
948 memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
950 gstate_initialize(lc);
951 gstate_new_state(lc, GSTATE_POWER_STARTUP, NULL);
954 linphone_core_assign_payload_type(&payload_type_pcmu8000,0,NULL);
955 linphone_core_assign_payload_type(&payload_type_gsm,3,NULL);
956 linphone_core_assign_payload_type(&payload_type_pcma8000,8,NULL);
957 linphone_core_assign_payload_type(&payload_type_lpc1015,115,NULL);
958 linphone_core_assign_payload_type(&payload_type_speex_nb,110,"vbr=on");
959 linphone_core_assign_payload_type(&payload_type_speex_wb,111,"vbr=on");
960 linphone_core_assign_payload_type(&payload_type_speex_uwb,112,"vbr=on");
961 linphone_core_assign_payload_type(&payload_type_telephone_event,101,"0-11");
962 linphone_core_assign_payload_type(&payload_type_ilbc,113,"mode=30");
964 #ifdef ENABLE_NONSTANDARD_GSM
967 pt=payload_type_clone(&payload_type_gsm);
968 pt->clock_rate=11025;
969 rtp_profile_set_payload(&av_profile,114,pt);
970 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
971 pt=payload_type_clone(&payload_type_gsm);
972 pt->clock_rate=22050;
973 rtp_profile_set_payload(&av_profile,115,pt);
974 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
979 linphone_core_assign_payload_type(&payload_type_h263,34,NULL);
980 linphone_core_assign_payload_type(&payload_type_theora,97,NULL);
981 linphone_core_assign_payload_type(&payload_type_h263_1998,98,"CIF=1;QCIF=1");
982 linphone_core_assign_payload_type(&payload_type_mp4v,99,"profile-level-id=3");
983 linphone_core_assign_payload_type(&payload_type_x_snow,100,NULL);
984 linphone_core_assign_payload_type(&payload_type_h264,102,NULL);
985 linphone_core_assign_payload_type(&payload_type_h264,103,"packetization-mode=1");
990 lc->config=lp_config_new(config_path);
991 if (factory_config_path)
992 lp_config_read_file(lc->config,factory_config_path);
995 sal_set_user_pointer(lc->sal,lc);
996 sal_set_callbacks(lc->sal,&linphone_sal_callbacks);
997 if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
998 sal_use_session_timers(lc->sal,200);
1000 sip_setup_register_all();
1001 sound_config_read(lc);
1002 net_config_read(lc);
1003 rtp_config_read(lc);
1004 codecs_config_read(lc);
1005 sip_config_read(lc); /* this will start eXosip*/
1006 video_config_read(lc);
1007 //autoreplier_config_init(&lc->autoreplier_conf);
1008 lc->prev_mode=LINPHONE_STATUS_ONLINE;
1009 lc->presence_mode=LINPHONE_STATUS_ONLINE;
1010 lc->max_call_logs=15;
1012 lc->vtable.display_status(lc,_("Ready"));
1013 gstate_new_state(lc, GSTATE_POWER_ON, NULL);
1014 lc->auto_net_state_mon=TRUE;
1019 * Instanciates a LinphoneCore object.
1020 * @ingroup initializing
1022 * The LinphoneCore object is the primary handle for doing all phone actions.
1023 * It should be unique within your application.
1024 * @param vtable a LinphoneCoreVTable structure holding your application callbacks
1025 * @param config_path a path to a config file. If it does not exists it will be created.
1026 * The config file is used to store all user settings, call logs, friends, proxies...
1027 * @param factory_config_path a path to a read-only config file that can be used to
1028 * to store hard-coded preference such as proxy settings or internal preferences.
1029 * The settings in this factory file always override the one in the normal config file.
1030 * It is OPTIONAL, use NULL if unneeded.
1031 * @param userdata an opaque user pointer that can be retrieved at any time (for example in
1032 * callbacks) using linphone_core_get_user_data().
1035 LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
1036 const char *config_path, const char *factory_config_path, void * userdata)
1038 LinphoneCore *core=ms_new(LinphoneCore,1);
1039 linphone_core_init(core,vtable,config_path, factory_config_path, userdata);
1044 * Returns the list of available audio codecs.
1046 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1047 * structure holding the codec information.
1048 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1049 * (such as the order of codecs).
1051 const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
1053 return lc->codecs_conf.audio_codecs;
1057 * Returns the list of available video codecs.
1059 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1060 * structure holding the codec information.
1061 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1062 * (such as the order of codecs).
1064 const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
1066 return lc->codecs_conf.video_codecs;
1070 * Sets the local "from" identity.
1073 * This data is used in absence of any proxy configuration or when no
1074 * default proxy configuration is set. See LinphoneProxyConfig
1076 int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact)
1078 LinphoneAddress *ctt;
1080 if ((ctt=linphone_address_new(contact))==0) {
1081 ms_error("Bad contact url: %s",contact);
1084 if (lc->sip_conf.contact!=NULL) ms_free(lc->sip_conf.contact);
1085 lc->sip_conf.contact=ms_strdup(contact);
1086 if (lc->sip_conf.guessed_contact!=NULL){
1087 ms_free(lc->sip_conf.guessed_contact);
1088 lc->sip_conf.guessed_contact=NULL;
1090 linphone_address_destroy(ctt);
1095 /*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
1096 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
1097 if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
1098 strncpy(result,linphone_core_get_nat_address(lc),LINPHONE_IPADDR_SIZE);
1101 if (dest==NULL) dest="87.98.157.38"; /*a public IP address*/
1102 if (linphone_core_get_local_ip_for(dest,result)==0)
1104 /*else fallback to SAL routine that will attempt to find the most realistic interface */
1105 sal_get_default_local_ip(lc->sal,lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,result,LINPHONE_IPADDR_SIZE);
1108 static void update_primary_contact(LinphoneCore *lc){
1110 char tmp[LINPHONE_IPADDR_SIZE];
1112 LinphoneAddress *url;
1113 if (lc->sip_conf.guessed_contact!=NULL){
1114 ms_free(lc->sip_conf.guessed_contact);
1115 lc->sip_conf.guessed_contact=NULL;
1117 url=linphone_address_new(lc->sip_conf.contact);
1119 ms_error("Could not parse identity contact !");
1120 url=linphone_address_new("sip:unknown@unkwownhost");
1122 linphone_core_get_local_ip(lc, NULL, tmp);
1123 if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
1124 ms_warning("Local loopback network only !");
1125 lc->sip_conf.loopback_only=TRUE;
1126 }else lc->sip_conf.loopback_only=FALSE;
1127 linphone_address_set_domain(url,tmp);
1128 linphone_address_set_port_int(url,lc->sip_conf.sip_port);
1129 guessed=linphone_address_as_string(url);
1130 lc->sip_conf.guessed_contact=guessed;
1131 linphone_address_destroy(url);
1135 * Returns the default identity when no proxy configuration is used.
1139 const char *linphone_core_get_primary_contact(LinphoneCore *lc){
1142 if (lc->sip_conf.guess_hostname){
1143 if (lc->sip_conf.guessed_contact==NULL || lc->sip_conf.loopback_only){
1144 update_primary_contact(lc);
1146 identity=lc->sip_conf.guessed_contact;
1148 identity=lc->sip_conf.contact;
1154 * Tells LinphoneCore to guess local hostname automatically in primary contact.
1158 void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
1159 lc->sip_conf.guess_hostname=val;
1163 * Returns TRUE if hostname part of primary contact is guessed automatically.
1167 bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
1168 return lc->sip_conf.guess_hostname;
1172 * Same as linphone_core_get_primary_contact() but the result is a LinphoneAddress object
1173 * instead of const char*
1177 LinphoneAddress *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
1178 return linphone_address_new(linphone_core_get_primary_contact(lc));
1182 * Sets the list of audio codecs.
1184 * @ingroup media_parameters
1185 * The list is taken by the LinphoneCore thus the application should not free it.
1186 * This list is made of struct PayloadType describing the codec parameters.
1188 int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
1190 if (lc->codecs_conf.audio_codecs!=NULL) ms_list_free(lc->codecs_conf.audio_codecs);
1191 lc->codecs_conf.audio_codecs=codecs;
1196 * Sets the list of video codecs.
1198 * @ingroup media_parameters
1199 * The list is taken by the LinphoneCore thus the application should not free it.
1200 * This list is made of struct PayloadType describing the codec parameters.
1202 int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
1204 if (lc->codecs_conf.video_codecs!=NULL) ms_list_free(lc->codecs_conf.video_codecs);
1205 lc->codecs_conf.video_codecs=codecs;
1209 const MSList * linphone_core_get_friend_list(const LinphoneCore *lc)
1215 * Returns the nominal jitter buffer size in milliseconds.
1217 * @ingroup media_parameters
1219 int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
1221 return lc->rtp_conf.audio_jitt_comp;
1225 * Returns the UDP port used for audio streaming.
1227 * @ingroup network_parameters
1229 int linphone_core_get_audio_port(const LinphoneCore *lc)
1231 return lc->rtp_conf.audio_rtp_port;
1235 * Returns the UDP port used for video streaming.
1237 * @ingroup network_parameters
1239 int linphone_core_get_video_port(const LinphoneCore *lc){
1240 return lc->rtp_conf.video_rtp_port;
1245 * Returns the value in seconds of the no-rtp timeout.
1247 * @ingroup media_parameters
1248 * When no RTP or RTCP packets have been received for a while
1249 * LinphoneCore will consider the call is broken (remote end crashed or
1250 * disconnected from the network), and thus will terminate the call.
1251 * The no-rtp timeout is the duration above which the call is considered broken.
1253 int linphone_core_get_nortp_timeout(const LinphoneCore *lc){
1254 return lc->rtp_conf.nortp_timeout;
1258 * Sets the nominal audio jitter buffer size in milliseconds.
1260 * @ingroup media_parameters
1262 void linphone_core_set_audio_jittcomp(LinphoneCore *lc, int value)
1264 lc->rtp_conf.audio_jitt_comp=value;
1268 * Sets the UDP port used for audio streaming.
1270 * @ingroup network_parameters
1272 void linphone_core_set_audio_port(LinphoneCore *lc, int port)
1274 lc->rtp_conf.audio_rtp_port=port;
1278 * Sets the UDP port used for video streaming.
1280 * @ingroup network_parameters
1282 void linphone_core_set_video_port(LinphoneCore *lc, int port){
1283 lc->rtp_conf.video_rtp_port=port;
1287 * Sets the no-rtp timeout value in seconds.
1289 * @ingroup media_parameters
1290 * See linphone_core_get_nortp_timeout() for details.
1292 void linphone_core_set_nortp_timeout(LinphoneCore *lc, int nortp_timeout){
1293 lc->rtp_conf.nortp_timeout=nortp_timeout;
1297 * Indicates whether SIP INFO is used for sending digits.
1299 * @ingroup media_parameters
1301 bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
1303 return lc->sip_conf.use_info;
1307 * Sets whether SIP INFO is to be used for sending digits.
1309 * @ingroup media_parameters
1311 void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
1313 lc->sip_conf.use_info=use_info;
1317 * Indicates whether RFC2833 is used for sending digits.
1319 * @ingroup media_parameters
1321 bool_t linphone_core_get_use_rfc2833_for_dtmf(LinphoneCore *lc)
1323 return lc->sip_conf.use_rfc2833;
1327 * Sets whether RFC2833 is to be used for sending digits.
1329 * @ingroup media_parameters
1331 void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833)
1333 lc->sip_conf.use_rfc2833=use_rfc2833;
1337 * Returns the UDP port used by SIP.
1339 * @ingroup network_parameters
1341 int linphone_core_get_sip_port(LinphoneCore *lc)
1343 return lc->sip_conf.sip_port;
1346 static bool_t exosip_running=FALSE;
1347 static char _ua_name[64]="Linphone";
1348 static char _ua_version[64]=LINPHONE_VERSION;
1350 #ifdef HAVE_EXOSIP_GET_VERSION
1351 extern const char *eXosip_get_version();
1354 static void apply_user_agent(LinphoneCore *lc){
1355 char ua_string[256];
1356 snprintf(ua_string,sizeof(ua_string),"%s/%s (eXosip2/%s)",_ua_name,_ua_version,
1357 #ifdef HAVE_EXOSIP_GET_VERSION
1358 eXosip_get_version()
1363 if (lc->sal) sal_set_user_agent(lc->sal,ua_string);
1367 * Sets the user agent string used in SIP messages.
1371 void linphone_core_set_user_agent(const char *name, const char *ver){
1372 strncpy(_ua_name,name,sizeof(_ua_name)-1);
1373 strncpy(_ua_version,ver,sizeof(_ua_version));
1377 * Sets the UDP port to be used by SIP.
1379 * @ingroup network_parameters
1381 void linphone_core_set_sip_port(LinphoneCore *lc,int port)
1383 const char *anyaddr;
1385 if (port==lc->sip_conf.sip_port) return;
1386 lc->sip_conf.sip_port=port;
1388 if (lc->sal==NULL) return;
1390 if (lc->sip_conf.ipv6_enabled)
1394 err=sal_listen_port (lc->sal,anyaddr,port, SalTransportDatagram,FALSE);
1396 char *msg=ortp_strdup_printf("UDP port %i seems already in use ! Cannot initialize.",port);
1398 lc->vtable.display_warning(lc,msg);
1402 apply_user_agent(lc);
1406 * Returns TRUE if IPv6 is enabled.
1408 * @ingroup network_parameters
1409 * See linphone_core_enable_ipv6() for more details on how IPv6 is supported in liblinphone.
1411 bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
1412 return lc->sip_conf.ipv6_enabled;
1416 * Turns IPv6 support on or off.
1418 * @ingroup network_parameters
1420 * @note IPv6 support is exclusive with IPv4 in liblinphone:
1421 * when IPv6 is turned on, IPv4 calls won't be possible anymore.
1422 * By default IPv6 support is off.
1424 void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
1425 if (lc->sip_conf.ipv6_enabled!=val){
1426 lc->sip_conf.ipv6_enabled=val;
1428 /* we need to restart eXosip */
1429 linphone_core_set_sip_port(lc, lc->sip_conf.sip_port);
1434 static void display_bandwidth(RtpSession *as, RtpSession *vs){
1435 ms_message("bandwidth usage: audio=[d=%.1f,u=%.1f] video=[d=%.1f,u=%.1f] kbit/sec",
1436 (as!=NULL) ? (rtp_session_compute_recv_bandwidth(as)*1e-3) : 0,
1437 (as!=NULL) ? (rtp_session_compute_send_bandwidth(as)*1e-3) : 0,
1438 (vs!=NULL) ? (rtp_session_compute_recv_bandwidth(vs)*1e-3) : 0,
1439 (vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0);
1442 static void linphone_core_disconnected(LinphoneCore *lc){
1443 lc->vtable.display_warning(lc,_("Remote end seems to have disconnected, the call is going to be closed."));
1444 linphone_core_terminate_call(lc,NULL);
1447 static void monitor_network_state(LinphoneCore *lc, time_t curtime){
1448 static time_t last_check=0;
1449 static bool_t last_status=FALSE;
1450 char result[LINPHONE_IPADDR_SIZE];
1453 /* only do the network up checking every five seconds */
1454 if (last_check==0 || (curtime-last_check)>=5){
1455 sal_get_default_local_ip(lc->sal,
1456 lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,
1457 result,LINPHONE_IPADDR_SIZE);
1458 if (strcmp(result,"::1")!=0 && strcmp(result,"127.0.0.1")!=0){
1460 }else new_status=FALSE;
1462 if (new_status!=last_status) {
1463 set_network_reachable(lc,new_status);
1464 last_status=new_status;
1469 static void proxy_update(LinphoneCore *lc){
1470 ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
1473 static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){
1474 LinphoneFriend *lf=linphone_core_get_friend_by_address(lc,info->sip_uri);
1477 ms_message("%s has a BuddyInfo assigned with image %p",info->sip_uri, info->image_data);
1478 if (lc->vtable.buddy_info_updated)
1479 lc->vtable.buddy_info_updated(lc,lf);
1481 ms_warning("Could not any friend with uri %s",info->sip_uri);
1485 static void analyze_buddy_lookup_results(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1487 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1488 for (elem=lc->bl_reqs;elem!=NULL;elem=ms_list_next(elem)){
1489 BuddyLookupRequest *req=(BuddyLookupRequest *)elem->data;
1490 if (req->status==BuddyLookupDone || req->status==BuddyLookupFailure){
1491 if (req->results!=NULL){
1492 BuddyInfo *i=(BuddyInfo*)req->results->data;
1493 ms_list_free(req->results);
1495 assign_buddy_info(lc,i);
1497 sip_setup_context_buddy_lookup_free(ctx,req);
1501 /*purge completed requests */
1502 while((elem=ms_list_find(lc->bl_reqs,NULL))!=NULL){
1503 lc->bl_reqs=ms_list_remove_link(lc->bl_reqs,elem);
1507 static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1509 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1510 for(elem=linphone_core_get_friend_list(lc);elem!=NULL;elem=elem->next){
1511 LinphoneFriend *lf=(LinphoneFriend*)elem->data;
1512 if (lf->info==NULL){
1513 if (linphone_core_lookup_known_proxy(lc,lf->uri)==cfg){
1514 if (linphone_address_get_username(lf->uri)!=NULL){
1515 BuddyLookupRequest *req;
1516 char *tmp=linphone_address_as_string_uri_only(lf->uri);
1517 req=sip_setup_context_create_buddy_lookup_request(ctx);
1518 buddy_lookup_request_set_key(req,tmp);
1519 buddy_lookup_request_set_max_results(req,1);
1520 sip_setup_context_buddy_lookup_submit(ctx,req);
1521 lc->bl_reqs=ms_list_append(lc->bl_reqs,req);
1529 static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
1530 LinphoneProxyConfig *cfg=NULL;
1531 linphone_core_get_default_proxy(lc,&cfg);
1533 if (lc->bl_refresh){
1534 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1535 if (ctx && (sip_setup_context_get_capabilities(ctx) & SIP_SETUP_CAP_BUDDY_LOOKUP)){
1536 linphone_core_grab_buddy_infos(lc,cfg);
1537 lc->bl_refresh=FALSE;
1540 if (lc->bl_reqs) analyze_buddy_lookup_results(lc,cfg);
1545 * Main loop function. It is crucial that your application call it periodically.
1547 * @ingroup initializing
1548 * linphone_core_iterate() performs various backgrounds tasks:
1549 * - receiving of SIP messages
1550 * - handles timers and timeout
1551 * - performs registration to proxies
1552 * - authentication retries
1553 * The application MUST call this function from periodically, in its main loop.
1554 * Be careful that this function must be call from the same thread as
1555 * other liblinphone methods. In not the case make sure all liblinphone calls are
1556 * serialized with a mutex.
1558 void linphone_core_iterate(LinphoneCore *lc){
1559 int disconnect_timeout = linphone_core_get_nortp_timeout(lc);
1560 time_t curtime=time(NULL);
1562 bool_t one_second_elapsed=FALSE;
1563 bool_t disconnected=FALSE;
1565 if (curtime-lc->prevtime>=1){
1566 lc->prevtime=curtime;
1567 one_second_elapsed=TRUE;
1570 if (lc->preview_finished){
1571 lc->preview_finished=0;
1572 ring_stop(lc->ringstream);
1573 lc->ringstream=NULL;
1574 lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
1577 sal_iterate(lc->sal);
1578 if (lc->auto_net_state_mon) monitor_network_state(lc,curtime);
1582 if (lc->call!=NULL){
1583 LinphoneCall *call=lc->call;
1585 if (call->dir==LinphoneCallIncoming && call->state==LCStateRinging){
1586 elapsed=curtime-call->start_time;
1587 ms_message("incoming call ringing for %i seconds",elapsed);
1588 if (elapsed>lc->sip_conf.inc_timeout){
1589 linphone_core_terminate_call(lc,NULL);
1591 }else if (call->state==LCStateAVRunning){
1592 if (one_second_elapsed){
1593 RtpSession *as=NULL,*vs=NULL;
1594 lc->prevtime=curtime;
1595 if (lc->audiostream!=NULL)
1596 as=lc->audiostream->session;
1597 if (lc->videostream!=NULL)
1598 vs=lc->videostream->session;
1599 display_bandwidth(as,vs);
1601 #ifdef VIDEO_ENABLED
1602 if (lc->videostream!=NULL)
1603 video_stream_iterate(lc->videostream);
1605 if (lc->audiostream!=NULL && disconnect_timeout>0)
1606 disconnected=!audio_stream_alive(lc->audiostream,disconnect_timeout);
1609 if (linphone_core_video_preview_enabled(lc)){
1610 if (lc->previewstream==NULL)
1611 toggle_video_preview(lc,TRUE);
1612 #ifdef VIDEO_ENABLED
1613 else video_stream_iterate(lc->previewstream);
1616 if (lc->previewstream!=NULL)
1617 toggle_video_preview(lc,FALSE);
1620 linphone_core_disconnected(lc);
1622 linphone_core_do_plugin_tasks(lc);
1624 if (one_second_elapsed && lp_config_needs_commit(lc->config)){
1625 lp_config_sync(lc->config);
1630 bool_t linphone_core_interpret_url(LinphoneCore *lc, const char *url, LinphoneAddress **real_parsed_url, char **route){
1631 enum_lookup_res_t *enumres=NULL;
1632 LinphoneAddress *parsed_url=NULL;
1633 char *enum_domain=NULL;
1634 LinphoneProxyConfig *proxy=lc->default_proxy;;
1636 const char *tmproute;
1637 LinphoneAddress *uri;
1639 if (real_parsed_url!=NULL) *real_parsed_url=NULL;
1641 tmproute=linphone_core_get_route(lc);
1643 if (is_enum(url,&enum_domain)){
1644 lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
1645 if (enum_lookup(enum_domain,&enumres)<0){
1646 lc->vtable.display_status(lc,_("Could not resolve this number."));
1647 ms_free(enum_domain);
1650 ms_free(enum_domain);
1651 tmpurl=enumres->sip_address[0];
1652 if (real_parsed_url!=NULL) *real_parsed_url=linphone_address_new(tmpurl);
1653 enum_lookup_res_free(enumres);
1654 if (tmproute) *route=ms_strdup(tmproute);
1657 /* check if we have a "sip:" */
1658 if (strstr(url,"sip:")==NULL){
1659 /* this doesn't look like a true sip uri */
1660 if (strchr(url,'@')!=NULL){
1661 /* seems like sip: is missing !*/
1662 tmpurl=ms_strdup_printf("sip:%s",url);
1663 uri=linphone_address_new(tmpurl);
1666 if (real_parsed_url!=NULL) *real_parsed_url=uri;
1672 /* append the proxy domain suffix */
1673 const char *identity=linphone_proxy_config_get_identity(proxy);
1674 char normalized_username[128];
1675 uri=linphone_address_new(identity);
1679 linphone_address_set_display_name(uri,NULL);
1680 linphone_proxy_config_normalize_number(proxy,url,normalized_username,
1681 sizeof(normalized_username));
1682 linphone_address_set_username(uri,normalized_username);
1684 if (real_parsed_url!=NULL) *real_parsed_url=uri;
1685 if (tmproute) *route=ms_strdup(tmproute);
1689 parsed_url=linphone_address_new(url);
1690 if (parsed_url!=NULL){
1691 if (real_parsed_url!=NULL) *real_parsed_url=parsed_url;
1692 else linphone_address_destroy(parsed_url);
1693 if (tmproute) *route=ms_strdup(tmproute);
1697 /* else we could not do anything with url given by user, so display an error */
1698 if (lc->vtable.display_warning!=NULL){
1699 lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
1705 * Returns the default identity SIP address.
1708 * This is an helper function:
1710 * If no default proxy is set, this will return the primary contact (
1711 * see linphone_core_get_primary_contact() ). If a default proxy is set
1712 * it returns the registered identity on the proxy.
1714 const char * linphone_core_get_identity(LinphoneCore *lc){
1715 LinphoneProxyConfig *proxy=NULL;
1717 linphone_core_get_default_proxy(lc,&proxy);
1719 from=linphone_proxy_config_get_identity(proxy);
1720 }else from=linphone_core_get_primary_contact(lc);
1724 const char * linphone_core_get_route(LinphoneCore *lc){
1725 LinphoneProxyConfig *proxy=NULL;
1726 const char *route=NULL;
1727 linphone_core_get_default_proxy(lc,&proxy);
1729 route=linphone_proxy_config_get_route(proxy);
1734 LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
1736 LinphoneProxyConfig *found_cfg=NULL;
1737 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=elem->next){
1738 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1739 const char *domain=linphone_proxy_config_get_domain(cfg);
1740 if (domain!=NULL && strcmp(domain,linphone_address_get_domain(uri))==0){
1748 static char *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){
1749 LinphoneAddress *ctt;
1750 const char *localip=call->localip;
1752 if (linphone_core_get_firewall_policy(lc)==LINPHONE_POLICY_USE_NAT_ADDRESS){
1753 ctt=linphone_core_get_primary_contact_parsed(lc);
1754 return ms_strdup_printf("sip:%s@%s",linphone_address_get_username(ctt),
1755 linphone_core_get_nat_address(lc));
1758 if (call->op && sal_op_get_contact(call->op)!=NULL){
1762 if (dest_proxy && dest_proxy->op){
1763 const char *fixed_contact=sal_op_get_contact(dest_proxy->op);
1764 if (fixed_contact) {
1765 ms_message("Contact has been fixed using proxy to %s",fixed_contact);
1766 return ms_strdup(fixed_contact);
1769 ctt=linphone_core_get_primary_contact_parsed(lc);
1773 /*otherwise use supllied localip*/
1774 linphone_address_set_domain(ctt,localip);
1775 linphone_address_set_port_int(ctt,linphone_core_get_sip_port(lc));
1776 ret=linphone_address_as_string_uri_only(ctt);
1777 linphone_address_destroy(ctt);
1778 ms_message("Contact has been fixed using local ip to %s",ret);
1785 * Initiates an outgoing call
1787 * @ingroup call_control
1788 * @param lc the LinphoneCore object
1789 * @param url the destination of the call (sip address).
1791 int linphone_core_invite(LinphoneCore *lc, const char *url)
1796 const char *from=NULL;
1798 LinphoneProxyConfig *proxy=NULL;
1799 LinphoneAddress *parsed_url2=NULL;
1800 LinphoneAddress *real_parsed_url=NULL;
1801 char *real_url=NULL;
1802 LinphoneProxyConfig *dest_proxy=NULL;
1805 if (lc->call!=NULL){
1806 lc->vtable.display_warning(lc,_("Sorry, having multiple simultaneous calls is not supported yet !"));
1810 linphone_core_get_default_proxy(lc,&proxy);
1811 if (!linphone_core_interpret_url(lc,url,&real_parsed_url,&route)){
1814 real_url=linphone_address_as_string(real_parsed_url);
1815 dest_proxy=linphone_core_lookup_known_proxy(lc,real_parsed_url);
1817 if (proxy!=dest_proxy && dest_proxy!=NULL) {
1818 ms_message("Overriding default proxy setting for this call:");
1819 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
1822 if (dest_proxy!=NULL)
1823 from=linphone_proxy_config_get_identity(dest_proxy);
1824 else if (proxy!=NULL)
1825 from=linphone_proxy_config_get_identity(proxy);
1827 /* if no proxy or no identity defined for this proxy, default to primary contact*/
1828 if (from==NULL) from=linphone_core_get_primary_contact(lc);
1830 parsed_url2=linphone_address_new(from);
1832 call=linphone_call_new_outgoing(lc,parsed_url2,real_parsed_url);
1833 sal_op_set_route(call->op,route);
1835 /*try to be best-effort in giving real local or routable contact address */
1836 contact=get_fixed_contact(lc,call,dest_proxy);
1838 sal_op_set_contact(call->op, contact);
1844 linphone_core_init_media_streams(lc,lc->call);
1845 if (!lc->sip_conf.sdp_200_ack){
1846 call->media_pending=TRUE;
1847 sal_call_set_local_media_description(call->op,call->localdesc);
1849 err=sal_call(call->op,from,real_url);
1851 if (lc->sip_conf.sdp_200_ack){
1852 call->media_pending=TRUE;
1853 sal_call_set_local_media_description(call->op,call->localdesc);
1855 barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
1856 lc->vtable.display_status(lc,barmsg);
1860 ms_warning("Could not initiate call.");
1861 lc->vtable.display_status(lc,_("could not call"));
1862 linphone_core_stop_media_streams(lc,call);
1863 linphone_call_destroy(call);
1865 }else gstate_new_state(lc, GSTATE_CALL_OUT_INVITE, url);
1867 if (real_url!=NULL) ms_free(real_url);
1868 if (route!=NULL) ms_free(route);
1869 return (err<0) ? -1 : 0;
1872 int linphone_core_refer(LinphoneCore *lc, const char *url)
1874 char *real_url=NULL;
1875 LinphoneAddress *real_parsed_url=NULL;
1878 if (!linphone_core_interpret_url(lc,url,&real_parsed_url, &route)){
1882 if (route!=NULL) ms_free(route);
1885 ms_warning("No established call to refer.");
1889 real_url=linphone_address_as_string (real_parsed_url);
1890 sal_refer(call->op,real_url);
1896 * Returns true if in incoming call is pending, ie waiting for being answered or declined.
1898 * @ingroup call_control
1900 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
1901 if (lc->call!=NULL && lc->call->dir==LinphoneCallIncoming){
1907 void linphone_core_init_media_streams(LinphoneCore *lc, LinphoneCall *call){
1908 SalMediaDescription *md=call->localdesc;
1909 lc->audiostream=audio_stream_new(md->streams[0].port,linphone_core_ipv6_enabled(lc));
1910 if (linphone_core_echo_limiter_enabled(lc)){
1911 const char *type=lp_config_get_string(lc->config,"sound","el_type","mic");
1912 if (strcasecmp(type,"mic")==0)
1913 audio_stream_enable_echo_limiter(lc->audiostream,ELControlMic);
1914 else if (strcasecmp(type,"speaker")==0)
1915 audio_stream_enable_echo_limiter(lc->audiostream,ELControlSpeaker);
1917 audio_stream_enable_gain_control(lc->audiostream,TRUE);
1918 if (linphone_core_echo_cancellation_enabled(lc)){
1919 int len,delay,framesize;
1920 len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
1921 delay=lp_config_get_int(lc->config,"sound","ec_delay",0);
1922 framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0);
1923 audio_stream_set_echo_canceller_params(lc->audiostream,len,delay,framesize);
1925 audio_stream_enable_automatic_gain_control(lc->audiostream,linphone_core_agc_enabled(lc));
1927 int enabled=lp_config_get_int(lc->config,"sound","noisegate",0);
1928 audio_stream_enable_noise_gate(lc->audiostream,enabled);
1931 rtp_session_set_transports(lc->audiostream->session,lc->a_rtp,lc->a_rtcp);
1933 #ifdef VIDEO_ENABLED
1934 if ((lc->video_conf.display || lc->video_conf.capture) && md->streams[1].port>0)
1935 lc->videostream=video_stream_new(md->streams[1].port,linphone_core_ipv6_enabled(lc));
1937 lc->videostream=NULL;
1941 static int dtmf_tab[16]={'0','1','2','3','4','5','6','7','8','9','*','#','A','B','C','D'};
1943 static void linphone_core_dtmf_received(RtpSession* s, int dtmf, void* user_data){
1944 LinphoneCore* lc = (LinphoneCore*)user_data;
1945 if (dtmf<0 || dtmf>15){
1946 ms_warning("Bad dtmf value %i",dtmf);
1949 if (lc->vtable.dtmf_received != NULL)
1950 lc->vtable.dtmf_received(lc, dtmf_tab[dtmf]);
1953 static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){
1955 MSFilter *f=st->equalizer;
1956 int enabled=lp_config_get_int(lc->config,"sound","eq_active",0);
1957 const char *gains=lp_config_get_string(lc->config,"sound","eq_gains",NULL);
1958 ms_filter_call_method(f,MS_EQUALIZER_SET_ACTIVE,&enabled);
1964 if (sscanf(gains,"%f:%f:%f %n",&g.frequency,&g.gain,&g.width,&bytes)==3){
1965 ms_message("Read equalizer gains: %f(~%f) --> %f",g.frequency,g.width,g.gain);
1966 ms_filter_call_method(f,MS_EQUALIZER_SET_GAIN,&g);
1975 static void post_configure_audio_streams(LinphoneCore *lc){
1976 AudioStream *st=lc->audiostream;
1977 float gain=lp_config_get_float(lc->config,"sound","mic_gain",-1);
1979 audio_stream_set_mic_gain(st,gain);
1980 if (linphone_core_echo_limiter_enabled(lc)){
1981 float speed=lp_config_get_float(lc->config,"sound","el_speed",-1);
1982 float thres=lp_config_get_float(lc->config,"sound","el_thres",-1);
1983 float force=lp_config_get_float(lc->config,"sound","el_force",-1);
1984 int sustain=lp_config_get_int(lc->config,"sound","el_sustain",-1);
1986 if (st->el_type==ELControlMic){
1988 if (speed==-1) speed=0.03;
1989 if (force==-1) force=10;
1991 else if (st->el_type==ELControlSpeaker){
1993 if (speed==-1) speed=0.02;
1994 if (force==-1) force=5;
1997 ms_filter_call_method(f,MS_VOLUME_SET_EA_SPEED,&speed);
1999 ms_filter_call_method(f,MS_VOLUME_SET_EA_THRESHOLD,&thres);
2001 ms_filter_call_method(f,MS_VOLUME_SET_EA_FORCE,&force);
2003 ms_filter_call_method(f,MS_VOLUME_SET_EA_SUSTAIN,&sustain);
2007 float ng_thres=lp_config_get_float(lc->config,"sound","ng_thres",0.05);
2008 float ng_floorgain=lp_config_get_float(lc->config,"sound","ng_floorgain",0);
2009 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_thres);
2010 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&ng_floorgain);
2012 parametrize_equalizer(lc,st);
2013 if (lc->vtable.dtmf_received!=NULL){
2014 /* replace by our default action*/
2015 audio_stream_play_received_dtmfs(lc->audiostream,FALSE);
2016 rtp_session_signal_connect(lc->audiostream->session,"telephone-event",(RtpCallback)linphone_core_dtmf_received,(unsigned long)lc);
2020 static RtpProfile *make_profile(LinphoneCore *lc, const SalStreamDescription *desc, int *used_pt){
2023 RtpProfile *prof=rtp_profile_new("Call profile");
2025 if (desc->type==SalAudio){
2026 bw=get_min_bandwidth(lc->up_audio_bw,desc->bandwidth);
2028 else bw=get_min_bandwidth(lc->up_video_bw,desc->bandwidth);
2029 for(elem=desc->payloads;elem!=NULL;elem=elem->next){
2030 PayloadType *pt=(PayloadType*)elem->data;
2031 if (bw>0) pt->normal_bitrate=bw*1000;
2032 else if (desc->type==SalAudio){
2033 pt->normal_bitrate=-1;
2036 *used_pt=payload_type_get_number(pt);
2041 snprintf(tmp,sizeof(tmp),"ptime=%i",desc->ptime);
2042 payload_type_append_send_fmtp(pt,tmp);
2044 rtp_profile_set_payload(prof,payload_type_get_number(pt),pt);
2049 void linphone_core_start_media_streams(LinphoneCore *lc, LinphoneCall *call){
2050 LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
2051 const char *tool="linphone-" LINPHONE_VERSION;
2054 /* adjust rtp jitter compensation. It must be at least the latency of the sound card */
2055 int jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp);
2057 if (call->media_start_time==0) call->media_start_time=time(NULL);
2059 cname=linphone_address_as_string_uri_only(me);
2061 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
2062 SalProtoRtpAvp,SalAudio);
2064 call->audio_profile=make_profile(lc,stream,&used_pt);
2065 if (!lc->use_files){
2066 MSSndCard *playcard=lc->sound_conf.play_sndcard;
2067 MSSndCard *captcard=lc->sound_conf.capt_sndcard;
2068 if (playcard==NULL) {
2069 ms_warning("No card defined for playback !");
2072 if (captcard==NULL) {
2073 ms_warning("No card defined for capture !");
2076 audio_stream_start_now(
2078 call->audio_profile,
2079 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
2086 linphone_core_echo_cancellation_enabled(lc));
2088 audio_stream_start_with_files(
2090 call->audio_profile,
2091 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
2099 post_configure_audio_streams(lc);
2100 audio_stream_set_rtcp_information(lc->audiostream, cname, tool);
2101 }else ms_warning("No audio stream defined ?");
2103 #ifdef VIDEO_ENABLED
2105 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
2106 SalProtoRtpAvp,SalVideo);
2107 /* shutdown preview */
2108 if (lc->previewstream!=NULL) {
2109 video_preview_stop(lc->previewstream);
2110 lc->previewstream=NULL;
2112 if (stream && (lc->video_conf.display || lc->video_conf.capture)) {
2113 const char *addr=stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr;
2114 call->video_profile=make_profile(lc,stream,&used_pt);
2115 video_stream_set_sent_video_size(lc->videostream,linphone_core_get_preferred_video_size(lc));
2116 video_stream_enable_self_view(lc->videostream,lc->video_conf.selfview);
2117 if (lc->video_conf.display && lc->video_conf.capture)
2118 video_stream_start(lc->videostream,
2119 call->video_profile, addr, stream->port,
2121 used_pt, jitt_comp, lc->video_conf.device);
2122 else if (lc->video_conf.display)
2123 video_stream_recv_only_start(lc->videostream,
2124 call->video_profile, addr, stream->port,
2125 used_pt, jitt_comp);
2126 else if (lc->video_conf.capture)
2127 video_stream_send_only_start(lc->videostream,
2128 call->video_profile, addr, stream->port,
2130 used_pt, jitt_comp, lc->video_conf.device);
2131 video_stream_set_rtcp_information(lc->videostream, cname,tool);
2138 linphone_address_destroy(me);
2139 lc->call->state=LCStateAVRunning;
2142 void linphone_core_stop_media_streams(LinphoneCore *lc, LinphoneCall *call){
2143 if (lc->audiostream!=NULL) {
2144 audio_stream_stop(lc->audiostream);
2145 lc->audiostream=NULL;
2147 #ifdef VIDEO_ENABLED
2148 if (lc->videostream!=NULL){
2149 if (lc->video_conf.display && lc->video_conf.capture)
2150 video_stream_stop(lc->videostream);
2151 else if (lc->video_conf.display)
2152 video_stream_recv_only_stop(lc->videostream);
2153 else if (lc->video_conf.capture)
2154 video_stream_send_only_stop(lc->videostream);
2155 lc->videostream=NULL;
2157 if (linphone_core_video_preview_enabled(lc)){
2158 if (lc->previewstream==NULL){
2159 lc->previewstream=video_preview_start(lc->video_conf.device, lc->video_conf.vsize);
2163 if (call->audio_profile){
2164 rtp_profile_clear_all(call->audio_profile);
2165 rtp_profile_destroy(call->audio_profile);
2166 call->audio_profile=NULL;
2168 if (call->video_profile){
2169 rtp_profile_clear_all(call->video_profile);
2170 rtp_profile_destroy(call->video_profile);
2171 call->video_profile=NULL;
2176 * Accept an incoming call.
2178 * @ingroup call_control
2179 * Basically the application is notified of incoming calls within the
2180 * invite_recv callback of the #LinphoneCoreVTable structure.
2181 * The application can later respond positively to the call using
2183 * @param lc the LinphoneCore object
2184 * @param url the SIP address of the originator of the call, or NULL.
2185 * This argument is useful for managing multiple calls simulatenously,
2186 * however this feature is not supported yet.
2187 * Using NULL will accept the unique incoming call in progress.
2189 int linphone_core_accept_call(LinphoneCore *lc, const char *url)
2191 LinphoneCall *call=lc->call;
2192 const char *contact=NULL;
2198 if (call->state==LCStateAVRunning){
2199 /*call already accepted*/
2204 if (lc->ringstream!=NULL) {
2205 ms_message("stop ringing");
2206 ring_stop(lc->ringstream);
2207 ms_message("ring stopped");
2208 lc->ringstream=NULL;
2211 /*try to be best-effort in giving real local or routable contact address*/
2212 contact=get_fixed_contact(lc,call,NULL);
2214 sal_op_set_contact(call->op,contact);
2216 sal_call_accept(call->op);
2217 lc->vtable.display_status(lc,_("Connected."));
2218 gstate_new_state(lc, GSTATE_CALL_IN_CONNECTED, NULL);
2219 call->resultdesc=sal_call_get_final_media_description(call->op);
2220 if (call->resultdesc){
2221 sal_media_description_ref(call->resultdesc);
2222 linphone_core_start_media_streams(lc, call);
2223 }else call->media_pending=TRUE;
2224 ms_message("call answered.");
2229 * Terminates a call.
2231 * @ingroup call_control
2232 * @param lc The LinphoneCore
2233 * @param url the destination of the call to be terminated, use NULL if there is
2234 * only one call (which is case in this version of liblinphone).
2236 int linphone_core_terminate_call(LinphoneCore *lc, const char *url)
2238 LinphoneCall *call=lc->call;
2243 sal_call_terminate(call->op);
2246 if (lc->ringstream!=NULL) {
2247 ring_stop(lc->ringstream);
2248 lc->ringstream=NULL;
2250 linphone_core_stop_media_streams(lc,call);
2251 lc->vtable.display_status(lc,_("Call ended") );
2252 gstate_new_state(lc, GSTATE_CALL_END, NULL);
2253 linphone_call_destroy(call);
2258 * Returns TRUE if there is a call running or pending.
2260 * @ingroup call_control
2262 bool_t linphone_core_in_call(const LinphoneCore *lc){
2263 return lc->call!=NULL;
2266 int linphone_core_send_publish(LinphoneCore *lc,
2267 LinphoneOnlineStatus presence_mode)
2270 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=ms_list_next(elem)){
2271 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2272 if (cfg->publish) linphone_proxy_config_send_publish(cfg,presence_mode);
2278 * Set the incoming call timeout in seconds.
2280 * @ingroup call_control
2281 * If an incoming call isn't answered for this timeout period, it is
2282 * automatically declined.
2284 void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
2285 lc->sip_conf.inc_timeout=seconds;
2289 * Returns the incoming call timeout
2291 * @ingroup call_control
2292 * See linphone_core_set_inc_timeout() for details.
2294 int linphone_core_get_inc_timeout(LinphoneCore *lc){
2295 return lc->sip_conf.inc_timeout;
2298 void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
2299 const char *contact,
2300 LinphoneOnlineStatus presence_mode)
2302 if (minutes_away>0) lc->minutes_away=minutes_away;
2304 if (lc->alt_contact!=NULL) {
2305 ms_free(lc->alt_contact);
2306 lc->alt_contact=NULL;
2308 if (contact) lc->alt_contact=ms_strdup(contact);
2309 if (lc->presence_mode!=presence_mode){
2310 linphone_core_notify_all_friends(lc,presence_mode);
2312 Improve the use of all LINPHONE_STATUS available.
2313 !TODO Do not mix "presence status" with "answer status code"..
2314 Use correct parameter to follow sip_if_match/sip_etag.
2316 linphone_core_send_publish(lc,presence_mode);
2318 lc->prev_mode=lc->presence_mode;
2319 lc->presence_mode=presence_mode;
2322 LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
2323 return lc->presence_mode;
2327 * Get playback sound level in 0-100 scale.
2329 * @ingroup media_parameters
2331 int linphone_core_get_play_level(LinphoneCore *lc)
2333 return lc->sound_conf.play_lev;
2337 * Get ring sound level in 0-100 scale
2339 * @ingroup media_parameters
2341 int linphone_core_get_ring_level(LinphoneCore *lc)
2343 return lc->sound_conf.ring_lev;
2347 * Get sound capture level in 0-100 scale
2349 * @ingroup media_parameters
2351 int linphone_core_get_rec_level(LinphoneCore *lc){
2352 return lc->sound_conf.rec_lev;
2356 * Set sound ring level in 0-100 scale
2358 * @ingroup media_parameters
2360 void linphone_core_set_ring_level(LinphoneCore *lc, int level){
2362 lc->sound_conf.ring_lev=level;
2363 sndcard=lc->sound_conf.ring_sndcard;
2364 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2368 * Set sound playback level in 0-100 scale
2370 * @ingroup media_parameters
2372 void linphone_core_set_play_level(LinphoneCore *lc, int level){
2374 lc->sound_conf.play_lev=level;
2375 sndcard=lc->sound_conf.play_sndcard;
2376 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2380 * Set sound capture level in 0-100 scale
2382 * @ingroup media_parameters
2384 void linphone_core_set_rec_level(LinphoneCore *lc, int level)
2387 lc->sound_conf.rec_lev=level;
2388 sndcard=lc->sound_conf.capt_sndcard;
2389 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_CAPTURE,level);
2392 static MSSndCard *get_card_from_string_id(const char *devid, unsigned int cap){
2393 MSSndCard *sndcard=NULL;
2395 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2396 if (sndcard!=NULL &&
2397 (ms_snd_card_get_capabilities(sndcard) & cap)==0 ){
2398 ms_warning("%s card does not have the %s capability, ignoring.",
2400 cap==MS_SND_CARD_CAP_CAPTURE ? "capture" : "playback");
2404 if (sndcard==NULL) {
2405 /* get a card that has read+write capabilities */
2406 sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
2407 /* otherwise refine to the first card having the right capability*/
2409 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2410 for(;elem!=NULL;elem=elem->next){
2411 sndcard=(MSSndCard*)elem->data;
2412 if (ms_snd_card_get_capabilities(sndcard) & cap) break;
2415 if (sndcard==NULL){/*looks like a bug! take the first one !*/
2416 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2417 sndcard=(MSSndCard*)elem->data;
2420 if (sndcard==NULL) ms_error("Could not find a suitable soundcard !");
2425 * Returns true if the specified sound device can capture sound.
2427 * @ingroup media_parameters
2428 * @param devid the device name as returned by linphone_core_get_sound_devices()
2430 bool_t linphone_core_sound_device_can_capture(LinphoneCore *lc, const char *devid){
2432 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2433 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_CAPTURE)) return TRUE;
2438 * Returns true if the specified sound device can play sound.
2440 * @ingroup media_parameters
2441 * @param devid the device name as returned by linphone_core_get_sound_devices()
2443 bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *devid){
2445 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2446 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_PLAYBACK)) return TRUE;
2451 * Sets the sound device used for ringing.
2453 * @ingroup media_parameters
2454 * @param devid the device name as returned by linphone_core_get_sound_devices()
2456 int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
2457 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2458 lc->sound_conf.ring_sndcard=card;
2459 if (card && lc->ready)
2460 lp_config_set_string(lc->config,"sound","ringer_dev_id",ms_snd_card_get_string_id(card));
2465 * Sets the sound device used for playback.
2467 * @ingroup media_parameters
2468 * @param devid the device name as returned by linphone_core_get_sound_devices()
2470 int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
2471 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2472 lc->sound_conf.play_sndcard=card;
2473 if (card && lc->ready)
2474 lp_config_set_string(lc->config,"sound","playback_dev_id",ms_snd_card_get_string_id(card));
2479 * Sets the sound device used for capture.
2481 * @ingroup media_parameters
2482 * @param devid the device name as returned by linphone_core_get_sound_devices()
2484 int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
2485 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_CAPTURE);
2486 lc->sound_conf.capt_sndcard=card;
2487 if (card && lc->ready)
2488 lp_config_set_string(lc->config,"sound","capture_dev_id",ms_snd_card_get_string_id(card));
2493 * Returns the name of the currently assigned sound device for ringing.
2495 * @ingroup media_parameters
2497 const char * linphone_core_get_ringer_device(LinphoneCore *lc)
2499 if (lc->sound_conf.ring_sndcard) return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
2504 * Returns the name of the currently assigned sound device for playback.
2506 * @ingroup media_parameters
2508 const char * linphone_core_get_playback_device(LinphoneCore *lc)
2510 return lc->sound_conf.play_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.play_sndcard) : NULL;
2514 * Returns the name of the currently assigned sound device for capture.
2516 * @ingroup media_parameters
2518 const char * linphone_core_get_capture_device(LinphoneCore *lc)
2520 return lc->sound_conf.capt_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard) : NULL;
2524 * Returns an unmodifiable array of available sound devices.
2526 * @ingroup media_parameters
2527 * The array is NULL terminated.
2529 const char** linphone_core_get_sound_devices(LinphoneCore *lc){
2530 build_sound_devices_table(lc);
2531 return lc->sound_conf.cards;
2535 * Returns an unmodifiable array of available video capture devices.
2537 * @ingroup media_parameters
2538 * The array is NULL terminated.
2540 const char** linphone_core_get_video_devices(const LinphoneCore *lc){
2541 return lc->video_conf.cams;
2544 char linphone_core_get_sound_source(LinphoneCore *lc)
2546 return lc->sound_conf.source;
2549 void linphone_core_set_sound_source(LinphoneCore *lc, char source)
2551 MSSndCard *sndcard=lc->sound_conf.capt_sndcard;
2552 lc->sound_conf.source=source;
2553 if (!sndcard) return;
2556 ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
2559 ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
2567 * Sets the path to a wav file used for ringing.
2569 * The file must be a wav 16bit linear.
2571 * @ingroup media_parameters
2573 void linphone_core_set_ring(LinphoneCore *lc,const char *path){
2574 if (lc->sound_conf.local_ring!=0){
2575 ms_free(lc->sound_conf.local_ring);
2577 lc->sound_conf.local_ring=ms_strdup(path);
2578 if (lc->ready && lc->sound_conf.local_ring)
2579 lp_config_set_string(lc->config,"sound","local_ring",lc->sound_conf.local_ring);
2583 * Returns the path to the wav file used for ringing.
2585 * @ingroup media_parameters
2587 const char *linphone_core_get_ring(const LinphoneCore *lc){
2588 return lc->sound_conf.local_ring;
2591 static void notify_end_of_ring(void *ud ,unsigned int event, void * arg){
2592 LinphoneCore *lc=(LinphoneCore*)ud;
2593 lc->preview_finished=1;
2596 int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata)
2598 if (lc->ringstream!=0){
2599 ms_warning("Cannot start ring now,there's already a ring being played");
2602 lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
2603 lc->preview_finished=0;
2604 if (lc->sound_conf.ring_sndcard!=NULL){
2605 lc->ringstream=ring_start_with_cb(ring,2000,lc->sound_conf.ring_sndcard,notify_end_of_ring,(void *)lc);
2611 * Sets the path to a wav file used for ringing back.
2613 * Ringback means the ring that is heard when it's ringing at the remote party.
2614 * The file must be a wav 16bit linear.
2616 * @ingroup media_parameters
2618 void linphone_core_set_ringback(LinphoneCore *lc, const char *path){
2619 if (lc->sound_conf.remote_ring!=0){
2620 ms_free(lc->sound_conf.remote_ring);
2622 lc->sound_conf.remote_ring=ms_strdup(path);
2626 * Returns the path to the wav file used for ringing back.
2628 * @ingroup media_parameters
2630 const char * linphone_core_get_ringback(const LinphoneCore *lc){
2631 return lc->sound_conf.remote_ring;
2635 * Enables or disable echo cancellation.
2637 * @ingroup media_parameters
2639 void linphone_core_enable_echo_cancellation(LinphoneCore *lc, bool_t val){
2640 lc->sound_conf.ec=val;
2642 lp_config_set_int(lc->config,"sound","echocancellation",val);
2646 * Returns TRUE if echo cancellation is enabled.
2648 * @ingroup media_parameters
2650 bool_t linphone_core_echo_cancellation_enabled(LinphoneCore *lc){
2651 return lc->sound_conf.ec;
2654 void linphone_core_enable_echo_limiter(LinphoneCore *lc, bool_t val){
2655 lc->sound_conf.ea=val;
2658 bool_t linphone_core_echo_limiter_enabled(const LinphoneCore *lc){
2659 return lc->sound_conf.ea;
2663 * Mutes or unmutes the local microphone.
2665 * @ingroup media_parameters
2667 void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){
2668 if (lc->audiostream!=NULL){
2669 audio_stream_set_mic_gain(lc->audiostream,
2670 (val==TRUE) ? 0 : 1.0);
2674 void linphone_core_enable_agc(LinphoneCore *lc, bool_t val){
2675 lc->sound_conf.agc=val;
2678 bool_t linphone_core_agc_enabled(const LinphoneCore *lc){
2679 return lc->sound_conf.agc;
2683 * Send the specified dtmf.
2685 * @ingroup media_parameters
2686 * This function only works during calls. The dtmf is automatically played to the user.
2687 * @param lc The LinphoneCore object
2688 * @param dtmf The dtmf name specified as a char, such as '0', '#' etc...
2691 void linphone_core_send_dtmf(LinphoneCore *lc, char dtmf)
2693 /*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
2694 if (linphone_core_get_use_rfc2833_for_dtmf(lc)!=0 || linphone_core_get_use_info_for_dtmf(lc)==0)
2697 if (lc->audiostream!=NULL){
2698 audio_stream_send_dtmf(lc->audiostream,dtmf);
2702 ms_error("we cannot send RFC2833 dtmf when we are not in communication");
2705 if (linphone_core_get_use_info_for_dtmf(lc)!=0){
2706 /* Out of Band DTMF (use INFO method) */
2707 LinphoneCall *call=lc->call;
2711 sal_call_send_dtmf(call->op,dtmf);
2715 void linphone_core_set_stun_server(LinphoneCore *lc, const char *server){
2716 if (lc->net_conf.stun_server!=NULL)
2717 ms_free(lc->net_conf.stun_server);
2719 lc->net_conf.stun_server=ms_strdup(server);
2720 else lc->net_conf.stun_server=NULL;
2723 const char * linphone_core_get_stun_server(const LinphoneCore *lc){
2724 return lc->net_conf.stun_server;
2727 const char * linphone_core_get_relay_addr(const LinphoneCore *lc){
2728 return lc->net_conf.relay;
2731 int linphone_core_set_relay_addr(LinphoneCore *lc, const char *addr){
2732 if (lc->net_conf.relay!=NULL){
2733 ms_free(lc->net_conf.relay);
2734 lc->net_conf.relay=NULL;
2737 lc->net_conf.relay=ms_strdup(addr);
2742 void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
2744 if (lc->net_conf.nat_address!=NULL){
2745 ms_free(lc->net_conf.nat_address);
2747 if (addr!=NULL) lc->net_conf.nat_address=ms_strdup(addr);
2748 else lc->net_conf.nat_address=NULL;
2749 if (lc->sip_conf.contact) update_primary_contact(lc);
2752 const char *linphone_core_get_nat_address(const LinphoneCore *lc)
2754 return lc->net_conf.nat_address;
2757 void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
2758 lc->net_conf.firewall_policy=pol;
2759 if (lc->sip_conf.contact) update_primary_contact(lc);
2762 LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
2763 return lc->net_conf.firewall_policy;
2767 * Get the list of call logs (past calls).
2769 * @ingroup call_logs
2771 const MSList * linphone_core_get_call_logs(LinphoneCore *lc){
2773 return lc->call_logs;
2777 * Erase the call log.
2779 * @ingroup call_logs
2781 void linphone_core_clear_call_logs(LinphoneCore *lc){
2783 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
2784 lc->call_logs=ms_list_free(lc->call_logs);
2785 call_logs_write_to_config_file(lc);
2788 static void toggle_video_preview(LinphoneCore *lc, bool_t val){
2789 #ifdef VIDEO_ENABLED
2790 if (lc->videostream==NULL){
2792 if (lc->previewstream==NULL){
2793 lc->previewstream=video_preview_start(lc->video_conf.device,
2794 lc->video_conf.vsize);
2797 if (lc->previewstream!=NULL){
2798 video_preview_stop(lc->previewstream);
2799 lc->previewstream=NULL;
2807 * Enables video globally.
2809 * @ingroup media_parameters
2810 * This function does not have any effect during calls. It just indicates LinphoneCore to
2811 * initiate future calls with video or not. The two boolean parameters indicate in which
2812 * direction video is enabled. Setting both to false disables video entirely.
2814 * @param vcap_enabled indicates whether video capture is enabled
2815 * @param display_enabled indicates whether video display should be shown
2818 void linphone_core_enable_video(LinphoneCore *lc, bool_t vcap_enabled, bool_t display_enabled){
2819 #ifndef VIDEO_ENABLED
2820 if (vcap_enabled || display_enabled)
2821 ms_warning("This version of linphone was built without video support.");
2823 lc->video_conf.capture=vcap_enabled;
2824 lc->video_conf.display=display_enabled;
2826 /* need to re-apply network bandwidth settings*/
2827 linphone_core_set_download_bandwidth(lc,
2828 linphone_core_get_download_bandwidth(lc));
2829 linphone_core_set_upload_bandwidth(lc,
2830 linphone_core_get_upload_bandwidth(lc));
2834 * Returns TRUE if video is enabled, FALSE otherwise.
2835 * @ingroup media_parameters
2837 bool_t linphone_core_video_enabled(LinphoneCore *lc){
2838 return (lc->video_conf.display || lc->video_conf.capture);
2842 * Controls video preview enablement.
2844 * @ingroup media_parameters
2845 * Video preview refers to the action of displaying the local webcam image
2846 * to the user while not in call.
2848 void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val){
2849 lc->video_conf.show_local=val;
2853 * Returns TRUE if video previewing is enabled.
2854 * @ingroup media_parameters
2856 bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
2857 return lc->video_conf.show_local;
2861 * Enables or disable self view during calls.
2863 * @ingroup media_parameters
2864 * Self-view refers to having local webcam image inserted in corner
2865 * of the video window during calls.
2866 * This function works at any time, including during calls.
2868 void linphone_core_enable_self_view(LinphoneCore *lc, bool_t val){
2869 lc->video_conf.selfview=val;
2870 #ifdef VIDEO_ENABLED
2871 if (lc->videostream){
2872 video_stream_enable_self_view(lc->videostream,val);
2878 * Returns TRUE if self-view is enabled, FALSE otherwise.
2880 * @ingroup media_parameters
2882 * Refer to linphone_core_enable_self_view() for details.
2884 bool_t linphone_core_self_view_enabled(const LinphoneCore *lc){
2885 return lc->video_conf.selfview;
2889 * Sets the active video device.
2891 * @ingroup media_parameters
2892 * @param id the name of the video device as returned by linphone_core_get_video_devices()
2894 int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
2895 MSWebCam *olddev=lc->video_conf.device;
2898 lc->video_conf.device=ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),id);
2899 if (lc->video_conf.device==NULL){
2900 ms_warning("Could not found video device %s",id);
2903 if (lc->video_conf.device==NULL)
2904 lc->video_conf.device=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());
2905 if (olddev!=NULL && olddev!=lc->video_conf.device){
2906 toggle_video_preview(lc,FALSE);/*restart the video local preview*/
2908 if (lc->ready && lc->video_conf.device){
2909 vd=ms_web_cam_get_string_id(lc->video_conf.device);
2910 if (vd && strstr(vd,"Static picture")!=NULL){
2913 lp_config_set_string(lc->config,"video","device",vd);
2919 * Returns the name of the currently active video device.
2921 * @ingroup media_parameters
2923 const char *linphone_core_get_video_device(const LinphoneCore *lc){
2924 if (lc->video_conf.device) return ms_web_cam_get_string_id(lc->video_conf.device);
2929 * Returns the native window handle of the video window, casted as an unsigned long.
2931 * @ingroup media_parameters
2933 unsigned long linphone_core_get_native_video_window_id(const LinphoneCore *lc){
2934 #ifdef VIDEO_ENABLED
2935 if (lc->videostream)
2936 return video_stream_get_native_window_id(lc->videostream);
2937 if (lc->previewstream)
2938 return video_stream_get_native_window_id(lc->previewstream);
2943 static MSVideoSizeDef supported_resolutions[]={
2944 { {MS_VIDEO_SIZE_SVGA_W,MS_VIDEO_SIZE_SVGA_H} , "svga" },
2945 { {MS_VIDEO_SIZE_4CIF_W,MS_VIDEO_SIZE_4CIF_H} , "4cif" },
2946 { {MS_VIDEO_SIZE_VGA_W,MS_VIDEO_SIZE_VGA_H} , "vga" },
2947 { {MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H} , "cif" },
2948 { {MS_VIDEO_SIZE_QVGA_W,MS_VIDEO_SIZE_QVGA_H} , "qvga" },
2949 { {MS_VIDEO_SIZE_QCIF_W,MS_VIDEO_SIZE_QCIF_H} , "qcif" },
2954 * Returns the zero terminated table of supported video resolutions.
2956 * @ingroup media_parameters
2958 const MSVideoSizeDef *linphone_core_get_supported_video_sizes(LinphoneCore *lc){
2959 return supported_resolutions;
2962 static MSVideoSize video_size_get_by_name(const char *name){
2963 MSVideoSizeDef *pdef=supported_resolutions;
2964 MSVideoSize null_vsize={0,0};
2965 for(;pdef->name!=NULL;pdef++){
2966 if (strcasecmp(name,pdef->name)==0){
2970 ms_warning("Video resolution %s is not supported in linphone.",name);
2974 static const char *video_size_get_name(MSVideoSize vsize){
2975 MSVideoSizeDef *pdef=supported_resolutions;
2976 for(;pdef->name!=NULL;pdef++){
2977 if (pdef->vsize.width==vsize.width && pdef->vsize.height==vsize.height){
2984 static bool_t video_size_supported(MSVideoSize vsize){
2985 if (video_size_get_name(vsize)) return TRUE;
2986 ms_warning("Video resolution %ix%i is not supported in linphone.",vsize.width,vsize.height);
2991 * Sets the preferred video size.
2993 * @ingroup media_parameters
2994 * This applies only to the stream that is captured and sent to the remote party,
2995 * since we accept all standard video size on the receive path.
2997 void linphone_core_set_preferred_video_size(LinphoneCore *lc, MSVideoSize vsize){
2998 if (video_size_supported(vsize)){
2999 MSVideoSize oldvsize=lc->video_conf.vsize;
3000 lc->video_conf.vsize=vsize;
3001 if (!ms_video_size_equal(oldvsize,vsize) && lc->previewstream!=NULL){
3002 toggle_video_preview(lc,FALSE);
3003 toggle_video_preview(lc,TRUE);
3006 lp_config_set_string(lc->config,"video","size",video_size_get_name(vsize));
3011 * Sets the preferred video size by its name.
3013 * @ingroup media_parameters
3014 * This is identical to linphone_core_set_preferred_video_size() except
3015 * that it takes the name of the video resolution as input.
3016 * Video resolution names are: qcif, svga, cif, vga, 4cif, svga ...
3018 void linphone_core_set_preferred_video_size_by_name(LinphoneCore *lc, const char *name){
3019 MSVideoSize vsize=video_size_get_by_name(name);
3020 MSVideoSize default_vsize={MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H};
3021 if (vsize.width!=0) linphone_core_set_preferred_video_size(lc,vsize);
3022 else linphone_core_set_preferred_video_size(lc,default_vsize);
3026 * Returns the current preferred video size for sending.
3028 * @ingroup media_parameters
3030 MSVideoSize linphone_core_get_preferred_video_size(LinphoneCore *lc){
3031 return lc->video_conf.vsize;
3034 void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
3035 lc->use_files=yesno;
3038 void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
3039 if (lc->play_file!=NULL){
3040 ms_free(lc->play_file);
3044 lc->play_file=ms_strdup(file);
3045 if (lc->audiostream)
3046 audio_stream_play(lc->audiostream,file);
3050 void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
3051 if (lc->rec_file!=NULL){
3052 ms_free(lc->rec_file);
3056 lc->rec_file=ms_strdup(file);
3057 if (lc->audiostream)
3058 audio_stream_record(lc->audiostream,file);
3063 * Retrieves the user pointer that was given to linphone_core_new()
3065 * @ingroup initializing
3067 void *linphone_core_get_user_data(LinphoneCore *lc){
3071 int linphone_core_get_mtu(const LinphoneCore *lc){
3072 return lc->net_conf.mtu;
3075 void linphone_core_set_mtu(LinphoneCore *lc, int mtu){
3076 lc->net_conf.mtu=mtu;
3079 ms_error("MTU too small !");
3083 ms_message("MTU is supposed to be %i, rtp payload max size will be %i",mtu, ms_get_payload_max_size());
3084 }else ms_set_mtu(0);//use mediastreamer2 default value
3087 void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context){
3089 lc->wait_ctx=user_context;
3092 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose){
3094 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingStart,purpose,0);
3098 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progress){
3100 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingProgress,purpose,progress);
3110 void linphone_core_stop_waiting(LinphoneCore *lc){
3112 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingFinished,NULL,0);
3116 void linphone_core_set_audio_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3121 void net_config_uninit(LinphoneCore *lc)
3123 net_config_t *config=&lc->net_conf;
3124 lp_config_set_int(lc->config,"net","download_bw",config->download_bw);
3125 lp_config_set_int(lc->config,"net","upload_bw",config->upload_bw);
3127 if (config->stun_server!=NULL)
3128 lp_config_set_string(lc->config,"net","stun_server",config->stun_server);
3129 if (config->nat_address!=NULL)
3130 lp_config_set_string(lc->config,"net","nat_address",config->nat_address);
3131 lp_config_set_int(lc->config,"net","firewall_policy",config->firewall_policy);
3132 lp_config_set_int(lc->config,"net","mtu",config->mtu);
3133 if (lc->net_conf.stun_server!=NULL)
3134 ms_free(lc->net_conf.stun_server);
3138 void sip_config_uninit(LinphoneCore *lc)
3142 sip_config_t *config=&lc->sip_conf;
3143 lp_config_set_int(lc->config,"sip","sip_port",config->sip_port);
3144 lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
3145 lp_config_set_string(lc->config,"sip","contact",config->contact);
3146 lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
3147 lp_config_set_int(lc->config,"sip","use_info",config->use_info);
3148 lp_config_set_int(lc->config,"sip","use_rfc2833",config->use_rfc2833);
3149 lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
3150 lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
3152 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
3154 for(elem=config->proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3155 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
3156 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
3157 linphone_proxy_config_edit(cfg); /* to unregister */
3163 sal_iterate(lc->sal);
3172 ms_list_for_each(config->proxies,(void (*)(void*)) linphone_proxy_config_destroy);
3173 ms_list_free(config->proxies);
3174 config->proxies=NULL;
3176 linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */
3178 for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3179 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
3180 linphone_auth_info_write_config(lc->config,ai,i);
3182 linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
3183 ms_list_for_each(lc->auth_info,(void (*)(void*))linphone_auth_info_destroy);
3184 ms_list_free(lc->auth_info);
3186 sal_uninit(lc->sal);
3190 void rtp_config_uninit(LinphoneCore *lc)
3192 rtp_config_t *config=&lc->rtp_conf;
3193 lp_config_set_int(lc->config,"rtp","audio_rtp_port",config->audio_rtp_port);
3194 lp_config_set_int(lc->config,"rtp","video_rtp_port",config->video_rtp_port);
3195 lp_config_set_int(lc->config,"rtp","audio_jitt_comp",config->audio_jitt_comp);
3196 lp_config_set_int(lc->config,"rtp","video_jitt_comp",config->video_jitt_comp);
3197 lp_config_set_int(lc->config,"rtp","nortp_timeout",config->nortp_timeout);
3200 void sound_config_uninit(LinphoneCore *lc)
3202 sound_config_t *config=&lc->sound_conf;
3203 ms_free(config->cards);
3205 lp_config_set_string(lc->config,"sound","remote_ring",config->remote_ring);
3207 if (config->local_ring) ms_free(config->local_ring);
3208 if (config->remote_ring) ms_free(config->remote_ring);
3209 ms_snd_card_manager_destroy();
3212 void video_config_uninit(LinphoneCore *lc)
3214 lp_config_set_int(lc->config,"video","enabled",linphone_core_video_enabled(lc));
3215 lp_config_set_string(lc->config,"video","size",video_size_get_name(linphone_core_get_preferred_video_size(lc)));
3216 lp_config_set_int(lc->config,"video","display",lc->video_conf.display);
3217 lp_config_set_int(lc->config,"video","capture",lc->video_conf.capture);
3218 lp_config_set_int(lc->config,"video","show_local",linphone_core_video_preview_enabled(lc));
3219 lp_config_set_int(lc->config,"video","self_view",linphone_core_self_view_enabled(lc));
3222 void codecs_config_uninit(LinphoneCore *lc)
3225 codecs_config_t *config=&lc->codecs_conf;
3230 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
3231 pt=(PayloadType*)(node->data);
3232 sprintf(key,"audio_codec_%i",index);
3233 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3234 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3235 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3239 for(node=config->video_codecs;node!=NULL;node=ms_list_next(node)){
3240 pt=(PayloadType*)(node->data);
3241 sprintf(key,"video_codec_%i",index);
3242 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3243 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3244 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3245 lp_config_set_string(lc->config,key,"recv_fmtp",pt->recv_fmtp);
3250 void ui_config_uninit(LinphoneCore* lc)
3253 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_destroy);
3254 ms_list_free(lc->friends);
3260 * Returns the LpConfig object used to manage the storage (config) file.
3263 * The application can use the LpConfig object to insert its own private
3264 * sections and pairs of key=value in the configuration file.
3267 LpConfig *linphone_core_get_config(LinphoneCore *lc){
3271 static void linphone_core_uninit(LinphoneCore *lc)
3275 linphone_core_terminate_call(lc,NULL);
3282 linphone_core_iterate(lc);
3285 gstate_new_state(lc, GSTATE_POWER_SHUTDOWN, NULL);
3286 #ifdef VIDEO_ENABLED
3287 if (lc->previewstream!=NULL){
3288 video_preview_stop(lc->previewstream);
3289 lc->previewstream=NULL;
3292 /* save all config */
3293 net_config_uninit(lc);
3294 sip_config_uninit(lc);
3295 rtp_config_uninit(lc);
3296 sound_config_uninit(lc);
3297 video_config_uninit(lc);
3298 codecs_config_uninit(lc);
3299 ui_config_uninit(lc);
3300 if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
3301 lp_config_destroy(lc->config);
3302 lc->config = NULL; /* Mark the config as NULL to block further calls */
3303 sip_setup_unregister_all();
3305 linphone_core_free_payload_types();
3308 exosip_running=FALSE;
3309 gstate_new_state(lc, GSTATE_POWER_OFF, NULL);
3312 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable){
3313 ms_message("Network state is now [%s]",isReachable?"UP":"DOWN");
3314 // second get the list of available proxies
3315 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3316 for(;elem!=NULL;elem=elem->next){
3317 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3318 if (linphone_proxy_config_register_enabled(cfg) ) {
3326 lc->network_reachable=isReachable;
3329 void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) {
3330 //first disable automatic mode
3331 if (lc->auto_net_state_mon) {
3332 ms_message("Disabling automatic network state monitoring");
3333 lc->auto_net_state_mon=FALSE;
3335 set_network_reachable(lc,isReachable);
3338 * Destroys a LinphoneCore
3340 * @ingroup initializing
3342 void linphone_core_destroy(LinphoneCore *lc){
3343 linphone_core_uninit(lc);