@camstack/addon-post-analysis 1.2.219 → 1.2.221

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.
@@ -5375,6 +5375,86 @@ var ZodIssueCode = {
5375
5375
  /** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
5376
5376
  var ZodFirstPartyTypeKind;
5377
5377
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5378
+ //#endregion
5379
+ //#region ../types/dist/sleep-BnujYGPe.mjs
5380
+ /**
5381
+ * The audio chunk plane's byte format, and the ONE expansion from a coded
5382
+ * window to float samples (D455).
5383
+ *
5384
+ * ## Why a format at all
5385
+ *
5386
+ * D450 took the plane off its 8 → 16 kHz upsample: it carries the SOURCE
5387
+ * RATE, and the one consumer that needs 16 kHz resamples next to the model.
5388
+ * It left the FORMAT alone — the broker still turned each G.711 byte into a
5389
+ * 4-byte f32le sample before the bytes entered the transport, so every leg of
5390
+ * the plane carried four times the source. The plane crosses hub-main twice on
5391
+ * the way to the analyzer, and the fleet's G.711 cameras are ~79 % of it.
5392
+ *
5393
+ * So the plane carries the source BYTES too, and whoever needs floats expands
5394
+ * them where it needs them. That is the same argument D450 made for the rate,
5395
+ * one step further along the same wire.
5396
+ *
5397
+ * ## Why the expansion lives here
5398
+ *
5399
+ * Two packages need it and they must never disagree: `addon-pipeline`'s broker
5400
+ * (which still has to serve a subscriber that did NOT ask for coded bytes —
5401
+ * `AudioChunkPlane` expands per subscription) and
5402
+ * `addon-pipeline-orchestrator`'s `AudioWindowAccumulator` (which flushes an
5403
+ * f32le window to the analyzer cap, whose `AudioChunkInput` contract is
5404
+ * unchanged and stays f32le). Both bundle the bare `@camstack/types` entry
5405
+ * into their own dist (`self-contained` externals), so this travels with a
5406
+ * `camstack deploy` and needs no published server.
5407
+ *
5408
+ * A second μ-law table anywhere else is the defect this module exists to
5409
+ * prevent. (`stream-broker.ts`'s `mulawToPcm` / `alawToPcm` are the ENCODE
5410
+ * direction for the WebRTC egress — a different transform, not a copy.)
5411
+ *
5412
+ * ## Absent means f32le
5413
+ *
5414
+ * `format` is optional on the wire and its absence means `f32le` — today's
5415
+ * bytes, byte for byte. A peer that never heard of the field is served what it
5416
+ * has always been served, because the broker only emits a coded window to a
5417
+ * subscription that DECLARED it accepts one (`AudioSubscribeOptions.accept`).
5418
+ * That is the D448 `rawForward` negotiation, and it is what makes this
5419
+ * deployable one addon at a time across three nodes.
5420
+ */
5421
+ /** Every byte format the audio chunk plane can carry. `f32le` is the default. */
5422
+ var AUDIO_CHUNK_FORMATS = [
5423
+ "f32le",
5424
+ "pcmu",
5425
+ "pcma"
5426
+ ];
5427
+ /**
5428
+ * Build the μ-law decode table (ITU-T G.711). Each of the 256 byte values maps
5429
+ * to a 16-bit PCM sample, normalised to [-1.0, 1.0] for f32le output.
5430
+ *
5431
+ * Moved here verbatim from `audio-rtp-decoder.ts`, which no longer decodes:
5432
+ * it buffers the coded bytes and the plane's consumers expand.
5433
+ */
5434
+ function buildUlawTable() {
5435
+ const table = new Float32Array(256);
5436
+ for (let i = 0; i < 256; i++) {
5437
+ const complemented = ~i & 255;
5438
+ const sign = (complemented & 128) !== 0 ? -1 : 1;
5439
+ const exponent = complemented >> 4 & 7;
5440
+ table[i] = sign * ((8 * (complemented & 15) + 132 << exponent) - 132) / 32768;
5441
+ }
5442
+ return table;
5443
+ }
5444
+ /** Build the A-law decode table (ITU-T G.711). */
5445
+ function buildAlawTable() {
5446
+ const table = new Float32Array(256);
5447
+ for (let i = 0; i < 256; i++) {
5448
+ const xored = i ^ 85;
5449
+ const sign = (xored & 128) !== 0 ? 1 : -1;
5450
+ const exponent = xored >> 4 & 7;
5451
+ const mantissa = xored & 15;
5452
+ table[i] = sign * (exponent === 0 ? 16 * mantissa + 8 : 16 * mantissa + 264 << exponent - 1) / 32768;
5453
+ }
5454
+ return table;
5455
+ }
5456
+ buildUlawTable();
5457
+ buildAlawTable();
5378
5458
  Object.fromEntries([
5379
5459
  {
5380
5460
  id: "overview",
@@ -6667,11 +6747,20 @@ var SubscribeFramesResultSchema = object({
6667
6747
  * (the wire-serialisable supertype of `Buffer`) to match `DecodedFrameSchema`
6668
6748
  * / `EncodedPacketSchema`'s precedent; a `Buffer` is assignable to it.
6669
6749
  */
6750
+ var AudioChunkFormatSchema = _enum(AUDIO_CHUNK_FORMATS);
6670
6751
  var DecodedAudioChunkSchema = object({
6671
6752
  data: _instanceof(Uint8Array),
6672
6753
  sampleRate: number().int().positive(),
6673
6754
  channels: number().int().positive(),
6674
- timestamp: number()
6755
+ timestamp: number(),
6756
+ /**
6757
+ * Byte format of `data`. ABSENT MEANS `f32le` — today's bytes, byte for
6758
+ * byte, for any peer that never heard of this field. A coded window
6759
+ * (`pcmu` / `pcma`, one byte per sample) is only ever emitted to a
6760
+ * subscription that DECLARED it accepts one, so absence can never mean
6761
+ * "coded bytes a consumer will read as floats" (D455).
6762
+ */
6763
+ format: AudioChunkFormatSchema.optional()
6675
6764
  });
6676
6765
  /**
6677
6766
  * Input for `stream-broker.subscribeAudioChunks` (Phase 5 / D9). The
@@ -6683,7 +6772,18 @@ var DecodedAudioChunkSchema = object({
6683
6772
  var SubscribeAudioChunksInputSchema = object({
6684
6773
  brokerId: string(),
6685
6774
  /** Short caller-identity tag (`audio-analyzer`, …) for `listClients`. */
6686
- tag: string().optional()
6775
+ tag: string().optional(),
6776
+ /**
6777
+ * Byte formats this subscriber can READ, best first. The broker serves the
6778
+ * chunk's own format when it is in this list and expands to `f32le`
6779
+ * otherwise, so a subscriber is never handed bytes it cannot interpret.
6780
+ *
6781
+ * Absent (or without the source format) means `f32le` — the behaviour every
6782
+ * subscriber had before D455, unchanged. This is the negotiation half of
6783
+ * the source-bytes lever: it is what lets the broker and its consumers
6784
+ * deploy one at a time across three nodes.
6785
+ */
6786
+ accept: array(AudioChunkFormatSchema).readonly().optional()
6687
6787
  });
6688
6788
  /** Result of `stream-broker.subscribeAudioChunks`. */
6689
6789
  var SubscribeAudioChunksResultSchema = object({
@@ -11239,6 +11339,51 @@ var AudioAnalysisSettingsSchema = object({
11239
11339
  minConfidence: number().min(0).max(1).default(.3),
11240
11340
  allowedClasses: array(string()).default([])
11241
11341
  });
11342
+ /**
11343
+ * `attachDevice` — the analyzer PULLS a camera's audio from the broker (D461).
11344
+ *
11345
+ * Until D461 the orchestrator drained the broker's chunk plane, accumulated
11346
+ * ~1 s windows and pushed them back out as `analyseChunk`. It neither produced
11347
+ * nor consumed the audio: the PCM crossed hub-main twice for a process that
11348
+ * only buffered it. `attachDevice` inverts the direction — the analyzer opens
11349
+ * its own `subscribeAudioChunks` against the broker and the subscriber IS the
11350
+ * decoder, so the coded G.711 bytes D455 put on the plane stay coded all the
11351
+ * way to the one expansion that feeds the model.
11352
+ *
11353
+ * The orchestrator still owns the POLICY (the `audioMode` gate, the on-motion
11354
+ * window, the per-device node assignment, the settings read) and therefore
11355
+ * still owns the attach/detach pair. It no longer owns the bytes.
11356
+ */
11357
+ var AudioAttachDeviceInputSchema = object({
11358
+ deviceId: number(),
11359
+ /** Broker id (`<deviceId>/<camStreamId>`) carrying this camera's audio. */
11360
+ brokerId: string(),
11361
+ /**
11362
+ * `clusterRoles.ingestNode` — the node whose broker owns the source dial.
11363
+ * Every `streamBroker` call the attachment makes is pinned to it, exactly as
11364
+ * the orchestrator's poller pinned them before the move.
11365
+ */
11366
+ ingestNodeId: string(),
11367
+ /**
11368
+ * Resolved once by the orchestrator at attach time, exactly as it was read
11369
+ * once per subscription before D461. The analyzer does NOT re-resolve per
11370
+ * window: a settings change re-attaches, which is what always happened.
11371
+ */
11372
+ settings: AudioAnalysisSettingsSchema
11373
+ });
11374
+ var AudioAttachDeviceResultSchema = object({
11375
+ /** False only when the analyzer is shutting down and refused to attach. */
11376
+ attached: boolean(),
11377
+ /**
11378
+ * True when the attachment replaced a live one for the same device. An
11379
+ * attach is idempotent by REPLACEMENT — two pollers on one camera would
11380
+ * double the broker's fanout and neither would know about the other.
11381
+ */
11382
+ replaced: boolean()
11383
+ });
11384
+ var AudioDetachDeviceResultSchema = object({
11385
+ /** False when no attachment existed — detach is idempotent. */
11386
+ detached: boolean() });
11242
11387
  var AudioClassificationResultSchema = object({
11243
11388
  labels: array(AudioClassificationLabelSchema).readonly(),
11244
11389
  rawLabels: array(AudioClassificationLabelSchema).readonly().optional(),
@@ -11247,7 +11392,7 @@ var AudioClassificationResultSchema = object({
11247
11392
  method(object({
11248
11393
  chunk: AudioChunkInputSchema,
11249
11394
  settings: AudioAnalysisSettingsSchema
11250
- }), AudioAnalysisResultSchema.nullable(), { kind: "mutation" }), method(AudioChunkInputSchema, AudioClassificationResultSchema, { timeoutMs: 3e4 }), method(_void(), boolean()), method(_void(), _void(), { kind: "mutation" }), method(_void(), object({ backend: string() }), {
11395
+ }), AudioAnalysisResultSchema.nullable(), { kind: "mutation" }), method(AudioChunkInputSchema, AudioClassificationResultSchema, { timeoutMs: 3e4 }), method(AudioAttachDeviceInputSchema, AudioAttachDeviceResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), AudioDetachDeviceResultSchema, { kind: "mutation" }), method(_void(), boolean()), method(_void(), _void(), { kind: "mutation" }), method(_void(), object({ backend: string() }), {
11251
11396
  kind: "mutation",
11252
11397
  auth: "admin"
11253
11398
  });
@@ -16219,24 +16364,6 @@ method(object({}), array(TargetKindSchema)), method(object({}), array(TargetSche
16219
16364
  targetId: string(),
16220
16365
  enabled: boolean()
16221
16366
  }), _void(), { kind: "mutation" });
16222
- var MACRO_LABELS = [
16223
- {
16224
- id: "person",
16225
- name: "Person"
16226
- },
16227
- {
16228
- id: "vehicle",
16229
- name: "Vehicle"
16230
- },
16231
- {
16232
- id: "animal",
16233
- name: "Animal"
16234
- },
16235
- {
16236
- id: "package",
16237
- name: "Package"
16238
- }
16239
- ];
16240
16367
  /**
16241
16368
  * The class names a per-class COUNT can ever be keyed on — the macro ids, and
16242
16369
  * only those.
@@ -16254,7 +16381,24 @@ var MACRO_LABELS = [
16254
16381
  * does not go through the engine's macro-expanding `expandClassSelector`), two
16255
16382
  * live rules were authored on `car`, and both counters read 0 forever.
16256
16383
  */
16257
- var DETECTION_MACRO_CLASSES = new Set(MACRO_LABELS.map((l) => l.id));
16384
+ var DETECTION_MACRO_CLASSES = new Set([
16385
+ {
16386
+ id: "person",
16387
+ name: "Person"
16388
+ },
16389
+ {
16390
+ id: "vehicle",
16391
+ name: "Vehicle"
16392
+ },
16393
+ {
16394
+ id: "animal",
16395
+ name: "Animal"
16396
+ },
16397
+ {
16398
+ id: "package",
16399
+ name: "Package"
16400
+ }
16401
+ ].map((l) => l.id));
16258
16402
  /** True when `className` is a macro the detector can actually emit (and hence a
16259
16403
  * class a count can be keyed on) — see {@link DETECTION_MACRO_CLASSES}. */
16260
16404
  function isDetectionMacroClass(className) {
@@ -27767,8 +27911,8 @@ includeCrops: boolean().optional() }).optional(), array(IdentitySchema).readonly
27767
27911
  *
27768
27912
  * An **empty array reads NOTHING** — `[]` is an empty page, never
27769
27913
  * "every camera". A request for no devices is a request, not an
27770
- * omission; same contract as `deviceManager.listFleet` and
27771
- * `pipelineAnalytics.listRecentTracks`.
27914
+ * omission; same contract as `deviceManager.listAll`'s `deviceIds`
27915
+ * and `pipelineAnalytics.listRecentTracks`.
27772
27916
  *
27773
27917
  * Absent (`undefined`) is the omission, and keeps the cluster-wide view.
27774
27918
  */
@@ -36652,12 +36796,24 @@ Object.freeze({
36652
36796
  addonId: null,
36653
36797
  access: "create"
36654
36798
  },
36799
+ "audioAnalyzer.attachDevice": {
36800
+ capName: "audio-analyzer",
36801
+ capScope: "system",
36802
+ addonId: null,
36803
+ access: "create"
36804
+ },
36655
36805
  "audioAnalyzer.classify": {
36656
36806
  capName: "audio-analyzer",
36657
36807
  capScope: "system",
36658
36808
  addonId: null,
36659
36809
  access: "view"
36660
36810
  },
36811
+ "audioAnalyzer.detachDevice": {
36812
+ capName: "audio-analyzer",
36813
+ capScope: "system",
36814
+ addonId: null,
36815
+ access: "create"
36816
+ },
36661
36817
  "audioAnalyzer.dispose": {
36662
36818
  capName: "audio-analyzer",
36663
36819
  capScope: "system",
@@ -42501,11 +42657,21 @@ Object.freeze({
42501
42657
  form: "single",
42502
42658
  optional: false
42503
42659
  }],
42660
+ "audioAnalyzer.attachDevice": [{
42661
+ name: "deviceId",
42662
+ form: "single",
42663
+ optional: false
42664
+ }],
42504
42665
  "audioAnalyzer.classify": [{
42505
42666
  name: "deviceId",
42506
42667
  form: "single",
42507
42668
  optional: true
42508
42669
  }],
42670
+ "audioAnalyzer.detachDevice": [{
42671
+ name: "deviceId",
42672
+ form: "single",
42673
+ optional: false
42674
+ }],
42509
42675
  "audioMetrics.getCurrentSnapshot": [{
42510
42676
  name: "deviceId",
42511
42677
  form: "single",
@@ -44357,6 +44523,52 @@ Object.freeze({
44357
44523
  "network-access": "ingress",
44358
44524
  "smtp-provider": "email"
44359
44525
  });
44526
+ var G711_SCALE_CORRECTION_DB = {
44527
+ PCMU: 20 * Math.log10(4),
44528
+ PCMA: 20 * Math.log10(8)
44529
+ };
44530
+ /**
44531
+ * Restate a dBFS number that was MEASURED through the pre-epoch decoder as the
44532
+ * same intent on the ITU-T scale (D460).
44533
+ *
44534
+ * ## When this applies, and when it is the wrong thing to reach for
44535
+ *
44536
+ * An absolute-dBFS number in this repo is one of two things, and only one of
44537
+ * them converts:
44538
+ *
44539
+ * - **A statement about the scale** — "-55 dBFS is near silence", "-25 dBFS
44540
+ * is loud". It was true on the ITU-T scale before the epoch and it is true
44541
+ * after. The defect was never in the number; it was that 19 of this hub's
44542
+ * 25 cameras did not obey it. Converting such a number takes something
44543
+ * correct and makes it wrong, in order to preserve a bug.
44544
+ * - **A measurement taken through the old decoder** — a value someone read
44545
+ * off a meter that under-reported by exactly 4× (PCMU) or 8× (PCMA). It
44546
+ * describes a sound that was really {@link G711_SCALE_CORRECTION_DB} dB
44547
+ * louder. That is what this function is for.
44548
+ *
44549
+ * Telling the two apart is a question about PROVENANCE, not about arithmetic,
44550
+ * and it cannot be answered from the number. It is answered by the comment the
44551
+ * author left — which is why `scripts/check-dbfs-era.mts` makes leaving one
44552
+ * mandatory.
44553
+ *
44554
+ * ## Why a function and not a typed-in number
44555
+ *
44556
+ * `-55 + 12.04` written into a source file is, six months later, completely
44557
+ * indistinguishable from a threshold somebody simply preferred. Calling this
44558
+ * keeps the derivation, the law, and the original measurement all visible at
44559
+ * the call site, so a future reader can disagree with the *premise* instead of
44560
+ * having to reverse-engineer the sum.
44561
+ *
44562
+ * **This is not a runtime gain.** It converts an authored CONSTANT once, where
44563
+ * it is declared. It must never be applied to a live sample or a stored
44564
+ * `AudioEvent.dbfs`: the decoder is correct now, and a second authority
44565
+ * adjusting numbers the decoder already got right is the original defect with
44566
+ * an extra place to argue with (D459).
44567
+ */
44568
+ function ituDbfsFromPreEpoch(law, authoredDbfs) {
44569
+ return authoredDbfs + G711_SCALE_CORRECTION_DB[law];
44570
+ }
44571
+ Math.round(ituDbfsFromPreEpoch("PCMU", -55));
44360
44572
  /** Schema defaults — an untouched sub-field must author exactly these. */
44361
44573
  var NC_AUDIO_DEFAULTS = {
44362
44574
  hitPercent: 60,
@@ -45570,6 +45782,12 @@ Object.defineProperty(exports, "EventCategory", {
45570
45782
  return EventCategory;
45571
45783
  }
45572
45784
  });
45785
+ Object.defineProperty(exports, "FIRST_LEVEL_MACRO_CLASSES", {
45786
+ enumerable: true,
45787
+ get: function() {
45788
+ return FIRST_LEVEL_MACRO_CLASSES;
45789
+ }
45790
+ });
45573
45791
  Object.defineProperty(exports, "FULL_IMAGE_BBOX", {
45574
45792
  enumerable: true,
45575
45793
  get: function() {
@@ -45588,12 +45806,6 @@ Object.defineProperty(exports, "LabelAttributionSchema", {
45588
45806
  return LabelAttributionSchema;
45589
45807
  }
45590
45808
  });
45591
- Object.defineProperty(exports, "MACRO_LABELS", {
45592
- enumerable: true,
45593
- get: function() {
45594
- return MACRO_LABELS;
45595
- }
45596
- });
45597
45809
  Object.defineProperty(exports, "MAX_ARCHIVED_DEBUG_NOTES", {
45598
45810
  enumerable: true,
45599
45811
  get: function() {