@blockcast/mmt-container 0.4.0-main.bb90ce9247fa → 0.4.0-main.bbdfdbf39ded

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 (205) hide show
  1. package/README.md +36 -20
  2. package/dist/align.d.ts +24 -18
  3. package/dist/align.d.ts.map +1 -1
  4. package/dist/align.js +23 -4
  5. package/dist/align.js.map +2 -2
  6. package/dist/browser-runtime.js +1721 -705
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +72 -34
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +309 -204
  11. package/dist/carp-catalog.js.map +3 -3
  12. package/dist/catalog-fec-params.d.ts +15 -4
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +137 -50
  15. package/dist/catalog-fec-params.js.map +4 -4
  16. package/dist/catalog-network-source.d.ts +24 -2
  17. package/dist/catalog-network-source.d.ts.map +1 -1
  18. package/dist/catalog-network-source.js +24 -1
  19. package/dist/catalog-network-source.js.map +3 -3
  20. package/dist/catalog-validator.d.ts +4 -3
  21. package/dist/catalog-validator.d.ts.map +1 -1
  22. package/dist/catalog-validator.js +0 -29
  23. package/dist/catalog-validator.js.map +3 -3
  24. package/dist/delivery-catalog.js +100 -230
  25. package/dist/delivery-catalog.js.map +4 -4
  26. package/dist/fec-manager.d.ts +64 -1
  27. package/dist/fec-manager.d.ts.map +1 -1
  28. package/dist/fec-manager.js +275 -62
  29. package/dist/fec-manager.js.map +4 -4
  30. package/dist/fec-state.d.ts +5 -3
  31. package/dist/fec-state.d.ts.map +1 -1
  32. package/dist/fec-state.js +34 -12
  33. package/dist/fec-state.js.map +4 -4
  34. package/dist/fec-worker-setup.d.ts +2 -0
  35. package/dist/fec-worker-setup.d.ts.map +1 -1
  36. package/dist/fec-worker-setup.js +15 -3
  37. package/dist/fec-worker-setup.js.map +3 -3
  38. package/dist/index.d.ts +5 -5
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +14 -8
  41. package/dist/index.js.map +2 -2
  42. package/dist/iso-block-locator.d.ts +29 -0
  43. package/dist/iso-block-locator.d.ts.map +1 -1
  44. package/dist/iso-block-locator.js +100 -17
  45. package/dist/iso-block-locator.js.map +4 -4
  46. package/dist/manifest-auth-plan.d.ts +26 -25
  47. package/dist/manifest-auth-plan.d.ts.map +1 -1
  48. package/dist/manifest-auth-plan.js +331 -1171
  49. package/dist/manifest-auth-plan.js.map +4 -4
  50. package/dist/mfu-reassembler.js +24 -13
  51. package/dist/mfu-reassembler.js.map +3 -3
  52. package/dist/mmtp-container-parser.d.ts.map +1 -1
  53. package/dist/mmtp-container-parser.js +96 -22
  54. package/dist/mmtp-container-parser.js.map +3 -3
  55. package/dist/mmtp-container-parser.no-modules.js +1138 -325
  56. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  57. package/dist/mmtp-decode-pipeline.js +96 -22
  58. package/dist/mmtp-decode-pipeline.js.map +3 -3
  59. package/dist/mmtp-fec-session.d.ts +159 -0
  60. package/dist/mmtp-fec-session.d.ts.map +1 -0
  61. package/dist/mmtp-fec-session.js +531 -0
  62. package/dist/mmtp-fec-session.js.map +7 -0
  63. package/dist/mmtp-router.d.ts +31 -5
  64. package/dist/mmtp-router.d.ts.map +1 -1
  65. package/dist/mmtp-router.js +168 -22
  66. package/dist/mmtp-router.js.map +3 -3
  67. package/dist/multicast-auth-catalog.d.ts +86 -92
  68. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  69. package/dist/multicast-auth-catalog.js +347 -132
  70. package/dist/multicast-auth-catalog.js.map +4 -4
  71. package/dist/multicast-input.d.ts +28 -6
  72. package/dist/multicast-input.d.ts.map +1 -1
  73. package/dist/multicast-input.js +293 -28
  74. package/dist/multicast-input.js.map +3 -3
  75. package/dist/multicast-manager.d.ts +89 -5
  76. package/dist/multicast-manager.d.ts.map +1 -1
  77. package/dist/multicast-manager.js +730 -356
  78. package/dist/multicast-manager.js.map +4 -4
  79. package/dist/multicast-transport.d.ts +12 -2
  80. package/dist/multicast-transport.d.ts.map +1 -1
  81. package/dist/multicast-transport.js +111 -235
  82. package/dist/multicast-transport.js.map +4 -4
  83. package/dist/multicast-unwrap.js +24 -13
  84. package/dist/multicast-unwrap.js.map +3 -3
  85. package/dist/no-modules.d.ts +4 -1
  86. package/dist/no-modules.d.ts.map +1 -1
  87. package/dist/no-modules.js +1087 -309
  88. package/dist/no-modules.js.map +4 -4
  89. package/dist/phase14-catalog-override.d.ts +1 -1
  90. package/dist/phase14-catalog-override.d.ts.map +1 -1
  91. package/dist/phase14-catalog-override.js +2 -2
  92. package/dist/phase14-catalog-override.js.map +2 -2
  93. package/dist/repair-fetch.d.ts +81 -6
  94. package/dist/repair-fetch.d.ts.map +1 -1
  95. package/dist/repair-fetch.js +159 -31
  96. package/dist/repair-fetch.js.map +3 -3
  97. package/dist/repair-layers.d.ts +2 -0
  98. package/dist/repair-layers.d.ts.map +1 -1
  99. package/dist/repair-layers.js +22 -2
  100. package/dist/repair-layers.js.map +3 -3
  101. package/dist/sample-combiner.d.ts +7 -1
  102. package/dist/sample-combiner.d.ts.map +1 -1
  103. package/dist/sample-combiner.js +14 -2
  104. package/dist/sample-combiner.js.map +2 -2
  105. package/dist/signaling.d.ts +2 -2
  106. package/dist/signaling.d.ts.map +1 -1
  107. package/dist/signaling.js +6 -3
  108. package/dist/signaling.js.map +3 -3
  109. package/dist/source-auth.js +2710 -7
  110. package/dist/source-auth.js.map +4 -4
  111. package/dist/switching-set-alignment.d.ts +1 -1
  112. package/dist/switching-set-alignment.js.map +1 -1
  113. package/dist/timestamp-codec.js +24 -13
  114. package/dist/timestamp-codec.js.map +3 -3
  115. package/dist/wasm-mfu-reassembler.js +3 -0
  116. package/dist/wasm-mfu-reassembler.js.map +3 -3
  117. package/dist/wasm-mmtp-container-parser.js +96 -22
  118. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  119. package/package.json +6 -9
  120. package/schemas/catalog.schema.json +124 -37
  121. package/src/align.ts +52 -21
  122. package/src/carp-catalog.ts +163 -61
  123. package/src/catalog-fec-params.ts +66 -20
  124. package/src/catalog-network-source.ts +45 -2
  125. package/src/catalog-validator.ts +4 -11
  126. package/src/fec-manager.ts +239 -63
  127. package/src/fec-state.ts +14 -12
  128. package/src/fec-worker-setup.ts +20 -2
  129. package/src/index.ts +29 -10
  130. package/src/iso-block-locator.ts +97 -6
  131. package/src/manifest-auth-plan.ts +39 -91
  132. package/src/mmtp-container-parser.ts +75 -7
  133. package/src/mmtp-fec-session.ts +533 -0
  134. package/src/mmtp-router.ts +133 -5
  135. package/src/multicast-auth-catalog.ts +131 -238
  136. package/src/multicast-input.ts +119 -61
  137. package/src/multicast-manager.ts +258 -21
  138. package/src/multicast-transport.ts +17 -3
  139. package/src/no-modules.ts +7 -1
  140. package/src/phase14-catalog-override.ts +3 -3
  141. package/src/repair-fetch.ts +283 -39
  142. package/src/repair-layers.ts +22 -2
  143. package/src/sample-combiner.ts +15 -2
  144. package/src/signaling.ts +2 -2
  145. package/src/switching-set-alignment.ts +1 -1
  146. package/test-vectors/align.json +108 -32
  147. package/test-vectors/bc-provenance-v2.json +1526 -0
  148. package/test-vectors/catalog/README.md +65 -4
  149. package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
  150. package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
  151. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
  152. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  153. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  154. package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
  155. package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
  156. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  157. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  158. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  159. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  160. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  161. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  162. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  163. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  164. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  165. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  166. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  167. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  168. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  169. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  170. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  171. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
  172. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
  173. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  174. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  175. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  176. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  177. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  178. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  179. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  180. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  181. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  182. package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
  183. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
  184. package/test-vectors/catalog/positive/fec-multicast.json +1 -1
  185. package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
  186. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  187. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  188. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  189. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +2 -2
  190. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  191. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  192. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  193. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  194. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  195. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  196. package/test-vectors/catalog/section-codes.json +30 -1
  197. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  198. package/test-vectors/catalog-validation.json +101 -5
  199. package/test-vectors/catalog-validator-public-api.mjs +14 -9
  200. package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
  201. package/dist/fec-codec.d.ts +0 -32
  202. package/dist/fec-codec.d.ts.map +0 -1
  203. package/dist/fec-codec.js +0 -47
  204. package/dist/fec-codec.js.map +0 -7
  205. package/src/fec-codec.ts +0 -61
@@ -44,7 +44,7 @@ export interface Phase14OverrideTrack {
44
44
  * derives it from the override's top-level `streamingFormat`. */
45
45
  packaging?: "mmtp" | "cmaf" | "loc" | "timeline";
46
46
  /** Required when packaging is `mmtp`; the current publisher emits MFU mode. */
47
- mmtpMode?: "mpu" | "mfu";
47
+ mmtpMode?: "mfu";
48
48
  /** Required when packaging is `mmtp`; copied into synthesized CMSF tracks. */
49
49
  timescale?: number;
50
50
  /** Required when packaging is `mmtp`; copied into synthesized C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.role = ot.role;
79
79
  if (existing.packaging === "mmtp") {
80
80
  const mode = existing.mmtpMode ?? ot.mmtpMode;
81
- if (mode !== "mpu" && mode !== "mfu") {
81
+ if (mode !== "mfu") {
82
82
  throw new Error(
83
83
  `[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`
84
84
  );
@@ -115,7 +115,7 @@ function mergeOverrideIntoCmsfTracks(tracks, override) {
115
115
  );
116
116
  }
117
117
  const mmtpMode = ot.mmtpMode;
118
- if (packaging === "mmtp" && mmtpMode !== "mpu" && mmtpMode !== "mfu") {
118
+ if (packaging === "mmtp" && mmtpMode !== "mfu") {
119
119
  throw new Error(
120
120
  `[phase14-catalog-override] track "${ot.name}" has packaging='mmtp' but no valid mmtpMode`
121
121
  );
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/phase14-catalog-override.ts"],
4
- "sourcesContent": ["/**\n * Phase 14 catalog-override hook (test harness only).\n *\n * When `globalThis.__PHASE14_CATALOG_OVERRIDE` is set (injected by the\n * 7point test via `page.addInitScript` \u2014 see\n * packages/moq-server/tests/7point-validation.test.mjs `applyPhase14CatalogOverride`)\n * the override's `tracks[]` are merged into whatever catalog the MoQ-delivered\n * JSON produced:\n *\n * - Dedupe by `track.name`.\n * - When both sides carry a track with the same name, the override's\n * `fec` config wins \u2014 this is how the 7point harness steers multi-track\n * tests onto the Phase 14 `video/base` + `video/delta` + `video/repair`\n * switching set without asking the publisher to change its catalog.\n * - Tracks present only in the override are appended as-is.\n * - Tracks present only in the MoQ catalog are preserved unchanged.\n *\n * This module is deliberately player-agnostic. It exposes:\n *\n * getPhase14CatalogOverride() \u2014 read + shape-check the global.\n * mergeOverrideIntoHangRenditions() \u2014 merge into a `@moq/hang`\n * Catalog.Root `video.renditions` /\n * `audio.renditions` dict. Used by\n * hang-mmt-fec/js/watch/src/broadcast.ts.\n * mergeOverrideIntoCmsfTracks() \u2014 merge into moqtail's CMSF-flat\n * `tracks[]` array. Used by\n * moqtail-private CMSFCatalog.from().\n *\n * Production builds never set the global, so all three helpers are no-ops at\n * runtime unless the test harness opts in.\n */\n\nimport type { FecAlgorithm, FecCatalogConfig } from \"./carp-catalog.js\";\n\n// ---------------------------------------------------------------------------\n// Override fixture shape (IETF draft-ietf-moq-catalogformat-01)\n// ---------------------------------------------------------------------------\n\n/**\n * A single override track entry \u2014 mirrors the fixture at\n * `packages/moq-server/tests/fixtures/multi-track-catalog.json`.\n *\n * Kept intentionally permissive: the canonical fixture carries `name`,\n * `altGroup`, `framerate`, and `fec`, but future 7point scenarios may extend\n * with additional hints without wanting this module to gate-keep them.\n */\nexport interface Phase14OverrideTrack {\n\tname: string;\n\t/** CMSF packaging kind. Optional per track \u2014 when absent, the merge\n\t * derives it from the override's top-level `streamingFormat`. */\n\tpackaging?: \"mmtp\" | \"cmaf\" | \"loc\" | \"timeline\";\n\t/** Required when packaging is `mmtp`; the current publisher emits MFU mode. */\n\tmmtpMode?: \"mpu\" | \"mfu\";\n\t/** Required when packaging is `mmtp`; copied into synthesized CMSF tracks. */\n\ttimescale?: number;\n\t/** Required when packaging is `mmtp`; copied into synthesized CMSF tracks. */\n\tgroupDurationMs?: number;\n\t/** Codec string. Optional per track \u2014 when absent, the merge inherits\n\t * from the existing video/audio rendition in the MoQ catalog (the\n\t * publisher's declaration). Throws only when neither the override nor\n\t * any existing rendition supplies one. */\n\tcodec?: string;\n\trole?: \"video\" | \"audio\" | \"timeline\";\n\taltGroup?: number;\n\tframerate?: number;\n\tfec?: Partial<FecCatalogConfig> & { algorithm: FecAlgorithm };\n}\n\n/**\n * The shape the 7point harness writes to `globalThis.__PHASE14_CATALOG_OVERRIDE`.\n * Extra top-level fields (`version`, `streamingFormat`, ...) are ignored \u2014\n * the merge only consumes `tracks[]`.\n */\nexport interface Phase14CatalogOverride {\n\tversion?: string;\n\tstreamingFormat?: string;\n\ttracks: Phase14OverrideTrack[];\n}\n\n// ---------------------------------------------------------------------------\n// Global reader\n// ---------------------------------------------------------------------------\n\n/**\n * Read `globalThis.__PHASE14_CATALOG_OVERRIDE` and return it only when it has\n * a well-formed `tracks[]` array. Malformed values log + return `null` rather\n * than throw so a broken fixture never kills the MoQ path for a real stream.\n */\nexport function getPhase14CatalogOverride(): Phase14CatalogOverride | null {\n\t// `globalThis` is defined in workers, service workers, and the main window;\n\t// it's the portable way to reach the test-injected hook from any context.\n\tconst g = globalThis as Record<string, unknown>;\n\tconst raw = g[\"__PHASE14_CATALOG_OVERRIDE\"];\n\tif (raw === undefined || raw === null) return null;\n\tif (typeof raw !== \"object\") {\n\t\tconsole.warn(\"[phase14-catalog-override] hook is not an object; ignoring\");\n\t\treturn null;\n\t}\n\tconst obj = raw as Record<string, unknown>;\n\tconst tracks = obj[\"tracks\"];\n\tif (!Array.isArray(tracks)) {\n\t\tconsole.warn(\"[phase14-catalog-override] hook.tracks is not an array; ignoring\");\n\t\treturn null;\n\t}\n\t// Shallow filter: keep only entries that at least have a string name.\n\t// Each consumer (hang or CMSF merge) validates shape further.\n\tconst filtered: Phase14OverrideTrack[] = [];\n\tfor (const t of tracks) {\n\t\tif (typeof t === \"object\" && t !== null) {\n\t\t\tconst entry = t as Record<string, unknown>;\n\t\t\tif (typeof entry[\"name\"] === \"string\" && (entry[\"name\"] as string).length > 0) {\n\t\t\t\tfiltered.push(entry as unknown as Phase14OverrideTrack);\n\t\t\t}\n\t\t}\n\t}\n\tif (filtered.length === 0) return null;\n\treturn {\n\t\tversion: typeof obj[\"version\"] === \"string\" ? (obj[\"version\"] as string) : undefined,\n\t\tstreamingFormat:\n\t\t\ttypeof obj[\"streamingFormat\"] === \"string\" ? (obj[\"streamingFormat\"] as string) : undefined,\n\t\ttracks: filtered,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Hang renditions merge (moq-lib / hang-mmt-fec)\n// ---------------------------------------------------------------------------\n\n/**\n * Merge override tracks into a `@moq/hang` Catalog.Root-like object. The\n * caller passes the already-parsed Catalog.Root (mutates in place and also\n * returns it for convenience). No-op when `override` is null.\n *\n * Dedupe rule: override wins for `fec` config and `framerate`. Everything\n * else (codec, container kind) is preserved from the MoQ-delivered rendition\n * when it exists, or synthesised from the override when it does not.\n *\n * Typed `any` here rather than narrow-matching `Catalog.Root` because the\n * upstream `@moq/hang` schema is branded (u53) and the container `kind` union\n * varies by version (`loc` kind appears in hang-mmt-fec's fork). Matching\n * that surface exactly would over-couple this module to a single upstream\n * revision; the runtime shape we rely on (`.video.renditions` dict mutation)\n * is stable.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function mergeOverrideIntoHangRenditions<T extends Record<string, any>>(\n\tcatalog: T,\n\toverride: Phase14CatalogOverride | null,\n): T {\n\tif (!override) return catalog;\n\n\tfor (const track of override.tracks) {\n\t\t// Default role inference: names without an explicit role field are\n\t\t// treated as video unless the name suffix says audio.\n\t\tconst role: \"video\" | \"audio\" =\n\t\t\ttrack.role === \"audio\" || track.name.startsWith(\"audio\") ? \"audio\" : \"video\";\n\n\t\tconst bagKey = role === \"audio\" ? \"audio\" : \"video\";\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tconst bag: { renditions: Record<string, any>; priority?: number } =\n\t\t\tcatalog[bagKey] ?? { renditions: {}, priority: 1 };\n\t\tconst existing = bag.renditions[track.name];\n\n\t\t// Merge: override fills gaps, does NOT overwrite existing fec/framerate.\n\t\t// The publisher's real catalog is ground truth for wire parameters:\n\t\t// if the existing rendition already has a matching fec config, that's\n\t\t// what the publisher's packets actually carry. Overwriting it with a\n\t\t// fixture value (e.g. Phase 14 target K=768 when publisher emits K=4)\n\t\t// causes the FEC manager to wait for symbols that never arrive.\n\t\t// Only when the rendition is brand-new (no existing fec) do we seed\n\t\t// from the fixture.\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tconst merged: Record<string, any> = {\n\t\t\t...(existing ?? {}),\n\t\t\tcontainer: existing?.container ?? { kind: \"mmtp-fec\" },\n\t\t\tcodec: existing?.codec ?? \"\",\n\t\t};\n\t\tif (existing?.framerate === undefined && track.framerate !== undefined) {\n\t\t\tmerged[\"framerate\"] = track.framerate;\n\t\t}\n\t\tif (existing?.fec === undefined && track.fec !== undefined) {\n\t\t\tmerged[\"fec\"] = track.fec;\n\t\t}\n\n\t\tbag.renditions[track.name] = merged;\n\t\t// Reassign so a freshly-created bag is actually reachable on the\n\t\t// catalog when the MoQ side was missing video/audio entirely.\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t(catalog as any)[bagKey] = bag;\n\t}\n\treturn catalog;\n}\n\n// ---------------------------------------------------------------------------\n// CMSF tracks merge (moqtail-private)\n// ---------------------------------------------------------------------------\n\n/**\n * Shape-minimal description of a CMSF track input (pre-validation JSON, not\n * the parsed `CMSFTrack`). Keeps this module free of a hard dependency on\n * moqtail-ts.\n */\ntype CmsfTrackJson = {\n\tname: string;\n\tpackaging?: string;\n\tmmtpMode?: string;\n\ttimescale?: number;\n\tgroupDurationMs?: number;\n\trole?: string;\n\tcodec?: string;\n\tframerate?: number;\n\tfec?: unknown;\n\t[k: string]: unknown;\n};\n\nfunction isPositiveInteger(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value > 0;\n}\n\n/**\n * Merge override tracks into a raw CMSF `tracks[]` JSON array (as produced\n * by `JSON.parse(catalog.json)` inside `CMSFCatalog.from`).\n *\n * Dedupe by `name`. For name collisions, publisher-emitted `fec` + `framerate`\n * are preserved (the publisher is ground truth for wire parameters). For new\n * track names, missing `packaging` is derived from the override's top-level\n * `streamingFormat`, and missing `codec` is inherited from any existing video\n * track in the catalog. Throws on bad init when neither source supplies them.\n */\nexport function mergeOverrideIntoCmsfTracks(\n\ttracks: CmsfTrackJson[],\n\toverride: Phase14CatalogOverride | null,\n): CmsfTrackJson[] {\n\tif (!override) return tracks;\n\n\tconst byName = new Map<string, CmsfTrackJson>();\n\tfor (const t of tracks) {\n\t\tif (typeof t?.name === \"string\") byName.set(t.name, t);\n\t}\n\n\t// Catalog-derived fallbacks (NOT magic numbers) \u2014 inherited from existing\n\t// publisher tracks. Used only when the override track doesn't carry them.\n\tconst derivedPackaging = override.streamingFormat;\n\tconst existingVideoTrack = tracks.find(\n\t\t(t) => t.role === \"video\" && typeof t.codec === \"string\" && (t.codec as string).length > 0,\n\t);\n\tconst existingAudioTrack = tracks.find(\n\t\t(t) => t.role === \"audio\" && typeof t.codec === \"string\" && (t.codec as string).length > 0,\n\t);\n\n\tfor (const ot of override.tracks) {\n\t\tconst existing = byName.get(ot.name);\n\t\tif (existing !== undefined) {\n\t\t\t// Preserve publisher-emitted fec + framerate \u2014 those describe what\n\t\t\t// is actually on the wire. Overwriting with fixture values causes\n\t\t\t// the player's FEC manager to wait for symbols that never arrive\n\t\t\t// when the fixture's K/P don't match the publisher's.\n\t\t\tif (existing.fec === undefined && ot.fec !== undefined) existing.fec = ot.fec;\n\t\t\tif (existing.framerate === undefined && ot.framerate !== undefined) {\n\t\t\t\texisting.framerate = ot.framerate;\n\t\t\t}\n\t\t\tif (ot.role !== undefined && existing.role === undefined) existing.role = ot.role;\n\t\t\tif (existing.packaging === \"mmtp\") {\n\t\t\t\tconst mode = existing.mmtpMode ?? ot.mmtpMode;\n\t\t\t\tif (mode !== \"mpu\" && mode !== \"mfu\") {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid mmtpMode`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\texisting.mmtpMode = mode;\n\t\t\t\tif (existing.timescale === undefined && ot.timescale !== undefined) existing.timescale = ot.timescale;\n\t\t\t\tif (existing.groupDurationMs === undefined && ot.groupDurationMs !== undefined) {\n\t\t\t\t\texisting.groupDurationMs = ot.groupDurationMs;\n\t\t\t\t}\n\t\t\t\tif (!isPositiveInteger(existing.timescale)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid timescale`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (!isPositiveInteger(existing.groupDurationMs)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid groupDurationMs`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconst packaging = ot.packaging ?? derivedPackaging;\n\t\t\tif (typeof packaging !== \"string\" || packaging.length === 0) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has no packaging \u2014 supply per-track or set top-level streamingFormat`,\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Role inference: repair tracks (ending in /repair) stay role-less\n\t\t\t// per CMSF convention; others default to video.\n\t\t\tconst role = ot.role ?? (ot.name.endsWith(\"/repair\") ? undefined : \"video\");\n\t\t\tconst inheritedCodec =\n\t\t\t\trole === \"audio\" ? existingAudioTrack?.codec : existingVideoTrack?.codec;\n\t\t\tconst codec = ot.codec ?? inheritedCodec;\n\t\t\tif (packaging !== \"timeline\" && (typeof codec !== \"string\" || codec.length === 0)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has no codec (packaging='${packaging}') \u2014 supply per-track or ensure the publisher catalog has a ${role ?? \"video\"} track to inherit from`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst mmtpMode = ot.mmtpMode;\n\t\t\tif (packaging === \"mmtp\" && mmtpMode !== \"mpu\" && mmtpMode !== \"mfu\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid mmtpMode`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (packaging === \"mmtp\" && !isPositiveInteger(ot.timescale)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid timescale`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (packaging === \"mmtp\" && !isPositiveInteger(ot.groupDurationMs)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid groupDurationMs`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst entry: CmsfTrackJson = {\n\t\t\t\tname: ot.name,\n\t\t\t\tpackaging,\n\t\t\t\tcodec: codec as string,\n\t\t\t};\n\t\t\tif (mmtpMode !== undefined) entry.mmtpMode = mmtpMode;\n\t\t\tif (ot.timescale !== undefined) entry.timescale = ot.timescale;\n\t\t\tif (ot.groupDurationMs !== undefined) entry.groupDurationMs = ot.groupDurationMs;\n\t\t\tif (role !== undefined) entry.role = role;\n\t\t\tif (ot.framerate !== undefined) entry.framerate = ot.framerate;\n\t\t\tif (ot.fec !== undefined) entry.fec = ot.fec;\n\t\t\ttracks.push(entry);\n\t\t\tbyName.set(ot.name, entry);\n\t\t}\n\t}\n\treturn tracks;\n}\n"],
5
- "mappings": ";AAwFO,SAAS,4BAA2D;AAG1E,QAAM,IAAI;AACV,QAAM,MAAM,EAAE,4BAA4B;AAC1C,MAAI,QAAQ,UAAa,QAAQ,KAAM,QAAO;AAC9C,MAAI,OAAO,QAAQ,UAAU;AAC5B,YAAQ,KAAK,4DAA4D;AACzE,WAAO;AAAA,EACR;AACA,QAAM,MAAM;AACZ,QAAM,SAAS,IAAI,QAAQ;AAC3B,MAAI,CAAC,MAAM,QAAQ,MAAM,GAAG;AAC3B,YAAQ,KAAK,kEAAkE;AAC/E,WAAO;AAAA,EACR;AAGA,QAAM,WAAmC,CAAC;AAC1C,aAAW,KAAK,QAAQ;AACvB,QAAI,OAAO,MAAM,YAAY,MAAM,MAAM;AACxC,YAAM,QAAQ;AACd,UAAI,OAAO,MAAM,MAAM,MAAM,YAAa,MAAM,MAAM,EAAa,SAAS,GAAG;AAC9E,iBAAS,KAAK,KAAwC;AAAA,MACvD;AAAA,IACD;AAAA,EACD;AACA,MAAI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KAAK,KAAK;AACjB,aAAO,IAAI,GAAG,MAAM,KAAK;AAAA,IAC1B;AAAA,EACD;AACA,SAAO;AACR;",
4
+ "sourcesContent": ["/**\n * Phase 14 catalog-override hook (test harness only).\n *\n * When `globalThis.__PHASE14_CATALOG_OVERRIDE` is set (injected by the\n * 7point test via `page.addInitScript` \u2014 see\n * packages/moq-server/tests/7point-validation.test.mjs `applyPhase14CatalogOverride`)\n * the override's `tracks[]` are merged into whatever catalog the MoQ-delivered\n * JSON produced:\n *\n * - Dedupe by `track.name`.\n * - When both sides carry a track with the same name, the override's\n * `fec` config wins \u2014 this is how the 7point harness steers multi-track\n * tests onto the Phase 14 `video/base` + `video/delta` + `video/repair`\n * switching set without asking the publisher to change its catalog.\n * - Tracks present only in the override are appended as-is.\n * - Tracks present only in the MoQ catalog are preserved unchanged.\n *\n * This module is deliberately player-agnostic. It exposes:\n *\n * getPhase14CatalogOverride() \u2014 read + shape-check the global.\n * mergeOverrideIntoHangRenditions() \u2014 merge into a `@moq/hang`\n * Catalog.Root `video.renditions` /\n * `audio.renditions` dict. Used by\n * hang-mmt-fec/js/watch/src/broadcast.ts.\n * mergeOverrideIntoCmsfTracks() \u2014 merge into moqtail's CMSF-flat\n * `tracks[]` array. Used by\n * moqtail-private CMSFCatalog.from().\n *\n * Production builds never set the global, so all three helpers are no-ops at\n * runtime unless the test harness opts in.\n */\n\nimport type { FecAlgorithm, FecCatalogConfig } from \"./carp-catalog.js\";\n\n// ---------------------------------------------------------------------------\n// Override fixture shape (IETF draft-ietf-moq-catalogformat-01)\n// ---------------------------------------------------------------------------\n\n/**\n * A single override track entry \u2014 mirrors the fixture at\n * `packages/moq-server/tests/fixtures/multi-track-catalog.json`.\n *\n * Kept intentionally permissive: the canonical fixture carries `name`,\n * `altGroup`, `framerate`, and `fec`, but future 7point scenarios may extend\n * with additional hints without wanting this module to gate-keep them.\n */\nexport interface Phase14OverrideTrack {\n\tname: string;\n\t/** CMSF packaging kind. Optional per track \u2014 when absent, the merge\n\t * derives it from the override's top-level `streamingFormat`. */\n\tpackaging?: \"mmtp\" | \"cmaf\" | \"loc\" | \"timeline\";\n\t/** Required when packaging is `mmtp`; the current publisher emits MFU mode. */\n\tmmtpMode?: \"mfu\";\n\t/** Required when packaging is `mmtp`; copied into synthesized CMSF tracks. */\n\ttimescale?: number;\n\t/** Required when packaging is `mmtp`; copied into synthesized CMSF tracks. */\n\tgroupDurationMs?: number;\n\t/** Codec string. Optional per track \u2014 when absent, the merge inherits\n\t * from the existing video/audio rendition in the MoQ catalog (the\n\t * publisher's declaration). Throws only when neither the override nor\n\t * any existing rendition supplies one. */\n\tcodec?: string;\n\trole?: \"video\" | \"audio\" | \"timeline\";\n\taltGroup?: number;\n\tframerate?: number;\n\tfec?: Partial<FecCatalogConfig> & { algorithm: FecAlgorithm };\n}\n\n/**\n * The shape the 7point harness writes to `globalThis.__PHASE14_CATALOG_OVERRIDE`.\n * Extra top-level fields (`version`, `streamingFormat`, ...) are ignored \u2014\n * the merge only consumes `tracks[]`.\n */\nexport interface Phase14CatalogOverride {\n\tversion?: string;\n\tstreamingFormat?: string;\n\ttracks: Phase14OverrideTrack[];\n}\n\n// ---------------------------------------------------------------------------\n// Global reader\n// ---------------------------------------------------------------------------\n\n/**\n * Read `globalThis.__PHASE14_CATALOG_OVERRIDE` and return it only when it has\n * a well-formed `tracks[]` array. Malformed values log + return `null` rather\n * than throw so a broken fixture never kills the MoQ path for a real stream.\n */\nexport function getPhase14CatalogOverride(): Phase14CatalogOverride | null {\n\t// `globalThis` is defined in workers, service workers, and the main window;\n\t// it's the portable way to reach the test-injected hook from any context.\n\tconst g = globalThis as Record<string, unknown>;\n\tconst raw = g[\"__PHASE14_CATALOG_OVERRIDE\"];\n\tif (raw === undefined || raw === null) return null;\n\tif (typeof raw !== \"object\") {\n\t\tconsole.warn(\"[phase14-catalog-override] hook is not an object; ignoring\");\n\t\treturn null;\n\t}\n\tconst obj = raw as Record<string, unknown>;\n\tconst tracks = obj[\"tracks\"];\n\tif (!Array.isArray(tracks)) {\n\t\tconsole.warn(\"[phase14-catalog-override] hook.tracks is not an array; ignoring\");\n\t\treturn null;\n\t}\n\t// Shallow filter: keep only entries that at least have a string name.\n\t// Each consumer (hang or CMSF merge) validates shape further.\n\tconst filtered: Phase14OverrideTrack[] = [];\n\tfor (const t of tracks) {\n\t\tif (typeof t === \"object\" && t !== null) {\n\t\t\tconst entry = t as Record<string, unknown>;\n\t\t\tif (typeof entry[\"name\"] === \"string\" && (entry[\"name\"] as string).length > 0) {\n\t\t\t\tfiltered.push(entry as unknown as Phase14OverrideTrack);\n\t\t\t}\n\t\t}\n\t}\n\tif (filtered.length === 0) return null;\n\treturn {\n\t\tversion: typeof obj[\"version\"] === \"string\" ? (obj[\"version\"] as string) : undefined,\n\t\tstreamingFormat:\n\t\t\ttypeof obj[\"streamingFormat\"] === \"string\" ? (obj[\"streamingFormat\"] as string) : undefined,\n\t\ttracks: filtered,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Hang renditions merge (moq-lib / hang-mmt-fec)\n// ---------------------------------------------------------------------------\n\n/**\n * Merge override tracks into a `@moq/hang` Catalog.Root-like object. The\n * caller passes the already-parsed Catalog.Root (mutates in place and also\n * returns it for convenience). No-op when `override` is null.\n *\n * Dedupe rule: override wins for `fec` config and `framerate`. Everything\n * else (codec, container kind) is preserved from the MoQ-delivered rendition\n * when it exists, or synthesised from the override when it does not.\n *\n * Typed `any` here rather than narrow-matching `Catalog.Root` because the\n * upstream `@moq/hang` schema is branded (u53) and the container `kind` union\n * varies by version (`loc` kind appears in hang-mmt-fec's fork). Matching\n * that surface exactly would over-couple this module to a single upstream\n * revision; the runtime shape we rely on (`.video.renditions` dict mutation)\n * is stable.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function mergeOverrideIntoHangRenditions<T extends Record<string, any>>(\n\tcatalog: T,\n\toverride: Phase14CatalogOverride | null,\n): T {\n\tif (!override) return catalog;\n\n\tfor (const track of override.tracks) {\n\t\t// Default role inference: names without an explicit role field are\n\t\t// treated as video unless the name suffix says audio.\n\t\tconst role: \"video\" | \"audio\" =\n\t\t\ttrack.role === \"audio\" || track.name.startsWith(\"audio\") ? \"audio\" : \"video\";\n\n\t\tconst bagKey = role === \"audio\" ? \"audio\" : \"video\";\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tconst bag: { renditions: Record<string, any>; priority?: number } =\n\t\t\tcatalog[bagKey] ?? { renditions: {}, priority: 1 };\n\t\tconst existing = bag.renditions[track.name];\n\n\t\t// Merge: override fills gaps, does NOT overwrite existing fec/framerate.\n\t\t// The publisher's real catalog is ground truth for wire parameters:\n\t\t// if the existing rendition already has a matching fec config, that's\n\t\t// what the publisher's packets actually carry. Overwriting it with a\n\t\t// fixture value (e.g. Phase 14 target K=768 when publisher emits K=4)\n\t\t// causes the FEC manager to wait for symbols that never arrive.\n\t\t// Only when the rendition is brand-new (no existing fec) do we seed\n\t\t// from the fixture.\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tconst merged: Record<string, any> = {\n\t\t\t...(existing ?? {}),\n\t\t\tcontainer: existing?.container ?? { kind: \"mmtp-fec\" },\n\t\t\tcodec: existing?.codec ?? \"\",\n\t\t};\n\t\tif (existing?.framerate === undefined && track.framerate !== undefined) {\n\t\t\tmerged[\"framerate\"] = track.framerate;\n\t\t}\n\t\tif (existing?.fec === undefined && track.fec !== undefined) {\n\t\t\tmerged[\"fec\"] = track.fec;\n\t\t}\n\n\t\tbag.renditions[track.name] = merged;\n\t\t// Reassign so a freshly-created bag is actually reachable on the\n\t\t// catalog when the MoQ side was missing video/audio entirely.\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t(catalog as any)[bagKey] = bag;\n\t}\n\treturn catalog;\n}\n\n// ---------------------------------------------------------------------------\n// CMSF tracks merge (moqtail-private)\n// ---------------------------------------------------------------------------\n\n/**\n * Shape-minimal description of a CMSF track input (pre-validation JSON, not\n * the parsed `CMSFTrack`). Keeps this module free of a hard dependency on\n * moqtail-ts.\n */\ntype CmsfTrackJson = {\n\tname: string;\n\tpackaging?: string;\n\tmmtpMode?: string;\n\ttimescale?: number;\n\tgroupDurationMs?: number;\n\trole?: string;\n\tcodec?: string;\n\tframerate?: number;\n\tfec?: unknown;\n\t[k: string]: unknown;\n};\n\nfunction isPositiveInteger(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value > 0;\n}\n\n/**\n * Merge override tracks into a raw CMSF `tracks[]` JSON array (as produced\n * by `JSON.parse(catalog.json)` inside `CMSFCatalog.from`).\n *\n * Dedupe by `name`. For name collisions, publisher-emitted `fec` + `framerate`\n * are preserved (the publisher is ground truth for wire parameters). For new\n * track names, missing `packaging` is derived from the override's top-level\n * `streamingFormat`, and missing `codec` is inherited from any existing video\n * track in the catalog. Throws on bad init when neither source supplies them.\n */\nexport function mergeOverrideIntoCmsfTracks(\n\ttracks: CmsfTrackJson[],\n\toverride: Phase14CatalogOverride | null,\n): CmsfTrackJson[] {\n\tif (!override) return tracks;\n\n\tconst byName = new Map<string, CmsfTrackJson>();\n\tfor (const t of tracks) {\n\t\tif (typeof t?.name === \"string\") byName.set(t.name, t);\n\t}\n\n\t// Catalog-derived fallbacks (NOT magic numbers) \u2014 inherited from existing\n\t// publisher tracks. Used only when the override track doesn't carry them.\n\tconst derivedPackaging = override.streamingFormat;\n\tconst existingVideoTrack = tracks.find(\n\t\t(t) => t.role === \"video\" && typeof t.codec === \"string\" && (t.codec as string).length > 0,\n\t);\n\tconst existingAudioTrack = tracks.find(\n\t\t(t) => t.role === \"audio\" && typeof t.codec === \"string\" && (t.codec as string).length > 0,\n\t);\n\n\tfor (const ot of override.tracks) {\n\t\tconst existing = byName.get(ot.name);\n\t\tif (existing !== undefined) {\n\t\t\t// Preserve publisher-emitted fec + framerate \u2014 those describe what\n\t\t\t// is actually on the wire. Overwriting with fixture values causes\n\t\t\t// the player's FEC manager to wait for symbols that never arrive\n\t\t\t// when the fixture's K/P don't match the publisher's.\n\t\t\tif (existing.fec === undefined && ot.fec !== undefined) existing.fec = ot.fec;\n\t\t\tif (existing.framerate === undefined && ot.framerate !== undefined) {\n\t\t\t\texisting.framerate = ot.framerate;\n\t\t\t}\n\t\t\tif (ot.role !== undefined && existing.role === undefined) existing.role = ot.role;\n\t\t\tif (existing.packaging === \"mmtp\") {\n\t\t\t\tconst mode = existing.mmtpMode ?? ot.mmtpMode;\n\t\t\t\tif (mode !== \"mfu\") {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid mmtpMode`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\texisting.mmtpMode = mode;\n\t\t\t\tif (existing.timescale === undefined && ot.timescale !== undefined) existing.timescale = ot.timescale;\n\t\t\t\tif (existing.groupDurationMs === undefined && ot.groupDurationMs !== undefined) {\n\t\t\t\t\texisting.groupDurationMs = ot.groupDurationMs;\n\t\t\t\t}\n\t\t\t\tif (!isPositiveInteger(existing.timescale)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid timescale`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (!isPositiveInteger(existing.groupDurationMs)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid groupDurationMs`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tconst packaging = ot.packaging ?? derivedPackaging;\n\t\t\tif (typeof packaging !== \"string\" || packaging.length === 0) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has no packaging \u2014 supply per-track or set top-level streamingFormat`,\n\t\t\t\t);\n\t\t\t}\n\t\t\t// Role inference: repair tracks (ending in /repair) stay role-less\n\t\t\t// per CMSF convention; others default to video.\n\t\t\tconst role = ot.role ?? (ot.name.endsWith(\"/repair\") ? undefined : \"video\");\n\t\t\tconst inheritedCodec =\n\t\t\t\trole === \"audio\" ? existingAudioTrack?.codec : existingVideoTrack?.codec;\n\t\t\tconst codec = ot.codec ?? inheritedCodec;\n\t\t\tif (packaging !== \"timeline\" && (typeof codec !== \"string\" || codec.length === 0)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has no codec (packaging='${packaging}') \u2014 supply per-track or ensure the publisher catalog has a ${role ?? \"video\"} track to inherit from`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst mmtpMode = ot.mmtpMode;\n\t\t\tif (packaging === \"mmtp\" && mmtpMode !== \"mfu\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid mmtpMode`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (packaging === \"mmtp\" && !isPositiveInteger(ot.timescale)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid timescale`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (packaging === \"mmtp\" && !isPositiveInteger(ot.groupDurationMs)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[phase14-catalog-override] track \"${ot.name}\" has packaging='mmtp' but no valid groupDurationMs`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst entry: CmsfTrackJson = {\n\t\t\t\tname: ot.name,\n\t\t\t\tpackaging,\n\t\t\t\tcodec: codec as string,\n\t\t\t};\n\t\t\tif (mmtpMode !== undefined) entry.mmtpMode = mmtpMode;\n\t\t\tif (ot.timescale !== undefined) entry.timescale = ot.timescale;\n\t\t\tif (ot.groupDurationMs !== undefined) entry.groupDurationMs = ot.groupDurationMs;\n\t\t\tif (role !== undefined) entry.role = role;\n\t\t\tif (ot.framerate !== undefined) entry.framerate = ot.framerate;\n\t\t\tif (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AAa,OAAO;AAC/C,cAAM,IAAI;AAAA,UACT,qCAAqC,GAAG,IAAI;AAAA,QAC7C;AAAA,MACD;AACA,UAAI,cAAc,UAAU,CAAC,kBAAkB,GAAG,SAAS,GAAG;AAC7D,cAAM,IAAI;AAAA,UACT,qCAAqC,GAAG,IAAI;AAAA,QAC7C;AAAA,MACD;AACA,UAAI,cAAc,UAAU,CAAC,kBAAkB,GAAG,eAAe,GAAG;AACnE,cAAM,IAAI;AAAA,UACT,qCAAqC,GAAG,IAAI;AAAA,QAC7C;AAAA,MACD;AACA,YAAM,QAAuB;AAAA,QAC5B,MAAM,GAAG;AAAA,QACT;AAAA,QACA;AAAA,MACD;AACA,UAAI,aAAa,OAAW,OAAM,WAAW;AAC7C,UAAI,GAAG,cAAc,OAAW,OAAM,YAAY,GAAG;AACrD,UAAI,GAAG,oBAAoB,OAAW,OAAM,kBAAkB,GAAG;AACjE,UAAI,SAAS,OAAW,OAAM,OAAO;AACrC,UAAI,GAAG,cAAc,OAAW,OAAM,YAAY,GAAG;AACrD,UAAI,GAAG,QAAQ,OAAW,OAAM,MAAM,GAAG;AACzC,aAAO,KAAK,KAAK;AACjB,aAAO,IAAI,GAAG,MAAM,KAAK;AAAA,IAC1B;AAAA,EACD;AACA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -80,13 +80,19 @@
80
80
  * A FETCH landing after the gate forced that frame out would recover media
81
81
  * the gate then drops as stale.
82
82
  *
83
- * The scheduler arms no timers. A fetch ends when its transport completes or
84
- * throws, when it is preempted, when any later scheduling event finds it past
85
- * its presentation deadline, when its block resolves (recovered, or failed at
86
- * that deadline), on track reset, or on dispose.
83
+ * The scheduler arms no timers for block requests. A fetch ends when its
84
+ * transport completes or throws, when it is preempted, when any later
85
+ * scheduling event finds it past its presentation deadline, when its block
86
+ * resolves (recovered, or failed at that deadline), on track reset, or on
87
+ * dispose. A range request (§7.5) is for a hole, not a tracked block, so no
88
+ * FEC deadline resolves it: it arms one timer at its deadline, cleared when
89
+ * it retires, so a hung range FETCH cannot hold the hole (and the release
90
+ * gate behind it) past that deadline.
87
91
  */
88
92
  import { type FecBlockProfile } from '@blockcast/mmt-base';
93
+ import { type RepairFetchRange } from '@blockcast/mmt-fec';
89
94
  import { type BlockClass, type ClassifierMode, type RepairPriority } from './block-policy.js';
95
+ import type { UndelimitedIsoLoss } from './fec-manager.js';
90
96
  import type { RepairLifecycleObserver } from './multicast-manager.js';
91
97
  /**
92
98
  * The highest value in the Source Media priority range of
@@ -186,6 +192,29 @@ export interface RepairFetchRequest {
186
192
  * must already be queued ahead of that request. A FETCH whose Request ID
187
193
  * is not known yet is cancelled as soon as FETCH_OK assigns it. */
188
194
  export type RepairFetchTransport = (request: RepairFetchRequest) => AsyncIterable<Uint8Array>;
195
+ /**
196
+ * One range repair FETCH for a lost SS_ID in an undelimited span
197
+ * (draft-ramadan-moq-fec §7.5): the absolute, inclusive repair-track Group
198
+ * range `repairFetchRange` gives. The last Group returned is the block holding
199
+ * `lostSsId`; earlier ones are other blocks, admitted like any repair object.
200
+ */
201
+ export interface RepairRangeFetchRequest extends RepairFetchRange {
202
+ readonly repairTrack: string;
203
+ /** The lost SS_ID x the range was computed for. */
204
+ readonly lostSsId: number;
205
+ readonly blockProfile: FecBlockProfile;
206
+ readonly packetId: number;
207
+ /** Same contract as `RepairFetchRequest.signal`: cancel on the wire. */
208
+ readonly signal: AbortSignal;
209
+ /** Same contract as `RepairFetchRequest.subscriberPriority`. */
210
+ readonly subscriberPriority: number | undefined;
211
+ }
212
+ /**
213
+ * Protocol-specific range FETCH (e.g. MoQT LOCATION_FILTER 0x03 Group range).
214
+ * Yield each repair object payload; return when the range ends. The abort
215
+ * rules of {@link RepairFetchTransport} apply unchanged.
216
+ */
217
+ export type RepairRangeFetchTransport = (request: RepairRangeFetchRequest) => AsyncIterable<Uint8Array>;
189
218
  /** Why a request could not carry a catalog-derived priority. */
190
219
  export type RepairPriorityReason = 'source-priority-absent' | 'source-priority-invalid' | 'repair-priority-absent' | 'repair-priority-invalid';
191
220
  /**
@@ -281,6 +310,22 @@ export interface WireRepairFetchOptions {
281
310
  * `all-protected` stream.
282
311
  */
283
312
  keyframeRepairBudgetMs?: (packetId: number, catalogTrackName?: string) => number;
313
+ /**
314
+ * Range repair for a lost SS_ID whose block no repair delimited
315
+ * (draft-ramadan-moq-fec §7.5), optional. Given, the host keeps such a gap
316
+ * as a pending hole and the scheduler FETCHes `repairFetchRange(x, K,
317
+ * anchor)` for it under the same admission, priority and abort rules as a
318
+ * block request (class `unknown`, P0). Requires `repairEpochReference`.
319
+ */
320
+ rangeTransport?: RepairRangeFetchTransport;
321
+ /**
322
+ * The epoch reference r of `repairTrack` on the live session
323
+ * (`RepairEpochReferences.reference`), or undefined while none is held.
324
+ * The §7.5 anchor is ext(S_prev) extended from it when a stated block ends
325
+ * where the hole starts, else r itself; without r no range request is sent
326
+ * (`range-no-anchor`).
327
+ */
328
+ repairEpochReference?: (repairTrack: string) => bigint | undefined;
284
329
  }
285
330
  /** Why the D-28 layer asked for a repair: the block's class at its deadline. */
286
331
  export type RepairSubscribeCallback = (sbn: number, packetId: number, catalogTrackName: string | undefined, blockClass: BlockClass) => void;
@@ -291,7 +336,33 @@ export type RepairSkipReason =
291
336
  /** The measured RTT is not less than the time left to the deadline. */
292
337
  | 'rtt-exceeds-budget'
293
338
  /** The player gave no usable presentation delay for the block's stream. */
294
- | 'presentation-delay-unavailable';
339
+ | 'presentation-delay-unavailable'
340
+ /** A lost SS_ID in an undelimited span had no §7.5 anchor to extend it from. */
341
+ | 'range-no-anchor';
342
+ /**
343
+ * Which term set a FETCH's deadline (BLO-33597): the multicast wait, the
344
+ * player's presentation delay past the block anchor, the keyframe budget past
345
+ * the anchor (when it granted more than the presentation delay), or the
346
+ * release gate's retention ceiling.
347
+ */
348
+ export type RepairDeadlineBound = 'wait' | 'presentation' | 'keyframe' | 'retention';
349
+ /** The admission inputs of a FETCH the scheduler sent (BLO-33597). */
350
+ export interface RepairSendMeasurement {
351
+ /** The reliable-path RTT admission compared against `budgetMs`. */
352
+ readonly rttMs: number;
353
+ /** Time left to the entry's deadline when the FETCH was sent. */
354
+ readonly budgetMs: number;
355
+ /**
356
+ * Delay past the block anchor the deadline was computed from; null when
357
+ * the block had no anchor (its deadline is then the multicast wait).
358
+ */
359
+ readonly delayMs: number | null;
360
+ /** Time since the block anchor; null when the block had no anchor. */
361
+ readonly blockAgeMs: number | null;
362
+ readonly bound: RepairDeadlineBound;
363
+ /** True for a range repair FETCH (§7.5 lost SS_ID); absent for a block FETCH. */
364
+ readonly range?: true;
365
+ }
295
366
  /** The subset of MulticastManager the scheduler drives. */
296
367
  export interface RepairFetchHost {
297
368
  readonly fecManager: {
@@ -330,6 +401,10 @@ export interface RepairFetchHost {
330
401
  noteKeyframeBudgetGranted?(extensionMs: number, sbn: number, packetId: number, catalogTrackName?: string): void;
331
402
  addRepairLifecycleObserver(observer: RepairLifecycleObserver): () => void;
332
403
  addTrackResetObserver(observer: (packetId: number, catalogTrackName: string) => void): () => void;
404
+ /** Register for lost SS_IDs in undelimited spans (required with `rangeTransport`). */
405
+ onUndelimitedLoss?(cb: (loss: UndelimitedIsoLoss) => void): void;
406
+ /** A hole's range repair ended, or none is sent: feed what was not stated. */
407
+ closeIsoHoles?(packetId: number, catalogTrackName: string | undefined, start: number, length: number): void;
333
408
  clearRepairForBlock(sbn: number, packetId: number, catalogTrackName?: string): void;
334
409
  processRepairFromMoQ(packet: Uint8Array, ownerPacketId?: number, catalogTrackName?: string): void;
335
410
  noteRepairScheduling(type: 'repair-preempted' | 'repair-deferred', sbn: number, packetId: number, catalogTrackName?: string): void;
@@ -349,7 +424,7 @@ export interface RepairFetchHost {
349
424
  * A FETCH the scheduler admitted and handed to the transport (optional):
350
425
  * every attempt, a retry or a reprioritised restart included.
351
426
  */
352
- noteRepairFetchSent?(priority: RepairPriority, sbn: number, packetId: number, catalogTrackName?: string): void;
427
+ noteRepairFetchSent?(priority: RepairPriority, sbn: number, packetId: number, catalogTrackName: string | undefined, measurement: RepairSendMeasurement): void;
353
428
  }
354
429
  /**
355
430
  * Wire the D-28 repair-fetch scheduler onto a MulticastManager.
@@ -1 +1 @@
1
- {"version":3,"file":"repair-fetch.d.ts","sourceRoot":"","sources":["../src/repair-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsFG;AAEH,OAAO,EAAwB,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAMrE;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,QAA0B,CAAA;AAEhE,wEAAwE;AACxE,MAAM,WAAW,YAAY;IAC3B,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B;;;;;;OAMG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IACtC;;;;;OAKG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CACvC;AAED;;;;;;;8DAO8D;AAC9D,MAAM,MAAM,mBAAmB,GAAG,CAChC,QAAQ,EAAE,MAAM,EAChB,gBAAgB,CAAC,EAAE,MAAM,KACtB,YAAY,GAAG,IAAI,CAAA;AAExB,8EAA8E;AAC9E,MAAM,WAAW,kBAAkB;IACjC,iDAAiD;IACjD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB;;;;;;OAMG;IACH,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAA;IACtC,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,MAA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AA;IACP;;;OAGG;IACH,mBAAmB,CAAC,CAClB,QAAQ,EAAE,cAAc,EACxB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,WAAW,EAAE,qBAAqB,GACjC,IAAI,CAAA;CACR;AAiDD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,sBAAsB,GAAG,MAAM,IAAI,CA6pB7F"}
@@ -24,6 +24,12 @@ function parseFecBlockProfile(value, where) {
24
24
  throw new Error(`${where} must be "iso-ssbg1-v1" (got ${JSON.stringify(value)})`);
25
25
  }
26
26
 
27
+ // ../mmt-base/dist/catalog-fec-source.js
28
+ var ALL_ROLES = Object.freeze(["video", "audio"]);
29
+
30
+ // src/repair-fetch.ts
31
+ import { extendSsId, repairFetchRange } from "@blockcast/mmt-fec";
32
+
27
33
  // src/block-policy.ts
28
34
  import { deriveFecInterleaveDepth } from "@blockcast/mmt-fec";
29
35
  function repairPriorityForClass(blockClass) {
@@ -75,6 +81,9 @@ function wireRepairFetch(mc, opts) {
75
81
  if (typeof opts.presentationDelayMs !== "function") {
76
82
  throw new Error("[RepairFetch] presentationDelayMs is required: a repair FETCH is due by the block's presentation deadline");
77
83
  }
84
+ if (opts.rangeTransport !== void 0 && (typeof opts.repairEpochReference !== "function" || !mc.onUndelimitedLoss || !mc.closeIsoHoles)) {
85
+ throw new Error("[RepairFetch] rangeTransport needs repairEpochReference and a host that reports undelimited losses");
86
+ }
78
87
  const entries = /* @__PURE__ */ new Map();
79
88
  const warnedNoTarget = /* @__PURE__ */ new Set();
80
89
  let disposed = false;
@@ -88,7 +97,12 @@ function wireRepairFetch(mc, opts) {
88
97
  const note = (type, entry) => {
89
98
  mc.noteRepairScheduling(type, entry.sbn, entry.packetId, entry.catalogTrackName);
90
99
  };
100
+ const clearEntry = (entry) => {
101
+ if (entry.range) mc.closeIsoHoles(entry.packetId, entry.catalogTrackName, entry.sbn, entry.range.holeLength);
102
+ else clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
103
+ };
91
104
  const releaseHold = (entry) => {
105
+ if (entry.range) return;
92
106
  if (entry.catalogTrackName === void 0) mc.fecManager.releaseRepairHold(entry.sbn, entry.packetId);
93
107
  else mc.fecManager.releaseRepairHold(entry.sbn, entry.packetId, entry.catalogTrackName);
94
108
  };
@@ -121,10 +135,10 @@ function wireRepairFetch(mc, opts) {
121
135
  const admit = (entry, now) => {
122
136
  const budgetMs = entry.deadlineAt - now;
123
137
  const rttMs = readRtt();
124
- if (rttMs !== null && rttMs < budgetMs) return true;
138
+ if (rttMs !== null && rttMs < budgetMs) return rttMs;
125
139
  retire(entry);
126
140
  releaseHold(entry);
127
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
141
+ clearEntry(entry);
128
142
  mc.noteRepairSkipped(
129
143
  rttMs === null ? "rtt-unmeasured" : "rtt-exceeds-budget",
130
144
  { rttMs, budgetMs, priority: entry.priority },
@@ -132,10 +146,11 @@ function wireRepairFetch(mc, opts) {
132
146
  entry.packetId,
133
147
  entry.catalogTrackName
134
148
  );
135
- return false;
149
+ return null;
136
150
  };
137
151
  const retire = (entry) => {
138
152
  if (entries.get(entry.key) === entry) entries.delete(entry.key);
153
+ if (entry.expiry !== void 0) clearTimeout(entry.expiry);
139
154
  };
140
155
  const urgentOutstanding = () => {
141
156
  for (const entry of entries.values()) {
@@ -164,17 +179,28 @@ function wireRepairFetch(mc, opts) {
164
179
  return derived.kind === "omit" ? { subscriberPriority: void 0 } : null;
165
180
  };
166
181
  const start = (entry, counted = true) => {
167
- if (!admit(entry, performance.now())) return;
182
+ const now = performance.now();
183
+ const rttMs = admit(entry, now);
184
+ if (rttMs === null) return;
168
185
  if (counted) entry.attempts++;
169
- mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName);
186
+ mc.noteRepairFetchSent?.(entry.priority, entry.sbn, entry.packetId, entry.catalogTrackName, {
187
+ rttMs,
188
+ budgetMs: entry.deadlineAt - now,
189
+ delayMs: entry.delayMs,
190
+ blockAgeMs: entry.anchorAt === null ? null : Math.max(0, now - entry.anchorAt),
191
+ bound: entry.bound,
192
+ ...entry.range ? { range: true } : {}
193
+ });
170
194
  const run = { controller: new AbortController(), stopped: null };
171
195
  entry.running = run;
172
- mc.fecManager.holdBlockForRepair(
173
- entry.sbn,
174
- entry.packetId,
175
- entry.catalogTrackName,
176
- entry.deadlineAt
177
- );
196
+ if (!entry.range) {
197
+ mc.fecManager.holdBlockForRepair(
198
+ entry.sbn,
199
+ entry.packetId,
200
+ entry.catalogTrackName,
201
+ entry.deadlineAt
202
+ );
203
+ }
178
204
  void execute(entry, run);
179
205
  };
180
206
  const dispatch = () => {
@@ -186,14 +212,14 @@ function wireRepairFetch(mc, opts) {
186
212
  if (entry.deadlineAt <= now) {
187
213
  stop(entry, "expired");
188
214
  retire(entry);
189
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
215
+ clearEntry(entry);
190
216
  }
191
217
  continue;
192
218
  }
193
219
  if (entry.deadlineAt <= now) {
194
220
  retire(entry);
195
221
  if (entry.priority === 2 && entry.attempts === 0) note("repair-deferred", entry);
196
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
222
+ clearEntry(entry);
197
223
  continue;
198
224
  }
199
225
  queued.push(entry);
@@ -230,9 +256,9 @@ function wireRepairFetch(mc, opts) {
230
256
  entry.running = null;
231
257
  if (error === void 0) {
232
258
  retire(entry);
233
- if (fed === 0 || !decodable(entry)) {
259
+ if (entry.range || fed === 0 || !decodable(entry)) {
234
260
  releaseHold(entry);
235
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
261
+ clearEntry(entry);
236
262
  }
237
263
  dispatch();
238
264
  return;
@@ -244,7 +270,7 @@ function wireRepairFetch(mc, opts) {
244
270
  }
245
271
  retire(entry);
246
272
  if (fed === 0) releaseHold(entry);
247
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
273
+ clearEntry(entry);
248
274
  console.warn(
249
275
  `[RepairFetch] fetch failed pid=${entry.packetId} sbn=${entry.sbn} track=${entry.repairTrack}:`,
250
276
  error
@@ -260,15 +286,21 @@ function wireRepairFetch(mc, opts) {
260
286
  };
261
287
  const execute = async (entry, run) => {
262
288
  let fed = 0;
289
+ const common = {
290
+ repairTrack: entry.repairTrack,
291
+ blockProfile: entry.blockProfile,
292
+ packetId: entry.packetId,
293
+ signal: run.controller.signal,
294
+ subscriberPriority: entry.subscriberPriority
295
+ };
263
296
  try {
264
- for await (const packet of opts.transport({
265
- repairTrack: entry.repairTrack,
266
- sbn: entry.sbn,
267
- blockProfile: entry.blockProfile,
268
- packetId: entry.packetId,
269
- signal: run.controller.signal,
270
- subscriberPriority: entry.subscriberPriority
271
- })) {
297
+ const packets = entry.range ? opts.rangeTransport({
298
+ ...common,
299
+ startGroup: entry.range.startGroup,
300
+ endGroup: entry.range.endGroup,
301
+ lostSsId: entry.range.lostSsId
302
+ }) : opts.transport({ ...common, sbn: entry.sbn });
303
+ for await (const packet of packets) {
272
304
  if (run.stopped !== null || entry.running !== run) break;
273
305
  fed++;
274
306
  if (entry.catalogTrackName === void 0) {
@@ -287,6 +319,7 @@ function wireRepairFetch(mc, opts) {
287
319
  if (entry.packetId !== packetId || entry.catalogTrackName !== catalogTrackName) continue;
288
320
  retire(entry);
289
321
  stop(entry, "reset");
322
+ if (entry.range) clearEntry(entry);
290
323
  }
291
324
  warnedNoTarget.delete(noTargetKey(packetId, catalogTrackName));
292
325
  dispatch();
@@ -313,6 +346,9 @@ function wireRepairFetch(mc, opts) {
313
346
  );
314
347
  if (promotedDeadline !== null && promotedDeadline.deadlineAt > entry2.deadlineAt) {
315
348
  entry2.deadlineAt = promotedDeadline.deadlineAt;
349
+ entry2.anchorAt = promotedDeadline.anchorAt;
350
+ entry2.delayMs = promotedDeadline.delayMs;
351
+ entry2.bound = promotedDeadline.bound;
316
352
  noteBudget(entry2, promotedDeadline.extensionMs);
317
353
  }
318
354
  if (entry2.running) {
@@ -338,7 +374,9 @@ function wireRepairFetch(mc, opts) {
338
374
  if (waitMs === void 0) return null;
339
375
  const waitDeadlineAt = now + waitMs;
340
376
  const anchor = mc.fecManager.blockAnchorAtMs(sbn, packetId, catalogTrackName);
341
- if (anchor === void 0) return { deadlineAt: waitDeadlineAt, extensionMs: 0 };
377
+ if (anchor === void 0) {
378
+ return { deadlineAt: waitDeadlineAt, extensionMs: 0, anchorAt: null, delayMs: null, bound: "wait" };
379
+ }
342
380
  let delayMs;
343
381
  try {
344
382
  delayMs = opts.presentationDelayMs(packetId, catalogTrackName);
@@ -349,12 +387,21 @@ function wireRepairFetch(mc, opts) {
349
387
  const retentionMs = mc.fecManager.terminalRetentionMsForPacket(packetId);
350
388
  if (retentionMs === void 0) return null;
351
389
  const ceilingAt = Math.min(anchor, earliestGatedFrameAt(packetId, catalogTrackName) ?? anchor) + retentionMs;
352
- const deadlineAt = (delay) => Math.max(waitDeadlineAt, Math.min(anchor + delay, ceilingAt));
353
- const base = deadlineAt(delayMs);
390
+ const at = (delay, delayBound) => {
391
+ const presentAt = Math.min(anchor + delay, ceilingAt);
392
+ if (waitDeadlineAt >= presentAt) return { deadlineAt: waitDeadlineAt, bound: "wait" };
393
+ return { deadlineAt: presentAt, bound: anchor + delay <= ceilingAt ? delayBound : "retention" };
394
+ };
395
+ const base = at(delayMs, "presentation");
354
396
  const budgetMs = keyframeBudgetEligible(blockClass, classifierMode(packetId, catalogTrackName)) && groupCanComplete(sbn, packetId, catalogTrackName) ? readKeyframeBudget(packetId, catalogTrackName) : null;
355
- if (budgetMs === null || budgetMs <= delayMs) return { deadlineAt: base, extensionMs: 0 };
356
- const extended = deadlineAt(budgetMs);
357
- return { deadlineAt: extended, extensionMs: extended - base };
397
+ if (budgetMs === null || budgetMs <= delayMs) return { ...base, extensionMs: 0, anchorAt: anchor, delayMs };
398
+ const extended = at(budgetMs, "keyframe");
399
+ return {
400
+ ...extended,
401
+ extensionMs: extended.deadlineAt - base.deadlineAt,
402
+ anchorAt: anchor,
403
+ delayMs: budgetMs
404
+ };
358
405
  };
359
406
  const earliestGatedFrameAt = (packetId, catalogTrackName) => {
360
407
  try {
@@ -431,6 +478,9 @@ function wireRepairFetch(mc, opts) {
431
478
  priority,
432
479
  subscriberPriority: wire.subscriberPriority,
433
480
  deadlineAt: deadline.deadlineAt,
481
+ anchorAt: deadline.anchorAt,
482
+ delayMs: deadline.delayMs,
483
+ bound: deadline.bound,
434
484
  order: enqueueOrder++,
435
485
  attempts: 0,
436
486
  running: null
@@ -440,14 +490,92 @@ function wireRepairFetch(mc, opts) {
440
490
  if (entry.priority < 2) preemptDeltas();
441
491
  dispatch();
442
492
  });
493
+ const rangeFor = (loss, repairTrack) => {
494
+ let reference;
495
+ try {
496
+ reference = opts.repairEpochReference(repairTrack);
497
+ } catch {
498
+ return null;
499
+ }
500
+ if (reference === void 0) return null;
501
+ try {
502
+ const anchor = loss.previousBlockStart === void 0 ? { reference } : { previousBlockStart: extendSsId(reference, loss.previousBlockStart) };
503
+ return repairFetchRange(loss.lostSsId, loss.kMax, anchor);
504
+ } catch (error) {
505
+ if (error instanceof RangeError) return null;
506
+ throw error;
507
+ }
508
+ };
509
+ if (opts.rangeTransport !== void 0) {
510
+ mc.onUndelimitedLoss((loss) => {
511
+ const { packetId, catalogTrackName, holeStart, holeLength } = loss;
512
+ const close = () => mc.closeIsoHoles(packetId, catalogTrackName, holeStart, holeLength);
513
+ if (disposed) return close();
514
+ const blockProfile = blockProfileOf(packetId);
515
+ const target = opts.resolveTarget(packetId, catalogTrackName);
516
+ if (!target) return close();
517
+ const priority = repairPriorityForClass("unknown");
518
+ const range = rangeFor(loss, target.repairTrack);
519
+ if (range === null) {
520
+ close();
521
+ mc.noteRepairSkipped("range-no-anchor", { rttMs: readRtt(), budgetMs: 0, priority }, holeStart, packetId, catalogTrackName);
522
+ return;
523
+ }
524
+ const identity = {
525
+ target,
526
+ sbn: holeStart,
527
+ packetId,
528
+ ...catalogTrackName === void 0 ? {} : { catalogTrackName }
529
+ };
530
+ const wire = wirePriority(identity, "unknown");
531
+ const deadline = presentationDeadlineAt(holeStart, packetId, catalogTrackName, performance.now(), "unknown");
532
+ if (deadline === null) {
533
+ close();
534
+ mc.noteRepairSkipped(
535
+ "presentation-delay-unavailable",
536
+ { rttMs: readRtt(), budgetMs: 0, priority },
537
+ holeStart,
538
+ packetId,
539
+ catalogTrackName
540
+ );
541
+ return;
542
+ }
543
+ const entry = {
544
+ key: JSON.stringify(["range", packetId, catalogTrackName ?? null, holeStart]),
545
+ ...identity,
546
+ repairTrack: target.repairTrack,
547
+ blockProfile,
548
+ priority,
549
+ subscriberPriority: wire.subscriberPriority,
550
+ deadlineAt: deadline.deadlineAt,
551
+ anchorAt: deadline.anchorAt,
552
+ delayMs: deadline.delayMs,
553
+ bound: deadline.bound,
554
+ order: enqueueOrder++,
555
+ attempts: 0,
556
+ running: null,
557
+ range: { ...range, lostSsId: loss.lostSsId, holeLength }
558
+ };
559
+ const previous = entries.get(entry.key);
560
+ if (previous) {
561
+ retire(previous);
562
+ stop(previous, "reset");
563
+ }
564
+ entries.set(entry.key, entry);
565
+ entry.expiry = setTimeout(dispatch, Math.max(0, entry.deadlineAt - performance.now()) + 1);
566
+ preemptDeltas();
567
+ dispatch();
568
+ });
569
+ }
443
570
  return () => {
444
571
  disposed = true;
445
572
  removeResetObserver();
446
573
  removeLifecycleObserver();
447
574
  for (const entry of [...entries.values()]) {
448
- clearRepair(entry.sbn, entry.packetId, entry.catalogTrackName);
575
+ clearEntry(entry);
449
576
  if (entry.running) releaseHold(entry);
450
577
  stop(entry, "disposed");
578
+ if (entry.expiry !== void 0) clearTimeout(entry.expiry);
451
579
  }
452
580
  entries.clear();
453
581
  };