Skip to content

Commit 6071412

Browse files
authored
Merge pull request w3c#712 from fippo/plotly
samples: use plotly for drawing the glass-to-glass chart
2 parents 6fc8007 + 95ed134 commit 6071412

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

samples/encode-decode-worker/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ <h2>WebCodecs in Worker + RVFC</h2>
166166
<br/></br>
167167
<button id="connect">Start</button>
168168
<button id="stop">Stop</button>
169-
<script src="https://www.gstatic.com/charts/loader.js"></script>
169+
<script src="https://cdn.plot.ly/plotly-2.18.2.min.js"></script>
170170
<script src="js/main.js"></script>
171171
</body>
172172
</html>

samples/encode-decode-worker/js/main.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ connectButton.disabled = false;
3232
stopButton.disabled = true;
3333

3434
videoSelect.onchange = function () {
35-
videoSource = videoSelect.value;
35+
videoSource = videoSelect.value;
3636
};
3737

3838
const qvgaConstraints = {video: {width: 320, height: 240}};
@@ -94,7 +94,7 @@ function gotDevices(deviceInfos) {
9494
if (deviceInfo.kind === 'videoinput') {
9595
option.text = deviceInfo.label || `camera ${videoSelect.length + 1}`;
9696
videoSelect.appendChild(option);
97-
}
97+
}
9898
}
9999
selectors.forEach((select, selectorIndex) => {
100100
if (Array.prototype.slice.call(select.childNodes).some(n => n.value === values[selectorIndex])) {
@@ -202,14 +202,14 @@ function stop() {
202202
document.addEventListener('DOMContentLoaded', async function(event) {
203203
if (stopped) return;
204204
addToEventLog('DOM Content Loaded');
205-
205+
206206
// Need to support standard mediacapture-transform implementations
207-
208-
if (typeof MediaStreamTrackProcessor === 'undefined' ||
209-
typeof MediaStreamTrackGenerator === 'undefined') {
207+
208+
if (typeof MediaStreamTrackProcessor === 'undefined' ||
209+
typeof MediaStreamTrackGenerator === 'undefined') {
210210
addToEventLog('Your browser does not support the MSTP and MSTG APIs.', 'fatal');
211211
return;
212-
}
212+
}
213213

214214
try {
215215
gotDevices(await navigator.mediaDevices.enumerateDevices());
@@ -231,24 +231,24 @@ document.addEventListener('DOMContentLoaded', async function(event) {
231231
} else {
232232
// draw the glass-glass latency chart
233233
metrics_report();
234-
google.charts.load('current', {'packages':['corechart']});
235-
google.charts.setOnLoadCallback(() => {
236-
let data = new google.visualization.DataTable();
237-
// addToEventLog('Data dump: ' + JSON.stringify(e2e.all));
238-
data.addColumn('number', 'Frame Number');
239-
data.addColumn('number', 'Glass-Glass Latency (ms)');
240-
data.addRows(e2e.all);
241-
let options = {
242-
width: 900,
243-
height: 500,
244-
title: 'Glass-Glass Latency (ms) versus Frame Number',
245-
haxis: {title: 'Frame Number'},
246-
vaxis: {title: 'Glass-Glass Latency'},
247-
legend: 'none'
248-
};
249-
let chart = new google.visualization.ScatterChart(chart2_div);
250-
chart.draw(data, options);
251-
});
234+
const x = e2e.all.map(item => item[0]);
235+
const y = e2e.all.map(item => item[1]);
236+
Plotly.newPlot(chart2_div, [{
237+
x,
238+
y,
239+
mode: 'markers',
240+
type: 'scatter',
241+
}], {
242+
xaxis: {
243+
title: 'Frame number',
244+
autorange: true,
245+
},
246+
yaxis: {
247+
title: 'Glass-Glass-Latency (ms)',
248+
autorange: true,
249+
},
250+
title: 'Glass-Glass Latency (ms) versus Frame Number',
251+
});
252252
}
253253
}, false);
254254

@@ -274,7 +274,7 @@ document.addEventListener('DOMContentLoaded', async function(event) {
274274

275275
async function startMedia() {
276276
if (stopped) return;
277-
addToEventLog('startMedia called');
277+
addToEventLog('startMedia called');
278278
try {
279279
// Collect the bitrate
280280
const rate = document.getElementById('rate').value;
@@ -331,11 +331,11 @@ document.addEventListener('DOMContentLoaded', async function(event) {
331331
resolutionScale: 1,
332332
framerateScale: 1.0,
333333
};
334-
334+
335335
let ssrcArr = new Uint32Array(1);
336336
window.crypto.getRandomValues(ssrcArr);
337337
const ssrc = ssrcArr[0];
338-
338+
339339
const config = {
340340
alpha: "discard",
341341
latencyMode: latencyPref,
@@ -345,7 +345,7 @@ document.addEventListener('DOMContentLoaded', async function(event) {
345345
height: ts.height/vConfig.resolutionScale,
346346
hardwareAcceleration: encHw,
347347
decHwAcceleration: decHw,
348-
bitrate: rate,
348+
bitrate: rate,
349349
framerate: ts.frameRate/vConfig.framerateScale,
350350
keyInterval: vConfig.keyInterval,
351351
ssrc: ssrc
@@ -365,7 +365,7 @@ document.addEventListener('DOMContentLoaded', async function(event) {
365365
config.codec = "hvc1.1.6.L123.00"; // Main profile, level 4.1, main Tier
366366
config.hevc = { format: "annexb" };
367367
config.pt = 2;
368-
break;
368+
break;
369369
case "VP8":
370370
config.codec = "vp8";
371371
config.pt = 3;

0 commit comments

Comments
 (0)