@blockcast/mmt-container 0.4.0 → 0.4.1-main.2e0aa69d293d

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 (220) hide show
  1. package/README.md +37 -21
  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 +5070 -908
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +76 -39
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +321 -205
  11. package/dist/carp-catalog.js.map +3 -3
  12. package/dist/catalog-fec-params.d.ts +12 -4
  13. package/dist/catalog-fec-params.d.ts.map +1 -1
  14. package/dist/catalog-fec-params.js +40 -17
  15. package/dist/catalog-fec-params.js.map +3 -3
  16. package/dist/catalog-network-source.d.ts +28 -7
  17. package/dist/catalog-network-source.d.ts.map +1 -1
  18. package/dist/catalog-network-source.js +21 -1
  19. package/dist/catalog-network-source.js.map +2 -2
  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/cmcd-producer.d.ts +13 -1
  25. package/dist/cmcd-producer.d.ts.map +1 -1
  26. package/dist/cmcd-producer.js +14 -0
  27. package/dist/cmcd-producer.js.map +2 -2
  28. package/dist/delivery-catalog.js +115 -235
  29. package/dist/delivery-catalog.js.map +4 -4
  30. package/dist/fec-manager.d.ts +113 -1
  31. package/dist/fec-manager.d.ts.map +1 -1
  32. package/dist/fec-manager.js +464 -66
  33. package/dist/fec-manager.js.map +4 -4
  34. package/dist/fec-state.d.ts +2 -1
  35. package/dist/fec-state.d.ts.map +1 -1
  36. package/dist/fec-state.js +18 -3
  37. package/dist/fec-state.js.map +3 -3
  38. package/dist/fec-worker-setup.d.ts +10 -0
  39. package/dist/fec-worker-setup.d.ts.map +1 -1
  40. package/dist/fec-worker-setup.js +15 -4
  41. package/dist/fec-worker-setup.js.map +2 -2
  42. package/dist/held-layer-admission.d.ts +58 -0
  43. package/dist/held-layer-admission.d.ts.map +1 -0
  44. package/dist/held-layer-admission.js +105 -0
  45. package/dist/held-layer-admission.js.map +7 -0
  46. package/dist/index.d.ts +5 -5
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +8 -8
  49. package/dist/index.js.map +2 -2
  50. package/dist/iso-block-locator.d.ts +39 -1
  51. package/dist/iso-block-locator.d.ts.map +1 -1
  52. package/dist/iso-block-locator.js +109 -17
  53. package/dist/iso-block-locator.js.map +3 -3
  54. package/dist/mfu-reassembler.js +21 -13
  55. package/dist/mfu-reassembler.js.map +2 -2
  56. package/dist/mmtp-container-parser.d.ts.map +1 -1
  57. package/dist/mmtp-container-parser.js +93 -22
  58. package/dist/mmtp-container-parser.js.map +2 -2
  59. package/dist/mmtp-container-parser.no-modules.js +3692 -1213
  60. package/dist/mmtp-container-parser.no-modules.js.map +4 -4
  61. package/dist/mmtp-decode-pipeline.js +93 -22
  62. package/dist/mmtp-decode-pipeline.js.map +2 -2
  63. package/dist/mmtp-fec-session.d.ts +192 -0
  64. package/dist/mmtp-fec-session.d.ts.map +1 -0
  65. package/dist/mmtp-fec-session.js +640 -0
  66. package/dist/mmtp-fec-session.js.map +7 -0
  67. package/dist/mmtp-router.d.ts +101 -32
  68. package/dist/mmtp-router.d.ts.map +1 -1
  69. package/dist/mmtp-router.js +422 -189
  70. package/dist/mmtp-router.js.map +2 -2
  71. package/dist/multicast-auth-catalog.d.ts +94 -92
  72. package/dist/multicast-auth-catalog.d.ts.map +1 -1
  73. package/dist/multicast-auth-catalog.js +746 -131
  74. package/dist/multicast-auth-catalog.js.map +4 -4
  75. package/dist/multicast-input.d.ts +31 -8
  76. package/dist/multicast-input.d.ts.map +1 -1
  77. package/dist/multicast-input.js +299 -35
  78. package/dist/multicast-input.js.map +3 -3
  79. package/dist/multicast-manager.d.ts +140 -12
  80. package/dist/multicast-manager.d.ts.map +1 -1
  81. package/dist/multicast-manager.js +4104 -605
  82. package/dist/multicast-manager.js.map +4 -4
  83. package/dist/multicast-transport.d.ts +16 -3
  84. package/dist/multicast-transport.d.ts.map +1 -1
  85. package/dist/multicast-transport.js +127 -240
  86. package/dist/multicast-transport.js.map +4 -4
  87. package/dist/multicast-unwrap.js +21 -13
  88. package/dist/multicast-unwrap.js.map +2 -2
  89. package/dist/no-modules.d.ts +5 -3
  90. package/dist/no-modules.d.ts.map +1 -1
  91. package/dist/no-modules.js +3643 -1197
  92. package/dist/no-modules.js.map +4 -4
  93. package/dist/phase14-catalog-override.d.ts +1 -1
  94. package/dist/phase14-catalog-override.d.ts.map +1 -1
  95. package/dist/phase14-catalog-override.js +2 -2
  96. package/dist/phase14-catalog-override.js.map +2 -2
  97. package/dist/repair-fetch.d.ts +90 -6
  98. package/dist/repair-fetch.d.ts.map +1 -1
  99. package/dist/repair-fetch.js +160 -32
  100. package/dist/repair-fetch.js.map +3 -3
  101. package/dist/repair-layers.d.ts +2 -0
  102. package/dist/repair-layers.d.ts.map +1 -1
  103. package/dist/repair-layers.js +19 -2
  104. package/dist/repair-layers.js.map +2 -2
  105. package/dist/sample-combiner.d.ts +7 -1
  106. package/dist/sample-combiner.d.ts.map +1 -1
  107. package/dist/sample-combiner.js +14 -2
  108. package/dist/sample-combiner.js.map +2 -2
  109. package/dist/signaling.d.ts +2 -2
  110. package/dist/signaling.d.ts.map +1 -1
  111. package/dist/signaling.js +3 -3
  112. package/dist/signaling.js.map +2 -2
  113. package/dist/switching-set-alignment.d.ts +1 -1
  114. package/dist/switching-set-alignment.js.map +1 -1
  115. package/dist/timestamp-codec.js +21 -13
  116. package/dist/timestamp-codec.js.map +2 -2
  117. package/dist/wasm-mfu-reassembler.js.map +1 -1
  118. package/dist/wasm-mmtp-container-parser.js +93 -22
  119. package/dist/wasm-mmtp-container-parser.js.map +2 -2
  120. package/package.json +6 -18
  121. package/schemas/catalog.schema.json +133 -38
  122. package/src/align.ts +52 -21
  123. package/src/carp-catalog.ts +188 -68
  124. package/src/catalog-fec-params.ts +28 -3
  125. package/src/catalog-network-source.ts +49 -7
  126. package/src/catalog-validator.ts +4 -11
  127. package/src/cmcd-producer.ts +23 -1
  128. package/src/fec-manager.ts +378 -63
  129. package/src/fec-state.ts +11 -4
  130. package/src/fec-worker-setup.ts +30 -2
  131. package/src/held-layer-admission.ts +161 -0
  132. package/src/index.ts +32 -19
  133. package/src/iso-block-locator.ts +110 -7
  134. package/src/mmtp-container-parser.ts +75 -7
  135. package/src/mmtp-fec-session.ts +606 -0
  136. package/src/mmtp-router.ts +453 -236
  137. package/src/multicast-auth-catalog.ts +196 -231
  138. package/src/multicast-input.ts +148 -124
  139. package/src/multicast-manager.ts +447 -53
  140. package/src/multicast-transport.ts +23 -5
  141. package/src/no-modules.ts +8 -7
  142. package/src/phase14-catalog-override.ts +3 -3
  143. package/src/repair-fetch.ts +306 -42
  144. package/src/repair-layers.ts +22 -2
  145. package/src/sample-combiner.ts +15 -2
  146. package/src/signaling.ts +2 -2
  147. package/src/switching-set-alignment.ts +1 -1
  148. package/test-vectors/align.json +108 -32
  149. package/test-vectors/bc-provenance-v2.json +1526 -0
  150. package/test-vectors/catalog/README.md +71 -4
  151. package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
  152. package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
  153. package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
  154. package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
  155. package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
  156. package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
  157. package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
  158. package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
  159. package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
  160. package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
  161. package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
  162. package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
  163. package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
  164. package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
  165. package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
  166. package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
  167. package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
  168. package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
  169. package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
  170. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
  171. package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
  172. package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
  173. package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
  174. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
  175. package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
  176. package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
  177. package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
  178. package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
  179. package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
  180. package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
  181. package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
  182. package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
  183. package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
  184. package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
  185. package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
  186. package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
  187. package/test-vectors/catalog/positive/fec-multicast.json +1 -1
  188. package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
  189. package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
  190. package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
  191. package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
  192. package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
  193. package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
  194. package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
  195. package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
  196. package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
  197. package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
  198. package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
  199. package/test-vectors/catalog/section-codes.json +31 -1
  200. package/test-vectors/catalog-multicast-auth-v1.json +38 -20
  201. package/test-vectors/catalog-validation.json +101 -5
  202. package/test-vectors/catalog-validator-public-api.mjs +14 -9
  203. package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
  204. package/dist/fec-codec.d.ts +0 -32
  205. package/dist/fec-codec.d.ts.map +0 -1
  206. package/dist/fec-codec.js +0 -47
  207. package/dist/fec-codec.js.map +0 -7
  208. package/dist/manifest-auth-plan.d.ts +0 -30
  209. package/dist/manifest-auth-plan.d.ts.map +0 -1
  210. package/dist/manifest-auth-plan.js +0 -1266
  211. package/dist/manifest-auth-plan.js.map +0 -7
  212. package/dist/source-auth.d.ts +0 -2
  213. package/dist/source-auth.d.ts.map +0 -1
  214. package/dist/source-auth.js +0 -1209
  215. package/dist/source-auth.js.map +0 -7
  216. package/src/fec-codec.ts +0 -61
  217. package/src/manifest-auth-plan.ts +0 -107
  218. package/src/source-auth.ts +0 -1
  219. package/test-vectors/generate-source-auth-fixture.mjs +0 -114
  220. package/test-vectors/source-auth-v1.json +0 -61
@@ -1034,8 +1034,23 @@ function isFmp4Box(data: Uint8Array): boolean {
1034
1034
  interface TimingStreamState {
1035
1035
  packetId: number
1036
1036
  resolver: IsoBmffTimingResolver
1037
+ /** FI=0/FI=1 heads that arrived before their sample's FT=1, oldest first. */
1038
+ awaitingTiming: AwaitingTimingHead[]
1037
1039
  }
1038
1040
 
1041
+ /** A head refused for missing timing, kept to be fed again when its FT=1 lands. */
1042
+ interface AwaitingTimingHead {
1043
+ packet: Uint8Array
1044
+ options: ParseHeaderOptions | undefined
1045
+ parsed: ParsedMmtpPacket
1046
+ mpuSequenceNumber: number
1047
+ movieFragmentSequenceNumber: number
1048
+ sampleNumber: number
1049
+ arrivedAt: number
1050
+ }
1051
+
1052
+ const MAX_AWAITING_TIMING_HEADS = 8
1053
+
1039
1054
  // ── MmtpContainerParser ─────────────────────────────────────────────
1040
1055
 
1041
1056
  export class MmtpContainerParser {
@@ -1098,6 +1113,7 @@ export class MmtpContainerParser {
1098
1113
  * reordering into the parser. */
1099
1114
  #reliableMoqStartupGate = new Map<string, number>()
1100
1115
  #disposed = false
1116
+ #replayingAwaitingTiming = false
1101
1117
  #fedObjects = 0
1102
1118
  #reassemblerFragmentsFed = 0
1103
1119
  #reassemblerDataUnitsReturned = 0
@@ -1446,7 +1462,10 @@ export class MmtpContainerParser {
1446
1462
  * a single failure bucket. Returns null so call sites stay `return this.#drop(...)`.
1447
1463
  */
1448
1464
  #drop(reason: MmtpFeedDropReason): null {
1449
- this.#countOutcome(`drop:${reason}`)
1465
+ // A replayed head was counted when it was fed; what befalls it now is a
1466
+ // side effect of the FT=1 that released it.
1467
+ if (this.#replayingAwaitingTiming) this.#countDeferredOutcome(reason)
1468
+ else this.#countOutcome(`drop:${reason}`)
1450
1469
  return null
1451
1470
  }
1452
1471
 
@@ -1471,6 +1490,12 @@ export class MmtpContainerParser {
1471
1490
  for (const combiner of this.#sampleCombiners.values()) {
1472
1491
  combiner.cleanupTimeouts(timeoutMs)
1473
1492
  }
1493
+ const now = Date.now()
1494
+ for (const { awaitingTiming } of this.#timingStreams.values()) {
1495
+ while (awaitingTiming.length > 0 && now - awaitingTiming[0]!.arrivedAt > timeoutMs) {
1496
+ awaitingTiming.shift()
1497
+ }
1498
+ }
1474
1499
  }
1475
1500
 
1476
1501
  /**
@@ -1587,7 +1612,7 @@ export class MmtpContainerParser {
1587
1612
  // Fire onSourceSymbol BEFORE MFU extraction so the consumer-side FEC
1588
1613
  // pipeline (e.g. FecWorkerClient.feedSource) starts as early as possible.
1589
1614
  // Source-only: parseHeader already gates fecPayloadId on !isRepair.
1590
- if (info.fecPayloadId !== null && this.#sourceSymbolCb) {
1615
+ if (info.fecPayloadId !== null && this.#sourceSymbolCb && !this.#replayingAwaitingTiming) {
1591
1616
  // Strip the 4-byte fec_payload_id trailer per ISO 23008-1 §C.5.2.
1592
1617
  // Symbol-size zero-padding is the consumer's responsibility — FEC
1593
1618
  // symbol size is a FEC-config concern, not a parser concern.
@@ -1654,6 +1679,7 @@ export class MmtpContainerParser {
1654
1679
  }
1655
1680
  return this.#drop('fragment-timing-refused')
1656
1681
  }
1682
+ this.#replayAwaitingTiming(streamKey, resolver)
1657
1683
  return {
1658
1684
  kind: 'fragment',
1659
1685
  packet: info,
@@ -1679,7 +1705,18 @@ export class MmtpContainerParser {
1679
1705
  mfuDuHeader.movieFragmentSequenceNumber,
1680
1706
  mfuDuHeader.sampleNumber,
1681
1707
  )
1682
- if (!headTiming) return this.#drop('mfu-sample-timing-missing')
1708
+ if (!headTiming) {
1709
+ this.#awaitTiming(streamKey, {
1710
+ packet,
1711
+ options,
1712
+ parsed,
1713
+ mpuSequenceNumber: mpu.mpuSequenceNumber,
1714
+ movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
1715
+ sampleNumber: mfuDuHeader.sampleNumber,
1716
+ arrivedAt: Date.now(),
1717
+ })
1718
+ return this.#drop('mfu-sample-timing-missing')
1719
+ }
1683
1720
  // A data unit's authored base offset is its position within the sample
1684
1721
  // (moqcast #37): 0 for a whole-sample DU, nonzero for one subsample DU
1685
1722
  // among siblings. Sizes below are therefore relative to that base, not
@@ -1781,11 +1818,12 @@ export class MmtpContainerParser {
1781
1818
  // a sample this stream declared, so it must be dropped outright -- letting
1782
1819
  // it buffer would occupy a combiner slot and could evict a legitimate
1783
1820
  // partitioned sample waiting on a sibling.
1784
- if (!resolver.sampleTiming(
1821
+ const assembledTiming = resolver.sampleTiming(
1785
1822
  assembled.mpuSequenceNumber,
1786
1823
  movieFragmentSequenceNumber,
1787
1824
  sampleNumber,
1788
- )) return this.#drop('assembled-timing-missing')
1825
+ )
1826
+ if (!assembledTiming) return this.#drop('assembled-timing-missing')
1789
1827
  if (assembled.mpuSequenceNumber !== mpu.mpuSequenceNumber)
1790
1828
  return this.#drop('assembled-mpu-mismatch')
1791
1829
 
@@ -1795,7 +1833,7 @@ export class MmtpContainerParser {
1795
1833
  // unpartitioned sample passes straight through with no buffering.
1796
1834
  let combined: CombinedSample | null
1797
1835
  try {
1798
- combined = this.#sampleCombinerFor(streamKey).addMfu(assembled)
1836
+ combined = this.#sampleCombinerFor(streamKey).addMfu(assembled, assembledTiming.size)
1799
1837
  } catch (error) {
1800
1838
  if (!(error instanceof SampleCombineError)) throw error
1801
1839
  console.warn(
@@ -2150,10 +2188,40 @@ export class MmtpContainerParser {
2150
2188
  if (existing) return existing.resolver
2151
2189
  if (!create) return null
2152
2190
  const resolver = new IsoBmffTimingResolver(this.#maxPendingTimingSamples)
2153
- this.#timingStreams.set(streamKey, { packetId, resolver })
2191
+ this.#timingStreams.set(streamKey, { packetId, resolver, awaitingTiming: [] })
2154
2192
  return resolver
2155
2193
  }
2156
2194
 
2195
+ #awaitTiming(streamKey: string, head: AwaitingTimingHead): void {
2196
+ const awaitingTiming = this.#timingStreams.get(streamKey)?.awaitingTiming
2197
+ if (!awaitingTiming) return
2198
+ awaitingTiming.push(head)
2199
+ if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) awaitingTiming.shift()
2200
+ }
2201
+
2202
+ /**
2203
+ * Feed again the heads whose timing the FT=1 just admitted declares. That
2204
+ * FT=1 can be an FEC recovery landing after its sample's FI=1, and neither
2205
+ * FEC path routes a source symbol that already arrived a second time.
2206
+ */
2207
+ #replayAwaitingTiming(streamKey: string, resolver: IsoBmffTimingResolver): void {
2208
+ const state = this.#timingStreams.get(streamKey)
2209
+ if (!state || state.awaitingTiming.length === 0) return
2210
+ const ready = state.awaitingTiming.filter(head => resolver.sampleTiming(
2211
+ head.mpuSequenceNumber,
2212
+ head.movieFragmentSequenceNumber,
2213
+ head.sampleNumber,
2214
+ ))
2215
+ if (ready.length === 0) return
2216
+ state.awaitingTiming = state.awaitingTiming.filter(head => !ready.includes(head))
2217
+ this.#replayingAwaitingTiming = true
2218
+ try {
2219
+ for (const head of ready) this.#feed(head.packet, head.options, head.parsed)
2220
+ } finally {
2221
+ this.#replayingAwaitingTiming = false
2222
+ }
2223
+ }
2224
+
2157
2225
  #dropTimingStream(streamKey: string): void {
2158
2226
  const state = this.#timingStreams.get(streamKey)
2159
2227
  if (!state) return