@depz/camera-sdk 0.0.0-stage → 0.3.1

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.
@@ -0,0 +1,64 @@
1
+ import { type NativeHandle } from "./native";
2
+ /** What recalibration does while a pipeline runs (the reference's RecalibrationMode). */
3
+ export type RecalibrationMode = "continuous" | "manual" | "off";
4
+ /** Every recalibration mode. */
5
+ export declare const RECALIBRATION_MODES: readonly RecalibrationMode[];
6
+ /** The terms of a correction (CORRECTION_TERMS). */
7
+ export type CorrectionTerm = "pitch" | "roll" | "yaw" | "ty";
8
+ /** The four terms of a correction. */
9
+ export declare const CORRECTION_TERMS: readonly CorrectionTerm[];
10
+ export declare function recalibrationModeValue(mode: RecalibrationMode | null): number;
11
+ export declare function termBits(terms: Iterable<CorrectionTerm>): number;
12
+ export declare function checkMode(value: unknown, what: string): RecalibrationMode;
13
+ /** The options of `Settings` (each one optional: its default). */
14
+ export interface SettingsOptions {
15
+ cacheDir?: string | null;
16
+ calibrationWeb?: string;
17
+ correctionStore?: boolean;
18
+ recalibration?: RecalibrationMode | null;
19
+ recalibrationHeldTerms?: Iterable<CorrectionTerm>;
20
+ /** The SDK's log records (c_api.md section 7): level (Python's logging numbers: 10 debug,
21
+ * 20 info, 30 warning, 40 error), the reference's logger ("depz_camera_sdk.pipeline.pipeline")
22
+ * and one English line. Called on the main thread, never waited for; null: silent. */
23
+ log?: LogHandler | null;
24
+ /** The least level handed to log; default 30 (warning). */
25
+ logLevel?: number;
26
+ }
27
+ /** A log handler: (level, logger, message), on the main thread. */
28
+ export type LogHandler = (level: number, logger: string, message: string) => void;
29
+ /** The log levels (Python's logging numbers). */
30
+ export declare const LOG_LEVELS: {
31
+ readonly debug: 10;
32
+ readonly info: 20;
33
+ readonly warning: 30;
34
+ readonly error: 40;
35
+ };
36
+ /** Everything the SDK would otherwise take from its environment (contracts/settings.json). */
37
+ export declare class Settings {
38
+ /** Root of the models and the engines' caches; null: the platform's cache folder. */
39
+ readonly cacheDir: string | null;
40
+ /** Server of the calibration web API; "": never ask the web. */
41
+ readonly calibrationWeb: string;
42
+ /** Read and write the calibration correction in the camera. */
43
+ readonly correctionStore: boolean;
44
+ /** The mode of a pipeline given no RecalibrationConfig; null: continuous for a live camera, off for a recording. */
45
+ readonly recalibration: RecalibrationMode | null;
46
+ /** The terms a pipeline given no RecalibrationConfig may not change. */
47
+ readonly recalibrationHeldTerms: ReadonlySet<CorrectionTerm>;
48
+ /** The log handler; null: silent. */
49
+ readonly log: LogHandler | null;
50
+ /** The least level handed to log. */
51
+ readonly logLevel: number;
52
+ /** The defaults: the platform's cache folder, the depz.ai web copy, the camera's correction store, auto recalibration, no log handler. */
53
+ constructor(options?: SettingsOptions);
54
+ /** The settings an environment gives (default: this process's now); a variable not set leaves its default. */
55
+ static fromEnv(env?: Record<string, string | undefined>): Settings;
56
+ }
57
+ /** Replaces the SDK's settings for the process. */
58
+ export declare function configure(settings: Settings): void;
59
+ /** The SDK's settings now. */
60
+ export declare function currentSettings(): Settings;
61
+ /** The C context of the settings now (made at its first use). Internal. */
62
+ export declare function currentContext(): NativeHandle;
63
+ /** The cache root of the settings now: models in <root>/models, the engines' caches (get_cache_dir). */
64
+ export declare function getCacheDir(): string;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Settings = exports.LOG_LEVELS = exports.CORRECTION_TERMS = exports.RECALIBRATION_MODES = void 0;
4
+ exports.recalibrationModeValue = recalibrationModeValue;
5
+ exports.termBits = termBits;
6
+ exports.checkMode = checkMode;
7
+ exports.configure = configure;
8
+ exports.currentSettings = currentSettings;
9
+ exports.currentContext = currentContext;
10
+ exports.getCacheDir = getCacheDir;
11
+ // SPDX-License-Identifier: Apache-2.0
12
+ // The SDK's settings (the reference's Settings, configure, current_settings) and the C context
13
+ // they make (depz_config_t, depz_context_create). As the reference reads its DEPZ_* variables at
14
+ // import, this module starts from Settings.fromEnv(process.env); configure() replaces the settings
15
+ // for the process (what was built before keeps the context it was built with).
16
+ const C = require("./generated/constants.g");
17
+ const errors_1 = require("./errors");
18
+ const native_1 = require("./native");
19
+ native_1.native.setErrorFactory(errors_1.errorOfStatus);
20
+ /** Every recalibration mode. */
21
+ exports.RECALIBRATION_MODES = ["off", "manual", "continuous"];
22
+ /** The four terms of a correction. */
23
+ exports.CORRECTION_TERMS = ["pitch", "roll", "yaw", "ty"];
24
+ const TERM_BITS = {
25
+ pitch: C.DEPZ_TERM_PITCH, roll: C.DEPZ_TERM_ROLL, yaw: C.DEPZ_TERM_YAW, ty: C.DEPZ_TERM_TY,
26
+ };
27
+ const MODE_VALUES = {
28
+ off: C.DEPZ_RECAL_OFF, manual: C.DEPZ_RECAL_MANUAL, continuous: C.DEPZ_RECAL_CONTINUOUS,
29
+ };
30
+ function recalibrationModeValue(mode) {
31
+ return mode === null ? C.DEPZ_RECAL_AUTO : MODE_VALUES[mode];
32
+ }
33
+ function termBits(terms) {
34
+ let bits = 0;
35
+ for (const t of terms)
36
+ bits |= TERM_BITS[t];
37
+ return bits;
38
+ }
39
+ function checkMode(value, what) {
40
+ if (typeof value !== "string" || !exports.RECALIBRATION_MODES.includes(value)) {
41
+ throw (0, errors_1.invalidArgument)(`${what} must be one of ${exports.RECALIBRATION_MODES.join(", ")}, got ${JSON.stringify(value)}`);
42
+ }
43
+ return value;
44
+ }
45
+ /** The log levels (Python's logging numbers). */
46
+ exports.LOG_LEVELS = { debug: C.DEPZ_LOG_DEBUG, info: C.DEPZ_LOG_INFO, warning: C.DEPZ_LOG_WARNING, error: C.DEPZ_LOG_ERROR };
47
+ const DEFAULT_CALIBRATION_WEB = "https://depz.ai";
48
+ /** Everything the SDK would otherwise take from its environment (contracts/settings.json). */
49
+ class Settings {
50
+ /** Root of the models and the engines' caches; null: the platform's cache folder. */
51
+ cacheDir;
52
+ /** Server of the calibration web API; "": never ask the web. */
53
+ calibrationWeb;
54
+ /** Read and write the calibration correction in the camera. */
55
+ correctionStore;
56
+ /** The mode of a pipeline given no RecalibrationConfig; null: continuous for a live camera, off for a recording. */
57
+ recalibration;
58
+ /** The terms a pipeline given no RecalibrationConfig may not change. */
59
+ recalibrationHeldTerms;
60
+ /** The log handler; null: silent. */
61
+ log;
62
+ /** The least level handed to log. */
63
+ logLevel;
64
+ /** The defaults: the platform's cache folder, the depz.ai web copy, the camera's correction store, auto recalibration, no log handler. */
65
+ constructor(options = {}) {
66
+ if (options === null || typeof options !== "object")
67
+ throw (0, errors_1.invalidArgument)("Settings options must be an object");
68
+ const known = ["cacheDir", "calibrationWeb", "correctionStore", "recalibration", "recalibrationHeldTerms", "log", "logLevel"];
69
+ for (const k of Object.keys(options)) {
70
+ if (!known.includes(k))
71
+ throw (0, errors_1.invalidArgument)(`Settings has no field ${k}`, { field: k });
72
+ }
73
+ this.cacheDir = options.cacheDir ? String(options.cacheDir) : null;
74
+ const web = options.calibrationWeb ?? DEFAULT_CALIBRATION_WEB;
75
+ if (typeof web !== "string")
76
+ throw (0, errors_1.invalidArgument)('Settings.calibration_web must be a string ("": never ask the web)');
77
+ this.calibrationWeb = web;
78
+ const store = options.correctionStore ?? true;
79
+ if (typeof store !== "boolean")
80
+ throw (0, errors_1.invalidArgument)("Settings.correction_store must be a bool");
81
+ this.correctionStore = store;
82
+ this.recalibration = options.recalibration == null ? null : checkMode(options.recalibration, "recalibration");
83
+ const held = new Set(options.recalibrationHeldTerms ?? []);
84
+ const unknown = [...held].filter((t) => !exports.CORRECTION_TERMS.includes(t)).sort();
85
+ if (unknown.length) {
86
+ throw (0, errors_1.invalidArgument)(`Settings.recalibration_held_terms: unknown terms ${JSON.stringify(unknown)} (the terms are ${exports.CORRECTION_TERMS.join(", ")})`);
87
+ }
88
+ this.recalibrationHeldTerms = held;
89
+ const log = options.log ?? null;
90
+ if (log !== null && typeof log !== "function")
91
+ throw (0, errors_1.invalidArgument)("Settings.log must be a function or null");
92
+ this.log = log;
93
+ const level = options.logLevel ?? C.DEPZ_LOG_WARNING;
94
+ if (!Number.isInteger(level))
95
+ throw (0, errors_1.invalidArgument)("Settings.log_level must be a whole number (10 debug ... 40 error)");
96
+ this.logLevel = level;
97
+ Object.freeze(this);
98
+ }
99
+ /** The settings an environment gives (default: this process's now); a variable not set leaves its default. */
100
+ static fromEnv(env = process.env) {
101
+ const off = (v) => ["off", "none", "0"].includes(v.trim().toLowerCase());
102
+ const o = {};
103
+ const api = env.DEPZ_CALIBRATION_API;
104
+ if (api !== undefined)
105
+ o.calibrationWeb = !api.trim() || off(api) ? "" : api.trim();
106
+ if (env.DEPZ_CORRECTION_STORE !== undefined)
107
+ o.correctionStore = !off(env.DEPZ_CORRECTION_STORE);
108
+ const mode = (env.DEPZ_RECALIBRATION ?? "").trim().toLowerCase();
109
+ if (mode && mode !== "auto") {
110
+ if (!exports.RECALIBRATION_MODES.includes(mode)) {
111
+ throw (0, errors_1.invalidArgument)(`DEPZ_RECALIBRATION must name a mode (auto, ${exports.RECALIBRATION_MODES.join(", ")}), got '${mode}'`);
112
+ }
113
+ o.recalibration = mode;
114
+ }
115
+ const terms = env.DEPZ_RECALIBRATION_TERMS;
116
+ if (terms !== undefined) {
117
+ const allowed = !terms.trim() || off(terms) ? new Set() : new Set(terms.split(",").map((t) => t.trim().toLowerCase()));
118
+ o.recalibrationHeldTerms = exports.CORRECTION_TERMS.filter((t) => !allowed.has(t));
119
+ }
120
+ return new Settings(o);
121
+ }
122
+ }
123
+ exports.Settings = Settings;
124
+ let current = Settings.fromEnv();
125
+ let context = null;
126
+ /** Replaces the SDK's settings for the process. */
127
+ function configure(settings) {
128
+ if (!(settings instanceof Settings))
129
+ throw new errors_1.DepzError(errors_1.ErrorCode.InvalidArgument, "configure takes a Settings");
130
+ current = settings;
131
+ context = null; // made again at its next use; objects built before keep theirs
132
+ }
133
+ /** The SDK's settings now. */
134
+ function currentSettings() {
135
+ return current;
136
+ }
137
+ /** The C context of the settings now (made at its first use). Internal. */
138
+ function currentContext() {
139
+ if (context === null) {
140
+ context = native_1.native.depz_context_create({
141
+ cacheDir: current.cacheDir,
142
+ calibrationWeb: current.calibrationWeb,
143
+ correctionStore: current.correctionStore ? C.DEPZ_SWITCH_ON : C.DEPZ_SWITCH_OFF,
144
+ recalibration: recalibrationModeValue(current.recalibration),
145
+ recalibrationHeldTerms: termBits(current.recalibrationHeldTerms),
146
+ logLevel: current.logLevel,
147
+ }, current.log);
148
+ }
149
+ return context;
150
+ }
151
+ /** The cache root of the settings now: models in <root>/models, the engines' caches (get_cache_dir). */
152
+ function getCacheDir() {
153
+ return native_1.native.depz_context_cache_dir(currentContext());
154
+ }
@@ -0,0 +1,137 @@
1
+ import type { RawSourceInfo } from "./generated/records.g";
2
+ import { Calibration, type Control } from "./calibration";
3
+ import type { CameraInfo, CaptureMode } from "./cameras";
4
+ import { RawFrame } from "./frames";
5
+ import { type NativeHandle } from "./native";
6
+ /** What a source delivers (the reference's SourceInfo, without os_id). */
7
+ export interface SourceInfo {
8
+ readonly serial: string;
9
+ readonly name: string;
10
+ /** "" when unknown. */
11
+ readonly cameraFamily: string;
12
+ /** The frame as delivered. */
13
+ readonly width: number;
14
+ readonly height: number;
15
+ /** The rate asked for. */
16
+ readonly fps: number;
17
+ readonly isLive: boolean;
18
+ readonly isStereo: boolean;
19
+ /** The clock its times are on ("linux_monotonic", ...; "unknown"). */
20
+ readonly clockDomain: string;
21
+ /** The payload's format ("MJPG", "YUYV"; "" none). */
22
+ readonly fourcc: string;
23
+ readonly isFrameRecordsActive: boolean;
24
+ }
25
+ /** Internal: the record of the C ABI. */
26
+ export declare function sourceInfoOf(i: RawSourceInfo): SourceInfo;
27
+ /** How a recording is replayed: as the camera delivered it (late frames dropped), or every frame. */
28
+ export type ReplayMode = "realtime" | "every_frame";
29
+ /** The common part of the sources. */
30
+ export declare abstract class FrameSource {
31
+ /** @internal */
32
+ readonly _h: NativeHandle;
33
+ /** @internal */
34
+ protected _atEof: boolean;
35
+ /** @internal */
36
+ protected constructor(handle: NativeHandle);
37
+ abstract get isLive(): boolean;
38
+ /** A finite source gave its last frame. */
39
+ get atEof(): boolean;
40
+ /** Opens the source (a Promise: a camera takes a while); its info. */
41
+ open(): Promise<SourceInfo>;
42
+ /** What it delivers (after open). */
43
+ get info(): SourceInfo;
44
+ /** One frame, waiting up to timeoutMs (-1 or omitted: no limit); null when nothing came in time
45
+ * or at the end (atEof set). */
46
+ grab(timeoutMs?: number): Promise<RawFrame | null>;
47
+ /** Closes the source (a camera: its stream). */
48
+ close(): void;
49
+ /** Its camera's controls: a live camera's read from the device now (none while it is not
50
+ * open), a recording's as recorded at the frame played last. */
51
+ listCameraControls(): Control[];
52
+ /** Its calibration as given at open (a recording: its camera record's); null when it has none. */
53
+ get baseCalibration(): Calibration | null;
54
+ /** The calibration in force at its position (with a recording's corrections); null when none. */
55
+ get activeCalibration(): Calibration | null;
56
+ /** Releases the C source now (a pipeline on it keeps its own reference). */
57
+ release(): void;
58
+ }
59
+ /** How a recording is replayed. */
60
+ export interface MkvSourceOptions {
61
+ /** Default "realtime". */
62
+ replayMode?: ReplayMode;
63
+ /** Start again at the end; default false. */
64
+ loop?: boolean;
65
+ /** Never faster than recorded; default true. */
66
+ pacePlayback?: boolean;
67
+ }
68
+ /** A recording (contracts/recording/FORMAT.md, schema 6; 3: recording_needs_migration, others
69
+ * recording_unsupported). Its replay is controlled here (or, under a pipeline, by pipeline.replay). */
70
+ export declare class MkvSource extends FrameSource {
71
+ readonly path: string;
72
+ readonly replayMode: ReplayMode;
73
+ readonly pacePlayback: boolean;
74
+ /** A recording to replay; opens nothing (a schema it does not read is refused here). */
75
+ constructor(path: string, options?: MkvSourceOptions);
76
+ get isLive(): boolean;
77
+ private get replay();
78
+ /** The frames of the file's frame index (0 before open). */
79
+ get frameCount(): number;
80
+ /** The container's duration; 0 when it says none. */
81
+ get durationUs(): number;
82
+ /** The rate of the frame index; NaN with fewer than 2 frames. */
83
+ get fpsMeasured(): number;
84
+ /** The rate the recorded capture mode declares. */
85
+ get fpsTarget(): number;
86
+ /** The frame index of the position; null before the first. */
87
+ get currentFrame(): number | null;
88
+ get isPaused(): boolean;
89
+ /** Played to its end without loop (cleared by a seek or a step). */
90
+ get atEof(): boolean;
91
+ /** Its capture mode (the CAPTURE_MODE tag), after open; null when it names none. */
92
+ get modeSlug(): string | null;
93
+ /** The recorded camera model's turn of the eyes (a Varius V: 90), after open. */
94
+ get eyeRotationDeg(): number;
95
+ /** [width, height] of the frames as stored, before the eyes are turned; null when they are
96
+ * not turned (the delivered size: info.width / height). */
97
+ get captureSize(): [number, number] | null;
98
+ /** Rewinds at its end. */
99
+ get loop(): boolean;
100
+ set loop(on: boolean);
101
+ /** No frame is handed out until resume (a paused grab gives null). */
102
+ pause(): void;
103
+ /** Plays on from the position. */
104
+ resume(): void;
105
+ /** To the frame at or before ptsUs (the recording's own time). */
106
+ seekRelativeUs(ptsUs: number): void;
107
+ /** To exactly that frame of the index. */
108
+ seekFrame(frame: number): void;
109
+ /** One frame forward (a paused replay hands out exactly that frame). */
110
+ stepOneForward(): void;
111
+ /** One frame back. */
112
+ stepOneBackward(): void;
113
+ /** Every track: {title: [[ptsUs, packet], ...]} ({} before open). */
114
+ recordingTracks(): Record<string, [number, unknown][]>;
115
+ /** The camera record (camera.json) the recording carries; null without one. */
116
+ get embeddedCameraInfo(): Record<string, unknown> | null;
117
+ }
118
+ /** What a camera source delivers. */
119
+ export interface CameraSourceOptions {
120
+ /** A capture mode (or its slug); omitted: the camera's default. */
121
+ mode?: CaptureMode | string | null;
122
+ /** [width, height] of the eye delivered; omitted: the camera's rule. */
123
+ eyeSize?: readonly [number, number] | null;
124
+ }
125
+ /** A live camera (opens nothing until open()). */
126
+ export declare class CameraSource extends FrameSource {
127
+ readonly camera: CameraInfo;
128
+ readonly modeSlug: string | null;
129
+ readonly eyeSize: readonly [number, number] | null;
130
+ /** A source on a camera found by findCamera or scanCameras; opens nothing. */
131
+ constructor(camera: CameraInfo, options?: CameraSourceOptions);
132
+ get isLive(): boolean;
133
+ /** A control of the camera read now; null when it could not be read. */
134
+ cameraControlGet(name: string): number | null;
135
+ /** Writes a control of the camera at once (a whole number). */
136
+ cameraControlSet(name: string, value: number): void;
137
+ }
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CameraSource = exports.MkvSource = exports.FrameSource = void 0;
4
+ exports.sourceInfoOf = sourceInfoOf;
5
+ // SPDX-License-Identifier: Apache-2.0
6
+ // Sources: a recording (the reference's MkvSource). open / grab / close; grab is a Promise (it
7
+ // waits on a worker thread), null at a timeout or at the end of a finite source (atEof set).
8
+ const C = require("./generated/constants.g");
9
+ const errors_1 = require("./errors");
10
+ const calibration_1 = require("./calibration");
11
+ const frames_1 = require("./frames");
12
+ const native_1 = require("./native");
13
+ const settings_1 = require("./settings");
14
+ /** Internal: the record of the C ABI. */
15
+ function sourceInfoOf(i) {
16
+ return Object.freeze({
17
+ serial: i.serial, name: i.name, cameraFamily: i.cameraFamily, width: i.width, height: i.height, fps: i.fps,
18
+ isLive: i.isLive !== 0, isStereo: i.isStereo !== 0, clockDomain: i.clockDomain, fourcc: i.fourcc,
19
+ isFrameRecordsActive: i.isFrameRecordsActive !== 0,
20
+ });
21
+ }
22
+ /** The common part of the sources. */
23
+ class FrameSource {
24
+ /** @internal */
25
+ _h;
26
+ /** @internal */
27
+ _atEof = false;
28
+ /** @internal */
29
+ constructor(handle) {
30
+ this._h = handle;
31
+ }
32
+ /** A finite source gave its last frame. */
33
+ get atEof() {
34
+ return this._atEof;
35
+ }
36
+ /** Opens the source (a Promise: a camera takes a while); its info. */
37
+ async open() {
38
+ await native_1.native.depz_source_open(this._h);
39
+ this._atEof = false;
40
+ return this.info;
41
+ }
42
+ /** What it delivers (after open). */
43
+ get info() {
44
+ return sourceInfoOf(native_1.native.depz_source_info(this._h));
45
+ }
46
+ /** One frame, waiting up to timeoutMs (-1 or omitted: no limit); null when nothing came in time
47
+ * or at the end (atEof set). */
48
+ async grab(timeoutMs = -1) {
49
+ const r = await native_1.native.depz_source_grab(this._h, timeoutMs);
50
+ if (typeof r === "number") {
51
+ if (r === C.DEPZ_E_END_OF_STREAM)
52
+ this._atEof = true;
53
+ return null;
54
+ }
55
+ return new frames_1.RawFrame(r);
56
+ }
57
+ /** Closes the source (a camera: its stream). */
58
+ close() {
59
+ native_1.native.depz_source_close(this._h);
60
+ }
61
+ /** Its camera's controls: a live camera's read from the device now (none while it is not
62
+ * open), a recording's as recorded at the frame played last. */
63
+ listCameraControls() {
64
+ return native_1.native.depz_source_controls(this._h).map((c) => (0, calibration_1.controlOf)(c));
65
+ }
66
+ /** Its calibration as given at open (a recording: its camera record's); null when it has none. */
67
+ get baseCalibration() {
68
+ const h = native_1.native.depz_source_calibration(this._h, "base");
69
+ return h === null ? null : new calibration_1.Calibration(h);
70
+ }
71
+ /** The calibration in force at its position (with a recording's corrections); null when none. */
72
+ get activeCalibration() {
73
+ const h = native_1.native.depz_source_calibration(this._h, "active");
74
+ return h === null ? null : new calibration_1.Calibration(h);
75
+ }
76
+ /** Releases the C source now (a pipeline on it keeps its own reference). */
77
+ release() {
78
+ this._h.release();
79
+ }
80
+ }
81
+ exports.FrameSource = FrameSource;
82
+ /** A recording (contracts/recording/FORMAT.md, schema 6; 3: recording_needs_migration, others
83
+ * recording_unsupported). Its replay is controlled here (or, under a pipeline, by pipeline.replay). */
84
+ class MkvSource extends FrameSource {
85
+ path;
86
+ replayMode;
87
+ pacePlayback;
88
+ /** A recording to replay; opens nothing (a schema it does not read is refused here). */
89
+ constructor(path, options = {}) {
90
+ if (typeof path !== "string")
91
+ throw (0, errors_1.invalidArgument)("MkvSource: path must be a string");
92
+ const mode = options.replayMode ?? "realtime";
93
+ if (mode !== "realtime" && mode !== "every_frame") {
94
+ throw (0, errors_1.invalidArgument)(`replay_mode must be "realtime" or "every_frame", got ${JSON.stringify(mode)}`);
95
+ }
96
+ const loop = options.loop ?? false, pace = options.pacePlayback ?? true;
97
+ if (typeof loop !== "boolean" || typeof pace !== "boolean")
98
+ throw (0, errors_1.invalidArgument)("MkvSource: loop and pacePlayback are bools");
99
+ super(native_1.native.depz_source_create_recording((0, settings_1.currentContext)(), path, {
100
+ replayMode: mode === "every_frame" ? C.DEPZ_REPLAY_EVERY_FRAME : C.DEPZ_REPLAY_REALTIME,
101
+ loop: loop ? C.DEPZ_SWITCH_ON : C.DEPZ_SWITCH_OFF,
102
+ pacePlayback: pace ? C.DEPZ_SWITCH_ON : C.DEPZ_SWITCH_OFF,
103
+ }));
104
+ this.path = path;
105
+ this.replayMode = mode;
106
+ this.pacePlayback = pace;
107
+ }
108
+ get isLive() {
109
+ return false;
110
+ }
111
+ get replay() {
112
+ return native_1.native.depz_source_replay_info(this._h);
113
+ }
114
+ /** The frames of the file's frame index (0 before open). */
115
+ get frameCount() {
116
+ return this.replay.frameCount;
117
+ }
118
+ /** The container's duration; 0 when it says none. */
119
+ get durationUs() {
120
+ return this.replay.durationUs;
121
+ }
122
+ /** The rate of the frame index; NaN with fewer than 2 frames. */
123
+ get fpsMeasured() {
124
+ return this.replay.fpsMeasured;
125
+ }
126
+ /** The rate the recorded capture mode declares. */
127
+ get fpsTarget() {
128
+ return this.replay.fpsTarget;
129
+ }
130
+ /** The frame index of the position; null before the first. */
131
+ get currentFrame() {
132
+ const f = this.replay.currentFrame;
133
+ return f < 0 ? null : f;
134
+ }
135
+ get isPaused() {
136
+ return this.replay.isPaused !== 0;
137
+ }
138
+ /** Played to its end without loop (cleared by a seek or a step). */
139
+ get atEof() {
140
+ return this.replay.atEof !== 0;
141
+ }
142
+ /** Its capture mode (the CAPTURE_MODE tag), after open; null when it names none. */
143
+ get modeSlug() {
144
+ return this.replay.modeSlug || null;
145
+ }
146
+ /** The recorded camera model's turn of the eyes (a Varius V: 90), after open. */
147
+ get eyeRotationDeg() {
148
+ return this.replay.eyeRotationDeg;
149
+ }
150
+ /** [width, height] of the frames as stored, before the eyes are turned; null when they are
151
+ * not turned (the delivered size: info.width / height). */
152
+ get captureSize() {
153
+ const r = this.replay;
154
+ return r.eyeRotationDeg !== 0 ? [r.streamWidth, r.streamHeight] : null;
155
+ }
156
+ /** Rewinds at its end. */
157
+ get loop() {
158
+ return this.replay.loop !== 0;
159
+ }
160
+ set loop(on) {
161
+ native_1.native.depz_source_replay(this._h, "set_loop", Boolean(on));
162
+ }
163
+ /** No frame is handed out until resume (a paused grab gives null). */
164
+ pause() {
165
+ native_1.native.depz_source_replay(this._h, "pause");
166
+ }
167
+ /** Plays on from the position. */
168
+ resume() {
169
+ native_1.native.depz_source_replay(this._h, "resume");
170
+ }
171
+ /** To the frame at or before ptsUs (the recording's own time). */
172
+ seekRelativeUs(ptsUs) {
173
+ native_1.native.depz_source_replay(this._h, "seek_us", ptsUs);
174
+ }
175
+ /** To exactly that frame of the index. */
176
+ seekFrame(frame) {
177
+ native_1.native.depz_source_replay(this._h, "seek_frame", frame);
178
+ }
179
+ /** One frame forward (a paused replay hands out exactly that frame). */
180
+ stepOneForward() {
181
+ native_1.native.depz_source_replay(this._h, "step", 1);
182
+ }
183
+ /** One frame back. */
184
+ stepOneBackward() {
185
+ native_1.native.depz_source_replay(this._h, "step", -1);
186
+ }
187
+ /** Every track: {title: [[ptsUs, packet], ...]} ({} before open). */
188
+ recordingTracks() {
189
+ return JSON.parse(native_1.native.depz_source_recording_tracks_json(this._h));
190
+ }
191
+ /** The camera record (camera.json) the recording carries; null without one. */
192
+ get embeddedCameraInfo() {
193
+ return JSON.parse(native_1.native.depz_source_embedded_camera_json(this._h));
194
+ }
195
+ }
196
+ exports.MkvSource = MkvSource;
197
+ /** A live camera (opens nothing until open()). */
198
+ class CameraSource extends FrameSource {
199
+ camera;
200
+ modeSlug;
201
+ eyeSize;
202
+ /** A source on a camera found by findCamera or scanCameras; opens nothing. */
203
+ constructor(camera, options = {}) {
204
+ if (camera === null || typeof camera !== "object" || !("_h" in camera))
205
+ throw (0, errors_1.invalidArgument)("CameraSource takes a CameraInfo");
206
+ const mode = options.mode ?? null;
207
+ const slug = mode === null ? null : typeof mode === "string" ? mode : mode.slug;
208
+ const eye = options.eyeSize ?? null;
209
+ if (eye !== null && (!Array.isArray(eye) || eye.length !== 2))
210
+ throw (0, errors_1.invalidArgument)("eyeSize must be [width, height]");
211
+ super(native_1.native.depz_source_create_camera(camera._h, slug, eye ? eye[0] : 0, eye ? eye[1] : 0));
212
+ this.camera = camera;
213
+ this.modeSlug = slug;
214
+ this.eyeSize = eye;
215
+ }
216
+ get isLive() {
217
+ return true;
218
+ }
219
+ /** A control of the camera read now; null when it could not be read. */
220
+ cameraControlGet(name) {
221
+ const c = native_1.native.depz_source_control_get(this._h, name);
222
+ return c.hasValue ? c.value : null;
223
+ }
224
+ /** Writes a control of the camera at once (a whole number). */
225
+ cameraControlSet(name, value) {
226
+ native_1.native.depz_source_control_set_number(this._h, name, value);
227
+ }
228
+ }
229
+ exports.CameraSource = CameraSource;
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@depz/camera-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.1",
4
+ "description": "The DEPZ stereo camera SDK for Node.js: a Node-API addon over the native SDK's C ABI. The native part comes in a platform package (optionalDependencies, added when packed: tools/pack_platform.mjs).",
5
+ "keywords": [
6
+ "depz",
7
+ "stereo",
8
+ "camera",
9
+ "depth",
10
+ "sdk",
11
+ "node-api"
12
+ ],
13
+ "license": "Apache-2.0",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/depz-ai/depz-camera-sdk.git",
17
+ "directory": "ts"
18
+ },
19
+ "main": "dist/index.js",
20
+ "types": "dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "dist/",
30
+ "README.md",
31
+ "LICENSE"
32
+ ],
33
+ "engines": {
34
+ "node": ">=20"
35
+ },
36
+ "optionalDependencies": {
37
+ "@depz/camera-sdk-linux-x64": "0.3.1",
38
+ "@depz/camera-sdk-linux-arm64": "0.3.1",
39
+ "@depz/camera-sdk-darwin-arm64": "0.3.1",
40
+ "@depz/camera-sdk-win32-x64": "0.3.1"
41
+ }
42
+ }