3 Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org)
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "linphonecore.h"
25 #include <ortp/telephonyevents.h>
26 #include "mediastreamer2/mediastream.h"
27 #include "mediastreamer2/mseventqueue.h"
28 #include "mediastreamer2/msvolume.h"
29 #include "mediastreamer2/msequalizer.h"
30 #include "mediastreamer2/dtmfgen.h"
38 /*#define UNSTANDART_GSM_11K 1*/
40 static const char *liblinphone_version=LIBLINPHONE_VERSION;
41 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable);
45 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result);
46 static void toggle_video_preview(LinphoneCore *lc, bool_t val);
48 /* relative path where is stored local ring*/
49 #define LOCAL_RING "rings/oldphone.wav"
50 /* same for remote ring (ringback)*/
51 #define REMOTE_RING "ringback.wav"
53 extern SalCallbacks linphone_sal_callbacks;
55 void lc_callback_obj_init(LCCallbackObj *obj,LinphoneCoreCbFunc func,void* ud)
61 int lc_callback_obj_invoke(LCCallbackObj *obj, LinphoneCore *lc){
62 if (obj->_func!=NULL) obj->_func(lc,obj->_user_data);
67 /*prevent a gcc bug with %c*/
68 static size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm){
69 #if !defined(_WIN32_WCE)
70 return strftime(s, max, fmt, tm);
77 static void set_call_log_date(LinphoneCallLog *cl, const struct tm *loctime){
78 my_strftime(cl->start_date,sizeof(cl->start_date),"%c",loctime);
81 LinphoneCallLog * linphone_call_log_new(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
82 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
86 #if !defined(_WIN32_WCE)
87 loctime=*localtime(&call->start_time);
91 localtime_r(&call->start_time,&loctime);
93 set_call_log_date(cl,&loctime);
99 static void call_logs_write_to_config_file(LinphoneCore *lc){
104 LpConfig *cfg=lc->config;
106 if (!lc->ready) return;
108 for(i=0,elem=lc->call_logs;elem!=NULL;elem=elem->next,++i){
109 LinphoneCallLog *cl=(LinphoneCallLog*)elem->data;
110 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
111 lp_config_set_int(cfg,logsection,"dir",cl->dir);
112 lp_config_set_int(cfg,logsection,"status",cl->status);
113 tmp=linphone_address_as_string(cl->from);
114 lp_config_set_string(cfg,logsection,"from",tmp);
116 tmp=linphone_address_as_string(cl->to);
117 lp_config_set_string(cfg,logsection,"to",tmp);
119 lp_config_set_string(cfg,logsection,"start_date",cl->start_date);
120 lp_config_set_int(cfg,logsection,"duration",cl->duration);
121 if (cl->refkey) lp_config_set_string(cfg,logsection,"refkey",cl->refkey);
123 for(;i<lc->max_call_logs;++i){
124 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
125 lp_config_clean_section(cfg,logsection);
129 static void call_logs_read_from_config_file(LinphoneCore *lc){
133 LpConfig *cfg=lc->config;
135 snprintf(logsection,sizeof(logsection),"call_log_%i",i);
136 if (lp_config_has_section(cfg,logsection)){
137 LinphoneCallLog *cl=ms_new0(LinphoneCallLog,1);
138 cl->dir=lp_config_get_int(cfg,logsection,"dir",0);
139 cl->status=lp_config_get_int(cfg,logsection,"status",0);
140 tmp=lp_config_get_string(cfg,logsection,"from",NULL);
141 if (tmp) cl->from=linphone_address_new(tmp);
142 tmp=lp_config_get_string(cfg,logsection,"to",NULL);
143 if (tmp) cl->to=linphone_address_new(tmp);
144 tmp=lp_config_get_string(cfg,logsection,"start_date",NULL);
145 if (tmp) strncpy(cl->start_date,tmp,sizeof(cl->start_date));
146 cl->duration=lp_config_get_int(cfg,logsection,"duration",0);
147 tmp=lp_config_get_string(cfg,logsection,"refkey",NULL);
148 if (tmp) cl->refkey=ms_strdup(tmp);
149 lc->call_logs=ms_list_append(lc->call_logs,cl);
155 void linphone_call_log_completed(LinphoneCallLog *calllog, LinphoneCall *call, LinphoneCallStatus status){
156 LinphoneCore *lc=call->core;
158 calllog->duration=time(NULL)-call->start_time;
160 if (status==LinphoneCallMissed){
163 info=ortp_strdup_printf(ngettext("You have missed %i call.",
164 "You have missed %i calls.", lc->missed_calls),
166 if (lc->vtable.display_status!=NULL)
167 lc->vtable.display_status(lc,info);
169 }else calllog->status=status;
170 lc->call_logs=ms_list_prepend(lc->call_logs,(void *)calllog);
171 if (ms_list_size(lc->call_logs)>lc->max_call_logs){
172 MSList *elem,*prevelem=NULL;
173 /*find the last element*/
174 for(elem=lc->call_logs;elem!=NULL;elem=elem->next){
178 linphone_call_log_destroy((LinphoneCallLog*)elem->data);
179 lc->call_logs=ms_list_remove_link(lc->call_logs,elem);
181 if (lc->vtable.call_log_updated!=NULL){
182 lc->vtable.call_log_updated(lc,calllog);
184 call_logs_write_to_config_file(lc);
188 * @addtogroup call_logs
193 * Returns a human readable string describing the call.
195 * @note: the returned char* must be freed by the application (use ms_free()).
197 char * linphone_call_log_to_str(LinphoneCallLog *cl){
200 char *from=linphone_address_as_string (cl->from);
201 char *to=linphone_address_as_string (cl->to);
203 case LinphoneCallAborted:
206 case LinphoneCallSuccess:
207 status=_("completed");
209 case LinphoneCallMissed:
215 tmp=ortp_strdup_printf(_("%s at %s\nFrom: %s\nTo: %s\nStatus: %s\nDuration: %i mn %i sec\n"),
216 (cl->dir==LinphoneCallIncoming) ? _("Incoming call") : _("Outgoing call"),
229 * Returns RTP statistics computed locally regarding the call.
232 const rtp_stats_t *linphone_call_log_get_local_stats(const LinphoneCallLog *cl){
233 return &cl->local_stats;
237 * Returns RTP statistics computed by remote end and sent back via RTCP.
239 * @note Not implemented yet.
241 const rtp_stats_t *linphone_call_log_get_remote_stats(const LinphoneCallLog *cl){
242 return &cl->remote_stats;
245 void linphone_call_log_set_user_pointer(LinphoneCallLog *cl, void *up){
249 void *linphone_call_log_get_user_pointer(const LinphoneCallLog *cl){
250 return cl->user_pointer;
256 * Associate a persistent reference key to the call log.
258 * The reference key can be for example an id to an external database.
259 * It is stored in the config file, thus can survive to process exits/restarts.
262 void linphone_call_log_set_ref_key(LinphoneCallLog *cl, const char *refkey){
263 if (cl->refkey!=NULL){
267 if (refkey) cl->refkey=ms_strdup(refkey);
268 call_logs_write_to_config_file(cl->lc);
272 * Get the persistent reference key associated to the call log.
274 * The reference key can be for example an id to an external database.
275 * It is stored in the config file, thus can survive to process exits/restarts.
278 const char *linphone_call_log_get_ref_key(const LinphoneCallLog *cl){
284 void linphone_call_log_destroy(LinphoneCallLog *cl){
285 if (cl->from!=NULL) linphone_address_destroy(cl->from);
286 if (cl->to!=NULL) linphone_address_destroy(cl->to);
287 if (cl->refkey!=NULL) ms_free(cl->refkey);
292 * Returns TRUE if the LinphoneCall asked to autoanswer
295 bool_t linphone_call_asked_to_autoanswer(LinphoneCall *call){
296 //return TRUE if the unique(for the moment) incoming call asked to be autoanswered
298 return sal_call_autoanswer_asked(call->op);
303 int linphone_core_get_call_duration(LinphoneCall *call){
304 if (call==NULL) return 0;
305 if (call->media_start_time==0) return 0;
306 return time(NULL)-call->media_start_time;
309 int linphone_core_get_current_call_duration(const LinphoneCore *lc){
310 LinphoneCall *call=linphone_core_get_current_call((LinphoneCore *)lc);
311 return linphone_core_get_call_duration(call);
314 const LinphoneAddress *linphone_core_get_current_call_remote_address(struct _LinphoneCore *lc){
315 LinphoneCall *call=linphone_core_get_current_call(lc);
316 if (call==NULL) return NULL;
317 return linphone_call_get_remote_address(call);
321 * Enable logs in supplied FILE*.
325 * @param file a C FILE* where to fprintf logs. If null stdout is used.
328 void linphone_core_enable_logs(FILE *file){
329 if (file==NULL) file=stdout;
330 ortp_set_log_file(file);
331 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
335 * Enable logs through the user's supplied log callback.
339 * @param logfunc The address of a OrtpLogFunc callback whose protoype is
340 * typedef void (*OrtpLogFunc)(OrtpLogLevel lev, const char *fmt, va_list args);
343 void linphone_core_enable_logs_with_cb(OrtpLogFunc logfunc){
344 ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
345 ortp_set_log_handler(logfunc);
349 * Entirely disable logging.
353 void linphone_core_disable_logs(){
354 ortp_set_log_level_mask(ORTP_ERROR|ORTP_FATAL);
359 net_config_read (LinphoneCore *lc)
363 LpConfig *config=lc->config;
365 tmp=lp_config_get_int(config,"net","download_bw",0);
366 linphone_core_set_download_bandwidth(lc,tmp);
367 tmp=lp_config_get_int(config,"net","upload_bw",0);
368 linphone_core_set_upload_bandwidth(lc,tmp);
369 linphone_core_set_stun_server(lc,lp_config_get_string(config,"net","stun_server",NULL));
370 tmpstr=lp_config_get_string(lc->config,"net","nat_address",NULL);
371 if (tmpstr!=NULL && (strlen(tmpstr)<1)) tmpstr=NULL;
372 linphone_core_set_nat_address(lc,tmpstr);
373 tmp=lp_config_get_int(lc->config,"net","firewall_policy",0);
374 linphone_core_set_firewall_policy(lc,tmp);
375 tmp=lp_config_get_int(lc->config,"net","nat_sdp_only",0);
376 lc->net_conf.nat_sdp_only=tmp;
377 tmp=lp_config_get_int(lc->config,"net","mtu",0);
378 linphone_core_set_mtu(lc,tmp);
379 tmp=lp_config_get_int(lc->config,"net","download_ptime",0);
380 linphone_core_set_download_ptime(lc,tmp);
384 static void build_sound_devices_table(LinphoneCore *lc){
385 const char **devices;
389 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
390 ndev=ms_list_size(elem);
391 devices=ms_malloc((ndev+1)*sizeof(const char *));
392 for (i=0;elem!=NULL;elem=elem->next,i++){
393 devices[i]=ms_snd_card_get_string_id((MSSndCard *)elem->data);
396 old=lc->sound_conf.cards;
397 lc->sound_conf.cards=devices;
398 if (old!=NULL) ms_free(old);
401 static void sound_config_read(LinphoneCore *lc)
408 /*alsadev let the user use custom alsa device within linphone*/
409 devid=lp_config_get_string(lc->config,"sound","alsadev",NULL);
411 MSSndCard *card=ms_alsa_card_new_custom(devid,devid);
412 ms_snd_card_manager_add_card(ms_snd_card_manager_get(),card);
415 /* retrieve all sound devices */
416 build_sound_devices_table(lc);
418 devid=lp_config_get_string(lc->config,"sound","playback_dev_id",NULL);
419 linphone_core_set_playback_device(lc,devid);
421 devid=lp_config_get_string(lc->config,"sound","ringer_dev_id",NULL);
422 linphone_core_set_ringer_device(lc,devid);
424 devid=lp_config_get_string(lc->config,"sound","capture_dev_id",NULL);
425 linphone_core_set_capture_device(lc,devid);
428 tmp=lp_config_get_int(lc->config,"sound","play_lev",80);
429 linphone_core_set_play_level(lc,tmp);
430 tmp=lp_config_get_int(lc->config,"sound","ring_lev",80);
431 linphone_core_set_ring_level(lc,tmp);
432 tmp=lp_config_get_int(lc->config,"sound","rec_lev",80);
433 linphone_core_set_rec_level(lc,tmp);
434 tmpbuf=lp_config_get_string(lc->config,"sound","source","m");
435 linphone_core_set_sound_source(lc,tmpbuf[0]);
438 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
439 tmpbuf=lp_config_get_string(lc->config,"sound","local_ring",tmpbuf);
440 if (ortp_file_exist(tmpbuf)==-1) {
441 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
443 if (strstr(tmpbuf,".wav")==NULL){
444 /* it currently uses old sound files, so replace them */
445 tmpbuf=PACKAGE_SOUND_DIR "/" LOCAL_RING;
448 linphone_core_set_ring(lc,tmpbuf);
450 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
451 tmpbuf=lp_config_get_string(lc->config,"sound","remote_ring",tmpbuf);
452 if (ortp_file_exist(tmpbuf)==-1){
453 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
455 if (strstr(tmpbuf,".wav")==NULL){
456 /* it currently uses old sound files, so replace them */
457 tmpbuf=PACKAGE_SOUND_DIR "/" REMOTE_RING;
459 linphone_core_set_ringback(lc,tmpbuf);
460 check_sound_device(lc);
461 lc->sound_conf.latency=0;
463 linphone_core_enable_echo_cancellation(lc,
464 lp_config_get_int(lc->config,"sound","echocancelation",0) |
465 lp_config_get_int(lc->config,"sound","echocancellation",0)
468 linphone_core_enable_echo_limiter(lc,
469 lp_config_get_int(lc->config,"sound","echolimiter",0));
470 linphone_core_enable_agc(lc,
471 lp_config_get_int(lc->config,"sound","agc",0));
473 gain=lp_config_get_float(lc->config,"sound","playback_gain_db",0);
474 linphone_core_set_playback_gain_db (lc,gain);
477 static void sip_config_read(LinphoneCore *lc)
485 tmp=lp_config_get_int(lc->config,"sip","use_info",0);
486 linphone_core_set_use_info_for_dtmf(lc,tmp);
488 if (lp_config_get_int(lc->config,"sip","use_session_timers",0)==1){
489 sal_use_session_timers(lc->sal,200);
493 tmp=lp_config_get_int(lc->config,"sip","use_rfc2833",0);
494 linphone_core_set_use_rfc2833_for_dtmf(lc,tmp);
496 ipv6=lp_config_get_int(lc->config,"sip","use_ipv6",-1);
499 if (host_has_ipv6_network()){
500 if (lc->vtable.display_message)
501 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"));
504 linphone_core_enable_ipv6(lc,ipv6);
505 memset(&tr,0,sizeof(tr));
506 if (lp_config_get_int(lc->config,"sip","sip_random_port",0)) {
507 tr.udp_port=(0xDFF&+random())+1024;
509 tr.udp_port=lp_config_get_int(lc->config,"sip","sip_port",5060);
511 if (lp_config_get_int(lc->config,"sip","sip_tcp_random_port",0)) {
512 tr.tcp_port=(0xDFF&+random())+1024;
514 tr.tcp_port=lp_config_get_int(lc->config,"sip","sip_tcp_port",0);
516 /*start listening on ports*/
517 linphone_core_set_sip_transports(lc,&tr);
519 tmpstr=lp_config_get_string(lc->config,"sip","contact",NULL);
520 if (tmpstr==NULL || linphone_core_set_primary_contact(lc,tmpstr)==-1) {
521 const char *hostname=NULL;
522 const char *username=NULL;
524 hostname=getenv("HOST");
525 username=getenv("USER");
526 if (hostname==NULL) hostname=getenv("HOSTNAME");
527 #endif /*HAVE_GETENV*/
529 hostname="unknown-host";
533 contact=ortp_strdup_printf("sip:%s@%s",username,hostname);
534 linphone_core_set_primary_contact(lc,contact);
538 tmp=lp_config_get_int(lc->config,"sip","guess_hostname",1);
539 linphone_core_set_guess_hostname(lc,tmp);
542 tmp=lp_config_get_int(lc->config,"sip","inc_timeout",15);
543 linphone_core_set_inc_timeout(lc,tmp);
545 /* get proxies config */
547 LinphoneProxyConfig *cfg=linphone_proxy_config_new_from_config_file(lc->config,i);
549 linphone_core_add_proxy_config(lc,cfg);
554 /* get the default proxy */
555 tmp=lp_config_get_int(lc->config,"sip","default_proxy",-1);
556 linphone_core_set_default_proxy_index(lc,tmp);
558 /* read authentication information */
560 LinphoneAuthInfo *ai=linphone_auth_info_new_from_config_file(lc->config,i);
562 linphone_core_add_auth_info(lc,ai);
563 linphone_auth_info_destroy(ai);
572 lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
574 /*for tuning or test*/
575 lc->sip_conf.sdp_200_ack=lp_config_get_int(lc->config,"sip","sdp_200_ack",0);
576 lc->sip_conf.only_one_codec=lp_config_get_int(lc->config,"sip","only_one_codec",0);
577 lc->sip_conf.register_only_when_network_is_up=
578 lp_config_get_int(lc->config,"sip","register_only_when_network_is_up",1);
579 lc->sip_conf.ping_with_options=lp_config_get_int(lc->config,"sip","ping_with_options",1);
580 lc->sip_conf.auto_net_state_mon=lp_config_get_int(lc->config,"sip","auto_net_state_mon",1);
581 lc->sip_conf.keepalive_period=lp_config_get_int(lc->config,"sip","keepalive_period",10000);
582 sal_set_keepalive_period(lc->sal,lc->sip_conf.keepalive_period);
585 static void rtp_config_read(LinphoneCore *lc)
590 bool_t rtp_no_xmit_on_audio_mute;
592 port=lp_config_get_int(lc->config,"rtp","audio_rtp_port",7078);
593 linphone_core_set_audio_port(lc,port);
595 port=lp_config_get_int(lc->config,"rtp","video_rtp_port",9078);
596 if (port==0) port=9078;
597 linphone_core_set_video_port(lc,port);
599 jitt_comp=lp_config_get_int(lc->config,"rtp","audio_jitt_comp",60);
600 linphone_core_set_audio_jittcomp(lc,jitt_comp);
601 jitt_comp=lp_config_get_int(lc->config,"rtp","video_jitt_comp",60);
602 nortp_timeout=lp_config_get_int(lc->config,"rtp","nortp_timeout",30);
603 linphone_core_set_nortp_timeout(lc,nortp_timeout);
604 rtp_no_xmit_on_audio_mute=lp_config_get_int(lc->config,"rtp","rtp_no_xmit_on_audio_mute",FALSE);
605 linphone_core_set_rtp_no_xmit_on_audio_mute(lc,rtp_no_xmit_on_audio_mute);
608 static PayloadType * find_payload(RtpProfile *prof, const char *mime_type, int clock_rate, const char *recv_fmtp){
609 PayloadType *candidate=NULL;
613 it=rtp_profile_get_payload(prof,i);
614 if (it!=NULL && strcasecmp(mime_type,it->mime_type)==0
615 && (clock_rate==it->clock_rate || clock_rate<=0) ){
616 if ( (recv_fmtp && it->recv_fmtp && strstr(recv_fmtp,it->recv_fmtp)!=NULL) ||
617 (recv_fmtp==NULL && it->recv_fmtp==NULL) ){
619 if (recv_fmtp) payload_type_set_recv_fmtp(it,recv_fmtp);
623 if (it->recv_fmtp==NULL) candidate=it;
628 if (candidate && recv_fmtp){
629 payload_type_set_recv_fmtp(candidate,recv_fmtp);
634 static bool_t get_codec(LpConfig *config, char* type, int index, PayloadType **ret){
636 const char *mime,*fmtp;
641 snprintf(codeckey,50,"%s_%i",type,index);
642 mime=lp_config_get_string(config,codeckey,"mime",NULL);
643 if (mime==NULL || strlen(mime)==0 ) return FALSE;
645 rate=lp_config_get_int(config,codeckey,"rate",8000);
646 fmtp=lp_config_get_string(config,codeckey,"recv_fmtp",NULL);
647 enabled=lp_config_get_int(config,codeckey,"enabled",1);
648 pt=find_payload(&av_profile,mime,rate,fmtp);
649 if (pt && enabled ) pt->flags|=PAYLOAD_TYPE_ENABLED;
650 //ms_message("Found codec %s/%i",pt->mime_type,pt->clock_rate);
651 if (pt==NULL) ms_warning("Ignoring codec config %s/%i with fmtp=%s because unsupported",
652 mime,rate,fmtp ? fmtp : "");
657 static const char *codec_pref_order[]={
670 static int find_codec_rank(const char *mime){
672 for(i=0;codec_pref_order[i]!=NULL;++i){
673 if (strcasecmp(codec_pref_order[i],mime)==0)
679 static int codec_compare(const PayloadType *a, const PayloadType *b){
681 ra=find_codec_rank(a->mime_type);
682 rb=find_codec_rank(b->mime_type);
684 if (ra<rb) return -1;
688 static MSList *add_missing_codecs(SalStreamType mtype, MSList *l){
691 PayloadType *pt=rtp_profile_get_payload(&av_profile,i);
693 if (mtype==SalVideo && pt->type!=PAYLOAD_VIDEO)
695 else if (mtype==SalAudio && (pt->type!=PAYLOAD_AUDIO_PACKETIZED
696 && pt->type!=PAYLOAD_AUDIO_CONTINUOUS)){
699 if (pt && ms_filter_codec_supported(pt->mime_type)){
700 if (ms_list_find(l,pt)==NULL){
701 payload_type_set_flag(pt,PAYLOAD_TYPE_ENABLED);
702 ms_message("Adding new codec %s/%i with fmtp %s",
703 pt->mime_type,pt->clock_rate,pt->recv_fmtp ? pt->recv_fmtp : "");
704 l=ms_list_insert_sorted(l,pt,(int (*)(const void *, const void *))codec_compare);
712 static void codecs_config_read(LinphoneCore *lc)
716 MSList *audio_codecs=NULL;
717 MSList *video_codecs=NULL;
718 for (i=0;get_codec(lc->config,"audio_codec",i,&pt);i++){
720 if (!ms_filter_codec_supported(pt->mime_type)){
721 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
722 }else audio_codecs=ms_list_append(audio_codecs,pt);
725 audio_codecs=add_missing_codecs(SalAudio,audio_codecs);
726 for (i=0;get_codec(lc->config,"video_codec",i,&pt);i++){
728 if (!ms_filter_codec_supported(pt->mime_type)){
729 ms_warning("Codec %s is not supported by mediastreamer2, removed.",pt->mime_type);
730 }else video_codecs=ms_list_append(video_codecs,(void *)pt);
733 video_codecs=add_missing_codecs(SalVideo,video_codecs);
734 linphone_core_set_audio_codecs(lc,audio_codecs);
735 linphone_core_set_video_codecs(lc,video_codecs);
736 linphone_core_update_allocated_audio_bandwidth(lc);
739 static void video_config_read(LinphoneCore *lc){
740 int capture, display, self_view;
744 const char **devices;
748 /* retrieve all video devices */
749 elem=ms_web_cam_manager_get_list(ms_web_cam_manager_get());
750 ndev=ms_list_size(elem);
751 devices=ms_malloc((ndev+1)*sizeof(const char *));
752 for (i=0;elem!=NULL;elem=elem->next,i++){
753 devices[i]=ms_web_cam_get_string_id((MSWebCam *)elem->data);
756 lc->video_conf.cams=devices;
758 str=lp_config_get_string(lc->config,"video","device",NULL);
759 if (str && str[0]==0) str=NULL;
760 linphone_core_set_video_device(lc,str);
762 linphone_core_set_preferred_video_size_by_name(lc,
763 lp_config_get_string(lc->config,"video","size","cif"));
765 enabled=lp_config_get_int(lc->config,"video","enabled",1);
766 capture=lp_config_get_int(lc->config,"video","capture",enabled);
767 display=lp_config_get_int(lc->config,"video","display",enabled);
768 self_view=lp_config_get_int(lc->config,"video","self_view",enabled);
770 linphone_core_enable_video(lc,capture,display);
771 linphone_core_enable_self_view(lc,self_view);
775 static void ui_config_read(LinphoneCore *lc)
779 for (i=0;(lf=linphone_friend_new_from_config_file(lc,i))!=NULL;i++){
780 linphone_core_add_friend(lc,lf);
782 call_logs_read_from_config_file(lc);
786 static void autoreplier_config_init(LinphoneCore *lc)
788 autoreplier_config_t *config=&lc->autoreplier_conf;
789 config->enabled=lp_config_get_int(lc->config,"autoreplier","enabled",0);
790 config->after_seconds=lp_config_get_int(lc->config,"autoreplier","after_seconds",6);
791 config->max_users=lp_config_get_int(lc->config,"autoreplier","max_users",1);
792 config->max_rec_time=lp_config_get_int(lc->config,"autoreplier","max_rec_time",60);
793 config->max_rec_msg=lp_config_get_int(lc->config,"autoreplier","max_rec_msg",10);
794 config->message=lp_config_get_string(lc->config,"autoreplier","message",NULL);
799 * Sets maximum available download bandwidth
801 * @ingroup media_parameters
803 * This is IP bandwidth, in kbit/s.
804 * This information is used signaled to other parties during
805 * calls (within SDP messages) so that the remote end can have
806 * sufficient knowledge to properly configure its audio & video
807 * codec output bitrate to not overflow available bandwidth.
809 * @param lc the LinphoneCore object
810 * @param bw the bandwidth in kbits/s, 0 for infinite
812 void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){
813 lc->net_conf.download_bw=bw;
814 if (bw==0){ /*infinite*/
818 lc->dw_audio_bw=MIN(lc->audio_bw,bw);
819 lc->dw_video_bw=MAX(bw-lc->dw_audio_bw-10,0);/*-10: security margin*/
824 * Sets maximum available upload bandwidth
826 * @ingroup media_parameters
828 * This is IP bandwidth, in kbit/s.
829 * This information is used by liblinphone together with remote
830 * side available bandwidth signaled in SDP messages to properly
831 * configure audio & video codec's output bitrate.
833 * @param lc the LinphoneCore object
834 * @param bw the bandwidth in kbits/s, 0 for infinite
836 void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){
837 lc->net_conf.upload_bw=bw;
838 if (bw==0){ /*infinite*/
842 lc->up_audio_bw=MIN(lc->audio_bw,bw);
843 lc->up_video_bw=MAX(bw-lc->up_audio_bw-10,0);/*-10: security margin*/
848 * Retrieve the maximum available download bandwidth.
850 * @ingroup media_parameters
852 * This value was set by linphone_core_set_download_bandwidth().
855 int linphone_core_get_download_bandwidth(const LinphoneCore *lc){
856 return lc->net_conf.download_bw;
860 * Retrieve the maximum available upload bandwidth.
862 * @ingroup media_parameters
864 * This value was set by linphone_core_set_upload_bandwidth().
867 int linphone_core_get_upload_bandwidth(const LinphoneCore *lc){
868 return lc->net_conf.upload_bw;
871 * set audio packetization time linphone expect to received from peer
873 void linphone_core_set_download_ptime(LinphoneCore *lc, int ptime) {
874 lc->net_conf.down_ptime=ptime;
877 int linphone_core_get_download_ptime(LinphoneCore *lc) {
878 return lc->net_conf.down_ptime;
883 * Returns liblinphone's version as a string.
888 const char * linphone_core_get_version(void){
889 return liblinphone_version;
893 static MSList *linphone_payload_types=NULL;
895 static void linphone_core_assign_payload_type(PayloadType *const_pt, int number, const char *recv_fmtp){
897 pt=payload_type_clone(const_pt);
898 payload_type_set_number(pt,number);
899 if (recv_fmtp!=NULL) payload_type_set_recv_fmtp(pt,recv_fmtp);
900 rtp_profile_set_payload(&av_profile,number,pt);
901 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
904 static void linphone_core_free_payload_types(void){
905 ms_list_for_each(linphone_payload_types,(void (*)(void*))payload_type_destroy);
906 ms_list_free(linphone_payload_types);
907 linphone_payload_types=NULL;
910 void linphone_core_set_state(LinphoneCore *lc, LinphoneGlobalState gstate, const char *message){
911 if (lc->vtable.global_state_changed){
912 lc->vtable.global_state_changed(lc,gstate,message);
916 static void linphone_core_init (LinphoneCore * lc, const LinphoneCoreVTable *vtable, const char *config_path,
917 const char *factory_config_path, void * userdata)
919 memset (lc, 0, sizeof (LinphoneCore));
922 memcpy(&lc->vtable,vtable,sizeof(LinphoneCoreVTable));
924 linphone_core_set_state(lc,LinphoneGlobalStartup,"Starting up");
926 linphone_core_assign_payload_type(&payload_type_pcmu8000,0,NULL);
927 linphone_core_assign_payload_type(&payload_type_gsm,3,NULL);
928 linphone_core_assign_payload_type(&payload_type_pcma8000,8,NULL);
929 linphone_core_assign_payload_type(&payload_type_lpc1015,115,NULL);
930 linphone_core_assign_payload_type(&payload_type_speex_nb,110,"vbr=on");
931 linphone_core_assign_payload_type(&payload_type_speex_wb,111,"vbr=on");
932 linphone_core_assign_payload_type(&payload_type_speex_uwb,112,"vbr=on");
933 linphone_core_assign_payload_type(&payload_type_telephone_event,101,"0-11");
934 linphone_core_assign_payload_type(&payload_type_ilbc,113,"mode=30");
935 linphone_core_assign_payload_type(&payload_type_amr,114,"octet-align=1");
937 #ifdef ENABLE_NONSTANDARD_GSM
940 pt=payload_type_clone(&payload_type_gsm);
941 pt->clock_rate=11025;
942 rtp_profile_set_payload(&av_profile,114,pt);
943 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
944 pt=payload_type_clone(&payload_type_gsm);
945 pt->clock_rate=22050;
946 rtp_profile_set_payload(&av_profile,115,pt);
947 linphone_payload_types=ms_list_append(linphone_payload_types,pt);
952 linphone_core_assign_payload_type(&payload_type_h263,34,NULL);
953 linphone_core_assign_payload_type(&payload_type_theora,97,NULL);
954 linphone_core_assign_payload_type(&payload_type_h263_1998,98,"CIF=1;QCIF=1");
955 linphone_core_assign_payload_type(&payload_type_mp4v,99,"profile-level-id=3");
956 linphone_core_assign_payload_type(&payload_type_x_snow,100,NULL);
957 linphone_core_assign_payload_type(&payload_type_h264,102,NULL);
958 linphone_core_assign_payload_type(&payload_type_h264,103,"packetization-mode=1");
962 /* create a mediastreamer2 event queue and set it as global */
963 /* This allows to run event's callback in linphone_core_iterate() */
964 lc->msevq=ms_event_queue_new();
965 ms_set_global_event_queue(lc->msevq);
967 lc->config=lp_config_new(config_path);
968 if (factory_config_path)
969 lp_config_read_file(lc->config,factory_config_path);
972 sal_set_user_pointer(lc->sal,lc);
973 sal_set_callbacks(lc->sal,&linphone_sal_callbacks);
975 sip_setup_register_all();
976 sound_config_read(lc);
979 codecs_config_read(lc);
980 sip_config_read(lc); /* this will start eXosip*/
981 video_config_read(lc);
982 //autoreplier_config_init(&lc->autoreplier_conf);
983 lc->presence_mode=LinphoneStatusOnline;
984 lc->max_call_logs=15;
986 if (lc->vtable.display_status)
987 lc->vtable.display_status(lc,_("Ready"));
988 linphone_core_set_state(lc,LinphoneGlobalOn,"Ready");
989 lc->auto_net_state_mon=lc->sip_conf.auto_net_state_mon;
995 * Instanciates a LinphoneCore object.
996 * @ingroup initializing
998 * The LinphoneCore object is the primary handle for doing all phone actions.
999 * It should be unique within your application.
1000 * @param vtable a LinphoneCoreVTable structure holding your application callbacks
1001 * @param config_path a path to a config file. If it does not exists it will be created.
1002 * The config file is used to store all user settings, call logs, friends, proxies...
1003 * @param factory_config_path a path to a read-only config file that can be used to
1004 * to store hard-coded preference such as proxy settings or internal preferences.
1005 * The settings in this factory file always override the one in the normal config file.
1006 * It is OPTIONAL, use NULL if unneeded.
1007 * @param userdata an opaque user pointer that can be retrieved at any time (for example in
1008 * callbacks) using linphone_core_get_user_data().
1011 LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable,
1012 const char *config_path, const char *factory_config_path, void * userdata)
1014 LinphoneCore *core=ms_new(LinphoneCore,1);
1015 linphone_core_init(core,vtable,config_path, factory_config_path, userdata);
1020 * Returns the list of available audio codecs.
1022 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1023 * structure holding the codec information.
1024 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1025 * (such as the order of codecs).
1027 const MSList *linphone_core_get_audio_codecs(const LinphoneCore *lc)
1029 return lc->codecs_conf.audio_codecs;
1033 * Returns the list of available video codecs.
1035 * This list is unmodifiable. The ->data field of the MSList points a PayloadType
1036 * structure holding the codec information.
1037 * It is possible to make copy of the list with ms_list_copy() in order to modify it
1038 * (such as the order of codecs).
1040 const MSList *linphone_core_get_video_codecs(const LinphoneCore *lc)
1042 return lc->codecs_conf.video_codecs;
1046 * Sets the local "from" identity.
1049 * This data is used in absence of any proxy configuration or when no
1050 * default proxy configuration is set. See LinphoneProxyConfig
1052 int linphone_core_set_primary_contact(LinphoneCore *lc, const char *contact)
1054 LinphoneAddress *ctt;
1056 if ((ctt=linphone_address_new(contact))==0) {
1057 ms_error("Bad contact url: %s",contact);
1060 if (lc->sip_conf.contact!=NULL) ms_free(lc->sip_conf.contact);
1061 lc->sip_conf.contact=ms_strdup(contact);
1062 if (lc->sip_conf.guessed_contact!=NULL){
1063 ms_free(lc->sip_conf.guessed_contact);
1064 lc->sip_conf.guessed_contact=NULL;
1066 linphone_address_destroy(ctt);
1071 /*result must be an array of chars at least LINPHONE_IPADDR_SIZE */
1072 void linphone_core_get_local_ip(LinphoneCore *lc, const char *dest, char *result){
1073 if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress
1074 && linphone_core_get_nat_address(lc)!=NULL){
1075 strncpy(result,linphone_core_get_nat_address(lc),LINPHONE_IPADDR_SIZE);
1078 if (linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,dest,result)==0)
1080 /*else fallback to SAL routine that will attempt to find the most realistic interface */
1081 sal_get_default_local_ip(lc->sal,lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,result,LINPHONE_IPADDR_SIZE);
1084 static void update_primary_contact(LinphoneCore *lc){
1086 char tmp[LINPHONE_IPADDR_SIZE];
1088 LinphoneAddress *url;
1089 if (lc->sip_conf.guessed_contact!=NULL){
1090 ms_free(lc->sip_conf.guessed_contact);
1091 lc->sip_conf.guessed_contact=NULL;
1093 url=linphone_address_new(lc->sip_conf.contact);
1095 ms_error("Could not parse identity contact !");
1096 url=linphone_address_new("sip:unknown@unkwownhost");
1098 linphone_core_get_local_ip(lc, NULL, tmp);
1099 if (strcmp(tmp,"127.0.0.1")==0 || strcmp(tmp,"::1")==0 ){
1100 ms_warning("Local loopback network only !");
1101 lc->sip_conf.loopback_only=TRUE;
1102 }else lc->sip_conf.loopback_only=FALSE;
1103 linphone_address_set_domain(url,tmp);
1104 linphone_address_set_port_int(url,linphone_core_get_sip_port (lc));
1105 guessed=linphone_address_as_string(url);
1106 lc->sip_conf.guessed_contact=guessed;
1107 linphone_address_destroy(url);
1111 * Returns the default identity when no proxy configuration is used.
1115 const char *linphone_core_get_primary_contact(LinphoneCore *lc){
1118 if (lc->sip_conf.guess_hostname){
1119 if (lc->sip_conf.guessed_contact==NULL || lc->sip_conf.loopback_only){
1120 update_primary_contact(lc);
1122 identity=lc->sip_conf.guessed_contact;
1124 identity=lc->sip_conf.contact;
1130 * Tells LinphoneCore to guess local hostname automatically in primary contact.
1134 void linphone_core_set_guess_hostname(LinphoneCore *lc, bool_t val){
1135 lc->sip_conf.guess_hostname=val;
1139 * Returns TRUE if hostname part of primary contact is guessed automatically.
1143 bool_t linphone_core_get_guess_hostname(LinphoneCore *lc){
1144 return lc->sip_conf.guess_hostname;
1148 * Same as linphone_core_get_primary_contact() but the result is a LinphoneAddress object
1149 * instead of const char*
1153 LinphoneAddress *linphone_core_get_primary_contact_parsed(LinphoneCore *lc){
1154 return linphone_address_new(linphone_core_get_primary_contact(lc));
1158 * Sets the list of audio codecs.
1160 * @ingroup media_parameters
1161 * The list is taken by the LinphoneCore thus the application should not free it.
1162 * This list is made of struct PayloadType describing the codec parameters.
1164 int linphone_core_set_audio_codecs(LinphoneCore *lc, MSList *codecs)
1166 if (lc->codecs_conf.audio_codecs!=NULL) ms_list_free(lc->codecs_conf.audio_codecs);
1167 lc->codecs_conf.audio_codecs=codecs;
1172 * Sets the list of video codecs.
1174 * @ingroup media_parameters
1175 * The list is taken by the LinphoneCore thus the application should not free it.
1176 * This list is made of struct PayloadType describing the codec parameters.
1178 int linphone_core_set_video_codecs(LinphoneCore *lc, MSList *codecs)
1180 if (lc->codecs_conf.video_codecs!=NULL) ms_list_free(lc->codecs_conf.video_codecs);
1181 lc->codecs_conf.video_codecs=codecs;
1185 const MSList * linphone_core_get_friend_list(const LinphoneCore *lc)
1191 * Returns the nominal jitter buffer size in milliseconds.
1193 * @ingroup media_parameters
1195 int linphone_core_get_audio_jittcomp(LinphoneCore *lc)
1197 return lc->rtp_conf.audio_jitt_comp;
1201 * Returns the UDP port used for audio streaming.
1203 * @ingroup network_parameters
1205 int linphone_core_get_audio_port(const LinphoneCore *lc)
1207 return lc->rtp_conf.audio_rtp_port;
1211 * Returns the UDP port used for video streaming.
1213 * @ingroup network_parameters
1215 int linphone_core_get_video_port(const LinphoneCore *lc){
1216 return lc->rtp_conf.video_rtp_port;
1221 * Returns the value in seconds of the no-rtp timeout.
1223 * @ingroup media_parameters
1224 * When no RTP or RTCP packets have been received for a while
1225 * LinphoneCore will consider the call is broken (remote end crashed or
1226 * disconnected from the network), and thus will terminate the call.
1227 * The no-rtp timeout is the duration above which the call is considered broken.
1229 int linphone_core_get_nortp_timeout(const LinphoneCore *lc){
1230 return lc->rtp_conf.nortp_timeout;
1233 bool_t linphone_core_get_rtp_no_xmit_on_audio_mute(const LinphoneCore *lc){
1234 return lc->rtp_conf.rtp_no_xmit_on_audio_mute;
1238 * Sets the nominal audio jitter buffer size in milliseconds.
1240 * @ingroup media_parameters
1242 void linphone_core_set_audio_jittcomp(LinphoneCore *lc, int value)
1244 lc->rtp_conf.audio_jitt_comp=value;
1247 void linphone_core_set_rtp_no_xmit_on_audio_mute(LinphoneCore *lc,bool_t rtp_no_xmit_on_audio_mute){
1248 lc->rtp_conf.rtp_no_xmit_on_audio_mute=rtp_no_xmit_on_audio_mute;
1252 * Sets the UDP port used for audio streaming.
1254 * @ingroup network_parameters
1256 void linphone_core_set_audio_port(LinphoneCore *lc, int port)
1258 lc->rtp_conf.audio_rtp_port=port;
1262 * Sets the UDP port used for video streaming.
1264 * @ingroup network_parameters
1266 void linphone_core_set_video_port(LinphoneCore *lc, int port){
1267 lc->rtp_conf.video_rtp_port=port;
1271 * Sets the no-rtp timeout value in seconds.
1273 * @ingroup media_parameters
1274 * See linphone_core_get_nortp_timeout() for details.
1276 void linphone_core_set_nortp_timeout(LinphoneCore *lc, int nortp_timeout){
1277 lc->rtp_conf.nortp_timeout=nortp_timeout;
1281 * Indicates whether SIP INFO is used for sending digits.
1283 * @ingroup media_parameters
1285 bool_t linphone_core_get_use_info_for_dtmf(LinphoneCore *lc)
1287 return lc->sip_conf.use_info;
1291 * Sets whether SIP INFO is to be used for sending digits.
1293 * @ingroup media_parameters
1295 void linphone_core_set_use_info_for_dtmf(LinphoneCore *lc,bool_t use_info)
1297 lc->sip_conf.use_info=use_info;
1301 * Indicates whether RFC2833 is used for sending digits.
1303 * @ingroup media_parameters
1305 bool_t linphone_core_get_use_rfc2833_for_dtmf(LinphoneCore *lc)
1307 return lc->sip_conf.use_rfc2833;
1311 * Sets whether RFC2833 is to be used for sending digits.
1313 * @ingroup media_parameters
1315 void linphone_core_set_use_rfc2833_for_dtmf(LinphoneCore *lc,bool_t use_rfc2833)
1317 lc->sip_conf.use_rfc2833=use_rfc2833;
1321 * Returns the UDP port used by SIP.
1323 * Deprecated: use linphone_core_get_sip_transports() instead.
1324 * @ingroup network_parameters
1326 int linphone_core_get_sip_port(LinphoneCore *lc)
1328 LCSipTransports *tr=&lc->sip_conf.transports;
1329 return tr->udp_port>0 ? tr->udp_port : tr->tcp_port;
1332 static char _ua_name[64]="Linphone";
1333 static char _ua_version[64]=LINPHONE_VERSION;
1335 #ifdef HAVE_EXOSIP_GET_VERSION
1336 extern const char *eXosip_get_version();
1339 static void apply_user_agent(LinphoneCore *lc){
1340 char ua_string[256];
1341 snprintf(ua_string,sizeof(ua_string)-1,"%s/%s (eXosip2/%s)",_ua_name,_ua_version,
1342 #ifdef HAVE_EXOSIP_GET_VERSION
1343 eXosip_get_version()
1348 if (lc->sal) sal_set_user_agent(lc->sal,ua_string);
1352 * Sets the user agent string used in SIP messages.
1356 void linphone_core_set_user_agent(const char *name, const char *ver){
1357 strncpy(_ua_name,name,sizeof(_ua_name)-1);
1358 strncpy(_ua_version,ver,sizeof(_ua_version));
1361 static void transport_error(LinphoneCore *lc, const char* transport, int port){
1362 char *msg=ortp_strdup_printf("Could not start %s transport on port %i, maybe this port is already used.",transport,port);
1364 if (lc->vtable.display_warning)
1365 lc->vtable.display_warning(lc,msg);
1369 static bool_t transports_unchanged(const LCSipTransports * tr1, const LCSipTransports * tr2){
1371 tr2->udp_port==tr1->udp_port &&
1372 tr2->tcp_port==tr1->tcp_port &&
1373 tr2->dtls_port==tr1->dtls_port &&
1374 tr2->tls_port==tr1->tls_port;
1377 static int apply_transports(LinphoneCore *lc){
1379 const char *anyaddr;
1380 LCSipTransports *tr=&lc->sip_conf.transports;
1382 if (lc->sip_conf.ipv6_enabled)
1387 sal_unlisten_ports (sal);
1388 if (tr->udp_port>0){
1389 if (sal_listen_port (sal,anyaddr,tr->udp_port,SalTransportDatagram,FALSE)!=0){
1390 transport_error(lc,"UDP",tr->udp_port);
1394 if (tr->tcp_port>0){
1395 if (sal_listen_port (sal,anyaddr,tr->tcp_port,SalTransportStream,FALSE)!=0){
1396 transport_error(lc,"TCP",tr->tcp_port);
1399 apply_user_agent(lc);
1404 * Sets the ports to be used for each of transport (UDP or TCP)
1406 * A zero value port for a given transport means the transport
1409 * @ingroup network_parameters
1411 int linphone_core_set_sip_transports(LinphoneCore *lc, const LCSipTransports * tr){
1413 if (transports_unchanged(tr,&lc->sip_conf.transports))
1415 memcpy(&lc->sip_conf.transports,tr,sizeof(*tr));
1417 if (lc->sal==NULL) return 0;
1418 return apply_transports(lc);
1422 * Retrieves the ports used for each transport (udp, tcp).
1423 * A zero value port for a given transport means the transport
1425 * @ingroup network_parameters
1427 int linphone_core_get_sip_transports(LinphoneCore *lc, LCSipTransports *tr){
1428 memcpy(tr,&lc->sip_conf.transports,sizeof(*tr));
1433 * Sets the UDP port to be used by SIP.
1435 * Deprecated: use linphone_core_set_sip_transports() instead.
1436 * @ingroup network_parameters
1438 void linphone_core_set_sip_port(LinphoneCore *lc,int port)
1441 memset(&tr,0,sizeof(tr));
1443 linphone_core_set_sip_transports (lc,&tr);
1447 * Returns TRUE if IPv6 is enabled.
1449 * @ingroup network_parameters
1450 * See linphone_core_enable_ipv6() for more details on how IPv6 is supported in liblinphone.
1452 bool_t linphone_core_ipv6_enabled(LinphoneCore *lc){
1453 return lc->sip_conf.ipv6_enabled;
1457 * Turns IPv6 support on or off.
1459 * @ingroup network_parameters
1461 * @note IPv6 support is exclusive with IPv4 in liblinphone:
1462 * when IPv6 is turned on, IPv4 calls won't be possible anymore.
1463 * By default IPv6 support is off.
1465 void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
1466 if (lc->sip_conf.ipv6_enabled!=val){
1467 lc->sip_conf.ipv6_enabled=val;
1469 /* we need to restart eXosip */
1470 apply_transports(lc);
1475 static void display_bandwidth(RtpSession *as, RtpSession *vs){
1476 ms_message("bandwidth usage: audio=[d=%.1f,u=%.1f] video=[d=%.1f,u=%.1f] kbit/sec",
1477 (as!=NULL) ? (rtp_session_compute_recv_bandwidth(as)*1e-3) : 0,
1478 (as!=NULL) ? (rtp_session_compute_send_bandwidth(as)*1e-3) : 0,
1479 (vs!=NULL) ? (rtp_session_compute_recv_bandwidth(vs)*1e-3) : 0,
1480 (vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0);
1483 static void linphone_core_disconnected(LinphoneCore *lc, LinphoneCall *call){
1487 from = linphone_call_get_remote_address_as_string(call);
1490 snprintf(temp,sizeof(temp),"Remote end %s seems to have disconnected, the call is going to be closed.",from);
1495 snprintf(temp,sizeof(temp),"Remote end seems to have disconnected, the call is going to be closed.");
1497 if (lc->vtable.display_warning!=NULL)
1498 lc->vtable.display_warning(lc,temp);
1499 linphone_core_terminate_call(lc,call);
1502 static void monitor_network_state(LinphoneCore *lc, time_t curtime){
1503 static time_t last_check=0;
1504 static bool_t last_status=FALSE;
1505 char result[LINPHONE_IPADDR_SIZE];
1506 bool_t new_status=last_status;
1508 /* only do the network up checking every five seconds */
1509 if (last_check==0 || (curtime-last_check)>=5){
1510 linphone_core_get_local_ip_for(lc->sip_conf.ipv6_enabled ? AF_INET6 : AF_INET,NULL,result);
1511 if (strcmp(result,"::1")!=0 && strcmp(result,"127.0.0.1")!=0){
1513 }else new_status=FALSE;
1515 if (new_status!=last_status) {
1517 ms_message("New local ip address is %s",result);
1519 set_network_reachable(lc,new_status);
1520 last_status=new_status;
1525 static void proxy_update(LinphoneCore *lc){
1526 ms_list_for_each(lc->sip_conf.proxies,(void (*)(void*))&linphone_proxy_config_update);
1527 MSList* list=ms_list_copy(lc->sip_conf.deleted_proxies);
1528 for(;list!=NULL;list=list->next){
1529 LinphoneProxyConfig* cfg = (LinphoneProxyConfig*) list->data;
1530 if (ms_time(NULL) - cfg->deletion_date > 5) {
1531 lc->sip_conf.deleted_proxies =ms_list_remove(lc->sip_conf.deleted_proxies,(void *)cfg);
1532 ms_message("clearing proxy config for [%s]",linphone_proxy_config_get_addr(cfg));
1533 linphone_proxy_config_destroy(cfg);
1539 static void assign_buddy_info(LinphoneCore *lc, BuddyInfo *info){
1540 LinphoneFriend *lf=linphone_core_get_friend_by_address(lc,info->sip_uri);
1543 ms_message("%s has a BuddyInfo assigned with image %p",info->sip_uri, info->image_data);
1544 if (lc->vtable.buddy_info_updated)
1545 lc->vtable.buddy_info_updated(lc,lf);
1547 ms_warning("Could not any friend with uri %s",info->sip_uri);
1551 static void analyze_buddy_lookup_results(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1553 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1554 for (elem=lc->bl_reqs;elem!=NULL;elem=ms_list_next(elem)){
1555 BuddyLookupRequest *req=(BuddyLookupRequest *)elem->data;
1556 if (req->status==BuddyLookupDone || req->status==BuddyLookupFailure){
1557 if (req->results!=NULL){
1558 BuddyInfo *i=(BuddyInfo*)req->results->data;
1559 ms_list_free(req->results);
1561 assign_buddy_info(lc,i);
1563 sip_setup_context_buddy_lookup_free(ctx,req);
1567 /*purge completed requests */
1568 while((elem=ms_list_find(lc->bl_reqs,NULL))!=NULL){
1569 lc->bl_reqs=ms_list_remove_link(lc->bl_reqs,elem);
1573 static void linphone_core_grab_buddy_infos(LinphoneCore *lc, LinphoneProxyConfig *cfg){
1575 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1576 for(elem=linphone_core_get_friend_list(lc);elem!=NULL;elem=elem->next){
1577 LinphoneFriend *lf=(LinphoneFriend*)elem->data;
1578 if (lf->info==NULL){
1579 if (linphone_core_lookup_known_proxy(lc,lf->uri)==cfg){
1580 if (linphone_address_get_username(lf->uri)!=NULL){
1581 BuddyLookupRequest *req;
1582 char *tmp=linphone_address_as_string_uri_only(lf->uri);
1583 req=sip_setup_context_create_buddy_lookup_request(ctx);
1584 buddy_lookup_request_set_key(req,tmp);
1585 buddy_lookup_request_set_max_results(req,1);
1586 sip_setup_context_buddy_lookup_submit(ctx,req);
1587 lc->bl_reqs=ms_list_append(lc->bl_reqs,req);
1595 static void linphone_core_do_plugin_tasks(LinphoneCore *lc){
1596 LinphoneProxyConfig *cfg=NULL;
1597 linphone_core_get_default_proxy(lc,&cfg);
1599 if (lc->bl_refresh){
1600 SipSetupContext *ctx=linphone_proxy_config_get_sip_setup_context(cfg);
1601 if (ctx && (sip_setup_context_get_capabilities(ctx) & SIP_SETUP_CAP_BUDDY_LOOKUP)){
1602 linphone_core_grab_buddy_infos(lc,cfg);
1603 lc->bl_refresh=FALSE;
1606 if (lc->bl_reqs) analyze_buddy_lookup_results(lc,cfg);
1611 * Main loop function. It is crucial that your application call it periodically.
1613 * @ingroup initializing
1614 * linphone_core_iterate() performs various backgrounds tasks:
1615 * - receiving of SIP messages
1616 * - handles timers and timeout
1617 * - performs registration to proxies
1618 * - authentication retries
1619 * The application MUST call this function from periodically, in its main loop.
1620 * Be careful that this function must be call from the same thread as
1621 * other liblinphone methods. In not the case make sure all liblinphone calls are
1622 * serialized with a mutex.
1624 void linphone_core_iterate(LinphoneCore *lc){
1627 int disconnect_timeout = linphone_core_get_nortp_timeout(lc);
1628 time_t curtime=time(NULL);
1630 bool_t one_second_elapsed=FALSE;
1631 bool_t disconnected=FALSE;
1633 if (curtime-lc->prevtime>=1){
1634 lc->prevtime=curtime;
1635 one_second_elapsed=TRUE;
1638 if (lc->preview_finished){
1639 lc->preview_finished=0;
1640 ring_stop(lc->ringstream);
1641 lc->ringstream=NULL;
1642 lc_callback_obj_invoke(&lc->preview_finished_cb,lc);
1645 if (lc->ringstream && lc->dmfs_playing_start_time!=0
1646 && (curtime-lc->dmfs_playing_start_time)>5){
1647 ring_stop(lc->ringstream);
1648 lc->ringstream=NULL;
1649 lc->dmfs_playing_start_time=0;
1652 sal_iterate(lc->sal);
1653 ms_event_queue_pump(lc->msevq);
1654 if (lc->auto_net_state_mon) monitor_network_state(lc,curtime);
1658 //we have to iterate for each call
1660 while(calls!= NULL){
1661 call = (LinphoneCall *)calls->data;
1662 /* get immediately a reference to next one in case the one
1663 we are going to examine is destroy and removed during
1664 linphone_core_start_invite() */
1666 if (call->state==LinphoneCallOutgoingInit && (curtime-call->start_time>=2)){
1667 /*start the call even if the OPTIONS reply did not arrive*/
1668 linphone_core_start_invite(lc,call,NULL);
1670 if (call->dir==LinphoneCallIncoming && call->state==LinphoneCallOutgoingRinging){
1671 elapsed=curtime-call->start_time;
1672 ms_message("incoming call ringing for %i seconds",elapsed);
1673 if (elapsed>lc->sip_conf.inc_timeout){
1674 call->log->status=LinphoneCallMissed;
1675 linphone_core_terminate_call(lc,call);
1679 call = linphone_core_get_current_call(lc);
1682 if (call->state==LinphoneCallStreamsRunning && one_second_elapsed)
1684 RtpSession *as=NULL,*vs=NULL;
1685 lc->prevtime=curtime;
1686 if (call->audiostream!=NULL)
1687 as=call->audiostream->session;
1688 if (call->videostream!=NULL)
1689 vs=call->videostream->session;
1690 display_bandwidth(as,vs);
1692 #ifdef VIDEO_ENABLED
1693 if (call->videostream!=NULL)
1694 video_stream_iterate(call->videostream);
1696 if (call->audiostream!=NULL && disconnect_timeout>0)
1697 disconnected=!audio_stream_alive(call->audiostream,disconnect_timeout);
1699 if (linphone_core_video_preview_enabled(lc)){
1700 if (lc->previewstream==NULL && lc->calls==NULL)
1701 toggle_video_preview(lc,TRUE);
1702 #ifdef VIDEO_ENABLED
1703 else video_stream_iterate(lc->previewstream);
1706 if (lc->previewstream!=NULL)
1707 toggle_video_preview(lc,FALSE);
1710 linphone_core_disconnected(lc,call);
1712 linphone_core_do_plugin_tasks(lc);
1714 if (one_second_elapsed && lp_config_needs_commit(lc->config)){
1715 lp_config_sync(lc->config);
1720 * Interpret a call destination as supplied by the user, and returns a fully qualified
1723 * A sip address should look like DisplayName <sip:username@domain:port> .
1724 * Basically this function performs the following tasks
1725 * - if a phone number is entered, prepend country prefix of the default proxy
1726 * configuration, eventually escape the '+' by 00.
1727 * - if no domain part is supplied, append the domain name of the default proxy
1728 * - if no sip: is present, prepend it
1730 * The result is a syntaxically correct SIP address.
1733 LinphoneAddress * linphone_core_interpret_url(LinphoneCore *lc, const char *url){
1734 enum_lookup_res_t *enumres=NULL;
1735 char *enum_domain=NULL;
1736 LinphoneProxyConfig *proxy=lc->default_proxy;;
1738 LinphoneAddress *uri;
1740 if (is_enum(url,&enum_domain)){
1741 if (lc->vtable.display_status!=NULL)
1742 lc->vtable.display_status(lc,_("Looking for telephone number destination..."));
1743 if (enum_lookup(enum_domain,&enumres)<0){
1744 if (lc->vtable.display_status!=NULL)
1745 lc->vtable.display_status(lc,_("Could not resolve this number."));
1746 ms_free(enum_domain);
1749 ms_free(enum_domain);
1750 tmpurl=enumres->sip_address[0];
1751 uri=linphone_address_new(tmpurl);
1752 enum_lookup_res_free(enumres);
1755 /* check if we have a "sip:" */
1756 if (strstr(url,"sip:")==NULL){
1757 /* this doesn't look like a true sip uri */
1758 if (strchr(url,'@')!=NULL){
1759 /* seems like sip: is missing !*/
1760 tmpurl=ms_strdup_printf("sip:%s",url);
1761 uri=linphone_address_new(tmpurl);
1769 /* append the proxy domain suffix */
1770 const char *identity=linphone_proxy_config_get_identity(proxy);
1771 char normalized_username[128];
1772 uri=linphone_address_new(identity);
1776 linphone_address_set_display_name(uri,NULL);
1777 linphone_proxy_config_normalize_number(proxy,url,normalized_username,
1778 sizeof(normalized_username));
1779 linphone_address_set_username(uri,normalized_username);
1783 uri=linphone_address_new(url);
1787 /* else we could not do anything with url given by user, so display an error */
1788 if (lc->vtable.display_warning!=NULL){
1789 lc->vtable.display_warning(lc,_("Could not parse given sip address. A sip url usually looks like sip:user@domain"));
1795 * Returns the default identity SIP address.
1798 * This is an helper function:
1800 * If no default proxy is set, this will return the primary contact (
1801 * see linphone_core_get_primary_contact() ). If a default proxy is set
1802 * it returns the registered identity on the proxy.
1804 const char * linphone_core_get_identity(LinphoneCore *lc){
1805 LinphoneProxyConfig *proxy=NULL;
1807 linphone_core_get_default_proxy(lc,&proxy);
1809 from=linphone_proxy_config_get_identity(proxy);
1810 }else from=linphone_core_get_primary_contact(lc);
1814 const char * linphone_core_get_route(LinphoneCore *lc){
1815 LinphoneProxyConfig *proxy=NULL;
1816 const char *route=NULL;
1817 linphone_core_get_default_proxy(lc,&proxy);
1819 route=linphone_proxy_config_get_route(proxy);
1824 bool_t linphone_core_is_in_communication_with(LinphoneCore *lc, const char *to)
1828 const LinphoneAddress *la=linphone_core_get_current_call_remote_address(lc);
1833 tmp = linphone_address_as_string(la);
1843 void linphone_core_start_pending_refered_calls(LinphoneCore *lc){
1845 for(elem=lc->calls;elem!=NULL;elem=elem->next){
1846 LinphoneCall *call=(LinphoneCall*)elem->data;
1847 if (call->refer_pending){
1848 ms_message("Starting new call to refered address %s",call->refer_to);
1849 call->refer_pending=FALSE;
1850 linphone_core_invite(lc,call->refer_to);
1856 LinphoneProxyConfig * linphone_core_lookup_known_proxy(LinphoneCore *lc, const LinphoneAddress *uri){
1858 LinphoneProxyConfig *found_cfg=NULL;
1859 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=elem->next){
1860 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
1861 const char *domain=linphone_proxy_config_get_domain(cfg);
1862 if (domain!=NULL && strcmp(domain,linphone_address_get_domain(uri))==0){
1870 static char *get_fixed_contact(LinphoneCore *lc, LinphoneCall *call , LinphoneProxyConfig *dest_proxy){
1871 LinphoneAddress *ctt;
1872 const char *localip=call->localip;
1874 /* first use user's supplied ip address if asked*/
1875 if (linphone_core_get_firewall_policy(lc)==LinphonePolicyUseNatAddress){
1876 ctt=linphone_core_get_primary_contact_parsed(lc);
1877 return ms_strdup_printf("sip:%s@%s",linphone_address_get_username(ctt),
1878 linphone_core_get_nat_address(lc));
1881 /* if already choosed, don't change it */
1882 if (call->op && sal_op_get_contact(call->op)!=NULL){
1885 /* if the ping OPTIONS request succeeded use the contact guessed from the
1888 const char *guessed=sal_op_get_contact(call->ping_op);
1890 ms_message("Contact has been fixed using OPTIONS to %s",guessed);
1891 return ms_strdup(guessed);
1895 /*if using a proxy, use the contact address as guessed with the REGISTERs*/
1896 if (dest_proxy && dest_proxy->op){
1897 const char *fixed_contact=sal_op_get_contact(dest_proxy->op);
1898 if (fixed_contact) {
1899 ms_message("Contact has been fixed using proxy to %s",fixed_contact);
1900 return ms_strdup(fixed_contact);
1904 ctt=linphone_core_get_primary_contact_parsed(lc);
1908 /*otherwise use supllied localip*/
1909 linphone_address_set_domain(ctt,localip);
1910 linphone_address_set_port_int(ctt,linphone_core_get_sip_port(lc));
1911 ret=linphone_address_as_string_uri_only(ctt);
1912 linphone_address_destroy(ctt);
1913 ms_message("Contact has been fixed using local ip to %s",ret);
1919 int linphone_core_start_invite(LinphoneCore *lc, LinphoneCall *call, LinphoneProxyConfig *dest_proxy){
1922 char *real_url,*barmsg;
1925 /*try to be best-effort in giving real local or routable contact address */
1926 contact=get_fixed_contact(lc,call,dest_proxy);
1928 sal_op_set_contact(call->op, contact);
1932 //TODO : should probably not be done here
1933 linphone_call_init_media_streams(call);
1934 if (!lc->sip_conf.sdp_200_ack){
1935 call->media_pending=TRUE;
1936 sal_call_set_local_media_description(call->op,call->localdesc);
1938 real_url=linphone_address_as_string(call->log->to);
1939 from=linphone_address_as_string(call->log->from);
1940 err=sal_call(call->op,from,real_url);
1942 if (lc->sip_conf.sdp_200_ack){
1943 call->media_pending=TRUE;
1944 sal_call_set_local_media_description(call->op,call->localdesc);
1946 barmsg=ortp_strdup_printf("%s %s", _("Contacting"), real_url);
1947 if (lc->vtable.display_status!=NULL)
1948 lc->vtable.display_status(lc,barmsg);
1952 if (lc->vtable.display_status!=NULL)
1953 lc->vtable.display_status(lc,_("Could not call"));
1954 linphone_call_stop_media_streams(call);
1955 linphone_call_set_state(call,LinphoneCallError,"Call failed");
1957 linphone_call_set_state(call,LinphoneCallOutgoingProgress,"Outgoing call in progress");
1965 * Initiates an outgoing call
1967 * @ingroup call_control
1968 * @param lc the LinphoneCore object
1969 * @param url the destination of the call (sip address, or phone number).
1971 LinphoneCall * linphone_core_invite(LinphoneCore *lc, const char *url){
1972 LinphoneAddress *addr=linphone_core_interpret_url(lc,url);
1975 call=linphone_core_invite_address(lc,addr);
1976 linphone_address_destroy(addr);
1983 * Initiates an outgoing call given a destination LinphoneAddress
1985 * @ingroup call_control
1986 * @param lc the LinphoneCore object
1987 * @param url the destination of the call (sip address).
1989 LinphoneCall * linphone_core_invite_address(LinphoneCore *lc, const LinphoneAddress *real_parsed_url)
1992 const char *route=NULL;
1993 const char *from=NULL;
1994 LinphoneProxyConfig *proxy=NULL;
1995 LinphoneAddress *parsed_url2=NULL;
1996 char *real_url=NULL;
1997 LinphoneProxyConfig *dest_proxy=NULL;
2000 if (linphone_core_in_call(lc)){
2001 if (lc->vtable.display_warning)
2002 lc->vtable.display_warning(lc,_("Sorry, you have to pause or stop the current call first !"));
2005 if(!linphone_core_can_we_add_call(lc)){
2006 if (lc->vtable.display_warning)
2007 lc->vtable.display_warning(lc,_("Sorry, we have reached the maximum number of simultaneous calls"));
2010 linphone_core_get_default_proxy(lc,&proxy);
2011 route=linphone_core_get_route(lc);
2013 real_url=linphone_address_as_string(real_parsed_url);
2014 dest_proxy=linphone_core_lookup_known_proxy(lc,real_parsed_url);
2016 if (proxy!=dest_proxy && dest_proxy!=NULL) {
2017 ms_message("Overriding default proxy setting for this call:");
2018 ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy));
2021 if (dest_proxy!=NULL)
2022 from=linphone_proxy_config_get_identity(dest_proxy);
2023 else if (proxy!=NULL)
2024 from=linphone_proxy_config_get_identity(proxy);
2026 /* if no proxy or no identity defined for this proxy, default to primary contact*/
2027 if (from==NULL) from=linphone_core_get_primary_contact(lc);
2029 parsed_url2=linphone_address_new(from);
2031 call=linphone_call_new_outgoing(lc,parsed_url2,linphone_address_clone(real_parsed_url));
2032 sal_op_set_route(call->op,route);
2034 if(linphone_core_add_call(lc,call)!= 0)
2036 ms_warning("we had a problem in adding the call into the invite ... weird");
2037 linphone_call_unref(call);
2040 /* this call becomes now the current one*/
2041 lc->current_call=call;
2042 linphone_call_set_state (call,LinphoneCallOutgoingInit,"Starting outgoing call");
2043 if (dest_proxy!=NULL || lc->sip_conf.ping_with_options==FALSE){
2044 err=linphone_core_start_invite(lc,call,dest_proxy);
2046 /*defer the start of the call after the OPTIONS ping*/
2047 call->ping_op=sal_op_new(lc->sal);
2048 sal_ping(call->ping_op,from,real_url);
2049 sal_op_set_user_pointer(call->ping_op,call);
2050 call->start_time=time(NULL);
2053 if (real_url!=NULL) ms_free(real_url);
2058 * Performs a simple call transfer to the specified destination.
2060 * The remote endpoint is expected to issue a new call to the specified destination.
2061 * The current call remains active and thus can be later paused or terminated.
2063 int linphone_core_transfer_call(LinphoneCore *lc, LinphoneCall *call, const char *url)
2065 char *real_url=NULL;
2066 LinphoneAddress *real_parsed_url=linphone_core_interpret_url(lc,url);
2068 if (!real_parsed_url){
2073 ms_warning("No established call to refer.");
2076 //lc->call=NULL; //Do not do that you will lose the call afterward . . .
2077 real_url=linphone_address_as_string (real_parsed_url);
2078 sal_refer(call->op,real_url);
2080 linphone_address_destroy(real_parsed_url);
2085 * Returns true if an incoming call is pending, ie waiting for being answered or declined.
2087 * @ingroup call_control
2089 bool_t linphone_core_inc_invite_pending(LinphoneCore*lc){
2090 LinphoneCall *call = linphone_core_get_current_call(lc);
2093 if(call->dir==LinphoneCallIncoming)
2101 * Accept an incoming call.
2103 * @ingroup call_control
2104 * Basically the application is notified of incoming calls within the
2105 * invite_recv callback of the #LinphoneCoreVTable structure.
2106 * The application can later respond positively to the call using
2108 * @param lc the LinphoneCore object
2109 * @param url the SIP address of the originator of the call, or NULL.
2110 * This argument is useful for managing multiple calls simulatenously,
2111 * however this feature is not supported yet.
2112 * Using NULL will accept the unique incoming call in progress.
2114 int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call)
2116 LinphoneProxyConfig *cfg=NULL;
2117 const char *contact=NULL;
2120 //if just one call is present answer the only one ...
2121 if(linphone_core_get_calls_nb (lc) != 1)
2124 call = (LinphoneCall*)linphone_core_get_calls(lc)->data;
2127 if (lc->current_call){
2128 ms_warning("Cannot accept this call, there is already one running.");
2132 if (call->state==LinphoneCallConnected){
2133 /*call already accepted*/
2137 /*can accept a new call only if others are on hold */
2140 for(elem=lc->calls;elem!=NULL;elem=elem->next){
2141 LinphoneCall *c=(LinphoneCall*)elem->data;
2142 if (c!=call && (c->state!=LinphoneCallPaused)){
2143 ms_warning("Cannot accept this call as another one is running, pause it before.");
2150 if (lc->ringstream!=NULL) {
2151 ms_message("stop ringing");
2152 ring_stop(lc->ringstream);
2153 ms_message("ring stopped");
2154 lc->ringstream=NULL;
2157 linphone_core_get_default_proxy(lc,&cfg);
2158 /*try to be best-effort in giving real local or routable contact address*/
2159 contact=get_fixed_contact(lc,call,cfg);
2161 sal_op_set_contact(call->op,contact);
2162 #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
2163 linphone_call_init_media_streams(call);
2165 sal_call_accept(call->op);
2166 if (lc->vtable.display_status!=NULL)
2167 lc->vtable.display_status(lc,_("Connected."));
2168 lc->current_call=call;
2169 linphone_call_set_state(call,LinphoneCallConnected,"Connected");
2170 call->resultdesc=sal_call_get_final_media_description(call->op);
2171 if (call->resultdesc){
2172 linphone_call_start_media_streams(call);
2173 linphone_call_set_state(call,LinphoneCallStreamsRunning,"Connected (streams running)");
2174 sal_media_description_ref(call->resultdesc);
2175 }else call->media_pending=TRUE;
2176 ms_message("call answered.");
2180 int linphone_core_abort_call(LinphoneCore *lc, LinphoneCall *call, const char *error){
2181 sal_call_terminate(call->op);
2184 if (lc->ringstream!=NULL) {
2185 ring_stop(lc->ringstream);
2186 lc->ringstream=NULL;
2188 linphone_call_stop_media_streams(call);
2189 if (lc->vtable.display_status!=NULL)
2190 lc->vtable.display_status(lc,_("Call aborted") );
2191 linphone_call_set_state(call,LinphoneCallError,error);
2197 * Terminates a call.
2199 * @ingroup call_control
2200 * @param lc The LinphoneCore
2201 * @param url the destination of the call to be terminated, use NULL if there is
2202 * only one call (which is case in this version of liblinphone).
2204 int linphone_core_terminate_call(LinphoneCore *lc, LinphoneCall *the_call)
2207 if (the_call == NULL){
2208 call = linphone_core_get_current_call(lc);
2209 if (ms_list_size(lc->calls)==1){
2210 call=(LinphoneCall*)lc->calls->data;
2212 ms_warning("No unique call to terminate !");
2220 sal_call_terminate(call->op);
2223 if (lc->ringstream!=NULL) {
2224 ring_stop(lc->ringstream);
2225 lc->ringstream=NULL;
2227 linphone_call_stop_media_streams(call);
2228 if (lc->vtable.display_status!=NULL)
2229 lc->vtable.display_status(lc,_("Call ended") );
2230 linphone_call_set_state(call,LinphoneCallEnd,"Call terminated");
2235 * Terminates all the calls.
2237 * @ingroup call_control
2238 * @param lc The LinphoneCore
2240 int linphone_core_terminate_all_calls(LinphoneCore *lc){
2243 LinphoneCall *the_call = lc->calls->data;
2244 linphone_core_terminate_call(lc,the_call);
2246 ms_list_free(lc->calls);
2251 * Returns the current list of calls.
2253 * Note that this list is read-only and might be changed by the core after a function call to linphone_core_iterate().
2254 * Similarly the LinphoneCall objects inside it might be destroyed without prior notice.
2255 * To hold references to LinphoneCall object into your program, you must use linphone_call_ref().
2257 * @ingroup call_control
2259 const MSList *linphone_core_get_calls(LinphoneCore *lc)
2265 * Returns TRUE if there is a call running or pending.
2267 * @ingroup call_control
2269 bool_t linphone_core_in_call(const LinphoneCore *lc){
2270 return linphone_core_get_current_call((LinphoneCore *)lc)!=NULL;
2274 * Returns The _LinphoneCall struct of the current call if one is in call
2276 * @ingroup call_control
2278 LinphoneCall *linphone_core_get_current_call(const LinphoneCore *lc)
2280 return lc->current_call;
2284 * Permits to pause the call
2286 * @ingroup call_control
2288 int linphone_core_pause_call(LinphoneCore *lc, LinphoneCall *the_call)
2290 LinphoneCall *call = the_call;
2292 if(linphone_core_get_current_call(lc) != call)
2294 ms_error("The call asked to be paused was not the current on");
2297 if (sal_call_hold(call->op,TRUE) != 0)
2299 if (lc->vtable.display_warning)
2300 lc->vtable.display_warning(lc,_("Could not pause the call"));
2302 linphone_call_set_state(call,LinphoneCallPausing,"Pausing call");
2303 if (lc->vtable.display_status)
2304 lc->vtable.display_status(lc,_("Pausing the current call..."));
2305 lc->current_call=NULL;
2306 linphone_core_start_pending_refered_calls(lc);
2311 * Permits to resume the call
2313 * @ingroup call_control
2315 int linphone_core_resume_call(LinphoneCore *lc, LinphoneCall *the_call)
2318 LinphoneCall *call = the_call;
2320 if(call->state!=LinphoneCallPaused ){
2321 ms_warning("we cannot resume a call when the communication is not established");
2324 if(linphone_core_get_current_call(lc) != NULL){
2325 if (lc->vtable.display_warning)
2326 lc->vtable.display_warning(lc,_("There is already a call in process, pause or stop it first."));
2329 if(sal_call_hold(call->op,FALSE) != 0){
2332 linphone_call_set_state (call,LinphoneCallResuming,"Resuming");
2333 snprintf(temp,sizeof(temp)-1,"Resuming the call with %s",linphone_call_get_remote_address_as_string(call));
2334 if (lc->vtable.display_status)
2335 lc->vtable.display_status(lc,temp);
2336 lc->current_call=call;
2341 * Compare the remote address with the one in call
2344 * @param b the remote address to compare with
2345 * @return 0 if it's the good call else 1
2347 static int linphone_call_remote_address_compare(const void * a, const void * b)
2349 if(b == NULL || a ==NULL)
2351 char *the_remote_address = ((char *)b);
2352 LinphoneCall *call = ((LinphoneCall *)a);
2354 ms_message("the remote address:%s\n",the_remote_address);
2355 ms_message("the call:%p => %s\n",call,linphone_call_get_remote_address_as_string(call));
2357 if(!strcmp(linphone_call_get_remote_address_as_string(call),the_remote_address))
2365 * Get the call with the remote_address specified
2367 * @param remote_address
2368 * @return the LinphoneCall of the call if found
2370 LinphoneCall *linphone_core_get_call_by_remote_address(LinphoneCore *lc, const char *remote_address){
2372 MSList *the_call = ms_list_find_custom(lc->calls,linphone_call_remote_address_compare,(void *)remote_address);
2373 if(the_call != NULL)
2375 return ((LinphoneCall *)the_call->data);
2380 int linphone_core_send_publish(LinphoneCore *lc,
2381 LinphoneOnlineStatus presence_mode)
2384 for (elem=linphone_core_get_proxy_config_list(lc);elem!=NULL;elem=ms_list_next(elem)){
2385 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
2386 if (cfg->publish) linphone_proxy_config_send_publish(cfg,presence_mode);
2392 * Set the incoming call timeout in seconds.
2394 * @ingroup call_control
2395 * If an incoming call isn't answered for this timeout period, it is
2396 * automatically declined.
2398 void linphone_core_set_inc_timeout(LinphoneCore *lc, int seconds){
2399 lc->sip_conf.inc_timeout=seconds;
2403 * Returns the incoming call timeout
2405 * @ingroup call_control
2406 * See linphone_core_set_inc_timeout() for details.
2408 int linphone_core_get_inc_timeout(LinphoneCore *lc){
2409 return lc->sip_conf.inc_timeout;
2412 void linphone_core_set_presence_info(LinphoneCore *lc,int minutes_away,
2413 const char *contact,
2414 LinphoneOnlineStatus presence_mode)
2416 if (minutes_away>0) lc->minutes_away=minutes_away;
2418 if (lc->alt_contact!=NULL) {
2419 ms_free(lc->alt_contact);
2420 lc->alt_contact=NULL;
2422 if (contact) lc->alt_contact=ms_strdup(contact);
2423 if (lc->presence_mode!=presence_mode){
2424 linphone_core_notify_all_friends(lc,presence_mode);
2426 Improve the use of all LINPHONE_STATUS available.
2427 !TODO Do not mix "presence status" with "answer status code"..
2428 Use correct parameter to follow sip_if_match/sip_etag.
2430 linphone_core_send_publish(lc,presence_mode);
2432 lc->presence_mode=presence_mode;
2435 LinphoneOnlineStatus linphone_core_get_presence_info(const LinphoneCore *lc){
2436 return lc->presence_mode;
2440 * Get playback sound level in 0-100 scale.
2442 * @ingroup media_parameters
2444 int linphone_core_get_play_level(LinphoneCore *lc)
2446 return lc->sound_conf.play_lev;
2450 * Get ring sound level in 0-100 scale
2452 * @ingroup media_parameters
2454 int linphone_core_get_ring_level(LinphoneCore *lc)
2456 return lc->sound_conf.ring_lev;
2460 * Get sound capture level in 0-100 scale
2462 * @ingroup media_parameters
2464 int linphone_core_get_rec_level(LinphoneCore *lc){
2465 return lc->sound_conf.rec_lev;
2469 * Set sound ring level in 0-100 scale
2471 * @ingroup media_parameters
2473 void linphone_core_set_ring_level(LinphoneCore *lc, int level){
2475 lc->sound_conf.ring_lev=level;
2476 sndcard=lc->sound_conf.ring_sndcard;
2477 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2481 * Allow to control play level before entering sound card: gain in db
2483 * @ingroup media_parameters
2485 void linphone_core_set_playback_gain_db (LinphoneCore *lc, float gaindb){
2487 LinphoneCall *call=linphone_core_get_current_call (lc);
2490 lc->sound_conf.soft_play_lev=gaindb;
2492 if (call==NULL || (st=call->audiostream)==NULL){
2493 ms_message("linphone_core_set_playback_gain_db(): no active call.");
2497 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_DB_GAIN,&gain);
2498 }else ms_warning("Could not apply gain: gain control wasn't activated.");
2502 * Get playback gain in db before entering sound card.
2504 * @ingroup media_parameters
2506 float linphone_core_get_playback_gain_db(LinphoneCore *lc) {
2507 return lc->sound_conf.soft_play_lev;
2511 * Set sound playback level in 0-100 scale
2513 * @ingroup media_parameters
2515 void linphone_core_set_play_level(LinphoneCore *lc, int level){
2517 lc->sound_conf.play_lev=level;
2518 sndcard=lc->sound_conf.play_sndcard;
2519 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_PLAYBACK,level);
2523 * Set sound capture level in 0-100 scale
2525 * @ingroup media_parameters
2527 void linphone_core_set_rec_level(LinphoneCore *lc, int level)
2530 lc->sound_conf.rec_lev=level;
2531 sndcard=lc->sound_conf.capt_sndcard;
2532 if (sndcard) ms_snd_card_set_level(sndcard,MS_SND_CARD_CAPTURE,level);
2535 static MSSndCard *get_card_from_string_id(const char *devid, unsigned int cap){
2536 MSSndCard *sndcard=NULL;
2538 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2539 if (sndcard!=NULL &&
2540 (ms_snd_card_get_capabilities(sndcard) & cap)==0 ){
2541 ms_warning("%s card does not have the %s capability, ignoring.",
2543 cap==MS_SND_CARD_CAP_CAPTURE ? "capture" : "playback");
2547 if (sndcard==NULL) {
2548 /* get a card that has read+write capabilities */
2549 sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
2550 /* otherwise refine to the first card having the right capability*/
2552 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2553 for(;elem!=NULL;elem=elem->next){
2554 sndcard=(MSSndCard*)elem->data;
2555 if (ms_snd_card_get_capabilities(sndcard) & cap) break;
2558 if (sndcard==NULL){/*looks like a bug! take the first one !*/
2559 const MSList *elem=ms_snd_card_manager_get_list(ms_snd_card_manager_get());
2560 if (elem) sndcard=(MSSndCard*)elem->data;
2563 if (sndcard==NULL) ms_error("Could not find a suitable soundcard !");
2568 * Returns true if the specified sound device can capture sound.
2570 * @ingroup media_parameters
2571 * @param devid the device name as returned by linphone_core_get_sound_devices()
2573 bool_t linphone_core_sound_device_can_capture(LinphoneCore *lc, const char *devid){
2575 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2576 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_CAPTURE)) return TRUE;
2581 * Returns true if the specified sound device can play sound.
2583 * @ingroup media_parameters
2584 * @param devid the device name as returned by linphone_core_get_sound_devices()
2586 bool_t linphone_core_sound_device_can_playback(LinphoneCore *lc, const char *devid){
2588 sndcard=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),devid);
2589 if (sndcard!=NULL && (ms_snd_card_get_capabilities(sndcard) & MS_SND_CARD_CAP_PLAYBACK)) return TRUE;
2594 * Sets the sound device used for ringing.
2596 * @ingroup media_parameters
2597 * @param devid the device name as returned by linphone_core_get_sound_devices()
2599 int linphone_core_set_ringer_device(LinphoneCore *lc, const char * devid){
2600 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2601 lc->sound_conf.ring_sndcard=card;
2602 if (card && lc->ready)
2603 lp_config_set_string(lc->config,"sound","ringer_dev_id",ms_snd_card_get_string_id(card));
2608 * Sets the sound device used for playback.
2610 * @ingroup media_parameters
2611 * @param devid the device name as returned by linphone_core_get_sound_devices()
2613 int linphone_core_set_playback_device(LinphoneCore *lc, const char * devid){
2614 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_PLAYBACK);
2615 lc->sound_conf.play_sndcard=card;
2616 if (card && lc->ready)
2617 lp_config_set_string(lc->config,"sound","playback_dev_id",ms_snd_card_get_string_id(card));
2622 * Sets the sound device used for capture.
2624 * @ingroup media_parameters
2625 * @param devid the device name as returned by linphone_core_get_sound_devices()
2627 int linphone_core_set_capture_device(LinphoneCore *lc, const char * devid){
2628 MSSndCard *card=get_card_from_string_id(devid,MS_SND_CARD_CAP_CAPTURE);
2629 lc->sound_conf.capt_sndcard=card;
2630 if (card && lc->ready)
2631 lp_config_set_string(lc->config,"sound","capture_dev_id",ms_snd_card_get_string_id(card));
2636 * Returns the name of the currently assigned sound device for ringing.
2638 * @ingroup media_parameters
2640 const char * linphone_core_get_ringer_device(LinphoneCore *lc)
2642 if (lc->sound_conf.ring_sndcard) return ms_snd_card_get_string_id(lc->sound_conf.ring_sndcard);
2647 * Returns the name of the currently assigned sound device for playback.
2649 * @ingroup media_parameters
2651 const char * linphone_core_get_playback_device(LinphoneCore *lc)
2653 return lc->sound_conf.play_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.play_sndcard) : NULL;
2657 * Returns the name of the currently assigned sound device for capture.
2659 * @ingroup media_parameters
2661 const char * linphone_core_get_capture_device(LinphoneCore *lc)
2663 return lc->sound_conf.capt_sndcard ? ms_snd_card_get_string_id(lc->sound_conf.capt_sndcard) : NULL;
2667 * Returns an unmodifiable array of available sound devices.
2669 * @ingroup media_parameters
2670 * The array is NULL terminated.
2672 const char** linphone_core_get_sound_devices(LinphoneCore *lc){
2673 build_sound_devices_table(lc);
2674 return lc->sound_conf.cards;
2678 * Returns an unmodifiable array of available video capture devices.
2680 * @ingroup media_parameters
2681 * The array is NULL terminated.
2683 const char** linphone_core_get_video_devices(const LinphoneCore *lc){
2684 return lc->video_conf.cams;
2687 char linphone_core_get_sound_source(LinphoneCore *lc)
2689 return lc->sound_conf.source;
2692 void linphone_core_set_sound_source(LinphoneCore *lc, char source)
2694 MSSndCard *sndcard=lc->sound_conf.capt_sndcard;
2695 lc->sound_conf.source=source;
2696 if (!sndcard) return;
2699 ms_snd_card_set_capture(sndcard,MS_SND_CARD_MIC);
2702 ms_snd_card_set_capture(sndcard,MS_SND_CARD_LINE);
2710 * Sets the path to a wav file used for ringing.
2712 * The file must be a wav 16bit linear.
2714 * @ingroup media_parameters
2716 void linphone_core_set_ring(LinphoneCore *lc,const char *path){
2717 if (lc->sound_conf.local_ring!=0){
2718 ms_free(lc->sound_conf.local_ring);
2720 lc->sound_conf.local_ring=ms_strdup(path);
2721 if (lc->ready && lc->sound_conf.local_ring)
2722 lp_config_set_string(lc->config,"sound","local_ring",lc->sound_conf.local_ring);
2726 * Returns the path to the wav file used for ringing.
2728 * @ingroup media_parameters
2730 const char *linphone_core_get_ring(const LinphoneCore *lc){
2731 return lc->sound_conf.local_ring;
2734 static void notify_end_of_ring(void *ud ,unsigned int event, void * arg){
2735 LinphoneCore *lc=(LinphoneCore*)ud;
2736 lc->preview_finished=1;
2739 int linphone_core_preview_ring(LinphoneCore *lc, const char *ring,LinphoneCoreCbFunc func,void * userdata)
2741 if (lc->ringstream!=0){
2742 ms_warning("Cannot start ring now,there's already a ring being played");
2745 lc_callback_obj_init(&lc->preview_finished_cb,func,userdata);
2746 lc->preview_finished=0;
2747 if (lc->sound_conf.ring_sndcard!=NULL){
2748 MSSndCard *ringcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
2749 lc->ringstream=ring_start_with_cb(ring,2000,ringcard,notify_end_of_ring,(void *)lc);
2755 * Sets the path to a wav file used for ringing back.
2757 * Ringback means the ring that is heard when it's ringing at the remote party.
2758 * The file must be a wav 16bit linear.
2760 * @ingroup media_parameters
2762 void linphone_core_set_ringback(LinphoneCore *lc, const char *path){
2763 if (lc->sound_conf.remote_ring!=0){
2764 ms_free(lc->sound_conf.remote_ring);
2766 lc->sound_conf.remote_ring=ms_strdup(path);
2770 * Returns the path to the wav file used for ringing back.
2772 * @ingroup media_parameters
2774 const char * linphone_core_get_ringback(const LinphoneCore *lc){
2775 return lc->sound_conf.remote_ring;
2779 * Enables or disable echo cancellation.
2781 * @ingroup media_parameters
2783 void linphone_core_enable_echo_cancellation(LinphoneCore *lc, bool_t val){
2784 lc->sound_conf.ec=val;
2786 lp_config_set_int(lc->config,"sound","echocancellation",val);
2790 * Returns TRUE if echo cancellation is enabled.
2792 * @ingroup media_parameters
2794 bool_t linphone_core_echo_cancellation_enabled(LinphoneCore *lc){
2795 return lc->sound_conf.ec;
2798 void linphone_core_enable_echo_limiter(LinphoneCore *lc, bool_t val){
2799 lc->sound_conf.ea=val;
2802 bool_t linphone_core_echo_limiter_enabled(const LinphoneCore *lc){
2803 return lc->sound_conf.ea;
2807 * Mutes or unmutes the local microphone.
2809 * @ingroup media_parameters
2811 void linphone_core_mute_mic(LinphoneCore *lc, bool_t val){
2812 LinphoneCall *call=linphone_core_get_current_call(lc);
2814 ms_warning("linphone_core_mute_mic(): No current call !");
2817 if (call->audiostream!=NULL){
2818 audio_stream_set_mic_gain(call->audiostream,
2819 (val==TRUE) ? 0 : lp_config_get_float(lc->config,"sound","mic_gain",1));
2820 if ( linphone_core_get_rtp_no_xmit_on_audio_mute(lc) ){
2821 audio_stream_mute_rtp(call->audiostream,val);
2823 call->audio_muted=val;
2827 bool_t linphone_core_is_mic_muted(LinphoneCore *lc) {
2829 LinphoneCall *call=linphone_core_get_current_call(lc);
2831 ms_warning("linphone_core_is_mic_muted(): No current call !");
2834 if (call->audiostream && call->audiostream->volsend){
2835 ms_filter_call_method(call->audiostream->volsend,MS_VOLUME_GET_GAIN,&gain);
2836 }else ms_warning("Could not get gain: gain control wasn't activated. ");
2838 return gain==0 || call->audio_muted;
2841 // returns rtp transmission status for an active stream
2842 // if audio is muted and config parameter rtp_no_xmit_on_audio_mute
2843 // was set on then rtp transmission is also muted
2844 bool_t linphone_core_is_rtp_muted(LinphoneCore *lc){
2845 LinphoneCall *call=linphone_core_get_current_call(lc);
2847 ms_warning("linphone_core_is_mic_muted(): No current call !");
2850 if( linphone_core_get_rtp_no_xmit_on_audio_mute(lc)){
2851 return call->audio_muted;
2856 void linphone_core_enable_agc(LinphoneCore *lc, bool_t val){
2857 lc->sound_conf.agc=val;
2860 bool_t linphone_core_agc_enabled(const LinphoneCore *lc){
2861 return lc->sound_conf.agc;
2865 * Send the specified dtmf.
2867 * @ingroup media_parameters
2868 * This function only works during calls. The dtmf is automatically played to the user.
2869 * @param lc The LinphoneCore object
2870 * @param dtmf The dtmf name specified as a char, such as '0', '#' etc...
2873 void linphone_core_send_dtmf(LinphoneCore *lc, char dtmf)
2875 LinphoneCall *call=linphone_core_get_current_call(lc);
2877 ms_warning("linphone_core_send_dtmf(): no active call");
2880 /*By default we send DTMF RFC2833 if we do not have enabled SIP_INFO but we can also send RFC2833 and SIP_INFO*/
2881 if (linphone_core_get_use_rfc2833_for_dtmf(lc)!=0 || linphone_core_get_use_info_for_dtmf(lc)==0)
2884 if (call->audiostream!=NULL){
2885 audio_stream_send_dtmf(call->audiostream,dtmf);
2889 ms_error("we cannot send RFC2833 dtmf when we are not in communication");
2892 if (linphone_core_get_use_info_for_dtmf(lc)!=0){
2893 /* Out of Band DTMF (use INFO method) */
2894 sal_call_send_dtmf(call->op,dtmf);
2898 void linphone_core_set_stun_server(LinphoneCore *lc, const char *server){
2899 if (lc->net_conf.stun_server!=NULL)
2900 ms_free(lc->net_conf.stun_server);
2902 lc->net_conf.stun_server=ms_strdup(server);
2903 else lc->net_conf.stun_server=NULL;
2906 const char * linphone_core_get_stun_server(const LinphoneCore *lc){
2907 return lc->net_conf.stun_server;
2910 const char * linphone_core_get_relay_addr(const LinphoneCore *lc){
2911 return lc->net_conf.relay;
2914 int linphone_core_set_relay_addr(LinphoneCore *lc, const char *addr){
2915 if (lc->net_conf.relay!=NULL){
2916 ms_free(lc->net_conf.relay);
2917 lc->net_conf.relay=NULL;
2920 lc->net_conf.relay=ms_strdup(addr);
2925 void linphone_core_set_nat_address(LinphoneCore *lc, const char *addr)
2927 if (lc->net_conf.nat_address!=NULL){
2928 ms_free(lc->net_conf.nat_address);
2930 if (addr!=NULL) lc->net_conf.nat_address=ms_strdup(addr);
2931 else lc->net_conf.nat_address=NULL;
2932 if (lc->sip_conf.contact) update_primary_contact(lc);
2935 const char *linphone_core_get_nat_address(const LinphoneCore *lc)
2937 return lc->net_conf.nat_address;
2940 void linphone_core_set_firewall_policy(LinphoneCore *lc, LinphoneFirewallPolicy pol){
2941 lc->net_conf.firewall_policy=pol;
2942 if (lc->sip_conf.contact) update_primary_contact(lc);
2945 LinphoneFirewallPolicy linphone_core_get_firewall_policy(const LinphoneCore *lc){
2946 return lc->net_conf.firewall_policy;
2950 * Get the list of call logs (past calls).
2952 * @ingroup call_logs
2954 const MSList * linphone_core_get_call_logs(LinphoneCore *lc){
2956 return lc->call_logs;
2960 * Erase the call log.
2962 * @ingroup call_logs
2964 void linphone_core_clear_call_logs(LinphoneCore *lc){
2966 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
2967 lc->call_logs=ms_list_free(lc->call_logs);
2968 call_logs_write_to_config_file(lc);
2971 static void toggle_video_preview(LinphoneCore *lc, bool_t val){
2972 #ifdef VIDEO_ENABLED
2974 if (lc->previewstream==NULL){
2975 lc->previewstream=video_preview_start(lc->video_conf.device,
2976 lc->video_conf.vsize);
2979 if (lc->previewstream!=NULL){
2980 video_preview_stop(lc->previewstream);
2981 lc->previewstream=NULL;
2988 * Enables video globally.
2990 * @ingroup media_parameters
2991 * This function does not have any effect during calls. It just indicates LinphoneCore to
2992 * initiate future calls with video or not. The two boolean parameters indicate in which
2993 * direction video is enabled. Setting both to false disables video entirely.
2995 * @param vcap_enabled indicates whether video capture is enabled
2996 * @param display_enabled indicates whether video display should be shown
2999 void linphone_core_enable_video(LinphoneCore *lc, bool_t vcap_enabled, bool_t display_enabled){
3000 #ifndef VIDEO_ENABLED
3001 if (vcap_enabled || display_enabled)
3002 ms_warning("This version of linphone was built without video support.");
3004 lc->video_conf.capture=vcap_enabled;
3005 lc->video_conf.display=display_enabled;
3007 /* need to re-apply network bandwidth settings*/
3008 linphone_core_set_download_bandwidth(lc,
3009 linphone_core_get_download_bandwidth(lc));
3010 linphone_core_set_upload_bandwidth(lc,
3011 linphone_core_get_upload_bandwidth(lc));
3015 * Returns TRUE if video is enabled, FALSE otherwise.
3016 * @ingroup media_parameters
3018 bool_t linphone_core_video_enabled(LinphoneCore *lc){
3019 return (lc->video_conf.display || lc->video_conf.capture);
3023 * Controls video preview enablement.
3025 * @ingroup media_parameters
3026 * Video preview refers to the action of displaying the local webcam image
3027 * to the user while not in call.
3029 void linphone_core_enable_video_preview(LinphoneCore *lc, bool_t val){
3030 lc->video_conf.show_local=val;
3034 * Returns TRUE if video previewing is enabled.
3035 * @ingroup media_parameters
3037 bool_t linphone_core_video_preview_enabled(const LinphoneCore *lc){
3038 return lc->video_conf.show_local;
3042 * Enables or disable self view during calls.
3044 * @ingroup media_parameters
3045 * Self-view refers to having local webcam image inserted in corner
3046 * of the video window during calls.
3047 * This function works at any time, including during calls.
3049 void linphone_core_enable_self_view(LinphoneCore *lc, bool_t val){
3050 #ifdef VIDEO_ENABLED
3051 LinphoneCall *call=linphone_core_get_current_call (lc);
3052 lc->video_conf.selfview=val;
3053 if (call && call->videostream){
3054 video_stream_enable_self_view(call->videostream,val);
3060 * Returns TRUE if self-view is enabled, FALSE otherwise.
3062 * @ingroup media_parameters
3064 * Refer to linphone_core_enable_self_view() for details.
3066 bool_t linphone_core_self_view_enabled(const LinphoneCore *lc){
3067 return lc->video_conf.selfview;
3071 * Sets the active video device.
3073 * @ingroup media_parameters
3074 * @param id the name of the video device as returned by linphone_core_get_video_devices()
3076 int linphone_core_set_video_device(LinphoneCore *lc, const char *id){
3077 MSWebCam *olddev=lc->video_conf.device;
3080 lc->video_conf.device=ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),id);
3081 if (lc->video_conf.device==NULL){
3082 ms_warning("Could not found video device %s",id);
3085 if (lc->video_conf.device==NULL)
3086 lc->video_conf.device=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());
3087 if (olddev!=NULL && olddev!=lc->video_conf.device){
3088 toggle_video_preview(lc,FALSE);/*restart the video local preview*/
3090 if (lc->ready && lc->video_conf.device){
3091 vd=ms_web_cam_get_string_id(lc->video_conf.device);
3092 if (vd && strstr(vd,"Static picture")!=NULL){
3095 lp_config_set_string(lc->config,"video","device",vd);
3101 * Returns the name of the currently active video device.
3103 * @ingroup media_parameters
3105 const char *linphone_core_get_video_device(const LinphoneCore *lc){
3106 if (lc->video_conf.device) return ms_web_cam_get_string_id(lc->video_conf.device);
3110 int linphone_core_set_static_picture(LinphoneCore *lc, const char *path) {
3111 #ifdef VIDEO_ENABLED
3112 VideoStream *vs = NULL;
3113 LinphoneCall *call=linphone_core_get_current_call (lc);
3114 /* Select the video stream from the call in the first place */
3115 if (call && call->videostream) {
3116 vs = call->videostream;
3118 /* If not in call, select the video stream from the preview */
3119 if (vs == NULL && lc->previewstream) {
3120 vs = lc->previewstream;
3123 /* If we have a video stream (either preview, either from call), we
3124 have a source and it is using the static picture filter, then
3125 force the filter to use that picture. */
3126 if (vs && vs->source) {
3127 if (ms_filter_get_id(vs->source) == MS_STATIC_IMAGE_ID) {
3128 ms_filter_call_method(vs->source, MS_FILTER_SET_IMAGE,
3133 /* Tell the static image filter to use that image from now on so
3134 that the image will be used next time it has to be read */
3135 ms_static_image_set_default_image(path);
3137 ms_warning("Video support not compiled.");
3143 * Returns the native window handle of the video window, casted as an unsigned long.
3145 * @ingroup media_parameters
3147 unsigned long linphone_core_get_native_video_window_id(const LinphoneCore *lc){
3148 #ifdef VIDEO_ENABLED
3149 LinphoneCall *call=linphone_core_get_current_call (lc);
3150 if (call && call->videostream)
3151 return video_stream_get_native_window_id(call->videostream);
3152 if (lc->previewstream)
3153 return video_stream_get_native_window_id(lc->previewstream);
3158 static MSVideoSizeDef supported_resolutions[]={
3159 { {MS_VIDEO_SIZE_SVGA_W,MS_VIDEO_SIZE_SVGA_H} , "svga" },
3160 { {MS_VIDEO_SIZE_4CIF_W,MS_VIDEO_SIZE_4CIF_H} , "4cif" },
3161 { {MS_VIDEO_SIZE_VGA_W,MS_VIDEO_SIZE_VGA_H} , "vga" },
3162 { {MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H} , "cif" },
3163 { {MS_VIDEO_SIZE_QVGA_W,MS_VIDEO_SIZE_QVGA_H} , "qvga" },
3164 { {MS_VIDEO_SIZE_QCIF_W,MS_VIDEO_SIZE_QCIF_H} , "qcif" },
3169 * Returns the zero terminated table of supported video resolutions.
3171 * @ingroup media_parameters
3173 const MSVideoSizeDef *linphone_core_get_supported_video_sizes(LinphoneCore *lc){
3174 return supported_resolutions;
3177 static MSVideoSize video_size_get_by_name(const char *name){
3178 MSVideoSizeDef *pdef=supported_resolutions;
3179 MSVideoSize null_vsize={0,0};
3180 for(;pdef->name!=NULL;pdef++){
3181 if (strcasecmp(name,pdef->name)==0){
3185 ms_warning("Video resolution %s is not supported in linphone.",name);
3189 static const char *video_size_get_name(MSVideoSize vsize){
3190 MSVideoSizeDef *pdef=supported_resolutions;
3191 for(;pdef->name!=NULL;pdef++){
3192 if (pdef->vsize.width==vsize.width && pdef->vsize.height==vsize.height){
3199 static bool_t video_size_supported(MSVideoSize vsize){
3200 if (video_size_get_name(vsize)) return TRUE;
3201 ms_warning("Video resolution %ix%i is not supported in linphone.",vsize.width,vsize.height);
3206 * Sets the preferred video size.
3208 * @ingroup media_parameters
3209 * This applies only to the stream that is captured and sent to the remote party,
3210 * since we accept all standard video size on the receive path.
3212 void linphone_core_set_preferred_video_size(LinphoneCore *lc, MSVideoSize vsize){
3213 if (video_size_supported(vsize)){
3214 MSVideoSize oldvsize=lc->video_conf.vsize;
3215 lc->video_conf.vsize=vsize;
3216 if (!ms_video_size_equal(oldvsize,vsize) && lc->previewstream!=NULL){
3217 toggle_video_preview(lc,FALSE);
3218 toggle_video_preview(lc,TRUE);
3221 lp_config_set_string(lc->config,"video","size",video_size_get_name(vsize));
3226 * Sets the preferred video size by its name.
3228 * @ingroup media_parameters
3229 * This is identical to linphone_core_set_preferred_video_size() except
3230 * that it takes the name of the video resolution as input.
3231 * Video resolution names are: qcif, svga, cif, vga, 4cif, svga ...
3233 void linphone_core_set_preferred_video_size_by_name(LinphoneCore *lc, const char *name){
3234 MSVideoSize vsize=video_size_get_by_name(name);
3235 MSVideoSize default_vsize={MS_VIDEO_SIZE_CIF_W,MS_VIDEO_SIZE_CIF_H};
3236 if (vsize.width!=0) linphone_core_set_preferred_video_size(lc,vsize);
3237 else linphone_core_set_preferred_video_size(lc,default_vsize);
3241 * Returns the current preferred video size for sending.
3243 * @ingroup media_parameters
3245 MSVideoSize linphone_core_get_preferred_video_size(LinphoneCore *lc){
3246 return lc->video_conf.vsize;
3250 * Ask the core to stream audio from and to files, instead of using the soundcard.
3252 void linphone_core_use_files(LinphoneCore *lc, bool_t yesno){
3253 lc->use_files=yesno;
3257 * Sets a wav file to be played when putting somebody on hold,
3258 * or when files are used instead of soundcards (see linphone_core_use_files()).
3260 * The file must be a 16 bit linear wav file.
3262 void linphone_core_set_play_file(LinphoneCore *lc, const char *file){
3263 LinphoneCall *call=linphone_core_get_current_call(lc);
3264 if (lc->play_file!=NULL){
3265 ms_free(lc->play_file);
3269 lc->play_file=ms_strdup(file);
3270 if (call && call->audiostream && call->audiostream->ticker)
3271 audio_stream_play(call->audiostream,file);
3277 * Sets a wav file where incoming stream is to be recorded,
3278 * when files are used instead of soundcards (see linphone_core_use_files()).
3280 * The file must be a 16 bit linear wav file.
3282 void linphone_core_set_record_file(LinphoneCore *lc, const char *file){
3283 LinphoneCall *call=linphone_core_get_current_call(lc);
3284 if (lc->rec_file!=NULL){
3285 ms_free(lc->rec_file);
3289 lc->rec_file=ms_strdup(file);
3290 if (call && call->audiostream)
3291 audio_stream_record(call->audiostream,file);
3295 static MSFilter *get_dtmf_gen(LinphoneCore *lc){
3296 LinphoneCall *call=linphone_core_get_current_call (lc);
3298 AudioStream *stream=call->audiostream;
3300 return stream->dtmfgen;
3303 if (lc->ringstream==NULL){
3304 MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard;
3305 lc->ringstream=ring_start(NULL,0,ringcard);
3306 lc->dmfs_playing_start_time=time(NULL);
3308 if (lc->dmfs_playing_start_time!=0)
3309 lc->dmfs_playing_start_time=time(NULL);
3311 return lc->ringstream->gendtmf;
3315 * Plays a dtmf to the local user.
3317 void linphone_core_play_dtmf(LinphoneCore *lc, char dtmf, int duration_ms){
3318 MSFilter *f=get_dtmf_gen(lc);
3320 ms_error("No dtmf generator at this time !");
3324 ms_filter_call_method(f, MS_DTMF_GEN_PLAY, &dtmf);
3325 else ms_filter_call_method(f, MS_DTMF_GEN_START, &dtmf);
3329 * Stops playing a dtmf started by linphone_core_play_dtmf().
3331 void linphone_core_stop_dtmf(LinphoneCore *lc){
3332 MSFilter *f=get_dtmf_gen(lc);
3333 ms_filter_call_method_noarg (f, MS_DTMF_GEN_STOP);
3338 * Retrieves the user pointer that was given to linphone_core_new()
3340 * @ingroup initializing
3342 void *linphone_core_get_user_data(LinphoneCore *lc){
3346 int linphone_core_get_mtu(const LinphoneCore *lc){
3347 return lc->net_conf.mtu;
3350 void linphone_core_set_mtu(LinphoneCore *lc, int mtu){
3351 lc->net_conf.mtu=mtu;
3354 ms_error("MTU too small !");
3358 ms_message("MTU is supposed to be %i, rtp payload max size will be %i",mtu, ms_get_payload_max_size());
3359 }else ms_set_mtu(0);//use mediastreamer2 default value
3362 void linphone_core_set_waiting_callback(LinphoneCore *lc, LinphoneWaitingCallback cb, void *user_context){
3364 lc->wait_ctx=user_context;
3367 void linphone_core_start_waiting(LinphoneCore *lc, const char *purpose){
3369 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingStart,purpose,0);
3373 void linphone_core_update_progress(LinphoneCore *lc, const char *purpose, float progress){
3375 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingProgress,purpose,progress);
3385 void linphone_core_stop_waiting(LinphoneCore *lc){
3387 lc->wait_ctx=lc->wait_cb(lc,lc->wait_ctx,LinphoneWaitingFinished,NULL,0);
3391 void linphone_core_set_audio_transports(LinphoneCore *lc, RtpTransport *rtp, RtpTransport *rtcp){
3397 * Retrieve RTP statistics regarding current call.
3398 * @param local RTP statistics computed locally.
3399 * @param remote RTP statistics computed by far end (obtained via RTCP feedback).
3401 * @note Remote RTP statistics is not implemented yet.
3403 * @returns 0 or -1 if no call is running.
3406 int linphone_core_get_current_call_stats(LinphoneCore *lc, rtp_stats_t *local, rtp_stats_t *remote){
3407 LinphoneCall *call=linphone_core_get_current_call (lc);
3409 if (call->audiostream!=NULL){
3410 memset(remote,0,sizeof(*remote));
3411 audio_stream_get_local_rtp_stats (call->audiostream,local);
3418 void net_config_uninit(LinphoneCore *lc)
3420 net_config_t *config=&lc->net_conf;
3421 lp_config_set_int(lc->config,"net","download_bw",config->download_bw);
3422 lp_config_set_int(lc->config,"net","upload_bw",config->upload_bw);
3424 if (config->stun_server!=NULL){
3425 lp_config_set_string(lc->config,"net","stun_server",config->stun_server);
3426 ms_free(lc->net_conf.stun_server);
3428 if (config->nat_address!=NULL){
3429 lp_config_set_string(lc->config,"net","nat_address",config->nat_address);
3430 ms_free(lc->net_conf.nat_address);
3432 lp_config_set_int(lc->config,"net","firewall_policy",config->firewall_policy);
3433 lp_config_set_int(lc->config,"net","mtu",config->mtu);
3437 void sip_config_uninit(LinphoneCore *lc)
3441 sip_config_t *config=&lc->sip_conf;
3442 lp_config_set_int(lc->config,"sip","sip_port",config->transports.udp_port);
3443 lp_config_set_int(lc->config,"sip","guess_hostname",config->guess_hostname);
3444 lp_config_set_string(lc->config,"sip","contact",config->contact);
3445 lp_config_set_int(lc->config,"sip","inc_timeout",config->inc_timeout);
3446 lp_config_set_int(lc->config,"sip","use_info",config->use_info);
3447 lp_config_set_int(lc->config,"sip","use_rfc2833",config->use_rfc2833);
3448 lp_config_set_int(lc->config,"sip","use_ipv6",config->ipv6_enabled);
3449 lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
3452 lp_config_set_int(lc->config,"sip","default_proxy",linphone_core_get_default_proxy(lc,NULL));
3454 for(elem=config->proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3455 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
3456 linphone_proxy_config_write_to_config_file(lc->config,cfg,i);
3457 linphone_proxy_config_edit(cfg); /* to unregister */
3463 sal_iterate(lc->sal);
3472 ms_list_for_each(config->proxies,(void (*)(void*)) linphone_proxy_config_destroy);
3473 ms_list_free(config->proxies);
3474 config->proxies=NULL;
3476 linphone_proxy_config_write_to_config_file(lc->config,NULL,i); /*mark the end */
3478 for(elem=lc->auth_info,i=0;elem!=NULL;elem=ms_list_next(elem),i++){
3479 LinphoneAuthInfo *ai=(LinphoneAuthInfo*)(elem->data);
3480 linphone_auth_info_write_config(lc->config,ai,i);
3482 linphone_auth_info_write_config(lc->config,NULL,i); /* mark the end */
3483 ms_list_for_each(lc->auth_info,(void (*)(void*))linphone_auth_info_destroy);
3484 ms_list_free(lc->auth_info);
3487 sal_uninit(lc->sal);
3490 if (lc->sip_conf.guessed_contact)
3491 ms_free(lc->sip_conf.guessed_contact);
3492 if (config->contact)
3493 ms_free(config->contact);
3497 void rtp_config_uninit(LinphoneCore *lc)
3499 rtp_config_t *config=&lc->rtp_conf;
3500 lp_config_set_int(lc->config,"rtp","audio_rtp_port",config->audio_rtp_port);
3501 lp_config_set_int(lc->config,"rtp","video_rtp_port",config->video_rtp_port);
3502 lp_config_set_int(lc->config,"rtp","audio_jitt_comp",config->audio_jitt_comp);
3503 lp_config_set_int(lc->config,"rtp","video_jitt_comp",config->video_jitt_comp);
3504 lp_config_set_int(lc->config,"rtp","nortp_timeout",config->nortp_timeout);
3507 void sound_config_uninit(LinphoneCore *lc)
3509 sound_config_t *config=&lc->sound_conf;
3510 ms_free(config->cards);
3512 lp_config_set_string(lc->config,"sound","remote_ring",config->remote_ring);
3514 if (config->local_ring) ms_free(config->local_ring);
3515 if (config->remote_ring) ms_free(config->remote_ring);
3516 ms_snd_card_manager_destroy();
3519 void video_config_uninit(LinphoneCore *lc)
3521 lp_config_set_int(lc->config,"video","enabled",linphone_core_video_enabled(lc));
3522 lp_config_set_string(lc->config,"video","size",video_size_get_name(linphone_core_get_preferred_video_size(lc)));
3523 lp_config_set_int(lc->config,"video","display",lc->video_conf.display);
3524 lp_config_set_int(lc->config,"video","capture",lc->video_conf.capture);
3525 lp_config_set_int(lc->config,"video","show_local",linphone_core_video_preview_enabled(lc));
3526 lp_config_set_int(lc->config,"video","self_view",linphone_core_self_view_enabled(lc));
3527 if (lc->video_conf.cams)
3528 ms_free(lc->video_conf.cams);
3531 void codecs_config_uninit(LinphoneCore *lc)
3534 codecs_config_t *config=&lc->codecs_conf;
3539 for(node=config->audio_codecs;node!=NULL;node=ms_list_next(node)){
3540 pt=(PayloadType*)(node->data);
3541 sprintf(key,"audio_codec_%i",index);
3542 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3543 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3544 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3547 sprintf(key,"audio_codec_%i",index);
3548 lp_config_clean_section (lc->config,key);
3551 for(node=config->video_codecs;node!=NULL;node=ms_list_next(node)){
3552 pt=(PayloadType*)(node->data);
3553 sprintf(key,"video_codec_%i",index);
3554 lp_config_set_string(lc->config,key,"mime",pt->mime_type);
3555 lp_config_set_int(lc->config,key,"rate",pt->clock_rate);
3556 lp_config_set_int(lc->config,key,"enabled",linphone_core_payload_type_enabled(lc,pt));
3557 lp_config_set_string(lc->config,key,"recv_fmtp",pt->recv_fmtp);
3560 sprintf(key,"video_codec_%i",index);
3561 lp_config_clean_section (lc->config,key);
3563 ms_list_free(lc->codecs_conf.audio_codecs);
3564 ms_list_free(lc->codecs_conf.video_codecs);
3567 void ui_config_uninit(LinphoneCore* lc)
3570 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_destroy);
3571 ms_list_free(lc->friends);
3577 * Returns the LpConfig object used to manage the storage (config) file.
3580 * The application can use the LpConfig object to insert its own private
3581 * sections and pairs of key=value in the configuration file.
3584 LpConfig *linphone_core_get_config(LinphoneCore *lc){
3588 static void linphone_core_uninit(LinphoneCore *lc)
3592 LinphoneCall *the_call = lc->calls->data;
3593 linphone_core_terminate_call(lc,the_call);
3594 linphone_core_iterate(lc);
3603 ms_list_for_each(lc->friends,(void (*)(void *))linphone_friend_close_subscriptions);
3604 linphone_core_set_state(lc,LinphoneGlobalShutdown,"Shutting down");
3605 #ifdef VIDEO_ENABLED
3606 if (lc->previewstream!=NULL){
3607 video_preview_stop(lc->previewstream);
3608 lc->previewstream=NULL;
3611 ms_event_queue_destroy(lc->msevq);
3612 /* save all config */
3613 net_config_uninit(lc);
3614 sip_config_uninit(lc);
3615 rtp_config_uninit(lc);
3616 sound_config_uninit(lc);
3617 video_config_uninit(lc);
3618 codecs_config_uninit(lc);
3619 ui_config_uninit(lc);
3620 if (lp_config_needs_commit(lc->config)) lp_config_sync(lc->config);
3621 lp_config_destroy(lc->config);
3622 lc->config = NULL; /* Mark the config as NULL to block further calls */
3623 sip_setup_unregister_all();
3625 ms_list_for_each(lc->call_logs,(void (*)(void*))linphone_call_log_destroy);
3626 lc->call_logs=ms_list_free(lc->call_logs);
3628 linphone_core_free_payload_types();
3631 linphone_core_set_state(lc,LinphoneGlobalOff,"Off");
3634 static void set_network_reachable(LinphoneCore* lc,bool_t isReachable){
3635 ms_message("Network state is now [%s]",isReachable?"UP":"DOWN");
3636 // second get the list of available proxies
3637 const MSList *elem=linphone_core_get_proxy_config_list(lc);
3638 for(;elem!=NULL;elem=elem->next){
3639 LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data;
3640 if (linphone_proxy_config_register_enabled(cfg) ) {
3648 lc->network_reachable=isReachable;
3651 void linphone_core_set_network_reachable(LinphoneCore* lc,bool_t isReachable) {
3652 //first disable automatic mode
3653 if (lc->auto_net_state_mon) {
3654 ms_message("Disabling automatic network state monitoring");
3655 lc->auto_net_state_mon=FALSE;
3657 set_network_reachable(lc,isReachable);
3660 bool_t linphone_core_is_network_reachabled(LinphoneCore* lc) {
3661 return lc->network_reachable;
3663 ortp_socket_t linphone_core_get_sip_socket(LinphoneCore *lc){
3664 return sal_get_socket(lc->sal);
3667 * Destroys a LinphoneCore
3669 * @ingroup initializing
3671 void linphone_core_destroy(LinphoneCore *lc){
3672 linphone_core_uninit(lc);
3676 * Get the number of Call
3678 * @ingroup call_control
3680 int linphone_core_get_calls_nb(const LinphoneCore *lc){
3681 return ms_list_size(lc->calls);;
3685 * Check if we do not have exceed the number of simultaneous call
3687 * @ingroup call_control
3689 bool_t linphone_core_can_we_add_call(LinphoneCore *lc)
3691 if(linphone_core_get_calls_nb(lc) < NB_MAX_CALLS)
3693 ms_error("Maximum amount of simultaneous calls reached !");
3698 int linphone_core_add_call( LinphoneCore *lc, LinphoneCall *call)
3700 if(linphone_core_can_we_add_call(lc))
3702 lc->calls = ms_list_append(lc->calls,call);
3708 int linphone_core_del_call( LinphoneCore *lc, LinphoneCall *call)
3711 MSList *the_calls = lc->calls;
3713 it=ms_list_find(the_calls,call);
3716 the_calls = ms_list_remove_link(the_calls,it);
3720 ms_warning("could not find the call into the list\n");
3723 lc->calls = the_calls;
3727 static PayloadType* find_payload_type_from_list(const char* type, int rate,const MSList* from) {
3729 for(elem=from;elem!=NULL;elem=elem->next){
3730 PayloadType *pt=(PayloadType*)elem->data;
3731 if ((strcmp((char*)type, payload_type_get_mime(pt)) == 0) && rate==pt->clock_rate) {
3739 * Get payload type from mime type and clock rate
3740 * @ingroup media_parameters
3741 * This function searches in audio and video codecs for the given payload type name and clockrate.
3742 * Returns NULL if not found.
3744 PayloadType* linphone_core_find_payload_type(LinphoneCore* lc, const char* type, int rate) {
3745 PayloadType* result = find_payload_type_from_list(type, rate, linphone_core_get_audio_codecs(lc));
3749 result = find_payload_type_from_list(type, rate, linphone_core_get_video_codecs(lc));