drone-path 0.0.0 → 0.8.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 +179 -0
- package/LICENSE +21 -0
- package/README.md +83 -6
- package/THIRD-PARTY-NOTICES.md +77 -0
- package/app/main.mjs +496 -0
- package/app/preload.cjs +31 -0
- package/app/update-policy.d.mts +6 -0
- package/app/update-policy.mjs +6 -0
- package/app/update.d.mts +10 -0
- package/app/update.mjs +54 -0
- package/bin/drone-path.mjs +5 -0
- package/dist/appassets.js +44 -0
- package/dist/apppaths.js +28 -0
- package/dist/appsession.js +128 -0
- package/dist/appstate.js +109 -0
- package/dist/assets.js +67 -0
- package/dist/cammeta.js +292 -0
- package/dist/changeset-gate.js +46 -0
- package/dist/cli.js +156 -0
- package/dist/config.js +469 -0
- package/dist/configfile.js +81 -0
- package/dist/decimate.js +94 -0
- package/dist/errors.js +4 -0
- package/dist/exportjob.js +106 -0
- package/dist/ff.js +121 -0
- package/dist/fftools.js +65 -0
- package/dist/geo.js +70 -0
- package/dist/inputs.js +59 -0
- package/dist/manual/anchors.js +23 -0
- package/dist/manual/build.js +78 -0
- package/dist/manual/cliref.js +36 -0
- package/dist/manual/links.js +76 -0
- package/dist/manual/markdown.js +101 -0
- package/dist/manual/model.js +4 -0
- package/dist/manual/module.js +8 -0
- package/dist/manual/nav.js +13 -0
- package/dist/manual/reference.js +26 -0
- package/dist/page.js +108 -0
- package/dist/paths.js +28 -0
- package/dist/plan.js +119 -0
- package/dist/png.js +52 -0
- package/dist/proto.js +102 -0
- package/dist/range.js +58 -0
- package/dist/render.js +408 -0
- package/dist/renderer/boot.js +7 -0
- package/dist/renderer/dom.js +132 -0
- package/dist/renderer/framemath.js +34 -0
- package/dist/renderer/leaflet.js +5 -0
- package/dist/renderer/scene.js +358 -0
- package/dist/renderer/theme.js +34 -0
- package/dist/renderer/tilesources.js +34 -0
- package/dist/renderer/trail.js +53 -0
- package/dist/restyle.js +24 -0
- package/dist/run.js +446 -0
- package/dist/serve.js +70 -0
- package/dist/srt.js +76 -0
- package/dist/summary.js +22 -0
- package/dist/telemetry-math.js +302 -0
- package/dist/telemetry.js +38 -0
- package/dist/tilecache.js +26 -0
- package/dist/tiles.js +241 -0
- package/dist/tracing.js +208 -0
- package/dist/version.js +3 -0
- package/package.json +93 -7
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Session vocabulary and state machine for the desktop app, free of Electron
|
|
2
|
+
// APIs: pick -> validate -> prepare -> hold one prepared recording.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { TILE_BASE, mediaUrlFor } from './apppaths.js';
|
|
6
|
+
import { STYLE_VALUES, VIEW_VALUES, asNumber } from './config.js';
|
|
7
|
+
import { errorMessage } from './errors.js';
|
|
8
|
+
import { isRecordingName } from './inputs.js';
|
|
9
|
+
import { buildSceneData } from './page.js';
|
|
10
|
+
import { prepareSession, recordingPageOpts } from './run.js';
|
|
11
|
+
/** Frame-exact duration from the reported frames and rate, not the container's. */
|
|
12
|
+
export function frameExactDuration(probe) {
|
|
13
|
+
return probe.frames / probe.fps.value;
|
|
14
|
+
}
|
|
15
|
+
// The IPC boundary's vocabulary check: whatever the renderer sends, the
|
|
16
|
+
// preparation only ever plans from a valid look.
|
|
17
|
+
export function parsePickRequest(raw) {
|
|
18
|
+
const input = typeof raw === 'object' && raw !== null ? raw : {};
|
|
19
|
+
const look = typeof input.settings === 'object' && input.settings !== null
|
|
20
|
+
? input.settings
|
|
21
|
+
: {};
|
|
22
|
+
const { style, view, hud } = look;
|
|
23
|
+
if (typeof style !== 'string' || !STYLE_VALUES.includes(style)) {
|
|
24
|
+
throw new Error(`unknown map style: ${String(style)}`);
|
|
25
|
+
}
|
|
26
|
+
if (typeof view !== 'string' || !VIEW_VALUES.includes(view)) {
|
|
27
|
+
throw new Error(`unknown view: ${String(view)}`);
|
|
28
|
+
}
|
|
29
|
+
const zoom = asNumber(look.zoom, 'zoom');
|
|
30
|
+
const zoomOut = asNumber(look.zoomOut, 'zoom-out');
|
|
31
|
+
if (!(zoom >= 0))
|
|
32
|
+
throw new Error('zoom must be >= 0 (0 = auto-fit)');
|
|
33
|
+
if (!(zoomOut >= 0))
|
|
34
|
+
throw new Error('zoom-out must be >= 0');
|
|
35
|
+
const introSec = asNumber(look.introSec, 'intro');
|
|
36
|
+
const outroSec = asNumber(look.outroSec, 'outro');
|
|
37
|
+
if (!(introSec >= 0))
|
|
38
|
+
throw new Error('intro must be 0 or more');
|
|
39
|
+
if (!(outroSec >= 0))
|
|
40
|
+
throw new Error('outro must be 0 or more');
|
|
41
|
+
const chips = typeof hud === 'object' && hud !== null ? hud : {};
|
|
42
|
+
return {
|
|
43
|
+
settings: {
|
|
44
|
+
style: style,
|
|
45
|
+
view: view,
|
|
46
|
+
zoom,
|
|
47
|
+
zoomOut,
|
|
48
|
+
hud: { heading: !!chips.heading, alt: !!chips.alt, speed: !!chips.speed },
|
|
49
|
+
introSec,
|
|
50
|
+
outroSec,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// The shared pipeline preparation plus the scene data the UI drives: probe,
|
|
55
|
+
// telemetry and the view plan — no tile wait, so the footage shows right away
|
|
56
|
+
// and the map fetches its tiles on demand.
|
|
57
|
+
export const prepareUiSession = async (videoPath, config, log, onProgress, deps) => {
|
|
58
|
+
const prep = await prepareSession(videoPath, config, log, {
|
|
59
|
+
onProgress,
|
|
60
|
+
deps,
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
scene: buildSceneData(recordingPageOpts(prep, config), TILE_BASE),
|
|
64
|
+
video: {
|
|
65
|
+
src: mediaUrlFor(videoPath),
|
|
66
|
+
fps: prep.probe.fps.value,
|
|
67
|
+
frames: prep.probe.frames,
|
|
68
|
+
width: prep.probe.width,
|
|
69
|
+
height: prep.probe.height,
|
|
70
|
+
},
|
|
71
|
+
tileBase: TILE_BASE,
|
|
72
|
+
bbox: prep.tel.bbox,
|
|
73
|
+
durationSec: frameExactDuration(prep.probe),
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
function isReadableVideo(filePath) {
|
|
77
|
+
if (!isRecordingName(filePath))
|
|
78
|
+
return false;
|
|
79
|
+
try {
|
|
80
|
+
return fs.statSync(filePath).isFile();
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export function createAppSession(options) {
|
|
87
|
+
const { config, pickFile } = options;
|
|
88
|
+
const prepare = options.prepare ?? prepareUiSession;
|
|
89
|
+
const log = options.log ?? (() => { });
|
|
90
|
+
const onPreparing = options.onPreparing ?? (() => { });
|
|
91
|
+
const onPrepareProgress = options.onPrepareProgress ?? (() => { });
|
|
92
|
+
let session = null;
|
|
93
|
+
let videoPath = null;
|
|
94
|
+
let picking = false;
|
|
95
|
+
return {
|
|
96
|
+
async pick(request) {
|
|
97
|
+
if (picking)
|
|
98
|
+
return { ok: false, error: 'a pick is already in progress' };
|
|
99
|
+
picking = true;
|
|
100
|
+
try {
|
|
101
|
+
const picked = await pickFile();
|
|
102
|
+
if (picked === null)
|
|
103
|
+
return { ok: false, canceled: true };
|
|
104
|
+
const resolved = path.resolve(picked);
|
|
105
|
+
if (!isReadableVideo(resolved)) {
|
|
106
|
+
log(`rejected: ${resolved}`);
|
|
107
|
+
return { ok: false, error: `not a readable .mp4 file: ${resolved}` };
|
|
108
|
+
}
|
|
109
|
+
onPreparing(resolved);
|
|
110
|
+
// The renderer's current look prepares the recording, so the prepared
|
|
111
|
+
// scene matches what the player shows.
|
|
112
|
+
session = await prepare(resolved, { ...config, ...request.settings }, log, onPrepareProgress);
|
|
113
|
+
videoPath = resolved;
|
|
114
|
+
log(`loaded: ${resolved}`);
|
|
115
|
+
return { ok: true };
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
log(`error: ${errorMessage(e)}`);
|
|
119
|
+
return { ok: false, error: errorMessage(e) };
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
picking = false;
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
getSession: () => session,
|
|
126
|
+
videoPath: () => videoPath,
|
|
127
|
+
};
|
|
128
|
+
}
|
package/dist/appstate.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// The desktop app's per-user state: the settings panel's last look in
|
|
2
|
+
// option-vocabulary values and the folder the last recording was opened from.
|
|
3
|
+
// Parsing and merging stay pure; the file I/O below them is the thin shell the
|
|
4
|
+
// app seeds from and flushes to.
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { DEFAULT_CONFIG, SETTINGS_KEYS, formatHud, parseSettingsPatch } from './config.js';
|
|
8
|
+
export const APP_STATE_VERSION = 1;
|
|
9
|
+
export function emptyAppState() {
|
|
10
|
+
return { settings: null, lastOpenDir: null };
|
|
11
|
+
}
|
|
12
|
+
// Older settings objects read tolerantly: a key their writer did not know
|
|
13
|
+
// starts at its documented default, so an upgrade keeps the look the user
|
|
14
|
+
// chose. A present-but-mistyped value (null included) stays the parser's
|
|
15
|
+
// business and fails the state.
|
|
16
|
+
function fillMissingSettings(raw) {
|
|
17
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
|
|
18
|
+
return raw;
|
|
19
|
+
const filled = { ...raw };
|
|
20
|
+
for (const key of SETTINGS_KEYS) {
|
|
21
|
+
if (!(key in filled))
|
|
22
|
+
filled[key] = DEFAULT_CONFIG[key];
|
|
23
|
+
}
|
|
24
|
+
return filled;
|
|
25
|
+
}
|
|
26
|
+
// The state falls back as a whole: a file whose shape this build cannot read
|
|
27
|
+
// is outdated or corrupt, and keeping parts of it would restore a look the
|
|
28
|
+
// user never chose.
|
|
29
|
+
export function parseAppState(raw) {
|
|
30
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
31
|
+
throw new Error('invalid app state');
|
|
32
|
+
}
|
|
33
|
+
const r = raw;
|
|
34
|
+
for (const key of Object.keys(r)) {
|
|
35
|
+
if (key !== 'version' && key !== 'settings' && key !== 'lastOpenDir') {
|
|
36
|
+
throw new Error(`unknown app state key ${key}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (r.version !== APP_STATE_VERSION) {
|
|
40
|
+
throw new Error(`unsupported app state version: ${String(r.version)}`);
|
|
41
|
+
}
|
|
42
|
+
const settings = r.settings === undefined || r.settings === null
|
|
43
|
+
? null
|
|
44
|
+
: parseSettingsPatch(fillMissingSettings(r.settings), 'app state');
|
|
45
|
+
if (r.lastOpenDir !== undefined && r.lastOpenDir !== null && typeof r.lastOpenDir !== 'string') {
|
|
46
|
+
throw new Error(`invalid app state: lastOpenDir: ${String(r.lastOpenDir)}`);
|
|
47
|
+
}
|
|
48
|
+
const lastOpenDir = typeof r.lastOpenDir === 'string' ? r.lastOpenDir : null;
|
|
49
|
+
return { settings, lastOpenDir };
|
|
50
|
+
}
|
|
51
|
+
// The file's option values use the config-file spelling (the HUD spec as its
|
|
52
|
+
// CLI string), so a state file reads like .dronepath.json.
|
|
53
|
+
export function serializeAppState(state) {
|
|
54
|
+
const out = { version: APP_STATE_VERSION };
|
|
55
|
+
if (state.settings) {
|
|
56
|
+
const settings = {};
|
|
57
|
+
for (const key of SETTINGS_KEYS) {
|
|
58
|
+
settings[key] =
|
|
59
|
+
key === 'hud' ? formatHud(state.settings.hud) : state.settings[key];
|
|
60
|
+
}
|
|
61
|
+
out.settings = settings;
|
|
62
|
+
}
|
|
63
|
+
if (state.lastOpenDir !== null)
|
|
64
|
+
out.lastOpenDir = state.lastOpenDir;
|
|
65
|
+
return `${JSON.stringify(out, null, 2)}\n`;
|
|
66
|
+
}
|
|
67
|
+
// The persisted look seeds the panel and the export base; machine-owned values
|
|
68
|
+
// always stay whatever the config layers resolved.
|
|
69
|
+
export function applyAppState(config, state) {
|
|
70
|
+
if (!state.settings)
|
|
71
|
+
return config;
|
|
72
|
+
return {
|
|
73
|
+
...config,
|
|
74
|
+
...state.settings,
|
|
75
|
+
// hud is an object; the winner is copied so no two configs share it.
|
|
76
|
+
hud: { ...state.settings.hud },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export function rememberOpenedFile(state, filePath) {
|
|
80
|
+
return { ...state, lastOpenDir: path.dirname(filePath) };
|
|
81
|
+
}
|
|
82
|
+
// A missing or unusable state file is a fresh install: never a failure the
|
|
83
|
+
// launch would die on.
|
|
84
|
+
export function readAppState(file) {
|
|
85
|
+
let text;
|
|
86
|
+
try {
|
|
87
|
+
text = fs.readFileSync(file, 'utf8');
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return emptyAppState();
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
return parseAppState(JSON.parse(text));
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return emptyAppState();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export function writeAppState(file, state) {
|
|
100
|
+
try {
|
|
101
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
102
|
+
fs.writeFileSync(file, serializeAppState(state));
|
|
103
|
+
}
|
|
104
|
+
catch (e) {
|
|
105
|
+
throw new Error(`cannot write app state ${file}: ${e.message}`, {
|
|
106
|
+
cause: e,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
package/dist/assets.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Pure URL-to-file routing shared by the render server and the app bundle:
|
|
2
|
+
// maps a request pathname to the resource that backs it. The route guards
|
|
3
|
+
// and the tile acceptance policy live here so they stay unit-testable; the
|
|
4
|
+
// servers only perform the I/O.
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { parseTilePathname, tilePaths } from './tilecache.js';
|
|
7
|
+
export const MIME = {
|
|
8
|
+
'.html': 'text/html; charset=utf-8',
|
|
9
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
10
|
+
'.css': 'text/css; charset=utf-8',
|
|
11
|
+
'.json': 'application/json; charset=utf-8',
|
|
12
|
+
'.txt': 'text/plain; charset=utf-8',
|
|
13
|
+
'.svg': 'image/svg+xml',
|
|
14
|
+
'.ico': 'image/x-icon',
|
|
15
|
+
'.png': 'image/png',
|
|
16
|
+
'.mp4': 'video/mp4',
|
|
17
|
+
};
|
|
18
|
+
export function mimeFor(filePath) {
|
|
19
|
+
return MIME[path.extname(filePath).toLowerCase()] ?? 'application/octet-stream';
|
|
20
|
+
}
|
|
21
|
+
export function resolveTileRoute(pathname, tileCache, policy) {
|
|
22
|
+
const parsed = parseTilePathname(pathname);
|
|
23
|
+
if (!parsed)
|
|
24
|
+
return null;
|
|
25
|
+
if (!('anyStyle' in policy) && parsed.style !== policy.style)
|
|
26
|
+
return null;
|
|
27
|
+
const paths = tilePaths(tileCache, parsed.style, parsed.tile);
|
|
28
|
+
return {
|
|
29
|
+
style: parsed.style,
|
|
30
|
+
tile: parsed.tile,
|
|
31
|
+
filePath: paths.file,
|
|
32
|
+
placeholderPath: paths.placeholder,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Serves /leaflet/*, /tiles/* and /renderer/*: the whitelist guards decide
|
|
36
|
+
// what may be served, and every /tiles/ URL is claimed (missing tiles are the
|
|
37
|
+
// caller's 404).
|
|
38
|
+
export function resolveAsset(url, routes) {
|
|
39
|
+
if (url.startsWith('/leaflet/')) {
|
|
40
|
+
const rel = url.slice('/leaflet/'.length);
|
|
41
|
+
if (!/^(leaflet\.(js|css|js\.map|css\.map)|images\/[a-z0-9_-]+\.png)$/.test(rel)) {
|
|
42
|
+
return { kind: 'missing' };
|
|
43
|
+
}
|
|
44
|
+
return fileResolution(path.join(routes.leafletDir, rel));
|
|
45
|
+
}
|
|
46
|
+
if (url.startsWith('/tiles/')) {
|
|
47
|
+
const tile = resolveTileRoute(url, routes.tileCache, { style: routes.style });
|
|
48
|
+
return tile
|
|
49
|
+
? {
|
|
50
|
+
kind: 'file',
|
|
51
|
+
filePath: tile.filePath,
|
|
52
|
+
fallbackPath: tile.placeholderPath,
|
|
53
|
+
mime: mimeFor(tile.filePath),
|
|
54
|
+
}
|
|
55
|
+
: { kind: 'missing' };
|
|
56
|
+
}
|
|
57
|
+
if (url.startsWith('/renderer/')) {
|
|
58
|
+
const rel = url.slice('/renderer/'.length);
|
|
59
|
+
if (!/^[a-z0-9_-]+\.js$/.test(rel))
|
|
60
|
+
return { kind: 'missing' };
|
|
61
|
+
return fileResolution(path.join(routes.rendererDir, rel));
|
|
62
|
+
}
|
|
63
|
+
return { kind: 'unrouted' };
|
|
64
|
+
}
|
|
65
|
+
function fileResolution(filePath) {
|
|
66
|
+
return { kind: 'file', filePath, mime: mimeFor(filePath) };
|
|
67
|
+
}
|
package/dist/cammeta.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
// Format (reverse-engineered and verified value-by-value against .SRT data):
|
|
2
|
+
// * the MP4 carries a `data` stream, sample-entry fourcc `djmd`, handler
|
|
3
|
+
// "CAM meta"; its payload is DJI's internal "DVTM" (DJI Video Metadata)
|
|
4
|
+
// protobuf: one ProductMeta message per MP4 sample = one video frame.
|
|
5
|
+
// Messages are VARIABLE length (e.g. 299-563 B on DJI Neo 2) - never
|
|
6
|
+
// assume a fixed stride; split the raw dump by ffprobe packet sizes so
|
|
7
|
+
// each message aligns to its packet PTS (= frame time).
|
|
8
|
+
// * ProductMeta { 1 clip_meta, 2 stream_meta, 3 frame_meta } (clip/stream
|
|
9
|
+
// meta appear only in the first sample).
|
|
10
|
+
// * frame_meta { 1 header, 2 camera, 3 imu (absent on Neo 2), 4 drone,
|
|
11
|
+
// 5 gimbal }:
|
|
12
|
+
// - camera.11 AbsoluteAltitude { 1 float32 meters MSL }
|
|
13
|
+
// - drone.3 EulerAngle { 1 pitch, 2 roll, 3 yaw } varint deci-degrees
|
|
14
|
+
// (yaw = drone heading, valid even while hovering)
|
|
15
|
+
// - drone.4 GpsBasic { 1 PositionCoord { 2 lat, 3 lon } doubles WGS84,
|
|
16
|
+
// 2 gps_altitude_mm varint }
|
|
17
|
+
// - drone.5 RelativeAltitude { 1 float32 millimeters above takeoff }
|
|
18
|
+
// * No epoch timestamp in-stream (frame_timestamp is microseconds since
|
|
19
|
+
// power-up); sample index == frame index.
|
|
20
|
+
// * Schemas: recovered DJI .proto files in AdrianEddy/telemetry-parser
|
|
21
|
+
// (MIT/Apache-2.0, dvtm_library.proto / dvtm_eagle4_wa530.proto);
|
|
22
|
+
// there is no official DJI spec and no public dvtm_NEO2.proto, but the
|
|
23
|
+
// Neo 2 layout matches those schemas.
|
|
24
|
+
//
|
|
25
|
+
// Robustness: a per-packet protobuf walk is the primary path; a whole-buffer
|
|
26
|
+
// byte scan of the GPS double pair (tag 0x11 lat / 0x19 lon) is the fallback
|
|
27
|
+
// for firmware layouts we do not understand.
|
|
28
|
+
import { execFile } from 'node:child_process';
|
|
29
|
+
import fs from 'node:fs';
|
|
30
|
+
import os from 'node:os';
|
|
31
|
+
import path from 'node:path';
|
|
32
|
+
import { promisify } from 'node:util';
|
|
33
|
+
import { ffprobeJson } from './ff.js';
|
|
34
|
+
import { gpsFix } from './geo.js';
|
|
35
|
+
import { firstDouble, firstFloat, firstVarint, parseProtoFields, subMessage, } from './proto.js';
|
|
36
|
+
const execFileAsync = promisify(execFile);
|
|
37
|
+
// DVTM field numbers (see the module comment for the message layout).
|
|
38
|
+
const FRAME_META = 3;
|
|
39
|
+
const CAMERA = 2;
|
|
40
|
+
const ABSOLUTE_ALTITUDE = 11;
|
|
41
|
+
const DRONE = 4;
|
|
42
|
+
const GPS_BASIC = 4;
|
|
43
|
+
const POSITION_COORD = 1;
|
|
44
|
+
const GPS_ALTITUDE_MM = 2;
|
|
45
|
+
const RELATIVE_ALTITUDE = 5;
|
|
46
|
+
const EULER_ANGLE = 3;
|
|
47
|
+
const VALUE = 1;
|
|
48
|
+
const PITCH = 1;
|
|
49
|
+
const ROLL = 2;
|
|
50
|
+
const YAW = 3;
|
|
51
|
+
const LAT = 2;
|
|
52
|
+
const LON = 3;
|
|
53
|
+
// Size of the 0x11/0x19 fixed64 GPS double pair scanned by the fallback.
|
|
54
|
+
const GPS_PAIR_SPAN = 18;
|
|
55
|
+
const FFMPEG_MAX_BUFFER = 64 * 1024 * 1024;
|
|
56
|
+
function emptyProductMeta() {
|
|
57
|
+
return {
|
|
58
|
+
fix: null,
|
|
59
|
+
noLock: false,
|
|
60
|
+
relAlt: null,
|
|
61
|
+
absAlt: null,
|
|
62
|
+
yawDeg: null,
|
|
63
|
+
pitchDeg: null,
|
|
64
|
+
rollDeg: null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function findCamMetaIndex(tools, videoPath) {
|
|
68
|
+
let probe;
|
|
69
|
+
try {
|
|
70
|
+
probe = await ffprobeJson(tools, videoPath, [
|
|
71
|
+
'-select_streams',
|
|
72
|
+
'd',
|
|
73
|
+
'-show_entries',
|
|
74
|
+
'stream=index:stream_tags=handler_name',
|
|
75
|
+
'-of',
|
|
76
|
+
'json',
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
throw new Error('ffprobe failed while probing the cam meta stream', { cause: e });
|
|
81
|
+
}
|
|
82
|
+
const streams = (probe['streams'] ?? []);
|
|
83
|
+
for (const stream of streams) {
|
|
84
|
+
if (stream.tags && stream.tags.handler_name === 'CAM meta')
|
|
85
|
+
return stream.index;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
export function decodeProductMeta(buf, start = 0, end = buf.length) {
|
|
90
|
+
const top = parseProtoFields(buf, start, end);
|
|
91
|
+
const frameMeta = subMessage(buf, top, FRAME_META);
|
|
92
|
+
const absAlt = frameMeta ? decodeAbsoluteAltitude(buf, frameMeta) : null;
|
|
93
|
+
const drone = frameMeta ? subMessage(buf, frameMeta, DRONE) : null;
|
|
94
|
+
const gps = drone ? decodeGps(buf, drone) : null;
|
|
95
|
+
const euler = drone ? decodeEulerAngles(buf, drone) : null;
|
|
96
|
+
return {
|
|
97
|
+
fix: gps?.fix ?? null,
|
|
98
|
+
noLock: gps?.noLock ?? false,
|
|
99
|
+
relAlt: drone ? decodeRelativeAltitude(buf, drone) : null,
|
|
100
|
+
// camera.11 is authoritative; gps_altitude_mm is its fallback.
|
|
101
|
+
absAlt: absAlt ?? gps?.gpsAltM ?? null,
|
|
102
|
+
yawDeg: euler?.yawDeg ?? null,
|
|
103
|
+
pitchDeg: euler?.pitchDeg ?? null,
|
|
104
|
+
rollDeg: euler?.rollDeg ?? null,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// camera.11 AbsoluteAltitude { 1 float32 meters MSL }.
|
|
108
|
+
function decodeAbsoluteAltitude(buf, frameMeta) {
|
|
109
|
+
const camera = subMessage(buf, frameMeta, CAMERA);
|
|
110
|
+
const absoluteAltitude = camera && subMessage(buf, camera, ABSOLUTE_ALTITUDE);
|
|
111
|
+
return absoluteAltitude ? firstFloat(absoluteAltitude, VALUE) : null;
|
|
112
|
+
}
|
|
113
|
+
function decodeGps(buf, drone) {
|
|
114
|
+
const out = { fix: null, noLock: false, gpsAltM: null };
|
|
115
|
+
const gps = subMessage(buf, drone, GPS_BASIC);
|
|
116
|
+
if (!gps)
|
|
117
|
+
return out;
|
|
118
|
+
const coord = subMessage(buf, gps, POSITION_COORD);
|
|
119
|
+
if (coord) {
|
|
120
|
+
const lat = firstDouble(coord, LAT);
|
|
121
|
+
const lon = firstDouble(coord, LON);
|
|
122
|
+
// Only a present pair is an event: a fix, or exactly one no-lock count.
|
|
123
|
+
if (lat !== null && lon !== null) {
|
|
124
|
+
const fix = gpsFix(lat, lon);
|
|
125
|
+
if (fix !== null)
|
|
126
|
+
out.fix = fix;
|
|
127
|
+
else
|
|
128
|
+
out.noLock = true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const altitudeMm = firstVarint(gps, GPS_ALTITUDE_MM);
|
|
132
|
+
if (altitudeMm !== null)
|
|
133
|
+
out.gpsAltM = altitudeMm / 1000;
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
// drone.5 RelativeAltitude { 1 float32 millimeters above takeoff }.
|
|
137
|
+
function decodeRelativeAltitude(buf, drone) {
|
|
138
|
+
const relative = subMessage(buf, drone, RELATIVE_ALTITUDE);
|
|
139
|
+
const millimeters = relative ? firstFloat(relative, VALUE) : null;
|
|
140
|
+
return millimeters !== null && Number.isFinite(millimeters)
|
|
141
|
+
? millimeters / 1000
|
|
142
|
+
: null;
|
|
143
|
+
}
|
|
144
|
+
function decodeEulerAngles(buf, drone) {
|
|
145
|
+
const euler = subMessage(buf, drone, EULER_ANGLE);
|
|
146
|
+
if (!euler)
|
|
147
|
+
return { pitchDeg: null, rollDeg: null, yawDeg: null };
|
|
148
|
+
const pitch = firstVarint(euler, PITCH);
|
|
149
|
+
const roll = firstVarint(euler, ROLL);
|
|
150
|
+
const yaw = firstVarint(euler, YAW);
|
|
151
|
+
return {
|
|
152
|
+
pitchDeg: pitch !== null ? pitch / 10 : null,
|
|
153
|
+
rollDeg: roll !== null ? roll / 10 : null,
|
|
154
|
+
yawDeg: yaw !== null ? yaw / 10 : null,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
// Byte-scan fallback: the 0x11/0x19 fixed64 GPS double pair. It judges
|
|
158
|
+
// coordinates through src/geo.ts's gpsFix - the same rule as the protobuf
|
|
159
|
+
// path, so a genuine fix is never accepted by one path and dropped by the
|
|
160
|
+
// other.
|
|
161
|
+
export function scanGpsPair(buf, offset = 0, end = buf.length) {
|
|
162
|
+
for (let i = offset; i <= end - GPS_PAIR_SPAN; i++) {
|
|
163
|
+
if (buf[i] === 0x11 && buf[i + 9] === 0x19) {
|
|
164
|
+
const fix = gpsFix(buf.readDoubleLE(i + 1), buf.readDoubleLE(i + 10));
|
|
165
|
+
if (fix !== null)
|
|
166
|
+
return { fix, at: i };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
// A probe failure is operational, not absence: it surfaces with its cause so
|
|
172
|
+
// a missing or broken ffprobe is never mistaken for a stream without data.
|
|
173
|
+
async function listCamMetaPackets(tools, videoPath, streamIndex) {
|
|
174
|
+
let probe;
|
|
175
|
+
try {
|
|
176
|
+
probe = await ffprobeJson(tools, videoPath, [
|
|
177
|
+
// NOTE: bare stream index - `d:N` would mean the N-th *data* stream.
|
|
178
|
+
'-select_streams',
|
|
179
|
+
String(streamIndex),
|
|
180
|
+
'-show_entries',
|
|
181
|
+
'packet=pts_time,size',
|
|
182
|
+
'-of',
|
|
183
|
+
'json',
|
|
184
|
+
]);
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
throw new Error('ffprobe failed while listing the cam meta packets', { cause: e });
|
|
188
|
+
}
|
|
189
|
+
return (probe['packets'] ?? []).map((packet) => ({
|
|
190
|
+
tSec: Number.parseFloat(packet.pts_time),
|
|
191
|
+
size: Number.parseInt(packet.size, 10),
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
async function dumpCamMetaStream(tools, videoPath, streamIndex) {
|
|
195
|
+
const tmp = path.join(os.tmpdir(), `cammeta_${process.pid}_${Date.now().toString(36)}.bin`);
|
|
196
|
+
try {
|
|
197
|
+
try {
|
|
198
|
+
await execFileAsync(tools.ffmpeg, [
|
|
199
|
+
'-v', 'error', '-y', '-i', videoPath,
|
|
200
|
+
'-map', `0:${streamIndex}`, '-c', 'copy', '-f', 'rawvideo', tmp,
|
|
201
|
+
], { maxBuffer: FFMPEG_MAX_BUFFER });
|
|
202
|
+
}
|
|
203
|
+
catch (e) {
|
|
204
|
+
throw new Error('ffmpeg failed while dumping the cam meta stream', { cause: e });
|
|
205
|
+
}
|
|
206
|
+
return fs.readFileSync(tmp);
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
fs.rmSync(tmp, { force: true });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function toCamSample(meta, tSec) {
|
|
213
|
+
return { tSec, ...meta };
|
|
214
|
+
}
|
|
215
|
+
// Primary path: walk the dump packet by packet so each ProductMeta message
|
|
216
|
+
// aligns to its packet PTS. No-lock packets are counted like SRT counts
|
|
217
|
+
// no-lock cues so summaries agree across telemetry sources; they join the
|
|
218
|
+
// samples only under keepAll.
|
|
219
|
+
export function decodePacketSamples(buf, packets, keepAll) {
|
|
220
|
+
const samples = [];
|
|
221
|
+
let noLock = 0;
|
|
222
|
+
let offset = 0;
|
|
223
|
+
for (const packet of packets) {
|
|
224
|
+
const end = offset + packet.size;
|
|
225
|
+
let meta = decodeProductMeta(buf, offset, end);
|
|
226
|
+
if (meta.fix === null) {
|
|
227
|
+
const hit = scanGpsPair(buf, offset, end);
|
|
228
|
+
if (hit)
|
|
229
|
+
meta = { ...meta, fix: hit.fix, noLock: false };
|
|
230
|
+
}
|
|
231
|
+
if (meta.noLock)
|
|
232
|
+
noLock++;
|
|
233
|
+
if (meta.fix !== null || keepAll) {
|
|
234
|
+
// No PTS: pretend "same time as the first sample" rather than
|
|
235
|
+
// fabricating a timeline out of a sample count (unit mismatch).
|
|
236
|
+
const tSec = Number.isFinite(packet.tSec) ? packet.tSec : 0;
|
|
237
|
+
samples.push(toCamSample(meta, tSec));
|
|
238
|
+
}
|
|
239
|
+
offset = end;
|
|
240
|
+
}
|
|
241
|
+
return { samples, noLock };
|
|
242
|
+
}
|
|
243
|
+
// Fallback path: no frame alignment.
|
|
244
|
+
function scanBufferForGpsPairs(buf) {
|
|
245
|
+
const samples = [];
|
|
246
|
+
for (let i = 0; i <= buf.length - GPS_PAIR_SPAN; i++) {
|
|
247
|
+
const hit = scanGpsPair(buf, i, i + GPS_PAIR_SPAN);
|
|
248
|
+
if (hit) {
|
|
249
|
+
const meta = emptyProductMeta();
|
|
250
|
+
meta.fix = hit.fix;
|
|
251
|
+
samples.push(toCamSample(meta, 0));
|
|
252
|
+
i += GPS_PAIR_SPAN - 1;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return samples;
|
|
256
|
+
}
|
|
257
|
+
// Best effort: scan-found samples carry no real timestamps.
|
|
258
|
+
function spreadSampleTimes(samples, durationSec) {
|
|
259
|
+
const span = Number.isFinite(durationSec) && durationSec > 0
|
|
260
|
+
? durationSec
|
|
261
|
+
: samples.length;
|
|
262
|
+
samples.forEach((sample, k) => {
|
|
263
|
+
sample.tSec = (k / Math.max(1, samples.length - 1)) * span;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
// opts.keepAll keeps every per-frame message even without a GPS fix (frame
|
|
267
|
+
// index then stays aligned to video frames; lat stays null). Default false
|
|
268
|
+
// keeps only GPS-bearing frames.
|
|
269
|
+
export async function parseCamMeta(tools, videoPath, durationSec, opts = {}) {
|
|
270
|
+
const keepAll = opts.keepAll === true;
|
|
271
|
+
// Null returns below mark a genuine absence ("no CAM meta stream"); tool
|
|
272
|
+
// failures have already thrown with their cause by this point.
|
|
273
|
+
const streamIndex = await findCamMetaIndex(tools, videoPath);
|
|
274
|
+
if (streamIndex === null)
|
|
275
|
+
return null;
|
|
276
|
+
const packets = await listCamMetaPackets(tools, videoPath, streamIndex);
|
|
277
|
+
const buf = await dumpCamMetaStream(tools, videoPath, streamIndex);
|
|
278
|
+
if (buf.length === 0)
|
|
279
|
+
return null;
|
|
280
|
+
const sizeSum = packets.reduce((sum, packet) => sum + (Number.isFinite(packet.size) ? packet.size : 0), 0);
|
|
281
|
+
if (packets.length > 0 && sizeSum === buf.length) {
|
|
282
|
+
const { samples, noLock } = decodePacketSamples(buf, packets, keepAll);
|
|
283
|
+
return { samples, noLock, method: 'dvtm-packets' };
|
|
284
|
+
}
|
|
285
|
+
const samples = scanBufferForGpsPairs(buf);
|
|
286
|
+
if (samples.length === 0)
|
|
287
|
+
return null;
|
|
288
|
+
spreadSampleTimes(samples, durationSec);
|
|
289
|
+
// The scan sees complete fix pairs only - a no-lock placeholder is
|
|
290
|
+
// indistinguishable from absent bytes in raw data.
|
|
291
|
+
return { samples, noLock: 0, method: 'cammeta-scan' };
|
|
292
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Strict Conventional Commits: lowercase feat/fix only; broader spellings
|
|
2
|
+
// stay exempt on purpose.
|
|
3
|
+
const PR_TITLE_NEEDS_CHANGESET = /^(feat|fix)(\([^)]+\))?!?:/;
|
|
4
|
+
// Release PRs carry the version fold, so CHANGELOG.md must change there.
|
|
5
|
+
const PR_TITLE_NEEDS_CHANGELOG = /^release(\([^)]+\))?:/;
|
|
6
|
+
// A fragment is a top-level .changeset/*.md file; the README documents the
|
|
7
|
+
// convention and never counts as a change entry.
|
|
8
|
+
const CHANGESET_FRAGMENT_PATH = /^\.changeset\/([^/]+)\.md$/;
|
|
9
|
+
const CHANGELOG_PATH = /^CHANGELOG\.md$/;
|
|
10
|
+
export function prNeedsChangeset(prTitle) {
|
|
11
|
+
return PR_TITLE_NEEDS_CHANGESET.test(prTitle.trim());
|
|
12
|
+
}
|
|
13
|
+
export function prNeedsChangelogUpdate(prTitle) {
|
|
14
|
+
return PR_TITLE_NEEDS_CHANGELOG.test(prTitle.trim());
|
|
15
|
+
}
|
|
16
|
+
// The shell skips git entirely for ungated titles: an exempt PR must never go
|
|
17
|
+
// red because listing changed files failed.
|
|
18
|
+
export function prNeedsArtifact(prTitle) {
|
|
19
|
+
return prNeedsChangeset(prTitle) || prNeedsChangelogUpdate(prTitle);
|
|
20
|
+
}
|
|
21
|
+
export function hasChangesetFragment(changedPaths) {
|
|
22
|
+
return changedPaths.some((path) => {
|
|
23
|
+
const match = CHANGESET_FRAGMENT_PATH.exec(path);
|
|
24
|
+
return match !== null && match[1].toLowerCase() !== 'readme';
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export function hasChangelogUpdate(changedPaths) {
|
|
28
|
+
return changedPaths.some((path) => CHANGELOG_PATH.test(path));
|
|
29
|
+
}
|
|
30
|
+
export function evaluateGate(prTitle, changedPaths) {
|
|
31
|
+
const title = prTitle.trim();
|
|
32
|
+
if (prNeedsChangeset(title)) {
|
|
33
|
+
return hasChangesetFragment(changedPaths)
|
|
34
|
+
? { ok: true, note: `changeset: fragment found for '${title}'` }
|
|
35
|
+
: {
|
|
36
|
+
ok: false,
|
|
37
|
+
error: `'${title}' must add a .changeset/*.md fragment (see .changeset/README.md)`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (prNeedsChangelogUpdate(title)) {
|
|
41
|
+
return hasChangelogUpdate(changedPaths)
|
|
42
|
+
? { ok: true, note: `changeset: CHANGELOG.md updated for '${title}'` }
|
|
43
|
+
: { ok: false, error: `'${title}' must change CHANGELOG.md` };
|
|
44
|
+
}
|
|
45
|
+
return { ok: true, note: `changeset: '${title}' requires no changelog artifact` };
|
|
46
|
+
}
|