mirror of https://github.com/vladmandic/human
switch worker from module to iife importscripts
parent
2d354d03e1
commit
b8db2f0a62
|
@ -1,7 +1,11 @@
|
|||
import Human from '../dist/human.esm.js';
|
||||
// load Human using IIFE script as Chome Mobile does not support Modules as Workers
|
||||
// import Human from '../dist/human.esm.js';
|
||||
self.importScripts('../dist/human.js');
|
||||
|
||||
let busy = false;
|
||||
const human = new Human();
|
||||
// @ts-ignore // Human is registered as global namespace using IIFE script
|
||||
// eslint-disable-next-line no-undef, new-cap
|
||||
const human = new Human.default();
|
||||
|
||||
function log(...msg) {
|
||||
const dt = new Date();
|
||||
|
|
|
@ -387,7 +387,9 @@ function webWorker(input, image, canvas, timestamp) {
|
|||
if (!worker) {
|
||||
// create new webworker and add event handler only once
|
||||
log('creating worker thread');
|
||||
worker = new Worker(ui.worker, { type: 'module' });
|
||||
// load Human using IIFE script as Chome Mobile does not support Modules as Workers
|
||||
// worker = new Worker(ui.worker, { type: 'module' });
|
||||
worker = new Worker(ui.worker);
|
||||
// after receiving message from webworker, parse&draw results and send new frame for processing
|
||||
worker.addEventListener('message', (msg) => {
|
||||
if (msg.data.result.performance && msg.data.result.performance.total) ui.detectFPS.push(1000 / msg.data.result.performance.total);
|
||||
|
|
|
@ -11,7 +11,15 @@ export function calc(newResult: Result): Result {
|
|||
// otherwise bufferedResult is a shallow clone of result plus updated local calculated values
|
||||
// thus mixing by-reference and by-value assignments to minimize memory operations
|
||||
|
||||
const bufferedFactor = 1000 / (Date.now() - newResult.timestamp) / 4;
|
||||
const elapsed = Date.now() - newResult.timestamp;
|
||||
// curve fitted: buffer = 8 - ln(delay)
|
||||
// interpolation formula: current = ((buffer - 1) * previous + live) / buffer
|
||||
// - at 50ms delay buffer = ~4.1 => 28% towards live data
|
||||
// - at 250ms delay buffer = ~2.5 => 40% towards live data
|
||||
// - at 500ms delay buffer = ~1.8 => 55% towards live data
|
||||
// - at 750ms delay buffer = ~1.4 => 71% towards live data
|
||||
// - at 1sec delay buffer = 1 which means live data is used
|
||||
const bufferedFactor = elapsed < 1000 ? 8 - Math.log(elapsed) : 1;
|
||||
|
||||
// interpolate body results
|
||||
if (!bufferedResult.body || (newResult.body.length !== bufferedResult.body.length)) {
|
||||
|
|
Loading…
Reference in New Issue