@@ -27,6 +27,9 @@ const calculateBitrate = (cur, old, timeDiff, fallback = 0) =>
27
27
? Math . round ( ( 8000 * ( cur - old ) ) / timeDiff )
28
28
: fallback
29
29
30
+ const calculateRate = ( diff , timeDiff , fallback = 0 ) =>
31
+ diff > 0 ? Math . round ( ( 1000 * diff ) / timeDiff ) : fallback
32
+
30
33
const positiveDiff = ( cur , old ) => Math . max ( 0 , ( cur || 0 ) - ( old || 0 ) )
31
34
32
35
const calculateLossRate = ( lost , total ) =>
@@ -145,6 +148,7 @@ async function getPeerConnectionStats(
145
148
bytesSent,
146
149
headerBytesSent,
147
150
packetsSent,
151
+ framesSent,
148
152
frameWidth,
149
153
frameHeight,
150
154
framesPerSecond,
@@ -166,6 +170,7 @@ async function getPeerConnectionStats(
166
170
packetsSent,
167
171
packetsLost,
168
172
nackCount,
173
+ framesSent,
169
174
frameWidth,
170
175
frameHeight,
171
176
framesPerSecond,
@@ -204,6 +209,7 @@ async function getPeerConnectionStats(
204
209
sumOptional ( values . outboundRtp , outboundRtp , prop ) ,
205
210
)
206
211
; [
212
+ 'framesSent' ,
207
213
'frameWidth' ,
208
214
'frameHeight' ,
209
215
'framesPerSecond' ,
@@ -345,9 +351,9 @@ async function getPeerConnectionStats(
345
351
decoderImplementation,
346
352
framesDecoded,
347
353
totalDecodeTime,
354
+ framesReceived,
348
355
frameWidth,
349
356
frameHeight,
350
- framesPerSecond,
351
357
firCount,
352
358
pliCount,
353
359
nackCount,
@@ -375,9 +381,9 @@ async function getPeerConnectionStats(
375
381
decoderImplementation,
376
382
framesDecoded,
377
383
totalDecodeTime,
384
+ framesReceived,
378
385
frameWidth,
379
386
frameHeight,
380
- framesPerSecond,
381
387
firCount,
382
388
pliCount,
383
389
nackCount,
@@ -419,6 +425,17 @@ async function getPeerConnectionStats(
419
425
prevStats . values . inboundRtp . headerBytesReceived ,
420
426
now - prevStats . t ,
421
427
)
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
+ }
422
439
// Update packet loss rate.
423
440
const lost = positiveDiff (
424
441
values . inboundRtp . packetsLost ,
0 commit comments