working on yuv

This commit is contained in:
open-trade 2022-01-27 18:58:29 +08:00
parent 74c53f17ae
commit c8b681b84c
7 changed files with 3744 additions and 7 deletions

2479
LibYUV.js Normal file

File diff suppressed because it is too large Load Diff

BIN
LibYUV.wasm Normal file

Binary file not shown.

View File

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

View File

@ -2,7 +2,7 @@
"name": "web_hbb",
"version": "1.0.0",
"scripts": {
"dev": "curl -O https://raw.githubusercontent.com/rgov/js-theora-decoder/main/yuv-canvas-1.2.6.js && vite",
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},

View File

@ -215,11 +215,11 @@ export default class Connection {
this.handleVideoFrame(msg?.videoFrame!);
} else if (msg?.clipboard) {
const cb = msg?.clipboard;
if (cb.compress) cb.content = globals.decompress(cb.content)!;
if (cb.compress) cb.content = await globals.decompress(cb.content)!;
globals.pushEvent("clipboard", cb);
} else if (msg?.cursorData) {
const cd = msg?.cursorData;
cd.colors = globals.decompress(cd.colors)!;
cd.colors = await globals.decompress(cd.colors)!;
globals.pushEvent("cursor_data", cd);
} else if (msg?.cursorId) {
globals.pushEvent("cursor_id", { id: msg?.cursorId });

View File

@ -2,8 +2,10 @@ import Connection from "./connection";
import _sodium from "libsodium-wrappers";
import * as zstd from 'zstddec';
import { CursorData } from "./message";
import { loadOpus, loadVp9 } from "./codec";
const decompressor = new zstd.ZSTDDecoder();
var decompressor;
var wasmDsp;
var currentFrame = undefined;
var events = [];
@ -122,7 +124,7 @@ export function decrypt(signed, nonce, key) {
return sodium.crypto_secretbox_open_easy(signed, makeOnce(nonce), key);
}
export function decompress(compressedArray) {
export async function decompress(compressedArray) {
const MAX = 1024 * 1024 * 64;
const MIN = 1024 * 1024;
let n = 30 * compressedArray.length;
@ -133,6 +135,9 @@ export function decompress(compressedArray) {
n = MIN;
}
try {
if (!decompressor) {
await initZstd();
}
return decompressor.decode(compressedArray, n);
} catch (e) {
console.error('decompress failed: ' + e);
@ -267,6 +272,24 @@ window.getByName = (name, arg) => {
return '';
}
window.init = () => {
decompressor.init();
window.init = async () => {
await initZstd();
}
function I420ToARGB(yuvbuffer) {
//
}
async function initZstd() {
loadOpus(() => { });
loadVp9(() => { });
fetch('./LibYUV.wasm').then(res => res.arrayBuffer()).then((buffer) => {
LibYUV['wasmBinary'] = buffer;
window.wasmDsp = wasmDsp = LibYUV({ wasmBinary: LibYUV.wasmBinary });
console.log('libyuv ready');
});
const tmp = new zstd.ZSTDDecoder();
await tmp.init();
console.log('zstd ready');
decompressor = tmp;
}

1234
yuv-canvas-1.2.6.js Normal file

File diff suppressed because it is too large Load Diff