Minor bugfixes

This commit is contained in:
Christoph Oberhofer
2016-03-20 22:54:58 +01:00
parent 49f1e3db32
commit 040f3e5704
5 changed files with 113 additions and 107 deletions
+37 -35
View File
File diff suppressed because one or more lines are too long
+3 -3
View File
File diff suppressed because one or more lines are too long
+37 -35
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -133,7 +133,7 @@ export default {
},
release: function() {
var tracks = streamRef && streamRef.getVideoTracks();
if (tracks.length) {
if (tracks && tracks.length) {
tracks[0].stop();
}
streamRef = null;
+35 -33
View File
@@ -88,17 +88,12 @@ function canRecord(cb) {
initCanvas(_config);
_framegrabber = FrameGrabber.create(_inputStream, _canvasContainer.dom.image);
if (_config.numOfWorkers > 0) {
initWorkers(function() {
if (ENV.development) {
console.log("Workers created");
}
ready(cb);
});
} else {
initializeData();
adjustWorkerPool(_config.numOfWorkers, function() {
if (_config.numOfWorkers === 0) {
initializeData();
}
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) {
var blobURL,
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 {
init: function(config, cb, imageWrapper) {
_config = merge({}, Config, config);
@@ -455,13 +463,7 @@ export default {
},
stop: function() {
_stopped = true;
_workerPool.forEach(function(workerThread) {
workerThread.worker.terminate();
if (ENV.development) {
console.log("Worker terminated!");
}
});
_workerPool.length = 0;
adjustWorkerPool(0);
if (_config.inputStream.type === "LiveStream") {
CameraAccess.release();
_inputStream.clearEventHandlers();