]> sjero.net Git - linphone/blobdiff - coreapi/linphonecall.c
Declare variables at the beginning of code blocks to fix compilation errors.
[linphone] / coreapi / linphonecall.c
index e9640701f698c17be5f16086caafbd4e984a9d8f..d5366e5c66a3da90a322392b1adaa029a39626b9 100644 (file)
@@ -84,9 +84,11 @@ static bool_t linphone_call_are_all_streams_encrypted(LinphoneCall *call) {
 
 #ifdef VIDEO_ENABLED
        // If video enabled, check ZRTP encryption in videostream
-       const LinphoneCallParams *params=linphone_call_get_current_params(call);
-       if (params->has_video && !call->videostream_encrypted) {
-               return FALSE;
+       {
+               const LinphoneCallParams *params=linphone_call_get_current_params(call);
+               if (params->has_video && !call->videostream_encrypted) {
+                       return FALSE;
+               }
        }
 #endif
 
@@ -110,9 +112,9 @@ void propagate_encryption_changed(LinphoneCall *call){
 
 #ifdef VIDEO_ENABLED
 static void linphone_call_videostream_encryption_changed(void *data, bool_t encrypted){
-       ms_message("Video stream is %s", encrypted ? "encrypted" : "not encrypted");
-
        LinphoneCall *call = (LinphoneCall *)data;
+
+       ms_message("Video stream is %s", encrypted ? "encrypted" : "not encrypted");
        call->videostream_encrypted=encrypted;
        propagate_encryption_changed(call);
 }
@@ -135,12 +137,14 @@ static void linphone_call_audiostream_encryption_changed(void *data, bool_t encr
 
 #ifdef VIDEO_ENABLED
        // Enable video encryption
-       const LinphoneCallParams *params=linphone_call_get_current_params(call);
-       if (params->has_video) {
-               ms_message("Trying to enable encryption on video stream");
-               OrtpZrtpParams params;
-               params.zid_file=NULL; //unused
-               video_stream_enable_zrtp(call->videostream,call->audiostream,&params);
+       {
+               const LinphoneCallParams *params=linphone_call_get_current_params(call);
+               if (params->has_video) {
+                       OrtpZrtpParams params;
+                       ms_message("Trying to enable encryption on video stream");
+                       params.zid_file=NULL; //unused
+                       video_stream_enable_zrtp(call->videostream,call->audiostream,&params);
+               }
        }
 #endif
 }
@@ -254,14 +258,6 @@ void linphone_call_make_local_media_description(LinphoneCore *lc, LinphoneCall *
        l=ms_list_append(l,pt);
        md->streams[0].payloads=l;
 
-       // if ZRTP is enabled, put the hello hash into the audiostream's desc
-       if (call->audiostream && call->audiostream->ms.zrtp_context!=NULL){
-               ortp_zrtp_get_hello_hash(call->audiostream->ms.zrtp_context,
-                       md->streams[0].zrtp_hello_hash,
-                       sizeof(md->streams[0].zrtp_hello_hash));
-               ms_message("Audio stream zrtp hash: %s", md->streams[0].zrtp_hello_hash);
-       }
-
        if (call->params.has_video){
                md->n_active_streams++;
                md->streams[1].rtp_port=call->video_port;
@@ -270,13 +266,6 @@ void linphone_call_make_local_media_description(LinphoneCore *lc, LinphoneCall *
                md->streams[1].type=SalVideo;
                l=make_codec_list(lc,lc->codecs_conf.video_codecs,0,NULL,-1);
                md->streams[1].payloads=l;
-               // if ZRTP is enabled, put the hello hash into the audiostream's desc
-               if (call->videostream->ms.zrtp_context!=NULL){
-                       ortp_zrtp_get_hello_hash(call->videostream->ms.zrtp_context,
-                               md->streams[1].zrtp_hello_hash,
-                               sizeof(md->streams[1].zrtp_hello_hash));
-                       ms_message("Video stream zrtp hash: %s", md->streams[1].zrtp_hello_hash);
-               }
        }
        if (md->n_total_streams < md->n_active_streams)
                md->n_total_streams = md->n_active_streams;
@@ -484,7 +473,7 @@ 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);
        _linphone_call_params_copy(&call->params,params);
        sal_op_set_custom_header(call->op,call->params.custom_headers);
@@ -543,7 +532,7 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro
        }
 
        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);
@@ -1309,20 +1298,6 @@ void linphone_call_init_video_stream(LinphoneCall *call){
 void linphone_call_init_media_streams(LinphoneCall *call){
        linphone_call_init_audio_stream(call);
        linphone_call_init_video_stream(call);
-
-       // moved from linphone_call_start_media_streams, because ZRTP needs to be
-       // at least partially initialized so that the SDP can contain 'zrtp-hash'
-       if (call->params.media_encryption==LinphoneMediaEncryptionZRTP) {
-               OrtpZrtpParams params;
-               /*will be set later when zrtp is activated*/
-               call->current_params.media_encryption=LinphoneMediaEncryptionNone;
-
-               params.zid_file=call->core->zrtp_secrets_cache;
-               audio_stream_enable_zrtp(call->audiostream,&params);
-       } else if (call->params.media_encryption==LinphoneMediaEncryptionSRTP){
-               call->current_params.media_encryption=linphone_call_are_all_streams_encrypted(call) ?
-                       LinphoneMediaEncryptionSRTP : LinphoneMediaEncryptionNone;
-       }
 }
 
 
@@ -1656,11 +1631,11 @@ static void linphone_call_start_video_stream(LinphoneCall *call, const char *cna
                const char *rtcp_addr=vstream->rtcp_addr[0]!='\0' ? vstream->rtcp_addr : call->resultdesc->addr;
                call->video_profile=make_profile(call,call->resultdesc,vstream,&used_pt);
                if (used_pt!=-1){
-                       call->current_params.video_codec = rtp_profile_get_payload(call->video_profile, used_pt);
                        VideoStreamDir dir=VideoStreamSendRecv;
                        MSWebCam *cam=lc->video_conf.device;
                        bool_t is_inactive=FALSE;
 
+                       call->current_params.video_codec = rtp_profile_get_payload(call->video_profile, used_pt);
                        call->current_params.has_video=TRUE;
 
                        video_stream_enable_adaptive_bitrate_control(call->videostream,
@@ -1730,9 +1705,6 @@ static void linphone_call_start_video_stream(LinphoneCall *call, const char *cna
 void linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_muted, bool_t send_ringbacktone){
        LinphoneCore *lc=call->core;
 
-       call->current_params.audio_codec = NULL;
-       call->current_params.video_codec = NULL;
-
        LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc);
        char *cname;
        bool_t use_arc=linphone_core_adaptive_rate_control_enabled(lc);
@@ -1741,6 +1713,9 @@ void linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_mut
                                                        SalProtoRtpAvp,SalVideo);
 #endif
 
+       call->current_params.audio_codec = NULL;
+       call->current_params.video_codec = NULL;
+
        if ((call->audiostream == NULL) && (call->videostream == NULL)) {
                ms_fatal("start_media_stream() called without prior init !");
                return;
@@ -1765,10 +1740,16 @@ void linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_mut
        call->playing_ringbacktone=send_ringbacktone;
        call->up_bw=linphone_core_get_upload_bandwidth(lc);
 
-       // ZRTP was initialized in linphone_call_init_media_streams with a
-       // partially iniitalized RtpSession, and now needs to get an update
        if (call->params.media_encryption==LinphoneMediaEncryptionZRTP) {
-               ortp_zrtp_start_engine(call->audiostream->ms.zrtp_context,call->audiostream->ms.session);
+               OrtpZrtpParams params;
+               /*will be set later when zrtp is activated*/
+               call->current_params.media_encryption=LinphoneMediaEncryptionNone;
+               
+               params.zid_file=lc->zrtp_secrets_cache;
+               audio_stream_enable_zrtp(call->audiostream,&params);
+       }else if (call->params.media_encryption==LinphoneMediaEncryptionSRTP){
+               call->current_params.media_encryption=linphone_call_are_all_streams_encrypted(call) ?
+                       LinphoneMediaEncryptionSRTP : LinphoneMediaEncryptionNone;
        }
 
        /*also reflect the change if the "wished" params, in order to avoid to propose SAVP or video again
@@ -1880,9 +1861,13 @@ void linphone_call_delete_upnp_session(LinphoneCall *call){
 }
 #endif //BUILD_UPNP
 
-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);
+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) {
@@ -1900,7 +1885,8 @@ void linphone_call_stop_audio_stream(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);
                }
@@ -1916,6 +1902,7 @@ void linphone_call_stop_video_stream(LinphoneCall *call) {
                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;
        }
@@ -2032,10 +2019,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;
 }
 
 /**
@@ -2050,18 +2047,34 @@ 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;
 }
 
 /**
@@ -2265,6 +2278,7 @@ void linphone_call_background_tasks(LinphoneCall *call, bool_t one_second_elapse
                                        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) {
@@ -2273,6 +2287,7 @@ void linphone_call_background_tasks(LinphoneCall *call, bool_t one_second_elapse
                                        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)
@@ -2306,6 +2321,7 @@ void linphone_call_background_tasks(LinphoneCall *call, bool_t one_second_elapse
                                        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) {
@@ -2314,6 +2330,7 @@ void linphone_call_background_tasks(LinphoneCall *call, bool_t one_second_elapse
                                        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)