|
|
|
@ -12,6 +12,10 @@ const models = { |
|
|
|
|
model144: 'libs/segm_full_v679.tflite' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let tflite; |
|
|
|
|
let wasmCheck; |
|
|
|
|
let isWasmDisabled = false; |
|
|
|
|
|
|
|
|
|
const segmentationDimensions = { |
|
|
|
|
model96: { |
|
|
|
|
height: 96, |
|
|
|
@ -36,38 +40,39 @@ export async function createVirtualBackgroundEffect(virtualBackground: Object, d |
|
|
|
|
if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) { |
|
|
|
|
throw new Error('JitsiStreamBackgroundEffect not supported!'); |
|
|
|
|
} |
|
|
|
|
let tflite; |
|
|
|
|
let wasmCheck; |
|
|
|
|
|
|
|
|
|
// Checks if WebAssembly feature is supported or enabled by/in the browser.
|
|
|
|
|
// Conditional import of wasm-check package is done to prevent
|
|
|
|
|
// the browser from crashing when the user opens the app.
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
wasmCheck = require('wasm-check'); |
|
|
|
|
const tfliteTimeout = 10000; |
|
|
|
|
|
|
|
|
|
if (wasmCheck?.feature?.simd) { |
|
|
|
|
tflite = await timeout(tfliteTimeout, createTFLiteSIMDModule()); |
|
|
|
|
} else { |
|
|
|
|
tflite = await timeout(tfliteTimeout, createTFLiteModule()); |
|
|
|
|
} |
|
|
|
|
} catch (err) { |
|
|
|
|
if (err?.message === '408') { |
|
|
|
|
logger.error('Failed to download tflite model!'); |
|
|
|
|
dispatch(showWarningNotification({ |
|
|
|
|
titleKey: 'virtualBackground.backgroundEffectError' |
|
|
|
|
})); |
|
|
|
|
} else { |
|
|
|
|
logger.error('Looks like WebAssembly is disabled or not supported on this browser'); |
|
|
|
|
dispatch(showWarningNotification({ |
|
|
|
|
titleKey: 'virtualBackground.webAssemblyWarning', |
|
|
|
|
description: 'WebAssembly disabled or not supported by this browser' |
|
|
|
|
})); |
|
|
|
|
if (!tflite && !isWasmDisabled) { |
|
|
|
|
try { |
|
|
|
|
wasmCheck = require('wasm-check'); |
|
|
|
|
const tfliteTimeout = 10000; |
|
|
|
|
|
|
|
|
|
if (wasmCheck?.feature?.simd) { |
|
|
|
|
tflite = await timeout(tfliteTimeout, createTFLiteSIMDModule()); |
|
|
|
|
} else { |
|
|
|
|
tflite = await timeout(tfliteTimeout, createTFLiteModule()); |
|
|
|
|
} |
|
|
|
|
} catch (err) { |
|
|
|
|
isWasmDisabled = true; |
|
|
|
|
|
|
|
|
|
if (err?.message === '408') { |
|
|
|
|
logger.error('Failed to download tflite model!'); |
|
|
|
|
dispatch(showWarningNotification({ |
|
|
|
|
titleKey: 'virtualBackground.backgroundEffectError' |
|
|
|
|
})); |
|
|
|
|
} else { |
|
|
|
|
logger.error('Looks like WebAssembly is disabled or not supported on this browser'); |
|
|
|
|
dispatch(showWarningNotification({ |
|
|
|
|
titleKey: 'virtualBackground.webAssemblyWarning', |
|
|
|
|
description: 'WebAssembly disabled or not supported by this browser' |
|
|
|
|
})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const modelBufferOffset = tflite._getModelBufferMemoryOffset(); |
|
|
|
|