2025-07-03 17:40:00 +08:00
|
|
|
postMessage({ hasInstalled: true });
|
|
|
|
|
|
|
|
|
|
let offscreenCanvas;
|
|
|
|
|
let webgl;
|
|
|
|
|
|
|
|
|
|
this.onmessage = (event) => {
|
|
|
|
|
const { data } = event;
|
|
|
|
|
const { cmd } = data;
|
|
|
|
|
|
|
|
|
|
if (cmd === 'init') {
|
|
|
|
|
const { canvas, options, scripts } = data;
|
|
|
|
|
|
|
|
|
|
self.importScripts(...scripts);
|
|
|
|
|
const WebGL = self.webgl.default;
|
|
|
|
|
|
|
|
|
|
offscreenCanvas = canvas;
|
|
|
|
|
webgl = new WebGL(canvas, options);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cmd === 'render') {
|
2026-04-23 14:21:51 +08:00
|
|
|
const { frame, type, width, height, yLength, uvLength } = data;
|
2025-07-03 17:40:00 +08:00
|
|
|
|
|
|
|
|
offscreenCanvas.width = width;
|
|
|
|
|
offscreenCanvas.height = height;
|
|
|
|
|
|
2026-04-23 14:21:51 +08:00
|
|
|
let error;
|
|
|
|
|
if (type === 'webcodecs') {
|
|
|
|
|
if (webgl) {
|
|
|
|
|
webgl.setFrameType('VIDEO_FRAME');
|
|
|
|
|
error = webgl.renderFrame(frame, width, height);
|
|
|
|
|
} else {
|
|
|
|
|
frame.close();
|
|
|
|
|
}
|
2025-07-03 17:40:00 +08:00
|
|
|
} else {
|
2026-04-23 14:21:51 +08:00
|
|
|
if (webgl) {
|
|
|
|
|
webgl.setFrameType('YUV_FRAME');
|
|
|
|
|
error = webgl.renderFrame(frame, width, height, yLength, uvLength);
|
|
|
|
|
}
|
2025-07-03 17:40:00 +08:00
|
|
|
}
|
2026-04-23 14:21:51 +08:00
|
|
|
if (error) {
|
|
|
|
|
postMessage({renderError: error});
|
|
|
|
|
webgl && webgl.dispose();
|
|
|
|
|
this.close();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-03 17:40:00 +08:00
|
|
|
} else if (cmd === 'display') {
|
|
|
|
|
const { options } = data;
|
|
|
|
|
webgl && webgl.setDisplayInfo(options);
|
|
|
|
|
} else if (cmd === 'close') {
|
|
|
|
|
webgl && webgl.dispose();
|
|
|
|
|
this.close();
|
|
|
|
|
}
|
|
|
|
|
};
|