Skip to content

Commit 2d5ba9b

Browse files
authored
Merge pull request #145 from wireapp/fix/sifa/WPB-24049-tune-rx-jitter
Tune stats rx jitter (WPB 24049
2 parents b965ada + 3e1ccbc commit 2d5ba9b

File tree

6 files changed

+69
-16
lines changed

6 files changed

+69
-16
lines changed

src/ccall/ccall.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,7 @@ static void ccall_reconnect(struct ccall *ccall,
526526

527527
if (notify) {
528528

529-
struct stats_report stats = {
530-
.packets.lost.rx = ICALL_RECONNECTING,
531-
.packets.lost.tx = ICALL_RECONNECTING,
532-
};
529+
struct stats_report stats = { 0 };
533530

534531
ICALL_CALL_CB(ccall->icall, qualityh,
535532
&ccall->icall,

src/egcall/egcall.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,10 +1029,7 @@ static void noconn_handler(void *arg)
10291029
{
10301030
struct egcall *egcall = arg;
10311031

1032-
struct stats_report stats = {
1033-
.packets.lost.rx = ICALL_NETWORK_PROBLEM,
1034-
.packets.lost.tx = ICALL_NETWORK_PROBLEM,
1035-
};
1032+
struct stats_report stats = { 0 };
10361033

10371034
ICALL_CALL_CB(egcall->icall, qualityh,
10381035
&egcall->icall,

src/jzon/jzon.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,21 @@ int jzon_double(double *dst, struct json_object *obj, const char *key)
162162
if (!json_object_object_get_ex(obj, key, &value))
163163
return ENOENT;
164164
type = json_object_get_type(value);
165-
if (type != json_type_double && type != json_type_int)
165+
166+
switch (type) {
167+
case json_type_double:
168+
*dst = json_object_get_double(value);
169+
break;
170+
171+
case json_type_int:
172+
*dst = (double)(json_object_get_int(value));
173+
break;
174+
175+
default:
166176
return EPROTO;
167177

168-
*dst = json_object_get_double(value);
178+
}
179+
169180
return 0;
170181
}
171182

src/stats/stats.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ static uint32_t calculate_loss_percentage(uint32_t packets, uint32_t lost) {
222222
static int read_packet_stats_and_jitter(struct avs_stats *stats, struct stats_obj* stats_obj)
223223
{
224224
struct le *le = NULL;
225+
double audio_jitter = 0;
226+
int aj_count = 0;
227+
double video_jitter = 0;
228+
int vj_count = 0;
225229

226230
if (!stats || !stats_obj) {
227231
return EINVAL;
@@ -231,6 +235,8 @@ static int read_packet_stats_and_jitter(struct avs_stats *stats, struct stats_ob
231235
Calculation of packet and loss statistics
232236
1. read json stats into report
233237
webrtc json -> stats.report
238+
1.1 rx jitter calculation is done wrt mean of incoming rtps
239+
that have nonzero received packets.
234240
2. calculate interval percentage for packet loss into tmp variables
235241
loss_tx = calculate_loss_percentage(...)
236242
loss_rx = calculate_loss_percentage(...)
@@ -245,11 +251,17 @@ static int read_packet_stats_and_jitter(struct avs_stats *stats, struct stats_ob
245251

246252
if (data->kind == STATS_KIND_AUDIO) {
247253
stats->report.packets.audio.rx += data->packets_received;
248-
stats->report.jitter.audio.rx = max(stats->report.jitter.audio.rx, (1000.0 * data->jitter));
254+
if (data->packets_received) {
255+
audio_jitter += data->jitter;
256+
aj_count++;
257+
}
249258
}
250259
else if (data->kind == STATS_KIND_VIDEO) {
251260
stats->report.packets.video.rx += data->packets_received;
252-
stats->report.jitter.video.rx = max(stats->report.jitter.video.rx, (1000.0 * data->jitter));
261+
if (data->packets_received) {
262+
video_jitter += data->jitter;
263+
vj_count++;
264+
}
253265
}
254266

255267
stats->report.packets.lost.rx += data->packets_lost;
@@ -279,6 +291,10 @@ static int read_packet_stats_and_jitter(struct avs_stats *stats, struct stats_ob
279291
stats->report.packets.lost.tx += data->packets_lost;
280292
}
281293

294+
// 1.1 calcualete rx jitter in ms with taking mean
295+
stats->report.jitter.audio.rx = aj_count ? 1000 * (audio_jitter / aj_count) : 0;
296+
stats->report.jitter.video.rx = vj_count ? 1000 * (video_jitter / vj_count) : 0;
297+
282298
// 2. calculate interval percentage for packet loss into tmp variables
283299
uint32_t loss_tx = calculate_loss_percentage(
284300
(stats->report.packets.audio.tx - stats->last_packets.audio.tx +

test/test_jzon.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ TEST(jzon, createf_succeeds)
153153
ASSERT_EQ(intv, 42);
154154
ASSERT_EQ(0, jzon_double(&doublev, jout, "double"));
155155
ASSERT_EQ(doublev, 42.);
156+
// Reading an integer as double should also be ok
157+
ASSERT_EQ(0, jzon_double(&doublev, jout, "int"));
158+
ASSERT_EQ(doublev, 42.);
156159

157160
ASSERT_EQ(0, jzon_bool(&bval, jout, "bool0"));
158161
ASSERT_FALSE(bval);

test/test_stats.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,32 +320,37 @@ class StatsJitter: public Base,
320320

321321
const auto irrelevant_rtp = new RTCInboundRtpStreamStats("irrelevantRtpId", Timestamp::Zero());
322322
irrelevant_rtp->kind = "irrelevant";
323-
irrelevant_rtp->jitter = 1.0;
323+
irrelevant_rtp->jitter = 1;
324+
irrelevant_rtp->packets_received = 1;
324325
report->AddStats(std::unique_ptr<RTCStats>(irrelevant_rtp));
325326

326327
const auto audio_rtp = new RTCInboundRtpStreamStats("someAudioRtpId", Timestamp::Zero());
327328
audio_rtp->kind = "audio";
328329
audio_rtp->jitter = 0.01;
330+
audio_rtp->packets_received = 1;
329331
report->AddStats(std::unique_ptr<RTCStats>(audio_rtp));
330332

331333
const auto another_audio_rtp = new RTCInboundRtpStreamStats("anotherRtpId", Timestamp::Zero());
332334
another_audio_rtp->kind = "audio";
333335
another_audio_rtp->jitter = 0.02;
336+
another_audio_rtp->packets_received = 1;
334337
report->AddStats(std::unique_ptr<RTCStats>(another_audio_rtp));
335338

336339
const auto video_rtp = new RTCInboundRtpStreamStats("someVideoRtpId", Timestamp::Zero());
337340
video_rtp->kind = "video";
338341
video_rtp->jitter = 0.025;
342+
video_rtp->packets_received = 1;
339343
report->AddStats(std::unique_ptr<RTCStats>(video_rtp));
340344

341345
const auto another_video_rtp = new RTCInboundRtpStreamStats("anotherVideoRtpId", Timestamp::Zero());
342346
another_video_rtp->kind = "video";
343347
another_video_rtp->jitter = 0.015;
348+
another_video_rtp->packets_received = 1;
344349
report->AddStats(std::unique_ptr<RTCStats>(another_video_rtp));
345350

346351
const auto remote_irrelevant_rtp = new RTCRemoteInboundRtpStreamStats("irrelevantRemoteRtpId", Timestamp::Zero());
347352
remote_irrelevant_rtp->kind = "irrelevant";
348-
remote_irrelevant_rtp->jitter = 1.0;
353+
remote_irrelevant_rtp->jitter = 1;
349354
report->AddStats(std::unique_ptr<RTCStats>(remote_irrelevant_rtp));
350355

351356
const auto remote_audio_rtp = new RTCRemoteInboundRtpStreamStats("someRemoteAudioRtpId", Timestamp::Zero());
@@ -370,14 +375,38 @@ TEST_F(StatsJitter, audio_and_video)
370375
stats_get_report(stats, &sr);
371376

372377
stats_jitter expected_jitter;
373-
expected_jitter.audio.rx = 20; // max of [0.01, 0.02] * 1000
378+
expected_jitter.audio.rx = 15; // mean of [0.01, 0.02] * 1000
374379
expected_jitter.audio.tx = 30;
375-
expected_jitter.video.rx = 25; // max of [0.025, 0.015] * 1000
380+
expected_jitter.video.rx = 20; // mean of [0.025, 0.015] * 1000
376381
expected_jitter.video.tx = 40;
377382

378383
EXPECT_EQ(sr.jitter, expected_jitter);
379384
}
380385

386+
TEST_F(StatsJitter, zero_packet_rtp)
387+
{
388+
const auto inbound_rtp = new RTCInboundRtpStreamStats("inboundRtpId", Timestamp::Zero());
389+
inbound_rtp->kind = "audio";
390+
inbound_rtp->jitter = 0.05;
391+
inbound_rtp->packets_received = 1;
392+
auto report = RTCStatsReport::Create(Timestamp::Zero());
393+
report->AddStats(std::unique_ptr<RTCStats>(inbound_rtp));
394+
395+
const auto zero_packets_inbound_rtp = new RTCInboundRtpStreamStats("zeroInboundRtpId", Timestamp::Zero());
396+
zero_packets_inbound_rtp->kind = "audio";
397+
zero_packets_inbound_rtp->jitter = 0;
398+
report->AddStats(std::unique_ptr<RTCStats>(zero_packets_inbound_rtp));
399+
400+
stats_update(stats, report->ToJson().c_str());
401+
stats_get_report(stats, &sr);
402+
403+
stats_jitter expected_jitter;
404+
405+
const auto expected_audio_jitter = 50;
406+
407+
EXPECT_EQ(sr.jitter.audio.rx, expected_audio_jitter);
408+
}
409+
381410
// ------------------------------------- RTT Tests --------------------------------------
382411
class StatsRtt: public Base,
383412
public ::testing::Test {

0 commit comments

Comments
 (0)