@blockcast/mmt-container 0.1.0-main.64a6b356bf43 → 0.1.0-main.6907e07c67dc

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 (106) hide show
  1. package/dist/browser-runtime.js +291 -58
  2. package/dist/browser-runtime.js.map +2 -2
  3. package/dist/catalog-fec-params.d.ts +15 -0
  4. package/dist/catalog-fec-params.d.ts.map +1 -1
  5. package/dist/catalog-fec-params.js +11 -0
  6. package/dist/catalog-fec-params.js.map +2 -2
  7. package/dist/cmaf-block-assembler.js.map +1 -1
  8. package/dist/cmaf-group-batcher.js.map +1 -1
  9. package/dist/cmcd-producer.d.ts.map +1 -1
  10. package/dist/cmcd-producer.js.map +2 -2
  11. package/dist/fec-manager.d.ts +1 -5
  12. package/dist/fec-manager.d.ts.map +1 -1
  13. package/dist/fec-manager.js +7 -19
  14. package/dist/fec-manager.js.map +2 -2
  15. package/dist/fec-worker-setup.d.ts +8 -0
  16. package/dist/fec-worker-setup.d.ts.map +1 -1
  17. package/dist/fec-worker-setup.js +5 -3
  18. package/dist/fec-worker-setup.js.map +2 -2
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +4 -0
  22. package/dist/index.js.map +2 -2
  23. package/dist/media-router.d.ts +19 -7
  24. package/dist/media-router.d.ts.map +1 -1
  25. package/dist/media-router.js +10 -6
  26. package/dist/media-router.js.map +2 -2
  27. package/dist/mfu-reassembler.js +56 -0
  28. package/dist/mfu-reassembler.js.map +2 -2
  29. package/dist/mmtp-container-parser.js +56 -0
  30. package/dist/mmtp-container-parser.js.map +2 -2
  31. package/dist/mmtp-container-parser.no-modules.js +71 -4
  32. package/dist/mmtp-container-parser.no-modules.js.map +2 -2
  33. package/dist/mmtp-decode-pipeline.js +56 -0
  34. package/dist/mmtp-decode-pipeline.js.map +2 -2
  35. package/dist/mmtp-router.d.ts.map +1 -1
  36. package/dist/mmtp-router.js +67 -8
  37. package/dist/mmtp-router.js.map +2 -2
  38. package/dist/mmtp-to-cmaf.d.ts +11 -2
  39. package/dist/mmtp-to-cmaf.d.ts.map +1 -1
  40. package/dist/mmtp-to-cmaf.js +15 -4
  41. package/dist/mmtp-to-cmaf.js.map +2 -2
  42. package/dist/multicast-manager.d.ts +13 -1
  43. package/dist/multicast-manager.d.ts.map +1 -1
  44. package/dist/multicast-manager.js +151 -43
  45. package/dist/multicast-manager.js.map +2 -2
  46. package/dist/multicast-transport.js +9 -5
  47. package/dist/multicast-transport.js.map +2 -2
  48. package/dist/multicast-unwrap.js.map +2 -2
  49. package/dist/no-modules.js +71 -4
  50. package/dist/no-modules.js.map +2 -2
  51. package/dist/signaling.js.map +2 -2
  52. package/dist/timestamp-codec.js.map +1 -1
  53. package/dist/track-session.d.ts +90 -1
  54. package/dist/track-session.d.ts.map +1 -1
  55. package/dist/track-session.js +99 -2
  56. package/dist/track-session.js.map +2 -2
  57. package/dist/wasm-mfu-reassembler.js +56 -0
  58. package/dist/wasm-mfu-reassembler.js.map +2 -2
  59. package/dist/wasm-mmtp-container-parser.js +56 -0
  60. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  61. package/node_modules/@blockcast/fec-worker/README.md +1 -1
  62. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.d.ts +2 -2
  63. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.js +2 -2
  64. package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts +4 -4
  65. package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts.map +1 -1
  66. package/node_modules/@blockcast/fec-worker/dist/fec-worker.js +3 -3
  67. package/node_modules/@blockcast/fec-worker/dist/fec-worker.js.map +2 -2
  68. package/node_modules/@blockcast/fec-worker/src/fec-worker-client.ts +2 -2
  69. package/node_modules/@blockcast/fec-worker/src/fec-worker-types.ts +4 -4
  70. package/node_modules/@blockcast/fec-worker/src/fec-worker.ts +6 -6
  71. package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +6 -5
  72. package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -1
  73. package/node_modules/@blockcast/mmt-base/dist/mmtp.js +5 -4
  74. package/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -1
  75. package/node_modules/@blockcast/mmt-base/src/mmtp.ts +6 -5
  76. package/node_modules/@blockcast/mmt-fec/dist/block-manager.d.ts +3 -1
  77. package/node_modules/@blockcast/mmt-fec/dist/block-manager.d.ts.map +1 -1
  78. package/node_modules/@blockcast/mmt-fec/dist/block-manager.js +3 -1
  79. package/node_modules/@blockcast/mmt-fec/dist/block-manager.js.map +1 -1
  80. package/node_modules/@blockcast/mmt-fec/dist/fec-block-mapper.d.ts +2 -2
  81. package/node_modules/@blockcast/mmt-fec/dist/fec-block-mapper.js +2 -2
  82. package/node_modules/@blockcast/mmt-fec/dist/oti.d.ts +5 -7
  83. package/node_modules/@blockcast/mmt-fec/dist/oti.d.ts.map +1 -1
  84. package/node_modules/@blockcast/mmt-fec/dist/oti.js +4 -6
  85. package/node_modules/@blockcast/mmt-fec/dist/oti.js.map +1 -1
  86. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +6 -5
  87. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -1
  88. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js +5 -4
  89. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -1
  90. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/mmtp.ts +6 -5
  91. package/node_modules/@blockcast/mmt-fec/src/block-manager.ts +3 -1
  92. package/node_modules/@blockcast/mmt-fec/src/fec-block-mapper.ts +2 -2
  93. package/node_modules/@blockcast/mmt-fec/src/oti.ts +5 -7
  94. package/package.json +6 -6
  95. package/src/catalog-fec-params.ts +28 -0
  96. package/src/cmcd-producer.ts +5 -0
  97. package/src/fec-manager.ts +17 -25
  98. package/src/fec-worker-setup.ts +11 -1
  99. package/src/index.ts +2 -0
  100. package/src/media-router.ts +32 -15
  101. package/src/mfu-reassembler.ts +95 -0
  102. package/src/mmtp-router.ts +14 -20
  103. package/src/mmtp-to-cmaf.ts +24 -2
  104. package/src/multicast-manager.ts +142 -18
  105. package/src/track-session.ts +136 -2
  106. package/test-vectors/source-contiguity-v1.json +131 -0
@@ -143,8 +143,8 @@ var init_fec_worker_client = __esm({
143
143
  * Caller must not access data after this call — it is detached.
144
144
  *
145
145
  * Carries the wire-level Repair FEC Payload ID fields (ISO 23008-1 §C.5.3):
146
- * - ssStart: SS_ID of first source symbol in the block (= SBN * SSB_length)
147
- * - ssbLength: K for this block
146
+ * - ssStart: SS_ID of first source symbol in the block (= SBN * configured K)
147
+ * - ssbLength: authored source-symbol count (1..configured K)
148
148
  * - rsId: repair symbol index within the block
149
149
  */
150
150
  feedRepair(ssStart, ssbLength, rsId, data, ts) {
@@ -1936,6 +1936,62 @@ if (void 0) {
1936
1936
  expect(out?.data).toEqual(new Uint8Array([161, 162]));
1937
1937
  expect(out?.sampleOffset).toBe(4);
1938
1938
  });
1939
+ test("a mid-data-unit packet sequence gap strands the data unit", () => {
1940
+ const reassembler = new MFUReassembler({ timeoutMs: null, maxBuffered: 10 });
1941
+ expect(
1942
+ reassembler.addFragment({
1943
+ fragmentationIndicator: 1,
1944
+ mpuSequenceNumber: 7,
1945
+ fragmentCounter: 2,
1946
+ movieFragmentSequenceNumber: 9,
1947
+ sampleNumber: 17,
1948
+ sampleOffset: 0,
1949
+ packetSequenceNumber: 100,
1950
+ data: new Uint8Array([161]),
1951
+ timestamp: 1100n,
1952
+ rapFlag: true
1953
+ })
1954
+ ).toBeNull();
1955
+ const interleaved = reassembler.addFragment({
1956
+ fragmentationIndicator: 0,
1957
+ mpuSequenceNumber: 7,
1958
+ fragmentCounter: 0,
1959
+ movieFragmentSequenceNumber: 9,
1960
+ sampleNumber: 18,
1961
+ sampleOffset: 0,
1962
+ packetSequenceNumber: 101,
1963
+ data: new Uint8Array([255]),
1964
+ timestamp: 1101n,
1965
+ rapFlag: true
1966
+ });
1967
+ expect(interleaved?.data).toEqual(new Uint8Array([255]));
1968
+ expect(
1969
+ reassembler.addFragment({
1970
+ fragmentationIndicator: 2,
1971
+ mpuSequenceNumber: 7,
1972
+ fragmentCounter: 1,
1973
+ packetSequenceNumber: 102,
1974
+ data: new Uint8Array([162]),
1975
+ timestamp: 1102n,
1976
+ rapFlag: false
1977
+ })
1978
+ ).toBeNull();
1979
+ const output = reassembler.addFragment({
1980
+ fragmentationIndicator: 3,
1981
+ mpuSequenceNumber: 7,
1982
+ fragmentCounter: 0,
1983
+ packetSequenceNumber: 103,
1984
+ data: new Uint8Array([163]),
1985
+ timestamp: 1103n,
1986
+ rapFlag: false
1987
+ });
1988
+ expect(output).toBeNull();
1989
+ expect(reassembler.stats.reassembledMFUs).toBe(1);
1990
+ expect(reassembler.stats.rejectedFragments).toBe(0);
1991
+ expect(reassembler.stats.evictedMemoryLimit).toBe(0);
1992
+ expect(reassembler.getStatus().bufferedMFUs).toBe(2);
1993
+ expect(reassembler.getStatus().pendingFragments).toBe(3);
1994
+ });
1939
1995
  test("sibling subsample DUs of one sample reassemble independently by offset", () => {
1940
1996
  const reassembler = new MFUReassembler({ timeoutMs: 1e3 });
1941
1997
  expect(
@@ -7719,16 +7775,26 @@ var MmtpToCmaf = class {
7719
7775
  return __privateGet(this, _audioInitSegment);
7720
7776
  }
7721
7777
  /** Convert a raw video sample to an fMP4 moof+mdat segment. */
7722
- wrapVideoSample(data, timestamp, keyframe, duration) {
7723
- return this.wrapVideoSampleWithTiming(data, timestamp, keyframe, duration).segment;
7778
+ wrapVideoSample(data, timestamp, keyframe, duration, compositionTimeOffset) {
7779
+ return this.wrapVideoSampleWithTiming(data, timestamp, keyframe, duration, compositionTimeOffset).segment;
7724
7780
  }
7725
7781
  /**
7726
7782
  * Convert a raw video sample and return the exact browser media interval
7727
7783
  * encoded into tfdt/trun. Consumers that correlate SourceBuffer appends with
7728
7784
  * requestVideoFrameCallback must use this rebased timestamp, not the wire or
7729
7785
  * caller-owned timestamp passed above.
7786
+ *
7787
+ * `compositionTimeOffset` is the signed authored PTS-DTS delta, in the same
7788
+ * #videoTimescale units as `timestamp` and `duration` — unlike wrapAudioSample,
7789
+ * which takes microseconds and rescales, because every other quantity on this
7790
+ * path is already denominated in #videoTimescale (see setVideoTrackParams).
7791
+ * Passing it therefore needs no conversion here; rescaling would double-convert.
7792
+ * Absent leaves the trun at version 0 with no offset field; a declared 0 is an
7793
+ * authored value and still promotes to version 1. Never reconstruct it from
7794
+ * arrival time.
7730
7795
  */
7731
- wrapVideoSampleWithTiming(data, timestamp, keyframe, duration) {
7796
+ wrapVideoSampleWithTiming(data, timestamp, keyframe, duration, compositionTimeOffset) {
7797
+ assertCompositionTimeOffsets([{ compositionTimeOffset }]);
7732
7798
  if (duration !== void 0 && Number.isFinite(duration) && duration > 0) {
7733
7799
  __privateSet(this, _frameDuration, Math.round(duration));
7734
7800
  } else if (__privateGet(this, _lastVideoTimestamp) > 0 && timestamp > __privateGet(this, _lastVideoTimestamp)) {
@@ -7746,7 +7812,8 @@ var MmtpToCmaf = class {
7746
7812
  frameDuration,
7747
7813
  keyframe,
7748
7814
  __privateWrapper(this, _videoSeq)._++,
7749
- __privateGet(this, _videoTrackId)
7815
+ __privateGet(this, _videoTrackId),
7816
+ compositionTimeOffset
7750
7817
  ),
7751
7818
  mediaTimestamp: relTs,
7752
7819
  duration: frameDuration
@@ -9255,6 +9322,24 @@ var TrackSession = class {
9255
9322
  get isFecArmed() {
9256
9323
  return __privateGet(this, _fecArmed);
9257
9324
  }
9325
+ /**
9326
+ * Start the deadline a `joining` entry deferred while the join was inactive
9327
+ * (SessionManager.joinActive). The track gets the FULL deadline from here,
9328
+ * because that is when media can first arrive. No-op outside `joining` and
9329
+ * when a deadline is already running, so it never shortens or restarts one.
9330
+ *
9331
+ * The `joinActive` guard is what makes this safe to call from anywhere: a
9332
+ * track parked in `joining` with a deferred (null) timer satisfies the other
9333
+ * two, so without it a host calling this while the join is still inactive
9334
+ * would arm the exact deadline the gate exists to defer -- silently
9335
+ * reinstating BLO-34289. It is a no-op for the internal caller, which writes
9336
+ * `#joinActive = true` before iterating the sessions.
9337
+ */
9338
+ armDeferredJoinDeadline() {
9339
+ if (__privateGet(this, _state) !== "joining" || __privateGet(this, _joinDeadlineTimer) !== null) return;
9340
+ if (!__privateGet(this, _manager).joinActive) return;
9341
+ __privateMethod(this, _TrackSession_instances, armJoinDeadline_fn).call(this, __privateGet(this, _manager).takeoverDeadlineMs);
9342
+ }
9258
9343
  dispose() {
9259
9344
  __privateMethod(this, _TrackSession_instances, clearHysteresis_fn).call(this);
9260
9345
  __privateMethod(this, _TrackSession_instances, clearJoinDeadline_fn).call(this);
@@ -9281,7 +9366,9 @@ transition_fn = function(to, opts) {
9281
9366
  const joinDeadlineMs = to === "joining" ? __privateGet(this, _manager).takeoverDeadlineMs : void 0;
9282
9367
  __privateSet(this, _state, to);
9283
9368
  if (from === "joining") __privateMethod(this, _TrackSession_instances, clearJoinDeadline_fn).call(this);
9284
- if (joinDeadlineMs !== void 0) __privateMethod(this, _TrackSession_instances, armJoinDeadline_fn).call(this, joinDeadlineMs);
9369
+ if (joinDeadlineMs !== void 0 && __privateGet(this, _manager).joinActive) {
9370
+ __privateMethod(this, _TrackSession_instances, armJoinDeadline_fn).call(this, joinDeadlineMs);
9371
+ }
9285
9372
  const fecActive = (s) => s === "joining" || s === "multicast" || s === "amt" || s === "failing" || s === "unicast-fallback";
9286
9373
  if (!fecActive(to) && !opts?.retainFec) __privateMethod(this, _TrackSession_instances, disarmFec_fn).call(this);
9287
9374
  __privateGet(this, _manager).callbacks?.onStateChange?.(this.config.trackName, from, to);
@@ -9333,13 +9420,16 @@ unsuppress_fn = function() {
9333
9420
  __privateGet(this, _manager).callbacks?.onSuppress?.(this.config.trackName, false);
9334
9421
  };
9335
9422
  var MAX_TAKEOVER_DEADLINE_MS = 2147483647;
9336
- var _takeoverDeadlineMs, _SessionManager_instances, requireTakeoverDeadlineMs_fn;
9423
+ var JOIN_DEFER_WARN_MS = 3e4;
9424
+ var _takeoverDeadlineMs, _joinActive, _joinDeferWarnTimer, _SessionManager_instances, armJoinDeferWarn_fn, clearJoinDeferWarn_fn, requireTakeoverDeadlineMs_fn;
9337
9425
  var SessionManager = class {
9338
9426
  constructor(poolOptions) {
9339
9427
  __privateAdd(this, _SessionManager_instances);
9340
9428
  this.sessions = /* @__PURE__ */ new Map();
9341
9429
  this.callbacks = null;
9342
9430
  __privateAdd(this, _takeoverDeadlineMs);
9431
+ __privateAdd(this, _joinActive, true);
9432
+ __privateAdd(this, _joinDeferWarnTimer, null);
9343
9433
  this.pool = new TransportPool(poolOptions);
9344
9434
  this.pool.onSubscriptionFailed((sub) => {
9345
9435
  for (const trackName of sub.consumers) {
@@ -9388,6 +9478,62 @@ var SessionManager = class {
9388
9478
  get hasTakeoverDeadline() {
9389
9479
  return __privateGet(this, _takeoverDeadlineMs) !== void 0;
9390
9480
  }
9481
+ /**
9482
+ * Whether the transport the joining tracks are waiting on is actually
9483
+ * subscribed. The takeover deadline is a media-arrival budget and media
9484
+ * cannot arrive before the join exists, so while this is false, entering
9485
+ * `joining` arms no deadline; flipping it true starts the FULL deadline for
9486
+ * every track already parked there.
9487
+ *
9488
+ * Default true, which is the arm-on-`joining` behaviour every host had
9489
+ * before: a host that only calls joinStarted() after its own join resolves
9490
+ * (moqtail-private's player, post-BLO-33339) is already at the right edge and
9491
+ * needs no gate. A host that arms joinStarted() up front — to have FEC
9492
+ * decoders ready before the first datagram — sets this false before addTrack()
9493
+ * and true when its subscribe settles. Charging a slow subscribe (bridge
9494
+ * reconnect, AMT relay handshake) against the media budget expired the
9495
+ * deadline before the subscription existed and abandoned the join on the
9496
+ * happy path. BLO-34289.
9497
+ *
9498
+ * The flag tracks the host's primary join, not per-track transport state. A
9499
+ * track that fails over to the next transport in its own chain while this is
9500
+ * false (transportFailed's failover branch also enters `joining`) has that
9501
+ * deadline gated on the primary join activating, not on its own transport.
9502
+ * Under the documented usage -- false once at setup, true once the subscribe
9503
+ * settles -- the two coincide.
9504
+ *
9505
+ * The gate is on the ENTRY into `joining`, and false cannot take back a
9506
+ * deadline already running: the `true -> false` edge arms the warn below and
9507
+ * clears nothing. So set it false BEFORE the `joining` entry it is meant to
9508
+ * gate. A host that instead flipped it false after a `transportFailed()`
9509
+ * failover had already entered `joining` would leave the full deadline
9510
+ * counting against a subscribe that had not begun -- BLO-34289 again, on the
9511
+ * failover edge. Clearing running deadlines on that edge is deliberately NOT
9512
+ * done: this flag is manager-wide, so one transport's brief false would
9513
+ * cancel an unrelated track's live deadline and then re-arm it at FULL length
9514
+ * on the next activation (armDeferredJoinDeadline sees `joining` + a null
9515
+ * timer and cannot tell a cleared deadline from a deferred one). Every
9516
+ * unrelated transport blip would restart the whole budget, so under repeated
9517
+ * failover a track that should have timed out is extended indefinitely and
9518
+ * never advances. Only a false that never returns true loses the timer
9519
+ * outright, and JOIN_DEFER_WARN_MS already covers that.
9520
+ *
9521
+ * Leaving this false is not free: see JOIN_DEFER_WARN_MS.
9522
+ */
9523
+ get joinActive() {
9524
+ return __privateGet(this, _joinActive);
9525
+ }
9526
+ set joinActive(active) {
9527
+ const wasActive = __privateGet(this, _joinActive);
9528
+ __privateSet(this, _joinActive, active);
9529
+ if (!active) {
9530
+ if (wasActive) __privateMethod(this, _SessionManager_instances, armJoinDeferWarn_fn).call(this);
9531
+ return;
9532
+ }
9533
+ __privateMethod(this, _SessionManager_instances, clearJoinDeferWarn_fn).call(this);
9534
+ if (wasActive) return;
9535
+ for (const [, session] of this.sessions) session.armDeferredJoinDeadline();
9536
+ }
9391
9537
  /** Narrow to MMTP callbacks (onTrackEvent). Safe — optional chaining handles PIM-only consumers. */
9392
9538
  get mmtp() {
9393
9539
  return this.callbacks;
@@ -9541,6 +9687,7 @@ var SessionManager = class {
9541
9687
  // Cleanup
9542
9688
  // -----------------------------------------------------------------------
9543
9689
  dispose() {
9690
+ __privateMethod(this, _SessionManager_instances, clearJoinDeferWarn_fn).call(this);
9544
9691
  for (const [, session] of this.sessions) {
9545
9692
  session.dispose();
9546
9693
  }
@@ -9550,7 +9697,23 @@ var SessionManager = class {
9550
9697
  }
9551
9698
  };
9552
9699
  _takeoverDeadlineMs = new WeakMap();
9700
+ _joinActive = new WeakMap();
9701
+ _joinDeferWarnTimer = new WeakMap();
9553
9702
  _SessionManager_instances = new WeakSet();
9703
+ armJoinDeferWarn_fn = function() {
9704
+ __privateSet(this, _joinDeferWarnTimer, setTimeout(() => {
9705
+ __privateSet(this, _joinDeferWarnTimer, null);
9706
+ const deferred = [...this.sessions.values()].filter((s) => s.state === "joining").length;
9707
+ console.warn(
9708
+ `[SessionManager] joinActive has been false for ${JOIN_DEFER_WARN_MS} ms and ${deferred} track(s) sit in 'joining' with no takeover deadline. Set joinActive = true when the subscribe settles, on every exit path including failures, or these tracks never time out, never release their FEC decoders, and never advance to the next transport.`
9709
+ );
9710
+ }, JOIN_DEFER_WARN_MS));
9711
+ };
9712
+ clearJoinDeferWarn_fn = function() {
9713
+ if (__privateGet(this, _joinDeferWarnTimer) === null) return;
9714
+ clearTimeout(__privateGet(this, _joinDeferWarnTimer));
9715
+ __privateSet(this, _joinDeferWarnTimer, null);
9716
+ };
9554
9717
  // -----------------------------------------------------------------------
9555
9718
  // Track management
9556
9719
  // -----------------------------------------------------------------------
@@ -9898,6 +10061,7 @@ var FECManager = class {
9898
10061
  const k = this.kForPacket(packetId);
9899
10062
  const isSourceSymbol = esi >= 0 && esi < k;
9900
10063
  const isStartupPartial = __privateGet(this, _startupPartialBlocks).has(blockKey);
10064
+ const isReadyMulticastRepair = __privateGet(this, _startupRequireRepairReady) && source === "multicast" && !isSourceSymbol && __privateGet(this, _startupRepairReadyPackets).has(streamKey);
9901
10065
  const awaitingMulticastRepair = __privateGet(this, _startupRequireRepairReady) && source === "multicast" && !__privateGet(this, _startupRepairReadyPackets).has(streamKey) && !__privateGet(this, _startupRepairFailOpenPackets).has(streamKey);
9902
10066
  if (awaitingMulticastRepair) {
9903
10067
  if (!isSourceSymbol) {
@@ -9924,7 +10088,7 @@ var FECManager = class {
9924
10088
  if (isSourceSymbol && esi === 0) {
9925
10089
  __privateGet(this, _startupPartialBlocks).delete(blockKey);
9926
10090
  __privateGet(this, _startupAlignedPackets).add(streamKey);
9927
- } else if (isStartupPartial || !__privateGet(this, _startupAlignedPackets).has(streamKey)) {
10091
+ } else if (isStartupPartial && !isReadyMulticastRepair || !__privateGet(this, _startupAlignedPackets).has(streamKey) && !isReadyMulticastRepair) {
9928
10092
  __privateMethod(this, _FECManager_instances, markStartupPartial_fn).call(this, blockKey);
9929
10093
  return false;
9930
10094
  }
@@ -10017,7 +10181,7 @@ var FECManager = class {
10017
10181
  symbolSizeForPacket(packetId) {
10018
10182
  return __privateMethod(this, _FECManager_instances, resolveTrackConfig_fn).call(this, packetId).symbolSize;
10019
10183
  }
10020
- /** FEC interleave window in milliseconds (0 = no interleaving). */
10184
+ /** FEC block span in milliseconds (0 = no interleaving). */
10021
10185
  get interleaveDepthMs() {
10022
10186
  return __privateGet(this, _fecInterleaveDepthMs);
10023
10187
  }
@@ -10339,14 +10503,10 @@ var FECManager = class {
10339
10503
  return null;
10340
10504
  }
10341
10505
  const fecData = repairData;
10342
- if (ssbLength > 1) {
10343
- this.noteBlockActivity(
10344
- Math.floor(ssStart / ssbLength),
10345
- packetId,
10346
- catalogTrackName
10347
- );
10348
- }
10349
- const sbn = ssbLength > 0 ? Math.floor(ssStart / ssbLength) : 0;
10506
+ const k = this.kForPacket(packetId);
10507
+ if (ssbLength <= 0 || ssbLength > k || ssStart % k !== 0) return null;
10508
+ const sbn = Math.floor(ssStart / k);
10509
+ this.noteBlockActivity(sbn, packetId, catalogTrackName);
10350
10510
  const blockKey = __privateMethod(this, _FECManager_instances, blockKey_fn).call(this, sbn, packetId, catalogTrackName);
10351
10511
  if (__privateGet(this, _completedBlocks).has(blockKey)) return null;
10352
10512
  const syncBlockOwner = __privateGet(this, _syncDecoderBlockOwners).get(blockKey);
@@ -10382,15 +10542,6 @@ var FECManager = class {
10382
10542
  if (recovered) __privateGet(this, _syncDecoderBlockOwners).delete(blockKey);
10383
10543
  return recovered;
10384
10544
  }
10385
- /**
10386
- * Unified symbol feeder. Dispatches to feedSourceSymbol or feedRepairSymbol.
10387
- */
10388
- feedSymbol(packetId, symbolId, data, isRepair) {
10389
- if (isRepair) {
10390
- return this.feedRepairSymbol(packetId, symbolId, 1, symbolId, data);
10391
- }
10392
- return this.feedSourceSymbol(packetId, symbolId, data);
10393
- }
10394
10545
  // -----------------------------------------------------------------------
10395
10546
  // Block lifecycle
10396
10547
  // -----------------------------------------------------------------------
@@ -13497,6 +13648,7 @@ var MmtpRouter = class {
13497
13648
  );
13498
13649
  }
13499
13650
  const repairSbn = __privateMethod(this, _MmtpRouter_instances, deriveRepairSbn_fn).call(this, parsed.ssStart, parsed.ssbLength, ownerPacketId);
13651
+ if (repairSbn === null) return;
13500
13652
  const repairEsi = __privateMethod(this, _MmtpRouter_instances, kForPacket_fn).call(this, ownerPacketId) + parsed.rsId;
13501
13653
  if (!__privateMethod(this, _MmtpRouter_instances, feedFecTransportSymbol_fn).call(this, ownerPacketId, repairSbn, repairEsi, parsed.repairData, "moq", catalogTrackName)) return;
13502
13654
  const recovered = catalogTrackName === void 0 ? __privateGet(this, _fecManager).feedRepairSymbol(
@@ -13527,7 +13679,7 @@ var MmtpRouter = class {
13527
13679
  } else {
13528
13680
  __privateGet(this, _fecManager).markBlockCompleted(repairSbn, ownerPacketId, catalogTrackName);
13529
13681
  }
13530
- __privateMethod(this, _MmtpRouter_instances, routeRecoveredBlock_fn).call(this, repairSbn, recovered, ownerPacketId, parsed.ssbLength, catalogTrackName);
13682
+ __privateMethod(this, _MmtpRouter_instances, routeRecoveredBlock_fn).call(this, repairSbn, recovered, ownerPacketId, catalogTrackName);
13531
13683
  }
13532
13684
  }
13533
13685
  }
@@ -13535,7 +13687,7 @@ var MmtpRouter = class {
13535
13687
  /** Route a recovered FEC block through the parser + dedup pipeline.
13536
13688
  * Sync WASM decoders return K fixed-width source symbols concatenated. */
13537
13689
  routeRecoveredBlock(blockId, data, packetId, catalogTrackName) {
13538
- __privateMethod(this, _MmtpRouter_instances, routeRecoveredBlock_fn).call(this, blockId, data, packetId, void 0, catalogTrackName);
13690
+ __privateMethod(this, _MmtpRouter_instances, routeRecoveredBlock_fn).call(this, blockId, data, packetId, catalogTrackName);
13539
13691
  }
13540
13692
  /** Route a single recovered source symbol through the parser + dedup pipeline.
13541
13693
  * Worker-backed decoders emit one padded source symbol per frame event. */
@@ -13694,8 +13846,9 @@ deriveSbnEsi_fn = function(ssId, packetId) {
13694
13846
  return { sbn: Math.floor(ssId / k), esi: ssId % k };
13695
13847
  };
13696
13848
  deriveRepairSbn_fn = function(ssStart, ssbLength, packetId) {
13697
- if (ssbLength > 0) return Math.floor(ssStart / ssbLength);
13698
- return __privateMethod(this, _MmtpRouter_instances, deriveSbnEsi_fn).call(this, ssStart, packetId).sbn;
13849
+ const k = __privateMethod(this, _MmtpRouter_instances, kForPacket_fn).call(this, packetId);
13850
+ if (ssbLength <= 0 || ssbLength > k || ssStart % k !== 0) return null;
13851
+ return Math.floor(ssStart / k);
13699
13852
  };
13700
13853
  resolveRepairOwnerPacketId_fn = function(packetId, ingress) {
13701
13854
  if (__privateMethod(this, _MmtpRouter_instances, classifyPacketId_fn).call(this, packetId) !== null) return packetId;
@@ -13854,6 +14007,7 @@ processMMTP_fn = function(packet, source, manifestIdentity, manifestAdmitted = f
13854
14007
  );
13855
14008
  }
13856
14009
  const repairSbn = __privateMethod(this, _MmtpRouter_instances, deriveRepairSbn_fn).call(this, parsed.ssStart, parsed.ssbLength, ownerPacketId);
14010
+ if (repairSbn === null) return;
13857
14011
  const repairEsi = __privateMethod(this, _MmtpRouter_instances, kForPacket_fn).call(this, ownerPacketId) + parsed.rsId;
13858
14012
  if (!__privateMethod(this, _MmtpRouter_instances, feedFecTransportSymbol_fn).call(this, ownerPacketId, repairSbn, repairEsi, parsed.repairData, source, catalogTrackNameForPacket(ingress, ownerPacketId))) return;
13859
14013
  const repairCatalogTrackName = catalogTrackNameForPacket(ingress, ownerPacketId);
@@ -13906,7 +14060,7 @@ processMMTP_fn = function(packet, source, manifestIdentity, manifestAdmitted = f
13906
14060
  repairCatalogTrackName
13907
14061
  );
13908
14062
  }
13909
- __privateMethod(this, _MmtpRouter_instances, routeRecoveredBlock_fn).call(this, repairSbn, recovered, ownerPacketId, parsed.ssbLength, catalogTrackNameForPacket(ingress, ownerPacketId));
14063
+ __privateMethod(this, _MmtpRouter_instances, routeRecoveredBlock_fn).call(this, repairSbn, recovered, ownerPacketId, catalogTrackNameForPacket(ingress, ownerPacketId));
13910
14064
  }
13911
14065
  }
13912
14066
  }
@@ -14022,7 +14176,7 @@ processMMTP_fn = function(packet, source, manifestIdentity, manifestAdmitted = f
14022
14176
  catalogTrackName
14023
14177
  );
14024
14178
  }
14025
- __privateMethod(this, _MmtpRouter_instances, routeRecoveredBlock_fn).call(this, sourceFec.sbn, recovered, info.packetId, void 0, catalogTrackName);
14179
+ __privateMethod(this, _MmtpRouter_instances, routeRecoveredBlock_fn).call(this, sourceFec.sbn, recovered, info.packetId, catalogTrackName);
14026
14180
  }
14027
14181
  }
14028
14182
  }
@@ -14370,8 +14524,8 @@ routeDirectRecoveredAudio_fn = function(packetId, data, meta, cb) {
14370
14524
  };
14371
14525
  // ── Private: FEC recovery routing ───────────────────────────────
14372
14526
  /** Route WASM-recovered block through appropriate path based on container kind. */
14373
- routeRecoveredBlock_fn = function(blockId, recovered, ownerPacketId, blockK, catalogTrackName) {
14374
- const k = blockK ?? __privateMethod(this, _MmtpRouter_instances, kForPacket_fn).call(this, ownerPacketId);
14527
+ routeRecoveredBlock_fn = function(blockId, recovered, ownerPacketId, catalogTrackName) {
14528
+ const k = __privateMethod(this, _MmtpRouter_instances, kForPacket_fn).call(this, ownerPacketId);
14375
14529
  const packetSymbolSize = __privateMethod(this, _MmtpRouter_instances, symbolSizeForPacket_fn).call(this, ownerPacketId);
14376
14530
  const symbolSize = packetSymbolSize > 0 ? packetSymbolSize : void 0;
14377
14531
  const result = processFecBlock(recovered, {
@@ -15229,12 +15383,16 @@ var driadDiscovery = new DRIADDiscovery();
15229
15383
  function endpointKey(endpoint) {
15230
15384
  return `${endpoint.sourceAddress ?? ""}|${endpoint.groupAddress}|${endpoint.port}`;
15231
15385
  }
15386
+ function carriesMedia(endpoint) {
15387
+ return endpoint.carriesMedia !== false;
15388
+ }
15232
15389
  function selectMulticastTier(endpoints, estimate) {
15233
- if (endpoints.length <= 1)
15234
- return endpoints[0];
15235
- const ranked = endpoints.filter((endpoint) => typeof endpoint.bandwidth === "number" && endpoint.bandwidth > 0).sort((a, b) => a.bandwidth - b.bandwidth);
15390
+ const media = endpoints.filter(carriesMedia);
15391
+ if (media.length <= 1)
15392
+ return media[0];
15393
+ const ranked = media.filter((endpoint) => typeof endpoint.bandwidth === "number" && endpoint.bandwidth > 0).sort((a, b) => a.bandwidth - b.bandwidth);
15236
15394
  if (ranked.length < 2)
15237
- return endpoints[0];
15395
+ return media[0];
15238
15396
  if (estimate === void 0)
15239
15397
  return ranked[0];
15240
15398
  const budget = estimate * 0.8;
@@ -15483,7 +15641,7 @@ var MulticastOrchestrator = class {
15483
15641
  const currentBandwidth = __privateGet(this, _current).bandwidth;
15484
15642
  if (typeof currentBandwidth !== "number")
15485
15643
  return void 0;
15486
- const desired = this.options.endpoints.filter((endpoint) => typeof endpoint.bandwidth === "number" && endpoint.bandwidth > currentBandwidth).sort((a, b) => a.bandwidth - b.bandwidth)[0];
15644
+ const desired = this.options.endpoints.filter((endpoint) => carriesMedia(endpoint) && typeof endpoint.bandwidth === "number" && endpoint.bandwidth > currentBandwidth).sort((a, b) => a.bandwidth - b.bandwidth)[0];
15487
15645
  if (!desired) {
15488
15646
  __privateSet(this, _favored, void 0);
15489
15647
  return void 0;
@@ -16757,6 +16915,43 @@ function fecReorderWindowFrames(fecInterleaveDepthMs, fps, _k, _repairSymbols) {
16757
16915
  return deriveFecInterleaveDepth(fecInterleaveDepthMs, frameMs);
16758
16916
  }
16759
16917
  var DEFAULT_ALT_GROUP = "__default__";
16918
+ var FEC_DIAGNOSTIC_BLOCK_TAIL = 8;
16919
+ function projectFecDiagnosticBlock(block) {
16920
+ return {
16921
+ sbn: block.sbn,
16922
+ state: block.state,
16923
+ sourceReceived: block.sourceReceived,
16924
+ repairReceived: block.repairReceived,
16925
+ k: block.k,
16926
+ t: block.repairCount,
16927
+ firstSymbolTs: block.firstSymbolTs,
16928
+ lastSymbolTs: block.lastSymbolTs,
16929
+ ...block.completedTs === void 0 ? {} : { completedTs: block.completedTs },
16930
+ deadlineTs: block.deadlineTs,
16931
+ altaVerified: block.altaVerified,
16932
+ relayBlockSigValid: block.relayBlockSigValid
16933
+ };
16934
+ }
16935
+ function projectFecDiagnosticConfig(config) {
16936
+ return {
16937
+ codec: config.codec,
16938
+ trackName: config.trackName,
16939
+ trackType: config.trackType,
16940
+ ...config.resolution === void 0 ? {} : { resolution: { w: config.resolution.w, h: config.resolution.h } },
16941
+ ...config.framerate === void 0 ? {} : { framerate: config.framerate },
16942
+ ...config.sampleRate === void 0 ? {} : { sampleRate: config.sampleRate },
16943
+ ...config.algorithm === void 0 ? {} : { algorithm: config.algorithm },
16944
+ k: config.k,
16945
+ t: config.repairCount,
16946
+ symbolSize: config.symbolSize,
16947
+ interleaveDepth: config.interleaveDepth,
16948
+ interleaveMs: config.interleaveMs,
16949
+ fecMode: config.fecMode,
16950
+ ...config.repairTrack === void 0 ? {} : { repairTrack: config.repairTrack },
16951
+ altaEnabled: config.altaEnabled,
16952
+ relayBlockSigEnabled: config.relayBlockSigEnabled
16953
+ };
16954
+ }
16760
16955
  function publishFecDiagnostics(packetId, stats) {
16761
16956
  const gateway = globalThis.multicast;
16762
16957
  if (typeof gateway?.reportFecDiagnostics !== "function") return false;
@@ -16765,10 +16960,7 @@ function publishFecDiagnostics(packetId, stats) {
16765
16960
  packetId,
16766
16961
  observedAt: Date.now(),
16767
16962
  stats: {
16768
- config: {
16769
- ...stats.config,
16770
- resolution: stats.config.resolution ? { ...stats.config.resolution } : void 0
16771
- },
16963
+ config: projectFecDiagnosticConfig(stats.config),
16772
16964
  sourceSymbols: stats.sourceSymbols,
16773
16965
  repairSymbols: stats.repairSymbols,
16774
16966
  blocksComplete: stats.blocksComplete,
@@ -16777,7 +16969,7 @@ function publishFecDiagnostics(packetId, stats) {
16777
16969
  greenFillFrames: stats.greenFillFrames,
16778
16970
  recoveryRate: stats.recoveryRate,
16779
16971
  liveSbn: stats.liveSbn,
16780
- blocks: stats.blocks.slice(-8).map((block) => ({ ...block })),
16972
+ blocks: stats.blocks.slice(-FEC_DIAGNOSTIC_BLOCK_TAIL).map(projectFecDiagnosticBlock),
16781
16973
  interleaveWindowBlocks: stats.interleaveWindowBlocks,
16782
16974
  avgRecoveryMs: stats.avgRecoveryMs,
16783
16975
  maxRecoveryMs: stats.maxRecoveryMs
@@ -16789,6 +16981,24 @@ function publishFecDiagnostics(packetId, stats) {
16789
16981
  function altGroupKey(track) {
16790
16982
  return track.altGroup === void 0 ? DEFAULT_ALT_GROUP : String(track.altGroup);
16791
16983
  }
16984
+ function repairTrackNamesBySource(tracks) {
16985
+ const bySource = /* @__PURE__ */ new Map();
16986
+ const add = (source, repair) => {
16987
+ if (!source || !repair) return;
16988
+ const names = bySource.get(source) ?? /* @__PURE__ */ new Set();
16989
+ names.add(repair);
16990
+ bySource.set(source, names);
16991
+ };
16992
+ for (const track of tracks) {
16993
+ if (track.fec !== void 0 && isFecCatalogConfig(track.fec) && track.fec.repairTrack) {
16994
+ add(track.name, track.fec.repairTrack);
16995
+ }
16996
+ if (track.packaging === "fec-repair" && Array.isArray(track.depends) && track.depends.length === 1) {
16997
+ add(track.depends[0], track.name);
16998
+ }
16999
+ }
17000
+ return bySource;
17001
+ }
16792
17002
  var _fec, _router, _transport, _reportedFecDiagnosticsFailure, _streamFecBaseline, _trackFecTiming, _switchingSets, _repairPacketIds, _repairInFlight, _repairLifecycleObservers, _trackResetObservers, _onRepairSubscribeCb, _MulticastManager_instances, configureTrackMapper_fn, applyStreamGlobalFecTiming_fn, _onTrackTypeDiscovered, emitRepairLifecycle_fn;
16793
17003
  var MulticastManager = class {
16794
17004
  constructor(options) {
@@ -17249,12 +17459,13 @@ var MulticastManager = class {
17249
17459
  * a factory returning a distinct decoder per stream.
17250
17460
  */
17251
17461
  configureMultiTrack(catalog, wasmDecoderSource) {
17462
+ const repairNamesBySource = repairTrackNamesBySource(catalog.tracks);
17252
17463
  const repairOwnerGroup = /* @__PURE__ */ new Map();
17253
17464
  const repairOwnerAltGroup = /* @__PURE__ */ new Map();
17254
17465
  for (const track of catalog.tracks) {
17255
- if (track.fec !== void 0 && isFecCatalogConfig(track.fec) && track.fec.repairTrack) {
17256
- repairOwnerGroup.set(track.fec.repairTrack, altGroupKey(track));
17257
- repairOwnerAltGroup.set(track.fec.repairTrack, track.altGroup);
17466
+ for (const repairName of repairNamesBySource.get(track.name) ?? []) {
17467
+ repairOwnerGroup.set(repairName, altGroupKey(track));
17468
+ repairOwnerAltGroup.set(repairName, track.altGroup);
17258
17469
  }
17259
17470
  }
17260
17471
  const groupKeyFor = (track) => repairOwnerGroup.get(track.name) ?? altGroupKey(track);
@@ -17357,9 +17568,13 @@ var MulticastManager = class {
17357
17568
  }
17358
17569
  if (track.fec !== void 0) {
17359
17570
  const fecCfg = track.fec;
17360
- const repairTrack = catalogTracksByName.get(fecCfg.repairTrack);
17361
- if (track.packetId !== void 0 && repairTrack?.packetId !== void 0) {
17362
- __privateGet(this, _router).setRepairPacketIdOwner(repairTrack.packetId, track.packetId);
17571
+ if (track.packetId !== void 0) {
17572
+ for (const repairName of repairNamesBySource.get(track.name) ?? []) {
17573
+ const repairTrack = catalogTracksByName.get(repairName);
17574
+ if (repairTrack?.packetId !== void 0) {
17575
+ __privateGet(this, _router).setRepairPacketIdOwner(repairTrack.packetId, track.packetId);
17576
+ }
17577
+ }
17363
17578
  }
17364
17579
  const wasmDecoder = fecDecoders.get(i);
17365
17580
  if (track.packetId !== void 0 && wasmDecoder !== void 0) {
@@ -17649,7 +17864,9 @@ async function setupFecWorkerForTrack(opts) {
17649
17864
  sampleRate: opts.sampleRate,
17650
17865
  algorithm: "raptor",
17651
17866
  k: opts.fecK,
17652
- repairCount: opts.fecRepairCount,
17867
+ // P as this receiver joined it, not the catalog total: the worker snapshot
17868
+ // and CMCD `x-bc-fec-p` are read from this. Identity on a single layer.
17869
+ repairCount: opts.joinedRepairCount ?? opts.fecRepairCount,
17653
17870
  symbolSize: opts.fecSymbolSize,
17654
17871
  interleaveDepth: interleaveDepthBlocks,
17655
17872
  interleaveMs: opts.fecInterleaveMs,
@@ -17847,12 +18064,16 @@ var MediaRouter = class {
17847
18064
  __privateAdd(this, _onDeltaFallbackCb, null);
17848
18065
  __privateAdd(this, _onDeltaRecoverCb, null);
17849
18066
  // ── Group-alignment observer (align.ts formula) ──────────────────
17850
- // Observation only — does NOT alter routing. Producers are wired in
17851
- // follow-up PRs; when they land they will call
17852
- // CmcdProducer.incrementSwitchMiscount() + emitSwitchDrift() from the
17853
- // onGroupDrift callback so divergence between packet-stamped groupIds
17854
- // and the shared formula surfaces on `x-bc-switch-drift-us` /
17855
- // `x-bc-switch-miscount`. Canonical Go impl: Blockcast/multicast
18067
+ // Observation only — does NOT alter routing, and nothing consumes it.
18068
+ // This note previously promised follow-up PRs wiring onGroupDrift to
18069
+ // CmcdProducer.incrementSwitchMiscount() + emitSwitchDrift(). Those PRs
18070
+ // never landed, and the sink they targeted was built by a different route:
18071
+ // both players already drive those two methods from
18072
+ // SwitchingSetMonitor.onMisaligned (base-vs-delta first-frame skew), so
18073
+ // wiring onGroupDrift there too would write one CMCD key from two
18074
+ // detectors measuring different faults. Do not re-license that wiring from
18075
+ // this comment. Removal of the whole hook is tracked by BLO-34141.
18076
+ // Canonical Go impl: Blockcast/multicast
17856
18077
  // cmd/caddy/sender/group_align.go (commit 104eeff). Canonical Rust impl:
17857
18078
  // moqtail/moqtail apps/relay/src/server/abr.rs (branch
17858
18079
  // experimental/server-side-abr, commit 39accbf).
@@ -19511,6 +19732,16 @@ var NO_FEC = {
19511
19732
  fecSymbolSize: 0,
19512
19733
  fecInterleaveMs: 0
19513
19734
  };
19735
+ function joinedRepairSymbolCount(params, joinedRepairTrackNames) {
19736
+ const layers = params.repairLayers;
19737
+ if (layers === void 0 || layers.length === 0) return params.fecRepairCount;
19738
+ const joined = new Set(joinedRepairTrackNames);
19739
+ let total = 0;
19740
+ for (const layer of layers) {
19741
+ if (joined.has(layer.repairTrackName)) total += layer.repairSymbols;
19742
+ }
19743
+ return total;
19744
+ }
19514
19745
  function recordOf(value) {
19515
19746
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
19516
19747
  }
@@ -19840,6 +20071,7 @@ export {
19840
20071
  FEC_SBN_MAX,
19841
20072
  FecSourceInfo,
19842
20073
  FecStarvationDetector,
20074
+ JOIN_DEFER_WARN_MS,
19843
20075
  KEYFRAME_LOST_TIMEOUT_SLACK,
19844
20076
  LOCHeaderExtensionId,
19845
20077
  MAX_ENCODING_SYMBOL_ID,
@@ -19940,6 +20172,7 @@ export {
19940
20172
  isSignalingPacket,
19941
20173
  isSourcePacket,
19942
20174
  isTrackTimingConfig,
20175
+ joinedRepairSymbolCount,
19943
20176
  mergeOverrideIntoCmsfTracks,
19944
20177
  mergeOverrideIntoHangRenditions,
19945
20178
  mfuReassemblyTimeoutMs,