@blockcast/mmt-container 2.2.0-main.c4fa878f4ff4 → 2.2.0-main.cb533d6dfc95
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 +29 -17
- package/dist/browser-runtime.js +1540 -317
- package/dist/browser-runtime.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +17 -1
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +15 -0
- package/dist/catalog-fec-params.js.map +2 -2
- package/dist/cmaf-block-assembler.js +92 -1
- package/dist/cmaf-block-assembler.js.map +2 -2
- package/dist/cmcd-producer.d.ts +60 -47
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +138 -109
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/codec-utils.d.ts.map +1 -1
- package/dist/codec-utils.js +92 -1
- package/dist/codec-utils.js.map +2 -2
- package/dist/delivery-catalog.js +26 -16
- package/dist/delivery-catalog.js.map +2 -2
- package/dist/delta-fallback-config.js.map +1 -1
- package/dist/fec-manager.d.ts +83 -15
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +446 -61
- package/dist/fec-manager.js.map +2 -2
- package/dist/fec-worker-setup.d.ts +1 -1
- package/dist/fec-worker-setup.js +1 -1
- package/dist/fec-worker-setup.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +48 -13
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +97 -25
- package/dist/iso-block-locator.js.map +2 -2
- package/dist/iso-bmff-timing.d.ts +10 -1
- package/dist/iso-bmff-timing.d.ts.map +1 -1
- package/dist/iso-bmff-timing.js +36 -2
- package/dist/iso-bmff-timing.js.map +2 -2
- package/dist/media-router.js.map +1 -1
- package/dist/mmtp-container-parser.d.ts +79 -10
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +299 -27
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +301 -30
- package/dist/mmtp-container-parser.no-modules.js.map +3 -3
- package/dist/mmtp-decode-pipeline.js +298 -27
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-router.d.ts +34 -8
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +647 -80
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-manager.d.ts +26 -3
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +1183 -160
- package/dist/multicast-manager.js.map +3 -3
- package/dist/multicast-transport.js +28 -18
- package/dist/multicast-transport.js.map +2 -2
- package/dist/no-modules.js +298 -27
- package/dist/no-modules.js.map +3 -3
- package/dist/repair-fetch.d.ts +38 -8
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +286 -27
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layer-subscriptions.d.ts +6 -2
- package/dist/repair-layer-subscriptions.d.ts.map +1 -1
- package/dist/repair-layer-subscriptions.js +6 -3
- package/dist/repair-layer-subscriptions.js.map +2 -2
- package/dist/track-session.d.ts +1 -1
- package/dist/track-session.d.ts.map +1 -1
- package/dist/track-session.js +1 -0
- package/dist/track-session.js.map +2 -2
- package/dist/wasm-mmtp-container-parser.js +298 -27
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +8 -5
- package/schemas/catalog.schema.json +4 -0
- package/src/catalog-fec-params.ts +36 -1
- package/src/cmcd-producer.ts +189 -179
- package/src/codec-utils.ts +121 -1
- package/src/fec-manager.ts +487 -35
- package/src/fec-worker-setup.ts +2 -2
- package/src/index.ts +9 -2
- package/src/iso-block-locator.ts +133 -31
- package/src/iso-bmff-timing.ts +40 -1
- package/src/mmtp-container-parser.ts +306 -29
- package/src/mmtp-router.ts +548 -38
- package/src/multicast-manager.ts +134 -16
- package/src/repair-fetch.ts +366 -50
- package/src/repair-layer-subscriptions.ts +13 -5
- package/src/track-session.ts +4 -1
package/src/fec-manager.ts
CHANGED
|
@@ -22,10 +22,12 @@ import {
|
|
|
22
22
|
isoBlockContains,
|
|
23
23
|
isoBlocksBehindLowerBound,
|
|
24
24
|
parseFecBlockProfile,
|
|
25
|
+
serial32Add,
|
|
25
26
|
serial32Distance,
|
|
26
27
|
serial32Precedes,
|
|
27
28
|
ssbg1FitsSymbol,
|
|
28
29
|
type FecBlockProfile,
|
|
30
|
+
type FecInstanceGeometry,
|
|
29
31
|
admitMmtpRepairObject,
|
|
30
32
|
parseMoqRepairFrameWithHeader,
|
|
31
33
|
type MMTPHeader,
|
|
@@ -169,6 +171,17 @@ export interface FecPacketStats {
|
|
|
169
171
|
|
|
170
172
|
export type FecSymbolSource = 'multicast' | 'moq'
|
|
171
173
|
|
|
174
|
+
/**
|
|
175
|
+
* What feedRebuiltSourceSymbol did with a rebuilt source: whether its block
|
|
176
|
+
* took it, and the block the synchronous decoder recovered with it, if any.
|
|
177
|
+
*/
|
|
178
|
+
export interface RebuiltSourceFeed {
|
|
179
|
+
readonly taken: boolean
|
|
180
|
+
readonly recovered: Uint8Array | null
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const NOT_TAKEN: RebuiltSourceFeed = Object.freeze({ taken: false, recovered: null })
|
|
184
|
+
|
|
172
185
|
/**
|
|
173
186
|
* One iso-ssbg1-v1 first-arrival source symbol MmtpRouter holds until a repair
|
|
174
187
|
* symbol states its block: the exact protected packet (no SS_ID, unpadded),
|
|
@@ -201,6 +214,25 @@ export interface UndelimitedIsoLoss {
|
|
|
201
214
|
readonly previousBlockStart?: number
|
|
202
215
|
}
|
|
203
216
|
|
|
217
|
+
/**
|
|
218
|
+
* A pending hole the stream ran more than the locator's horizon past before
|
|
219
|
+
* its range repair ended (BLO-52085): no repair can state its blocks any
|
|
220
|
+
* more, and the release gate no longer waits for it.
|
|
221
|
+
*/
|
|
222
|
+
export type ExpiredIsoHole = Pick<UndelimitedIsoLoss, 'packetId' | 'catalogTrackName' | 'holeStart' | 'holeLength'>
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* What a failed iso-ssbg1-v1 repair-less span was: the `length` SS_IDs from
|
|
226
|
+
* its start, between two stated blocks, of which `sources` arrived. No repair
|
|
227
|
+
* stated the blocks inside it, so the receiver cannot tell its complete
|
|
228
|
+
* blocks from the ones that lost a source: the span failed, not the block
|
|
229
|
+
* that starts it.
|
|
230
|
+
*/
|
|
231
|
+
export interface IsoSpanFailure {
|
|
232
|
+
readonly length: number
|
|
233
|
+
readonly sources: number
|
|
234
|
+
}
|
|
235
|
+
|
|
204
236
|
/**
|
|
205
237
|
* How the multicast leg hands its symbols to this manager.
|
|
206
238
|
*
|
|
@@ -510,10 +542,21 @@ export class FECManager {
|
|
|
510
542
|
// 'pending' forever, which would park every later frame of its stream in
|
|
511
543
|
// the in-order release gate. Each entry owns its handle; the callback
|
|
512
544
|
// checks it still owns the key, so a settled or reset key is never touched.
|
|
513
|
-
|
|
545
|
+
/**
|
|
546
|
+
* Per owed Worker cleanup: the bound on its acknowledgement, when its block
|
|
547
|
+
* was due, and when its cleanup was asked for (see `onCleanupComplete`).
|
|
548
|
+
*/
|
|
549
|
+
#pendingWorkerCleanupBounds = new Map<
|
|
550
|
+
string,
|
|
551
|
+
{ handle: ReturnType<typeof setTimeout>; dueAtMs: number; askedAtMs: number }
|
|
552
|
+
>()
|
|
514
553
|
// Source symbol count per track-scoped block — marks complete when K symbols arrive.
|
|
515
554
|
#blockSourceCounts = new Map<string, number>()
|
|
516
555
|
#blockSourceEsis = new Map<string, Set<number>>()
|
|
556
|
+
// Source ESIs per block that another FEC instance rebuilt and fed in
|
|
557
|
+
// (feedRebuiltSourceSymbol). Kept apart from #blockSourceEsis: they are
|
|
558
|
+
// not network arrivals and never make a block clean.
|
|
559
|
+
#blockRebuiltEsis = new Map<string, Set<number>>()
|
|
517
560
|
// Authored SSB_length per block (ISO/IEC 23008-1 §C.5.3), learned from the
|
|
518
561
|
// first repair symbol. The FFmpeg moq_mmt publisher closes a block every D
|
|
519
562
|
// media units, usually before it holds K symbols; under iso-ssbg1-v1
|
|
@@ -522,10 +565,14 @@ export class FECManager {
|
|
|
522
565
|
// SSB_length source arrivals and recoverable from SSB_length received
|
|
523
566
|
// symbols; waiting for K fails every one of them.
|
|
524
567
|
#blockAuthoredLengths = new Map<string, number>()
|
|
568
|
+
// Keys whose authored length is a repair-less span's (#openIsoSpan), until
|
|
569
|
+
// a repair states the block there or the span resolves.
|
|
570
|
+
#isoSpanKeys = new Set<string>()
|
|
525
571
|
#ssbLengthConflictCount = 0
|
|
526
572
|
#blockRepairRsIds = new Map<string, Set<number>>()
|
|
527
573
|
// RSB_length per block (C.5.3 Repair FEC Payload ID): how many repair
|
|
528
|
-
// symbols its repair group carries
|
|
574
|
+
// symbols its repair group carries; 0 for a repair-less span no repair can
|
|
575
|
+
// state (#openIsoSpan). Same lifecycle as #blockRepairRsIds.
|
|
529
576
|
#blockRsbLengths = new Map<string, number>()
|
|
530
577
|
/** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
|
|
531
578
|
#heldLayerStates = new Map<string, HeldLayerAdmission>()
|
|
@@ -644,6 +691,10 @@ export class FECManager {
|
|
|
644
691
|
// ── Keyframe-protected repair policy (block-policy.ts) ──
|
|
645
692
|
// One classifier per physical stream, built from that stream's geometry.
|
|
646
693
|
#classifiers = new Map<string, BlockClassifier>()
|
|
694
|
+
// A stream without catalog timing has no classifier, so the last RAP it
|
|
695
|
+
// released stands in for one: "an MPU boundary bounds its RAPs" holds until
|
|
696
|
+
// a second RAP is released inside one MPU (BLO-52085).
|
|
697
|
+
#noSpanRaps = new Map<string, { mpu: number; presentationTime: bigint; inside: boolean }>()
|
|
647
698
|
// Geometry a stream-scoped configuration gave one stream (streamKey). ABR
|
|
648
699
|
// rungs can share a packetId with a different framerate or GOP, so the
|
|
649
700
|
// packet-level geometry is only the geometry of a packet whose streams
|
|
@@ -725,13 +776,17 @@ export class FECManager {
|
|
|
725
776
|
onBlockComplete:
|
|
726
777
|
| ((sbn: number, packetId: number, catalogTrackName?: string) => void)
|
|
727
778
|
| null = null
|
|
728
|
-
/**
|
|
779
|
+
/**
|
|
780
|
+
* A block reached its fail bound. `blockClass` is its class at failure.
|
|
781
|
+
* `span` is set when what failed is a repair-less span starting at `sbn`.
|
|
782
|
+
*/
|
|
729
783
|
onBlockFailed:
|
|
730
784
|
| ((
|
|
731
785
|
sbn: number,
|
|
732
786
|
packetId: number,
|
|
733
787
|
catalogTrackName: string | undefined,
|
|
734
788
|
blockClass: BlockClass,
|
|
789
|
+
span?: IsoSpanFailure,
|
|
735
790
|
) => void)
|
|
736
791
|
| null = null
|
|
737
792
|
/**
|
|
@@ -815,6 +870,8 @@ export class FECManager {
|
|
|
815
870
|
* for it, which it must be.
|
|
816
871
|
*/
|
|
817
872
|
#onUndelimitedLoss: ((loss: UndelimitedIsoLoss) => void) | null = null
|
|
873
|
+
/** Set with the loss handler: true takes an expired hole to close (`closeIsoHoles`). */
|
|
874
|
+
#onIsoHoleExpired: ((hole: ExpiredIsoHole) => boolean) | null = null
|
|
818
875
|
/** A block every symbol of which vanished was created by SBN evidence. */
|
|
819
876
|
onBlockVanished:
|
|
820
877
|
| ((sbn: number, packetId: number, catalogTrackName: string | undefined) => void)
|
|
@@ -827,6 +884,19 @@ export class FECManager {
|
|
|
827
884
|
onSourceDiscontinuity:
|
|
828
885
|
| ((packetId: number, catalogTrackName: string | undefined) => void)
|
|
829
886
|
| null = null
|
|
887
|
+
/**
|
|
888
|
+
* The span and tolerance the catalog states for a keyframe overlay
|
|
889
|
+
* installed over a source track (draft-ramadan-moq-mmt-02 7.4.1: the
|
|
890
|
+
* overlay instance's own interleaveDepthMs and reorderToleranceMs), or
|
|
891
|
+
* undefined while none is installed. A block only a late source can
|
|
892
|
+
* complete also waits for that overlay's repair (#lateSourceWaitMs).
|
|
893
|
+
*/
|
|
894
|
+
keyframeOverlayTiming:
|
|
895
|
+
| ((
|
|
896
|
+
packetId: number,
|
|
897
|
+
catalogTrackName: string | undefined,
|
|
898
|
+
) => Pick<FecInstanceGeometry, 'interleaveDepthMs' | 'reorderToleranceMs'> | undefined)
|
|
899
|
+
| null = null
|
|
830
900
|
|
|
831
901
|
// Worker-path callbacks — async recovery and stats from FecWorkerClient.
|
|
832
902
|
/**
|
|
@@ -1469,7 +1539,12 @@ export class FECManager {
|
|
|
1469
1539
|
timer.handle = null
|
|
1470
1540
|
this.#requestRepair(sbn, packetId, catalogTrackName)
|
|
1471
1541
|
}
|
|
1472
|
-
timer.handle = setTimeout(
|
|
1542
|
+
timer.handle = setTimeout(
|
|
1543
|
+
onFire,
|
|
1544
|
+
this.#receiptAtMs === undefined
|
|
1545
|
+
? Math.max(0, deadlineMs - performance.now())
|
|
1546
|
+
: this.#receiptTimerDelayMs(deadlineMs, 0),
|
|
1547
|
+
)
|
|
1473
1548
|
this.#repairDeadlines.set(key, timer)
|
|
1474
1549
|
}
|
|
1475
1550
|
|
|
@@ -1663,6 +1738,12 @@ export class FECManager {
|
|
|
1663
1738
|
* Vanished blocks are not enumerated here: their starts are unknown until a
|
|
1664
1739
|
* repair states them. The SS_IDs between two stated blocks become one
|
|
1665
1740
|
* repair-less span when the later block's repair arrives (placeIsoRepair).
|
|
1741
|
+
*
|
|
1742
|
+
* A `held` source arrived before its block was known and is fed only now
|
|
1743
|
+
* that a repair, a span or a closed hole placed it: how far its block start
|
|
1744
|
+
* then lies behind the frontier measures how long the receiver held it, not
|
|
1745
|
+
* where the stream was, so only its SS_ID and packet_sequence_number judge
|
|
1746
|
+
* it (BLO-52085).
|
|
1666
1747
|
*/
|
|
1667
1748
|
#noteSbnSeen(
|
|
1668
1749
|
sbn: number,
|
|
@@ -1671,6 +1752,7 @@ export class FECManager {
|
|
|
1671
1752
|
symbol: 'source' | 'repair',
|
|
1672
1753
|
packetSequenceNumber?: number,
|
|
1673
1754
|
ssId = sbn,
|
|
1755
|
+
held = false,
|
|
1674
1756
|
): void {
|
|
1675
1757
|
const streamKey = this.#streamKey(packetId, catalogTrackName)
|
|
1676
1758
|
// Arrival at FEC, not receipt (withReceiptTime): this bounds how far SS_ID
|
|
@@ -1706,6 +1788,7 @@ export class FECManager {
|
|
|
1706
1788
|
// The classifier compares authored order with SBN order only within
|
|
1707
1789
|
// one continuous SBN sequence.
|
|
1708
1790
|
this.#classifiers.get(streamKey)?.noteSourceDiscontinuity()
|
|
1791
|
+
this.#noSpanRaps.delete(streamKey)
|
|
1709
1792
|
this.#highestSbn.set(streamKey, { sbn, atMs: now })
|
|
1710
1793
|
this.#sourceFrontiers.set(streamKey, { sbn, atMs: now })
|
|
1711
1794
|
if (psn === undefined) this.#sourceAnchors.delete(streamKey)
|
|
@@ -1726,7 +1809,7 @@ export class FECManager {
|
|
|
1726
1809
|
}
|
|
1727
1810
|
if (!this.#blockPrecedes(previous.sbn, sbn)) {
|
|
1728
1811
|
if (symbol === 'source' && window !== null && this.#blockPrecedes(sbn, previous.sbn) && (
|
|
1729
|
-
this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId) ||
|
|
1812
|
+
(!held && this.#blocksBehind(sbn, previous.sbn, packetId) > this.#isoRetentionBlocks(packetId)) ||
|
|
1730
1813
|
(psn !== undefined && anchor !== undefined && serial32Precedes(ssId, anchor.ssId) &&
|
|
1731
1814
|
psn !== anchor.psn && !sentInOrder({ ssId, psn }, anchor))
|
|
1732
1815
|
)) {
|
|
@@ -2080,21 +2163,28 @@ export class FECManager {
|
|
|
2080
2163
|
this.#blockWaitDeadlinesMs.delete(key)
|
|
2081
2164
|
this.#repairHoldUntilMs.delete(key)
|
|
2082
2165
|
this.#traceLifecycle('timeout-queued', sbn, packetId, catalogTrackName)
|
|
2083
|
-
this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName)
|
|
2166
|
+
this.#finalizeExpiredBlock(sbn, packetId, catalogTrackName, currentDeadlineMs ?? firedAtMs)
|
|
2084
2167
|
}
|
|
2085
|
-
timer.handle = setTimeout(
|
|
2168
|
+
timer.handle = setTimeout(
|
|
2169
|
+
onFire,
|
|
2170
|
+
this.#receiptAtMs === undefined
|
|
2171
|
+
? Math.max(1, Math.ceil(deadlineMs - nowMs))
|
|
2172
|
+
: this.#receiptTimerDelayMs(deadlineMs, 1),
|
|
2173
|
+
)
|
|
2086
2174
|
this.#activeBlocks.set(key, timer)
|
|
2087
2175
|
this.#indexBlockKey(key, sbn, packetId)
|
|
2088
2176
|
}
|
|
2089
2177
|
|
|
2090
2178
|
/**
|
|
2091
2179
|
* Hand a block whose delivery is over to its decoder for finalization: the
|
|
2092
|
-
* datagram deadline fired, or the ordered relay moved past it.
|
|
2180
|
+
* datagram deadline fired, or the ordered relay moved past it. `dueAtMs`
|
|
2181
|
+
* is when it was due: its deadline, or now.
|
|
2093
2182
|
*/
|
|
2094
2183
|
#finalizeExpiredBlock(
|
|
2095
2184
|
sbn: number,
|
|
2096
2185
|
packetId: number,
|
|
2097
2186
|
catalogTrackName: string | undefined,
|
|
2187
|
+
dueAtMs = performance.now(),
|
|
2098
2188
|
): void {
|
|
2099
2189
|
const key = this.#blockKey(sbn, packetId, catalogTrackName)
|
|
2100
2190
|
// A vanished block that never received a symbol holds no decoder state
|
|
@@ -2118,7 +2208,7 @@ export class FECManager {
|
|
|
2118
2208
|
if (workerClient) {
|
|
2119
2209
|
this.#pendingWorkerCleanups.add(key)
|
|
2120
2210
|
this.#pendingWorkerCleanupClients.set(key, workerClient)
|
|
2121
|
-
this.#boundOwedCleanup(key, packetId, workerClient)
|
|
2211
|
+
this.#boundOwedCleanup(key, packetId, workerClient, dueAtMs)
|
|
2122
2212
|
workerClient.cleanup(sbn)
|
|
2123
2213
|
} else {
|
|
2124
2214
|
const decoder = this.#decoderForPacket(packetId, catalogTrackName)?.client
|
|
@@ -2289,6 +2379,9 @@ export class FECManager {
|
|
|
2289
2379
|
// sibling's change, but the first stream-scoped geometry on a packet
|
|
2290
2380
|
// does change the siblings that have none (stream-geometry-absent).
|
|
2291
2381
|
this.#bumpEpoch(packetId)
|
|
2382
|
+
for (const key of [...this.#noSpanRaps.keys()]) {
|
|
2383
|
+
if (this.#belongsToPacket(key, packetId)) this.#noSpanRaps.delete(key)
|
|
2384
|
+
}
|
|
2292
2385
|
for (const [key, classifier] of [...this.#classifiers]) {
|
|
2293
2386
|
if (!this.#belongsToPacket(key, packetId)) continue
|
|
2294
2387
|
const stream = this.#parseStreamKey(key)
|
|
@@ -2532,7 +2625,9 @@ export class FECManager {
|
|
|
2532
2625
|
}
|
|
2533
2626
|
resetMap(this.#blockSourceCounts)
|
|
2534
2627
|
resetMap(this.#blockSourceEsis)
|
|
2628
|
+
resetMap(this.#blockRebuiltEsis)
|
|
2535
2629
|
resetMap(this.#blockAuthoredLengths)
|
|
2630
|
+
resetSet(this.#isoSpanKeys)
|
|
2536
2631
|
resetMap(this.#blockRepairRsIds)
|
|
2537
2632
|
resetMap(this.#blockRsbLengths)
|
|
2538
2633
|
resetMap(this.#heldLayerStates)
|
|
@@ -2565,6 +2660,7 @@ export class FECManager {
|
|
|
2565
2660
|
resetMap(this.#isoLocators)
|
|
2566
2661
|
resetMap(this.#sourceAnchors)
|
|
2567
2662
|
this.#classifiers.delete(this.#streamKey(packetId, catalogTrackName))
|
|
2663
|
+
this.#noSpanRaps.delete(this.#streamKey(packetId, catalogTrackName))
|
|
2568
2664
|
this.#bumpEpoch(packetId)
|
|
2569
2665
|
for (const [sbn, keys] of this.#blockKeysBySbn) {
|
|
2570
2666
|
for (const key of keys.keys()) {
|
|
@@ -2663,7 +2759,9 @@ export class FECManager {
|
|
|
2663
2759
|
dropMap(this.#pendingWorkerCleanupClients)
|
|
2664
2760
|
dropMap(this.#blockSourceCounts)
|
|
2665
2761
|
dropMap(this.#blockSourceEsis)
|
|
2762
|
+
dropMap(this.#blockRebuiltEsis)
|
|
2666
2763
|
dropMap(this.#blockAuthoredLengths)
|
|
2764
|
+
dropSet(this.#isoSpanKeys)
|
|
2667
2765
|
dropMap(this.#blockRepairRsIds)
|
|
2668
2766
|
dropMap(this.#blockRsbLengths)
|
|
2669
2767
|
dropMap(this.#blockPathCounts)
|
|
@@ -2679,6 +2777,7 @@ export class FECManager {
|
|
|
2679
2777
|
dropMap(this.#isoLocators)
|
|
2680
2778
|
dropMap(this.#sourceAnchors)
|
|
2681
2779
|
dropMap(this.#classifiers)
|
|
2780
|
+
dropMap(this.#noSpanRaps)
|
|
2682
2781
|
dropMap(this.#streamGeometries)
|
|
2683
2782
|
dropSet(this.#pendingWorkerCleanups)
|
|
2684
2783
|
dropSet(this.#completedBlocks)
|
|
@@ -2881,6 +2980,10 @@ export class FECManager {
|
|
|
2881
2980
|
}
|
|
2882
2981
|
}
|
|
2883
2982
|
|
|
2983
|
+
if (isSourceSymbol && source === 'multicast') {
|
|
2984
|
+
this.#noteMulticastSource(this.#isoLocatorFor(packetId, catalogTrackName), (sbn + esi) >>> 0, packetId, catalogTrackName)
|
|
2985
|
+
}
|
|
2986
|
+
|
|
2884
2987
|
return true
|
|
2885
2988
|
}
|
|
2886
2989
|
|
|
@@ -3006,8 +3109,10 @@ export class FECManager {
|
|
|
3006
3109
|
}
|
|
3007
3110
|
/**
|
|
3008
3111
|
* An open block's accepted sources, distinct repair RS_IDs, authored K'
|
|
3009
|
-
* (SSB_length) and RSB_length (each undefined until a repair stated it
|
|
3010
|
-
*
|
|
3112
|
+
* (SSB_length) and RSB_length (each undefined until a repair stated it; a
|
|
3113
|
+
* repair-less span states its length, and RSB_length 0 when it is longer
|
|
3114
|
+
* than K, since no repair can reach it). Undefined for a block that is not
|
|
3115
|
+
* open.
|
|
3011
3116
|
*/
|
|
3012
3117
|
blockSymbolCounts(
|
|
3013
3118
|
sbn: number,
|
|
@@ -3090,8 +3195,9 @@ export class FECManager {
|
|
|
3090
3195
|
return true
|
|
3091
3196
|
}
|
|
3092
3197
|
/**
|
|
3093
|
-
* Drop a block's repair hold: its FETCH ended without delivering
|
|
3094
|
-
*
|
|
3198
|
+
* Drop a block's repair hold: its FETCH ended without delivering, or brought
|
|
3199
|
+
* back only a repair that cannot complete it. The block falls back to its
|
|
3200
|
+
* multicast wait, which may already have passed.
|
|
3095
3201
|
*/
|
|
3096
3202
|
releaseRepairHold(sbn: number, packetId: number, catalogTrackName?: string): void {
|
|
3097
3203
|
const key = this.#blockKey(sbn, packetId, catalogTrackName)
|
|
@@ -3253,6 +3359,8 @@ export class FECManager {
|
|
|
3253
3359
|
const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName)
|
|
3254
3360
|
const evictedBefore = locator.heldEvicted
|
|
3255
3361
|
const held = locator.hold(ssId, source)
|
|
3362
|
+
this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName)
|
|
3363
|
+
if (held && source.source === 'multicast') this.#noteMulticastSource(locator, ssId, packetId, catalogTrackName)
|
|
3256
3364
|
const evicted = locator.heldEvicted - evictedBefore
|
|
3257
3365
|
if (evicted > 0) {
|
|
3258
3366
|
const before = this.#isoHeldEvictedCount
|
|
@@ -3280,17 +3388,26 @@ export class FECManager {
|
|
|
3280
3388
|
ssStart: number,
|
|
3281
3389
|
ssbLength: number,
|
|
3282
3390
|
): IsoRepairPlacement<IsoHeldSource> {
|
|
3283
|
-
const
|
|
3391
|
+
const locator = this.#growingIsoLocatorFor(packetId, catalogTrackName)
|
|
3392
|
+
const placement = locator.placeRepair(ssStart, ssbLength)
|
|
3393
|
+
this.#settleExpiredIsoHoles(locator, packetId, catalogTrackName)
|
|
3284
3394
|
if (placement.status !== 'placed') {
|
|
3285
3395
|
this.#isoRepairRefusedCount++
|
|
3286
3396
|
if (this.#isoRepairRefusedCount <= 5 || this.#isoRepairRefusedCount % 100 === 0) {
|
|
3287
3397
|
console.warn(`[FECManager] packetId=${packetId} iso-ssbg1-v1 repair refused (${placement.status}): ${placement.reason}`)
|
|
3288
3398
|
}
|
|
3399
|
+
// The repair FETCH of a span's first group brought back a shorter block:
|
|
3400
|
+
// the span holds more than one, so that group cannot complete it, and
|
|
3401
|
+
// holding the span (and every frame behind it) for the FETCH buys
|
|
3402
|
+
// nothing. It falls back to its multicast wait.
|
|
3403
|
+
if (placement.ofSpan !== undefined) this.releaseRepairHold(placement.ofSpan.start, packetId, catalogTrackName)
|
|
3289
3404
|
return placement
|
|
3290
3405
|
}
|
|
3406
|
+
// A repair states the block at its SS_Start: a span the locator kept
|
|
3407
|
+
// there is now that one block (IsoBlockLocator.placeRepair).
|
|
3408
|
+
this.#isoSpanKeys.delete(this.#blockKey(placement.block.start, packetId, catalogTrackName))
|
|
3291
3409
|
if (placement.span !== undefined) this.#openIsoSpan(placement.span, packetId, catalogTrackName)
|
|
3292
3410
|
if (placement.hole !== undefined) {
|
|
3293
|
-
const locator = this.#isoLocatorFor(packetId, catalogTrackName)
|
|
3294
3411
|
const hole = placement.hole.block
|
|
3295
3412
|
const previous = locator.blockEndingAt(hole.start)
|
|
3296
3413
|
const loss: UndelimitedIsoLoss = {
|
|
@@ -3312,18 +3429,38 @@ export class FECManager {
|
|
|
3312
3429
|
* `handler`, instead of a repair-less span; null restores spans. Set by the
|
|
3313
3430
|
* range repair scheduler; applies to every stream from its next gap. The
|
|
3314
3431
|
* handler and the deferral are one setting, so no hole is ever created with
|
|
3315
|
-
* nobody to close it.
|
|
3432
|
+
* nobody to close it. `onExpired` is told of each pending hole the stream
|
|
3433
|
+
* runs past the locator's horizon (BLO-52085): returning true, it closes
|
|
3434
|
+
* the hole (`closeIsoHoles`), so the span it leaves still fails and is
|
|
3435
|
+
* reported; otherwise the hole is discarded with its sources.
|
|
3316
3436
|
*/
|
|
3317
|
-
setUndelimitedLossHandler(
|
|
3437
|
+
setUndelimitedLossHandler(
|
|
3438
|
+
handler: ((loss: UndelimitedIsoLoss) => void) | null,
|
|
3439
|
+
onExpired: ((hole: ExpiredIsoHole) => boolean) | null = null,
|
|
3440
|
+
): void {
|
|
3318
3441
|
this.#onUndelimitedLoss = handler
|
|
3442
|
+
this.#onIsoHoleExpired = handler === null ? null : onExpired
|
|
3319
3443
|
this.#deferIsoGaps = handler !== null
|
|
3320
3444
|
for (const locator of this.#isoLocators.values()) locator.deferIncompleteGaps = this.#deferIsoGaps
|
|
3321
3445
|
}
|
|
3322
3446
|
|
|
3447
|
+
/** Hand each hole the locator's horizon passed to its owner, or discard it (setUndelimitedLossHandler). */
|
|
3448
|
+
#settleExpiredIsoHoles(
|
|
3449
|
+
locator: IsoBlockLocator<IsoHeldSource>,
|
|
3450
|
+
packetId: number,
|
|
3451
|
+
catalogTrackName: string | undefined,
|
|
3452
|
+
): void {
|
|
3453
|
+
for (const hole of locator.takeExpiredHoles()) {
|
|
3454
|
+
const expired: ExpiredIsoHole = { packetId, catalogTrackName, holeStart: hole.start, holeLength: hole.length }
|
|
3455
|
+
if (this.#onIsoHoleExpired?.(expired) !== true) locator.closeHolesWithin(hole.start, hole.length)
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3323
3459
|
/**
|
|
3324
|
-
* The range repair for a hole ended: every hole
|
|
3325
|
-
*
|
|
3326
|
-
* with the held sources they placed, for the caller to feed
|
|
3460
|
+
* The range repair for a hole ended: every hole inside `[start, start +
|
|
3461
|
+
* length)`, pending or expired, becomes a repair-less span. Returns those
|
|
3462
|
+
* spans with the held sources they placed, for the caller to feed
|
|
3463
|
+
* (MmtpRouter).
|
|
3327
3464
|
*/
|
|
3328
3465
|
closeIsoHoles(
|
|
3329
3466
|
packetId: number,
|
|
@@ -3345,6 +3482,14 @@ export class FECManager {
|
|
|
3345
3482
|
* its placed sources exactly as on the wire (feedRepairSymbol). A span every
|
|
3346
3483
|
* SS_ID of which vanished resolves through its deadline like any vanished
|
|
3347
3484
|
* block.
|
|
3485
|
+
*
|
|
3486
|
+
* A span longer than K holds more than one block (SSB_length <= K), and the
|
|
3487
|
+
* locator states no block inside a span, only one exactly its range
|
|
3488
|
+
* (IsoBlockLocator.placeRepair): no repair, multicast or FETCHed, can ever
|
|
3489
|
+
* reach it. Its repair group is empty, so only its own late sources can
|
|
3490
|
+
* complete it, and it waits as a stated block its group cannot complete
|
|
3491
|
+
* does (#lateSourceWaitMs; BLO-52085 D4). A span of K or less may be one
|
|
3492
|
+
* block whose repair is still to come, and keeps the whole wait.
|
|
3348
3493
|
*/
|
|
3349
3494
|
#openIsoSpan(
|
|
3350
3495
|
span: { readonly block: IsoBlockRange; readonly placed: readonly unknown[] },
|
|
@@ -3352,7 +3497,16 @@ export class FECManager {
|
|
|
3352
3497
|
catalogTrackName: string | undefined,
|
|
3353
3498
|
): void {
|
|
3354
3499
|
const key = this.#blockKey(span.block.start, packetId, catalogTrackName)
|
|
3355
|
-
|
|
3500
|
+
// A span's key is always new here. An authored length is set only here or
|
|
3501
|
+
// from a repair stating that block (#noteAuthoredLength), and the locator
|
|
3502
|
+
// opens a span only where no repair stated a block, so none can precede
|
|
3503
|
+
// it. Were one to, the guard would skip the RSB_length 0 a long span
|
|
3504
|
+
// needs to fail early.
|
|
3505
|
+
if (!this.#blockAuthoredLengths.has(key)) {
|
|
3506
|
+
this.#blockAuthoredLengths.set(key, span.block.length)
|
|
3507
|
+
this.#isoSpanKeys.add(key)
|
|
3508
|
+
if (span.block.length > this.#isoLocatorFor(packetId, catalogTrackName).kMax) this.#blockRsbLengths.set(key, 0)
|
|
3509
|
+
}
|
|
3356
3510
|
if (span.placed.length === 0) this.#materializeBlock(span.block.start, packetId, catalogTrackName, true)
|
|
3357
3511
|
}
|
|
3358
3512
|
|
|
@@ -3470,11 +3624,14 @@ export class FECManager {
|
|
|
3470
3624
|
/**
|
|
3471
3625
|
* Whether an MPU boundary still bounds this stream's RAPs (see
|
|
3472
3626
|
* `BlockClassifier.mpuBoundsRaps`). Gap decisions drop MPU evidence once
|
|
3473
|
-
* it does not. A stream with no classifier yet has shown nothing against it
|
|
3627
|
+
* it does not. A stream with no classifier yet has shown nothing against it,
|
|
3628
|
+
* and neither has a stream without catalog timing until it releases two
|
|
3629
|
+
* RAPs inside one MPU.
|
|
3474
3630
|
*/
|
|
3475
3631
|
mpuBoundsRapsFor(packetId: number, catalogTrackName?: string): boolean {
|
|
3476
|
-
|
|
3477
|
-
return this.#
|
|
3632
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName)
|
|
3633
|
+
if (!this.#hasCatalogTimingForPacket(packetId)) return this.#noSpanRaps.get(streamKey)?.inside !== true
|
|
3634
|
+
return this.#classifiers.get(streamKey)?.mpuBoundsRaps ?? true
|
|
3478
3635
|
}
|
|
3479
3636
|
|
|
3480
3637
|
/** A block's class now, or frozen at its resolution. */
|
|
@@ -3510,7 +3667,15 @@ export class FECManager {
|
|
|
3510
3667
|
presentationTime: bigint,
|
|
3511
3668
|
mediaTimescale: number,
|
|
3512
3669
|
): void {
|
|
3513
|
-
if (!this.#trackConfigs.has(packetId)
|
|
3670
|
+
if (!this.#trackConfigs.has(packetId)) return
|
|
3671
|
+
if (!this.#hasCatalogTimingForPacket(packetId)) {
|
|
3672
|
+
const streamKey = this.#streamKey(packetId, catalogTrackName)
|
|
3673
|
+
const last = this.#noSpanRaps.get(streamKey)
|
|
3674
|
+
const inside = last?.inside === true ||
|
|
3675
|
+
(last?.mpu === mpu && last.presentationTime !== presentationTime)
|
|
3676
|
+
this.#noSpanRaps.set(streamKey, { mpu, presentationTime, inside })
|
|
3677
|
+
return
|
|
3678
|
+
}
|
|
3514
3679
|
this.#applyClassifierChanges(
|
|
3515
3680
|
packetId,
|
|
3516
3681
|
catalogTrackName,
|
|
@@ -3820,13 +3985,27 @@ export class FECManager {
|
|
|
3820
3985
|
|
|
3821
3986
|
client.onCleanupComplete((sbn: number) => {
|
|
3822
3987
|
if (this.#releasedWorkerClients.has(client)) return
|
|
3823
|
-
const
|
|
3988
|
+
const owed = [...this.#pendingWorkerCleanups].filter((key) => this.#pendingWorkerCleanupClients.get(key) === client)
|
|
3989
|
+
const cleanupKeys = owed.filter((key) => {
|
|
3824
3990
|
const block = this.#parseBlockKey(key)
|
|
3825
|
-
return block.packetId === packetId &&
|
|
3826
|
-
block.sbn === sbn &&
|
|
3827
|
-
this.#pendingWorkerCleanupClients.get(key) === client
|
|
3991
|
+
return block.packetId === packetId && block.sbn === sbn
|
|
3828
3992
|
})
|
|
3829
|
-
|
|
3993
|
+
// A cleanup is a queue-drain barrier: the Worker took every symbol fed
|
|
3994
|
+
// before it was asked for first, so every block already due by then
|
|
3995
|
+
// is settled by this acknowledgement too, not one barrier later. The
|
|
3996
|
+
// client sends one barrier at a time, and the blocks a repair walk
|
|
3997
|
+
// stated in one span are due together (BLO-52085). That holds only
|
|
3998
|
+
// while no block is fed a symbol after its dueAtMs, which is its
|
|
3999
|
+
// receipt-scoped deadline, not when feeding stopped: a symbol fed
|
|
4000
|
+
// between that deadline and the block's timer, after another block's
|
|
4001
|
+
// barrier was asked for, would find the block settled (failed) one
|
|
4002
|
+
// barrier early. Walks end before D-28 (walkDeadlineAt), so that window
|
|
4003
|
+
// is the timer's lateness alone; whatever feeds a block past its dueAtMs
|
|
4004
|
+
// must leave it to its own barrier.
|
|
4005
|
+
const askedAtMs = Math.max(...cleanupKeys.map((key) => this.#pendingWorkerCleanupBounds.get(key)?.askedAtMs ?? -Infinity))
|
|
4006
|
+
const due = owed.filter((key) =>
|
|
4007
|
+
!cleanupKeys.includes(key) && (this.#pendingWorkerCleanupBounds.get(key)?.dueAtMs ?? Infinity) <= askedAtMs)
|
|
4008
|
+
for (const key of [...cleanupKeys, ...due]) this.#settleOwedCleanup(key, 'cleanup-ack')
|
|
3830
4009
|
})
|
|
3831
4010
|
|
|
3832
4011
|
client.onError((msg: string, code?: FecWorkerErrorCode) => {
|
|
@@ -3908,9 +4087,11 @@ export class FECManager {
|
|
|
3908
4087
|
* fail deadline already passed, so failing it is the decision that deadline
|
|
3909
4088
|
* made. A late ack then finds nothing owed and is a no-op.
|
|
3910
4089
|
*/
|
|
3911
|
-
#boundOwedCleanup(key: string, packetId: number, client: FecWorkerClient): void {
|
|
4090
|
+
#boundOwedCleanup(key: string, packetId: number, client: FecWorkerClient, dueAtMs: number): void {
|
|
3912
4091
|
this.#clearOwedCleanupBound(key)
|
|
3913
4092
|
const bound = {
|
|
4093
|
+
dueAtMs,
|
|
4094
|
+
askedAtMs: performance.now(),
|
|
3914
4095
|
handle: setTimeout(() => {
|
|
3915
4096
|
if (this.#pendingWorkerCleanupBounds.get(key) !== bound) return
|
|
3916
4097
|
this.#pendingWorkerCleanupBounds.delete(key)
|
|
@@ -4041,7 +4222,22 @@ export class FECManager {
|
|
|
4041
4222
|
this.#isoSourceOversizeCount++
|
|
4042
4223
|
return null
|
|
4043
4224
|
}
|
|
4044
|
-
|
|
4225
|
+
return this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, located.block.start)
|
|
4226
|
+
}
|
|
4227
|
+
|
|
4228
|
+
/**
|
|
4229
|
+
* Hand one placed source symbol to the stream's decoder: its Worker, which
|
|
4230
|
+
* answers through onFrame (null here), or its synchronous decoder, whose
|
|
4231
|
+
* recovered block is returned. `sbn` is the SS_Start of the block a repair
|
|
4232
|
+
* stated for `ssId`.
|
|
4233
|
+
*/
|
|
4234
|
+
#feedDecoderSource(
|
|
4235
|
+
packetId: number,
|
|
4236
|
+
ssId: number,
|
|
4237
|
+
symbolData: Uint8Array,
|
|
4238
|
+
catalogTrackName: string | undefined,
|
|
4239
|
+
sbn: number,
|
|
4240
|
+
): Uint8Array | null {
|
|
4045
4241
|
const blockKey = this.#blockKey(sbn, packetId, catalogTrackName)
|
|
4046
4242
|
const syncBlockOwner = this.#syncDecoderBlockOwners.get(blockKey)
|
|
4047
4243
|
|
|
@@ -4086,6 +4282,97 @@ export class FECManager {
|
|
|
4086
4282
|
return recovered
|
|
4087
4283
|
}
|
|
4088
4284
|
|
|
4285
|
+
/**
|
|
4286
|
+
* Feed a source symbol of this stream that another FEC instance over the
|
|
4287
|
+
* same packets rebuilt: a keyframe overlay recovery whose base SS_ID the
|
|
4288
|
+
* caller determined (draft-ramadan-moq-mmt-02 7.1, 7.4.4; joint decoding,
|
|
4289
|
+
* BLO-52085). It joins its block's decoder as a received source would, so
|
|
4290
|
+
* it reduces the erasures the block still has to solve, but it is not a
|
|
4291
|
+
* network arrival: no transport accounting, no classification evidence,
|
|
4292
|
+
* no deadline refresh, and it never makes a block clean.
|
|
4293
|
+
*
|
|
4294
|
+
* Only a block a repair stated takes one (a repair-less span has no
|
|
4295
|
+
* decoder block). A block that is terminal, or already holds that source,
|
|
4296
|
+
* does not. The symbol is the exact protected packet, unpadded, as
|
|
4297
|
+
* feedSourceSymbol takes it.
|
|
4298
|
+
*
|
|
4299
|
+
* `recovered` is the block the synchronous decoder completed with it; the
|
|
4300
|
+
* caller routes it and completes the block, as for any recovery. When
|
|
4301
|
+
* every source of the block is then present, received or rebuilt, and no
|
|
4302
|
+
* decoder returned it (a Worker answers asynchronously, and reports such a
|
|
4303
|
+
* block as clean on its own side), the block is completed here as
|
|
4304
|
+
* recovered, with nothing left to route.
|
|
4305
|
+
*/
|
|
4306
|
+
feedRebuiltSourceSymbol(
|
|
4307
|
+
packetId: number,
|
|
4308
|
+
ssId: number,
|
|
4309
|
+
symbolData: Uint8Array,
|
|
4310
|
+
catalogTrackName?: string,
|
|
4311
|
+
): RebuiltSourceFeed {
|
|
4312
|
+
if (!this.#hasBlockProfile(packetId)) return NOT_TAKEN
|
|
4313
|
+
const located = this.#isoLocatorFor(packetId, catalogTrackName).locate(ssId)
|
|
4314
|
+
if (located === null || located.block.span) return NOT_TAKEN
|
|
4315
|
+
if (!ssbg1FitsSymbol(symbolData.byteLength, this.#trackConfig(packetId).symbolSize)) return NOT_TAKEN
|
|
4316
|
+
const sbn = located.block.start
|
|
4317
|
+
const key = this.#blockKey(sbn, packetId, catalogTrackName)
|
|
4318
|
+
if (this.#completedBlocks.has(key) || this.#blockSourceEsis.get(key)?.has(located.esi)) return NOT_TAKEN
|
|
4319
|
+
let rebuilt = this.#blockRebuiltEsis.get(key)
|
|
4320
|
+
if (rebuilt?.has(located.esi)) return NOT_TAKEN
|
|
4321
|
+
if (rebuilt === undefined) {
|
|
4322
|
+
rebuilt = new Set()
|
|
4323
|
+
this.#blockRebuiltEsis.set(key, rebuilt)
|
|
4324
|
+
}
|
|
4325
|
+
const config = this.#trackConfigs.get(packetId)
|
|
4326
|
+
const wasShort = config !== undefined &&
|
|
4327
|
+
this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config) !== undefined
|
|
4328
|
+
rebuilt.add(located.esi)
|
|
4329
|
+
const recovered = this.#feedDecoderSource(packetId, ssId, symbolData, catalogTrackName, sbn)
|
|
4330
|
+
if (recovered === null && !this.#completeWhenSourcesPresent(key, sbn, located.block.length, packetId, catalogTrackName)) {
|
|
4331
|
+
// The late-source cut assumed only a late source could complete this
|
|
4332
|
+
// block; with this source its group can, so it gets a full multicast
|
|
4333
|
+
// wait again, counted from now.
|
|
4334
|
+
// ponytail: from now, not from its sources, so it can close up to one
|
|
4335
|
+
// multicast wait after its uncut deadline; at most once per block, since
|
|
4336
|
+
// a rebuilt source only adds to what the block holds and the cut cannot
|
|
4337
|
+
// apply to it again. Keep the uncut deadline and re-arm to it if a lab
|
|
4338
|
+
// run shows that wait.
|
|
4339
|
+
if (wasShort && this.#activeBlocks.has(key) &&
|
|
4340
|
+
this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config!) === undefined) {
|
|
4341
|
+
this.#armBlockTimeout(sbn, packetId, catalogTrackName, this.#multicastWaitMs(config!))
|
|
4342
|
+
}
|
|
4343
|
+
}
|
|
4344
|
+
return { taken: true, recovered }
|
|
4345
|
+
}
|
|
4346
|
+
|
|
4347
|
+
/**
|
|
4348
|
+
* A block that holds every one of its `length` sources, received or
|
|
4349
|
+
* rebuilt by another instance, with at least one rebuilt, is recovered:
|
|
4350
|
+
* every packet of it was delivered, by its own arrival or by the instance
|
|
4351
|
+
* that rebuilt it, so nothing is routed. Returns whether it completed it.
|
|
4352
|
+
*/
|
|
4353
|
+
#completeWhenSourcesPresent(
|
|
4354
|
+
key: string,
|
|
4355
|
+
sbn: number,
|
|
4356
|
+
length: number,
|
|
4357
|
+
packetId: number,
|
|
4358
|
+
catalogTrackName: string | undefined,
|
|
4359
|
+
): boolean {
|
|
4360
|
+
const rebuilt = this.#blockRebuiltEsis.get(key)
|
|
4361
|
+
if (rebuilt === undefined || this.#completedBlocks.has(key)) return false
|
|
4362
|
+
let present = rebuilt.size
|
|
4363
|
+
for (const esi of this.#blockSourceEsis.get(key) ?? []) if (!rebuilt.has(esi)) present++
|
|
4364
|
+
if (present < length) return false
|
|
4365
|
+
this.#traceLifecycle('recovered', sbn, packetId, catalogTrackName)
|
|
4366
|
+
this.countRecovery(packetId, sbn, catalogTrackName)
|
|
4367
|
+
this.cancelBlockTimeout(sbn, packetId, catalogTrackName)
|
|
4368
|
+
if (catalogTrackName === undefined) {
|
|
4369
|
+
this.onBlockComplete?.(sbn, packetId)
|
|
4370
|
+
} else {
|
|
4371
|
+
this.onBlockComplete?.(sbn, packetId, catalogTrackName)
|
|
4372
|
+
}
|
|
4373
|
+
return true
|
|
4374
|
+
}
|
|
4375
|
+
|
|
4089
4376
|
/**
|
|
4090
4377
|
* fec-01 4.5: a reed-solomon repair packet whose SSB_length + RSB_length
|
|
4091
4378
|
* exceeds 255, or whose RS_ID is not below RSB_length, is discarded with the
|
|
@@ -4343,9 +4630,120 @@ export class FECManager {
|
|
|
4343
4630
|
this.#completeCleanBlock(blockKey, sbn, packetId, catalogTrackName)
|
|
4344
4631
|
return null
|
|
4345
4632
|
}
|
|
4633
|
+
// Its K' is known now: a block this repair shows short of it waits less.
|
|
4634
|
+
if (recovered === null) this.#shortenUnrecoverableWait(blockKey, sbn, packetId, catalogTrackName)
|
|
4346
4635
|
return recovered
|
|
4347
4636
|
}
|
|
4348
4637
|
|
|
4638
|
+
/**
|
|
4639
|
+
* A first-arrival multicast source, held or placed. A datagram flow keeps
|
|
4640
|
+
* its sources in send order, so one that moves the stream's newest source
|
|
4641
|
+
* position past a block leaves the sources that block still misses
|
|
4642
|
+
* reordered behind it at best: it shortens the wait of every block it
|
|
4643
|
+
* passed that only a late source can complete. MoQ is left out: its streams
|
|
4644
|
+
* can overtake one another, so a MoQ source shows nothing about the sources
|
|
4645
|
+
* sent before it.
|
|
4646
|
+
*/
|
|
4647
|
+
#noteMulticastSource(
|
|
4648
|
+
locator: IsoBlockLocator<IsoHeldSource>,
|
|
4649
|
+
ssId: number,
|
|
4650
|
+
packetId: number,
|
|
4651
|
+
catalogTrackName: string | undefined,
|
|
4652
|
+
): void {
|
|
4653
|
+
const previous = locator.newestSource
|
|
4654
|
+
if (!locator.noteSource(ssId) || previous === undefined) return
|
|
4655
|
+
// The blocks whose last SS_ID lies in [previous, ssId): this source
|
|
4656
|
+
// passed them and the previous newest one had not.
|
|
4657
|
+
for (const block of locator.blocksBetween((previous - 1) >>> 0, ssId)) {
|
|
4658
|
+
if (!serial32Precedes(serial32Add(block.start, block.length - 1), ssId)) continue
|
|
4659
|
+
this.#shortenUnrecoverableWait(
|
|
4660
|
+
this.#blockKey(block.start, packetId, catalogTrackName),
|
|
4661
|
+
block.start,
|
|
4662
|
+
packetId,
|
|
4663
|
+
catalogTrackName,
|
|
4664
|
+
)
|
|
4665
|
+
}
|
|
4666
|
+
}
|
|
4667
|
+
|
|
4668
|
+
/**
|
|
4669
|
+
* The wait of a block that only a late source can complete (BLO-52085): a
|
|
4670
|
+
* repair stated it, or it is a repair-less span longer than K (whose group
|
|
4671
|
+
* is empty, #openIsoSpan), its received sources plus every symbol its
|
|
4672
|
+
* repair group carries (RSB_length) are short of K' (the repair scheduler's
|
|
4673
|
+
* group-cannot-complete), and a later source of the stream has arrived, so
|
|
4674
|
+
* a source it misses is lost or reordered behind that one. The span, which
|
|
4675
|
+
* covers repair symbols paced after its sources, buys it nothing: it waits
|
|
4676
|
+
* the late-symbol allowance alone, the multicast wait less the span (the
|
|
4677
|
+
* catalog tolerance or the measured delivery gap). Undefined for any other
|
|
4678
|
+
* block.
|
|
4679
|
+
*
|
|
4680
|
+
* An installed keyframe overlay (keyframeOverlayTiming) may still rebuild
|
|
4681
|
+
* a RAP packet the block lost: a second FEC instance over the same packets
|
|
4682
|
+
* (draft-ramadan-moq-mmt-02 7.4), whose repair is paced across its own
|
|
4683
|
+
* span, unrelated to the base's. That packet can complete a stated block
|
|
4684
|
+
* (feedRebuiltSourceSymbol), and failing the block first would let the
|
|
4685
|
+
* release gate pass the keyframe, whose rebuild then lands stale. The
|
|
4686
|
+
* overlay repair of a packet the block lost goes out within the overlay's
|
|
4687
|
+
* span of that packet (fec-core-00 9.3), and the later source was sent
|
|
4688
|
+
* after it, so the block waits that span plus the larger of the allowance
|
|
4689
|
+
* and the overlay's own tolerance. An overlay that states no span (its
|
|
4690
|
+
* block may then span keyframes), or one whose wait is not shorter than
|
|
4691
|
+
* the whole multicast wait, leaves the block its whole wait: undefined.
|
|
4692
|
+
*/
|
|
4693
|
+
#lateSourceWaitMs(
|
|
4694
|
+
key: string,
|
|
4695
|
+
sbn: number,
|
|
4696
|
+
packetId: number,
|
|
4697
|
+
catalogTrackName: string | undefined,
|
|
4698
|
+
config: ResolvedFECTrackConfig,
|
|
4699
|
+
): number | undefined {
|
|
4700
|
+
const authoredLength = this.#blockAuthoredLengths.get(key)
|
|
4701
|
+
const rsbLength = this.#blockRsbLengths.get(key)
|
|
4702
|
+
if (authoredLength === undefined || rsbLength === undefined) return undefined
|
|
4703
|
+
// A source another instance rebuilt (feedRebuiltSourceSymbol) is one the
|
|
4704
|
+
// decoder holds: the group need only cover what neither delivered.
|
|
4705
|
+
let present = this.#blockSourceCounts.get(key) ?? 0
|
|
4706
|
+
const received = this.#blockSourceEsis.get(key)
|
|
4707
|
+
for (const esi of this.#blockRebuiltEsis.get(key) ?? []) if (!received?.has(esi)) present++
|
|
4708
|
+
if (present + rsbLength >= authoredLength) return undefined
|
|
4709
|
+
const newestSource = this.#isoLocators.get(this.#streamKey(packetId, catalogTrackName))?.newestSource
|
|
4710
|
+
if (newestSource === undefined || !serial32Precedes(serial32Add(sbn, authoredLength - 1), newestSource)) {
|
|
4711
|
+
return undefined
|
|
4712
|
+
}
|
|
4713
|
+
const waitMs = this.#multicastWaitMs(config)
|
|
4714
|
+
const allowanceMs = waitMs - config.interleaveDepthMs
|
|
4715
|
+
const overlay = this.keyframeOverlayTiming?.(packetId, catalogTrackName)
|
|
4716
|
+
if (overlay === undefined) return allowanceMs
|
|
4717
|
+
const overlaySpanMs = overlay.interleaveDepthMs ?? 0
|
|
4718
|
+
const overlayWaitMs = overlaySpanMs + Math.max(allowanceMs, overlay.reorderToleranceMs ?? 0)
|
|
4719
|
+
return overlaySpanMs > 0 && overlayWaitMs < waitMs ? overlayWaitMs : undefined
|
|
4720
|
+
}
|
|
4721
|
+
|
|
4722
|
+
/**
|
|
4723
|
+
* Bring an open block's wait in to its late-source wait, when it has one.
|
|
4724
|
+
* Never later than it is armed: only a source can complete such a block,
|
|
4725
|
+
* so a repair of its group (paced across the span) must not keep it open.
|
|
4726
|
+
*/
|
|
4727
|
+
#shortenUnrecoverableWait(
|
|
4728
|
+
key: string,
|
|
4729
|
+
sbn: number,
|
|
4730
|
+
packetId: number,
|
|
4731
|
+
catalogTrackName: string | undefined,
|
|
4732
|
+
): void {
|
|
4733
|
+
if (!this.#activeBlocks.has(key)) return
|
|
4734
|
+
const config = this.#trackConfigs.get(packetId)
|
|
4735
|
+
if (config === undefined) return
|
|
4736
|
+
const waitMs = this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, config)
|
|
4737
|
+
if (waitMs === undefined) return
|
|
4738
|
+
const armedAtMs = this.#blockWaitDeadlinesMs.get(key)
|
|
4739
|
+
this.#armBlockTimeout(
|
|
4740
|
+
sbn,
|
|
4741
|
+
packetId,
|
|
4742
|
+
catalogTrackName,
|
|
4743
|
+
armedAtMs === undefined ? waitMs : Math.min(waitMs, armedAtMs - this.#receiptNow()),
|
|
4744
|
+
)
|
|
4745
|
+
}
|
|
4746
|
+
|
|
4349
4747
|
/**
|
|
4350
4748
|
* Record a block's authored SSB_length from a repair symbol. Returns false,
|
|
4351
4749
|
* leaving the block unchanged, when the symbol contradicts the block: a
|
|
@@ -4485,7 +4883,8 @@ export class FECManager {
|
|
|
4485
4883
|
* the inactivity deadline on each symbol, records the symbol's in-band
|
|
4486
4884
|
* classification evidence, and marks the block clean when all of its
|
|
4487
4885
|
* authored source symbols arrived: the SSB_length a repair symbol declared,
|
|
4488
|
-
* otherwise K.
|
|
4886
|
+
* otherwise K. `held` marks a source held unplaced since it arrived and
|
|
4887
|
+
* placed only now (see #noteSbnSeen).
|
|
4489
4888
|
*
|
|
4490
4889
|
* Throws for a packetId that was never configured, so a classified block
|
|
4491
4890
|
* never reads the manager-global K or timeout.
|
|
@@ -4496,6 +4895,7 @@ export class FECManager {
|
|
|
4496
4895
|
catalogTrackName: string | undefined,
|
|
4497
4896
|
esi: number,
|
|
4498
4897
|
evidence: SourceSymbolEvidence,
|
|
4898
|
+
held = false,
|
|
4499
4899
|
): void {
|
|
4500
4900
|
const trackConfig = this.#trackConfigs.get(packetId)
|
|
4501
4901
|
if (trackConfig === undefined) {
|
|
@@ -4517,6 +4917,7 @@ export class FECManager {
|
|
|
4517
4917
|
'source',
|
|
4518
4918
|
evidence.packetSequenceNumber,
|
|
4519
4919
|
Number.isInteger(esi) ? (sbn + esi) >>> 0 : sbn,
|
|
4920
|
+
held,
|
|
4520
4921
|
)
|
|
4521
4922
|
|
|
4522
4923
|
// A source ESI at or past the block's authored SSB_length contradicts it;
|
|
@@ -4561,6 +4962,20 @@ export class FECManager {
|
|
|
4561
4962
|
this.#completeCleanBlock(key, sbn, packetId, catalogTrackName)
|
|
4562
4963
|
return
|
|
4563
4964
|
}
|
|
4965
|
+
// A late arrival can be the last source a block lacked besides those
|
|
4966
|
+
// another instance rebuilt (feedRebuiltSourceSymbol).
|
|
4967
|
+
if (
|
|
4968
|
+
this.#blockRebuiltEsis.has(key) &&
|
|
4969
|
+
this.#completeWhenSourcesPresent(
|
|
4970
|
+
key,
|
|
4971
|
+
sbn,
|
|
4972
|
+
this.#isoLocatorFor(packetId, catalogTrackName).blockAt(sbn)?.length ?? authoredLength,
|
|
4973
|
+
packetId,
|
|
4974
|
+
catalogTrackName,
|
|
4975
|
+
)
|
|
4976
|
+
) {
|
|
4977
|
+
return
|
|
4978
|
+
}
|
|
4564
4979
|
|
|
4565
4980
|
this.noteBlockActivity(sbn, packetId, catalogTrackName, true)
|
|
4566
4981
|
|
|
@@ -4580,7 +4995,9 @@ export class FECManager {
|
|
|
4580
4995
|
this.cancelBlockTimeout(sbn, packetId, catalogTrackName)
|
|
4581
4996
|
this.#blockSourceCounts.delete(key)
|
|
4582
4997
|
this.#blockSourceEsis.delete(key)
|
|
4998
|
+
this.#blockRebuiltEsis.delete(key)
|
|
4583
4999
|
this.#blockAuthoredLengths.delete(key)
|
|
5000
|
+
this.#isoSpanKeys.delete(key)
|
|
4584
5001
|
this.#blockRepairRsIds.delete(key)
|
|
4585
5002
|
this.#blockRsbLengths.delete(key)
|
|
4586
5003
|
// BLO-3323 L15: track which SBNs reached K source-symbol arrivals so the
|
|
@@ -4622,6 +5039,20 @@ export class FECManager {
|
|
|
4622
5039
|
return this.#receiptAtMs ?? performance.now()
|
|
4623
5040
|
}
|
|
4624
5041
|
|
|
5042
|
+
/**
|
|
5043
|
+
* The whole-ms delay of a timer for `deadlineMs` armed inside a receipt
|
|
5044
|
+
* scope: counted from the receipt time, as the timer of a symbol fed when
|
|
5045
|
+
* it was received was, less the whole ms since. So it fires on the tick
|
|
5046
|
+
* that timer would have, never later than a delay counted from now, and
|
|
5047
|
+
* its handler still re-arms a timer that fires before its deadline.
|
|
5048
|
+
* Counted from now, a deadline set from the receipt time is rounded up
|
|
5049
|
+
* from another fraction of a ms (BLO-52085).
|
|
5050
|
+
*/
|
|
5051
|
+
#receiptTimerDelayMs(deadlineMs: number, minMs: number): number {
|
|
5052
|
+
const receivedAtMs = this.#receiptAtMs!
|
|
5053
|
+
return Math.max(minMs, Math.ceil(deadlineMs - receivedAtMs) - Math.ceil(performance.now() - receivedAtMs))
|
|
5054
|
+
}
|
|
5055
|
+
|
|
4625
5056
|
/**
|
|
4626
5057
|
* A held packet admitted late arms from its (earlier) receipt time; that
|
|
4627
5058
|
* never pulls in a deadline later activity already armed. Outside a
|
|
@@ -4693,7 +5124,18 @@ export class FECManager {
|
|
|
4693
5124
|
)
|
|
4694
5125
|
}
|
|
4695
5126
|
|
|
4696
|
-
|
|
5127
|
+
// A block only a late source can complete waits the late-symbol
|
|
5128
|
+
// allowance from its own sources' activity; nothing else moves it later.
|
|
5129
|
+
if (!sourceProgress && this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) !== undefined) {
|
|
5130
|
+
this.#shortenUnrecoverableWait(key, sbn, packetId, catalogTrackName)
|
|
5131
|
+
return
|
|
5132
|
+
}
|
|
5133
|
+
this.#armBlockTimeout(
|
|
5134
|
+
sbn,
|
|
5135
|
+
packetId,
|
|
5136
|
+
catalogTrackName,
|
|
5137
|
+
this.#lateSourceWaitMs(key, sbn, packetId, catalogTrackName, trackConfig) ?? timeoutMs,
|
|
5138
|
+
)
|
|
4697
5139
|
}
|
|
4698
5140
|
|
|
4699
5141
|
#failBlock(
|
|
@@ -4702,6 +5144,9 @@ export class FECManager {
|
|
|
4702
5144
|
catalogTrackName?: string,
|
|
4703
5145
|
): void {
|
|
4704
5146
|
const key = this.#blockKey(sbn, packetId, catalogTrackName)
|
|
5147
|
+
const span: IsoSpanFailure | undefined = this.#isoSpanKeys.delete(key)
|
|
5148
|
+
? { length: this.#blockAuthoredLengths.get(key) ?? 0, sources: this.#blockSourceCounts.get(key) ?? 0 }
|
|
5149
|
+
: undefined
|
|
4705
5150
|
this.#traceLifecycle('failed', sbn, packetId, catalogTrackName)
|
|
4706
5151
|
this.#clearRepairDeadline(key)
|
|
4707
5152
|
this.#clearBlockTimer(key)
|
|
@@ -4711,6 +5156,7 @@ export class FECManager {
|
|
|
4711
5156
|
}
|
|
4712
5157
|
this.#blockSourceCounts.delete(key)
|
|
4713
5158
|
this.#blockSourceEsis.delete(key)
|
|
5159
|
+
this.#blockRebuiltEsis.delete(key)
|
|
4714
5160
|
this.#blockAuthoredLengths.delete(key)
|
|
4715
5161
|
this.#blockRepairRsIds.delete(key)
|
|
4716
5162
|
this.#blockRsbLengths.delete(key)
|
|
@@ -4720,7 +5166,8 @@ export class FECManager {
|
|
|
4720
5166
|
this.#markPathBlockComplete(sbn, packetId, catalogTrackName)
|
|
4721
5167
|
this.#fecStats.blocksFailed++
|
|
4722
5168
|
this.#statsForPacket(packetId).blocksFailed++
|
|
4723
|
-
this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass)
|
|
5169
|
+
if (span === undefined) this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass)
|
|
5170
|
+
else this.onBlockFailed?.(sbn, packetId, catalogTrackName, blockClass, span)
|
|
4724
5171
|
this.onBlockResolved?.(sbn, packetId, catalogTrackName)
|
|
4725
5172
|
}
|
|
4726
5173
|
|
|
@@ -4750,7 +5197,9 @@ export class FECManager {
|
|
|
4750
5197
|
this.#retireBlockClass(key, block.sbn, block.packetId, block.catalogTrackName)
|
|
4751
5198
|
this.#blockSourceCounts.delete(key)
|
|
4752
5199
|
this.#blockSourceEsis.delete(key)
|
|
5200
|
+
this.#blockRebuiltEsis.delete(key)
|
|
4753
5201
|
this.#blockAuthoredLengths.delete(key)
|
|
5202
|
+
this.#isoSpanKeys.delete(key)
|
|
4754
5203
|
this.#blockRepairRsIds.delete(key)
|
|
4755
5204
|
this.#blockRsbLengths.delete(key)
|
|
4756
5205
|
this.#clearBlockTimer(key)
|
|
@@ -4858,7 +5307,9 @@ export class FECManager {
|
|
|
4858
5307
|
this.#blockKeysBySbn.clear()
|
|
4859
5308
|
this.#blockSourceCounts.clear()
|
|
4860
5309
|
this.#blockSourceEsis.clear()
|
|
5310
|
+
this.#blockRebuiltEsis.clear()
|
|
4861
5311
|
this.#blockAuthoredLengths.clear()
|
|
5312
|
+
this.#isoSpanKeys.clear()
|
|
4862
5313
|
this.#blockRepairRsIds.clear()
|
|
4863
5314
|
this.#blockRsbLengths.clear()
|
|
4864
5315
|
this.#heldLayerStates.clear()
|
|
@@ -4883,6 +5334,7 @@ export class FECManager {
|
|
|
4883
5334
|
this.#blockAnchorsMs.clear()
|
|
4884
5335
|
this.#blockCatalogTrackNames.clear()
|
|
4885
5336
|
this.#classifiers.clear()
|
|
5337
|
+
this.#noSpanRaps.clear()
|
|
4886
5338
|
this.#streamGeometries.clear()
|
|
4887
5339
|
this.#failedBlocks.clear()
|
|
4888
5340
|
this.#resolvedBlockClasses.clear()
|