@kymoscope/sdk 0.15.0 → 0.16.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/dist/kymoscope-embed.js +71 -71
- package/dist/kymoscope-sdk.js +65 -65
- package/dist/types/analysis/actions.d.ts +9 -0
- package/dist/types/analysis/aiCheck.d.ts +40 -0
- package/dist/types/analysis/badParts.d.ts +32 -0
- package/dist/types/analysis/changes.d.ts +8 -0
- package/dist/types/analysis/context.d.ts +7 -1
- package/dist/types/analysis/energy.d.ts +21 -0
- package/dist/types/analysis/gap.d.ts +6 -0
- package/dist/types/analysis/golden.d.ts +6 -0
- package/dist/types/analysis/index.d.ts +4 -0
- package/dist/types/analysis/known.d.ts +27 -0
- package/dist/types/analysis/oee.d.ts +5 -1
- package/dist/types/analysis/presets.d.ts +1 -1
- package/dist/types/analysis/ranges.d.ts +18 -0
- package/dist/types/analysis/reliability.d.ts +62 -1
- package/dist/types/analysis/report.d.ts +2 -2
- package/dist/types/analysis/review.d.ts +119 -0
- package/dist/types/analysis/runWear.d.ts +13 -0
- package/dist/types/analysis/shifts.d.ts +1 -0
- package/dist/types/analysis/stops.d.ts +10 -0
- package/dist/types/analysis/types.d.ts +31 -0
- package/dist/types/engine/createEngine.d.ts +22 -1
- package/dist/types/index.d.ts +6 -1
- package/dist/types/lib/live/clockProbe.d.ts +26 -0
- package/dist/types/lib/live/publisher.d.ts +5 -0
- package/dist/types/lib/live/types.d.ts +8 -0
- package/dist/types/lib/live/videoTrack.d.ts +46 -2
- package/dist/types/lib/measurePack.d.ts +13 -0
- package/dist/types/lib/recordings/videoSource.d.ts +12 -1
- package/dist/types/lib/segments/rules.d.ts +4 -0
- package/dist/types/lib/sync/detect.d.ts +28 -0
- package/dist/types/lib/sync/estimate.d.ts +143 -0
- package/dist/types/lib/sync/flash.d.ts +49 -0
- package/dist/types/lib/sync/frameFeatures.d.ts +16 -0
- package/package.json +1 -1
|
@@ -13,7 +13,10 @@ import { type PanelChartSettings } from '../lib/panelChartSettings';
|
|
|
13
13
|
import type { MathChannel, MathChannelPatch } from '../lib/mathChannels/types';
|
|
14
14
|
import type { EvalResult } from '../lib/mathChannels/types';
|
|
15
15
|
import type { LiveConnection, LiveStreamDescriptor, LiveStreamOptions, LocalLiveStream, StreamKeyProvider } from '../lib/live/types';
|
|
16
|
-
import { type VideoSource } from '../lib/live/videoTrack';
|
|
16
|
+
import { type CameraSync, type VideoSource } from '../lib/live/videoTrack';
|
|
17
|
+
import { type DetectSyncOptions, type DetectSyncResult } from '../lib/sync/detect';
|
|
18
|
+
import { type FlashResult, type FlashSwitch } from '../lib/sync/flash';
|
|
19
|
+
import { type ClockEstimate } from '../lib/live/clockProbe';
|
|
17
20
|
import type { ChannelChooser } from '../lib/importers/types';
|
|
18
21
|
import type { RecordingKey } from '../lib/recordings/keys';
|
|
19
22
|
import { DATASET_PALETTE } from '../lib/datasetColors';
|
|
@@ -393,6 +396,24 @@ export declare function createEngine(options?: EngineOptions): {
|
|
|
393
396
|
sources: () => VideoSource[];
|
|
394
397
|
/** Add a video source (e.g. a RecordedVideoSource of an open recording); replaces one with the same id and recordingId. */
|
|
395
398
|
register(source: VideoSource): void;
|
|
399
|
+
/** Set the sync record of camera `id`'s sources (live and recorded; only that recording's when `recordingId` is
|
|
400
|
+
* given, only the live one for null): what the Camera panel applies. Storing it is the host's (set_camera_sync). */
|
|
401
|
+
setSync(id: string, recordingId: string | null | undefined, sync: CameraSync | null): void;
|
|
402
|
+
/** Estimate recorded camera `id`'s offset (and drift) against the open recording `recordingId` it was recorded
|
|
403
|
+
* with, from what the picture and the data show (lib/sync): its frames are decoded in this browser. Resolves with
|
|
404
|
+
* the estimate or a refusal and why; stores and applies nothing (store it as method 'auto', then setSync). */
|
|
405
|
+
detectSync(id: string, recordingId: string, o?: DetectSyncOptions): Promise<DetectSyncResult>;
|
|
406
|
+
/** This browser's clock against the relay's (GET /v1/time; clockProbe.ts), or null (no relay, or an old one). */
|
|
407
|
+
relayClock(): Promise<ClockEstimate | null>;
|
|
408
|
+
/** Flash calibration of live camera `id` (lib/sync/flash.ts): it filmed a screen showing `switches` (relay Unix s;
|
|
409
|
+
* `displayClockOffsetMs`: the showing browser's clock against the relay's, used for the camera when its sender
|
|
410
|
+
* reported none). Waits until the camera's frames cover the last switch plus 3 s (at most 15 s), decodes them here
|
|
411
|
+
* and estimates its latency. Stores nothing: store it as method 'calibration', then setSync. */
|
|
412
|
+
calibrateFlash(id: string, switches: FlashSwitch[], o?: {
|
|
413
|
+
displayClockOffsetMs?: number | null;
|
|
414
|
+
signal?: AbortSignal;
|
|
415
|
+
onProgress?: (fraction: number) => void;
|
|
416
|
+
}): Promise<FlashResult>;
|
|
396
417
|
/** Remove the registered sources of camera `id` (of only that recording when `recordingId` is given). */
|
|
397
418
|
unregister(id: string, recordingId?: string): void;
|
|
398
419
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -67,7 +67,12 @@ export { openMessage, sealMessage, KIND_VIDEO, KIND_CHAIN } from './lib/live/wir
|
|
|
67
67
|
export { ChainLane, chainVerifier, decodeChain, encodeChain, newRun, CHAIN_LIVE, CHAIN_RECORDING } from './lib/live/chainWire';
|
|
68
68
|
export type { Chain, StreamIntegrity } from './lib/live/chainWire';
|
|
69
69
|
export { encodeVideo, decodeVideo, fragmentVideo, VIDEO_MAX_FRAGMENT, type VideoMessage } from './lib/live/videoWire';
|
|
70
|
-
export type { VideoSource, EncodedUnit, VideoTrackInfo } from './lib/live/videoTrack';
|
|
70
|
+
export type { VideoSource, EncodedUnit, VideoTrackInfo, CameraSync } from './lib/live/videoTrack';
|
|
71
|
+
export { clockShiftS, syncShiftS } from './lib/live/videoTrack';
|
|
72
|
+
export { estimateSync, confidenceLabel, type FrameFeatures, type DataChannel, type EstimateOptions, type SyncEstimate, type SyncRefusal, type SyncResult, type TriedChannel } from './lib/sync/estimate';
|
|
73
|
+
export { type DetectSyncResult, type DetectSyncOptions } from './lib/sync/detect';
|
|
74
|
+
export { estimateFlash, flashCycle, flashLevel, nextFlashCycle, FLASH_ACTIVE_S, FLASH_CYCLE_S, type FlashResult, type FlashSwitch } from './lib/sync/flash';
|
|
75
|
+
export { probeClock, type ClockEstimate } from './lib/live/clockProbe';
|
|
71
76
|
export { RecordedVideoSource, type RecordedVideoSourceOptions } from './lib/recordings/videoSource';
|
|
72
77
|
export { LivePublisher, fetchUsage, liveBytesPerSec, RegistryError, type CameraQuality, type LiveProfile, type LiveUsage, type PublisherDeps, type PublisherOptions, type PublisherState, type PublisherStatus } from './lib/live/publisher';
|
|
73
78
|
export { CameraSender, CAMERA_QUALITIES, LOW_PRESET, type CameraPreset, type CameraStats, type CameraLayerStats, type CameraSenderDeps, type CameraRecorder } from './lib/live/cameraSender';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This device's clock against the relay's (spec 2026-11-19-camera-sync-design.md, 4.0), as the Python library's
|
|
3
|
+
* clocksync: a few GET /v1/time probes, the one with the smallest round trip, the relay's reading taken at its midpoint
|
|
4
|
+
* (NTP). offsetMs = local − relay, good to ±rttMs/2. Senders report it at register and with every heartbeat; the
|
|
5
|
+
* Camera panel applies only the difference between a camera's and its data's (clockShiftS).
|
|
6
|
+
*/
|
|
7
|
+
export interface ClockEstimate {
|
|
8
|
+
offsetMs: number;
|
|
9
|
+
rttMs: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const CLOCK_PROBES = 5;
|
|
12
|
+
/** Probed again this often (ms). */
|
|
13
|
+
export declare const CLOCK_REPROBE_MS = 600000;
|
|
14
|
+
/** A probe not answered within this (ms) is lost: a stalled relay never holds a register or heartbeat. */
|
|
15
|
+
export declare const CLOCK_PROBE_TIMEOUT_MS = 3000;
|
|
16
|
+
/** The estimate, or null when no probe answered (an old relay without /v1/time). `now`: ms epoch, the clock the
|
|
17
|
+
* sender stamps with. */
|
|
18
|
+
export declare function probeClock(relayUrl: string, fetchFn: typeof fetch, now: () => number, probes?: number, timeoutMs?: number): Promise<ClockEstimate | null>;
|
|
19
|
+
/** The register/heartbeat body fields of an estimate (none: {}). */
|
|
20
|
+
export declare const clockFields: (e: ClockEstimate | null) => {
|
|
21
|
+
clock_offset_ms: number;
|
|
22
|
+
clock_rtt_ms: number;
|
|
23
|
+
} | {
|
|
24
|
+
clock_offset_ms?: undefined;
|
|
25
|
+
clock_rtt_ms?: undefined;
|
|
26
|
+
};
|
|
@@ -187,6 +187,9 @@ export declare class LivePublisher {
|
|
|
187
187
|
private usage;
|
|
188
188
|
private bitrate;
|
|
189
189
|
private noticeCode;
|
|
190
|
+
/** This device's clock against the relay's (clockProbe.ts), reported at register and with every heartbeat. */
|
|
191
|
+
private clock;
|
|
192
|
+
private clockAt;
|
|
190
193
|
constructor(opts: PublisherOptions, deps: PublisherDeps);
|
|
191
194
|
/** The registered stream id (null until start() registers). */
|
|
192
195
|
get streamId(): string | null;
|
|
@@ -230,6 +233,8 @@ export declare class LivePublisher {
|
|
|
230
233
|
private mint;
|
|
231
234
|
private call;
|
|
232
235
|
private register;
|
|
236
|
+
/** Probe the relay's clock when due (at start, then every CLOCK_REPROBE_MS); a failed probe keeps the last estimate. */
|
|
237
|
+
private probeClock;
|
|
233
238
|
private admitted;
|
|
234
239
|
private notice;
|
|
235
240
|
private senderDevice;
|
|
@@ -35,6 +35,10 @@ export interface LiveStreamDescriptor {
|
|
|
35
35
|
low_of_stream_id?: string | null;
|
|
36
36
|
/** Set while a plan limit holds the stream back (e.g. "Video limit reached this month"); null/absent otherwise. */
|
|
37
37
|
limit_notice?: string | null;
|
|
38
|
+
/** A camera's sync record (list_stream_cameras); null/absent: none. */
|
|
39
|
+
sync?: import('./videoTrack').CameraSync | null;
|
|
40
|
+
/** Its sender's clock minus the relay's (ms, reported by the sender); null/absent: not reported. */
|
|
41
|
+
clock_offset_ms?: number | null;
|
|
38
42
|
}
|
|
39
43
|
/**
|
|
40
44
|
* The keys of a stream in an end-to-end encrypted project: frames name their key id
|
|
@@ -112,4 +116,8 @@ export interface LiveConnection {
|
|
|
112
116
|
integrity?: StreamIntegrity;
|
|
113
117
|
/** The plan-limit banner it was opened with (LiveStreamDescriptor.limit_notice); a Camera panel shows it. */
|
|
114
118
|
limitNotice?: string | null;
|
|
119
|
+
/** A camera's sync record (LiveStreamDescriptor.sync), else null/absent. */
|
|
120
|
+
sync?: import('./videoTrack').CameraSync | null;
|
|
121
|
+
/** Its sender's clock minus the relay's (LiveStreamDescriptor.clock_offset_ms), else null/absent. */
|
|
122
|
+
clockOffsetMs?: number | null;
|
|
115
123
|
}
|
|
@@ -24,6 +24,27 @@ export interface VideoTrackInfo {
|
|
|
24
24
|
* and four of the camera's usual gaps for a slow one. */
|
|
25
25
|
export declare const NO_SIGNAL_MIN_MS = 3000;
|
|
26
26
|
export declare function noSignalAfterMs(gapMs: number | null | undefined): number;
|
|
27
|
+
/**
|
|
28
|
+
* A camera's sync record: how its frames' stamps relate to the data's clock. offsetMs > 0: a frame is stamped that
|
|
29
|
+
* much after what it shows (render, sensor, encoder latency), so the player shows a later frame; driftPpm: the camera's
|
|
30
|
+
* clock running fast (ppm) from tRef (Unix s). Stored with the camera stream (its device's) and copied to each camera
|
|
31
|
+
* recording; method 'default' (its sender's, e.g. 50 ms for game capture) < 'auto' < 'calibration' < 'manual'.
|
|
32
|
+
*/
|
|
33
|
+
export interface CameraSync {
|
|
34
|
+
offsetMs: number;
|
|
35
|
+
driftPpm: number;
|
|
36
|
+
tRef: number;
|
|
37
|
+
method: 'default' | 'manual' | 'auto' | 'calibration';
|
|
38
|
+
confidence?: number;
|
|
39
|
+
spreadMs?: number;
|
|
40
|
+
}
|
|
41
|
+
/** Seconds to add to the data's wall time `t` (Unix s) to get the camera stamp that shows it: offset + drift·(t − tRef). */
|
|
42
|
+
export declare function syncShiftS(sync: CameraSync | null | undefined, t: number): number;
|
|
43
|
+
/**
|
|
44
|
+
* Seconds to add for two senders' clocks: a camera's clock offset minus its data's (each the sender's clock minus the
|
|
45
|
+
* relay's, ms; see clockProbe.ts). 0 when either is unknown (an old sender reports none): nothing is guessed.
|
|
46
|
+
*/
|
|
47
|
+
export declare function clockShiftS(cameraMs: number | null | undefined, dataMs: number | null | undefined): number;
|
|
27
48
|
/**
|
|
28
49
|
* A camera's video as the Camera panel plays it: a live camera connection's ring (kind 'live'), or a camera
|
|
29
50
|
* recorded with a cloud recording (kind 'recorded', RecordedVideoSource). Listed by engine.video.sources().
|
|
@@ -41,11 +62,23 @@ export interface VideoSource {
|
|
|
41
62
|
parentName?: string | null;
|
|
42
63
|
/** Recorded: the data recording it was recorded with (that dataset's info.meta.recordingId). */
|
|
43
64
|
recordingId?: string | null;
|
|
65
|
+
/** Its sync record (the camera recording's, or the live camera's); null/absent: none (offset 0). The Camera panel
|
|
66
|
+
* applies it (syncShiftS) under its own offset. engine.video.setSync changes it. */
|
|
67
|
+
sync?: CameraSync | null;
|
|
68
|
+
/** Its sender's clock minus the relay's (ms); null/absent: not reported. The Camera panel applies it against its
|
|
69
|
+
* data's (clockShiftS). */
|
|
70
|
+
clockOffsetMs?: number | null;
|
|
71
|
+
/** Recorded: its data recording's clock offset (the data it was recorded with); live: the data connection's. */
|
|
72
|
+
dataClockOffsetMs?: number | null;
|
|
44
73
|
info(): VideoTrackInfo;
|
|
45
74
|
/** Earliest and latest capture times (Unix s), or null. */
|
|
46
75
|
range(): [number, number] | null;
|
|
47
|
-
/** Units to decode to show the frame at capture time `t` (Unix s): the last keyframe
|
|
76
|
+
/** Units to decode to show the frame at capture time `t` (Unix s): the last keyframe before it through the unit
|
|
77
|
+
* nearest `t` (nearestEnd). */
|
|
48
78
|
seekPlan(t: number): EncodedUnit[] | Promise<EncodedUnit[]>;
|
|
79
|
+
/** The units to decode the span [t0, t1] (from the keyframe at or before t0), for the sync estimator and flash
|
|
80
|
+
* calibration (live: what the ring still holds). */
|
|
81
|
+
unitsBetween?(t0: number, t1: number): Promise<EncodedUnit[]>;
|
|
49
82
|
/** Live: the newest keyframe and everything after it. */
|
|
50
83
|
livePlan?(): EncodedUnit[];
|
|
51
84
|
/** Live: each new unit; returns an unsubscribe. */
|
|
@@ -60,6 +93,13 @@ export interface VideoSource {
|
|
|
60
93
|
/** Recorded: resolves once the codec is known (info().codec). */
|
|
61
94
|
ready?(): Promise<void>;
|
|
62
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* The index of the unit to show at `t` in `units` (capture order): the nearest one (a tie: the earlier), so the
|
|
98
|
+
* error is ±½ frame, not 0..1 frame late; before the first unit, none (-1). `floor`: the last index with t <= `t`.
|
|
99
|
+
*/
|
|
100
|
+
export declare function nearestEnd(units: readonly {
|
|
101
|
+
t: number;
|
|
102
|
+
}[], t: number, floor: number): number;
|
|
63
103
|
/** A live camera connection's track as a VideoSource (the same object per track while id/name/parent stay). */
|
|
64
104
|
export declare function liveVideoSource(c: {
|
|
65
105
|
id: string;
|
|
@@ -67,6 +107,8 @@ export declare function liveVideoSource(c: {
|
|
|
67
107
|
parentId: string | null;
|
|
68
108
|
lowOf?: string | null;
|
|
69
109
|
video: VideoTrack;
|
|
110
|
+
sync?: CameraSync | null;
|
|
111
|
+
clockOffsetMs?: number | null;
|
|
70
112
|
}): VideoSource;
|
|
71
113
|
/** Per-camera ring of encoded units: reassembles fragments, bounds memory at GOP boundaries, plans decodes. */
|
|
72
114
|
export declare class VideoTrack {
|
|
@@ -87,8 +129,10 @@ export declare class VideoTrack {
|
|
|
87
129
|
push(m: VideoMessage): EncodedUnit | null;
|
|
88
130
|
/** Drop whole GOPs from the front while over budget; the only GOP is never dropped. */
|
|
89
131
|
private trim;
|
|
90
|
-
/** Units to decode to show the frame at wall time `t` (unix s):
|
|
132
|
+
/** Units to decode to show the frame at wall time `t` (unix s): its keyframe through the unit nearest t. */
|
|
91
133
|
seekPlan(t: number): EncodedUnit[];
|
|
134
|
+
/** The units from the keyframe at or before `t0` through the last at or before `t1` (what the ring still holds). */
|
|
135
|
+
unitsBetween(t0: number, t1: number): EncodedUnit[];
|
|
92
136
|
/** The newest keyframe and everything after it. */
|
|
93
137
|
livePlan(): EncodedUnit[];
|
|
94
138
|
/** Called with each completed unit added to the ring. Returns an unsubscribe. */
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** How a recording measure is stored (recording_measures.data; the app's measures.ts and the report service). A
|
|
2
|
+
* measure over GZIP_FROM bytes of JSON (a day of short batches' deviation runs to megabytes, over the server's 2 MB
|
|
3
|
+
* per row) is gzipped: plain as { gz: base64 }, sealed as the gzip bytes (JSON never starts with gzip's 0x1f 0x8b).
|
|
4
|
+
* Rows stored before read as they are. */
|
|
5
|
+
export declare const GZIP_FROM = 64000;
|
|
6
|
+
/** The bytes to seal for `data`: its JSON, gzipped when large. */
|
|
7
|
+
export declare function measureBytes(data: unknown): Promise<Uint8Array>;
|
|
8
|
+
/** The body to store unsealed for `data`: the measure itself, or { gz } when large. */
|
|
9
|
+
export declare function measureBody(data: unknown): Promise<unknown>;
|
|
10
|
+
/** An unsealed body back to its measure. */
|
|
11
|
+
export declare function fromMeasureBody<T>(x: unknown): Promise<T>;
|
|
12
|
+
/** Opened bytes back to their measure. */
|
|
13
|
+
export declare function fromMeasureBytes<T>(b: Uint8Array): Promise<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MessageKey } from '../live/wire';
|
|
2
|
-
import type
|
|
2
|
+
import { type CameraSync, type EncodedUnit, type VideoSource, type VideoTrackInfo } from '../live/videoTrack';
|
|
3
3
|
import { type ChainCount } from './chainCheck';
|
|
4
4
|
export interface RecordedVideoSourceOptions {
|
|
5
5
|
/** The camera stream's id (what a Camera panel's cameraStreamId names). */
|
|
@@ -22,6 +22,11 @@ export interface RecordedVideoSourceOptions {
|
|
|
22
22
|
open: MessageKey;
|
|
23
23
|
/** Decoded units kept, in bytes (default 256 MB); least recently used chunks go first. */
|
|
24
24
|
maxBytes?: number;
|
|
25
|
+
/** The camera recording's sync record (VideoSource.sync). */
|
|
26
|
+
sync?: CameraSync | null;
|
|
27
|
+
/** Its sender's clock offset and its data recording's (VideoSource.clockOffsetMs, dataClockOffsetMs). */
|
|
28
|
+
clockOffsetMs?: number | null;
|
|
29
|
+
dataClockOffsetMs?: number | null;
|
|
25
30
|
}
|
|
26
31
|
export declare class RecordedVideoSource implements VideoSource {
|
|
27
32
|
readonly kind: "recorded";
|
|
@@ -30,6 +35,9 @@ export declare class RecordedVideoSource implements VideoSource {
|
|
|
30
35
|
readonly parentId: string | null;
|
|
31
36
|
readonly parentName: string | null;
|
|
32
37
|
readonly recordingId: string;
|
|
38
|
+
sync: CameraSync | null;
|
|
39
|
+
clockOffsetMs: number | null;
|
|
40
|
+
dataClockOffsetMs: number | null;
|
|
33
41
|
private chunks;
|
|
34
42
|
private fetch;
|
|
35
43
|
private open;
|
|
@@ -52,6 +60,9 @@ export declare class RecordedVideoSource implements VideoSource {
|
|
|
52
60
|
/** Chunk i's units in order, its last one finished from the next chunk; [] when it can't be downloaded. */
|
|
53
61
|
private units;
|
|
54
62
|
seekPlan(t: number): Promise<EncodedUnit[]>;
|
|
63
|
+
/** Units from the last keyframe at or before `t0` through the last one at or before `t1` (capture order): what a
|
|
64
|
+
* decode of that span needs (the sync estimator's frame features). */
|
|
65
|
+
unitsBetween(t0: number, t1: number): Promise<EncodedUnit[]>;
|
|
55
66
|
/** Resolves once the codec is known (the first keyframe of the first chunks), or they had none. */
|
|
56
67
|
ready(): Promise<void>;
|
|
57
68
|
info(): VideoTrackInfo;
|
|
@@ -6,9 +6,13 @@
|
|
|
6
6
|
export type CompareOp = '>' | '>=' | '<' | '<=' | '==' | '!=';
|
|
7
7
|
export type KpiStat = 'min' | 'max' | 'mean' | 'integral' | 'first' | 'last' | 'delta';
|
|
8
8
|
export declare const KPI_STATS: KpiStat[];
|
|
9
|
+
/** A rule's value only: `target`, the value is the distance to it, closer is better (a dimension or a weight to hit);
|
|
10
|
+
* `better`, which way is better when there is no target (set with the rule: everyone judges its cycles alike). */
|
|
9
11
|
export interface KpiSpec {
|
|
10
12
|
channel: string;
|
|
11
13
|
stat: KpiStat;
|
|
14
|
+
target?: number;
|
|
15
|
+
better?: 'min' | 'max';
|
|
12
16
|
}
|
|
13
17
|
/** `duration` (s) and `<channel>:<stat>`; null when the channel had no sample in the segment. */
|
|
14
18
|
export type Kpis = Record<string, number | null>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Detect sync" for a recorded camera: its recording's numeric channels and its frames (decoded here, nothing leaves
|
|
3
|
+
* the browser) through the estimator. Reads the data, picks the active channels and the segments, decodes only the
|
|
4
|
+
* video those segments need, estimates. Stores nothing: the caller applies the result (set_camera_sync, method 'auto').
|
|
5
|
+
*/
|
|
6
|
+
import type { DataSource, ColumnSchema } from '../data/dataSource';
|
|
7
|
+
import type { VideoSource } from '../live/videoTrack';
|
|
8
|
+
import { type EstimateOptions, type SyncResult } from './estimate';
|
|
9
|
+
export interface DetectSyncInput {
|
|
10
|
+
video: VideoSource;
|
|
11
|
+
/** The data recording the camera was recorded with: its dataset's source and schema. */
|
|
12
|
+
data: DataSource;
|
|
13
|
+
schema: ColumnSchema[];
|
|
14
|
+
/** The time column (s) and the Unix time at its 0 (the recording's info.meta.wallOrigin). */
|
|
15
|
+
timeKey: string;
|
|
16
|
+
wallOrigin: number;
|
|
17
|
+
}
|
|
18
|
+
export interface DetectSyncOptions {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
/** 0..1: reading the data, then decoding (most of it), then the estimate. */
|
|
21
|
+
onProgress?: (fraction: number) => void;
|
|
22
|
+
estimate?: EstimateOptions;
|
|
23
|
+
}
|
|
24
|
+
export type DetectSyncResult = SyncResult & {
|
|
25
|
+
elapsedMs: number;
|
|
26
|
+
frames: number;
|
|
27
|
+
};
|
|
28
|
+
export declare function detectSync(input: DetectSyncInput, o?: DetectSyncOptions): Promise<DetectSyncResult>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camera ↔ data offset by content (spec 2026-11-19-camera-sync-design §5.1): something in the picture changes when some
|
|
3
|
+
* channel changes; find the lag that lines them up. Pure arrays in, an estimate or a refusal out; nothing here knows
|
|
4
|
+
* what the picture or the channel means.
|
|
5
|
+
*
|
|
6
|
+
* Video features (frameFeatures.ts): per frame an 8×6 grid of mean luminance (level) and of mean |Δ| to the previous
|
|
7
|
+
* frame (diff, divided by the frame gap: a rate, placed at the midpoint of the two frames), both high-passed. Data
|
|
8
|
+
* features per channel: the value (high-passed), |value| high-passed and |d/dt| (at the midpoint of its two samples).
|
|
9
|
+
* Pairs: level ↔ value, diff ↔ |d/dt| and |value| (motion follows a derivative, a rotation rate or vibration; a lamp or
|
|
10
|
+
* gauge a level). Channels that look like one sensor's axes add their vector's magnitude (withAxisMagnitudes), paired
|
|
11
|
+
* value ↔ diff only and always taken to the fine pass: a hand-held camera's picture moves with the whole sensor.
|
|
12
|
+
*
|
|
13
|
+
* 1. Channels: numeric, ≥ 10 Hz, the most active (moves on the second scale, not a ramp or noise), at most 8.
|
|
14
|
+
* 2. Segments: ~20 s windows over the overlap (≥ 5; at most 10, spread out, the most active of each part).
|
|
15
|
+
* 3. Coarse: every pair, pooled over the segments on a 40 ms grid over [−1 s, +3 s]: each channel's best pair by
|
|
16
|
+
* peak z-score.
|
|
17
|
+
* 4. Fine: the best channels, per segment on a 5 ms grid, parabolic peak; Theil–Sen line through the segment offsets
|
|
18
|
+
* → offset at tRef and drift; spread = MAD of the residuals around that line (not the mean: drift isn't noise).
|
|
19
|
+
* 5. Accept: ≥ 5 segments, spread ≤ ½ frame, median segment z ≥ 6, offset in [−1 frame, +3 s], and channels that
|
|
20
|
+
* pass agreeing within a frame (a setpoint's actuator delay shows up as disagreement).
|
|
21
|
+
* Sign: offsetMs > 0 = a frame is stamped later than what it shows (CameraSync): video(t) ≈ data(t − offset).
|
|
22
|
+
*/
|
|
23
|
+
export interface FrameFeatures {
|
|
24
|
+
/** Each frame's stamp (s, the data's clock: Unix s for a recording), ascending. */
|
|
25
|
+
t: ArrayLike<number>;
|
|
26
|
+
/** Features per frame (48 for the 8×6 grid). */
|
|
27
|
+
cells: number;
|
|
28
|
+
/** frames × cells: mean luminance of each cell (0..255). */
|
|
29
|
+
levels: ArrayLike<number>;
|
|
30
|
+
/** frames × cells: mean |luminance − the previous frame's| of each cell (frame 0: anything, unused). */
|
|
31
|
+
diffs: ArrayLike<number>;
|
|
32
|
+
}
|
|
33
|
+
export interface DataChannel {
|
|
34
|
+
name: string;
|
|
35
|
+
t: ArrayLike<number>;
|
|
36
|
+
v: ArrayLike<number>;
|
|
37
|
+
unit?: string;
|
|
38
|
+
/** Derived by withAxisMagnitudes: a sensor's vector magnitude, compared as a motion energy (value ~ diff). */
|
|
39
|
+
magnitude?: true;
|
|
40
|
+
}
|
|
41
|
+
export interface EstimateOptions {
|
|
42
|
+
/** Plausible offsets (ms): a stamp can't precede what it shows by more than a frame. Default −1 frame … +3000. */
|
|
43
|
+
minLagMs?: number;
|
|
44
|
+
maxLagMs?: number;
|
|
45
|
+
/** Segment length (s, default 20; shorter when the overlap holds fewer than minSegments). */
|
|
46
|
+
segmentS?: number;
|
|
47
|
+
minSegments?: number;
|
|
48
|
+
maxSegments?: number;
|
|
49
|
+
/** Channels compared (the most active first). Default 8. */
|
|
50
|
+
maxChannels?: number;
|
|
51
|
+
/** z-score needed: the median of the segments' peaks against the lags outside the peak's lobe (default 5). */
|
|
52
|
+
minZ?: number;
|
|
53
|
+
/** Channels taken to the fine pass (default 3). */
|
|
54
|
+
fineChannels?: number;
|
|
55
|
+
/** Feature pairs compared (default all three). */
|
|
56
|
+
pairs?: [DataKind, VideoKind][];
|
|
57
|
+
}
|
|
58
|
+
export interface SegmentOffset {
|
|
59
|
+
t: number;
|
|
60
|
+
offsetMs: number;
|
|
61
|
+
z: number;
|
|
62
|
+
peak: number;
|
|
63
|
+
}
|
|
64
|
+
export interface SyncEstimate {
|
|
65
|
+
ok: true;
|
|
66
|
+
offsetMs: number;
|
|
67
|
+
driftPpm: number;
|
|
68
|
+
/** Unix s the offset is at (the middle of the segments). */
|
|
69
|
+
tRef: number;
|
|
70
|
+
/** 0..1, from the z-score and the spread against half a frame. */
|
|
71
|
+
confidence: number;
|
|
72
|
+
/** MAD of the segment offsets around the fitted line (ms). */
|
|
73
|
+
spreadMs: number;
|
|
74
|
+
/** Channels whose estimates passed and agree (the offset is their median), the clearest first. */
|
|
75
|
+
channels: string[];
|
|
76
|
+
segments: SegmentOffset[];
|
|
77
|
+
z: number;
|
|
78
|
+
framePeriodMs: number;
|
|
79
|
+
/** Every channel compared in the fine pass: what it matched in the picture and its numbers. */
|
|
80
|
+
tried: TriedChannel[];
|
|
81
|
+
}
|
|
82
|
+
export interface TriedChannel {
|
|
83
|
+
channel: string;
|
|
84
|
+
feature: string;
|
|
85
|
+
offsetMs: number;
|
|
86
|
+
driftPpm: number;
|
|
87
|
+
spreadMs: number;
|
|
88
|
+
z: number;
|
|
89
|
+
segments: number;
|
|
90
|
+
refused: string | null;
|
|
91
|
+
}
|
|
92
|
+
export interface SyncRefusal {
|
|
93
|
+
ok: false;
|
|
94
|
+
/** English, for the user ("Couldn't detect: …"). */
|
|
95
|
+
reason: string;
|
|
96
|
+
/** The best channel's numbers, when one got that far. */
|
|
97
|
+
best?: {
|
|
98
|
+
channel: string;
|
|
99
|
+
offsetMs: number;
|
|
100
|
+
spreadMs: number;
|
|
101
|
+
z: number;
|
|
102
|
+
segments: number;
|
|
103
|
+
};
|
|
104
|
+
tried?: TriedChannel[];
|
|
105
|
+
}
|
|
106
|
+
export type SyncResult = SyncEstimate | SyncRefusal;
|
|
107
|
+
interface Chan extends DataChannel {
|
|
108
|
+
rate: number;
|
|
109
|
+
activity: number;
|
|
110
|
+
}
|
|
111
|
+
/** Channels worth comparing, the most active first: ≥ 10 Hz, not constant, moving on the second scale. Activity =
|
|
112
|
+
* (mean std in 20 s tiles / overall std: a ramp or a single step scores low) × lag-1 autocorrelation on a 40 ms grid
|
|
113
|
+
* (noise scores low). */
|
|
114
|
+
export declare function rankChannels(channels: DataChannel[], range: [number, number], tile?: number): Chan[];
|
|
115
|
+
/** Segments [a, b] (s) to compare: ~segmentS long, at least minSegments when the overlap allows, at most maxSegments
|
|
116
|
+
* spread over it (the most active tile of each part). `range` is where data and video both are. */
|
|
117
|
+
export declare function planSegments(channels: DataChannel[], range: [number, number], o?: EstimateOptions): {
|
|
118
|
+
segments: [number, number][];
|
|
119
|
+
video: [number, number][];
|
|
120
|
+
};
|
|
121
|
+
/** Overlapping (or within 2 s) windows joined: decoded in one pass. */
|
|
122
|
+
export declare function mergeWindows(w: [number, number][]): [number, number][];
|
|
123
|
+
/** Theil–Sen line through (t, y): slope, the value at tRef, and the MAD of the residuals around it. */
|
|
124
|
+
export declare function theilSen(t: number[], y: number[], tRef: number): {
|
|
125
|
+
slope: number;
|
|
126
|
+
at: number;
|
|
127
|
+
mad: number;
|
|
128
|
+
};
|
|
129
|
+
export type VideoKind = 'level' | 'diff';
|
|
130
|
+
export type DataKind = 'value' | 'abs' | 'rate';
|
|
131
|
+
/** Channels that look like the axes of one sensor (a shared name stem + a digit or x/y/z, 2–3 of them, the same unit
|
|
132
|
+
* and sample times) get the magnitude of their vector as a channel of its own (`<stem> |v|`), after the given ones:
|
|
133
|
+
* a hand-held or mounted camera's picture moves with the whole sensor's motion, which no single axis carries
|
|
134
|
+
* (a GoPro's GYRO). A group already derived (by name) isn't again. */
|
|
135
|
+
export declare function withAxisMagnitudes(channels: DataChannel[]): DataChannel[];
|
|
136
|
+
/**
|
|
137
|
+
* The camera's offset (and drift) against the data, or why not. `frames` and `channels` on the same clock (Unix s);
|
|
138
|
+
* `channels` any numeric ones (the most active are picked).
|
|
139
|
+
*/
|
|
140
|
+
export declare function estimateSync(frames: FrameFeatures, channels: DataChannel[], o?: EstimateOptions): SyncResult;
|
|
141
|
+
/** "high" / "medium" / "low", for the UI. */
|
|
142
|
+
export declare const confidenceLabel: (c: number) => "high" | "low" | "medium";
|
|
143
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time flash calibration of a physical camera (spec 2026-11-19-camera-sync-design.md, 5.2): a screen the camera
|
|
3
|
+
* films switches between dark and light on a known pseudo-random schedule; the camera's frame brightness (the 8×6 grid
|
|
4
|
+
* cell that follows it best: the whole screen, a corner of it, a reflection) against that schedule gives its latency:
|
|
5
|
+
* frame stamp minus the moment the screen showed what the frame shows. Stored as the camera's sync, method
|
|
6
|
+
* 'calibration'.
|
|
7
|
+
*
|
|
8
|
+
* The schedule is a function of the relay's clock (every sender's common reference, clockProbe.ts): cycles of
|
|
9
|
+
* FLASH_CYCLE_S seconds from the Unix epoch, each light at 0, switching at FLASH_INTERVALS_MS (the same every cycle,
|
|
10
|
+
* each 340–1200 ms: at most 3 switches a second, WCAG 2.3.1), dark from FLASH_ACTIVE_S to the cycle's end. Anything
|
|
11
|
+
* that knows the relay's time can show it (the app's calibration view) or simulate it (the rig's camera).
|
|
12
|
+
*/
|
|
13
|
+
import type { FrameFeatures } from './estimate';
|
|
14
|
+
export declare const FLASH_CYCLE_S = 15;
|
|
15
|
+
export declare const FLASH_ACTIVE_S = 12;
|
|
16
|
+
/** The switch intervals of a cycle (ms): MINSTD (48271, 2^31 − 1) from SEED, 340 + x mod 861 — exact in doubles. */
|
|
17
|
+
export declare const FLASH_INTERVALS_MS: readonly number[];
|
|
18
|
+
/** The schedule's level (1 light, 0 dark) at relay time `t` (Unix s). */
|
|
19
|
+
export declare function flashLevel(t: number): 0 | 1;
|
|
20
|
+
/** The start (relay Unix s) of the first cycle at least `leadS` after `t`. */
|
|
21
|
+
export declare const nextFlashCycle: (t: number, leadS?: number) => number;
|
|
22
|
+
/** A switch as shown: when (Unix s, on whatever clock the caller says) and the level from then. */
|
|
23
|
+
export interface FlashSwitch {
|
|
24
|
+
t: number;
|
|
25
|
+
level: 0 | 1;
|
|
26
|
+
}
|
|
27
|
+
/** The ideal switches of the cycle starting at `start` (relay Unix s). */
|
|
28
|
+
export declare const flashCycle: (start: number) => FlashSwitch[];
|
|
29
|
+
export type FlashResult = {
|
|
30
|
+
ok: true;
|
|
31
|
+
offsetMs: number;
|
|
32
|
+
spreadMs: number;
|
|
33
|
+
confidence: number;
|
|
34
|
+
cell: number;
|
|
35
|
+
frames: number;
|
|
36
|
+
switches: number;
|
|
37
|
+
} | {
|
|
38
|
+
ok: false;
|
|
39
|
+
reason: string;
|
|
40
|
+
frames: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The latency of a camera that filmed `switches` (on the camera's clock, ascending; the level before the first is dark),
|
|
44
|
+
* from its frames' grid brightness (frameFeatures). Coarse: each cell's correlation with the level at each lag (10 ms);
|
|
45
|
+
* fine, on the best cell: lags 0.5 ms apart, each frame's predicted brightness the light fraction of an exposure window
|
|
46
|
+
* ending at stamp − lag (widths 0 … one frame period). Latency = stamp − the window's middle. ±: half the lags within
|
|
47
|
+
* 0.5 % of the best correlation.
|
|
48
|
+
*/
|
|
49
|
+
export declare function estimateFlash(f: FrameFeatures, switches: FlashSwitch[]): FlashResult;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A recorded camera's frames as the sync estimator's features (estimate.ts FrameFeatures), decoded in this browser
|
|
3
|
+
* (WebCodecs): each frame drawn to a 32×18 canvas, its luminance averaged in an 8×6 grid (level) and the mean
|
|
4
|
+
* |Δ luminance| of each cell's pixels to the previous frame (diff). Every VideoFrame is closed as soon as it is drawn
|
|
5
|
+
* (a hardware decoder stalls when its frames are held). Windows are decoded in pieces of PIECE_S, each continuing the
|
|
6
|
+
* previous one's decode (no gap at a keyframe boundary), so a long window never sits in memory whole.
|
|
7
|
+
*/
|
|
8
|
+
import type { VideoSource } from '../live/videoTrack';
|
|
9
|
+
import type { FrameFeatures } from './estimate';
|
|
10
|
+
export interface FrameFeatureOptions {
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
/** 0..1 over the windows' seconds. */
|
|
13
|
+
onProgress?: (fraction: number) => void;
|
|
14
|
+
}
|
|
15
|
+
/** Features of every frame decoded for `windows` ([t0, t1] Unix s, ascending, disjoint) of a recorded camera. */
|
|
16
|
+
export declare function frameFeatures(source: VideoSource, windows: [number, number][], o?: FrameFeatureOptions): Promise<FrameFeatures>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kymoscope/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "The Kymoscope data engine and charts for the browser: import large measurement files, plot them, stream live data end-to-end encrypted.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"homepage": "https://kymoscope.com/docs/introduction",
|