-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
80 lines (76 loc) · 2.44 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<title>WebCodecs test</title>
<style>
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
#canvas {
width: 50%;
}
</style>
</head>
<body>
<button id="run_js">Run JS</button>
<button id="run_wasm">Run WASM</button>
<button id="run_wasm_gl">Run WASM GL</button>
<button id="run_wasm_vr" disabled>Run WASM VR</button>
<div>
<canvas id="canvas"></canvas>
</div>
<video></video>
<script type="module">
import init, { get_frames, run_wasm, run_wasm_gl, test_wasm_vr, run_wasm_vr } from './webcodecs.js';
await init('./webcodecs_bg.wasm');
document.querySelector('#run_js').addEventListener('click', runJS);
document.querySelector('#run_wasm').addEventListener('click', run_wasm);
document.querySelector('#run_wasm_gl').addEventListener('click', run_wasm_gl);
if (navigator.xr) {
test_wasm_vr().then((isSupported) => {
if (isSupported) {
document.querySelector('#run_wasm_vr').disabled = false;
document.querySelector('#run_wasm_vr').addEventListener('click', run_wasm_vr);
} else {
console.log("Immersive VR not available");
}
},
(e) => {
console.log(e);
});
} else {
console.log("Navigator doesn't have XR!");
}
function runJS() {
const frames = get_frames();
const canvas = document.querySelector('#canvas');
const context = canvas.getContext('2d');
const decoder = new VideoDecoder({
output: (f) => {
context.drawImage(f, 0, 0, f.width, f.height, 0, 0, canvas.width, canvas.height);
f.close();
},
error: (e) => {
console.log(e);
},
});
decoder.configure({
codec: "hev1.1.2.L153.90",
hardwareAcceleration: "prefer-hardware",
});
let frameNum = 0;
setInterval(() => {
decoder.decode(new EncodedVideoChunk({
timestamp: 0,
type: frameNum % frames.length == 0 ? 'key': 'delta',
data: frames[frameNum % frames.length],
}));
++frameNum;
}, 50);
}
</script>
</body>
</html>