drone-path 0.9.0 → 0.11.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +16 -14
  3. package/THIRD-PARTY-NOTICES.md +7 -7
  4. package/app/ipc.d.mts +43 -0
  5. package/app/ipc.mjs +216 -0
  6. package/app/main.mjs +10 -204
  7. package/dist/appsession.js +34 -75
  8. package/dist/appstate.js +24 -21
  9. package/dist/buildinfo.js +9 -16
  10. package/dist/cammeta-decode.js +237 -0
  11. package/dist/cammeta.js +8 -247
  12. package/dist/cli.js +40 -32
  13. package/dist/config.js +333 -173
  14. package/dist/configfile.js +20 -7
  15. package/dist/errors.js +30 -0
  16. package/dist/exec-tool.js +13 -0
  17. package/dist/exportjob.js +7 -7
  18. package/dist/{fftools.js → ffmpeg-tools.js} +5 -4
  19. package/dist/{ff.js → ffmpeg.js} +14 -29
  20. package/dist/frametime.js +32 -0
  21. package/dist/geo.js +1 -1
  22. package/dist/manual/build.js +5 -10
  23. package/dist/manual/cliref.js +4 -1
  24. package/dist/manual/reference.js +6 -11
  25. package/dist/{run.js → pipeline.js} +100 -143
  26. package/dist/png.js +1 -18
  27. package/dist/{proto.js → protobuf-wire.js} +5 -5
  28. package/dist/range.js +3 -3
  29. package/dist/{page.js → render-page.js} +2 -2
  30. package/dist/render.js +25 -115
  31. package/dist/renderer/boot.js +2 -2
  32. package/dist/renderer/dom.js +32 -10
  33. package/dist/renderer/scene.js +14 -6
  34. package/dist/restyle.js +1 -1
  35. package/dist/serve.js +1 -31
  36. package/dist/srt.js +2 -2
  37. package/dist/telemetry-json-schema.js +6 -11
  38. package/dist/telemetry-json.js +46 -27
  39. package/dist/telemetry-math.js +3 -2
  40. package/dist/{summary.js → telemetry-summary.js} +4 -4
  41. package/dist/telemetry.js +32 -18
  42. package/dist/tiles.js +30 -86
  43. package/dist/track-format.js +13 -0
  44. package/dist/track-geojson.js +44 -0
  45. package/dist/track-gpx.js +34 -0
  46. package/dist/track-kml.js +47 -0
  47. package/dist/track-kmz.js +68 -0
  48. package/dist/track-write.js +41 -0
  49. package/dist/track.js +79 -0
  50. package/package.json +13 -14
  51. package/dist/tracing.js +0 -184
  52. /package/dist/{renderer/leaflet.js → logging.js} +0 -0
  53. /package/dist/{inputs.js → recordings.js} +0 -0
package/dist/render.js CHANGED
@@ -2,9 +2,8 @@ import http from 'node:http';
2
2
  import { spawn } from 'node:child_process';
3
3
  import { once } from 'node:events';
4
4
  import { MIME } from './assets.js';
5
- import { errorMessage } from './errors.js';
5
+ import { ERR_RENDER_CANCELED, errorMessage } from './errors.js';
6
6
  import { RENDERER_DIR, serveAsset } from './serve.js';
7
- import { NOOP_TRACER, stage } from './tracing.js';
8
7
  const PAGE_LOAD_TIMEOUT_MS = 60000;
9
8
  const SCREENSHOT_TIMEOUT_MS = 60000;
10
9
  function startServer({ html, style, tileCache, }) {
@@ -146,10 +145,8 @@ async function captureFrame(run, loop, page, idx) {
146
145
  run.timing.evalMs += Date.now() - evalStart;
147
146
  const captureStart = Date.now();
148
147
  const buf = await page.screenshot(screenshotOptions(run.capture));
149
- const captureMs = Date.now() - captureStart;
150
- run.timing.captureMs += captureMs;
148
+ run.timing.captureMs += Date.now() - captureStart;
151
149
  const done = ++loop.capturesDone;
152
- run.batches.recordFrame(done, captureMs);
153
150
  const emitStart = Date.now();
154
151
  await run.stream.submit(idx, buf);
155
152
  run.timing.emitMs += Date.now() - emitStart;
@@ -170,7 +167,7 @@ async function workerLoop(run, loop, workerId) {
170
167
  if (loop.failed)
171
168
  return;
172
169
  if (run.signal?.aborted)
173
- throw new Error('render canceled');
170
+ throw new Error(ERR_RENDER_CANCELED);
174
171
  const idx = loop.cursor++;
175
172
  if (idx >= run.frames)
176
173
  break;
@@ -189,16 +186,13 @@ async function runWorkers(run, workerCount) {
189
186
  throw e;
190
187
  })));
191
188
  const rejected = settled.find((r) => r.status === 'rejected');
192
- run.batches.close(rejected?.reason);
193
- run.captureSpan.setAttribute('render.frames.captured', loop.capturesDone);
194
189
  if (rejected)
195
190
  throw rejected.reason;
196
191
  }
197
- async function finishEncode(encoder, stream, encodeSpan, log, outPath) {
192
+ async function finishEncode(encoder, stream, log, outPath) {
198
193
  await stream.flushReady();
199
194
  stream.end();
200
195
  const code = await encoder.closed;
201
- encodeSpan.setAttribute('render.ffmpeg.exitCode', code ?? -1);
202
196
  if (code !== 0) {
203
197
  throw new Error(`ffmpeg exited with code ${code}: ${encoder.stderrText().trim()}`);
204
198
  }
@@ -208,86 +202,16 @@ function formatProfile(profile, workerCount) {
208
202
  return (`profile: eval=${(profile.evalMs / 1000).toFixed(1)}s capture=${(profile.captureMs / 1000).toFixed(1)}s ` +
209
203
  `encode-backpressure=${(profile.emitMs / 1000).toFixed(1)}s (summed over ${workerCount} workers)`);
210
204
  }
211
- export class FrameBatchRecorder {
212
- tracer;
213
- parent;
214
- frames;
215
- cadence;
216
- openSpan = null;
217
- durations = [];
218
- closed = false;
219
- constructor(tracer, parent, frames, cadence = 100) {
220
- this.tracer = tracer;
221
- this.parent = parent;
222
- this.frames = frames;
223
- this.cadence = cadence;
224
- }
225
- recordFrame(capturedSoFar, captureMs) {
226
- if (this.closed)
227
- return;
228
- this.openSpan ??= this.tracer.startSpan('render.capture.batch', {
229
- parent: this.parent,
230
- });
231
- this.durations.push(captureMs);
232
- const boundary = capturedSoFar % this.cadence === 0 || capturedSoFar === this.frames;
233
- if (!boundary)
234
- return;
235
- const span = this.openSpan;
236
- const durations = this.durations;
237
- this.openSpan = null;
238
- this.durations = [];
239
- span.setAttribute('render.frames.captured', capturedSoFar);
240
- span.setAttribute('render.frame.minMs', Math.min(...durations));
241
- span.setAttribute('render.frame.avgMs', Math.round((durations.reduce((a, b) => a + b, 0) / durations.length) * 10) / 10);
242
- span.setAttribute('render.frame.maxMs', Math.max(...durations));
243
- span.end();
244
- }
245
- close(error) {
246
- if (this.closed)
247
- return;
248
- this.closed = true;
249
- if (this.openSpan === null)
250
- return;
251
- if (error !== undefined)
252
- this.openSpan.fail(error);
253
- this.openSpan.end();
254
- this.openSpan = null;
255
- this.durations = [];
256
- }
257
- }
258
205
  async function captureAndEncode(active, env) {
259
- const { ctx, tracer, renderSpan, url, timing, workerCount } = env;
260
- const { fpsStr, codec, quality, preset, outPath, signal, width, height, frames, frameStart, capture, log, onCapture, tools, } = ctx;
206
+ const { ctx, url, timing, workerCount } = env;
207
+ const { fpsStr, codec, quality, preset, outPath, signal, log, tools } = ctx;
261
208
  const encoder = spawnEncoder(tools.ffmpeg, fpsStr, { codec, quality, preset }, outPath);
262
209
  const killOnAbort = () => encoder.kill();
263
210
  signal?.addEventListener('abort', killOnAbort, { once: true });
264
211
  const stream = new OrderedFrameStream(encoder);
265
212
  try {
266
- await stage(tracer, 'render.encode', renderSpan, {
267
- 'render.codec': codec,
268
- 'render.quality': quality,
269
- 'render.preset': preset,
270
- }, async (encodeSpan) => {
271
- await stage(tracer, 'render.capture', renderSpan, {}, async (captureSpan) => {
272
- await runWorkers({
273
- active,
274
- url,
275
- width,
276
- height,
277
- frames,
278
- frameStart,
279
- capture,
280
- signal,
281
- log,
282
- onCapture,
283
- stream,
284
- batches: new FrameBatchRecorder(tracer, captureSpan, frames),
285
- timing,
286
- captureSpan,
287
- }, workerCount);
288
- });
289
- await finishEncode(encoder, stream, encodeSpan, log, outPath);
290
- });
213
+ await runWorkers({ ...ctx, active, url, stream, timing }, workerCount);
214
+ await finishEncode(encoder, stream, log, outPath);
291
215
  }
292
216
  catch (e) {
293
217
  encoder.kill();
@@ -298,23 +222,17 @@ async function captureAndEncode(active, env) {
298
222
  }
299
223
  }
300
224
  function reportProfile(env) {
301
- const { ctx, timing, renderSpan, workerCount } = env;
225
+ const { ctx, timing, workerCount } = env;
302
226
  const profile = {
303
227
  evalMs: Math.round(timing.evalMs),
304
228
  captureMs: Math.round(timing.captureMs),
305
229
  emitMs: Math.round(timing.emitMs),
306
230
  };
307
- renderSpan.setAttributes({
308
- 'render.evalMs': profile.evalMs,
309
- 'render.captureMs': profile.captureMs,
310
- 'render.emitMs': profile.emitMs,
311
- });
312
231
  ctx.log(formatProfile(profile, workerCount));
313
232
  return { profile };
314
233
  }
315
234
  export async function renderVideo(opts) {
316
- const { html, style, tileCache, width, height, frames, fpsStr, workers, outPath, log = () => { }, browserPath = null, tools, capture = 'jpeg', codec = 'h264', quality = 'high', preset = 'medium', frameStart = 0, signal, trace, onCapture, } = opts;
317
- const tracer = trace?.tracer ?? NOOP_TRACER;
235
+ const { html, style, tileCache, width, height, frames, fpsStr, workers, outPath, log = () => { }, browserPath = null, tools, capture = 'jpeg', codec = 'h264', quality = 'high', preset = 'medium', frameStart = 0, signal, onCapture, } = opts;
318
236
  const workerCount = Math.max(1, Math.min(workers, frames));
319
237
  const ctx = {
320
238
  width,
@@ -332,27 +250,19 @@ export async function renderVideo(opts) {
332
250
  onCapture,
333
251
  tools,
334
252
  };
335
- return stage(tracer, 'render', trace?.parent, {
336
- 'render.workers': workerCount,
337
- 'render.capture.mode': capture,
338
- 'render.codec': codec,
339
- 'render.quality': quality,
340
- 'render.preset': preset,
341
- }, async (renderSpan) => {
342
- if (signal?.aborted)
343
- throw new Error('render canceled');
344
- const timing = { evalMs: 0, captureMs: 0, emitMs: 0 };
345
- const { server, url } = await startServer({ html, style, tileCache });
346
- const env = { ctx, tracer, renderSpan, url, timing, workerCount };
347
- let browser = null;
348
- try {
349
- browser = await launchBrowser(log, browserPath);
350
- await captureAndEncode(browser, env);
351
- }
352
- finally {
353
- await browser?.close().catch(() => { });
354
- server.close();
355
- }
356
- return reportProfile(env);
357
- });
253
+ if (signal?.aborted)
254
+ throw new Error(ERR_RENDER_CANCELED);
255
+ const timing = { evalMs: 0, captureMs: 0, emitMs: 0 };
256
+ const { server, url } = await startServer({ html, style, tileCache });
257
+ const env = { ctx, url, timing, workerCount };
258
+ let browser = null;
259
+ try {
260
+ browser = await launchBrowser(log, browserPath);
261
+ await captureAndEncode(browser, env);
262
+ }
263
+ finally {
264
+ await browser?.close().catch(() => { });
265
+ server.close();
266
+ }
267
+ return reportProfile(env);
358
268
  }
@@ -1,6 +1,6 @@
1
1
  import { createScene } from './scene.js';
2
- export function bootScene(host, data, L) {
3
- const scene = createScene(host, data, { L });
2
+ export function bootScene(host, data, L, opts) {
3
+ const scene = createScene(host, data, { L, hudHost: opts?.hudHost });
4
4
  // The pane size may only settle after creation; re-measure post-layout.
5
5
  requestAnimationFrame(() => scene.relayout());
6
6
  return scene;
@@ -1,5 +1,4 @@
1
- export function sceneCss(src, theme, width, height, scale, scope) {
2
- const at = `.${scope}`;
1
+ function mapCss(at, src, theme, width, height) {
3
2
  return `
4
3
  ${at} { margin: 0; padding: 0; overflow: hidden; background: ${src.bg}; }
5
4
  ${at}, ${at} * { animation: none !important; transition: none !important; }
@@ -17,7 +16,10 @@ export function sceneCss(src, theme, width, height, scale, scope) {
17
16
  position: absolute; inset: 0; z-index: 500; pointer-events: none;
18
17
  background: radial-gradient(ellipse 78% 78% at 50% 44%,
19
18
  rgba(0,0,0,0) 52%, rgba(0,0,0,${theme.vignette}) 100%);
20
- }
19
+ }`;
20
+ }
21
+ function droneCss(at, theme, scale) {
22
+ return `
21
23
  ${at} .drone-wrap {
22
24
  width: ${Math.round(46 * scale)}px; height: ${Math.round(46 * scale)}px;
23
25
  border-radius: 50%;
@@ -30,7 +32,10 @@ export function sceneCss(src, theme, width, height, scale, scope) {
30
32
  box-sizing: border-box;
31
33
  }
32
34
  ${at} .drone-arrow { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
33
- ${at} .drone-arrow svg { width: 72%; height: 72%; display: block; }
35
+ ${at} .drone-arrow svg { width: 72%; height: 72%; display: block; }`;
36
+ }
37
+ function chipCss(at, theme, scale) {
38
+ return `
34
39
  ${at} #hud {
35
40
  position: absolute; top: ${Math.round(16 * scale)}px; left: ${Math.round(16 * scale)}px;
36
41
  display: flex; flex-direction: column; gap: ${Math.round(8 * scale)}px;
@@ -59,7 +64,10 @@ export function sceneCss(src, theme, width, height, scale, scope) {
59
64
  font-size: 0.55em; font-weight: 700; letter-spacing: 1.2px;
60
65
  color: ${theme.core}; opacity: 0.95;
61
66
  }
62
- ${at} .chip .unit { font-weight: 500; opacity: 0.72; font-size: 0.68em; }
67
+ ${at} .chip .unit { font-weight: 500; opacity: 0.72; font-size: 0.68em; }`;
68
+ }
69
+ function attrCss(at, scale) {
70
+ return `
63
71
  ${at} #attr {
64
72
  position: absolute; right: 0; bottom: 0; z-index: 1000; max-width: 72%;
65
73
  background: rgba(12, 14, 22, 0.62); color: rgba(255,255,255,0.78);
@@ -69,7 +77,10 @@ export function sceneCss(src, theme, width, height, scale, scope) {
69
77
  border-radius: ${Math.round(4 * scale)}px 0 0 0;
70
78
  pointer-events: none;
71
79
  }
72
- ${at} #attr a { color: rgba(255,255,255,0.92); text-decoration: none; }
80
+ ${at} #attr a { color: rgba(255,255,255,0.92); text-decoration: none; }`;
81
+ }
82
+ function scaleBarCss(at, scale) {
83
+ return `
73
84
  ${at} #scalebar {
74
85
  position: absolute; left: ${Math.round(10 * scale)}px; bottom: ${Math.round(8 * scale)}px;
75
86
  z-index: 1000; pointer-events: none;
@@ -85,6 +96,14 @@ export function sceneCss(src, theme, width, height, scale, scope) {
85
96
  box-shadow: 0 1px 2px rgba(0,0,0,0.6);
86
97
  }`;
87
98
  }
99
+ export function sceneCss(src, theme, width, height, scale, scope) {
100
+ const at = `.${scope}`;
101
+ return (mapCss(at, src, theme, width, height) +
102
+ droneCss(at, theme, scale) +
103
+ chipCss(at, theme, scale) +
104
+ attrCss(at, scale) +
105
+ scaleBarCss(at, scale));
106
+ }
88
107
  export function hudMarkup(hud) {
89
108
  const chips = [];
90
109
  if (hud.alt) {
@@ -95,14 +114,17 @@ export function hudMarkup(hud) {
95
114
  }
96
115
  return chips.map((chip) => ` ${chip}`).join('\n');
97
116
  }
117
+ /** A null hud keeps the chips out of the map frame: the caller mounts them in
118
+ a strip outside the map image instead. */
98
119
  export function mapMarkup(hud, attribution) {
120
+ const hudBlock = hud === null ? '' : `<div id="hud">
121
+ ${hudMarkup(hud)}
122
+ </div>
123
+ `;
99
124
  return `<div id="map-frame">
100
125
  <div id="map"></div>
101
126
  <div id="vignette"></div>
102
- <div id="hud">
103
- ${hudMarkup(hud)}
104
- </div>
105
- <div id="attr">${attribution}</div>
127
+ ${hudBlock}<div id="attr">${attribution}</div>
106
128
  <div id="scalebar"><span id="scaletext"></span><div id="scaleline"></div></div>
107
129
  </div>`;
108
130
  }
@@ -34,15 +34,18 @@ class SceneState {
34
34
  decor;
35
35
  altEl = null;
36
36
  speedEl = null;
37
+ /** Chip container: inside the map frame for exports, or an external strip. */
38
+ hudRoot;
37
39
  curIdx = 0;
38
- constructor(host, firstData, L) {
40
+ constructor(host, firstData, L, hudHost) {
39
41
  this.host = host;
40
42
  this.data = firstData;
41
43
  this.L = L;
42
44
  host.classList.add(this.scopeClass);
43
45
  this.styleEl = document.createElement('style');
44
46
  document.head.appendChild(this.styleEl);
45
- host.innerHTML = mapMarkup(firstData.hud, firstData.attribution);
47
+ host.innerHTML = mapMarkup(hudHost ? null : firstData.hud, firstData.attribution);
48
+ this.hudRoot = hudHost ?? el(host, '#hud');
46
49
  this.attrEl = el(host, '#attr');
47
50
  this.applyChrome();
48
51
  this.mapEl = el(host, '#map');
@@ -94,6 +97,9 @@ class SceneState {
94
97
  applyChrome() {
95
98
  this.styleEl.textContent = sceneCss(TILE_SOURCES[this.data.style], themeFor(this.data.style, this.data.trailColor), this.data.width, this.data.height, this.scale(), this.scopeClass);
96
99
  this.attrEl.innerHTML = this.data.attribution;
100
+ // The compact map card truncates the credit to one line; the hover title
101
+ // carries the full text wherever the browser can show it.
102
+ this.attrEl.title = this.attrEl.textContent ?? '';
97
103
  quietAttributionLinks(this.attrEl);
98
104
  }
99
105
  layoutMap() {
@@ -236,9 +242,11 @@ class SceneState {
236
242
  this.decor = this.buildDecor();
237
243
  }
238
244
  rebuildHud() {
239
- el(this.host, '#hud').innerHTML = hudMarkup(this.data.hud);
240
- this.altEl = this.host.querySelector('#chip-alt .num');
241
- this.speedEl = this.host.querySelector('#chip-speed .num');
245
+ // Scoped to the chip container so an external strip and a second scene
246
+ // (the export preview) can never cross-write.
247
+ this.hudRoot.innerHTML = hudMarkup(this.data.hud);
248
+ this.altEl = this.hudRoot.querySelector('#chip-alt .num');
249
+ this.speedEl = this.hudRoot.querySelector('#chip-speed .num');
242
250
  if (this.decor.arrowEl) {
243
251
  this.decor.arrowEl.style.display = this.data.hud.heading ? '' : 'none';
244
252
  }
@@ -330,5 +338,5 @@ class SceneState {
330
338
  }
331
339
  }
332
340
  export function createScene(host, firstData, deps) {
333
- return new SceneState(host, firstData, deps.L);
341
+ return new SceneState(host, firstData, deps.L, deps.hudHost);
334
342
  }
package/dist/restyle.js CHANGED
@@ -1,4 +1,4 @@
1
- import { buildSceneData, planPageOpts } from './page.js';
1
+ import { buildSceneData, planPageOpts } from './render-page.js';
2
2
  export function restyleSceneData(prev, config, meta, size = { width: prev.width, height: prev.height }) {
3
3
  const planned = planPageOpts({
4
4
  bbox: meta.bbox,
package/dist/serve.js CHANGED
@@ -1,10 +1,8 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { createRequire } from 'node:module';
4
- import { pipeline } from 'node:stream';
5
4
  import { fileURLToPath } from 'node:url';
6
- import { mimeFor, resolveAsset } from './assets.js';
7
- import { rangePlan } from './range.js';
5
+ import { resolveAsset } from './assets.js';
8
6
  const require_ = createRequire(import.meta.url);
9
7
  const LEAFLET_DIR = path.dirname(require_.resolve('leaflet/dist/leaflet.js'));
10
8
  export const RENDERER_DIR = fileURLToPath(new URL('./renderer/', import.meta.url));
@@ -27,31 +25,3 @@ export function serveAsset(url, res, routes) {
27
25
  res.end('not found');
28
26
  return true;
29
27
  }
30
- export function serveFileWithRange(req, res, filePath) {
31
- let size;
32
- try {
33
- size = fs.statSync(filePath).size;
34
- }
35
- catch {
36
- res.writeHead(404, { 'Content-Type': 'text/plain' });
37
- res.end('not found');
38
- return Promise.resolve();
39
- }
40
- const mime = mimeFor(filePath);
41
- const plan = rangePlan(req.headers['range'], size, mime);
42
- res.writeHead(plan.status, plan.headers);
43
- if (plan.status === 416) {
44
- res.end(plan.body);
45
- return Promise.resolve();
46
- }
47
- if (req.method === 'HEAD') {
48
- res.end();
49
- return Promise.resolve();
50
- }
51
- const stream = plan.status === 206
52
- ? fs.createReadStream(filePath, { start: plan.span.start, end: plan.span.end })
53
- : fs.createReadStream(filePath);
54
- return new Promise((resolve) => {
55
- pipeline(stream, res, () => resolve());
56
- });
57
- }
package/dist/srt.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { readFile } from 'node:fs/promises';
2
- import { gpsFix } from './geo.js';
2
+ import { gpsFixOrNull } from './geo.js';
3
3
  const RX_TIMING = /^(\d{2}):(\d{2}):(\d{2})[,.](\d{3})\s*-->/;
4
4
  const RX_LATLON = /\[latitude:\s*(-?\d+\.?\d*)\]\s*\[longitude:\s*(-?\d+\.?\d*)\]/;
5
5
  const RX_ALT = /\[rel_alt:\s*(-?\d+\.?\d*)\s+abs_alt:\s*(-?\d+\.?\d*)\]/;
@@ -65,7 +65,7 @@ export function parseSrtText(text) {
65
65
  const latLon = RX_LATLON.exec(line);
66
66
  if (latLon && !cueSawLatLon) {
67
67
  cueSawLatLon = true;
68
- const fix = gpsFix(parseNumber(latLon[1]), parseNumber(latLon[2]));
68
+ const fix = gpsFixOrNull(parseNumber(latLon[1]), parseNumber(latLon[2]));
69
69
  if (fix !== null) {
70
70
  cue.fix = fix;
71
71
  }
@@ -1,23 +1,18 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import { runToolMain } from './errors.js';
4
5
  import { generateTelemetryJsonSchema } from './telemetry-json.js';
5
6
  export function writeTelemetryJsonSchema(file) {
6
7
  fs.mkdirSync(path.dirname(file), { recursive: true });
7
8
  fs.writeFileSync(file, generateTelemetryJsonSchema());
8
9
  }
9
10
  function main() {
10
- try {
11
- const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
12
- const file = path.join(root, 'docs', 'telemetry-json.schema.json');
13
- writeTelemetryJsonSchema(file);
14
- process.stderr.write(`[drone-path] docs: wrote ${path.relative(root, file)}\n`);
15
- }
16
- catch (e) {
17
- process.stderr.write(`[drone-path] ERROR: ${e.message}\n`);
18
- process.exitCode = 1;
19
- }
11
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
12
+ const file = path.join(root, 'docs', 'telemetry-json.schema.json');
13
+ writeTelemetryJsonSchema(file);
14
+ process.stderr.write(`[drone-path] docs: wrote ${path.relative(root, file)}\n`);
20
15
  }
21
16
  if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
22
- main();
17
+ void runToolMain(main);
23
18
  }
@@ -1,4 +1,7 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
1
3
  import { z } from 'zod';
4
+ import { resolveFrameRange } from './config.js';
2
5
  export const TELEMETRY_JSON_SCHEMA_VERSION = 1;
3
6
  const GimbalDeviceSchema = z.strictObject({
4
7
  id: z.int(),
@@ -37,36 +40,35 @@ export const TelemetryDocumentSchema = z.strictObject({
37
40
  gimbalDevice: GimbalDeviceSchema.optional(),
38
41
  frames: z.array(TelemetryRecordSchema),
39
42
  });
40
- const BEFORE_HEADING_KEYS = [
41
- 'gimbalDeviceTimestampMs',
42
- 'lat',
43
- 'lng',
44
- 'altAbs',
45
- 'altRel',
46
- 'gpsAltMm',
47
- 'pitchDeg',
48
- 'rollDeg',
49
- 'yawDeg',
50
- 'gimbalPitchDeg',
51
- 'gimbalRollDeg',
52
- 'gimbalYawDeg',
53
- ];
54
- const EXPOSURE_KEYS = [
55
- 'iso',
56
- 'shutterTime',
57
- 'whiteBalanceCctK',
58
- 'fNumber',
59
- ];
60
- const INTEGER_VALUE_KEYS = new Set([
61
- 'gimbalDeviceTimestampMs',
62
- 'gpsAltMm',
63
- 'iso',
64
- 'whiteBalanceCctK',
65
- ]);
43
+ // The Record annotation makes a schema field without an entry here a compile
44
+ // error instead of a silently dropped record key.
45
+ const TELEMETRY_VALUES = {
46
+ gimbalDeviceTimestampMs: { position: 'before-heading', integer: true },
47
+ lat: { position: 'before-heading' },
48
+ lng: { position: 'before-heading' },
49
+ altAbs: { position: 'before-heading' },
50
+ altRel: { position: 'before-heading' },
51
+ gpsAltMm: { position: 'before-heading', integer: true },
52
+ pitchDeg: { position: 'before-heading' },
53
+ rollDeg: { position: 'before-heading' },
54
+ yawDeg: { position: 'before-heading' },
55
+ gimbalPitchDeg: { position: 'before-heading' },
56
+ gimbalRollDeg: { position: 'before-heading' },
57
+ gimbalYawDeg: { position: 'before-heading' },
58
+ iso: { position: 'exposure', integer: true },
59
+ shutterTime: { position: 'exposure' },
60
+ whiteBalanceCctK: { position: 'exposure', integer: true },
61
+ fNumber: { position: 'exposure' },
62
+ };
63
+ function valueKeys(position) {
64
+ return Object.keys(TELEMETRY_VALUES).filter((key) => TELEMETRY_VALUES[key].position === position);
65
+ }
66
+ const BEFORE_HEADING_KEYS = valueKeys('before-heading');
67
+ const EXPOSURE_KEYS = valueKeys('exposure');
66
68
  function copyValue(record, key, value) {
67
69
  if (value === null || value === undefined)
68
70
  return;
69
- record[key] = INTEGER_VALUE_KEYS.has(key) ? Math.round(value) : value;
71
+ record[key] = TELEMETRY_VALUES[key].integer ? Math.round(value) : value;
70
72
  }
71
73
  function buildRecord(input, index) {
72
74
  const row = input.frames[index] ?? {};
@@ -81,6 +83,18 @@ function buildRecord(input, index) {
81
83
  copyValue(record, key, row[key]);
82
84
  return record;
83
85
  }
86
+ export function segmentTelemetryInput(input, range) {
87
+ const segment = resolveFrameRange(range, input.frameCount);
88
+ if (!segment)
89
+ return input;
90
+ return {
91
+ ...input,
92
+ frameCount: segment.end - segment.start + 1,
93
+ frames: input.frames.slice(segment.start, segment.end + 1),
94
+ headingDeg: input.headingDeg.slice(segment.start, segment.end + 1),
95
+ frameStart: segment.start,
96
+ };
97
+ }
84
98
  export function buildTelemetryDocument(input) {
85
99
  if (input.headingDeg.length !== input.frameCount) {
86
100
  throw new Error('telemetry JSON: heading count does not match the frame count');
@@ -102,6 +116,11 @@ export function buildTelemetryDocument(input) {
102
116
  export function serializeTelemetryDocument(doc) {
103
117
  return `${JSON.stringify(doc, null, 2)}\n`;
104
118
  }
119
+ export function writeTelemetryDocument(file, input) {
120
+ const doc = buildTelemetryDocument(input);
121
+ fs.mkdirSync(path.dirname(file), { recursive: true });
122
+ fs.writeFileSync(file, serializeTelemetryDocument(doc));
123
+ }
105
124
  export function generateTelemetryJsonSchema() {
106
125
  return `${JSON.stringify(z.toJSONSchema(TelemetryDocumentSchema), null, 2)}\n`;
107
126
  }
@@ -1,4 +1,5 @@
1
1
  import { bearingDeg, circularMeanDeg, haversineM } from './geo.js';
2
+ import { timeAt } from './frametime.js';
2
3
  const MAX_INTERPOLATION_GAP_S = 3;
3
4
  const SPEED_SMOOTHING_SPAN = 5;
4
5
  const HEADING_MIN_MOVE_M = 1.5;
@@ -214,7 +215,7 @@ function firstKnownHeading(rawHeading) {
214
215
  function buildFrameData(samples, frames, fpsValue, speedBySample, headingBySample) {
215
216
  const frameData = [];
216
217
  for (let frame = 0; frame < frames; frame++) {
217
- const t = frame / fpsValue;
218
+ const t = timeAt(frame, fpsValue);
218
219
  const pos = positionAt(samples, t);
219
220
  const si = nearestSampleIndex(samples, t);
220
221
  frameData.push({
@@ -242,7 +243,7 @@ function bridgeMissingFramePositions(frameData) {
242
243
  trail--;
243
244
  }
244
245
  }
245
- export function buildTelemetry(loaded, timing) {
246
+ export function computeTelemetry(loaded, timing) {
246
247
  const { samples, source, method, noLock } = loaded;
247
248
  const fixes = fixRefs(samples);
248
249
  if (fixes.length < 2)
@@ -3,15 +3,15 @@ export function telemetrySummary(tel) {
3
3
  source: tel.source,
4
4
  method: tel.method,
5
5
  headingMode: tel.headingMode,
6
- fixes: tel.fixCount,
6
+ fixCount: tel.fixCount,
7
7
  noLock: tel.noLock,
8
8
  trackDistanceM: Math.round(tel.trackDistanceM),
9
9
  };
10
10
  }
11
- export function fixesLabel(fixes) {
12
- return `${fixes} fixes`;
11
+ export function fixCountLabel(fixCount) {
12
+ return `${fixCount} fixes`;
13
13
  }
14
- export function noLockCuesLabel(noLock) {
14
+ export function noLockCountLabel(noLock) {
15
15
  return `${noLock} no-lock cues`;
16
16
  }
17
17
  export function trackDistanceLabel(trackDistanceM) {