@camstack/addon-decoder-nodeav 1.2.94 → 1.2.96

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
  });
@@ -24905,8 +25050,8 @@ includeCrops: boolean().optional() }).optional(), array(IdentitySchema).readonly
24905
25050
  *
24906
25051
  * An **empty array reads NOTHING** — `[]` is an empty page, never
24907
25052
  * "every camera". A request for no devices is a request, not an
24908
- * omission; same contract as `deviceManager.listFleet` and
24909
- * `pipelineAnalytics.listRecentTracks`.
25053
+ * omission; same contract as `deviceManager.listAll`'s `deviceIds`
25054
+ * and `pipelineAnalytics.listRecentTracks`.
24910
25055
  *
24911
25056
  * Absent (`undefined`) is the omission, and keeps the cluster-wide view.
24912
25057
  */
@@ -30674,12 +30819,24 @@ Object.freeze({
30674
30819
  addonId: null,
30675
30820
  access: "create"
30676
30821
  },
30822
+ "audioAnalyzer.attachDevice": {
30823
+ capName: "audio-analyzer",
30824
+ capScope: "system",
30825
+ addonId: null,
30826
+ access: "create"
30827
+ },
30677
30828
  "audioAnalyzer.classify": {
30678
30829
  capName: "audio-analyzer",
30679
30830
  capScope: "system",
30680
30831
  addonId: null,
30681
30832
  access: "view"
30682
30833
  },
30834
+ "audioAnalyzer.detachDevice": {
30835
+ capName: "audio-analyzer",
30836
+ capScope: "system",
30837
+ addonId: null,
30838
+ access: "create"
30839
+ },
30683
30840
  "audioAnalyzer.dispose": {
30684
30841
  capName: "audio-analyzer",
30685
30842
  capScope: "system",
@@ -36523,11 +36680,21 @@ Object.freeze({
36523
36680
  form: "single",
36524
36681
  optional: false
36525
36682
  }],
36683
+ "audioAnalyzer.attachDevice": [{
36684
+ name: "deviceId",
36685
+ form: "single",
36686
+ optional: false
36687
+ }],
36526
36688
  "audioAnalyzer.classify": [{
36527
36689
  name: "deviceId",
36528
36690
  form: "single",
36529
36691
  optional: true
36530
36692
  }],
36693
+ "audioAnalyzer.detachDevice": [{
36694
+ name: "deviceId",
36695
+ form: "single",
36696
+ optional: false
36697
+ }],
36531
36698
  "audioMetrics.getCurrentSnapshot": [{
36532
36699
  name: "deviceId",
36533
36700
  form: "single",
@@ -38379,6 +38546,52 @@ Object.freeze({
38379
38546
  "network-access": "ingress",
38380
38547
  "smtp-provider": "email"
38381
38548
  });
38549
+ var G711_SCALE_CORRECTION_DB = {
38550
+ PCMU: 20 * Math.log10(4),
38551
+ PCMA: 20 * Math.log10(8)
38552
+ };
38553
+ /**
38554
+ * Restate a dBFS number that was MEASURED through the pre-epoch decoder as the
38555
+ * same intent on the ITU-T scale (D460).
38556
+ *
38557
+ * ## When this applies, and when it is the wrong thing to reach for
38558
+ *
38559
+ * An absolute-dBFS number in this repo is one of two things, and only one of
38560
+ * them converts:
38561
+ *
38562
+ * - **A statement about the scale** — "-55 dBFS is near silence", "-25 dBFS
38563
+ * is loud". It was true on the ITU-T scale before the epoch and it is true
38564
+ * after. The defect was never in the number; it was that 19 of this hub's
38565
+ * 25 cameras did not obey it. Converting such a number takes something
38566
+ * correct and makes it wrong, in order to preserve a bug.
38567
+ * - **A measurement taken through the old decoder** — a value someone read
38568
+ * off a meter that under-reported by exactly 4× (PCMU) or 8× (PCMA). It
38569
+ * describes a sound that was really {@link G711_SCALE_CORRECTION_DB} dB
38570
+ * louder. That is what this function is for.
38571
+ *
38572
+ * Telling the two apart is a question about PROVENANCE, not about arithmetic,
38573
+ * and it cannot be answered from the number. It is answered by the comment the
38574
+ * author left — which is why `scripts/check-dbfs-era.mts` makes leaving one
38575
+ * mandatory.
38576
+ *
38577
+ * ## Why a function and not a typed-in number
38578
+ *
38579
+ * `-55 + 12.04` written into a source file is, six months later, completely
38580
+ * indistinguishable from a threshold somebody simply preferred. Calling this
38581
+ * keeps the derivation, the law, and the original measurement all visible at
38582
+ * the call site, so a future reader can disagree with the *premise* instead of
38583
+ * having to reverse-engineer the sum.
38584
+ *
38585
+ * **This is not a runtime gain.** It converts an authored CONSTANT once, where
38586
+ * it is declared. It must never be applied to a live sample or a stored
38587
+ * `AudioEvent.dbfs`: the decoder is correct now, and a second authority
38588
+ * adjusting numbers the decoder already got right is the original defect with
38589
+ * an extra place to argue with (D459).
38590
+ */
38591
+ function ituDbfsFromPreEpoch(law, authoredDbfs) {
38592
+ return authoredDbfs + G711_SCALE_CORRECTION_DB[law];
38593
+ }
38594
+ Math.round(ituDbfsFromPreEpoch("PCMU", -55));
38382
38595
  /** Schema defaults — an untouched sub-field must author exactly these. */
38383
38596
  var NC_AUDIO_DEFAULTS = {
38384
38597
  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
  });
@@ -24901,8 +25046,8 @@ includeCrops: boolean().optional() }).optional(), array(IdentitySchema).readonly
24901
25046
  *
24902
25047
  * An **empty array reads NOTHING** — `[]` is an empty page, never
24903
25048
  * "every camera". A request for no devices is a request, not an
24904
- * omission; same contract as `deviceManager.listFleet` and
24905
- * `pipelineAnalytics.listRecentTracks`.
25049
+ * omission; same contract as `deviceManager.listAll`'s `deviceIds`
25050
+ * and `pipelineAnalytics.listRecentTracks`.
24906
25051
  *
24907
25052
  * Absent (`undefined`) is the omission, and keeps the cluster-wide view.
24908
25053
  */
@@ -30670,12 +30815,24 @@ Object.freeze({
30670
30815
  addonId: null,
30671
30816
  access: "create"
30672
30817
  },
30818
+ "audioAnalyzer.attachDevice": {
30819
+ capName: "audio-analyzer",
30820
+ capScope: "system",
30821
+ addonId: null,
30822
+ access: "create"
30823
+ },
30673
30824
  "audioAnalyzer.classify": {
30674
30825
  capName: "audio-analyzer",
30675
30826
  capScope: "system",
30676
30827
  addonId: null,
30677
30828
  access: "view"
30678
30829
  },
30830
+ "audioAnalyzer.detachDevice": {
30831
+ capName: "audio-analyzer",
30832
+ capScope: "system",
30833
+ addonId: null,
30834
+ access: "create"
30835
+ },
30679
30836
  "audioAnalyzer.dispose": {
30680
30837
  capName: "audio-analyzer",
30681
30838
  capScope: "system",
@@ -36519,11 +36676,21 @@ Object.freeze({
36519
36676
  form: "single",
36520
36677
  optional: false
36521
36678
  }],
36679
+ "audioAnalyzer.attachDevice": [{
36680
+ name: "deviceId",
36681
+ form: "single",
36682
+ optional: false
36683
+ }],
36522
36684
  "audioAnalyzer.classify": [{
36523
36685
  name: "deviceId",
36524
36686
  form: "single",
36525
36687
  optional: true
36526
36688
  }],
36689
+ "audioAnalyzer.detachDevice": [{
36690
+ name: "deviceId",
36691
+ form: "single",
36692
+ optional: false
36693
+ }],
36527
36694
  "audioMetrics.getCurrentSnapshot": [{
36528
36695
  name: "deviceId",
36529
36696
  form: "single",
@@ -38375,6 +38542,52 @@ Object.freeze({
38375
38542
  "network-access": "ingress",
38376
38543
  "smtp-provider": "email"
38377
38544
  });
38545
+ var G711_SCALE_CORRECTION_DB = {
38546
+ PCMU: 20 * Math.log10(4),
38547
+ PCMA: 20 * Math.log10(8)
38548
+ };
38549
+ /**
38550
+ * Restate a dBFS number that was MEASURED through the pre-epoch decoder as the
38551
+ * same intent on the ITU-T scale (D460).
38552
+ *
38553
+ * ## When this applies, and when it is the wrong thing to reach for
38554
+ *
38555
+ * An absolute-dBFS number in this repo is one of two things, and only one of
38556
+ * them converts:
38557
+ *
38558
+ * - **A statement about the scale** — "-55 dBFS is near silence", "-25 dBFS
38559
+ * is loud". It was true on the ITU-T scale before the epoch and it is true
38560
+ * after. The defect was never in the number; it was that 19 of this hub's
38561
+ * 25 cameras did not obey it. Converting such a number takes something
38562
+ * correct and makes it wrong, in order to preserve a bug.
38563
+ * - **A measurement taken through the old decoder** — a value someone read
38564
+ * off a meter that under-reported by exactly 4× (PCMU) or 8× (PCMA). It
38565
+ * describes a sound that was really {@link G711_SCALE_CORRECTION_DB} dB
38566
+ * louder. That is what this function is for.
38567
+ *
38568
+ * Telling the two apart is a question about PROVENANCE, not about arithmetic,
38569
+ * and it cannot be answered from the number. It is answered by the comment the
38570
+ * author left — which is why `scripts/check-dbfs-era.mts` makes leaving one
38571
+ * mandatory.
38572
+ *
38573
+ * ## Why a function and not a typed-in number
38574
+ *
38575
+ * `-55 + 12.04` written into a source file is, six months later, completely
38576
+ * indistinguishable from a threshold somebody simply preferred. Calling this
38577
+ * keeps the derivation, the law, and the original measurement all visible at
38578
+ * the call site, so a future reader can disagree with the *premise* instead of
38579
+ * having to reverse-engineer the sum.
38580
+ *
38581
+ * **This is not a runtime gain.** It converts an authored CONSTANT once, where
38582
+ * it is declared. It must never be applied to a live sample or a stored
38583
+ * `AudioEvent.dbfs`: the decoder is correct now, and a second authority
38584
+ * adjusting numbers the decoder already got right is the original defect with
38585
+ * an extra place to argue with (D459).
38586
+ */
38587
+ function ituDbfsFromPreEpoch(law, authoredDbfs) {
38588
+ return authoredDbfs + G711_SCALE_CORRECTION_DB[law];
38589
+ }
38590
+ Math.round(ituDbfsFromPreEpoch("PCMU", -55));
38378
38591
  /** Schema defaults — an untouched sub-field must author exactly these. */
38379
38592
  var NC_AUDIO_DEFAULTS = {
38380
38593
  hitPercent: 60,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-decoder-nodeav",
3
- "version": "1.2.94",
3
+ "version": "1.2.96",
4
4
  "description": "Standalone in-process node-av decoder addon for CamStack",
5
5
  "keywords": [
6
6
  "camstack",