4 Copyright (C) 2010 Belledonne Communications SARL
5 (simon.morlat@linphone.org)
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "linphonecore.h"
28 #include <ortp/event.h>
32 #include "mediastreamer2/mediastream.h"
33 #include "mediastreamer2/msvolume.h"
34 #include "mediastreamer2/msequalizer.h"
35 #include "mediastreamer2/msfileplayer.h"
36 #include "mediastreamer2/msjpegwriter.h"
37 #include "mediastreamer2/mseventqueue.h"
40 static MSWebCam *get_nowebcam_device(){
41 return ms_web_cam_manager_get_cam(ms_web_cam_manager_get(),"StaticImage: Static picture");
45 static bool_t generate_b64_crypto_key(int key_length, char* key_out) {
47 uint8_t* tmp = (uint8_t*) malloc(key_length);
48 if (crypto_get_random(tmp, key_length)) {
49 ms_error("Failed to generate random key");
54 b64_size = b64_encode((const char*)tmp, key_length, NULL, 0);
56 ms_error("Failed to b64 encode key");
60 key_out[b64_size] = '\0';
61 b64_encode((const char*)tmp, key_length, key_out, 40);
66 LinphoneCore *linphone_call_get_core(const LinphoneCall *call){
70 static const char* get_hexa_zrtp_identifier(LinphoneCore *lc){
71 const char *confZid=lp_config_get_string(lc->config,"rtp","zid",NULL);
72 if (confZid != NULL) {
76 snprintf(zidstr,sizeof(zidstr),"%x-%x-%x",rand(),rand(),rand());
77 lp_config_set_string(lc->config,"rtp","zid",zidstr);
78 return lp_config_get_string(lc->config,"rtp","zid",NULL);
82 const char* linphone_call_get_authentication_token(LinphoneCall *call){
83 return call->auth_token;
86 bool_t linphone_call_get_authentication_token_verified(LinphoneCall *call){
87 return call->auth_token_verified;
89 bool_t linphone_call_are_all_streams_encrypted(LinphoneCall *call) {
90 // Check ZRTP encryption in audiostream
91 if (!call->audiostream_encrypted) {
96 // If video enabled, check ZRTP encryption in videostream
97 const LinphoneCallParams *params=linphone_call_get_current_params(call);
98 if (params->has_video && !call->videostream_encrypted) {
106 void propagate_encryption_changed(LinphoneCall *call){
107 if (call->core->vtable.call_encryption_changed == NULL) return;
109 if (!linphone_call_are_all_streams_encrypted(call)) {
110 ms_message("Some streams are not encrypted");
111 call->core->vtable.call_encryption_changed(call->core, call, FALSE, call->auth_token);
113 ms_message("All streams are encrypted");
114 call->core->vtable.call_encryption_changed(call->core, call, TRUE, call->auth_token);
119 static void linphone_call_videostream_encryption_changed(void *data, bool_t encrypted){
120 ms_message("Video stream is %s", encrypted ? "encrypted" : "not encrypted");
122 LinphoneCall *call = (LinphoneCall *)data;
123 call->videostream_encrypted=encrypted;
124 propagate_encryption_changed(call);
128 static void linphone_call_audiostream_encryption_changed(void *data, bool_t encrypted) {
129 char status[255]={0};
130 ms_message("Audio stream is %s ", encrypted ? "encrypted" : "not encrypted");
132 LinphoneCall *call = (LinphoneCall *)data;
133 call->audiostream_encrypted=encrypted;
135 if (encrypted && call->core->vtable.display_status != NULL) {
136 snprintf(status,sizeof(status)-1,_("Authentication token is %s"),call->auth_token);
137 call->core->vtable.display_status(call->core, status);
140 propagate_encryption_changed(call);
144 // Enable video encryption
145 const LinphoneCallParams *params=linphone_call_get_current_params(call);
146 if (params->has_video) {
147 ms_message("Trying to enable encryption on video stream");
148 OrtpZrtpParams params;
149 params.zid=get_hexa_zrtp_identifier(call->core);
150 params.zid_file=NULL; //unused
151 video_stream_enable_zrtp(call->videostream,call->audiostream,¶ms);
157 static void linphone_call_audiostream_auth_token_ready(void *data, const char* auth_token, bool_t verified) {
158 LinphoneCall *call=(LinphoneCall *)data;
159 if (call->auth_token != NULL)
160 ms_free(call->auth_token);
162 call->auth_token=ms_strdup(auth_token);
163 call->auth_token_verified=verified;
165 ms_message("Authentication token is %s (%s)", auth_token, verified?"verified":"unverified");
169 static MSList *make_codec_list(LinphoneCore *lc, const MSList *codecs, int bandwidth_limit){
172 for(it=codecs;it!=NULL;it=it->next){
173 PayloadType *pt=(PayloadType*)it->data;
174 if (pt->flags & PAYLOAD_TYPE_ENABLED){
175 if (bandwidth_limit>0 && !linphone_core_is_payload_type_usable_for_bandwidth(lc,pt,bandwidth_limit)){
176 ms_message("Codec %s/%i eliminated because of audio bandwidth constraint.",pt->mime_type,pt->clock_rate);
179 if (linphone_core_check_payload_type_usability(lc,pt)){
180 l=ms_list_append(l,payload_type_clone(pt));
187 static SalMediaDescription *_create_local_media_description(LinphoneCore *lc, LinphoneCall *call, unsigned int session_id, unsigned int session_ver){
191 const char *me=linphone_core_get_identity(lc);
192 LinphoneAddress *addr=linphone_address_new(me);
193 const char *username=linphone_address_get_username (addr);
194 SalMediaDescription *md=sal_media_description_new();
196 md->session_id=session_id;
197 md->session_ver=session_ver;
199 strncpy(md->addr,call->localip,sizeof(md->addr));
200 strncpy(md->username,username,sizeof(md->username));
201 md->bandwidth=linphone_core_get_download_bandwidth(lc);
203 /*set audio capabilities */
204 strncpy(md->streams[0].addr,call->localip,sizeof(md->streams[0].addr));
205 md->streams[0].port=call->audio_port;
206 md->streams[0].proto=(call->params.media_encryption == LinphoneMediaEncryptionSRTP) ?
207 SalProtoRtpSavp : SalProtoRtpAvp;
208 md->streams[0].type=SalAudio;
209 md->streams[0].ptime=lc->net_conf.down_ptime;
210 l=make_codec_list(lc,lc->codecs_conf.audio_codecs,call->params.audio_bw);
211 pt=payload_type_clone(rtp_profile_get_payload_from_mime(&av_profile,"telephone-event"));
212 l=ms_list_append(l,pt);
213 md->streams[0].payloads=l;
216 if (call->params.has_video){
218 md->streams[1].port=call->video_port;
219 md->streams[1].proto=md->streams[0].proto;
220 md->streams[1].type=SalVideo;
221 l=make_codec_list(lc,lc->codecs_conf.video_codecs,0);
222 md->streams[1].payloads=l;
225 for(i=0; i<md->nstreams; i++) {
226 if (md->streams[i].proto == SalProtoRtpSavp) {
227 md->streams[i].crypto[0].tag = 1;
228 md->streams[i].crypto[0].algo = AES_128_SHA1_80;
229 if (!generate_b64_crypto_key(30, md->streams[i].crypto[0].master_key))
230 md->streams[i].crypto[0].algo = 0;
231 md->streams[i].crypto[1].tag = 2;
232 md->streams[i].crypto[1].algo = AES_128_SHA1_32;
233 if (!generate_b64_crypto_key(30, md->streams[i].crypto[1].master_key))
234 md->streams[i].crypto[1].algo = 0;
235 md->streams[i].crypto[2].algo = 0;
239 linphone_address_destroy(addr);
243 void update_local_media_description(LinphoneCore *lc, LinphoneCall *call, SalMediaDescription **md){
245 *md = _create_local_media_description(lc,call,0,0);
247 unsigned int id = (*md)->session_id;
248 unsigned int ver = (*md)->session_ver+1;
249 sal_media_description_unref(*md);
250 *md = _create_local_media_description(lc,call,id,ver);
254 SalMediaDescription *create_local_media_description(LinphoneCore *lc, LinphoneCall *call){
255 unsigned int id=rand() & 0xfff;
256 return _create_local_media_description(lc,call,id,id);
259 static int find_port_offset(LinphoneCore *lc){
263 bool_t already_used=FALSE;
264 for(offset=0;offset<100;offset+=2){
265 audio_port=linphone_core_get_audio_port (lc)+offset;
267 for(elem=lc->calls;elem!=NULL;elem=elem->next){
268 LinphoneCall *call=(LinphoneCall*)elem->data;
269 if (call->audio_port==audio_port) {
274 if (!already_used) break;
277 ms_error("Could not find any free port !");
283 static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){
286 call->state=LinphoneCallIdle;
287 call->start_time=time(NULL);
288 call->media_start_time=0;
289 call->log=linphone_call_log_new(call, from, to);
290 call->owns_call_log=TRUE;
291 linphone_core_notify_all_friends(call->core,LinphoneStatusOnThePhone);
292 port_offset=find_port_offset (call->core);
293 if (port_offset==-1) return;
294 call->audio_port=linphone_core_get_audio_port(call->core)+port_offset;
295 call->video_port=linphone_core_get_video_port(call->core)+port_offset;
299 static void discover_mtu(LinphoneCore *lc, const char *remote){
301 if (lc->net_conf.mtu==0 ){
302 /*attempt to discover mtu*/
303 mtu=ms_discover_mtu(remote);
306 ms_message("Discovered mtu is %i, RTP payload max size is %i",
307 mtu, ms_get_payload_max_size());
312 LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, const LinphoneCallParams *params)
314 LinphoneCall *call=ms_new0(LinphoneCall,1);
315 call->dir=LinphoneCallOutgoing;
316 call->op=sal_op_new(lc->sal);
317 sal_op_set_user_pointer(call->op,call);
319 linphone_core_get_local_ip(lc,linphone_address_get_domain(to),call->localip);
320 linphone_call_init_common(call,from,to);
321 call->params=*params;
322 call->localdesc=create_local_media_description (lc,call);
323 call->camera_active=params->has_video;
324 if (linphone_core_get_firewall_policy(call->core)==LinphonePolicyUseStun)
325 linphone_core_run_stun_tests(call->core,call);
326 discover_mtu(lc,linphone_address_get_domain (to));
327 if (params->referer){
328 sal_call_set_referer (call->op,params->referer->op);
333 LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){
334 LinphoneCall *call=ms_new0(LinphoneCall,1);
337 call->dir=LinphoneCallIncoming;
338 sal_op_set_user_pointer(op,call);
342 if (lc->sip_conf.ping_with_options){
343 /*the following sends an option request back to the caller so that
344 we get a chance to discover our nat'd address before answering.*/
345 call->ping_op=sal_op_new(lc->sal);
346 from_str=linphone_address_as_string(from);
347 sal_op_set_route(call->ping_op,sal_op_get_network_origin(call->op));
348 sal_op_set_user_pointer(call->ping_op,call);
349 sal_ping(call->ping_op,linphone_core_find_best_identity(lc,from,NULL),from_str);
353 linphone_address_clean(from);
354 linphone_core_get_local_ip(lc,linphone_address_get_domain(from),call->localip);
355 linphone_call_init_common(call, from, to);
356 linphone_core_init_default_params(lc, &call->params);
357 call->localdesc=create_local_media_description (lc,call);
358 call->camera_active=call->params.has_video;
359 if (linphone_core_get_firewall_policy(call->core)==LinphonePolicyUseStun)
360 linphone_core_run_stun_tests(call->core,call);
361 discover_mtu(lc,linphone_address_get_domain(from));
365 /* this function is called internally to get rid of a call.
366 It performs the following tasks:
367 - remove the call from the internal list of calls
368 - update the call logs accordingly
371 static void linphone_call_set_terminated(LinphoneCall *call){
372 LinphoneCore *lc=call->core;
374 linphone_core_update_allocated_audio_bandwidth(lc);
376 call->owns_call_log=FALSE;
377 linphone_call_log_completed(call);
380 if (call == lc->current_call){
381 ms_message("Resetting the current call");
382 lc->current_call=NULL;
385 if (linphone_core_del_call(lc,call) != 0){
386 ms_error("Could not remove the call from the list !!!");
389 if (ms_list_size(lc->calls)==0)
390 linphone_core_notify_all_friends(lc,lc->presence_mode);
394 const char *linphone_call_state_to_string(LinphoneCallState cs){
396 case LinphoneCallIdle:
397 return "LinphoneCallIdle";
398 case LinphoneCallIncomingReceived:
399 return "LinphoneCallIncomingReceived";
400 case LinphoneCallOutgoingInit:
401 return "LinphoneCallOutgoingInit";
402 case LinphoneCallOutgoingProgress:
403 return "LinphoneCallOutgoingProgress";
404 case LinphoneCallOutgoingRinging:
405 return "LinphoneCallOutgoingRinging";
406 case LinphoneCallOutgoingEarlyMedia:
407 return "LinphoneCallOutgoingEarlyMedia";
408 case LinphoneCallConnected:
409 return "LinphoneCallConnected";
410 case LinphoneCallStreamsRunning:
411 return "LinphoneCallStreamsRunning";
412 case LinphoneCallPausing:
413 return "LinphoneCallPausing";
414 case LinphoneCallPaused:
415 return "LinphoneCallPaused";
416 case LinphoneCallResuming:
417 return "LinphoneCallResuming";
418 case LinphoneCallRefered:
419 return "LinphoneCallRefered";
420 case LinphoneCallError:
421 return "LinphoneCallError";
422 case LinphoneCallEnd:
423 return "LinphoneCallEnd";
424 case LinphoneCallPausedByRemote:
425 return "LinphoneCallPausedByRemote";
426 case LinphoneCallUpdatedByRemote:
427 return "LinphoneCallUpdatedByRemote";
428 case LinphoneCallIncomingEarlyMedia:
429 return "LinphoneCallIncomingEarlyMedia";
430 case LinphoneCallUpdated:
431 return "LinphoneCallUpdated";
432 case LinphoneCallReleased:
433 return "LinphoneCallReleased";
435 return "undefined state";
438 void linphone_call_set_state(LinphoneCall *call, LinphoneCallState cstate, const char *message){
439 LinphoneCore *lc=call->core;
441 if (call->state!=cstate){
442 if (call->state==LinphoneCallEnd || call->state==LinphoneCallError){
443 if (cstate!=LinphoneCallReleased){
444 ms_warning("Spurious call state change from %s to %s, ignored.",linphone_call_state_to_string(call->state),
445 linphone_call_state_to_string(cstate));
449 ms_message("Call %p: moving from state %s to %s",call,linphone_call_state_to_string(call->state),
450 linphone_call_state_to_string(cstate));
451 if (cstate!=LinphoneCallRefered){
452 /*LinphoneCallRefered is rather an event, not a state.
453 Indeed it does not change the state of the call (still paused or running)*/
456 if (cstate==LinphoneCallEnd || cstate==LinphoneCallError){
457 if (call->reason==LinphoneReasonDeclined){
458 call->log->status=LinphoneCallDeclined;
460 linphone_call_set_terminated (call);
462 if (cstate == LinphoneCallConnected) {
463 call->log->status=LinphoneCallSuccess;
466 if (lc->vtable.call_state_changed)
467 lc->vtable.call_state_changed(lc,call,cstate,message);
468 if (cstate==LinphoneCallReleased){
469 if (call->op!=NULL) {
470 /* so that we cannot have anymore upcalls for SAL
471 concerning this call*/
472 sal_op_release(call->op);
475 linphone_call_unref(call);
480 static void linphone_call_destroy(LinphoneCall *obj)
483 sal_op_release(obj->op);
486 if (obj->resultdesc!=NULL) {
487 sal_media_description_unref(obj->resultdesc);
488 obj->resultdesc=NULL;
490 if (obj->localdesc!=NULL) {
491 sal_media_description_unref(obj->localdesc);
495 sal_op_release(obj->ping_op);
498 ms_free(obj->refer_to);
500 if (obj->owns_call_log)
501 linphone_call_log_destroy(obj->log);
502 if (obj->auth_token) {
503 ms_free(obj->auth_token);
510 * @addtogroup call_control
515 * Increments the call 's reference count.
516 * An application that wishes to retain a pointer to call object
517 * must use this function to unsure the pointer remains
518 * valid. Once the application no more needs this pointer,
519 * it must call linphone_call_unref().
521 void linphone_call_ref(LinphoneCall *obj){
526 * Decrements the call object reference count.
527 * See linphone_call_ref().
529 void linphone_call_unref(LinphoneCall *obj){
532 linphone_call_destroy(obj);
537 * Returns current parameters associated to the call.
539 const LinphoneCallParams * linphone_call_get_current_params(const LinphoneCall *call){
540 return &call->current_params;
544 * Returns the remote address associated to this call
547 const LinphoneAddress * linphone_call_get_remote_address(const LinphoneCall *call){
548 return call->dir==LinphoneCallIncoming ? call->log->from : call->log->to;
552 * Returns the remote address associated to this call as a string.
554 * The result string must be freed by user using ms_free().
556 char *linphone_call_get_remote_address_as_string(const LinphoneCall *call){
557 return linphone_address_as_string(linphone_call_get_remote_address(call));
561 * Retrieves the call's current state.
563 LinphoneCallState linphone_call_get_state(const LinphoneCall *call){
568 * Returns the reason for a call termination (either error or normal termination)
570 LinphoneReason linphone_call_get_reason(const LinphoneCall *call){
575 * Get the user_pointer in the LinphoneCall
577 * @ingroup call_control
579 * return user_pointer an opaque user pointer that can be retrieved at any time
581 void *linphone_call_get_user_pointer(LinphoneCall *call)
583 return call->user_pointer;
587 * Set the user_pointer in the LinphoneCall
589 * @ingroup call_control
591 * the user_pointer is an opaque user pointer that can be retrieved at any time in the LinphoneCall
593 void linphone_call_set_user_pointer(LinphoneCall *call, void *user_pointer)
595 call->user_pointer = user_pointer;
599 * Returns the call log associated to this call.
601 LinphoneCallLog *linphone_call_get_call_log(const LinphoneCall *call){
606 * Returns the refer-to uri (if the call was transfered).
608 const char *linphone_call_get_refer_to(const LinphoneCall *call){
609 return call->refer_to;
613 * Returns direction of the call (incoming or outgoing).
615 LinphoneCallDir linphone_call_get_dir(const LinphoneCall *call){
616 return call->log->dir;
620 * Returns the far end's user agent description string, if available.
622 const char *linphone_call_get_remote_user_agent(LinphoneCall *call){
624 return sal_op_get_remote_ua (call->op);
630 * Returns true if this calls has received a transfer that has not been
632 * Pending transfers are executed when this call is being paused or closed,
633 * locally or by remote endpoint.
634 * If the call is already paused while receiving the transfer request, the
635 * transfer immediately occurs.
637 bool_t linphone_call_has_transfer_pending(const LinphoneCall *call){
638 return call->refer_pending;
642 * Returns call's duration in seconds.
644 int linphone_call_get_duration(const LinphoneCall *call){
645 if (call->media_start_time==0) return 0;
646 return time(NULL)-call->media_start_time;
650 * Returns the call object this call is replacing, if any.
651 * Call replacement can occur during call transfers.
652 * By default, the core automatically terminates the replaced call and accept the new one.
653 * This function allows the application to know whether a new incoming call is a one that replaces another one.
655 LinphoneCall *linphone_call_get_replaced_call(LinphoneCall *call){
656 SalOp *op=sal_call_get_replaces(call->op);
658 return (LinphoneCall*)sal_op_get_user_pointer(op);
664 * Indicate whether camera input should be sent to remote end.
666 void linphone_call_enable_camera (LinphoneCall *call, bool_t enable){
668 if (call->videostream!=NULL && call->videostream->ticker!=NULL){
669 LinphoneCore *lc=call->core;
670 MSWebCam *nowebcam=get_nowebcam_device();
671 if (call->camera_active!=enable && lc->video_conf.device!=nowebcam){
672 video_stream_change_camera(call->videostream,
673 enable ? lc->video_conf.device : nowebcam);
676 call->camera_active=enable;
681 * Take a photo of currently received video and write it into a jpeg file.
683 int linphone_call_take_video_snapshot(LinphoneCall *call, const char *file){
685 if (call->videostream!=NULL && call->videostream->jpegwriter!=NULL){
686 return ms_filter_call_method(call->videostream->jpegwriter,MS_JPEG_WRITER_TAKE_SNAPSHOT,(void*)file);
688 ms_warning("Cannot take snapshot: no currently running video stream on this call.");
695 * Returns TRUE if camera pictures are sent to the remote party.
697 bool_t linphone_call_camera_enabled (const LinphoneCall *call){
698 return call->camera_active;
702 * Enable video stream.
704 void linphone_call_params_enable_video(LinphoneCallParams *cp, bool_t enabled){
705 cp->has_video=enabled;
709 * Returns whether video is enabled.
711 bool_t linphone_call_params_video_enabled(const LinphoneCallParams *cp){
712 return cp->has_video;
715 enum LinphoneMediaEncryption linphone_call_params_get_media_encryption(LinphoneCallParams *cp) {
716 return cp->media_encryption;
719 void linphone_call_params_set_media_encryption(LinphoneCallParams *cp, enum LinphoneMediaEncryption e) {
720 cp->media_encryption = e;
725 * Enable sending of real early media (during outgoing calls).
727 void linphone_call_params_enable_early_media_sending(LinphoneCallParams *cp, bool_t enabled){
728 cp->real_early_media=enabled;
731 bool_t linphone_call_params_early_media_sending_enabled(const LinphoneCallParams *cp){
732 return cp->real_early_media;
736 * Returns true if the call is part of the locally managed conference.
738 bool_t linphone_call_params_local_conference_mode(const LinphoneCallParams *cp){
739 return cp->in_conference;
743 * Refine bandwidth settings for this call by setting a bandwidth limit for audio streams.
744 * As a consequence, codecs whose bitrates are not compatible with this limit won't be used.
746 void linphone_call_params_set_audio_bandwidth_limit(LinphoneCallParams *cp, int bandwidth){
747 cp->audio_bw=bandwidth;
752 * Request remote side to send us a Video Fast Update.
754 void linphone_call_send_vfu_request(LinphoneCall *call)
756 if (LinphoneCallStreamsRunning == linphone_call_get_state(call))
757 sal_call_send_vfu_request(call->op);
764 LinphoneCallParams * linphone_call_params_copy(const LinphoneCallParams *cp){
765 LinphoneCallParams *ncp=ms_new0(LinphoneCallParams,1);
766 memcpy(ncp,cp,sizeof(LinphoneCallParams));
773 void linphone_call_params_destroy(LinphoneCallParams *p){
782 #ifdef TEST_EXT_RENDERER
783 static void rendercb(void *data, const MSPicture *local, const MSPicture *remote){
784 ms_message("rendercb, local buffer=%p, remote buffer=%p",
785 local ? local->planes[0] : NULL, remote? remote->planes[0] : NULL);
790 static void video_stream_event_cb(void *user_pointer, const MSFilter *f, const unsigned int event_id, const void *args){
791 ms_warning("In linphonecall.c: video_stream_event_cb");
793 case MS_VIDEO_DECODER_DECODING_ERRORS:
794 ms_warning("Case is MS_VIDEO_DECODER_DECODING_ERRORS");
795 linphone_call_send_vfu_request((LinphoneCall*) user_pointer);
798 ms_warning("Unhandled event %i", event_id);
804 void linphone_call_init_media_streams(LinphoneCall *call){
805 LinphoneCore *lc=call->core;
806 SalMediaDescription *md=call->localdesc;
807 AudioStream *audiostream;
809 call->audiostream=audiostream=audio_stream_new(md->streams[0].port,linphone_core_ipv6_enabled(lc));
810 if (linphone_core_echo_limiter_enabled(lc)){
811 const char *type=lp_config_get_string(lc->config,"sound","el_type","mic");
812 if (strcasecmp(type,"mic")==0)
813 audio_stream_enable_echo_limiter(audiostream,ELControlMic);
814 else if (strcasecmp(type,"full")==0)
815 audio_stream_enable_echo_limiter(audiostream,ELControlFull);
817 audio_stream_enable_gain_control(audiostream,TRUE);
818 if (linphone_core_echo_cancellation_enabled(lc)){
819 int len,delay,framesize;
820 const char *statestr=lp_config_get_string(lc->config,"sound","ec_state",NULL);
821 len=lp_config_get_int(lc->config,"sound","ec_tail_len",0);
822 delay=lp_config_get_int(lc->config,"sound","ec_delay",0);
823 framesize=lp_config_get_int(lc->config,"sound","ec_framesize",0);
824 audio_stream_set_echo_canceller_params(audiostream,len,delay,framesize);
825 if (statestr && audiostream->ec){
826 ms_filter_call_method(audiostream->ec,MS_ECHO_CANCELLER_SET_STATE_STRING,(void*)statestr);
829 audio_stream_enable_automatic_gain_control(audiostream,linphone_core_agc_enabled(lc));
831 int enabled=lp_config_get_int(lc->config,"sound","noisegate",0);
832 audio_stream_enable_noise_gate(audiostream,enabled);
836 rtp_session_set_transports(audiostream->session,lc->a_rtp,lc->a_rtcp);
838 call->audiostream_app_evq = ortp_ev_queue_new();
839 rtp_session_register_event_queue(audiostream->session,call->audiostream_app_evq);
843 if ((lc->video_conf.display || lc->video_conf.capture) && md->streams[1].port>0){
844 call->videostream=video_stream_new(md->streams[1].port,linphone_core_ipv6_enabled(lc));
845 if( lc->video_conf.displaytype != NULL)
846 video_stream_set_display_filter_name(call->videostream,lc->video_conf.displaytype);
847 video_stream_set_event_callback(call->videostream,video_stream_event_cb, call);
849 rtp_session_set_transports(call->videostream->session,lc->v_rtp,lc->v_rtcp);
850 call->videostream_app_evq = ortp_ev_queue_new();
851 rtp_session_register_event_queue(call->videostream->session,call->videostream_app_evq);
852 #ifdef TEST_EXT_RENDERER
853 video_stream_set_render_callback(call->videostream,rendercb,NULL);
857 call->videostream=NULL;
862 static int dtmf_tab[16]={'0','1','2','3','4','5','6','7','8','9','*','#','A','B','C','D'};
864 static void linphone_core_dtmf_received(RtpSession* s, int dtmf, void* user_data){
865 LinphoneCore* lc = (LinphoneCore*)user_data;
866 if (dtmf<0 || dtmf>15){
867 ms_warning("Bad dtmf value %i",dtmf);
870 if (lc->vtable.dtmf_received != NULL)
871 lc->vtable.dtmf_received(lc, linphone_core_get_current_call(lc), dtmf_tab[dtmf]);
874 static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){
876 MSFilter *f=st->equalizer;
877 int enabled=lp_config_get_int(lc->config,"sound","eq_active",0);
878 const char *gains=lp_config_get_string(lc->config,"sound","eq_gains",NULL);
879 ms_filter_call_method(f,MS_EQUALIZER_SET_ACTIVE,&enabled);
885 if (sscanf(gains,"%f:%f:%f %n",&g.frequency,&g.gain,&g.width,&bytes)==3){
886 ms_message("Read equalizer gains: %f(~%f) --> %f",g.frequency,g.width,g.gain);
887 ms_filter_call_method(f,MS_EQUALIZER_SET_GAIN,&g);
896 void _post_configure_audio_stream(AudioStream *st, LinphoneCore *lc, bool_t muted){
897 float mic_gain=lp_config_get_float(lc->config,"sound","mic_gain",1);
900 float ng_thres=lp_config_get_float(lc->config,"sound","ng_thres",0.05);
901 float ng_floorgain=lp_config_get_float(lc->config,"sound","ng_floorgain",0);
902 int dc_removal=lp_config_get_int(lc->config,"sound","dc_removal",0);
905 audio_stream_set_mic_gain(st,mic_gain);
907 audio_stream_set_mic_gain(st,0);
909 recv_gain = lc->sound_conf.soft_play_lev;
910 if (recv_gain != 0) {
911 linphone_core_set_playback_gain_db (lc,recv_gain);
914 ms_filter_call_method(st->volsend,MS_VOLUME_REMOVE_DC,&dc_removal);
915 float speed=lp_config_get_float(lc->config,"sound","el_speed",-1);
916 thres=lp_config_get_float(lc->config,"sound","el_thres",-1);
917 float force=lp_config_get_float(lc->config,"sound","el_force",-1);
918 int sustain=lp_config_get_int(lc->config,"sound","el_sustain",-1);
919 float transmit_thres=lp_config_get_float(lc->config,"sound","el_transmit_thres",-1);
922 if (speed==-1) speed=0.03;
923 if (force==-1) force=25;
924 ms_filter_call_method(f,MS_VOLUME_SET_EA_SPEED,&speed);
925 ms_filter_call_method(f,MS_VOLUME_SET_EA_FORCE,&force);
927 ms_filter_call_method(f,MS_VOLUME_SET_EA_THRESHOLD,&thres);
929 ms_filter_call_method(f,MS_VOLUME_SET_EA_SUSTAIN,&sustain);
930 if (transmit_thres!=-1)
931 ms_filter_call_method(f,MS_VOLUME_SET_EA_TRANSMIT_THRESHOLD,&transmit_thres);
933 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_thres);
934 ms_filter_call_method(st->volsend,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&ng_floorgain);
937 /* parameters for a limited noise-gate effect, using echo limiter threshold */
938 float floorgain = 1/mic_gain;
939 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&thres);
940 ms_filter_call_method(st->volrecv,MS_VOLUME_SET_NOISE_GATE_FLOORGAIN,&floorgain);
942 parametrize_equalizer(lc,st);
945 static void post_configure_audio_streams(LinphoneCall*call){
946 AudioStream *st=call->audiostream;
947 LinphoneCore *lc=call->core;
948 _post_configure_audio_stream(st,lc,call->audio_muted);
949 if (lc->vtable.dtmf_received!=NULL){
950 /* replace by our default action*/
951 audio_stream_play_received_dtmfs(call->audiostream,FALSE);
952 rtp_session_signal_connect(call->audiostream->session,"telephone-event",(RtpCallback)linphone_core_dtmf_received,(unsigned long)lc);
956 static RtpProfile *make_profile(LinphoneCall *call, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){
959 RtpProfile *prof=rtp_profile_new("Call profile");
962 LinphoneCore *lc=call->core;
966 for(elem=desc->payloads;elem!=NULL;elem=elem->next){
967 PayloadType *pt=(PayloadType*)elem->data;
970 if ((pt->flags & PAYLOAD_TYPE_FLAG_CAN_SEND) && first) {
971 if (desc->type==SalAudio){
972 linphone_core_update_allocated_audio_bandwidth_in_call(call,pt);
973 up_ptime=linphone_core_get_upload_ptime(lc);
975 *used_pt=payload_type_get_number(pt);
978 if (desc->bandwidth>0) remote_bw=desc->bandwidth;
979 else if (md->bandwidth>0) {
980 /*case where b=AS is given globally, not per stream*/
981 remote_bw=md->bandwidth;
982 if (desc->type==SalVideo){
983 remote_bw=get_video_bandwidth(remote_bw,call->audio_bw);
987 if (desc->type==SalAudio){
988 bw=get_min_bandwidth(call->audio_bw,remote_bw);
989 }else bw=get_min_bandwidth(get_video_bandwidth(linphone_core_get_upload_bandwidth (lc),call->audio_bw),remote_bw);
990 if (bw>0) pt->normal_bitrate=bw*1000;
991 else if (desc->type==SalAudio){
992 pt->normal_bitrate=-1;
995 up_ptime=desc->ptime;
999 snprintf(tmp,sizeof(tmp),"ptime=%i",up_ptime);
1000 payload_type_append_send_fmtp(pt,tmp);
1002 number=payload_type_get_number(pt);
1003 if (rtp_profile_get_payload(prof,number)!=NULL){
1004 ms_warning("A payload type with number %i already exists in profile !",number);
1006 rtp_profile_set_payload(prof,number,pt);
1012 static void setup_ring_player(LinphoneCore *lc, LinphoneCall *call){
1013 int pause_time=3000;
1014 audio_stream_play(call->audiostream,lc->sound_conf.ringback_tone);
1015 ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time);
1018 #define LINPHONE_RTCP_SDES_TOOL "Linphone-" LINPHONE_VERSION
1020 static void linphone_call_start_audio_stream(LinphoneCall *call, const char *cname, bool_t muted, bool_t send_ringbacktone, bool_t use_arc){
1021 LinphoneCore *lc=call->core;
1022 int jitt_comp=lc->rtp_conf.audio_jitt_comp;
1024 /* look for savp stream first */
1025 const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc,
1026 SalProtoRtpSavp,SalAudio);
1027 /* no savp audio stream, use avp */
1029 stream=sal_media_description_find_stream(call->resultdesc,
1030 SalProtoRtpAvp,SalAudio);
1032 if (stream && stream->dir!=SalStreamInactive && stream->port!=0){
1033 MSSndCard *playcard=lc->sound_conf.lsd_card ?
1034 lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard;
1035 MSSndCard *captcard=lc->sound_conf.capt_sndcard;
1036 const char *playfile=lc->play_file;
1037 const char *recfile=lc->rec_file;
1038 call->audio_profile=make_profile(call,call->resultdesc,stream,&used_pt);
1042 if (playcard==NULL) {
1043 ms_warning("No card defined for playback !");
1045 if (captcard==NULL) {
1046 ms_warning("No card defined for capture !");
1048 /*Replace soundcard filters by inactive file players or recorders
1049 when placed in recvonly or sendonly mode*/
1050 if (stream->port==0 || stream->dir==SalStreamRecvOnly){
1053 }else if (stream->dir==SalStreamSendOnly){
1057 /*And we will eventually play "playfile" if set by the user*/
1060 if (send_ringbacktone){
1062 playfile=NULL;/* it is setup later*/
1064 /*if playfile are supplied don't use soundcards*/
1065 if (lc->use_files) {
1069 if (call->params.in_conference){
1070 /* first create the graph without soundcard resources*/
1071 captcard=playcard=NULL;
1073 use_ec=captcard==NULL ? FALSE : linphone_core_echo_cancellation_enabled(lc);
1075 audio_stream_enable_adaptive_bitrate_control(call->audiostream,use_arc);
1076 audio_stream_start_full(
1078 call->audio_profile,
1079 stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr,
1090 post_configure_audio_streams(call);
1091 if (muted && !send_ringbacktone){
1092 audio_stream_set_mic_gain(call->audiostream,0);
1094 if (stream->dir==SalStreamSendOnly && playfile!=NULL){
1096 ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time);
1098 if (send_ringbacktone){
1099 setup_ring_player(lc,call);
1101 audio_stream_set_rtcp_information(call->audiostream, cname, LINPHONE_RTCP_SDES_TOOL);
1102 if (call->params.in_conference){
1103 /*transform the graph to connect it to the conference filter */
1104 linphone_call_add_to_conf(call);
1107 if (stream->proto == SalProtoRtpSavp) {
1108 const SalStreamDescription *local_st_desc=sal_media_description_find_stream(call->localdesc,
1109 SalProtoRtpSavp,SalAudio);
1111 audio_stream_enable_strp(
1113 stream->crypto[0].algo,
1114 local_st_desc->crypto[0].master_key,
1115 stream->crypto[0].master_key);
1117 }else ms_warning("No audio stream accepted ?");
1121 static void linphone_call_start_video_stream(LinphoneCall *call, const char *cname,bool_t all_inputs_muted){
1122 #ifdef VIDEO_ENABLED
1123 LinphoneCore *lc=call->core;
1125 /* look for savp stream first */
1126 const SalStreamDescription *vstream=sal_media_description_find_stream(call->resultdesc,
1127 SalProtoRtpSavp,SalVideo);
1128 /* no savp audio stream, use avp */
1130 vstream=sal_media_description_find_stream(call->resultdesc,
1131 SalProtoRtpAvp,SalVideo);
1133 /* shutdown preview */
1134 if (lc->previewstream!=NULL) {
1135 video_preview_stop(lc->previewstream);
1136 lc->previewstream=NULL;
1138 call->current_params.has_video=FALSE;
1139 if (vstream && vstream->dir!=SalStreamInactive && vstream->port!=0) {
1140 const char *addr=vstream->addr[0]!='\0' ? vstream->addr : call->resultdesc->addr;
1141 call->video_profile=make_profile(call,call->resultdesc,vstream,&used_pt);
1143 VideoStreamDir dir=VideoStreamSendRecv;
1144 MSWebCam *cam=lc->video_conf.device;
1145 bool_t is_inactive=FALSE;
1147 call->current_params.has_video=TRUE;
1149 video_stream_set_sent_video_size(call->videostream,linphone_core_get_preferred_video_size(lc));
1150 video_stream_enable_self_view(call->videostream,lc->video_conf.selfview);
1151 if (lc->video_window_id!=0)
1152 video_stream_set_native_window_id(call->videostream,lc->video_window_id);
1153 if (lc->preview_window_id!=0)
1154 video_stream_set_native_preview_window_id (call->videostream,lc->preview_window_id);
1155 video_stream_use_preview_video_window (call->videostream,lc->use_preview_window);
1157 if (vstream->dir==SalStreamSendOnly && lc->video_conf.capture ){
1158 cam=get_nowebcam_device();
1159 dir=VideoStreamSendOnly;
1160 }else if (vstream->dir==SalStreamRecvOnly && lc->video_conf.display ){
1161 dir=VideoStreamRecvOnly;
1162 }else if (vstream->dir==SalStreamSendRecv){
1163 if (lc->video_conf.display && lc->video_conf.capture)
1164 dir=VideoStreamSendRecv;
1165 else if (lc->video_conf.display)
1166 dir=VideoStreamRecvOnly;
1168 dir=VideoStreamSendOnly;
1170 ms_warning("video stream is inactive.");
1171 /*either inactive or incompatible with local capabilities*/
1174 if (call->camera_active==FALSE || all_inputs_muted){
1175 cam=get_nowebcam_device();
1178 video_stream_set_direction (call->videostream, dir);
1179 ms_message("%s lc rotation:%d\n", __FUNCTION__, lc->device_rotation);
1180 video_stream_set_device_rotation(call->videostream, lc->device_rotation);
1181 video_stream_start(call->videostream,
1182 call->video_profile, addr, vstream->port,
1184 used_pt, lc->rtp_conf.audio_jitt_comp, cam);
1185 video_stream_set_rtcp_information(call->videostream, cname,LINPHONE_RTCP_SDES_TOOL);
1188 if (vstream->proto == SalProtoRtpSavp) {
1189 const SalStreamDescription *local_st_desc=sal_media_description_find_stream(call->localdesc,
1190 SalProtoRtpSavp,SalVideo);
1192 video_stream_enable_strp(
1194 vstream->crypto[0].algo,
1195 local_st_desc->crypto[0].master_key,
1196 vstream->crypto[0].master_key
1199 }else ms_warning("No video stream accepted.");
1201 ms_warning("No valid video stream defined.");
1206 void linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_muted, bool_t send_ringbacktone){
1207 LinphoneCore *lc=call->core;
1208 LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
1211 #ifdef VIDEO_ENABLED
1212 const SalStreamDescription *vstream=sal_media_description_find_stream(call->resultdesc,
1213 SalProtoRtpAvp,SalVideo);
1216 if(call->audiostream == NULL)
1218 ms_fatal("start_media_stream() called without prior init !");
1221 call->current_params = call->params;
1222 if (call->media_start_time==0) call->media_start_time=time(NULL);
1223 cname=linphone_address_as_string_uri_only(me);
1225 #if defined(VIDEO_ENABLED)
1226 if (vstream && vstream->dir!=SalStreamInactive && vstream->payloads!=NULL){
1227 /*when video is used, do not make adaptive rate control on audio, it is stupid.*/
1231 linphone_call_start_audio_stream(call,cname,all_inputs_muted,send_ringbacktone,use_arc);
1232 linphone_call_start_video_stream(call,cname,all_inputs_muted);
1234 call->all_muted=all_inputs_muted;
1235 call->playing_ringbacktone=send_ringbacktone;
1236 call->up_bw=linphone_core_get_upload_bandwidth(lc);
1238 if (ortp_zrtp_available()) {
1239 OrtpZrtpParams params;
1240 params.zid=get_hexa_zrtp_identifier(lc);
1241 params.zid_file=lc->zrtp_secrets_cache;
1242 audio_stream_enable_zrtp(call->audiostream,¶ms);
1248 linphone_address_destroy(me);
1251 static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){
1252 audio_stream_get_local_rtp_stats (st,&log->local_stats);
1253 log->quality=audio_stream_get_average_quality_rating(st);
1256 void linphone_call_stop_media_streams(LinphoneCall *call){
1257 if (call->audiostream!=NULL) {
1258 rtp_session_unregister_event_queue(call->audiostream->session,call->audiostream_app_evq);
1259 ortp_ev_queue_flush(call->audiostream_app_evq);
1260 ortp_ev_queue_destroy(call->audiostream_app_evq);
1262 if (call->audiostream->ec){
1263 const char *state_str=NULL;
1264 ms_filter_call_method(call->audiostream->ec,MS_ECHO_CANCELLER_GET_STATE_STRING,&state_str);
1266 ms_message("Writing echo canceller state, %i bytes",(int)strlen(state_str));
1267 lp_config_set_string(call->core->config,"sound","ec_state",state_str);
1270 linphone_call_log_fill_stats (call->log,call->audiostream);
1271 if (call->endpoint){
1272 linphone_call_remove_from_conf(call);
1274 audio_stream_stop(call->audiostream);
1275 call->audiostream=NULL;
1279 #ifdef VIDEO_ENABLED
1280 if (call->videostream!=NULL){
1281 rtp_session_unregister_event_queue(call->videostream->session,call->videostream_app_evq);
1282 ortp_ev_queue_flush(call->videostream_app_evq);
1283 ortp_ev_queue_destroy(call->videostream_app_evq);
1284 video_stream_stop(call->videostream);
1285 call->videostream=NULL;
1287 ms_event_queue_skip(call->core->msevq);
1290 if (call->audio_profile){
1291 rtp_profile_clear_all(call->audio_profile);
1292 rtp_profile_destroy(call->audio_profile);
1293 call->audio_profile=NULL;
1295 if (call->video_profile){
1296 rtp_profile_clear_all(call->video_profile);
1297 rtp_profile_destroy(call->video_profile);
1298 call->video_profile=NULL;
1304 void linphone_call_enable_echo_cancellation(LinphoneCall *call, bool_t enable) {
1305 if (call!=NULL && call->audiostream!=NULL && call->audiostream->ec){
1306 bool_t bypass_mode = !enable;
1307 ms_filter_call_method(call->audiostream->ec,MS_ECHO_CANCELLER_SET_BYPASS_MODE,&bypass_mode);
1310 bool_t linphone_call_echo_cancellation_enabled(LinphoneCall *call) {
1311 if (call!=NULL && call->audiostream!=NULL && call->audiostream->ec){
1313 ms_filter_call_method(call->audiostream->ec,MS_ECHO_CANCELLER_GET_BYPASS_MODE,&val);
1316 return linphone_core_echo_cancellation_enabled(call->core);
1320 void linphone_call_enable_echo_limiter(LinphoneCall *call, bool_t val){
1321 if (call!=NULL && call->audiostream!=NULL ) {
1323 const char *type=lp_config_get_string(call->core->config,"sound","el_type","mic");
1324 if (strcasecmp(type,"mic")==0)
1325 audio_stream_enable_echo_limiter(call->audiostream,ELControlMic);
1326 else if (strcasecmp(type,"full")==0)
1327 audio_stream_enable_echo_limiter(call->audiostream,ELControlFull);
1329 audio_stream_enable_echo_limiter(call->audiostream,ELInactive);
1334 bool_t linphone_call_echo_limiter_enabled(const LinphoneCall *call){
1335 if (call!=NULL && call->audiostream!=NULL ){
1336 return call->audiostream->el_type !=ELInactive ;
1338 return linphone_core_echo_limiter_enabled(call->core);
1343 * @addtogroup call_misc
1348 * Returns the measured sound volume played locally (received from remote)
1349 * It is expressed in dbm0.
1351 float linphone_call_get_play_volume(LinphoneCall *call){
1352 AudioStream *st=call->audiostream;
1353 if (st && st->volrecv){
1355 ms_filter_call_method(st->volrecv,MS_VOLUME_GET,&vol);
1359 return LINPHONE_VOLUME_DB_LOWEST;
1363 * Returns the measured sound volume recorded locally (sent to remote)
1364 * It is expressed in dbm0.
1366 float linphone_call_get_record_volume(LinphoneCall *call){
1367 AudioStream *st=call->audiostream;
1368 if (st && st->volsend && !call->audio_muted && call->state==LinphoneCallStreamsRunning){
1370 ms_filter_call_method(st->volsend,MS_VOLUME_GET,&vol);
1374 return LINPHONE_VOLUME_DB_LOWEST;
1378 * Obtain real-time quality rating of the call
1380 * Based on local RTP statistics and RTCP feedback, a quality rating is computed and updated
1381 * during all the duration of the call. This function returns its value at the time of the function call.
1382 * It is expected that the rating is updated at least every 5 seconds or so.
1383 * The rating is a floating point number comprised between 0 and 5.
1385 * 4-5 = good quality <br>
1386 * 3-4 = average quality <br>
1387 * 2-3 = poor quality <br>
1388 * 1-2 = very poor quality <br>
1389 * 0-1 = can't be worse, mostly unusable <br>
1391 * @returns The function returns -1 if no quality measurement is available, for example if no
1392 * active audio stream exist. Otherwise it returns the quality rating.
1394 float linphone_call_get_current_quality(LinphoneCall *call){
1395 if (call->audiostream){
1396 return audio_stream_get_quality_rating(call->audiostream);
1402 * Returns call quality averaged over all the duration of the call.
1404 * See linphone_call_get_current_quality() for more details about quality measurement.
1406 float linphone_call_get_average_quality(LinphoneCall *call){
1407 if (call->audiostream){
1408 return audio_stream_get_average_quality_rating(call->audiostream);
1417 static void display_bandwidth(RtpSession *as, RtpSession *vs){
1418 ms_message("bandwidth usage: audio=[d=%.1f,u=%.1f] video=[d=%.1f,u=%.1f] kbit/sec",
1419 (as!=NULL) ? (rtp_session_compute_recv_bandwidth(as)*1e-3) : 0,
1420 (as!=NULL) ? (rtp_session_compute_send_bandwidth(as)*1e-3) : 0,
1421 (vs!=NULL) ? (rtp_session_compute_recv_bandwidth(vs)*1e-3) : 0,
1422 (vs!=NULL) ? (rtp_session_compute_send_bandwidth(vs)*1e-3) : 0);
1425 static void linphone_core_disconnected(LinphoneCore *lc, LinphoneCall *call){
1429 from = linphone_call_get_remote_address_as_string(call);
1432 snprintf(temp,sizeof(temp),"Remote end %s seems to have disconnected, the call is going to be closed.",from);
1437 snprintf(temp,sizeof(temp),"Remote end seems to have disconnected, the call is going to be closed.");
1439 if (lc->vtable.display_warning!=NULL)
1440 lc->vtable.display_warning(lc,temp);
1441 linphone_core_terminate_call(lc,call);
1444 void linphone_call_background_tasks(LinphoneCall *call, bool_t one_second_elapsed){
1445 int disconnect_timeout = linphone_core_get_nortp_timeout(call->core);
1446 bool_t disconnected=FALSE;
1448 if (call->state==LinphoneCallStreamsRunning && one_second_elapsed){
1449 RtpSession *as=NULL,*vs=NULL;
1450 float audio_load=0, video_load=0;
1451 if (call->audiostream!=NULL){
1452 as=call->audiostream->session;
1453 if (call->audiostream->ticker)
1454 audio_load=ms_ticker_get_average_load(call->audiostream->ticker);
1456 if (call->videostream!=NULL){
1457 if (call->videostream->ticker)
1458 video_load=ms_ticker_get_average_load(call->videostream->ticker);
1459 vs=call->videostream->session;
1461 display_bandwidth(as,vs);
1462 ms_message("Thread processing load: audio=%f\tvideo=%f",audio_load,video_load);
1464 #ifdef VIDEO_ENABLED
1465 if (call->videostream!=NULL) {
1466 // Beware that the application queue should not depend on treatments fron the
1467 // mediastreamer queue.
1468 video_stream_iterate(call->videostream);
1470 if (call->videostream_app_evq){
1472 while (NULL != (ev=ortp_ev_queue_get(call->videostream_app_evq))){
1473 OrtpEventType evt=ortp_event_get_type(ev);
1474 if (evt == ORTP_EVENT_ZRTP_ENCRYPTION_CHANGED){
1475 OrtpEventData *evd=ortp_event_get_data(ev);
1476 linphone_call_videostream_encryption_changed(call, evd->info.zrtp_stream_encrypted);
1478 ortp_event_destroy(ev);
1483 if (call->audiostream!=NULL) {
1484 // Beware that the application queue should not depend on treatments fron the
1485 // mediastreamer queue.
1486 audio_stream_iterate(call->audiostream);
1488 if (call->audiostream->evq){
1490 while (NULL != (ev=ortp_ev_queue_get(call->audiostream_app_evq))){
1491 OrtpEventType evt=ortp_event_get_type(ev);
1492 if (evt == ORTP_EVENT_ZRTP_ENCRYPTION_CHANGED){
1493 OrtpEventData *evd=ortp_event_get_data(ev);
1494 linphone_call_audiostream_encryption_changed(call, evd->info.zrtp_stream_encrypted);
1495 } else if (evt == ORTP_EVENT_ZRTP_SAS_READY) {
1496 OrtpEventData *evd=ortp_event_get_data(ev);
1497 linphone_call_audiostream_auth_token_ready(call, evd->info.zrtp_sas.sas, evd->info.zrtp_sas.verified);
1499 ortp_event_destroy(ev);
1503 if (call->state==LinphoneCallStreamsRunning && one_second_elapsed && call->audiostream!=NULL && disconnect_timeout>0 )
1504 disconnected=!audio_stream_alive(call->audiostream,disconnect_timeout);
1506 linphone_core_disconnected(call->core,call);
1509 void linphone_call_log_completed(LinphoneCall *call){
1510 LinphoneCore *lc=call->core;
1512 call->log->duration=time(NULL)-call->start_time;
1514 if (call->log->status==LinphoneCallMissed){
1517 info=ortp_strdup_printf(ngettext("You have missed %i call.",
1518 "You have missed %i calls.", lc->missed_calls),
1520 if (lc->vtable.display_status!=NULL)
1521 lc->vtable.display_status(lc,info);
1524 lc->call_logs=ms_list_prepend(lc->call_logs,(void *)call->log);
1525 if (ms_list_size(lc->call_logs)>lc->max_call_logs){
1526 MSList *elem,*prevelem=NULL;
1527 /*find the last element*/
1528 for(elem=lc->call_logs;elem!=NULL;elem=elem->next){
1532 linphone_call_log_destroy((LinphoneCallLog*)elem->data);
1533 lc->call_logs=ms_list_remove_link(lc->call_logs,elem);
1535 if (lc->vtable.call_log_updated!=NULL){
1536 lc->vtable.call_log_updated(lc,call->log);
1538 call_logs_write_to_config_file(lc);