Minor bugfixes

pull/98/merge
Christoph Oberhofer 9 years ago
parent 49f1e3db32
commit 040f3e5704

72
dist/quagga.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -133,7 +133,7 @@ export default {
}, },
release: function() { release: function() {
var tracks = streamRef && streamRef.getVideoTracks(); var tracks = streamRef && streamRef.getVideoTracks();
if (tracks.length) { if (tracks && tracks.length) {
tracks[0].stop(); tracks[0].stop();
} }
streamRef = null; streamRef = null;

@ -88,17 +88,12 @@ function canRecord(cb) {
initCanvas(_config); initCanvas(_config);
_framegrabber = FrameGrabber.create(_inputStream, _canvasContainer.dom.image); _framegrabber = FrameGrabber.create(_inputStream, _canvasContainer.dom.image);
if (_config.numOfWorkers > 0) { adjustWorkerPool(_config.numOfWorkers, function() {
initWorkers(function() { if (_config.numOfWorkers === 0) {
if (ENV.development) { initializeData();
console.log("Workers created"); }
}
ready(cb);
});
} else {
initializeData();
ready(cb); ready(cb);
} });
} }
function ready(cb){ function ready(cb){
@ -313,22 +308,6 @@ function start() {
}()); }());
} }
function initWorkers(cb) {
var i;
_workerPool = [];
for (i = 0; i < _config.numOfWorkers; i++) {
initWorker(workerInitialized);
}
function workerInitialized(workerThread) {
_workerPool.push(workerThread);
if (_workerPool.length >= _config.numOfWorkers){
cb();
}
}
}
function initWorker(cb) { function initWorker(cb) {
var blobURL, var blobURL,
workerThread = { workerThread = {
@ -439,6 +418,35 @@ function setReaders(readers) {
} }
} }
function adjustWorkerPool(capacity, cb) {
const increaseBy = capacity - _workerPool.length;
if (increaseBy === 0) {
return cb && cb();
}
if (increaseBy < 0) {
const workersToTerminate = _workerPool.slice(increaseBy);
workersToTerminate.forEach(function(workerThread) {
workerThread.worker.terminate();
if (ENV.development) {
console.log("Worker terminated!");
}
});
_workerPool = _workerPool.slice(0, increaseBy);
return cb && cb();
} else {
for (var i = 0; i < increaseBy; i++) {
initWorker(workerInitialized);
}
function workerInitialized(workerThread) {
_workerPool.push(workerThread);
if (_workerPool.length >= capacity){
cb && cb();
}
}
}
}
export default { export default {
init: function(config, cb, imageWrapper) { init: function(config, cb, imageWrapper) {
_config = merge({}, Config, config); _config = merge({}, Config, config);
@ -455,13 +463,7 @@ export default {
}, },
stop: function() { stop: function() {
_stopped = true; _stopped = true;
_workerPool.forEach(function(workerThread) { adjustWorkerPool(0);
workerThread.worker.terminate();
if (ENV.development) {
console.log("Worker terminated!");
}
});
_workerPool.length = 0;
if (_config.inputStream.type === "LiveStream") { if (_config.inputStream.type === "LiveStream") {
CameraAccess.release(); CameraAccess.release();
_inputStream.clearEventHandlers(); _inputStream.clearEventHandlers();

Loading…
Cancel
Save