@blockcast/mmt-container 0.1.0-main.c71423b8a4e4 → 0.1.0-main.ce3c8aeb7f68

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.
Files changed (148) hide show
  1. package/dist/align.d.ts +6 -2
  2. package/dist/align.d.ts.map +1 -1
  3. package/dist/align.js.map +2 -2
  4. package/dist/audio-ring-buffer.js +23 -36
  5. package/dist/audio-ring-buffer.js.map +1 -1
  6. package/dist/browser-runtime.js +6865 -6485
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +3 -1
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +21 -2
  11. package/dist/carp-catalog.js.map +4 -4
  12. package/dist/catalog-fec-params.js +10 -0
  13. package/dist/catalog-fec-params.js.map +4 -4
  14. package/dist/cmaf-block-assembler.d.ts +42 -0
  15. package/dist/cmaf-block-assembler.d.ts.map +1 -1
  16. package/dist/cmaf-block-assembler.js +542 -535
  17. package/dist/cmaf-block-assembler.js.map +2 -2
  18. package/dist/cmaf-group-batcher.js +27 -46
  19. package/dist/cmaf-group-batcher.js.map +2 -2
  20. package/dist/cmcd-producer.js +45 -66
  21. package/dist/cmcd-producer.js.map +1 -1
  22. package/dist/fec-manager.d.ts +13 -1
  23. package/dist/fec-manager.d.ts.map +1 -1
  24. package/dist/fec-manager.js +1151 -871
  25. package/dist/fec-manager.js.map +2 -2
  26. package/dist/fec-starvation-detector.js +25 -40
  27. package/dist/fec-starvation-detector.js.map +1 -1
  28. package/dist/fec-worker-setup.js +242 -225
  29. package/dist/fec-worker-setup.js.map +3 -3
  30. package/dist/index.d.ts +3 -3
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js.map +2 -2
  33. package/dist/iso-bmff-timing.js +63 -88
  34. package/dist/iso-bmff-timing.js.map +1 -1
  35. package/dist/loc.js +7 -4
  36. package/dist/loc.js.map +1 -1
  37. package/dist/manifest-auth-plan.js +292 -311
  38. package/dist/manifest-auth-plan.js.map +1 -1
  39. package/dist/media-router.d.ts +0 -99
  40. package/dist/media-router.d.ts.map +1 -1
  41. package/dist/media-router.js +270 -504
  42. package/dist/media-router.js.map +3 -3
  43. package/dist/mfu-reassembler.js +597 -607
  44. package/dist/mfu-reassembler.js.map +3 -3
  45. package/dist/mmtp-container-parser.d.ts +37 -0
  46. package/dist/mmtp-container-parser.d.ts.map +1 -1
  47. package/dist/mmtp-container-parser.js +1531 -1522
  48. package/dist/mmtp-container-parser.js.map +3 -3
  49. package/dist/mmtp-container-parser.no-modules.js +179 -102
  50. package/dist/mmtp-container-parser.no-modules.js.map +3 -3
  51. package/dist/mmtp-decode-pipeline.js +1641 -1651
  52. package/dist/mmtp-decode-pipeline.js.map +3 -3
  53. package/dist/mmtp-router.d.ts +34 -0
  54. package/dist/mmtp-router.d.ts.map +1 -1
  55. package/dist/mmtp-router.js +3676 -3390
  56. package/dist/mmtp-router.js.map +3 -3
  57. package/dist/mmtp-to-cmaf.d.ts +7 -1
  58. package/dist/mmtp-to-cmaf.d.ts.map +1 -1
  59. package/dist/mmtp-to-cmaf.js +109 -134
  60. package/dist/mmtp-to-cmaf.js.map +2 -2
  61. package/dist/multicast-input.d.ts +7 -35
  62. package/dist/multicast-input.d.ts.map +1 -1
  63. package/dist/multicast-input.js +21 -2
  64. package/dist/multicast-input.js.map +4 -4
  65. package/dist/multicast-manager.d.ts +10 -1
  66. package/dist/multicast-manager.d.ts.map +1 -1
  67. package/dist/multicast-manager.js +5584 -4961
  68. package/dist/multicast-manager.js.map +4 -4
  69. package/dist/multicast-transport.d.ts +7 -0
  70. package/dist/multicast-transport.d.ts.map +1 -1
  71. package/dist/multicast-transport.js +369 -421
  72. package/dist/multicast-transport.js.map +4 -4
  73. package/dist/multicast-unwrap.js +53 -30
  74. package/dist/multicast-unwrap.js.map +2 -2
  75. package/dist/no-modules.js +2096 -2097
  76. package/dist/no-modules.js.map +3 -3
  77. package/dist/sample-combiner.js +118 -139
  78. package/dist/sample-combiner.js.map +1 -1
  79. package/dist/signaling.js.map +2 -2
  80. package/dist/source-auth.js +353 -382
  81. package/dist/source-auth.js.map +1 -1
  82. package/dist/switching-set-alignment.js +14 -29
  83. package/dist/switching-set-alignment.js.map +1 -1
  84. package/dist/timestamp-codec.js +17 -11
  85. package/dist/timestamp-codec.js.map +2 -2
  86. package/dist/track-pipeline-setup.js +105 -125
  87. package/dist/track-pipeline-setup.js.map +1 -1
  88. package/dist/track-pipeline.js +107 -127
  89. package/dist/track-pipeline.js.map +1 -1
  90. package/dist/track-session.d.ts +16 -0
  91. package/dist/track-session.d.ts.map +1 -1
  92. package/dist/track-session.js +230 -243
  93. package/dist/track-session.js.map +2 -2
  94. package/dist/transport-pool.js +24 -38
  95. package/dist/transport-pool.js.map +1 -1
  96. package/dist/wasm-mfu-reassembler.d.ts +6 -1
  97. package/dist/wasm-mfu-reassembler.d.ts.map +1 -1
  98. package/dist/wasm-mfu-reassembler.js +127 -144
  99. package/dist/wasm-mfu-reassembler.js.map +2 -2
  100. package/dist/wasm-mmtp-container-parser.js +1659 -1650
  101. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  102. package/node_modules/@blockcast/fec-worker/README.md +5 -1
  103. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.d.ts +8 -2
  104. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.d.ts.map +1 -1
  105. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.js +89 -16
  106. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.js.map +1 -1
  107. package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts +48 -3
  108. package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts.map +1 -1
  109. package/node_modules/@blockcast/fec-worker/dist/fec-worker.js +55 -8
  110. package/node_modules/@blockcast/fec-worker/dist/fec-worker.js.map +2 -2
  111. package/node_modules/@blockcast/fec-worker/dist/index.d.ts +1 -1
  112. package/node_modules/@blockcast/fec-worker/dist/index.d.ts.map +1 -1
  113. package/node_modules/@blockcast/fec-worker/dist/index.js.map +1 -1
  114. package/node_modules/@blockcast/fec-worker/src/fec-worker-client.ts +97 -17
  115. package/node_modules/@blockcast/fec-worker/src/fec-worker-types.ts +46 -2
  116. package/node_modules/@blockcast/fec-worker/src/fec-worker.ts +78 -10
  117. package/node_modules/@blockcast/fec-worker/src/index.ts +2 -0
  118. package/node_modules/@blockcast/mmt-base/README.md +1 -0
  119. package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +52 -0
  120. package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -1
  121. package/node_modules/@blockcast/mmt-base/dist/mmtp.js +142 -37
  122. package/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -1
  123. package/node_modules/@blockcast/mmt-base/src/mmtp.ts +158 -37
  124. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/README.md +1 -0
  125. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +52 -0
  126. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -1
  127. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js +142 -37
  128. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -1
  129. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/mmtp.ts +158 -37
  130. package/package.json +7 -6
  131. package/schemas/catalog.schema.json +1 -1
  132. package/src/align.ts +6 -2
  133. package/src/carp-catalog.ts +13 -3
  134. package/src/cmaf-block-assembler.ts +90 -81
  135. package/src/fec-manager.ts +530 -146
  136. package/src/index.ts +2 -2
  137. package/src/media-router.ts +0 -397
  138. package/src/mmtp-container-parser.ts +97 -21
  139. package/src/mmtp-router.ts +302 -125
  140. package/src/mmtp-to-cmaf.ts +21 -7
  141. package/src/multicast-input.ts +23 -3
  142. package/src/multicast-manager.ts +83 -11
  143. package/src/multicast-transport.ts +56 -17
  144. package/src/track-session.ts +16 -0
  145. package/src/wasm-mfu-reassembler.ts +40 -24
  146. package/test-vectors/catalog/README.md +2 -0
  147. package/test-vectors/catalog/negative/multicast-packet-id-signaling.json +26 -0
  148. package/test-vectors/catalog-validation.json +11 -0
@@ -1,46 +1,3 @@
1
- var __typeError = (msg) => {
2
- throw TypeError(msg);
3
- };
4
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
9
- var __privateWrapper = (obj, member, setter, getter) => ({
10
- set _(value) {
11
- __privateSet(obj, member, value, setter);
12
- },
13
- get _() {
14
- return __privateGet(obj, member, getter);
15
- }
16
- });
17
-
18
- // src/align.ts
19
- function groupIdForTicks(ticks, groupDurationTicks) {
20
- if (!Number.isInteger(ticks)) {
21
- throw new Error(
22
- `[align] groupIdForTicks: ticks must be an integer, got ${ticks}`
23
- );
24
- }
25
- if (!Number.isInteger(groupDurationTicks) || groupDurationTicks <= 0) {
26
- throw new Error(
27
- `[align] groupIdForTicks: groupDurationTicks must be a positive integer, got ${groupDurationTicks}`
28
- );
29
- }
30
- if (ticks < 0) return 0;
31
- return Math.floor(ticks / groupDurationTicks);
32
- }
33
- function driftCheck(expected, actual) {
34
- if (!Number.isInteger(expected) || !Number.isInteger(actual)) {
35
- throw new Error(
36
- `[align] driftCheck: both arguments must be integer groupIds, got expected=${expected} actual=${actual}`
37
- );
38
- }
39
- const deltaGroups = actual - expected;
40
- if (deltaGroups === 0) return { kind: "aligned", deltaGroups: 0 };
41
- return { kind: "drifted", deltaGroups };
42
- }
43
-
44
1
  // src/track-session.ts
45
2
  import { fecBlockBudgetMs } from "@blockcast/mmt-fec";
46
3
  function computeFecDeliveryWindowMs(config) {
@@ -61,15 +18,6 @@ function computeFecDeliveryWindowMs(config) {
61
18
  }
62
19
 
63
20
  // src/media-router.ts
64
- var GROUP_ALIGN_WARN_BUDGET = {
65
- "invalid-tick-inputs": 1,
66
- "ticks-formula-threw": 1,
67
- "invalid-seconds-inputs": 1,
68
- "sub-nanosecond-duration": 1,
69
- "media-time-overflow": 1,
70
- "seconds-formula-threw": 1,
71
- "callback-threw": 3
72
- };
73
21
  var TrackSourceConflictError = class extends Error {
74
22
  constructor(trackName) {
75
23
  super(`Track source already assigned for '${trackName}'; call clearTrackSource first`);
@@ -79,136 +27,90 @@ var TrackSourceConflictError = class extends Error {
79
27
  };
80
28
  var DEFAULT_CROSSFADE_FRAMES = 10;
81
29
  var DEFAULT_MAX_OVERLAY_BUFFER = 128;
82
- var _active, _multicastVideoKeyed, _multicastAudioReceived, _moqVideoKeyframeEmitted, _requireAudio, _suppressed, _audioFallbackTimer, _audioFallbackMs, _crossfadeFrames, _maxOverlayBuffer, _allowDeltaMulticastTakeoverAfterMoqKeyframe, _repairInFlight, _maxRepairInFlight, _onRepairRequest, _onVideoFrame, _onAudioFrame, _onOverlayFrame, _onSourceSwitch, _sourceSwitchReady, _sourceSwitchToken, _pendingMulticastToken, _pendingMulticastVideo, _pendingMulticastAudio, _trackSources, _trackTypes, _crossfadeCounters, _overlayBoundaryReached, _overlayBuffer, _deltaConfigured, _deltaActive, _deltaWindow, _deltaWindowSize, _deltaFailThresholdRatio, _deltaRecoverThresholdRatio, _deltaProbeIntervalMs, _lastProbeAt, _onDeltaFallbackCb, _onDeltaRecoverCb, _onGroupDrift, _groupAlignWarnCounts, _MediaRouter_instances, skipWithWarning_fn, resolveTicks_fn, resolveSeconds_fn, _moqAudioWarmed, tryActivateMulticast_fn, commitMulticastActivation_fn, rejectMulticastActivation_fn, emitForTrack_fn, handleOverlayFrame_fn;
83
30
  var MediaRouter = class {
31
+ #active = "moq";
32
+ #multicastVideoKeyed = false;
33
+ #multicastAudioReceived = false;
34
+ #moqVideoKeyframeEmitted = false;
35
+ #requireAudio;
36
+ #suppressed = false;
37
+ // true after multicast confirmed — suppresses MoQ
38
+ #audioFallbackTimer = null;
39
+ // Configurable constants (from catalog/FEC config, not magic numbers)
40
+ #audioFallbackMs;
41
+ #crossfadeFrames;
42
+ #maxOverlayBuffer;
43
+ #allowDeltaMulticastTakeoverAfterMoqKeyframe;
44
+ // ── Keyframe repair state ────────────────────────────────────────
45
+ /** Groups currently being repaired — idempotent guard per Pitfall 2 (T-13-01 mitigation) */
46
+ #repairInFlight = /* @__PURE__ */ new Set();
47
+ /** Max concurrent repairs — prevents relay SUBSCRIBE flood (T-13-01 mitigation) */
48
+ #maxRepairInFlight;
49
+ /** Callback to request MoQ subscribe for a specific group (wired by player) */
50
+ #onRepairRequest = null;
51
+ #onVideoFrame = null;
52
+ #onAudioFrame = null;
53
+ #onOverlayFrame = null;
54
+ #onSourceSwitch = null;
55
+ #sourceSwitchReady = null;
56
+ #sourceSwitchToken = 0;
57
+ #pendingMulticastToken = null;
58
+ #pendingMulticastVideo = null;
59
+ #pendingMulticastAudio = null;
60
+ // Per-track source state
61
+ #trackSources = /* @__PURE__ */ new Map();
62
+ // Track type registry: trackName → { type, source }.
63
+ // Init data / inline signaling is authoritative until catalog updates.
64
+ // Priority: 'init' > 'catalog' > 'name' (backward compat fallback).
65
+ #trackTypes = /* @__PURE__ */ new Map();
66
+ // Crossfade state: maps trackName → remaining binary-path frames allowed during window
67
+ #crossfadeCounters = /* @__PURE__ */ new Map();
68
+ // Overlay alignment state
69
+ #overlayBoundaryReached = false;
70
+ #overlayBuffer = [];
71
+ // ── Phase 14: deltaActive state machine (D-11..D-14) ─────────────
72
+ // No timers — state transitions driven entirely by notifyDeltaBlock() callbacks.
73
+ // All thresholds derived from catalog fields or throw at configureDelta() time.
74
+ #deltaConfigured = false;
75
+ #deltaActive = true;
76
+ #deltaWindow = [];
77
+ // ring buffer: true = block failed
78
+ #deltaWindowSize = 0;
79
+ #deltaFailThresholdRatio = 0;
80
+ // P/K
81
+ #deltaRecoverThresholdRatio = 0;
82
+ // (P/K)/2 — hysteresis (D-13)
83
+ #deltaProbeIntervalMs = 0;
84
+ #lastProbeAt = 0;
85
+ #onDeltaFallbackCb = null;
86
+ #onDeltaRecoverCb = null;
84
87
  constructor(options) {
85
- __privateAdd(this, _MediaRouter_instances);
86
- __privateAdd(this, _active, "moq");
87
- __privateAdd(this, _multicastVideoKeyed, false);
88
- __privateAdd(this, _multicastAudioReceived, false);
89
- __privateAdd(this, _moqVideoKeyframeEmitted, false);
90
- __privateAdd(this, _requireAudio);
91
- __privateAdd(this, _suppressed, false);
92
- // true after multicast confirmed — suppresses MoQ
93
- __privateAdd(this, _audioFallbackTimer, null);
94
- // Configurable constants (from catalog/FEC config, not magic numbers)
95
- __privateAdd(this, _audioFallbackMs);
96
- __privateAdd(this, _crossfadeFrames);
97
- __privateAdd(this, _maxOverlayBuffer);
98
- __privateAdd(this, _allowDeltaMulticastTakeoverAfterMoqKeyframe);
99
- // ── Keyframe repair state ────────────────────────────────────────
100
- /** Groups currently being repaired — idempotent guard per Pitfall 2 (T-13-01 mitigation) */
101
- __privateAdd(this, _repairInFlight, /* @__PURE__ */ new Set());
102
- /** Max concurrent repairs — prevents relay SUBSCRIBE flood (T-13-01 mitigation) */
103
- __privateAdd(this, _maxRepairInFlight);
104
- /** Callback to request MoQ subscribe for a specific group (wired by player) */
105
- __privateAdd(this, _onRepairRequest, null);
106
- __privateAdd(this, _onVideoFrame, null);
107
- __privateAdd(this, _onAudioFrame, null);
108
- __privateAdd(this, _onOverlayFrame, null);
109
- __privateAdd(this, _onSourceSwitch, null);
110
- __privateAdd(this, _sourceSwitchReady, null);
111
- __privateAdd(this, _sourceSwitchToken, 0);
112
- __privateAdd(this, _pendingMulticastToken, null);
113
- __privateAdd(this, _pendingMulticastVideo, null);
114
- __privateAdd(this, _pendingMulticastAudio, null);
115
- // Per-track source state
116
- __privateAdd(this, _trackSources, /* @__PURE__ */ new Map());
117
- // Track type registry: trackName → { type, source }.
118
- // Init data / inline signaling is authoritative until catalog updates.
119
- // Priority: 'init' > 'catalog' > 'name' (backward compat fallback).
120
- __privateAdd(this, _trackTypes, /* @__PURE__ */ new Map());
121
- // Crossfade state: maps trackName → remaining binary-path frames allowed during window
122
- __privateAdd(this, _crossfadeCounters, /* @__PURE__ */ new Map());
123
- // Overlay alignment state
124
- __privateAdd(this, _overlayBoundaryReached, false);
125
- __privateAdd(this, _overlayBuffer, []);
126
- // ── Phase 14: deltaActive state machine (D-11..D-14) ─────────────
127
- // No timers — state transitions driven entirely by notifyDeltaBlock() callbacks.
128
- // All thresholds derived from catalog fields or throw at configureDelta() time.
129
- __privateAdd(this, _deltaConfigured, false);
130
- __privateAdd(this, _deltaActive, true);
131
- __privateAdd(this, _deltaWindow, []);
132
- // ring buffer: true = block failed
133
- __privateAdd(this, _deltaWindowSize, 0);
134
- __privateAdd(this, _deltaFailThresholdRatio, 0);
135
- // P/K
136
- __privateAdd(this, _deltaRecoverThresholdRatio, 0);
137
- // (P/K)/2 — hysteresis (D-13)
138
- __privateAdd(this, _deltaProbeIntervalMs, 0);
139
- __privateAdd(this, _lastProbeAt, 0);
140
- __privateAdd(this, _onDeltaFallbackCb, null);
141
- __privateAdd(this, _onDeltaRecoverCb, null);
142
- // ── Group-alignment observer (align.ts formula) ──────────────────
143
- // Observation only — does NOT alter routing. Producers are wired in
144
- // follow-up PRs; when they land they will call
145
- // CmcdProducer.incrementSwitchMiscount() + emitSwitchDrift() from the
146
- // onGroupDrift callback so divergence between packet-stamped groupIds
147
- // and the shared formula surfaces on `x-bc-switch-drift-us` /
148
- // `x-bc-switch-miscount`. Canonical Go impl: Blockcast/multicast
149
- // cmd/caddy/sender/group_align.go (commit 104eeff). Canonical Rust impl:
150
- // moqtail/moqtail apps/relay/src/server/abr.rs (branch
151
- // experimental/server-side-abr, commit 39accbf).
152
- __privateAdd(this, _onGroupDrift, null);
153
- __privateAdd(this, _groupAlignWarnCounts, /* @__PURE__ */ new Map());
154
- /**
155
- * MoQ unicast audio warmup gate. When audio is required, multicast takeover
156
- * waits until the MoQ unicast audio decoder has emitted at least one frame
157
- * (so downstream samples-before-takeover counters observe nonzero) or until
158
- * the existing audio-fallback timer forces the flag true.
159
- */
160
- __privateAdd(this, _moqAudioWarmed, false);
161
- __privateSet(this, _requireAudio, options?.requireAudio ?? true);
162
- __privateSet(this, _audioFallbackMs, options?.audioFallbackMs ?? 0);
163
- __privateSet(this, _crossfadeFrames, options?.crossfadeFrames ?? DEFAULT_CROSSFADE_FRAMES);
164
- __privateSet(this, _maxOverlayBuffer, options?.maxOverlayBuffer ?? DEFAULT_MAX_OVERLAY_BUFFER);
165
- __privateSet(this, _maxRepairInFlight, options?.maxRepairInFlight ?? 2);
166
- __privateSet(this, _allowDeltaMulticastTakeoverAfterMoqKeyframe, options?.allowDeltaMulticastTakeoverAfterMoqKeyframe ?? false);
88
+ this.#requireAudio = options?.requireAudio ?? true;
89
+ this.#audioFallbackMs = options?.audioFallbackMs ?? 0;
90
+ this.#crossfadeFrames = options?.crossfadeFrames ?? DEFAULT_CROSSFADE_FRAMES;
91
+ this.#maxOverlayBuffer = options?.maxOverlayBuffer ?? DEFAULT_MAX_OVERLAY_BUFFER;
92
+ this.#maxRepairInFlight = options?.maxRepairInFlight ?? 2;
93
+ this.#allowDeltaMulticastTakeoverAfterMoqKeyframe = options?.allowDeltaMulticastTakeoverAfterMoqKeyframe ?? false;
167
94
  }
168
95
  onVideoFrame(cb) {
169
- __privateSet(this, _onVideoFrame, cb);
96
+ this.#onVideoFrame = cb;
170
97
  }
171
98
  onAudioFrame(cb) {
172
- __privateSet(this, _onAudioFrame, cb);
99
+ this.#onAudioFrame = cb;
173
100
  }
174
101
  onOverlayFrame(cb) {
175
- __privateSet(this, _onOverlayFrame, cb);
102
+ this.#onOverlayFrame = cb;
176
103
  }
177
104
  onSourceSwitch(cb) {
178
- __privateSet(this, _onSourceSwitch, cb);
179
- }
180
- onGroupDrift(cb) {
181
- __privateSet(this, _onGroupDrift, cb);
182
- }
183
- notifyGroupBoundary(trackName, packetGroupId, timingOrMediaTimeSec, groupDurationSec) {
184
- if (!__privateGet(this, _onGroupDrift)) return;
185
- const resolved = typeof timingOrMediaTimeSec === "object" && timingOrMediaTimeSec !== null ? __privateMethod(this, _MediaRouter_instances, resolveTicks_fn).call(this, trackName, timingOrMediaTimeSec) : __privateMethod(this, _MediaRouter_instances, resolveSeconds_fn).call(this, trackName, timingOrMediaTimeSec, groupDurationSec);
186
- if (!resolved) return;
187
- if (resolved.mediaTimeSec === 0 && packetGroupId !== 0) return;
188
- const expected = resolved.expected;
189
- const result = driftCheck(expected, packetGroupId);
190
- if (result.kind === "aligned") return;
191
- try {
192
- __privateGet(this, _onGroupDrift).call(this, {
193
- trackName,
194
- expectedGroupId: expected,
195
- actualGroupId: packetGroupId,
196
- deltaGroups: result.deltaGroups,
197
- mediaTimeSec: resolved.mediaTimeSec,
198
- groupDurationSec: resolved.groupDurationSec,
199
- ...resolved.timing ? { timing: resolved.timing } : {}
200
- });
201
- } catch (err) {
202
- __privateMethod(this, _MediaRouter_instances, skipWithWarning_fn).call(this, "callback-threw", `[MediaRouter] onGroupDrift callback threw (track=${trackName} expected=${expected} actual=${packetGroupId}); continuing: ${err?.message ?? err}`);
203
- }
105
+ this.#onSourceSwitch = cb;
204
106
  }
205
107
  get activeSource() {
206
- return __privateGet(this, _active);
108
+ return this.#active;
207
109
  }
208
110
  // ── Keyframe repair API ──────────────────────────────────────────
209
111
  /** Register callback for keyframe repair requests. Player wires this to issue MoQ SUBSCRIBE. */
210
112
  onRepairRequest(cb) {
211
- __privateSet(this, _onRepairRequest, cb);
113
+ this.#onRepairRequest = cb;
212
114
  }
213
115
  /**
214
116
  * Request repair for a lost keyframe group. Only fires when activeSource is 'multicast'.
@@ -217,17 +119,16 @@ var MediaRouter = class {
217
119
  * @param trackName - Track name for the SUBSCRIBE (e.g. 'video'). Default: 'video'.
218
120
  */
219
121
  repairLostGroup(expectedGroupId, trackName = "video") {
220
- var _a;
221
- if (__privateGet(this, _active) !== "multicast") return;
222
- if (__privateGet(this, _repairInFlight).has(expectedGroupId)) return;
223
- if (__privateGet(this, _repairInFlight).size >= __privateGet(this, _maxRepairInFlight)) {
122
+ if (this.#active !== "multicast") return;
123
+ if (this.#repairInFlight.has(expectedGroupId)) return;
124
+ if (this.#repairInFlight.size >= this.#maxRepairInFlight) {
224
125
  console.warn(
225
- `[MediaRouter] max repair in flight (${__privateGet(this, _maxRepairInFlight)}), dropping repair for group ${expectedGroupId}`
126
+ `[MediaRouter] max repair in flight (${this.#maxRepairInFlight}), dropping repair for group ${expectedGroupId}`
226
127
  );
227
128
  return;
228
129
  }
229
- __privateGet(this, _repairInFlight).add(expectedGroupId);
230
- (_a = __privateGet(this, _onRepairRequest)) == null ? void 0 : _a.call(this, expectedGroupId, trackName);
130
+ this.#repairInFlight.add(expectedGroupId);
131
+ this.#onRepairRequest?.(expectedGroupId, trackName);
231
132
  }
232
133
  /**
233
134
  * Feed a recovered keyframe frame from the repair path.
@@ -235,17 +136,16 @@ var MediaRouter = class {
235
136
  * Does NOT change activeSource. Does NOT trigger failbackToMoq.
236
137
  */
237
138
  feedRepair(data, meta, kind) {
238
- var _a, _b;
239
- if (__privateGet(this, _active) !== "multicast") return;
139
+ if (this.#active !== "multicast") return;
240
140
  const routedMeta = { ...meta, source: "repair", recovered: true };
241
- if (kind === "video") (_a = __privateGet(this, _onVideoFrame)) == null ? void 0 : _a.call(this, data, routedMeta);
242
- else (_b = __privateGet(this, _onAudioFrame)) == null ? void 0 : _b.call(this, data, routedMeta);
141
+ if (kind === "video") this.#onVideoFrame?.(data, routedMeta);
142
+ else this.#onAudioFrame?.(data, routedMeta);
243
143
  }
244
144
  /**
245
145
  * Clear repair-in-flight state for a group (called after repair completes or times out).
246
146
  */
247
147
  clearRepairInFlight(groupId) {
248
- __privateGet(this, _repairInFlight).delete(groupId);
148
+ this.#repairInFlight.delete(groupId);
249
149
  }
250
150
  // ── Phase 14: deltaActive state machine API ──────────────────────
251
151
  /**
@@ -272,17 +172,17 @@ var MediaRouter = class {
272
172
  "[MediaRouter] configureDelta: either deltaProbeIntervalMs or interleaveDepthMs required for probe interval derivation"
273
173
  );
274
174
  }
275
- __privateSet(this, _deltaWindowSize, cfg.deltaFailWindowBlocks ?? Math.ceil(cfg.framerate));
276
- __privateSet(this, _deltaFailThresholdRatio, cfg.repairSymbols / cfg.sourceSymbols);
277
- __privateSet(this, _deltaRecoverThresholdRatio, __privateGet(this, _deltaFailThresholdRatio) / 2);
278
- __privateSet(this, _deltaProbeIntervalMs, cfg.deltaProbeIntervalMs ?? computeFecDeliveryWindowMs({
175
+ this.#deltaWindowSize = cfg.deltaFailWindowBlocks ?? Math.ceil(cfg.framerate);
176
+ this.#deltaFailThresholdRatio = cfg.repairSymbols / cfg.sourceSymbols;
177
+ this.#deltaRecoverThresholdRatio = this.#deltaFailThresholdRatio / 2;
178
+ this.#deltaProbeIntervalMs = cfg.deltaProbeIntervalMs ?? computeFecDeliveryWindowMs({
279
179
  interleaveDepthMs: cfg.interleaveDepthMs,
280
180
  sourceSymbols: cfg.sourceSymbols
281
- }));
282
- __privateSet(this, _deltaActive, true);
283
- __privateSet(this, _deltaWindow, []);
284
- __privateSet(this, _lastProbeAt, 0);
285
- __privateSet(this, _deltaConfigured, true);
181
+ });
182
+ this.#deltaActive = true;
183
+ this.#deltaWindow = [];
184
+ this.#lastProbeAt = 0;
185
+ this.#deltaConfigured = true;
286
186
  }
287
187
  /**
288
188
  * Notify the state machine of a completed FEC block for the delta track.
@@ -293,59 +193,58 @@ var MediaRouter = class {
293
193
  * If configureDelta() has not been called, this is a silent no-op (pre-catalog state).
294
194
  */
295
195
  notifyDeltaBlock(failed, nowMs) {
296
- var _a, _b;
297
- if (!__privateGet(this, _deltaConfigured)) return;
298
- __privateGet(this, _deltaWindow).push(failed);
299
- if (__privateGet(this, _deltaWindow).length > __privateGet(this, _deltaWindowSize)) {
300
- __privateGet(this, _deltaWindow).shift();
196
+ if (!this.#deltaConfigured) return;
197
+ this.#deltaWindow.push(failed);
198
+ if (this.#deltaWindow.length > this.#deltaWindowSize) {
199
+ this.#deltaWindow.shift();
301
200
  }
302
- if (__privateGet(this, _deltaWindow).length < __privateGet(this, _deltaWindowSize)) return;
303
- const failedCount = __privateGet(this, _deltaWindow).filter((x) => x).length;
304
- const ratio = failedCount / __privateGet(this, _deltaWindowSize);
305
- if (__privateGet(this, _deltaActive)) {
306
- if (ratio > __privateGet(this, _deltaFailThresholdRatio)) {
307
- __privateSet(this, _deltaActive, false);
308
- __privateSet(this, _lastProbeAt, nowMs);
309
- (_a = __privateGet(this, _onDeltaFallbackCb)) == null ? void 0 : _a.call(this);
201
+ if (this.#deltaWindow.length < this.#deltaWindowSize) return;
202
+ const failedCount = this.#deltaWindow.filter((x) => x).length;
203
+ const ratio = failedCount / this.#deltaWindowSize;
204
+ if (this.#deltaActive) {
205
+ if (ratio > this.#deltaFailThresholdRatio) {
206
+ this.#deltaActive = false;
207
+ this.#lastProbeAt = nowMs;
208
+ this.#onDeltaFallbackCb?.();
310
209
  }
311
210
  } else {
312
- if (nowMs - __privateGet(this, _lastProbeAt) >= __privateGet(this, _deltaProbeIntervalMs) && ratio < __privateGet(this, _deltaRecoverThresholdRatio)) {
313
- __privateSet(this, _deltaActive, true);
314
- __privateSet(this, _lastProbeAt, nowMs);
315
- (_b = __privateGet(this, _onDeltaRecoverCb)) == null ? void 0 : _b.call(this);
211
+ if (nowMs - this.#lastProbeAt >= this.#deltaProbeIntervalMs && ratio < this.#deltaRecoverThresholdRatio) {
212
+ this.#deltaActive = true;
213
+ this.#lastProbeAt = nowMs;
214
+ this.#onDeltaRecoverCb?.();
316
215
  }
317
216
  }
318
217
  }
319
218
  /** Register callback fired when delta track degrades past threshold (D-12). */
320
219
  onDeltaFallback(cb) {
321
- __privateSet(this, _onDeltaFallbackCb, cb);
220
+ this.#onDeltaFallbackCb = cb;
322
221
  }
323
222
  /** Register callback fired when delta track recovers below recovery threshold (D-13). */
324
223
  onDeltaRecover(cb) {
325
- __privateSet(this, _onDeltaRecoverCb, cb);
224
+ this.#onDeltaRecoverCb = cb;
326
225
  }
327
226
  /** Whether the delta track is currently considered healthy (true = active). */
328
227
  get deltaActive() {
329
- return __privateGet(this, _deltaActive);
228
+ return this.#deltaActive;
330
229
  }
331
230
  // ── Test-visible accessors for threshold verification ────────────
332
231
  // These expose internal derived values for test assertions (Tests 3,4,5,6,7).
333
232
  // Prefixed with 'delta' to namespace clearly within the public API surface.
334
233
  /** Derived window size — exposed for test assertions (Test 3, 4). */
335
234
  get deltaWindowSize() {
336
- return __privateGet(this, _deltaWindowSize);
235
+ return this.#deltaWindowSize;
337
236
  }
338
237
  /** Derived fail threshold ratio (P/K) — exposed for test assertions (Test 6). */
339
238
  get deltaFailThresholdRatio() {
340
- return __privateGet(this, _deltaFailThresholdRatio);
239
+ return this.#deltaFailThresholdRatio;
341
240
  }
342
241
  /** Derived recovery threshold ratio ((P/K)/2) — exposed for test assertions (Test 7). */
343
242
  get deltaRecoverThresholdRatio() {
344
- return __privateGet(this, _deltaRecoverThresholdRatio);
243
+ return this.#deltaRecoverThresholdRatio;
345
244
  }
346
245
  /** Derived probe interval ms — exposed for test assertions (Test 5a). */
347
246
  get deltaProbeIntervalMs() {
348
- return __privateGet(this, _deltaProbeIntervalMs);
247
+ return this.#deltaProbeIntervalMs;
349
248
  }
350
249
  /**
351
250
  * Register a track name → type mapping from catalog.
@@ -353,7 +252,7 @@ var MediaRouter = class {
353
252
  * takes precedence until the next catalog update.
354
253
  */
355
254
  registerTrackType(trackName, type) {
356
- __privateGet(this, _trackTypes).set(trackName, { type, source: "catalog" });
255
+ this.#trackTypes.set(trackName, { type, source: "catalog" });
357
256
  }
358
257
  /**
359
258
  * Register a track name → type from init data / inline signaling (MMTP FT=0).
@@ -361,9 +260,9 @@ var MediaRouter = class {
361
260
  * Does NOT overwrite an existing catalog registration.
362
261
  */
363
262
  registerTrackTypeFromInit(trackName, type) {
364
- const existing = __privateGet(this, _trackTypes).get(trackName);
263
+ const existing = this.#trackTypes.get(trackName);
365
264
  if (existing?.source === "catalog") return;
366
- __privateGet(this, _trackTypes).set(trackName, { type, source: "init" });
265
+ this.#trackTypes.set(trackName, { type, source: "init" });
367
266
  }
368
267
  /**
369
268
  * Assign a per-track source. Frames from this source bypass the binary
@@ -373,12 +272,12 @@ var MediaRouter = class {
373
272
  * track without a clearTrackSource() in between.
374
273
  */
375
274
  setTrackSource(trackName, source, opts) {
376
- if (__privateGet(this, _trackSources).has(trackName)) {
275
+ if (this.#trackSources.has(trackName)) {
377
276
  throw new TrackSourceConflictError(trackName);
378
277
  }
379
278
  const effectivePolicy = opts?.policy ?? (opts?.overlay ? "wait" : void 0);
380
279
  if (effectivePolicy === "crossfade") {
381
- __privateGet(this, _crossfadeCounters).set(trackName, __privateGet(this, _crossfadeFrames));
280
+ this.#crossfadeCounters.set(trackName, this.#crossfadeFrames);
382
281
  }
383
282
  const record = {
384
283
  source,
@@ -389,9 +288,9 @@ var MediaRouter = class {
389
288
  record.unsubscribeFrame = source.onFrame((data, meta) => {
390
289
  record.emitCount++;
391
290
  if (effectivePolicy === "wait") {
392
- __privateMethod(this, _MediaRouter_instances, handleOverlayFrame_fn).call(this, data, meta);
291
+ this.#handleOverlayFrame(data, meta);
393
292
  } else {
394
- __privateMethod(this, _MediaRouter_instances, emitForTrack_fn).call(this, trackName, data, meta);
293
+ this.#emitForTrack(trackName, data, meta);
395
294
  }
396
295
  });
397
296
  if (source.onError) {
@@ -399,25 +298,25 @@ var MediaRouter = class {
399
298
  this.clearTrackSource(trackName);
400
299
  });
401
300
  }
402
- __privateGet(this, _trackSources).set(trackName, record);
301
+ this.#trackSources.set(trackName, record);
403
302
  }
404
303
  /**
405
304
  * Remove the per-track source for the given track.
406
305
  * Binary switching resumes for this track after this call.
407
306
  */
408
307
  clearTrackSource(trackName) {
409
- const record = __privateGet(this, _trackSources).get(trackName);
308
+ const record = this.#trackSources.get(trackName);
410
309
  if (!record) return;
411
310
  record.unsubscribeFrame();
412
311
  record.unsubscribeError?.();
413
312
  record.source.dispose?.();
414
- __privateGet(this, _trackSources).delete(trackName);
415
- __privateGet(this, _crossfadeCounters).delete(trackName);
416
- const reg = __privateGet(this, _trackTypes).get(trackName);
313
+ this.#trackSources.delete(trackName);
314
+ this.#crossfadeCounters.delete(trackName);
315
+ const reg = this.#trackTypes.get(trackName);
417
316
  const isMedia = reg?.type === "video" || reg?.type === "audio" || reg === void 0 && (trackName === "video" || trackName === "audio");
418
317
  if (!isMedia) {
419
- __privateSet(this, _overlayBoundaryReached, false);
420
- __privateSet(this, _overlayBuffer, []);
318
+ this.#overlayBoundaryReached = false;
319
+ this.#overlayBuffer = [];
421
320
  }
422
321
  }
423
322
  /**
@@ -425,12 +324,11 @@ var MediaRouter = class {
425
324
  * Overlay tracks waiting for alignment flush their buffered frames now.
426
325
  */
427
326
  notifyFecBlockBoundary() {
428
- var _a;
429
- if (__privateGet(this, _overlayBoundaryReached)) return;
430
- __privateSet(this, _overlayBoundaryReached, true);
431
- const buffered = __privateGet(this, _overlayBuffer).splice(0);
327
+ if (this.#overlayBoundaryReached) return;
328
+ this.#overlayBoundaryReached = true;
329
+ const buffered = this.#overlayBuffer.splice(0);
432
330
  for (const { data, meta } of buffered) {
433
- (_a = __privateGet(this, _onOverlayFrame)) == null ? void 0 : _a.call(this, data, meta);
331
+ this.#onOverlayFrame?.(data, meta);
434
332
  }
435
333
  }
436
334
  /**
@@ -439,97 +337,102 @@ var MediaRouter = class {
439
337
  * Returns 0 if no per-track source is active for the track.
440
338
  */
441
339
  trackSourceEmitCount(trackName) {
442
- return __privateGet(this, _trackSources).get(trackName)?.emitCount ?? 0;
340
+ return this.#trackSources.get(trackName)?.emitCount ?? 0;
443
341
  }
444
342
  /** Feed a frame from the MoQ path. Suppressed when multicast is active OR a per-track source owns this track. */
445
343
  feedMoq(data, meta, kind) {
446
- var _a, _b;
447
- if (__privateGet(this, _trackSources).has(kind)) {
448
- const remaining = __privateGet(this, _crossfadeCounters).get(kind);
344
+ if (this.#trackSources.has(kind)) {
345
+ const remaining = this.#crossfadeCounters.get(kind);
449
346
  if (remaining && remaining > 0) {
450
347
  const next = remaining - 1;
451
348
  if (next === 0) {
452
- __privateGet(this, _crossfadeCounters).delete(kind);
349
+ this.#crossfadeCounters.delete(kind);
453
350
  } else {
454
- __privateGet(this, _crossfadeCounters).set(kind, next);
351
+ this.#crossfadeCounters.set(kind, next);
455
352
  }
456
353
  } else {
457
354
  return;
458
355
  }
459
356
  }
460
- if (__privateGet(this, _suppressed)) return;
357
+ if (this.#suppressed) return;
461
358
  const routedMeta = { ...meta, source: "moq" };
462
- if (kind === "video") (_a = __privateGet(this, _onVideoFrame)) == null ? void 0 : _a.call(this, data, routedMeta);
463
- else (_b = __privateGet(this, _onAudioFrame)) == null ? void 0 : _b.call(this, data, routedMeta);
359
+ if (kind === "video") this.#onVideoFrame?.(data, routedMeta);
360
+ else this.#onAudioFrame?.(data, routedMeta);
464
361
  }
465
362
  /** Feed a frame from the multicast path. Video waits for keyframe before activating. */
466
363
  feedMulticast(data, meta, kind) {
467
- var _a, _b;
468
- if (__privateGet(this, _trackSources).has(kind)) {
469
- const remaining = __privateGet(this, _crossfadeCounters).get(kind);
364
+ if (this.#trackSources.has(kind)) {
365
+ const remaining = this.#crossfadeCounters.get(kind);
470
366
  if (remaining && remaining > 0) {
471
367
  const next = remaining - 1;
472
368
  if (next === 0) {
473
- __privateGet(this, _crossfadeCounters).delete(kind);
369
+ this.#crossfadeCounters.delete(kind);
474
370
  } else {
475
- __privateGet(this, _crossfadeCounters).set(kind, next);
371
+ this.#crossfadeCounters.set(kind, next);
476
372
  }
477
373
  } else {
478
374
  return;
479
375
  }
480
376
  }
481
377
  if (kind === "video") {
482
- if (!__privateGet(this, _multicastVideoKeyed)) {
483
- const moqSeededDelta = !meta.keyframe && __privateGet(this, _allowDeltaMulticastTakeoverAfterMoqKeyframe) && __privateGet(this, _moqVideoKeyframeEmitted);
378
+ if (!this.#multicastVideoKeyed) {
379
+ const moqSeededDelta = !meta.keyframe && this.#allowDeltaMulticastTakeoverAfterMoqKeyframe && this.#moqVideoKeyframeEmitted;
484
380
  if (!meta.keyframe && !moqSeededDelta) return;
485
- __privateSet(this, _multicastVideoKeyed, true);
381
+ this.#multicastVideoKeyed = true;
486
382
  const pendingMeta = { ...meta, source: "multicast" };
487
383
  if (!moqSeededDelta) pendingMeta.sourceDiscontinuity = true;
488
- __privateSet(this, _pendingMulticastVideo, {
384
+ this.#pendingMulticastVideo = {
489
385
  data: data.slice(),
490
386
  meta: pendingMeta
491
- });
492
- if (__privateGet(this, _requireAudio) && __privateGet(this, _audioFallbackMs) > 0 && !__privateGet(this, _multicastAudioReceived) && !__privateGet(this, _audioFallbackTimer)) {
493
- __privateSet(this, _audioFallbackTimer, setTimeout(() => {
494
- if (!__privateGet(this, _multicastAudioReceived) && __privateGet(this, _active) !== "multicast") {
495
- __privateSet(this, _multicastAudioReceived, true);
496
- __privateSet(this, _moqAudioWarmed, true);
497
- __privateMethod(this, _MediaRouter_instances, tryActivateMulticast_fn).call(this);
387
+ };
388
+ if (this.#requireAudio && this.#audioFallbackMs > 0 && !this.#multicastAudioReceived && !this.#audioFallbackTimer) {
389
+ this.#audioFallbackTimer = setTimeout(() => {
390
+ if (!this.#multicastAudioReceived && this.#active !== "multicast") {
391
+ this.#multicastAudioReceived = true;
392
+ this.#moqAudioWarmed = true;
393
+ this.#tryActivateMulticast();
498
394
  }
499
- }, __privateGet(this, _audioFallbackMs)));
395
+ }, this.#audioFallbackMs);
500
396
  }
501
- } else if (__privateGet(this, _active) !== "multicast") {
397
+ } else if (this.#active !== "multicast") {
502
398
  if (meta.keyframe) {
503
- __privateSet(this, _pendingMulticastVideo, {
399
+ this.#pendingMulticastVideo = {
504
400
  data: data.slice(),
505
401
  meta: { ...meta, source: "multicast", sourceDiscontinuity: true }
506
- });
402
+ };
507
403
  }
508
- __privateMethod(this, _MediaRouter_instances, tryActivateMulticast_fn).call(this);
404
+ this.#tryActivateMulticast();
509
405
  return;
510
406
  }
511
- if (__privateGet(this, _active) === "multicast") (_a = __privateGet(this, _onVideoFrame)) == null ? void 0 : _a.call(this, data, { ...meta, source: "multicast" });
512
- __privateMethod(this, _MediaRouter_instances, tryActivateMulticast_fn).call(this);
407
+ if (this.#active === "multicast") this.#onVideoFrame?.(data, { ...meta, source: "multicast" });
408
+ this.#tryActivateMulticast();
513
409
  } else {
514
- __privateSet(this, _multicastAudioReceived, true);
515
- if (__privateGet(this, _audioFallbackTimer)) {
516
- clearTimeout(__privateGet(this, _audioFallbackTimer));
517
- __privateSet(this, _audioFallbackTimer, null);
410
+ this.#multicastAudioReceived = true;
411
+ if (this.#audioFallbackTimer) {
412
+ clearTimeout(this.#audioFallbackTimer);
413
+ this.#audioFallbackTimer = null;
518
414
  }
519
- if (!__privateGet(this, _moqAudioWarmed)) __privateSet(this, _moqAudioWarmed, true);
520
- __privateMethod(this, _MediaRouter_instances, tryActivateMulticast_fn).call(this);
521
- if (__privateGet(this, _active) === "multicast") {
522
- (_b = __privateGet(this, _onAudioFrame)) == null ? void 0 : _b.call(this, data, { ...meta, source: "multicast" });
523
- } else if (__privateGet(this, _pendingMulticastToken) !== null) {
524
- __privateSet(this, _pendingMulticastAudio, { data: data.slice(), meta: { ...meta, source: "multicast" } });
415
+ if (!this.#moqAudioWarmed) this.#moqAudioWarmed = true;
416
+ this.#tryActivateMulticast();
417
+ if (this.#active === "multicast") {
418
+ this.#onAudioFrame?.(data, { ...meta, source: "multicast" });
419
+ } else if (this.#pendingMulticastToken !== null) {
420
+ this.#pendingMulticastAudio = { data: data.slice(), meta: { ...meta, source: "multicast" } };
525
421
  }
526
422
  }
527
423
  }
424
+ /**
425
+ * MoQ unicast audio warmup gate. When audio is required, multicast takeover
426
+ * waits until the MoQ unicast audio decoder has emitted at least one frame
427
+ * (so downstream samples-before-takeover counters observe nonzero) or until
428
+ * the existing audio-fallback timer forces the flag true.
429
+ */
430
+ #moqAudioWarmed = false;
528
431
  /** Called by the player when the MoQ unicast audio decoder emits first frame. */
529
432
  notifyMoqAudioEmit() {
530
- if (__privateGet(this, _moqAudioWarmed)) return;
531
- __privateSet(this, _moqAudioWarmed, true);
532
- __privateMethod(this, _MediaRouter_instances, tryActivateMulticast_fn).call(this);
433
+ if (this.#moqAudioWarmed) return;
434
+ this.#moqAudioWarmed = true;
435
+ this.#tryActivateMulticast();
533
436
  }
534
437
  /**
535
438
  * Called by the player after a MoQ video keyframe has reached the active
@@ -537,249 +440,112 @@ var MediaRouter = class {
537
440
  * paths leave allowDeltaMulticastTakeoverAfterMoqKeyframe disabled.
538
441
  */
539
442
  notifyMoqVideoKeyframeEmit() {
540
- __privateSet(this, _moqVideoKeyframeEmitted, true);
541
- __privateMethod(this, _MediaRouter_instances, tryActivateMulticast_fn).call(this);
443
+ this.#moqVideoKeyframeEmitted = true;
444
+ this.#tryActivateMulticast();
445
+ }
446
+ #tryActivateMulticast() {
447
+ if (this.#active === "multicast") return;
448
+ if (this.#pendingMulticastToken !== null) return;
449
+ if (!this.#multicastVideoKeyed) return;
450
+ if (this.#requireAudio && !this.#multicastAudioReceived) return;
451
+ if (this.#requireAudio && !this.#moqAudioWarmed) return;
452
+ const token = ++this.#sourceSwitchToken;
453
+ const maybeReady = this.#onSourceSwitch?.("multicast");
454
+ if (!maybeReady || typeof maybeReady.then !== "function") {
455
+ this.#commitMulticastActivation(token);
456
+ return;
457
+ }
458
+ const ready = Promise.resolve(maybeReady);
459
+ this.#pendingMulticastToken = token;
460
+ this.#sourceSwitchReady = ready;
461
+ void ready.then(
462
+ () => this.#commitMulticastActivation(token),
463
+ (err) => this.#rejectMulticastActivation(token, err)
464
+ ).finally(() => {
465
+ if (this.#sourceSwitchReady === ready) this.#sourceSwitchReady = null;
466
+ });
467
+ }
468
+ #commitMulticastActivation(token) {
469
+ if (token !== this.#sourceSwitchToken) return;
470
+ this.#active = "multicast";
471
+ this.#suppressed = true;
472
+ this.#pendingMulticastToken = null;
473
+ const video = this.#pendingMulticastVideo;
474
+ this.#pendingMulticastVideo = null;
475
+ const audio = this.#pendingMulticastAudio;
476
+ this.#pendingMulticastAudio = null;
477
+ if (video) this.#onVideoFrame?.(video.data, video.meta);
478
+ if (audio) this.#onAudioFrame?.(audio.data, audio.meta);
479
+ }
480
+ #rejectMulticastActivation(token, err) {
481
+ if (token !== this.#sourceSwitchToken) return;
482
+ if (this.#pendingMulticastToken === token) this.#pendingMulticastToken = null;
483
+ this.#pendingMulticastVideo = null;
484
+ this.#pendingMulticastAudio = null;
485
+ console.warn("[MediaRouter] onSourceSwitch(multicast) failed", err);
542
486
  }
543
487
  /** Switch back to MoQ immediately (called on multicast failback). */
544
488
  failbackToMoq() {
545
- var _a;
546
- const hadPendingMulticast = __privateGet(this, _pendingMulticastToken) !== null;
547
- if (__privateGet(this, _active) === "moq" && !hadPendingMulticast) return;
548
- ++__privateWrapper(this, _sourceSwitchToken)._;
549
- __privateSet(this, _active, "moq");
550
- __privateSet(this, _suppressed, false);
551
- __privateSet(this, _pendingMulticastToken, null);
552
- __privateSet(this, _pendingMulticastVideo, null);
553
- __privateSet(this, _pendingMulticastAudio, null);
554
- __privateSet(this, _sourceSwitchReady, null);
555
- __privateSet(this, _multicastVideoKeyed, false);
556
- __privateSet(this, _multicastAudioReceived, false);
557
- __privateSet(this, _moqVideoKeyframeEmitted, false);
558
- if (__privateGet(this, _audioFallbackTimer)) {
559
- clearTimeout(__privateGet(this, _audioFallbackTimer));
560
- __privateSet(this, _audioFallbackTimer, null);
489
+ const hadPendingMulticast = this.#pendingMulticastToken !== null;
490
+ if (this.#active === "moq" && !hadPendingMulticast) return;
491
+ ++this.#sourceSwitchToken;
492
+ this.#active = "moq";
493
+ this.#suppressed = false;
494
+ this.#pendingMulticastToken = null;
495
+ this.#pendingMulticastVideo = null;
496
+ this.#pendingMulticastAudio = null;
497
+ this.#sourceSwitchReady = null;
498
+ this.#multicastVideoKeyed = false;
499
+ this.#multicastAudioReceived = false;
500
+ this.#moqVideoKeyframeEmitted = false;
501
+ if (this.#audioFallbackTimer) {
502
+ clearTimeout(this.#audioFallbackTimer);
503
+ this.#audioFallbackTimer = null;
561
504
  }
562
- (_a = __privateGet(this, _onSourceSwitch)) == null ? void 0 : _a.call(this, "moq");
505
+ this.#onSourceSwitch?.("moq");
563
506
  }
564
507
  /** Dispose timers and per-track sources. Call on teardown to prevent
565
508
  * stale timer callbacks firing into garbage-collected closures (WR-03). */
566
509
  dispose() {
567
- if (__privateGet(this, _audioFallbackTimer)) {
568
- clearTimeout(__privateGet(this, _audioFallbackTimer));
569
- __privateSet(this, _audioFallbackTimer, null);
510
+ if (this.#audioFallbackTimer) {
511
+ clearTimeout(this.#audioFallbackTimer);
512
+ this.#audioFallbackTimer = null;
570
513
  }
571
- for (const [name] of __privateGet(this, _trackSources)) {
514
+ for (const [name] of this.#trackSources) {
572
515
  this.clearTrackSource(name);
573
516
  }
574
517
  }
575
- };
576
- _active = new WeakMap();
577
- _multicastVideoKeyed = new WeakMap();
578
- _multicastAudioReceived = new WeakMap();
579
- _moqVideoKeyframeEmitted = new WeakMap();
580
- _requireAudio = new WeakMap();
581
- _suppressed = new WeakMap();
582
- _audioFallbackTimer = new WeakMap();
583
- _audioFallbackMs = new WeakMap();
584
- _crossfadeFrames = new WeakMap();
585
- _maxOverlayBuffer = new WeakMap();
586
- _allowDeltaMulticastTakeoverAfterMoqKeyframe = new WeakMap();
587
- _repairInFlight = new WeakMap();
588
- _maxRepairInFlight = new WeakMap();
589
- _onRepairRequest = new WeakMap();
590
- _onVideoFrame = new WeakMap();
591
- _onAudioFrame = new WeakMap();
592
- _onOverlayFrame = new WeakMap();
593
- _onSourceSwitch = new WeakMap();
594
- _sourceSwitchReady = new WeakMap();
595
- _sourceSwitchToken = new WeakMap();
596
- _pendingMulticastToken = new WeakMap();
597
- _pendingMulticastVideo = new WeakMap();
598
- _pendingMulticastAudio = new WeakMap();
599
- _trackSources = new WeakMap();
600
- _trackTypes = new WeakMap();
601
- _crossfadeCounters = new WeakMap();
602
- _overlayBoundaryReached = new WeakMap();
603
- _overlayBuffer = new WeakMap();
604
- _deltaConfigured = new WeakMap();
605
- _deltaActive = new WeakMap();
606
- _deltaWindow = new WeakMap();
607
- _deltaWindowSize = new WeakMap();
608
- _deltaFailThresholdRatio = new WeakMap();
609
- _deltaRecoverThresholdRatio = new WeakMap();
610
- _deltaProbeIntervalMs = new WeakMap();
611
- _lastProbeAt = new WeakMap();
612
- _onDeltaFallbackCb = new WeakMap();
613
- _onDeltaRecoverCb = new WeakMap();
614
- _onGroupDrift = new WeakMap();
615
- _groupAlignWarnCounts = new WeakMap();
616
- _MediaRouter_instances = new WeakSet();
617
- /**
618
- * Warn at most `GROUP_ALIGN_WARN_BUDGET[reason]` times **per reason**, across
619
- * every skip and post-emit failure on the drift path.
620
- *
621
- * Note the two call shapes: the resolvers call this *instead of* computing a
622
- * groupId, and return its `null` to skip the drift check; the `onGroupDrift`
623
- * catch calls it after the check already ran and the event was already
624
- * emitted, so there only the warn is coalesced and the `null` is discarded.
625
- *
626
- * Keyed on a short stable `reason` tag, NOT on the formatted message: the
627
- * messages interpolate track name and operand values, so message-keying
628
- * would hand a malformed stream a fresh warn slot on every boundary — the
629
- * log flood this coalescing exists to prevent.
630
- *
631
- * Per-reason rather than one shared boolean (PCL-2211, #329 review): the
632
- * budget is never reset — not by `dispose()`, not on source switch — so a
633
- * single flag means the FIRST malformed boundary of a long-running stream
634
- * permanently silences every later, genuinely different failure mode. The
635
- * throw/overflow diagnostics carry the operand values (`ticks=`, `durTicks=`,
636
- * `err.message`) an incident responder actually needs, and under one shared
637
- * flag those are precisely the ones most likely to be already spent by an
638
- * unrelated NaN at catalog load.
639
- *
640
- * A closed, bounded set of reasons times a small per-reason budget is still
641
- * bounded, so this cannot flood. See `GROUP_ALIGN_WARN_BUDGET` for why the
642
- * budget is not uniform.
643
- */
644
- skipWithWarning_fn = function(reason, message) {
645
- const seen = __privateGet(this, _groupAlignWarnCounts).get(reason) ?? 0;
646
- if (seen < GROUP_ALIGN_WARN_BUDGET[reason]) {
647
- __privateGet(this, _groupAlignWarnCounts).set(reason, seen + 1);
648
- console.warn(message);
649
- }
650
- return null;
651
- };
652
- /**
653
- * Exact path: integers straight from the catalog, no rounding. `mediaTimeSec`
654
- * / `groupDurationSec` are derived for reporting only and never feed the
655
- * groupId computation.
656
- */
657
- resolveTicks_fn = function(trackName, timing) {
658
- const { mediaTimeTicks, groupDurationTicks, timescale } = timing;
659
- if (!Number.isInteger(mediaTimeTicks) || !Number.isInteger(groupDurationTicks) || groupDurationTicks <= 0 || !Number.isInteger(timescale) || timescale <= 0) {
660
- return __privateMethod(this, _MediaRouter_instances, skipWithWarning_fn).call(this, "invalid-tick-inputs", `[MediaRouter] notifyGroupBoundary invalid tick inputs (track=${trackName} mediaTimeTicks=${mediaTimeTicks} groupDurationTicks=${groupDurationTicks} timescale=${timescale}); skipping drift check. Pre-validate at catalog load time.`);
661
- }
662
- try {
663
- return {
664
- expected: groupIdForTicks(mediaTimeTicks, groupDurationTicks),
665
- mediaTimeSec: mediaTimeTicks / timescale,
666
- groupDurationSec: groupDurationTicks / timescale,
667
- // Snapshot, not the caller's reference: a producer that reuses one
668
- // scratch object per boundary would otherwise retroactively mutate
669
- // every GroupDriftEvent it has already emitted. Three integers.
670
- timing: { mediaTimeTicks, groupDurationTicks, timescale }
671
- };
672
- } catch (err) {
673
- return __privateMethod(this, _MediaRouter_instances, skipWithWarning_fn).call(this, "ticks-formula-threw", `[MediaRouter] notifyGroupBoundary: groupIdForTicks threw (track=${trackName} mediaTimeTicks=${mediaTimeTicks} groupDurationTicks=${groupDurationTicks}); skipping drift check: ${err?.message ?? err}`);
674
- }
675
- };
676
- /**
677
- * Legacy seconds path. Quantizes to a synthetic 1e9 Hz timescale — the exact
678
- * behaviour the deprecated `align.groupIdFor` wrapper had, reproduced here so
679
- * that wrapper has no non-test callers left and can be deleted (BLO-21176).
680
- *
681
- * Inherits that wrapper's ns-rounding error; see the `@deprecated` overload.
682
- * Delete this branch once every caller passes ticks.
683
- */
684
- resolveSeconds_fn = function(trackName, mediaTimeSec, groupDurationSec) {
685
- if (!Number.isFinite(groupDurationSec) || groupDurationSec <= 0 || !Number.isFinite(mediaTimeSec)) {
686
- return __privateMethod(this, _MediaRouter_instances, skipWithWarning_fn).call(this, "invalid-seconds-inputs", `[MediaRouter] notifyGroupBoundary invalid inputs (track=${trackName} mediaTimeSec=${mediaTimeSec} groupDurationSec=${groupDurationSec}); skipping drift check. Pre-validate at catalog load time.`);
687
- }
688
- const TS = 1e9;
689
- const ticks = mediaTimeSec < 0 ? 0 : Math.round(mediaTimeSec * TS);
690
- const durTicks = Math.round(groupDurationSec * TS);
691
- if (durTicks <= 0) {
692
- return __privateMethod(this, _MediaRouter_instances, skipWithWarning_fn).call(this, "sub-nanosecond-duration", `[MediaRouter] notifyGroupBoundary: groupDurationSec=${groupDurationSec} rounds to <1 tick at 1e9 Hz (track=${trackName}); skipping drift check. Pass GroupBoundaryTicks for sub-nanosecond durations.`);
693
- }
694
- if (!Number.isSafeInteger(ticks)) {
695
- return __privateMethod(this, _MediaRouter_instances, skipWithWarning_fn).call(this, "media-time-overflow", `[MediaRouter] notifyGroupBoundary: mediaTimeSec=${mediaTimeSec} overflows safe-integer ticks at 1e9 Hz (>~104 days, track=${trackName}); skipping drift check. Pass GroupBoundaryTicks with the catalog timescale.`);
696
- }
697
- try {
698
- return {
699
- expected: groupIdForTicks(ticks, durTicks),
700
- mediaTimeSec,
701
- groupDurationSec
702
- };
703
- } catch (err) {
704
- return __privateMethod(this, _MediaRouter_instances, skipWithWarning_fn).call(this, "seconds-formula-threw", `[MediaRouter] notifyGroupBoundary: groupIdForTicks threw (track=${trackName} mediaTimeSec=${mediaTimeSec} groupDurationSec=${groupDurationSec} ticks=${ticks} durTicks=${durTicks}); skipping drift check: ${err?.message ?? err}`);
705
- }
706
- };
707
- _moqAudioWarmed = new WeakMap();
708
- tryActivateMulticast_fn = function() {
709
- var _a;
710
- if (__privateGet(this, _active) === "multicast") return;
711
- if (__privateGet(this, _pendingMulticastToken) !== null) return;
712
- if (!__privateGet(this, _multicastVideoKeyed)) return;
713
- if (__privateGet(this, _requireAudio) && !__privateGet(this, _multicastAudioReceived)) return;
714
- if (__privateGet(this, _requireAudio) && !__privateGet(this, _moqAudioWarmed)) return;
715
- const token = ++__privateWrapper(this, _sourceSwitchToken)._;
716
- const maybeReady = (_a = __privateGet(this, _onSourceSwitch)) == null ? void 0 : _a.call(this, "multicast");
717
- if (!maybeReady || typeof maybeReady.then !== "function") {
718
- __privateMethod(this, _MediaRouter_instances, commitMulticastActivation_fn).call(this, token);
719
- return;
720
- }
721
- const ready = Promise.resolve(maybeReady);
722
- __privateSet(this, _pendingMulticastToken, token);
723
- __privateSet(this, _sourceSwitchReady, ready);
724
- void ready.then(
725
- () => __privateMethod(this, _MediaRouter_instances, commitMulticastActivation_fn).call(this, token),
726
- (err) => __privateMethod(this, _MediaRouter_instances, rejectMulticastActivation_fn).call(this, token, err)
727
- ).finally(() => {
728
- if (__privateGet(this, _sourceSwitchReady) === ready) __privateSet(this, _sourceSwitchReady, null);
729
- });
730
- };
731
- commitMulticastActivation_fn = function(token) {
732
- var _a, _b;
733
- if (token !== __privateGet(this, _sourceSwitchToken)) return;
734
- __privateSet(this, _active, "multicast");
735
- __privateSet(this, _suppressed, true);
736
- __privateSet(this, _pendingMulticastToken, null);
737
- const video = __privateGet(this, _pendingMulticastVideo);
738
- __privateSet(this, _pendingMulticastVideo, null);
739
- const audio = __privateGet(this, _pendingMulticastAudio);
740
- __privateSet(this, _pendingMulticastAudio, null);
741
- if (video) (_a = __privateGet(this, _onVideoFrame)) == null ? void 0 : _a.call(this, video.data, video.meta);
742
- if (audio) (_b = __privateGet(this, _onAudioFrame)) == null ? void 0 : _b.call(this, audio.data, audio.meta);
743
- };
744
- rejectMulticastActivation_fn = function(token, err) {
745
- if (token !== __privateGet(this, _sourceSwitchToken)) return;
746
- if (__privateGet(this, _pendingMulticastToken) === token) __privateSet(this, _pendingMulticastToken, null);
747
- __privateSet(this, _pendingMulticastVideo, null);
748
- __privateSet(this, _pendingMulticastAudio, null);
749
- console.warn("[MediaRouter] onSourceSwitch(multicast) failed", err);
750
- };
751
- // ── Private helpers ──────────────────────────────────────────────────────
752
- /** Emit a frame on the correct per-track callback using the type registry.
753
- * Falls back to name match if no type registered (backward compat). */
754
- emitForTrack_fn = function(trackName, data, meta) {
755
- var _a, _b, _c, _d, _e, _f;
756
- const reg = __privateGet(this, _trackTypes).get(trackName);
757
- if (reg?.type === "video") {
758
- (_a = __privateGet(this, _onVideoFrame)) == null ? void 0 : _a.call(this, data, meta);
759
- } else if (reg?.type === "audio") {
760
- (_b = __privateGet(this, _onAudioFrame)) == null ? void 0 : _b.call(this, data, meta);
761
- } else if (reg !== void 0) {
762
- (_c = __privateGet(this, _onOverlayFrame)) == null ? void 0 : _c.call(this, data, meta);
763
- } else {
764
- if (trackName === "video") (_d = __privateGet(this, _onVideoFrame)) == null ? void 0 : _d.call(this, data, meta);
765
- else if (trackName === "audio") (_e = __privateGet(this, _onAudioFrame)) == null ? void 0 : _e.call(this, data, meta);
766
- else (_f = __privateGet(this, _onOverlayFrame)) == null ? void 0 : _f.call(this, data, meta);
518
+ // ── Private helpers ──────────────────────────────────────────────────────
519
+ /** Emit a frame on the correct per-track callback using the type registry.
520
+ * Falls back to name match if no type registered (backward compat). */
521
+ #emitForTrack(trackName, data, meta) {
522
+ const reg = this.#trackTypes.get(trackName);
523
+ if (reg?.type === "video") {
524
+ this.#onVideoFrame?.(data, meta);
525
+ } else if (reg?.type === "audio") {
526
+ this.#onAudioFrame?.(data, meta);
527
+ } else if (reg !== void 0) {
528
+ this.#onOverlayFrame?.(data, meta);
529
+ } else {
530
+ if (trackName === "video") this.#onVideoFrame?.(data, meta);
531
+ else if (trackName === "audio") this.#onAudioFrame?.(data, meta);
532
+ else this.#onOverlayFrame?.(data, meta);
533
+ }
767
534
  }
768
- };
769
- /** Handle an overlay frame: buffer until first FEC block boundary, then pass through. */
770
- handleOverlayFrame_fn = function(data, meta) {
771
- var _a;
772
- if (__privateGet(this, _overlayBoundaryReached)) {
773
- (_a = __privateGet(this, _onOverlayFrame)) == null ? void 0 : _a.call(this, data, meta);
774
- return;
775
- }
776
- if (__privateGet(this, _overlayBuffer).length >= __privateGet(this, _maxOverlayBuffer)) {
777
- console.warn(
778
- `[MediaRouter] overlay buffer full (${__privateGet(this, _maxOverlayBuffer)} frames); dropping frame ts=${meta.timestamp}`
779
- );
780
- return;
535
+ /** Handle an overlay frame: buffer until first FEC block boundary, then pass through. */
536
+ #handleOverlayFrame(data, meta) {
537
+ if (this.#overlayBoundaryReached) {
538
+ this.#onOverlayFrame?.(data, meta);
539
+ return;
540
+ }
541
+ if (this.#overlayBuffer.length >= this.#maxOverlayBuffer) {
542
+ console.warn(
543
+ `[MediaRouter] overlay buffer full (${this.#maxOverlayBuffer} frames); dropping frame ts=${meta.timestamp}`
544
+ );
545
+ return;
546
+ }
547
+ this.#overlayBuffer.push({ data, meta });
781
548
  }
782
- __privateGet(this, _overlayBuffer).push({ data, meta });
783
549
  };
784
550
  export {
785
551
  MediaRouter,