From 0d7bbfaa5154cbaca4441058de3c361baa966ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bostr=C3=B6m?= Date: Mon, 5 Feb 2024 14:35:46 +0100 Subject: [PATCH] Total kbps --- src/demo.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/demo.js b/src/demo.js index e0d8b96..faf4e0b 100644 --- a/src/demo.js +++ b/src/demo.js @@ -321,7 +321,11 @@ async function pollGetStats() { } outboundRtpsByRid.set(stats.rid, stats); } - let statusStr = 'Sender Stats\n\n'; + let totalSendBytes = 0; + let prevTotalSendBytes = 0; + let deltaTimestampMs = 1000; + + let statusStr = ''; let qpStr = ''; for (let i = 0; i < 3; ++i) { if (i != 0) { @@ -330,6 +334,15 @@ async function pollGetStats() { } const outboundRtp = outboundRtpsByRid.get(`${i}`); const prevOutboundRtp = pc1PrevStatsReport.get(outboundRtp.id); + + totalSendBytes += outboundRtp.bytesSent; + if (prevOutboundRtp) { + prevTotalSendBytes += prevOutboundRtp.bytesSent; + // The delta of all RTP stats objects should be the same so it doesn't + // matter from which RID we take the delta timestamp. + deltaTimestampMs = outboundRtp.timestamp - prevOutboundRtp.timestamp; + } + statusStr += outboundRtpToString(report, outboundRtp, prevOutboundRtp); if (prevOutboundRtp && outboundRtp.framesEncoded > prevOutboundRtp.framesEncoded) { @@ -340,6 +353,10 @@ async function pollGetStats() { qpStr += 'N/A'; } } + const totalBps = + (totalSendBytes - prevTotalSendBytes) / deltaTimestampMs * 1000; + statusStr = + `Sending ${Math.round(totalBps * 8 / 1000)} kbps...\n\n${statusStr}`; const reason = outboundRtpsByRid.get('0')?.qualityLimitationReason ?? 'none'; statusStr += `\n\nLimited by ${reason} (QP values: ${qpStr}).`;