Skip to content

Commit

Permalink
fix: Fix quality report when packet count regresses
Browse files Browse the repository at this point in the history
Due to a bug in Firefox and/or Janus, when using simulcast video the
remote report for one of the streams (typically the lowest quality one)
may start with garbage values. This causes the received packet count to
be reported the maximum integer value minus the packet lost count (which
is usually around a few thousands). When newer stats arrive the received
packets start to increase from that extremely high value, and eventually
it overflows, causing the received packet count to go back from
~4294967295 to ~0.

In other cases it was seen that the received packet count can regress a
few values, although it is not clear when or why (this was much rarer
and not reproducible, unlike the scenario described above).

To prevent the regressed value from distorting the analysis due to the
packet count being < 0, and as in both cases once the packet count
regressed the received packet count in all following stat reports
increase from the regressed value, now the stats are reset when a lower
packet count is found.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Jan 28, 2025
1 parent 4343a87 commit 8c34ada
Show file tree
Hide file tree
Showing 2 changed files with 688 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/utils/webrtc/analyzers/PeerConnectionAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,19 @@ PeerConnectionAnalyzer.prototype = {
packetsLost[kind] = this._packetsLost[kind].getLastRawValue()
}

// In some (also strange) cases a newer stat may report a lower
// value than a previous one (it happens sometimes with garbage
// remote reports in simulcast video that cause the values to
// overflow, although it was also seen with a small value regression
// when enabling video). If that happens the stats are reset to
// prevent distorting the analysis with negative packet counts; note
// that in this case the previous value is not kept because it is
// not just an isolated wrong value, all the following stats
// increase from the regressed value.
if (packets[kind] >= 0 && packets[kind] < this._packets[kind].getLastRawValue()) {
this._resetStats(kind)
}

this._addStats(kind, packets[kind], packetsLost[kind], timestamp[kind], roundTripTime[kind])
}
},
Expand Down
Loading

0 comments on commit 8c34ada

Please sign in to comment.