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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/dist/align.d.ts +6 -2
  2. package/dist/align.d.ts.map +1 -1
  3. package/dist/align.js.map +2 -2
  4. package/dist/audio-ring-buffer.js +23 -36
  5. package/dist/audio-ring-buffer.js.map +1 -1
  6. package/dist/browser-runtime.js +6865 -6485
  7. package/dist/browser-runtime.js.map +4 -4
  8. package/dist/carp-catalog.d.ts +3 -1
  9. package/dist/carp-catalog.d.ts.map +1 -1
  10. package/dist/carp-catalog.js +21 -2
  11. package/dist/carp-catalog.js.map +4 -4
  12. package/dist/catalog-fec-params.js +10 -0
  13. package/dist/catalog-fec-params.js.map +4 -4
  14. package/dist/cmaf-block-assembler.d.ts +42 -0
  15. package/dist/cmaf-block-assembler.d.ts.map +1 -1
  16. package/dist/cmaf-block-assembler.js +542 -535
  17. package/dist/cmaf-block-assembler.js.map +2 -2
  18. package/dist/cmaf-group-batcher.js +27 -46
  19. package/dist/cmaf-group-batcher.js.map +2 -2
  20. package/dist/cmcd-producer.js +45 -66
  21. package/dist/cmcd-producer.js.map +1 -1
  22. package/dist/fec-manager.d.ts +13 -1
  23. package/dist/fec-manager.d.ts.map +1 -1
  24. package/dist/fec-manager.js +1151 -871
  25. package/dist/fec-manager.js.map +2 -2
  26. package/dist/fec-starvation-detector.js +25 -40
  27. package/dist/fec-starvation-detector.js.map +1 -1
  28. package/dist/fec-worker-setup.js +242 -225
  29. package/dist/fec-worker-setup.js.map +3 -3
  30. package/dist/index.d.ts +3 -3
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js.map +2 -2
  33. package/dist/iso-bmff-timing.js +63 -88
  34. package/dist/iso-bmff-timing.js.map +1 -1
  35. package/dist/loc.js +7 -4
  36. package/dist/loc.js.map +1 -1
  37. package/dist/manifest-auth-plan.js +292 -311
  38. package/dist/manifest-auth-plan.js.map +1 -1
  39. package/dist/media-router.d.ts +0 -99
  40. package/dist/media-router.d.ts.map +1 -1
  41. package/dist/media-router.js +270 -504
  42. package/dist/media-router.js.map +3 -3
  43. package/dist/mfu-reassembler.js +597 -607
  44. package/dist/mfu-reassembler.js.map +3 -3
  45. package/dist/mmtp-container-parser.d.ts +37 -0
  46. package/dist/mmtp-container-parser.d.ts.map +1 -1
  47. package/dist/mmtp-container-parser.js +1531 -1522
  48. package/dist/mmtp-container-parser.js.map +3 -3
  49. package/dist/mmtp-container-parser.no-modules.js +179 -102
  50. package/dist/mmtp-container-parser.no-modules.js.map +3 -3
  51. package/dist/mmtp-decode-pipeline.js +1641 -1651
  52. package/dist/mmtp-decode-pipeline.js.map +3 -3
  53. package/dist/mmtp-router.d.ts +34 -0
  54. package/dist/mmtp-router.d.ts.map +1 -1
  55. package/dist/mmtp-router.js +3676 -3390
  56. package/dist/mmtp-router.js.map +3 -3
  57. package/dist/mmtp-to-cmaf.d.ts +7 -1
  58. package/dist/mmtp-to-cmaf.d.ts.map +1 -1
  59. package/dist/mmtp-to-cmaf.js +109 -134
  60. package/dist/mmtp-to-cmaf.js.map +2 -2
  61. package/dist/multicast-input.d.ts +7 -35
  62. package/dist/multicast-input.d.ts.map +1 -1
  63. package/dist/multicast-input.js +21 -2
  64. package/dist/multicast-input.js.map +4 -4
  65. package/dist/multicast-manager.d.ts +10 -1
  66. package/dist/multicast-manager.d.ts.map +1 -1
  67. package/dist/multicast-manager.js +5584 -4961
  68. package/dist/multicast-manager.js.map +4 -4
  69. package/dist/multicast-transport.d.ts +7 -0
  70. package/dist/multicast-transport.d.ts.map +1 -1
  71. package/dist/multicast-transport.js +369 -421
  72. package/dist/multicast-transport.js.map +4 -4
  73. package/dist/multicast-unwrap.js +53 -30
  74. package/dist/multicast-unwrap.js.map +2 -2
  75. package/dist/no-modules.js +2096 -2097
  76. package/dist/no-modules.js.map +3 -3
  77. package/dist/sample-combiner.js +118 -139
  78. package/dist/sample-combiner.js.map +1 -1
  79. package/dist/signaling.js.map +2 -2
  80. package/dist/source-auth.js +353 -382
  81. package/dist/source-auth.js.map +1 -1
  82. package/dist/switching-set-alignment.js +14 -29
  83. package/dist/switching-set-alignment.js.map +1 -1
  84. package/dist/timestamp-codec.js +17 -11
  85. package/dist/timestamp-codec.js.map +2 -2
  86. package/dist/track-pipeline-setup.js +105 -125
  87. package/dist/track-pipeline-setup.js.map +1 -1
  88. package/dist/track-pipeline.js +107 -127
  89. package/dist/track-pipeline.js.map +1 -1
  90. package/dist/track-session.d.ts +16 -0
  91. package/dist/track-session.d.ts.map +1 -1
  92. package/dist/track-session.js +230 -243
  93. package/dist/track-session.js.map +2 -2
  94. package/dist/transport-pool.js +24 -38
  95. package/dist/transport-pool.js.map +1 -1
  96. package/dist/wasm-mfu-reassembler.d.ts +6 -1
  97. package/dist/wasm-mfu-reassembler.d.ts.map +1 -1
  98. package/dist/wasm-mfu-reassembler.js +127 -144
  99. package/dist/wasm-mfu-reassembler.js.map +2 -2
  100. package/dist/wasm-mmtp-container-parser.js +1659 -1650
  101. package/dist/wasm-mmtp-container-parser.js.map +3 -3
  102. package/node_modules/@blockcast/fec-worker/README.md +5 -1
  103. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.d.ts +8 -2
  104. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.d.ts.map +1 -1
  105. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.js +89 -16
  106. package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.js.map +1 -1
  107. package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts +48 -3
  108. package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts.map +1 -1
  109. package/node_modules/@blockcast/fec-worker/dist/fec-worker.js +55 -8
  110. package/node_modules/@blockcast/fec-worker/dist/fec-worker.js.map +2 -2
  111. package/node_modules/@blockcast/fec-worker/dist/index.d.ts +1 -1
  112. package/node_modules/@blockcast/fec-worker/dist/index.d.ts.map +1 -1
  113. package/node_modules/@blockcast/fec-worker/dist/index.js.map +1 -1
  114. package/node_modules/@blockcast/fec-worker/src/fec-worker-client.ts +97 -17
  115. package/node_modules/@blockcast/fec-worker/src/fec-worker-types.ts +46 -2
  116. package/node_modules/@blockcast/fec-worker/src/fec-worker.ts +78 -10
  117. package/node_modules/@blockcast/fec-worker/src/index.ts +2 -0
  118. package/node_modules/@blockcast/mmt-base/README.md +1 -0
  119. package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +52 -0
  120. package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -1
  121. package/node_modules/@blockcast/mmt-base/dist/mmtp.js +142 -37
  122. package/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -1
  123. package/node_modules/@blockcast/mmt-base/src/mmtp.ts +158 -37
  124. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/README.md +1 -0
  125. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +52 -0
  126. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -1
  127. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js +142 -37
  128. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -1
  129. package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/mmtp.ts +158 -37
  130. package/package.json +7 -6
  131. package/schemas/catalog.schema.json +1 -1
  132. package/src/align.ts +6 -2
  133. package/src/carp-catalog.ts +13 -3
  134. package/src/cmaf-block-assembler.ts +90 -81
  135. package/src/fec-manager.ts +530 -146
  136. package/src/index.ts +2 -2
  137. package/src/media-router.ts +0 -397
  138. package/src/mmtp-container-parser.ts +97 -21
  139. package/src/mmtp-router.ts +302 -125
  140. package/src/mmtp-to-cmaf.ts +21 -7
  141. package/src/multicast-input.ts +23 -3
  142. package/src/multicast-manager.ts +83 -11
  143. package/src/multicast-transport.ts +56 -17
  144. package/src/track-session.ts +16 -0
  145. package/src/wasm-mfu-reassembler.ts +40 -24
  146. package/test-vectors/catalog/README.md +2 -0
  147. package/test-vectors/catalog/negative/multicast-packet-id-signaling.json +26 -0
  148. package/test-vectors/catalog-validation.json +11 -0
@@ -75,6 +75,8 @@ let altaEnabled = false;
75
75
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
76
  let altaVerifier: any = null; // JsAltaVerifier instance (loaded from ALTA WASM)
77
77
  let snapshotTimer: ReturnType<typeof setInterval> | null = null;
78
+ // blockUpdate events are posted only after a client subscribes (BLO-36599).
79
+ let blockUpdatesSubscribed = false;
78
80
 
79
81
  // Block tracking
80
82
  const blocks = new Map<number, FecBlockSnapshot>();
@@ -478,6 +480,7 @@ function emitSnapshot(): void {
478
480
  }
479
481
 
480
482
  function emitBlockUpdate(block: FecBlockSnapshot): void {
483
+ if (!blockUpdatesSubscribed) return;
481
484
  emit({ type: "blockUpdate", block: { ...block } });
482
485
  }
483
486
 
@@ -496,16 +499,19 @@ function emitRecoveredSymbols(
496
499
  });
497
500
  return;
498
501
  }
499
- if (recoveredBlock.byteLength < symbolSize * config.k) {
502
+ // The decoder returns only the block's authored source symbols
503
+ // (SSB_length x T); the encoder's zero padding is not media.
504
+ const ssbLength = block.ssbLength ?? config.k;
505
+ if (recoveredBlock.byteLength !== symbolSize * ssbLength) {
500
506
  emit({
501
507
  type: "error",
502
508
  code: "recovered-block-too-short",
503
- message: `[FecWorker] recovered block too short: got ${recoveredBlock.byteLength}B, expected at least ${symbolSize * config.k}B`,
509
+ message: `[FecWorker] recovered block has the wrong length: got ${recoveredBlock.byteLength}B, expected ${symbolSize * ssbLength}B (SSB_length=${ssbLength})`,
504
510
  });
505
511
  return;
506
512
  }
507
513
 
508
- for (let i = 0; i < config.k; i++) {
514
+ for (let i = 0; i < ssbLength; i++) {
509
515
  const symbol = recoveredBlock.subarray(i * symbolSize, (i + 1) * symbolSize);
510
516
 
511
517
  // Source authentication now runs once at router admission in
@@ -520,6 +526,7 @@ function emitRecoveredSymbols(
520
526
  recovered: true,
521
527
  sbn,
522
528
  esi: i,
529
+ ssbLength,
523
530
  };
524
531
  emit({ type: "frame", data: buf, meta }, [buf]);
525
532
  }
@@ -662,6 +669,10 @@ async function handleConfigure(
662
669
 
663
670
  wasmDecoder.configure_params(config.k, config.symbolSize);
664
671
 
672
+ // Tell the client which optional commands this Worker accepts, so it can
673
+ // batch symbols without risking a Worker that predates the batch command.
674
+ emit({ type: "capabilities", commands: ["feedSymbols", "subscribeBlockUpdates"] });
675
+
665
676
  // Start periodic snapshot emission (200ms floor)
666
677
  startSnapshotTimer();
667
678
 
@@ -716,9 +727,11 @@ function handleFeedSource(
716
727
  // authenticated by the canonical manifest verifier at router admission.
717
728
  if (altaEnabled) altaPending++;
718
729
 
719
- // Check if block is complete (all K source symbols received)
730
+ // Check if block is complete (all authored source symbols received:
731
+ // SSB_length once a repair symbol declared it, otherwise K)
732
+ const authoredLength = block.ssbLength ?? block.k;
720
733
  if (
721
- block.sourceReceived >= block.k &&
734
+ block.sourceReceived >= authoredLength &&
722
735
  block.state === "collecting"
723
736
  ) {
724
737
  markBlockTerminal(block, "complete");
@@ -730,7 +743,7 @@ function handleFeedSource(
730
743
  // of earlier missing symbols after repair arrived. Clean completion is
731
744
  // already routed by the source path, so only emit when the block did not
732
745
  // reach K source arrivals.
733
- if (result && result.byteLength > 0 && block.sourceReceived < block.k) {
746
+ if (result && result.byteLength > 0 && block.sourceReceived < authoredLength) {
734
747
  const recovered = new Uint8Array(toOwnedArrayBuffer(result));
735
748
  const recoveryMs = performance.now() - block.firstSymbolTs;
736
749
  recoveryTimes.push(recoveryMs);
@@ -786,6 +799,16 @@ function handleFeedRepair(
786
799
  const existingBlock = blocks.get(sbn);
787
800
  if (existingBlock && isTerminalBlock(existingBlock)) return;
788
801
  if (acceptedRepairEsis.get(sbn)?.has(repairEsi)) return;
802
+ // One block has one authored SSB_length; a repair symbol naming another
803
+ // is dropped before it reaches the decoder (which rejects it too).
804
+ if (existingBlock?.ssbLength !== undefined && existingBlock.ssbLength !== cmd.ssbLength) {
805
+ emit({
806
+ type: "error",
807
+ code: "repair-ssb-length-conflict",
808
+ message: `[FecWorker] Dropping repair symbol whose SSB_length ${cmd.ssbLength} conflicts with ${existingBlock.ssbLength} (sbn=${sbn})`,
809
+ });
810
+ return;
811
+ }
789
812
 
790
813
  const result = wasmDecoder.add_repair(
791
814
  cmd.ssStart,
@@ -802,13 +825,20 @@ function handleFeedRepair(
802
825
  }
803
826
  repairEsis.add(repairEsi);
804
827
  const block = getOrCreateBlock(sbn);
828
+ block.ssbLength = cmd.ssbLength;
805
829
  block.repairReceived++;
806
830
  block.lastSymbolTs = performance.now();
807
831
  repairSymbols++;
808
- // If WASM returned data, it is the recovered source block: K fixed-width
809
- // source symbols concatenated. Split it before emitting so MmtpRouter gets
810
- // the same one-symbol shape as a direct source packet.
811
- if (result && result.byteLength > 0) {
832
+ // Every authored source symbol already arrived: knowing SSB_length makes
833
+ // the block clean. The decoder's return is the source already routed.
834
+ // Otherwise, returned data is the recovered source block: its SSB_length
835
+ // fixed-width authored symbols concatenated. Split it before emitting so
836
+ // MmtpRouter gets the same one-symbol shape as a direct source packet.
837
+ if (block.sourceReceived >= cmd.ssbLength && block.state === "collecting") {
838
+ markBlockTerminal(block, "complete");
839
+ blocksComplete++;
840
+ emitBlockUpdate(block);
841
+ } else if (result && result.byteLength > 0) {
812
842
  const recovered = new Uint8Array(toOwnedArrayBuffer(result));
813
843
  const recoveryMs = performance.now() - block.firstSymbolTs;
814
844
  recoveryTimes.push(recoveryMs);
@@ -994,6 +1024,38 @@ function handleReset(): void {
994
1024
  if (config) emitSnapshot();
995
1025
  }
996
1026
 
1027
+ /**
1028
+ * A batch of symbols fed in one page task (BLO-36599). Each record is
1029
+ * handled exactly as its single-symbol command would be, in order, and a
1030
+ * failing record reports the same `command-failed` error that command would
1031
+ * without stopping the records after it.
1032
+ */
1033
+ function handleFeedSymbols(
1034
+ cmd: Extract<FecWorkerCommand, { type: "feedSymbols" }>,
1035
+ ): void {
1036
+ if (!Array.isArray(cmd.symbols)) {
1037
+ throw new Error("[FecWorker] feedSymbols: symbols must be an array");
1038
+ }
1039
+ for (const symbol of cmd.symbols) {
1040
+ try {
1041
+ if (symbol?.type === "feedSource") handleFeedSource(symbol);
1042
+ else if (symbol?.type === "feedRepair") handleFeedRepair(symbol);
1043
+ else {
1044
+ throw new Error(
1045
+ `[FecWorker] feedSymbols: unknown symbol type ${String((symbol as { type?: unknown } | null)?.type)}`,
1046
+ );
1047
+ }
1048
+ } catch (err) {
1049
+ emit({
1050
+ type: "error",
1051
+ code: "command-failed",
1052
+ message:
1053
+ err instanceof Error ? err.message : `[FecWorker] ${String(err)}`,
1054
+ });
1055
+ }
1056
+ }
1057
+ }
1058
+
997
1059
  // --- Main message handler ---
998
1060
 
999
1061
  async function dispatchCommand(cmd: FecWorkerCommand): Promise<void> {
@@ -1011,6 +1073,9 @@ async function dispatchCommand(cmd: FecWorkerCommand): Promise<void> {
1011
1073
  case "feedRepair":
1012
1074
  handleFeedRepair(cmd);
1013
1075
  break;
1076
+ case "feedSymbols":
1077
+ handleFeedSymbols(cmd);
1078
+ break;
1014
1079
  case "relayBlockSig":
1015
1080
  handleRelayBlockSig(cmd);
1016
1081
  break;
@@ -1020,6 +1085,9 @@ async function dispatchCommand(cmd: FecWorkerCommand): Promise<void> {
1020
1085
  case "reset":
1021
1086
  handleReset();
1022
1087
  break;
1088
+ case "subscribeBlockUpdates":
1089
+ blockUpdatesSubscribed = true;
1090
+ break;
1023
1091
  case "dispose":
1024
1092
  handleDispose();
1025
1093
  break;
@@ -6,6 +6,8 @@
6
6
 
7
7
  export type {
8
8
  FecWorkerCommand,
9
+ FecSymbolCommand,
10
+ FecWorkerOptionalCommand,
9
11
  FecWorkerEvent,
10
12
  FecWorkerErrorCode,
11
13
  FecTrackConfig,
@@ -60,6 +60,7 @@ MPU `payload_length` is interpreted strictly as ISO's length-after-field value:
60
60
  | `parseAlFecMessage` | function | Parse an AL-FEC signaling message → `AlFecConfig` |
61
61
  | `MoqRepairFrame`, `AlFecConfig` | type | Repair-frame / AL-FEC config shapes |
62
62
  | `ALFEC_MESSAGE_ID` (0x0203), `FEC_CODE_XOR` (1), `FEC_CODE_RAPTORQ` (2), `REPAIR_FEC_PID_SIZE` (13) | const | AL-FEC signaling + payload-id constants |
63
+ | `MMTP_SIGNALING_PACKET_ID` (0), `MMTP_PACKET_ID_MAX` (0xffff) | const | Signaling-flow `packet_id` (never a track's) and the 16-bit `packet_id` ceiling; a track's `packet_id` is 1..65535 |
63
64
 
64
65
  ### ALTA trailer (re-exported from `@blockcast/mmt-alta-parse`)
65
66
 
@@ -74,12 +74,32 @@ export declare const PACKET_TYPE_MPU = 0;
74
74
  export declare const PACKET_TYPE_SIGNALING = 2;
75
75
  export declare const PACKET_TYPE_REPAIR = 3;
76
76
  export declare const ALFEC_MESSAGE_ID = 515;
77
+ /**
78
+ * MMTP `packet_id` of the signaling flow, which carries PACKET_TYPE_SIGNALING
79
+ * packets such as the AL-FEC message (ALFEC_MESSAGE_ID). The FFmpeg `moq_mmt`
80
+ * muxer sends that message on this packet_id into the same multicast group as
81
+ * the media, and moqcast-draft (PR #44) makes advertising it for a track a
82
+ * MUST NOT. A track's packet_id is therefore 1..MMTP_PACKET_ID_MAX.
83
+ */
84
+ export declare const MMTP_SIGNALING_PACKET_ID = 0;
85
+ /** Largest value of the 16-bit MMTP `packet_id` header field. */
86
+ export declare const MMTP_PACKET_ID_MAX = 65535;
77
87
  export declare const FEC_CODE_XOR = 1;
78
88
  export declare const FEC_CODE_RAPTORQ = 2;
79
89
  /**
80
90
  * Parse MMTP header from buffer
81
91
  */
82
92
  export declare function parseMMTPHeader(buffer: Uint8Array): MMTPHeader;
93
+ /**
94
+ * The MMTP `packet_id` of `buffer`, or null exactly when parseMMTPHeader would
95
+ * throw for it (short buffer, V != 0, truncated packet_counter or header
96
+ * extension).
97
+ *
98
+ * This is the per-packet filter a receiver runs before any other work, so it
99
+ * builds no header object, DataView or BigInt timestamp (BLO-36599). Use
100
+ * parseMMTPHeader when any other header field is needed.
101
+ */
102
+ export declare function readMMTPPacketId(buffer: Uint8Array): number | null;
83
103
  /**
84
104
  * Unwrap MMTP packet to extract payload
85
105
  */
@@ -147,6 +167,16 @@ export declare function explainMFURejection(mmtpPacket: Uint8Array, options?: {
147
167
  export declare function extractMFUPayload(mmtpPacket: Uint8Array, options?: {
148
168
  skipFecId?: boolean;
149
169
  }): MFUExtraction | null;
170
+ /**
171
+ * extractMFUPayload for a caller that already holds this packet's parsed MMTP
172
+ * header, so the header is not parsed a second time (BLO-36599).
173
+ *
174
+ * `header` must be `parseMMTPHeader(mmtpPacket)` of this same packet; the
175
+ * result is then identical to `extractMFUPayload(mmtpPacket, options)`.
176
+ */
177
+ export declare function extractMFUPayloadWithHeader(mmtpPacket: Uint8Array, header: MMTPHeader, options?: {
178
+ skipFecId?: boolean;
179
+ }): MFUExtraction | null;
150
180
  /**
151
181
  * Extract timestamp from MMTP packet
152
182
  */
@@ -178,6 +208,18 @@ export declare function extractFecPayloadId(mmtpPacket: Uint8Array): {
178
208
  * payload contains a four-byte Source FEC Payload ID.
179
209
  */
180
210
  export declare function hasSourceFecPayloadId(mmtpPacket: Uint8Array): boolean;
211
+ /**
212
+ * The Source FEC Payload ID of a packet whose MMTP header the caller already
213
+ * parsed, or null when the packet carries none: present only when FEC_type=1
214
+ * and the exact suffix after the ISO-declared MPU payload holds the four-byte
215
+ * ID (ISO/IEC 23008-1 §C.5.2). Same answer as extractFecPayloadId, without a
216
+ * second header parse (BLO-36599).
217
+ *
218
+ * `header` must be `parseMMTPHeader(mmtpPacket)` of this same packet.
219
+ */
220
+ export declare function sourceFecPayloadIdOf(mmtpPacket: Uint8Array, header: MMTPHeader): {
221
+ ssId: number;
222
+ } | null;
181
223
  /**
182
224
  * MMTP header-extension ext_type assigned to the detached ALTA authenticator
183
225
  * trailer (Path 2 / 08-07). Carried in an `[ext_type][ext_length][auth]`
@@ -237,6 +279,16 @@ export interface MoqRepairFrame {
237
279
  * @returns Parsed frame or null if invalid
238
280
  */
239
281
  export declare function parseMoqRepairFrame(frame: Uint8Array): MoqRepairFrame | null;
282
+ /**
283
+ * parseMoqRepairFrame for a caller that already holds this frame's parsed MMTP
284
+ * header, so the header is not parsed a second time (BLO-36599). The router's
285
+ * multicast repair branch uses it: one repair packet in every K + P otherwise
286
+ * paid two header parses.
287
+ *
288
+ * `header` must be `parseMMTPHeader(frame)` of this same frame; the result is
289
+ * then identical to `parseMoqRepairFrame(frame)`.
290
+ */
291
+ export declare function parseMoqRepairFrameWithHeader(frame: Uint8Array, header: MMTPHeader): MoqRepairFrame | null;
240
292
  /**
241
293
  * AL-FEC signaling configuration parsed from ISO/IEC 23008-1:2023 Table C.3 message.
242
294
  */
@@ -1 +1 @@
1
- {"version":3,"file":"mmtp.d.ts","sourceRoot":"","sources":["../src/mmtp.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,IAAI,uBAAuB,EAC7C,KAAK,WAAW,IAAI,gBAAgB,EACrC,MAAM,2BAA2B,CAAA;AAElC;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,sDAAsD;IACtD,iBAAiB,EAAE,OAAO,CAAA;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,4DAA4D;IAC5D,aAAa,EAAE,OAAO,CAAA;IACtB,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EA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MAAM,CAAA;CACpE,GAAG,IAAI,CASP;AAED,wEAAwE;AACxE,MAAM,WAAW,cAAc;IAC7B,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAA;IAChB,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAA;IACf,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAA;IACjB,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAA;IACZ,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAA;IACjB,mFAAmF;IACnF,UAAU,EAAE,UAAU,CAAA;CACvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,cAAc,GAAG,IAAI,CAE5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,UAAU,GACjB,cAAc,GAAG,IAAI,CAEvB;AA0BD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,CAAC,CAAA;IACnB,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;IACvB,GAAG,EAAE,UAAU,CAAA;CAChB;AAoBD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,CA2E5E"}
@@ -12,6 +12,16 @@ export const PACKET_TYPE_SIGNALING = 0x02;
12
12
  export const PACKET_TYPE_REPAIR = 0x03;
13
13
  // AL-FEC Signaling Message ID (ISO/IEC 23008-1:2023 Amendment 1:2025)
14
14
  export const ALFEC_MESSAGE_ID = 0x0203;
15
+ /**
16
+ * MMTP `packet_id` of the signaling flow, which carries PACKET_TYPE_SIGNALING
17
+ * packets such as the AL-FEC message (ALFEC_MESSAGE_ID). The FFmpeg `moq_mmt`
18
+ * muxer sends that message on this packet_id into the same multicast group as
19
+ * the media, and moqcast-draft (PR #44) makes advertising it for a track a
20
+ * MUST NOT. A track's packet_id is therefore 1..MMTP_PACKET_ID_MAX.
21
+ */
22
+ export const MMTP_SIGNALING_PACKET_ID = 0;
23
+ /** Largest value of the 16-bit MMTP `packet_id` header field. */
24
+ export const MMTP_PACKET_ID_MAX = 0xffff;
15
25
  // FEC Code IDs
16
26
  export const FEC_CODE_XOR = 1;
17
27
  export const FEC_CODE_RAPTORQ = 2;
@@ -81,6 +91,36 @@ export function parseMMTPHeader(buffer) {
81
91
  rapFlag,
82
92
  };
83
93
  }
94
+ /**
95
+ * The MMTP `packet_id` of `buffer`, or null exactly when parseMMTPHeader would
96
+ * throw for it (short buffer, V != 0, truncated packet_counter or header
97
+ * extension).
98
+ *
99
+ * This is the per-packet filter a receiver runs before any other work, so it
100
+ * builds no header object, DataView or BigInt timestamp (BLO-36599). Use
101
+ * parseMMTPHeader when any other header field is needed.
102
+ */
103
+ export function readMMTPPacketId(buffer) {
104
+ if (buffer.length < MMTP_HEADER_SIZE)
105
+ return null;
106
+ const flags = buffer[0];
107
+ if (((flags >> 6) & 0x03) !== 0)
108
+ return null;
109
+ let offset = MMTP_HEADER_SIZE;
110
+ if ((flags & 0x20) !== 0) {
111
+ if (offset + 4 > buffer.length)
112
+ return null;
113
+ offset += 4;
114
+ }
115
+ if ((flags & 0x02) !== 0) {
116
+ if (offset + 4 > buffer.length)
117
+ return null;
118
+ const length = (buffer[offset + 2] << 8) | buffer[offset + 3];
119
+ if (offset + 4 + length > buffer.length)
120
+ return null;
121
+ }
122
+ return (buffer[2] << 8) | buffer[3];
123
+ }
84
124
  /**
85
125
  * Unwrap MMTP packet to extract payload
86
126
  */
@@ -227,7 +267,7 @@ export function extractNALUnit(mmtpPacket) {
227
267
  * reason reported to operators can never drift from the decision the parser
228
268
  * actually made.
229
269
  */
230
- function planMfuExtraction(mmtpPacket, options) {
270
+ function planMfuExtraction(mmtpPacket, options, parsedHeader) {
231
271
  if (mmtpPacket.length < MMTP_HEADER_SIZE + MPU_HEADER_SIZE) {
232
272
  return {
233
273
  rejection: {
@@ -237,16 +277,21 @@ function planMfuExtraction(mmtpPacket, options) {
237
277
  };
238
278
  }
239
279
  let header;
240
- try {
241
- header = parseMMTPHeader(mmtpPacket);
280
+ if (parsedHeader) {
281
+ header = parsedHeader;
242
282
  }
243
- catch (error) {
244
- return {
245
- rejection: {
246
- gate: 'mmtp-header-unparseable',
247
- detail: error instanceof Error ? error.message : String(error),
248
- },
249
- };
283
+ else {
284
+ try {
285
+ header = parseMMTPHeader(mmtpPacket);
286
+ }
287
+ catch (error) {
288
+ return {
289
+ rejection: {
290
+ gate: 'mmtp-header-unparseable',
291
+ detail: error instanceof Error ? error.message : String(error),
292
+ },
293
+ };
294
+ }
250
295
  }
251
296
  if (header.packetType !== PACKET_TYPE_MPU) {
252
297
  return {
@@ -320,7 +365,19 @@ export function explainMFURejection(mmtpPacket, options) {
320
365
  return 'rejection' in result ? result.rejection : null;
321
366
  }
322
367
  export function extractMFUPayload(mmtpPacket, options) {
323
- const result = planMfuExtraction(mmtpPacket, options);
368
+ return extractPlannedMfu(mmtpPacket, planMfuExtraction(mmtpPacket, options));
369
+ }
370
+ /**
371
+ * extractMFUPayload for a caller that already holds this packet's parsed MMTP
372
+ * header, so the header is not parsed a second time (BLO-36599).
373
+ *
374
+ * `header` must be `parseMMTPHeader(mmtpPacket)` of this same packet; the
375
+ * result is then identical to `extractMFUPayload(mmtpPacket, options)`.
376
+ */
377
+ export function extractMFUPayloadWithHeader(mmtpPacket, header, options) {
378
+ return extractPlannedMfu(mmtpPacket, planMfuExtraction(mmtpPacket, options, header));
379
+ }
380
+ function extractPlannedMfu(mmtpPacket, result) {
324
381
  if ('rejection' in result)
325
382
  return null;
326
383
  const { header, payload, mpu, fragmentType, layout, trailerLayout } = result.plan;
@@ -373,37 +430,59 @@ export function isFecRepairPacket(mmtpPacket) {
373
430
  * and ATSC A/331 §8.1.2.5 which defers to ISO 23008-1 Annex C.
374
431
  */
375
432
  export function extractFecPayloadId(mmtpPacket) {
376
- if (!hasSourceFecPayloadId(mmtpPacket))
377
- return null;
378
- // Flat 4-byte SS_ID: encoder writes block_id * K + symbol_id
379
- const off = mmtpPacket.length - SOURCE_FEC_PAYLOAD_ID_SIZE;
380
- const view = new DataView(mmtpPacket.buffer, mmtpPacket.byteOffset + off, SOURCE_FEC_PAYLOAD_ID_SIZE);
381
- return { ssId: view.getUint32(0, false) };
433
+ const header = parseHeaderForSourceFecId(mmtpPacket);
434
+ return header ? sourceFecPayloadIdOf(mmtpPacket, header) : null;
382
435
  }
383
436
  /**
384
437
  * Return true when FEC_type=1 and the exact suffix after the ISO-declared MPU
385
438
  * payload contains a four-byte Source FEC Payload ID.
386
439
  */
387
440
  export function hasSourceFecPayloadId(mmtpPacket) {
441
+ const header = parseHeaderForSourceFecId(mmtpPacket);
442
+ return header !== null && sourceFecPayloadIdOf(mmtpPacket, header) !== null;
443
+ }
444
+ function parseHeaderForSourceFecId(mmtpPacket) {
388
445
  if (mmtpPacket.length < MMTP_HEADER_SIZE + MPU_HEADER_SIZE)
389
- return false;
390
- let header;
446
+ return null;
391
447
  try {
392
- header = parseMMTPHeader(mmtpPacket);
448
+ return parseMMTPHeader(mmtpPacket);
393
449
  }
394
450
  catch {
395
- return false;
451
+ return null;
396
452
  }
453
+ }
454
+ /**
455
+ * The Source FEC Payload ID of a packet whose MMTP header the caller already
456
+ * parsed, or null when the packet carries none: present only when FEC_type=1
457
+ * and the exact suffix after the ISO-declared MPU payload holds the four-byte
458
+ * ID (ISO/IEC 23008-1 §C.5.2). Same answer as extractFecPayloadId, without a
459
+ * second header parse (BLO-36599).
460
+ *
461
+ * `header` must be `parseMMTPHeader(mmtpPacket)` of this same packet.
462
+ */
463
+ export function sourceFecPayloadIdOf(mmtpPacket, header) {
464
+ if (mmtpPacket.length < MMTP_HEADER_SIZE + MPU_HEADER_SIZE)
465
+ return null;
397
466
  if (header.packetType !== PACKET_TYPE_MPU)
398
- return false;
467
+ return null;
399
468
  const payload = mmtpPacket.subarray(header.headerLength);
400
469
  if (payload.length < MPU_HEADER_SIZE)
401
- return false;
402
- const mpu = parseMPUHeader(payload);
403
- if (mpu.payloadLength < MPU_HEADER_REMAINDER_SIZE)
404
- return false;
405
- const declaredEnd = MPU_LENGTH_FIELD_SIZE + mpu.payloadLength;
406
- return resolveDeclaredTrailers(payload, declaredEnd, header.fecType)?.hasFecId ?? false;
470
+ return null;
471
+ const payloadLength = (payload[0] << 8) | payload[1];
472
+ if (payloadLength < MPU_HEADER_REMAINDER_SIZE)
473
+ return null;
474
+ const declaredEnd = MPU_LENGTH_FIELD_SIZE + payloadLength;
475
+ if (!resolveDeclaredTrailers(payload, declaredEnd, header.fecType)?.hasFecId)
476
+ return null;
477
+ // Flat 4-byte SS_ID: encoder writes block_id * K + symbol_id
478
+ const off = mmtpPacket.length - SOURCE_FEC_PAYLOAD_ID_SIZE;
479
+ return {
480
+ ssId: ((mmtpPacket[off] << 24) |
481
+ (mmtpPacket[off + 1] << 16) |
482
+ (mmtpPacket[off + 2] << 8) |
483
+ mmtpPacket[off + 3]) >>>
484
+ 0,
485
+ };
407
486
  }
408
487
  /**
409
488
  * MMTP header-extension ext_type assigned to the detached ALTA authenticator
@@ -421,22 +500,34 @@ export const MMTP_EXT_TRAILER_HEADER_SIZE = _LEAF_MMTP_EXT_TRAILER_HEADER_SIZE;
421
500
  export const extractAltaTrailer = _leafExtractAltaTrailer;
422
501
  /** Size of Repair FEC Payload ID per ISO/IEC 23008-1 Section C.5.3 */
423
502
  export const REPAIR_FEC_PID_SIZE = 13;
424
- /** Parse the 13-byte Repair FEC Payload ID after the complete dynamic MMTP header. */
425
- function readRepairFecPayloadIdFields(mmtpPacket) {
503
+ /**
504
+ * Parse the 13-byte Repair FEC Payload ID after the complete dynamic MMTP header.
505
+ * `parsedHeader`, when given, must be `parseMMTPHeader(mmtpPacket)` of this
506
+ * same packet; it spares the second header parse (BLO-36599).
507
+ */
508
+ function readRepairFecPayloadIdFields(mmtpPacket, parsedHeader) {
426
509
  let header;
427
- try {
428
- header = parseMMTPHeader(mmtpPacket);
510
+ if (parsedHeader) {
511
+ header = parsedHeader;
429
512
  }
430
- catch {
431
- return null;
513
+ else {
514
+ try {
515
+ header = parseMMTPHeader(mmtpPacket);
516
+ }
517
+ catch {
518
+ return null;
519
+ }
432
520
  }
433
521
  if (header.packetType !== PACKET_TYPE_REPAIR || header.fecType !== 2)
434
522
  return null;
435
523
  const off = header.headerLength;
436
524
  if (mmtpPacket.length < off + REPAIR_FEC_PID_SIZE)
437
525
  return null;
438
- const view = new DataView(mmtpPacket.buffer, mmtpPacket.byteOffset + off, REPAIR_FEC_PID_SIZE);
439
- const ssStart = view.getUint32(0, false); // 32 bits
526
+ const ssStart = ((mmtpPacket[off] << 24) |
527
+ (mmtpPacket[off + 1] << 16) |
528
+ (mmtpPacket[off + 2] << 8) |
529
+ mmtpPacket[off + 3]) >>>
530
+ 0; // 32 bits
440
531
  const rsbLength = (mmtpPacket[off + 4] << 16) | (mmtpPacket[off + 5] << 8) | mmtpPacket[off + 6]; // 24 bits
441
532
  const rsId = (mmtpPacket[off + 7] << 16) | (mmtpPacket[off + 8] << 8) | mmtpPacket[off + 9]; // 24 bits
442
533
  const ssbLength = (mmtpPacket[off + 10] << 16) | (mmtpPacket[off + 11] << 8) | mmtpPacket[off + 12]; // 24 bits
@@ -484,7 +575,21 @@ export function extractRepairFecPayloadId(mmtpPacket) {
484
575
  * @returns Parsed frame or null if invalid
485
576
  */
486
577
  export function parseMoqRepairFrame(frame) {
487
- const repairId = readRepairFecPayloadIdFields(frame);
578
+ return moqRepairFrameFrom(frame, readRepairFecPayloadIdFields(frame));
579
+ }
580
+ /**
581
+ * parseMoqRepairFrame for a caller that already holds this frame's parsed MMTP
582
+ * header, so the header is not parsed a second time (BLO-36599). The router's
583
+ * multicast repair branch uses it: one repair packet in every K + P otherwise
584
+ * paid two header parses.
585
+ *
586
+ * `header` must be `parseMMTPHeader(frame)` of this same frame; the result is
587
+ * then identical to `parseMoqRepairFrame(frame)`.
588
+ */
589
+ export function parseMoqRepairFrameWithHeader(frame, header) {
590
+ return moqRepairFrameFrom(frame, readRepairFecPayloadIdFields(frame, header));
591
+ }
592
+ function moqRepairFrameFrom(frame, repairId) {
488
593
  if (!repairId)
489
594
  return null;
490
595
  const symbolData = frame.subarray(repairId.dataOffset);