Skip to content

Commit

Permalink
Total kbps
Browse files Browse the repository at this point in the history
  • Loading branch information
henbos committed Feb 5, 2024
1 parent c12435d commit 0d7bbfa
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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}).`;
Expand Down

0 comments on commit 0d7bbfa

Please sign in to comment.