@zappar/zappar-cv 0.4.0-beta.4 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +91 -34
- package/README.md +2 -2
- package/lib/additional.d.ts +2 -1
- package/lib/additional.js +1 -2
- package/lib/camera-source-map.d.ts +10 -0
- package/lib/camera-source-map.js +32 -0
- package/lib/camera-source.d.ts +2 -5
- package/lib/camera-source.js +18 -32
- package/lib/cameramodel.js +18 -23
- package/lib/compatibility.js +2 -4
- package/lib/deserializer.js +1 -5
- package/lib/direct.js +12 -16
- package/lib/drawcamera.js +27 -31
- package/lib/drawface.js +5 -9
- package/lib/drawfaceproject.js +5 -9
- package/lib/drawplane.js +6 -11
- package/lib/event.js +5 -13
- package/lib/facelandmark.d.ts +1 -2
- package/lib/facelandmark.js +11 -18
- package/lib/facelandmarkdata.js +1 -4
- package/lib/facelandmarkinterface.js +1 -2
- package/lib/facemesh.js +10 -17
- package/lib/gen/zappar-client.js +11 -25
- package/lib/gen/zappar-cwrap.js +38 -33
- package/lib/gen/zappar-native.d.ts +11 -1
- package/lib/gen/zappar-native.js +20 -11
- package/lib/gen/zappar-server.js +6 -14
- package/lib/gen/zappar.d.ts +12 -0
- package/lib/gen/zappar.js +5 -11
- package/lib/gfx.d.ts +1 -0
- package/lib/gfx.js +1 -0
- package/lib/gl-state-manager.d.ts +9 -0
- package/lib/gl-state-manager.js +31 -0
- package/lib/html-element-source.d.ts +3 -20
- package/lib/html-element-source.js +39 -287
- package/lib/image-process-gl.d.ts +37 -0
- package/lib/image-process-gl.js +306 -0
- package/lib/imagebitmap-camera-source.d.ts +36 -0
- package/lib/imagebitmap-camera-source.js +273 -0
- package/lib/imagetracker.d.ts +28 -0
- package/lib/imagetracker.js +115 -0
- package/lib/index-standalone.d.ts +3 -0
- package/lib/index-standalone.js +5 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -27
- package/lib/landmarkdatagenerate.js +25 -30
- package/lib/loglevel.js +9 -16
- package/lib/messages.js +4 -8
- package/lib/mstp-camera-source.d.ts +29 -0
- package/lib/mstp-camera-source.js +226 -0
- package/lib/native.d.ts +2 -1
- package/lib/native.js +229 -130
- package/lib/options.d.ts +3 -0
- package/lib/options.js +1 -0
- package/lib/permission.js +13 -27
- package/lib/pipeline.d.ts +14 -5
- package/lib/pipeline.js +125 -61
- package/lib/profile.d.ts +2 -0
- package/lib/profile.js +59 -53
- package/lib/riff-reader.d.ts +18 -0
- package/lib/riff-reader.js +52 -0
- package/lib/sequencerecorder.d.ts +1 -0
- package/lib/sequencerecorder.js +17 -11
- package/lib/sequencesource.d.ts +7 -1
- package/lib/sequencesource.js +102 -64
- package/lib/serializer.js +1 -5
- package/lib/shader.js +2 -7
- package/lib/source.d.ts +6 -4
- package/lib/source.js +1 -5
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -4
- package/lib/worker-client.d.ts +1 -1
- package/lib/worker-client.js +9 -26
- package/lib/worker-imagebitmap.d.ts +5 -0
- package/lib/worker-imagebitmap.js +59 -0
- package/lib/worker-server.d.ts +0 -5
- package/lib/worker-server.js +133 -41
- package/lib/worker.js +6 -10
- package/lib/workerinterface.d.ts +47 -1
- package/lib/workerinterface.js +1 -2
- package/lib/zcv.js +117 -135
- package/lib/zcv.wasm +0 -0
- package/package.json +33 -32
- package/umd/169.zappar-cv.js +1 -0
- package/umd/{482727c0e7dd40d73f5aae47f238ad61.zbin → 482727c0e7dd40d73f5a.zbin} +0 -0
- package/umd/6a8309f88f836a752c68.wasm +0 -0
- package/umd/752.zappar-cv.js +1 -0
- package/umd/{b4f46e148a3b3b5aef90717d8d60e3fc.zbin → b4f46e148a3b3b5aef90.zbin} +0 -0
- package/umd/{f7b62a3a53b5c9b3222ba8dc53cb8b11.zbin → f7b62a3a53b5c9b3222b.zbin} +0 -0
- package/umd/zappar-cv.js +1 -9
- package/umd/zappar-cv.worker.js +1 -1
- package/lib/bundleworker-mainthread.d.ts +0 -2
- package/lib/bundleworker-mainthread.js +0 -36
- package/lib/bundleworker-worker.d.ts +0 -6
- package/lib/bundleworker-worker.js +0 -34
- package/lib/zcv-slam.js +0 -16
- package/lib/zcv-slam.wasm +0 -0
- package/umd/1ec038c18c27f4adf35917a8175401f0.wasm +0 -0
- package/umd/9c0b0dcf514b48c05541.bundleworker.js +0 -1
- package/umd/d115e485cffe500afc4f7c1272ea8f62.wasm +0 -0
package/lib/permission.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,10 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const ua_parser_js_1 = require("ua-parser-js");
|
|
14
|
-
let parser = new ua_parser_js_1.UAParser();
|
|
10
|
+
import { UAParser } from "ua-parser-js";
|
|
11
|
+
let parser = new UAParser();
|
|
15
12
|
let _permissionGrantedCamera = false;
|
|
16
13
|
let _permissionGrantedMotion = false;
|
|
17
14
|
let _permissionDeniedCamera = false;
|
|
@@ -32,26 +29,19 @@ function checkForCameraPermission() {
|
|
|
32
29
|
});
|
|
33
30
|
}
|
|
34
31
|
checkForCameraPermission();
|
|
35
|
-
function permissionGrantedCamera() { return _permissionGrantedCamera; }
|
|
36
|
-
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
function
|
|
42
|
-
exports.permissionDeniedMotion = permissionDeniedMotion;
|
|
43
|
-
function permissionDeniedAny() { return _permissionDeniedCamera || _permissionDeniedMotion; }
|
|
44
|
-
exports.permissionDeniedAny = permissionDeniedAny;
|
|
45
|
-
function permissionGrantedAll() { return _permissionGrantedCamera && _permissionGrantedMotion; }
|
|
46
|
-
exports.permissionGrantedAll = permissionGrantedAll;
|
|
47
|
-
function permissionRequestAll() {
|
|
32
|
+
export function permissionGrantedCamera() { return _permissionGrantedCamera; }
|
|
33
|
+
export function permissionGrantedMotion() { return _permissionGrantedMotion; }
|
|
34
|
+
export function permissionDeniedCamera() { return _permissionDeniedCamera; }
|
|
35
|
+
export function permissionDeniedMotion() { return _permissionDeniedMotion; }
|
|
36
|
+
export function permissionDeniedAny() { return _permissionDeniedCamera || _permissionDeniedMotion; }
|
|
37
|
+
export function permissionGrantedAll() { return _permissionGrantedCamera && _permissionGrantedMotion; }
|
|
38
|
+
export function permissionRequestAll() {
|
|
48
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
40
|
yield permissionRequestMotion();
|
|
50
41
|
yield permissionRequestCamera();
|
|
51
42
|
});
|
|
52
43
|
}
|
|
53
|
-
|
|
54
|
-
function permissionRequestCamera() {
|
|
44
|
+
export function permissionRequestCamera() {
|
|
55
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
46
|
try {
|
|
57
47
|
let res = yield navigator.mediaDevices.getUserMedia({
|
|
@@ -68,8 +58,7 @@ function permissionRequestCamera() {
|
|
|
68
58
|
}
|
|
69
59
|
});
|
|
70
60
|
}
|
|
71
|
-
|
|
72
|
-
function permissionRequestMotion() {
|
|
61
|
+
export function permissionRequestMotion() {
|
|
73
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
63
|
if (window.DeviceOrientationEvent && window.DeviceOrientationEvent.requestPermission) {
|
|
75
64
|
let permissionResult = yield window.DeviceOrientationEvent.requestPermission();
|
|
@@ -84,8 +73,7 @@ function permissionRequestMotion() {
|
|
|
84
73
|
_permissionDeniedMotion = false;
|
|
85
74
|
});
|
|
86
75
|
}
|
|
87
|
-
|
|
88
|
-
function permissionRequestUI() {
|
|
76
|
+
export function permissionRequestUI() {
|
|
89
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
78
|
yield checkForCameraPermission();
|
|
91
79
|
if (permissionGrantedAll()) {
|
|
@@ -158,11 +146,10 @@ function permissionRequestUI() {
|
|
|
158
146
|
});
|
|
159
147
|
});
|
|
160
148
|
}
|
|
161
|
-
exports.permissionRequestUI = permissionRequestUI;
|
|
162
149
|
function nextFrame() {
|
|
163
150
|
return new Promise(resolve => requestAnimationFrame(() => resolve()));
|
|
164
151
|
}
|
|
165
|
-
function permissionDeniedUI() {
|
|
152
|
+
export function permissionDeniedUI() {
|
|
166
153
|
switch (parser.getBrowser().name) {
|
|
167
154
|
case "Chrome":
|
|
168
155
|
permissionDeniedUIChrome();
|
|
@@ -172,7 +159,6 @@ function permissionDeniedUI() {
|
|
|
172
159
|
break;
|
|
173
160
|
}
|
|
174
161
|
}
|
|
175
|
-
exports.permissionDeniedUI = permissionDeniedUI;
|
|
176
162
|
function permissionDeniedUIIOS() {
|
|
177
163
|
let div = document.createElement("div");
|
|
178
164
|
div.classList.add("zappar-permission-request");
|
package/lib/pipeline.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="dom-webcodecs" />
|
|
2
|
+
import { zappar_pipeline_t, zappar_camera_source_t } from "./gen/zappar";
|
|
2
3
|
import { zappar_cwrap } from "./gen/zappar-native";
|
|
3
4
|
import { zappar_client } from "./gen/zappar-client";
|
|
4
5
|
import { MsgManager } from "./messages";
|
|
5
|
-
import { mat4 } from "gl-matrix";
|
|
6
6
|
import { Source, CameraFrameInfo } from "./source";
|
|
7
|
-
import { CameraFrameReturnS2C } from "./workerinterface";
|
|
7
|
+
import { CameraFrameReturnS2C, ImageBitmapS2C, VideoFrameS2C } from "./workerinterface";
|
|
8
8
|
import { FaceMesh } from "./facemesh";
|
|
9
9
|
import { Event } from "./event";
|
|
10
10
|
export declare class Pipeline {
|
|
@@ -24,11 +24,13 @@ export declare class Pipeline {
|
|
|
24
24
|
private _faceProjectDraw;
|
|
25
25
|
private _sequenceRecorder;
|
|
26
26
|
private _sequenceRecordDeviceAttitudeMatrices;
|
|
27
|
+
private _sequenceRecorderFirstCameraToken;
|
|
27
28
|
onGLContextReset: Event;
|
|
28
29
|
static create(client: zappar_cwrap, mgr: MsgManager): zappar_pipeline_t;
|
|
29
30
|
static get(p: zappar_pipeline_t): Pipeline | undefined;
|
|
30
31
|
private constructor();
|
|
31
32
|
frameUpdate(client: zappar_client): void;
|
|
33
|
+
cleanOldFrames(): void;
|
|
32
34
|
cameraTokenReturn(msg: CameraFrameReturnS2C): void;
|
|
33
35
|
sequenceRecordStart(expectedFrames: number): void;
|
|
34
36
|
sequenceRecordStop(): void;
|
|
@@ -47,11 +49,18 @@ export declare class Pipeline {
|
|
|
47
49
|
cameraFrameTextureMatrix(sw: number, sh: number, mirror: boolean): Float32Array;
|
|
48
50
|
cameraFrameUserFacing(): boolean;
|
|
49
51
|
cameraPoseWithAttitude(mirror: boolean): Float32Array;
|
|
52
|
+
videoFrameFromWorker(msg: VideoFrameS2C): void;
|
|
53
|
+
imageBitmapFromWorker(msg: ImageBitmapS2C): void;
|
|
54
|
+
uploadGL(): void;
|
|
55
|
+
registerToken(info: CameraFrameInfo): number;
|
|
50
56
|
processGL(): void;
|
|
51
57
|
motionAccelerometerSubmit(timestamp: number, x: number, y: number, z: number): void;
|
|
52
58
|
motionRotationRateSubmit(timestamp: number, x: number, y: number, z: number): void;
|
|
53
59
|
motionAttitudeSubmit(timestamp: number, x: number, y: number, z: number): void;
|
|
54
60
|
motionAttitudeMatrix(m: Float32Array): void;
|
|
55
|
-
|
|
61
|
+
sendCameraStreamToWorker(source: zappar_camera_source_t, stream: ReadableStream<VideoFrame>, userFacing: boolean): void;
|
|
62
|
+
sendCameraToScreenRotationToWorker(rot: number): void;
|
|
63
|
+
sendImageBitmapToWorker(img: ImageBitmap, rot: number, userFacing: boolean, tokenId: number, cameraModel: Float32Array, cameraToDevice: Float32Array): void;
|
|
64
|
+
sendDataToWorker(data: ArrayBuffer, token: number, width: number, height: number, userFacing: boolean, cameraToDevice: Float32Array, cameraModel: Float32Array): void;
|
|
56
65
|
}
|
|
57
|
-
export declare function applyScreenCounterRotation(info: CameraFrameInfo | undefined, inp: Float32Array):
|
|
66
|
+
export declare function applyScreenCounterRotation(info: CameraFrameInfo | undefined, inp: Float32Array): Float32Array;
|
package/lib/pipeline.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const loglevel_1 = require("./loglevel");
|
|
12
|
-
const sequencerecorder_1 = require("./sequencerecorder");
|
|
1
|
+
import { cameraFrameTextureMatrix, CameraDraw } from "./drawcamera";
|
|
2
|
+
import { mat4 } from "gl-matrix";
|
|
3
|
+
import { cameraRotationForScreenOrientation } from "./cameramodel";
|
|
4
|
+
import { FaceDraw } from "./drawface";
|
|
5
|
+
import { FaceDrawProject } from "./drawfaceproject";
|
|
6
|
+
import { disposeDrawPlane } from "./drawplane";
|
|
7
|
+
import { Event } from "./event";
|
|
8
|
+
import { zcerr } from "./loglevel";
|
|
9
|
+
import { SequenceRecorder } from "./sequencerecorder";
|
|
10
|
+
import { getCameraSource } from "./camera-source-map";
|
|
13
11
|
let byId = new Map();
|
|
14
|
-
|
|
12
|
+
let identity = mat4.create();
|
|
13
|
+
export class Pipeline {
|
|
15
14
|
constructor(_client, _impl, _mgr) {
|
|
16
15
|
this._client = _client;
|
|
17
16
|
this._impl = _impl;
|
|
@@ -23,7 +22,8 @@ class Pipeline {
|
|
|
23
22
|
this.videoTextures = [];
|
|
24
23
|
this.cameraPixelArrays = [];
|
|
25
24
|
this._sequenceRecordDeviceAttitudeMatrices = true;
|
|
26
|
-
this.
|
|
25
|
+
this._sequenceRecorderFirstCameraToken = 0;
|
|
26
|
+
this.onGLContextReset = new Event();
|
|
27
27
|
}
|
|
28
28
|
static create(client, mgr) {
|
|
29
29
|
let ret = client.pipeline_create();
|
|
@@ -43,6 +43,10 @@ class Pipeline {
|
|
|
43
43
|
}, [msg]);
|
|
44
44
|
}
|
|
45
45
|
this.pendingMessages = [];
|
|
46
|
+
this.cleanOldFrames();
|
|
47
|
+
}
|
|
48
|
+
cleanOldFrames() {
|
|
49
|
+
var _a, _b;
|
|
46
50
|
let currentToken = this._client.pipeline_camera_frame_user_data(this._impl);
|
|
47
51
|
if (!currentToken)
|
|
48
52
|
return;
|
|
@@ -50,12 +54,14 @@ class Pipeline {
|
|
|
50
54
|
if (t[0] < currentToken) {
|
|
51
55
|
if (t[1].texture)
|
|
52
56
|
this.videoTextures.push(t[1].texture);
|
|
57
|
+
(_b = (_a = t[1].frame) === null || _a === void 0 ? void 0 : _a.close) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
53
58
|
this.cameraTokens.delete(t[0]);
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
61
|
}
|
|
57
62
|
cameraTokenReturn(msg) {
|
|
58
|
-
if (this._sequenceRecorder && this._sequenceRecordDeviceAttitudeMatrices
|
|
63
|
+
if (this._sequenceRecorder && this._sequenceRecordDeviceAttitudeMatrices
|
|
64
|
+
&& msg.token >= this._sequenceRecorderFirstCameraToken) {
|
|
59
65
|
let info = this.cameraTokens.get(msg.token);
|
|
60
66
|
if (info) {
|
|
61
67
|
if (msg.att)
|
|
@@ -69,8 +75,9 @@ class Pipeline {
|
|
|
69
75
|
}
|
|
70
76
|
sequenceRecordStart(expectedFrames) {
|
|
71
77
|
if (!this._sequenceRecorder)
|
|
72
|
-
this._sequenceRecorder = new
|
|
78
|
+
this._sequenceRecorder = new SequenceRecorder(expectedFrames);
|
|
73
79
|
this._sequenceRecorder.start();
|
|
80
|
+
this._sequenceRecorderFirstCameraToken = this.nextCameraToken;
|
|
74
81
|
}
|
|
75
82
|
sequenceRecordStop() {
|
|
76
83
|
var _a;
|
|
@@ -106,7 +113,7 @@ class Pipeline {
|
|
|
106
113
|
if (!token)
|
|
107
114
|
return;
|
|
108
115
|
if (!this._cameraDraw)
|
|
109
|
-
this._cameraDraw = new
|
|
116
|
+
this._cameraDraw = new CameraDraw(this.glContext);
|
|
110
117
|
this._cameraDraw.drawCameraFrame(screenWidth, screenHeight, token, mirror === true);
|
|
111
118
|
}
|
|
112
119
|
glContextLost() {
|
|
@@ -119,7 +126,7 @@ class Pipeline {
|
|
|
119
126
|
delete this._cameraDraw;
|
|
120
127
|
delete this._faceDraw;
|
|
121
128
|
delete this._faceProjectDraw;
|
|
122
|
-
|
|
129
|
+
disposeDrawPlane();
|
|
123
130
|
this.onGLContextReset.emit();
|
|
124
131
|
for (let tex of this.videoTextures) {
|
|
125
132
|
if (this.glContext)
|
|
@@ -153,17 +160,17 @@ class Pipeline {
|
|
|
153
160
|
if (!this.glContext)
|
|
154
161
|
return;
|
|
155
162
|
if (!this._faceDraw)
|
|
156
|
-
this._faceDraw = new
|
|
157
|
-
let mat =
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
this._faceDraw = new FaceDraw(this.glContext);
|
|
164
|
+
let mat = mat4.create();
|
|
165
|
+
mat4.multiply(mat, projectionMatrix, cameraMatrix);
|
|
166
|
+
mat4.multiply(mat, mat, targetMatrix);
|
|
160
167
|
this._faceDraw.drawFace(mat, o);
|
|
161
168
|
}
|
|
162
169
|
drawFaceProject(matrix, vertices, uvMatrix, uvs, indices, texture) {
|
|
163
170
|
if (!this.glContext)
|
|
164
171
|
return;
|
|
165
172
|
if (!this._faceProjectDraw)
|
|
166
|
-
this._faceProjectDraw = new
|
|
173
|
+
this._faceProjectDraw = new FaceDrawProject(this.glContext);
|
|
167
174
|
this._faceProjectDraw.drawFace(matrix, vertices, uvMatrix, uvs, indices, texture);
|
|
168
175
|
}
|
|
169
176
|
cameraFrameTexture() {
|
|
@@ -173,8 +180,8 @@ class Pipeline {
|
|
|
173
180
|
cameraFrameTextureMatrix(sw, sh, mirror) {
|
|
174
181
|
let info = this.getCurrentCameraInfo();
|
|
175
182
|
if (!info)
|
|
176
|
-
return
|
|
177
|
-
return
|
|
183
|
+
return mat4.create();
|
|
184
|
+
return cameraFrameTextureMatrix(info.dataWidth, info.dataHeight, sw, sh, info.uvTransform || identity, mirror);
|
|
178
185
|
}
|
|
179
186
|
cameraFrameUserFacing() {
|
|
180
187
|
var _a;
|
|
@@ -183,18 +190,58 @@ class Pipeline {
|
|
|
183
190
|
cameraPoseWithAttitude(mirror) {
|
|
184
191
|
let res = applyScreenCounterRotation(this.getCurrentCameraInfo(), this._client.pipeline_camera_frame_camera_attitude(this._impl));
|
|
185
192
|
if (mirror) {
|
|
186
|
-
let scale =
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
193
|
+
let scale = mat4.create();
|
|
194
|
+
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
195
|
+
mat4.multiply(res, scale, res);
|
|
196
|
+
mat4.multiply(res, res, scale);
|
|
190
197
|
}
|
|
191
|
-
|
|
198
|
+
mat4.invert(res, res);
|
|
192
199
|
return res;
|
|
193
200
|
}
|
|
201
|
+
videoFrameFromWorker(msg) {
|
|
202
|
+
let tokenId = this.nextCameraToken++;
|
|
203
|
+
const cameraSource = getCameraSource(msg.source);
|
|
204
|
+
if (!cameraSource)
|
|
205
|
+
return;
|
|
206
|
+
this.cameraTokens.set(tokenId, {
|
|
207
|
+
dataWidth: msg.w,
|
|
208
|
+
dataHeight: msg.h,
|
|
209
|
+
texture: undefined,
|
|
210
|
+
frame: msg.d,
|
|
211
|
+
userFacing: msg.userFacing,
|
|
212
|
+
uvTransform: msg.uvTransform,
|
|
213
|
+
cameraModel: msg.cameraModel,
|
|
214
|
+
cameraToDevice: msg.cameraToDevice,
|
|
215
|
+
cameraSource
|
|
216
|
+
});
|
|
217
|
+
this.cleanOldFrames();
|
|
218
|
+
}
|
|
219
|
+
imageBitmapFromWorker(msg) {
|
|
220
|
+
let data = this.cameraTokens.get(msg.tokenId);
|
|
221
|
+
if (!data)
|
|
222
|
+
return;
|
|
223
|
+
data.dataWidth = msg.dataWidth;
|
|
224
|
+
data.dataHeight = msg.dataHeight;
|
|
225
|
+
data.frame = msg.frame;
|
|
226
|
+
data.userFacing = msg.userFacing;
|
|
227
|
+
data.uvTransform = msg.uvTransform;
|
|
228
|
+
this.tokensInFlight--;
|
|
229
|
+
this.cleanOldFrames();
|
|
230
|
+
}
|
|
231
|
+
uploadGL() {
|
|
232
|
+
var _a, _b;
|
|
233
|
+
let info = this.getCurrentCameraInfo();
|
|
234
|
+
(_b = (_a = info === null || info === void 0 ? void 0 : info.cameraSource) === null || _a === void 0 ? void 0 : _a.uploadGL) === null || _b === void 0 ? void 0 : _b.call(_a, info);
|
|
235
|
+
}
|
|
236
|
+
registerToken(info) {
|
|
237
|
+
let tokenId = this.nextCameraToken++;
|
|
238
|
+
this.cameraTokens.set(tokenId, info);
|
|
239
|
+
this.tokensInFlight++;
|
|
240
|
+
return tokenId;
|
|
241
|
+
}
|
|
194
242
|
processGL() {
|
|
195
|
-
var _a;
|
|
196
243
|
if (!this.glContext) {
|
|
197
|
-
|
|
244
|
+
zcerr("no GL context for camera frames - please call pipeline_gl_context_set");
|
|
198
245
|
return;
|
|
199
246
|
}
|
|
200
247
|
if (!this.currentCameraSource)
|
|
@@ -203,26 +250,7 @@ class Pipeline {
|
|
|
203
250
|
this.currentCameraSource.getFrame(true);
|
|
204
251
|
return;
|
|
205
252
|
}
|
|
206
|
-
|
|
207
|
-
if (!info)
|
|
208
|
-
return;
|
|
209
|
-
let tokenId = this.nextCameraToken++;
|
|
210
|
-
this.cameraTokens.set(tokenId, info);
|
|
211
|
-
let msg = {
|
|
212
|
-
d: info.data,
|
|
213
|
-
p: this._impl,
|
|
214
|
-
width: info.dataWidth,
|
|
215
|
-
height: info.dataHeight,
|
|
216
|
-
token: tokenId,
|
|
217
|
-
userFacing: info.userFacing,
|
|
218
|
-
c2d: info.cameraToDevice,
|
|
219
|
-
cm: info.cameraModel,
|
|
220
|
-
t: "cameraFrameC2S"
|
|
221
|
-
};
|
|
222
|
-
if (!this._sequenceRecordDeviceAttitudeMatrices)
|
|
223
|
-
(_a = this._sequenceRecorder) === null || _a === void 0 ? void 0 : _a.appendCameraFrame(info);
|
|
224
|
-
this.tokensInFlight++;
|
|
225
|
-
this._mgr.postOutgoingMessage(msg, [info.data]);
|
|
253
|
+
this.currentCameraSource.getFrame(false);
|
|
226
254
|
}
|
|
227
255
|
motionAccelerometerSubmit(timestamp, x, y, z) {
|
|
228
256
|
var _a;
|
|
@@ -246,18 +274,54 @@ class Pipeline {
|
|
|
246
274
|
// This doesn't need to be added to the sequence since that's done on frame update instead
|
|
247
275
|
this._client.pipeline_motion_attitude_matrix_submit(this._impl, m);
|
|
248
276
|
}
|
|
249
|
-
|
|
250
|
-
let
|
|
251
|
-
|
|
277
|
+
sendCameraStreamToWorker(source, stream, userFacing) {
|
|
278
|
+
let msg = {
|
|
279
|
+
t: "streamC2S",
|
|
280
|
+
p: this._impl,
|
|
281
|
+
s: stream,
|
|
282
|
+
userFacing,
|
|
283
|
+
source
|
|
284
|
+
};
|
|
285
|
+
this._mgr.postOutgoingMessage(msg, [msg.s]);
|
|
286
|
+
}
|
|
287
|
+
sendCameraToScreenRotationToWorker(rot) {
|
|
288
|
+
let msg = {
|
|
289
|
+
p: this._impl,
|
|
290
|
+
t: "cameraToScreenC2S",
|
|
291
|
+
r: rot
|
|
292
|
+
};
|
|
293
|
+
this._mgr.postOutgoingMessage(msg, []);
|
|
294
|
+
}
|
|
295
|
+
sendImageBitmapToWorker(img, rot, userFacing, tokenId, cameraModel, cameraToDevice) {
|
|
296
|
+
let msg = {
|
|
297
|
+
p: this._impl,
|
|
298
|
+
t: "imageBitmapC2S",
|
|
299
|
+
i: img,
|
|
300
|
+
r: rot,
|
|
301
|
+
tokenId,
|
|
302
|
+
userFacing,
|
|
303
|
+
cameraModel,
|
|
304
|
+
cameraToDevice
|
|
305
|
+
};
|
|
306
|
+
this._mgr.postOutgoingMessage(msg, [img]);
|
|
307
|
+
}
|
|
308
|
+
sendDataToWorker(data, token, width, height, userFacing, cameraToDevice, cameraModel) {
|
|
309
|
+
let msg = {
|
|
310
|
+
d: data,
|
|
311
|
+
p: this._impl,
|
|
312
|
+
width, height, token, userFacing,
|
|
313
|
+
c2d: cameraToDevice,
|
|
314
|
+
cm: cameraModel,
|
|
315
|
+
t: "cameraFrameC2S"
|
|
316
|
+
};
|
|
317
|
+
this._mgr.postOutgoingMessage(msg, [data]);
|
|
252
318
|
}
|
|
253
319
|
}
|
|
254
|
-
|
|
255
|
-
function applyScreenCounterRotation(info, inp) {
|
|
320
|
+
export function applyScreenCounterRotation(info, inp) {
|
|
256
321
|
let userFacing = false;
|
|
257
322
|
userFacing = info ? info.userFacing : false;
|
|
258
|
-
let mult =
|
|
259
|
-
|
|
260
|
-
|
|
323
|
+
let mult = mat4.create();
|
|
324
|
+
mat4.fromRotation(mult, cameraRotationForScreenOrientation(userFacing) * Math.PI / 180.0, [0, 0, 1]);
|
|
325
|
+
mat4.multiply(mult, mult, inp);
|
|
261
326
|
return mult;
|
|
262
327
|
}
|
|
263
|
-
exports.applyScreenCounterRotation = applyScreenCounterRotation;
|
package/lib/profile.d.ts
CHANGED
package/lib/profile.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.profile = exports.EmbeddedVideoImplementation = void 0;
|
|
4
|
-
const UAParser = require("ua-parser-js");
|
|
5
|
-
var EmbeddedVideoImplementation;
|
|
1
|
+
import * as UAParser from "ua-parser-js";
|
|
2
|
+
export var EmbeddedVideoImplementation;
|
|
6
3
|
(function (EmbeddedVideoImplementation) {
|
|
7
4
|
EmbeddedVideoImplementation[EmbeddedVideoImplementation["OBJECT_URL"] = 0] = "OBJECT_URL";
|
|
8
5
|
EmbeddedVideoImplementation[EmbeddedVideoImplementation["SRC_OBJECT"] = 1] = "SRC_OBJECT";
|
|
9
|
-
})(EmbeddedVideoImplementation
|
|
10
|
-
|
|
6
|
+
})(EmbeddedVideoImplementation || (EmbeddedVideoImplementation = {}));
|
|
7
|
+
export let profile = {
|
|
11
8
|
deviceMotionMutliplier: -1.0,
|
|
12
9
|
blacklisted: false,
|
|
13
10
|
showGyroPermissionsWarningIfNecessary: false,
|
|
@@ -17,56 +14,65 @@ exports.profile = {
|
|
|
17
14
|
videoHeight: 480,
|
|
18
15
|
dataWidth: 320,
|
|
19
16
|
dataHeight: 240,
|
|
20
|
-
videoElementInDOM: false
|
|
17
|
+
videoElementInDOM: false,
|
|
18
|
+
preferMediaStreamTrackProcessorCamera: false,
|
|
19
|
+
preferImageBitmapCamera: false
|
|
21
20
|
};
|
|
22
|
-
window
|
|
21
|
+
if (typeof window !== "undefined") {
|
|
22
|
+
window["zeeProfile"] = profile;
|
|
23
|
+
if (window.location.href.indexOf("_mstppipeline") >= 0) {
|
|
24
|
+
console.log("Configuring for MSTP camera pipeline (if supported)");
|
|
25
|
+
profile.preferMediaStreamTrackProcessorCamera = true;
|
|
26
|
+
}
|
|
27
|
+
if (window.location.href.indexOf("_imagebitmappipeline") >= 0) {
|
|
28
|
+
console.log("Configuring for ImageBitmap camera pipeline (if supported)");
|
|
29
|
+
profile.preferImageBitmapCamera = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
23
32
|
let agent = new UAParser.UAParser();
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
let os = (agent.getOS().name || "unknown").toLowerCase();
|
|
34
|
+
let engine = (agent.getEngine().name || "unknown").toLowerCase();
|
|
35
|
+
if (engine === "webkit" && os !== "ios") {
|
|
36
|
+
profile.deviceMotionMutliplier = 1.0;
|
|
37
|
+
if (typeof window !== "undefined" && window.orientation !== undefined) {
|
|
38
|
+
// iPad
|
|
39
|
+
iDevice("15.0");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (engine === "webkit" && os === "ios") {
|
|
43
|
+
profile.deviceMotionMutliplier = 1.0;
|
|
44
|
+
const version = agent.getOS().version || "15.0";
|
|
45
|
+
iDevice(version);
|
|
46
|
+
}
|
|
47
|
+
function iDevice(version) {
|
|
48
|
+
let versionParts = version.split(".");
|
|
49
|
+
if (versionParts.length >= 2) {
|
|
50
|
+
const majorVersion = parseInt(versionParts[0]);
|
|
51
|
+
const minorVersion = parseInt(versionParts[1]);
|
|
52
|
+
if (majorVersion < 11 ||
|
|
53
|
+
(majorVersion === 11 && minorVersion < 3)) {
|
|
54
|
+
profile.blacklisted = true;
|
|
55
|
+
}
|
|
56
|
+
if (majorVersion < 12 ||
|
|
57
|
+
(majorVersion === 12 && minorVersion < 2)) {
|
|
58
|
+
profile.videoElementInDOM = true;
|
|
30
59
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
let engine = agent.getEngine();
|
|
36
|
-
if (!engine || engine.name !== "WebKit") {
|
|
37
|
-
break;
|
|
60
|
+
if ((majorVersion === 12 && minorVersion >= 2) || (majorVersion >= 13))
|
|
61
|
+
profile.showGyroPermissionsWarningIfNecessary = true;
|
|
62
|
+
if (majorVersion >= 13) {
|
|
63
|
+
profile.showSafariPermissionsResetIfNecessary = true;
|
|
38
64
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
exports.profile.blacklisted = true;
|
|
50
|
-
}
|
|
51
|
-
if (majorVersion < 12 ||
|
|
52
|
-
(majorVersion === 12 && minorVersion < 2)) {
|
|
53
|
-
exports.profile.videoElementInDOM = true;
|
|
54
|
-
}
|
|
55
|
-
if ((majorVersion === 12 && minorVersion >= 2) || (majorVersion >= 13))
|
|
56
|
-
exports.profile.showGyroPermissionsWarningIfNecessary = true;
|
|
57
|
-
if (majorVersion >= 13) {
|
|
58
|
-
exports.profile.showSafariPermissionsResetIfNecessary = true;
|
|
59
|
-
}
|
|
60
|
-
if (((majorVersion >= 12 && minorVersion > 1) || (majorVersion >= 13)) &&
|
|
61
|
-
navigator.mediaDevices &&
|
|
62
|
-
navigator.mediaDevices.getSupportedConstraints &&
|
|
63
|
-
navigator.mediaDevices.getSupportedConstraints().frameRate) {
|
|
64
|
-
exports.profile.requestHighFrameRate = true;
|
|
65
|
-
// Avoid bug where iOS letterboxes 16:9 into 4:3 for high fps
|
|
66
|
-
exports.profile.videoHeight = 360;
|
|
67
|
-
exports.profile.dataHeight = 180;
|
|
68
|
-
}
|
|
65
|
+
if (((majorVersion >= 12 && minorVersion > 1) || (majorVersion >= 13)) &&
|
|
66
|
+
navigator.mediaDevices &&
|
|
67
|
+
navigator.mediaDevices.getSupportedConstraints &&
|
|
68
|
+
navigator.mediaDevices.getSupportedConstraints().frameRate) {
|
|
69
|
+
profile.requestHighFrameRate = true;
|
|
70
|
+
if (majorVersion < 14) {
|
|
71
|
+
// Avoid bug where iOS letterboxes 16:9 into 4:3 for high fps
|
|
72
|
+
// Doesn't seem needed with newer versions of iOS, tested on 14.8.1 and 15.2
|
|
73
|
+
profile.videoHeight = 360;
|
|
74
|
+
profile.dataHeight = 180;
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
|
-
|
|
77
|
+
}
|
|
72
78
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface Chunk {
|
|
2
|
+
ident: string;
|
|
3
|
+
data: Uint8Array;
|
|
4
|
+
subident?: string;
|
|
5
|
+
subchunks?: Chunk[];
|
|
6
|
+
}
|
|
7
|
+
export declare class RiffReader {
|
|
8
|
+
private _data;
|
|
9
|
+
private _paddingBytes;
|
|
10
|
+
truncatedChunks: boolean;
|
|
11
|
+
private _view;
|
|
12
|
+
root: Chunk;
|
|
13
|
+
constructor(_data: ArrayBuffer, _paddingBytes?: boolean);
|
|
14
|
+
private _parse;
|
|
15
|
+
private _parseChunk;
|
|
16
|
+
find(str: string, inChunk?: Chunk): Chunk | undefined;
|
|
17
|
+
has(str: string): boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const decoder = new TextDecoder();
|
|
2
|
+
export class RiffReader {
|
|
3
|
+
constructor(_data, _paddingBytes = false) {
|
|
4
|
+
this._data = _data;
|
|
5
|
+
this._paddingBytes = _paddingBytes;
|
|
6
|
+
this.truncatedChunks = false;
|
|
7
|
+
this._view = new DataView(this._data);
|
|
8
|
+
this.root = this._parse();
|
|
9
|
+
}
|
|
10
|
+
_parse() {
|
|
11
|
+
const header = decoder.decode(this._data.slice(0, 4));
|
|
12
|
+
if (header !== "RIFF")
|
|
13
|
+
throw new Error("Not a valid ZPT file");
|
|
14
|
+
return this._parseChunk(0);
|
|
15
|
+
}
|
|
16
|
+
_parseChunk(offset) {
|
|
17
|
+
const ident = decoder.decode(this._data.slice(offset, offset + 4));
|
|
18
|
+
const length = this._view.getUint32(offset + 4, true);
|
|
19
|
+
const data = new Uint8Array(this._data, offset + 8, length);
|
|
20
|
+
if (data.byteLength !== length)
|
|
21
|
+
this.truncatedChunks = true;
|
|
22
|
+
let subchunks;
|
|
23
|
+
let subident;
|
|
24
|
+
if (ident === "RIFF" || ident === "LIST") {
|
|
25
|
+
subident = decoder.decode(this._data.slice(offset + 8, offset + 12));
|
|
26
|
+
subchunks = [];
|
|
27
|
+
let currentOffset = 4;
|
|
28
|
+
while (currentOffset < data.byteLength - 1) {
|
|
29
|
+
const subchunk = this._parseChunk(offset + 8 + currentOffset);
|
|
30
|
+
subchunks.push(subchunk);
|
|
31
|
+
currentOffset += subchunk.data.byteLength + 8;
|
|
32
|
+
if (this._paddingBytes && subchunk.data.byteLength & 0x1)
|
|
33
|
+
currentOffset++;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { ident, data, subident, subchunks };
|
|
37
|
+
}
|
|
38
|
+
find(str, inChunk = this.root) {
|
|
39
|
+
if (inChunk.ident === str)
|
|
40
|
+
return inChunk;
|
|
41
|
+
if (!inChunk.subchunks)
|
|
42
|
+
return;
|
|
43
|
+
for (let c of inChunk.subchunks) {
|
|
44
|
+
const found = this.find(str, c);
|
|
45
|
+
if (found)
|
|
46
|
+
return found;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
has(str) {
|
|
50
|
+
return this.find(str) !== undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|