Skip to content

Commit f27f48d

Browse files
committed
update recv fps metric calculation
1 parent 9ea8ebc commit f27f48d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

scripts/peer-connection-stats.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const calculateBitrate = (cur, old, timeDiff, fallback = 0) =>
2727
? Math.round((8000 * (cur - old)) / timeDiff)
2828
: fallback
2929

30+
const calculateRate = (diff, timeDiff, fallback = 0) =>
31+
diff > 0 ? Math.round((1000 * diff) / timeDiff) : fallback
32+
3033
const positiveDiff = (cur, old) => Math.max(0, (cur || 0) - (old || 0))
3134

3235
const calculateLossRate = (lost, total) =>
@@ -145,6 +148,7 @@ async function getPeerConnectionStats(
145148
bytesSent,
146149
headerBytesSent,
147150
packetsSent,
151+
framesSent,
148152
frameWidth,
149153
frameHeight,
150154
framesPerSecond,
@@ -166,6 +170,7 @@ async function getPeerConnectionStats(
166170
packetsSent,
167171
packetsLost,
168172
nackCount,
173+
framesSent,
169174
frameWidth,
170175
frameHeight,
171176
framesPerSecond,
@@ -204,6 +209,7 @@ async function getPeerConnectionStats(
204209
sumOptional(values.outboundRtp, outboundRtp, prop),
205210
)
206211
;[
212+
'framesSent',
207213
'frameWidth',
208214
'frameHeight',
209215
'framesPerSecond',
@@ -345,9 +351,9 @@ async function getPeerConnectionStats(
345351
decoderImplementation,
346352
framesDecoded,
347353
totalDecodeTime,
354+
framesReceived,
348355
frameWidth,
349356
frameHeight,
350-
framesPerSecond,
351357
firCount,
352358
pliCount,
353359
nackCount,
@@ -375,9 +381,9 @@ async function getPeerConnectionStats(
375381
decoderImplementation,
376382
framesDecoded,
377383
totalDecodeTime,
384+
framesReceived,
378385
frameWidth,
379386
frameHeight,
380-
framesPerSecond,
381387
firCount,
382388
pliCount,
383389
nackCount,
@@ -419,6 +425,17 @@ async function getPeerConnectionStats(
419425
prevStats.values.inboundRtp.headerBytesReceived,
420426
now - prevStats.t,
421427
)
428+
// Update video framesPerSecond.
429+
if (values.inboundRtp.kind === 'video') {
430+
const frames = positiveDiff(
431+
values.inboundRtp.framesReceived,
432+
prevStats.values.inboundRtp.framesReceived,
433+
)
434+
values.inboundRtp.framesPerSecond = calculateRate(
435+
frames,
436+
now - prevStats.t,
437+
)
438+
}
422439
// Update packet loss rate.
423440
const lost = positiveDiff(
424441
values.inboundRtp.packetsLost,

0 commit comments

Comments
 (0)