Fix AVIF multithreading (#981)

This commit is contained in:
Ingvar Stepanyan
2021-03-23 12:28:56 +00:00
committed by GitHub
parent 914bff41c6
commit 9d890a8fd6
11 changed files with 37 additions and 13 deletions

View File

@@ -13,11 +13,22 @@
import type { AVIFModule } from 'codecs/avif/enc/avif_enc';
import type { EncodeOptions } from '../shared/meta';
import wasmUrlWithoutMT from 'url:codecs/avif/enc/avif_enc.wasm';
import wasmUrlWithMT from 'url:codecs/avif/enc/avif_enc_mt.wasm';
import workerUrl from 'omt:codecs/avif/enc/avif_enc_mt.worker.js';
import { initEmscriptenModule } from 'features/worker-utils';
import { threads } from 'wasm-feature-detect';
let emscriptenModule: Promise<AVIFModule>;
async function init() {
if (await threads()) {
const avifEncoder = await import('codecs/avif/enc/avif_enc_mt');
return initEmscriptenModule<AVIFModule>(
avifEncoder.default,
wasmUrlWithMT,
workerUrl,
);
}
const avifEncoder = await import('codecs/avif/enc/avif_enc.js');
return initEmscriptenModule(avifEncoder.default, wasmUrlWithoutMT);
}