Cleaning up after stopping quagga

pull/29/head
Christoph Oberhofer 10 years ago
parent dbc1fa511b
commit c31ed9c7d9

118
dist/quagga.js vendored

@ -437,7 +437,7 @@ define("almond", function(){});
define( define(
'barcode_reader',[],function() { 'barcode_reader',[],function() {
"use strict";
function BarcodeReader() { function BarcodeReader() {
this._row = []; this._row = [];
@ -631,7 +631,7 @@ define(
"./barcode_reader" "./barcode_reader"
], ],
function(BarcodeReader) { function(BarcodeReader) {
"use strict";
function Code128Reader() { function Code128Reader() {
BarcodeReader.call(this); BarcodeReader.call(this);
@ -1079,7 +1079,7 @@ define(
"./barcode_reader" "./barcode_reader"
], ],
function(BarcodeReader) { function(BarcodeReader) {
"use strict";
function EANReader() { function EANReader() {
BarcodeReader.call(this); BarcodeReader.call(this);
@ -1269,6 +1269,7 @@ define(
return endInfo; return endInfo;
} }
} }
return null;
}; };
EANReader.prototype._findEnd = function(offset, isWhite) { EANReader.prototype._findEnd = function(offset, isWhite) {
@ -1334,7 +1335,7 @@ define(
decodedCodes.push(code); decodedCodes.push(code);
code = self._decodePayload(code, result, decodedCodes); code = self._decodePayload(code, result, decodedCodes);
code = self._findEnd(code.end, false); code = self._findEnd(code.end, false);
if (code === null){ if (!code){
return null; return null;
} }
@ -1378,7 +1379,7 @@ define(
/* global define */ /* global define */
define('image_loader',[],function() { define('image_loader',[],function() {
"use strict";
var ImageLoader = {}; var ImageLoader = {};
ImageLoader.load = function(directory, callback, offset, size, sequence) { ImageLoader.load = function(directory, callback, offset, size, sequence) {
@ -1442,7 +1443,7 @@ define('image_loader',[],function() {
/* global define */ /* global define */
define('input_stream',["image_loader"], function(ImageLoader) { define('input_stream',["image_loader"], function(ImageLoader) {
"use strict";
var InputStream = {}; var InputStream = {};
InputStream.createVideoStream = function(video) { InputStream.createVideoStream = function(video) {
@ -1508,6 +1509,17 @@ define('input_stream',["image_loader"], function(ImageLoader) {
} }
}; };
that.clearEventHandlers = function() {
_eventNames.forEach(function(eventName) {
var handlers = _eventHandlers[eventName];
if (handlers && handlers.length > 0) {
handlers.forEach(function(handler) {
video.removeEventListener(eventName, handler);
});
}
});
};
that.trigger = function(eventName, args) { that.trigger = function(eventName, args) {
var j, var j,
handlers = _eventHandlers[eventName]; handlers = _eventHandlers[eventName];
@ -1708,7 +1720,7 @@ define("typedefs", (function (global) {
/* global define */ /* global define */
define('subImage',["typedefs"], function() { define('subImage',["typedefs"], function() {
"use strict";
/** /**
* Construct representing a part of another {ImageWrapper}. Shares data * Construct representing a part of another {ImageWrapper}. Shares data
@ -1805,7 +1817,7 @@ define('subImage',["typedefs"], function() {
/* global define, vec2 */ /* global define, vec2 */
define('cluster',[],function() { define('cluster',[],function() {
"use strict";
/** /**
* Creates a cluster for grouping similar orientations of datapoints * Creates a cluster for grouping similar orientations of datapoints
@ -4150,7 +4162,7 @@ define("glMatrixAddon", ["glMatrix"], (function (global) {
/* global define */ /* global define */
define('array_helper',[],function() { define('array_helper',[],function() {
"use strict";
return { return {
init : function(arr, val) { init : function(arr, val) {
@ -4237,7 +4249,7 @@ define('array_helper',[],function() {
define('cv_utils',['cluster', 'glMatrixAddon', "array_helper"], function(Cluster2, glMatrixAddon, ArrayHelper) { define('cv_utils',['cluster', 'glMatrixAddon', "array_helper"], function(Cluster2, glMatrixAddon, ArrayHelper) {
"use strict";
/* /*
* cv_utils.js * cv_utils.js
* Collection of CV functions and libraries * Collection of CV functions and libraries
@ -4852,7 +4864,7 @@ define('image_wrapper',[
], ],
function(SubImage, CVUtils, ArrayHelper) { function(SubImage, CVUtils, ArrayHelper) {
'use strict';
/** /**
* Represents a basic image combining the data and size. * Represents a basic image combining the data and size.
@ -5273,7 +5285,7 @@ define('image_wrapper',[
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization * http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
*/ */
define('tracer',[],function() { define('tracer',[],function() {
"use strict";
var Tracer = { var Tracer = {
searchDirections : [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]], searchDirections : [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]],
@ -5382,7 +5394,7 @@ define('tracer',[],function() {
* http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization * http://www.codeproject.com/Tips/407172/Connected-Component-Labeling-and-Vectorization
*/ */
define('rasterizer',["tracer"], function(Tracer) { define('rasterizer',["tracer"], function(Tracer) {
"use strict";
var Rasterizer = { var Rasterizer = {
createContour2D : function() { createContour2D : function() {
@ -5578,7 +5590,7 @@ define('rasterizer',["tracer"], function(Tracer) {
/* global define */ /* global define */
define('skeletonizer',[],function() { define('skeletonizer',[],function() {
"use strict";
/* @preserve ASM BEGIN */ /* @preserve ASM BEGIN */
function Skeletonizer(stdlib, foreign, buffer) { function Skeletonizer(stdlib, foreign, buffer) {
@ -5783,7 +5795,7 @@ define('skeletonizer',[],function() {
/* global define */ /* global define */
define('image_debug',[],function() { define('image_debug',[],function() {
"use strict";
return { return {
drawRect: function(pos, size, ctx, style){ drawRect: function(pos, size, ctx, style){
@ -6328,7 +6340,7 @@ function(ImageWrapper, CVUtils, Rasterizer, Tracer, skeletonizer, ArrayHelper, I
/* global define */ /* global define */
define('bresenham',[],function() { define('bresenham',[],function() {
"use strict";
var Bresenham = {}; var Bresenham = {};
var Slope = { var Slope = {
@ -6534,7 +6546,7 @@ define(
"./array_helper" "./array_helper"
], ],
function(BarcodeReader, ArrayHelper) { function(BarcodeReader, ArrayHelper) {
"use strict";
function Code39Reader() { function Code39Reader() {
BarcodeReader.call(this); BarcodeReader.call(this);
@ -6736,7 +6748,7 @@ define(
"./barcode_reader" "./barcode_reader"
], ],
function(BarcodeReader) { function(BarcodeReader) {
"use strict";
function CodabarReader() { function CodabarReader() {
BarcodeReader.call(this); BarcodeReader.call(this);
@ -7049,7 +7061,7 @@ define(
"./ean_reader" "./ean_reader"
], ],
function(EANReader) { function(EANReader) {
"use strict";
function UPCReader() { function UPCReader() {
EANReader.call(this); EANReader.call(this);
@ -7080,7 +7092,7 @@ define(
"./ean_reader" "./ean_reader"
], ],
function(EANReader) { function(EANReader) {
"use strict";
function EAN8Reader() { function EAN8Reader() {
EANReader.call(this); EANReader.call(this);
@ -7125,7 +7137,7 @@ define(
"./ean_reader" "./ean_reader"
], ],
function(EANReader) { function(EANReader) {
"use strict";
function UPCEReader() { function UPCEReader() {
EANReader.call(this); EANReader.call(this);
@ -7249,7 +7261,7 @@ define('barcode_decoder',[
UPCReader, UPCReader,
EAN8Reader, EAN8Reader,
UPCEReader) { UPCEReader) {
"use strict";
var readers = { var readers = {
code_128_reader: Code128Reader, code_128_reader: Code128Reader,
@ -7526,7 +7538,7 @@ define('barcode_decoder',[
/* global define */ /* global define */
define('frame_grabber',["cv_utils"], function(CVUtils) { define('frame_grabber',["cv_utils"], function(CVUtils) {
"use strict";
var FrameGrabber = {}; var FrameGrabber = {};
@ -7619,7 +7631,7 @@ define('frame_grabber',["cv_utils"], function(CVUtils) {
/* global define */ /* global define */
define('html_utils',[], function() { define('html_utils',[], function() {
"use strict";
function createNode(htmlStr) { function createNode(htmlStr) {
var temp = document.createElement('div'); var temp = document.createElement('div');
@ -7710,7 +7722,7 @@ define('config',[],function(){
/* global define */ /* global define */
define('events',[],function() { define('events',[],function() {
"use strict";
var _events = function() { var _events = function() {
var events = {}; var events = {};
@ -7801,8 +7813,9 @@ define('events',[],function() {
/* global define, MediaStreamTrack */ /* global define, MediaStreamTrack */
define('camera_access',["html_utils"], function(HtmlUtils) { define('camera_access',["html_utils"], function(HtmlUtils) {
"use strict";
var streamRef; var streamRef,
loadedDataHandler;
/** /**
* Wraps browser-specific getUserMedia * Wraps browser-specific getUserMedia
@ -7818,6 +7831,25 @@ define('camera_access',["html_utils"], function(HtmlUtils) {
}, failure); }, failure);
} }
function loadedData(video, callback) {
var attempts = 10;
function checkVideo() {
if (attempts > 0) {
if (video.videoWidth > 0 && video.videoHeight > 0) {
console.log(video.videoWidth + "px x " + video.videoHeight + "px");
callback();
} else {
window.setTimeout(checkVideo, 500);
}
} else {
callback('Unable to play video stream. Is webcam working?');
}
attempts--;
}
checkVideo();
}
/** /**
* Tries to attach the camera-stream to a given video-element * Tries to attach the camera-stream to a given video-element
* and calls the callback function when the content is ready * and calls the callback function when the content is ready
@ -7828,25 +7860,11 @@ define('camera_access',["html_utils"], function(HtmlUtils) {
function initCamera(constraints, video, callback) { function initCamera(constraints, video, callback) {
getUserMedia(constraints, function(src) { getUserMedia(constraints, function(src) {
video.src = src; video.src = src;
video.addEventListener('loadeddata', function() { if (loadedDataHandler) {
var attempts = 10; video.removeEventListener("loadeddata", loadedDataHandler, false);
}
function checkVideo() { loadedDataHandler = loadedData.bind(null, video, callback);
if (attempts > 0) { video.addEventListener('loadeddata', loadedDataHandler, false);
if (video.videoWidth > 0 && video.videoHeight > 0) {
console.log(video.videoWidth + "px x " + video.videoHeight + "px");
callback();
} else {
window.setTimeout(checkVideo, 500);
}
} else {
callback('Unable to play video stream. Is webcam working?');
}
attempts--;
}
checkVideo();
}, false);
video.play(); video.play();
}, function(e) { }, function(e) {
console.log(e); console.log(e);
@ -7957,7 +7975,7 @@ function(Code128Reader,
CameraAccess, CameraAccess,
ImageDebug, ImageDebug,
CVUtils) { CVUtils) {
"use strict";
var _inputStream, var _inputStream,
_framegrabber, _framegrabber,
@ -8335,8 +8353,14 @@ function(Code128Reader,
}, },
stop : function() { stop : function() {
_stopped = true; _stopped = true;
_workerPool.forEach(function(workerThread) {
workerThread.worker.terminate();
console.log("Worker terminated!");
});
_workerPool.length = 0;
if (_config.inputStream.type === "LiveStream") { if (_config.inputStream.type === "LiveStream") {
CameraAccess.release(); CameraAccess.release();
_inputStream.clearEventHandlers();
} }
}, },
pause: function() { pause: function() {

File diff suppressed because one or more lines are too long

@ -3,7 +3,8 @@
define(["html_utils"], function(HtmlUtils) { define(["html_utils"], function(HtmlUtils) {
"use strict"; "use strict";
var streamRef; var streamRef,
loadedDataHandler;
/** /**
* Wraps browser-specific getUserMedia * Wraps browser-specific getUserMedia
@ -19,6 +20,25 @@ define(["html_utils"], function(HtmlUtils) {
}, failure); }, failure);
} }
function loadedData(video, callback) {
var attempts = 10;
function checkVideo() {
if (attempts > 0) {
if (video.videoWidth > 0 && video.videoHeight > 0) {
console.log(video.videoWidth + "px x " + video.videoHeight + "px");
callback();
} else {
window.setTimeout(checkVideo, 500);
}
} else {
callback('Unable to play video stream. Is webcam working?');
}
attempts--;
}
checkVideo();
}
/** /**
* Tries to attach the camera-stream to a given video-element * Tries to attach the camera-stream to a given video-element
* and calls the callback function when the content is ready * and calls the callback function when the content is ready
@ -29,25 +49,11 @@ define(["html_utils"], function(HtmlUtils) {
function initCamera(constraints, video, callback) { function initCamera(constraints, video, callback) {
getUserMedia(constraints, function(src) { getUserMedia(constraints, function(src) {
video.src = src; video.src = src;
video.addEventListener('loadeddata', function() { if (loadedDataHandler) {
var attempts = 10; video.removeEventListener("loadeddata", loadedDataHandler, false);
}
function checkVideo() { loadedDataHandler = loadedData.bind(null, video, callback);
if (attempts > 0) { video.addEventListener('loadeddata', loadedDataHandler, false);
if (video.videoWidth > 0 && video.videoHeight > 0) {
console.log(video.videoWidth + "px x " + video.videoHeight + "px");
callback();
} else {
window.setTimeout(checkVideo, 500);
}
} else {
callback('Unable to play video stream. Is webcam working?');
}
attempts--;
}
checkVideo();
}, false);
video.play(); video.play();
}, function(e) { }, function(e) {
console.log(e); console.log(e);

@ -196,6 +196,7 @@ define(
return endInfo; return endInfo;
} }
} }
return null;
}; };
EANReader.prototype._findEnd = function(offset, isWhite) { EANReader.prototype._findEnd = function(offset, isWhite) {
@ -261,7 +262,7 @@ define(
decodedCodes.push(code); decodedCodes.push(code);
code = self._decodePayload(code, result, decodedCodes); code = self._decodePayload(code, result, decodedCodes);
code = self._findEnd(code.end, false); code = self._findEnd(code.end, false);
if (code === null){ if (!code){
return null; return null;
} }

@ -68,6 +68,17 @@ define(["image_loader"], function(ImageLoader) {
} }
}; };
that.clearEventHandlers = function() {
_eventNames.forEach(function(eventName) {
var handlers = _eventHandlers[eventName];
if (handlers && handlers.length > 0) {
handlers.forEach(function(handler) {
video.removeEventListener(eventName, handler);
});
}
});
};
that.trigger = function(eventName, args) { that.trigger = function(eventName, args) {
var j, var j,
handlers = _eventHandlers[eventName]; handlers = _eventHandlers[eventName];

@ -407,8 +407,14 @@ function(Code128Reader,
}, },
stop : function() { stop : function() {
_stopped = true; _stopped = true;
_workerPool.forEach(function(workerThread) {
workerThread.worker.terminate();
console.log("Worker terminated!");
});
_workerPool.length = 0;
if (_config.inputStream.type === "LiveStream") { if (_config.inputStream.type === "LiveStream") {
CameraAccess.release(); CameraAccess.release();
_inputStream.clearEventHandlers();
} }
}, },
pause: function() { pause: function() {

Loading…
Cancel
Save