From 3d5e586c693bb744838a20607c8d0faf982747af Mon Sep 17 00:00:00 2001 From: Julien Chavanton Date: Thu, 25 Mar 2021 21:38:56 -0700 Subject: [PATCH] mos average fix when missing RTT --- daemon/call.c | 6 ++++-- daemon/call_interfaces.c | 5 ++++- daemon/ssrc.c | 16 ++++++++++------ include/ssrc.h | 1 + 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 3d0356daf..2ed1280b8 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2566,13 +2566,15 @@ void call_destroy(struct call *c) { if (!se->stats_blocks.length || !se->lowest_mos || !se->highest_mos) continue; + int mos_samples = (se->stats_blocks.length - se->no_mos_count); + if (mos_samples < 1) mos_samples = 1; ilog(LOG_INFO, "--- SSRC %s%" PRIx32 "%s", FMT_M(se->h.ssrc)); ilog(LOG_INFO, "------ Average MOS %" PRIu64 ".%" PRIu64 ", " "lowest MOS %" PRIu64 ".%" PRIu64 " (at %u:%02u), " "highest MOS %" PRIu64 ".%" PRIu64 " (at %u:%02u)", - se->average_mos.mos / se->stats_blocks.length / 10, - se->average_mos.mos / se->stats_blocks.length % 10, + se->average_mos.mos / mos_samples / 10, + se->average_mos.mos / mos_samples % 10, se->lowest_mos->mos / 10, se->lowest_mos->mos % 10, (unsigned int) (timeval_diff(&se->lowest_mos->reported, &c->created) / 1000000) / 60, diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index aca727499..4e95beb25 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -1730,7 +1730,10 @@ static void ng_stats_ssrc(bencode_item_t *dict, struct ssrc_hash *ht) { if (!se->stats_blocks.length || !se->lowest_mos || !se->highest_mos) continue; - ng_stats_ssrc_mos_entry_dict_avg(ent, "average MOS", &se->average_mos, se->stats_blocks.length); + int mos_samples = se->stats_blocks.length - se->no_mos_count; + if (mos_samples < 1) mos_samples = 1; + + ng_stats_ssrc_mos_entry_dict_avg(ent, "average MOS", &se->average_mos, mos_samples); ng_stats_ssrc_mos_entry_dict(ent, "lowest MOS", se->lowest_mos); ng_stats_ssrc_mos_entry_dict(ent, "highest MOS", se->highest_mos); diff --git a/daemon/ssrc.c b/daemon/ssrc.c index 63079a1c3..693a96ed8 100644 --- a/daemon/ssrc.c +++ b/daemon/ssrc.c @@ -382,17 +382,21 @@ void ssrc_receiver_report(struct call_media *m, const struct ssrc_receiver_repor g_queue_push_tail(&other_e->stats_blocks, ssb); - if (G_UNLIKELY(!other_e->lowest_mos) || ssb->mos < other_e->lowest_mos->mos) + if (ssb->mos && ((G_UNLIKELY(!other_e->lowest_mos) || ssb->mos < other_e->lowest_mos->mos))) other_e->lowest_mos = ssb; if (G_UNLIKELY(!other_e->highest_mos) || ssb->mos > other_e->highest_mos->mos) other_e->highest_mos = ssb; // running tally - other_e->average_mos.jitter += ssb->jitter; - other_e->average_mos.rtt += ssb->rtt; - other_e->average_mos.rtt_leg += ssb->rtt_leg; - other_e->average_mos.packetloss += ssb->packetloss; - other_e->average_mos.mos += ssb->mos; + if (!ssb->mos) { // when we do not have the RTT for both legs, we have no MOS + other_e->no_mos_count++; + } else { + other_e->average_mos.jitter += ssb->jitter; + other_e->average_mos.mos += ssb->mos; + other_e->average_mos.rtt += ssb->rtt; + other_e->average_mos.rtt_leg += ssb->rtt_leg; + other_e->average_mos.packetloss += ssb->packetloss; + } goto out_ul_oe; diff --git a/include/ssrc.h b/include/ssrc.h index fd203bdc1..f83491205 100644 --- a/include/ssrc.h +++ b/include/ssrc.h @@ -93,6 +93,7 @@ struct ssrc_entry_call { struct ssrc_stats_block *lowest_mos, *highest_mos, average_mos; // contains a running tally of all stats blocks + uint16_t no_mos_count; // how many time we where not able to compute MOS due to missing RTT unsigned int last_rtt; // last calculated raw rtt without rtt from opposide side // for transcoding