@camstack/server 1.2.928 → 1.2.930
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 +12 -0
- package/package.json +10 -10
- package/system/dist/addon-id-CVg1_r5E.mjs +39 -0
- package/system/dist/addon-id-Di0lNJ89.js +50 -0
- package/system/dist/addon-pages.cap-Df9FQwN1.js +49 -0
- package/system/dist/addon-pages.cap-DksUlE8j.mjs +44 -0
- package/system/dist/addon-settings.cap-3-TIIMq_.mjs +592 -0
- package/system/dist/addon-settings.cap-DAiE0Nb0.js +651 -0
- package/system/dist/addon-utils.mjs +1 -1
- package/system/dist/addon-widgets.cap-C4jxflbF.js +200 -0
- package/system/dist/addon-widgets.cap-D9m48X78.mjs +183 -0
- package/system/dist/base-addon-DD5dIfcZ.js +4624 -0
- package/system/dist/base-addon-Md14i7pe.mjs +4505 -0
- package/system/dist/base-device-2sL1DMm1.js +1103 -0
- package/system/dist/base-device-IuM1AwXZ.mjs +1098 -0
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +8 -6
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +6 -4
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +8 -6
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +7 -5
- package/system/dist/builtins/alerts/alerts.addon.js +113 -56
- package/system/dist/builtins/alerts/alerts.addon.mjs +60 -3
- package/system/dist/builtins/autotrack/index.js +21 -17
- package/system/dist/builtins/autotrack/index.mjs +5 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +14 -11
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +8 -5
- package/system/dist/builtins/calendars/calendars.addon.js +8 -6
- package/system/dist/builtins/calendars/calendars.addon.mjs +3 -1
- package/system/dist/builtins/camera-grid/index.js +615 -58
- package/system/dist/builtins/camera-grid/index.mjs +558 -1
- package/system/dist/builtins/composer/composer.addon.js +788 -209
- package/system/dist/builtins/composer/composer.addon.mjs +583 -4
- package/system/dist/builtins/console-logging/index.js +4 -3
- package/system/dist/builtins/console-logging/index.mjs +2 -1
- package/system/dist/builtins/core-blocks/actions-service.d.ts +18 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +8670 -386
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +8294 -11
- package/system/dist/builtins/core-blocks/tcp-connect.d.ts +3 -0
- package/system/dist/builtins/core-notifier/core-notifier.addon.js +250 -21
- package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +230 -1
- package/system/dist/builtins/device-history/device-history.addon.js +110 -31
- package/system/dist/builtins/device-history/device-history.addon.mjs +81 -2
- package/system/dist/builtins/device-manager/device-manager.addon.js +12806 -227
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +12583 -5
- package/system/dist/builtins/hub-forwarder/index.js +4 -3
- package/system/dist/builtins/hub-forwarder/index.mjs +2 -1
- package/system/dist/builtins/keychain/index.js +31 -28
- package/system/dist/builtins/keychain/index.mjs +7 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +15 -12
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +4 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +140 -39
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +106 -6
- package/system/dist/builtins/local-network/local-network.addon.js +43 -39
- package/system/dist/builtins/local-network/local-network.addon.mjs +7 -3
- package/system/dist/builtins/loki-logging/index.js +23 -17
- package/system/dist/builtins/loki-logging/index.mjs +7 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +156 -15
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +151 -10
- package/system/dist/builtins/platform-probe/index.js +25 -23
- package/system/dist/builtins/platform-probe/index.mjs +12 -10
- package/system/dist/builtins/record-entries/index.js +9 -7
- package/system/dist/builtins/record-entries/index.mjs +3 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +4 -4
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +97 -44
- package/system/dist/builtins/snapshot/index.mjs +54 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +5 -4
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +21 -20
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +87 -61
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +29 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +81 -72
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +10 -1
- package/system/dist/builtins/system-config/system-config.addon.js +17 -14
- package/system/dist/builtins/system-config/system-config.addon.mjs +118 -115
- package/system/dist/builtins/winston-logging/index.js +7 -5
- package/system/dist/builtins/winston-logging/index.mjs +3 -1
- package/system/dist/calendars.cap-CaFlShS9.js +155 -0
- package/system/dist/calendars.cap-_C4eD4fi.mjs +138 -0
- package/system/dist/camstack-error-DJ-TUAi1.js +23 -0
- package/system/dist/camstack-error-viZYfcj9.mjs +18 -0
- package/system/dist/cap-call-context-Bd76CbOW.js +95 -0
- package/system/dist/cap-call-context-DNwdgGSQ.mjs +78 -0
- package/system/dist/capability-definition-C2rJdVeX.mjs +177 -0
- package/system/dist/capability-definition-HCmTem8c.js +242 -0
- package/system/dist/{capture-engine-BcuwOSXv.js → capture-engine-DZ0LIUqA.js} +5 -4
- package/system/dist/{capture-engine-Bz7eXFjT.mjs → capture-engine-DiwbjoWp.mjs} +2 -1
- package/system/dist/command-origin-claim-Cief660O.js +35 -0
- package/system/dist/command-origin-claim-D1Wy7Qld.mjs +24 -0
- package/system/dist/composition-sources-BEUWn2s_.mjs +391 -0
- package/system/dist/composition-sources-acfR4hDq.js +408 -0
- package/system/dist/{constants-D2etJ02O.js → constants-Ba3FTIHl.js} +1 -1
- package/system/dist/constants-C860Y6U4.js +26 -0
- package/system/dist/{constants-BcUTQd1M.mjs → constants-DB4piTD5.mjs} +1 -1
- package/system/dist/constants-DCLpoF4L.mjs +21 -0
- package/system/dist/coral-accelerators-7o8hqvcN.js +564 -0
- package/system/dist/coral-accelerators-BKcXP59c.mjs +521 -0
- package/system/dist/core-blocks.cap-BMeMCBrx.js +18733 -0
- package/system/dist/core-blocks.cap-BRPsLAij.mjs +18008 -0
- package/system/dist/{custom-action-registry-N7flBDwT.mjs → custom-action-registry-B9zFBNVa.mjs} +37 -37
- package/system/dist/custom-actions-BFUSalC9.mjs +25 -0
- package/system/dist/custom-actions-D92NRi2c.js +36 -0
- package/system/dist/database-snapshot.cap-DF38e-0P.js +162 -0
- package/system/dist/database-snapshot.cap-dhrc9xnY.mjs +133 -0
- package/system/dist/declared-device-BWphj9WE.js +303 -0
- package/system/dist/declared-device-CKERA1Hi.mjs +286 -0
- package/system/dist/{device-ca-ExMN3xW3.mjs → device-ca-BLM6fccc.mjs} +2 -1
- package/system/dist/{device-ca-CU8zh9Pi.js → device-ca-C5kJE6mL.js} +7 -6
- package/system/dist/device-certificate-Cddm4Idn.mjs +91 -0
- package/system/dist/device-certificate-CguVACQO.js +162 -0
- package/system/dist/device-identifiers-BQg9EQi1.js +600 -0
- package/system/dist/device-identifiers-iSuQCKmK.mjs +529 -0
- package/system/dist/device-kind-BJ2pfsjw.mjs +78 -0
- package/system/dist/device-kind-CsSiv_YF.js +101 -0
- package/system/dist/device-manager.cap-2abwVLCM.js +2874 -0
- package/system/dist/device-manager.cap-CFZSPfUh.mjs +2749 -0
- package/system/dist/device-provider.cap-3Uvk6f5-.mjs +331 -0
- package/system/dist/device-provider.cap-D7TV2kVH.js +366 -0
- package/system/dist/{device-row-store-CeW_GWh9.mjs → device-row-store-YF3jtmkk.mjs} +4 -1
- package/system/dist/{device-row-store-BMIR-n3m.js → device-row-store-doTfMOqn.js} +12 -9
- package/system/dist/device-transitions.cap-B5w5PYU_.js +860 -0
- package/system/dist/device-transitions.cap-DojcwEuX.mjs +819 -0
- package/system/dist/device-type-CbQsnFdC.js +477 -0
- package/system/dist/device-type-DgEvK3ch.mjs +454 -0
- package/system/dist/entry-kind-D9MuVJCK.mjs +44 -0
- package/system/dist/entry-kind-cq90c--V.js +55 -0
- package/system/dist/error.cap-CSM_SRfR.mjs +3423 -0
- package/system/dist/error.cap-DBhgPeWK.js +3848 -0
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/history-catalog-BKRarIL_.js +831 -0
- package/system/dist/history-catalog-BwTeQ4Mr.mjs +802 -0
- package/system/dist/{hub-identity-Csxx2Q8k.js → hub-identity-BMdR3Mw9.js} +2 -2
- package/system/dist/{hub-identity-CYC1820R.mjs → hub-identity-DjMN9Ac2.mjs} +10 -10
- package/system/dist/{hub-mdns-ciao-By5577HM.js → hub-mdns-ciao--0v1TKME.js} +5 -5
- package/system/dist/{hub-mdns-ciao-CCDxM5qz.mjs → hub-mdns-ciao-DBrtHOcc.mjs} +2 -2
- package/system/dist/index.js +763 -151
- package/system/dist/index.mjs +832 -220
- package/system/dist/integration-instances.cap-Cl9O-k4h.mjs +538 -0
- package/system/dist/integration-instances.cap-dJIxg2_s.js +549 -0
- package/system/dist/keychain-admin.cap-Db_oFX4H.js +425 -0
- package/system/dist/keychain-admin.cap-GtM7gVGG.mjs +396 -0
- package/system/dist/l10n-Bu6aUvSY.mjs +10 -0
- package/system/dist/l10n-CGMvp7NF.js +15 -0
- package/system/dist/labels-DX5S8deC.js +81 -0
- package/system/dist/labels-DsBcU7md.mjs +64 -0
- package/system/dist/{legacy-integration-rows-door-CVwOo5aq.js → legacy-integration-rows-door-B1nzxxr5.js} +2 -2
- package/system/dist/{legacy-integration-rows-door-D9tQOUzh.mjs → legacy-integration-rows-door-nTvo_6jQ.mjs} +1 -1
- package/system/dist/log-destination.cap-CxZzAVaR.mjs +143 -0
- package/system/dist/log-destination.cap-DELPJkZ0.js +148 -0
- package/system/dist/low-power-sleep.cap-7lfVU41N.js +103 -0
- package/system/dist/low-power-sleep.cap-tGPmaZ_V.mjs +92 -0
- package/system/dist/mask-shape-Ci8Co9w0.mjs +57 -0
- package/system/dist/mask-shape-CmPA2fst.js +92 -0
- package/system/dist/metrics-provider.cap-BNmcHDkQ.mjs +405 -0
- package/system/dist/metrics-provider.cap-BcmQUt6l.js +410 -0
- package/system/dist/migration-BMjgkyG2.js +380 -0
- package/system/dist/migration-DRJAtdy7.mjs +321 -0
- package/system/dist/network-access.cap-B5TWLDCC.js +1099 -0
- package/system/dist/network-access.cap-BJnGbE6n.mjs +1004 -0
- package/system/dist/notification-rules.cap-BDh0LDhV.js +3428 -0
- package/system/dist/notification-rules.cap-DUmiMBQB.mjs +3357 -0
- package/system/dist/notification-targets-CRH-9Dy5.js +509 -0
- package/system/dist/notification-targets-DaNE-pIt.mjs +486 -0
- package/system/dist/ops-log-CB4pIdqi.mjs +64 -0
- package/system/dist/ops-log-pxt9176Z.js +81 -0
- package/system/dist/pinned-binary-BOhOSNff.js +28 -0
- package/system/dist/pinned-binary-CrIRAi4G.mjs +23 -0
- package/system/dist/platform-probe.cap-1WrMhWHx.js +250 -0
- package/system/dist/platform-probe.cap-BFeqFLtQ.mjs +233 -0
- package/system/dist/prefix-walk-BkMxoXpL.js +843 -0
- package/system/dist/prefix-walk-ifwg_ukx.mjs +790 -0
- package/system/dist/ptz-autotrack.cap-BW7w0zHD.js +229 -0
- package/system/dist/ptz-autotrack.cap-DT2GypXw.mjs +224 -0
- package/system/dist/quantity-D3g5SxsZ.mjs +114 -0
- package/system/dist/quantity-lY1KiTSZ.js +143 -0
- package/system/dist/raw-secret-migration-DxuBFtvi.js +50 -0
- package/system/dist/raw-secret-migration-iv88mLoc.mjs +39 -0
- package/system/dist/record-entries.cap-sMUhTvTU.mjs +75 -0
- package/system/dist/record-entries.cap-ti1C046R.js +80 -0
- package/system/dist/record-kind-DoBfYHCs.js +203 -0
- package/system/dist/record-kind-ub6NXqfh.mjs +162 -0
- package/system/dist/recording-archive.cap-7OrIn9e5.mjs +1299 -0
- package/system/dist/recording-archive.cap-D7bo-QSM.js +1328 -0
- package/system/dist/records.cap-ClcWV64i.js +329 -0
- package/system/dist/records.cap-CwLT2ByG.mjs +294 -0
- package/system/dist/relocate-CdVQAk-w.js +804 -0
- package/system/dist/relocate-CoZZTui1.mjs +661 -0
- package/system/dist/rename-composition-block-BJsL58Ih.js +34798 -0
- package/system/dist/rename-composition-block-OAtErZgq.mjs +33631 -0
- package/system/dist/{restore-archive-BJfyu0sG.mjs → restore-archive-CjAyKpgX.mjs} +96 -94
- package/system/dist/{restore-archive-CIFvqOze.js → restore-archive-CkTkv3Ss.js} +6 -4
- package/system/dist/scoped-settings-CylSSq_8.js +955 -0
- package/system/dist/scoped-settings-DVWUIP7Z.mjs +650 -0
- package/system/dist/server-name-BIhLuHvX.mjs +35 -0
- package/system/dist/server-name-OALNvpqC.js +52 -0
- package/system/dist/settings-store.cap-Ci4F2zul.mjs +569 -0
- package/system/dist/settings-store.cap-wlJhCspr.js +640 -0
- package/system/dist/snapshot.cap-3suPdBHV.js +250 -0
- package/system/dist/snapshot.cap-Bs8Oyaqh.mjs +245 -0
- package/system/dist/source-info-DGB7SdB_.mjs +190 -0
- package/system/dist/source-info-DtWf4k2j.js +225 -0
- package/system/dist/storage-admin.cap-BSv1NjKJ.mjs +883 -0
- package/system/dist/storage-admin.cap-he0OqvVM.js +906 -0
- package/system/dist/storage-location-CBT8GCD6.mjs +163 -0
- package/system/dist/storage-location-CTweDMZf.js +198 -0
- package/system/dist/storage-location-mode-B21UVRRX.mjs +167 -0
- package/system/dist/storage-location-mode-CS4sMzo-.js +232 -0
- package/system/dist/storage-migration.cap-CyyATY_p.js +330 -0
- package/system/dist/storage-migration.cap-D7QqGobp.mjs +313 -0
- package/system/dist/storage-occupancy.cap-2rmnS58Z.js +622 -0
- package/system/dist/storage-occupancy.cap-CqBztTl9.mjs +611 -0
- package/system/dist/storage-provider.cap-Bw0CfxVc.js +213 -0
- package/system/dist/storage-provider.cap-CMeck2w4.mjs +202 -0
- package/system/dist/stream-catalog.cap-Bp7SkgIf.mjs +6560 -0
- package/system/dist/stream-catalog.cap-D3uwePiA.js +6763 -0
- package/system/dist/streaming-shared-B8cXatuU.mjs +431 -0
- package/system/dist/streaming-shared-DQwFZOSi.js +526 -0
- package/system/dist/system-reasons-Be_k1W8g.js +25 -0
- package/system/dist/system-reasons-CYj4qwyS.mjs +20 -0
- package/system/dist/tag-BxLazvVb.js +2138 -0
- package/system/dist/tag-uZBAq6ox.mjs +2073 -0
- package/system/dist/user-management.cap-B9QDu8NE.js +825 -0
- package/system/dist/user-management.cap-DBIi77sB.mjs +766 -0
- package/system/dist/vector-store.cap-DnyfrYDn.js +330 -0
- package/system/dist/vector-store.cap-h2GHWQ1t.mjs +319 -0
- package/system/dist/{wal-maintenance-CTrCPzds.mjs → wal-maintenance-BG01rOn9.mjs} +0 -0
- package/system/dist/{wal-maintenance-dq7T3quB.js → wal-maintenance-DyrebYKF.js} +0 -0
- package/system/dist/zod-secret-DS7mj1bk.js +78 -0
- package/system/dist/zod-secret-zY4nM61M.mjs +73 -0
- package/system/package.json +1 -1
- package/system/dist/composition-sources-BI614LJx.mjs +0 -141
- package/system/dist/composition-sources-v_kkb8A9.js +0 -152
- package/system/dist/coral-accelerators-BSVsBVzt.js +0 -250
- package/system/dist/coral-accelerators-BW3OcrLD.mjs +0 -231
- package/system/dist/dist-BCHMSqzc.mjs +0 -143467
- package/system/dist/dist-BZfvhfS1.js +0 -146970
- package/system/dist/prefix-walk-DAOBSyH1.mjs +0 -88
- package/system/dist/prefix-walk-Dv6MLZlM.js +0 -99
- package/system/dist/rename-composition-block-C9HuBrKS.js +0 -112
- package/system/dist/rename-composition-block-DtaYmYAR.mjs +0 -101
|
@@ -1,10 +1,567 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as cameraGridLayoutCapability, i as motionCapability, n as MOTION_CLOSE_AFTER_MS, t as streamCatalogCapability } from "../../stream-catalog.cap-Bp7SkgIf.mjs";
|
|
2
|
+
import { _ as hydrateSchema, b as EventCategory, p as createEvent, t as BaseAddon } from "../../base-addon-Md14i7pe.mjs";
|
|
3
|
+
import { Z as errMsg } from "../../scoped-settings-DVWUIP7Z.mjs";
|
|
4
|
+
import { t as memoizePinnedFfmpeg } from "../../pinned-binary-CrIRAi4G.mjs";
|
|
5
|
+
import { f as DERIVED_CAMERA_SILENCED_CAP_NAMES } from "../../device-identifiers-iSuQCKmK.mjs";
|
|
6
|
+
import { t as DeviceFeature } from "../../device-type-DgEvK3ch.mjs";
|
|
7
|
+
import { R as COMPOSED_DEVICE_STABLE_ID_PREFIX, i as compileHelper, x as COMPOSER_ADDON_ID } from "../../error.cap-CSM_SRfR.mjs";
|
|
8
|
+
import { t as snapshotCapability } from "../../snapshot.cap-Bs8Oyaqh.mjs";
|
|
9
|
+
import { n as declarationOwnerNodeId, t as DeclaredDevices } from "../../declared-device-CKERA1Hi.mjs";
|
|
10
|
+
import { t as BaseDevice } from "../../base-device-IuM1AwXZ.mjs";
|
|
11
|
+
import { t as bareAddonId } from "../../addon-id-CVg1_r5E.mjs";
|
|
2
12
|
import { z } from "zod";
|
|
3
13
|
import { FfmpegProcess } from "@camstack/types/node";
|
|
4
14
|
import { promises } from "node:fs";
|
|
5
15
|
import { join } from "node:path";
|
|
6
16
|
import { spawn } from "node:child_process";
|
|
7
17
|
import { createServer } from "node:http";
|
|
18
|
+
//#region ../types/dist/esm/ffmpeg/invocation.mjs
|
|
19
|
+
var AUDIO_ENCODER_BY_CODEC = {
|
|
20
|
+
opus: "libopus",
|
|
21
|
+
aac: "aac",
|
|
22
|
+
pcmu: "pcm_mulaw",
|
|
23
|
+
pcma: "pcm_alaw"
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Camera-microphone audio, per codec. Lives HERE rather than in
|
|
27
|
+
* `encode-defaults.ts` only to avoid an import cycle (`encode-defaults` depends
|
|
28
|
+
* on these types); it is re-exported from there, which is where to read it.
|
|
29
|
+
*
|
|
30
|
+
* Every source in this repo is a mono camera mic. The former broker preset
|
|
31
|
+
* encoded Opus at `channels: 2`, spending bitrate duplicating one channel —
|
|
32
|
+
* that is the value this consolidation changed.
|
|
33
|
+
*/
|
|
34
|
+
var AUDIO_PRESETS = {
|
|
35
|
+
aac: {
|
|
36
|
+
kind: "encode",
|
|
37
|
+
codec: "aac",
|
|
38
|
+
bitrateKbps: 128,
|
|
39
|
+
sampleRateHz: 48e3,
|
|
40
|
+
channels: 1
|
|
41
|
+
},
|
|
42
|
+
opus: {
|
|
43
|
+
kind: "encode",
|
|
44
|
+
codec: "opus",
|
|
45
|
+
bitrateKbps: 64,
|
|
46
|
+
sampleRateHz: 48e3,
|
|
47
|
+
channels: 1
|
|
48
|
+
},
|
|
49
|
+
pcmu: {
|
|
50
|
+
kind: "encode",
|
|
51
|
+
codec: "pcmu",
|
|
52
|
+
sampleRateHz: 8e3,
|
|
53
|
+
channels: 1
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
/** `-hide_banner -loglevel <level>` — every ffmpeg site opens with this. */
|
|
57
|
+
function logBannerArgs(level) {
|
|
58
|
+
return [
|
|
59
|
+
"-hide_banner",
|
|
60
|
+
"-loglevel",
|
|
61
|
+
level
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
/** `true` when the resolved value means "decode in software" (⇒ no `-hwaccel`). */
|
|
65
|
+
function isSoftwareDecode(decodeHwAccel) {
|
|
66
|
+
return !decodeHwAccel || decodeHwAccel === "none" || decodeHwAccel === "copy";
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Every INPUT option, in order, terminated by `-i <url>`. Nothing may be
|
|
70
|
+
* appended to this list by a caller — that is the whole point of the function.
|
|
71
|
+
*/
|
|
72
|
+
function buildInputArgs(input, decodeHwAccel) {
|
|
73
|
+
const args = [];
|
|
74
|
+
if (!isSoftwareDecode(decodeHwAccel)) args.push("-hwaccel", String(decodeHwAccel));
|
|
75
|
+
if (input.extraArgs?.length) args.push(...input.extraArgs);
|
|
76
|
+
if (input.decodeThreadCount !== void 0 && input.decodeThreadCount > 0) args.push("-threads", String(input.decodeThreadCount));
|
|
77
|
+
if (input.analyzeDurationUs !== void 0) args.push("-analyzeduration", String(input.analyzeDurationUs));
|
|
78
|
+
if (input.probeSizeBytes !== void 0) args.push("-probesize", String(input.probeSizeBytes));
|
|
79
|
+
if (input.lowDelay === true) args.push("-flags", "low_delay");
|
|
80
|
+
if (input.useWallclockTimestamps === true) args.push("-use_wallclock_as_timestamps", "1");
|
|
81
|
+
if (input.fflags?.length) for (const flag of input.fflags) args.push("-fflags", flag);
|
|
82
|
+
if (input.rtspTransport) args.push("-rtsp_transport", input.rtspTransport);
|
|
83
|
+
if (input.rawVideo !== void 0) {
|
|
84
|
+
const raw = input.rawVideo;
|
|
85
|
+
args.push("-f", "rawvideo", "-pix_fmt", raw.pixelFormat, "-video_size", `${String(raw.width)}x${String(raw.height)}`, "-framerate", String(raw.framerate));
|
|
86
|
+
}
|
|
87
|
+
args.push("-i", input.url);
|
|
88
|
+
return args;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Derive the output `-map` selectors. The three cases, in the order they are
|
|
92
|
+
* decided:
|
|
93
|
+
*
|
|
94
|
+
* 1. **A filter graph** — the picture is the graph's declared video pad, and
|
|
95
|
+
* the audio is its audio pad when it has one, otherwise input 0's mic. A
|
|
96
|
+
* graph's output is not addressable any other way.
|
|
97
|
+
* 2. **N inputs, no graph** — map input 0 EXPLICITLY. ffmpeg's own selection
|
|
98
|
+
* picks the "best" stream across ALL inputs, so the egress would silently
|
|
99
|
+
* become whichever camera happens to have the largest frame.
|
|
100
|
+
* 3. **One input, no graph** — no `-map`. Anything else would change the argv
|
|
101
|
+
* of every call site that exists today for no gain.
|
|
102
|
+
*/
|
|
103
|
+
function resolveStreamMaps(selection) {
|
|
104
|
+
const graph = selection.filterGraph;
|
|
105
|
+
if (graph) return {
|
|
106
|
+
video: `[${graph.videoOutLabel}]`,
|
|
107
|
+
audio: graph.audioOutLabel ? `[${graph.audioOutLabel}]` : "0:a:0?"
|
|
108
|
+
};
|
|
109
|
+
if (selection.extraInputs?.length) return {
|
|
110
|
+
video: "0:v:0",
|
|
111
|
+
audio: "0:a:0?"
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
video: null,
|
|
115
|
+
audio: null
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** The `-vf` filter args, or `[]` when a consumer `-vf` already claims the slot. */
|
|
119
|
+
function buildVideoFilterArgs(scale, outputArgs, filterGraph, hwUpload) {
|
|
120
|
+
if (filterGraph) {
|
|
121
|
+
if (scale) throw new Error("FfmpegInvocation: video.scale cannot be combined with a filter graph — scale inside the graph instead (the -vf would feed an output the graph already feeds)");
|
|
122
|
+
if (outputArgs.some((a) => a === "-vf")) throw new Error("FfmpegInvocation: outputArgs carries a -vf while a filter graph feeds the same output — fold the filter into the graph");
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
if (outputArgs.some((a) => a === "-vf")) return [];
|
|
126
|
+
if (!scale) return hwUpload.length > 0 ? ["-vf", hwUpload] : [];
|
|
127
|
+
const suffix = hwUpload.length > 0 ? `,${hwUpload}` : "";
|
|
128
|
+
if (scale.mode === "exact") return ["-vf", `scale=${scale.width}:${scale.height}${suffix}`];
|
|
129
|
+
return ["-vf", `scale='min(${scale.width},iw)':'min(${scale.height},ih)':force_original_aspect_ratio=decrease:force_divisible_by=2${suffix}`];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The upload filter a hardware encode needs, or `''`.
|
|
133
|
+
*
|
|
134
|
+
* Nothing is uploaded when the DECODE already left the frames on the GPU
|
|
135
|
+
* (`-hwaccel vaapi`): they are surfaces already, and uploading a surface is an
|
|
136
|
+
* error rather than a no-op.
|
|
137
|
+
*/
|
|
138
|
+
function resolveHwUpload(device, decodeHwAccel) {
|
|
139
|
+
if (device === void 0) return "";
|
|
140
|
+
if (!isSoftwareDecode(decodeHwAccel)) return "";
|
|
141
|
+
return "format=nv12,hwupload";
|
|
142
|
+
}
|
|
143
|
+
/** Rate-control args for an encode plan. */
|
|
144
|
+
function buildRateControlArgs(video) {
|
|
145
|
+
const kbps = video.bitrateKbps;
|
|
146
|
+
if (kbps === void 0) return [];
|
|
147
|
+
const rc = video.rateControl ?? {
|
|
148
|
+
kind: "cap",
|
|
149
|
+
vbvSeconds: 2
|
|
150
|
+
};
|
|
151
|
+
const bufsize = Math.max(1, Math.round(kbps * rc.vbvSeconds));
|
|
152
|
+
return [
|
|
153
|
+
...rc.kind === "cbr" ? ["-b:v", `${kbps}k`] : rc.targetFraction !== void 0 ? ["-b:v", `${Math.max(1, Math.round(kbps * rc.targetFraction))}k`] : [],
|
|
154
|
+
"-maxrate",
|
|
155
|
+
`${kbps}k`,
|
|
156
|
+
"-bufsize",
|
|
157
|
+
`${bufsize}k`
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
/** The whole video block (`-vf` … `-c:v` … knobs), after `-i`. */
|
|
161
|
+
function buildVideoArgs(video, outputArgs, filterGraph, hwEncode) {
|
|
162
|
+
if (video.kind === "raw") {
|
|
163
|
+
if (filterGraph && video.filter !== void 0) throw new Error("FfmpegInvocation: video.filter cannot be combined with a filter graph — fold the filter into the graph");
|
|
164
|
+
return [
|
|
165
|
+
...video.filter !== void 0 ? ["-vf", video.filter] : [],
|
|
166
|
+
"-c:v",
|
|
167
|
+
"rawvideo",
|
|
168
|
+
"-pix_fmt",
|
|
169
|
+
video.pixelFormat,
|
|
170
|
+
...video.fps !== void 0 ? ["-r", String(video.fps)] : []
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
if (video.kind === "copy") {
|
|
174
|
+
if (filterGraph) throw new Error("FfmpegInvocation: a filter graph produces a NEW picture, so video.kind must be `encode`");
|
|
175
|
+
return [
|
|
176
|
+
"-c:v",
|
|
177
|
+
"copy",
|
|
178
|
+
...video.bitstreamFilter ? ["-bsf:v", video.bitstreamFilter] : []
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
const hwUpload = hwEncode === void 0 ? "" : resolveHwUpload(hwEncode.device, hwEncode.decodeHwAccel);
|
|
182
|
+
if (hwEncode !== void 0 && filterGraph) throw new Error("FfmpegInvocation: a hardware encode fed by a filter graph must upload INSIDE the graph — hwEncodeDevice cannot be combined with filterGraph");
|
|
183
|
+
const args = [
|
|
184
|
+
...buildVideoFilterArgs(video.scale, outputArgs, filterGraph, hwUpload),
|
|
185
|
+
"-c:v",
|
|
186
|
+
video.encoder
|
|
187
|
+
];
|
|
188
|
+
if (video.preset !== void 0) args.push("-preset", video.preset);
|
|
189
|
+
if (video.tune !== void 0) args.push("-tune", video.tune);
|
|
190
|
+
if (video.singleSlicePerFrame === true && video.encoder === "libx264") args.push("-x264-params", "sliced-threads=0");
|
|
191
|
+
if (video.profile !== void 0) args.push("-profile:v", video.profile);
|
|
192
|
+
if (video.level !== void 0) args.push("-level", video.level);
|
|
193
|
+
if (video.pixelFormat !== void 0) args.push("-pix_fmt", video.pixelFormat);
|
|
194
|
+
if (video.fps !== void 0) args.push("-r", String(video.fps));
|
|
195
|
+
if (video.fpsMode !== void 0) args.push("-fps_mode", video.fpsMode);
|
|
196
|
+
if (video.gopFrames !== void 0) args.push("-g", String(video.gopFrames));
|
|
197
|
+
if (video.forceKeyFramesSeconds !== void 0) args.push("-force_key_frames", `expr:gte(t,n_forced*${video.forceKeyFramesSeconds})`);
|
|
198
|
+
if (video.bf !== void 0) args.push("-bf", String(video.bf));
|
|
199
|
+
args.push(...buildRateControlArgs(video));
|
|
200
|
+
if (video.bitstreamFilter !== void 0) args.push("-bsf:v", video.bitstreamFilter);
|
|
201
|
+
return args;
|
|
202
|
+
}
|
|
203
|
+
/** The whole audio block, after `-i`. */
|
|
204
|
+
function buildAudioArgs(audio) {
|
|
205
|
+
if (audio.kind === "none") return ["-an"];
|
|
206
|
+
if (audio.kind === "copy") return ["-c:a", "copy"];
|
|
207
|
+
const args = [];
|
|
208
|
+
if (audio.filter !== void 0) args.push("-af", audio.filter);
|
|
209
|
+
args.push("-c:a", AUDIO_ENCODER_BY_CODEC[audio.codec]);
|
|
210
|
+
if (audio.application !== void 0) args.push("-application", audio.application);
|
|
211
|
+
if (audio.frameDurationMs !== void 0) args.push("-frame_duration", String(audio.frameDurationMs));
|
|
212
|
+
if (audio.globalHeader === true) args.push("-flags", "+global_header");
|
|
213
|
+
if (audio.sampleRateHz !== void 0) args.push("-ar", String(audio.sampleRateHz));
|
|
214
|
+
if (audio.bitrateKbps !== void 0) args.push("-b:a", `${audio.bitrateKbps}k`);
|
|
215
|
+
if (audio.vbvBufferKbits !== void 0) args.push("-bufsize", `${audio.vbvBufferKbits}k`);
|
|
216
|
+
if (audio.channels !== void 0) args.push("-ac", String(audio.channels));
|
|
217
|
+
return args;
|
|
218
|
+
}
|
|
219
|
+
/** RTP output-leg args (`-payload_type`, `-ssrc`, `-sdp_file`, `-f rtp <url>`). */
|
|
220
|
+
function buildRtpOutputArgs(out) {
|
|
221
|
+
const args = [];
|
|
222
|
+
if (out.payloadType !== void 0) args.push("-payload_type", String(out.payloadType));
|
|
223
|
+
if (out.ssrc !== void 0) args.push("-ssrc", String(out.ssrc));
|
|
224
|
+
if (out.sdpFile !== void 0) args.push("-sdp_file", out.sdpFile);
|
|
225
|
+
args.push("-f", "rtp", out.url);
|
|
226
|
+
return args;
|
|
227
|
+
}
|
|
228
|
+
/** `true` when the sink is a raw elementary bytestream that cannot mux audio. */
|
|
229
|
+
function isElementaryVideoSink(sink) {
|
|
230
|
+
return sink.kind === "stdout" && (sink.container === "h264" || sink.container === "hevc");
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The fragmented-MP4 muxer flags, in the order the recorder has proven them
|
|
234
|
+
* (`recorder/addon/ffmpeg-args.ts` passes the same `movflags` string through
|
|
235
|
+
* `-segment_format_options`, across every vendor in the fleet):
|
|
236
|
+
*
|
|
237
|
+
* - `frag_keyframe` — cut a fragment at each key frame, so every fragment
|
|
238
|
+
* opens on a sync sample. HKSV's whole requirement.
|
|
239
|
+
* - `empty_moov` — write `ftyp`+`moov` up front with no samples in it, which
|
|
240
|
+
* is what makes the head a standalone INITIALISATION segment.
|
|
241
|
+
* - `default_base_moof` — fragment offsets are self-relative, so a fragment is
|
|
242
|
+
* demuxable without the bytes that preceded it. D31's byte-range read path
|
|
243
|
+
* depends on exactly this property of the recorder's segments.
|
|
244
|
+
*/
|
|
245
|
+
var FMP4_MOVFLAGS = "+frag_keyframe+empty_moov+default_base_moof";
|
|
246
|
+
/**
|
|
247
|
+
* The terminal sink args for every non-`rtp-outputs` sink. Exhaustive over the
|
|
248
|
+
* union so a new member cannot fall through to `['-f', container, 'pipe:1']`,
|
|
249
|
+
* which is what a plain `container` read would have done for `mp4` — a valid
|
|
250
|
+
* argv that writes a NON-fragmented, unseekable-to-a-pipe MP4 and produces one
|
|
251
|
+
* unusable byte stream.
|
|
252
|
+
*/
|
|
253
|
+
function buildStdoutOrRtspSinkArgs(sink) {
|
|
254
|
+
if (sink.kind === "rtsp-listen") return [
|
|
255
|
+
"-f",
|
|
256
|
+
"rtsp",
|
|
257
|
+
"-rtsp_transport",
|
|
258
|
+
"tcp",
|
|
259
|
+
"-rtsp_flags",
|
|
260
|
+
"listen",
|
|
261
|
+
sink.url
|
|
262
|
+
];
|
|
263
|
+
if (sink.kind === "rtp-outputs") return [];
|
|
264
|
+
return sink.container === "mp4" ? buildFmp4SinkArgs(sink) : [
|
|
265
|
+
"-f",
|
|
266
|
+
sink.container,
|
|
267
|
+
"pipe:1"
|
|
268
|
+
];
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* How far BELOW the negotiated fragment length `-min_frag_duration` is set.
|
|
272
|
+
*
|
|
273
|
+
* `-min_frag_duration` refuses to cut before that much media has accumulated,
|
|
274
|
+
* and then waits for the next key frame. Set to exactly `fragmentMs`, the
|
|
275
|
+
* commonest camera configuration in existence — a key-frame grid EQUAL to the
|
|
276
|
+
* requested fragment length — lands the deadline on the same instant as the key
|
|
277
|
+
* frame, loses the race, and skips to the following one: **every fragment comes
|
|
278
|
+
* out at twice the requested length.**
|
|
279
|
+
*
|
|
280
|
+
* Measured on the live fleet 2026-08-07, camera 101, `-c:v copy` (D84):
|
|
281
|
+
*
|
|
282
|
+
* | slot | GOP | `-min_frag_duration` | median gap |
|
|
283
|
+
* | --- | --- | --- | --- |
|
|
284
|
+
* | 1280×720 | 40 f @ 10 fps = 4.0 s | 4000 ms | **7944 ms** |
|
|
285
|
+
* | 1280×720 | 40 f @ 10 fps = 4.0 s | 3600 ms | 3973 ms |
|
|
286
|
+
* | 3840×2160 | 100 f @ 25 fps = 4.0 s | 4000 ms | 8042 ms |
|
|
287
|
+
* | 3840×2160 | 100 f @ 25 fps = 4.0 s | 3600 ms | 3998 ms |
|
|
288
|
+
*
|
|
289
|
+
* A doubled fragment is not a cosmetic overshoot: HKSV requires every fragment
|
|
290
|
+
* to be no longer than the length the controller SELECTED, so the shipped-but-
|
|
291
|
+
* inert phase-1 sink would have violated the contract on its first real clip.
|
|
292
|
+
*
|
|
293
|
+
* 10 % is chosen against the two failures either side of it. Too small and
|
|
294
|
+
* ordinary jitter (measured spread 3953-4096 ms) re-loses the race; too large
|
|
295
|
+
* and a source with a key frame slightly EARLY than the grid gets cut there,
|
|
296
|
+
* yielding a short fragment for no reason.
|
|
297
|
+
*/
|
|
298
|
+
var FMP4_MIN_FRAG_MARGIN = .9;
|
|
299
|
+
/** `-movflags … -min_frag_duration <us> -f mp4 pipe:1`. */
|
|
300
|
+
function buildFmp4SinkArgs(sink) {
|
|
301
|
+
return [
|
|
302
|
+
"-movflags",
|
|
303
|
+
FMP4_MOVFLAGS,
|
|
304
|
+
"-min_frag_duration",
|
|
305
|
+
String(Math.max(0, Math.round(sink.fragmentMs * FMP4_MIN_FRAG_MARGIN * 1e3))),
|
|
306
|
+
"-f",
|
|
307
|
+
"mp4",
|
|
308
|
+
"pipe:1"
|
|
309
|
+
];
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* A second output mapping source audio to RTP-over-UDP. `0:a:0?` makes the
|
|
313
|
+
* audio optional so a source with no audio skips it instead of failing the
|
|
314
|
+
* whole invocation.
|
|
315
|
+
*/
|
|
316
|
+
function buildAudioSidecarArgs(sidecar) {
|
|
317
|
+
return [
|
|
318
|
+
"-map",
|
|
319
|
+
"0:a:0?",
|
|
320
|
+
...buildAudioArgs(sidecar.codec === "pcma" ? {
|
|
321
|
+
kind: "encode",
|
|
322
|
+
codec: "pcma",
|
|
323
|
+
sampleRateHz: 8e3,
|
|
324
|
+
channels: 1
|
|
325
|
+
} : AUDIO_PRESETS[sidecar.codec]),
|
|
326
|
+
...buildRtpOutputArgs({
|
|
327
|
+
url: sidecar.rtpUrl,
|
|
328
|
+
sdpFile: sidecar.sdpFile
|
|
329
|
+
})
|
|
330
|
+
];
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Assemble the full ffmpeg argument list. Layout:
|
|
334
|
+
*
|
|
335
|
+
* -hide_banner -loglevel <level>
|
|
336
|
+
* [-hwaccel <backend|auto>] ─┐ INPUT options — strictly before -i.
|
|
337
|
+
* [<input.extraArgs>] │
|
|
338
|
+
* [-fflags <flag>…] │
|
|
339
|
+
* [-rtsp_transport tcp] │
|
|
340
|
+
* -i <url> ─┘ …repeated per extraInput
|
|
341
|
+
* [-filter_complex <graph>] ─ global, after the LAST -i
|
|
342
|
+
* [-map <video>] <video block> <threads> ─┐ OUTPUT options.
|
|
343
|
+
* [-map <audio>] <audio block> │
|
|
344
|
+
* <consumer outputArgs verbatim> │
|
|
345
|
+
* <sink> ─┘ terminal
|
|
346
|
+
*
|
|
347
|
+
* The `-map`s are DERIVED (see {@link resolveStreamMaps}), never constants:
|
|
348
|
+
* one input with no graph emits none at all, which is why the argv of every
|
|
349
|
+
* call site that predates the N-input extension is unchanged to the byte.
|
|
350
|
+
*
|
|
351
|
+
* {@link FfmpegInvocation.audioSidecar} is the one map that stays literal
|
|
352
|
+
* (`0:a:0?`): the sidecar is defined as the SOURCE's microphone on its own RTP
|
|
353
|
+
* output, not as whatever the main output happens to carry.
|
|
354
|
+
*/
|
|
355
|
+
/** The hardware-encode context for this invocation, or `undefined`. */
|
|
356
|
+
function hwEncodeFor(inv) {
|
|
357
|
+
return inv.hwEncodeDevice === void 0 ? void 0 : {
|
|
358
|
+
device: inv.hwEncodeDevice,
|
|
359
|
+
decodeHwAccel: inv.decodeHwAccel
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function buildFfmpegArgs(inv) {
|
|
363
|
+
const graph = inv.filterGraph ?? null;
|
|
364
|
+
const head = [
|
|
365
|
+
...logBannerArgs(inv.logLevel),
|
|
366
|
+
...inv.hwEncodeDevice !== void 0 ? ["-vaapi_device", inv.hwEncodeDevice.renderNode] : [],
|
|
367
|
+
...buildInputArgs(inv.input, inv.decodeHwAccel),
|
|
368
|
+
...(inv.extraInputs ?? []).flatMap((extra) => buildInputArgs(extra, inv.decodeHwAccel)),
|
|
369
|
+
...graph ? ["-filter_complex", graph.graph] : []
|
|
370
|
+
];
|
|
371
|
+
const threadArgs = [...inv.threadCount > 0 ? ["-threads", String(inv.threadCount)] : [], ...inv.filterThreadCount !== void 0 && inv.filterThreadCount > 0 ? ["-filter_threads", String(inv.filterThreadCount)] : []];
|
|
372
|
+
const maps = resolveStreamMaps(inv);
|
|
373
|
+
const videoMapArgs = maps.video ? ["-map", maps.video] : [];
|
|
374
|
+
const audioMapArgs = maps.audio ? ["-map", maps.audio] : [];
|
|
375
|
+
if (inv.sink.kind === "rtp-outputs") {
|
|
376
|
+
const videoLeg = inv.sink.video ? [
|
|
377
|
+
"-an",
|
|
378
|
+
"-map",
|
|
379
|
+
maps.video ?? "0:v:0",
|
|
380
|
+
...buildVideoArgs(inv.video, inv.outputArgs, graph, hwEncodeFor(inv)),
|
|
381
|
+
...threadArgs,
|
|
382
|
+
...inv.outputArgs,
|
|
383
|
+
...buildRtpOutputArgs(inv.sink.video)
|
|
384
|
+
] : [];
|
|
385
|
+
const audioLeg = inv.sink.audio ? [
|
|
386
|
+
"-vn",
|
|
387
|
+
"-map",
|
|
388
|
+
maps.audio ?? "0:a:0?",
|
|
389
|
+
...buildAudioArgs(inv.audio),
|
|
390
|
+
...buildRtpOutputArgs(inv.sink.audio)
|
|
391
|
+
] : [];
|
|
392
|
+
return [
|
|
393
|
+
...head,
|
|
394
|
+
...videoLeg,
|
|
395
|
+
...audioLeg
|
|
396
|
+
];
|
|
397
|
+
}
|
|
398
|
+
const mutedAudio = isElementaryVideoSink(inv.sink) || inv.audio.kind === "none";
|
|
399
|
+
const audioArgs = isElementaryVideoSink(inv.sink) ? ["-an"] : buildAudioArgs(inv.audio);
|
|
400
|
+
return [
|
|
401
|
+
...head,
|
|
402
|
+
...videoMapArgs,
|
|
403
|
+
...buildVideoArgs(inv.video, inv.outputArgs, graph, hwEncodeFor(inv)),
|
|
404
|
+
...threadArgs,
|
|
405
|
+
...mutedAudio ? [] : audioMapArgs,
|
|
406
|
+
...audioArgs,
|
|
407
|
+
...inv.outputArgs,
|
|
408
|
+
...buildStdoutOrRtspSinkArgs(inv.sink),
|
|
409
|
+
...inv.audioSidecar ? buildAudioSidecarArgs(inv.audioSidecar) : []
|
|
410
|
+
];
|
|
411
|
+
}
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region ../types/dist/esm/composition/engine-hosted-blocks.mjs
|
|
414
|
+
function isSpecOfKind(spec, kind) {
|
|
415
|
+
return spec !== void 0 && spec.kind === kind;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* The blocks of `kind` whose composer row exists. A block whose row the
|
|
419
|
+
* composer has not declared yet is left out: nothing can be hosted on it until
|
|
420
|
+
* its next apply, and the next pass picks it up.
|
|
421
|
+
*/
|
|
422
|
+
function selectEngineHostedBlocks(kind, compositions, composerRows) {
|
|
423
|
+
if (compositions.state === "not-loaded") return {
|
|
424
|
+
kind: "untrusted",
|
|
425
|
+
reason: compositions.reason
|
|
426
|
+
};
|
|
427
|
+
const rowByStableId = new Map(composerRows.map((row) => [row.stableId, row]));
|
|
428
|
+
const blocks = [];
|
|
429
|
+
for (const view of compositions.views) {
|
|
430
|
+
const block = view.block;
|
|
431
|
+
const composition = block.source?.kind === "composition" ? block.source.composition : null;
|
|
432
|
+
if (composition === null) continue;
|
|
433
|
+
const spec = composition.helper;
|
|
434
|
+
if (!isSpecOfKind(spec, kind)) continue;
|
|
435
|
+
const stableId = `${COMPOSED_DEVICE_STABLE_ID_PREFIX}${block.id}`;
|
|
436
|
+
const row = rowByStableId.get(stableId);
|
|
437
|
+
if (row === void 0) continue;
|
|
438
|
+
blocks.push({
|
|
439
|
+
blockId: block.id,
|
|
440
|
+
deviceId: row.id,
|
|
441
|
+
stableId,
|
|
442
|
+
name: block.name,
|
|
443
|
+
enabled: block.enabled,
|
|
444
|
+
updatedAt: block.updatedAt,
|
|
445
|
+
composition,
|
|
446
|
+
spec
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
kind: "trusted",
|
|
451
|
+
blocks
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
var WITHDRAWAL_CONFIRMATIONS = 2;
|
|
455
|
+
/**
|
|
456
|
+
* D49 for an engine's hosted set: a block missing from ONE trusted read is
|
|
457
|
+
* kept; a second consecutive trusted read that agrees withdraws it. An
|
|
458
|
+
* untrusted read is never fed here, so it neither counts nor resets.
|
|
459
|
+
*/
|
|
460
|
+
var HostedWithdrawalGate = class {
|
|
461
|
+
misses = /* @__PURE__ */ new Map();
|
|
462
|
+
/**
|
|
463
|
+
* `hosted`: what the engine serves now; `present`: what this trusted read
|
|
464
|
+
* names. Returns the ids to withdraw now, and the ids kept on a first miss.
|
|
465
|
+
*/
|
|
466
|
+
judge(hosted, present) {
|
|
467
|
+
const withdraw = [];
|
|
468
|
+
const held = [];
|
|
469
|
+
const misses = /* @__PURE__ */ new Map();
|
|
470
|
+
for (const id of hosted) {
|
|
471
|
+
if (present.has(id)) continue;
|
|
472
|
+
const count = (this.misses.get(id) ?? 0) + 1;
|
|
473
|
+
if (count < WITHDRAWAL_CONFIRMATIONS) {
|
|
474
|
+
held.push(id);
|
|
475
|
+
misses.set(id, count);
|
|
476
|
+
} else withdraw.push(id);
|
|
477
|
+
}
|
|
478
|
+
this.misses = misses;
|
|
479
|
+
return {
|
|
480
|
+
withdraw,
|
|
481
|
+
held
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
/**
|
|
486
|
+
* Build `DeviceClass` on the composer's row `(stableId, id)`. The context is
|
|
487
|
+
* `loadContext` (D677: a caller that BUILDS a device hydrates its stored
|
|
488
|
+
* runtime state first); a kernel without it is refused by name rather than
|
|
489
|
+
* building on an empty state. The device is never `register`ed and its config
|
|
490
|
+
* never persisted: the row, its name and its lifetime are the composer's.
|
|
491
|
+
*/
|
|
492
|
+
async function hostEngineDevice(devices, row, config, DeviceClass) {
|
|
493
|
+
if (devices.loadContext === void 0) throw new Error(`this kernel cannot build a device on a row it does not own (no loadContext) — device ${String(row.id)} is not hosted`);
|
|
494
|
+
const base = await devices.loadContext(row.stableId, row.id, null, config);
|
|
495
|
+
const registered = [];
|
|
496
|
+
const device = new DeviceClass({
|
|
497
|
+
...base,
|
|
498
|
+
registerNativeCap: (cap, provider) => {
|
|
499
|
+
base.registerNativeCap(cap, provider);
|
|
500
|
+
registered.push(cap.name);
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
return {
|
|
504
|
+
device,
|
|
505
|
+
withdraw: async () => {
|
|
506
|
+
await device.removeDevice();
|
|
507
|
+
for (const capName of registered) base.unregisterNativeCap?.(capName);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Whether an engine may stop sweeping: only once a pass found no old row left.
|
|
513
|
+
* `none` is not done — a registry that has not answered the integration yet
|
|
514
|
+
* reads as null too, and the sweep is one indexed read per pass.
|
|
515
|
+
*/
|
|
516
|
+
function legacySweepDone(sweep) {
|
|
517
|
+
return sweep.kind === "swept" && sweep.drained;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* The legacy rows, one bounded batch at a time: only the rows under the old
|
|
521
|
+
* integration, ordered by id, at most `DECLARED_DEVICE_SWEEP_LIMIT` — a large
|
|
522
|
+
* leftover set drains over passes instead of being refused whole by the
|
|
523
|
+
* sweep's own bound.
|
|
524
|
+
*/
|
|
525
|
+
function legacyEngineRowsIndex(rows, integrationId) {
|
|
526
|
+
return rows.filter((row) => row.integrationId === integrationId).toSorted((left, right) => left.id - right.id).slice(0, 32);
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Remove every camera row an engine declared itself before its cameras were
|
|
530
|
+
* blocks, unconditionally, through the declared sweep (`removeDevice` →
|
|
531
|
+
* tombstone, D865). No integration means nothing was ever declared, and
|
|
532
|
+
* nothing is minted to find out. A failed read throws: the caller retries.
|
|
533
|
+
*/
|
|
534
|
+
async function sweepLegacyEngineRows(ports, integrationName) {
|
|
535
|
+
const integration = await ports.getIntegration(ports.addonId);
|
|
536
|
+
if (integration === null) return { kind: "none" };
|
|
537
|
+
let found = 0;
|
|
538
|
+
return {
|
|
539
|
+
kind: "swept",
|
|
540
|
+
removed: (await new DeclaredDevices({
|
|
541
|
+
logger: ports.logger,
|
|
542
|
+
addonId: ports.addonId,
|
|
543
|
+
devices: ports.devices,
|
|
544
|
+
localNodeId: ports.localNodeId,
|
|
545
|
+
getIntegration: async () => integration,
|
|
546
|
+
createIntegration: async () => {
|
|
547
|
+
throw new Error(`${ports.addonId}: the legacy sweep never mints an integration`);
|
|
548
|
+
},
|
|
549
|
+
updateIntegration: async () => void 0,
|
|
550
|
+
listOwnDevices: async () => {
|
|
551
|
+
const index = legacyEngineRowsIndex(await ports.listAddonRows(ports.addonId), integration.id);
|
|
552
|
+
found = index.length;
|
|
553
|
+
return index;
|
|
554
|
+
}
|
|
555
|
+
}).reconcile({
|
|
556
|
+
integrationName,
|
|
557
|
+
integrationId: integration.id,
|
|
558
|
+
placement: "hub",
|
|
559
|
+
devices: []
|
|
560
|
+
})).removed,
|
|
561
|
+
drained: found === 0
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
//#endregion
|
|
8
565
|
//#region src/builtins/camera-grid/grid-device-settings.ts
|
|
9
566
|
/** The widget id, registered in `ui-library`'s `HOST_WIDGETS`. */
|
|
10
567
|
var GRID_LAYOUT_WIDGET_ID = "host/camera-grid-layout";
|