@blockcast/mmt-container 0.4.0 → 0.4.1-main.cbe342dbdd9c
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.
- package/README.md +36 -20
- package/dist/align.d.ts +24 -18
- package/dist/align.d.ts.map +1 -1
- package/dist/align.js +23 -4
- package/dist/align.js.map +2 -2
- package/dist/browser-runtime.js +1839 -692
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +76 -39
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +321 -205
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +12 -4
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +40 -17
- package/dist/catalog-fec-params.js.map +3 -3
- package/dist/catalog-network-source.d.ts +28 -7
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js +21 -1
- package/dist/catalog-network-source.js.map +2 -2
- package/dist/catalog-validator.d.ts +4 -3
- package/dist/catalog-validator.d.ts.map +1 -1
- package/dist/catalog-validator.js +0 -29
- package/dist/catalog-validator.js.map +3 -3
- package/dist/cmcd-producer.d.ts +8 -0
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +14 -0
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/delivery-catalog.js +98 -234
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.d.ts +121 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +421 -66
- package/dist/fec-manager.js.map +3 -3
- package/dist/fec-state.d.ts +2 -1
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +18 -3
- package/dist/fec-state.js.map +3 -3
- package/dist/fec-worker-setup.d.ts +10 -0
- package/dist/fec-worker-setup.d.ts.map +1 -1
- package/dist/fec-worker-setup.js +15 -4
- package/dist/fec-worker-setup.js.map +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +39 -1
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +109 -17
- package/dist/iso-block-locator.js.map +3 -3
- package/dist/manifest-auth-plan.d.ts +26 -25
- package/dist/manifest-auth-plan.d.ts.map +1 -1
- package/dist/manifest-auth-plan.js +331 -1171
- package/dist/manifest-auth-plan.js.map +4 -4
- package/dist/mfu-reassembler.js +21 -13
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +93 -22
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +1137 -317
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +93 -22
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-fec-session.d.ts +159 -0
- package/dist/mmtp-fec-session.d.ts.map +1 -0
- package/dist/mmtp-fec-session.js +531 -0
- package/dist/mmtp-fec-session.js.map +7 -0
- package/dist/mmtp-router.d.ts +39 -6
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +184 -27
- package/dist/mmtp-router.js.map +2 -2
- package/dist/multicast-auth-catalog.d.ts +86 -92
- package/dist/multicast-auth-catalog.d.ts.map +1 -1
- package/dist/multicast-auth-catalog.js +347 -132
- package/dist/multicast-auth-catalog.js.map +4 -4
- package/dist/multicast-input.d.ts +31 -8
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +299 -35
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +94 -5
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +877 -357
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +12 -2
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +108 -238
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +21 -13
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +4 -1
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +1086 -301
- package/dist/no-modules.js.map +4 -4
- package/dist/phase14-catalog-override.d.ts +1 -1
- package/dist/phase14-catalog-override.d.ts.map +1 -1
- package/dist/phase14-catalog-override.js +2 -2
- package/dist/phase14-catalog-override.js.map +2 -2
- package/dist/repair-fetch.d.ts +81 -6
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +156 -31
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layers.d.ts +2 -0
- package/dist/repair-layers.d.ts.map +1 -1
- package/dist/repair-layers.js +19 -2
- package/dist/repair-layers.js.map +2 -2
- package/dist/sample-combiner.d.ts +7 -1
- package/dist/sample-combiner.d.ts.map +1 -1
- package/dist/sample-combiner.js +14 -2
- package/dist/sample-combiner.js.map +2 -2
- package/dist/signaling.d.ts +2 -2
- package/dist/signaling.d.ts.map +1 -1
- package/dist/signaling.js +3 -3
- package/dist/signaling.js.map +2 -2
- package/dist/source-auth.js +2710 -7
- package/dist/source-auth.js.map +4 -4
- package/dist/switching-set-alignment.d.ts +1 -1
- package/dist/switching-set-alignment.js.map +1 -1
- package/dist/timestamp-codec.js +21 -13
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +1 -1
- package/dist/wasm-mmtp-container-parser.js +93 -22
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +6 -9
- package/schemas/catalog.schema.json +133 -38
- package/src/align.ts +52 -21
- package/src/carp-catalog.ts +188 -68
- package/src/catalog-fec-params.ts +28 -3
- package/src/catalog-network-source.ts +49 -7
- package/src/catalog-validator.ts +4 -11
- package/src/cmcd-producer.ts +17 -0
- package/src/fec-manager.ts +452 -63
- package/src/fec-state.ts +11 -4
- package/src/fec-worker-setup.ts +30 -2
- package/src/index.ts +27 -10
- package/src/iso-block-locator.ts +110 -7
- package/src/manifest-auth-plan.ts +39 -91
- package/src/mmtp-container-parser.ts +75 -7
- package/src/mmtp-fec-session.ts +533 -0
- package/src/mmtp-router.ts +166 -7
- package/src/multicast-auth-catalog.ts +131 -238
- package/src/multicast-input.ts +148 -124
- package/src/multicast-manager.ts +267 -21
- package/src/multicast-transport.ts +17 -3
- package/src/no-modules.ts +7 -1
- package/src/phase14-catalog-override.ts +3 -3
- package/src/repair-fetch.ts +283 -39
- package/src/repair-layers.ts +22 -2
- package/src/sample-combiner.ts +15 -2
- package/src/signaling.ts +2 -2
- package/src/switching-set-alignment.ts +1 -1
- package/test-vectors/align.json +108 -32
- package/test-vectors/bc-provenance-v2.json +1526 -0
- package/test-vectors/catalog/README.md +71 -4
- package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
- package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
- package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
- package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
- package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
- package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
- package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
- package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
- package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
- package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
- package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
- package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
- package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
- package/test-vectors/catalog/positive/fec-multicast.json +1 -1
- package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
- package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
- package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
- package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
- package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
- package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
- package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
- package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
- package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
- package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
- package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
- package/test-vectors/catalog/section-codes.json +31 -1
- package/test-vectors/catalog-multicast-auth-v1.json +38 -20
- package/test-vectors/catalog-validation.json +101 -5
- package/test-vectors/catalog-validator-public-api.mjs +14 -9
- package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
- package/dist/fec-codec.d.ts +0 -32
- package/dist/fec-codec.d.ts.map +0 -1
- package/dist/fec-codec.js +0 -47
- package/dist/fec-codec.js.map +0 -7
- package/src/fec-codec.ts +0 -61
package/src/fec-manager.ts
CHANGED
|
@@ -27,7 +27,12 @@ import {
|
|
|
27
27
|
ssbg1FitsSymbol,
|
|
28
28
|
type FecBlockProfile,
|
|
29
29
|
} from '@blockcast/mmt-base'
|
|
30
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
IsoBlockLocator,
|
|
32
|
+
type IsoBlockRange,
|
|
33
|
+
type IsoPlacedSource,
|
|
34
|
+
type IsoRepairPlacement,
|
|
35
|
+
} from './iso-block-locator.js'
|
|
31
36
|
import { MIN_INTERLEAVE_DEPTH_MS } from './fec-state.js'
|
|
32
37
|
import {
|
|
33
38
|
BlockClassifier,
|
|
@@ -54,6 +59,9 @@ import type {
|
|
|
54
59
|
// Constants
|
|
55
60
|
// ---------------------------------------------------------------------------
|
|
56
61
|
|
|
62
|
+
/** fec-01 4.5: a GF(2^8) reed-solomon block holds at most 255 symbols. */
|
|
63
|
+
const RS_MAX_BLOCK_SYMBOLS = 255
|
|
64
|
+
|
|
57
65
|
// MIN_INTERLEAVE_DEPTH_MS lives with the catalog FEC predicate that also
|
|
58
66
|
// needs it (fec-state.ts); re-exported here for existing importers.
|
|
59
67
|
export { MIN_INTERLEAVE_DEPTH_MS }
|
|
@@ -156,6 +164,25 @@ export interface IsoHeldSource {
|
|
|
156
164
|
readonly oversized: boolean
|
|
157
165
|
}
|
|
158
166
|
|
|
167
|
+
/**
|
|
168
|
+
* A lost SS_ID in an undelimited span (draft-ramadan-moq-fec §7.5): a repair
|
|
169
|
+
* stated a block past SS_IDs whose every repair symbol was lost and at least
|
|
170
|
+
* one source too. They wait as a pending hole `[holeStart, holeStart +
|
|
171
|
+
* holeLength)` for a range repair FETCH.
|
|
172
|
+
*/
|
|
173
|
+
export interface UndelimitedIsoLoss {
|
|
174
|
+
readonly packetId: number
|
|
175
|
+
readonly catalogTrackName: string | undefined
|
|
176
|
+
readonly holeStart: number
|
|
177
|
+
readonly holeLength: number
|
|
178
|
+
/** The highest SS_ID in the hole no source arrived for: the §7.5 x. */
|
|
179
|
+
readonly lostSsId: number
|
|
180
|
+
/** K: the catalog `sourceSymbols`, the largest SSB_length. */
|
|
181
|
+
readonly kMax: number
|
|
182
|
+
/** 32-bit SS_Start of the stated block that ends where the hole starts (S_prev). */
|
|
183
|
+
readonly previousBlockStart?: number
|
|
184
|
+
}
|
|
185
|
+
|
|
159
186
|
/**
|
|
160
187
|
* How the multicast leg hands its symbols to this manager.
|
|
161
188
|
*
|
|
@@ -224,6 +251,11 @@ export interface FECManagerConfig {
|
|
|
224
251
|
* is refused.
|
|
225
252
|
*/
|
|
226
253
|
blockProfile?: FecBlockProfile
|
|
254
|
+
/**
|
|
255
|
+
* The catalog `fec.algorithm` (`TrackFecParams.fecAlgorithm`). Defaults to
|
|
256
|
+
* RaptorQ. Reed-Solomon bounds every block to 255 symbols (fec-01 4.5).
|
|
257
|
+
*/
|
|
258
|
+
algorithm?: 'raptorq' | 'reed-solomon'
|
|
227
259
|
k?: number
|
|
228
260
|
/** Symbol size in bytes (T). NOT repair count. */
|
|
229
261
|
symbolSize?: number
|
|
@@ -241,10 +273,69 @@ export interface FECManagerConfig {
|
|
|
241
273
|
* block `unknown` (fail-closed: protected).
|
|
242
274
|
*/
|
|
243
275
|
geometry?: BlockClassifierGeometry
|
|
276
|
+
/**
|
|
277
|
+
* fec-01 6.3.9: the source track's base repair layers (catalog
|
|
278
|
+
* `TrackFecParams.repairLayers`). Layer i's held total is
|
|
279
|
+
* B_i = rsIdOffset + repairSymbols. Absent: no anchored check.
|
|
280
|
+
*/
|
|
281
|
+
repairLayers?: readonly FecRepairLayer[]
|
|
282
|
+
/** The base layers this receiver holds. Defaults to layer 0 alone. */
|
|
283
|
+
heldLayers?: readonly number[]
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** One base repair layer, as `assembleRepairLayers` resolves it. */
|
|
287
|
+
export interface FecRepairLayer {
|
|
288
|
+
layer: number
|
|
289
|
+
repairTrackName: string
|
|
290
|
+
rsIdOffset: number
|
|
291
|
+
repairSymbols: number
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Why a source track's FEC failed closed at runtime (fec-01 6.3.9): a repair
|
|
296
|
+
* packet stated an RSB_length below a held layer's total B_i on that layer's
|
|
297
|
+
* own repair track (`below_own_track_total`), or at or after the anchor, the
|
|
298
|
+
* earliest block in SS_Start serial order whose repair carried >= B_i
|
|
299
|
+
* (`below_anchored_total`). Repair for the track is refused from then on.
|
|
300
|
+
*/
|
|
301
|
+
export interface FecFailClosedReason {
|
|
302
|
+
code: 'below_own_track_total' | 'below_anchored_total'
|
|
303
|
+
layer: number
|
|
304
|
+
total: number
|
|
305
|
+
rsbLength: number
|
|
306
|
+
ssStart: number
|
|
307
|
+
anchor?: number
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** A {@link FecFailClosedReason} with the stream it closed, as reported to the fail-closed handler. */
|
|
311
|
+
export interface FecFailClosedEvent extends FecFailClosedReason {
|
|
312
|
+
packetId: number
|
|
313
|
+
catalogTrackName: string | undefined
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
interface HeldLayerState {
|
|
317
|
+
layer: number
|
|
318
|
+
repairTrackName: string
|
|
319
|
+
total: number
|
|
320
|
+
/** Earliest (serial order) block start whose repair carried >= total. */
|
|
321
|
+
anchor?: number
|
|
322
|
+
/** Latest (serial order) block start whose repair carried < total. */
|
|
323
|
+
latestBelow?: number
|
|
324
|
+
/** RSB_length that latestBelow's repair carried, for the fail-closed reason. */
|
|
325
|
+
latestBelowRsb?: number
|
|
326
|
+
/** Newest block start seen; anchor and latestBelow are retired behind it. */
|
|
327
|
+
newest?: number
|
|
328
|
+
/**
|
|
329
|
+
* The anchor fell behind the horizon, so no block that can still arrive
|
|
330
|
+
* precedes it: every later packet must carry >= total. Its serial is no
|
|
331
|
+
* longer compared, so SS_Start wrapping past it cannot misorder it.
|
|
332
|
+
*/
|
|
333
|
+
settled?: boolean
|
|
244
334
|
}
|
|
245
335
|
|
|
246
336
|
interface ResolvedFECTrackConfig {
|
|
247
337
|
blockProfile?: FecBlockProfile
|
|
338
|
+
algorithm?: 'raptorq' | 'reed-solomon'
|
|
248
339
|
k: number
|
|
249
340
|
symbolSize: number
|
|
250
341
|
interleaveDepthMs: number
|
|
@@ -253,6 +344,8 @@ interface ResolvedFECTrackConfig {
|
|
|
253
344
|
trackKind?: TrackKind
|
|
254
345
|
codec?: string
|
|
255
346
|
geometry?: BlockClassifierGeometry
|
|
347
|
+
repairLayers?: readonly FecRepairLayer[]
|
|
348
|
+
heldLayers?: readonly number[]
|
|
256
349
|
}
|
|
257
350
|
|
|
258
351
|
/** Which symbol path completed a short block. */
|
|
@@ -450,6 +543,11 @@ export class FECManager {
|
|
|
450
543
|
// RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
|
|
451
544
|
// symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
|
|
452
545
|
#blockRsbLengths = new Map<string, number>()
|
|
546
|
+
/** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
|
|
547
|
+
#heldLayerStates = new Map<string, HeldLayerState[]>()
|
|
548
|
+
/** Streams whose FEC failed closed at runtime (fec-01 6.3.9). */
|
|
549
|
+
#fecFailClosed = new Map<string, FecFailClosedReason>()
|
|
550
|
+
#onFecFailClosed: ((event: FecFailClosedEvent) => void) | null = null
|
|
453
551
|
// Blocks already recovered — prevents late source symbols from restarting timeouts.
|
|
454
552
|
// WASM removes blocks after recovery; late symbols create empty blocks returning null,
|
|
455
553
|
// which would falsely start new timeouts without this guard.
|
|
@@ -572,12 +670,17 @@ export class FECManager {
|
|
|
572
670
|
// per stream. Not only throws: the ordinary out-of-range case is detected by
|
|
573
671
|
// arithmetic and never throws at all.
|
|
574
672
|
#orderedHorizonWarnedFor = new Set<number>()
|
|
575
|
-
// Newest block start (SS_Start)
|
|
576
|
-
//
|
|
673
|
+
// Newest block start (SS_Start) any symbol carried per stream and when: the
|
|
674
|
+
// frontier isoSpanResolution reads.
|
|
577
675
|
#highestSbn = new Map<string, { sbn: number; atMs: number }>()
|
|
676
|
+
// The same from source symbols alone: the frontier a source is judged
|
|
677
|
+
// against for a discontinuity. Repairs ride their own group, which can run
|
|
678
|
+
// blocks ahead of the media they protect.
|
|
679
|
+
#sourceFrontiers = new Map<string, { sbn: number; atMs: number }>()
|
|
578
680
|
// iso-ssbg1-v1 block location per stream (streamKey). A source belongs to a
|
|
579
681
|
// block only once a repair symbol stated the block's (SS_Start, SSB_length).
|
|
580
682
|
#isoLocators = new Map<string, IsoBlockLocator<IsoHeldSource>>()
|
|
683
|
+
#deferIsoGaps = false
|
|
581
684
|
#isoRepairRefusedCount = 0
|
|
582
685
|
#isoSourceOversizeCount = 0
|
|
583
686
|
// Held sources a locator's capacity cap evicted (IsoBlockLocator.heldCapacity):
|
|
@@ -592,9 +695,9 @@ export class FECManager {
|
|
|
592
695
|
// rate-limited like the other per-symbol warns here. Cumulative.
|
|
593
696
|
#isoDecoderUnplacedRetireFailed = 0
|
|
594
697
|
// The latest source symbol per stream that carried its MMTP
|
|
595
|
-
// packet_sequence_number: the anchor that bounds how
|
|
596
|
-
// producer can have
|
|
597
|
-
#sourceAnchors = new Map<string, {
|
|
698
|
+
// packet_sequence_number, by its own SS_ID: the anchor that bounds how far
|
|
699
|
+
// the producer's SS_IDs can have moved before or after another source symbol.
|
|
700
|
+
#sourceAnchors = new Map<string, { ssId: number; psn: number; atMs: number }>()
|
|
598
701
|
// Catalog/reset epoch per packetId. Gap decisions carry it for fencing.
|
|
599
702
|
#packetEpochs = new Map<number, number>()
|
|
600
703
|
|
|
@@ -708,6 +811,14 @@ export class FECManager {
|
|
|
708
811
|
reason: ClassifierReason | null,
|
|
709
812
|
) => void)
|
|
710
813
|
| null = null
|
|
814
|
+
/**
|
|
815
|
+
* A repair stated a block past a gap that is missing a source and whose
|
|
816
|
+
* every repair was lost: a lost SS_ID in an undelimited span
|
|
817
|
+
* (draft-ramadan-moq-fec §7.5). Set with `setUndelimitedLossHandler`; the
|
|
818
|
+
* receiver keeps the gap as a pending hole until `closeIsoHoles` is called
|
|
819
|
+
* for it, which it must be.
|
|
820
|
+
*/
|
|
821
|
+
#onUndelimitedLoss: ((loss: UndelimitedIsoLoss) => void) | null = null
|
|
711
822
|
/** A block every symbol of which vanished was created by SBN evidence. */
|
|
712
823
|
onBlockVanished:
|
|
713
824
|
| ((sbn: number, packetId: number, catalogTrackName: string | undefined) => void)
|
|
@@ -1509,8 +1620,8 @@ export class FECManager {
|
|
|
1509
1620
|
// Deliberately one block tighter than deriveFecRetentionBlocks over the same
|
|
1510
1621
|
// inputs (that function's `+ 1`). Different question: the retention horizon
|
|
1511
1622
|
// asks how long the decoder still ACCEPTS symbols for a block, this asks how
|
|
1512
|
-
// many blocks a stream can
|
|
1513
|
-
//
|
|
1623
|
+
// many blocks a stream can jump ahead of its frontier before a source symbol
|
|
1624
|
+
// there is a discontinuity rather than loss (see #noteSbnSeen).
|
|
1514
1625
|
// The extra block of retention is slack for a block still being fed; a block
|
|
1515
1626
|
// nothing has been heard from does not get it. Not the units defect — but it
|
|
1516
1627
|
// is the next place the two can drift, so change both or neither.
|
|
@@ -1521,23 +1632,28 @@ export class FECManager {
|
|
|
1521
1632
|
|
|
1522
1633
|
/**
|
|
1523
1634
|
* Record that a symbol for block `sbn` (the block's SS_Start) arrived and
|
|
1524
|
-
* advance the stream's
|
|
1635
|
+
* advance the stream's frontiers, the newest block start seen.
|
|
1525
1636
|
*
|
|
1526
|
-
* A SOURCE symbol
|
|
1527
|
-
*
|
|
1528
|
-
*
|
|
1637
|
+
* A SOURCE symbol is judged against the newest source block alone: repairs
|
|
1638
|
+
* ride their own group, which can run blocks ahead of the media. One whose
|
|
1639
|
+
* block goes back further than the blocks this manager retains, or that
|
|
1640
|
+
* cannot have been sent before the source it lies behind, or that jumps
|
|
1641
|
+
* further than the stream could have produced since its last symbol, is a
|
|
1642
|
+
* source discontinuity, not loss. A repair symbol can only advance the
|
|
1529
1643
|
* frontier: a D-28 fetch legitimately answers for an old block, so it never
|
|
1530
1644
|
* signals a discontinuity.
|
|
1531
1645
|
*
|
|
1532
1646
|
* The producer closes a block at its Dth media-unit boundary OR when K
|
|
1533
1647
|
* source symbols filled it, so one interleave span can start several blocks
|
|
1534
|
-
* (every large keyframe does). What bounds a
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
1537
|
-
*
|
|
1538
|
-
* packet_sequence_number
|
|
1539
|
-
*
|
|
1540
|
-
*
|
|
1648
|
+
* (every large keyframe does). What bounds a jump is therefore packet
|
|
1649
|
+
* evidence, not a block rate: SS_ID advances by one per FEC source packet
|
|
1650
|
+
* (ISO/IEC 23008-1 C.5.2) and the MMTP packet_sequence_number by one per
|
|
1651
|
+
* packet of the packet_id, so with both source symbols'
|
|
1652
|
+
* packet_sequence_number their SS_IDs (`ssId`, not their block starts,
|
|
1653
|
+
* which a repair-less span can put far behind) can move at most the packets
|
|
1654
|
+
* sent between them, in either direction, plus K of slack for sources lost
|
|
1655
|
+
* before a hop that renumbers packets. Without it, only the D-close rate is
|
|
1656
|
+
* known.
|
|
1541
1657
|
*
|
|
1542
1658
|
* Vanished blocks are not enumerated here: their starts are unknown until a
|
|
1543
1659
|
* repair states them. The SS_IDs between two stated blocks become one
|
|
@@ -1549,10 +1665,11 @@ export class FECManager {
|
|
|
1549
1665
|
catalogTrackName: string | undefined,
|
|
1550
1666
|
symbol: 'source' | 'repair',
|
|
1551
1667
|
packetSequenceNumber?: number,
|
|
1668
|
+
ssId = sbn,
|
|
1552
1669
|
): void {
|
|
1553
1670
|
const streamKey = this.#streamKey(packetId, catalogTrackName)
|
|
1554
1671
|
const now = performance.now()
|
|
1555
|
-
const previous = this.#highestSbn.get(streamKey)
|
|
1672
|
+
const previous = (symbol === 'source' ? this.#sourceFrontiers : this.#highestSbn).get(streamKey)
|
|
1556
1673
|
const anchor = this.#sourceAnchors.get(streamKey)
|
|
1557
1674
|
const psn = symbol === 'source' &&
|
|
1558
1675
|
packetSequenceNumber !== undefined &&
|
|
@@ -1562,29 +1679,46 @@ export class FECManager {
|
|
|
1562
1679
|
? packetSequenceNumber
|
|
1563
1680
|
: undefined
|
|
1564
1681
|
const anchorHere = (): void => {
|
|
1565
|
-
if (psn !== undefined && (anchor === undefined || !
|
|
1566
|
-
this.#sourceAnchors.set(streamKey, {
|
|
1682
|
+
if (psn !== undefined && (anchor === undefined || !serial32Precedes(ssId, anchor.ssId))) {
|
|
1683
|
+
this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now })
|
|
1567
1684
|
}
|
|
1568
1685
|
}
|
|
1686
|
+
const advance = (): void => {
|
|
1687
|
+
const highest = this.#highestSbn.get(streamKey)
|
|
1688
|
+
if (highest === undefined || this.#blockPrecedes(highest.sbn, sbn)) {
|
|
1689
|
+
this.#highestSbn.set(streamKey, { sbn, atMs: now })
|
|
1690
|
+
}
|
|
1691
|
+
if (symbol === 'source') this.#sourceFrontiers.set(streamKey, { sbn, atMs: now })
|
|
1692
|
+
anchorHere()
|
|
1693
|
+
}
|
|
1569
1694
|
const discontinuity = (): void => {
|
|
1570
1695
|
// The classifier compares authored order with SBN order only within
|
|
1571
1696
|
// one continuous SBN sequence.
|
|
1572
1697
|
this.#classifiers.get(streamKey)?.noteSourceDiscontinuity()
|
|
1573
1698
|
this.#highestSbn.set(streamKey, { sbn, atMs: now })
|
|
1699
|
+
this.#sourceFrontiers.set(streamKey, { sbn, atMs: now })
|
|
1574
1700
|
if (psn === undefined) this.#sourceAnchors.delete(streamKey)
|
|
1575
|
-
else this.#sourceAnchors.set(streamKey, {
|
|
1701
|
+
else this.#sourceAnchors.set(streamKey, { ssId, psn, atMs: now })
|
|
1576
1702
|
this.onSourceDiscontinuity?.(packetId, catalogTrackName)
|
|
1577
1703
|
}
|
|
1578
1704
|
if (previous === undefined) {
|
|
1579
|
-
|
|
1580
|
-
anchorHere()
|
|
1705
|
+
advance()
|
|
1581
1706
|
return
|
|
1582
1707
|
}
|
|
1583
1708
|
const config = this.#trackConfig(packetId)
|
|
1584
1709
|
const window = this.#liveWindowBlocks(config)
|
|
1710
|
+
// Packets sent from `from` to `to`, serial arithmetic (RFC 1982): more
|
|
1711
|
+
// than half the space means it went backwards.
|
|
1712
|
+
const sentInOrder = (from: { ssId: number; psn: number }, to: { ssId: number; psn: number }): boolean => {
|
|
1713
|
+
const sent = (to.psn - from.psn) >>> 0
|
|
1714
|
+
return sent <= 0x7fff_ffff && serial32Distance(from.ssId, to.ssId) <= sent + config.k
|
|
1715
|
+
}
|
|
1585
1716
|
if (!this.#blockPrecedes(previous.sbn, sbn)) {
|
|
1586
|
-
if (symbol === 'source' && window !== null &&
|
|
1587
|
-
|
|
1717
|
+
if (symbol === 'source' && window !== null && this.#blockPrecedes(sbn, previous.sbn) && (
|
|
1718
|
+
this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId) ||
|
|
1719
|
+
(psn !== undefined && anchor !== undefined && serial32Precedes(ssId, anchor.ssId) &&
|
|
1720
|
+
psn !== anchor.psn && !sentInOrder({ ssId, psn }, anchor))
|
|
1721
|
+
)) {
|
|
1588
1722
|
discontinuity()
|
|
1589
1723
|
return
|
|
1590
1724
|
}
|
|
@@ -1598,15 +1732,8 @@ export class FECManager {
|
|
|
1598
1732
|
// producer that does not maintain it); only then is the D-close rate
|
|
1599
1733
|
// the whole bound.
|
|
1600
1734
|
if (psn !== undefined && anchor !== undefined &&
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
// plus the anchor's own offset into its block (< K). Packets sent
|
|
1604
|
-
// from the anchor packet to this one, serial arithmetic (RFC 1982):
|
|
1605
|
-
// more than half the space means it went backwards.
|
|
1606
|
-
const sent = (psn - anchor.psn) >>> 0
|
|
1607
|
-
plausible =
|
|
1608
|
-
sent <= 0x7fff_ffff &&
|
|
1609
|
-
serial32Distance(anchor.sbn, sbn) <= sent + config.k
|
|
1735
|
+
serial32Precedes(anchor.ssId, ssId) && psn !== anchor.psn) {
|
|
1736
|
+
plausible = sentInOrder(anchor, { ssId, psn })
|
|
1610
1737
|
} else {
|
|
1611
1738
|
plausible = missing <= window + Math.ceil((now - previous.atMs) / config.interleaveDepthMs)
|
|
1612
1739
|
}
|
|
@@ -1616,8 +1743,7 @@ export class FECManager {
|
|
|
1616
1743
|
discontinuity()
|
|
1617
1744
|
return
|
|
1618
1745
|
}
|
|
1619
|
-
|
|
1620
|
-
anchorHere()
|
|
1746
|
+
advance()
|
|
1621
1747
|
}
|
|
1622
1748
|
|
|
1623
1749
|
/*
|
|
@@ -2054,8 +2180,10 @@ export class FECManager {
|
|
|
2054
2180
|
)
|
|
2055
2181
|
}
|
|
2056
2182
|
const hasCatalogTiming = FECManager.#hasCatalogTiming({ interleaveDepthMs: ownInterleaveDepthMs })
|
|
2183
|
+
const algorithm = config.algorithm ?? previous.algorithm
|
|
2057
2184
|
const next: ResolvedFECTrackConfig = {
|
|
2058
2185
|
blockProfile,
|
|
2186
|
+
...(algorithm === undefined ? {} : { algorithm }),
|
|
2059
2187
|
k,
|
|
2060
2188
|
symbolSize:
|
|
2061
2189
|
config.symbolSize != null && config.symbolSize > 0
|
|
@@ -2073,6 +2201,23 @@ export class FECManager {
|
|
|
2073
2201
|
...((config.geometry ?? previous.geometry) === undefined
|
|
2074
2202
|
? {}
|
|
2075
2203
|
: { geometry: config.geometry ?? previous.geometry }),
|
|
2204
|
+
...((config.repairLayers ?? previous.repairLayers) === undefined
|
|
2205
|
+
? {}
|
|
2206
|
+
: { repairLayers: config.repairLayers ?? previous.repairLayers }),
|
|
2207
|
+
...((config.heldLayers ?? previous.heldLayers) === undefined
|
|
2208
|
+
? {}
|
|
2209
|
+
: { heldLayers: config.heldLayers ?? previous.heldLayers }),
|
|
2210
|
+
}
|
|
2211
|
+
if (
|
|
2212
|
+
// By content: a catalog refresh rebuilds equal arrays, and forgetting
|
|
2213
|
+
// the anchors on one would fail open.
|
|
2214
|
+
JSON.stringify(next.repairLayers) !== JSON.stringify(previous.repairLayers) ||
|
|
2215
|
+
JSON.stringify(next.heldLayers) !== JSON.stringify(previous.heldLayers)
|
|
2216
|
+
) {
|
|
2217
|
+
// A different layer set is a different set of totals to anchor.
|
|
2218
|
+
for (const key of [...this.#heldLayerStates.keys()]) {
|
|
2219
|
+
if (this.#belongsToPacket(key, packetId)) this.#heldLayerStates.delete(key)
|
|
2220
|
+
}
|
|
2076
2221
|
}
|
|
2077
2222
|
if (!hasCatalogTiming) {
|
|
2078
2223
|
// A missing/zero span has no catalog deadline. Keep an explicitly
|
|
@@ -2375,6 +2520,8 @@ export class FECManager {
|
|
|
2375
2520
|
resetMap(this.#blockAuthoredLengths)
|
|
2376
2521
|
resetMap(this.#blockRepairRsIds)
|
|
2377
2522
|
resetMap(this.#blockRsbLengths)
|
|
2523
|
+
resetMap(this.#heldLayerStates)
|
|
2524
|
+
resetMap(this.#fecFailClosed)
|
|
2378
2525
|
resetMap(this.#blockPathCounts)
|
|
2379
2526
|
resetMap(this.#blockAnchorsMs)
|
|
2380
2527
|
resetMap(this.#blockCatalogTrackNames)
|
|
@@ -2397,6 +2544,7 @@ export class FECManager {
|
|
|
2397
2544
|
resetSet(this.#materializedBlocks)
|
|
2398
2545
|
resetMap(this.#resolvedBlockClasses)
|
|
2399
2546
|
resetMap(this.#highestSbn)
|
|
2547
|
+
resetMap(this.#sourceFrontiers)
|
|
2400
2548
|
resetMap(this.#isoLocators)
|
|
2401
2549
|
resetMap(this.#sourceAnchors)
|
|
2402
2550
|
this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName))
|
|
@@ -2510,6 +2658,7 @@ export class FECManager {
|
|
|
2510
2658
|
dropMap(this.#orderedPendingBlocks)
|
|
2511
2659
|
dropMap(this.#resolvedBlockClasses)
|
|
2512
2660
|
dropMap(this.#highestSbn)
|
|
2661
|
+
dropMap(this.#sourceFrontiers)
|
|
2513
2662
|
dropMap(this.#isoLocators)
|
|
2514
2663
|
dropMap(this.#sourceAnchors)
|
|
2515
2664
|
dropMap(this.#classifiers)
|
|
@@ -2642,7 +2791,11 @@ export class FECManager {
|
|
|
2642
2791
|
this.#startupPartialBlocks.delete(blockKey)
|
|
2643
2792
|
this.#startupAlignedPackets.add(streamKey)
|
|
2644
2793
|
} else if (
|
|
2645
|
-
|
|
2794
|
+
// A ready multicast repair opens a block the join has not seen yet, never
|
|
2795
|
+
// a join partial: its sources were refused, so its repairs alone open a
|
|
2796
|
+
// block that cannot decode and fails at its deadline, once per packet ID
|
|
2797
|
+
// per join (BLO-48308).
|
|
2798
|
+
isStartupPartial ||
|
|
2646
2799
|
(!this.#startupAlignedPackets.has(streamKey) && !isReadyMulticastRepair)
|
|
2647
2800
|
) {
|
|
2648
2801
|
this.#markStartupPartial(blockKey)
|
|
@@ -2981,6 +3134,7 @@ export class FECManager {
|
|
|
2981
3134
|
let locator = this.#isoLocators.get(streamKey)
|
|
2982
3135
|
if (!locator) {
|
|
2983
3136
|
locator = new IsoBlockLocator<IsoHeldSource>(this.#trackConfig(packetId).k, this.#isoRetentionBlocks(packetId))
|
|
3137
|
+
locator.deferIncompleteGaps = this.#deferIsoGaps
|
|
2984
3138
|
this.#isoLocators.set(streamKey, locator)
|
|
2985
3139
|
}
|
|
2986
3140
|
return locator
|
|
@@ -3028,6 +3182,11 @@ export class FECManager {
|
|
|
3028
3182
|
return blocks
|
|
3029
3183
|
}
|
|
3030
3184
|
|
|
3185
|
+
/** The iso-ssbg1-v1 locator horizon of a configured packetId, in blocks (#isoRetentionBlocks). */
|
|
3186
|
+
isoRetentionBlocksForPacket(packetId: number): number | undefined {
|
|
3187
|
+
return this.#hasBlockProfile(packetId) ? this.#isoRetentionBlocks(packetId) : undefined
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3031
3190
|
/** Whether an iso-ssbg1-v1 protected packet fits one ssbg_mode1 symbol (len + 2 <= T). */
|
|
3032
3191
|
isoSourceFits(packetId: number, packetLength: number): boolean {
|
|
3033
3192
|
const symbolSize = this.#trackConfigs.get(packetId)?.symbolSize
|
|
@@ -3095,23 +3254,74 @@ export class FECManager {
|
|
|
3095
3254
|
}
|
|
3096
3255
|
return placement
|
|
3097
3256
|
}
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
const
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3257
|
+
if (placement.span !== undefined) this.#openIsoSpan(placement.span, packetId, catalogTrackName)
|
|
3258
|
+
if (placement.hole !== undefined) {
|
|
3259
|
+
const locator = this.#isoLocatorFor(packetId, catalogTrackName)
|
|
3260
|
+
const hole = placement.hole.block
|
|
3261
|
+
const previous = locator.blockEndingAt(hole.start)
|
|
3262
|
+
const loss: UndelimitedIsoLoss = {
|
|
3263
|
+
packetId,
|
|
3264
|
+
catalogTrackName,
|
|
3265
|
+
holeStart: hole.start,
|
|
3266
|
+
holeLength: hole.length,
|
|
3267
|
+
lostSsId: placement.hole.lostSsId,
|
|
3268
|
+
kMax: this.#trackConfig(packetId).k,
|
|
3269
|
+
...(previous === undefined ? {} : { previousBlockStart: previous.start }),
|
|
3270
|
+
}
|
|
3271
|
+
this.#onUndelimitedLoss!(loss)
|
|
3111
3272
|
}
|
|
3112
3273
|
return placement
|
|
3113
3274
|
}
|
|
3114
3275
|
|
|
3276
|
+
/**
|
|
3277
|
+
* Keep an iso-ssbg1-v1 gap missing a source as a pending hole, reported to
|
|
3278
|
+
* `handler`, instead of a repair-less span; null restores spans. Set by the
|
|
3279
|
+
* range repair scheduler; applies to every stream from its next gap. The
|
|
3280
|
+
* handler and the deferral are one setting, so no hole is ever created with
|
|
3281
|
+
* nobody to close it.
|
|
3282
|
+
*/
|
|
3283
|
+
setUndelimitedLossHandler(handler: ((loss: UndelimitedIsoLoss) => void) | null): void {
|
|
3284
|
+
this.#onUndelimitedLoss = handler
|
|
3285
|
+
this.#deferIsoGaps = handler !== null
|
|
3286
|
+
for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps
|
|
3287
|
+
}
|
|
3288
|
+
|
|
3289
|
+
/**
|
|
3290
|
+
* The range repair for a hole ended: every hole still pending inside
|
|
3291
|
+
* `[start, start + length)` becomes a repair-less span. Returns those spans
|
|
3292
|
+
* with the held sources they placed, for the caller to feed (MmtpRouter).
|
|
3293
|
+
*/
|
|
3294
|
+
closeIsoHoles(
|
|
3295
|
+
packetId: number,
|
|
3296
|
+
catalogTrackName: string | undefined,
|
|
3297
|
+
start: number,
|
|
3298
|
+
length: number,
|
|
3299
|
+
): { block: IsoBlockRange; placed: IsoPlacedSource<IsoHeldSource>[] }[] {
|
|
3300
|
+
const locator = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))
|
|
3301
|
+
if (locator === undefined) return []
|
|
3302
|
+
const spans = locator.closeHolesWithin(start, length)
|
|
3303
|
+
for (const span of spans) this.#openIsoSpan(span, packetId, catalogTrackName)
|
|
3304
|
+
return spans
|
|
3305
|
+
}
|
|
3306
|
+
|
|
3307
|
+
/**
|
|
3308
|
+
* A repair-less span has no repair to state its length, so it is known
|
|
3309
|
+
* here: its sources make it clean exactly when all of them arrived. A
|
|
3310
|
+
* stated block learns its SSB_length from its own repair symbol, fed after
|
|
3311
|
+
* its placed sources exactly as on the wire (feedRepairSymbol). A span every
|
|
3312
|
+
* SS_ID of which vanished resolves through its deadline like any vanished
|
|
3313
|
+
* block.
|
|
3314
|
+
*/
|
|
3315
|
+
#openIsoSpan(
|
|
3316
|
+
span: { readonly block: IsoBlockRange; readonly placed: readonly unknown[] },
|
|
3317
|
+
packetId: number,
|
|
3318
|
+
catalogTrackName: string | undefined,
|
|
3319
|
+
): void {
|
|
3320
|
+
const key = this.#blockKey(span.block.start, packetId, catalogTrackName)
|
|
3321
|
+
if (!this.#blockAuthoredLengths.has(key)) this.#blockAuthoredLengths.set(key, span.block.length)
|
|
3322
|
+
if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true)
|
|
3323
|
+
}
|
|
3324
|
+
|
|
3115
3325
|
/**
|
|
3116
3326
|
* Resolution of the SS_IDs strictly between two released frames' SS_IDs on
|
|
3117
3327
|
* an iso-ssbg1-v1 stream, for in-order frame release: null while a block
|
|
@@ -3820,6 +4030,184 @@ export class FECManager {
|
|
|
3820
4030
|
return recovered
|
|
3821
4031
|
}
|
|
3822
4032
|
|
|
4033
|
+
/**
|
|
4034
|
+
* fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
|
|
4035
|
+
* exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
|
|
4036
|
+
* block state unchanged. The router calls this before the repair places a
|
|
4037
|
+
* block or takes any other part in block bookkeeping. A RaptorQ track admits
|
|
4038
|
+
* every header that parsed (its RS_ID < RSB_length check is in the parser).
|
|
4039
|
+
*/
|
|
4040
|
+
admitRepairBlockLength(
|
|
4041
|
+
packetId: number,
|
|
4042
|
+
ssbLength: number,
|
|
4043
|
+
rsbLength: number,
|
|
4044
|
+
rsId: number,
|
|
4045
|
+
): boolean {
|
|
4046
|
+
if (rsId >= rsbLength) return false
|
|
4047
|
+
if (this.#trackConfigs.get(packetId)?.algorithm !== 'reed-solomon') return true
|
|
4048
|
+
return ssbLength + rsbLength <= RS_MAX_BLOCK_SYMBOLS
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4051
|
+
/**
|
|
4052
|
+
* Whether a repair symbol of `byteLength` bytes is a valid member of a
|
|
4053
|
+
* `packetId` block: every repair symbol is exactly the track's T. A symbol of
|
|
4054
|
+
* any other size is counted on `repairSymbolSizeMismatches`, warned (rate
|
|
4055
|
+
* limited) and refused. The router calls this before the symbol takes any
|
|
4056
|
+
* other part in block state (placement, first-arrival dedup, completed-block
|
|
4057
|
+
* accounting), so a malformed repair is counted whatever its arrival order:
|
|
4058
|
+
* judged after dedup, one landing on an already-complete block, or behind a
|
|
4059
|
+
* valid copy from the other transport, was swallowed as a duplicate and never
|
|
4060
|
+
* counted (BLO-48306). A packetId with no configured block profile admits
|
|
4061
|
+
* nothing here; its repair is dropped upstream as unreadable.
|
|
4062
|
+
*/
|
|
4063
|
+
admitRepairSymbolSize(
|
|
4064
|
+
packetId: number,
|
|
4065
|
+
ssStart: number,
|
|
4066
|
+
ssbLength: number,
|
|
4067
|
+
rsId: number,
|
|
4068
|
+
byteLength: number,
|
|
4069
|
+
): boolean {
|
|
4070
|
+
if (!this.#hasBlockProfile(packetId)) return false
|
|
4071
|
+
const symbolSize = this.#trackConfig(packetId).symbolSize
|
|
4072
|
+
if (symbolSize > 0 && byteLength !== symbolSize) {
|
|
4073
|
+
this.#repairSymbolSizeMismatchCount++
|
|
4074
|
+
if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
|
|
4075
|
+
console.warn(
|
|
4076
|
+
`[FECManager] Dropping repair symbol with invalid size: got ${byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`,
|
|
4077
|
+
)
|
|
4078
|
+
}
|
|
4079
|
+
return false
|
|
4080
|
+
}
|
|
4081
|
+
return true
|
|
4082
|
+
}
|
|
4083
|
+
|
|
4084
|
+
/**
|
|
4085
|
+
* fec-01 6.3.9 receiver check, run on a repair packet after the 4.5 discard
|
|
4086
|
+
* and the size check, before it places a block. For each held layer i with
|
|
4087
|
+
* total B_i = O_i + P_i: the anchor is the earliest block, in SS_Start
|
|
4088
|
+
* serial order, whose repair carried RSB_length >= B_i. The source track
|
|
4089
|
+
* fails closed on (a) a packet on layer i's own repair track (i > 0) below
|
|
4090
|
+
* B_i, or (b) any packet of the instance at or after the anchor below B_i.
|
|
4091
|
+
* Blocks before the anchor (pre-append) stay valid at the previous total. A
|
|
4092
|
+
* packet on a repair track the catalog does not list is discarded and
|
|
4093
|
+
* anchors nothing. `repairTrackName` is the subscribed repair track, never
|
|
4094
|
+
* inferred from RS_ID; without it only (b) runs. Returns false when the
|
|
4095
|
+
* repair must be dropped, including every repair once the track failed.
|
|
4096
|
+
*/
|
|
4097
|
+
admitRepairLayerTotal(
|
|
4098
|
+
packetId: number,
|
|
4099
|
+
catalogTrackName: string | undefined,
|
|
4100
|
+
repairTrackName: string | undefined,
|
|
4101
|
+
ssStart: number,
|
|
4102
|
+
rsbLength: number,
|
|
4103
|
+
): boolean {
|
|
4104
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName)
|
|
4105
|
+
if (this.#fecFailClosed.has(streamKey)) return false
|
|
4106
|
+
const config = this.#trackConfigs.get(packetId)
|
|
4107
|
+
const layers = config?.repairLayers
|
|
4108
|
+
if (layers === undefined || layers.length === 0) return true
|
|
4109
|
+
if (repairTrackName !== undefined && !layers.some((l) => l.repairTrackName === repairTrackName)) {
|
|
4110
|
+
return false
|
|
4111
|
+
}
|
|
4112
|
+
let states = this.#heldLayerStates.get(streamKey)
|
|
4113
|
+
if (states === undefined) {
|
|
4114
|
+
const held = new Set(config!.heldLayers ?? [0])
|
|
4115
|
+
states = layers
|
|
4116
|
+
.filter((l) => held.has(l.layer))
|
|
4117
|
+
.map((l) => ({ layer: l.layer, repairTrackName: l.repairTrackName, total: l.rsIdOffset + l.repairSymbols }))
|
|
4118
|
+
this.#heldLayerStates.set(streamKey, states)
|
|
4119
|
+
}
|
|
4120
|
+
const horizon = this.#layerAnchorHorizon(packetId)
|
|
4121
|
+
// A repair may run ahead of the media, but one more than `horizon` past the
|
|
4122
|
+
// source frontier must not move the held-layer state: advancing `newest` on
|
|
4123
|
+
// it would retire every real anchor and skip this check until traffic caught
|
|
4124
|
+
// up. Such a repair is still judged below the total: it is on its own track,
|
|
4125
|
+
// or after any anchor by definition. With no anchor yet it says nothing.
|
|
4126
|
+
// It is still admitted: in iso the frontier only moves when a repair places
|
|
4127
|
+
// held sources, so dropping it would stall recovery after a long outage.
|
|
4128
|
+
// IsoBlockLocator.placeRepair may still refuse the same repair as `ahead`:
|
|
4129
|
+
// it measures from `newest`, which held sources move, not from this frontier.
|
|
4130
|
+
const frontier = this.#sourceFrontiers.get(streamKey)?.sbn
|
|
4131
|
+
const farAhead =
|
|
4132
|
+
frontier !== undefined && serial32Precedes(frontier, ssStart) && serial32Distance(frontier, ssStart) > horizon
|
|
4133
|
+
for (const state of states) {
|
|
4134
|
+
let code: FecFailClosedReason['code'] | undefined
|
|
4135
|
+
if (farAhead) {
|
|
4136
|
+
if (rsbLength < state.total) {
|
|
4137
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = 'below_own_track_total'
|
|
4138
|
+
else if (state.anchor !== undefined || state.settled) code = 'below_anchored_total'
|
|
4139
|
+
}
|
|
4140
|
+
} else {
|
|
4141
|
+
// Serials more than `horizon` behind the newest block are retired, so
|
|
4142
|
+
// every serial still compared sits inside one half-window and SS_Start
|
|
4143
|
+
// wrapping on a long-running stream cannot reorder them.
|
|
4144
|
+
if (state.newest === undefined || serial32Precedes(state.newest, ssStart)) state.newest = ssStart
|
|
4145
|
+
const stale = (s: number) => serial32Distance(s, state.newest!) > horizon
|
|
4146
|
+
if (state.latestBelow !== undefined && stale(state.latestBelow)) {
|
|
4147
|
+
delete state.latestBelow
|
|
4148
|
+
delete state.latestBelowRsb
|
|
4149
|
+
}
|
|
4150
|
+
if (state.anchor !== undefined && stale(state.anchor)) state.settled = true
|
|
4151
|
+
if (rsbLength < state.total) {
|
|
4152
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = 'below_own_track_total'
|
|
4153
|
+
else if (stale(ssStart)) continue // past retention: undecodable, anchors nothing
|
|
4154
|
+
else if (state.settled || (state.anchor !== undefined && !serial32Precedes(ssStart, state.anchor))) code = 'below_anchored_total'
|
|
4155
|
+
else if (state.latestBelow === undefined || serial32Precedes(state.latestBelow, ssStart)) {
|
|
4156
|
+
state.latestBelow = ssStart
|
|
4157
|
+
state.latestBelowRsb = rsbLength
|
|
4158
|
+
}
|
|
4159
|
+
} else if (!state.settled && !stale(ssStart)) {
|
|
4160
|
+
if (state.anchor === undefined || serial32Precedes(ssStart, state.anchor)) state.anchor = ssStart
|
|
4161
|
+
if (state.latestBelow !== undefined && !serial32Precedes(state.latestBelow, state.anchor)) {
|
|
4162
|
+
code = 'below_anchored_total'
|
|
4163
|
+
ssStart = state.latestBelow
|
|
4164
|
+
rsbLength = state.latestBelowRsb!
|
|
4165
|
+
}
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
if (code !== undefined) {
|
|
4169
|
+
const reason: FecFailClosedReason = {
|
|
4170
|
+
code, layer: state.layer, total: state.total, rsbLength, ssStart,
|
|
4171
|
+
...(state.anchor === undefined ? {} : { anchor: state.anchor }),
|
|
4172
|
+
}
|
|
4173
|
+
this.#fecFailClosed.set(streamKey, reason)
|
|
4174
|
+
this.#onFecFailClosed?.({ ...reason, packetId, catalogTrackName })
|
|
4175
|
+
console.warn(
|
|
4176
|
+
`[FECManager] FEC failed closed (fec-01 6.3.9) packetId=${packetId} track=${catalogTrackName ?? '-'}: ${JSON.stringify(reason)}`,
|
|
4177
|
+
)
|
|
4178
|
+
return false
|
|
4179
|
+
}
|
|
4180
|
+
}
|
|
4181
|
+
return true
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4184
|
+
/**
|
|
4185
|
+
* How far (in SS_Start symbols) behind the newest block a 6.3.9 anchor or
|
|
4186
|
+
* below-total block can still matter: the iso locator's retention in blocks
|
|
4187
|
+
* times K, capped at 2^30 so compared serials stay inside one half-window.
|
|
4188
|
+
*/
|
|
4189
|
+
#layerAnchorHorizon(packetId: number): number {
|
|
4190
|
+
const cap = 0x40000000
|
|
4191
|
+
let blocks: number | undefined
|
|
4192
|
+
try { blocks = this.isoRetentionBlocksForPacket(packetId) } catch { blocks = undefined }
|
|
4193
|
+
const k = this.#trackConfigs.get(packetId)?.k ?? 0
|
|
4194
|
+
return blocks === undefined || k <= 0 ? cap : Math.min(cap, blocks * k)
|
|
4195
|
+
}
|
|
4196
|
+
|
|
4197
|
+
/**
|
|
4198
|
+
* Report each stream whose FEC fails closed at runtime (fec-01 6.3.9), once,
|
|
4199
|
+
* when it does; null stops reporting. The player wiring forwards it to
|
|
4200
|
+
* CmcdProducer.updateFecFailClosed.
|
|
4201
|
+
*/
|
|
4202
|
+
setFecFailClosedHandler(handler: ((event: FecFailClosedEvent) => void) | null): void {
|
|
4203
|
+
this.#onFecFailClosed = handler
|
|
4204
|
+
}
|
|
4205
|
+
|
|
4206
|
+
/** The runtime fail-closed reason of a stream's FEC (fec-01 6.3.9), if any. */
|
|
4207
|
+
fecFailClosedReason(packetId: number, catalogTrackName?: string): FecFailClosedReason | undefined {
|
|
4208
|
+
return this.#fecFailClosed.get(this.#streamKey(packetId, catalogTrackName))
|
|
4209
|
+
}
|
|
4210
|
+
|
|
3823
4211
|
/**
|
|
3824
4212
|
* Feed a repair symbol to the WASM FEC decoder.
|
|
3825
4213
|
*
|
|
@@ -3840,16 +4228,7 @@ export class FECManager {
|
|
|
3840
4228
|
// A packetId with no configured block profile has no block geometry: its
|
|
3841
4229
|
// repair names no block this manager can track or decode.
|
|
3842
4230
|
if (!this.#hasBlockProfile(packetId)) return null
|
|
3843
|
-
|
|
3844
|
-
if (symbolSize > 0 && repairData.byteLength !== symbolSize) {
|
|
3845
|
-
this.#repairSymbolSizeMismatchCount++
|
|
3846
|
-
if (this.#repairSymbolSizeMismatchCount <= 5 || this.#repairSymbolSizeMismatchCount % 100 === 0) {
|
|
3847
|
-
console.warn(
|
|
3848
|
-
`[FECManager] Dropping repair symbol with invalid size: got ${repairData.byteLength}B, expected ${symbolSize}B (packetId=${packetId}, ssStart=${ssStart}, ssbLength=${ssbLength}, rsId=${rsId})`,
|
|
3849
|
-
)
|
|
3850
|
-
}
|
|
3851
|
-
return null
|
|
3852
|
-
}
|
|
4231
|
+
if (!this.admitRepairSymbolSize(packetId, ssStart, ssbLength, rsId, repairData.byteLength)) return null
|
|
3853
4232
|
const fecData = repairData
|
|
3854
4233
|
|
|
3855
4234
|
// ISO/IEC 23008-1 C.5.3: the block is [SS_Start, SS_Start + SSB_length),
|
|
@@ -4072,7 +4451,14 @@ export class FECManager {
|
|
|
4072
4451
|
// Skip blocks already recovered — late source symbols must not restart timeouts
|
|
4073
4452
|
if (this.#completedBlocks.has(key)) return
|
|
4074
4453
|
|
|
4075
|
-
this.#noteSbnSeen(
|
|
4454
|
+
this.#noteSbnSeen(
|
|
4455
|
+
sbn,
|
|
4456
|
+
packetId,
|
|
4457
|
+
catalogTrackName,
|
|
4458
|
+
'source',
|
|
4459
|
+
evidence.packetSequenceNumber,
|
|
4460
|
+
Number.isInteger(esi) ? (sbn + esi) >>> 0 : sbn,
|
|
4461
|
+
)
|
|
4076
4462
|
|
|
4077
4463
|
// A source ESI at or past the block's authored SSB_length contradicts it;
|
|
4078
4464
|
// its geometry can no longer be trusted, so fail it closed.
|
|
@@ -4386,6 +4772,8 @@ export class FECManager {
|
|
|
4386
4772
|
this.#blockAuthoredLengths.clear()
|
|
4387
4773
|
this.#blockRepairRsIds.clear()
|
|
4388
4774
|
this.#blockRsbLengths.clear()
|
|
4775
|
+
this.#heldLayerStates.clear()
|
|
4776
|
+
this.#fecFailClosed.clear()
|
|
4389
4777
|
this.#completedBlocks.clear()
|
|
4390
4778
|
this.#cleanlyCompletedBlocks.clear()
|
|
4391
4779
|
this.#repairRequestedBlocks.clear()
|
|
@@ -4410,6 +4798,7 @@ export class FECManager {
|
|
|
4410
4798
|
this.#repairedBlocks.clear()
|
|
4411
4799
|
this.#materializedBlocks.clear()
|
|
4412
4800
|
this.#highestSbn.clear()
|
|
4801
|
+
this.#sourceFrontiers.clear()
|
|
4413
4802
|
this.#isoLocators.clear()
|
|
4414
4803
|
this.#sourceAnchors.clear()
|
|
4415
4804
|
this.#trackConfigs.clear()
|