@camstack/addon-decoder-nodeav 1.2.95 → 1.2.97

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/dist/index.js CHANGED
@@ -5349,6 +5349,86 @@ var ZodIssueCode = {
5349
5349
  /** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
5350
5350
  var ZodFirstPartyTypeKind;
5351
5351
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5352
+ //#endregion
5353
+ //#region ../types/dist/sleep-BnujYGPe.mjs
5354
+ /**
5355
+ * The audio chunk plane's byte format, and the ONE expansion from a coded
5356
+ * window to float samples (D455).
5357
+ *
5358
+ * ## Why a format at all
5359
+ *
5360
+ * D450 took the plane off its 8 → 16 kHz upsample: it carries the SOURCE
5361
+ * RATE, and the one consumer that needs 16 kHz resamples next to the model.
5362
+ * It left the FORMAT alone — the broker still turned each G.711 byte into a
5363
+ * 4-byte f32le sample before the bytes entered the transport, so every leg of
5364
+ * the plane carried four times the source. The plane crosses hub-main twice on
5365
+ * the way to the analyzer, and the fleet's G.711 cameras are ~79 % of it.
5366
+ *
5367
+ * So the plane carries the source BYTES too, and whoever needs floats expands
5368
+ * them where it needs them. That is the same argument D450 made for the rate,
5369
+ * one step further along the same wire.
5370
+ *
5371
+ * ## Why the expansion lives here
5372
+ *
5373
+ * Two packages need it and they must never disagree: `addon-pipeline`'s broker
5374
+ * (which still has to serve a subscriber that did NOT ask for coded bytes —
5375
+ * `AudioChunkPlane` expands per subscription) and
5376
+ * `addon-pipeline-orchestrator`'s `AudioWindowAccumulator` (which flushes an
5377
+ * f32le window to the analyzer cap, whose `AudioChunkInput` contract is
5378
+ * unchanged and stays f32le). Both bundle the bare `@camstack/types` entry
5379
+ * into their own dist (`self-contained` externals), so this travels with a
5380
+ * `camstack deploy` and needs no published server.
5381
+ *
5382
+ * A second μ-law table anywhere else is the defect this module exists to
5383
+ * prevent. (`stream-broker.ts`'s `mulawToPcm` / `alawToPcm` are the ENCODE
5384
+ * direction for the WebRTC egress — a different transform, not a copy.)
5385
+ *
5386
+ * ## Absent means f32le
5387
+ *
5388
+ * `format` is optional on the wire and its absence means `f32le` — today's
5389
+ * bytes, byte for byte. A peer that never heard of the field is served what it
5390
+ * has always been served, because the broker only emits a coded window to a
5391
+ * subscription that DECLARED it accepts one (`AudioSubscribeOptions.accept`).
5392
+ * That is the D448 `rawForward` negotiation, and it is what makes this
5393
+ * deployable one addon at a time across three nodes.
5394
+ */
5395
+ /** Every byte format the audio chunk plane can carry. `f32le` is the default. */
5396
+ var AUDIO_CHUNK_FORMATS = [
5397
+ "f32le",
5398
+ "pcmu",
5399
+ "pcma"
5400
+ ];
5401
+ /**
5402
+ * Build the μ-law decode table (ITU-T G.711). Each of the 256 byte values maps
5403
+ * to a 16-bit PCM sample, normalised to [-1.0, 1.0] for f32le output.
5404
+ *
5405
+ * Moved here verbatim from `audio-rtp-decoder.ts`, which no longer decodes:
5406
+ * it buffers the coded bytes and the plane's consumers expand.
5407
+ */
5408
+ function buildUlawTable() {
5409
+ const table = new Float32Array(256);
5410
+ for (let i = 0; i < 256; i++) {
5411
+ const complemented = ~i & 255;
5412
+ const sign = (complemented & 128) !== 0 ? -1 : 1;
5413
+ const exponent = complemented >> 4 & 7;
5414
+ table[i] = sign * ((8 * (complemented & 15) + 132 << exponent) - 132) / 32768;
5415
+ }
5416
+ return table;
5417
+ }
5418
+ /** Build the A-law decode table (ITU-T G.711). */
5419
+ function buildAlawTable() {
5420
+ const table = new Float32Array(256);
5421
+ for (let i = 0; i < 256; i++) {
5422
+ const xored = i ^ 85;
5423
+ const sign = (xored & 128) !== 0 ? 1 : -1;
5424
+ const exponent = xored >> 4 & 7;
5425
+ const mantissa = xored & 15;
5426
+ table[i] = sign * (exponent === 0 ? 16 * mantissa + 8 : 16 * mantissa + 264 << exponent - 1) / 32768;
5427
+ }
5428
+ return table;
5429
+ }
5430
+ buildUlawTable();
5431
+ buildAlawTable();
5352
5432
  Object.fromEntries([
5353
5433
  {
5354
5434
  id: "overview",
@@ -6641,11 +6721,20 @@ var SubscribeFramesResultSchema = object({
6641
6721
  * (the wire-serialisable supertype of `Buffer`) to match `DecodedFrameSchema`
6642
6722
  * / `EncodedPacketSchema`'s precedent; a `Buffer` is assignable to it.
6643
6723
  */
6724
+ var AudioChunkFormatSchema = _enum(AUDIO_CHUNK_FORMATS);
6644
6725
  var DecodedAudioChunkSchema = object({
6645
6726
  data: _instanceof(Uint8Array),
6646
6727
  sampleRate: number().int().positive(),
6647
6728
  channels: number().int().positive(),
6648
- timestamp: number()
6729
+ timestamp: number(),
6730
+ /**
6731
+ * Byte format of `data`. ABSENT MEANS `f32le` — today's bytes, byte for
6732
+ * byte, for any peer that never heard of this field. A coded window
6733
+ * (`pcmu` / `pcma`, one byte per sample) is only ever emitted to a
6734
+ * subscription that DECLARED it accepts one, so absence can never mean
6735
+ * "coded bytes a consumer will read as floats" (D455).
6736
+ */
6737
+ format: AudioChunkFormatSchema.optional()
6649
6738
  });
6650
6739
  /**
6651
6740
  * Input for `stream-broker.subscribeAudioChunks` (Phase 5 / D9). The
@@ -6657,7 +6746,18 @@ var DecodedAudioChunkSchema = object({
6657
6746
  var SubscribeAudioChunksInputSchema = object({
6658
6747
  brokerId: string(),
6659
6748
  /** Short caller-identity tag (`audio-analyzer`, …) for `listClients`. */
6660
- tag: string().optional()
6749
+ tag: string().optional(),
6750
+ /**
6751
+ * Byte formats this subscriber can READ, best first. The broker serves the
6752
+ * chunk's own format when it is in this list and expands to `f32le`
6753
+ * otherwise, so a subscriber is never handed bytes it cannot interpret.
6754
+ *
6755
+ * Absent (or without the source format) means `f32le` — the behaviour every
6756
+ * subscriber had before D455, unchanged. This is the negotiation half of
6757
+ * the source-bytes lever: it is what lets the broker and its consumers
6758
+ * deploy one at a time across three nodes.
6759
+ */
6760
+ accept: array(AudioChunkFormatSchema).readonly().optional()
6661
6761
  });
6662
6762
  /** Result of `stream-broker.subscribeAudioChunks`. */
6663
6763
  var SubscribeAudioChunksResultSchema = object({
@@ -10641,6 +10741,51 @@ var AudioAnalysisSettingsSchema = object({
10641
10741
  minConfidence: number().min(0).max(1).default(.3),
10642
10742
  allowedClasses: array(string()).default([])
10643
10743
  });
10744
+ /**
10745
+ * `attachDevice` — the analyzer PULLS a camera's audio from the broker (D461).
10746
+ *
10747
+ * Until D461 the orchestrator drained the broker's chunk plane, accumulated
10748
+ * ~1 s windows and pushed them back out as `analyseChunk`. It neither produced
10749
+ * nor consumed the audio: the PCM crossed hub-main twice for a process that
10750
+ * only buffered it. `attachDevice` inverts the direction — the analyzer opens
10751
+ * its own `subscribeAudioChunks` against the broker and the subscriber IS the
10752
+ * decoder, so the coded G.711 bytes D455 put on the plane stay coded all the
10753
+ * way to the one expansion that feeds the model.
10754
+ *
10755
+ * The orchestrator still owns the POLICY (the `audioMode` gate, the on-motion
10756
+ * window, the per-device node assignment, the settings read) and therefore
10757
+ * still owns the attach/detach pair. It no longer owns the bytes.
10758
+ */
10759
+ var AudioAttachDeviceInputSchema = object({
10760
+ deviceId: number(),
10761
+ /** Broker id (`<deviceId>/<camStreamId>`) carrying this camera's audio. */
10762
+ brokerId: string(),
10763
+ /**
10764
+ * `clusterRoles.ingestNode` — the node whose broker owns the source dial.
10765
+ * Every `streamBroker` call the attachment makes is pinned to it, exactly as
10766
+ * the orchestrator's poller pinned them before the move.
10767
+ */
10768
+ ingestNodeId: string(),
10769
+ /**
10770
+ * Resolved once by the orchestrator at attach time, exactly as it was read
10771
+ * once per subscription before D461. The analyzer does NOT re-resolve per
10772
+ * window: a settings change re-attaches, which is what always happened.
10773
+ */
10774
+ settings: AudioAnalysisSettingsSchema
10775
+ });
10776
+ var AudioAttachDeviceResultSchema = object({
10777
+ /** False only when the analyzer is shutting down and refused to attach. */
10778
+ attached: boolean(),
10779
+ /**
10780
+ * True when the attachment replaced a live one for the same device. An
10781
+ * attach is idempotent by REPLACEMENT — two pollers on one camera would
10782
+ * double the broker's fanout and neither would know about the other.
10783
+ */
10784
+ replaced: boolean()
10785
+ });
10786
+ var AudioDetachDeviceResultSchema = object({
10787
+ /** False when no attachment existed — detach is idempotent. */
10788
+ detached: boolean() });
10644
10789
  var AudioClassificationResultSchema = object({
10645
10790
  labels: array(AudioClassificationLabelSchema).readonly(),
10646
10791
  rawLabels: array(AudioClassificationLabelSchema).readonly().optional(),
@@ -10649,7 +10794,7 @@ var AudioClassificationResultSchema = object({
10649
10794
  method(object({
10650
10795
  chunk: AudioChunkInputSchema,
10651
10796
  settings: AudioAnalysisSettingsSchema
10652
- }), AudioAnalysisResultSchema.nullable(), { kind: "mutation" }), method(AudioChunkInputSchema, AudioClassificationResultSchema, { timeoutMs: 3e4 }), method(_void(), boolean()), method(_void(), _void(), { kind: "mutation" }), method(_void(), object({ backend: string() }), {
10797
+ }), 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() }), {
10653
10798
  kind: "mutation",
10654
10799
  auth: "admin"
10655
10800
  });
@@ -20315,6 +20460,14 @@ var NativeCropResultSchema = object({
20315
20460
  * set `encodeJpeg: true`; `bytes` is then absent.
20316
20461
  */
20317
20462
  jpeg: string().optional(),
20463
+ /**
20464
+ * The SAME compressed JPEG as `jpeg`, as bytes (D462). Present instead of
20465
+ * `jpeg` when the request set `acceptJpegBytes`; a request that did not gets
20466
+ * `jpeg` exactly as before. MsgPack and the mesh leg both carry binary —
20467
+ * `bytes` above has crossed this boundary as a `Uint8Array` all along — so
20468
+ * base64 was buying nothing but a multi-megabyte string in the relay's heap.
20469
+ */
20470
+ jpegBytes: _instanceof(Uint8Array).optional(),
20318
20471
  width: number().int().positive(),
20319
20472
  height: number().int().positive(),
20320
20473
  /**
@@ -20381,7 +20534,14 @@ var ParkTrackFrameResultSchema = discriminatedUnion("parked", [object({
20381
20534
  })]);
20382
20535
  /** A retrieved parcel — the runner's own JPEG, base64 for the wire. */
20383
20536
  var ParkedTrackFrameSchema = object({
20384
- jpeg: string(),
20537
+ /**
20538
+ * Base64 JPEG — the pre-D462 wire. OPTIONAL since D462: a request that set
20539
+ * `acceptJpegBytes` is answered in `jpegBytes` and this is then absent.
20540
+ * Exactly one of the two is present.
20541
+ */
20542
+ jpeg: string().optional(),
20543
+ /** The same JPEG as bytes, for a caller that declared it reads them (D462). */
20544
+ jpegBytes: _instanceof(Uint8Array).optional(),
20385
20545
  width: number().int().positive(),
20386
20546
  height: number().int().positive(),
20387
20547
  /** The frame instant the parcel shows (the caller's clock, echoed back). */
@@ -20968,6 +21128,13 @@ method(RunnerCameraConfigSchema, object({ success: literal(true) }), { kind: "mu
20968
21128
  bbox: NativeCropBboxSchema,
20969
21129
  maxWidth: number().int().positive().optional(),
20970
21130
  /**
21131
+ * The caller reads a `Uint8Array` (D462). When set, a JPEG answer comes
21132
+ * back in `jpegBytes` instead of base64 `jpeg`. Absent means the old
21133
+ * wire — never assume consent: a pre-D462 caller parses the field as
21134
+ * base64 and bytes would decode to garbage rather than fail.
21135
+ */
21136
+ acceptJpegBytes: boolean().optional(),
21137
+ /**
20971
21138
  * When `true`, the runner encodes the resolved crop to JPEG ON THE
20972
21139
  * OWNING NODE and returns it in `jpeg` (base64) INSTEAD of raw `bytes`.
20973
21140
  * Callers set this for CROSS-NODE fetches (`handle.nodeId` is a remote
@@ -21035,7 +21202,14 @@ method(RunnerCameraConfigSchema, object({ success: literal(true) }), { kind: "mu
21035
21202
  }), ParkTrackFrameResultSchema, { kind: "mutation" }), method(object({
21036
21203
  deviceId: number(),
21037
21204
  trackId: string(),
21038
- kind: ParkedFrameKindSchema
21205
+ kind: ParkedFrameKindSchema,
21206
+ /**
21207
+ * The caller reads a `Uint8Array` (D462). When set, a JPEG answer comes
21208
+ * back in `jpegBytes` instead of base64 `jpeg`. Absent means the old
21209
+ * wire — never assume consent: a pre-D462 caller parses the field as
21210
+ * base64 and bytes would decode to garbage rather than fail.
21211
+ */
21212
+ acceptJpegBytes: boolean().optional()
21039
21213
  }), ParkedTrackFrameSchema.nullable()), method(object({
21040
21214
  deviceId: number(),
21041
21215
  trackId: string()
@@ -30674,12 +30848,24 @@ Object.freeze({
30674
30848
  addonId: null,
30675
30849
  access: "create"
30676
30850
  },
30851
+ "audioAnalyzer.attachDevice": {
30852
+ capName: "audio-analyzer",
30853
+ capScope: "system",
30854
+ addonId: null,
30855
+ access: "create"
30856
+ },
30677
30857
  "audioAnalyzer.classify": {
30678
30858
  capName: "audio-analyzer",
30679
30859
  capScope: "system",
30680
30860
  addonId: null,
30681
30861
  access: "view"
30682
30862
  },
30863
+ "audioAnalyzer.detachDevice": {
30864
+ capName: "audio-analyzer",
30865
+ capScope: "system",
30866
+ addonId: null,
30867
+ access: "create"
30868
+ },
30683
30869
  "audioAnalyzer.dispose": {
30684
30870
  capName: "audio-analyzer",
30685
30871
  capScope: "system",
@@ -36523,11 +36709,21 @@ Object.freeze({
36523
36709
  form: "single",
36524
36710
  optional: false
36525
36711
  }],
36712
+ "audioAnalyzer.attachDevice": [{
36713
+ name: "deviceId",
36714
+ form: "single",
36715
+ optional: false
36716
+ }],
36526
36717
  "audioAnalyzer.classify": [{
36527
36718
  name: "deviceId",
36528
36719
  form: "single",
36529
36720
  optional: true
36530
36721
  }],
36722
+ "audioAnalyzer.detachDevice": [{
36723
+ name: "deviceId",
36724
+ form: "single",
36725
+ optional: false
36726
+ }],
36531
36727
  "audioMetrics.getCurrentSnapshot": [{
36532
36728
  name: "deviceId",
36533
36729
  form: "single",
@@ -38379,6 +38575,52 @@ Object.freeze({
38379
38575
  "network-access": "ingress",
38380
38576
  "smtp-provider": "email"
38381
38577
  });
38578
+ var G711_SCALE_CORRECTION_DB = {
38579
+ PCMU: 20 * Math.log10(4),
38580
+ PCMA: 20 * Math.log10(8)
38581
+ };
38582
+ /**
38583
+ * Restate a dBFS number that was MEASURED through the pre-epoch decoder as the
38584
+ * same intent on the ITU-T scale (D460).
38585
+ *
38586
+ * ## When this applies, and when it is the wrong thing to reach for
38587
+ *
38588
+ * An absolute-dBFS number in this repo is one of two things, and only one of
38589
+ * them converts:
38590
+ *
38591
+ * - **A statement about the scale** — "-55 dBFS is near silence", "-25 dBFS
38592
+ * is loud". It was true on the ITU-T scale before the epoch and it is true
38593
+ * after. The defect was never in the number; it was that 19 of this hub's
38594
+ * 25 cameras did not obey it. Converting such a number takes something
38595
+ * correct and makes it wrong, in order to preserve a bug.
38596
+ * - **A measurement taken through the old decoder** — a value someone read
38597
+ * off a meter that under-reported by exactly 4× (PCMU) or 8× (PCMA). It
38598
+ * describes a sound that was really {@link G711_SCALE_CORRECTION_DB} dB
38599
+ * louder. That is what this function is for.
38600
+ *
38601
+ * Telling the two apart is a question about PROVENANCE, not about arithmetic,
38602
+ * and it cannot be answered from the number. It is answered by the comment the
38603
+ * author left — which is why `scripts/check-dbfs-era.mts` makes leaving one
38604
+ * mandatory.
38605
+ *
38606
+ * ## Why a function and not a typed-in number
38607
+ *
38608
+ * `-55 + 12.04` written into a source file is, six months later, completely
38609
+ * indistinguishable from a threshold somebody simply preferred. Calling this
38610
+ * keeps the derivation, the law, and the original measurement all visible at
38611
+ * the call site, so a future reader can disagree with the *premise* instead of
38612
+ * having to reverse-engineer the sum.
38613
+ *
38614
+ * **This is not a runtime gain.** It converts an authored CONSTANT once, where
38615
+ * it is declared. It must never be applied to a live sample or a stored
38616
+ * `AudioEvent.dbfs`: the decoder is correct now, and a second authority
38617
+ * adjusting numbers the decoder already got right is the original defect with
38618
+ * an extra place to argue with (D459).
38619
+ */
38620
+ function ituDbfsFromPreEpoch(law, authoredDbfs) {
38621
+ return authoredDbfs + G711_SCALE_CORRECTION_DB[law];
38622
+ }
38623
+ Math.round(ituDbfsFromPreEpoch("PCMU", -55));
38382
38624
  /** Schema defaults — an untouched sub-field must author exactly these. */
38383
38625
  var NC_AUDIO_DEFAULTS = {
38384
38626
  hitPercent: 60,
package/dist/index.mjs CHANGED
@@ -5345,6 +5345,86 @@ var ZodIssueCode = {
5345
5345
  /** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
5346
5346
  var ZodFirstPartyTypeKind;
5347
5347
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5348
+ //#endregion
5349
+ //#region ../types/dist/sleep-BnujYGPe.mjs
5350
+ /**
5351
+ * The audio chunk plane's byte format, and the ONE expansion from a coded
5352
+ * window to float samples (D455).
5353
+ *
5354
+ * ## Why a format at all
5355
+ *
5356
+ * D450 took the plane off its 8 → 16 kHz upsample: it carries the SOURCE
5357
+ * RATE, and the one consumer that needs 16 kHz resamples next to the model.
5358
+ * It left the FORMAT alone — the broker still turned each G.711 byte into a
5359
+ * 4-byte f32le sample before the bytes entered the transport, so every leg of
5360
+ * the plane carried four times the source. The plane crosses hub-main twice on
5361
+ * the way to the analyzer, and the fleet's G.711 cameras are ~79 % of it.
5362
+ *
5363
+ * So the plane carries the source BYTES too, and whoever needs floats expands
5364
+ * them where it needs them. That is the same argument D450 made for the rate,
5365
+ * one step further along the same wire.
5366
+ *
5367
+ * ## Why the expansion lives here
5368
+ *
5369
+ * Two packages need it and they must never disagree: `addon-pipeline`'s broker
5370
+ * (which still has to serve a subscriber that did NOT ask for coded bytes —
5371
+ * `AudioChunkPlane` expands per subscription) and
5372
+ * `addon-pipeline-orchestrator`'s `AudioWindowAccumulator` (which flushes an
5373
+ * f32le window to the analyzer cap, whose `AudioChunkInput` contract is
5374
+ * unchanged and stays f32le). Both bundle the bare `@camstack/types` entry
5375
+ * into their own dist (`self-contained` externals), so this travels with a
5376
+ * `camstack deploy` and needs no published server.
5377
+ *
5378
+ * A second μ-law table anywhere else is the defect this module exists to
5379
+ * prevent. (`stream-broker.ts`'s `mulawToPcm` / `alawToPcm` are the ENCODE
5380
+ * direction for the WebRTC egress — a different transform, not a copy.)
5381
+ *
5382
+ * ## Absent means f32le
5383
+ *
5384
+ * `format` is optional on the wire and its absence means `f32le` — today's
5385
+ * bytes, byte for byte. A peer that never heard of the field is served what it
5386
+ * has always been served, because the broker only emits a coded window to a
5387
+ * subscription that DECLARED it accepts one (`AudioSubscribeOptions.accept`).
5388
+ * That is the D448 `rawForward` negotiation, and it is what makes this
5389
+ * deployable one addon at a time across three nodes.
5390
+ */
5391
+ /** Every byte format the audio chunk plane can carry. `f32le` is the default. */
5392
+ var AUDIO_CHUNK_FORMATS = [
5393
+ "f32le",
5394
+ "pcmu",
5395
+ "pcma"
5396
+ ];
5397
+ /**
5398
+ * Build the μ-law decode table (ITU-T G.711). Each of the 256 byte values maps
5399
+ * to a 16-bit PCM sample, normalised to [-1.0, 1.0] for f32le output.
5400
+ *
5401
+ * Moved here verbatim from `audio-rtp-decoder.ts`, which no longer decodes:
5402
+ * it buffers the coded bytes and the plane's consumers expand.
5403
+ */
5404
+ function buildUlawTable() {
5405
+ const table = new Float32Array(256);
5406
+ for (let i = 0; i < 256; i++) {
5407
+ const complemented = ~i & 255;
5408
+ const sign = (complemented & 128) !== 0 ? -1 : 1;
5409
+ const exponent = complemented >> 4 & 7;
5410
+ table[i] = sign * ((8 * (complemented & 15) + 132 << exponent) - 132) / 32768;
5411
+ }
5412
+ return table;
5413
+ }
5414
+ /** Build the A-law decode table (ITU-T G.711). */
5415
+ function buildAlawTable() {
5416
+ const table = new Float32Array(256);
5417
+ for (let i = 0; i < 256; i++) {
5418
+ const xored = i ^ 85;
5419
+ const sign = (xored & 128) !== 0 ? 1 : -1;
5420
+ const exponent = xored >> 4 & 7;
5421
+ const mantissa = xored & 15;
5422
+ table[i] = sign * (exponent === 0 ? 16 * mantissa + 8 : 16 * mantissa + 264 << exponent - 1) / 32768;
5423
+ }
5424
+ return table;
5425
+ }
5426
+ buildUlawTable();
5427
+ buildAlawTable();
5348
5428
  Object.fromEntries([
5349
5429
  {
5350
5430
  id: "overview",
@@ -6637,11 +6717,20 @@ var SubscribeFramesResultSchema = object({
6637
6717
  * (the wire-serialisable supertype of `Buffer`) to match `DecodedFrameSchema`
6638
6718
  * / `EncodedPacketSchema`'s precedent; a `Buffer` is assignable to it.
6639
6719
  */
6720
+ var AudioChunkFormatSchema = _enum(AUDIO_CHUNK_FORMATS);
6640
6721
  var DecodedAudioChunkSchema = object({
6641
6722
  data: _instanceof(Uint8Array),
6642
6723
  sampleRate: number().int().positive(),
6643
6724
  channels: number().int().positive(),
6644
- timestamp: number()
6725
+ timestamp: number(),
6726
+ /**
6727
+ * Byte format of `data`. ABSENT MEANS `f32le` — today's bytes, byte for
6728
+ * byte, for any peer that never heard of this field. A coded window
6729
+ * (`pcmu` / `pcma`, one byte per sample) is only ever emitted to a
6730
+ * subscription that DECLARED it accepts one, so absence can never mean
6731
+ * "coded bytes a consumer will read as floats" (D455).
6732
+ */
6733
+ format: AudioChunkFormatSchema.optional()
6645
6734
  });
6646
6735
  /**
6647
6736
  * Input for `stream-broker.subscribeAudioChunks` (Phase 5 / D9). The
@@ -6653,7 +6742,18 @@ var DecodedAudioChunkSchema = object({
6653
6742
  var SubscribeAudioChunksInputSchema = object({
6654
6743
  brokerId: string(),
6655
6744
  /** Short caller-identity tag (`audio-analyzer`, …) for `listClients`. */
6656
- tag: string().optional()
6745
+ tag: string().optional(),
6746
+ /**
6747
+ * Byte formats this subscriber can READ, best first. The broker serves the
6748
+ * chunk's own format when it is in this list and expands to `f32le`
6749
+ * otherwise, so a subscriber is never handed bytes it cannot interpret.
6750
+ *
6751
+ * Absent (or without the source format) means `f32le` — the behaviour every
6752
+ * subscriber had before D455, unchanged. This is the negotiation half of
6753
+ * the source-bytes lever: it is what lets the broker and its consumers
6754
+ * deploy one at a time across three nodes.
6755
+ */
6756
+ accept: array(AudioChunkFormatSchema).readonly().optional()
6657
6757
  });
6658
6758
  /** Result of `stream-broker.subscribeAudioChunks`. */
6659
6759
  var SubscribeAudioChunksResultSchema = object({
@@ -10637,6 +10737,51 @@ var AudioAnalysisSettingsSchema = object({
10637
10737
  minConfidence: number().min(0).max(1).default(.3),
10638
10738
  allowedClasses: array(string()).default([])
10639
10739
  });
10740
+ /**
10741
+ * `attachDevice` — the analyzer PULLS a camera's audio from the broker (D461).
10742
+ *
10743
+ * Until D461 the orchestrator drained the broker's chunk plane, accumulated
10744
+ * ~1 s windows and pushed them back out as `analyseChunk`. It neither produced
10745
+ * nor consumed the audio: the PCM crossed hub-main twice for a process that
10746
+ * only buffered it. `attachDevice` inverts the direction — the analyzer opens
10747
+ * its own `subscribeAudioChunks` against the broker and the subscriber IS the
10748
+ * decoder, so the coded G.711 bytes D455 put on the plane stay coded all the
10749
+ * way to the one expansion that feeds the model.
10750
+ *
10751
+ * The orchestrator still owns the POLICY (the `audioMode` gate, the on-motion
10752
+ * window, the per-device node assignment, the settings read) and therefore
10753
+ * still owns the attach/detach pair. It no longer owns the bytes.
10754
+ */
10755
+ var AudioAttachDeviceInputSchema = object({
10756
+ deviceId: number(),
10757
+ /** Broker id (`<deviceId>/<camStreamId>`) carrying this camera's audio. */
10758
+ brokerId: string(),
10759
+ /**
10760
+ * `clusterRoles.ingestNode` — the node whose broker owns the source dial.
10761
+ * Every `streamBroker` call the attachment makes is pinned to it, exactly as
10762
+ * the orchestrator's poller pinned them before the move.
10763
+ */
10764
+ ingestNodeId: string(),
10765
+ /**
10766
+ * Resolved once by the orchestrator at attach time, exactly as it was read
10767
+ * once per subscription before D461. The analyzer does NOT re-resolve per
10768
+ * window: a settings change re-attaches, which is what always happened.
10769
+ */
10770
+ settings: AudioAnalysisSettingsSchema
10771
+ });
10772
+ var AudioAttachDeviceResultSchema = object({
10773
+ /** False only when the analyzer is shutting down and refused to attach. */
10774
+ attached: boolean(),
10775
+ /**
10776
+ * True when the attachment replaced a live one for the same device. An
10777
+ * attach is idempotent by REPLACEMENT — two pollers on one camera would
10778
+ * double the broker's fanout and neither would know about the other.
10779
+ */
10780
+ replaced: boolean()
10781
+ });
10782
+ var AudioDetachDeviceResultSchema = object({
10783
+ /** False when no attachment existed — detach is idempotent. */
10784
+ detached: boolean() });
10640
10785
  var AudioClassificationResultSchema = object({
10641
10786
  labels: array(AudioClassificationLabelSchema).readonly(),
10642
10787
  rawLabels: array(AudioClassificationLabelSchema).readonly().optional(),
@@ -10645,7 +10790,7 @@ var AudioClassificationResultSchema = object({
10645
10790
  method(object({
10646
10791
  chunk: AudioChunkInputSchema,
10647
10792
  settings: AudioAnalysisSettingsSchema
10648
- }), AudioAnalysisResultSchema.nullable(), { kind: "mutation" }), method(AudioChunkInputSchema, AudioClassificationResultSchema, { timeoutMs: 3e4 }), method(_void(), boolean()), method(_void(), _void(), { kind: "mutation" }), method(_void(), object({ backend: string() }), {
10793
+ }), 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() }), {
10649
10794
  kind: "mutation",
10650
10795
  auth: "admin"
10651
10796
  });
@@ -20311,6 +20456,14 @@ var NativeCropResultSchema = object({
20311
20456
  * set `encodeJpeg: true`; `bytes` is then absent.
20312
20457
  */
20313
20458
  jpeg: string().optional(),
20459
+ /**
20460
+ * The SAME compressed JPEG as `jpeg`, as bytes (D462). Present instead of
20461
+ * `jpeg` when the request set `acceptJpegBytes`; a request that did not gets
20462
+ * `jpeg` exactly as before. MsgPack and the mesh leg both carry binary —
20463
+ * `bytes` above has crossed this boundary as a `Uint8Array` all along — so
20464
+ * base64 was buying nothing but a multi-megabyte string in the relay's heap.
20465
+ */
20466
+ jpegBytes: _instanceof(Uint8Array).optional(),
20314
20467
  width: number().int().positive(),
20315
20468
  height: number().int().positive(),
20316
20469
  /**
@@ -20377,7 +20530,14 @@ var ParkTrackFrameResultSchema = discriminatedUnion("parked", [object({
20377
20530
  })]);
20378
20531
  /** A retrieved parcel — the runner's own JPEG, base64 for the wire. */
20379
20532
  var ParkedTrackFrameSchema = object({
20380
- jpeg: string(),
20533
+ /**
20534
+ * Base64 JPEG — the pre-D462 wire. OPTIONAL since D462: a request that set
20535
+ * `acceptJpegBytes` is answered in `jpegBytes` and this is then absent.
20536
+ * Exactly one of the two is present.
20537
+ */
20538
+ jpeg: string().optional(),
20539
+ /** The same JPEG as bytes, for a caller that declared it reads them (D462). */
20540
+ jpegBytes: _instanceof(Uint8Array).optional(),
20381
20541
  width: number().int().positive(),
20382
20542
  height: number().int().positive(),
20383
20543
  /** The frame instant the parcel shows (the caller's clock, echoed back). */
@@ -20964,6 +21124,13 @@ method(RunnerCameraConfigSchema, object({ success: literal(true) }), { kind: "mu
20964
21124
  bbox: NativeCropBboxSchema,
20965
21125
  maxWidth: number().int().positive().optional(),
20966
21126
  /**
21127
+ * The caller reads a `Uint8Array` (D462). When set, a JPEG answer comes
21128
+ * back in `jpegBytes` instead of base64 `jpeg`. Absent means the old
21129
+ * wire — never assume consent: a pre-D462 caller parses the field as
21130
+ * base64 and bytes would decode to garbage rather than fail.
21131
+ */
21132
+ acceptJpegBytes: boolean().optional(),
21133
+ /**
20967
21134
  * When `true`, the runner encodes the resolved crop to JPEG ON THE
20968
21135
  * OWNING NODE and returns it in `jpeg` (base64) INSTEAD of raw `bytes`.
20969
21136
  * Callers set this for CROSS-NODE fetches (`handle.nodeId` is a remote
@@ -21031,7 +21198,14 @@ method(RunnerCameraConfigSchema, object({ success: literal(true) }), { kind: "mu
21031
21198
  }), ParkTrackFrameResultSchema, { kind: "mutation" }), method(object({
21032
21199
  deviceId: number(),
21033
21200
  trackId: string(),
21034
- kind: ParkedFrameKindSchema
21201
+ kind: ParkedFrameKindSchema,
21202
+ /**
21203
+ * The caller reads a `Uint8Array` (D462). When set, a JPEG answer comes
21204
+ * back in `jpegBytes` instead of base64 `jpeg`. Absent means the old
21205
+ * wire — never assume consent: a pre-D462 caller parses the field as
21206
+ * base64 and bytes would decode to garbage rather than fail.
21207
+ */
21208
+ acceptJpegBytes: boolean().optional()
21035
21209
  }), ParkedTrackFrameSchema.nullable()), method(object({
21036
21210
  deviceId: number(),
21037
21211
  trackId: string()
@@ -30670,12 +30844,24 @@ Object.freeze({
30670
30844
  addonId: null,
30671
30845
  access: "create"
30672
30846
  },
30847
+ "audioAnalyzer.attachDevice": {
30848
+ capName: "audio-analyzer",
30849
+ capScope: "system",
30850
+ addonId: null,
30851
+ access: "create"
30852
+ },
30673
30853
  "audioAnalyzer.classify": {
30674
30854
  capName: "audio-analyzer",
30675
30855
  capScope: "system",
30676
30856
  addonId: null,
30677
30857
  access: "view"
30678
30858
  },
30859
+ "audioAnalyzer.detachDevice": {
30860
+ capName: "audio-analyzer",
30861
+ capScope: "system",
30862
+ addonId: null,
30863
+ access: "create"
30864
+ },
30679
30865
  "audioAnalyzer.dispose": {
30680
30866
  capName: "audio-analyzer",
30681
30867
  capScope: "system",
@@ -36519,11 +36705,21 @@ Object.freeze({
36519
36705
  form: "single",
36520
36706
  optional: false
36521
36707
  }],
36708
+ "audioAnalyzer.attachDevice": [{
36709
+ name: "deviceId",
36710
+ form: "single",
36711
+ optional: false
36712
+ }],
36522
36713
  "audioAnalyzer.classify": [{
36523
36714
  name: "deviceId",
36524
36715
  form: "single",
36525
36716
  optional: true
36526
36717
  }],
36718
+ "audioAnalyzer.detachDevice": [{
36719
+ name: "deviceId",
36720
+ form: "single",
36721
+ optional: false
36722
+ }],
36527
36723
  "audioMetrics.getCurrentSnapshot": [{
36528
36724
  name: "deviceId",
36529
36725
  form: "single",
@@ -38375,6 +38571,52 @@ Object.freeze({
38375
38571
  "network-access": "ingress",
38376
38572
  "smtp-provider": "email"
38377
38573
  });
38574
+ var G711_SCALE_CORRECTION_DB = {
38575
+ PCMU: 20 * Math.log10(4),
38576
+ PCMA: 20 * Math.log10(8)
38577
+ };
38578
+ /**
38579
+ * Restate a dBFS number that was MEASURED through the pre-epoch decoder as the
38580
+ * same intent on the ITU-T scale (D460).
38581
+ *
38582
+ * ## When this applies, and when it is the wrong thing to reach for
38583
+ *
38584
+ * An absolute-dBFS number in this repo is one of two things, and only one of
38585
+ * them converts:
38586
+ *
38587
+ * - **A statement about the scale** — "-55 dBFS is near silence", "-25 dBFS
38588
+ * is loud". It was true on the ITU-T scale before the epoch and it is true
38589
+ * after. The defect was never in the number; it was that 19 of this hub's
38590
+ * 25 cameras did not obey it. Converting such a number takes something
38591
+ * correct and makes it wrong, in order to preserve a bug.
38592
+ * - **A measurement taken through the old decoder** — a value someone read
38593
+ * off a meter that under-reported by exactly 4× (PCMU) or 8× (PCMA). It
38594
+ * describes a sound that was really {@link G711_SCALE_CORRECTION_DB} dB
38595
+ * louder. That is what this function is for.
38596
+ *
38597
+ * Telling the two apart is a question about PROVENANCE, not about arithmetic,
38598
+ * and it cannot be answered from the number. It is answered by the comment the
38599
+ * author left — which is why `scripts/check-dbfs-era.mts` makes leaving one
38600
+ * mandatory.
38601
+ *
38602
+ * ## Why a function and not a typed-in number
38603
+ *
38604
+ * `-55 + 12.04` written into a source file is, six months later, completely
38605
+ * indistinguishable from a threshold somebody simply preferred. Calling this
38606
+ * keeps the derivation, the law, and the original measurement all visible at
38607
+ * the call site, so a future reader can disagree with the *premise* instead of
38608
+ * having to reverse-engineer the sum.
38609
+ *
38610
+ * **This is not a runtime gain.** It converts an authored CONSTANT once, where
38611
+ * it is declared. It must never be applied to a live sample or a stored
38612
+ * `AudioEvent.dbfs`: the decoder is correct now, and a second authority
38613
+ * adjusting numbers the decoder already got right is the original defect with
38614
+ * an extra place to argue with (D459).
38615
+ */
38616
+ function ituDbfsFromPreEpoch(law, authoredDbfs) {
38617
+ return authoredDbfs + G711_SCALE_CORRECTION_DB[law];
38618
+ }
38619
+ Math.round(ituDbfsFromPreEpoch("PCMU", -55));
38378
38620
  /** Schema defaults — an untouched sub-field must author exactly these. */
38379
38621
  var NC_AUDIO_DEFAULTS = {
38380
38622
  hitPercent: 60,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-decoder-nodeav",
3
- "version": "1.2.95",
3
+ "version": "1.2.97",
4
4
  "description": "Standalone in-process node-av decoder addon for CamStack",
5
5
  "keywords": [
6
6
  "camstack",