@blockcast/fec-worker 0.3.0-main.d9354616fdf2 → 0.3.0-main.e4bf1a9cc227

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.
@@ -12,19 +12,16 @@
12
12
 
13
13
  /**
14
14
  * FEC block profile (BLO-35597, ISO/IEC 23008-1 Annex C): the catalog
15
- * `fec.blockProfile` token. Both profiles carry identical wire tuples whose
16
- * block math differs, so it is required and never inferred.
17
- *
18
- * - `k-padded-v1` (legacy): SBN = floor(SS_ID / K), ESI = SS_ID % K;
19
- * SS_Start = SBN * K; repair ESI = K + RS_ID.
20
- * - `iso-ssbg1-v1` (C.3.3 ssbg_mode1): SS_ID increments by one per source
21
- * packet mod 2^32; a block is `[SS_Start, SS_Start + SSB_length)` keyed by
22
- * SS_Start; `k` is only the maximum SSB_length; repair ESI =
23
- * SSB_length + RS_ID.
15
+ * `fec.blockProfile` token. Required and never inferred; the only profile is
16
+ * `iso-ssbg1-v1` (C.3.3 ssbg_mode1): SS_ID increments by one per source
17
+ * packet mod 2^32; a block is `[SS_Start, SS_Start + SSB_length)` keyed by
18
+ * SS_Start; `k` is only the maximum SSB_length; repair ESI =
19
+ * SSB_length + RS_ID. The retired `k-padded-v1` token is refused like any
20
+ * unknown one.
24
21
  *
25
22
  * Mirrors @blockcast/mmt-base `FecBlockProfile`.
26
23
  */
27
- export type FecBlockProfile = "k-padded-v1" | "iso-ssbg1-v1";
24
+ export type FecBlockProfile = "iso-ssbg1-v1";
28
25
 
29
26
  /** Per-track FEC configuration. Matches design spec section 3.2 FecTrackConfig. */
30
27
  export interface FecTrackConfig {
@@ -51,18 +48,25 @@ export interface FecTrackConfig {
51
48
  repairCount: number;
52
49
  /** Bytes per symbol */
53
50
  symbolSize: number;
54
- /** Retained decoder horizon as a BLOCK COUNT (SBN distance), not D.
55
- * `isRetiredSbn` retires blocks more than this many blocks behind
56
- * `liveSbn` (serial order on SS_ID, BLO-35597 iso:5) and
57
- * `MmtFecDecoder::new` documents it as "the number of interleaved blocks".
58
- * Under `iso-ssbg1-v1` the distance is `isoBlocksBehind(SS_ID, live SS_ID, k)`
59
- * (block-order.ts), the lower bound every ISO receiver layer shares.
51
+ /** Retained decoder horizon as a BLOCK COUNT, not D. `isRetiredSbn`
52
+ * retires blocks more than this many blocks behind the live SS_ID, by
53
+ * `isoBlocksBehind(SS_ID, live SS_ID, k)` (block-order.ts), the lower
54
+ * bound every ISO receiver layer shares, and `MmtFecDecoder::new`
55
+ * documents it as "the number of interleaved blocks".
60
56
  * Never assign `deriveFecInterleaveDepth()` here — that returns media units
61
57
  * per block, which is a different quantity (BLO-35597). */
62
58
  interleaveDepth: number;
63
- /** Interleave depth in milliseconds (D * frameDurationMs) */
59
+ /**
60
+ * Catalog interleave span in integer milliseconds. A positive value is the complete
61
+ * source-plus-repair span; zero represents an absent/zero catalog span and
62
+ * carries no elapsed-time deadline.
63
+ */
64
64
  interleaveMs: number;
65
- /** Catalog-derived source+repair delivery window used for decoder cleanup. */
65
+ /**
66
+ * Positive cleanup budget. For a positive `interleaveMs` this is the
67
+ * catalog span plus its explicit reorder allowance. For zero it is a
68
+ * receiver-local bound only, never an inferred catalog deadline.
69
+ */
66
70
  deliveryWindowMs: number;
67
71
  /** FEC encoding mode */
68
72
  fecMode: "subframe" | "object";
@@ -79,8 +83,7 @@ export interface FecTrackConfig {
79
83
 
80
84
  /** Per-block snapshot for live block visualization and stats. */
81
85
  export interface FecBlockSnapshot {
82
- /** Block key: the source block number under `k-padded-v1`, the block's
83
- * SS_Start under `iso-ssbg1-v1`. */
86
+ /** Block key: the block's SS_Start. */
84
87
  sbn: number;
85
88
  /** Current block state */
86
89
  state: "collecting" | "complete" | "recovered" | "failed";
@@ -103,7 +106,10 @@ export interface FecBlockSnapshot {
103
106
  lastSymbolTs: number;
104
107
  /** Timestamp when block completed (ms), undefined if not yet complete */
105
108
  completedTs?: number;
106
- /** Deadline timestamp for block completion (ms) */
109
+ /**
110
+ * Cleanup timestamp (ms). It is the catalog completion deadline when
111
+ * `config.interleaveMs > 0`, and a local retention timestamp otherwise.
112
+ */
107
113
  deadlineTs: number;
108
114
  /** Count of source symbols with valid ALTA signature (AUTH-02) */
109
115
  altaVerified: number;
@@ -168,8 +174,7 @@ export interface FecTrackStats {
168
174
  /** Blocks with invalid relay signature */
169
175
  relayBlocksFailed: number;
170
176
 
171
- /** Live media position: the newest source block number under
172
- * `k-padded-v1`, the newest accepted SS_ID / SS_Start under `iso-ssbg1-v1`. */
177
+ /** Live media position: the newest accepted SS_ID / SS_Start. */
173
178
  liveSbn: number;
174
179
  /** Active block snapshots */
175
180
  blocks: FecBlockSnapshot[];
@@ -220,13 +225,14 @@ export interface FecTrackStats {
220
225
  */
221
226
  sourceDroppedDuplicate?: number;
222
227
  /**
223
- * `iso-ssbg1-v1` only: accepted source symbols whose block never became
224
- * known (no repair symbol named a range containing them) before their
225
- * SS_ID fell behind the retained horizon. They were already fed to the
226
- * decoder and routed directly; this counts the bookkeeping retired with
227
- * them, i.e. evidence that a block's repair symbols never arrived.
228
+ * Accepted source symbols whose block never became known (no repair
229
+ * symbol named a range containing them) before their SS_ID fell behind
230
+ * the retained horizon. They were already fed to the decoder and routed
231
+ * directly; this counts the bookkeeping retired with them, i.e. evidence
232
+ * that a block's repair symbols never arrived. The decoder retires its
233
+ * own copies by the same horizon inside `cleanup_by_ss_start`.
228
234
  */
229
- sourceUnplacedRetired?: number;
235
+ sourceUnplacedRetired: number;
230
236
  /** Native decoder counters, converted to numbers so browser diagnostics remain JSON-safe. */
231
237
  decoder?: {
232
238
  sourcePackets: number;
@@ -266,7 +272,7 @@ export interface FrameMeta {
266
272
  altaVerified: boolean | null;
267
273
  /** Whether this frame was recovered via FEC (not received directly) */
268
274
  recovered: boolean;
269
- /** Block key this frame belongs to: SBN (`k-padded-v1`) or SS_Start (`iso-ssbg1-v1`) */
275
+ /** Block key this frame belongs to: the block's SS_Start */
270
276
  sbn: number;
271
277
  /** Encoding Symbol ID within the recovered source block (0..ssbLength-1).
272
278
  * Under `iso-ssbg1-v1` a recovered frame is the full T-byte ssbg_mode1
@@ -301,13 +307,12 @@ export type FecWorkerCommand =
301
307
  | {
302
308
  type: "feedSource";
303
309
  /** Flat 32-bit Source Symbol ID from the MMTP Source FEC Payload ID
304
- * (ISO 23008-1 §C.5.2). Under `k-padded-v1` the WASM decoder derives
305
- * SBN = floor(ssId/K) and ESI = ssId % K internally — do NOT
306
- * pre-compute. Under `iso-ssbg1-v1` SS_IDs are consecutive per source
307
- * packet mod 2^32 and the block comes from a repair's range. */
310
+ * (ISO 23008-1 §C.5.2). SS_IDs are consecutive per source packet mod
311
+ * 2^32 and the block comes from a repair's range — do NOT
312
+ * pre-compute a block. */
308
313
  ssId: number;
309
- /** `k-padded-v1`: the source symbol. `iso-ssbg1-v1`: the protected
310
- * packet exactly, unpadded and without its SS_ID (at most T-2 bytes). */
314
+ /** The protected packet exactly, unpadded and without its SS_ID (at
315
+ * most T-2 bytes). */
311
316
  data: ArrayBuffer;
312
317
  ts: number;
313
318
  /** Optional ALTA authenticator bytes (detached mode — 08-07 MMTP
@@ -326,14 +331,13 @@ export type FecWorkerCommand =
326
331
  | {
327
332
  type: "feedRepair";
328
333
  /** SS_Start: SS_ID of the first source symbol in the block, from the
329
- * MMTP Repair FEC Payload ID (ISO 23008-1 §C.5.3). `k-padded-v1`:
330
- * = SBN * configured K. `iso-ssbg1-v1`: any uint32; the block key. */
334
+ * MMTP Repair FEC Payload ID (ISO 23008-1 §C.5.3): any uint32; the
335
+ * block key. */
331
336
  ssStart: number;
332
337
  /** Authored source-symbol count for this block; 1..configured K. */
333
338
  ssbLength: number;
334
339
  /** RS_ID: repair symbol index within the block; WASM maps to repair
335
- * ESI = configured K + RS_ID (`k-padded-v1`) or SSB_length + RS_ID
336
- * (`iso-ssbg1-v1`). */
340
+ * ESI = SSB_length + RS_ID. */
337
341
  rsId: number;
338
342
  data: ArrayBuffer;
339
343
  ts: number;
@@ -358,7 +362,7 @@ export type FecWorkerCommand =
358
362
  | {
359
363
  type: "cleanup";
360
364
  /** Every timed-out block covered by this coalesced queue-drain barrier,
361
- * by block key: SBN (`k-padded-v1`) or SS_Start (`iso-ssbg1-v1`). */
365
+ * by block key (SS_Start). */
362
366
  sbns: number[];
363
367
  }
364
368
  | { type: "reset" }
package/src/fec-worker.ts CHANGED
@@ -22,8 +22,6 @@ import type {
22
22
  } from "./fec-worker-types.js";
23
23
  import { toOwnedArrayBuffer } from "./transfer.js";
24
24
  import {
25
- blockPrecedes,
26
- blocksBehind,
27
25
  isoBlockContains,
28
26
  isoBlocksBehind,
29
27
  isoBlocksOverlap,
@@ -36,10 +34,9 @@ import {
36
34
  // The decoder derives SBN/ESI internally — do not pre-compute.
37
35
  interface WasmFecDecoder {
38
36
  /**
39
- * ISO 23008-1 §C.5.2: ss_id is the flat 32-bit Source Symbol ID.
40
- * `k-padded-v1`: data is the source symbol. `iso-ssbg1-v1`: data is the
41
- * protected packet, unpadded; the decoder builds the ssbg_mode1 symbol and
42
- * holds it until a repair names the block containing it.
37
+ * ISO 23008-1 §C.5.2: ss_id is the flat 32-bit Source Symbol ID; data is
38
+ * the protected packet, unpadded. The decoder builds the ssbg_mode1 symbol
39
+ * and holds it until a repair names the block containing it.
43
40
  */
44
41
  add_source(
45
42
  ss_id: number,
@@ -47,11 +44,9 @@ interface WasmFecDecoder {
47
44
  timestamp: number,
48
45
  ): Uint8Array | undefined;
49
46
  /**
50
- * ISO 23008-1 §C.5.3. `k-padded-v1`: repair ESI = configured K + rs_id,
51
- * SBN = ss_start / configured K. `iso-ssbg1-v1`: the block is
52
- * `[ss_start, ss_start + ssb_length)` with K' = ssb_length and repair
53
- * ESI = ssb_length + rs_id; a recovered block is ssb_length x T bytes of
54
- * ssbg_mode1 symbols.
47
+ * ISO 23008-1 §C.5.3: the block is `[ss_start, ss_start + ssb_length)`
48
+ * with K' = ssb_length and repair ESI = ssb_length + rs_id; a recovered
49
+ * block is ssb_length x T bytes of ssbg_mode1 symbols.
55
50
  */
56
51
  add_repair(
57
52
  ss_start: number,
@@ -68,14 +63,12 @@ interface WasmFecDecoder {
68
63
  */
69
64
  cleanup_blocks_detailed(sbns: Uint32Array): void;
70
65
  /**
71
- * `k-padded-v1` only (throws under `iso-ssbg1-v1`): remove decoder blocks
72
- * below its configured live-SBN interleave horizon; returns their SBNs.
73
- */
74
- cleanup_by_sbn(current_sbn: number): Uint32Array;
75
- /**
76
- * `iso-ssbg1-v1` only: remove decoder blocks, and held unplaced sources,
77
- * more than interleaveDepth `isoBlocksBehind` the live SS_ID; returns the
78
- * SS_Starts of the blocks it removed.
66
+ * Remove decoder blocks, and held unplaced sources, more than
67
+ * interleaveDepth `isoBlocksBehind` the live SS_ID; returns the SS_Starts
68
+ * of the blocks it removed. It runs the decoder's `retire_unplaced` sweep
69
+ * itself, so the Worker never calls that separately: synchronizeDecoderHorizon
70
+ * calls this after every source and repair it accepts, which is what keeps
71
+ * the decoder's unplaced pool bounded when a block's repairs never arrive.
79
72
  */
80
73
  cleanup_by_ss_start(current: number): Uint32Array;
81
74
  /** The block profile the decoder was constructed with. */
@@ -255,15 +248,9 @@ function clearBlockTracking(): void {
255
248
  */
256
249
  function isRetiredSbn(sbn: number): boolean {
257
250
  if (config === null || !liveSbnKnown) return false;
258
- // iso-ssbg1-v1: `sbn` is an SS_ID (a block's SS_Start or a source's own
259
- // SS_ID) and liveSbn the live SS_ID; K is only the maximum block length.
260
- return config.blockProfile === "iso-ssbg1-v1"
261
- ? isoBlocksBehind(sbn, liveSbn, config.k) > config.interleaveDepth
262
- : blocksBehind(sbn, liveSbn, config.k) > config.interleaveDepth;
263
- }
264
-
265
- function isIsoProfile(): boolean {
266
- return config?.blockProfile === "iso-ssbg1-v1";
251
+ // `sbn` is an SS_ID (a block's SS_Start or a source's own SS_ID) and
252
+ // liveSbn the live SS_ID; K is only the maximum block length.
253
+ return isoBlocksBehind(sbn, liveSbn, config.k) > config.interleaveDepth;
267
254
  }
268
255
 
269
256
  /**
@@ -291,9 +278,7 @@ function findIsoBlock(ssId: number): FecBlockSnapshot | undefined {
291
278
  * retired, after which the SS_ID retirement check refuses every member.
292
279
  */
293
280
  function isRetiredBlock(key: number, block: FecBlockSnapshot): boolean {
294
- return isIsoProfile()
295
- ? isRetiredSbn((key + isoKnownLength(block) - 1) % SS_ID_SPAN)
296
- : isRetiredSbn(key);
281
+ return isRetiredSbn((key + isoKnownLength(block) - 1) % SS_ID_SPAN);
297
282
  }
298
283
 
299
284
  /**
@@ -310,15 +295,10 @@ function trimBlockRetention(): void {
310
295
  }
311
296
  }
312
297
 
313
- /** Advance the live position: an SBN (k-padded-v1) or an SS_ID / SS_Start (iso-ssbg1-v1). */
298
+ /** Advance the live position: an SS_ID / SS_Start, in serial order. */
314
299
  function advanceMediaHorizon(sbn: number): void {
315
300
  if (!config) return;
316
- if (liveSbnKnown) {
317
- const ahead = config.blockProfile === "iso-ssbg1-v1"
318
- ? serialPrecedes(liveSbn, sbn)
319
- : blockPrecedes(liveSbn, sbn, config.k);
320
- if (!ahead) return;
321
- }
301
+ if (liveSbnKnown && !serialPrecedes(liveSbn, sbn)) return;
322
302
  liveSbn = sbn;
323
303
  liveSbnKnown = true;
324
304
  trimBlockRetention();
@@ -336,10 +316,7 @@ function markBlockTerminal(
336
316
 
337
317
  function synchronizeDecoderHorizon(): void {
338
318
  if (!wasmDecoder || !liveSbnKnown) return;
339
- const iso = isIsoProfile();
340
- const expired = iso
341
- ? wasmDecoder.cleanup_by_ss_start(liveSbn)
342
- : wasmDecoder.cleanup_by_sbn(liveSbn);
319
+ const expired = wasmDecoder.cleanup_by_ss_start(liveSbn);
343
320
  for (const sbn of expired) {
344
321
  const block = blocks.get(sbn);
345
322
  if (!block || isTerminalBlock(block)) {
@@ -350,7 +327,7 @@ function synchronizeDecoderHorizon(): void {
350
327
  blocksFailed++;
351
328
  emitBlockUpdate(block);
352
329
  }
353
- if (iso) retireUnplacedSources();
330
+ retireUnplacedSources();
354
331
  trimBlockRetention();
355
332
  }
356
333
 
@@ -548,6 +525,8 @@ function getOrCreateBlock(sbn: number, isoSsbLength?: number): FecBlockSnapshot
548
525
  repairCount: config.repairCount,
549
526
  firstSymbolTs: now,
550
527
  lastSymbolTs: now,
528
+ // A positive interleaveMs makes this the catalog completion deadline;
529
+ // zero makes deliveryWindowMs a receiver-local cleanup bound.
551
530
  deadlineTs: now + config.deliveryWindowMs,
552
531
  altaVerified: 0,
553
532
  relayBlockSigValid: null,
@@ -583,8 +562,10 @@ function buildStatsSnapshot(): FecTrackStats {
583
562
 
584
563
  // Cap block array to interleave window
585
564
  const maxBlocks = Math.max(config.interleaveDepth * 3, 24);
565
+ // Newest first in SS_ID serial order, so the cap keeps the newest blocks
566
+ // across the 2^32 wrap too: every block start precedes the live SS_ID.
586
567
  const blockArray = Array.from(blocks.values())
587
- .sort((a, b) => b.sbn - a.sbn)
568
+ .sort((a, b) => serialDistance(a.sbn, liveSbn) - serialDistance(b.sbn, liveSbn))
588
569
  .slice(0, maxBlocks);
589
570
 
590
571
  return {
@@ -620,7 +601,7 @@ function buildStatsSnapshot(): FecTrackStats {
620
601
  sourceDroppedRetired,
621
602
  sourceDroppedTerminal,
622
603
  sourceDroppedDuplicate,
623
- ...(config.blockProfile === "iso-ssbg1-v1" ? { sourceUnplacedRetired } : {}),
604
+ sourceUnplacedRetired,
624
605
  decoder,
625
606
  };
626
607
  }
@@ -662,22 +643,19 @@ function emitRecoveredSymbols(
662
643
  return;
663
644
  }
664
645
 
665
- const iso = config.blockProfile === "iso-ssbg1-v1";
666
646
  for (let i = 0; i < ssbLength; i++) {
667
647
  const symbol = recoveredBlock.subarray(i * symbolSize, (i + 1) * symbolSize);
668
648
  // ssbg_mode1 symbols are emitted whole: the router trims them by their
669
649
  // length field. A field past T-2 or non-zero padding means the
670
650
  // recovered symbol is not what was sent, so it is refused, not trimmed.
671
- if (iso) {
672
- const invalid = invalidSsbg1Symbol(symbol, symbolSize);
673
- if (invalid !== null) {
674
- emit({
675
- type: "error",
676
- code: "recovered-ssbg1-symbol-invalid",
677
- message: `[FecWorker] Dropping recovered ssbg_mode1 symbol (ssStart=${sbn}, esi=${i}, SSB_length=${ssbLength}): ${invalid}`,
678
- });
679
- continue;
680
- }
651
+ const invalid = invalidSsbg1Symbol(symbol, symbolSize);
652
+ if (invalid !== null) {
653
+ emit({
654
+ type: "error",
655
+ code: "recovered-ssbg1-symbol-invalid",
656
+ message: `[FecWorker] Dropping recovered ssbg_mode1 symbol (ssStart=${sbn}, esi=${i}, SSB_length=${ssbLength}): ${invalid}`,
657
+ });
658
+ continue;
681
659
  }
682
660
 
683
661
  // Source authentication now runs once at router admission in
@@ -990,12 +968,12 @@ async function handleConfigure(
990
968
  const blockProfile: unknown = cmd.config.blockProfile;
991
969
  if (blockProfile === undefined) {
992
970
  throw new Error(
993
- '[FecWorker] configure: blockProfile is required: name the FEC block profile ("k-padded-v1" or "iso-ssbg1-v1")',
971
+ '[FecWorker] configure: blockProfile is required: name the FEC block profile ("iso-ssbg1-v1")',
994
972
  );
995
973
  }
996
- if (blockProfile !== "k-padded-v1" && blockProfile !== "iso-ssbg1-v1") {
974
+ if (blockProfile !== "iso-ssbg1-v1") {
997
975
  throw new Error(
998
- `[FecWorker] configure: blockProfile must be "k-padded-v1" or "iso-ssbg1-v1" (got ${JSON.stringify(blockProfile)})`,
976
+ `[FecWorker] configure: blockProfile must be "iso-ssbg1-v1" (got ${JSON.stringify(blockProfile)})`,
999
977
  );
1000
978
  }
1001
979
  if (
@@ -1010,10 +988,11 @@ async function handleConfigure(
1010
988
  }
1011
989
  if (
1012
990
  !Number.isFinite(cmd.config.interleaveMs) ||
1013
- cmd.config.interleaveMs <= 0
991
+ !Number.isSafeInteger(cmd.config.interleaveMs) ||
992
+ cmd.config.interleaveMs < 0
1014
993
  ) {
1015
994
  throw new Error(
1016
- `[FecWorker] configure: interleaveMs must be finite and > 0 (got ${cmd.config.interleaveMs})`,
995
+ `[FecWorker] configure: interleaveMs must be a finite non-negative integer (got ${cmd.config.interleaveMs})`,
1017
996
  );
1018
997
  }
1019
998
  if (
@@ -1071,9 +1050,13 @@ async function handleConfigure(
1071
1050
  // Cap: 1.5× interleave depth — wide enough to hold one full FEC recovery
1072
1051
  // window plus jitter, narrow enough to bound memory.
1073
1052
  pendingVerifyCap = Math.ceil(config.interleaveDepth * 1.5);
1074
- // TTL: 1.5× block duration (K symbols at one per interleave tick) —
1075
- // after this many ms, any unresolved entry has missed its FEC window.
1076
- pendingVerifyTtlMs = Math.ceil(config.interleaveMs * config.k * 1.5);
1053
+ // TTL: preserve the existing 1.5× K-tick lifetime when a positive span is
1054
+ // signaled. A zero span has no media cadence, so use the supplied local
1055
+ // cleanup budget rather than manufacturing one from an inferred frame rate.
1056
+ const verifyWindowMs = config.interleaveMs > 0
1057
+ ? config.interleaveMs * config.k
1058
+ : config.deliveryWindowMs;
1059
+ pendingVerifyTtlMs = Math.ceil(verifyWindowMs * 1.5);
1077
1060
 
1078
1061
  // Initialize ALTA WASM verifier if public key and WASM module provided (D-05, D-09)
1079
1062
  altaVerifier = null;
@@ -1134,51 +1117,7 @@ function handleFeedSource(
1134
1117
  throw new Error("[FecWorker] feedSource: invalid source symbol");
1135
1118
  }
1136
1119
 
1137
- const view = new Uint8Array(cmd.data);
1138
- if (config.blockProfile === "iso-ssbg1-v1") {
1139
- feedIsoSource(cmd, view, wasmDecoder, config);
1140
- return;
1141
- }
1142
-
1143
- // Derive SBN locally for block-level accounting. WASM derives the same
1144
- // value internally (ISO 23008-1 §C.5.2: SBN = floor(SS_ID / K)).
1145
- const sbn = config.k > 0 ? Math.floor(cmd.ssId / config.k) : cmd.ssId;
1146
- const esi = cmd.ssId % config.k;
1147
- if (isRetiredSbn(sbn)) {
1148
- sourceDroppedRetired++;
1149
- return;
1150
- }
1151
- const existingBlock = blocks.get(sbn);
1152
- if (existingBlock && isTerminalBlock(existingBlock)) {
1153
- sourceDroppedTerminal++;
1154
- return;
1155
- }
1156
- if (acceptedSourceEsis.get(sbn)?.has(esi)) {
1157
- sourceDroppedDuplicate++;
1158
- return;
1159
- }
1160
-
1161
- const result = wasmDecoder.add_source(cmd.ssId, view, cmd.ts);
1162
- advanceMediaHorizon(sbn);
1163
- let sourceEsis = acceptedSourceEsis.get(sbn);
1164
- if (!sourceEsis) {
1165
- sourceEsis = new Set<number>();
1166
- acceptedSourceEsis.set(sbn, sourceEsis);
1167
- }
1168
- sourceEsis.add(esi);
1169
-
1170
- // Update block state
1171
- const block = getOrCreateBlock(sbn);
1172
- block.sourceReceived++;
1173
- block.lastSymbolTs = performance.now();
1174
- sourceSymbols++;
1175
-
1176
- // The FEC worker must remain decode-only on the per-symbol hot path. ALTA
1177
- // WASM is retained temporarily for low-rate signaling users, but media is
1178
- // authenticated by the canonical manifest verifier at router admission.
1179
- if (altaEnabled) altaPending++;
1180
-
1181
- settleSourceArrival(sbn, block, result);
1120
+ feedIsoSource(cmd, new Uint8Array(cmd.data), wasmDecoder, config);
1182
1121
  }
1183
1122
 
1184
1123
  function handleFeedRepair(
@@ -1190,17 +1129,14 @@ function handleFeedRepair(
1190
1129
  if (!config) {
1191
1130
  throw new Error("[FecWorker] feedRepair: config missing");
1192
1131
  }
1193
- // k-padded-v1 blocks start at multiples of K and repair ESI = K + RS_ID;
1194
1132
  // iso-ssbg1-v1 blocks start at any SS_ID and repair ESI = SSB_length + RS_ID.
1195
- const iso = config.blockProfile === "iso-ssbg1-v1";
1196
1133
  if (
1197
1134
  !isUint32(cmd.ssStart) ||
1198
1135
  !isUint32(cmd.ssbLength) ||
1199
1136
  cmd.ssbLength <= 0 ||
1200
1137
  cmd.ssbLength > config.k ||
1201
- (!iso && cmd.ssStart % config.k !== 0) ||
1202
1138
  !isUint32(cmd.rsId) ||
1203
- (iso ? cmd.ssbLength : config.k) + cmd.rsId > UINT24_MAX ||
1139
+ cmd.ssbLength + cmd.rsId > UINT24_MAX ||
1204
1140
  !(cmd.data instanceof ArrayBuffer)
1205
1141
  ) {
1206
1142
  throw new Error("[FecWorker] feedRepair: invalid repair symbol");
@@ -1218,51 +1154,7 @@ function handleFeedRepair(
1218
1154
  }
1219
1155
  return;
1220
1156
  }
1221
- if (iso) {
1222
- feedIsoRepair(cmd, view, wasmDecoder);
1223
- return;
1224
- }
1225
- const sbn = Math.floor(cmd.ssStart / config.k);
1226
- const repairEsi = config.k + cmd.rsId;
1227
- // The repair path's mirror drops stay silent and uncounted: BLO-35597
1228
- // defect 2 is a source-symbol shortfall, so only the source side needed
1229
- // evidence. The asymmetry is deliberate, not an oversight — extend these
1230
- // the same way if a repair-side shortfall ever needs attributing.
1231
- if (isRetiredSbn(sbn)) return;
1232
- const existingBlock = blocks.get(sbn);
1233
- if (existingBlock && isTerminalBlock(existingBlock)) return;
1234
- if (acceptedRepairEsis.get(sbn)?.has(repairEsi)) return;
1235
- // One block has one authored SSB_length; a repair symbol naming another
1236
- // is dropped before it reaches the decoder (which rejects it too).
1237
- if (existingBlock?.ssbLength !== undefined && existingBlock.ssbLength !== cmd.ssbLength) {
1238
- emit({
1239
- type: "error",
1240
- code: "repair-ssb-length-conflict",
1241
- message: `[FecWorker] Dropping repair symbol whose SSB_length ${cmd.ssbLength} conflicts with ${existingBlock.ssbLength} (sbn=${sbn})`,
1242
- });
1243
- return;
1244
- }
1245
-
1246
- const result = wasmDecoder.add_repair(
1247
- cmd.ssStart,
1248
- cmd.ssbLength,
1249
- cmd.rsId,
1250
- view,
1251
- cmd.ts,
1252
- );
1253
- advanceMediaHorizon(sbn);
1254
- let repairEsis = acceptedRepairEsis.get(sbn);
1255
- if (!repairEsis) {
1256
- repairEsis = new Set<number>();
1257
- acceptedRepairEsis.set(sbn, repairEsis);
1258
- }
1259
- repairEsis.add(repairEsi);
1260
- const block = getOrCreateBlock(sbn);
1261
- block.ssbLength = cmd.ssbLength;
1262
- block.repairReceived++;
1263
- block.lastSymbolTs = performance.now();
1264
- repairSymbols++;
1265
- settleRepairArrival(sbn, block, cmd.ssbLength, result);
1157
+ feedIsoRepair(cmd, view, wasmDecoder);
1266
1158
  }
1267
1159
 
1268
1160
  function handleRelayBlockSig(
@@ -1315,10 +1207,9 @@ function handleCleanup(
1315
1207
  continue;
1316
1208
  }
1317
1209
  currentBlock ??= getOrCreateBlock(sbn);
1318
- // k-padded-v1 compares with K, unchanged. iso-ssbg1-v1 compares with
1319
- // the block's SSB_length; a key no repair declared has none, so a
1320
- // block the Worker never knew can only have failed.
1321
- const authoredLength = isIsoProfile() ? currentBlock.ssbLength : currentBlock.k;
1210
+ // Compare with the block's SSB_length; a key no repair declared has
1211
+ // none, so a block the Worker never knew can only have failed.
1212
+ const authoredLength = currentBlock.ssbLength;
1322
1213
  if (authoredLength !== undefined && currentBlock.sourceReceived >= authoredLength) {
1323
1214
  markBlockTerminal(currentBlock, "complete");
1324
1215
  blocksComplete++;