Skip to content

Commit

Permalink
scan frequency as proposed by serratus
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Jauernig authored and Matthias Jauernig committed Mar 23, 2016
1 parent 9b1e697 commit 3cf474d
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions src/quagga.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,29 @@ function update() {
}
}

function start() {
function startContinuousUpdate() {
var next = null,
delay = 1000 / (_config.frequency || 60);

_stopped = false;
( function frame() {
(function frame(timestamp) {
next = next || timestamp;
if (!_stopped) {
update();
if (_onUIThread && _config.inputStream.type === "LiveStream") {
window.requestAnimFrame(frame);
if (timestamp >= next) {
next += delay;
update();
}
window.requestAnimFrame(frame);
}
}());
}(performance.now()));
}

function start() {
if (_onUIThread && _config.inputStream.type === "LiveStream") {
startContinuousUpdate();
} else {
update();
}
}

function initWorker(cb) {
Expand Down Expand Up @@ -360,23 +373,21 @@ function workerInterface(factory) {
var imageWrapper;

self.onmessage = function(e) {
setTimeout(function() {
if (e.data.cmd === 'init') {
var config = e.data.config;
config.numOfWorkers = 0;
imageWrapper = new Quagga.ImageWrapper({
x: e.data.size.x,
y: e.data.size.y
}, new Uint8Array(e.data.imageData));
Quagga.init(config, ready, imageWrapper);
Quagga.onProcessed(onProcessed);
} else if (e.data.cmd === 'process') {
imageWrapper.data = new Uint8Array(e.data.imageData);
Quagga.start();
} else if (e.data.cmd === 'setReaders') {
Quagga.setReaders(e.data.readers);
}
}, Quagga.getConfig().scanDelay || 0);
if (e.data.cmd === 'init') {
var config = e.data.config;
config.numOfWorkers = 0;
imageWrapper = new Quagga.ImageWrapper({
x: e.data.size.x,
y: e.data.size.y
}, new Uint8Array(e.data.imageData));
Quagga.init(config, ready, imageWrapper);
Quagga.onProcessed(onProcessed);
} else if (e.data.cmd === 'process') {
imageWrapper.data = new Uint8Array(e.data.imageData);
Quagga.start();
} else if (e.data.cmd === 'setReaders') {
Quagga.setReaders(e.data.readers);
}
};

function onProcessed(result) {
Expand Down Expand Up @@ -518,8 +529,5 @@ export default {
},
ImageWrapper: ImageWrapper,
ImageDebug: ImageDebug,
ResultCollector: ResultCollector,
getConfig: function getConfig() {
return _config;
}
ResultCollector: ResultCollector
};

0 comments on commit 3cf474d

Please sign in to comment.