@camstack/server 1.2.718 → 1.2.720
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 +13 -0
- package/dist/addon-root-inventory.js +1 -1
- package/dist/agent/addon-scan.js +11 -7
- package/dist/agent/agent-addon-updates.js +1 -1
- package/dist/agent/agent-cap-dispatch-service.js +1 -1
- package/dist/agent/agent-heap-watch.js +1 -1
- package/dist/agent/agent-http.js +1 -1
- package/dist/agent/agent-hub-addon-update.js +1 -1
- package/dist/agent/agent-hub-registration.js +1 -1
- package/dist/agent/agent-infra-capabilities.js +2 -2
- package/dist/agent/agent-mesh-gate.js +1 -1
- package/dist/agent/agent-node-certificates.js +1 -1
- package/dist/agent/agent-pairing-routes.js +1 -1
- package/dist/agent/agent-pairing-store.js +1 -1
- package/dist/agent/agent-service.js +6 -2
- package/dist/agent/agent-update-service.js +3 -1
- package/dist/agent/hub-membership-client.js +1 -1
- package/dist/agent/infra-boot-guard.js +2 -2
- package/dist/agent/main.js +9 -9
- package/dist/api/addon-upload.js +1 -1
- package/dist/api/core/addon-settings.router.js +1 -1
- package/dist/api/core/agent-pairing.router.js +1 -1
- package/dist/api/core/auth-device-cert.procedures.js +1 -1
- package/dist/api/core/cap-providers.js +6 -6
- package/dist/api/core/certificates.router.js +1 -1
- package/dist/api/core/lifecycle-job-runner.js +1 -1
- package/dist/api/core/logging-settings.js +1 -1
- package/dist/api/core/logs.router.js +2 -2
- package/dist/api/core/notifications.router.js +1 -1
- package/dist/api/core/preferences.router.js +1 -1
- package/dist/api/core/repl.router.js +1 -1
- package/dist/api/cors/cors-policy.js +1 -1
- package/dist/api/mesh-membership-routes.js +1 -1
- package/dist/api/model-distributor.js +1 -1
- package/dist/api/trpc/cap-route-error-formatter.js +1 -1
- package/dist/api/trpc/cap-router-runtime.js +2 -2
- package/dist/api/trpc/core-cap-bridge.js +1 -1
- package/dist/api/trpc/device-collection-dispatch.js +1 -1
- package/dist/api/trpc/generated-cap-routers.js +1 -1
- package/dist/api/trpc/principal-authorization.js +1 -1
- package/dist/api/trpc/principal-visibility.js +1 -1
- package/dist/api/trpc/scope-access.js +1 -1
- package/dist/api/trpc/trpc.context.js +1 -1
- package/dist/api/trpc/trpc.middleware.js +1 -1
- package/dist/api/trpc/trpc.router.js +3 -3
- package/dist/auth/auth-network-policy.js +1 -1
- package/dist/auth/client-address.js +1 -1
- package/dist/auth/hub-sessions.js +1 -1
- package/dist/auth/session-lifetimes.js +1 -1
- package/dist/auth/sso-finish-deps.js +1 -1
- package/dist/boot/boot-config.js +53 -133
- package/dist/boot/platform-keychain-key.js +1 -1
- package/dist/boot/post-boot.service.js +1 -1
- package/dist/bootstrap-packages.js +3 -3
- package/dist/core/addon/addon-call-gateway.js +1 -1
- package/dist/core/addon/addon-package.service.js +140 -21
- package/dist/core/addon/addon-registry.service.js +36 -32
- package/dist/core/addon/addon-requirements.js +81 -0
- package/dist/core/addon/hub-addon-api.js +1 -1
- package/dist/core/addon/installed-addon-versions.js +82 -0
- package/dist/core/addon/package-dir-utils.js +11 -1
- package/dist/core/addon/settings-door-wiring.js +1 -1
- package/dist/core/addon-bridge/addon-bridge.service.js +3 -3
- package/dist/core/addon-pages/addon-pages.service.js +1 -1
- package/dist/core/agent/agent-desired-set.js +1 -1
- package/dist/core/agent/agent-pairing-http.js +1 -1
- package/dist/core/agent/agent-registry.service.js +41 -7
- package/dist/core/agent/cluster-node-history-store.js +1 -1
- package/dist/core/agent/delivery-requirements.js +36 -0
- package/dist/core/agent/forgotten-node-revoker.js +1 -1
- package/dist/core/agent/node-removal-hooks.js +6 -2
- package/dist/core/auth/auth.service.js +1 -1
- package/dist/core/config/config.schema.js +2 -2
- package/dist/core/config/config.service.js +1 -1
- package/dist/core/events/event-bus.service.js +1 -1
- package/dist/core/feature/feature.service.js +1 -1
- package/dist/core/lifecycle/lifecycle-state-machine.js +2 -2
- package/dist/core/logging/log-history.js +1 -1
- package/dist/core/logging/log-ring-buffer.js +2 -2
- package/dist/core/logging/logging.service.js +2 -2
- package/dist/core/logging/scoped-logger.js +2 -2
- package/dist/core/moleculer/cap-route-authority.js +2 -2
- package/dist/core/moleculer/hub-mesh-guard.js +1 -1
- package/dist/core/moleculer/moleculer.service.js +1 -1
- package/dist/core/network/network-quality.service.js +1 -1
- package/dist/core/notification/notification-wrapper.service.js +1 -1
- package/dist/core/notification/toast-wrapper.service.js +1 -1
- package/dist/core/repl/repl-engine.service.js +1 -1
- package/dist/core/server-update/server-update.service.js +3 -0
- package/dist/core/server-update/system-ensure-prebuilds.js +3 -3
- package/dist/core/server-update/system-exec-npm.js +2 -2
- package/dist/core/storage/fs-storage-backend.js +2 -2
- package/dist/core/storage/storage-location-manager.js +2 -2
- package/dist/core/storage/storage.service.js +1 -1
- package/dist/framework-nodepath.js +14 -1
- package/dist/launcher.js +23 -23
- package/dist/legacy-package-names.js +15 -0
- package/dist/main.js +2 -2
- package/dist/manual-boot.js +4 -3
- package/dist/package-inventory.js +6 -3
- package/dist/server-root/index.js +182 -30
- package/dist/single-copy-cleanup-runner.js +3 -3
- package/dist/single-copy-cleanup.js +19 -14
- package/package.json +53 -19
- package/scripts/closure-postinstall.mjs +1 -1
- package/system/assets/addon-pages-aggregator/icon.svg +5 -0
- package/system/assets/addon-widgets-aggregator/icon.svg +6 -0
- package/system/assets/alert-center/icon.svg +5 -0
- package/system/assets/autotrack/icon.svg +5 -0
- package/system/assets/backup-orchestrator/icon.svg +5 -0
- package/system/assets/calendars/icon.svg +5 -0
- package/system/assets/camera-grid/icon.svg +10 -0
- package/system/assets/composer/icon.svg +7 -0
- package/system/assets/console-logging/icon.svg +4 -0
- package/system/assets/core-blocks/icon.svg +6 -0
- package/system/assets/device-history/icon.svg +4 -0
- package/system/assets/device-manager/icon.svg +6 -0
- package/system/assets/filesystem-storage/icon.svg +6 -0
- package/system/assets/hub-forwarder/icon.svg +7 -0
- package/system/assets/keychain/icon.svg +6 -0
- package/system/assets/liveness-monitor/icon.svg +4 -0
- package/system/assets/local-auth/icon.svg +5 -0
- package/system/assets/local-network/icon.svg +7 -0
- package/system/assets/loki-logging/icon.svg +7 -0
- package/system/assets/metrics-native/icon.svg +3 -0
- package/system/assets/platform-probe/icon.svg +5 -0
- package/system/assets/record-entries/icon.svg +8 -0
- package/system/assets/remote-access-orchestrator/icon.svg +5 -0
- package/system/assets/snapshot/icon.svg +4 -0
- package/system/assets/sqlite-settings/icon.svg +5 -0
- package/system/assets/storage-orchestrator/icon.svg +8 -0
- package/system/assets/system-config/icon.svg +4 -0
- package/system/assets/winston-logging/icon.svg +6 -0
- package/system/dist/addon/addon-api-factory.d.ts +35 -0
- package/system/dist/addon-routes/addon-route-registry.d.ts +37 -0
- package/system/dist/addon-runner.js +11894 -0
- package/system/dist/addon-runner.mjs +11840 -0
- package/system/dist/addon-utils.d.ts +23 -0
- package/system/dist/addon-utils.js +27 -0
- package/system/dist/addon-utils.mjs +3 -0
- package/system/dist/agent-https-BMbnmX5u.mjs +1042 -0
- package/system/dist/agent-https-DslXCDRW.js +1289 -0
- package/system/dist/amd-accelerators-CEuPFBBK.js +36 -0
- package/system/dist/amd-accelerators-U_RsoEDd.mjs +35 -0
- package/system/dist/auth/auth-audit-log.d.ts +45 -0
- package/system/dist/auth/auth-manager.d.ts +155 -0
- package/system/dist/auth/cidr.d.ts +22 -0
- package/system/dist/auth/device-ca-store.d.ts +57 -0
- package/system/dist/auth/device-ca.d.ts +65 -0
- package/system/dist/auth/device-credential-manager.d.ts +158 -0
- package/system/dist/auth/external-identity-manager.d.ts +42 -0
- package/system/dist/auth/jwt-signing-key.d.ts +42 -0
- package/system/dist/auth/legacy-token-tables.d.ts +16 -0
- package/system/dist/auth/login-session-manager.d.ts +140 -0
- package/system/dist/auth/origin.d.ts +34 -0
- package/system/dist/auth/parse-record.d.ts +18 -0
- package/system/dist/auth/scope-matcher.d.ts +8 -0
- package/system/dist/auth/session-revocation-bus.d.ts +32 -0
- package/system/dist/auth/token-expiry.d.ts +62 -0
- package/system/dist/auth/totp-manager.d.ts +107 -0
- package/system/dist/auth/user-management-internal.d.ts +90 -0
- package/system/dist/auth/user-manager.d.ts +69 -0
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.d.ts +57 -0
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +271 -0
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +263 -0
- package/system/dist/builtins/addon-pages-aggregator/dedupe-pages.d.ts +24 -0
- package/system/dist/builtins/addon-pages-aggregator/index.d.ts +1 -0
- package/system/dist/builtins/addon-pages-aggregator/index.js +8 -0
- package/system/dist/builtins/addon-pages-aggregator/index.mjs +2 -0
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.d.ts +57 -0
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +257 -0
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +249 -0
- package/system/dist/builtins/addon-widgets-aggregator/index.d.ts +1 -0
- package/system/dist/builtins/addon-widgets-aggregator/index.js +8 -0
- package/system/dist/builtins/addon-widgets-aggregator/index.mjs +2 -0
- package/system/dist/builtins/alerts/alert-episode-policy.d.ts +39 -0
- package/system/dist/builtins/alerts/alert-store.d.ts +32 -0
- package/system/dist/builtins/alerts/alerts.addon.d.ts +148 -0
- package/system/dist/builtins/alerts/alerts.addon.js +1566 -0
- package/system/dist/builtins/alerts/alerts.addon.mjs +1559 -0
- package/system/dist/builtins/alerts/device-label.d.ts +8 -0
- package/system/dist/builtins/alerts/emit-alert-policy.d.ts +15 -0
- package/system/dist/builtins/alerts/index.d.ts +1 -0
- package/system/dist/builtins/alerts/index.js +4 -0
- package/system/dist/builtins/alerts/index.mjs +2 -0
- package/system/dist/builtins/alerts/migration-alerts.d.ts +13 -0
- package/system/dist/builtins/alerts/prune-policy.d.ts +44 -0
- package/system/dist/builtins/alerts/record-kinds.d.ts +15 -0
- package/system/dist/builtins/alerts/runner-alert.d.ts +58 -0
- package/system/dist/builtins/autotrack/autotrack-cameras.d.ts +125 -0
- package/system/dist/builtins/autotrack/autotrack-config.d.ts +89 -0
- package/system/dist/builtins/autotrack/autotrack-decision.d.ts +86 -0
- package/system/dist/builtins/autotrack/autotrack-loop.d.ts +95 -0
- package/system/dist/builtins/autotrack/autotrack.addon.d.ts +108 -0
- package/system/dist/builtins/autotrack/frame-error.d.ts +50 -0
- package/system/dist/builtins/autotrack/frame-measurements.d.ts +97 -0
- package/system/dist/builtins/autotrack/index.d.ts +2 -0
- package/system/dist/builtins/autotrack/index.js +1018 -0
- package/system/dist/builtins/autotrack/index.mjs +1012 -0
- package/system/dist/builtins/autotrack/ptz-mirror.d.ts +54 -0
- package/system/dist/builtins/autotrack/target-selection.d.ts +46 -0
- package/system/dist/builtins/backup-orchestrator/backup-databases.d.ts +51 -0
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.d.ts +291 -0
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +3213 -0
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +3204 -0
- package/system/dist/builtins/backup-orchestrator/cron-helpers.d.ts +23 -0
- package/system/dist/builtins/backup-orchestrator/destination-policy.d.ts +91 -0
- package/system/dist/builtins/backup-orchestrator/download-helpers.d.ts +12 -0
- package/system/dist/builtins/backup-orchestrator/encryption-key-store.d.ts +49 -0
- package/system/dist/builtins/backup-orchestrator/index.d.ts +2 -0
- package/system/dist/builtins/backup-orchestrator/index.js +8 -0
- package/system/dist/builtins/backup-orchestrator/index.mjs +2 -0
- package/system/dist/builtins/backup-orchestrator/manifest-store.d.ts +134 -0
- package/system/dist/builtins/backup-orchestrator/record-kinds.d.ts +56 -0
- package/system/dist/builtins/backup-orchestrator/restore-archive.d.ts +24 -0
- package/system/dist/builtins/backup-orchestrator/run-queue.d.ts +106 -0
- package/system/dist/builtins/backup-orchestrator/schedule-store.d.ts +59 -0
- package/system/dist/builtins/backup-orchestrator/seed-marker-store.d.ts +26 -0
- package/system/dist/builtins/backup-orchestrator/staging-paths.d.ts +36 -0
- package/system/dist/builtins/backup-orchestrator/write-targets.d.ts +63 -0
- package/system/dist/builtins/calendars/calendar-color.d.ts +9 -0
- package/system/dist/builtins/calendars/calendar-prefs-store.d.ts +34 -0
- package/system/dist/builtins/calendars/calendars.addon.d.ts +19 -0
- package/system/dist/builtins/calendars/calendars.addon.js +227 -0
- package/system/dist/builtins/calendars/calendars.addon.mjs +220 -0
- package/system/dist/builtins/calendars/index.d.ts +1 -0
- package/system/dist/builtins/calendars/index.js +8 -0
- package/system/dist/builtins/calendars/index.mjs +2 -0
- package/system/dist/builtins/calendars/record-kinds.d.ts +18 -0
- package/system/dist/builtins/camera-grid/acquire-retry.d.ts +30 -0
- package/system/dist/builtins/camera-grid/addon.d.ts +205 -0
- package/system/dist/builtins/camera-grid/flv-join.d.ts +40 -0
- package/system/dist/builtins/camera-grid/grid-activity-mirror.d.ts +42 -0
- package/system/dist/builtins/camera-grid/grid-activity.d.ts +91 -0
- package/system/dist/builtins/camera-grid/grid-camera-declarations.d.ts +59 -0
- package/system/dist/builtins/camera-grid/grid-camera-device.d.ts +68 -0
- package/system/dist/builtins/camera-grid/grid-canvas-derivation.d.ts +54 -0
- package/system/dist/builtins/camera-grid/grid-canvas-seed.d.ts +112 -0
- package/system/dist/builtins/camera-grid/grid-canvas.d.ts +85 -0
- package/system/dist/builtins/camera-grid/grid-child.d.ts +32 -0
- package/system/dist/builtins/camera-grid/grid-compositor-child.d.ts +3 -0
- package/system/dist/builtins/camera-grid/grid-compositor-invocation.d.ts +47 -0
- package/system/dist/builtins/camera-grid/grid-compositor.d.ts +54 -0
- package/system/dist/builtins/camera-grid/grid-detection-mapping.d.ts +61 -0
- package/system/dist/builtins/camera-grid/grid-device-settings.d.ts +35 -0
- package/system/dist/builtins/camera-grid/grid-filter-graph.d.ts +53 -0
- package/system/dist/builtins/camera-grid/grid-frame-sample.d.ts +53 -0
- package/system/dist/builtins/camera-grid/grid-instances.d.ts +22 -0
- package/system/dist/builtins/camera-grid/grid-last-frame-store.d.ts +58 -0
- package/system/dist/builtins/camera-grid/grid-layout-native-provider.d.ts +34 -0
- package/system/dist/builtins/camera-grid/grid-plan.d.ts +34 -0
- package/system/dist/builtins/camera-grid/grid-profiles.d.ts +104 -0
- package/system/dist/builtins/camera-grid/grid-row-normalization.d.ts +10 -0
- package/system/dist/builtins/camera-grid/grid-sentry-sources.d.ts +64 -0
- package/system/dist/builtins/camera-grid/grid-snapshot.d.ts +62 -0
- package/system/dist/builtins/camera-grid/grid-stream-descriptor.d.ts +53 -0
- package/system/dist/builtins/camera-grid/grid-stream-invocation.d.ts +44 -0
- package/system/dist/builtins/camera-grid/grid-stream-relay.d.ts +35 -0
- package/system/dist/builtins/camera-grid/grid-stream-session.d.ts +143 -0
- package/system/dist/builtins/camera-grid/grid-tile-feed.d.ts +50 -0
- package/system/dist/builtins/camera-grid/grid-tile-plan.d.ts +66 -0
- package/system/dist/builtins/camera-grid/grid-wire-format.d.ts +30 -0
- package/system/dist/builtins/camera-grid/index.d.ts +45 -0
- package/system/dist/builtins/camera-grid/index.js +3994 -0
- package/system/dist/builtins/camera-grid/index.mjs +3961 -0
- package/system/dist/builtins/camera-grid/silence-analysis.d.ts +37 -0
- package/system/dist/builtins/cluster-agent/record-kinds.d.ts +49 -0
- package/system/dist/builtins/composer/actuator-dispatch.d.ts +13 -0
- package/system/dist/builtins/composer/actuator-groups.d.ts +68 -0
- package/system/dist/builtins/composer/actuator-invoke.d.ts +32 -0
- package/system/dist/builtins/composer/claim-gate.d.ts +59 -0
- package/system/dist/builtins/composer/composed-device-set.d.ts +52 -0
- package/system/dist/builtins/composer/composed-device.d.ts +57 -0
- package/system/dist/builtins/composer/composer-apply-waits.d.ts +28 -0
- package/system/dist/builtins/composer/composer-grafts.d.ts +73 -0
- package/system/dist/builtins/composer/composer-live-set.d.ts +30 -0
- package/system/dist/builtins/composer/composer-plan.d.ts +112 -0
- package/system/dist/builtins/composer/composer-runtime-factory.d.ts +30 -0
- package/system/dist/builtins/composer/composer-seeds.d.ts +28 -0
- package/system/dist/builtins/composer/composer-verdict.d.ts +33 -0
- package/system/dist/builtins/composer/composer.addon.d.ts +26 -0
- package/system/dist/builtins/composer/composer.addon.js +6229 -0
- package/system/dist/builtins/composer/composer.addon.mjs +6223 -0
- package/system/dist/builtins/composer/composer.d.ts +208 -0
- package/system/dist/builtins/composer/composition-declarations.d.ts +64 -0
- package/system/dist/builtins/composer/composition-evaluation.d.ts +53 -0
- package/system/dist/builtins/composer/composition-runtime.d.ts +203 -0
- package/system/dist/builtins/composer/composition-target.d.ts +60 -0
- package/system/dist/builtins/composer/confirmed-seed.d.ts +44 -0
- package/system/dist/builtins/composer/deadline-timer.d.ts +18 -0
- package/system/dist/builtins/composer/existing-target.d.ts +131 -0
- package/system/dist/builtins/composer/field-record.d.ts +64 -0
- package/system/dist/builtins/composer/forward-commands.d.ts +61 -0
- package/system/dist/builtins/composer/graft-host.d.ts +71 -0
- package/system/dist/builtins/composer/held-claims.d.ts +29 -0
- package/system/dist/builtins/composer/history-helpers.d.ts +67 -0
- package/system/dist/builtins/composer/index.d.ts +1 -0
- package/system/dist/builtins/composer/index.js +8 -0
- package/system/dist/builtins/composer/index.mjs +2 -0
- package/system/dist/builtins/composer/math-quantity.d.ts +20 -0
- package/system/dist/builtins/composer/own-field-reads.d.ts +30 -0
- package/system/dist/builtins/composer/owned-fields-target.d.ts +95 -0
- package/system/dist/builtins/composer/pulse-seed-resolve.d.ts +59 -0
- package/system/dist/builtins/composer/pulse-seed.d.ts +75 -0
- package/system/dist/builtins/composer/slice-assembler.d.ts +26 -0
- package/system/dist/builtins/composer/source-readings.d.ts +128 -0
- package/system/dist/builtins/composer/source-tracker.d.ts +135 -0
- package/system/dist/builtins/console-logging/console-destination.d.ts +19 -0
- package/system/dist/builtins/console-logging/console-logging.addon.d.ts +26 -0
- package/system/dist/builtins/console-logging/index.d.ts +3 -0
- package/system/dist/builtins/console-logging/index.js +108 -0
- package/system/dist/builtins/console-logging/index.mjs +99 -0
- package/system/dist/builtins/core-blocks/actions-service.d.ts +113 -0
- package/system/dist/builtins/core-blocks/actions-store.d.ts +32 -0
- package/system/dist/builtins/core-blocks/actions-wiring.d.ts +32 -0
- package/system/dist/builtins/core-blocks/block-package.d.ts +54 -0
- package/system/dist/builtins/core-blocks/block-settings-store.d.ts +93 -0
- package/system/dist/builtins/core-blocks/block-supervisor.d.ts +176 -0
- package/system/dist/builtins/core-blocks/block-type-defs.d.ts +29 -0
- package/system/dist/builtins/core-blocks/blocks-integration.d.ts +89 -0
- package/system/dist/builtins/core-blocks/compile-block.d.ts +52 -0
- package/system/dist/builtins/core-blocks/composition-api.d.ts +50 -0
- package/system/dist/builtins/core-blocks/composition-peers.d.ts +31 -0
- package/system/dist/builtins/core-blocks/composition-sources.d.ts +40 -0
- package/system/dist/builtins/core-blocks/core-block-store.d.ts +120 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +108 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +6374 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +6355 -0
- package/system/dist/builtins/core-blocks/extract-settings-schema.d.ts +6 -0
- package/system/dist/builtins/core-blocks/index.d.ts +8 -0
- package/system/dist/builtins/core-blocks/index.js +21 -0
- package/system/dist/builtins/core-blocks/index.mjs +2 -0
- package/system/dist/builtins/core-blocks/lock-door-gate.d.ts +31 -0
- package/system/dist/builtins/core-blocks/lock-door-sensor.d.ts +35 -0
- package/system/dist/builtins/core-blocks/power-source-service.d.ts +70 -0
- package/system/dist/builtins/core-blocks/record-kinds.d.ts +83 -0
- package/system/dist/builtins/core-blocks/remote-call-redirect.d.ts +23 -0
- package/system/dist/builtins/core-blocks/remote-components-service.d.ts +10 -0
- package/system/dist/builtins/core-blocks/remote-service.d.ts +85 -0
- package/system/dist/builtins/core-blocks/remote-wiring.d.ts +49 -0
- package/system/dist/builtins/core-blocks/runs-api.d.ts +30 -0
- package/system/dist/builtins/core-blocks/runs-ledger.d.ts +64 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-engine.d.ts +91 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-holds.d.ts +54 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-service.d.ts +76 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-store.d.ts +23 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-timeline.d.ts +53 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-trace.d.ts +17 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-types.d.ts +20 -0
- package/system/dist/builtins/core-blocks/scheduler/scheduler-wiring.d.ts +41 -0
- package/system/dist/builtins/core-blocks/templates-service.d.ts +24 -0
- package/system/dist/builtins/device-history/capture/capture-engine.d.ts +113 -0
- package/system/dist/builtins/device-history/capture/capture-filter.d.ts +37 -0
- package/system/dist/builtins/device-history/capture/device-directory.d.ts +47 -0
- package/system/dist/builtins/device-history/capture/field-path.d.ts +10 -0
- package/system/dist/builtins/device-history/capture/point-writer.d.ts +63 -0
- package/system/dist/builtins/device-history/device-history.addon.d.ts +53 -0
- package/system/dist/builtins/device-history/device-history.addon.js +2885 -0
- package/system/dist/builtins/device-history/device-history.addon.mjs +2878 -0
- package/system/dist/builtins/device-history/index.d.ts +3 -0
- package/system/dist/builtins/device-history/ingest/producer-ingest.d.ts +99 -0
- package/system/dist/builtins/device-history/query/history-query.d.ts +116 -0
- package/system/dist/builtins/device-history/query/point-shape.d.ts +31 -0
- package/system/dist/builtins/device-history/retention/departure-tracker.d.ts +33 -0
- package/system/dist/builtins/device-history/retention/orphans.d.ts +50 -0
- package/system/dist/builtins/device-history/retention/retention.d.ts +74 -0
- package/system/dist/builtins/device-history/rollup/rollup-engine.d.ts +74 -0
- package/system/dist/builtins/device-history/rollup/rollup-math.d.ts +50 -0
- package/system/dist/builtins/device-history/runtime/history-runtime.d.ts +118 -0
- package/system/dist/builtins/device-history/status/counters.d.ts +55 -0
- package/system/dist/builtins/device-history/store/history-door.d.ts +7 -0
- package/system/dist/builtins/device-history/store/history-schema.d.ts +28 -0
- package/system/dist/builtins/device-history/store/history-store.d.ts +109 -0
- package/system/dist/builtins/device-history/store/row-readers.d.ts +11 -0
- package/system/dist/builtins/device-history/store/series-registry.d.ts +64 -0
- package/system/dist/builtins/device-history/store/series-scale.d.ts +37 -0
- package/system/dist/builtins/device-history/time/bucket-time.d.ts +25 -0
- package/system/dist/builtins/device-manager/adoption-job-engine.d.ts +153 -0
- package/system/dist/builtins/device-manager/claimed-status-overlay.d.ts +45 -0
- package/system/dist/builtins/device-manager/contribution-cache.d.ts +85 -0
- package/system/dist/builtins/device-manager/day-night-config-schema.d.ts +30 -0
- package/system/dist/builtins/device-manager/device-aggregation-merge.d.ts +22 -0
- package/system/dist/builtins/device-manager/device-aggregation.d.ts +335 -0
- package/system/dist/builtins/device-manager/device-bindings-store.d.ts +278 -0
- package/system/dist/builtins/device-manager/device-config-contribution.d.ts +45 -0
- package/system/dist/builtins/device-manager/device-config-secrets.d.ts +40 -0
- package/system/dist/builtins/device-manager/device-event-propagator.d.ts +26 -0
- package/system/dist/builtins/device-manager/device-extension-linked-slot.d.ts +27 -0
- package/system/dist/builtins/device-manager/device-form-secrets.d.ts +25 -0
- package/system/dist/builtins/device-manager/device-linked-devices.d.ts +201 -0
- package/system/dist/builtins/device-manager/device-manager.addon.d.ts +234 -0
- package/system/dist/builtins/device-manager/device-manager.addon.js +11369 -0
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +11358 -0
- package/system/dist/builtins/device-manager/device-meta-actions.d.ts +338 -0
- package/system/dist/builtins/device-manager/device-meta-store.d.ts +103 -0
- package/system/dist/builtins/device-manager/device-meta-types.d.ts +277 -0
- package/system/dist/builtins/device-manager/device-online-fallback.d.ts +35 -0
- package/system/dist/builtins/device-manager/device-projection.d.ts +71 -0
- package/system/dist/builtins/device-manager/device-provider-context.d.ts +126 -0
- package/system/dist/builtins/device-manager/device-queries.d.ts +67 -0
- package/system/dist/builtins/device-manager/device-removal-hooks.d.ts +92 -0
- package/system/dist/builtins/device-manager/device-row-store.d.ts +449 -0
- package/system/dist/builtins/device-manager/device-source-activation.d.ts +103 -0
- package/system/dist/builtins/device-manager/device-state-claim-views.d.ts +92 -0
- package/system/dist/builtins/device-manager/device-state-claims.d.ts +66 -0
- package/system/dist/builtins/device-manager/device-state-mirror.d.ts +267 -0
- package/system/dist/builtins/device-manager/device-sync-resolvers.d.ts +30 -0
- package/system/dist/builtins/device-manager/device-tombstone-store.d.ts +29 -0
- package/system/dist/builtins/device-manager/discovery-orchestrator.d.ts +45 -0
- package/system/dist/builtins/device-manager/field-claims-index.d.ts +96 -0
- package/system/dist/builtins/device-manager/field-ownership.d.ts +71 -0
- package/system/dist/builtins/device-manager/fleet-read-census.d.ts +104 -0
- package/system/dist/builtins/device-manager/image-settings-config-schema.d.ts +22 -0
- package/system/dist/builtins/device-manager/index.d.ts +2 -0
- package/system/dist/builtins/device-manager/index.js +8 -0
- package/system/dist/builtins/device-manager/index.mjs +2 -0
- package/system/dist/builtins/device-manager/linked-devices-manual-backfill.d.ts +27 -0
- package/system/dist/builtins/device-manager/location-alignment.d.ts +61 -0
- package/system/dist/builtins/device-manager/migrate-device.d.ts +192 -0
- package/system/dist/builtins/device-manager/migrate-guard.d.ts +78 -0
- package/system/dist/builtins/device-manager/migrate-hardware-state.d.ts +79 -0
- package/system/dist/builtins/device-manager/migrate-reload.d.ts +46 -0
- package/system/dist/builtins/device-manager/migration-refused.d.ts +23 -0
- package/system/dist/builtins/device-manager/mirror-row-writer.d.ts +222 -0
- package/system/dist/builtins/device-manager/record-kinds.d.ts +14 -0
- package/system/dist/builtins/device-manager/recording-onboard-config-schema.d.ts +65 -0
- package/system/dist/builtins/device-manager/removal-cleanup.d.ts +50 -0
- package/system/dist/builtins/device-manager/removal-fence.d.ts +58 -0
- package/system/dist/builtins/device-manager/running-flip.d.ts +11 -0
- package/system/dist/builtins/device-manager/runtime-state-persist-gate.d.ts +64 -0
- package/system/dist/builtins/device-manager/secret-config-paths.d.ts +24 -0
- package/system/dist/builtins/device-manager/stale-wrapper-activations.d.ts +59 -0
- package/system/dist/builtins/device-manager/write-lock.d.ts +17 -0
- package/system/dist/builtins/hub-forwarder/hub-forwarder-destination.d.ts +43 -0
- package/system/dist/builtins/hub-forwarder/hub-forwarder.addon.d.ts +16 -0
- package/system/dist/builtins/hub-forwarder/index.d.ts +3 -0
- package/system/dist/builtins/hub-forwarder/index.js +151 -0
- package/system/dist/builtins/hub-forwarder/index.mjs +142 -0
- package/system/dist/builtins/keychain/index.d.ts +1 -0
- package/system/dist/builtins/keychain/index.js +2059 -0
- package/system/dist/builtins/keychain/index.mjs +2052 -0
- package/system/dist/builtins/keychain/key-sources.d.ts +37 -0
- package/system/dist/builtins/keychain/keychain-crypto.d.ts +28 -0
- package/system/dist/builtins/keychain/keychain-reset-trigger.d.ts +25 -0
- package/system/dist/builtins/keychain/keychain-service.d.ts +180 -0
- package/system/dist/builtins/keychain/keychain-store.d.ts +125 -0
- package/system/dist/builtins/keychain/keychain-usage.d.ts +17 -0
- package/system/dist/builtins/keychain/keychain.addon.d.ts +36 -0
- package/system/dist/builtins/keychain/platform-key-source.d.ts +24 -0
- package/system/dist/builtins/keychain/record-kinds.d.ts +16 -0
- package/system/dist/builtins/keychain/system-held-secrets.d.ts +25 -0
- package/system/dist/builtins/liveness-monitor/index.d.ts +2 -0
- package/system/dist/builtins/liveness-monitor/index.js +6 -0
- package/system/dist/builtins/liveness-monitor/index.mjs +2 -0
- package/system/dist/builtins/liveness-monitor/liveness-checks.d.ts +85 -0
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.d.ts +46 -0
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +443 -0
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +437 -0
- package/system/dist/builtins/liveness-monitor/liveness-reporter.d.ts +28 -0
- package/system/dist/builtins/liveness-monitor/storage-root-access.d.ts +53 -0
- package/system/dist/builtins/local-auth/admin-account-boot.d.ts +27 -0
- package/system/dist/builtins/local-auth/auth-config-reader.d.ts +39 -0
- package/system/dist/builtins/local-auth/auth-schema.d.ts +93 -0
- package/system/dist/builtins/local-auth/index.d.ts +1 -0
- package/system/dist/builtins/local-auth/index.js +4 -0
- package/system/dist/builtins/local-auth/index.mjs +2 -0
- package/system/dist/builtins/local-auth/jwt-signing-key-keeper.d.ts +30 -0
- package/system/dist/builtins/local-auth/local-auth.addon.d.ts +48 -0
- package/system/dist/builtins/local-auth/local-auth.addon.js +12418 -0
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +12388 -0
- package/system/dist/builtins/local-auth/oauth-grants.d.ts +71 -0
- package/system/dist/builtins/local-auth/oauth-session-manager.d.ts +44 -0
- package/system/dist/builtins/local-auth/person-scopes.d.ts +7 -0
- package/system/dist/builtins/local-auth/preferences-record-kinds.d.ts +27 -0
- package/system/dist/builtins/local-auth/record-kinds.d.ts +137 -0
- package/system/dist/builtins/local-auth/user-preferences-store.d.ts +56 -0
- package/system/dist/builtins/local-network/address-book.d.ts +128 -0
- package/system/dist/builtins/local-network/agent-mdns.d.ts +56 -0
- package/system/dist/builtins/local-network/hub-mdns-ciao.d.ts +7 -0
- package/system/dist/builtins/local-network/hub-mdns.d.ts +58 -0
- package/system/dist/builtins/local-network/index.d.ts +1 -0
- package/system/dist/builtins/local-network/index.js +10 -0
- package/system/dist/builtins/local-network/index.mjs +2 -0
- package/system/dist/builtins/local-network/ipv6-lan.d.ts +21 -0
- package/system/dist/builtins/local-network/local-hostname.d.ts +15 -0
- package/system/dist/builtins/local-network/local-network.addon.d.ts +334 -0
- package/system/dist/builtins/local-network/local-network.addon.js +2487 -0
- package/system/dist/builtins/local-network/local-network.addon.mjs +2466 -0
- package/system/dist/builtins/local-network/scan/dns-wire.d.ts +17 -0
- package/system/dist/builtins/local-network/scan/scan-engine.d.ts +31 -0
- package/system/dist/builtins/local-network/scan/scan-io-node.d.ts +2 -0
- package/system/dist/builtins/local-network/scan/scan-io.d.ts +56 -0
- package/system/dist/builtins/local-network/scan/subnets.d.ts +57 -0
- package/system/dist/builtins/loki-logging/index.d.ts +4 -0
- package/system/dist/builtins/loki-logging/index.js +915 -0
- package/system/dist/builtins/loki-logging/index.mjs +901 -0
- package/system/dist/builtins/loki-logging/loki-destination.d.ts +142 -0
- package/system/dist/builtins/loki-logging/loki-logging.addon.d.ts +66 -0
- package/system/dist/builtins/loki-logging/loki-payload.d.ts +100 -0
- package/system/dist/builtins/loki-logging/loki-read.d.ts +51 -0
- package/system/dist/builtins/loki-logging/retire-enabled-flag.d.ts +48 -0
- package/system/dist/builtins/native-metrics/cgroup-memory.d.ts +240 -0
- package/system/dist/builtins/native-metrics/cgroup-pids.d.ts +159 -0
- package/system/dist/builtins/native-metrics/container-memory-ring.d.ts +18 -0
- package/system/dist/builtins/native-metrics/darwin-memory.d.ts +26 -0
- package/system/dist/builtins/native-metrics/gpu-probe.d.ts +18 -0
- package/system/dist/builtins/native-metrics/index.d.ts +2 -0
- package/system/dist/builtins/native-metrics/load-series-config.d.ts +83 -0
- package/system/dist/builtins/native-metrics/load-series-reader.d.ts +63 -0
- package/system/dist/builtins/native-metrics/load-series-types.d.ts +14 -0
- package/system/dist/builtins/native-metrics/native-metrics-provider.d.ts +49 -0
- package/system/dist/builtins/native-metrics/native-metrics.addon.d.ts +233 -0
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +3116 -0
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +3106 -0
- package/system/dist/builtins/native-metrics/node-load-ring.d.ts +212 -0
- package/system/dist/builtins/native-metrics/node-metrics-history-recorder.d.ts +155 -0
- package/system/dist/builtins/native-metrics/proc-process-table.d.ts +25 -0
- package/system/dist/builtins/native-metrics/process-classification.d.ts +110 -0
- package/system/dist/builtins/native-metrics/thread-cpu-sampler.d.ts +116 -0
- package/system/dist/builtins/platform-probe/accelerator-facts-probe.d.ts +24 -0
- package/system/dist/builtins/platform-probe/accelerator-reprobe.d.ts +23 -0
- package/system/dist/builtins/platform-probe/amd-accelerators.d.ts +15 -0
- package/system/dist/builtins/platform-probe/amd-npu.d.ts +35 -0
- package/system/dist/builtins/platform-probe/coral-accelerators.d.ts +87 -0
- package/system/dist/builtins/platform-probe/index.d.ts +57 -0
- package/system/dist/builtins/platform-probe/index.js +1151 -0
- package/system/dist/builtins/platform-probe/index.mjs +1140 -0
- package/system/dist/builtins/platform-probe/inference-config-resolver.d.ts +29 -0
- package/system/dist/builtins/platform-probe/intel-accelerators.d.ts +14 -0
- package/system/dist/builtins/platform-probe/intel-npu.d.ts +38 -0
- package/system/dist/builtins/platform-probe/platform-scorer.d.ts +66 -0
- package/system/dist/builtins/platform-probe/runtime-packages.d.ts +6 -0
- package/system/dist/builtins/platform-probe/windows-hardware.d.ts +77 -0
- package/system/dist/builtins/record-entries/entries-service.d.ts +42 -0
- package/system/dist/builtins/record-entries/index.d.ts +1 -0
- package/system/dist/builtins/record-entries/index.js +162 -0
- package/system/dist/builtins/record-entries/index.mjs +156 -0
- package/system/dist/builtins/record-entries/record-entries.addon.d.ts +13 -0
- package/system/dist/builtins/records-isolated.d.ts +10 -0
- package/system/dist/builtins/remote-access-orchestrator/enabled-providers-reconcile.d.ts +96 -0
- package/system/dist/builtins/remote-access-orchestrator/index.d.ts +1 -0
- package/system/dist/builtins/remote-access-orchestrator/index.js +8 -0
- package/system/dist/builtins/remote-access-orchestrator/index.mjs +2 -0
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.d.ts +71 -0
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +214 -0
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +208 -0
- package/system/dist/builtins/shared/device-state-changed.d.ts +16 -0
- package/system/dist/builtins/shared/settle-sources.d.ts +22 -0
- package/system/dist/builtins/snapshot/index.d.ts +2 -0
- package/system/dist/builtins/snapshot/index.js +2720 -0
- package/system/dist/builtins/snapshot/index.mjs +2713 -0
- package/system/dist/builtins/snapshot/snapshot-cache.d.ts +108 -0
- package/system/dist/builtins/snapshot/snapshot-coalescing.d.ts +135 -0
- package/system/dist/builtins/snapshot/snapshot-courtesy.d.ts +68 -0
- package/system/dist/builtins/snapshot/snapshot-durable-store.d.ts +36 -0
- package/system/dist/builtins/snapshot/snapshot-fatigue.d.ts +41 -0
- package/system/dist/builtins/snapshot/snapshot-grab-pick.d.ts +20 -0
- package/system/dist/builtins/snapshot/snapshot-link-url.d.ts +66 -0
- package/system/dist/builtins/snapshot/snapshot-media-handler.d.ts +121 -0
- package/system/dist/builtins/snapshot/snapshot-resize.d.ts +75 -0
- package/system/dist/builtins/snapshot/snapshot.addon.d.ts +581 -0
- package/system/dist/builtins/sqlite-storage/analyze-stats.d.ts +83 -0
- package/system/dist/builtins/sqlite-storage/config-store.d.ts +8 -0
- package/system/dist/builtins/sqlite-storage/database-snapshot-provider.d.ts +18 -0
- package/system/dist/builtins/sqlite-storage/device-store.d.ts +23 -0
- package/system/dist/builtins/sqlite-storage/file-host-client.d.ts +75 -0
- package/system/dist/builtins/sqlite-storage/file-host-handlers.d.ts +27 -0
- package/system/dist/builtins/sqlite-storage/file-host-protocol.d.ts +167 -0
- package/system/dist/builtins/sqlite-storage/file-host-worker.d.ts +1 -0
- package/system/dist/builtins/sqlite-storage/filesystem-browse-provider.d.ts +25 -0
- package/system/dist/builtins/sqlite-storage/filesystem-storage-provider.d.ts +83 -0
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.d.ts +33 -0
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +419 -0
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +411 -0
- package/system/dist/builtins/sqlite-storage/filter-compiler.d.ts +126 -0
- package/system/dist/builtins/sqlite-storage/index.d.ts +12 -0
- package/system/dist/builtins/sqlite-storage/index.js +82 -0
- package/system/dist/builtins/sqlite-storage/index.mjs +50 -0
- package/system/dist/builtins/sqlite-storage/integration-record-kinds.d.ts +31 -0
- package/system/dist/builtins/sqlite-storage/integration-registry.d.ts +34 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-actions.d.ts +12 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-edits.d.ts +35 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-engine.d.ts +125 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-hold.d.ts +23 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-pass.d.ts +48 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-restore-marker.d.ts +3 -0
- package/system/dist/builtins/sqlite-storage/migrations/migration-types.d.ts +151 -0
- package/system/dist/builtins/sqlite-storage/migrations/migrations-provider.d.ts +61 -0
- package/system/dist/builtins/sqlite-storage/owned-sqlite-file.d.ts +173 -0
- package/system/dist/builtins/sqlite-storage/path-guard.d.ts +11 -0
- package/system/dist/builtins/sqlite-storage/placement-errors.d.ts +60 -0
- package/system/dist/builtins/sqlite-storage/placement-router.d.ts +85 -0
- package/system/dist/builtins/sqlite-storage/prefix-range.d.ts +50 -0
- package/system/dist/builtins/sqlite-storage/query-bounds.d.ts +110 -0
- package/system/dist/builtins/sqlite-storage/query-profiler.d.ts +242 -0
- package/system/dist/builtins/sqlite-storage/records/records-catalog.d.ts +27 -0
- package/system/dist/builtins/sqlite-storage/records/records-engine-types.d.ts +48 -0
- package/system/dist/builtins/sqlite-storage/records/records-engine.d.ts +115 -0
- package/system/dist/builtins/sqlite-storage/records/records-explain.d.ts +18 -0
- package/system/dist/builtins/sqlite-storage/records/records-plan.d.ts +95 -0
- package/system/dist/builtins/sqlite-storage/records/records-probe.d.ts +33 -0
- package/system/dist/builtins/sqlite-storage/records/records-provider.d.ts +72 -0
- package/system/dist/builtins/sqlite-storage/records/records-rows.d.ts +46 -0
- package/system/dist/builtins/sqlite-storage/records/records-sql.d.ts +39 -0
- package/system/dist/builtins/sqlite-storage/retired-settings-keys.d.ts +276 -0
- package/system/dist/builtins/sqlite-storage/shm-lock-canary.d.ts +60 -0
- package/system/dist/builtins/sqlite-storage/sqlite-pragmas.d.ts +191 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings-backend.d.ts +583 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.d.ts +52 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +2960 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +2952 -0
- package/system/dist/builtins/sqlite-storage/sqlite-snapshot-protocol.d.ts +54 -0
- package/system/dist/builtins/sqlite-storage/sqlite-snapshot-worker.d.ts +33 -0
- package/system/dist/builtins/sqlite-storage/sqlite-snapshotter.d.ts +118 -0
- package/system/dist/builtins/sqlite-storage/stale-data/stale-data-audit.d.ts +81 -0
- package/system/dist/builtins/sqlite-storage/stale-data/stale-data-ports.d.ts +17 -0
- package/system/dist/builtins/sqlite-storage/statement-shape.d.ts +64 -0
- package/system/dist/builtins/sqlite-storage/storage-admin-provider.d.ts +33 -0
- package/system/dist/builtins/sqlite-storage/table-sizes.d.ts +95 -0
- package/system/dist/builtins/sqlite-storage/vector-index-shared.d.ts +81 -0
- package/system/dist/builtins/sqlite-storage/vector-index-vec.d.ts +143 -0
- package/system/dist/builtins/sqlite-storage/vector-provider.d.ts +30 -0
- package/system/dist/builtins/sqlite-storage/wal-checkpoint-policy.d.ts +196 -0
- package/system/dist/builtins/sqlite-storage/wal-checkpoint-worker.d.ts +1 -0
- package/system/dist/builtins/sqlite-storage/wal-checkpointer.d.ts +76 -0
- package/system/dist/builtins/sqlite-storage/wal-maintenance.d.ts +130 -0
- package/system/dist/builtins/storage-orchestrator/access-guards.d.ts +43 -0
- package/system/dist/builtins/storage-orchestrator/data-store-dispatch.d.ts +39 -0
- package/system/dist/builtins/storage-orchestrator/drain-ratchet.d.ts +104 -0
- package/system/dist/builtins/storage-orchestrator/drain-state-store.d.ts +26 -0
- package/system/dist/builtins/storage-orchestrator/hub-settings-forward.d.ts +128 -0
- package/system/dist/builtins/storage-orchestrator/index.d.ts +7 -0
- package/system/dist/builtins/storage-orchestrator/index.js +11 -0
- package/system/dist/builtins/storage-orchestrator/index.mjs +2 -0
- package/system/dist/builtins/storage-orchestrator/location-class-paths.d.ts +13 -0
- package/system/dist/builtins/storage-orchestrator/location-history-recorder.d.ts +76 -0
- package/system/dist/builtins/storage-orchestrator/location-occupancy-slice.d.ts +71 -0
- package/system/dist/builtins/storage-orchestrator/location-occupancy.d.ts +19 -0
- package/system/dist/builtins/storage-orchestrator/location-protection.d.ts +20 -0
- package/system/dist/builtins/storage-orchestrator/location-repoint-move.d.ts +57 -0
- package/system/dist/builtins/storage-orchestrator/location-repointer.d.ts +97 -0
- package/system/dist/builtins/storage-orchestrator/location-root-collision.d.ts +80 -0
- package/system/dist/builtins/storage-orchestrator/location-secrets.d.ts +114 -0
- package/system/dist/builtins/storage-orchestrator/location-store.d.ts +82 -0
- package/system/dist/builtins/storage-orchestrator/location-volume-capacity.d.ts +58 -0
- package/system/dist/builtins/storage-orchestrator/provider-discovery.d.ts +24 -0
- package/system/dist/builtins/storage-orchestrator/record-kinds.d.ts +43 -0
- package/system/dist/builtins/storage-orchestrator/storage-cleanup-coordinator.d.ts +68 -0
- package/system/dist/builtins/storage-orchestrator/storage-location-band-monitor.d.ts +77 -0
- package/system/dist/builtins/storage-orchestrator/storage-migration-coordinator.d.ts +241 -0
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.d.ts +318 -0
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +5280 -0
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +5264 -0
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.service.d.ts +475 -0
- package/system/dist/builtins/storage-orchestrator/storage-pressure-manager.d.ts +115 -0
- package/system/dist/builtins/system-backup/backup-encryption.d.ts +94 -0
- package/system/dist/builtins/system-backup/system-backup.service.d.ts +308 -0
- package/system/dist/builtins/system-config/index.d.ts +2 -0
- package/system/dist/builtins/system-config/index.js +10 -0
- package/system/dist/builtins/system-config/index.mjs +2 -0
- package/system/dist/builtins/system-config/mesh-actions.d.ts +3 -0
- package/system/dist/builtins/system-config/record-kinds.d.ts +32 -0
- package/system/dist/builtins/system-config/system-config.addon.d.ts +56 -0
- package/system/dist/builtins/system-config/system-config.addon.js +89334 -0
- package/system/dist/builtins/system-config/system-config.addon.mjs +89233 -0
- package/system/dist/builtins/winston-logging/index.d.ts +3 -0
- package/system/dist/builtins/winston-logging/index.js +324 -0
- package/system/dist/builtins/winston-logging/index.mjs +313 -0
- package/system/dist/builtins/winston-logging/log-file-cursor.d.ts +12 -0
- package/system/dist/builtins/winston-logging/log-file-index-store.d.ts +11 -0
- package/system/dist/builtins/winston-logging/log-file-index.d.ts +77 -0
- package/system/dist/builtins/winston-logging/log-file-read-client.d.ts +44 -0
- package/system/dist/builtins/winston-logging/log-file-read-protocol.d.ts +41 -0
- package/system/dist/builtins/winston-logging/log-file-read-worker.d.ts +1 -0
- package/system/dist/builtins/winston-logging/log-file-reader.d.ts +51 -0
- package/system/dist/builtins/winston-logging/winston-destination.d.ts +39 -0
- package/system/dist/builtins/winston-logging/winston-logging.addon.d.ts +20 -0
- package/system/dist/chunk-CNf5ZN-e.mjs +37 -0
- package/system/dist/chunk-Cek0wNdY.js +64 -0
- package/system/dist/composition-sources-C14epb_m.js +155 -0
- package/system/dist/composition-sources-EXNuxmGQ.mjs +132 -0
- package/system/dist/constants-DIGWBiNC.mjs +20 -0
- package/system/dist/constants-M7NtSiRo.js +66 -0
- package/system/dist/coral-accelerators-BSVsBVzt.js +250 -0
- package/system/dist/coral-accelerators-DBlgWB8k.mjs +231 -0
- package/system/dist/custom-action-registry-JuMHGKEc.js +1638 -0
- package/system/dist/custom-action-registry-oHl1xltx.mjs +1482 -0
- package/system/dist/device-ca-3vmBP1i0.js +474 -0
- package/system/dist/device-ca-DZlvNBWU.mjs +367 -0
- package/system/dist/dist-DcMqHB_N.mjs +108095 -0
- package/system/dist/dist-M9yHiIY7.js +110554 -0
- package/system/dist/download/hosted-model-revisions.d.ts +10 -0
- package/system/dist/download/model-download-service.d.ts +35 -0
- package/system/dist/download/model-downloader.d.ts +156 -0
- package/system/dist/events/event-bus.d.ts +10 -0
- package/system/dist/events/system-event-bus.d.ts +14 -0
- package/system/dist/feature/feature-manager.d.ts +11 -0
- package/system/dist/file-host-worker.js +160 -0
- package/system/dist/file-host-worker.mjs +160 -0
- package/system/dist/formatter-DkYZ4LXp.mjs +162 -0
- package/system/dist/formatter-xbxeV4GD.js +167 -0
- package/system/dist/framework-resolver-hook.mjs +49 -0
- package/system/dist/http/asset-compression.d.ts +55 -0
- package/system/dist/http/authenticated-file-server.d.ts +53 -0
- package/system/dist/http/data-plane-registry.d.ts +58 -0
- package/system/dist/http/file-data-plane.d.ts +18 -0
- package/system/dist/http/lan-http-bind.d.ts +41 -0
- package/system/dist/http/reverse-proxy.d.ts +42 -0
- package/system/dist/hub-mdns-ciao-CpCKuQnK.js +1163 -0
- package/system/dist/hub-mdns-ciao-Czz2ssit.mjs +942 -0
- package/system/dist/i18n/catalog-registry.d.ts +35 -0
- package/system/dist/i18n/index.d.ts +2 -0
- package/system/dist/index.d.ts +156 -0
- package/system/dist/index.js +28736 -0
- package/system/dist/index.mjs +28065 -0
- package/system/dist/intel-accelerators-BvBjZn4j.js +16 -0
- package/system/dist/intel-accelerators-idEumqk1.mjs +15 -0
- package/system/dist/intel-npu-C8HKvRQF.mjs +27 -0
- package/system/dist/intel-npu-DYF5hO5K.js +28 -0
- package/system/dist/kernel/addon-class-resolver.d.ts +4 -0
- package/system/dist/kernel/addon-engine-manager.d.ts +22 -0
- package/system/dist/kernel/addon-health-monitor.d.ts +163 -0
- package/system/dist/kernel/addon-installer.d.ts +651 -0
- package/system/dist/kernel/addon-loader.d.ts +144 -0
- package/system/dist/kernel/addon-manifest.d.ts +128 -0
- package/system/dist/kernel/addon-refused-error.d.ts +30 -0
- package/system/dist/kernel/addon-residue.d.ts +45 -0
- package/system/dist/kernel/addon-settings-store.d.ts +43 -0
- package/system/dist/kernel/addon-version-policy.d.ts +34 -0
- package/system/dist/kernel/anon-rss.d.ts +12 -0
- package/system/dist/kernel/array-buffer-census.d.ts +118 -0
- package/system/dist/kernel/bootstrap-config.d.ts +7 -0
- package/system/dist/kernel/cap-router-builder.d.ts +180 -0
- package/system/dist/kernel/capability-handle.d.ts +46 -0
- package/system/dist/kernel/capability-registry.d.ts +621 -0
- package/system/dist/kernel/config-manager.d.ts +174 -0
- package/system/dist/kernel/config-schema.d.ts +37 -0
- package/system/dist/kernel/custom-action-registry.d.ts +32 -0
- package/system/dist/kernel/deps/addon-deps-manager.d.ts +28 -0
- package/system/dist/kernel/deps/closure-dedupe.d.ts +105 -0
- package/system/dist/kernel/deps/ensure-addon-natives.d.ts +41 -0
- package/system/dist/kernel/deps/ensure-native-prebuilds.d.ts +40 -0
- package/system/dist/kernel/deps/manifest-native-deps.d.ts +42 -0
- package/system/dist/kernel/deps/manifest-python-deps.d.ts +20 -0
- package/system/dist/kernel/deps/manifest-system-deps.d.ts +18 -0
- package/system/dist/kernel/deps/npm-command.d.ts +60 -0
- package/system/dist/kernel/deps/system-package-allowlist.d.ts +12 -0
- package/system/dist/kernel/deps/system-package-broker.d.ts +31 -0
- package/system/dist/kernel/deps/system-package-client.d.ts +9 -0
- package/system/dist/kernel/device-call-redirect.d.ts +18 -0
- package/system/dist/kernel/device-registry.d.ts +29 -0
- package/system/dist/kernel/device-settings-store.d.ts +74 -0
- package/system/dist/kernel/event-loop-stall-monitor.d.ts +41 -0
- package/system/dist/kernel/event-plane-report.d.ts +225 -0
- package/system/dist/kernel/fs-utils.d.ts +88 -0
- package/system/dist/kernel/gc-census.d.ts +161 -0
- package/system/dist/kernel/heap-spaces.d.ts +112 -0
- package/system/dist/kernel/heap-watch.d.ts +816 -0
- package/system/dist/kernel/host-externals.d.ts +12 -0
- package/system/dist/kernel/hwaccel/hwaccel-resolver.d.ts +56 -0
- package/system/dist/kernel/hwaccel/vaapi-init-probe.d.ts +29 -0
- package/system/dist/kernel/index.d.ts +116 -0
- package/system/dist/kernel/inference/inference-resolver.d.ts +22 -0
- package/system/dist/kernel/inference/local-python-runtimes.d.ts +2 -0
- package/system/dist/kernel/infra-capabilities.d.ts +13 -0
- package/system/dist/kernel/isolated-builtin-phase.d.ts +57 -0
- package/system/dist/kernel/lifecycle/job-journal.d.ts +19 -0
- package/system/dist/kernel/lifecycle/lifecycle-job-engine.d.ts +106 -0
- package/system/dist/kernel/lifecycle/staging-area.d.ts +31 -0
- package/system/dist/kernel/moleculer/accessory-prune-gate.d.ts +55 -0
- package/system/dist/kernel/moleculer/addon-context-factory.d.ts +104 -0
- package/system/dist/kernel/moleculer/addon-data-plane-facility.d.ts +19 -0
- package/system/dist/kernel/moleculer/addon-deploy-source.d.ts +16 -0
- package/system/dist/kernel/moleculer/addon-peer-bytes-facility.d.ts +25 -0
- package/system/dist/kernel/moleculer/addon-runner.d.ts +1 -0
- package/system/dist/kernel/moleculer/addon-service-factory.d.ts +50 -0
- package/system/dist/kernel/moleculer/agent-event-scope.d.ts +49 -0
- package/system/dist/kernel/moleculer/agent-ui-unlock.d.ts +67 -0
- package/system/dist/kernel/moleculer/broker-factory.d.ts +95 -0
- package/system/dist/kernel/moleculer/broker-transport-swap.d.ts +60 -0
- package/system/dist/kernel/moleculer/cap-usage-registry.d.ts +126 -0
- package/system/dist/kernel/moleculer/capabilities-access.d.ts +21 -0
- package/system/dist/kernel/moleculer/child-addon-call-dispatch.d.ts +53 -0
- package/system/dist/kernel/moleculer/child-cap-descriptors.d.ts +34 -0
- package/system/dist/kernel/moleculer/child-cap-dispatch.d.ts +59 -0
- package/system/dist/kernel/moleculer/children-batch-loader.d.ts +98 -0
- package/system/dist/kernel/moleculer/core-cap-service.d.ts +65 -0
- package/system/dist/kernel/moleculer/crash-supervisor.d.ts +50 -0
- package/system/dist/kernel/moleculer/device-cap-proxy.d.ts +70 -0
- package/system/dist/kernel/moleculer/device-event-ring.d.ts +155 -0
- package/system/dist/kernel/moleculer/event-bus-core.d.ts +198 -0
- package/system/dist/kernel/moleculer/event-bus.d.ts +106 -0
- package/system/dist/kernel/moleculer/hub-log-forwarder.d.ts +36 -0
- package/system/dist/kernel/moleculer/hub-service.d.ts +39 -0
- package/system/dist/kernel/moleculer/init-watchdog.d.ts +60 -0
- package/system/dist/kernel/moleculer/mesh-access-middleware.d.ts +42 -0
- package/system/dist/kernel/moleculer/mesh-identity.d.ts +57 -0
- package/system/dist/kernel/moleculer/mesh-mtls/constants.d.ts +17 -0
- package/system/dist/kernel/moleculer/mesh-mtls/index.d.ts +12 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-ca-keeper.d.ts +60 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-ca.d.ts +49 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-certificate-registry.d.ts +105 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-crl.d.ts +16 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-membership.d.ts +64 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-peer-transport.d.ts +47 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-renewal.d.ts +135 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-tls-enabler.d.ts +9 -0
- package/system/dist/kernel/moleculer/mesh-mtls/mesh-tls-gate.d.ts +40 -0
- package/system/dist/kernel/moleculer/mesh-mtls/pairing/agent-pairing.d.ts +214 -0
- package/system/dist/kernel/moleculer/mesh-mtls/pairing/hub-pairing.d.ts +115 -0
- package/system/dist/kernel/moleculer/mesh-mtls/pairing/index.d.ts +3 -0
- package/system/dist/kernel/moleculer/mesh-mtls/pairing/pairing-protocol.d.ts +107 -0
- package/system/dist/kernel/moleculer/mesh-mtls/tls-tcp-transporter.d.ts +242 -0
- package/system/dist/kernel/moleculer/mesh-queue-report.d.ts +51 -0
- package/system/dist/kernel/moleculer/node-registry.d.ts +146 -0
- package/system/dist/kernel/moleculer/process-context.d.ts +4 -0
- package/system/dist/kernel/moleculer/process-service.d.ts +92 -0
- package/system/dist/kernel/moleculer/provider-registry.d.ts +28 -0
- package/system/dist/kernel/moleculer/readiness-context.d.ts +67 -0
- package/system/dist/kernel/moleculer/readiness-service.d.ts +37 -0
- package/system/dist/kernel/moleculer/records-api-transport.d.ts +9 -0
- package/system/dist/kernel/moleculer/register-framework-resolver.d.ts +8 -0
- package/system/dist/kernel/moleculer/register-node-client.d.ts +49 -0
- package/system/dist/kernel/moleculer/remote-logger.d.ts +43 -0
- package/system/dist/kernel/moleculer/resilient-cap-call.d.ts +28 -0
- package/system/dist/kernel/moleculer/runner-addon-settings.d.ts +29 -0
- package/system/dist/kernel/moleculer/runner-device-settings.d.ts +39 -0
- package/system/dist/kernel/moleculer/runner-heap-flags.d.ts +228 -0
- package/system/dist/kernel/moleculer/runner-native-allocator.d.ts +107 -0
- package/system/dist/kernel/moleculer/runner-process-group.d.ts +96 -0
- package/system/dist/kernel/moleculer/runner-refusal.d.ts +27 -0
- package/system/dist/kernel/moleculer/runtime-state-load.d.ts +29 -0
- package/system/dist/kernel/moleculer/settings-read-guard.d.ts +49 -0
- package/system/dist/kernel/moleculer/stream-probe-service.d.ts +28 -0
- package/system/dist/kernel/moleculer/trpc-links.d.ts +244 -0
- package/system/dist/kernel/moleculer/typed-array-serde.d.ts +14 -0
- package/system/dist/kernel/moleculer/worker-device-restore.d.ts +10 -0
- package/system/dist/kernel/outbound-queue-watch.d.ts +94 -0
- package/system/dist/kernel/prefix-walk.d.ts +39 -0
- package/system/dist/kernel/process-cpu-census.d.ts +74 -0
- package/system/dist/kernel/provider-kind-drift.d.ts +21 -0
- package/system/dist/kernel/restart-coordinator.d.ts +90 -0
- package/system/dist/kernel/sections-store.d.ts +20 -0
- package/system/dist/kernel/settings-door-view.d.ts +41 -0
- package/system/dist/kernel/settings-read-error.d.ts +35 -0
- package/system/dist/kernel/settings-view-types.d.ts +80 -0
- package/system/dist/kernel/socket-plane-report.d.ts +268 -0
- package/system/dist/kernel/status-overlay.d.ts +38 -0
- package/system/dist/kernel/storage-location-registry.d.ts +55 -0
- package/system/dist/kernel/store-settings-view.d.ts +14 -0
- package/system/dist/kernel/system-settings-mirror.d.ts +46 -0
- package/system/dist/kernel/system-settings-policy.d.ts +28 -0
- package/system/dist/kernel/transport/cap-action-census.d.ts +218 -0
- package/system/dist/kernel/transport/cap-action-name.d.ts +100 -0
- package/system/dist/kernel/transport/cap-child-index.d.ts +49 -0
- package/system/dist/kernel/transport/cap-route-resolver.d.ts +231 -0
- package/system/dist/kernel/transport/cap-route.d.ts +168 -0
- package/system/dist/kernel/transport/cap-routing-hints.d.ts +42 -0
- package/system/dist/kernel/transport/child-cap-protocol.d.ts +307 -0
- package/system/dist/kernel/transport/claimed-get-status.d.ts +39 -0
- package/system/dist/kernel/transport/create-local-transport.d.ts +7 -0
- package/system/dist/kernel/transport/device-call-redirect.d.ts +39 -0
- package/system/dist/kernel/transport/frame-codec.d.ts +122 -0
- package/system/dist/kernel/transport/hub-cap-forward.d.ts +96 -0
- package/system/dist/kernel/transport/index.d.ts +38 -0
- package/system/dist/kernel/transport/local-child-client.d.ts +199 -0
- package/system/dist/kernel/transport/local-child-registry.d.ts +654 -0
- package/system/dist/kernel/transport/local-endpoint-path.d.ts +6 -0
- package/system/dist/kernel/transport/local-transport.d.ts +122 -0
- package/system/dist/kernel/transport/parent-unowned-call.d.ts +283 -0
- package/system/dist/kernel/transport/peer-answered-error.d.ts +21 -0
- package/system/dist/kernel/transport/socket-channel.d.ts +116 -0
- package/system/dist/kernel/transport/socket-traffic.d.ts +118 -0
- package/system/dist/kernel/transport/uds-event-bridge.d.ts +85 -0
- package/system/dist/kernel/transport/uds-event-bus.d.ts +93 -0
- package/system/dist/kernel/transport/uds-local-transport.d.ts +18 -0
- package/system/dist/kernel/transport/uds-log-ingest.d.ts +43 -0
- package/system/dist/kernel/transport/uds-logger.d.ts +44 -0
- package/system/dist/kernel/utils/ring-buffer.d.ts +15 -0
- package/system/dist/kernel/workspace-detect.d.ts +9 -0
- package/system/dist/lib-5THG9eKz.mjs +15545 -0
- package/system/dist/lib-C3U1yluo.js +7110 -0
- package/system/dist/lib-CZ3g2WTS.js +15549 -0
- package/system/dist/lib-DFZblCIu.mjs +7106 -0
- package/system/dist/lifecycle/lifecycle-state-machine.d.ts +28 -0
- package/system/dist/log-file-read-protocol-B7M3X3bT.mjs +785 -0
- package/system/dist/log-file-read-protocol-D0WcLbIV.js +817 -0
- package/system/dist/log-file-read-worker.js +64 -0
- package/system/dist/log-file-read-worker.mjs +64 -0
- package/system/dist/log-read-filter-Bi066jwU.js +134 -0
- package/system/dist/log-read-filter-D7Ev3zm-.mjs +93 -0
- package/system/dist/logging/formatter.d.ts +57 -0
- package/system/dist/logging/log-manager.d.ts +145 -0
- package/system/dist/logging/log-read-filter.d.ts +43 -0
- package/system/dist/logging/log-redactor.d.ts +30 -0
- package/system/dist/logging/log-ring-buffer.d.ts +62 -0
- package/system/dist/logging/logging-gate.d.ts +76 -0
- package/system/dist/logging/logging-gate.singleton.d.ts +16 -0
- package/system/dist/logging/partitioned-log-buffer.d.ts +169 -0
- package/system/dist/logging/scoped-logger.d.ts +17 -0
- package/system/dist/migrations/hub/index.d.ts +11 -0
- package/system/dist/ms-CgH2OFlD.mjs +120 -0
- package/system/dist/ms-LB3giGoU.js +124 -0
- package/system/dist/network/network-quality.d.ts +11 -0
- package/system/dist/notification/notification-service.d.ts +43 -0
- package/system/dist/notification/toast-service.d.ts +22 -0
- package/system/dist/pipeline/engine-manager-resolver.d.ts +15 -0
- package/system/dist/pipeline/pipeline-runner.d.ts +8 -0
- package/system/dist/pipeline/pipeline-validator.d.ts +13 -0
- package/system/dist/platform-key-source-BWlq0jjn.mjs +23 -0
- package/system/dist/platform-key-source-Di7HrlGR.js +40 -0
- package/system/dist/prefix-range-D_KueXbQ.js +27 -0
- package/system/dist/prefix-range-Dl0znowN.mjs +22 -0
- package/system/dist/prefix-walk-DAOBSyH1.mjs +88 -0
- package/system/dist/prefix-walk-Dv6MLZlM.js +99 -0
- package/system/dist/process/proc-stat.d.ts +75 -0
- package/system/dist/process/resource-monitor.d.ts +28 -0
- package/system/dist/python/python-env-manager.d.ts +12 -0
- package/system/dist/read-all-rows-CVoO1ONM.js +29 -0
- package/system/dist/read-all-rows-TaPqdWNF.mjs +25 -0
- package/system/dist/records/read-all-rows.d.ts +6 -0
- package/system/dist/repl/interfaces.d.ts +31 -0
- package/system/dist/repl/repl-engine.d.ts +8 -0
- package/system/dist/resource-monitor-Di9daRwI.mjs +96 -0
- package/system/dist/resource-monitor-mio9dSCT.js +113 -0
- package/system/dist/restore-archive-Cy7jGqiD.js +4325 -0
- package/system/dist/restore-archive-DS4nvQ43.mjs +4213 -0
- package/system/dist/retention-Dqm_EiVq.mjs +893 -0
- package/system/dist/retention-Ufa2fci-.js +1024 -0
- package/system/dist/retired-settings-keys-C8nOOr5H.js +381 -0
- package/system/dist/retired-settings-keys-u6xQA6r7.mjs +364 -0
- package/system/dist/safe-buffer-B1OjL1I9.mjs +42 -0
- package/system/dist/safe-buffer-D3aoa-7X.js +46 -0
- package/system/dist/settle-sources-Bhsy57y-.js +38 -0
- package/system/dist/settle-sources-CDtNC8ub.mjs +33 -0
- package/system/dist/snapshot-courtesy-CyFs1M3I.mjs +167 -0
- package/system/dist/snapshot-courtesy-D_C5-nC0.js +192 -0
- package/system/dist/sqlite-snapshot-protocol-2QaTouWV.mjs +34 -0
- package/system/dist/sqlite-snapshot-protocol-B9OndqZv.js +51 -0
- package/system/dist/sqlite-snapshot-worker.js +185 -0
- package/system/dist/sqlite-snapshot-worker.mjs +179 -0
- package/system/dist/src-CnAqG6EF.js +714 -0
- package/system/dist/src-hG4grMU4.mjs +709 -0
- package/system/dist/storage/fs-storage-backend.d.ts +40 -0
- package/system/dist/storage/storage-location-manager.d.ts +23 -0
- package/system/dist/storage/storage-manager.d.ts +83 -0
- package/system/dist/tls/agent-https-names.d.ts +25 -0
- package/system/dist/tls/agent-https.d.ts +111 -0
- package/system/dist/tls/boot-tls.d.ts +35 -0
- package/system/dist/tls/cert-backdate.d.ts +10 -0
- package/system/dist/tls/cert-evaluation.d.ts +41 -0
- package/system/dist/tls/cert-identity.d.ts +60 -0
- package/system/dist/tls/cert-issue.d.ts +57 -0
- package/system/dist/tls/cert-manager.d.ts +124 -0
- package/system/dist/tls/cert-name-constraints.d.ts +53 -0
- package/system/dist/tls/cert-utc-time.d.ts +1 -0
- package/system/dist/tls/https-listener.d.ts +30 -0
- package/system/dist/tls/index.d.ts +12 -0
- package/system/dist/tls/tls-actions.d.ts +49 -0
- package/system/dist/tls/tls-status.d.ts +57 -0
- package/system/dist/tls/uploaded-cert.d.ts +46 -0
- package/system/dist/wal-checkpoint-policy-BahrTtyD.mjs +186 -0
- package/system/dist/wal-checkpoint-policy-d2z2qPqx.js +233 -0
- package/system/dist/wal-checkpoint-worker.js +144 -0
- package/system/dist/wal-checkpoint-worker.mjs +143 -0
- package/system/dist/wal-maintenance-BmugbgS7.js +0 -0
- package/system/dist/wal-maintenance-Bnb2QzYG.mjs +0 -0
- package/system/dist/x509.es-BRiJgOvu.mjs +11939 -0
- package/system/dist/x509.es-WtnRNyYS.js +12076 -0
- package/system/package.json +516 -0
|
@@ -0,0 +1,3994 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
require("../../chunk-Cek0wNdY.js");
|
|
6
|
+
const require_dist = require("../../dist-M9yHiIY7.js");
|
|
7
|
+
let zod = require("zod");
|
|
8
|
+
let _camstack_types_node = require("@camstack/types/node");
|
|
9
|
+
let node_path = require("node:path");
|
|
10
|
+
let node_fs = require("node:fs");
|
|
11
|
+
let node_child_process = require("node:child_process");
|
|
12
|
+
let node_http = require("node:http");
|
|
13
|
+
//#region src/builtins/camera-grid/grid-camera-declarations.ts
|
|
14
|
+
/**
|
|
15
|
+
* Turning persisted grid rows into the camera declarations `DeclaredDevices`
|
|
16
|
+
* reconciles.
|
|
17
|
+
*
|
|
18
|
+
* Modelled on `terminal-camera-declarations.ts`, and for the same reasons: the
|
|
19
|
+
* declaration set is the ONLY thing standing between a transient RPC failure
|
|
20
|
+
* and a sweep that deletes every camera this addon owns.
|
|
21
|
+
*/
|
|
22
|
+
/** The prefix every stable id this addon has ever minted starts with. */
|
|
23
|
+
var GRID_CAMERA_STABLE_ID_PREFIX = "camera-grid-";
|
|
24
|
+
/**
|
|
25
|
+
* The stable id is `camera-grid-<instance uuid>` and NOTHING else.
|
|
26
|
+
*
|
|
27
|
+
* A stable id is permanent the instant it is minted: bindings, grid layouts in
|
|
28
|
+
* other addons, recording rows, the timeline and this addon's own tombstones
|
|
29
|
+
* all reference it, and a device whose stable id changes is a NEW camera with
|
|
30
|
+
* an empty history. So it may only be derived from something that itself never
|
|
31
|
+
* changes.
|
|
32
|
+
*
|
|
33
|
+
* The instance uuid is the only such thing here. Deriving it from the NAME
|
|
34
|
+
* would rename-break every reference; deriving it from the CELLS would mint a
|
|
35
|
+
* new camera every time the operator drags a rectangle — which is the entire
|
|
36
|
+
* activity this addon exists for. Terminal learned the same lesson from the
|
|
37
|
+
* other end: its original one-camera-per-node id is permanent, and its profile
|
|
38
|
+
* migration had to ENRICH that row rather than mint a replacement.
|
|
39
|
+
*/
|
|
40
|
+
function newGridCameraStableId(instanceId) {
|
|
41
|
+
return `${GRID_CAMERA_STABLE_ID_PREFIX}${instanceId}`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Explicit persisted instances only. A grid camera exists because an operator
|
|
45
|
+
* created a grid, never because some source camera happens to exist.
|
|
46
|
+
*
|
|
47
|
+
* A grid with NO cells is declared like any other: creation is name-only and
|
|
48
|
+
* the layout is authored afterwards in the camera's own device details, so
|
|
49
|
+
* "no cells yet" is the normal first state, not an invalid row.
|
|
50
|
+
*/
|
|
51
|
+
function buildGridCameraDeclarations(instances) {
|
|
52
|
+
return instances.filter((instance) => instance.enabled).map((instance) => ({
|
|
53
|
+
stableId: instance.cameraStableId,
|
|
54
|
+
name: instance.name,
|
|
55
|
+
config: { instanceId: instance.id }
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The rows `DeclaredDevices` is allowed to consider — every live declaration
|
|
60
|
+
* plus ONE bounded batch of orphans.
|
|
61
|
+
*
|
|
62
|
+
* Two guards, both copied from Terminal because both were paid for there:
|
|
63
|
+
*
|
|
64
|
+
* 1. **An unknown integration id yields an EMPTY index.** `null`/`undefined`
|
|
65
|
+
* means "the integration lookup has not answered", which is not the same
|
|
66
|
+
* fact as "this addon owns no rows" — and only the second one may drive a
|
|
67
|
+
* withdrawal.
|
|
68
|
+
* 2. **The orphan batch is bounded and deterministically ordered.** The generic
|
|
69
|
+
* sweep refuses an over-limit set outright; selecting a batch here drains a
|
|
70
|
+
* large historical orphan set across passes without weakening that guard.
|
|
71
|
+
*/
|
|
72
|
+
function gridCameraReconciliationIndex(rows, integrationId, declarations, managedStableIds = /* @__PURE__ */ new Set()) {
|
|
73
|
+
if (!integrationId) return [];
|
|
74
|
+
const declared = new Set(declarations.map((camera) => camera.stableId));
|
|
75
|
+
const owned = rows.filter((row) => row.integrationId === integrationId && (declared.has(row.stableId) || managedStableIds.has(row.stableId) || row.stableId.startsWith(GRID_CAMERA_STABLE_ID_PREFIX)));
|
|
76
|
+
return [...owned.filter((row) => declared.has(row.stableId)), ...owned.filter((row) => !declared.has(row.stableId)).sort((left, right) => left.id - right.id).slice(0, 32)];
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/builtins/camera-grid/grid-device-settings.ts
|
|
80
|
+
/** The widget id, registered in `ui-library`'s `HOST_WIDGETS`. */
|
|
81
|
+
var GRID_LAYOUT_WIDGET_ID = "host/camera-grid-layout";
|
|
82
|
+
/**
|
|
83
|
+
* The layout section, or `null` when this device is not a grid.
|
|
84
|
+
*
|
|
85
|
+
* `isGrid` is the ANSWER to "is this a grid", never "do we know yet". A caller
|
|
86
|
+
* that cannot tell must not call this — an unresolved read rendered as `null`
|
|
87
|
+
* would hide the editor from a real grid (D315).
|
|
88
|
+
*/
|
|
89
|
+
function buildGridDeviceSchema(isGrid) {
|
|
90
|
+
if (!isGrid) return null;
|
|
91
|
+
return { sections: [{
|
|
92
|
+
id: "camera-grid-layout",
|
|
93
|
+
tab: "general",
|
|
94
|
+
title: "Grid layout",
|
|
95
|
+
titleKey: "server:gridDevice.s_camera-grid-layout.title",
|
|
96
|
+
order: 20,
|
|
97
|
+
fields: [{
|
|
98
|
+
type: "widget",
|
|
99
|
+
key: "_gridLayout",
|
|
100
|
+
label: "",
|
|
101
|
+
labelKey: "server:gridDevice.s_camera-grid-layout._gridLayout.label",
|
|
102
|
+
widgetId: GRID_LAYOUT_WIDGET_ID
|
|
103
|
+
}]
|
|
104
|
+
}] };
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/builtins/camera-grid/grid-layout-native-provider.ts
|
|
108
|
+
/**
|
|
109
|
+
* The `camera-grid-layout` provider, contribution included.
|
|
110
|
+
*
|
|
111
|
+
* ## Why the section lives on the DEVICE provider and not on the addon
|
|
112
|
+
*
|
|
113
|
+
* `camera-grid-layout` is registered per device, through
|
|
114
|
+
* `DeviceContext.registerNativeCap`. `child-cap-dispatch` resolves a call that
|
|
115
|
+
* carries a `deviceId` to the device-scoped provider FIRST, and when the method
|
|
116
|
+
* is absent there it throws rather than falling back to the singleton — the
|
|
117
|
+
* fallback exists only for a collection cap's list method. Every contribution
|
|
118
|
+
* method carries a `deviceId` by definition, so an addon-level wrapper is
|
|
119
|
+
* simply never reached: it registered, it type-checked, and the live hub
|
|
120
|
+
* answered HTTP 500 with
|
|
121
|
+
* `method 'getDeviceSettingsContribution' not found on provider
|
|
122
|
+
* 'camera-grid-layout'`.
|
|
123
|
+
*
|
|
124
|
+
* That is why the whole provider is built here, in one place, and handed to
|
|
125
|
+
* `registerNativeCap` as a single object. `exposesDeviceSettings` widens
|
|
126
|
+
* `InferProvider` and not `InferNativeProvider`, so the type below is the wider
|
|
127
|
+
* one; registering it is safe because a native registration only ever needs a
|
|
128
|
+
* SUBSET of what this carries.
|
|
129
|
+
*
|
|
130
|
+
* The refusal (D526) rides along: a device the addon cannot name as a grid gets
|
|
131
|
+
* `null`, so a camera that is not a grid gets no section at all rather than a
|
|
132
|
+
* panel that renders its own emptiness.
|
|
133
|
+
*/
|
|
134
|
+
function buildGridLayoutNativeProvider(source) {
|
|
135
|
+
return {
|
|
136
|
+
getLayout: async ({ deviceId }) => source.getLayout(deviceId),
|
|
137
|
+
saveLayout: async (patch) => source.saveLayout(patch),
|
|
138
|
+
getDeviceSettingsContribution: async ({ deviceId }) => {
|
|
139
|
+
const schema = buildGridDeviceSchema(source.getLayout(deviceId) !== null);
|
|
140
|
+
return schema === null ? null : require_dist.hydrateSchema(schema, {});
|
|
141
|
+
},
|
|
142
|
+
getDeviceLiveContribution: async () => null,
|
|
143
|
+
applyDeviceSettingsPatch: async () => ({ success: true })
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/builtins/camera-grid/grid-camera-device.ts
|
|
148
|
+
/**
|
|
149
|
+
* The composite camera device.
|
|
150
|
+
*
|
|
151
|
+
* An ORDINARY camera in every respect the rest of the system can see: it
|
|
152
|
+
* records, it appears in the timeline, it has profile slots, it is bound like
|
|
153
|
+
* any other. What makes it a grid is invisible from here — its streams are
|
|
154
|
+
* composed rather than dialled, and object detection is switched off at
|
|
155
|
+
* CREATION (see `silence-analysis.ts`), never re-asserted.
|
|
156
|
+
*
|
|
157
|
+
* ## The three native caps, and why each is native
|
|
158
|
+
*
|
|
159
|
+
* - **`stream-catalog`** — what this grid OFFERS, one descriptor per profile it
|
|
160
|
+
* can honestly compose. Named on every pull, idle included: the broker sweeps
|
|
161
|
+
* anything its registry holds that a catalog does not name.
|
|
162
|
+
* - **`camera-grid-layout`** — the geometry, on the camera's own page. Device
|
|
163
|
+
* scoped so the widget asks THE CAMERA; the addon-scoped custom actions it
|
|
164
|
+
* replaces could only be reached by a caller that already knew the addon id,
|
|
165
|
+
* which is why the editor rendered nowhere.
|
|
166
|
+
* - **`snapshot`** — a frame of the composition. It used to be deliberately
|
|
167
|
+
* ABSENT, on the reasoning that the broker's ordinary grab takes one from the
|
|
168
|
+
* profile slot and taking one IS a consumer. That is true and it is the
|
|
169
|
+
* defect: it means a thumbnail in a list starts N decodes, and on a battery
|
|
170
|
+
* source it would be a wake. A native provider runs BEFORE that grab and
|
|
171
|
+
* answers from the live composition or from the frame it kept
|
|
172
|
+
* (`grid-snapshot.ts`).
|
|
173
|
+
*/
|
|
174
|
+
var gridCameraSchema = zod.z.object({
|
|
175
|
+
/** The persisted grid row this camera was declared from. */
|
|
176
|
+
instanceId: zod.z.string().min(1) });
|
|
177
|
+
var runtime = null;
|
|
178
|
+
function installGridCameraRuntime(next) {
|
|
179
|
+
runtime = next;
|
|
180
|
+
}
|
|
181
|
+
function activeRuntime() {
|
|
182
|
+
if (runtime === null) throw new Error("camera-grid: the addon runtime is not installed");
|
|
183
|
+
return runtime;
|
|
184
|
+
}
|
|
185
|
+
var GridCameraDevice = class extends require_dist.BaseDevice {
|
|
186
|
+
features = [require_dist.DeviceFeature.NativeSnapshot];
|
|
187
|
+
constructor(ctx) {
|
|
188
|
+
super(ctx, gridCameraSchema, { type: ctx.deviceMeta.type });
|
|
189
|
+
this.ctx.registerNativeCap(require_dist.streamCatalogCapability, { getCatalog: async ({ deviceId }) => {
|
|
190
|
+
if (deviceId !== this.id) return [];
|
|
191
|
+
return this.catalog();
|
|
192
|
+
} });
|
|
193
|
+
const layoutProvider = buildGridLayoutNativeProvider({
|
|
194
|
+
getLayout: (deviceId) => activeRuntime().getLayout(deviceId),
|
|
195
|
+
saveLayout: (patch) => activeRuntime().saveLayout(patch)
|
|
196
|
+
});
|
|
197
|
+
this.ctx.registerNativeCap(require_dist.cameraGridLayoutCapability, layoutProvider);
|
|
198
|
+
this.ctx.registerNativeCap(require_dist.snapshotCapability, {
|
|
199
|
+
getSnapshot: async ({ deviceId }) => activeRuntime().getSnapshot(deviceId),
|
|
200
|
+
invalidateCache: async () => {}
|
|
201
|
+
});
|
|
202
|
+
this.ctx.registerNativeCap(require_dist.motionCapability, {
|
|
203
|
+
getStatus: async ({ deviceId }) => activeRuntime().motionStatus(deviceId),
|
|
204
|
+
isDetected: async ({ deviceId }) => activeRuntime().motionStatus(deviceId).detected
|
|
205
|
+
});
|
|
206
|
+
this.markOnline(true);
|
|
207
|
+
}
|
|
208
|
+
catalog() {
|
|
209
|
+
const descriptors = activeRuntime().descriptorsFor(this.config.get("instanceId"));
|
|
210
|
+
if (descriptors === null) throw new Error(`camera-grid: cannot describe the streams of instance ${this.config.get("instanceId")}`);
|
|
211
|
+
return descriptors;
|
|
212
|
+
}
|
|
213
|
+
setAddonOnline(online) {
|
|
214
|
+
this.markOnline(online);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/builtins/camera-grid/acquire-retry.ts
|
|
219
|
+
async function acquireWithRetry(attempt, deps) {
|
|
220
|
+
const startedAt = deps.now();
|
|
221
|
+
for (;;) try {
|
|
222
|
+
return await attempt();
|
|
223
|
+
} catch (error) {
|
|
224
|
+
const waited = deps.now() - startedAt;
|
|
225
|
+
if (waited >= deps.budgetMs) throw error;
|
|
226
|
+
deps.onRetry?.(waited);
|
|
227
|
+
await deps.sleep();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/builtins/camera-grid/grid-instances.ts
|
|
232
|
+
/**
|
|
233
|
+
* The operator-written grid rows.
|
|
234
|
+
*
|
|
235
|
+
* Shape follows `readTerminalInstances`: a grid is a persisted row that
|
|
236
|
+
* DECLARES a camera, and the declaration reconcile turns rows into devices.
|
|
237
|
+
*
|
|
238
|
+
* Config is operator-writable, so a malformed or duplicate row is IGNORED
|
|
239
|
+
* rather than allowed to make the reconcile destructive. One bad row must never
|
|
240
|
+
* delete every camera this addon declares — that failure mode is why the
|
|
241
|
+
* Terminal addon reads its rows the same way.
|
|
242
|
+
*/
|
|
243
|
+
/** A rectangle in normalized [0,1] coordinates of whatever contains it. */
|
|
244
|
+
var NormalizedRectSchema = zod.z.object({
|
|
245
|
+
x: zod.z.number().min(0).max(1),
|
|
246
|
+
y: zod.z.number().min(0).max(1),
|
|
247
|
+
width: zod.z.number().gt(0).max(1),
|
|
248
|
+
height: zod.z.number().gt(0).max(1)
|
|
249
|
+
});
|
|
250
|
+
/**
|
|
251
|
+
* One source camera, the part of its picture taken, and where that part lands
|
|
252
|
+
* on the composite's canvas. Both rectangles are NORMALIZED so a source that
|
|
253
|
+
* changes resolution does not silently start cutting the wrong region.
|
|
254
|
+
*/
|
|
255
|
+
var GridCellSchema = zod.z.object({
|
|
256
|
+
deviceId: zod.z.number().int().positive(),
|
|
257
|
+
source: NormalizedRectSchema,
|
|
258
|
+
cell: NormalizedRectSchema
|
|
259
|
+
});
|
|
260
|
+
var GridInstanceSchema = zod.z.object({
|
|
261
|
+
id: zod.z.string().uuid(),
|
|
262
|
+
cameraStableId: zod.z.string().min(1).max(256),
|
|
263
|
+
name: zod.z.string().min(1).max(160),
|
|
264
|
+
enabled: zod.z.boolean(),
|
|
265
|
+
/**
|
|
266
|
+
* NO canvas size. It is DERIVED, per profile, from the cells and the sources'
|
|
267
|
+
* own dimensions (`grid-canvas-derivation.ts`) — the two numbers that used to
|
|
268
|
+
* live here were typed into the editor and silently decided both how much the
|
|
269
|
+
* composite cost and how sharp it was.
|
|
270
|
+
*
|
|
271
|
+
* Rows written before that change still carry `width`/`height`; zod drops
|
|
272
|
+
* unknown keys, so they are ignored rather than migrated. Nothing reads them,
|
|
273
|
+
* and a migration that rewrote every row to delete two fields would be a
|
|
274
|
+
* write with no reader.
|
|
275
|
+
*/
|
|
276
|
+
fps: zod.z.number().int().min(1).max(60),
|
|
277
|
+
/**
|
|
278
|
+
* Which profiles this grid PUBLISHES, of the ones it could serve.
|
|
279
|
+
*
|
|
280
|
+
* Default `mid` + `low`, and the default is the finding: a grid's `high` is
|
|
281
|
+
* composed of its sources' `high`, so on this fleet it is a 4K canvas built
|
|
282
|
+
* from 4K decodes — a thing to opt into, not to be handed by a viewer's
|
|
283
|
+
* adaptive climbing to the top rung it can see.
|
|
284
|
+
*
|
|
285
|
+
* Absent on rows written before this, which is why the default lives in the
|
|
286
|
+
* schema rather than at the call site: an old grid starts publishing the two
|
|
287
|
+
* cheap rungs without anyone touching it.
|
|
288
|
+
*/
|
|
289
|
+
publishedProfiles: zod.z.array(zod.z.enum([
|
|
290
|
+
"high",
|
|
291
|
+
"mid",
|
|
292
|
+
"low"
|
|
293
|
+
])).max(3).default(["mid", "low"]),
|
|
294
|
+
/**
|
|
295
|
+
* Empty is the NORMAL freshly-created state: a grid is created from the
|
|
296
|
+
* integration page with a name only, and laid out afterwards in the camera's
|
|
297
|
+
* own settings. A grid with no cells declares its camera and emits nothing.
|
|
298
|
+
*/
|
|
299
|
+
cells: zod.z.array(GridCellSchema).max(16).default([])
|
|
300
|
+
});
|
|
301
|
+
function readGridInstances(raw, onInvalid) {
|
|
302
|
+
const ids = /* @__PURE__ */ new Set();
|
|
303
|
+
const stableIds = /* @__PURE__ */ new Set();
|
|
304
|
+
const instances = [];
|
|
305
|
+
for (const value of raw) {
|
|
306
|
+
const parsed = GridInstanceSchema.safeParse(value);
|
|
307
|
+
if (!parsed.success) {
|
|
308
|
+
onInvalid?.("Ignoring malformed camera-grid configuration");
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const instance = parsed.data;
|
|
312
|
+
if (ids.has(instance.id) || stableIds.has(instance.cameraStableId)) {
|
|
313
|
+
onInvalid?.(`Ignoring duplicate camera-grid instance ${instance.id}`);
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
ids.add(instance.id);
|
|
317
|
+
stableIds.add(instance.cameraStableId);
|
|
318
|
+
instances.push(instance);
|
|
319
|
+
}
|
|
320
|
+
return instances;
|
|
321
|
+
}
|
|
322
|
+
//#endregion
|
|
323
|
+
//#region src/builtins/camera-grid/grid-plan.ts
|
|
324
|
+
/**
|
|
325
|
+
* Bits per pixel per frame. A composite is mostly static furniture with a few
|
|
326
|
+
* moving subjects, so it compresses well; this lands a 1920x1080@10 grid near
|
|
327
|
+
* 3 Mbps and a 640x360@10 one near 0.35 Mbps. A single flat number would either
|
|
328
|
+
* starve a 4K canvas or spend a 4K budget on a thumbnail-sized one.
|
|
329
|
+
*/
|
|
330
|
+
var BITS_PER_PIXEL_PER_FRAME = .15;
|
|
331
|
+
var MIN_BITRATE_KBPS = 256;
|
|
332
|
+
var MAX_BITRATE_KBPS = 16e3;
|
|
333
|
+
function bitrateFor(width, height, fps) {
|
|
334
|
+
const bps = width * height * fps * BITS_PER_PIXEL_PER_FRAME;
|
|
335
|
+
return Math.min(MAX_BITRATE_KBPS, Math.max(MIN_BITRATE_KBPS, Math.round(bps / 1e3)));
|
|
336
|
+
}
|
|
337
|
+
/** `null` when the grid has nothing to compose — the normal freshly-created state. */
|
|
338
|
+
function gridPlanFor(instance, encode) {
|
|
339
|
+
if (instance.cells.length === 0) return null;
|
|
340
|
+
const ordinalByDeviceId = /* @__PURE__ */ new Map();
|
|
341
|
+
const sourceDeviceIds = [];
|
|
342
|
+
const cells = instance.cells.map((cell) => {
|
|
343
|
+
let ordinal = ordinalByDeviceId.get(cell.deviceId);
|
|
344
|
+
if (ordinal === void 0) {
|
|
345
|
+
ordinal = sourceDeviceIds.length;
|
|
346
|
+
ordinalByDeviceId.set(cell.deviceId, ordinal);
|
|
347
|
+
sourceDeviceIds.push(cell.deviceId);
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
inputIndex: ordinal,
|
|
351
|
+
source: cell.source,
|
|
352
|
+
cell: cell.cell
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
const canvas = encode.canvas;
|
|
356
|
+
return {
|
|
357
|
+
layout: {
|
|
358
|
+
width: canvas.width,
|
|
359
|
+
height: canvas.height,
|
|
360
|
+
cells
|
|
361
|
+
},
|
|
362
|
+
sourceDeviceIds,
|
|
363
|
+
encoder: encode.encoder,
|
|
364
|
+
decodeHwAccel: encode.decodeHwAccel,
|
|
365
|
+
fps: instance.fps,
|
|
366
|
+
bitrateKbps: bitrateFor(canvas.width, canvas.height, instance.fps)
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
//#endregion
|
|
370
|
+
//#region src/builtins/camera-grid/grid-row-normalization.ts
|
|
371
|
+
/**
|
|
372
|
+
* Creation is NAME ONLY.
|
|
373
|
+
*
|
|
374
|
+
* The operator adds a row on the integration page and types a name. Everything
|
|
375
|
+
* else — the identity the rest of the cluster will reference forever, the
|
|
376
|
+
* canvas, the frame rate, the cells — is filled in here on the way past, and
|
|
377
|
+
* then edited in the camera's own device details.
|
|
378
|
+
*
|
|
379
|
+
* This runs BEFORE `readGridInstances`, which deliberately IGNORES a row it
|
|
380
|
+
* cannot parse so one bad row can never make the declaration reconcile
|
|
381
|
+
* destructive. A freshly typed name is exactly such a row, so without this step
|
|
382
|
+
* a new grid would be silently discarded at the moment of creation.
|
|
383
|
+
*/
|
|
384
|
+
/** Canvas and cadence a grid starts life with, until the layout editor changes them. */
|
|
385
|
+
var DEFAULT_WIDTH = 1920;
|
|
386
|
+
var DEFAULT_HEIGHT = 1080;
|
|
387
|
+
var DEFAULT_FPS = 10;
|
|
388
|
+
function nonEmptyString(value) {
|
|
389
|
+
if (typeof value !== "string") return null;
|
|
390
|
+
const trimmed = value.trim();
|
|
391
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
392
|
+
}
|
|
393
|
+
function positiveInt(value, fallback) {
|
|
394
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* @param mintId a UUID factory — injected so the normalization is testable
|
|
398
|
+
* without reaching for `crypto`.
|
|
399
|
+
*/
|
|
400
|
+
function normalizeGridRows(raw, mintId) {
|
|
401
|
+
let changed = false;
|
|
402
|
+
const rows = [];
|
|
403
|
+
for (const row of raw) {
|
|
404
|
+
const name = nonEmptyString(row["name"]);
|
|
405
|
+
if (name === null) {
|
|
406
|
+
changed = true;
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
const id = nonEmptyString(row["id"]) ?? mintId();
|
|
410
|
+
const cameraStableId = nonEmptyString(row["cameraStableId"]) ?? newGridCameraStableId(id);
|
|
411
|
+
const normalized = {
|
|
412
|
+
...row,
|
|
413
|
+
id,
|
|
414
|
+
cameraStableId,
|
|
415
|
+
name,
|
|
416
|
+
enabled: typeof row["enabled"] === "boolean" ? row["enabled"] : true,
|
|
417
|
+
width: positiveInt(row["width"], DEFAULT_WIDTH),
|
|
418
|
+
height: positiveInt(row["height"], DEFAULT_HEIGHT),
|
|
419
|
+
fps: positiveInt(row["fps"], DEFAULT_FPS),
|
|
420
|
+
cells: Array.isArray(row["cells"]) ? row["cells"] : []
|
|
421
|
+
};
|
|
422
|
+
if (!changed) changed = Object.keys(normalized).some((key) => normalized[key] !== row[key]);
|
|
423
|
+
rows.push(normalized);
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
rows,
|
|
427
|
+
changed
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region src/builtins/camera-grid/grid-activity-mirror.ts
|
|
432
|
+
/**
|
|
433
|
+
* What a grid says about ITSELF, kept from what its sources said.
|
|
434
|
+
*
|
|
435
|
+
* ## Why the grid answers at all
|
|
436
|
+
*
|
|
437
|
+
* A grid is a camera, and the viewer already knows how to light a camera: the
|
|
438
|
+
* motion ring keys off `motion.on-motion-changed` filtered by `deviceId`, the
|
|
439
|
+
* audio one off `pipeline.audio-inference-result`. So the grid does not need a
|
|
440
|
+
* new channel, a new cap or a line of app code — it needs to answer those
|
|
441
|
+
* questions about its own device id. The operator set both rules: motion is on
|
|
442
|
+
* if AT LEAST ONE source has it, and the audio level is the LOUDEST of them.
|
|
443
|
+
*
|
|
444
|
+
* It is derived from the SOURCES' events and never from the composed picture.
|
|
445
|
+
* Analysing the composite would be a second motion authority for cameras that
|
|
446
|
+
* already have one, and a decode this addon does not pay today.
|
|
447
|
+
*
|
|
448
|
+
* ## The falling edge is the whole difficulty
|
|
449
|
+
*
|
|
450
|
+
* Bus events are telemetry and may be dropped (D8/D11). A lost `detected:
|
|
451
|
+
* false` would leave a grid lit for ever, and the grid has no phase machine to
|
|
452
|
+
* produce a falling edge of its own — a real camera's comes from the pipeline
|
|
453
|
+
* runner, which a grid deliberately does not run.
|
|
454
|
+
*
|
|
455
|
+
* So a source's motion is remembered WITH ITS TIME and expires on its own. That
|
|
456
|
+
* is D49's shape: in-memory state refreshed off the event path, never a gate
|
|
457
|
+
* that re-reads something fallible in order to decide. A dropped clear costs a
|
|
458
|
+
* ring that stays lit until the expiry instead of for ever, and a subject that
|
|
459
|
+
* is genuinely still there keeps renewing it.
|
|
460
|
+
*
|
|
461
|
+
* The expiry is `MOTION_CLOSE_AFTER_MS`, imported and not re-spelled: it is the
|
|
462
|
+
* system's one answer to "how long after the last push is a camera still
|
|
463
|
+
* moving", and a second number here would be a second authority disagreeing
|
|
464
|
+
* with the first on exactly the cameras that make up the grid.
|
|
465
|
+
*/
|
|
466
|
+
/**
|
|
467
|
+
* How long an audio reading counts as current.
|
|
468
|
+
*
|
|
469
|
+
* The analyzer emits one per window per camera, so a source that has gone quiet
|
|
470
|
+
* simply stops arriving — there is no "silence" event to wait for. Without a
|
|
471
|
+
* window the loudest reading of the day would be the grid's level for ever.
|
|
472
|
+
* Chosen to span several analysis windows so an ordinary gap does not blink the
|
|
473
|
+
* level away, and to be far shorter than a person notices a stale ring.
|
|
474
|
+
*/
|
|
475
|
+
var AUDIO_FRESH_MS = 5e3;
|
|
476
|
+
var GridActivityMirror = class {
|
|
477
|
+
motion = /* @__PURE__ */ new Map();
|
|
478
|
+
audio = /* @__PURE__ */ new Map();
|
|
479
|
+
lastDetectedAt = null;
|
|
480
|
+
/**
|
|
481
|
+
* One source's motion push. `detected: false` is as important as `true`.
|
|
482
|
+
*
|
|
483
|
+
* `lastDetectedAt` moves only on a source's RISING edge — the source was not
|
|
484
|
+
* moving, or its last `true` had expired. A source's pushes include a
|
|
485
|
+
* heartbeat (the bridge's sustain ticks, every `true` a camera re-sends while
|
|
486
|
+
* a subject stays), and moving the stamp on each one made the grid's
|
|
487
|
+
* `lastDetectedAt` "the last tick of any cell" while every camera's is its
|
|
488
|
+
* last effective RISE (D696): the viewer's Motion order then ranked the grid
|
|
489
|
+
* above the very cells it shows (2026-10-06).
|
|
490
|
+
*/
|
|
491
|
+
noteMotion(sourceDeviceId, detected, atMs) {
|
|
492
|
+
const prev = this.motion.get(sourceDeviceId);
|
|
493
|
+
const wasMoving = prev !== void 0 && prev.detected && atMs - prev.atMs <= 15e3;
|
|
494
|
+
this.motion.set(sourceDeviceId, {
|
|
495
|
+
detected,
|
|
496
|
+
atMs
|
|
497
|
+
});
|
|
498
|
+
if (detected && !wasMoving) this.lastDetectedAt = Math.max(this.lastDetectedAt ?? 0, atMs);
|
|
499
|
+
}
|
|
500
|
+
/** One source's audio window. `dbfs` is the level, on the analyzer's scale. */
|
|
501
|
+
noteAudio(sourceDeviceId, dbfs, atMs) {
|
|
502
|
+
this.audio.set(sourceDeviceId, {
|
|
503
|
+
dbfs,
|
|
504
|
+
atMs
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Drop every source this grid no longer composes.
|
|
509
|
+
*
|
|
510
|
+
* A cell removed while its camera was moving would otherwise hold the grid
|
|
511
|
+
* lit until the expiry, for a picture the source is not even in.
|
|
512
|
+
*/
|
|
513
|
+
keepOnly(sourceDeviceIds) {
|
|
514
|
+
const keep = new Set(sourceDeviceIds);
|
|
515
|
+
const motionIds = Array.from(this.motion.keys());
|
|
516
|
+
const audioIds = Array.from(this.audio.keys());
|
|
517
|
+
for (const id of motionIds) if (!keep.has(id)) this.motion.delete(id);
|
|
518
|
+
for (const id of audioIds) if (!keep.has(id)) this.audio.delete(id);
|
|
519
|
+
}
|
|
520
|
+
/** At least one source moving, as of `nowMs`. */
|
|
521
|
+
motionAt(nowMs) {
|
|
522
|
+
let detected = false;
|
|
523
|
+
for (const state of this.motion.values()) {
|
|
524
|
+
if (!state.detected) continue;
|
|
525
|
+
if (nowMs - state.atMs > 15e3) continue;
|
|
526
|
+
detected = true;
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
return {
|
|
530
|
+
detected,
|
|
531
|
+
lastDetectedAt: this.lastDetectedAt
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* The loudest CURRENT reading, or `null` when nothing fresh has been heard.
|
|
536
|
+
*
|
|
537
|
+
* Null and not `-Infinity`: "nobody has reported a level" is a different
|
|
538
|
+
* answer from "it is silent", and a number here would have the viewer draw a
|
|
539
|
+
* level for a grid whose sources are not being analysed at all.
|
|
540
|
+
*/
|
|
541
|
+
loudestAt(nowMs) {
|
|
542
|
+
let loudest = null;
|
|
543
|
+
for (const state of this.audio.values()) {
|
|
544
|
+
if (nowMs - state.atMs > AUDIO_FRESH_MS) continue;
|
|
545
|
+
if (loudest === null || state.dbfs > loudest) loudest = state.dbfs;
|
|
546
|
+
}
|
|
547
|
+
return loudest;
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
//#endregion
|
|
551
|
+
//#region src/builtins/camera-grid/grid-detection-mapping.ts
|
|
552
|
+
/**
|
|
553
|
+
* Where this detection lands on the canvas — once per cell that shows it.
|
|
554
|
+
*
|
|
555
|
+
* Empty is a real answer: the subject is in a part of the source this grid does
|
|
556
|
+
* not display, or the frame arrived with no size to measure against. Neither is
|
|
557
|
+
* a reason to guess.
|
|
558
|
+
*/
|
|
559
|
+
function mapDetectionToCanvas(input) {
|
|
560
|
+
const { width: frameW, height: frameH } = input.sourceFrame;
|
|
561
|
+
if (frameW <= 0 || frameH <= 0) return [];
|
|
562
|
+
const left = input.bbox.x / frameW;
|
|
563
|
+
const top = input.bbox.y / frameH;
|
|
564
|
+
const right = (input.bbox.x + input.bbox.width) / frameW;
|
|
565
|
+
const bottom = (input.bbox.y + input.bbox.height) / frameH;
|
|
566
|
+
const out = [];
|
|
567
|
+
for (const { source, cell } of input.cells) {
|
|
568
|
+
if (source.width <= 0 || source.height <= 0) continue;
|
|
569
|
+
const l = Math.max(left, source.x);
|
|
570
|
+
const t = Math.max(top, source.y);
|
|
571
|
+
const r = Math.min(right, source.x + source.width);
|
|
572
|
+
const b = Math.min(bottom, source.y + source.height);
|
|
573
|
+
if (r <= l || b <= t) continue;
|
|
574
|
+
const cx = (l - source.x) / source.width;
|
|
575
|
+
const cy = (t - source.y) / source.height;
|
|
576
|
+
const cw = (r - l) / source.width;
|
|
577
|
+
const ch = (b - t) / source.height;
|
|
578
|
+
out.push({
|
|
579
|
+
x: (cell.x + cx * cell.width) * input.canvas.width,
|
|
580
|
+
y: (cell.y + cy * cell.height) * input.canvas.height,
|
|
581
|
+
width: cw * cell.width * input.canvas.width,
|
|
582
|
+
height: ch * cell.height * input.canvas.height
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
return out;
|
|
586
|
+
}
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region src/builtins/camera-grid/grid-activity.ts
|
|
589
|
+
/**
|
|
590
|
+
* The grid's own motion / audio / detection, forwarded from its sources.
|
|
591
|
+
*
|
|
592
|
+
* ## Why the grid speaks a camera's language instead of a new one
|
|
593
|
+
*
|
|
594
|
+
* The operator asked for the grid's tile to light up in the viewer exactly as a
|
|
595
|
+
* camera's card does, with NO app change. The app already knows how: it filters
|
|
596
|
+
* `motion.on-motion-changed` by `deviceId` for the motion ring,
|
|
597
|
+
* `pipeline.audio-inference-result` for the audio one, and `detection.result`
|
|
598
|
+
* for the detection one. So the grid answers those three questions about its
|
|
599
|
+
* own device id, in the same shapes. Nothing new is invented, and nothing in
|
|
600
|
+
* the viewer is touched.
|
|
601
|
+
*
|
|
602
|
+
* The rules are the operator's: motion if AT LEAST ONE source has it, and the
|
|
603
|
+
* LOUDEST source's level for audio.
|
|
604
|
+
*
|
|
605
|
+
* ## What speaking a camera's language costs, and why it is safe here
|
|
606
|
+
*
|
|
607
|
+
* Those categories have other listeners, and emitting on them makes the grid a
|
|
608
|
+
* motion source for the whole system. Checked, one by one, before shipping:
|
|
609
|
+
* the recorder's event capture, the HomeKit and Alexa exports and the Home
|
|
610
|
+
* Assistant export are all per-device and do nothing until an operator enables
|
|
611
|
+
* them for this camera — and if an operator DOES export a grid to HomeKit, a
|
|
612
|
+
* grid reporting motion is correct, not a surprise.
|
|
613
|
+
*
|
|
614
|
+
* The one listener with no gate of its own was `pipeline-analytics`, which
|
|
615
|
+
* would have opened a motion EPISODE per grid, duplicating the rows its sources
|
|
616
|
+
* already write. Its gate turned out to be the `pipeline-analytics` WRAPPER
|
|
617
|
+
* BINDING, so the answer is the one the operator gave: a derived camera is
|
|
618
|
+
* created with the analytics wrappers OFF (`grid-analytics-defaults.ts`).
|
|
619
|
+
* That is a binding, not a new flag, so an operator who wants a grid analysed
|
|
620
|
+
* can simply turn it back on.
|
|
621
|
+
*
|
|
622
|
+
* ## Detection carries boxes whether or not anyone wanted them
|
|
623
|
+
*
|
|
624
|
+
* `detection.result` is the same event the viewer draws BOXES from, so a grid
|
|
625
|
+
* that reports detections reports boxes. Sending the source's own pixel box
|
|
626
|
+
* would draw it against the composed canvas at confidently wrong coordinates,
|
|
627
|
+
* so every box is carried through the cell geometry first
|
|
628
|
+
* (`grid-detection-mapping.ts`) and lands where the subject actually is.
|
|
629
|
+
*/
|
|
630
|
+
/**
|
|
631
|
+
* One mirror per grid, and the emission that follows an update.
|
|
632
|
+
*
|
|
633
|
+
* Deliberately NOT one mirror per source: the question is always "is THIS grid
|
|
634
|
+
* lit", and a source shared by two grids answers it twice, differently, because
|
|
635
|
+
* the other cells differ.
|
|
636
|
+
*/
|
|
637
|
+
var GridActivityForwarder = class {
|
|
638
|
+
deps;
|
|
639
|
+
mirrors = /* @__PURE__ */ new Map();
|
|
640
|
+
constructor(deps) {
|
|
641
|
+
this.deps = deps;
|
|
642
|
+
}
|
|
643
|
+
/** A source camera's motion push. */
|
|
644
|
+
onSourceMotion(sourceDeviceId, detected, atMs) {
|
|
645
|
+
for (const grid of this.deps.gridsForSource(sourceDeviceId)) {
|
|
646
|
+
const mirror = this.mirrorFor(grid);
|
|
647
|
+
const before = mirror.motionAt(atMs).detected;
|
|
648
|
+
mirror.noteMotion(sourceDeviceId, detected, atMs);
|
|
649
|
+
const after = mirror.motionAt(atMs);
|
|
650
|
+
if (after.detected === before) continue;
|
|
651
|
+
this.emitMotion(grid.deviceId, after, atMs);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
/** A source camera's audio window. */
|
|
655
|
+
onSourceAudio(sourceDeviceId, dbfs, atMs) {
|
|
656
|
+
for (const grid of this.deps.gridsForSource(sourceDeviceId)) {
|
|
657
|
+
const mirror = this.mirrorFor(grid);
|
|
658
|
+
mirror.noteAudio(sourceDeviceId, dbfs, atMs);
|
|
659
|
+
const loudest = mirror.loudestAt(atMs);
|
|
660
|
+
if (loudest === null) continue;
|
|
661
|
+
this.emitAudio(grid.deviceId, loudest, atMs);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
/** A source camera's detection frame, with its boxes in SOURCE pixels. */
|
|
665
|
+
onSourceDetections(frame) {
|
|
666
|
+
for (const grid of this.deps.gridsForSource(frame.deviceId)) {
|
|
667
|
+
const cells = grid.cellsForSource(frame.deviceId);
|
|
668
|
+
if (cells.length === 0) continue;
|
|
669
|
+
const detections = [];
|
|
670
|
+
for (const detection of frame.detections) for (const bbox of mapDetectionToCanvas({
|
|
671
|
+
bbox: detection.bbox,
|
|
672
|
+
sourceFrame: {
|
|
673
|
+
width: frame.width,
|
|
674
|
+
height: frame.height
|
|
675
|
+
},
|
|
676
|
+
canvas: grid.canvas,
|
|
677
|
+
cells
|
|
678
|
+
})) {
|
|
679
|
+
const { refinedBbox: _refined, mask: _mask, ...rest } = detection;
|
|
680
|
+
detections.push({
|
|
681
|
+
...rest,
|
|
682
|
+
bbox
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
if (detections.length === 0) continue;
|
|
686
|
+
this.emitDetections(grid, frame, detections);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
/** The grid's own motion answer, for `motion.getStatus`. */
|
|
690
|
+
motionStatusFor(deviceId, nowMs) {
|
|
691
|
+
return this.mirrors.get(deviceId)?.motionAt(nowMs) ?? {
|
|
692
|
+
detected: false,
|
|
693
|
+
lastDetectedAt: null
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
/** Drop the mirror of a grid that no longer exists. */
|
|
697
|
+
forget(deviceId) {
|
|
698
|
+
this.mirrors.delete(deviceId);
|
|
699
|
+
}
|
|
700
|
+
mirrorFor(grid) {
|
|
701
|
+
let mirror = this.mirrors.get(grid.deviceId);
|
|
702
|
+
if (mirror === void 0) {
|
|
703
|
+
mirror = new GridActivityMirror();
|
|
704
|
+
this.mirrors.set(grid.deviceId, mirror);
|
|
705
|
+
}
|
|
706
|
+
mirror.keepOnly(grid.sourceDeviceIds);
|
|
707
|
+
return mirror;
|
|
708
|
+
}
|
|
709
|
+
source(deviceId) {
|
|
710
|
+
return {
|
|
711
|
+
type: "device",
|
|
712
|
+
id: deviceId,
|
|
713
|
+
addonId: this.deps.addonId,
|
|
714
|
+
deviceId
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
emitMotion(deviceId, state, atMs) {
|
|
718
|
+
const payload = {
|
|
719
|
+
deviceId,
|
|
720
|
+
detected: state.detected,
|
|
721
|
+
timestamp: atMs,
|
|
722
|
+
source: "onboard"
|
|
723
|
+
};
|
|
724
|
+
this.deps.eventBus.emit(require_dist.createEvent(require_dist.EventCategory.MotionOnMotionChanged, this.source(deviceId), payload));
|
|
725
|
+
this.deps.logger.debug("camera grid: motion forwarded", {
|
|
726
|
+
tags: { deviceId },
|
|
727
|
+
meta: { detected: state.detected }
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
emitAudio(deviceId, dbfs, atMs) {
|
|
731
|
+
const payload = {
|
|
732
|
+
deviceId,
|
|
733
|
+
frame: {
|
|
734
|
+
kind: "audio-window",
|
|
735
|
+
windowId: `grid-${String(deviceId)}-${String(atMs)}`,
|
|
736
|
+
deviceId,
|
|
737
|
+
timestamp: atMs,
|
|
738
|
+
startMs: atMs,
|
|
739
|
+
endMs: atMs,
|
|
740
|
+
level: {
|
|
741
|
+
rms: 0,
|
|
742
|
+
dbfs
|
|
743
|
+
},
|
|
744
|
+
detections: []
|
|
745
|
+
},
|
|
746
|
+
nodeId: "hub"
|
|
747
|
+
};
|
|
748
|
+
this.deps.eventBus.emit(require_dist.createEvent(require_dist.EventCategory.PipelineAudioInferenceResult, this.source(deviceId), payload));
|
|
749
|
+
}
|
|
750
|
+
emitDetections(grid, sourceFrame, detections) {
|
|
751
|
+
const payload = {
|
|
752
|
+
frame: {
|
|
753
|
+
kind: "frame",
|
|
754
|
+
frameId: `grid-${String(grid.deviceId)}-${sourceFrame.frameId}`,
|
|
755
|
+
deviceId: grid.deviceId,
|
|
756
|
+
timestamp: sourceFrame.timestamp,
|
|
757
|
+
width: grid.canvas.width,
|
|
758
|
+
height: grid.canvas.height,
|
|
759
|
+
detections
|
|
760
|
+
},
|
|
761
|
+
analysisResults: []
|
|
762
|
+
};
|
|
763
|
+
this.deps.eventBus.emit(require_dist.createEvent(require_dist.EventCategory.DetectionResult, this.source(grid.deviceId), payload));
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
//#endregion
|
|
767
|
+
//#region src/builtins/camera-grid/grid-wire-format.ts
|
|
768
|
+
/** What the relay answers with, and what the sampler must demux. */
|
|
769
|
+
var GRID_WIRE_CONTENT_TYPE = "video/x-flv";
|
|
770
|
+
/** `/grid/<instanceId>/<profile>.flv`. */
|
|
771
|
+
var GRID_WIRE_PATH_SUFFIX = ".flv";
|
|
772
|
+
/**
|
|
773
|
+
* How the broker must ingest it: `pull-flv` is documented as ALWAYS read
|
|
774
|
+
* through the ffmpeg source reader with `-c copy`. `pull-http` would have been
|
|
775
|
+
* the intuitive choice and means MJPEG in this broker — it answers with
|
|
776
|
+
* `HTTP_MJPEG_H264_OUTPUT_ARGS` and re-encodes an already-encoded H.264.
|
|
777
|
+
*/
|
|
778
|
+
var GRID_WIRE_STREAM_KIND = "pull-flv";
|
|
779
|
+
//#endregion
|
|
780
|
+
//#region src/builtins/camera-grid/grid-frame-sample.ts
|
|
781
|
+
/**
|
|
782
|
+
* ONE JPEG out of a composition that is already running.
|
|
783
|
+
*
|
|
784
|
+
* ## Why this is not the ffmpeg primitive
|
|
785
|
+
*
|
|
786
|
+
* `FfmpegProcess` + `buildFfmpegArgs` own the STREAM job: a long-lived encode
|
|
787
|
+
* with a hardware cascade, a first-data deadline and a bounded restart. This is
|
|
788
|
+
* the other kind — run-to-completion, no encode plan worth sharing, finishes or
|
|
789
|
+
* is killed — which is the class `scripts/check-ffmpeg-primitive.ts` already
|
|
790
|
+
* carves out by name for `recorder/still/still-frame-service.ts` ("single-JPEG
|
|
791
|
+
* still grab") and `builtins/snapshot/snapshot.addon.ts` ("keyframe snapshot
|
|
792
|
+
* grab"). It is the same job as those two, on a pipe instead of a URL.
|
|
793
|
+
*
|
|
794
|
+
* ## Why a pipe and not the grid's own URL
|
|
795
|
+
*
|
|
796
|
+
* Dialling the relay would be a CONSUMER, and a consumer of a cold grid starts
|
|
797
|
+
* the composition — N broker acquisitions for a thumbnail, which is the one
|
|
798
|
+
* thing the operator ruled out. Reading the bytes of a session that is ALREADY
|
|
799
|
+
* running costs nothing: the child is up, the packets are being produced, and
|
|
800
|
+
* this just takes a copy of them.
|
|
801
|
+
*
|
|
802
|
+
* Bounded on both ends. A composition whose first key frame is far away must
|
|
803
|
+
* not hold an ffmpeg (or this promise) open for ever, so the grab has a
|
|
804
|
+
* deadline and the child is killed at it — a snapshot that did not arrive is
|
|
805
|
+
* `null`, and `null` is a real answer.
|
|
806
|
+
*/
|
|
807
|
+
/** Long enough for a 2 s GOP plus a probe, short enough that a list does not hang. */
|
|
808
|
+
var DEFAULT_TIMEOUT_MS = 8e3;
|
|
809
|
+
/** JPEG quality. 4 is visually clean at thumbnail and list sizes and ~40 KB at 1080p. */
|
|
810
|
+
var JPEG_QUALITY = "4";
|
|
811
|
+
var GridFrameSampler = class {
|
|
812
|
+
options;
|
|
813
|
+
constructor(options) {
|
|
814
|
+
this.options = options;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* @returns the JPEG, or `null` — a grab that produced nothing, could not be
|
|
818
|
+
* attached, or ran out of time. Every one of those is logged with the
|
|
819
|
+
* device: a branch that accepts the request and produces nothing must say so.
|
|
820
|
+
*/
|
|
821
|
+
async sample(deviceId, source) {
|
|
822
|
+
const spawnFn = this.options.spawnFn ?? node_child_process.spawn;
|
|
823
|
+
const timeoutMs = this.options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
824
|
+
const child = spawnFn(this.options.binaryPath, [
|
|
825
|
+
"-hide_banner",
|
|
826
|
+
"-loglevel",
|
|
827
|
+
"error",
|
|
828
|
+
"-f",
|
|
829
|
+
"flv",
|
|
830
|
+
"-i",
|
|
831
|
+
"pipe:0",
|
|
832
|
+
"-frames:v",
|
|
833
|
+
"1",
|
|
834
|
+
"-q:v",
|
|
835
|
+
JPEG_QUALITY,
|
|
836
|
+
"-f",
|
|
837
|
+
"mjpeg",
|
|
838
|
+
"pipe:1"
|
|
839
|
+
], { stdio: [
|
|
840
|
+
"pipe",
|
|
841
|
+
"pipe",
|
|
842
|
+
"pipe"
|
|
843
|
+
] });
|
|
844
|
+
const chunks = [];
|
|
845
|
+
child.stdout?.on("data", (chunk) => chunks.push(chunk));
|
|
846
|
+
child.stderr?.on("data", () => {});
|
|
847
|
+
const hold = source.attach((chunk) => {
|
|
848
|
+
if (child.stdin?.writable === true) child.stdin.write(chunk);
|
|
849
|
+
});
|
|
850
|
+
if (hold === null) {
|
|
851
|
+
child.kill("SIGKILL");
|
|
852
|
+
this.options.logger.warn("camera grid: could not attach to sample a frame", { tags: { deviceId } });
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
const timer = setTimeout(() => {
|
|
856
|
+
child.kill("SIGKILL");
|
|
857
|
+
}, timeoutMs);
|
|
858
|
+
timer.unref?.();
|
|
859
|
+
try {
|
|
860
|
+
await new Promise((resolve) => {
|
|
861
|
+
child.once("exit", () => resolve());
|
|
862
|
+
child.once("error", () => resolve());
|
|
863
|
+
});
|
|
864
|
+
} finally {
|
|
865
|
+
clearTimeout(timer);
|
|
866
|
+
hold.close();
|
|
867
|
+
try {
|
|
868
|
+
child.stdin?.end();
|
|
869
|
+
} catch (error) {
|
|
870
|
+
this.options.logger.debug("camera grid: the frame grab stdin refused to close", {
|
|
871
|
+
tags: { deviceId },
|
|
872
|
+
meta: { error: require_dist.errMsg(error) }
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
const jpeg = Buffer.concat(chunks);
|
|
877
|
+
if (jpeg.length === 0) {
|
|
878
|
+
this.options.logger.warn("camera grid: the frame grab produced no bytes", {
|
|
879
|
+
tags: { deviceId },
|
|
880
|
+
meta: { timeoutMs }
|
|
881
|
+
});
|
|
882
|
+
return null;
|
|
883
|
+
}
|
|
884
|
+
return jpeg;
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
//#endregion
|
|
888
|
+
//#region src/builtins/camera-grid/grid-last-frame-store.ts
|
|
889
|
+
/**
|
|
890
|
+
* The last COMPOSED frame per grid, on disk, so it outlives the process.
|
|
891
|
+
*
|
|
892
|
+
* ## Why not `@camstack/server/system`'s SnapshotDurableStore
|
|
893
|
+
*
|
|
894
|
+
* Because the shape is right and the reach is not: that class lives under
|
|
895
|
+
* `builtins/snapshot/` and `@camstack/server/system` does not export it — a builtin's
|
|
896
|
+
* internals are not an addon-facing module, and an addon that reached into one
|
|
897
|
+
* would be importing another addon, which this repo forbids outright. What is
|
|
898
|
+
* shared is the REASONING, and it is worth restating rather than linking,
|
|
899
|
+
* because the failure it prevents here is the same one measured on 2026-09-17:
|
|
900
|
+
* the cache is RAM, three server updates emptied it, and a camera that cannot
|
|
901
|
+
* be asked for a fresh frame showed the courtesy card all morning with nothing
|
|
902
|
+
* broken.
|
|
903
|
+
*
|
|
904
|
+
* A grid is that camera by construction. It has no fresh frame whenever nobody
|
|
905
|
+
* is watching it, which is most of the time and is the entire point of D519.
|
|
906
|
+
*
|
|
907
|
+
* ## Shape
|
|
908
|
+
*
|
|
909
|
+
* One file per device under `ctx.dataDir` — `<nodeDataDir>/addons-data/
|
|
910
|
+
* camera-grid`, which this addon owns exclusively — overwritten rather than
|
|
911
|
+
* appended: what is wanted is A recent frame, not a history. A history here
|
|
912
|
+
* would grow without a reaper and compete with the recordings for the disk.
|
|
913
|
+
*
|
|
914
|
+
* Writes are THROTTLED. A composition emits 10 frames a second and a process
|
|
915
|
+
* restarts a few times a week; persisting every frame buys nothing and costs a
|
|
916
|
+
* write per frame.
|
|
917
|
+
*
|
|
918
|
+
* NOTHING here throws. The caller already has its picture; persistence is a
|
|
919
|
+
* bonus for the NEXT boot, and a disk that refuses must never cost a snapshot
|
|
920
|
+
* that succeeded. A frame that cannot be read is reported ABSENT — absent is
|
|
921
|
+
* the truth, and the courtesy card is the correct answer to it.
|
|
922
|
+
*/
|
|
923
|
+
/** One recent frame is the value; a newer one is not worth the disk. */
|
|
924
|
+
var DEFAULT_MIN_INTERVAL_MS = 6e4;
|
|
925
|
+
/** Its own subdirectory, so the addon's other state is never mistaken for a frame. */
|
|
926
|
+
var SUBDIR = "last-frame";
|
|
927
|
+
/**
|
|
928
|
+
* How long the caller may be made to wait on the disk, for ANY of it.
|
|
929
|
+
*
|
|
930
|
+
* A bonus that costs a snapshot is not a bonus. One second is far more than a
|
|
931
|
+
* healthy local write needs and far less than a viewer will sit through.
|
|
932
|
+
*/
|
|
933
|
+
var DEFAULT_DEADLINE_MS = 1e3;
|
|
934
|
+
var GridLastFrameFileStore = class {
|
|
935
|
+
dir;
|
|
936
|
+
minIntervalMs;
|
|
937
|
+
now;
|
|
938
|
+
fs;
|
|
939
|
+
deadlineMs;
|
|
940
|
+
logger;
|
|
941
|
+
/** Last write per device, so the throttle survives without touching disk. */
|
|
942
|
+
lastWriteMs = /* @__PURE__ */ new Map();
|
|
943
|
+
constructor(options) {
|
|
944
|
+
this.dir = (0, node_path.join)(options.dataDir, SUBDIR);
|
|
945
|
+
this.minIntervalMs = options.minIntervalMs ?? DEFAULT_MIN_INTERVAL_MS;
|
|
946
|
+
this.now = options.now ?? (() => Date.now());
|
|
947
|
+
this.fs = options.fs ?? node_fs.promises;
|
|
948
|
+
this.deadlineMs = options.deadlineMs ?? DEFAULT_DEADLINE_MS;
|
|
949
|
+
this.logger = options.logger;
|
|
950
|
+
}
|
|
951
|
+
async put(deviceId, jpeg) {
|
|
952
|
+
if (jpeg.length === 0) return;
|
|
953
|
+
const at = this.now();
|
|
954
|
+
const previous = this.lastWriteMs.get(deviceId);
|
|
955
|
+
if (previous !== void 0 && at - previous < this.minIntervalMs) return;
|
|
956
|
+
if (await this.bounded(deviceId, "keep the composed frame", false, async () => {
|
|
957
|
+
await this.fs.mkdir(this.dir, { recursive: true });
|
|
958
|
+
const target = this.pathFor(deviceId);
|
|
959
|
+
const staging = `${target}.writing`;
|
|
960
|
+
await this.fs.writeFile(staging, jpeg);
|
|
961
|
+
await this.fs.rename(staging, target);
|
|
962
|
+
return true;
|
|
963
|
+
})) this.lastWriteMs.set(deviceId, at);
|
|
964
|
+
}
|
|
965
|
+
async get(deviceId) {
|
|
966
|
+
return this.bounded(deviceId, "read the kept frame", null, async () => {
|
|
967
|
+
const jpeg = await this.fs.readFile(this.pathFor(deviceId));
|
|
968
|
+
return jpeg.length > 0 ? jpeg : null;
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Run one piece of disk work, and answer `fallback` whether it REFUSES or
|
|
973
|
+
* never answers at all.
|
|
974
|
+
*
|
|
975
|
+
* The `try/catch` this replaces covered only the first of those. Measured on
|
|
976
|
+
* the CI runner (Linux, root, in a container) 2026-09-20: `fs.mkdir` with
|
|
977
|
+
* `recursive: true` under a parent that cannot hold a directory never
|
|
978
|
+
* settles — procfs answers ENOENT and Node's recursive mkdir retries the
|
|
979
|
+
* child forever — and `put` is AWAITED on the snapshot answer path, so the
|
|
980
|
+
* grid's snapshot RPC never answered either. An exception is not the only
|
|
981
|
+
* way the disk says no.
|
|
982
|
+
*/
|
|
983
|
+
async bounded(deviceId, what, fallback, work) {
|
|
984
|
+
let timer = null;
|
|
985
|
+
const expiry = new Promise((resolve) => {
|
|
986
|
+
timer = setTimeout(() => resolve({ settled: false }), this.deadlineMs);
|
|
987
|
+
timer.unref();
|
|
988
|
+
});
|
|
989
|
+
try {
|
|
990
|
+
const outcome = await Promise.race([work().then((value) => ({
|
|
991
|
+
settled: true,
|
|
992
|
+
value
|
|
993
|
+
})), expiry]);
|
|
994
|
+
if (!outcome.settled) {
|
|
995
|
+
this.logger.warn(`camera grid: the disk did not ${what} within its deadline`, {
|
|
996
|
+
tags: { deviceId },
|
|
997
|
+
meta: { deadlineMs: this.deadlineMs }
|
|
998
|
+
});
|
|
999
|
+
return fallback;
|
|
1000
|
+
}
|
|
1001
|
+
return outcome.value;
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
this.logger.warn(`camera grid: the disk could not ${what}`, {
|
|
1004
|
+
tags: { deviceId },
|
|
1005
|
+
meta: { error: require_dist.errMsg(error) }
|
|
1006
|
+
});
|
|
1007
|
+
return fallback;
|
|
1008
|
+
} finally {
|
|
1009
|
+
if (timer !== null) clearTimeout(timer);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
pathFor(deviceId) {
|
|
1013
|
+
return (0, node_path.join)(this.dir, `${String(deviceId)}.jpg`);
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
//#endregion
|
|
1017
|
+
//#region src/builtins/camera-grid/grid-canvas.ts
|
|
1018
|
+
/** Bytes one yuv420p frame of this size occupies. */
|
|
1019
|
+
function yuv420pSize(width, height) {
|
|
1020
|
+
return width * height + 2 * (width / 2) * (height / 2);
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Round DOWN to even.
|
|
1024
|
+
*
|
|
1025
|
+
* Down and not nearest: a tile that rounded UP would claim a row of samples the
|
|
1026
|
+
* decoder was never asked to produce, and the copy would either overrun or be
|
|
1027
|
+
* refused at the moment the picture is wanted.
|
|
1028
|
+
*/
|
|
1029
|
+
function evenDown(value) {
|
|
1030
|
+
return Math.max(0, Math.floor(value / 2) * 2);
|
|
1031
|
+
}
|
|
1032
|
+
var GridCanvas = class {
|
|
1033
|
+
width;
|
|
1034
|
+
height;
|
|
1035
|
+
buffer;
|
|
1036
|
+
lumaBytes;
|
|
1037
|
+
chromaBytes;
|
|
1038
|
+
constructor(width, height) {
|
|
1039
|
+
this.width = width;
|
|
1040
|
+
this.height = height;
|
|
1041
|
+
this.lumaBytes = width * height;
|
|
1042
|
+
this.chromaBytes = width / 2 * (height / 2);
|
|
1043
|
+
this.buffer = Buffer.alloc(yuv420pSize(width, height));
|
|
1044
|
+
this.clear();
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Legible black — Y 0, chroma 128 (neutral).
|
|
1048
|
+
*
|
|
1049
|
+
* `Buffer.alloc` already zeroes, and zeroed CHROMA is not black: it is a
|
|
1050
|
+
* strong green. A cell nobody has filled yet has to look like an empty cell,
|
|
1051
|
+
* not like a fault.
|
|
1052
|
+
*/
|
|
1053
|
+
clear() {
|
|
1054
|
+
this.buffer.fill(0, 0, this.lumaBytes);
|
|
1055
|
+
this.buffer.fill(128, this.lumaBytes);
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Copy one decoded tile in at `origin`.
|
|
1059
|
+
*
|
|
1060
|
+
* Returns false — never throws, never writes a partial tile — when the tile
|
|
1061
|
+
* does not fit, is the wrong size for the dimensions it claims, or sits on an
|
|
1062
|
+
* odd boundary. This runs on the output tick, so a bad frame from one source
|
|
1063
|
+
* must cost that source's rectangle and nothing else.
|
|
1064
|
+
*/
|
|
1065
|
+
blit(tile, size, origin) {
|
|
1066
|
+
if (!isEven(size.width) || !isEven(size.height)) return false;
|
|
1067
|
+
if (!isEven(origin.x) || !isEven(origin.y)) return false;
|
|
1068
|
+
if (size.width <= 0 || size.height <= 0) return false;
|
|
1069
|
+
if (origin.x < 0 || origin.y < 0) return false;
|
|
1070
|
+
if (origin.x + size.width > this.width) return false;
|
|
1071
|
+
if (origin.y + size.height > this.height) return false;
|
|
1072
|
+
if (tile.length !== yuv420pSize(size.width, size.height)) return false;
|
|
1073
|
+
for (let row = 0; row < size.height; row += 1) {
|
|
1074
|
+
const from = row * size.width;
|
|
1075
|
+
const to = (origin.y + row) * this.width + origin.x;
|
|
1076
|
+
tile.copy(this.buffer, to, from, from + size.width);
|
|
1077
|
+
}
|
|
1078
|
+
const tileLuma = size.width * size.height;
|
|
1079
|
+
const tileChroma = size.width / 2 * (size.height / 2);
|
|
1080
|
+
const halfW = size.width / 2;
|
|
1081
|
+
const halfH = size.height / 2;
|
|
1082
|
+
const canvasHalfW = this.width / 2;
|
|
1083
|
+
for (let plane = 0; plane < 2; plane += 1) {
|
|
1084
|
+
const tileBase = tileLuma + plane * tileChroma;
|
|
1085
|
+
const canvasBase = this.lumaBytes + plane * this.chromaBytes;
|
|
1086
|
+
for (let row = 0; row < halfH; row += 1) {
|
|
1087
|
+
const from = tileBase + row * halfW;
|
|
1088
|
+
const to = canvasBase + (origin.y / 2 + row) * canvasHalfW + origin.x / 2;
|
|
1089
|
+
tile.copy(this.buffer, to, from, from + halfW);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
return true;
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
function isEven(value) {
|
|
1096
|
+
return Number.isInteger(value) && value % 2 === 0;
|
|
1097
|
+
}
|
|
1098
|
+
//#endregion
|
|
1099
|
+
//#region src/builtins/camera-grid/grid-canvas-derivation.ts
|
|
1100
|
+
/**
|
|
1101
|
+
* The canvas is a RESULT, not a field.
|
|
1102
|
+
*
|
|
1103
|
+
* ## Why the operator stopped typing it
|
|
1104
|
+
*
|
|
1105
|
+
* A grid's resolution used to be two numbers in the editor, beside FPS. They
|
|
1106
|
+
* looked harmless and were not: that number silently decided how much the
|
|
1107
|
+
* composite cost and how sharp it was. An operator typing 1920x1080 was, without
|
|
1108
|
+
* being told, committing the hub to reading two 4 MP streams — or, with the
|
|
1109
|
+
* rule before it, to upscaling a 640x360 sub-stream by 3x. Neither is a thing
|
|
1110
|
+
* anyone can be expected to work out from a text field.
|
|
1111
|
+
*
|
|
1112
|
+
* ## What it is derived from
|
|
1113
|
+
*
|
|
1114
|
+
* The operator draws two rectangles per camera — which part of the source to
|
|
1115
|
+
* take, and where it lands — and both are fractions, so nothing is pixels yet.
|
|
1116
|
+
* Exactly one number is missing: how many pixels the whole canvas is worth.
|
|
1117
|
+
*
|
|
1118
|
+
* A cell has `sourceResolution x crop` REAL pixels behind it. Showing them 1:1
|
|
1119
|
+
* neither invents nor discards anything, so the cell should be exactly that
|
|
1120
|
+
* many pixels — and since the cell is a fraction `f` of the canvas, the canvas
|
|
1121
|
+
* it implies is `real / f`. Each cell proposes one, and the LARGEST wins: the
|
|
1122
|
+
* hungriest cell is served 1:1 and the others scale down by a hair, never up.
|
|
1123
|
+
*
|
|
1124
|
+
* Gaps change nothing. Cells need not cover the canvas, and an uncovered part
|
|
1125
|
+
* is background — it has no pixels to propose.
|
|
1126
|
+
*
|
|
1127
|
+
* ## One per profile
|
|
1128
|
+
*
|
|
1129
|
+
* A source is a different size at each profile, so each profile derives its own
|
|
1130
|
+
* canvas: a grid's `low` composes its sources' `low` onto the canvas their
|
|
1131
|
+
* `low` implies. That is what makes the three outputs 1:1 with what they are
|
|
1132
|
+
* made of, and what lets a viewer's adaptive pick a rung without the grid
|
|
1133
|
+
* needing to know it exists.
|
|
1134
|
+
*/
|
|
1135
|
+
/**
|
|
1136
|
+
* What an encoder will take. Not a taste: `libx264` refuses beyond 8192 in
|
|
1137
|
+
* either axis, and a canvas that large is a composition nobody can decode
|
|
1138
|
+
* anyway. Reached only by a cell that shows a sliver of a source at full
|
|
1139
|
+
* canvas width, which is a layout, not a mistake — so it is CLAMPED rather
|
|
1140
|
+
* than refused, and clamped in both axes together so the picture the operator
|
|
1141
|
+
* drew keeps its shape.
|
|
1142
|
+
*/
|
|
1143
|
+
var MAX_CANVAS_WIDTH = 7680;
|
|
1144
|
+
var MAX_CANVAS_HEIGHT = 4320;
|
|
1145
|
+
/** Below this a composition is not a cheaper picture, it is no picture. */
|
|
1146
|
+
var MIN_CANVAS_EDGE = 160;
|
|
1147
|
+
/**
|
|
1148
|
+
* The canvas these cells imply, or `null` when they imply none.
|
|
1149
|
+
*
|
|
1150
|
+
* `null` for a grid with no cells — the normal freshly-created state — and for
|
|
1151
|
+
* a layout whose every rectangle is degenerate. Both are "there is no picture
|
|
1152
|
+
* to size", which the caller turns into "this profile is not on offer" rather
|
|
1153
|
+
* than into a guess.
|
|
1154
|
+
*/
|
|
1155
|
+
function deriveGridCanvas(cells) {
|
|
1156
|
+
let width = 0;
|
|
1157
|
+
let height = 0;
|
|
1158
|
+
for (const entry of cells) {
|
|
1159
|
+
if (entry.cell.width <= 0 || entry.cell.height <= 0) continue;
|
|
1160
|
+
if (entry.sourceSize.width <= 0 || entry.sourceSize.height <= 0) continue;
|
|
1161
|
+
const realWidth = entry.sourceSize.width * entry.source.width;
|
|
1162
|
+
const realHeight = entry.sourceSize.height * entry.source.height;
|
|
1163
|
+
if (realWidth <= 0 || realHeight <= 0) continue;
|
|
1164
|
+
width = Math.max(width, realWidth / entry.cell.width);
|
|
1165
|
+
height = Math.max(height, realHeight / entry.cell.height);
|
|
1166
|
+
}
|
|
1167
|
+
if (width <= 0 || height <= 0) return null;
|
|
1168
|
+
const overshoot = Math.max(width / MAX_CANVAS_WIDTH, height / MAX_CANVAS_HEIGHT, 1);
|
|
1169
|
+
const factor = Math.max(MIN_CANVAS_EDGE / width, MIN_CANVAS_EDGE / height, 1) / overshoot;
|
|
1170
|
+
return {
|
|
1171
|
+
width: Math.max(2, evenDown(width * factor)),
|
|
1172
|
+
height: Math.max(2, evenDown(height * factor))
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
//#endregion
|
|
1176
|
+
//#region src/builtins/camera-grid/grid-profiles.ts
|
|
1177
|
+
/**
|
|
1178
|
+
* One id per profile, for every grid, forever.
|
|
1179
|
+
*
|
|
1180
|
+
* D519's reason is what keeps `high`'s id bare: a newly-spelled id mints a
|
|
1181
|
+
* second cam-stream and orphans whatever profile assignment the operator had
|
|
1182
|
+
* made. `grid` was `high` on the live hub before any of this and still is.
|
|
1183
|
+
*/
|
|
1184
|
+
var GRID_CAM_STREAM_ID = "grid";
|
|
1185
|
+
/** Every profile a grid can compose, in descending quality. */
|
|
1186
|
+
var GRID_PROFILES = [
|
|
1187
|
+
"high",
|
|
1188
|
+
"mid",
|
|
1189
|
+
"low"
|
|
1190
|
+
];
|
|
1191
|
+
/** The cam-stream id a grid publishes for one profile. */
|
|
1192
|
+
function gridCamStreamId(profile) {
|
|
1193
|
+
return profile === "high" ? GRID_CAM_STREAM_ID : `${GRID_CAM_STREAM_ID}-${profile}`;
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* What this grid can honestly publish, per profile, with the canvas or the
|
|
1197
|
+
* refusal.
|
|
1198
|
+
*
|
|
1199
|
+
* Every profile gets a row whether it is offered or not: an absent row says
|
|
1200
|
+
* nothing, and the caller logging a refusal needs the reason more than the
|
|
1201
|
+
* caller publishing an offer needs the offer.
|
|
1202
|
+
*/
|
|
1203
|
+
function gridProfilePlans(input) {
|
|
1204
|
+
const sourceDeviceIds = [...new Set(input.cells.map((cell) => cell.deviceId))];
|
|
1205
|
+
const servedBy = /* @__PURE__ */ new Map();
|
|
1206
|
+
for (const deviceId of sourceDeviceIds) servedBy.set(deviceId, input.profilesServedBy(deviceId));
|
|
1207
|
+
return GRID_PROFILES.map((profile) => {
|
|
1208
|
+
if (sourceDeviceIds.length === 0) return {
|
|
1209
|
+
profile,
|
|
1210
|
+
offered: false,
|
|
1211
|
+
missingSources: []
|
|
1212
|
+
};
|
|
1213
|
+
const sizeBySource = /* @__PURE__ */ new Map();
|
|
1214
|
+
const missingSources = [];
|
|
1215
|
+
for (const deviceId of sourceDeviceIds) {
|
|
1216
|
+
const match = (servedBy.get(deviceId) ?? null)?.find((entry) => entry.profile === profile);
|
|
1217
|
+
if (match === void 0 || match.width <= 0 || match.height <= 0) {
|
|
1218
|
+
missingSources.push(deviceId);
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
sizeBySource.set(deviceId, {
|
|
1222
|
+
width: match.width,
|
|
1223
|
+
height: match.height
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
if (missingSources.length > 0) return {
|
|
1227
|
+
profile,
|
|
1228
|
+
offered: false,
|
|
1229
|
+
missingSources
|
|
1230
|
+
};
|
|
1231
|
+
const canvas = deriveGridCanvas(input.cells.map((cell) => ({
|
|
1232
|
+
source: cell.source,
|
|
1233
|
+
cell: cell.cell,
|
|
1234
|
+
sourceSize: sizeBySource.get(cell.deviceId) ?? {
|
|
1235
|
+
width: 0,
|
|
1236
|
+
height: 0
|
|
1237
|
+
}
|
|
1238
|
+
})));
|
|
1239
|
+
if (canvas === null) return {
|
|
1240
|
+
profile,
|
|
1241
|
+
offered: false,
|
|
1242
|
+
missingSources: []
|
|
1243
|
+
};
|
|
1244
|
+
return {
|
|
1245
|
+
profile,
|
|
1246
|
+
offered: true,
|
|
1247
|
+
canvas,
|
|
1248
|
+
published: input.publishedProfiles.includes(profile)
|
|
1249
|
+
};
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
//#endregion
|
|
1253
|
+
//#region src/builtins/camera-grid/grid-sentry-sources.ts
|
|
1254
|
+
function gridSourceDial(acquired) {
|
|
1255
|
+
const sentryUrl = acquired.sentryUrl;
|
|
1256
|
+
if (typeof sentryUrl === "string" && sentryUrl.length > 0) return {
|
|
1257
|
+
url: sentryUrl,
|
|
1258
|
+
pipelineKey: acquired.pipelineKey,
|
|
1259
|
+
mode: "sentry"
|
|
1260
|
+
};
|
|
1261
|
+
return {
|
|
1262
|
+
url: acquired.url,
|
|
1263
|
+
pipelineKey: acquired.pipelineKey,
|
|
1264
|
+
mode: "live"
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
//#endregion
|
|
1268
|
+
//#region src/builtins/camera-grid/grid-snapshot.ts
|
|
1269
|
+
/**
|
|
1270
|
+
* A grid's snapshot — a frame of the COMPOSITION, never a dial.
|
|
1271
|
+
*
|
|
1272
|
+
* ## The decision, and the two things it rejects
|
|
1273
|
+
*
|
|
1274
|
+
* The operator: *"Lo snapshot possiamo sempre farlo dallo stream sempre, non
|
|
1275
|
+
* c'e' bisogno di comporre gli snapshots"* [we can always take the snapshot from the stream, there is no need to compose the snapshots]. So:
|
|
1276
|
+
*
|
|
1277
|
+
* - **Not composed from source snapshots.** That would be a SECOND compositor,
|
|
1278
|
+
* with its own geometry, its own aspect handling and its own bugs, producing
|
|
1279
|
+
* a picture that differs from the real one in ways nobody would ever notice
|
|
1280
|
+
* until they mattered.
|
|
1281
|
+
* - **Not produced by starting the composition.** The whole of D519 is "a grid
|
|
1282
|
+
* costs nothing when nobody watches". A thumbnail that dials N cameras — and
|
|
1283
|
+
* on a battery camera, wakes one — spends the entire budget of the feature on
|
|
1284
|
+
* a 160-pixel-wide picture in a list.
|
|
1285
|
+
*
|
|
1286
|
+
* ## The three states, all answered
|
|
1287
|
+
*
|
|
1288
|
+
* | state | answer |
|
|
1289
|
+
* | --- | --- |
|
|
1290
|
+
* | a composition is running | one frame sampled out of the bytes it is already emitting |
|
|
1291
|
+
* | nothing running, a frame was kept | that frame — stale, and honest about it |
|
|
1292
|
+
* | nothing running, nothing ever kept | `null`, logged with the reason |
|
|
1293
|
+
*
|
|
1294
|
+
* `null` is the courtesy card, which is the correct picture of "this grid has
|
|
1295
|
+
* never been watched". What it must never be is a reason to dial.
|
|
1296
|
+
*
|
|
1297
|
+
* ## Why this is a NATIVE snapshot provider
|
|
1298
|
+
*
|
|
1299
|
+
* The wrapper's ladder is native-first: a native that produces a frame
|
|
1300
|
+
* short-circuits before the broker frame-grab, and the broker frame-grab is the
|
|
1301
|
+
* thing that would wake the sources. A grid with a stored frame or a live
|
|
1302
|
+
* composition therefore never reaches it. The residual — a grid that has never
|
|
1303
|
+
* once been composed — is documented in D519; it cannot wake a battery camera,
|
|
1304
|
+
* because a grid never dials one live at all (`grid-sentry-sources.ts`).
|
|
1305
|
+
*/
|
|
1306
|
+
/**
|
|
1307
|
+
* Which of the three answers applies. Pure, so the rule can be read — and
|
|
1308
|
+
* sabotaged — without a socket, a file or an ffmpeg.
|
|
1309
|
+
*/
|
|
1310
|
+
function gridSnapshotAnswerFor(input) {
|
|
1311
|
+
if (input.running) return { kind: "live" };
|
|
1312
|
+
if (input.hasStoredFrame) return { kind: "stored" };
|
|
1313
|
+
return {
|
|
1314
|
+
kind: "none",
|
|
1315
|
+
reason: "never-composed"
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
var GridSnapshotSource = class {
|
|
1319
|
+
deps;
|
|
1320
|
+
constructor(deps) {
|
|
1321
|
+
this.deps = deps;
|
|
1322
|
+
}
|
|
1323
|
+
async getSnapshot(deviceId) {
|
|
1324
|
+
const sessions = this.deps.sessionsFor(deviceId);
|
|
1325
|
+
if (sessions.length === 0) return null;
|
|
1326
|
+
const live = sessions.find((session) => session.isRunning()) ?? null;
|
|
1327
|
+
const stored = await this.readStored(deviceId);
|
|
1328
|
+
const answer = gridSnapshotAnswerFor({
|
|
1329
|
+
running: live !== null,
|
|
1330
|
+
hasStoredFrame: stored !== null
|
|
1331
|
+
});
|
|
1332
|
+
if (answer.kind === "live" && live !== null) {
|
|
1333
|
+
const sampled = await this.sample(deviceId, live);
|
|
1334
|
+
if (sampled !== null) {
|
|
1335
|
+
await this.keep(deviceId, sampled);
|
|
1336
|
+
return toImage(sampled);
|
|
1337
|
+
}
|
|
1338
|
+
if (stored !== null) return toImage(stored);
|
|
1339
|
+
this.deps.logger.warn("camera grid: the composition is running but produced no frame, and none was kept", { tags: { deviceId } });
|
|
1340
|
+
return null;
|
|
1341
|
+
}
|
|
1342
|
+
if (answer.kind === "stored" && stored !== null) return toImage(stored);
|
|
1343
|
+
this.deps.logger.warn("camera grid: no frame for this grid — nothing is composing it and none was ever kept", {
|
|
1344
|
+
tags: { deviceId },
|
|
1345
|
+
meta: {
|
|
1346
|
+
reason: "never-composed",
|
|
1347
|
+
compositions: sessions.length
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
return null;
|
|
1351
|
+
}
|
|
1352
|
+
async sample(deviceId, session) {
|
|
1353
|
+
try {
|
|
1354
|
+
const jpeg = await this.deps.sampleFrame(session);
|
|
1355
|
+
if (jpeg !== null && jpeg.length > 0) return jpeg;
|
|
1356
|
+
this.deps.logger.warn("camera grid: could not sample a frame from the live composition", { tags: { deviceId } });
|
|
1357
|
+
return null;
|
|
1358
|
+
} catch (error) {
|
|
1359
|
+
this.deps.logger.warn("camera grid: could not sample a frame from the live composition", {
|
|
1360
|
+
tags: { deviceId },
|
|
1361
|
+
meta: { error: require_dist.errMsg(error) }
|
|
1362
|
+
});
|
|
1363
|
+
return null;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
async readStored(deviceId) {
|
|
1367
|
+
try {
|
|
1368
|
+
const jpeg = await this.deps.store.get(deviceId);
|
|
1369
|
+
return jpeg !== null && jpeg.length > 0 ? jpeg : null;
|
|
1370
|
+
} catch (error) {
|
|
1371
|
+
this.deps.logger.warn("camera grid: the kept frame could not be read", {
|
|
1372
|
+
tags: { deviceId },
|
|
1373
|
+
meta: { error: require_dist.errMsg(error) }
|
|
1374
|
+
});
|
|
1375
|
+
return null;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
async keep(deviceId, jpeg) {
|
|
1379
|
+
try {
|
|
1380
|
+
await this.deps.store.put(deviceId, jpeg);
|
|
1381
|
+
} catch (error) {
|
|
1382
|
+
this.deps.logger.warn("camera grid: the composed frame could not be kept", {
|
|
1383
|
+
tags: { deviceId },
|
|
1384
|
+
meta: { error: require_dist.errMsg(error) }
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
function toImage(jpeg) {
|
|
1390
|
+
return {
|
|
1391
|
+
base64: jpeg.toString("base64"),
|
|
1392
|
+
contentType: "image/jpeg"
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
//#endregion
|
|
1396
|
+
//#region src/builtins/camera-grid/grid-stream-relay.ts
|
|
1397
|
+
/**
|
|
1398
|
+
* The loopback HTTP endpoint the broker dials to consume a grid.
|
|
1399
|
+
*
|
|
1400
|
+
* A GET is the demand signal and the transport in one: the connection opening
|
|
1401
|
+
* is the first consumer arriving, and the connection closing is it leaving.
|
|
1402
|
+
* There is no other way to start or stop a composition, which is what makes
|
|
1403
|
+
* "off when nobody watches" true by construction rather than by a policy
|
|
1404
|
+
* somebody has to remember to apply.
|
|
1405
|
+
*
|
|
1406
|
+
* Bound on 127.0.0.1 only. The broker is hub-only and so is this addon
|
|
1407
|
+
* ({@link ../package.json} `placement: hub-only`), so the endpoint never needs
|
|
1408
|
+
* to be reachable from another node — and an MPEG-TS of every camera in the
|
|
1409
|
+
* grid is not something to expose on a LAN interface by accident.
|
|
1410
|
+
*/
|
|
1411
|
+
var PATH_PREFIX = "/grid/";
|
|
1412
|
+
var PATH_SUFFIX = GRID_WIRE_PATH_SUFFIX;
|
|
1413
|
+
/** How long a reader may refuse to drain before it is cut. */
|
|
1414
|
+
var SLOW_READER_MS = 5e3;
|
|
1415
|
+
function asProfile(raw) {
|
|
1416
|
+
return GRID_PROFILES.find((profile) => profile === raw) ?? null;
|
|
1417
|
+
}
|
|
1418
|
+
/** `/grid/<instanceId>/<profile>.flv`, or `null` when it is anything else. */
|
|
1419
|
+
function parseGridStreamPath(url) {
|
|
1420
|
+
const path = (url ?? "").split("?")[0] ?? "";
|
|
1421
|
+
if (!path.startsWith(PATH_PREFIX) || !path.endsWith(PATH_SUFFIX)) return null;
|
|
1422
|
+
const raw = path.slice(6, path.length - PATH_SUFFIX.length);
|
|
1423
|
+
const at = raw.lastIndexOf("/");
|
|
1424
|
+
if (at <= 0) return null;
|
|
1425
|
+
const profile = asProfile(raw.slice(at + 1));
|
|
1426
|
+
if (profile === null) return null;
|
|
1427
|
+
try {
|
|
1428
|
+
const instanceId = decodeURIComponent(raw.slice(0, at));
|
|
1429
|
+
return instanceId.length > 0 ? {
|
|
1430
|
+
instanceId,
|
|
1431
|
+
profile
|
|
1432
|
+
} : null;
|
|
1433
|
+
} catch {
|
|
1434
|
+
return null;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
var GridStreamRelay = class {
|
|
1438
|
+
deps;
|
|
1439
|
+
server = null;
|
|
1440
|
+
baseUrl = "";
|
|
1441
|
+
open = /* @__PURE__ */ new Set();
|
|
1442
|
+
constructor(deps) {
|
|
1443
|
+
this.deps = deps;
|
|
1444
|
+
}
|
|
1445
|
+
async start() {
|
|
1446
|
+
if (this.server) return;
|
|
1447
|
+
const server = (0, node_http.createServer)((req, res) => {
|
|
1448
|
+
const request = parseGridStreamPath(req.url);
|
|
1449
|
+
if (req.method !== "GET" || request === null) {
|
|
1450
|
+
res.writeHead(404).end();
|
|
1451
|
+
return;
|
|
1452
|
+
}
|
|
1453
|
+
this.serve(request, res);
|
|
1454
|
+
});
|
|
1455
|
+
await new Promise((resolve, reject) => {
|
|
1456
|
+
server.once("error", reject);
|
|
1457
|
+
server.listen(0, "127.0.0.1", resolve);
|
|
1458
|
+
});
|
|
1459
|
+
const address = server.address();
|
|
1460
|
+
if (typeof address !== "object" || address === null) {
|
|
1461
|
+
server.close();
|
|
1462
|
+
throw new Error("camera-grid: the stream relay did not bind a TCP port");
|
|
1463
|
+
}
|
|
1464
|
+
this.server = server;
|
|
1465
|
+
this.baseUrl = `http://127.0.0.1:${String(address.port)}`;
|
|
1466
|
+
}
|
|
1467
|
+
/** The URL a grid's catalog descriptor advertises. Empty before {@link start}. */
|
|
1468
|
+
streamUrl(request) {
|
|
1469
|
+
if (!this.baseUrl) throw new Error("camera-grid: the stream relay is not started");
|
|
1470
|
+
const instance = encodeURIComponent(request.instanceId);
|
|
1471
|
+
return `${this.baseUrl}${PATH_PREFIX}${instance}/${request.profile}${PATH_SUFFIX}`;
|
|
1472
|
+
}
|
|
1473
|
+
async serve(request, res) {
|
|
1474
|
+
const { instanceId, profile } = request;
|
|
1475
|
+
const session = this.deps.sessionFor(request);
|
|
1476
|
+
if (session === null) {
|
|
1477
|
+
this.deps.logger.warn("camera grid: a stream was requested for an unknown grid", { meta: {
|
|
1478
|
+
instanceId,
|
|
1479
|
+
profile
|
|
1480
|
+
} });
|
|
1481
|
+
res.writeHead(404).end();
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
this.open.add(res);
|
|
1485
|
+
let hold = null;
|
|
1486
|
+
let stallTimer = null;
|
|
1487
|
+
const sendHead = () => {
|
|
1488
|
+
if (res.headersSent) return;
|
|
1489
|
+
res.writeHead(200, {
|
|
1490
|
+
"content-type": GRID_WIRE_CONTENT_TYPE,
|
|
1491
|
+
"cache-control": "no-store",
|
|
1492
|
+
connection: "keep-alive"
|
|
1493
|
+
});
|
|
1494
|
+
res.flushHeaders();
|
|
1495
|
+
};
|
|
1496
|
+
const clearStall = () => {
|
|
1497
|
+
if (stallTimer === null) return;
|
|
1498
|
+
clearTimeout(stallTimer);
|
|
1499
|
+
stallTimer = null;
|
|
1500
|
+
};
|
|
1501
|
+
res.on("drain", clearStall);
|
|
1502
|
+
try {
|
|
1503
|
+
hold = await session.open({
|
|
1504
|
+
onData: (chunk) => {
|
|
1505
|
+
if (res.writableEnded || res.destroyed) return;
|
|
1506
|
+
sendHead();
|
|
1507
|
+
if (res.write(chunk) || stallTimer !== null) return;
|
|
1508
|
+
stallTimer = setTimeout(() => {
|
|
1509
|
+
stallTimer = null;
|
|
1510
|
+
this.deps.logger.warn("camera grid: cutting a reader that never drained — it was holding the composition", {
|
|
1511
|
+
tags: { deviceId: session.deviceId },
|
|
1512
|
+
meta: {
|
|
1513
|
+
instanceId,
|
|
1514
|
+
profile,
|
|
1515
|
+
stalledForMs: SLOW_READER_MS
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1518
|
+
res.destroy();
|
|
1519
|
+
}, SLOW_READER_MS);
|
|
1520
|
+
stallTimer.unref?.();
|
|
1521
|
+
},
|
|
1522
|
+
onClose: (reason) => {
|
|
1523
|
+
this.deps.logger.info("camera grid: ending a reader", {
|
|
1524
|
+
tags: { deviceId: session.deviceId },
|
|
1525
|
+
meta: {
|
|
1526
|
+
instanceId,
|
|
1527
|
+
profile,
|
|
1528
|
+
reason
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1531
|
+
clearStall();
|
|
1532
|
+
res.end();
|
|
1533
|
+
}
|
|
1534
|
+
});
|
|
1535
|
+
} catch (error) {
|
|
1536
|
+
this.deps.logger.warn("camera grid: could not serve a grid stream", {
|
|
1537
|
+
tags: { deviceId: session.deviceId },
|
|
1538
|
+
meta: {
|
|
1539
|
+
instanceId,
|
|
1540
|
+
profile,
|
|
1541
|
+
error: require_dist.errMsg(error)
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
if (!res.headersSent) res.writeHead(503, { "content-type": "text/plain" });
|
|
1545
|
+
res.end("camera grid unavailable");
|
|
1546
|
+
this.open.delete(res);
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
sendHead();
|
|
1550
|
+
res.on("close", () => {
|
|
1551
|
+
this.open.delete(res);
|
|
1552
|
+
clearStall();
|
|
1553
|
+
hold?.close();
|
|
1554
|
+
});
|
|
1555
|
+
}
|
|
1556
|
+
async dispose() {
|
|
1557
|
+
for (const res of this.open) res.destroy();
|
|
1558
|
+
this.open.clear();
|
|
1559
|
+
const server = this.server;
|
|
1560
|
+
this.server = null;
|
|
1561
|
+
this.baseUrl = "";
|
|
1562
|
+
if (server) await new Promise((resolve) => server.close(() => resolve()));
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
//#endregion
|
|
1566
|
+
//#region src/builtins/camera-grid/grid-stream-descriptor.ts
|
|
1567
|
+
/**
|
|
1568
|
+
* `profileHint` is load-bearing, not decoration.
|
|
1569
|
+
*
|
|
1570
|
+
* A device publishing a SINGLE stream with no hint is ranked by pixel count,
|
|
1571
|
+
* and a single stream ranks into `mid` — the slot `recordings` does not select
|
|
1572
|
+
* on its own (`high|mid` picks high), that `recordingsLow` ignores, and that
|
|
1573
|
+
* scrub never reads. The Dreame robot's one 720p relay landed exactly there and
|
|
1574
|
+
* its footage was written nowhere anything looked.
|
|
1575
|
+
*
|
|
1576
|
+
* With several compositions published the hint does a second job: it says which
|
|
1577
|
+
* slot each one is FOR. Ranked by pixels a grid's `mid` would take the `high`
|
|
1578
|
+
* slot on any grid whose `high` was not offered.
|
|
1579
|
+
*/
|
|
1580
|
+
function gridStreamDescriptor(input) {
|
|
1581
|
+
return {
|
|
1582
|
+
camStreamId: gridCamStreamId(input.profile),
|
|
1583
|
+
kind: GRID_WIRE_STREAM_KIND,
|
|
1584
|
+
url: input.url,
|
|
1585
|
+
codec: "h264",
|
|
1586
|
+
resolution: {
|
|
1587
|
+
width: input.width,
|
|
1588
|
+
height: input.height
|
|
1589
|
+
},
|
|
1590
|
+
fps: input.fps,
|
|
1591
|
+
label: `Grid composition (${input.profile})`,
|
|
1592
|
+
profileHint: input.profile,
|
|
1593
|
+
autoEligible: true
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
//#endregion
|
|
1597
|
+
//#region src/builtins/camera-grid/flv-join.ts
|
|
1598
|
+
/**
|
|
1599
|
+
* Making one FLV stream joinable by many readers.
|
|
1600
|
+
*
|
|
1601
|
+
* MPEG-TS is self-describing: a reader attaches mid-stream, waits for the next
|
|
1602
|
+
* PAT/PMT and decodes. FLV is not. Its 9-byte signature, its `onMetaData`
|
|
1603
|
+
* script tag and its AVC sequence header appear ONCE, at the top, and a reader
|
|
1604
|
+
* that arrives later is handed the middle of a tag — ffmpeg answers `Invalid
|
|
1605
|
+
* data found when processing input`, which is exactly what the hub did the
|
|
1606
|
+
* minute the grid started emitting FLV (2026-09-17). The grid emits FLV because
|
|
1607
|
+
* the bundled ffmpeg segfaults remuxing MPEG-TS (D519 notes, same day), so the
|
|
1608
|
+
* format is not negotiable and this is the price of it.
|
|
1609
|
+
*
|
|
1610
|
+
* The join point therefore does two things, and nothing else:
|
|
1611
|
+
*
|
|
1612
|
+
* - **remembers what describes the stream** — the header, the newest script
|
|
1613
|
+
* tag, the newest AVC sequence header. Newest, not first: an encoder that
|
|
1614
|
+
* respawns emits a new sequence header, and a reader handed the old one
|
|
1615
|
+
* decodes noise;
|
|
1616
|
+
* - **starts each reader on a tag boundary at a KEYFRAME**, never mid-tag and
|
|
1617
|
+
* never on an inter frame that references pictures the reader never saw.
|
|
1618
|
+
*
|
|
1619
|
+
* It is a parser, not a buffer: nothing is retained beyond the preamble and the
|
|
1620
|
+
* partial tag currently being assembled. A composite at 10 fps with a 2-second
|
|
1621
|
+
* GOP makes a reader wait at most two seconds to join, which is the same wait
|
|
1622
|
+
* MPEG-TS would have imposed for its next key frame.
|
|
1623
|
+
*/
|
|
1624
|
+
/** FLV tag header: type(1) + dataSize(3) + timestamp(3) + extended(1) + streamId(3). */
|
|
1625
|
+
var TAG_HEADER_BYTES = 11;
|
|
1626
|
+
/** Every tag is followed by its own size as a 4-byte trailer. */
|
|
1627
|
+
var TAG_TRAILER_BYTES = 4;
|
|
1628
|
+
/** `FLV` + version(1) + flags(1) + dataOffset(4), then PreviousTagSize0(4). */
|
|
1629
|
+
var FLV_HEADER_BYTES = 13;
|
|
1630
|
+
var TAG_TYPE_SCRIPT = 18;
|
|
1631
|
+
var TAG_TYPE_VIDEO = 9;
|
|
1632
|
+
/** High nibble of a video tag's first byte: 1 = key frame. */
|
|
1633
|
+
var VIDEO_FRAME_TYPE_KEY = 1;
|
|
1634
|
+
/** Second byte of an AVC video tag: 0 = sequence header, 1 = NALU. */
|
|
1635
|
+
var AVC_PACKET_TYPE_SEQUENCE_HEADER = 0;
|
|
1636
|
+
/**
|
|
1637
|
+
* One reader's view of the stream.
|
|
1638
|
+
*
|
|
1639
|
+
* Every consumer holds one, the first included: a join point with a privileged
|
|
1640
|
+
* "primary" reader would have two code paths for the same question, and the
|
|
1641
|
+
* grid's first consumer is not special — it just happens to arrive when the
|
|
1642
|
+
* preamble is still being learnt.
|
|
1643
|
+
*/
|
|
1644
|
+
var FlvReader = class {
|
|
1645
|
+
state;
|
|
1646
|
+
detach;
|
|
1647
|
+
constructor(state, detach) {
|
|
1648
|
+
this.state = state;
|
|
1649
|
+
this.detach = detach;
|
|
1650
|
+
}
|
|
1651
|
+
/** True until the preamble and a key frame have been handed over. */
|
|
1652
|
+
get pending() {
|
|
1653
|
+
return !this.state.started;
|
|
1654
|
+
}
|
|
1655
|
+
/** The bytes owed to this reader since the last call, or `null`. */
|
|
1656
|
+
take() {
|
|
1657
|
+
const queued = this.state.queued;
|
|
1658
|
+
if (queued.length === 0) return null;
|
|
1659
|
+
this.state.queued = [];
|
|
1660
|
+
return queued.length === 1 ? queued[0] ?? null : Buffer.concat(queued);
|
|
1661
|
+
}
|
|
1662
|
+
/** Stop receiving. Anything queued is dropped with the reader. */
|
|
1663
|
+
close() {
|
|
1664
|
+
this.state.queued = [];
|
|
1665
|
+
this.detach(this.state);
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1668
|
+
function parseVideoFlags(body) {
|
|
1669
|
+
const first = body[0];
|
|
1670
|
+
const second = body[1];
|
|
1671
|
+
if (first === void 0) return {
|
|
1672
|
+
isKeyFrame: false,
|
|
1673
|
+
isSequenceHeader: false
|
|
1674
|
+
};
|
|
1675
|
+
const frameType = first >> 4;
|
|
1676
|
+
const sequenceHeader = second === AVC_PACKET_TYPE_SEQUENCE_HEADER;
|
|
1677
|
+
return {
|
|
1678
|
+
isKeyFrame: frameType === VIDEO_FRAME_TYPE_KEY && !sequenceHeader,
|
|
1679
|
+
isSequenceHeader: sequenceHeader
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
var FlvJoinPoint = class {
|
|
1683
|
+
buffer = Buffer.alloc(0);
|
|
1684
|
+
header = null;
|
|
1685
|
+
script = null;
|
|
1686
|
+
sequenceHeader = null;
|
|
1687
|
+
readers = /* @__PURE__ */ new Set();
|
|
1688
|
+
/** Attach a reader. It receives the preamble at the next key frame. */
|
|
1689
|
+
join() {
|
|
1690
|
+
const state = {
|
|
1691
|
+
started: false,
|
|
1692
|
+
queued: []
|
|
1693
|
+
};
|
|
1694
|
+
this.readers.add(state);
|
|
1695
|
+
return new FlvReader(state, (gone) => this.readers.delete(gone));
|
|
1696
|
+
}
|
|
1697
|
+
/** Feed bytes from the encoder; each reader then takes what it is owed. */
|
|
1698
|
+
accept(chunk) {
|
|
1699
|
+
this.buffer = this.buffer.length === 0 ? chunk : Buffer.concat([this.buffer, chunk]);
|
|
1700
|
+
this.consumeHeader();
|
|
1701
|
+
for (const tag of this.consumeTags()) this.dispatch(tag);
|
|
1702
|
+
}
|
|
1703
|
+
consumeHeader() {
|
|
1704
|
+
if (this.header !== null) return;
|
|
1705
|
+
if (this.buffer.length < FLV_HEADER_BYTES) return;
|
|
1706
|
+
this.header = this.buffer.subarray(0, FLV_HEADER_BYTES);
|
|
1707
|
+
this.buffer = this.buffer.subarray(FLV_HEADER_BYTES);
|
|
1708
|
+
}
|
|
1709
|
+
*consumeTags() {
|
|
1710
|
+
if (this.header === null) return;
|
|
1711
|
+
for (;;) {
|
|
1712
|
+
if (this.buffer.length < TAG_HEADER_BYTES) return;
|
|
1713
|
+
const dataSize = this.buffer.readUIntBE(1, 3);
|
|
1714
|
+
const total = TAG_HEADER_BYTES + dataSize + TAG_TRAILER_BYTES;
|
|
1715
|
+
if (this.buffer.length < total) return;
|
|
1716
|
+
const bytes = this.buffer.subarray(0, total);
|
|
1717
|
+
const type = bytes.readUInt8(0);
|
|
1718
|
+
const body = bytes.subarray(TAG_HEADER_BYTES, TAG_HEADER_BYTES + dataSize);
|
|
1719
|
+
const flags = type === TAG_TYPE_VIDEO ? parseVideoFlags(body) : {
|
|
1720
|
+
isKeyFrame: false,
|
|
1721
|
+
isSequenceHeader: false
|
|
1722
|
+
};
|
|
1723
|
+
this.buffer = this.buffer.subarray(total);
|
|
1724
|
+
yield {
|
|
1725
|
+
bytes,
|
|
1726
|
+
type,
|
|
1727
|
+
...flags
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
dispatch(tag) {
|
|
1732
|
+
if (tag.type === TAG_TYPE_SCRIPT) this.script = tag.bytes;
|
|
1733
|
+
if (tag.isSequenceHeader) this.sequenceHeader = tag.bytes;
|
|
1734
|
+
for (const reader of this.readers) {
|
|
1735
|
+
if (reader.started) {
|
|
1736
|
+
reader.queued.push(tag.bytes);
|
|
1737
|
+
continue;
|
|
1738
|
+
}
|
|
1739
|
+
if (!tag.isKeyFrame) continue;
|
|
1740
|
+
const preamble = this.preamble();
|
|
1741
|
+
if (preamble === null) continue;
|
|
1742
|
+
reader.started = true;
|
|
1743
|
+
reader.queued.push(preamble, tag.bytes);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
/** The bytes that describe the stream, or `null` while any is still unknown. */
|
|
1747
|
+
preamble() {
|
|
1748
|
+
if (this.header === null || this.sequenceHeader === null) return null;
|
|
1749
|
+
const parts = [this.header];
|
|
1750
|
+
if (this.script !== null) parts.push(this.script);
|
|
1751
|
+
parts.push(this.sequenceHeader);
|
|
1752
|
+
return Buffer.concat(parts);
|
|
1753
|
+
}
|
|
1754
|
+
};
|
|
1755
|
+
//#endregion
|
|
1756
|
+
//#region src/builtins/camera-grid/grid-stream-session.ts
|
|
1757
|
+
var DEFAULT_LINGER_MS = 3e3;
|
|
1758
|
+
var GridStreamSession = class {
|
|
1759
|
+
options;
|
|
1760
|
+
consumers = /* @__PURE__ */ new Map();
|
|
1761
|
+
/**
|
|
1762
|
+
* The FLV stream's describing bytes, and where each reader may start.
|
|
1763
|
+
*
|
|
1764
|
+
* Rebuilt with every cold start: a new child means a new header and a new
|
|
1765
|
+
* sequence header, and handing a reader the previous child's would decode
|
|
1766
|
+
* noise. See `flv-join.ts` for why FLV needs this and MPEG-TS did not.
|
|
1767
|
+
*/
|
|
1768
|
+
join = new FlvJoinPoint();
|
|
1769
|
+
running = null;
|
|
1770
|
+
starting = null;
|
|
1771
|
+
lingerTimer = null;
|
|
1772
|
+
teardown = null;
|
|
1773
|
+
disposed = false;
|
|
1774
|
+
constructor(options) {
|
|
1775
|
+
this.options = options;
|
|
1776
|
+
}
|
|
1777
|
+
get logTags() {
|
|
1778
|
+
return { deviceId: this.options.deviceId };
|
|
1779
|
+
}
|
|
1780
|
+
/** The COMPOSITE camera's device id — what every log line about this grid is tagged with. */
|
|
1781
|
+
get deviceId() {
|
|
1782
|
+
return this.options.deviceId;
|
|
1783
|
+
}
|
|
1784
|
+
isRunning() {
|
|
1785
|
+
return this.running !== null;
|
|
1786
|
+
}
|
|
1787
|
+
consumerCount() {
|
|
1788
|
+
return this.consumers.size;
|
|
1789
|
+
}
|
|
1790
|
+
/** Resolves once any in-flight start or teardown has finished. For tests and shutdown. */
|
|
1791
|
+
async settled() {
|
|
1792
|
+
await this.starting?.catch(() => void 0);
|
|
1793
|
+
await this.teardown;
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Attach a consumer, starting the composition if this is the first one.
|
|
1797
|
+
*
|
|
1798
|
+
* @throws when the grid has nothing to compose, or a source could not be
|
|
1799
|
+
* acquired. Both are LOGGED before they are thrown: a branch that accepts a
|
|
1800
|
+
* consumer and then produces no media is exactly the branch that reads as
|
|
1801
|
+
* "nothing ever happened".
|
|
1802
|
+
*/
|
|
1803
|
+
async open(consumer) {
|
|
1804
|
+
if (this.disposed) throw new Error("camera-grid: this stream session is disposed");
|
|
1805
|
+
this.cancelLinger();
|
|
1806
|
+
this.consumers.set(consumer, this.join.join());
|
|
1807
|
+
try {
|
|
1808
|
+
await this.ensureRunning();
|
|
1809
|
+
} catch (error) {
|
|
1810
|
+
this.dropConsumer(consumer);
|
|
1811
|
+
this.scheduleTeardownIfIdle();
|
|
1812
|
+
throw error;
|
|
1813
|
+
}
|
|
1814
|
+
let closed = false;
|
|
1815
|
+
return { close: () => {
|
|
1816
|
+
if (closed) return;
|
|
1817
|
+
closed = true;
|
|
1818
|
+
this.dropConsumer(consumer);
|
|
1819
|
+
this.options.deps.logger.debug("camera grid: consumer left", {
|
|
1820
|
+
tags: this.logTags,
|
|
1821
|
+
meta: { remaining: this.consumers.size }
|
|
1822
|
+
});
|
|
1823
|
+
this.scheduleTeardownIfIdle();
|
|
1824
|
+
} };
|
|
1825
|
+
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Attach to a composition that is ALREADY running, or refuse.
|
|
1828
|
+
*
|
|
1829
|
+
* The whole difference from {@link open} is the refusal, and the refusal is
|
|
1830
|
+
* the feature. A snapshot of a grid is a frame of the composition — which
|
|
1831
|
+
* only exists while something is watching it — and the operator's rule is
|
|
1832
|
+
* that producing a thumbnail must never be the reason N cameras get dialled.
|
|
1833
|
+
* `open()` would start the composition, acquire every source, and on a
|
|
1834
|
+
* battery camera that is a wake nobody asked for.
|
|
1835
|
+
*
|
|
1836
|
+
* `null` is a real answer: "there is no composition to take a frame from",
|
|
1837
|
+
* which the caller turns into the stored last frame, or into nothing.
|
|
1838
|
+
*/
|
|
1839
|
+
openIfRunning(consumer) {
|
|
1840
|
+
if (this.disposed || this.running === null) return null;
|
|
1841
|
+
this.cancelLinger();
|
|
1842
|
+
this.consumers.set(consumer, this.join.join());
|
|
1843
|
+
let closed = false;
|
|
1844
|
+
return { close: () => {
|
|
1845
|
+
if (closed) return;
|
|
1846
|
+
closed = true;
|
|
1847
|
+
this.dropConsumer(consumer);
|
|
1848
|
+
this.scheduleTeardownIfIdle();
|
|
1849
|
+
} };
|
|
1850
|
+
}
|
|
1851
|
+
/** Forget a consumer AND the reader holding bytes on its behalf. */
|
|
1852
|
+
dropConsumer(consumer) {
|
|
1853
|
+
this.consumers.get(consumer)?.close();
|
|
1854
|
+
this.consumers.delete(consumer);
|
|
1855
|
+
}
|
|
1856
|
+
/**
|
|
1857
|
+
* The child ended on its own. Every consumer is told WHY — a stream that
|
|
1858
|
+
* simply stops is indistinguishable from a stalled one at the far end.
|
|
1859
|
+
*/
|
|
1860
|
+
onChildEnded(reason) {
|
|
1861
|
+
if (this.running === null) return;
|
|
1862
|
+
this.options.deps.logger.warn("camera grid: the composition ended", {
|
|
1863
|
+
tags: this.logTags,
|
|
1864
|
+
meta: {
|
|
1865
|
+
reason,
|
|
1866
|
+
consumers: this.consumers.size
|
|
1867
|
+
}
|
|
1868
|
+
});
|
|
1869
|
+
for (const [consumer, reader] of [...this.consumers]) {
|
|
1870
|
+
reader.close();
|
|
1871
|
+
consumer.onClose(reason);
|
|
1872
|
+
}
|
|
1873
|
+
this.consumers.clear();
|
|
1874
|
+
this.teardown = this.stopNow();
|
|
1875
|
+
}
|
|
1876
|
+
async dispose() {
|
|
1877
|
+
this.disposed = true;
|
|
1878
|
+
this.cancelLinger();
|
|
1879
|
+
for (const [consumer, reader] of [...this.consumers]) {
|
|
1880
|
+
reader.close();
|
|
1881
|
+
consumer.onClose("shutdown");
|
|
1882
|
+
}
|
|
1883
|
+
this.consumers.clear();
|
|
1884
|
+
await this.settled();
|
|
1885
|
+
await this.stopNow();
|
|
1886
|
+
}
|
|
1887
|
+
async ensureRunning() {
|
|
1888
|
+
if (this.running) return this.running;
|
|
1889
|
+
if (this.starting) return this.starting;
|
|
1890
|
+
const starting = this.startCold();
|
|
1891
|
+
this.starting = starting;
|
|
1892
|
+
try {
|
|
1893
|
+
const state = await starting;
|
|
1894
|
+
this.running = state;
|
|
1895
|
+
return state;
|
|
1896
|
+
} finally {
|
|
1897
|
+
if (this.starting === starting) this.starting = null;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
async startCold() {
|
|
1901
|
+
const plan = this.options.resolvePlan();
|
|
1902
|
+
if (plan === null || plan.layout.cells.length === 0 || plan.sourceDeviceIds.length === 0) {
|
|
1903
|
+
this.options.deps.logger.warn("camera grid: a consumer attached but the grid has no cells — nothing to compose", { tags: this.logTags });
|
|
1904
|
+
throw new Error("camera-grid: this grid has no cells to compose");
|
|
1905
|
+
}
|
|
1906
|
+
const acquired = [];
|
|
1907
|
+
try {
|
|
1908
|
+
for (const sourceDeviceId of plan.sourceDeviceIds) acquired.push(await this.options.deps.acquireSource(sourceDeviceId));
|
|
1909
|
+
} catch (error) {
|
|
1910
|
+
this.options.deps.logger.error("camera grid: could not acquire every source — releasing the ones already taken", {
|
|
1911
|
+
tags: this.logTags,
|
|
1912
|
+
meta: {
|
|
1913
|
+
acquired: acquired.length,
|
|
1914
|
+
error: require_dist.errMsg(error)
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
await this.releaseAll(acquired);
|
|
1918
|
+
throw error;
|
|
1919
|
+
}
|
|
1920
|
+
try {
|
|
1921
|
+
this.join = new FlvJoinPoint();
|
|
1922
|
+
for (const consumer of this.consumers.keys()) this.consumers.set(consumer, this.join.join());
|
|
1923
|
+
const child = await this.options.deps.startChild(plan, acquired);
|
|
1924
|
+
child.stdout.on("data", (chunk) => {
|
|
1925
|
+
this.join.accept(chunk);
|
|
1926
|
+
for (const [consumer, reader] of this.consumers) {
|
|
1927
|
+
const owed = reader.take();
|
|
1928
|
+
if (owed !== null) consumer.onData(owed);
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
this.options.deps.logger.info("camera grid: composition started", {
|
|
1932
|
+
tags: this.logTags,
|
|
1933
|
+
meta: {
|
|
1934
|
+
cells: plan.layout.cells.length,
|
|
1935
|
+
sources: [...plan.sourceDeviceIds],
|
|
1936
|
+
canvas: `${String(plan.layout.width)}x${String(plan.layout.height)}`,
|
|
1937
|
+
fps: plan.fps
|
|
1938
|
+
}
|
|
1939
|
+
});
|
|
1940
|
+
return {
|
|
1941
|
+
child,
|
|
1942
|
+
sources: acquired
|
|
1943
|
+
};
|
|
1944
|
+
} catch (error) {
|
|
1945
|
+
this.options.deps.logger.error("camera grid: the composition failed to start", {
|
|
1946
|
+
tags: this.logTags,
|
|
1947
|
+
meta: { error: require_dist.errMsg(error) }
|
|
1948
|
+
});
|
|
1949
|
+
await this.releaseAll(acquired);
|
|
1950
|
+
throw error;
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
scheduleTeardownIfIdle() {
|
|
1954
|
+
if (this.consumers.size > 0) return;
|
|
1955
|
+
if (this.running === null && this.starting === null) return;
|
|
1956
|
+
const lingerMs = this.options.deps.lingerMs ?? DEFAULT_LINGER_MS;
|
|
1957
|
+
if (lingerMs <= 0) {
|
|
1958
|
+
this.teardown = this.stopNow();
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1961
|
+
this.cancelLinger();
|
|
1962
|
+
this.lingerTimer = setTimeout(() => {
|
|
1963
|
+
this.lingerTimer = null;
|
|
1964
|
+
if (this.consumers.size > 0) return;
|
|
1965
|
+
this.teardown = this.stopNow();
|
|
1966
|
+
}, lingerMs);
|
|
1967
|
+
this.lingerTimer.unref?.();
|
|
1968
|
+
}
|
|
1969
|
+
cancelLinger() {
|
|
1970
|
+
if (this.lingerTimer === null) return;
|
|
1971
|
+
clearTimeout(this.lingerTimer);
|
|
1972
|
+
this.lingerTimer = null;
|
|
1973
|
+
}
|
|
1974
|
+
async stopNow() {
|
|
1975
|
+
const state = this.running;
|
|
1976
|
+
this.running = null;
|
|
1977
|
+
if (state === null) return;
|
|
1978
|
+
try {
|
|
1979
|
+
await state.child.stop();
|
|
1980
|
+
} catch (error) {
|
|
1981
|
+
this.options.deps.logger.warn("camera grid: the composition did not stop cleanly", {
|
|
1982
|
+
tags: this.logTags,
|
|
1983
|
+
meta: { error: require_dist.errMsg(error) }
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
await this.releaseAll(state.sources);
|
|
1987
|
+
this.options.deps.logger.info("camera grid: composition stopped — no consumers left", {
|
|
1988
|
+
tags: this.logTags,
|
|
1989
|
+
meta: { released: state.sources.length }
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1992
|
+
async releaseAll(sources) {
|
|
1993
|
+
for (const source of sources) try {
|
|
1994
|
+
await this.options.deps.releaseSource(source.pipelineKey);
|
|
1995
|
+
} catch (error) {
|
|
1996
|
+
this.options.deps.logger.error("camera grid: could NOT release a source handle", {
|
|
1997
|
+
tags: this.logTags,
|
|
1998
|
+
meta: {
|
|
1999
|
+
pipelineKey: source.pipelineKey,
|
|
2000
|
+
error: require_dist.errMsg(error)
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
};
|
|
2006
|
+
//#endregion
|
|
2007
|
+
//#region src/builtins/camera-grid/silence-analysis.ts
|
|
2008
|
+
/**
|
|
2009
|
+
* Every analyzer a composite camera is created with switched OFF.
|
|
2010
|
+
*
|
|
2011
|
+
* A grid is a picture we composed from cameras that are ALREADY analyzed. Running
|
|
2012
|
+
* detection on the composite would pay for the same subjects a second time, and
|
|
2013
|
+
* would attribute them to a camera that does not exist as a viewpoint — a person
|
|
2014
|
+
* detected in the bottom-right cell is a person on THAT camera, not on the grid.
|
|
2015
|
+
*
|
|
2016
|
+
* `motion-detection` sits first deliberately: it is the one that holds the decode
|
|
2017
|
+
* session open, so its absence is the difference between a grid costing a
|
|
2018
|
+
* composition and costing a full decode pipeline. Same ordering, and the same
|
|
2019
|
+
* reason, as the Terminal addon's list.
|
|
2020
|
+
*
|
|
2021
|
+
* Called ONLY on creation. An operator who deliberately turns detection back on
|
|
2022
|
+
* for a grid must win, and a reconcile that re-asserted every pass would silently
|
|
2023
|
+
* overrule them once a minute.
|
|
2024
|
+
*/
|
|
2025
|
+
/**
|
|
2026
|
+
* The list lives in `@camstack/types` now, and this is an alias rather than a
|
|
2027
|
+
* second copy. There WERE two — this one and the Terminal addon's — and they
|
|
2028
|
+
* had drifted: neither named `pipeline-analytics`, the one cap with no gate of
|
|
2029
|
+
* its own, which is what a grid forwarding its sources' motion would have used
|
|
2030
|
+
* to write a duplicate motion episode per event.
|
|
2031
|
+
*/
|
|
2032
|
+
var GRID_SILENCED_CAP_NAMES = require_dist.DERIVED_CAMERA_SILENCED_CAP_NAMES;
|
|
2033
|
+
/**
|
|
2034
|
+
* Resolve the addon currently providing `capName` for this device, from the
|
|
2035
|
+
* device's OWN bindings. `listBindableCapsForDeviceType` answers for the device
|
|
2036
|
+
* TYPE and would happily name a wrapper that is not the one bound here.
|
|
2037
|
+
*
|
|
2038
|
+
* `null` when the cap is not bound at all — not an error: a deployment with no
|
|
2039
|
+
* audio analyzer has nothing to switch off, and demanding one would make every
|
|
2040
|
+
* grid creation fail on a perfectly valid hub.
|
|
2041
|
+
*/
|
|
2042
|
+
async function resolveBoundWrapper(api, deviceId, capName) {
|
|
2043
|
+
const bindings = await api.deviceManager.getBindings.query({ deviceId });
|
|
2044
|
+
for (const entry of bindings.entries) {
|
|
2045
|
+
if (entry.capName !== capName) continue;
|
|
2046
|
+
if (entry.kind !== "wrapped") continue;
|
|
2047
|
+
if (entry.providerAddonId === "") return null;
|
|
2048
|
+
return entry.providerAddonId;
|
|
2049
|
+
}
|
|
2050
|
+
return null;
|
|
2051
|
+
}
|
|
2052
|
+
/**
|
|
2053
|
+
* @throws if a cap IS bound and the write to its authority failed. The composite
|
|
2054
|
+
* would then be running a full analyzer over a picture whose subjects are already
|
|
2055
|
+
* counted elsewhere — exactly the cost this removes — and a silent version of
|
|
2056
|
+
* that failure is unfindable.
|
|
2057
|
+
*/
|
|
2058
|
+
async function silenceAnalysisFor(deps, deviceId) {
|
|
2059
|
+
const failures = [];
|
|
2060
|
+
for (const capName of GRID_SILENCED_CAP_NAMES) try {
|
|
2061
|
+
const wrapperAddonId = await resolveBoundWrapper(deps.api, deviceId, capName);
|
|
2062
|
+
if (wrapperAddonId === null) {
|
|
2063
|
+
deps.logger.debug("camera grid: no analyzer bound for this capability", {
|
|
2064
|
+
tags: { deviceId },
|
|
2065
|
+
meta: { capName }
|
|
2066
|
+
});
|
|
2067
|
+
continue;
|
|
2068
|
+
}
|
|
2069
|
+
await deps.api.deviceManager.setWrapperActive.mutate({
|
|
2070
|
+
deviceId,
|
|
2071
|
+
capName,
|
|
2072
|
+
wrapperAddonId,
|
|
2073
|
+
active: false
|
|
2074
|
+
});
|
|
2075
|
+
deps.logger.info("camera grid: analyzer switched off at its authority", {
|
|
2076
|
+
tags: { deviceId },
|
|
2077
|
+
meta: {
|
|
2078
|
+
capName,
|
|
2079
|
+
wrapperAddonId
|
|
2080
|
+
}
|
|
2081
|
+
});
|
|
2082
|
+
} catch (err) {
|
|
2083
|
+
failures.push(`${capName}: ${require_dist.errMsg(err)}`);
|
|
2084
|
+
deps.logger.error("camera grid: could NOT switch an analyzer off", {
|
|
2085
|
+
tags: { deviceId },
|
|
2086
|
+
meta: {
|
|
2087
|
+
capName,
|
|
2088
|
+
error: require_dist.errMsg(err)
|
|
2089
|
+
}
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
if (failures.length > 0) throw new Error(`camera grid ${deviceId}: could not switch off ${failures.length} analyzer(s) — it will run at full detection cost (${failures.join("; ")})`);
|
|
2093
|
+
}
|
|
2094
|
+
//#endregion
|
|
2095
|
+
//#region src/builtins/camera-grid/grid-canvas-seed.ts
|
|
2096
|
+
/**
|
|
2097
|
+
* What the canvas SAYS before a single camera has delivered a frame.
|
|
2098
|
+
*
|
|
2099
|
+
* ## Why black was not good enough
|
|
2100
|
+
*
|
|
2101
|
+
* The compositor emits from its very first tick (`grid-compositor.ts`) — that
|
|
2102
|
+
* is the whole point of a canvas, and it is what removed the ~9 s cold start.
|
|
2103
|
+
* But what it emitted until now was black, and black is the same picture for
|
|
2104
|
+
* four different situations: a grid with no cells, a grid whose sources are all
|
|
2105
|
+
* broken, a grid whose sources are merely slow, and a viewer that connected to
|
|
2106
|
+
* the wrong camera. An operator cannot tell them apart, and the one they
|
|
2107
|
+
* actually hit — sources still opening — is the one that fixes itself.
|
|
2108
|
+
*
|
|
2109
|
+
* The seed paints the LAYOUT instead: one card per cell, at the cell's own
|
|
2110
|
+
* rectangle, carrying the camera's name and the word `Waiting`. Three states
|
|
2111
|
+
* become three pictures — "no cards" is an empty grid, "a card still there" is
|
|
2112
|
+
* a tile that has not arrived, and "a picture" is a tile that has.
|
|
2113
|
+
*
|
|
2114
|
+
* It is honest about what it is. It is not a stand-in picture of the camera,
|
|
2115
|
+
* and it never carries a state it has not been told (a tile whose source is
|
|
2116
|
+
* genuinely broken is a matter for the tile's own decoder and its logs — this
|
|
2117
|
+
* says only "nothing has arrived here yet", which is true of both).
|
|
2118
|
+
*
|
|
2119
|
+
* ## Drawn ONCE, before the tick exists
|
|
2120
|
+
*
|
|
2121
|
+
* The seed is a full-canvas frame blitted in at the compositor's construction,
|
|
2122
|
+
* so the first tick already carries it and the tick never waits on anything.
|
|
2123
|
+
* Rendering it is the only asynchronous part, and it happens BEFORE the
|
|
2124
|
+
* compositor is built — never on the tick, which serves every cell.
|
|
2125
|
+
*
|
|
2126
|
+
* ## Why SVG → sharp, and why the conversion is here
|
|
2127
|
+
*
|
|
2128
|
+
* `snapshot-courtesy.ts` already renders text this way and states the reason:
|
|
2129
|
+
* shelling out to ffmpeg's `drawtext` was 52 ms against sharp's 4.8 ms, and an
|
|
2130
|
+
* SVG names a font FAMILY that fontconfig resolves instead of a font PATH that
|
|
2131
|
+
* has to be probed. This is that pattern, not a second one.
|
|
2132
|
+
*
|
|
2133
|
+
* What is different is the output. The canvas is yuv420p — that is what makes a
|
|
2134
|
+
* blit a strided memcpy — and sharp has no yuv output, so the raster is
|
|
2135
|
+
* converted once, here, by `rgbToYuv420p`. Once per composition start, over a
|
|
2136
|
+
* frame that is already being allocated; never per tick.
|
|
2137
|
+
*
|
|
2138
|
+
* ## Even, like everything else that touches the canvas
|
|
2139
|
+
*
|
|
2140
|
+
* The cards are the TILES' own rectangles, which `buildGridTilePlan` has
|
|
2141
|
+
* already snapped to even pixels — yuv420p subsamples chroma 2×2, and an odd
|
|
2142
|
+
* rectangle tints a tile rather than breaking it. Nothing here re-derives a
|
|
2143
|
+
* rectangle; it copies the one the decoder was sized against, so a card cannot
|
|
2144
|
+
* land anywhere other than exactly where its picture will.
|
|
2145
|
+
*/
|
|
2146
|
+
/**
|
|
2147
|
+
* The word a card carries. Deliberately not a fault: nothing has arrived YET,
|
|
2148
|
+
* which is true of a camera that is slow and of one that is broken, and this
|
|
2149
|
+
* placeholder knows which it is for neither.
|
|
2150
|
+
*/
|
|
2151
|
+
var GRID_SEED_WAITING_LABEL = "Waiting";
|
|
2152
|
+
/**
|
|
2153
|
+
* Family names, not paths — librsvg resolves them through fontconfig, and the
|
|
2154
|
+
* trailing generics keep a host without DejaVu rendering something legible
|
|
2155
|
+
* rather than nothing. Same stack as the courtesy frame, for the same reason.
|
|
2156
|
+
*/
|
|
2157
|
+
var SEED_FONT_STACK = "DejaVu Sans,DejaVu Sans Mono,Helvetica,Arial,sans-serif";
|
|
2158
|
+
/** The card. Dark enough to read as "empty", lit enough to read as "a cell". */
|
|
2159
|
+
var CARD_FILL = "#1b1b21";
|
|
2160
|
+
var CARD_BORDER = "#3f3f4c";
|
|
2161
|
+
var CARD_NAME = "#e8e8ee";
|
|
2162
|
+
var CARD_STATE = "#8f8f9e";
|
|
2163
|
+
/**
|
|
2164
|
+
* The label for one source.
|
|
2165
|
+
*
|
|
2166
|
+
* A name we could not read is not a reason to paint an anonymous rectangle: the
|
|
2167
|
+
* DEVICE ID is what every log line about that tile carries, so it is the one
|
|
2168
|
+
* label an operator can act on. A blank or whitespace name is treated as no
|
|
2169
|
+
* name for the same reason.
|
|
2170
|
+
*/
|
|
2171
|
+
function gridSeedName(names, deviceId) {
|
|
2172
|
+
const name = names.get(deviceId)?.trim();
|
|
2173
|
+
return name === void 0 || name.length === 0 ? `Camera ${String(deviceId)}` : name;
|
|
2174
|
+
}
|
|
2175
|
+
/**
|
|
2176
|
+
* The seed a tile plan implies — pure, and the plan is the ONLY input to the
|
|
2177
|
+
* geometry. A card is its tile's rectangle, never a recomputed one.
|
|
2178
|
+
*/
|
|
2179
|
+
function buildGridSeedSpec(plan, names) {
|
|
2180
|
+
return {
|
|
2181
|
+
canvas: plan.canvas,
|
|
2182
|
+
cells: plan.tiles.map((tile) => ({
|
|
2183
|
+
origin: tile.origin,
|
|
2184
|
+
size: tile.size,
|
|
2185
|
+
name: gridSeedName(names, tile.deviceId)
|
|
2186
|
+
}))
|
|
2187
|
+
};
|
|
2188
|
+
}
|
|
2189
|
+
/** XML escaping for text placed inside an SVG `<text>` node. */
|
|
2190
|
+
function escapeSeedText(value) {
|
|
2191
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
2192
|
+
}
|
|
2193
|
+
/**
|
|
2194
|
+
* The document the seed is rasterized from.
|
|
2195
|
+
*
|
|
2196
|
+
* No full-bleed background: the uncovered part of a canvas is NOT a cell — the
|
|
2197
|
+
* cells need not cover it (`grid-canvas-derivation.ts`) — and painting a card's
|
|
2198
|
+
* treatment over it would say "waiting" about a tile that does not exist. It
|
|
2199
|
+
* stays the canvas' own black.
|
|
2200
|
+
*
|
|
2201
|
+
* Each card clips its own text. A camera named for a whole street would
|
|
2202
|
+
* otherwise spill across the cell next to it, and a label on the wrong tile is
|
|
2203
|
+
* worse than a truncated one.
|
|
2204
|
+
*/
|
|
2205
|
+
function buildGridSeedSvg(spec) {
|
|
2206
|
+
const parts = [`<svg xmlns="http://www.w3.org/2000/svg" width="${String(spec.canvas.width)}" height="${String(spec.canvas.height)}">`];
|
|
2207
|
+
for (const [index, cell] of spec.cells.entries()) {
|
|
2208
|
+
const { width, height } = cell.size;
|
|
2209
|
+
const nameSize = Math.max(9, Math.min(Math.round(width / 12), Math.round(height / 8)));
|
|
2210
|
+
const stateSize = Math.max(8, Math.round(nameSize * .62));
|
|
2211
|
+
const stroke = Math.max(2, Math.round(Math.min(width, height) / 100));
|
|
2212
|
+
const inset = stroke / 2;
|
|
2213
|
+
const centreX = cell.origin.x + width / 2;
|
|
2214
|
+
const centreY = cell.origin.y + height / 2;
|
|
2215
|
+
const clipId = `seed-cell-${String(index)}`;
|
|
2216
|
+
parts.push(`<clipPath id="${clipId}"><rect x="${String(cell.origin.x)}" y="${String(cell.origin.y)}" width="${String(width)}" height="${String(height)}"/></clipPath>`, `<rect x="${String(cell.origin.x + inset)}" y="${String(cell.origin.y + inset)}" width="${String(width - stroke)}" height="${String(height - stroke)}" fill="${CARD_FILL}" stroke="${CARD_BORDER}" stroke-width="${String(stroke)}"/>`, `<g clip-path="url(#${clipId})" font-family="${SEED_FONT_STACK}" text-anchor="middle">`, `<text x="${String(centreX)}" y="${String(Math.round(centreY))}" font-size="${String(nameSize)}" fill="${CARD_NAME}">${escapeSeedText(cell.name)}</text>`, `<text x="${String(centreX)}" y="${String(Math.round(centreY + nameSize * 1.15))}" font-size="${String(stateSize)}" fill="${CARD_STATE}">${GRID_SEED_WAITING_LABEL}</text>`, `</g>`);
|
|
2217
|
+
}
|
|
2218
|
+
parts.push("</svg>");
|
|
2219
|
+
return parts.join("");
|
|
2220
|
+
}
|
|
2221
|
+
/** Limited-range BT.601, which is what a raw yuv420p stream handed to x264 is read as. */
|
|
2222
|
+
var Y_OFFSET = 16;
|
|
2223
|
+
var CHROMA_OFFSET = 128;
|
|
2224
|
+
function clampByte(value) {
|
|
2225
|
+
return Math.min(255, Math.max(0, Math.round(value)));
|
|
2226
|
+
}
|
|
2227
|
+
function luma(r, g, b) {
|
|
2228
|
+
return Y_OFFSET + (65.481 * r + 128.553 * g + 24.966 * b) / 255;
|
|
2229
|
+
}
|
|
2230
|
+
function chromaU(r, g, b) {
|
|
2231
|
+
return CHROMA_OFFSET + (-37.797 * r - 74.203 * g + 112 * b) / 255;
|
|
2232
|
+
}
|
|
2233
|
+
function chromaV(r, g, b) {
|
|
2234
|
+
return CHROMA_OFFSET + (112 * r - 93.786 * g - 18.214 * b) / 255;
|
|
2235
|
+
}
|
|
2236
|
+
/**
|
|
2237
|
+
* Packed RGB → yuv420p, once.
|
|
2238
|
+
*
|
|
2239
|
+
* Chroma is the average of each 2×2 block's colour, converted once per block —
|
|
2240
|
+
* which is what 4:2:0 means, and what keeps a card's border from fringing.
|
|
2241
|
+
* Sizes must be even; the canvas refuses anything else, so a caller that got
|
|
2242
|
+
* here with an odd size has a bug the blit would hide.
|
|
2243
|
+
*/
|
|
2244
|
+
function rgbToYuv420p(rgb, size) {
|
|
2245
|
+
const { width, height } = size;
|
|
2246
|
+
const out = Buffer.alloc(yuv420pSize(width, height));
|
|
2247
|
+
const lumaBytes = width * height;
|
|
2248
|
+
const chromaBytes = width / 2 * (height / 2);
|
|
2249
|
+
for (let y = 0; y < height; y += 1) for (let x = 0; x < width; x += 1) {
|
|
2250
|
+
const at = (y * width + x) * 3;
|
|
2251
|
+
out[y * width + x] = clampByte(luma(rgb[at] ?? 0, rgb[at + 1] ?? 0, rgb[at + 2] ?? 0));
|
|
2252
|
+
}
|
|
2253
|
+
const halfW = width / 2;
|
|
2254
|
+
for (let y = 0; y < height / 2; y += 1) for (let x = 0; x < halfW; x += 1) {
|
|
2255
|
+
let r = 0;
|
|
2256
|
+
let g = 0;
|
|
2257
|
+
let b = 0;
|
|
2258
|
+
for (let dy = 0; dy < 2; dy += 1) for (let dx = 0; dx < 2; dx += 1) {
|
|
2259
|
+
const at = ((y * 2 + dy) * width + (x * 2 + dx)) * 3;
|
|
2260
|
+
r += rgb[at] ?? 0;
|
|
2261
|
+
g += rgb[at + 1] ?? 0;
|
|
2262
|
+
b += rgb[at + 2] ?? 0;
|
|
2263
|
+
}
|
|
2264
|
+
const at = y * halfW + x;
|
|
2265
|
+
out[lumaBytes + at] = clampByte(chromaU(r / 4, g / 4, b / 4));
|
|
2266
|
+
out[lumaBytes + chromaBytes + at] = clampByte(chromaV(r / 4, g / 4, b / 4));
|
|
2267
|
+
}
|
|
2268
|
+
return out;
|
|
2269
|
+
}
|
|
2270
|
+
/**
|
|
2271
|
+
* Render the seed as one yuv420p frame the canvas can take whole.
|
|
2272
|
+
*
|
|
2273
|
+
* Rejects on failure rather than answering black: the caller decides, and it
|
|
2274
|
+
* decides to carry on without a seed — a grid that would not start because its
|
|
2275
|
+
* placeholder would not draw is a worse grid than one that starts black.
|
|
2276
|
+
*/
|
|
2277
|
+
async function renderGridSeed(spec) {
|
|
2278
|
+
const { default: sharp } = await import("sharp");
|
|
2279
|
+
const rgb = await sharp(Buffer.from(buildGridSeedSvg(spec))).flatten({ background: {
|
|
2280
|
+
r: 0,
|
|
2281
|
+
g: 0,
|
|
2282
|
+
b: 0
|
|
2283
|
+
} }).raw().toBuffer();
|
|
2284
|
+
const expected = spec.canvas.width * spec.canvas.height * 3;
|
|
2285
|
+
if (rgb.length !== expected) throw new Error(`camera-grid: the seed rasterized to ${String(rgb.length)} bytes, expected ${String(expected)}`);
|
|
2286
|
+
return rgbToYuv420p(rgb, spec.canvas);
|
|
2287
|
+
}
|
|
2288
|
+
//#endregion
|
|
2289
|
+
//#region src/builtins/camera-grid/grid-tile-feed.ts
|
|
2290
|
+
/**
|
|
2291
|
+
* One source's decoded tiles, of which only the LATEST is ever wanted.
|
|
2292
|
+
*
|
|
2293
|
+
* ## Why dropping is the point, not a compromise
|
|
2294
|
+
*
|
|
2295
|
+
* ffmpeg's `overlay` consumes one frame per input per output frame, so an input
|
|
2296
|
+
* that got ahead of another stays ahead for the life of the child — that is the
|
|
2297
|
+
* tile gap. A canvas asks a different question: "what does this camera look
|
|
2298
|
+
* like NOW". Everything behind the newest frame is not a backlog to work
|
|
2299
|
+
* through, it is history, and dropping it is what keeps every tile at the same
|
|
2300
|
+
* moment however unevenly their frames arrive.
|
|
2301
|
+
*
|
|
2302
|
+
* It is also the only bound on memory here. A decoder child that outruns the
|
|
2303
|
+
* output tick — or a tick that stalls — would otherwise grow an unbounded queue
|
|
2304
|
+
* of raw frames, and a raw frame is 345 KB at 640x360.
|
|
2305
|
+
*
|
|
2306
|
+
* ## The last frame is HELD
|
|
2307
|
+
*
|
|
2308
|
+
* A tick that finds nothing new redraws what was there. A tile must not blink
|
|
2309
|
+
* because a source was 40 ms late, and a source that has genuinely stopped is a
|
|
2310
|
+
* still picture — which is legible, and which the snapshot path already treats
|
|
2311
|
+
* as the honest answer for a camera that is not sending.
|
|
2312
|
+
*/
|
|
2313
|
+
var GridTileFeed = class {
|
|
2314
|
+
frameBytes;
|
|
2315
|
+
partial = Buffer.alloc(0);
|
|
2316
|
+
newest = null;
|
|
2317
|
+
fresh = false;
|
|
2318
|
+
constructor(frameBytes) {
|
|
2319
|
+
this.frameBytes = frameBytes;
|
|
2320
|
+
}
|
|
2321
|
+
/** Feed bytes from the decoder. Any whole frames inside replace the newest. */
|
|
2322
|
+
push(chunk) {
|
|
2323
|
+
let buf = this.partial.length === 0 ? chunk : Buffer.concat([this.partial, chunk]);
|
|
2324
|
+
while (buf.length >= this.frameBytes) {
|
|
2325
|
+
this.newest = Buffer.from(buf.subarray(0, this.frameBytes));
|
|
2326
|
+
this.fresh = true;
|
|
2327
|
+
buf = buf.subarray(this.frameBytes);
|
|
2328
|
+
}
|
|
2329
|
+
this.partial = buf.length === 0 ? Buffer.alloc(0) : Buffer.from(buf);
|
|
2330
|
+
}
|
|
2331
|
+
/** The newest whole frame, or `null` while none has arrived. */
|
|
2332
|
+
latest() {
|
|
2333
|
+
this.fresh = false;
|
|
2334
|
+
return this.newest;
|
|
2335
|
+
}
|
|
2336
|
+
/** Has a new frame arrived since the last {@link latest}? */
|
|
2337
|
+
hasFresh() {
|
|
2338
|
+
return this.fresh;
|
|
2339
|
+
}
|
|
2340
|
+
/**
|
|
2341
|
+
* Forget the half frame, keep the picture.
|
|
2342
|
+
*
|
|
2343
|
+
* Raw video has no framing: the feed cuts on a fixed length, so bytes from a
|
|
2344
|
+
* NEW decoder concatenated onto a partial frame from the old one would be
|
|
2345
|
+
* misaligned for ever — every frame after it sheared, with nothing to
|
|
2346
|
+
* re-sync on. Called whenever a tile's decoder is replaced.
|
|
2347
|
+
*
|
|
2348
|
+
* The newest frame is kept deliberately: the cell holds its last picture
|
|
2349
|
+
* while its decoder comes back, instead of blinking to black.
|
|
2350
|
+
*/
|
|
2351
|
+
resetPartial() {
|
|
2352
|
+
this.partial = Buffer.alloc(0);
|
|
2353
|
+
}
|
|
2354
|
+
/** For the bound in the spec: one frame plus at most a partial one. */
|
|
2355
|
+
bufferedBytes() {
|
|
2356
|
+
return (this.newest?.length ?? 0) + this.partial.length;
|
|
2357
|
+
}
|
|
2358
|
+
};
|
|
2359
|
+
//#endregion
|
|
2360
|
+
//#region src/builtins/camera-grid/grid-compositor.ts
|
|
2361
|
+
/**
|
|
2362
|
+
* The composition, driven by the OUTPUT's clock.
|
|
2363
|
+
*
|
|
2364
|
+
* ## What this replaces, and why it is the only thing that works
|
|
2365
|
+
*
|
|
2366
|
+
* `overlay` pairs its inputs BY PTS and ffmpeg gives each input pts 0 at its
|
|
2367
|
+
* own first frame, so two sources that joined at different moments compose
|
|
2368
|
+
* different moments for the life of the child. Measured at 4-5 s on this hub,
|
|
2369
|
+
* drifting over hours as the sources' key-frame phases slide through each other.
|
|
2370
|
+
* Every cheaper fix was tried and measured: `-use_wallclock_as_timestamps`
|
|
2371
|
+
* re-times by arrival and wrecked the pacing; `-copyts` changes nothing because
|
|
2372
|
+
* the broker re-bases each session (both restreams report `pts_time:0`), so
|
|
2373
|
+
* there is no shared timeline to align against; and serving each dial from the
|
|
2374
|
+
* newest key frame it already holds only moves the offsets into the past,
|
|
2375
|
+
* because those key frames are of different ages.
|
|
2376
|
+
*
|
|
2377
|
+
* Here there is nothing to pair. Every tick asks each source "what do you look
|
|
2378
|
+
* like NOW" and the answer is whatever arrived last. The gap is zero by
|
|
2379
|
+
* construction rather than by tuning.
|
|
2380
|
+
*
|
|
2381
|
+
* ## It also removes the wait
|
|
2382
|
+
*
|
|
2383
|
+
* A cell with no frame yet is not a reason to hold the picture back. The output
|
|
2384
|
+
* exists from the first tick and cells fill in as their sources arrive —
|
|
2385
|
+
* instead of the whole grid waiting for the slowest source's first key frame,
|
|
2386
|
+
* which is what the ~9 s cold start was.
|
|
2387
|
+
*
|
|
2388
|
+
* What a cell with no frame yet SHOWS is the seed (`grid-canvas-seed.ts`),
|
|
2389
|
+
* blitted in once at construction: its own rectangle, with its camera's name
|
|
2390
|
+
* and the word `Waiting`. It was black, and black said the same thing about an
|
|
2391
|
+
* empty grid, a broken grid and a grid that is merely still opening.
|
|
2392
|
+
*
|
|
2393
|
+
* ## What it costs
|
|
2394
|
+
*
|
|
2395
|
+
* The same N decodes ffmpeg already paid, in N children instead of one, plus
|
|
2396
|
+
* one strided memcpy per tile per tick (`grid-canvas.ts`). It does NOT reuse the
|
|
2397
|
+
* frames the detection pipeline decodes: those live in per-session decode
|
|
2398
|
+
* workers behind two process boundaries, the shm plane that once joined them was
|
|
2399
|
+
* removed on 2026-07-16, and what the pipeline retains is a model-sized view
|
|
2400
|
+
* (320x180 JPEG, on demand), not a tile.
|
|
2401
|
+
*/
|
|
2402
|
+
var GridCompositor = class {
|
|
2403
|
+
deps;
|
|
2404
|
+
canvas;
|
|
2405
|
+
/** Keyed by tile id — unique per CELL, because one camera can hold two. */
|
|
2406
|
+
placed = /* @__PURE__ */ new Map();
|
|
2407
|
+
closed = false;
|
|
2408
|
+
constructor(deps) {
|
|
2409
|
+
this.deps = deps;
|
|
2410
|
+
this.canvas = new GridCanvas(deps.plan.canvas.width, deps.plan.canvas.height);
|
|
2411
|
+
if (deps.seed !== null) this.canvas.blit(deps.seed, deps.plan.canvas, {
|
|
2412
|
+
x: 0,
|
|
2413
|
+
y: 0
|
|
2414
|
+
});
|
|
2415
|
+
for (const tile of deps.plan.tiles) this.placed.set(tile.id, {
|
|
2416
|
+
tile,
|
|
2417
|
+
feed: new GridTileFeed(tile.frameBytes)
|
|
2418
|
+
});
|
|
2419
|
+
}
|
|
2420
|
+
/**
|
|
2421
|
+
* Raw bytes from one decoder output.
|
|
2422
|
+
*
|
|
2423
|
+
* A tile this composition has no rectangle for is IGNORED, never thrown on: a
|
|
2424
|
+
* child that outlives a layout change would otherwise take the tick down with
|
|
2425
|
+
* it, and the tick is what every other cell depends on.
|
|
2426
|
+
*/
|
|
2427
|
+
onTile(tileId, chunk) {
|
|
2428
|
+
this.placed.get(tileId)?.feed.push(chunk);
|
|
2429
|
+
}
|
|
2430
|
+
/**
|
|
2431
|
+
* Compose and emit one frame. Returns what the sink said about back-pressure.
|
|
2432
|
+
*
|
|
2433
|
+
* Every tile is redrawn, fresh or not: a tile that produced nothing this tick
|
|
2434
|
+
* is a still picture, not a hole, and clearing it would make a late source
|
|
2435
|
+
* flicker. The canvas is never cleared between ticks for the same reason.
|
|
2436
|
+
*/
|
|
2437
|
+
tick() {
|
|
2438
|
+
if (this.closed) return true;
|
|
2439
|
+
for (const { tile, feed } of this.placed.values()) {
|
|
2440
|
+
const frame = feed.latest();
|
|
2441
|
+
if (frame === null) continue;
|
|
2442
|
+
this.canvas.blit(frame, tile.size, tile.origin);
|
|
2443
|
+
}
|
|
2444
|
+
return this.deps.write(this.canvas.buffer);
|
|
2445
|
+
}
|
|
2446
|
+
/**
|
|
2447
|
+
* A tile's decoder was replaced: drop its half frame, keep its picture.
|
|
2448
|
+
*
|
|
2449
|
+
* Without this the new decoder's bytes would be appended to the old one's
|
|
2450
|
+
* partial frame and every frame after would be sheared — raw video has no
|
|
2451
|
+
* framing to re-sync on.
|
|
2452
|
+
*/
|
|
2453
|
+
resetTile(tileId) {
|
|
2454
|
+
this.placed.get(tileId)?.feed.resetPartial();
|
|
2455
|
+
}
|
|
2456
|
+
/** After this, a tick emits nothing — a dead child must not keep writing. */
|
|
2457
|
+
close() {
|
|
2458
|
+
this.closed = true;
|
|
2459
|
+
}
|
|
2460
|
+
};
|
|
2461
|
+
//#endregion
|
|
2462
|
+
//#region src/builtins/camera-grid/grid-tile-plan.ts
|
|
2463
|
+
/**
|
|
2464
|
+
* The operator's layout, as one decoder child per CELL.
|
|
2465
|
+
*
|
|
2466
|
+
* ## Why per cell, when `grid-plan.ts` dedupes per source
|
|
2467
|
+
*
|
|
2468
|
+
* The single ffmpeg that this replaces made a camera used by two cells ONE
|
|
2469
|
+
* input, because decoding it twice doubles the expensive half of the job. A
|
|
2470
|
+
* compositor cannot do that with the same shape: this repo has exactly one
|
|
2471
|
+
* ffmpeg argv builder (`scripts/check-ffmpeg-primitive.ts`, Rule 1) and it
|
|
2472
|
+
* expresses one output per process, so a source feeding two differently cropped
|
|
2473
|
+
* and differently scaled tiles needs two children.
|
|
2474
|
+
*
|
|
2475
|
+
* The trade is small and worth stating: since D528 every source is read at its
|
|
2476
|
+
* CHEAPEST stream, so the duplicate is a second 640x360 sub-stream decode, not a
|
|
2477
|
+
* second 4 MP one. Teaching the builder several outputs would buy that back, and
|
|
2478
|
+
* is the right change to make if a grid ever shows one camera many times — it is
|
|
2479
|
+
* deliberately not made for a case that costs this little.
|
|
2480
|
+
*
|
|
2481
|
+
* ## Why the tile is scaled in the DECODER
|
|
2482
|
+
*
|
|
2483
|
+
* ffmpeg's scaler is SIMD and already there. Scaling in this process would be a
|
|
2484
|
+
* per-pixel loop in JavaScript, on the event loop that also answers the grid's
|
|
2485
|
+
* RPCs. Handing each child the exact pixel size its rectangle needs makes the
|
|
2486
|
+
* composition a strided memcpy (`grid-canvas.ts`) and keeps the only per-pixel
|
|
2487
|
+
* work where it belongs.
|
|
2488
|
+
*
|
|
2489
|
+
* ## Even, and snapped DOWN
|
|
2490
|
+
*
|
|
2491
|
+
* yuv420p subsamples chroma 2x2, so an odd origin lands a tile's chroma half a
|
|
2492
|
+
* sample off its luma — which TINTS the tile instead of breaking it, and
|
|
2493
|
+
* survives review. Sizes round DOWN so a tile never claims a row the decoder
|
|
2494
|
+
* was not asked to produce; a cell that rounds away to nothing is dropped
|
|
2495
|
+
* rather than emitted at zero size, because a zero-size output is an ffmpeg
|
|
2496
|
+
* start-up failure that would take the whole grid with it.
|
|
2497
|
+
*/
|
|
2498
|
+
/** Smallest tile worth decoding. Below this it is not a cheaper picture, it is none. */
|
|
2499
|
+
var MIN_TILE_PX = 2;
|
|
2500
|
+
/** The one pixel format the canvas is in, so a blit is a copy and not a convert. */
|
|
2501
|
+
var TILE_PIXEL_FORMAT = "yuv420p";
|
|
2502
|
+
var FULL_FRAME_EPSILON$1 = 1e-6;
|
|
2503
|
+
function isFullFrame$1(rect) {
|
|
2504
|
+
return Math.abs(rect.x) < FULL_FRAME_EPSILON$1 && Math.abs(rect.y) < FULL_FRAME_EPSILON$1 && Math.abs(rect.width - 1) < FULL_FRAME_EPSILON$1 && Math.abs(rect.height - 1) < FULL_FRAME_EPSILON$1;
|
|
2505
|
+
}
|
|
2506
|
+
/**
|
|
2507
|
+
* `crop` resolved against the source's OWN size at runtime (`iw`/`ih`), never
|
|
2508
|
+
* against a resolution guessed here — which is what lets a stored rectangle
|
|
2509
|
+
* survive a camera that changes resolution under us.
|
|
2510
|
+
*/
|
|
2511
|
+
function cropExpression$1(source) {
|
|
2512
|
+
return `crop=iw*${source.width}:ih*${source.height}:iw*${source.x}:ih*${source.y}`;
|
|
2513
|
+
}
|
|
2514
|
+
function buildGridTilePlan(input) {
|
|
2515
|
+
const tiles = [];
|
|
2516
|
+
for (const [index, cell] of input.cells.entries()) {
|
|
2517
|
+
const width = evenDown(cell.cell.width * input.canvas.width);
|
|
2518
|
+
const height = evenDown(cell.cell.height * input.canvas.height);
|
|
2519
|
+
if (width < MIN_TILE_PX || height < MIN_TILE_PX) continue;
|
|
2520
|
+
const x = Math.min(evenDown(cell.cell.x * input.canvas.width), evenDown(input.canvas.width - width));
|
|
2521
|
+
const y = Math.min(evenDown(cell.cell.y * input.canvas.height), evenDown(input.canvas.height - height));
|
|
2522
|
+
tiles.push({
|
|
2523
|
+
id: `cell-${String(index)}`,
|
|
2524
|
+
deviceId: cell.deviceId,
|
|
2525
|
+
size: {
|
|
2526
|
+
width,
|
|
2527
|
+
height
|
|
2528
|
+
},
|
|
2529
|
+
origin: {
|
|
2530
|
+
x,
|
|
2531
|
+
y
|
|
2532
|
+
},
|
|
2533
|
+
frameBytes: yuv420pSize(width, height),
|
|
2534
|
+
filter: [
|
|
2535
|
+
...isFullFrame$1(cell.source) ? [] : [cropExpression$1(cell.source)],
|
|
2536
|
+
`scale=${String(width)}:${String(height)}`,
|
|
2537
|
+
`format=${TILE_PIXEL_FORMAT}`
|
|
2538
|
+
].join(",")
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2541
|
+
return {
|
|
2542
|
+
canvas: input.canvas,
|
|
2543
|
+
tiles
|
|
2544
|
+
};
|
|
2545
|
+
}
|
|
2546
|
+
//#endregion
|
|
2547
|
+
//#region src/builtins/camera-grid/grid-compositor-invocation.ts
|
|
2548
|
+
/** See D527: the probe returns from the SDP instead of reading media. */
|
|
2549
|
+
var ANALYZE_DURATION_US$1 = 0;
|
|
2550
|
+
var PROBE_SIZE_BYTES$1 = 32;
|
|
2551
|
+
/**
|
|
2552
|
+
* Threads per child, and why they are BOUNDED rather than automatic.
|
|
2553
|
+
*
|
|
2554
|
+
* ffmpeg's default is one thread per core, applied to decode, the filter graph
|
|
2555
|
+
* and the output — and it applies it per CHILD. A compositor has N+1 of them,
|
|
2556
|
+
* so on the hub's 20-core CPU two tiles reading 640x360 sub-streams were
|
|
2557
|
+
* measured holding 71 and 56 threads (2026-09-18). That is not a CPU problem:
|
|
2558
|
+
* the container's pid cgroup counts THREADS, its ceiling is 2048, and it was
|
|
2559
|
+
* sitting at 1858. Every new `pthread_create` then fails with EAGAIN, which
|
|
2560
|
+
* ffmpeg reports as `ff_frame_thread_encoder_init failed` — the grid stopped
|
|
2561
|
+
* working, and nothing about the message says "out of pids".
|
|
2562
|
+
*
|
|
2563
|
+
* A tile decodes one small stream and scales it once; one thread does that at a
|
|
2564
|
+
* few percent of a core (measured: 2.2-2.4%). The encoder gets a few more
|
|
2565
|
+
* because it is the only piece whose work scales with the canvas.
|
|
2566
|
+
*
|
|
2567
|
+
* The DECODER needs its own number. `threadCount` lands after the video args,
|
|
2568
|
+
* so it bounds the encoder only — a tile set to `threadCount: 1` still carried
|
|
2569
|
+
* `min(cores, 16)` decoder frame threads plus a filter pool, and measured 72.
|
|
2570
|
+
* With all three set it measures 26.
|
|
2571
|
+
*/
|
|
2572
|
+
var TILE_THREADS = 1;
|
|
2573
|
+
/** libavfilter's own slice pool, which neither of the other two touches. */
|
|
2574
|
+
var FILTER_THREADS = 1;
|
|
2575
|
+
var ENCODER_THREADS = 4;
|
|
2576
|
+
var PRESET$1 = "veryfast";
|
|
2577
|
+
var TUNE$1 = "zerolatency";
|
|
2578
|
+
var GOP_SECONDS$1 = 1;
|
|
2579
|
+
/** One tile's decoder: dial in, raw yuv420p frames out. */
|
|
2580
|
+
function gridTileDecoderInvocation(input) {
|
|
2581
|
+
return {
|
|
2582
|
+
logLevel: "error",
|
|
2583
|
+
decodeHwAccel: null,
|
|
2584
|
+
input: {
|
|
2585
|
+
url: input.url,
|
|
2586
|
+
rtspTransport: "tcp",
|
|
2587
|
+
fflags: ["+discardcorrupt"],
|
|
2588
|
+
lowDelay: true,
|
|
2589
|
+
analyzeDurationUs: ANALYZE_DURATION_US$1,
|
|
2590
|
+
probeSizeBytes: PROBE_SIZE_BYTES$1,
|
|
2591
|
+
decodeThreadCount: TILE_THREADS
|
|
2592
|
+
},
|
|
2593
|
+
video: {
|
|
2594
|
+
kind: "raw",
|
|
2595
|
+
pixelFormat: TILE_PIXEL_FORMAT,
|
|
2596
|
+
filter: input.tile.filter,
|
|
2597
|
+
fps: input.fps
|
|
2598
|
+
},
|
|
2599
|
+
audio: { kind: "none" },
|
|
2600
|
+
threadCount: TILE_THREADS,
|
|
2601
|
+
filterThreadCount: FILTER_THREADS,
|
|
2602
|
+
outputArgs: [],
|
|
2603
|
+
sink: {
|
|
2604
|
+
kind: "stdout",
|
|
2605
|
+
container: "rawvideo"
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
}
|
|
2609
|
+
/** The canvas encoder: raw frames on stdin, one compressed stream out. */
|
|
2610
|
+
function gridCanvasEncoderInvocation(input) {
|
|
2611
|
+
const video = {
|
|
2612
|
+
kind: "encode",
|
|
2613
|
+
encoder: input.encoder,
|
|
2614
|
+
preset: PRESET$1,
|
|
2615
|
+
tune: TUNE$1,
|
|
2616
|
+
pixelFormat: TILE_PIXEL_FORMAT,
|
|
2617
|
+
fps: input.fps,
|
|
2618
|
+
gopFrames: input.fps * GOP_SECONDS$1,
|
|
2619
|
+
bitrateKbps: input.bitrateKbps,
|
|
2620
|
+
scale: null
|
|
2621
|
+
};
|
|
2622
|
+
return {
|
|
2623
|
+
logLevel: "error",
|
|
2624
|
+
decodeHwAccel: null,
|
|
2625
|
+
input: {
|
|
2626
|
+
url: "pipe:0",
|
|
2627
|
+
rawVideo: {
|
|
2628
|
+
pixelFormat: TILE_PIXEL_FORMAT,
|
|
2629
|
+
width: input.canvas.width,
|
|
2630
|
+
height: input.canvas.height,
|
|
2631
|
+
framerate: input.fps
|
|
2632
|
+
}
|
|
2633
|
+
},
|
|
2634
|
+
video,
|
|
2635
|
+
audio: { kind: "none" },
|
|
2636
|
+
threadCount: ENCODER_THREADS,
|
|
2637
|
+
filterThreadCount: FILTER_THREADS,
|
|
2638
|
+
outputArgs: [],
|
|
2639
|
+
sink: {
|
|
2640
|
+
kind: "stdout",
|
|
2641
|
+
container: "flv"
|
|
2642
|
+
}
|
|
2643
|
+
};
|
|
2644
|
+
}
|
|
2645
|
+
//#endregion
|
|
2646
|
+
//#region src/builtins/camera-grid/grid-compositor-child.ts
|
|
2647
|
+
/**
|
|
2648
|
+
* The composition as processes: one decoder per tile, one encoder, one tick.
|
|
2649
|
+
*
|
|
2650
|
+
* It presents the SAME shape the single ffmpeg did — `{ stdout, stop }` — so
|
|
2651
|
+
* `GridStreamSession` is untouched. The seam is deliberate: the session owns
|
|
2652
|
+
* demand, acquisition and teardown, and none of that changes because the
|
|
2653
|
+
* picture is assembled differently.
|
|
2654
|
+
*
|
|
2655
|
+
* ## The order things start in, and why it is the order
|
|
2656
|
+
*
|
|
2657
|
+
* The seed first, then the encoder, then the tick, then the decoders. The tick
|
|
2658
|
+
* writes the canvas from its very first beat, so the encoder produces a stream
|
|
2659
|
+
* — and the consumer sees a picture — before any camera has delivered anything.
|
|
2660
|
+
* That is the cold start the old shape spent waiting for the slowest source's
|
|
2661
|
+
* first key frame, and it is now spent watching cells fill in.
|
|
2662
|
+
*
|
|
2663
|
+
* What that first picture SAYS is the seed (`grid-canvas-seed.ts`): one card
|
|
2664
|
+
* per cell, at the cell's own rectangle, naming its camera. It is drawn once,
|
|
2665
|
+
* here, before the compositor is built — a tick must never wait on a render —
|
|
2666
|
+
* and it is bounded and fallible: a seed that cannot be drawn leaves the canvas
|
|
2667
|
+
* black, which is what it was before, and never stops the composition.
|
|
2668
|
+
*
|
|
2669
|
+
* ## Back-pressure is a SKIPPED tick, never a queue
|
|
2670
|
+
*
|
|
2671
|
+
* A raw canvas frame is 3.1 MB at 1080p. If the encoder stops draining, the one
|
|
2672
|
+
* safe thing is to stop composing until it drains again: a queue of raw frames
|
|
2673
|
+
* is how a stalled encoder becomes an OOM, and a dropped frame in a live
|
|
2674
|
+
* composite costs nothing anybody can see.
|
|
2675
|
+
*
|
|
2676
|
+
* ## A tile comes back; only the ENCODER ends the composition
|
|
2677
|
+
*
|
|
2678
|
+
* Every child exiting used to end it, on the reasoning that a frozen tile is a
|
|
2679
|
+
* nicer picture and a worse fact. In practice it produced neither: a 4K source
|
|
2680
|
+
* ended mid-run (`code=0` — the input simply finished), the composition tore
|
|
2681
|
+
* down, the consumer re-dialled, and the grid served nothing but restarts. That
|
|
2682
|
+
* is what the operator saw as the `auto` rung being stuck.
|
|
2683
|
+
*
|
|
2684
|
+
* A canvas makes the better answer cheap: while a decoder comes back, its cell
|
|
2685
|
+
* holds the last frame it produced and every other cell carries on. The bound
|
|
2686
|
+
* (`TILE_MAX_RESTARTS`) keeps a source that is genuinely gone from respawning
|
|
2687
|
+
* for ever — and when it is reached, the composition does end, with the tile
|
|
2688
|
+
* named.
|
|
2689
|
+
*
|
|
2690
|
+
* The encoder is different: nothing downstream of it exists without it, so its
|
|
2691
|
+
* exit is the composition's exit, first time.
|
|
2692
|
+
*/
|
|
2693
|
+
/**
|
|
2694
|
+
* The encoder must produce its first bytes quickly, because the tick feeds it a
|
|
2695
|
+
* black canvas immediately — a silence here is the encoder failing to start,
|
|
2696
|
+
* not a camera being slow.
|
|
2697
|
+
*/
|
|
2698
|
+
var ENCODER_FIRST_DATA_MS = 5e3;
|
|
2699
|
+
/**
|
|
2700
|
+
* A decoder's first frame waits for its source's next key frame, which on this
|
|
2701
|
+
* fleet is up to a GOP. Generous, and it costs only that tile: the picture is
|
|
2702
|
+
* already on screen.
|
|
2703
|
+
*/
|
|
2704
|
+
var DECODER_FIRST_DATA_MS = 15e3;
|
|
2705
|
+
/**
|
|
2706
|
+
* How many times a tile's decoder may come back before the composition gives up
|
|
2707
|
+
* on it.
|
|
2708
|
+
*
|
|
2709
|
+
* The bound exists so a source that is genuinely gone still ends the
|
|
2710
|
+
* composition rather than respawning for ever; below it, a decoder that dies is
|
|
2711
|
+
* simply replaced while its cell holds the last frame it produced.
|
|
2712
|
+
*/
|
|
2713
|
+
var TILE_MAX_RESTARTS = 5;
|
|
2714
|
+
/**
|
|
2715
|
+
* How long the seed may wait for the source cameras' names.
|
|
2716
|
+
*
|
|
2717
|
+
* The seed is drawn BEFORE the encoder is spawned — that is what puts it on the
|
|
2718
|
+
* first tick — so everything it waits for is added to the cold start the rest
|
|
2719
|
+
* of this file exists to keep short. A name is a nicety; the card exists
|
|
2720
|
+
* either way, labelled by device id. So the read is bounded and the deadline
|
|
2721
|
+
* is not an error.
|
|
2722
|
+
*/
|
|
2723
|
+
var SEED_NAMES_TIMEOUT_MS = 1500;
|
|
2724
|
+
/**
|
|
2725
|
+
* The names for the cards, or an empty map.
|
|
2726
|
+
*
|
|
2727
|
+
* Never throws and never delays past the deadline: an unnamed card is a
|
|
2728
|
+
* complete card (`gridSeedName` falls back to the device id), and a grid that
|
|
2729
|
+
* started late because a name lookup was slow would be a worse grid.
|
|
2730
|
+
*/
|
|
2731
|
+
async function resolveSeedNames(ctx, deviceIds) {
|
|
2732
|
+
const resolve = ctx.resolveSourceNames;
|
|
2733
|
+
if (resolve === void 0) return /* @__PURE__ */ new Map();
|
|
2734
|
+
const empty = /* @__PURE__ */ new Map();
|
|
2735
|
+
return new Promise((settle) => {
|
|
2736
|
+
const timer = setTimeout(() => {
|
|
2737
|
+
ctx.logger.warn("camera grid: the seed could not read the source names in time", {
|
|
2738
|
+
tags: { deviceId: ctx.deviceId },
|
|
2739
|
+
meta: {
|
|
2740
|
+
sources: deviceIds.length,
|
|
2741
|
+
timeoutMs: SEED_NAMES_TIMEOUT_MS
|
|
2742
|
+
}
|
|
2743
|
+
});
|
|
2744
|
+
settle(empty);
|
|
2745
|
+
}, SEED_NAMES_TIMEOUT_MS);
|
|
2746
|
+
timer.unref();
|
|
2747
|
+
resolve(deviceIds).then((names) => {
|
|
2748
|
+
clearTimeout(timer);
|
|
2749
|
+
settle(names);
|
|
2750
|
+
}, (error) => {
|
|
2751
|
+
clearTimeout(timer);
|
|
2752
|
+
ctx.logger.warn("camera grid: the seed could not read the source names", {
|
|
2753
|
+
tags: { deviceId: ctx.deviceId },
|
|
2754
|
+
meta: {
|
|
2755
|
+
sources: deviceIds.length,
|
|
2756
|
+
error: require_dist.errMsg(error)
|
|
2757
|
+
}
|
|
2758
|
+
});
|
|
2759
|
+
settle(empty);
|
|
2760
|
+
});
|
|
2761
|
+
});
|
|
2762
|
+
}
|
|
2763
|
+
/**
|
|
2764
|
+
* The picture the canvas starts as: one card per cell, naming its camera.
|
|
2765
|
+
*
|
|
2766
|
+
* `null` — black, which is what this was before — when it cannot be drawn. A
|
|
2767
|
+
* placeholder that refused to render must never be the reason a grid does not
|
|
2768
|
+
* start, so every failure here is a warning and a composition that carries on.
|
|
2769
|
+
*/
|
|
2770
|
+
async function buildCanvasSeed(ctx, tilePlan) {
|
|
2771
|
+
const names = await resolveSeedNames(ctx, [...new Set(tilePlan.tiles.map((tile) => tile.deviceId))]);
|
|
2772
|
+
try {
|
|
2773
|
+
return await renderGridSeed(buildGridSeedSpec(tilePlan, names));
|
|
2774
|
+
} catch (error) {
|
|
2775
|
+
ctx.logger.warn("camera grid: the canvas seed could not be drawn - starting black", {
|
|
2776
|
+
tags: { deviceId: ctx.deviceId },
|
|
2777
|
+
meta: {
|
|
2778
|
+
error: require_dist.errMsg(error),
|
|
2779
|
+
tiles: tilePlan.tiles.length
|
|
2780
|
+
}
|
|
2781
|
+
});
|
|
2782
|
+
return null;
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
async function startGridCompositorChild(ctx, plan, sources, onEnded) {
|
|
2786
|
+
const tilePlan = buildGridTilePlan({
|
|
2787
|
+
canvas: {
|
|
2788
|
+
width: plan.layout.width,
|
|
2789
|
+
height: plan.layout.height
|
|
2790
|
+
},
|
|
2791
|
+
cells: plan.layout.cells.map((cell) => ({
|
|
2792
|
+
deviceId: plan.sourceDeviceIds[cell.inputIndex] ?? 0,
|
|
2793
|
+
source: cell.source,
|
|
2794
|
+
cell: cell.cell
|
|
2795
|
+
}))
|
|
2796
|
+
});
|
|
2797
|
+
if (tilePlan.tiles.length === 0) throw new Error("camera-grid: every cell rounded away to nothing — there is no picture to make");
|
|
2798
|
+
let ended = false;
|
|
2799
|
+
const end = (reason) => {
|
|
2800
|
+
if (ended) return;
|
|
2801
|
+
ended = true;
|
|
2802
|
+
onEnded(reason);
|
|
2803
|
+
};
|
|
2804
|
+
const seed = await buildCanvasSeed(ctx, tilePlan);
|
|
2805
|
+
let encoderIn = null;
|
|
2806
|
+
let encoderOut = null;
|
|
2807
|
+
let draining = false;
|
|
2808
|
+
let tick = null;
|
|
2809
|
+
const compositor = new GridCompositor({
|
|
2810
|
+
plan: tilePlan,
|
|
2811
|
+
seed,
|
|
2812
|
+
write: (frame) => {
|
|
2813
|
+
const sink = encoderIn;
|
|
2814
|
+
if (sink === null || draining || sink.destroyed) return false;
|
|
2815
|
+
const accepted = sink.write(frame);
|
|
2816
|
+
if (!accepted) draining = true;
|
|
2817
|
+
return accepted;
|
|
2818
|
+
}
|
|
2819
|
+
});
|
|
2820
|
+
const startTick = () => {
|
|
2821
|
+
if (tick !== null) return;
|
|
2822
|
+
tick = setInterval(() => {
|
|
2823
|
+
compositor.tick();
|
|
2824
|
+
}, Math.max(1, Math.round(1e3 / plan.fps)));
|
|
2825
|
+
tick.unref();
|
|
2826
|
+
};
|
|
2827
|
+
const encoder = new _camstack_types_node.FfmpegProcess({
|
|
2828
|
+
binaryPath: ctx.binaryPath,
|
|
2829
|
+
buildArgs: () => require_dist.buildFfmpegArgs(gridCanvasEncoderInvocation({
|
|
2830
|
+
canvas: tilePlan.canvas,
|
|
2831
|
+
fps: plan.fps,
|
|
2832
|
+
encoder: plan.encoder,
|
|
2833
|
+
bitrateKbps: plan.bitrateKbps
|
|
2834
|
+
})),
|
|
2835
|
+
decodeHwAccel: null,
|
|
2836
|
+
logger: ctx.logger.child("encode"),
|
|
2837
|
+
deviceId: ctx.deviceId,
|
|
2838
|
+
role: "camera-grid-encode",
|
|
2839
|
+
tags: { tiles: tilePlan.tiles.length },
|
|
2840
|
+
firstDataTimeoutMs: ENCODER_FIRST_DATA_MS,
|
|
2841
|
+
maxRestarts: 0,
|
|
2842
|
+
stdio: [
|
|
2843
|
+
"pipe",
|
|
2844
|
+
"pipe",
|
|
2845
|
+
"pipe"
|
|
2846
|
+
],
|
|
2847
|
+
onChild: (child) => {
|
|
2848
|
+
encoderIn = child.stdin;
|
|
2849
|
+
if (child.stdout) encoderOut = child.stdout;
|
|
2850
|
+
child.stdin?.on("drain", () => {
|
|
2851
|
+
draining = false;
|
|
2852
|
+
});
|
|
2853
|
+
startTick();
|
|
2854
|
+
child.stderr?.on("data", () => {});
|
|
2855
|
+
child.stdin?.on("error", () => {});
|
|
2856
|
+
},
|
|
2857
|
+
onExit: (exit) => end(`encoder:${exit.classification}`)
|
|
2858
|
+
});
|
|
2859
|
+
try {
|
|
2860
|
+
await encoder.start();
|
|
2861
|
+
} catch (error) {
|
|
2862
|
+
if (tick !== null) clearInterval(tick);
|
|
2863
|
+
compositor.close();
|
|
2864
|
+
throw error;
|
|
2865
|
+
}
|
|
2866
|
+
if (encoderIn === null || encoderOut === null) {
|
|
2867
|
+
await encoder.stop();
|
|
2868
|
+
throw new Error("camera-grid: the canvas encoder exposed no stdin/stdout to compose into");
|
|
2869
|
+
}
|
|
2870
|
+
const urlByDeviceId = /* @__PURE__ */ new Map();
|
|
2871
|
+
for (const [index, deviceId] of plan.sourceDeviceIds.entries()) {
|
|
2872
|
+
const url = sources[index]?.url;
|
|
2873
|
+
if (url !== void 0) urlByDeviceId.set(deviceId, url);
|
|
2874
|
+
}
|
|
2875
|
+
const decoders = [];
|
|
2876
|
+
const startDecoder = async (tile) => {
|
|
2877
|
+
const url = urlByDeviceId.get(tile.deviceId);
|
|
2878
|
+
if (url === void 0) throw new Error(`camera-grid: no acquired source for device ${String(tile.deviceId)}`);
|
|
2879
|
+
const decoder = new _camstack_types_node.FfmpegProcess({
|
|
2880
|
+
binaryPath: ctx.binaryPath,
|
|
2881
|
+
buildArgs: () => require_dist.buildFfmpegArgs(gridTileDecoderInvocation({
|
|
2882
|
+
tile,
|
|
2883
|
+
url,
|
|
2884
|
+
fps: plan.fps
|
|
2885
|
+
})),
|
|
2886
|
+
decodeHwAccel: null,
|
|
2887
|
+
logger: ctx.logger.child("tile"),
|
|
2888
|
+
deviceId: tile.deviceId,
|
|
2889
|
+
role: "camera-grid-tile",
|
|
2890
|
+
tags: {
|
|
2891
|
+
tile: tile.id,
|
|
2892
|
+
width: tile.size.width,
|
|
2893
|
+
height: tile.size.height
|
|
2894
|
+
},
|
|
2895
|
+
firstDataTimeoutMs: DECODER_FIRST_DATA_MS,
|
|
2896
|
+
maxRestarts: TILE_MAX_RESTARTS,
|
|
2897
|
+
onChild: (child) => {
|
|
2898
|
+
child.stdout?.on("data", (chunk) => {
|
|
2899
|
+
compositor.onTile(tile.id, chunk);
|
|
2900
|
+
});
|
|
2901
|
+
child.stderr?.on("data", () => {});
|
|
2902
|
+
},
|
|
2903
|
+
onExit: () => {
|
|
2904
|
+
compositor.resetTile(tile.id);
|
|
2905
|
+
},
|
|
2906
|
+
onGiveUp: (error) => end(`tile ${tile.id}: ${error.message}`)
|
|
2907
|
+
});
|
|
2908
|
+
decoders.push(decoder);
|
|
2909
|
+
await decoder.start();
|
|
2910
|
+
};
|
|
2911
|
+
const stopAll = async () => {
|
|
2912
|
+
if (tick !== null) clearInterval(tick);
|
|
2913
|
+
compositor.close();
|
|
2914
|
+
await Promise.allSettled(decoders.map((d) => d.stop()));
|
|
2915
|
+
await encoder.stop();
|
|
2916
|
+
};
|
|
2917
|
+
try {
|
|
2918
|
+
for (const tile of tilePlan.tiles) await startDecoder(tile);
|
|
2919
|
+
} catch (error) {
|
|
2920
|
+
await stopAll();
|
|
2921
|
+
throw error;
|
|
2922
|
+
}
|
|
2923
|
+
ctx.logger.info("camera grid: composing on an output clock", {
|
|
2924
|
+
tags: { deviceId: ctx.deviceId },
|
|
2925
|
+
meta: {
|
|
2926
|
+
tiles: tilePlan.tiles.length,
|
|
2927
|
+
canvas: `${String(tilePlan.canvas.width)}x${String(tilePlan.canvas.height)}`,
|
|
2928
|
+
fps: plan.fps,
|
|
2929
|
+
seeded: seed !== null
|
|
2930
|
+
}
|
|
2931
|
+
});
|
|
2932
|
+
return {
|
|
2933
|
+
stdout: encoderOut,
|
|
2934
|
+
stop: stopAll
|
|
2935
|
+
};
|
|
2936
|
+
}
|
|
2937
|
+
//#endregion
|
|
2938
|
+
//#region src/builtins/camera-grid/addon.ts
|
|
2939
|
+
var INTEGRATION_NAME = "Camera Grids";
|
|
2940
|
+
var RECONCILE_MS = 6e4;
|
|
2941
|
+
/**
|
|
2942
|
+
* How long a source acquire may keep asking while a provider is still coming up.
|
|
2943
|
+
* Long enough to cover the republish window after a hub restart, short enough
|
|
2944
|
+
* that a genuinely missing profile fails while the operator is still looking.
|
|
2945
|
+
*/
|
|
2946
|
+
var SOURCE_ACQUIRE_BUDGET_MS = 8e3;
|
|
2947
|
+
var SOURCE_ACQUIRE_PAUSE_MS = 700;
|
|
2948
|
+
var DEFAULTS = {
|
|
2949
|
+
cameraGrids: [],
|
|
2950
|
+
cameraGridTombstones: []
|
|
2951
|
+
};
|
|
2952
|
+
/** One composition per (grid, profile) — a grid composes each separately. */
|
|
2953
|
+
function sessionKey(instanceId, profile) {
|
|
2954
|
+
return `${instanceId}::${profile}`;
|
|
2955
|
+
}
|
|
2956
|
+
/**
|
|
2957
|
+
* One grid's composition of one profile.
|
|
2958
|
+
*
|
|
2959
|
+
* The profile is back in the key after a spell with a single output. What made
|
|
2960
|
+
* the per-profile shape painful was never the count: it was that a rebuild
|
|
2961
|
+
* meant a blank screen until the slowest source produced a key frame. An output
|
|
2962
|
+
* clock (D530) shows the picture at once and fills the cells in, so a rung the
|
|
2963
|
+
* adaptive can stand on costs what it is worth.
|
|
2964
|
+
*/
|
|
2965
|
+
var GridSessionEntry = class {
|
|
2966
|
+
instanceId;
|
|
2967
|
+
profile;
|
|
2968
|
+
session;
|
|
2969
|
+
constructor(instanceId, profile, session) {
|
|
2970
|
+
this.instanceId = instanceId;
|
|
2971
|
+
this.profile = profile;
|
|
2972
|
+
this.session = session;
|
|
2973
|
+
}
|
|
2974
|
+
isRunning() {
|
|
2975
|
+
return this.session.isRunning();
|
|
2976
|
+
}
|
|
2977
|
+
};
|
|
2978
|
+
var CameraGridAddon = class extends require_dist.BaseAddon {
|
|
2979
|
+
relay = null;
|
|
2980
|
+
reconcileTimer = null;
|
|
2981
|
+
/** Keyed by instance id — ONE composition per grid. */
|
|
2982
|
+
sessions = /* @__PURE__ */ new Map();
|
|
2983
|
+
deviceIdByInstanceId = /* @__PURE__ */ new Map();
|
|
2984
|
+
tombstones = /* @__PURE__ */ new Set();
|
|
2985
|
+
/**
|
|
2986
|
+
* What each grid can honestly publish, per profile.
|
|
2987
|
+
*
|
|
2988
|
+
* ABSENT means "not asked yet", and it is a REFUSAL to describe — the device
|
|
2989
|
+
* throws rather than answering an empty catalog, because an empty catalog
|
|
2990
|
+
* retracts every stream the broker holds for the grid. It is refreshed on
|
|
2991
|
+
* every reconcile and on every layout save; the window belongs to the READER
|
|
2992
|
+
* (D224), and 60 s is the window for a fact — "does 101 have a low assigned"
|
|
2993
|
+
* — that only changes when an operator changes it.
|
|
2994
|
+
*/
|
|
2995
|
+
plansByInstanceId = /* @__PURE__ */ new Map();
|
|
2996
|
+
activity = null;
|
|
2997
|
+
snapshots = null;
|
|
2998
|
+
frameSampler = null;
|
|
2999
|
+
/** The node's pinned ffmpeg (D540). `null` until init resolved it — a
|
|
3000
|
+
* composition then refuses by name; there is no PATH default. */
|
|
3001
|
+
ffmpegBinaryPath = null;
|
|
3002
|
+
/** The node's pinned build, remembered only on success (D540). */
|
|
3003
|
+
pinnedFfmpeg = require_dist.memoizePinnedFfmpeg(() => this.ctx.deps.ensureFfmpeg());
|
|
3004
|
+
/** A resolution in flight, so a reconcile pass never starts a second. */
|
|
3005
|
+
ffmpegResolving = null;
|
|
3006
|
+
integrationId;
|
|
3007
|
+
constructor() {
|
|
3008
|
+
super({ ...DEFAULTS });
|
|
3009
|
+
}
|
|
3010
|
+
async onInitialize() {
|
|
3011
|
+
this.replaceTombstones(this.config.cameraGridTombstones);
|
|
3012
|
+
await this.normalizeRows();
|
|
3013
|
+
if (require_dist.declarationOwnerNodeId(this.ctx.kernel.localNodeId) === "hub") {
|
|
3014
|
+
await this.resolveFfmpeg();
|
|
3015
|
+
const relay = new GridStreamRelay({
|
|
3016
|
+
logger: this.ctx.logger.child("relay"),
|
|
3017
|
+
sessionFor: (request) => this.sessionFor(request)
|
|
3018
|
+
});
|
|
3019
|
+
await relay.start();
|
|
3020
|
+
this.relay = relay;
|
|
3021
|
+
this.snapshots = new GridSnapshotSource({
|
|
3022
|
+
logger: this.ctx.logger.child("snapshot"),
|
|
3023
|
+
sessionsFor: (deviceId) => this.sessionsForDevice(deviceId),
|
|
3024
|
+
sampleFrame: async (session) => this.sampleFrame(session),
|
|
3025
|
+
store: new GridLastFrameFileStore({
|
|
3026
|
+
dataDir: this.ctx.dataDir,
|
|
3027
|
+
logger: this.ctx.logger.child("snapshot")
|
|
3028
|
+
})
|
|
3029
|
+
});
|
|
3030
|
+
this.activity = new GridActivityForwarder({
|
|
3031
|
+
eventBus: this.ctx.eventBus,
|
|
3032
|
+
logger: this.ctx.logger.child("activity"),
|
|
3033
|
+
addonId: this.ctx.id,
|
|
3034
|
+
gridsForSource: (sourceDeviceId) => this.gridsForSource(sourceDeviceId),
|
|
3035
|
+
now: () => Date.now()
|
|
3036
|
+
});
|
|
3037
|
+
this.subscribeSourceActivity();
|
|
3038
|
+
installGridCameraRuntime({
|
|
3039
|
+
descriptorsFor: (instanceId) => this.descriptorsFor(instanceId),
|
|
3040
|
+
getLayout: (deviceId) => this.gridViewFor(deviceId),
|
|
3041
|
+
saveLayout: async (patch) => this.saveGridLayout(patch),
|
|
3042
|
+
getSnapshot: async (deviceId) => this.getSnapshot(deviceId),
|
|
3043
|
+
motionStatus: (deviceId) => {
|
|
3044
|
+
const state = this.activity?.motionStatusFor(deviceId, Date.now()) ?? {
|
|
3045
|
+
detected: false,
|
|
3046
|
+
lastDetectedAt: null
|
|
3047
|
+
};
|
|
3048
|
+
return {
|
|
3049
|
+
...state,
|
|
3050
|
+
autoClearAfterMs: state.detected ? require_dist.MOTION_CLOSE_AFTER_MS : null
|
|
3051
|
+
};
|
|
3052
|
+
}
|
|
3053
|
+
});
|
|
3054
|
+
await this.reconcile().catch((error) => {
|
|
3055
|
+
this.ctx.logger.warn("camera grid: initial reconciliation failed — will retry", { meta: { error: require_dist.errMsg(error) } });
|
|
3056
|
+
});
|
|
3057
|
+
this.reconcileTimer = setInterval(() => {
|
|
3058
|
+
this.reconcile().catch((error) => {
|
|
3059
|
+
this.ctx.logger.warn("camera grid: reconciliation failed", { meta: { error: require_dist.errMsg(error) } });
|
|
3060
|
+
});
|
|
3061
|
+
}, RECONCILE_MS);
|
|
3062
|
+
this.reconcileTimer.unref?.();
|
|
3063
|
+
}
|
|
3064
|
+
return { providers: [{
|
|
3065
|
+
capability: require_dist.cameraGridLayoutCapability,
|
|
3066
|
+
provider: buildGridLayoutNativeProvider({
|
|
3067
|
+
getLayout: (deviceId) => this.gridViewFor(deviceId),
|
|
3068
|
+
saveLayout: (patch) => this.saveGridLayout(patch)
|
|
3069
|
+
})
|
|
3070
|
+
}] };
|
|
3071
|
+
}
|
|
3072
|
+
async onConfigChanged() {
|
|
3073
|
+
this.replaceTombstones(this.config.cameraGridTombstones);
|
|
3074
|
+
await this.normalizeRows();
|
|
3075
|
+
await this.applyLayoutChanges();
|
|
3076
|
+
if (this.relay) this.reconcile().catch((error) => {
|
|
3077
|
+
this.ctx.logger.warn("camera grid: reconciliation after a config change failed", { meta: { error: require_dist.errMsg(error) } });
|
|
3078
|
+
});
|
|
3079
|
+
}
|
|
3080
|
+
async onShutdown() {
|
|
3081
|
+
if (this.reconcileTimer) clearInterval(this.reconcileTimer);
|
|
3082
|
+
this.reconcileTimer = null;
|
|
3083
|
+
installGridCameraRuntime(null);
|
|
3084
|
+
await this.relay?.dispose();
|
|
3085
|
+
this.relay = null;
|
|
3086
|
+
for (const entry of this.sessions.values()) await entry.session.dispose();
|
|
3087
|
+
this.sessions.clear();
|
|
3088
|
+
this.snapshots = null;
|
|
3089
|
+
this.frameSampler = null;
|
|
3090
|
+
}
|
|
3091
|
+
instances() {
|
|
3092
|
+
return readGridInstances(this.config.cameraGrids, (message) => {
|
|
3093
|
+
this.ctx.logger.warn(message);
|
|
3094
|
+
});
|
|
3095
|
+
}
|
|
3096
|
+
instanceById(instanceId) {
|
|
3097
|
+
return this.instances().find((instance) => instance.id === instanceId);
|
|
3098
|
+
}
|
|
3099
|
+
/**
|
|
3100
|
+
* Fill in everything a name-only row is missing, and persist if it changed.
|
|
3101
|
+
*
|
|
3102
|
+
* Without this a freshly typed row is unparseable, and `readGridInstances`
|
|
3103
|
+
* IGNORES what it cannot parse — so creation would silently do nothing.
|
|
3104
|
+
*/
|
|
3105
|
+
async normalizeRows() {
|
|
3106
|
+
const normalized = normalizeGridRows(this.config.cameraGrids, () => crypto.randomUUID());
|
|
3107
|
+
if (!normalized.changed) return;
|
|
3108
|
+
this.ctx.logger.info("camera grid: completing operator-created rows", { meta: {
|
|
3109
|
+
rows: normalized.rows.length,
|
|
3110
|
+
wasRows: this.config.cameraGrids.length
|
|
3111
|
+
} });
|
|
3112
|
+
await this.updateGlobalSettings({ cameraGrids: [...normalized.rows] });
|
|
3113
|
+
}
|
|
3114
|
+
replaceTombstones(stableIds) {
|
|
3115
|
+
this.tombstones.clear();
|
|
3116
|
+
for (const stableId of stableIds) if (typeof stableId === "string" && stableId.length > 0) this.tombstones.add(stableId);
|
|
3117
|
+
}
|
|
3118
|
+
async reconcile() {
|
|
3119
|
+
if (!this.relay) return;
|
|
3120
|
+
const instances = this.instances();
|
|
3121
|
+
const declarations = buildGridCameraDeclarations(instances);
|
|
3122
|
+
await this.refreshSourcePlans(instances);
|
|
3123
|
+
await this.retireWithdrawnSessions(instances);
|
|
3124
|
+
const result = await new require_dist.DeclaredDevices({
|
|
3125
|
+
logger: this.ctx.logger.child("declaration"),
|
|
3126
|
+
addonId: this.ctx.id,
|
|
3127
|
+
devices: this.ctx.kernel.devices,
|
|
3128
|
+
localNodeId: this.ctx.kernel.localNodeId,
|
|
3129
|
+
getIntegration: async (addonId) => {
|
|
3130
|
+
const integration = await this.ctx.api.integrations.getByAddonId.query({ addonId });
|
|
3131
|
+
this.integrationId = integration?.id ?? null;
|
|
3132
|
+
return integration;
|
|
3133
|
+
},
|
|
3134
|
+
createIntegration: async (input) => {
|
|
3135
|
+
const integration = await this.ctx.api.integrations.create.mutate(input);
|
|
3136
|
+
this.integrationId = integration.id;
|
|
3137
|
+
return integration;
|
|
3138
|
+
},
|
|
3139
|
+
updateIntegration: async ({ id, info }) => {
|
|
3140
|
+
await this.ctx.api.integrations.update.mutate({
|
|
3141
|
+
id,
|
|
3142
|
+
info,
|
|
3143
|
+
skipRestart: true
|
|
3144
|
+
});
|
|
3145
|
+
},
|
|
3146
|
+
listOwnDevices: async () => {
|
|
3147
|
+
return gridCameraReconciliationIndex(await this.ctx.api.deviceManager.listAll.query({ addonId: this.ctx.id }), this.integrationId, declarations, this.tombstones);
|
|
3148
|
+
}
|
|
3149
|
+
}).reconcile({
|
|
3150
|
+
integrationName: INTEGRATION_NAME,
|
|
3151
|
+
placement: "hub",
|
|
3152
|
+
devices: declarations.map((camera) => ({
|
|
3153
|
+
stableId: camera.stableId,
|
|
3154
|
+
name: camera.name,
|
|
3155
|
+
type: require_dist.DeviceType.Camera,
|
|
3156
|
+
DeviceClass: GridCameraDevice,
|
|
3157
|
+
config: camera.config,
|
|
3158
|
+
role: "camera-grid"
|
|
3159
|
+
}))
|
|
3160
|
+
});
|
|
3161
|
+
const declaredByStableId = new Map(declarations.map((camera) => [camera.stableId, camera]));
|
|
3162
|
+
for (const outcome of result.devices) {
|
|
3163
|
+
if (!(outcome.device instanceof GridCameraDevice)) continue;
|
|
3164
|
+
const declaration = declaredByStableId.get(outcome.stableId);
|
|
3165
|
+
if (!declaration) continue;
|
|
3166
|
+
const config = outcome.device.config;
|
|
3167
|
+
if (config.get("instanceId") !== declaration.config.instanceId) await config.setAll(declaration.config);
|
|
3168
|
+
const instanceId = declaration.config.instanceId;
|
|
3169
|
+
this.deviceIdByInstanceId.set(instanceId, outcome.device.id);
|
|
3170
|
+
this.ensureSessions(instanceId, outcome.device.id);
|
|
3171
|
+
if (outcome.created) await this.silenceAnalysis(outcome.device.id);
|
|
3172
|
+
outcome.device.setAddonOnline(true);
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
async silenceAnalysis(deviceId) {
|
|
3176
|
+
try {
|
|
3177
|
+
await silenceAnalysisFor({
|
|
3178
|
+
api: this.ctx.api,
|
|
3179
|
+
logger: this.ctx.logger
|
|
3180
|
+
}, deviceId);
|
|
3181
|
+
} catch (error) {
|
|
3182
|
+
this.ctx.logger.error("camera grid: a new grid could not be silenced", {
|
|
3183
|
+
tags: { deviceId },
|
|
3184
|
+
meta: { error: require_dist.errMsg(error) }
|
|
3185
|
+
});
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
/**
|
|
3189
|
+
* Listen to the SOURCES, so the grid can say the same things about itself.
|
|
3190
|
+
*
|
|
3191
|
+
* Filtered by source id inside the handler rather than by subscribing per
|
|
3192
|
+
* camera: the bus filter is per category, the set of sources changes whenever
|
|
3193
|
+
* an operator drags a cell, and a per-camera subscription would have to be
|
|
3194
|
+
* torn down and rebuilt on every layout save.
|
|
3195
|
+
*
|
|
3196
|
+
* Every handler is TOTAL — a malformed payload is ignored, never thrown out
|
|
3197
|
+
* of. These are telemetry events on a shared bus (D8/D11), and a throw here
|
|
3198
|
+
* would take the grid's forwarding down for every grid because one camera
|
|
3199
|
+
* emitted something unexpected.
|
|
3200
|
+
*/
|
|
3201
|
+
subscribeSourceActivity() {
|
|
3202
|
+
this.subscribe({ category: require_dist.EventCategory.MotionOnMotionChanged }, (event) => {
|
|
3203
|
+
const data = event.data;
|
|
3204
|
+
if (typeof data.deviceId !== "number" || typeof data.detected !== "boolean") return;
|
|
3205
|
+
const at = typeof data.timestamp === "number" ? data.timestamp : Date.now();
|
|
3206
|
+
this.activity?.onSourceMotion(data.deviceId, data.detected, at);
|
|
3207
|
+
});
|
|
3208
|
+
this.subscribe({ category: require_dist.EventCategory.PipelineAudioInferenceResult }, (event) => {
|
|
3209
|
+
const data = event.data;
|
|
3210
|
+
const dbfs = data.frame?.level?.dbfs;
|
|
3211
|
+
if (typeof data.deviceId !== "number" || typeof dbfs !== "number") return;
|
|
3212
|
+
this.activity?.onSourceAudio(data.deviceId, dbfs, Date.now());
|
|
3213
|
+
});
|
|
3214
|
+
this.subscribe({ category: require_dist.EventCategory.DetectionResult }, (event) => {
|
|
3215
|
+
const frame = event.data.frame;
|
|
3216
|
+
if (frame === void 0 || frame.kind !== "frame") return;
|
|
3217
|
+
this.activity?.onSourceDetections(frame);
|
|
3218
|
+
});
|
|
3219
|
+
}
|
|
3220
|
+
/**
|
|
3221
|
+
* Which grids show this camera. Empty for the overwhelming majority of
|
|
3222
|
+
* events, which is why it is the FIRST thing every handler asks.
|
|
3223
|
+
*/
|
|
3224
|
+
gridsForSource(sourceDeviceId) {
|
|
3225
|
+
const targets = [];
|
|
3226
|
+
for (const [instanceId, deviceId] of this.deviceIdByInstanceId) {
|
|
3227
|
+
const instance = this.instanceById(instanceId);
|
|
3228
|
+
if (!instance || !instance.enabled) continue;
|
|
3229
|
+
if (sourceDeviceId === deviceId) continue;
|
|
3230
|
+
if (instance.cells.filter((cell) => cell.deviceId === sourceDeviceId).length === 0) continue;
|
|
3231
|
+
targets.push({
|
|
3232
|
+
deviceId,
|
|
3233
|
+
canvas: this.canvasFor(instanceId) ?? {
|
|
3234
|
+
width: 0,
|
|
3235
|
+
height: 0
|
|
3236
|
+
},
|
|
3237
|
+
cellsForSource: (id) => instance.cells.filter((cell) => cell.deviceId === id).map((cell) => ({
|
|
3238
|
+
source: cell.source,
|
|
3239
|
+
cell: cell.cell
|
|
3240
|
+
})),
|
|
3241
|
+
sourceDeviceIds: [...new Set(instance.cells.map((cell) => cell.deviceId))]
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
return targets;
|
|
3245
|
+
}
|
|
3246
|
+
/**
|
|
3247
|
+
* Which stream each grid reads each of its sources at, asked of the BROKER.
|
|
3248
|
+
*
|
|
3249
|
+
* `listAllProfileSlots` is the one authority on "does 101 have a low
|
|
3250
|
+
* assigned", and `sourceCamStreamId === null` is its way of saying no. A read
|
|
3251
|
+
* that FAILS leaves the previous answer in place and says so — it is not an
|
|
3252
|
+
* empty catalog, and turning it into one would retract the streams of every
|
|
3253
|
+
* grid on the hub.
|
|
3254
|
+
*/
|
|
3255
|
+
async refreshSourcePlans(instances) {
|
|
3256
|
+
let slots;
|
|
3257
|
+
try {
|
|
3258
|
+
slots = await this.ctx.api.streamBroker.listAllProfileSlots.query();
|
|
3259
|
+
} catch (error) {
|
|
3260
|
+
this.ctx.logger.warn("camera grid: could not read the broker profile slots - keeping the last answer", { meta: {
|
|
3261
|
+
error: require_dist.errMsg(error),
|
|
3262
|
+
grids: instances.length
|
|
3263
|
+
} });
|
|
3264
|
+
return;
|
|
3265
|
+
}
|
|
3266
|
+
const servedBy = /* @__PURE__ */ new Map();
|
|
3267
|
+
for (const slot of slots) {
|
|
3268
|
+
if (slot.sourceCamStreamId === null) continue;
|
|
3269
|
+
const profiles = servedBy.get(slot.deviceId) ?? [];
|
|
3270
|
+
profiles.push({
|
|
3271
|
+
profile: slot.profile,
|
|
3272
|
+
width: slot.resolution?.width ?? 0,
|
|
3273
|
+
height: slot.resolution?.height ?? 0
|
|
3274
|
+
});
|
|
3275
|
+
servedBy.set(slot.deviceId, profiles);
|
|
3276
|
+
}
|
|
3277
|
+
for (const instance of instances) {
|
|
3278
|
+
const plans = gridProfilePlans({
|
|
3279
|
+
publishedProfiles: instance.publishedProfiles,
|
|
3280
|
+
cells: instance.cells.map((cell) => ({
|
|
3281
|
+
deviceId: cell.deviceId,
|
|
3282
|
+
source: cell.source,
|
|
3283
|
+
cell: cell.cell
|
|
3284
|
+
})),
|
|
3285
|
+
profilesServedBy: (deviceId) => servedBy.get(deviceId) ?? null
|
|
3286
|
+
});
|
|
3287
|
+
const previous = this.plansByInstanceId.get(instance.id);
|
|
3288
|
+
this.plansByInstanceId.set(instance.id, plans);
|
|
3289
|
+
this.logSourcePlan(instance, plans, previous);
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
/**
|
|
3293
|
+
* Say WHICH stream each cell is read at, and who could not be read - once per
|
|
3294
|
+
* change.
|
|
3295
|
+
*
|
|
3296
|
+
* Both halves earn their line. A grid silently missing from a catalog is
|
|
3297
|
+
* indistinguishable from a broker that swept it, so the refusal names the
|
|
3298
|
+
* sources. And the chosen profiles are the answer to "why is this tile
|
|
3299
|
+
* soft?" — a camera whose only assigned slot is `high` is read at `high`, and
|
|
3300
|
+
* nothing else in the system would ever say so.
|
|
3301
|
+
*
|
|
3302
|
+
* Logged on the EDGE: a grid that cannot be composed would otherwise write a
|
|
3303
|
+
* line a minute for ever.
|
|
3304
|
+
*/
|
|
3305
|
+
logSourcePlan(instance, plans, previous) {
|
|
3306
|
+
const shape = (value) => JSON.stringify(value);
|
|
3307
|
+
if (previous !== void 0 && shape(previous) === shape(plans)) return;
|
|
3308
|
+
const deviceId = this.deviceIdByInstanceId.get(instance.id) ?? 0;
|
|
3309
|
+
for (const row of plans) {
|
|
3310
|
+
if (row.offered || row.missingSources.length === 0) continue;
|
|
3311
|
+
this.ctx.logger.info("camera grid: a profile is NOT on offer", {
|
|
3312
|
+
tags: { deviceId },
|
|
3313
|
+
meta: {
|
|
3314
|
+
instanceId: instance.id,
|
|
3315
|
+
profile: row.profile,
|
|
3316
|
+
missingSources: [...row.missingSources]
|
|
3317
|
+
}
|
|
3318
|
+
});
|
|
3319
|
+
}
|
|
3320
|
+
this.ctx.logger.info("camera grid: published profiles", {
|
|
3321
|
+
tags: { deviceId },
|
|
3322
|
+
meta: {
|
|
3323
|
+
instanceId: instance.id,
|
|
3324
|
+
offered: Object.fromEntries(plans.filter((row) => row.offered && row.published).map((row) => [row.profile, row.offered ? `${String(row.canvas.width)}x${String(row.canvas.height)}` : ""]))
|
|
3325
|
+
}
|
|
3326
|
+
});
|
|
3327
|
+
}
|
|
3328
|
+
plansFor(instanceId) {
|
|
3329
|
+
return this.plansByInstanceId.get(instanceId) ?? null;
|
|
3330
|
+
}
|
|
3331
|
+
planFor(instanceId, profile) {
|
|
3332
|
+
return this.plansFor(instanceId)?.find((row) => row.profile === profile) ?? null;
|
|
3333
|
+
}
|
|
3334
|
+
/**
|
|
3335
|
+
* The canvas of the BEST profile this grid offers.
|
|
3336
|
+
*
|
|
3337
|
+
* Used where a single geometry is needed for something that is not a
|
|
3338
|
+
* composition — the detection boxes a grid forwards (`grid-activity`), which
|
|
3339
|
+
* are normalized against whatever picture the viewer is looking at. The best
|
|
3340
|
+
* offered one is the honest default; a grid offering nothing has no geometry
|
|
3341
|
+
* and says so.
|
|
3342
|
+
*/
|
|
3343
|
+
canvasFor(instanceId) {
|
|
3344
|
+
for (const row of this.plansFor(instanceId) ?? []) if (row.offered) return row.canvas;
|
|
3345
|
+
return null;
|
|
3346
|
+
}
|
|
3347
|
+
ensureSessions(instanceId, deviceId) {
|
|
3348
|
+
for (const profile of GRID_PROFILES) {
|
|
3349
|
+
const key = sessionKey(instanceId, profile);
|
|
3350
|
+
const plan = this.planFor(instanceId, profile);
|
|
3351
|
+
if (plan === null || !plan.offered || !plan.published) {
|
|
3352
|
+
const stale = this.sessions.get(key);
|
|
3353
|
+
if (stale) {
|
|
3354
|
+
this.sessions.delete(key);
|
|
3355
|
+
stale.session.dispose();
|
|
3356
|
+
}
|
|
3357
|
+
continue;
|
|
3358
|
+
}
|
|
3359
|
+
if (this.sessions.has(key)) continue;
|
|
3360
|
+
const binaryPath = this.ffmpegBinaryPath;
|
|
3361
|
+
if (binaryPath === null) {
|
|
3362
|
+
this.ctx.logger.error("camera-grid: composition refused — no pinned ffmpeg on this node (D540)", {
|
|
3363
|
+
tags: { deviceId },
|
|
3364
|
+
meta: {
|
|
3365
|
+
instanceId,
|
|
3366
|
+
profile
|
|
3367
|
+
}
|
|
3368
|
+
});
|
|
3369
|
+
this.resolveFfmpeg();
|
|
3370
|
+
continue;
|
|
3371
|
+
}
|
|
3372
|
+
this.sessions.set(key, new GridSessionEntry(instanceId, profile, this.makeSession(instanceId, deviceId, profile, binaryPath)));
|
|
3373
|
+
}
|
|
3374
|
+
}
|
|
3375
|
+
/**
|
|
3376
|
+
* The source cameras' names, for the cards the canvas is seeded with.
|
|
3377
|
+
*
|
|
3378
|
+
* Asked of the device manager, which OWNS the name, at the moment the seed is
|
|
3379
|
+
* drawn — never kept here. A consumer that mirrored this would be stale on
|
|
3380
|
+
* exactly the write an operator makes (D224), for a label.
|
|
3381
|
+
*
|
|
3382
|
+
* A device that cannot be read is simply absent from the map, and its card
|
|
3383
|
+
* carries the device id instead. One unreadable camera never costs the other
|
|
3384
|
+
* cards their names, which is why these are settled rather than awaited as
|
|
3385
|
+
* one batch.
|
|
3386
|
+
*/
|
|
3387
|
+
async sourceNames(deviceIds) {
|
|
3388
|
+
const names = /* @__PURE__ */ new Map();
|
|
3389
|
+
const results = await Promise.allSettled(deviceIds.map(async (deviceId) => {
|
|
3390
|
+
return {
|
|
3391
|
+
deviceId,
|
|
3392
|
+
name: (await this.ctx.api.deviceManager.getDevice.query({ deviceId }))?.name ?? null
|
|
3393
|
+
};
|
|
3394
|
+
}));
|
|
3395
|
+
for (const result of results) {
|
|
3396
|
+
if (result.status !== "fulfilled") continue;
|
|
3397
|
+
const { deviceId, name } = result.value;
|
|
3398
|
+
if (name !== null) names.set(deviceId, name);
|
|
3399
|
+
}
|
|
3400
|
+
return names;
|
|
3401
|
+
}
|
|
3402
|
+
makeSession(instanceId, deviceId, profile, binaryPath) {
|
|
3403
|
+
const childContext = {
|
|
3404
|
+
binaryPath,
|
|
3405
|
+
logger: this.ctx.logger,
|
|
3406
|
+
deviceId,
|
|
3407
|
+
resolveSourceNames: (deviceIds) => this.sourceNames(deviceIds)
|
|
3408
|
+
};
|
|
3409
|
+
const session = new GridStreamSession({
|
|
3410
|
+
deviceId,
|
|
3411
|
+
deps: {
|
|
3412
|
+
logger: this.ctx.logger,
|
|
3413
|
+
acquireSource: async (sourceDeviceId) => {
|
|
3414
|
+
const dial = gridSourceDial(await acquireWithRetry(() => this.ctx.api.streamBroker.getStreamWithCodec.mutate({
|
|
3415
|
+
deviceId: sourceDeviceId,
|
|
3416
|
+
video: "copy",
|
|
3417
|
+
audio: "none",
|
|
3418
|
+
profile,
|
|
3419
|
+
tag: `camera-grid:${String(deviceId)}:${profile}`
|
|
3420
|
+
}), {
|
|
3421
|
+
budgetMs: SOURCE_ACQUIRE_BUDGET_MS,
|
|
3422
|
+
now: () => Date.now(),
|
|
3423
|
+
sleep: () => new Promise((resolve) => setTimeout(resolve, SOURCE_ACQUIRE_PAUSE_MS)),
|
|
3424
|
+
onRetry: (waitedMs) => {
|
|
3425
|
+
this.ctx.logger.info("camera grid: a source has not republished yet — asking again", {
|
|
3426
|
+
tags: { deviceId },
|
|
3427
|
+
meta: {
|
|
3428
|
+
instanceId,
|
|
3429
|
+
profile,
|
|
3430
|
+
sourceDeviceId,
|
|
3431
|
+
waitedMs
|
|
3432
|
+
}
|
|
3433
|
+
});
|
|
3434
|
+
}
|
|
3435
|
+
}));
|
|
3436
|
+
this.ctx.logger.info("camera grid: source acquired", {
|
|
3437
|
+
tags: { deviceId },
|
|
3438
|
+
meta: {
|
|
3439
|
+
instanceId,
|
|
3440
|
+
profile,
|
|
3441
|
+
sourceDeviceId,
|
|
3442
|
+
mode: dial.mode,
|
|
3443
|
+
...dial.mode === "sentry" ? { why: "battery source - the sentry dial never asks for the camera" } : {}
|
|
3444
|
+
}
|
|
3445
|
+
});
|
|
3446
|
+
return {
|
|
3447
|
+
url: dial.url,
|
|
3448
|
+
pipelineKey: dial.pipelineKey
|
|
3449
|
+
};
|
|
3450
|
+
},
|
|
3451
|
+
releaseSource: async (pipelineKey) => {
|
|
3452
|
+
await this.ctx.api.streamBroker.releaseStreamWithCodec.mutate({ pipelineKey });
|
|
3453
|
+
},
|
|
3454
|
+
startChild: async (plan, sources) => startGridCompositorChild(childContext, plan, sources, (reason) => {
|
|
3455
|
+
session.onChildEnded(reason);
|
|
3456
|
+
})
|
|
3457
|
+
},
|
|
3458
|
+
resolvePlan: () => {
|
|
3459
|
+
const instance = this.instanceById(instanceId);
|
|
3460
|
+
const plan = this.planFor(instanceId, profile);
|
|
3461
|
+
if (!instance || plan === null || !plan.offered || !plan.published) return null;
|
|
3462
|
+
return gridPlanFor(instance, {
|
|
3463
|
+
encoder: "libx264",
|
|
3464
|
+
decodeHwAccel: null,
|
|
3465
|
+
canvas: plan.canvas
|
|
3466
|
+
});
|
|
3467
|
+
}
|
|
3468
|
+
});
|
|
3469
|
+
return session;
|
|
3470
|
+
}
|
|
3471
|
+
/** The session a dial is asking for, or `null` - which the relay answers 404 to. */
|
|
3472
|
+
sessionFor(request) {
|
|
3473
|
+
return this.sessions.get(sessionKey(request.instanceId, request.profile))?.session ?? null;
|
|
3474
|
+
}
|
|
3475
|
+
/** This grid's sessions, in DESCENDING quality — the snapshot takes the first running one. */
|
|
3476
|
+
sessionsForDevice(deviceId) {
|
|
3477
|
+
const instanceId = this.instanceIdForDevice(deviceId);
|
|
3478
|
+
if (instanceId === null) return [];
|
|
3479
|
+
const entries = [];
|
|
3480
|
+
for (const profile of GRID_PROFILES) {
|
|
3481
|
+
const entry = this.sessions.get(sessionKey(instanceId, profile));
|
|
3482
|
+
if (entry) entries.push(entry);
|
|
3483
|
+
}
|
|
3484
|
+
return entries;
|
|
3485
|
+
}
|
|
3486
|
+
/** A grid that is gone stops immediately - it must not keep N sources dialled. */
|
|
3487
|
+
async retireWithdrawnSessions(instances) {
|
|
3488
|
+
const live = new Set(instances.filter((instance) => instance.enabled).map((i) => i.id));
|
|
3489
|
+
for (const [key, entry] of [...this.sessions]) {
|
|
3490
|
+
if (live.has(entry.instanceId)) continue;
|
|
3491
|
+
this.ctx.logger.info("camera grid: retiring a withdrawn grid", {
|
|
3492
|
+
tags: { deviceId: this.deviceIdByInstanceId.get(entry.instanceId) ?? 0 },
|
|
3493
|
+
meta: { instanceId: entry.instanceId }
|
|
3494
|
+
});
|
|
3495
|
+
this.sessions.delete(key);
|
|
3496
|
+
await entry.session.dispose();
|
|
3497
|
+
}
|
|
3498
|
+
for (const instanceId of [...this.deviceIdByInstanceId.keys()]) {
|
|
3499
|
+
if (live.has(instanceId)) continue;
|
|
3500
|
+
this.activity?.forget(this.deviceIdByInstanceId.get(instanceId) ?? 0);
|
|
3501
|
+
this.deviceIdByInstanceId.delete(instanceId);
|
|
3502
|
+
this.plansByInstanceId.delete(instanceId);
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
/**
|
|
3506
|
+
* A geometry change is a NEW composition. The running child is composing the
|
|
3507
|
+
* old one, and ffmpeg has no way to be told otherwise, so it is stopped: the
|
|
3508
|
+
* consumer's next read re-dials and gets the new picture.
|
|
3509
|
+
*/
|
|
3510
|
+
async applyLayoutChanges() {
|
|
3511
|
+
for (const entry of this.sessions.values()) {
|
|
3512
|
+
if (!entry.session.isRunning()) continue;
|
|
3513
|
+
this.ctx.logger.info("camera grid: the layout changed - restarting the composition", {
|
|
3514
|
+
tags: { deviceId: this.deviceIdByInstanceId.get(entry.instanceId) ?? 0 },
|
|
3515
|
+
meta: { instanceId: entry.instanceId }
|
|
3516
|
+
});
|
|
3517
|
+
entry.session.onChildEnded("layout-changed");
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
async getSnapshot(deviceId) {
|
|
3521
|
+
const snapshots = this.snapshots;
|
|
3522
|
+
if (snapshots === null) return null;
|
|
3523
|
+
return snapshots.getSnapshot(deviceId);
|
|
3524
|
+
}
|
|
3525
|
+
/**
|
|
3526
|
+
* One frame out of a composition that is ALREADY running.
|
|
3527
|
+
*
|
|
3528
|
+
* `openIfRunning` is the whole guarantee: it refuses a cold session, so a
|
|
3529
|
+
* thumbnail can never be the reason N sources get acquired. A grid that is
|
|
3530
|
+
* not being watched has no fresh frame, and that is the honest answer.
|
|
3531
|
+
*/
|
|
3532
|
+
async sampleFrame(entry) {
|
|
3533
|
+
const sampler = this.frameSampler;
|
|
3534
|
+
if (sampler === null) return null;
|
|
3535
|
+
return sampler.sample(entry.session.deviceId, { attach: (onChunk) => entry.session.openIfRunning({
|
|
3536
|
+
onData: onChunk,
|
|
3537
|
+
onClose: () => {}
|
|
3538
|
+
}) });
|
|
3539
|
+
}
|
|
3540
|
+
/**
|
|
3541
|
+
* Every stream this grid offers, or `null` when the addon cannot say.
|
|
3542
|
+
*
|
|
3543
|
+
* `null` is a refusal to describe and the device turns it into a THROW. An
|
|
3544
|
+
* empty array would be the broker reading "this camera offers nothing" and
|
|
3545
|
+
* sweeping every stream it holds for the grid.
|
|
3546
|
+
*/
|
|
3547
|
+
descriptorsFor(instanceId) {
|
|
3548
|
+
const instance = this.instanceById(instanceId);
|
|
3549
|
+
const relay = this.relay;
|
|
3550
|
+
const plans = this.plansFor(instanceId);
|
|
3551
|
+
if (!instance || !relay || plans === null) return null;
|
|
3552
|
+
return plans.filter((row) => row.offered && row.published).map((row) => gridStreamDescriptor({
|
|
3553
|
+
profile: row.profile,
|
|
3554
|
+
width: row.offered ? row.canvas.width : 0,
|
|
3555
|
+
height: row.offered ? row.canvas.height : 0,
|
|
3556
|
+
fps: instance.fps,
|
|
3557
|
+
url: relay.streamUrl({
|
|
3558
|
+
instanceId,
|
|
3559
|
+
profile: row.profile
|
|
3560
|
+
})
|
|
3561
|
+
}));
|
|
3562
|
+
}
|
|
3563
|
+
instanceIdForDevice(deviceId) {
|
|
3564
|
+
for (const [instanceId, id] of this.deviceIdByInstanceId) if (id === deviceId) return instanceId;
|
|
3565
|
+
return null;
|
|
3566
|
+
}
|
|
3567
|
+
instanceForDevice(deviceId) {
|
|
3568
|
+
const instanceId = this.instanceIdForDevice(deviceId);
|
|
3569
|
+
return instanceId === null ? null : this.instanceById(instanceId) ?? null;
|
|
3570
|
+
}
|
|
3571
|
+
gridViewFor(deviceId) {
|
|
3572
|
+
const instance = this.instanceForDevice(deviceId);
|
|
3573
|
+
if (!instance) return null;
|
|
3574
|
+
return {
|
|
3575
|
+
instanceId: instance.id,
|
|
3576
|
+
deviceId,
|
|
3577
|
+
name: instance.name,
|
|
3578
|
+
fps: instance.fps,
|
|
3579
|
+
cells: instance.cells.map((cell) => ({
|
|
3580
|
+
deviceId: cell.deviceId,
|
|
3581
|
+
source: cell.source,
|
|
3582
|
+
cell: cell.cell
|
|
3583
|
+
})),
|
|
3584
|
+
profiles: (this.plansByInstanceId.get(instance.id) ?? []).map((row) => ({
|
|
3585
|
+
profile: row.profile,
|
|
3586
|
+
offered: row.offered,
|
|
3587
|
+
published: row.offered && row.published,
|
|
3588
|
+
missingSources: row.offered ? [] : [...row.missingSources],
|
|
3589
|
+
canvas: row.offered ? `${String(row.canvas.width)}x${String(row.canvas.height)}` : ""
|
|
3590
|
+
}))
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
async saveGridLayout(input) {
|
|
3594
|
+
const instance = this.instanceForDevice(input.deviceId);
|
|
3595
|
+
if (!instance) throw new Error(`camera-grid: device ${String(input.deviceId)} is not a grid camera`);
|
|
3596
|
+
const updated = {
|
|
3597
|
+
...instance,
|
|
3598
|
+
...input.name !== void 0 ? { name: input.name.trim() } : {},
|
|
3599
|
+
...input.fps !== void 0 ? { fps: input.fps } : {},
|
|
3600
|
+
...input.publishedProfiles !== void 0 ? { publishedProfiles: [...input.publishedProfiles] } : {},
|
|
3601
|
+
cells: input.cells.map((cell) => ({ ...cell }))
|
|
3602
|
+
};
|
|
3603
|
+
this.ctx.logger.info("camera grid: layout saved", {
|
|
3604
|
+
tags: { deviceId: input.deviceId },
|
|
3605
|
+
meta: {
|
|
3606
|
+
cells: updated.cells.length,
|
|
3607
|
+
sources: [...new Set(updated.cells.map((cell) => cell.deviceId))],
|
|
3608
|
+
fps: updated.fps
|
|
3609
|
+
}
|
|
3610
|
+
});
|
|
3611
|
+
await this.updateGlobalSettings({ cameraGrids: this.config.cameraGrids.map((row) => row["id"] === instance.id ? {
|
|
3612
|
+
...row,
|
|
3613
|
+
...updated
|
|
3614
|
+
} : row) });
|
|
3615
|
+
await this.refreshSourcePlans(this.instances());
|
|
3616
|
+
this.ensureSessions(instance.id, input.deviceId);
|
|
3617
|
+
const view = this.gridViewFor(input.deviceId);
|
|
3618
|
+
if (!view) throw new Error("camera-grid: the grid vanished while it was being saved");
|
|
3619
|
+
return view;
|
|
3620
|
+
}
|
|
3621
|
+
/**
|
|
3622
|
+
* Resolve the pinned build, single-flighted, and hand it to the frame sampler.
|
|
3623
|
+
* Never throws: a failure is an ERROR and leaves the binary unknown, so the
|
|
3624
|
+
* next pass that wants a composition asks again. Never PATH: the host's
|
|
3625
|
+
* ffmpeg is not ours (`packages/types/src/deps/ffmpeg-binary-source.ts`).
|
|
3626
|
+
*/
|
|
3627
|
+
resolveFfmpeg() {
|
|
3628
|
+
if (this.ffmpegBinaryPath !== null) return Promise.resolve();
|
|
3629
|
+
if (this.ffmpegResolving !== null) return this.ffmpegResolving;
|
|
3630
|
+
const attempt = this.pinnedFfmpeg().then((binaryPath) => {
|
|
3631
|
+
this.ffmpegBinaryPath = binaryPath;
|
|
3632
|
+
this.frameSampler = new GridFrameSampler({
|
|
3633
|
+
binaryPath,
|
|
3634
|
+
logger: this.ctx.logger.child("snapshot")
|
|
3635
|
+
});
|
|
3636
|
+
}).catch((err) => {
|
|
3637
|
+
this.ctx.logger.error("camera-grid: the pinned ffmpeg could not be resolved — compositions refuse until it is (D540)", { meta: { error: require_dist.errMsg(err) } });
|
|
3638
|
+
}).finally(() => {
|
|
3639
|
+
this.ffmpegResolving = null;
|
|
3640
|
+
});
|
|
3641
|
+
this.ffmpegResolving = attempt;
|
|
3642
|
+
return attempt;
|
|
3643
|
+
}
|
|
3644
|
+
/**
|
|
3645
|
+
* The integration page: a list of grids, with a NAME.
|
|
3646
|
+
*
|
|
3647
|
+
* Deliberately nothing else. A generated form for the geometry would render
|
|
3648
|
+
* "cell 1 source = 592, cell 1 crop x = 0.25" and be unusable, so the
|
|
3649
|
+
* geometry lives in a WIDGET on the camera's own device details, declared by
|
|
3650
|
+
* the `camera-grid-layout` CAPABILITY (`camera-grid-layout.cap.ts`). It used
|
|
3651
|
+
* to be a `type:'widget'` field in this addon's own `deviceSettingsSchema()`
|
|
3652
|
+
* and it rendered NOWHERE: that section is only fetched for the four addons
|
|
3653
|
+
* hand-listed in `PIPELINE_CLUSTER_DEVICE_ADDONS`, and an addon not on the
|
|
3654
|
+
* list falls off silently. A cap-declared widget is placed by the framework,
|
|
3655
|
+
* on the camera, beside PTZ and motion zones.
|
|
3656
|
+
*/
|
|
3657
|
+
globalSettingsSchema() {
|
|
3658
|
+
return this.schema({ sections: [{
|
|
3659
|
+
id: "camera-grids",
|
|
3660
|
+
title: "Camera grids",
|
|
3661
|
+
titleKey: "server:globalSettings.s_camera-grids.title",
|
|
3662
|
+
description: "A grid is a composite camera: several cameras composed into one picture, recorded and played back like any other camera. Create one here with a name; open its camera to lay it out. Object detection is switched OFF on a new grid — the cameras it is composed from are already analysed.",
|
|
3663
|
+
descriptionKey: "server:globalSettings.s_camera-grids.description",
|
|
3664
|
+
columns: 1,
|
|
3665
|
+
fields: [this.field({
|
|
3666
|
+
type: "editable-array",
|
|
3667
|
+
key: "cameraGrids",
|
|
3668
|
+
label: "Grids",
|
|
3669
|
+
labelKey: "server:globalSettings.s_camera-grids.cameraGrids.label",
|
|
3670
|
+
default: [],
|
|
3671
|
+
maxRows: 16,
|
|
3672
|
+
addLabel: "Add grid",
|
|
3673
|
+
emptyMessage: "No camera grids yet.",
|
|
3674
|
+
rowTitleTemplate: "{name}",
|
|
3675
|
+
defaultItem: {
|
|
3676
|
+
name: "",
|
|
3677
|
+
enabled: true
|
|
3678
|
+
},
|
|
3679
|
+
itemFields: [{
|
|
3680
|
+
type: "text",
|
|
3681
|
+
key: "name",
|
|
3682
|
+
label: "Name",
|
|
3683
|
+
labelKey: "server:globalSettings.s_camera-grids.cameraGrids.name.label",
|
|
3684
|
+
required: true
|
|
3685
|
+
}, {
|
|
3686
|
+
type: "boolean",
|
|
3687
|
+
key: "enabled",
|
|
3688
|
+
label: "Enabled",
|
|
3689
|
+
labelKey: "server:globalSettings.s_camera-grids.cameraGrids.enabled.label",
|
|
3690
|
+
description: "A disabled grid withdraws its camera.",
|
|
3691
|
+
descriptionKey: "server:globalSettings.s_camera-grids.cameraGrids.enabled.description",
|
|
3692
|
+
default: true
|
|
3693
|
+
}]
|
|
3694
|
+
})]
|
|
3695
|
+
}] });
|
|
3696
|
+
}
|
|
3697
|
+
integrationSettingSections() {
|
|
3698
|
+
return ["camera-grids"];
|
|
3699
|
+
}
|
|
3700
|
+
};
|
|
3701
|
+
//#endregion
|
|
3702
|
+
//#region src/builtins/camera-grid/grid-filter-graph.ts
|
|
3703
|
+
var CANVAS_LABEL = "canvas";
|
|
3704
|
+
var OUT_LABEL = "grid";
|
|
3705
|
+
/** Full-frame within a tolerance, i.e. nothing to crop. */
|
|
3706
|
+
var FULL_FRAME_EPSILON = 1e-6;
|
|
3707
|
+
function isFullFrame(rect) {
|
|
3708
|
+
return Math.abs(rect.x) < FULL_FRAME_EPSILON && Math.abs(rect.y) < FULL_FRAME_EPSILON && Math.abs(rect.width - 1) < FULL_FRAME_EPSILON && Math.abs(rect.height - 1) < FULL_FRAME_EPSILON;
|
|
3709
|
+
}
|
|
3710
|
+
/**
|
|
3711
|
+
* yuv420p subsamples chroma 2x2, so an odd width or height is rejected by every
|
|
3712
|
+
* encoder we use. Rounding here lets the reason be stated; rounding inside the
|
|
3713
|
+
* child is a start-up failure with no context.
|
|
3714
|
+
*/
|
|
3715
|
+
function toEven(value) {
|
|
3716
|
+
const rounded = Math.round(value);
|
|
3717
|
+
const even = rounded % 2 === 0 ? rounded : rounded - 1;
|
|
3718
|
+
return Math.max(2, even);
|
|
3719
|
+
}
|
|
3720
|
+
function assertWithin(rect, what, cellIndex) {
|
|
3721
|
+
if (rect.x < 0 || rect.y < 0 || rect.width <= 0 || rect.height <= 0 || rect.x + rect.width > 1.000001 || rect.y + rect.height > 1.000001) throw new Error(`camera-grid: cell ${cellIndex} falls ${what} (x=${rect.x} y=${rect.y} w=${rect.width} h=${rect.height}) — ffmpeg would render this as a silently clipped picture`);
|
|
3722
|
+
}
|
|
3723
|
+
/**
|
|
3724
|
+
* `crop` resolved against the source's OWN size at runtime (`iw`/`ih`), never
|
|
3725
|
+
* against a resolution guessed here. That is what makes the stored rectangle
|
|
3726
|
+
* survive a source that changes resolution.
|
|
3727
|
+
*/
|
|
3728
|
+
function cropExpression(source) {
|
|
3729
|
+
return `crop=iw*${source.width}:ih*${source.height}:iw*${source.x}:ih*${source.y}`;
|
|
3730
|
+
}
|
|
3731
|
+
function buildGridFilterGraph(layout) {
|
|
3732
|
+
if (layout.cells.length === 0) throw new Error("camera-grid: a composite needs at least one cell to emit anything");
|
|
3733
|
+
const steps = [`color=c=black:s=${layout.width}x${layout.height}:d=1[${CANVAS_LABEL}]`];
|
|
3734
|
+
const cellLabels = [];
|
|
3735
|
+
layout.cells.forEach((cell, index) => {
|
|
3736
|
+
assertWithin(cell.source, "outside its source", index);
|
|
3737
|
+
assertWithin(cell.cell, "outside the canvas", index);
|
|
3738
|
+
const targetWidth = toEven(cell.cell.width * layout.width);
|
|
3739
|
+
const targetHeight = toEven(cell.cell.height * layout.height);
|
|
3740
|
+
const label = `c${index}`;
|
|
3741
|
+
const filters = [...isFullFrame(cell.source) ? [] : [cropExpression(cell.source)], `scale=${targetWidth}:${targetHeight}`];
|
|
3742
|
+
steps.push(`[${cell.inputIndex}:v]${filters.join(",")}[${label}]`);
|
|
3743
|
+
cellLabels.push(label);
|
|
3744
|
+
});
|
|
3745
|
+
let base = CANVAS_LABEL;
|
|
3746
|
+
layout.cells.forEach((cell, index) => {
|
|
3747
|
+
const x = Math.round(cell.cell.x * layout.width);
|
|
3748
|
+
const y = Math.round(cell.cell.y * layout.height);
|
|
3749
|
+
const out = index === layout.cells.length - 1 ? OUT_LABEL : `s${index}`;
|
|
3750
|
+
steps.push(`[${base}][${cellLabels[index]}]overlay=${x}:${y}[${out}]`);
|
|
3751
|
+
base = out;
|
|
3752
|
+
});
|
|
3753
|
+
return {
|
|
3754
|
+
graph: steps.join(";"),
|
|
3755
|
+
videoOutLabel: OUT_LABEL
|
|
3756
|
+
};
|
|
3757
|
+
}
|
|
3758
|
+
//#endregion
|
|
3759
|
+
//#region src/builtins/camera-grid/grid-stream-invocation.ts
|
|
3760
|
+
/**
|
|
3761
|
+
* The encoder preset. `veryfast` because a composite is the one encode in the
|
|
3762
|
+
* cluster whose input cost already scales with the number of cameras in it —
|
|
3763
|
+
* the decode side of a 2x2 is four decodes — so the encode side is where a
|
|
3764
|
+
* cheap default matters most.
|
|
3765
|
+
*/
|
|
3766
|
+
var PRESET = "veryfast";
|
|
3767
|
+
/**
|
|
3768
|
+
* `-tune zerolatency`, and this one is worth several SECONDS.
|
|
3769
|
+
*
|
|
3770
|
+
* x264's defaults hold frames before emitting any: a rate-control lookahead of
|
|
3771
|
+
* ~40 frames plus B-frames. At a composite's 10 fps that lookahead alone is
|
|
3772
|
+
* about four seconds of picture sitting inside the encoder — the operator saw
|
|
3773
|
+
* it as "ritardi di secondi" and it was not the network, the relay or the
|
|
3774
|
+
* broker. `zerolatency` sets `rc-lookahead=0`, `sync-lookahead=0` and
|
|
3775
|
+
* `bframes=0`, which is exactly the trade a live composite wants: a few percent
|
|
3776
|
+
* more bitrate for the same picture, in exchange for the encoder emitting each
|
|
3777
|
+
* frame as it arrives.
|
|
3778
|
+
*
|
|
3779
|
+
* It is not a preset. `veryfast` says how hard the encoder searches; this says
|
|
3780
|
+
* how long it is allowed to WAIT, and the two are independent.
|
|
3781
|
+
*/
|
|
3782
|
+
var TUNE = "zerolatency";
|
|
3783
|
+
/** yuv420p: the only pixel format every consumer of a CamStack profile reads. */
|
|
3784
|
+
var PIXEL_FORMAT = "yuv420p";
|
|
3785
|
+
/**
|
|
3786
|
+
* Key-frame cadence, in seconds.
|
|
3787
|
+
*
|
|
3788
|
+
* Two things ride on this and they pull the same way. A recorder cuts its
|
|
3789
|
+
* segments on a key frame, so a long GOP produces long segments and a scrub
|
|
3790
|
+
* that lands far from where the operator clicked. And every consumer — the
|
|
3791
|
+
* broker's reader included — starts at a key frame, so the GOP is the WORST
|
|
3792
|
+
* CASE wait before a grid appears at all: at two seconds a viewer could stare
|
|
3793
|
+
* at nothing for two seconds after pressing play.
|
|
3794
|
+
*
|
|
3795
|
+
* One second halves that wait. It costs bitrate (an IDR is expensive and there
|
|
3796
|
+
* are now twice as many), which is why it is not lower: below a second the
|
|
3797
|
+
* bitrate paid buys a wait nobody can feel.
|
|
3798
|
+
*/
|
|
3799
|
+
var GOP_SECONDS = 1;
|
|
3800
|
+
/**
|
|
3801
|
+
* `-analyzeduration` / `-probesize`, as small as ffmpeg allows.
|
|
3802
|
+
*
|
|
3803
|
+
* ## The probes are SEQUENTIAL, and this is what the tile skew was
|
|
3804
|
+
*
|
|
3805
|
+
* The sentence that used to be here said the probes are "PARALLEL inputs of one
|
|
3806
|
+
* child". They are not. ffmpeg opens its inputs one after another and each open
|
|
3807
|
+
* BLOCKS in `avformat_find_stream_info` until its budget is spent — so input 0
|
|
3808
|
+
* is already connected and receiving while ffmpeg is still opening input 1, its
|
|
3809
|
+
* frames pile up, and `overlay` (which pairs inputs BY PTS) marries input 0's
|
|
3810
|
+
* oldest frame to input 1's newest. The lag is fixed for the life of the child:
|
|
3811
|
+
* both tiles then advance one frame per output frame, so nothing ever closes it.
|
|
3812
|
+
* The FIRST cell is the most behind; the last is live.
|
|
3813
|
+
*
|
|
3814
|
+
* Reproduced in one command on 2026-09-18 — two sources hstacked, one frame,
|
|
3815
|
+
* reading the cameras' own burnt-in clocks out of the composed picture:
|
|
3816
|
+
*
|
|
3817
|
+
* ```
|
|
3818
|
+
* 13:11:21 | 13:11:23 two seconds, and the earlier input is the late one
|
|
3819
|
+
* ```
|
|
3820
|
+
*
|
|
3821
|
+
* ## Why the old numbers cost seconds
|
|
3822
|
+
*
|
|
3823
|
+
* `-probesize` is a BYTE budget, and 1 MB of a 640x360 sub-stream is tens of
|
|
3824
|
+
* seconds of video — so `-analyzeduration 1s` never got the chance to stop it
|
|
3825
|
+
* and each open ran until the byte budget filled. Zero and 32 make the probe
|
|
3826
|
+
* return from the SDP, which already declares the codec, without reading media.
|
|
3827
|
+
*
|
|
3828
|
+
* Measured on this hub, the two sources of the live grid, three runs each,
|
|
3829
|
+
* production input args otherwise identical — time to the first composed frame,
|
|
3830
|
+
* and the skew read off the two burnt-in clocks in that frame:
|
|
3831
|
+
*
|
|
3832
|
+
* ```
|
|
3833
|
+
* 1 s / 1 MB 8986, 9728, 9712 ms skew 5 s, 5 s, 4 s
|
|
3834
|
+
* 0 / 32 2281, 2270, 2304 ms skew 1 s, 1 s, 0 s
|
|
3835
|
+
* ```
|
|
3836
|
+
*
|
|
3837
|
+
* The same numbers are the ~9 s cold start the operator had accepted: it was a
|
|
3838
|
+
* SUM of the opens, never the wait for the slowest source.
|
|
3839
|
+
*
|
|
3840
|
+
* Checked before shipping, because a probe that reads nothing has to survive
|
|
3841
|
+
* what it is not told: h264, h265 and a derived (`mid-to-low`) source all open
|
|
3842
|
+
* with `rc=0`, a 20 s run produces 200 frames of 200 either way (so the pacing
|
|
3843
|
+
* this file already lost once is untouched), and the skew is still 0 at 25 s
|
|
3844
|
+
* into a run — it is set at start-up and does not drift.
|
|
3845
|
+
*
|
|
3846
|
+
* What remains is the spread in when each source's first key frame arrives, and
|
|
3847
|
+
* a `/muted` dial waits for the next IDR. That spread is small here; if it ever
|
|
3848
|
+
* is not, the answer is to start the inputs from a join point we hold, NOT to
|
|
3849
|
+
* re-time the inputs (see `useWallclockTimestamps` below).
|
|
3850
|
+
*/
|
|
3851
|
+
var ANALYZE_DURATION_US = 0;
|
|
3852
|
+
var PROBE_SIZE_BYTES = 32;
|
|
3853
|
+
function inputPlanFor(source) {
|
|
3854
|
+
return {
|
|
3855
|
+
url: source.url,
|
|
3856
|
+
rtspTransport: "tcp",
|
|
3857
|
+
fflags: ["+discardcorrupt"],
|
|
3858
|
+
lowDelay: true,
|
|
3859
|
+
analyzeDurationUs: ANALYZE_DURATION_US,
|
|
3860
|
+
probeSizeBytes: PROBE_SIZE_BYTES
|
|
3861
|
+
};
|
|
3862
|
+
}
|
|
3863
|
+
/**
|
|
3864
|
+
* @throws when the layout addresses an input the sources do not contain, or
|
|
3865
|
+
* when there is nothing to compose. Both are plan errors: ffmpeg would refuse
|
|
3866
|
+
* them at start-up with a message about a filter pad, which names the graph
|
|
3867
|
+
* rather than the configuration that produced it.
|
|
3868
|
+
*/
|
|
3869
|
+
function gridStreamInvocation(input) {
|
|
3870
|
+
if (input.sources.length === 0 || input.layout.cells.length === 0) throw new Error("camera-grid: a composite needs at least one cell with a source before it can emit anything");
|
|
3871
|
+
for (const cell of input.layout.cells) if (cell.inputIndex < 0 || cell.inputIndex >= input.sources.length) throw new Error(`camera-grid: cell addresses input ordinal ${cell.inputIndex}, but only ${input.sources.length} input(s) were acquired`);
|
|
3872
|
+
const graph = buildGridFilterGraph(input.layout);
|
|
3873
|
+
const [first, ...rest] = input.sources;
|
|
3874
|
+
if (first === void 0) throw new Error("camera-grid: a composite needs at least one cell with a source");
|
|
3875
|
+
const video = {
|
|
3876
|
+
kind: "encode",
|
|
3877
|
+
encoder: input.encoder,
|
|
3878
|
+
preset: PRESET,
|
|
3879
|
+
tune: TUNE,
|
|
3880
|
+
pixelFormat: PIXEL_FORMAT,
|
|
3881
|
+
fps: input.fps,
|
|
3882
|
+
gopFrames: input.fps * GOP_SECONDS,
|
|
3883
|
+
bitrateKbps: input.bitrateKbps,
|
|
3884
|
+
scale: null
|
|
3885
|
+
};
|
|
3886
|
+
return {
|
|
3887
|
+
logLevel: "error",
|
|
3888
|
+
decodeHwAccel: input.decodeHwAccel,
|
|
3889
|
+
input: inputPlanFor(first),
|
|
3890
|
+
extraInputs: rest.map(inputPlanFor),
|
|
3891
|
+
filterGraph: graph,
|
|
3892
|
+
video,
|
|
3893
|
+
audio: { kind: "none" },
|
|
3894
|
+
threadCount: 0,
|
|
3895
|
+
outputArgs: [],
|
|
3896
|
+
sink: {
|
|
3897
|
+
kind: "stdout",
|
|
3898
|
+
container: "flv"
|
|
3899
|
+
}
|
|
3900
|
+
};
|
|
3901
|
+
}
|
|
3902
|
+
//#endregion
|
|
3903
|
+
//#region src/builtins/camera-grid/grid-child.ts
|
|
3904
|
+
/**
|
|
3905
|
+
* Spawning the composition, through the ONE primitive.
|
|
3906
|
+
*
|
|
3907
|
+
* `FfmpegProcess` (`@camstack/types`) owns spawn, the first-data deadline, the
|
|
3908
|
+
* hardware→software retry, exit classification and the bounded restart. This
|
|
3909
|
+
* file owns only the PLUMBING — which bytes go where — because that is the one
|
|
3910
|
+
* thing the primitive deliberately does not own.
|
|
3911
|
+
*
|
|
3912
|
+
* `maxRestarts: 0`. A composite is demand-driven: if the child dies, the
|
|
3913
|
+
* session tells every consumer why and tears down, and the consumer's next read
|
|
3914
|
+
* starts a cold one with freshly acquired sources. A restart inside the process
|
|
3915
|
+
* would reuse broker handles that may already have been released.
|
|
3916
|
+
*/
|
|
3917
|
+
/** No first-data deadline retry loop: one attempt, and the session hears about it. */
|
|
3918
|
+
var FIRST_DATA_TIMEOUT_MS = 15e3;
|
|
3919
|
+
async function startGridChild(ctx, plan, sources, onEnded) {
|
|
3920
|
+
const invocation = (decodeHwAccel) => gridStreamInvocation({
|
|
3921
|
+
layout: plan.layout,
|
|
3922
|
+
sources: plan.sourceDeviceIds.map((deviceId, index) => ({
|
|
3923
|
+
deviceId,
|
|
3924
|
+
url: sources[index]?.url ?? ""
|
|
3925
|
+
})),
|
|
3926
|
+
decodeHwAccel,
|
|
3927
|
+
encoder: plan.encoder,
|
|
3928
|
+
fps: plan.fps,
|
|
3929
|
+
bitrateKbps: plan.bitrateKbps
|
|
3930
|
+
});
|
|
3931
|
+
let stdout = null;
|
|
3932
|
+
const process = new _camstack_types_node.FfmpegProcess({
|
|
3933
|
+
binaryPath: ctx.binaryPath,
|
|
3934
|
+
buildArgs: (decodeHwAccel) => require_dist.buildFfmpegArgs(invocation(decodeHwAccel)),
|
|
3935
|
+
decodeHwAccel: plan.decodeHwAccel,
|
|
3936
|
+
logger: ctx.logger,
|
|
3937
|
+
deviceId: ctx.deviceId,
|
|
3938
|
+
role: "camera-grid",
|
|
3939
|
+
tags: {
|
|
3940
|
+
cells: plan.layout.cells.length,
|
|
3941
|
+
inputs: plan.sourceDeviceIds.length
|
|
3942
|
+
},
|
|
3943
|
+
firstDataTimeoutMs: FIRST_DATA_TIMEOUT_MS,
|
|
3944
|
+
maxRestarts: 0,
|
|
3945
|
+
onChild: (child) => {
|
|
3946
|
+
if (child.stdout) stdout = child.stdout;
|
|
3947
|
+
child.stderr?.on("data", () => {});
|
|
3948
|
+
},
|
|
3949
|
+
onExit: (exit) => {
|
|
3950
|
+
onEnded(exit.classification);
|
|
3951
|
+
}
|
|
3952
|
+
});
|
|
3953
|
+
await process.start();
|
|
3954
|
+
if (stdout === null) {
|
|
3955
|
+
await process.stop();
|
|
3956
|
+
throw new Error("camera-grid: the composition child produced no stdout to read");
|
|
3957
|
+
}
|
|
3958
|
+
return {
|
|
3959
|
+
stdout,
|
|
3960
|
+
stop: async () => {
|
|
3961
|
+
await process.stop();
|
|
3962
|
+
}
|
|
3963
|
+
};
|
|
3964
|
+
}
|
|
3965
|
+
//#endregion
|
|
3966
|
+
exports.CameraGridAddon = CameraGridAddon;
|
|
3967
|
+
exports.GRID_CAM_STREAM_ID = GRID_CAM_STREAM_ID;
|
|
3968
|
+
exports.GRID_PROFILES = GRID_PROFILES;
|
|
3969
|
+
exports.GRID_SILENCED_CAP_NAMES = GRID_SILENCED_CAP_NAMES;
|
|
3970
|
+
exports.GridCameraDevice = GridCameraDevice;
|
|
3971
|
+
exports.GridFrameSampler = GridFrameSampler;
|
|
3972
|
+
exports.GridLastFrameFileStore = GridLastFrameFileStore;
|
|
3973
|
+
exports.GridSnapshotSource = GridSnapshotSource;
|
|
3974
|
+
exports.GridStreamRelay = GridStreamRelay;
|
|
3975
|
+
exports.GridStreamSession = GridStreamSession;
|
|
3976
|
+
exports.buildGridCameraDeclarations = buildGridCameraDeclarations;
|
|
3977
|
+
exports.buildGridFilterGraph = buildGridFilterGraph;
|
|
3978
|
+
exports.default = CameraGridAddon;
|
|
3979
|
+
exports.deriveGridCanvas = deriveGridCanvas;
|
|
3980
|
+
exports.gridCamStreamId = gridCamStreamId;
|
|
3981
|
+
exports.gridCameraReconciliationIndex = gridCameraReconciliationIndex;
|
|
3982
|
+
exports.gridPlanFor = gridPlanFor;
|
|
3983
|
+
exports.gridProfilePlans = gridProfilePlans;
|
|
3984
|
+
exports.gridSnapshotAnswerFor = gridSnapshotAnswerFor;
|
|
3985
|
+
exports.gridSourceDial = gridSourceDial;
|
|
3986
|
+
exports.gridStreamDescriptor = gridStreamDescriptor;
|
|
3987
|
+
exports.gridStreamInvocation = gridStreamInvocation;
|
|
3988
|
+
exports.installGridCameraRuntime = installGridCameraRuntime;
|
|
3989
|
+
exports.newGridCameraStableId = newGridCameraStableId;
|
|
3990
|
+
exports.normalizeGridRows = normalizeGridRows;
|
|
3991
|
+
exports.parseGridStreamPath = parseGridStreamPath;
|
|
3992
|
+
exports.readGridInstances = readGridInstances;
|
|
3993
|
+
exports.silenceAnalysisFor = silenceAnalysisFor;
|
|
3994
|
+
exports.startGridChild = startGridChild;
|