Added scope to Soure to determine if it was created by quagga or not

feature/image-source
Christoph Oberhofer 8 years ago
parent eae4904e7a
commit b799a154b0

@ -1,7 +1,9 @@
import {clone} from 'lodash';
import {determineOrientation, PORTRAIT} from '../common/device';
import {determineOrientation} from '../common/device';
import CameraAccess from './camera_access';
import {getViewport} from '../common/utils';
import {generateSourceInterface} from './SourceInterface';
import {Scope} from './input/SourceScope';
const ConstraintPresets = [
{
@ -151,14 +153,14 @@ function adjustWithZoom(videoConstraints) {
};
}
export function fromCamera(constraints, {target} = {}) {
export function fromCamera(constraints, {target, scope = Scope.EXTERNAL} = {}) {
let {video: videoConstraints, zoom} = adjustWithZoom(constraints);
const video = getOrCreateVideo(target);
return CameraAccess.request(video, videoConstraints)
.then((mediastream) => {
let track = mediastream.getVideoTracks()[0];
return {
return Object.assign(generateSourceInterface(), {
type: "CAMERA",
getDimensions() {
const viewport = {
@ -182,13 +184,13 @@ export function fromCamera(constraints, {target} = {}) {
},
};
},
getConstraints: function() {
getConstraints() {
return videoConstraints;
},
getDrawable: function() {
getDrawable() {
return video;
},
applyConstraints: function(newConstraints) {
applyConstraints(newConstraints) {
track.stop();
constraints = newConstraints;
const adjustment = adjustWithZoom(constraints);
@ -200,9 +202,15 @@ export function fromCamera(constraints, {target} = {}) {
track = mediastream.getVideoTracks()[0];
});
},
getLabel: function() {
getLabel() {
return track.label;
},
stop() {
track.stop();
},
getScope() {
return scope;
}
};
});
});
}

@ -1,4 +1,5 @@
import {findTagsInObjectURL} from './exif_helper';
import {generateSourceInterface} from './SourceInterface';
export function fromImage(input, constraints = {width: 800, height: 800, channels: 3}) {
var $image = null;
@ -49,7 +50,7 @@ export function fromImage(input, constraints = {width: 800, height: 800, channel
const calculatedHeight = imageAR > 1 ? Math.floor((1 / imageAR) * constraints.width) : constraints.width;
const colorChannels = constraints.channels || 3;
return {
return Object.assign(generateSourceInterface(), {
type: "IMAGE",
colorChannels,
tags,
@ -76,9 +77,6 @@ export function fromImage(input, constraints = {width: 800, height: 800, channel
getConstraints: function() {
return constraints;
},
applyConstraints: function() {
console.log('ImageSource.applyConstraints not implemented');
},
};
});
});
}

@ -1,5 +1,6 @@
export * from './ImageSource';
export * from './CameraSource';
export * from './SourceScope';
export function fromCanvas(input) {
var $canvas = null;

@ -0,0 +1,29 @@
const viewport = {
x: 0,
y: 0,
width: 0,
height: 0,
};
const canvas = {
height: 0,
width: 0,
};
export function generateSourceInterface() {
return {
type: "INTERFACE",
getDimensions() {
return {
viewport,
canvas,
};
},
getConstraints() {},
getDrawable() {},
applyConstraints() {},
getLabel() {},
stop() {},
getScope() {},
};
}

@ -0,0 +1,4 @@
export const Scope = {
INTERNAL: "INTERNAL",
EXTERNAL: 'EXTERNAL',
};

@ -143,7 +143,10 @@ function createApi() {
fromCamera(options) {
const config = merge({}, Config, options);
return Source
.fromCamera(config.constraints, {target: config.target})
.fromCamera(config.constraints, {
target: config.target,
scope: Source.Scope.INTERNAL,
})
.then(fromSource.bind(null, config));
},
fromSource(src, inputConfig) {

@ -6,8 +6,8 @@ import BarcodeDecoder from './decoder/barcode_decoder';
import createEventedElement from './common/events';
import {release, aquire, releaseAll} from './common/buffers';
import Config from './config/config';
import CameraAccess from './input/camera_access';
import {getViewport} from './common/utils';
import {Scope} from './input/SourceScope';
const vec2 = {
clone: require('gl-vec2/clone')
@ -438,8 +438,8 @@ function createScanner(pixelCapturer) {
_stopped = true;
adjustWorkerPool(0);
releaseAll();
if (source.type === "CAMERA") {
CameraAccess.release();
if (source.getScope() === Scope.INTERNAL) {
source.stop();
}
},
applyConfig(newConfig) {

Loading…
Cancel
Save