drone-path 0.8.1 → 0.10.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 +43 -0
- package/README.md +18 -25
- package/THIRD-PARTY-NOTICES.md +14 -7
- package/app/ipc.mjs +178 -0
- package/app/main.mjs +10 -150
- package/app/preload.cjs +3 -0
- package/dist/appassets.js +2 -11
- package/dist/apppaths.js +2 -10
- package/dist/appsession.js +59 -59
- package/dist/appstate.js +22 -38
- package/dist/assets.js +0 -7
- package/dist/buildinfo.js +71 -0
- package/dist/cammeta.js +127 -89
- package/dist/changeset-gate.js +0 -7
- package/dist/cli.js +3 -36
- package/dist/config.js +216 -167
- package/dist/configfile.js +0 -8
- package/dist/decimate.js +2 -12
- package/dist/exportjob.js +3 -19
- package/dist/ff.js +2 -27
- package/dist/fftools.js +0 -10
- package/dist/frametime.js +32 -0
- package/dist/geo.js +3 -13
- package/dist/inputs.js +0 -4
- package/dist/manual/anchors.js +1 -7
- package/dist/manual/build.js +0 -6
- package/dist/manual/cliref.js +0 -6
- package/dist/manual/links.js +0 -17
- package/dist/manual/markdown.js +2 -10
- package/dist/manual/model.js +0 -3
- package/dist/manual/module.js +0 -3
- package/dist/manual/nav.js +0 -2
- package/dist/manual/reference.js +1 -4
- package/dist/page.js +3 -26
- package/dist/paths.js +0 -12
- package/dist/plan.js +1 -18
- package/dist/png.js +1 -21
- package/dist/proto.js +4 -4
- package/dist/range.js +0 -8
- package/dist/render.js +38 -165
- package/dist/renderer/dom.js +0 -6
- package/dist/renderer/framemath.js +0 -4
- package/dist/renderer/scene.js +10 -34
- package/dist/renderer/theme.js +58 -10
- package/dist/renderer/tilesources.js +0 -10
- package/dist/renderer/trail.js +1 -12
- package/dist/restyle.js +1 -9
- package/dist/run.js +79 -143
- package/dist/serve.js +0 -13
- package/dist/srt.js +30 -8
- package/dist/summary.js +0 -3
- package/dist/telemetry-json-schema.js +23 -0
- package/dist/telemetry-json.js +113 -0
- package/dist/telemetry-math.js +11 -46
- package/dist/telemetry.js +58 -11
- package/dist/tilecache.js +0 -5
- package/dist/tiles.js +31 -117
- package/package.json +15 -13
- package/dist/renderer/leaflet.js +0 -5
- package/dist/tracing.js +0 -208
package/dist/telemetry-math.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
// Pure telemetry math: turns time-stamped samples into per-frame values
|
|
2
|
-
// (position, speed, heading) plus the track statistics. No I/O lives here,
|
|
3
|
-
// so the loader shell and the unit tests drive it directly with in-memory
|
|
4
|
-
// samples.
|
|
5
1
|
import { bearingDeg, circularMeanDeg, haversineM } from './geo.js';
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
2
|
+
import { timeAt } from './frametime.js';
|
|
3
|
+
const MAX_INTERPOLATION_GAP_S = 3;
|
|
4
|
+
const SPEED_SMOOTHING_SPAN = 5;
|
|
5
|
+
const HEADING_MIN_MOVE_M = 1.5;
|
|
6
|
+
const HEADING_HALF_WINDOW_S = 0.35;
|
|
7
|
+
const HEADING_MAX_BASELINE_S = 3;
|
|
8
|
+
const HEADING_MIN_SPEED_MPS = 0.5;
|
|
9
|
+
const HEADING_SMOOTHING_SPAN = 4;
|
|
13
10
|
function isFixSample(sample) {
|
|
14
11
|
return sample.fix !== null;
|
|
15
12
|
}
|
|
16
|
-
// The fix-bearing samples in order, with their indices; the pipeline works
|
|
17
|
-
// from these instead of re-deriving who carries a fix.
|
|
18
13
|
function fixRefs(samples) {
|
|
19
14
|
const refs = [];
|
|
20
15
|
samples.forEach((sample, index) => {
|
|
@@ -38,7 +33,6 @@ function interpolateAltitude(a, b, fraction) {
|
|
|
38
33
|
return altA;
|
|
39
34
|
return altA + (altB - altA) * fraction;
|
|
40
35
|
}
|
|
41
|
-
// Nearest sample with a GPS fix at or beyond idx in the given direction.
|
|
42
36
|
function nearestFix(samples, idx, direction) {
|
|
43
37
|
let i = idx;
|
|
44
38
|
while (i >= 0 && i < samples.length) {
|
|
@@ -49,8 +43,6 @@ function nearestFix(samples, idx, direction) {
|
|
|
49
43
|
}
|
|
50
44
|
return null;
|
|
51
45
|
}
|
|
52
|
-
// Position at time t (seconds). Gaps of missing fixes longer than maxGapSec
|
|
53
|
-
// are bridged by holding the earlier fix instead of interpolating across them.
|
|
54
46
|
function positionAt(samples, t, maxGapSec = MAX_INTERPOLATION_GAP_S) {
|
|
55
47
|
const n = samples.length;
|
|
56
48
|
if (n === 0)
|
|
@@ -80,7 +72,6 @@ function positionAt(samples, t, maxGapSec = MAX_INTERPOLATION_GAP_S) {
|
|
|
80
72
|
alt: interpolateAltitude(a, b, fraction),
|
|
81
73
|
};
|
|
82
74
|
}
|
|
83
|
-
// t before the first sample yields index 0.
|
|
84
75
|
function sampleIndexBefore(samples, t) {
|
|
85
76
|
let lo = 0;
|
|
86
77
|
let hi = samples.length - 1;
|
|
@@ -119,9 +110,6 @@ function computeTrackStats(fixes) {
|
|
|
119
110
|
}
|
|
120
111
|
return { bbox, trackDistanceM };
|
|
121
112
|
}
|
|
122
|
-
// Centered difference over neighboring fixes (m/s), smoothed with a moving
|
|
123
|
-
// average to tame GPS jitter for the HUD. Values live on the sample indexes
|
|
124
|
-
// so any sample can answer a frame's nearest-sample lookup.
|
|
125
113
|
function computeSpeedBySample(sampleCount, fixes) {
|
|
126
114
|
const rawSpeed = new Array(fixes.length).fill(null);
|
|
127
115
|
for (let k = 1; k < fixes.length - 1; k++) {
|
|
@@ -130,7 +118,6 @@ function computeSpeedBySample(sampleCount, fixes) {
|
|
|
130
118
|
rawSpeed[k] = haversineM(fixes[k - 1].fix, fixes[k + 1].fix) / dt;
|
|
131
119
|
}
|
|
132
120
|
}
|
|
133
|
-
// Endpoints reuse the adjacent centered value.
|
|
134
121
|
rawSpeed[0] = rawSpeed[1] ?? 0;
|
|
135
122
|
rawSpeed[fixes.length - 1] = rawSpeed[fixes.length - 2] ?? 0;
|
|
136
123
|
const speedBySample = new Array(sampleCount).fill(0);
|
|
@@ -150,10 +137,6 @@ function computeSpeedBySample(sampleCount, fixes) {
|
|
|
150
137
|
}
|
|
151
138
|
return speedBySample;
|
|
152
139
|
}
|
|
153
|
-
// Preferred source: drone body yaw (DVTM EulerAngle, deci-degrees) - valid
|
|
154
|
-
// even while hovering. Fallback: course over ground measured across a moving
|
|
155
|
-
// baseline (consecutive fixes are only centimeters apart at 60 fps, so
|
|
156
|
-
// neighbor bearings are pure GPS jitter). Held while truly stationary.
|
|
157
140
|
function computeHeadingBySample(samples, fixes, speedBySample) {
|
|
158
141
|
const hasYaw = samples.some((sample) => sample.yawDeg !== null);
|
|
159
142
|
const headingMode = hasYaw ? 'yaw' : 'cog';
|
|
@@ -165,7 +148,6 @@ function computeHeadingBySample(samples, fixes, speedBySample) {
|
|
|
165
148
|
fillCourseOverGroundHeadings(fixes, speedBySample, rawHeading);
|
|
166
149
|
}
|
|
167
150
|
fillHeadingGaps(rawHeading);
|
|
168
|
-
// Samples without a fix carry the default so the array is fully populated.
|
|
169
151
|
const defaultHeading = rawHeading[0] ?? firstKnownHeading(rawHeading) ?? 0;
|
|
170
152
|
const headingBySample = new Array(samples.length).fill(defaultHeading);
|
|
171
153
|
for (let k = 0; k < fixes.length; k++) {
|
|
@@ -191,8 +173,6 @@ function fillCourseOverGroundHeadings(fixes, speedBySample, rawHeading) {
|
|
|
191
173
|
const tk = fixes[k].tSec;
|
|
192
174
|
if ((speedBySample[fixes[k].index] ?? 0) < HEADING_MIN_SPEED_MPS)
|
|
193
175
|
continue;
|
|
194
|
-
// Grow the baseline until the pair clears the GPS jitter floor: slow
|
|
195
|
-
// flights get a wider window instead of losing their heading to holds.
|
|
196
176
|
let ka = k;
|
|
197
177
|
let kb = k;
|
|
198
178
|
let displacement = 0;
|
|
@@ -212,9 +192,6 @@ function fillCourseOverGroundHeadings(fixes, speedBySample, rawHeading) {
|
|
|
212
192
|
}
|
|
213
193
|
}
|
|
214
194
|
}
|
|
215
|
-
// The leading unknowns are back-filled from the FIRST known heading, never
|
|
216
|
-
// the flight's final heading, which would point the arrow the wrong way on
|
|
217
|
-
// clips that start hovering and turn later.
|
|
218
195
|
function fillHeadingGaps(rawHeading) {
|
|
219
196
|
let last = null;
|
|
220
197
|
for (let k = 0; k < rawHeading.length; k++) {
|
|
@@ -223,17 +200,9 @@ function fillHeadingGaps(rawHeading) {
|
|
|
223
200
|
else
|
|
224
201
|
rawHeading[k] = last;
|
|
225
202
|
}
|
|
226
|
-
const
|
|
227
|
-
if (firstKnown !== null) {
|
|
228
|
-
for (let k = 0; k < rawHeading.length; k++) {
|
|
229
|
-
if (rawHeading[k] === null)
|
|
230
|
-
rawHeading[k] = firstKnown;
|
|
231
|
-
else
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
203
|
+
const fallback = firstKnownHeading(rawHeading) ?? 0;
|
|
235
204
|
for (let k = 0; k < rawHeading.length; k++) {
|
|
236
|
-
rawHeading[k] ??=
|
|
205
|
+
rawHeading[k] ??= fallback;
|
|
237
206
|
}
|
|
238
207
|
}
|
|
239
208
|
function firstKnownHeading(rawHeading) {
|
|
@@ -246,7 +215,7 @@ function firstKnownHeading(rawHeading) {
|
|
|
246
215
|
function buildFrameData(samples, frames, fpsValue, speedBySample, headingBySample) {
|
|
247
216
|
const frameData = [];
|
|
248
217
|
for (let frame = 0; frame < frames; frame++) {
|
|
249
|
-
const t = frame
|
|
218
|
+
const t = timeAt(frame, fpsValue);
|
|
250
219
|
const pos = positionAt(samples, t);
|
|
251
220
|
const si = nearestSampleIndex(samples, t);
|
|
252
221
|
frameData.push({
|
|
@@ -258,9 +227,6 @@ function buildFrameData(samples, frames, fpsValue, speedBySample, headingBySampl
|
|
|
258
227
|
}
|
|
259
228
|
return frameData;
|
|
260
229
|
}
|
|
261
|
-
// Bridge fully-missing frame positions at the very ends: frames before the
|
|
262
|
-
// first fix hold the first fix, frames after the last fix hold the last fix
|
|
263
|
-
// (the hold-earlier policy from positionAt, applied past its ends).
|
|
264
230
|
function bridgeMissingFramePositions(frameData) {
|
|
265
231
|
const first = frameData.find((d) => d.fix !== null);
|
|
266
232
|
const last = [...frameData].reverse().find((d) => d.fix !== null);
|
|
@@ -277,7 +243,6 @@ function bridgeMissingFramePositions(frameData) {
|
|
|
277
243
|
trail--;
|
|
278
244
|
}
|
|
279
245
|
}
|
|
280
|
-
// The pure pipeline: samples in, per-frame telemetry and track stats out.
|
|
281
246
|
export function buildTelemetry(loaded, timing) {
|
|
282
247
|
const { samples, source, method, noLock } = loaded;
|
|
283
248
|
const fixes = fixRefs(samples);
|
package/dist/telemetry.js
CHANGED
|
@@ -1,13 +1,55 @@
|
|
|
1
|
-
// The telemetry I/O shell: discovers and parses a recording's telemetry
|
|
2
|
-
// sources (.SRT sidecar, embedded CAM meta) and hands the samples to the pure
|
|
3
|
-
// pipeline in src/telemetry-math.ts. The math is reachable without files so
|
|
4
|
-
// unit tests can drive it with in-memory samples.
|
|
5
1
|
import { parseSrt } from './srt.js';
|
|
6
2
|
import { parseCamMeta } from './cammeta.js';
|
|
7
3
|
import { findSrtSidecar } from './inputs.js';
|
|
8
4
|
import { buildTelemetry } from './telemetry-math.js';
|
|
9
|
-
|
|
5
|
+
function srtCueToFrameValues(cue) {
|
|
6
|
+
return {
|
|
7
|
+
lat: cue.fix?.lat ?? null,
|
|
8
|
+
lng: cue.fix?.lon ?? null,
|
|
9
|
+
altAbs: cue.absAlt,
|
|
10
|
+
altRel: cue.relAlt,
|
|
11
|
+
iso: cue.iso,
|
|
12
|
+
shutterTime: cue.shutterTime,
|
|
13
|
+
whiteBalanceCctK: cue.whiteBalanceCctK,
|
|
14
|
+
fNumber: cue.fNumber,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function camSampleToFrameValues(sample) {
|
|
18
|
+
return {
|
|
19
|
+
gimbalDeviceTimestampMs: sample.gimbalDeviceTimestampMs,
|
|
20
|
+
lat: sample.fix?.lat ?? null,
|
|
21
|
+
lng: sample.fix?.lon ?? null,
|
|
22
|
+
altAbs: sample.absAlt,
|
|
23
|
+
altRel: sample.relAlt,
|
|
24
|
+
gpsAltMm: sample.gpsAltMm,
|
|
25
|
+
pitchDeg: sample.pitchDeg,
|
|
26
|
+
rollDeg: sample.rollDeg,
|
|
27
|
+
yawDeg: sample.yawDeg,
|
|
28
|
+
gimbalPitchDeg: sample.gimbalPitchDeg,
|
|
29
|
+
gimbalRollDeg: sample.gimbalRollDeg,
|
|
30
|
+
gimbalYawDeg: sample.gimbalYawDeg,
|
|
31
|
+
iso: sample.iso,
|
|
32
|
+
whiteBalanceCctK: sample.whiteBalanceCctK,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
10
35
|
async function loadSamples(tools, videoPath, durationSec) {
|
|
36
|
+
const cam = await parseCamMeta(tools, videoPath, durationSec, { keepAll: true });
|
|
37
|
+
if (cam) {
|
|
38
|
+
const fixSamples = cam.samples.filter((sample) => sample.fix !== null);
|
|
39
|
+
if (fixSamples.length === 0) {
|
|
40
|
+
throw new Error('no telemetry found: the CAM meta (DVTM) stream has no GPS fix pairs; ' +
|
|
41
|
+
'the .SRT sidecar is only consulted when no CAM meta stream is present');
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
samples: fixSamples,
|
|
45
|
+
source: 'cammeta',
|
|
46
|
+
method: cam.method,
|
|
47
|
+
noLock: cam.noLock,
|
|
48
|
+
frameValues: cam.method === 'dvtm-packets' ? cam.samples.map(camSampleToFrameValues) : [],
|
|
49
|
+
protoFile: cam.protoFile,
|
|
50
|
+
gimbalDevice: cam.gimbalDevice,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
11
53
|
const srtPath = findSrtSidecar(videoPath);
|
|
12
54
|
if (srtPath) {
|
|
13
55
|
const parsed = await parseSrt(srtPath);
|
|
@@ -24,15 +66,20 @@ async function loadSamples(tools, videoPath, durationSec) {
|
|
|
24
66
|
source: 'srt',
|
|
25
67
|
method: 'srt-cues',
|
|
26
68
|
noLock: parsed.noLock,
|
|
69
|
+
frameValues: parsed.cues.map(srtCueToFrameValues),
|
|
70
|
+
protoFile: null,
|
|
71
|
+
gimbalDevice: null,
|
|
27
72
|
};
|
|
28
73
|
}
|
|
29
|
-
|
|
30
|
-
if (!cam || cam.samples.length === 0) {
|
|
31
|
-
throw new Error('no telemetry found: no .SRT sidecar and no GPS pairs in the CAM meta stream');
|
|
32
|
-
}
|
|
33
|
-
return { samples: cam.samples, source: 'cammeta', method: cam.method, noLock: cam.noLock };
|
|
74
|
+
throw new Error('no telemetry found: no CAM meta (DVTM) stream and no .SRT sidecar');
|
|
34
75
|
}
|
|
35
76
|
export async function loadTelemetry(videoPath, { frames, fpsValue, durationSec, tools, }) {
|
|
36
77
|
const loaded = await loadSamples(tools, videoPath, durationSec);
|
|
37
|
-
|
|
78
|
+
const { frameValues, protoFile, gimbalDevice, ...samples } = loaded;
|
|
79
|
+
return {
|
|
80
|
+
telemetry: buildTelemetry(samples, { frames, fpsValue }),
|
|
81
|
+
frameValues,
|
|
82
|
+
protoFile,
|
|
83
|
+
gimbalDevice,
|
|
84
|
+
};
|
|
38
85
|
}
|
package/dist/tilecache.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// The one tile cache layout and tile URL parsing, shared by the prefetcher,
|
|
2
|
-
// the render server and the app server so they can never disagree about
|
|
3
|
-
// where a tile lives or which URLs are tiles at all.
|
|
4
1
|
import path from 'node:path';
|
|
5
2
|
import { TILE_SOURCES } from './renderer/tilesources.js';
|
|
6
3
|
function cacheKeyFor(style) {
|
|
@@ -10,8 +7,6 @@ export function parseTilePathname(pathname) {
|
|
|
10
7
|
const m = /^\/tiles\/([a-z0-9_-]+)\/(\d+)\/(\d+)\/(\d+)\.png$/.exec(pathname);
|
|
11
8
|
if (!m)
|
|
12
9
|
return null;
|
|
13
|
-
// The URL regex admits any slug; only vocabulary styles are tiles, so the
|
|
14
|
-
// returned style is never a cast lie the callers must re-check.
|
|
15
10
|
const style = Object.hasOwn(TILE_SOURCES, m[1]) ? m[1] : null;
|
|
16
11
|
return style === null
|
|
17
12
|
? null
|
package/dist/tiles.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
// The polite tile download policy in one home: every request start - retries
|
|
2
|
-
// included - is spaced REQUEST_INTERVAL_MS apart (2.0 req/s) and at most
|
|
3
|
-
// DOWNLOAD_WORKERS downloads run at once, whichever entry point drives them.
|
|
4
|
-
// createTileTraffic (the app: on-demand tiles and exports on one queue) and
|
|
5
|
-
// prefetchTiles (the CLI's bulk prefetch, its own queue as it runs alone) are
|
|
6
|
-
// thin wrappers whose priorities decide ordering and sharing.
|
|
7
1
|
import fs from 'node:fs';
|
|
8
2
|
import path from 'node:path';
|
|
3
|
+
import PQueue from 'p-queue';
|
|
9
4
|
import { errorMessage } from './errors.js';
|
|
10
5
|
import { solidPng } from './png.js';
|
|
11
6
|
import { tilePaths } from './tilecache.js';
|
|
@@ -18,28 +13,8 @@ const DOWNLOAD_WORKERS = 2;
|
|
|
18
13
|
const REQUEST_INTERVAL_MS = 500;
|
|
19
14
|
const RETRY_DELAY_MS = 500;
|
|
20
15
|
const FETCH_TIMEOUT_MS = 20000;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// acquires first - and the stamp lands at the actual release with every
|
|
24
|
-
// turn re-checking after sleeping: a late event-loop wake can never
|
|
25
|
-
// squeeze the next start inside the previous release's interval.
|
|
26
|
-
let nextFreeAt = 0;
|
|
27
|
-
let tail = Promise.resolve();
|
|
28
|
-
return () => {
|
|
29
|
-
const turn = tail.then(async () => {
|
|
30
|
-
for (;;) {
|
|
31
|
-
const now = Date.now();
|
|
32
|
-
if (now >= nextFreeAt) {
|
|
33
|
-
nextFreeAt = now + REQUEST_INTERVAL_MS;
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
await sleep(nextFreeAt - now);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
tail = turn.catch(() => { });
|
|
40
|
-
return turn;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
16
|
+
// p-queue starts higher priorities first, so 'now' jumps the queued pre-warm.
|
|
17
|
+
const TASK_PRIORITY = { now: 1, background: 0 };
|
|
43
18
|
function tileUrl(style, tile) {
|
|
44
19
|
const source = TILE_SOURCES[style];
|
|
45
20
|
const subdomain = source.subdomains.length
|
|
@@ -51,26 +26,27 @@ function tileUrl(style, tile) {
|
|
|
51
26
|
.replace('{x}', String(tile.x))
|
|
52
27
|
.replace('{y}', String(tile.y));
|
|
53
28
|
}
|
|
54
|
-
// A canceled download is not a failed one: no placeholder is written and the
|
|
55
|
-
// tile stays uncached, so a later request may fetch the real tile.
|
|
56
29
|
function canceledError(signal) {
|
|
57
30
|
return new Error('tile download canceled', { cause: signal.reason });
|
|
58
31
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
32
|
+
async function fetchBody(url, signal) {
|
|
33
|
+
const res = await fetch(url, {
|
|
34
|
+
headers: { 'User-Agent': USER_AGENT },
|
|
35
|
+
signal: signal
|
|
36
|
+
? AbortSignal.any([AbortSignal.timeout(FETCH_TIMEOUT_MS), signal])
|
|
37
|
+
: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
38
|
+
});
|
|
39
|
+
return res.ok ? Buffer.from(await res.arrayBuffer()) : null;
|
|
40
|
+
}
|
|
41
|
+
async function downloadTile(queue, url, priority, signal) {
|
|
63
42
|
for (let attempt = 0; attempt < DOWNLOAD_ATTEMPTS; attempt++) {
|
|
64
|
-
await acquire();
|
|
65
43
|
try {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
signal
|
|
69
|
-
? AbortSignal.any([AbortSignal.timeout(FETCH_TIMEOUT_MS), signal])
|
|
70
|
-
: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
44
|
+
const body = await queue.add(() => fetchBody(url, signal), {
|
|
45
|
+
priority: TASK_PRIORITY[priority],
|
|
46
|
+
signal,
|
|
71
47
|
});
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
48
|
+
if (body)
|
|
49
|
+
return body;
|
|
74
50
|
}
|
|
75
51
|
catch {
|
|
76
52
|
if (signal?.aborted)
|
|
@@ -80,9 +56,6 @@ async function downloadTile(url, acquire, signal) {
|
|
|
80
56
|
}
|
|
81
57
|
return null;
|
|
82
58
|
}
|
|
83
|
-
// An fs failure while writing the cache is the cache's fault, not the
|
|
84
|
-
// network's: it fails the tile's job instead of being retried as a download,
|
|
85
|
-
// and names the cache so the log and Open errors read it as a cache failure.
|
|
86
59
|
function writeCacheFile(cachePath, data) {
|
|
87
60
|
try {
|
|
88
61
|
fs.mkdirSync(path.dirname(cachePath), { recursive: true });
|
|
@@ -92,9 +65,6 @@ function writeCacheFile(cachePath, data) {
|
|
|
92
65
|
throw new Error(`cache write failed: ${cachePath}: ${errorMessage(e)}`, { cause: e });
|
|
93
66
|
}
|
|
94
67
|
}
|
|
95
|
-
// Placeholder PNGs are pure derivations of the tile source's background
|
|
96
|
-
// color; memoizing per downloader keeps repeat failures cheap without any
|
|
97
|
-
// module-level mutable state.
|
|
98
68
|
function createPlaceholderSource() {
|
|
99
69
|
const cache = new Map();
|
|
100
70
|
return (style) => {
|
|
@@ -106,14 +76,11 @@ function createPlaceholderSource() {
|
|
|
106
76
|
return png;
|
|
107
77
|
};
|
|
108
78
|
}
|
|
109
|
-
|
|
110
|
-
// placeholder is served as a fallback so a missing tile is retried on a later
|
|
111
|
-
// run instead of being cached as missing.
|
|
112
|
-
async function fetchTileToCache(ctx, style, tile, signal) {
|
|
79
|
+
async function fetchTileToCache(ctx, style, tile, priority, signal) {
|
|
113
80
|
const paths = tilePaths(ctx.cacheDir, style, tile);
|
|
114
81
|
if (fs.existsSync(paths.file))
|
|
115
82
|
return { file: paths.file, status: 'cached' };
|
|
116
|
-
const body = await downloadTile(tileUrl(style, tile),
|
|
83
|
+
const body = await downloadTile(ctx.queue, tileUrl(style, tile), priority, signal);
|
|
117
84
|
if (body) {
|
|
118
85
|
writeCacheFile(paths.file, body);
|
|
119
86
|
return { file: paths.file, status: 'downloaded' };
|
|
@@ -122,73 +89,25 @@ async function fetchTileToCache(ctx, style, tile, signal) {
|
|
|
122
89
|
return { file: paths.placeholder, status: 'failed' };
|
|
123
90
|
}
|
|
124
91
|
function createDownloader(cacheDir, placeholderPng) {
|
|
125
|
-
const
|
|
92
|
+
const queue = new PQueue({
|
|
93
|
+
concurrency: DOWNLOAD_WORKERS,
|
|
94
|
+
intervalCap: 1,
|
|
95
|
+
interval: REQUEST_INTERVAL_MS,
|
|
96
|
+
// Sliding window: no more than intervalCap starts in any interval window,
|
|
97
|
+
// matching the old request gate's nextFreeAt semantics.
|
|
98
|
+
strict: true,
|
|
99
|
+
});
|
|
100
|
+
const ctx = { cacheDir, queue, placeholderPng };
|
|
126
101
|
const inFlight = new Map();
|
|
127
|
-
const queue = [];
|
|
128
|
-
let active = 0;
|
|
129
|
-
function pump() {
|
|
130
|
-
while (active < DOWNLOAD_WORKERS) {
|
|
131
|
-
const job = queue.shift();
|
|
132
|
-
if (!job)
|
|
133
|
-
break;
|
|
134
|
-
if (job.signal?.aborted) {
|
|
135
|
-
job.detach();
|
|
136
|
-
job.fail(canceledError(job.signal));
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
active++;
|
|
140
|
-
void (async () => {
|
|
141
|
-
try {
|
|
142
|
-
job.settle(await fetchTileToCache(ctx, job.style, job.tile, job.signal));
|
|
143
|
-
}
|
|
144
|
-
catch (e) {
|
|
145
|
-
job.fail(e);
|
|
146
|
-
}
|
|
147
|
-
finally {
|
|
148
|
-
job.detach();
|
|
149
|
-
active--;
|
|
150
|
-
pump();
|
|
151
|
-
}
|
|
152
|
-
})();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
102
|
return {
|
|
156
103
|
enqueue(style, tile, options = {}) {
|
|
157
104
|
const priority = options.priority ?? 'background';
|
|
158
105
|
const key = `${priority}:${tilePaths(cacheDir, style, tile).file}`;
|
|
159
|
-
//
|
|
160
|
-
// sharing follows the abort signal of the download it joins.
|
|
106
|
+
// Share only within one stream: a canceled stream's downloads must never be handed to the next one.
|
|
161
107
|
const shared = inFlight.get(key);
|
|
162
108
|
if (shared && shared.signal === options.signal)
|
|
163
109
|
return shared.promise;
|
|
164
|
-
const task =
|
|
165
|
-
const job = {
|
|
166
|
-
style,
|
|
167
|
-
tile,
|
|
168
|
-
signal: options.signal,
|
|
169
|
-
settle: resolve,
|
|
170
|
-
fail: reject,
|
|
171
|
-
detach: () => { },
|
|
172
|
-
};
|
|
173
|
-
const signal = options.signal;
|
|
174
|
-
if (signal) {
|
|
175
|
-
const onAbort = () => {
|
|
176
|
-
const at = queue.indexOf(job);
|
|
177
|
-
if (at < 0)
|
|
178
|
-
return;
|
|
179
|
-
queue.splice(at, 1);
|
|
180
|
-
job.detach();
|
|
181
|
-
reject(canceledError(signal));
|
|
182
|
-
};
|
|
183
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
|
184
|
-
job.detach = () => signal.removeEventListener('abort', onAbort);
|
|
185
|
-
}
|
|
186
|
-
if (priority === 'now')
|
|
187
|
-
queue.unshift(job);
|
|
188
|
-
else
|
|
189
|
-
queue.push(job);
|
|
190
|
-
pump();
|
|
191
|
-
});
|
|
110
|
+
const task = fetchTileToCache(ctx, style, tile, priority, options.signal);
|
|
192
111
|
const entry = { promise: task, signal: options.signal };
|
|
193
112
|
const clear = () => {
|
|
194
113
|
if (inFlight.get(key) === entry)
|
|
@@ -200,8 +119,6 @@ function createDownloader(cacheDir, placeholderPng) {
|
|
|
200
119
|
},
|
|
201
120
|
};
|
|
202
121
|
}
|
|
203
|
-
// The app's tile traffic on one polite queue: on-demand tiles jump ahead of
|
|
204
|
-
// the queued prefetch, and both stay inside the same 2.0 req/s budget.
|
|
205
122
|
export function createTileTraffic(cacheDir) {
|
|
206
123
|
const downloader = createDownloader(cacheDir, createPlaceholderSource());
|
|
207
124
|
return {
|
|
@@ -233,9 +150,6 @@ export function createTileTraffic(cacheDir) {
|
|
|
233
150
|
},
|
|
234
151
|
};
|
|
235
152
|
}
|
|
236
|
-
// Polite bulk fetching for the pipeline: 2 concurrent workers, 2.0 req/s. It
|
|
237
|
-
// settles once per tile (cached, downloaded or failed) through onTile and
|
|
238
|
-
// rejects with 'tile download canceled' when a signal aborts it.
|
|
239
153
|
export function prefetchTiles(options) {
|
|
240
154
|
return createTileTraffic(options.cacheDir).stream(options);
|
|
241
155
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drone-path",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Render flight-path map overlay videos (exactly the source frame rate and frame count) from DJI drone recordings - telemetry from the
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Render flight-path map overlay videos (exactly the source frame rate and frame count) from DJI drone recordings - telemetry from the embedded CAM-meta (DVTM) stream or the .SRT sidecar.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "app/main.mjs",
|
|
7
7
|
"bin": {
|
|
@@ -21,16 +21,18 @@
|
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"app": "electron app/main.mjs",
|
|
24
|
-
"app:dev": "npm run build:manual && concurrently -k \"next dev ui --webpack -p 3210\" \"wait-on http://127.0.0.1:3210 && electron app/main.mjs --dev-url http://localhost:3210\"",
|
|
24
|
+
"app:dev": "npm run build:manual && npm run build:info && concurrently -k \"next dev ui --webpack -p 3210\" \"wait-on http://127.0.0.1:3210 && electron app/main.mjs --dev-url http://localhost:3210\"",
|
|
25
25
|
"app:pack": "electron-builder --publish never",
|
|
26
|
-
"build": "npm run build:manual && npm run build:ui",
|
|
26
|
+
"build": "npm run build:manual && npm run build:info && npm run build:ui",
|
|
27
27
|
"build:cli": "tsc -p tsconfig.json",
|
|
28
|
+
"build:info": "npm run build:cli && node dist/buildinfo.js",
|
|
28
29
|
"build:manual": "npm run build:cli && node dist/manual/build.js",
|
|
29
30
|
"build:ui": "next build ui --webpack",
|
|
30
31
|
"docs:reference": "npm run build:cli && node dist/manual/reference.js",
|
|
32
|
+
"docs:schema": "npm run build:cli && node dist/telemetry-json-schema.js",
|
|
31
33
|
"changeset": "changeset",
|
|
32
34
|
"changeset:version": "changeset version && npm install --package-lock-only",
|
|
33
|
-
"test": "npm run build:manual && npm run typecheck:test && vitest run",
|
|
35
|
+
"test": "npm run build:manual && npm run build:info && npm run typecheck:test && vitest run",
|
|
34
36
|
"typecheck:test": "tsc --noEmit -p test/tsconfig.json",
|
|
35
37
|
"lint": "eslint .",
|
|
36
38
|
"prepare": "npm run build"
|
|
@@ -59,14 +61,12 @@
|
|
|
59
61
|
},
|
|
60
62
|
"homepage": "https://github.com/MrManny/drone-path#readme",
|
|
61
63
|
"dependencies": {
|
|
62
|
-
"
|
|
63
|
-
"@opentelemetry/exporter-trace-otlp-proto": "~0.301.0",
|
|
64
|
-
"@opentelemetry/resources": "~3.1.0",
|
|
65
|
-
"@opentelemetry/sdk-trace": "~3.1.0",
|
|
66
|
-
"commander": "~15.0.0",
|
|
64
|
+
"commander": "~15.1.0",
|
|
67
65
|
"electron-updater": "~6.8.11",
|
|
68
66
|
"leaflet": "~1.9.4",
|
|
69
|
-
"
|
|
67
|
+
"p-queue": "~10.0.0",
|
|
68
|
+
"playwright-core": "~1.65.0",
|
|
69
|
+
"zod": "~4.6.7"
|
|
70
70
|
},
|
|
71
71
|
"optionalDependencies": {
|
|
72
72
|
"ffmpeg-ffprobe-static": "~7.1.0-rc.1"
|
|
@@ -77,15 +77,17 @@
|
|
|
77
77
|
"@next/eslint-plugin-next": "~16.4.3",
|
|
78
78
|
"@testing-library/react": "~16.3.3",
|
|
79
79
|
"@testing-library/user-event": "~14.6.8",
|
|
80
|
+
"@types/leaflet": "~1.9.22",
|
|
80
81
|
"@types/node": "~24.19.2",
|
|
81
82
|
"@types/react": "~19.3.0",
|
|
82
83
|
"@types/react-dom": "~19.3.0",
|
|
83
|
-
"concurrently": "~10.0.
|
|
84
|
+
"concurrently": "~10.0.7",
|
|
84
85
|
"electron": "~45.2.1",
|
|
85
86
|
"electron-builder": "~26.18.0",
|
|
86
87
|
"eslint": "~10.14.0",
|
|
87
88
|
"eslint-plugin-react-hooks": "~7.1.1",
|
|
88
|
-
"jsdom": "~
|
|
89
|
+
"jsdom": "~31.0.0",
|
|
90
|
+
"lucide-react": "~1.71.0",
|
|
89
91
|
"marked": "~18.1.3",
|
|
90
92
|
"next": "~16.4.3",
|
|
91
93
|
"react": "~19.3.1",
|
package/dist/renderer/leaflet.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// The minimal Leaflet surface the shared renderer touches. Consumers pass the
|
|
2
|
-
// real namespace in (the generated page takes window.L, the app its bundled
|
|
3
|
-
// module import), so this code stays free of bundler and global assumptions
|
|
4
|
-
// and tests can drive it with a fake.
|
|
5
|
-
export {};
|