Skip to content

Commit

Permalink
Fix simulcast report
Browse files Browse the repository at this point in the history
  • Loading branch information
Karolk99 committed Jul 2, 2024
1 parent 0ca3bad commit 1656f2a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
4 changes: 2 additions & 2 deletions webrtc/src/benchmarkRtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export const runBenchmark = async (args: Args) => {
time < args.duration;
step = Math.min(step, args.duration - time), time += step
) {
const report = reportToString();
appendReportCSV(args.csvReportPath, time);
const report = reportToString(args.useSimulcast);
appendReportCSV(args.csvReportPath, time, args.useSimulcast);

writeInPlace(`Duration: ${time} / ${args.duration}s, ${report}`);
await delay(step);
Expand Down
40 changes: 29 additions & 11 deletions webrtc/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,45 @@ const fs = require("fs");
let rawTrackEncodings: RawTrackEncodings = new Map();
let rawTrackScores: RawRtcScores = new Map();

export const reportToString = () => {
const encoding = new EncodingsReport(rawTrackEncodings).toString();
export const reportToString = (useSimulcast: boolean) => {
const encoding = new EncodingsReport(
rawTrackEncodings,
useSimulcast
).toString();
const rtcScore = new RtcScoreReport(rawTrackScores).toString();

return `Encodings: ${encoding}, RtcScore: ${rtcScore}`;
};


export const createReportCSV = (path: string) => {
const csv_columns = `timestamp,min,max,q1,q2,q3,low,mid,high\n`
const csv_columns = `timestamp,min,max,q1,q2,q3,low,mid,high\n`;
fs.writeFile(path, csv_columns, () => {});
}
};

export const appendReportCSV = (path: string, timestamp: number) => {
const encoding = new EncodingsReport(rawTrackEncodings);
export const appendReportCSV = (
path: string,
timestamp: number,
useSimulcast: boolean
) => {
const encoding = new EncodingsReport(rawTrackEncodings, useSimulcast);
const rtcScore = new RtcScoreReport(rawTrackScores);

if (rtcScore.report === null) return;

const report = { ...rtcScore.report, encoding: encoding.report };

// duration,min,max,q1,q2,q3,low,mid,high
const newLine = `${timestamp},${report.min.toFixed(2)},${report.max.toFixed(2)},${report.quartiles.Q1.toFixed(2)},${report.quartiles.Q2.toFixed(2)},${report.quartiles.Q3.toFixed(2)},${report.encoding.l},${report.encoding.m},${report.encoding.h}\n`;
const newLine = `${timestamp},${report.min.toFixed(2)},${report.max.toFixed(
2
)},${report.quartiles.Q1.toFixed(2)},${report.quartiles.Q2.toFixed(
2
)},${report.quartiles.Q3.toFixed(2)},${report.encoding.l},${
report.encoding.m
},${report.encoding.h}\n`;

fs.appendFile(path, newLine, (err: any) => {});
};


export const onConsoleMessage = (msg: ConsoleMessage, peerToken: PeerToken) => {
const content = msg.text().trim();

Expand All @@ -50,7 +61,7 @@ class EncodingsReport {
h: number;
};

constructor(reportRaw: Map<string, string>) {
constructor(reportRaw: Map<string, string>, useSimulcast: boolean) {
const totalEncodings = { l: 0, m: 0, h: 0 };

reportRaw.forEach((encodings: string, peerId: string) => {
Expand All @@ -62,7 +73,14 @@ class EncodingsReport {
}
});

this.report = totalEncodings;
if (useSimulcast) {
this.report = totalEncodings;
} else {
// when simulcast is not used, returned encoding is always high
// even though encoding used in no simulcast test is always medium
const m = Object.values(totalEncodings).reduce((a, b) => a + b, 0);
this.report = { l: 0, m: m, h: 0 };
}
}

toString = () => {
Expand Down

0 comments on commit 1656f2a

Please sign in to comment.