summaryrefslogtreecommitdiff
path: root/src/mos.c
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2016-03-21 22:13:04 +0100
committerAlfred E. Heggestad <aeh@db.org>2016-03-21 22:13:04 +0100
commit5860fdb9a9b26e37852520d4598749f65f893bb5 (patch)
tree2fbc7a6ec5ccde2d49c3ea79106880126a1de7ed /src/mos.c
parentffe31320d624f61afc536570853538c9df227254 (diff)
mos: add pseudo Mean Opinion Score routine
thanks to Lorenzo Mangani for the original patch
Diffstat (limited to 'src/mos.c')
-rw-r--r--src/mos.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/mos.c b/src/mos.c
new file mode 100644
index 0000000..8f78512
--- /dev/null
+++ b/src/mos.c
@@ -0,0 +1,63 @@
+/**
+ * @file src/mos.c MOS (Mean Opinion Score)
+ *
+ * Copyright (C) 2010 - 2016 Creytiv.com
+ */
+#include <re.h>
+#include <baresip.h>
+#include "core.h"
+
+
+static double rfactor_to_mos(double r)
+{
+ double mos;
+
+ mos = 1 + (0.035) * (r) + (0.000007) * (r) * ((r) - 60) * (100 - (r));
+
+ if (mos > 5)
+ mos = 5;
+
+ return mos;
+}
+
+
+/**
+ * Calculate Pseudo-MOS (Mean Opinion Score)
+ *
+ * @param r_factor Pointer to where R-factor is written (optional)
+ * @param rtt Average roundtrip time
+ * @param jitter Jitter
+ * @param num_packets_lost Number of packets lost
+ *
+ * @return The calculated MOS value from 1 to 5
+ *
+ * Reference: https://metacpan.org/pod/Algorithm::MOS
+ */
+double mos_calculate(double *r_factor, double rtt,
+ double jitter, u_int32_t num_packets_lost)
+{
+ double effective_latency = rtt + (jitter * 2) + 10;
+ double mos_val;
+ double r;
+
+ if (effective_latency < 160) {
+ r = 93.2 - (effective_latency / 40);
+ }
+ else {
+ r = 93.2 - (effective_latency - 120) / 10;
+ }
+
+ r = r - (num_packets_lost * 2.5);
+
+ if (r > 100)
+ r = 100;
+ else if (r < 0)
+ r = 0;
+
+ mos_val = rfactor_to_mos(r);
+
+ if (r_factor)
+ *r_factor = r;
+
+ return mos_val;
+}