Skip to content

Commit

Permalink
MT#61263 add G.107.2 fullband option
Browse files Browse the repository at this point in the history
And add appropriate test

Change-Id: Ib9fb7914a7f22ecbf29866a56b1d4c65921f15a0
  • Loading branch information
rfuchs committed Oct 18, 2024
1 parent 743867b commit a371d36
Show file tree
Hide file tree
Showing 7 changed files with 1,063 additions and 4 deletions.
3 changes: 3 additions & 0 deletions daemon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,9 @@ static void options(int *argc, char ***argv) {
rtpe_config.common.mos_type = MOS_LEGACY;
else if (!strcasecmp(mos, "g107") || !strcasecmp(mos, "g.107"))
rtpe_config.common.mos_type = MOS_LEGACY;
else if (!strcasecmp(mos, "g1072") || !strcasecmp(mos, "g.1072")
|| !strcasecmp(mos, "g.107.2") || !strcasecmp(mos, "g107.2"))
rtpe_config.common.mos_type = MOS_FB;
#endif
else
die("Invalid --mos option ('%s')", mos);
Expand Down
35 changes: 35 additions & 0 deletions daemon/ssrc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ssrc.h"

#include <glib.h>
#include <math.h>

#include "helpers.h"
#include "call.h"
Expand All @@ -13,9 +14,11 @@ static mos_calc_fn mos_calc_legacy;

#ifdef WITH_TRANSCODING
static mos_calc_fn mos_calc_nb;
static mos_calc_fn mos_calc_fb;

static mos_calc_fn *mos_calcs[__MOS_TYPES] = {
[MOS_NB] = mos_calc_nb,
[MOS_FB] = mos_calc_fb,
[MOS_LEGACY] = mos_calc_legacy,
};
#endif
Expand Down Expand Up @@ -130,6 +133,38 @@ static void mos_calc_nb(struct ssrc_stats_block *ssb) {

ssb->mos = mos_from_rx(Rx);
}

static void mos_calc_fb(struct ssrc_stats_block *ssb) {
double rtt;
if (rtpe_config.mos == MOS_CQ && !ssb->rtt)
return; // can not compute the MOS-CQ unless we have a valid RTT
else if (rtpe_config.mos == MOS_LQ)
rtt = 0; // ignore RTT
else
rtt = ((double) ssb->rtt) / 1000. / 2.;

// G.107.2
rtt += ssb->jitter;
double Ppl = ssb->packetloss;
double Iee = 10.2 + (132. - 10.2) * (Ppl / (Ppl + 4.3));
double Id;
if (rtt <= 100)
Id = 0;
else {
// x = (Math.log(Ta) - Math.log(100)) / Math.log(2)
// = Math.log2(Ta / 100)
// = Math.log2(Ta) - Math.log2(100)
double x = log2(rtt) - log2(100);
Id = 1.48 * 25 * (pow(1 + pow(x, 6), 1./6.) - 3 * pow(1 + pow(x / 3, 6), 1./6.) + 2);
}

static const double Ro = 148;
static const double Is = 0;
static const double A = 0;
double Rx = Ro - Is - Id - Iee + A;

ssb->mos = mos_from_rx(Rx / 1.48 * 100000);
}
#endif

// returned as mos * 10 (i.e. 10 - 50 for 1.0 to 5.0)
Expand Down
7 changes: 6 additions & 1 deletion docs/rtpengine.md
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ call to inject-DTMF won't be sent to __\-\-dtmf-log-dest=__ or __\-\-listen-tcp-
with stats for that call media every *interval* milliseconds, plus one message
every *interval* milliseconds with global stats.

- __\-\-mos=CQ__\|__LQ__\|__G.107__\|__legacy__
- __\-\-mos=CQ__\|__LQ__\|__G.107__\|__G.107.2__\|__legacy__

Options influencing the MOS (Mean Opinion Score) calculation formula.
Multiple options can be listed, using multiple __\-\-mos=...__ arguments at
Expand All @@ -1318,6 +1318,11 @@ call to inject-DTMF won't be sent to __\-\-dtmf-log-dest=__ or __\-\-listen-tcp-
The previous default (and only option) was __legacy__, which uses a custom
formula which yields slightly higher MOS values than G.107.

The option __G.107.2__ uses G.107.2 for fullband audio codecs and the
simplified G.107 formula for all other audio codecs. The full G.107.2
formula is somewhat math-heavy and yields higher MOS values for fullband
audio codecs compared to G.107.

- __\-\-measure-rtp__

Enable measuring RTP metrics even for plain RTP passthrough scenarios. Without
Expand Down
5 changes: 4 additions & 1 deletion lib/codeclib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,8 +1653,11 @@ void codeclib_init(int print) {
if (def->supplemental)
g_queue_push_tail(&__supplemental_codecs, def);

if (rtpe_common_config_ptr->mos_type)
if (rtpe_common_config_ptr->mos_type) {
def->mos_type = rtpe_common_config_ptr->mos_type;
if (def->mos_type == MOS_FB && def->default_clockrate != 48000)
def->mos_type = MOS_NB;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/codeclib.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ struct codec_def_s {
const str silence_pattern;
enum {
MOS_NB = 0, // default
MOS_FB,
MOS_LEGACY,

__MOS_TYPES
Expand Down
8 changes: 6 additions & 2 deletions t/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ include ../lib/common.Makefile
daemon-tests-main daemon-tests-jb daemon-tests-dtx daemon-tests-dtx-cn daemon-tests-pubsub \
daemon-tests-intfs daemon-tests-stats daemon-tests-delay-buffer daemon-tests-delay-timing \
daemon-tests-evs daemon-tests-player-cache daemon-tests-redis daemon-tests-redis-json \
daemon-tests-measure-rtp daemon-tests-mos-legacy
daemon-tests-measure-rtp daemon-tests-mos-legacy daemon-tests-mos-fullband

TESTS= test-bitstr aes-crypt aead-aes-crypt test-const_str_hash.strhash
ifeq ($(with_transcoding),yes)
Expand Down Expand Up @@ -139,7 +139,8 @@ daemon-tests: daemon-tests-main daemon-tests-jb daemon-tests-pubsub daemon-tests
daemon-tests-evs daemon-tests-async-tc \
daemon-tests-audio-player daemon-tests-audio-player-play-media \
daemon-tests-intfs daemon-tests-stats daemon-tests-player-cache daemon-tests-redis \
daemon-tests-rtpp-flags daemon-tests-redis-json daemon-tests-measure-rtp daemon-tests-mos-legacy
daemon-tests-rtpp-flags daemon-tests-redis-json daemon-tests-measure-rtp daemon-tests-mos-legacy \
daemon-tests-mos-fullband

daemon-test-deps: tests-preload.so
$(MAKE) -C ../daemon
Expand Down Expand Up @@ -204,6 +205,9 @@ daemon-tests-measure-rtp: daemon-test-deps
daemon-tests-mos-legacy: daemon-test-deps
./auto-test-helper "$@" perl -I../perl auto-daemon-tests-mos-legacy.pl

daemon-tests-mos-fullband: daemon-test-deps
./auto-test-helper "$@" perl -I../perl auto-daemon-tests-mos-fullband.pl

test-bitstr: test-bitstr.o

test-mix-buffer: test-mix-buffer.o $(COMMONOBJS) mix_buffer.o ssrc.o rtp.o crypto.o helpers.o \
Expand Down
Loading

0 comments on commit a371d36

Please sign in to comment.