From 1182c5e824392fd8a7e7aea0aae23334484dd4ce Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 29 Dec 2017 11:08:58 +0100 Subject: [PATCH] Restore call reporting code. --- coreapi/linphonecore.c | 14 +- coreapi/private_functions.h | 2 +- coreapi/quality_reporting.c | 168 ++++++++---------- src/c-wrapper/api/c-call-stats.cpp | 4 + src/call/call-p.h | 3 + src/call/call.cpp | 15 ++ .../session/call-session-listener.h | 3 + src/conference/session/media-session-p.h | 5 - src/conference/session/media-session.cpp | 162 ++--------------- 9 files changed, 117 insertions(+), 259 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 92d4c9c87..29eb6eda4 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -3602,10 +3602,8 @@ LinphoneCall * linphone_core_invite_address_with_params(LinphoneCore *lc, const return NULL; } -#if 0 /* Unless this call is for a conference, it becomes now the current one*/ if (linphone_call_params_get_local_conference_mode(params) == FALSE) -#endif L_GET_PRIVATE_FROM_C_OBJECT(lc)->setCurrentCall(L_GET_CPP_PTR_FROM_C_OBJECT(call)); bool defer = L_GET_PRIVATE_FROM_C_OBJECT(call)->initiateOutgoing(); if (!defer) { @@ -6960,19 +6958,13 @@ LinphoneStatus linphone_core_add_to_conference(LinphoneCore *lc, LinphoneCall *c } LinphoneStatus linphone_core_add_all_to_conference(LinphoneCore *lc) { -#if 0 - bctbx_list_t *calls=lc->calls; - while (calls) { - LinphoneCall *call=(LinphoneCall*)calls->data; - calls=calls->next; - if(linphone_call_get_conference(call) == NULL) { // Prevent the call to the conference server from being added to the conference - linphone_core_add_to_conference(lc, call); - } + for (const auto &call : L_GET_CPP_PTR_FROM_C_OBJECT(lc)->getCalls()) { + if (!linphone_call_get_conference(L_GET_C_BACK_PTR(call))) // Prevent the call to the conference server from being added to the conference + linphone_core_add_to_conference(lc, L_GET_C_BACK_PTR(call)); } if(lc->conf_ctx && linphone_conference_check_class(lc->conf_ctx, LinphoneConferenceClassLocal)) { linphone_core_enter_conference(lc); } -#endif return 0; } diff --git a/coreapi/private_functions.h b/coreapi/private_functions.h index 4a92c06df..a7f110508 100644 --- a/coreapi/private_functions.h +++ b/coreapi/private_functions.h @@ -215,8 +215,8 @@ void _linphone_call_stats_uninit(LinphoneCallStats *stats); void _linphone_call_stats_clone(LinphoneCallStats *dst, const LinphoneCallStats *src); void _linphone_call_stats_set_ice_state (LinphoneCallStats *stats, LinphoneIceState state); void _linphone_call_stats_set_type (LinphoneCallStats *stats, LinphoneStreamType type); -mblk_t *_linphone_call_stats_get_received_rtcp (const LinphoneCallStats *stats); void _linphone_call_stats_set_received_rtcp (LinphoneCallStats *stats, mblk_t *m); +mblk_t *_linphone_call_stats_get_sent_rtcp (const LinphoneCallStats *stats); void _linphone_call_stats_set_sent_rtcp (LinphoneCallStats *stats, mblk_t *m); int _linphone_call_stats_get_updated (const LinphoneCallStats *stats); void _linphone_call_stats_set_updated (LinphoneCallStats *stats, int updated); diff --git a/coreapi/quality_reporting.c b/coreapi/quality_reporting.c index e6d84a4d4..8950b5970 100644 --- a/coreapi/quality_reporting.c +++ b/coreapi/quality_reporting.c @@ -33,9 +33,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #endif +#include + // For migration purpose. #include "address/address-p.h" #include "c-wrapper/c-wrapper.h" +#include "call/call-p.h" +#include "conference/session/media-session-p.h" #define STR_REASSIGN(dest, src) {\ if (dest != NULL) \ @@ -45,16 +49,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. /*since printf family functions are LOCALE dependent, float separator may differ depending on the user's locale (LC_NUMERIC environment var).*/ -#if 0 static char * float_to_one_decimal_string(float f) { float rounded_f = floorf(f * 10 + .5f) / 10; int floor_part = (int) rounded_f; - int one_decimal_part = (int)floorf(10 * (rounded_f - floor_part) + .5f); + int one_decimal_part = (int)floorf(10 * (rounded_f - (float)floor_part) + .5f); return ms_strdup_printf("%d.%d", floor_part, one_decimal_part); } -#endif static void append_to_buffer_valist(char **buff, size_t *buff_size, size_t *offset, const char *fmt, va_list args) { belle_sip_error_code ret; @@ -84,14 +86,12 @@ static void append_to_buffer_valist(char **buff, size_t *buff_size, size_t *offs } } -#if 0 static void append_to_buffer(char **buff, size_t *buff_size, size_t *offset, const char *fmt, ...) { va_list args; va_start(args, fmt); append_to_buffer_valist(buff, buff_size, offset, fmt, args); va_end(args); } -#endif static void reset_avg_metrics(reporting_session_report_t * report){ int i; @@ -123,7 +123,6 @@ static void reset_avg_metrics(reporting_session_report_t * report){ #define METRICS_DELAY 1 << 4 #define METRICS_SIGNAL 1 << 5 -#if 0 static uint8_t are_metrics_filled(const reporting_content_metrics_t *rm) { uint8_t ret = 0; @@ -158,17 +157,14 @@ static uint8_t are_metrics_filled(const reporting_content_metrics_t *rm) { return ret; } -#endif -#if 0 static bool_t quality_reporting_enabled(const LinphoneCall * call) { - return (call->dest_proxy != NULL && linphone_proxy_config_quality_reporting_enabled(call->dest_proxy)); + return (L_GET_PRIVATE_FROM_C_OBJECT(call)->getDestProxy() + && linphone_proxy_config_quality_reporting_enabled(L_GET_PRIVATE_FROM_C_OBJECT(call)->getDestProxy())); } -#endif -#if 0 static bool_t media_report_enabled(LinphoneCall * call, int stats_type){ - if (! quality_reporting_enabled(call)) + if (!quality_reporting_enabled(call)) return FALSE; if (stats_type == LINPHONE_CALL_STATS_VIDEO && !linphone_call_params_video_enabled(linphone_call_get_current_params(call))) @@ -177,11 +173,9 @@ static bool_t media_report_enabled(LinphoneCall * call, int stats_type){ if (stats_type == LINPHONE_CALL_STATS_TEXT && !linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(call))) return FALSE; - return (call->log->reporting.reports[stats_type] != NULL); + return (L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog()->reporting.reports[stats_type] != NULL); } -#endif -#if 0 static void append_metrics_to_buffer(char ** buffer, size_t * size, size_t * offset, const reporting_content_metrics_t *rm) { char * timestamps_start_str = NULL; char * timestamps_stop_str = NULL; @@ -277,9 +271,7 @@ static void append_metrics_to_buffer(char ** buffer, size_t * size, size_t * off ms_free(moslq_str); ms_free(moscq_str); } -#endif -#if 0 static int send_report(LinphoneCall* call, reporting_session_report_t * report, const char * report_event) { LinphoneContent *content; size_t offset = 0; @@ -362,7 +354,7 @@ static int send_report(LinphoneCall* call, reporting_session_report_t * report, } #endif - linphone_content_set_buffer(content, buffer, strlen(buffer)); + linphone_content_set_buffer(content, (uint8_t *)buffer, strlen(buffer)); ms_free(buffer); if (linphone_call_get_log(call)->reporting.on_report_sent != NULL) { @@ -386,7 +378,7 @@ static int send_report(LinphoneCall* call, reporting_session_report_t * report, sal_address_has_uri_param(salAddress, "maddr") || linphone_address_get_port(request_uri) != 0) { ms_message("Publishing report with custom route %s", collector_uri); - sal_op_set_route(lev->op, collector_uri); + lev->op->set_route(collector_uri); } if (linphone_event_send_publish(lev, content) != 0){ @@ -414,9 +406,7 @@ static int send_report(LinphoneCall* call, reporting_session_report_t * report, return ret; } -#endif -#if 0 static const SalStreamDescription * get_media_stream_for_desc(const SalMediaDescription * smd, SalStreamType sal_stream_type) { int count; if (smd != NULL) { @@ -428,38 +418,35 @@ static const SalStreamDescription * get_media_stream_for_desc(const SalMediaDesc } return NULL; } -#endif static void update_ip(LinphoneCall * call, int stats_type) { -#if 0 SalStreamType sal_stream_type = stats_type == LINPHONE_CALL_STATS_AUDIO ? SalAudio : stats_type == LINPHONE_CALL_STATS_VIDEO ? SalVideo : SalText; - const SalStreamDescription * local_desc = get_media_stream_for_desc(call->localdesc, sal_stream_type); - const SalStreamDescription * remote_desc = get_media_stream_for_desc(sal_call_get_remote_media_description(call->op), sal_stream_type); + const SalStreamDescription * local_desc = get_media_stream_for_desc(_linphone_call_get_local_desc(call), sal_stream_type); + const SalStreamDescription * remote_desc = get_media_stream_for_desc(L_GET_PRIVATE_FROM_C_OBJECT(call)->getOp()->get_remote_media_description(), sal_stream_type); + LinphoneCallLog *log = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog(); if (local_desc != NULL) { /*since this function might be called for video stream AFTER it has been uninitialized, local description might be invalid. In any other case, IP/port should be always filled and valid*/ if (strlen(local_desc->rtp_addr) > 0) { - call->log->reporting.reports[stats_type]->info.local_addr.port = local_desc->rtp_port; - STR_REASSIGN(call->log->reporting.reports[stats_type]->info.local_addr.ip, ms_strdup(local_desc->rtp_addr)); + log->reporting.reports[stats_type]->info.local_addr.port = local_desc->rtp_port; + STR_REASSIGN(log->reporting.reports[stats_type]->info.local_addr.ip, ms_strdup(local_desc->rtp_addr)); } } if (remote_desc != NULL) { /*port is always stored in stream description struct*/ - call->log->reporting.reports[stats_type]->info.remote_addr.port = remote_desc->rtp_port; + log->reporting.reports[stats_type]->info.remote_addr.port = remote_desc->rtp_port; /*for IP it can be not set if we are using a direct route*/ if (strlen(remote_desc->rtp_addr) > 0) { - STR_REASSIGN(call->log->reporting.reports[stats_type]->info.remote_addr.ip, ms_strdup(remote_desc->rtp_addr)); + STR_REASSIGN(log->reporting.reports[stats_type]->info.remote_addr.ip, ms_strdup(remote_desc->rtp_addr)); } else { - STR_REASSIGN(call->log->reporting.reports[stats_type]->info.remote_addr.ip, ms_strdup(sal_call_get_remote_media_description(call->op)->addr)); + STR_REASSIGN(log->reporting.reports[stats_type]->info.remote_addr.ip, ms_strdup(L_GET_PRIVATE_FROM_C_OBJECT(call)->getOp()->get_remote_media_description()->addr)); } } -#endif } -#if 0 static void qos_analyzer_on_action_suggested(void *user_data, int datac, const char** datav){ reporting_session_report_t *report = (reporting_session_report_t*)user_data; LinphoneCall *call = report->call; @@ -502,7 +489,6 @@ static void qos_analyzer_on_action_suggested(void *user_data, int datac, const c appendbuf=ms_strdup_printf("%s%s;", report->qos_analyzer.output?report->qos_analyzer.output:"", datav[3]); STR_REASSIGN(report->qos_analyzer.output, appendbuf); } -#endif void linphone_reporting_update_ip(LinphoneCall * call) { update_ip(call, LINPHONE_CALL_STATS_AUDIO); @@ -511,23 +497,23 @@ void linphone_reporting_update_ip(LinphoneCall * call) { } void linphone_reporting_update_media_info(LinphoneCall * call, int stats_type) { -#if 0 MediaStream * stream = NULL; const PayloadType * local_payload = NULL; const PayloadType * remote_payload = NULL; const LinphoneCallParams * current_params = linphone_call_get_current_params(call); - reporting_session_report_t * report = call->log->reporting.reports[stats_type]; + LinphoneCallLog *log = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog(); + reporting_session_report_t * report = log->reporting.reports[stats_type]; char * dialog_id; // call->op might be already released if hanging up in state LinphoneCallOutgoingInit - if (!media_report_enabled(call, stats_type) || call->op == NULL) + if (!media_report_enabled(call, stats_type) || !L_GET_PRIVATE_FROM_C_OBJECT(call)->getOp()) return; - dialog_id = sal_op_get_dialog_id(call->op); + dialog_id = L_GET_PRIVATE_FROM_C_OBJECT(call)->getOp()->get_dialog_id(); - STR_REASSIGN(report->info.call_id, ms_strdup(call->log->call_id)); + STR_REASSIGN(report->info.call_id, ms_strdup(log->call_id)); - STR_REASSIGN(report->local_metrics.user_agent, ms_strdup(linphone_core_get_user_agent(call->core))); + STR_REASSIGN(report->local_metrics.user_agent, ms_strdup(linphone_core_get_user_agent(linphone_call_get_core(call)))); STR_REASSIGN(report->remote_metrics.user_agent, ms_strdup(linphone_call_get_remote_user_agent(call))); // RFC states: "LocalGroupID provides the identification for the purposes @@ -546,36 +532,36 @@ void linphone_reporting_update_media_info(LinphoneCall * call, int stats_type) { ); - if (call->dir == LinphoneCallIncoming) { - STR_REASSIGN(report->info.remote_addr.id, linphone_address_as_string(call->log->from)); - STR_REASSIGN(report->info.local_addr.id, linphone_address_as_string(call->log->to)); + if (L_GET_CPP_PTR_FROM_C_OBJECT(call)->getDirection() == LinphoneCallIncoming) { + STR_REASSIGN(report->info.remote_addr.id, linphone_address_as_string(log->from)); + STR_REASSIGN(report->info.local_addr.id, linphone_address_as_string(log->to)); STR_REASSIGN(report->info.orig_id, ms_strdup(report->info.remote_addr.id)); } else { - STR_REASSIGN(report->info.remote_addr.id, linphone_address_as_string(call->log->to)); - STR_REASSIGN(report->info.local_addr.id, linphone_address_as_string(call->log->from)); + STR_REASSIGN(report->info.remote_addr.id, linphone_address_as_string(log->to)); + STR_REASSIGN(report->info.local_addr.id, linphone_address_as_string(log->from)); STR_REASSIGN(report->info.orig_id, ms_strdup(report->info.local_addr.id)); } - report->local_metrics.timestamps.start = call->log->start_date_time; - report->local_metrics.timestamps.stop = call->log->start_date_time + linphone_call_get_duration(call); + report->local_metrics.timestamps.start = log->start_date_time; + report->local_metrics.timestamps.stop = log->start_date_time + linphone_call_get_duration(call); /*we use same timestamps for remote too*/ - report->remote_metrics.timestamps.start = call->log->start_date_time; - report->remote_metrics.timestamps.stop = call->log->start_date_time + linphone_call_get_duration(call); + report->remote_metrics.timestamps.start = log->start_date_time; + report->remote_metrics.timestamps.stop = log->start_date_time + linphone_call_get_duration(call); /*yet we use the same payload config for local and remote, since this is the largest use case*/ - if (stats_type == LINPHONE_CALL_STATS_AUDIO && call->audiostream != NULL) { - stream = &call->audiostream->ms; + if (stats_type == LINPHONE_CALL_STATS_AUDIO && L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeAudio)) { + stream = L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeAudio); local_payload = linphone_call_params_get_used_audio_codec(current_params); remote_payload = local_payload; - } else if (stats_type == LINPHONE_CALL_STATS_VIDEO && call->videostream != NULL) { - stream = &call->videostream->ms; + } else if (stats_type == LINPHONE_CALL_STATS_VIDEO && L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeVideo)) { + stream = L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeVideo); local_payload = linphone_call_params_get_used_video_codec(current_params); remote_payload = local_payload; - } else if (stats_type == LINPHONE_CALL_STATS_TEXT && call->textstream != NULL) { - stream = &call->textstream->ms; + } else if (stats_type == LINPHONE_CALL_STATS_TEXT && L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeText)) { + stream = L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeText); local_payload = linphone_call_params_get_used_text_codec(current_params); remote_payload = local_payload; } @@ -611,43 +597,39 @@ void linphone_reporting_update_media_info(LinphoneCall * call, int stats_type) { } ms_free(dialog_id); -#endif } /* generate random float in interval ] 0.9 t ; 1.1 t [*/ -#if 0 static float reporting_rand(float t){ - return t * (.2f * (rand() / (RAND_MAX * 1.0f)) + 0.9f); + return t * (.2f * ((float)rand() / (float)RAND_MAX) + 0.9f); } -#endif void linphone_reporting_on_rtcp_update(LinphoneCall *call, SalStreamType stats_type) { -#if 0 - reporting_session_report_t * report = call->log->reporting.reports[stats_type]; + reporting_session_report_t * report = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog()->reporting.reports[stats_type]; reporting_content_metrics_t * metrics = NULL; LinphoneCallStats *stats = NULL; mblk_t *block = NULL; int report_interval; if (stats_type == 0) { - stats = call->audio_stats; + stats = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getStats(LinphoneStreamTypeAudio); } else if (stats_type == 1) { - stats = call->video_stats; + stats = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getStats(LinphoneStreamTypeVideo); } else { - stats = call->text_stats; + stats = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getStats(LinphoneStreamTypeText); } if (! media_report_enabled(call,stats_type)) return; - report_interval = linphone_proxy_config_get_quality_reporting_interval(call->dest_proxy); + report_interval = linphone_proxy_config_get_quality_reporting_interval(L_GET_PRIVATE_FROM_C_OBJECT(call)->getDestProxy()); - if (stats->updated == LINPHONE_CALL_STATS_RECEIVED_RTCP_UPDATE) { + if (_linphone_call_stats_get_updated(stats) == LINPHONE_CALL_STATS_RECEIVED_RTCP_UPDATE) { metrics = &report->remote_metrics; - block = stats->received_rtcp; - } else if (stats->updated == LINPHONE_CALL_STATS_SENT_RTCP_UPDATE) { + block = _linphone_call_stats_get_received_rtcp(stats); + } else if (_linphone_call_stats_get_updated(stats) == LINPHONE_CALL_STATS_SENT_RTCP_UPDATE) { metrics = &report->local_metrics; - block = stats->sent_rtcp; + block = _linphone_call_stats_get_sent_rtcp(stats); } do{ if (rtcp_is_XR(block) && (rtcp_XR_get_block_type(block) == RTCP_XR_VOIP_METRICS)){ @@ -658,7 +640,7 @@ void linphone_reporting_on_rtcp_update(LinphoneCall *call, SalStreamType stats_t // for local mos rating, we'll use the quality indicator directly // because rtcp XR might not be enabled - if (stats->updated == LINPHONE_CALL_STATS_RECEIVED_RTCP_UPDATE){ + if (_linphone_call_stats_get_updated(stats) == LINPHONE_CALL_STATS_RECEIVED_RTCP_UPDATE){ metrics->quality_estimates.moslq = (rtcp_XR_voip_metrics_get_mos_lq(block)==127) ? 127 : rtcp_XR_voip_metrics_get_mos_lq(block) / 10.f; metrics->quality_estimates.moscq = (rtcp_XR_voip_metrics_get_mos_cq(block)==127) ? @@ -676,7 +658,9 @@ void linphone_reporting_on_rtcp_update(LinphoneCall *call, SalStreamType stats_t metrics->delay.round_trip_delay += rtcp_XR_voip_metrics_get_round_trip_delay(block); }else if (rtcp_is_SR(block)){ - MediaStream *ms=(stats_type==0 ? &call->audiostream->ms : &call->videostream->ms); + MediaStream *ms = (stats_type == 0) + ? L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeAudio) + : L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeVideo); float rtt = rtp_session_get_round_trip_propagation(ms->sessions.rtp_session); if (rtt > 1e-6){ @@ -692,19 +676,17 @@ void linphone_reporting_on_rtcp_update(LinphoneCall *call, SalStreamType stats_t linphone_reporting_update_media_info(call, stats_type); send_report(call, report, "VQIntervalReport"); } -#endif } static int publish_report(LinphoneCall *call, const char *event_type){ -#if 0 int ret = 0; int i; for (i = 0; i < SAL_MEDIA_DESCRIPTION_MAX_STREAMS; i++){ - int stream_index = i == call->main_audio_stream_index ? LINPHONE_CALL_STATS_AUDIO : call->main_video_stream_index ? LINPHONE_CALL_STATS_VIDEO : LINPHONE_CALL_STATS_TEXT; + int stream_index = i == _linphone_call_get_main_audio_stream_index(call) ? LINPHONE_CALL_STATS_AUDIO : _linphone_call_get_main_video_stream_index(call) ? LINPHONE_CALL_STATS_VIDEO : LINPHONE_CALL_STATS_TEXT; if (media_report_enabled(call, stream_index)) { int sndret; linphone_reporting_update_media_info(call, stream_index); - sndret=send_report(call, call->log->reporting.reports[stream_index], event_type); + sndret=send_report(call, L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog()->reporting.reports[stream_index], event_type); if (sndret>0){ ret += 10+(i+1)*sndret; } @@ -713,25 +695,17 @@ static int publish_report(LinphoneCall *call, const char *event_type){ } } return ret; -#else - return 0; -#endif } int linphone_reporting_publish_session_report(LinphoneCall* call, bool_t call_term) { -#if 0 const char * session_type = call_term?"VQSessionReport: CallTerm":"VQSessionReport"; return publish_report(call, session_type); -#else - return 0; -#endif } int linphone_reporting_publish_interval_report(LinphoneCall* call) { return publish_report(call, "VQIntervalReport"); } -#if 0 static bool_t set_on_action_suggested_cb(MediaStream *stream,void (*on_action_suggested)(void*,int,const char**),void* u) { if (stream&&stream->rc){ MSQosAnalyzer *analyzer=ms_bitrate_controller_get_qos_analyzer(stream->rc); @@ -744,37 +718,40 @@ static bool_t set_on_action_suggested_cb(MediaStream *stream,void (*on_action_su } return FALSE; } -#endif void linphone_reporting_call_state_updated(LinphoneCall *call){ -#if 0 LinphoneCallState state=linphone_call_get_state(call); + LinphoneCallLog *log = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getLog(); if (state == LinphoneCallReleased||!quality_reporting_enabled(call)){ return; } switch (state){ case LinphoneCallStreamsRunning:{ int i = 0; - MediaStream *streams[3] = { (MediaStream*) call->audiostream, (MediaStream *) call->videostream, (MediaStream *) call->textstream }; + MediaStream *streams[3] = { + L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeAudio), + L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeVideo), + L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeText) + }; for (i = 0; i < SAL_MEDIA_DESCRIPTION_MAX_STREAMS; i++) { - int stream_index = i == call->main_audio_stream_index ? LINPHONE_CALL_STATS_AUDIO : call->main_video_stream_index ? LINPHONE_CALL_STATS_VIDEO : LINPHONE_CALL_STATS_TEXT; + int stream_index = i == _linphone_call_get_main_audio_stream_index(call) ? LINPHONE_CALL_STATS_AUDIO : _linphone_call_get_main_video_stream_index(call) ? LINPHONE_CALL_STATS_VIDEO : LINPHONE_CALL_STATS_TEXT; bool_t enabled = media_report_enabled(call, stream_index); - if (enabled && set_on_action_suggested_cb(streams[stream_index], qos_analyzer_on_action_suggested, call->log->reporting.reports[stream_index])) { - call->log->reporting.reports[stream_index]->call=call; - STR_REASSIGN(call->log->reporting.reports[stream_index]->qos_analyzer.name, ms_strdup(ms_qos_analyzer_get_name(ms_bitrate_controller_get_qos_analyzer(streams[stream_index]->rc)))); + if (enabled && set_on_action_suggested_cb(streams[stream_index], qos_analyzer_on_action_suggested, log->reporting.reports[stream_index])) { + log->reporting.reports[stream_index]->call=call; + STR_REASSIGN(log->reporting.reports[stream_index]->qos_analyzer.name, ms_strdup(ms_qos_analyzer_get_name(ms_bitrate_controller_get_qos_analyzer(streams[stream_index]->rc)))); } } linphone_reporting_update_ip(call); - if (!media_report_enabled(call, LINPHONE_CALL_STATS_VIDEO) && call->log->reporting.was_video_running){ - send_report(call, call->log->reporting.reports[LINPHONE_CALL_STATS_VIDEO], "VQSessionReport"); + if (!media_report_enabled(call, LINPHONE_CALL_STATS_VIDEO) && log->reporting.was_video_running){ + send_report(call, log->reporting.reports[LINPHONE_CALL_STATS_VIDEO], "VQSessionReport"); } - call->log->reporting.was_video_running=media_report_enabled(call, LINPHONE_CALL_STATS_VIDEO); + log->reporting.was_video_running=media_report_enabled(call, LINPHONE_CALL_STATS_VIDEO); break; } case LinphoneCallEnd:{ - set_on_action_suggested_cb(&call->audiostream->ms, NULL, NULL); - set_on_action_suggested_cb(&call->videostream->ms, NULL, NULL); - if (call->log->status==LinphoneCallSuccess || call->log->status==LinphoneCallAborted){ + set_on_action_suggested_cb(L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeAudio), NULL, NULL); + set_on_action_suggested_cb(L_GET_PRIVATE_FROM_C_OBJECT(call)->getMediaStream(LinphoneStreamTypeVideo), NULL, NULL); + if (log->status==LinphoneCallSuccess || log->status==LinphoneCallAborted){ linphone_reporting_publish_session_report(call, TRUE); } break; @@ -783,7 +760,6 @@ void linphone_reporting_call_state_updated(LinphoneCall *call){ break; } } -#endif } reporting_session_report_t * linphone_reporting_new() { diff --git a/src/c-wrapper/api/c-call-stats.cpp b/src/c-wrapper/api/c-call-stats.cpp index 76dfd56f0..2ee7bec13 100644 --- a/src/c-wrapper/api/c-call-stats.cpp +++ b/src/c-wrapper/api/c-call-stats.cpp @@ -115,6 +115,10 @@ void _linphone_call_stats_set_received_rtcp (LinphoneCallStats *stats, mblk_t *m stats->received_rtcp = m; } +mblk_t *_linphone_call_stats_get_sent_rtcp (const LinphoneCallStats *stats) { + return stats->sent_rtcp; +} + void _linphone_call_stats_set_sent_rtcp (LinphoneCallStats *stats, mblk_t *m) { stats->sent_rtcp = m; } diff --git a/src/call/call-p.h b/src/call/call-p.h index f9b219d5e..523062e7c 100644 --- a/src/call/call-p.h +++ b/src/call/call-p.h @@ -92,7 +92,10 @@ private: void onInfoReceived (const std::shared_ptr &session, const LinphoneInfoMessage *im) override; void onNoMediaTimeoutCheck (const std::shared_ptr &session, bool oneSecondElapsed) override; void onEncryptionChanged (const std::shared_ptr &session, bool activated, const std::string &authToken) override; + void onCallSessionStateChangedForReporting (const std::shared_ptr &session) override; + void onRtcpUpdateForReporting (const std::shared_ptr &session, SalStreamType type) override; void onStatsUpdated (const std::shared_ptr &session, const LinphoneCallStats *stats) override; + void onUpdateMediaInfoForReporting (const std::shared_ptr &session, int statsType) override; void onResetCurrentSession (const std::shared_ptr &session) override; void onSetCurrentSession (const std::shared_ptr &session) override; void onFirstVideoFrameDecoded (const std::shared_ptr &session) override; diff --git a/src/call/call.cpp b/src/call/call.cpp index dcd157132..a11f185c3 100644 --- a/src/call/call.cpp +++ b/src/call/call.cpp @@ -349,11 +349,26 @@ void CallPrivate::onEncryptionChanged (const shared_ptr &sess linphone_call_notify_encryption_changed(L_GET_C_BACK_PTR(q), activated, authToken.empty() ? nullptr : authToken.c_str()); } +void CallPrivate::onCallSessionStateChangedForReporting (const shared_ptr &session) { + L_Q(); + linphone_reporting_call_state_updated(L_GET_C_BACK_PTR(q)); +} + +void CallPrivate::onRtcpUpdateForReporting (const shared_ptr &session, SalStreamType type) { + L_Q(); + linphone_reporting_on_rtcp_update(L_GET_C_BACK_PTR(q), type); +} + void CallPrivate::onStatsUpdated (const shared_ptr &session, const LinphoneCallStats *stats) { L_Q(); linphone_call_notify_stats_updated(L_GET_C_BACK_PTR(q), stats); } +void CallPrivate::onUpdateMediaInfoForReporting (const std::shared_ptr &session, int statsType) { + L_Q(); + linphone_reporting_update_media_info(L_GET_C_BACK_PTR(q), statsType); +} + void CallPrivate::onResetCurrentSession (const shared_ptr &session) { L_Q(); q->getCore()->getPrivate()->setCurrentCall(nullptr); diff --git a/src/conference/session/call-session-listener.h b/src/conference/session/call-session-listener.h index 953460490..66b76d292 100644 --- a/src/conference/session/call-session-listener.h +++ b/src/conference/session/call-session-listener.h @@ -55,7 +55,10 @@ public: virtual void onEncryptionChanged (const std::shared_ptr &session, bool activated, const std::string &authToken) {} + virtual void onCallSessionStateChangedForReporting (const std::shared_ptr &session) {} + virtual void onRtcpUpdateForReporting (const std::shared_ptr &session, SalStreamType type) {} virtual void onStatsUpdated (const std::shared_ptr &session, const LinphoneCallStats *stats) {} + virtual void onUpdateMediaInfoForReporting (const std::shared_ptr &session, int statsType) {} virtual void onResetCurrentSession (const std::shared_ptr &session) {} virtual void onSetCurrentSession (const std::shared_ptr &session) {} diff --git a/src/conference/session/media-session-p.h b/src/conference/session/media-session-p.h index 545582610..df098e4ff 100644 --- a/src/conference/session/media-session-p.h +++ b/src/conference/session/media-session-p.h @@ -231,11 +231,6 @@ private: void updateLocalStats (LinphoneCallStats *stats, MediaStream *stream) const; void updateRtpStats (LinphoneCallStats *stats, int streamIndex); - bool mediaReportEnabled (int statsType); - bool qualityReportingEnabled () const; - void updateReportingCallState (); - void updateReportingMediaInfo (int statsType); - void executeBackgroundTasks (bool oneSecondElapsed); void reportBandwidth (); void reportBandwidthForStream (MediaStream *ms, LinphoneStreamType type); diff --git a/src/conference/session/media-session.cpp b/src/conference/session/media-session.cpp index b7d84c8f4..e8cdd2f3b 100644 --- a/src/conference/session/media-session.cpp +++ b/src/conference/session/media-session.cpp @@ -705,7 +705,8 @@ void MediaSessionPrivate::setState (CallSession::State newState, const string &m if ((newState != state) && (newState != CallSession::State::StreamsRunning)) q->cancelDtmfs(); CallSessionPrivate::setState(newState, message); - updateReportingCallState(); + if (listener) + listener->onCallSessionStateChangedForReporting(q->getSharedFromThis()); } // ----------------------------------------------------------------------------- @@ -945,9 +946,13 @@ void MediaSessionPrivate::notifyStatsUpdated (int streamIndex) const { switch (_linphone_call_stats_get_updated(stats)) { case LINPHONE_CALL_STATS_RECEIVED_RTCP_UPDATE: case LINPHONE_CALL_STATS_SENT_RTCP_UPDATE: -#if 0 - linphone_reporting_on_rtcp_update(call, stream_index == call->main_audio_stream_index ? SalAudio : stream_index == call->main_video_stream_index ? SalVideo : SalText); -#endif + if (listener) { + listener->onRtcpUpdateForReporting(q->getSharedFromThis(), + (streamIndex == mainAudioStreamIndex) + ? SalAudio + : (streamIndex == mainVideoStreamIndex) ? SalVideo : SalText + ); + } break; default: break; @@ -2972,7 +2977,8 @@ void MediaSessionPrivate::startVideoStream (CallSession::State targetState) { void MediaSessionPrivate::stopAudioStream () { L_Q(); if (audioStream) { - updateReportingMediaInfo(LINPHONE_CALL_STATS_AUDIO); + if (listener) + listener->onUpdateMediaInfoForReporting(q->getSharedFromThis(), LINPHONE_CALL_STATS_AUDIO); media_stream_reclaim_sessions(&audioStream->ms, &sessions[mainAudioStreamIndex]); if (audioStream->ec) { char *stateStr = nullptr; @@ -3001,8 +3007,10 @@ void MediaSessionPrivate::stopAudioStream () { } void MediaSessionPrivate::stopTextStream () { + L_Q(); if (textStream) { - updateReportingMediaInfo(LINPHONE_CALL_STATS_TEXT); + if (listener) + listener->onUpdateMediaInfoForReporting(q->getSharedFromThis(), LINPHONE_CALL_STATS_TEXT); media_stream_reclaim_sessions(&textStream->ms, &sessions[mainTextStreamIndex]); fillLogStats(&textStream->ms); text_stream_stop(textStream); @@ -3021,7 +3029,8 @@ void MediaSessionPrivate::stopVideoStream () { #ifdef VIDEO_ENABLED L_Q(); if (videoStream) { - updateReportingMediaInfo(LINPHONE_CALL_STATS_VIDEO); + if (listener) + listener->onUpdateMediaInfoForReporting(q->getSharedFromThis(), LINPHONE_CALL_STATS_VIDEO); media_stream_reclaim_sessions(&videoStream->ms, &sessions[mainVideoStreamIndex]); fillLogStats(&videoStream->ms); ms_bandwidth_controller_remove_stream(q->getCore()->getCCore()->bw_controller, &videoStream->ms); @@ -3372,145 +3381,6 @@ void MediaSessionPrivate::updateRtpStats (LinphoneCallStats *stats, int streamIn // ----------------------------------------------------------------------------- -bool MediaSessionPrivate::mediaReportEnabled (int statsType) { - L_Q(); - if (!qualityReportingEnabled()) - return false; - if ((statsType == LINPHONE_CALL_STATS_VIDEO) && !q->getCurrentParams()->videoEnabled()) - return false; - if ((statsType == LINPHONE_CALL_STATS_TEXT) && !q->getCurrentParams()->realtimeTextEnabled()) - return false; - return (log->reporting.reports[statsType] != nullptr); -} - -bool MediaSessionPrivate::qualityReportingEnabled () const { - return (destProxy && linphone_proxy_config_quality_reporting_enabled(destProxy)); -} - -void MediaSessionPrivate::updateReportingCallState () { - if ((state == CallSession::State::Released) || !qualityReportingEnabled()) - return; - switch (state) { - case CallSession::State::StreamsRunning: -#if 0 - for (int i = 0; i < SAL_MEDIA_DESCRIPTION_MAX_STREAMS; i++) { - int streamIndex = (i == mainAudioStreamIndex) ? LINPHONE_CALL_STATS_AUDIO : mainVideoStreamIndex ? LINPHONE_CALL_STATS_VIDEO : LINPHONE_CALL_STATS_TEXT; - bool enabled = mediaReportEnabled(streamIndex); - MediaStream *ms = getMediaStream(i); - if (enabled && set_on_action_suggested_cb(ms, qos_analyzer_on_action_suggested, log->reporting.reports[streamIndex])) { - log->reporting.reports[streamIndex]->call = call; - STR_REASSIGN(log->reporting.reports[streamIndex]->qos_analyzer.name, ms_strdup(ms_qos_analyzer_get_name(ms_bitrate_controller_get_qos_analyzer(ms->rc)))); - } - } - linphone_reporting_update_ip(call); - if (!mediaReportEnabled(LINPHONE_CALL_STATS_VIDEO) && log->reporting.was_video_running) - send_report(log->reporting.reports[LINPHONE_CALL_STATS_VIDEO], "VQSessionReport"); -#endif - log->reporting.was_video_running = mediaReportEnabled(LINPHONE_CALL_STATS_VIDEO); - break; - case CallSession::State::End: -#if 0 - set_on_action_suggested_cb(&audioStream->ms, nullptr, nullptr); - set_on_action_suggested_cb(&videoStream->ms, nullptr, nullptr); - if ((log->status == LinphoneCallSuccess) || (log->status == LinphoneCallAborted)) - linphone_reporting_publish_session_report(call, true); -#endif - break; - default: - break; - } -} - -void MediaSessionPrivate::updateReportingMediaInfo (int statsType) { - L_Q(); - /* op might be already released if hanging up in state CallSession::State::OutgoingInit */ - if (!op || !mediaReportEnabled(statsType)) - return; - - char *dialogId = op->get_dialog_id(); - reporting_session_report_t * report = log->reporting.reports[statsType]; - STR_REASSIGN(report->info.call_id, ms_strdup(log->call_id)); - - STR_REASSIGN(report->local_metrics.user_agent, ms_strdup(linphone_core_get_user_agent(q->getCore()->getCCore()))); - STR_REASSIGN(report->remote_metrics.user_agent, ms_strdup(q->getRemoteUserAgent().c_str())); - - /* RFC states: "LocalGroupID provides the identification for the purposes of aggregation for the local endpoint" */ - STR_REASSIGN(report->info.local_addr.group, ms_strdup_printf("%s-%s-%s", - dialogId ? dialogId : "", "local", - report->local_metrics.user_agent ? report->local_metrics.user_agent : "")); - STR_REASSIGN(report->info.remote_addr.group, ms_strdup_printf("%s-%s-%s", - dialogId ? dialogId : "", "remote", - report->remote_metrics.user_agent ? report->remote_metrics.user_agent : "")); - - if (direction == LinphoneCallIncoming) { - STR_REASSIGN(report->info.remote_addr.id, linphone_address_as_string(log->from)); - STR_REASSIGN(report->info.local_addr.id, linphone_address_as_string(log->to)); - STR_REASSIGN(report->info.orig_id, ms_strdup(report->info.remote_addr.id)); - } else { - STR_REASSIGN(report->info.remote_addr.id, linphone_address_as_string(log->to)); - STR_REASSIGN(report->info.local_addr.id, linphone_address_as_string(log->from)); - STR_REASSIGN(report->info.orig_id, ms_strdup(report->info.local_addr.id)); - } - - report->local_metrics.timestamps.start = log->start_date_time; - report->local_metrics.timestamps.stop = log->start_date_time + q->getDuration(); - - /* We use same timestamps for remote too */ - report->remote_metrics.timestamps.start = log->start_date_time; - report->remote_metrics.timestamps.stop = log->start_date_time + q->getDuration(); - - /* Yet we use the same payload config for local and remote, since this is the largest use case */ - MediaStream *stream = nullptr; - const OrtpPayloadType *localPayload = nullptr; - const OrtpPayloadType *remotePayload = nullptr; - if (audioStream && (statsType == LINPHONE_CALL_STATS_AUDIO)) { - stream = &audioStream->ms; - localPayload = q->getCurrentParams()->getUsedAudioCodec(); - remotePayload = localPayload; - } else if (videoStream && (statsType == LINPHONE_CALL_STATS_VIDEO)) { - stream = &videoStream->ms; - localPayload = q->getCurrentParams()->getUsedVideoCodec(); - remotePayload = localPayload; - } else if (textStream && (statsType == LINPHONE_CALL_STATS_TEXT)) { - stream = &textStream->ms; - localPayload = q->getCurrentParams()->getUsedRealtimeTextCodec(); - remotePayload = localPayload; - } - - if (stream) { - RtpSession * session = stream->sessions.rtp_session; - report->info.local_addr.ssrc = rtp_session_get_send_ssrc(session); - report->info.remote_addr.ssrc = rtp_session_get_recv_ssrc(session); - if (stream->qi){ - report->local_metrics.quality_estimates.moslq = ms_quality_indicator_get_average_lq_rating(stream->qi) >= 0 ? - MAX(1, ms_quality_indicator_get_average_lq_rating(stream->qi)) : -1; - report->local_metrics.quality_estimates.moscq = ms_quality_indicator_get_average_rating(stream->qi) >= 0 ? - MAX(1, ms_quality_indicator_get_average_rating(stream->qi)) : -1; - } - } - - STR_REASSIGN(report->dialog_id, ms_strdup_printf("%s;%u", dialogId ? dialogId : "", report->info.local_addr.ssrc)); - ms_free(dialogId); - - if (localPayload) { - report->local_metrics.session_description.payload_type = localPayload->type; - if (localPayload->mime_type) - STR_REASSIGN(report->local_metrics.session_description.payload_desc, ms_strdup(localPayload->mime_type)); - report->local_metrics.session_description.sample_rate = localPayload->clock_rate; - if (localPayload->recv_fmtp) - STR_REASSIGN(report->local_metrics.session_description.fmtp, ms_strdup(localPayload->recv_fmtp)); - } - - if (remotePayload) { - report->remote_metrics.session_description.payload_type = remotePayload->type; - STR_REASSIGN(report->remote_metrics.session_description.payload_desc, ms_strdup(remotePayload->mime_type)); - report->remote_metrics.session_description.sample_rate = remotePayload->clock_rate; - STR_REASSIGN(report->remote_metrics.session_description.fmtp, ms_strdup(remotePayload->recv_fmtp)); - } -} - -// ----------------------------------------------------------------------------- - void MediaSessionPrivate::executeBackgroundTasks (bool oneSecondElapsed) { L_Q(); switch (state) {