This commit is contained in:
rustdesk 2022-01-28 03:53:23 +08:00
parent 58f2419f27
commit 58415897ae
6 changed files with 56 additions and 2504 deletions

2479
LibYUV.js

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -6,7 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="node_modules/ogv/dist/ogv.js"></script> <script src="node_modules/ogv/dist/ogv.js"></script>
<script src="./yuv-canvas-1.2.6.js"></script> <script src="./yuv-canvas-1.2.6.js"></script>
<script src="./LibYUV.js"></script>
<title>Vite App</title> <title>Vite App</title>
</head> </head>
<body> <body>

View File

@ -239,6 +239,7 @@ export default class Connection {
draw(frame: any) { draw(frame: any) {
this._draw?.(frame); this._draw?.(frame);
// globals.I420ToABGR(frame);
} }
close() { close() {

View File

@ -5,7 +5,7 @@ import { CursorData } from "./message";
import { loadOpus, loadVp9 } from "./codec"; import { loadOpus, loadVp9 } from "./codec";
var decompressor; var decompressor;
var wasmDsp; var wasmExports;
var currentFrame = undefined; var currentFrame = undefined;
var events = []; var events = [];
@ -280,34 +280,65 @@ window.init = async () => {
await initZstd(); await initZstd();
} }
function I420ToABGR(yb) { let yPtr, yPtrLen, uPtr, uPtrLen, vPtr, vPtrLen, outPtr, outPtrLen;
if (!wasmDsp) return null; // let testSpeed = [0, 0];
const yPtr = wasmDsp._malloc(yb.y.bytes.length); export function I420ToABGR(yb) {
wasmDsp.HEAPU8.set(yb.y.bytes, yPtr); if (!wasmExports) return;
const uPtr = wasmDsp._malloc(yb.u.bytes.length); // testSpeed[0] += 1;
wasmDsp.HEAPU8.set(yb.u.bytes, uPtr); const tm0 = new Date().getTime();
const vPtr = wasmDsp._malloc(yb.v.bytes.length); const { malloc, free, memory } = wasmExports;
wasmDsp.HEAPU8.set(yb.v.bytes, vPtr); const HEAPU8 = new Uint8Array(memory.buffer);
const oSize = yb.format.width * yb.format.height * 4; let n = yb.y.bytes.length;
const outPtr = wasmDsp._malloc(oSize); if (yPtrLen != n) {
const res = wasmDsp._I420ToABGR(yPtr, yb.y.stride, uPtr, yb.u.stride, vPtr, yb.v.stride, outPtr, yb.format.width * 4, if (yPtr) free(yPtr);
yb.format.width, yb.format.height); yPtrLen = n;
const out = wasmDsp.HEAPU8.slice(outPtr, outPtr + oSize); yPtr = malloc(n);
wasmDsp._free(yPtr); }
wasmDsp._free(uPtr); HEAPU8.set(yb.y.bytes, yPtr);
wasmDsp._free(vPtr); n = yb.u.bytes.length;
wasmDsp._free(outPtr); if (uPtrLen != n) {
if (uPtr) free(uPtr);
uPtrLen = n;
uPtr = malloc(n);
}
HEAPU8.set(yb.u.bytes, uPtr);
n = yb.v.bytes.length;
if (vPtrLen != n) {
if (vPtr) free(vPtr);
vPtrLen = n;
vPtr = malloc(n);
}
HEAPU8.set(yb.v.bytes, vPtr);
const w = yb.format.width;
const h = yb.format.height;
n = w * h * 4;
if (outPtrLen != n) {
if (outPtr) free(outPtr);
outPtrLen = n;
outPtr = malloc(n);
}
// const res = wasmExports.I420ToARGB(yPtr, yb.y.stride, uPtr, yb.u.stride, vPtr, yb.v.stride, outPtr, w * 4, w, h);
// const res = wasmExports.AVX_YUV_to_RGB(outPtr, yPtr, uPtr, vPtr, w, h);
const res = wasmExports.yuv420_rgb24_std(w, h, yPtr, uPtr, vPtr, yb.y.stride, yb.v.stride, outPtr, w * 4, 0);
const out = HEAPU8.slice(outPtr, outPtr + n);
/*
testSpeed[1] += new Date().getTime() - tm0;
if (testSpeed[0] > 30) {
console.log(testSpeed[1] / testSpeed[0]);
testSpeed = [0, 0];
}
*/
return out; return out;
} }
async function initZstd() { async function initZstd() {
loadOpus(() => { }); loadOpus(() => { });
loadVp9(() => { }); loadVp9(() => { });
fetch('./LibYUV.wasm').then(res => res.arrayBuffer()).then((buffer) => { const response = await fetch('yuv.wasm');
LibYUV['wasmBinary'] = buffer; const file = await response.arrayBuffer();
window.wasmDsp = wasmDsp = LibYUV({ wasmBinary: LibYUV.wasmBinary }); const wasm = await WebAssembly.instantiate(file);
console.log('libyuv ready'); wasmExports = wasm.instance.exports;
}); console.log('yuv ready');
const tmp = new zstd.ZSTDDecoder(); const tmp = new zstd.ZSTDDecoder();
await tmp.init(); await tmp.init();
console.log('zstd ready'); console.log('zstd ready');

BIN
yuv.wasm Executable file

Binary file not shown.