X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=coreapi%2Flinphonecall.c;h=db3190bbb3e851709690144472689ea3cc3e6ad5;hb=0fa5d7c73b672772a8841c65ff0c7fcdc4e1fce7;hp=d43c457b67de9193b6aa9d300caa32cafd87ecd5;hpb=2043ec6a90a4f2e7f077391909c968b4f7c98e9e;p=linphone diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index d43c457b..db3190bb 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "private.h" #include #include - +#include #include "mediastreamer2/mediastream.h" #include "mediastreamer2/msvolume.h" @@ -161,21 +161,22 @@ void linphone_call_set_authentication_token_verified(LinphoneCall *call, bool_t if (call->audiostream==NULL){ ms_error("linphone_call_set_authentication_token_verified(): No audio stream"); } - if (call->audiostream->ortpZrtpContext==NULL){ + if (call->audiostream->ms.zrtp_context==NULL){ ms_error("linphone_call_set_authentication_token_verified(): No zrtp context."); } if (!call->auth_token_verified && verified){ - ortp_zrtp_sas_verified(call->audiostream->ortpZrtpContext); + ortp_zrtp_sas_verified(call->audiostream->ms.zrtp_context); }else if (call->auth_token_verified && !verified){ - ortp_zrtp_sas_reset_verified(call->audiostream->ortpZrtpContext); + ortp_zrtp_sas_reset_verified(call->audiostream->ms.zrtp_context); } call->auth_token_verified=verified; propagate_encryption_changed(call); } -static MSList *make_codec_list(LinphoneCore *lc, const MSList *codecs, int bandwidth_limit,int* max_sample_rate){ +static MSList *make_codec_list(LinphoneCore *lc, const MSList *codecs, int bandwidth_limit,int* max_sample_rate, int nb_codecs_limit){ MSList *l=NULL; const MSList *it; + int nb = 0; if (max_sample_rate) *max_sample_rate=0; for(it=codecs;it!=NULL;it=it->next){ PayloadType *pt=(PayloadType*)it->data; @@ -186,45 +187,49 @@ static MSList *make_codec_list(LinphoneCore *lc, const MSList *codecs, int bandw } if (linphone_core_check_payload_type_usability(lc,pt)){ l=ms_list_append(l,payload_type_clone(pt)); + nb++; if (max_sample_rate && payload_type_get_rate(pt)>*max_sample_rate) *max_sample_rate=payload_type_get_rate(pt); } } + if ((nb_codecs_limit > 0) && (nb >= nb_codecs_limit)) break; } return l; } static void update_media_description_from_stun(SalMediaDescription *md, const StunCandidate *ac, const StunCandidate *vc){ - if (ac->port!=0){ - strcpy(md->streams[0].rtp_addr,ac->addr); - md->streams[0].rtp_port=ac->port; - if ((ac->addr[0]!='\0' && vc->addr[0]!='\0' && strcmp(ac->addr,vc->addr)==0) || md->nstreams==1){ - strcpy(md->addr,ac->addr); + int i; + for (i = 0; i < md->n_active_streams; i++) { + if ((md->streams[i].type == SalAudio) && (ac->port != 0)) { + strcpy(md->streams[0].rtp_addr,ac->addr); + md->streams[0].rtp_port=ac->port; + if ((ac->addr[0]!='\0' && vc->addr[0]!='\0' && strcmp(ac->addr,vc->addr)==0) || md->n_active_streams==1){ + strcpy(md->addr,ac->addr); + } + } + if ((md->streams[i].type == SalVideo) && (vc->port != 0)) { + strcpy(md->streams[1].rtp_addr,vc->addr); + md->streams[1].rtp_port=vc->port; } } - if (vc->port!=0){ - strcpy(md->streams[1].rtp_addr,vc->addr); - md->streams[1].rtp_port=vc->port; - } - } - -static SalMediaDescription *_create_local_media_description(LinphoneCore *lc, LinphoneCall *call, unsigned int session_id, unsigned int session_ver){ +void linphone_call_make_local_media_description(LinphoneCore *lc, LinphoneCall *call){ MSList *l; PayloadType *pt; + SalMediaDescription *old_md=call->localdesc; int i; const char *me=linphone_core_get_identity(lc); LinphoneAddress *addr=linphone_address_new(me); const char *username=linphone_address_get_username (addr); SalMediaDescription *md=sal_media_description_new(); - - if (call->ping_time>0) { - linphone_core_adapt_to_network(lc,call->ping_time,&call->params); - } + bool_t keep_srtp_keys=lp_config_get_int(lc->config,"sip","keep_srtp_keys",0); - md->session_id=session_id; - md->session_ver=session_ver; - md->nstreams=1; + linphone_core_adapt_to_network(lc,call->ping_time,&call->params); + + md->session_id=(old_md ? old_md->session_id : (rand() & 0xfff)); + md->session_ver=(old_md ? (old_md->session_ver+1) : (rand() & 0xfff)); + md->n_total_streams=(old_md ? old_md->n_total_streams : 1); + md->n_active_streams=1; strncpy(md->addr,call->localip,sizeof(md->addr)); strncpy(md->username,username,sizeof(md->username)); @@ -244,70 +249,99 @@ static SalMediaDescription *_create_local_media_description(LinphoneCore *lc, Li md->streams[0].ptime=call->params.down_ptime; else md->streams[0].ptime=linphone_core_get_download_ptime(lc); - l=make_codec_list(lc,lc->codecs_conf.audio_codecs,call->params.audio_bw,&md->streams[0].max_rate); - pt=payload_type_clone(rtp_profile_get_payload_from_mime(&av_profile,"telephone-event")); + l=make_codec_list(lc,lc->codecs_conf.audio_codecs,call->params.audio_bw,&md->streams[0].max_rate,-1); + pt=payload_type_clone(rtp_profile_get_payload_from_mime(lc->default_profile,"telephone-event")); l=ms_list_append(l,pt); md->streams[0].payloads=l; - - if (call->params.has_video){ - md->nstreams++; + md->n_active_streams++; md->streams[1].rtp_port=call->video_port; md->streams[1].rtcp_port=call->video_port+1; md->streams[1].proto=md->streams[0].proto; md->streams[1].type=SalVideo; - l=make_codec_list(lc,lc->codecs_conf.video_codecs,0,NULL); + l=make_codec_list(lc,lc->codecs_conf.video_codecs,0,NULL,-1); md->streams[1].payloads=l; } - - for(i=0; instreams; i++) { + if (md->n_total_streams < md->n_active_streams) + md->n_total_streams = md->n_active_streams; + + /* Deactivate inactive streams. */ + for (i = md->n_active_streams; i < md->n_total_streams; i++) { + md->streams[i].rtp_port = 0; + md->streams[i].rtcp_port = 0; + md->streams[i].proto = SalProtoRtpAvp; + md->streams[i].type = old_md->streams[i].type; + md->streams[i].dir = SalStreamInactive; + l = make_codec_list(lc, lc->codecs_conf.video_codecs, 0, NULL, 1); + md->streams[i].payloads = l; + } + + for(i=0; in_active_streams; i++) { if (md->streams[i].proto == SalProtoRtpSavp) { - md->streams[i].crypto[0].tag = 1; - md->streams[i].crypto[0].algo = AES_128_SHA1_80; - if (!generate_b64_crypto_key(30, md->streams[i].crypto[0].master_key)) - md->streams[i].crypto[0].algo = 0; - md->streams[i].crypto[1].tag = 2; - md->streams[i].crypto[1].algo = AES_128_SHA1_32; - if (!generate_b64_crypto_key(30, md->streams[i].crypto[1].master_key)) - md->streams[i].crypto[1].algo = 0; - md->streams[i].crypto[2].algo = 0; + if (keep_srtp_keys && old_md && old_md->streams[i].proto==SalProtoRtpSavp){ + int j; + for(j=0;jstreams[i].crypto[j],&old_md->streams[i].crypto[j],sizeof(SalSrtpCryptoAlgo)); + } + }else{ + md->streams[i].crypto[0].tag = 1; + md->streams[i].crypto[0].algo = AES_128_SHA1_80; + if (!generate_b64_crypto_key(30, md->streams[i].crypto[0].master_key)) + md->streams[i].crypto[0].algo = 0; + md->streams[i].crypto[1].tag = 2; + md->streams[i].crypto[1].algo = AES_128_SHA1_32; + if (!generate_b64_crypto_key(30, md->streams[i].crypto[1].master_key)) + md->streams[i].crypto[1].algo = 0; + md->streams[i].crypto[2].algo = 0; + } } } update_media_description_from_stun(md,&call->ac,&call->vc); if (call->ice_session != NULL) { linphone_core_update_local_media_description_from_ice(md, call->ice_session); + linphone_core_update_ice_state_in_call_stats(call); } - linphone_address_destroy(addr); - return md; -} - -void update_local_media_description(LinphoneCore *lc, LinphoneCall *call){ - SalMediaDescription *md=call->localdesc; - if (md== NULL) { - call->localdesc = create_local_media_description(lc,call); - } else { - call->localdesc = _create_local_media_description(lc,call,md->session_id,md->session_ver+1); - sal_media_description_unref(md); +#ifdef BUILD_UPNP + if(call->upnp_session != NULL) { + linphone_core_update_local_media_description_from_upnp(md, call->upnp_session); + linphone_core_update_upnp_state_in_call_stats(call); } +#endif //BUILD_UPNP + linphone_address_destroy(addr); + call->localdesc=md; + if (old_md) sal_media_description_unref(old_md); } -SalMediaDescription *create_local_media_description(LinphoneCore *lc, LinphoneCall *call){ - unsigned int id=rand() & 0xfff; - return _create_local_media_description(lc,call,id,id); -} - -static int find_port_offset(LinphoneCore *lc){ +static int find_port_offset(LinphoneCore *lc, SalStreamType type){ int offset; MSList *elem; - int audio_port; + int tried_port; + int existing_port; bool_t already_used=FALSE; for(offset=0;offset<100;offset+=2){ - audio_port=linphone_core_get_audio_port (lc)+offset; + switch (type) { + default: + case SalAudio: + tried_port=linphone_core_get_audio_port (lc)+offset; + break; + case SalVideo: + tried_port=linphone_core_get_video_port (lc)+offset; + break; + } already_used=FALSE; for(elem=lc->calls;elem!=NULL;elem=elem->next){ LinphoneCall *call=(LinphoneCall*)elem->data; - if (call->audio_port==audio_port) { + switch (type) { + default: + case SalAudio: + existing_port = call->audio_port; + break; + case SalVideo: + existing_port = call->video_port; + break; + } + if (existing_port==tried_port) { already_used=TRUE; break; } @@ -321,8 +355,54 @@ static int find_port_offset(LinphoneCore *lc){ return offset; } +static int select_random_port(LinphoneCore *lc, SalStreamType type) { + MSList *elem; + int nb_tries; + int tried_port = 0; + int existing_port = 0; + int min_port = 0, max_port = 0; + bool_t already_used = FALSE; + + switch (type) { + default: + case SalAudio: + linphone_core_get_audio_port_range(lc, &min_port, &max_port); + break; + case SalVideo: + linphone_core_get_video_port_range(lc, &min_port, &max_port); + break; + } + tried_port = (rand() % (max_port - min_port) + min_port) & ~0x1; + if (tried_port < min_port) tried_port = min_port + 2; + for (nb_tries = 0; nb_tries < 100; nb_tries++) { + for (elem = lc->calls; elem != NULL; elem = elem->next) { + LinphoneCall *call = (LinphoneCall *)elem->data; + switch (type) { + default: + case SalAudio: + existing_port = call->audio_port; + break; + case SalVideo: + existing_port = call->video_port; + break; + } + if (existing_port == tried_port) { + already_used = TRUE; + break; + } + } + if (!already_used) break; + } + if (nb_tries == 100) { + ms_error("Could not find any free port!"); + return -1; + } + return tried_port; +} + static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, LinphoneAddress *to){ int port_offset; + int min_port, max_port; call->magic=linphone_call_magic; call->refcnt=1; call->state=LinphoneCallIdle; @@ -332,10 +412,26 @@ static void linphone_call_init_common(LinphoneCall *call, LinphoneAddress *from, call->log=linphone_call_log_new(call, from, to); call->owns_call_log=TRUE; linphone_core_notify_all_friends(call->core,LinphoneStatusOnThePhone); - port_offset=find_port_offset (call->core); - if (port_offset==-1) return; - call->audio_port=linphone_core_get_audio_port(call->core)+port_offset; - call->video_port=linphone_core_get_video_port(call->core)+port_offset; + linphone_core_get_audio_port_range(call->core, &min_port, &max_port); + if (min_port == max_port) { + /* Used fixed RTP audio port. */ + port_offset=find_port_offset (call->core, SalAudio); + if (port_offset==-1) return; + call->audio_port=linphone_core_get_audio_port(call->core)+port_offset; + } else { + /* Select random RTP audio port in the specified range. */ + call->audio_port = select_random_port(call->core, SalAudio); + } + linphone_core_get_video_port_range(call->core, &min_port, &max_port); + if (min_port == max_port) { + /* Used fixed RTP video port. */ + port_offset=find_port_offset (call->core, SalVideo); + if (port_offset==-1) return; + call->video_port=linphone_core_get_video_port(call->core)+port_offset; + } else { + /* Select random RTP video port in the specified range. */ + call->video_port = select_random_port(call->core, SalVideo); + } linphone_call_init_stats(&call->stats[LINPHONE_CALL_STATS_AUDIO], LINPHONE_CALL_STATS_AUDIO); linphone_call_init_stats(&call->stats[LINPHONE_CALL_STATS_VIDEO], LINPHONE_CALL_STATS_VIDEO); } @@ -345,6 +441,11 @@ void linphone_call_init_stats(LinphoneCallStats *stats, int type) { stats->received_rtcp = NULL; stats->sent_rtcp = NULL; stats->ice_state = LinphoneIceStateNotActivated; +#ifdef BUILD_UPNP + stats->upnp_state = LinphoneUpnpStateIdle; +#else + stats->upnp_state = LinphoneUpnpStateNotAvailable; +#endif //BUILD_UPNP } @@ -368,9 +469,12 @@ LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddr call->op=sal_op_new(lc->sal); sal_op_set_user_pointer(call->op,call); call->core=lc; - linphone_core_get_local_ip(lc,linphone_address_get_domain(to),call->localip); + linphone_core_get_local_ip(lc,NULL,call->localip); linphone_call_init_common(call,from,to); - call->params=*params; + _linphone_call_params_copy(&call->params,params); + sal_op_set_custom_header(call->op,call->params.custom_headers); + call->params.custom_headers=NULL; + if (linphone_core_get_firewall_policy(call->core) == LinphonePolicyUseIce) { call->ice_session = ice_session_new(); ice_session_set_role(call->ice_session, IR_Controlling); @@ -378,6 +482,13 @@ LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddr if (linphone_core_get_firewall_policy(call->core) == LinphonePolicyUseStun) { call->ping_time=linphone_core_run_stun_tests(call->core,call); } +#ifdef BUILD_UPNP + if (linphone_core_get_firewall_policy(call->core) == LinphonePolicyUseUpnp) { + if(!lc->rtp_conf.disable_upnp) { + call->upnp_session = linphone_upnp_session_new(call); + } + } +#endif //BUILD_UPNP call->camera_active=params->has_video; discover_mtu(lc,linphone_address_get_domain (to)); @@ -391,6 +502,7 @@ LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddr LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){ LinphoneCall *call=ms_new0(LinphoneCall,1); char *from_str; + const SalMediaDescription *md; call->dir=LinphoneCallIncoming; sal_op_set_user_pointer(op,call); @@ -398,21 +510,35 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro call->core=lc; if (lc->sip_conf.ping_with_options){ - /*the following sends an option request back to the caller so that - we get a chance to discover our nat'd address before answering.*/ - call->ping_op=sal_op_new(lc->sal); - from_str=linphone_address_as_string_uri_only(from); - sal_op_set_route(call->ping_op,sal_op_get_network_origin(op)); - sal_op_set_user_pointer(call->ping_op,call); - sal_ping(call->ping_op,linphone_core_find_best_identity(lc,from,NULL),from_str); - ms_free(from_str); +#ifdef BUILD_UPNP + if (lc->upnp != NULL && linphone_core_get_firewall_policy(lc)==LinphonePolicyUseUpnp && + linphone_upnp_context_get_state(lc->upnp) == LinphoneUpnpStateOk) { +#else //BUILD_UPNP + { +#endif //BUILD_UPNP + /*the following sends an option request back to the caller so that + we get a chance to discover our nat'd address before answering.*/ + call->ping_op=sal_op_new(lc->sal); + from_str=linphone_address_as_string_uri_only(from); + sal_op_set_route(call->ping_op,sal_op_get_network_origin(op)); + sal_op_set_user_pointer(call->ping_op,call); + sal_ping(call->ping_op,linphone_core_find_best_identity(lc,from,NULL),from_str); + ms_free(from_str); + } } linphone_address_clean(from); - linphone_core_get_local_ip(lc,linphone_address_get_domain(from),call->localip); + linphone_core_get_local_ip(lc,NULL,call->localip); linphone_call_init_common(call, from, to); + call->log->call_id=ms_strdup(sal_op_get_call_id(op)); /*must be known at that time*/ linphone_core_init_default_params(lc, &call->params); + md=sal_call_get_remote_media_description(op); call->params.has_video &= !!lc->video_policy.automatically_accept; + if (md) { + // It is licit to receive an INVITE without SDP + // In this case WE chose the media parameters according to policy. + call->params.has_video &= linphone_core_media_description_contains_video_stream(md); + } switch (linphone_core_get_firewall_policy(call->core)) { case LinphonePolicyUseIce: call->ice_session = ice_session_new(); @@ -424,13 +550,28 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro if (linphone_core_gather_ice_candidates(call->core,call)<0) { /* Ice candidates gathering failed, proceed with the call anyway. */ linphone_call_delete_ice_session(call); - linphone_call_stop_media_streams(call); + linphone_call_stop_media_streams_for_ice_gathering(call); } } break; case LinphonePolicyUseStun: call->ping_time=linphone_core_run_stun_tests(call->core,call); /* No break to also destroy ice session in this case. */ + break; + case LinphonePolicyUseUpnp: +#ifdef BUILD_UPNP + if(!lc->rtp_conf.disable_upnp) { + call->upnp_session = linphone_upnp_session_new(call); + if (call->upnp_session != NULL) { + linphone_call_init_media_streams(call); + if (linphone_core_update_upnp_from_remote_media_description(call, sal_call_get_remote_media_description(op))<0) { + /* uPnP port mappings failed, proceed with the call anyway. */ + linphone_call_delete_upnp_session(call); + } + } + } +#endif //BUILD_UPNP + break; default: break; } @@ -519,8 +660,8 @@ const char *linphone_call_state_to_string(LinphoneCallState cs){ return "LinphoneCallUpdatedByRemote"; case LinphoneCallIncomingEarlyMedia: return "LinphoneCallIncomingEarlyMedia"; - case LinphoneCallUpdated: - return "LinphoneCallUpdated"; + case LinphoneCallUpdating: + return "LinphoneCallUpdating"; case LinphoneCallReleased: return "LinphoneCallReleased"; } @@ -579,6 +720,10 @@ void linphone_call_set_state(LinphoneCall *call, LinphoneCallState cstate, const static void linphone_call_destroy(LinphoneCall *obj) { +#ifdef BUILD_UPNP + linphone_call_delete_upnp_session(obj); +#endif //BUILD_UPNP + linphone_call_delete_ice_session(obj); if (obj->op!=NULL) { sal_op_release(obj->op); obj->op=NULL; @@ -602,10 +747,7 @@ static void linphone_call_destroy(LinphoneCall *obj) if (obj->auth_token) { ms_free(obj->auth_token); } - if (obj->ice_session) { - ice_session_destroy(obj->ice_session); - } - + linphone_call_params_uninit(&obj->params); ms_free(obj); } @@ -640,7 +782,9 @@ void linphone_call_unref(LinphoneCall *obj){ /** * Returns current parameters associated to the call. **/ -const LinphoneCallParams * linphone_call_get_current_params(const LinphoneCall *call){ +const LinphoneCallParams * linphone_call_get_current_params(LinphoneCall *call){ + if (call->params.record_file) + call->current_params.record_file=call->params.record_file; return &call->current_params; } @@ -673,6 +817,12 @@ const LinphoneCallParams * linphone_call_get_remote_params(LinphoneCall *call){ }else if (vsd){ cp->has_video=is_video_active(vsd); } + if (!cp->has_video){ + if (md->bandwidth>0 && md->bandwidth<=linphone_core_get_edge_bw(call->core)){ + cp->low_bandwidth=TRUE; + } + } + cp->custom_headers=(SalCustomHeader*)sal_op_get_custom_header(call->op); return cp; } } @@ -765,6 +915,16 @@ const char *linphone_call_get_remote_user_agent(LinphoneCall *call){ return NULL; } +/** + * Returns the far end's sip contact as a string, if available. +**/ +const char *linphone_call_get_remote_contact(LinphoneCall *call){ + if (call->op){ + return sal_op_get_remote_contact(call->op); + } + return NULL; +} + /** * Returns true if this calls has received a transfer that has not been * executed yet. @@ -804,7 +964,7 @@ LinphoneCall *linphone_call_get_replaced_call(LinphoneCall *call){ **/ void linphone_call_enable_camera (LinphoneCall *call, bool_t enable){ #ifdef VIDEO_ENABLED - if (call->videostream!=NULL && call->videostream->ticker!=NULL){ + if (call->videostream!=NULL && call->videostream->ms.ticker!=NULL){ LinphoneCore *lc=call->core; MSWebCam *nowebcam=get_nowebcam_device(); if (call->camera_active!=enable && lc->video_conf.device!=nowebcam){ @@ -816,6 +976,18 @@ void linphone_call_enable_camera (LinphoneCall *call, bool_t enable){ #endif } +#ifdef VIDEO_ENABLED +/** + * Request remote side to send us a Video Fast Update. +**/ +void linphone_call_send_vfu_request(LinphoneCall *call) +{ + if (LinphoneCallStreamsRunning == linphone_call_get_state(call)) + sal_call_send_vfu_request(call->op); +} +#endif + + /** * Take a photo of currently received video and write it into a jpeg file. **/ @@ -844,14 +1016,46 @@ void linphone_call_params_enable_video(LinphoneCallParams *cp, bool_t enabled){ cp->has_video=enabled; } +/** + * Returns the audio codec used in the call, described as a PayloadType structure. +**/ const PayloadType* linphone_call_params_get_used_audio_codec(const LinphoneCallParams *cp) { return cp->audio_codec; } + +/** + * Returns the video codec used in the call, described as a PayloadType structure. +**/ const PayloadType* linphone_call_params_get_used_video_codec(const LinphoneCallParams *cp) { return cp->video_codec; } +/** + * @ingroup call_control + * Use to know if this call has been configured in low bandwidth mode. + * This mode can be automatically discovered thanks to a stun server when activate_edge_workarounds=1 in section [net] of configuration file. + * An application that would have reliable way to know network capacity may not use activate_edge_workarounds=1 but instead manually configure + * low bandwidth mode with linphone_call_params_enable_low_bandwidth(). + *
When enabled, this param may transform a call request with video in audio only mode. + * @return TRUE if low bandwidth has been configured/detected + */ +bool_t linphone_call_params_low_bandwidth_enabled(const LinphoneCallParams *cp) { + return cp->low_bandwidth; +} + +/** + * @ingroup call_control + * Indicate low bandwith mode. + * Configuring a call to low bandwidth mode will result in the core to activate several settings for the call in order to ensure that bitrate usage + * is lowered to the minimum possible. Typically, ptime (packetization time) will be increased, audio codec's output bitrate will be targetted to 20kbit/s provided + * that it is achievable by the codec selected after SDP handshake. Video is automatically disabled. + * +**/ +void linphone_call_params_enable_low_bandwidth(LinphoneCallParams *cp, bool_t enabled){ + cp->low_bandwidth=enabled; +} + /** * Returns whether video is enabled. **/ @@ -859,10 +1063,16 @@ bool_t linphone_call_params_video_enabled(const LinphoneCallParams *cp){ return cp->has_video; } +/** + * Returns kind of media encryption selected for the call. +**/ enum LinphoneMediaEncryption linphone_call_params_get_media_encryption(const LinphoneCallParams *cp) { return cp->media_encryption; } +/** + * Set requested media encryption for a call. +**/ void linphone_call_params_set_media_encryption(LinphoneCallParams *cp, enum LinphoneMediaEncryption e) { cp->media_encryption = e; } @@ -875,6 +1085,9 @@ void linphone_call_params_enable_early_media_sending(LinphoneCallParams *cp, boo cp->real_early_media=enabled; } +/** + * Indicates whether sending of early media was enabled. +**/ bool_t linphone_call_params_early_media_sending_enabled(const LinphoneCallParams *cp){ return cp->real_early_media; } @@ -894,33 +1107,46 @@ void linphone_call_params_set_audio_bandwidth_limit(LinphoneCallParams *cp, int cp->audio_bw=bandwidth; } -#ifdef VIDEO_ENABLED -/** - * Request remote side to send us a Video Fast Update. -**/ -void linphone_call_send_vfu_request(LinphoneCall *call) -{ - if (LinphoneCallStreamsRunning == linphone_call_get_state(call)) - sal_call_send_vfu_request(call->op); +void linphone_call_params_add_custom_header(LinphoneCallParams *params, const char *header_name, const char *header_value){ + params->custom_headers=sal_custom_header_append(params->custom_headers,header_name,header_value); +} + +const char *linphone_call_params_get_custom_header(const LinphoneCallParams *params, const char *header_name){ + return sal_custom_header_find(params->custom_headers,header_name); +} + +void _linphone_call_params_copy(LinphoneCallParams *ncp, const LinphoneCallParams *cp){ + memcpy(ncp,cp,sizeof(LinphoneCallParams)); + if (cp->record_file) ncp->record_file=ms_strdup(cp->record_file); + /* + * The management of the custom headers is not optimal. We copy everything while ref counting would be more efficient. + */ + if (cp->custom_headers) ncp->custom_headers=sal_custom_header_clone(cp->custom_headers); } -#endif /** - * + * Copy existing LinphoneCallParams to a new LinphoneCallParams object. **/ LinphoneCallParams * linphone_call_params_copy(const LinphoneCallParams *cp){ LinphoneCallParams *ncp=ms_new0(LinphoneCallParams,1); - memcpy(ncp,cp,sizeof(LinphoneCallParams)); + _linphone_call_params_copy(ncp,cp); return ncp; } +void linphone_call_params_uninit(LinphoneCallParams *p){ + if (p->record_file) ms_free(p->record_file); + if (p->custom_headers) sal_custom_header_free(p->custom_headers); +} + /** - * + * Destroy LinphoneCallParams. **/ void linphone_call_params_destroy(LinphoneCallParams *p){ + linphone_call_params_uninit(p); ms_free(p); } + /** * @} **/ @@ -942,11 +1168,11 @@ static void video_stream_event_cb(void *user_pointer, const MSFilter *f, const u ms_warning("Case is MS_VIDEO_DECODER_DECODING_ERRORS"); linphone_call_send_vfu_request(call); break; - case MS_VIDEO_DECODER_FIRST_IMAGE_DECODED: - ms_message("First video frame decoded successfully"); - if (call->nextVideoFrameDecoded._func != NULL) - call->nextVideoFrameDecoded._func(call, call->nextVideoFrameDecoded._user_data); - break; + case MS_VIDEO_DECODER_FIRST_IMAGE_DECODED: + ms_message("First video frame decoded successfully"); + if (call->nextVideoFrameDecoded._func != NULL) + call->nextVideoFrameDecoded._func(call, call->nextVideoFrameDecoded._user_data); + break; default: ms_warning("Unhandled event %i", event_id); break; @@ -955,19 +1181,21 @@ static void video_stream_event_cb(void *user_pointer, const MSFilter *f, const u #endif void linphone_call_set_next_video_frame_decoded_callback(LinphoneCall *call, LinphoneCallCbFunc cb, void* user_data) { - call->nextVideoFrameDecoded._func = cb; - call->nextVideoFrameDecoded._user_data = user_data; + call->nextVideoFrameDecoded._func = cb; + call->nextVideoFrameDecoded._user_data = user_data; #ifdef VIDEO_ENABLED - ms_filter_call_method_noarg(call->videostream->decoder, MS_VIDEO_DECODER_RESET_FIRST_IMAGE_NOTIFICATION); + ms_filter_call_method_noarg(call->videostream->ms.decoder, MS_VIDEO_DECODER_RESET_FIRST_IMAGE_NOTIFICATION); #endif } void linphone_call_init_audio_stream(LinphoneCall *call){ LinphoneCore *lc=call->core; AudioStream *audiostream; - int dscp=linphone_core_get_audio_dscp(lc); + int dscp; + if (call->audiostream != NULL) return; call->audiostream=audiostream=audio_stream_new(call->audio_port,call->audio_port+1,linphone_core_ipv6_enabled(lc)); + dscp=linphone_core_get_audio_dscp(lc); if (dscp!=-1) audio_stream_set_dscp(audiostream,dscp); if (linphone_core_echo_limiter_enabled(lc)){ @@ -1000,26 +1228,31 @@ void linphone_call_init_audio_stream(LinphoneCall *call){ if (lc->rtptf){ RtpTransport *artp=lc->rtptf->audio_rtp_func(lc->rtptf->audio_rtp_func_data, call->audio_port); RtpTransport *artcp=lc->rtptf->audio_rtcp_func(lc->rtptf->audio_rtcp_func_data, call->audio_port+1); - rtp_session_set_transports(audiostream->session,artp,artcp); + rtp_session_set_transports(audiostream->ms.session,artp,artcp); } if ((linphone_core_get_firewall_policy(lc) == LinphonePolicyUseIce) && (call->ice_session != NULL)){ - rtp_session_set_pktinfo(audiostream->session, TRUE); - rtp_session_set_symmetric_rtp(audiostream->session, FALSE); + rtp_session_set_pktinfo(audiostream->ms.session, TRUE); + rtp_session_set_symmetric_rtp(audiostream->ms.session, FALSE); if (ice_session_check_list(call->ice_session, 0) == NULL) { ice_session_add_check_list(call->ice_session, ice_check_list_new()); } - audiostream->ice_check_list = ice_session_check_list(call->ice_session, 0); - ice_check_list_set_rtp_session(audiostream->ice_check_list, audiostream->session); + audiostream->ms.ice_check_list = ice_session_check_list(call->ice_session, 0); + ice_check_list_set_rtp_session(audiostream->ms.ice_check_list, audiostream->ms.session); } call->audiostream_app_evq = ortp_ev_queue_new(); - rtp_session_register_event_queue(audiostream->session,call->audiostream_app_evq); + rtp_session_register_event_queue(audiostream->ms.session,call->audiostream_app_evq); } void linphone_call_init_video_stream(LinphoneCall *call){ #ifdef VIDEO_ENABLED LinphoneCore *lc=call->core; + if (!call->params.has_video) { + linphone_call_stop_video_stream(call); + return; + } + if (call->videostream != NULL) return; if ((lc->video_conf.display || lc->video_conf.capture) && call->params.has_video){ int video_recv_buf_size=lp_config_get_int(lc->config,"video","recv_buf_size",0); int dscp=linphone_core_get_video_dscp(lc); @@ -1028,7 +1261,7 @@ void linphone_call_init_video_stream(LinphoneCall *call){ if (dscp!=-1) video_stream_set_dscp(call->videostream,dscp); video_stream_enable_display_filter_auto_rotate(call->videostream, lp_config_get_int(lc->config,"video","display_filter_auto_rotate",0)); - if (video_recv_buf_size>0) rtp_session_set_recv_buf_size(call->videostream->session,video_recv_buf_size); + if (video_recv_buf_size>0) rtp_session_set_recv_buf_size(call->videostream->ms.session,video_recv_buf_size); if( lc->video_conf.displaytype != NULL) video_stream_set_display_filter_name(call->videostream,lc->video_conf.displaytype); @@ -1036,19 +1269,19 @@ void linphone_call_init_video_stream(LinphoneCall *call){ if (lc->rtptf){ RtpTransport *vrtp=lc->rtptf->video_rtp_func(lc->rtptf->video_rtp_func_data, call->video_port); RtpTransport *vrtcp=lc->rtptf->video_rtcp_func(lc->rtptf->video_rtcp_func_data, call->video_port+1); - rtp_session_set_transports(call->videostream->session,vrtp,vrtcp); + rtp_session_set_transports(call->videostream->ms.session,vrtp,vrtcp); } if ((linphone_core_get_firewall_policy(lc) == LinphonePolicyUseIce) && (call->ice_session != NULL)){ - rtp_session_set_pktinfo(call->videostream->session, TRUE); - rtp_session_set_symmetric_rtp(call->videostream->session, FALSE); + rtp_session_set_pktinfo(call->videostream->ms.session, TRUE); + rtp_session_set_symmetric_rtp(call->videostream->ms.session, FALSE); if (ice_session_check_list(call->ice_session, 1) == NULL) { ice_session_add_check_list(call->ice_session, ice_check_list_new()); } - call->videostream->ice_check_list = ice_session_check_list(call->ice_session, 1); - ice_check_list_set_rtp_session(call->videostream->ice_check_list, call->videostream->session); + call->videostream->ms.ice_check_list = ice_session_check_list(call->ice_session, 1); + ice_check_list_set_rtp_session(call->videostream->ms.ice_check_list, call->videostream->ms.session); } call->videostream_app_evq = ortp_ev_queue_new(); - rtp_session_register_event_queue(call->videostream->session,call->videostream_app_evq); + rtp_session_register_event_queue(call->videostream->ms.session,call->videostream_app_evq); #ifdef TEST_EXT_RENDERER video_stream_set_render_callback(call->videostream,rendercb,NULL); #endif @@ -1066,8 +1299,7 @@ void linphone_call_init_media_streams(LinphoneCall *call){ static int dtmf_tab[16]={'0','1','2','3','4','5','6','7','8','9','*','#','A','B','C','D'}; -static void linphone_core_dtmf_received(RtpSession* s, int dtmf, void* user_data){ - LinphoneCore* lc = (LinphoneCore*)user_data; +static void linphone_core_dtmf_received(LinphoneCore *lc, int dtmf){ if (dtmf<0 || dtmf>15){ ms_warning("Bad dtmf value %i",dtmf); return; @@ -1099,7 +1331,7 @@ static void parametrize_equalizer(LinphoneCore *lc, AudioStream *st){ } void _post_configure_audio_stream(AudioStream *st, LinphoneCore *lc, bool_t muted){ - float mic_gain=lp_config_get_float(lc->config,"sound","mic_gain",1); + float mic_gain=lc->sound_conf.soft_mic_lev; float thres = 0; float recv_gain; float ng_thres=lp_config_get_float(lc->config,"sound","ng_thres",0.05); @@ -1107,7 +1339,7 @@ void _post_configure_audio_stream(AudioStream *st, LinphoneCore *lc, bool_t mute int dc_removal=lp_config_get_int(lc->config,"sound","dc_removal",0); if (!muted) - audio_stream_set_mic_gain(st,mic_gain); + linphone_core_set_mic_gain_db (lc, mic_gain); else audio_stream_set_mic_gain(st,0); @@ -1141,7 +1373,7 @@ void _post_configure_audio_stream(AudioStream *st, LinphoneCore *lc, bool_t mute } if (st->volrecv){ /* parameters for a limited noise-gate effect, using echo limiter threshold */ - float floorgain = 1/mic_gain; + float floorgain = 1/pow(10,(mic_gain)/10); int spk_agc=lp_config_get_int(lc->config,"sound","speaker_agc_enabled",0); ms_filter_call_method(st->volrecv, MS_VOLUME_ENABLE_AGC, &spk_agc); ms_filter_call_method(st->volrecv,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_thres); @@ -1155,10 +1387,10 @@ static void post_configure_audio_streams(LinphoneCall*call){ LinphoneCore *lc=call->core; _post_configure_audio_stream(st,lc,call->audio_muted); if (lc->vtable.dtmf_received!=NULL){ - /* replace by our default action*/ audio_stream_play_received_dtmfs(call->audiostream,FALSE); - rtp_session_signal_connect(call->audiostream->session,"telephone-event",(RtpCallback)linphone_core_dtmf_received,(unsigned long)lc); } + if (call->record_active) + linphone_call_start_recording(call); } static RtpProfile *make_profile(LinphoneCall *call, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){ @@ -1310,6 +1542,8 @@ static void linphone_call_start_audio_stream(LinphoneCall *call, const char *cna if (captcard && stream->max_rate>0) ms_snd_card_set_preferred_sample_rate(captcard, stream->max_rate); audio_stream_enable_adaptive_bitrate_control(call->audiostream,use_arc); audio_stream_enable_adaptive_jittcomp(call->audiostream, linphone_core_audio_adaptive_jittcomp_enabled(lc)); + if (!call->params.in_conference && call->params.record_file) + audio_stream_mixed_record_open(call->audiostream,call->params.record_file); audio_stream_start_full( call->audiostream, call->audio_profile, @@ -1338,23 +1572,23 @@ static void linphone_call_start_audio_stream(LinphoneCall *call, const char *cna } audio_stream_set_rtcp_information(call->audiostream, cname, rtcp_tool); - /* valid local tags are > 0 */ + /* valid local tags are > 0 */ if (stream->proto == SalProtoRtpSavp) { - const SalStreamDescription *local_st_desc=sal_media_description_find_stream(call->localdesc, - SalProtoRtpSavp,SalAudio); - int crypto_idx = find_crypto_index_from_tag(local_st_desc->crypto, stream->crypto_local_tag); - - if (crypto_idx >= 0) { - audio_stream_enable_strp( - call->audiostream, - stream->crypto[0].algo, - local_st_desc->crypto[crypto_idx].master_key, - stream->crypto[0].master_key); - call->audiostream_encrypted=TRUE; - } else { - ms_warning("Failed to find local crypto algo with tag: %d", stream->crypto_local_tag); - call->audiostream_encrypted=FALSE; - } + const SalStreamDescription *local_st_desc=sal_media_description_find_stream(call->localdesc, + SalProtoRtpSavp,SalAudio); + int crypto_idx = find_crypto_index_from_tag(local_st_desc->crypto, stream->crypto_local_tag); + + if (crypto_idx >= 0) { + audio_stream_enable_srtp( + call->audiostream, + stream->crypto[0].algo, + local_st_desc->crypto[crypto_idx].master_key, + stream->crypto[0].master_key); + call->audiostream_encrypted=TRUE; + } else { + ms_warning("Failed to find local crypto algo with tag: %d", stream->crypto_local_tag); + call->audiostream_encrypted=FALSE; + } }else call->audiostream_encrypted=FALSE; if (call->params.in_conference){ /*transform the graph to connect it to the conference filter */ @@ -1362,6 +1596,7 @@ static void linphone_call_start_audio_stream(LinphoneCall *call, const char *cna linphone_call_add_to_conf(call, mute); } call->current_params.in_conference=call->params.in_conference; + call->current_params.low_bandwidth=call->params.low_bandwidth; }else ms_warning("No audio stream accepted ?"); } } @@ -1431,7 +1666,7 @@ static void linphone_call_start_video_stream(LinphoneCall *call, const char *cna cam=get_nowebcam_device(); } if (!is_inactive){ - call->log->video_enabled = TRUE; + call->log->video_enabled = TRUE; video_stream_set_direction (call->videostream, dir); ms_message("%s lc rotation:%d\n", __FUNCTION__, lc->device_rotation); video_stream_set_device_rotation(call->videostream, lc->device_rotation); @@ -1535,26 +1770,105 @@ void linphone_call_start_media_streams_for_ice_gathering(LinphoneCall *call){ #endif } +void linphone_call_stop_media_streams_for_ice_gathering(LinphoneCall *call){ + audio_stream_unprepare_sound(call->audiostream); +#ifdef VIDEO_ENABLED + if (call->videostream) { + video_stream_unprepare_video(call->videostream); + } +#endif +} + +void linphone_call_update_crypto_parameters(LinphoneCall *call, SalMediaDescription *old_md, SalMediaDescription *new_md) { + SalStreamDescription *old_stream; + SalStreamDescription *new_stream; + int i; + + old_stream = sal_media_description_find_stream(old_md, SalProtoRtpSavp, SalAudio); + new_stream = sal_media_description_find_stream(new_md, SalProtoRtpSavp, SalAudio); + if (old_stream && new_stream) { + const SalStreamDescription *local_st_desc = sal_media_description_find_stream(call->localdesc, SalProtoRtpSavp, SalAudio); + if (local_st_desc) { + int crypto_idx = find_crypto_index_from_tag(local_st_desc->crypto, new_stream->crypto_local_tag); + if (crypto_idx >= 0) { + audio_stream_enable_srtp(call->audiostream, new_stream->crypto[0].algo, local_st_desc->crypto[crypto_idx].master_key, new_stream->crypto[0].master_key); + call->audiostream_encrypted = TRUE; + } else { + ms_warning("Failed to find local crypto algo with tag: %d", new_stream->crypto_local_tag); + call->audiostream_encrypted = FALSE; + } + for (i = 0; i < SAL_CRYPTO_ALGO_MAX; i++) { + old_stream->crypto[i].tag = new_stream->crypto[i].tag; + old_stream->crypto[i].algo = new_stream->crypto[i].algo; + strncpy(old_stream->crypto[i].master_key, new_stream->crypto[i].master_key, sizeof(old_stream->crypto[i].master_key) - 1); + } + } + } + +#ifdef VIDEO_ENABLED + old_stream = sal_media_description_find_stream(old_md, SalProtoRtpSavp, SalVideo); + new_stream = sal_media_description_find_stream(new_md, SalProtoRtpSavp, SalVideo); + if (old_stream && new_stream) { + const SalStreamDescription *local_st_desc = sal_media_description_find_stream(call->localdesc, SalProtoRtpSavp, SalVideo); + if (local_st_desc) { + int crypto_idx = find_crypto_index_from_tag(local_st_desc->crypto, new_stream->crypto_local_tag); + if (crypto_idx >= 0) { + video_stream_enable_strp(call->videostream, new_stream->crypto[0].algo, local_st_desc->crypto[crypto_idx].master_key, new_stream->crypto[0].master_key); + call->videostream_encrypted = TRUE; + } else { + ms_warning("Failed to find local crypto algo with tag: %d", new_stream->crypto_local_tag); + call->videostream_encrypted = FALSE; + } + for (i = 0; i < SAL_CRYPTO_ALGO_MAX; i++) { + old_stream->crypto[i].tag = new_stream->crypto[i].tag; + old_stream->crypto[i].algo = new_stream->crypto[i].algo; + strncpy(old_stream->crypto[i].master_key, new_stream->crypto[i].master_key, sizeof(old_stream->crypto[i].master_key) - 1); + } + } + } +#endif +} + +void linphone_call_update_remote_session_id_and_ver(LinphoneCall *call) { + SalMediaDescription *remote_desc = sal_call_get_remote_media_description(call->op); + if (remote_desc) { + call->remote_session_id = remote_desc->session_id; + call->remote_session_ver = remote_desc->session_ver; + } +} + void linphone_call_delete_ice_session(LinphoneCall *call){ if (call->ice_session != NULL) { ice_session_destroy(call->ice_session); call->ice_session = NULL; - if (call->audiostream != NULL) call->audiostream->ice_check_list = NULL; - if (call->videostream != NULL) call->videostream->ice_check_list = NULL; + if (call->audiostream != NULL) call->audiostream->ms.ice_check_list = NULL; + if (call->videostream != NULL) call->videostream->ms.ice_check_list = NULL; call->stats[LINPHONE_CALL_STATS_AUDIO].ice_state = LinphoneIceStateNotActivated; call->stats[LINPHONE_CALL_STATS_VIDEO].ice_state = LinphoneIceStateNotActivated; } } -static void linphone_call_log_fill_stats(LinphoneCallLog *log, AudioStream *st){ - audio_stream_get_local_rtp_stats (st,&log->local_stats); - log->quality=audio_stream_get_average_quality_rating(st); +#ifdef BUILD_UPNP +void linphone_call_delete_upnp_session(LinphoneCall *call){ + if(call->upnp_session!=NULL) { + linphone_upnp_session_destroy(call->upnp_session); + call->upnp_session=NULL; + } } +#endif //BUILD_UPNP -void linphone_call_stop_media_streams(LinphoneCall *call){ +static void linphone_call_log_fill_stats(LinphoneCallLog *log, MediaStream *st){ + float quality=media_stream_get_average_quality_rating(st); + if (quality>=0){ + if (log->quality!=-1){ + log->quality*=quality/5.0; + }else log->quality=quality; + } +} + +void linphone_call_stop_audio_stream(LinphoneCall *call) { if (call->audiostream!=NULL) { - call->audiostream->ice_check_list = NULL; - rtp_session_unregister_event_queue(call->audiostream->session,call->audiostream_app_evq); + rtp_session_unregister_event_queue(call->audiostream->ms.session,call->audiostream_app_evq); ortp_ev_queue_flush(call->audiostream_app_evq); ortp_ev_queue_destroy(call->audiostream_app_evq); call->audiostream_app_evq=NULL; @@ -1567,26 +1881,33 @@ void linphone_call_stop_media_streams(LinphoneCall *call){ lp_config_set_string(call->core->config,"sound","ec_state",state_str); } } - linphone_call_log_fill_stats (call->log,call->audiostream); + audio_stream_get_local_rtp_stats(call->audiostream,&call->log->local_stats); + linphone_call_log_fill_stats (call->log,(MediaStream*)call->audiostream); if (call->endpoint){ linphone_call_remove_from_conf(call); } audio_stream_stop(call->audiostream); call->audiostream=NULL; } +} - +void linphone_call_stop_video_stream(LinphoneCall *call) { #ifdef VIDEO_ENABLED if (call->videostream!=NULL){ - call->videostream->ice_check_list = NULL; - rtp_session_unregister_event_queue(call->videostream->session,call->videostream_app_evq); + rtp_session_unregister_event_queue(call->videostream->ms.session,call->videostream_app_evq); ortp_ev_queue_flush(call->videostream_app_evq); ortp_ev_queue_destroy(call->videostream_app_evq); call->videostream_app_evq=NULL; + linphone_call_log_fill_stats(call->log,(MediaStream*)call->videostream); video_stream_stop(call->videostream); call->videostream=NULL; } #endif +} + +void linphone_call_stop_media_streams(LinphoneCall *call){ + linphone_call_stop_audio_stream(call); + linphone_call_stop_video_stream(call); ms_event_queue_skip(call->core->msevq); if (call->audio_profile){ @@ -1694,10 +2015,20 @@ float linphone_call_get_record_volume(LinphoneCall *call){ * active audio stream exist. Otherwise it returns the quality rating. **/ float linphone_call_get_current_quality(LinphoneCall *call){ + float audio_rating=-1; + float video_rating=-1; + float result; if (call->audiostream){ - return audio_stream_get_quality_rating(call->audiostream); + audio_rating=media_stream_get_quality_rating((MediaStream*)call->audiostream)/5.0; } - return -1; + if (call->videostream){ + video_rating=media_stream_get_quality_rating((MediaStream*)call->videostream)/5.0; + } + if (audio_rating<0 && video_rating<0) result=-1; + else if (audio_rating<0) result=video_rating*5.0; + else if (video_rating<0) result=audio_rating*5.0; + else result=audio_rating*video_rating*5.0; + return result; } /** @@ -1712,20 +2043,83 @@ float linphone_call_get_average_quality(LinphoneCall *call){ return -1; } +static void update_local_stats(LinphoneCallStats *stats, MediaStream *stream){ + const MSQualityIndicator *qi=media_stream_get_quality_indicator(stream); + if (qi) { + stats->local_late_rate=ms_quality_indicator_get_local_late_rate(qi); + stats->local_loss_rate=ms_quality_indicator_get_local_loss_rate(qi); + } +} + /** * Access last known statistics for audio stream, for a given call. **/ -const LinphoneCallStats *linphone_call_get_audio_stats(const LinphoneCall *call) { - return &call->stats[LINPHONE_CALL_STATS_AUDIO]; +const LinphoneCallStats *linphone_call_get_audio_stats(LinphoneCall *call) { + LinphoneCallStats *stats=&call->stats[LINPHONE_CALL_STATS_AUDIO]; + if (call->audiostream){ + update_local_stats(stats,(MediaStream*)call->audiostream); + } + return stats; } /** * Access last known statistics for video stream, for a given call. **/ -const LinphoneCallStats *linphone_call_get_video_stats(const LinphoneCall *call) { - return &call->stats[LINPHONE_CALL_STATS_VIDEO]; +const LinphoneCallStats *linphone_call_get_video_stats(LinphoneCall *call) { + LinphoneCallStats *stats=&call->stats[LINPHONE_CALL_STATS_VIDEO]; + if (call->videostream){ + update_local_stats(stats,(MediaStream*)call->videostream); + } + return stats; } +/** + * Enable recording of the call (voice-only). + * This function must be used before the call parameters are assigned to the call. + * The call recording can be started and paused after the call is established with + * linphone_call_start_recording() and linphone_call_pause_recording(). + * @param cp the call parameters + * @param path path and filename of the file where audio is written. +**/ +void linphone_call_params_set_record_file(LinphoneCallParams *cp, const char *path){ + if (cp->record_file){ + ms_free(cp->record_file); + cp->record_file=NULL; + } + if (path) cp->record_file=ms_strdup(path); +} + +/** + * Retrieves the path for the audio recoding of the call. +**/ +const char *linphone_call_params_get_record_file(const LinphoneCallParams *cp){ + return cp->record_file; +} + +/** + * Start call recording. + * The output file where audio is recorded must be previously specified with linphone_call_params_set_record_file(). +**/ +void linphone_call_start_recording(LinphoneCall *call){ + if (!call->params.record_file){ + ms_error("linphone_call_start_recording(): no output file specified. Use linphone_call_params_set_record_file()."); + return; + } + if (call->audiostream && !call->params.in_conference){ + audio_stream_mixed_record_start(call->audiostream); + } + call->record_active=TRUE; +} + +/** + * Stop call recording. +**/ +void linphone_call_stop_recording(LinphoneCall *call){ + if (call->audiostream && !call->params.in_conference){ + audio_stream_mixed_record_stop(call->audiostream); + } + call->record_active=FALSE; +} /** * @} @@ -1752,7 +2146,7 @@ static void linphone_core_disconnected(LinphoneCore *lc, LinphoneCall *call){ if (from) { snprintf(temp,sizeof(temp),"Remote end %s seems to have disconnected, the call is going to be closed.",from); - free(from); + ms_free(from); } else { @@ -1761,6 +2155,7 @@ static void linphone_core_disconnected(LinphoneCore *lc, LinphoneCall *call){ if (lc->vtable.display_warning!=NULL) lc->vtable.display_warning(lc,temp); linphone_core_terminate_call(lc,call); + linphone_core_play_named_tone(lc,LinphoneToneCallFailed); } static void handle_ice_events(LinphoneCall *call, OrtpEvent *ev){ @@ -1795,9 +2190,8 @@ static void handle_ice_events(LinphoneCall *call, OrtpEvent *ev){ ice_session_compute_candidates_foundations(call->ice_session); ice_session_eliminate_redundant_candidates(call->ice_session); ice_session_choose_default_candidates(call->ice_session); - ping_time = ice_session_gathering_duration(call->ice_session); + ping_time = ice_session_average_gathering_round_trip_time(call->ice_session); if (ping_time >=0) { - ping_time /= ice_session_nb_check_lists(call->ice_session); call->ping_time=ping_time; } } else { @@ -1805,23 +2199,26 @@ static void handle_ice_events(LinphoneCall *call, OrtpEvent *ev){ linphone_call_delete_ice_session(call); } switch (call->state) { - case LinphoneCallStreamsRunning: + case LinphoneCallUpdating: linphone_core_start_update_call(call->core, call); break; case LinphoneCallUpdatedByRemote: linphone_core_start_accept_call_update(call->core, call); break; case LinphoneCallOutgoingInit: - linphone_call_stop_media_streams(call); + linphone_call_stop_media_streams_for_ice_gathering(call); linphone_core_proceed_with_invite_if_ready(call->core, call, NULL); break; - default: - linphone_call_stop_media_streams(call); + case LinphoneCallIdle: + linphone_call_stop_media_streams_for_ice_gathering(call); linphone_core_notify_incoming_call(call->core, call); break; + default: + break; } } else if (evt == ORTP_EVENT_ICE_LOSING_PAIRS_COMPLETED) { linphone_core_start_accept_call_update(call->core, call); + linphone_core_update_ice_state_in_call_stats(call); } else if (evt == ORTP_EVENT_ICE_RESTART_NEEDED) { ice_session_restart(call->ice_session); ice_session_set_role(call->ice_session, IR_Controlling); @@ -1838,24 +2235,29 @@ void linphone_call_background_tasks(LinphoneCall *call, bool_t one_second_elapse RtpSession *as=NULL,*vs=NULL; float audio_load=0, video_load=0; if (call->audiostream!=NULL){ - as=call->audiostream->session; - if (call->audiostream->ticker) - audio_load=ms_ticker_get_average_load(call->audiostream->ticker); + as=call->audiostream->ms.session; + if (call->audiostream->ms.ticker) + audio_load=ms_ticker_get_average_load(call->audiostream->ms.ticker); } if (call->videostream!=NULL){ - if (call->videostream->ticker) - video_load=ms_ticker_get_average_load(call->videostream->ticker); - vs=call->videostream->session; + if (call->videostream->ms.ticker) + video_load=ms_ticker_get_average_load(call->videostream->ms.ticker); + vs=call->videostream->ms.session; } report_bandwidth(call,as,vs); ms_message("Thread processing load: audio=%f\tvideo=%f",audio_load,video_load); } + +#ifdef BUILD_UPNP + linphone_upnp_call_process(call); +#endif //BUILD_UPNP + #ifdef VIDEO_ENABLED if (call->videostream!=NULL) { OrtpEvent *ev; /* Ensure there is no dangling ICE check list. */ - if (call->ice_session == NULL) call->videostream->ice_check_list = NULL; + if (call->ice_session == NULL) call->videostream->ms.ice_check_list = NULL; // Beware that the application queue should not depend on treatments fron the // mediastreamer queue. @@ -1867,19 +2269,21 @@ void linphone_call_background_tasks(LinphoneCall *call, bool_t one_second_elapse if (evt == ORTP_EVENT_ZRTP_ENCRYPTION_CHANGED){ linphone_call_videostream_encryption_changed(call, evd->info.zrtp_stream_encrypted); } else if (evt == ORTP_EVENT_RTCP_PACKET_RECEIVED) { - call->stats[LINPHONE_CALL_STATS_VIDEO].round_trip_delay = rtp_session_get_round_trip_propagation(call->videostream->session); + call->stats[LINPHONE_CALL_STATS_VIDEO].round_trip_delay = rtp_session_get_round_trip_propagation(call->videostream->ms.session); if(call->stats[LINPHONE_CALL_STATS_VIDEO].received_rtcp != NULL) freemsg(call->stats[LINPHONE_CALL_STATS_VIDEO].received_rtcp); call->stats[LINPHONE_CALL_STATS_VIDEO].received_rtcp = evd->packet; evd->packet = NULL; + update_local_stats(&call->stats[LINPHONE_CALL_STATS_VIDEO],(MediaStream*)call->videostream); if (lc->vtable.call_stats_updated) lc->vtable.call_stats_updated(lc, call, &call->stats[LINPHONE_CALL_STATS_VIDEO]); } else if (evt == ORTP_EVENT_RTCP_PACKET_EMITTED) { - memcpy(&call->stats[LINPHONE_CALL_STATS_VIDEO].jitter_stats, rtp_session_get_jitter_stats(call->videostream->session), sizeof(jitter_stats_t)); + memcpy(&call->stats[LINPHONE_CALL_STATS_VIDEO].jitter_stats, rtp_session_get_jitter_stats(call->videostream->ms.session), sizeof(jitter_stats_t)); if(call->stats[LINPHONE_CALL_STATS_VIDEO].sent_rtcp != NULL) freemsg(call->stats[LINPHONE_CALL_STATS_VIDEO].sent_rtcp); call->stats[LINPHONE_CALL_STATS_VIDEO].sent_rtcp = evd->packet; evd->packet = NULL; + update_local_stats(&call->stats[LINPHONE_CALL_STATS_VIDEO],(MediaStream*)call->videostream); if (lc->vtable.call_stats_updated) lc->vtable.call_stats_updated(lc, call, &call->stats[LINPHONE_CALL_STATS_VIDEO]); } else if ((evt == ORTP_EVENT_ICE_SESSION_PROCESSING_FINISHED) || (evt == ORTP_EVENT_ICE_GATHERING_FINISHED) @@ -1894,7 +2298,7 @@ void linphone_call_background_tasks(LinphoneCall *call, bool_t one_second_elapse OrtpEvent *ev; /* Ensure there is no dangling ICE check list. */ - if (call->ice_session == NULL) call->audiostream->ice_check_list = NULL; + if (call->ice_session == NULL) call->audiostream->ms.ice_check_list = NULL; // Beware that the application queue should not depend on treatments fron the // mediastreamer queue. @@ -1908,24 +2312,28 @@ void linphone_call_background_tasks(LinphoneCall *call, bool_t one_second_elapse } else if (evt == ORTP_EVENT_ZRTP_SAS_READY) { linphone_call_audiostream_auth_token_ready(call, evd->info.zrtp_sas.sas, evd->info.zrtp_sas.verified); } else if (evt == ORTP_EVENT_RTCP_PACKET_RECEIVED) { - call->stats[LINPHONE_CALL_STATS_AUDIO].round_trip_delay = rtp_session_get_round_trip_propagation(call->audiostream->session); + call->stats[LINPHONE_CALL_STATS_AUDIO].round_trip_delay = rtp_session_get_round_trip_propagation(call->audiostream->ms.session); if(call->stats[LINPHONE_CALL_STATS_AUDIO].received_rtcp != NULL) freemsg(call->stats[LINPHONE_CALL_STATS_AUDIO].received_rtcp); call->stats[LINPHONE_CALL_STATS_AUDIO].received_rtcp = evd->packet; evd->packet = NULL; + update_local_stats(&call->stats[LINPHONE_CALL_STATS_AUDIO],(MediaStream*)call->audiostream); if (lc->vtable.call_stats_updated) lc->vtable.call_stats_updated(lc, call, &call->stats[LINPHONE_CALL_STATS_AUDIO]); } else if (evt == ORTP_EVENT_RTCP_PACKET_EMITTED) { - memcpy(&call->stats[LINPHONE_CALL_STATS_AUDIO].jitter_stats, rtp_session_get_jitter_stats(call->audiostream->session), sizeof(jitter_stats_t)); + memcpy(&call->stats[LINPHONE_CALL_STATS_AUDIO].jitter_stats, rtp_session_get_jitter_stats(call->audiostream->ms.session), sizeof(jitter_stats_t)); if(call->stats[LINPHONE_CALL_STATS_AUDIO].sent_rtcp != NULL) freemsg(call->stats[LINPHONE_CALL_STATS_AUDIO].sent_rtcp); call->stats[LINPHONE_CALL_STATS_AUDIO].sent_rtcp = evd->packet; evd->packet = NULL; + update_local_stats(&call->stats[LINPHONE_CALL_STATS_AUDIO],(MediaStream*)call->audiostream); if (lc->vtable.call_stats_updated) lc->vtable.call_stats_updated(lc, call, &call->stats[LINPHONE_CALL_STATS_AUDIO]); } else if ((evt == ORTP_EVENT_ICE_SESSION_PROCESSING_FINISHED) || (evt == ORTP_EVENT_ICE_GATHERING_FINISHED) || (evt == ORTP_EVENT_ICE_LOSING_PAIRS_COMPLETED) || (evt == ORTP_EVENT_ICE_RESTART_NEEDED)) { handle_ice_events(call, ev); + } else if (evt==ORTP_EVENT_TELEPHONE_EVENT){ + linphone_core_dtmf_received(lc,evd->info.telephone_event); } ortp_event_destroy(ev); } @@ -1981,6 +2389,46 @@ void linphone_call_set_transfer_state(LinphoneCall* call, LinphoneCallState stat } } +/** + * Returns true if the call is part of the conference. + * @ingroup conferencing +**/ bool_t linphone_call_is_in_conference(const LinphoneCall *call) { return call->params.in_conference; } + + +/** + * Perform a zoom of the video displayed during a call. + * @param call the call. + * @param zoom_factor a floating point number describing the zoom factor. A value 1.0 corresponds to no zoom applied. + * @param cx a floating point number pointing the horizontal center of the zoom to be applied. This value should be between 0.0 and 1.0. + * @param cy a floating point number pointing the vertical center of the zoom to be applied. This value should be between 0.0 and 1.0. + * + * cx and cy are updated in return in case their coordinates were to excentrated for the requested zoom factor. The zoom ensures that all the screen is fullfilled with the video. +**/ +void linphone_call_zoom_video(LinphoneCall* call, float zoom_factor, float* cx, float* cy) { + VideoStream* vstream = call->videostream; + if (vstream && vstream->output) { + float zoom[3]; + + if (zoom_factor < 1) + zoom_factor = 1; + float halfsize = 0.5 * 1.0 / zoom_factor; + + if ((*cx - halfsize) < 0) + *cx = 0 + halfsize; + if ((*cx + halfsize) > 1) + *cx = 1 - halfsize; + if ((*cy - halfsize) < 0) + *cy = 0 + halfsize; + if ((*cy + halfsize) > 1) + *cy = 1 - halfsize; + + zoom[0] = zoom_factor; + zoom[1] = *cx; + zoom[2] = *cy; + ms_filter_call_method(vstream->output, MS_VIDEO_DISPLAY_ZOOM, &zoom); + }else ms_warning("Could not apply zoom: video output wasn't activated."); +} +