@blockcast/mmt-container 0.4.1 → 0.5.0-main.6f3380bce0c1
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 +2 -2
- package/dist/browser-runtime.js +3407 -376
- package/dist/browser-runtime.js.map +4 -4
- package/dist/cmcd-producer.d.ts +5 -1
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/delivery-catalog.js +18 -2
- package/dist/delivery-catalog.js.map +2 -2
- package/dist/fec-manager.d.ts +13 -16
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +137 -76
- package/dist/fec-manager.js.map +3 -3
- package/dist/held-layer-admission.d.ts +58 -0
- package/dist/held-layer-admission.d.ts.map +1 -0
- package/dist/held-layer-admission.js +105 -0
- package/dist/held-layer-admission.js.map +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +2682 -1023
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-fec-session.d.ts +36 -3
- package/dist/mmtp-fec-session.d.ts.map +1 -1
- package/dist/mmtp-fec-session.js +114 -5
- package/dist/mmtp-fec-session.js.map +3 -3
- package/dist/mmtp-router.d.ts +64 -28
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +286 -203
- package/dist/mmtp-router.js.map +2 -2
- package/dist/multicast-auth-catalog.d.ts +10 -2
- package/dist/multicast-auth-catalog.d.ts.map +1 -1
- package/dist/multicast-auth-catalog.js +422 -22
- package/dist/multicast-auth-catalog.js.map +4 -4
- package/dist/multicast-manager.d.ts +48 -9
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +3349 -354
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +4 -1
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +20 -3
- package/dist/multicast-transport.js.map +2 -2
- package/dist/no-modules.d.ts +1 -2
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +2668 -1007
- package/dist/no-modules.js.map +4 -4
- package/dist/repair-fetch.d.ts +10 -1
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +5 -2
- package/dist/repair-fetch.js.map +2 -2
- package/package.json +5 -14
- package/src/cmcd-producer.ts +6 -1
- package/src/fec-manager.ts +74 -127
- package/src/held-layer-admission.ts +161 -0
- package/src/index.ts +5 -9
- package/src/mmtp-fec-session.ts +76 -3
- package/src/mmtp-router.ts +341 -272
- package/src/multicast-auth-catalog.ts +81 -8
- package/src/multicast-manager.ts +189 -48
- package/src/multicast-transport.ts +6 -2
- package/src/no-modules.ts +1 -6
- package/src/repair-fetch.ts +24 -4
- package/dist/manifest-auth-plan.d.ts +0 -31
- package/dist/manifest-auth-plan.d.ts.map +0 -1
- package/dist/manifest-auth-plan.js +0 -426
- package/dist/manifest-auth-plan.js.map +0 -7
- package/dist/source-auth.d.ts +0 -2
- package/dist/source-auth.d.ts.map +0 -1
- package/dist/source-auth.js +0 -3912
- package/dist/source-auth.js.map +0 -7
- package/src/manifest-auth-plan.ts +0 -55
- package/src/source-auth.ts +0 -1
- package/test-vectors/generate-source-auth-fixture.mjs +0 -114
- package/test-vectors/source-auth-v1.json +0 -61
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockcast/mmt-container",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-main.6f3380bce0c1",
|
|
4
4
|
"description": "MMTP/LOC container parsing for MMT over MoQ and SSM",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -14,10 +14,6 @@
|
|
|
14
14
|
"import": "./dist/browser-runtime.js",
|
|
15
15
|
"types": "./dist/index.d.ts"
|
|
16
16
|
},
|
|
17
|
-
"./source-auth": {
|
|
18
|
-
"import": "./dist/source-auth.js",
|
|
19
|
-
"types": "./dist/source-auth.d.ts"
|
|
20
|
-
},
|
|
21
17
|
"./mfu": {
|
|
22
18
|
"import": "./dist/mfu-reassembler.js",
|
|
23
19
|
"types": "./dist/mfu-reassembler.d.ts"
|
|
@@ -102,10 +98,6 @@
|
|
|
102
98
|
"import": "./dist/multicast-auth-catalog.js",
|
|
103
99
|
"types": "./dist/multicast-auth-catalog.d.ts"
|
|
104
100
|
},
|
|
105
|
-
"./manifest-auth-plan": {
|
|
106
|
-
"import": "./dist/manifest-auth-plan.js",
|
|
107
|
-
"types": "./dist/manifest-auth-plan.d.ts"
|
|
108
|
-
},
|
|
109
101
|
"./catalog-validator": {
|
|
110
102
|
"import": "./dist/catalog-validator.js",
|
|
111
103
|
"types": "./dist/catalog-validator.d.ts"
|
|
@@ -166,17 +158,16 @@
|
|
|
166
158
|
"build": "tsc --emitDeclarationOnly && node build.mjs",
|
|
167
159
|
"dev": "tsc --watch",
|
|
168
160
|
"clean": "rm -rf dist",
|
|
169
|
-
"bench:source-auth": "node bench/source-auth-wasm.mjs",
|
|
170
161
|
"bench:amt-hot-path": "node --expose-gc --max-semi-space-size=64 bench/amt-hot-path.mjs",
|
|
171
162
|
"test:catalog-validator-public-api": "node test-vectors/catalog-validator-public-api.mjs",
|
|
172
163
|
"test": "vitest run",
|
|
173
164
|
"test:watch": "vitest"
|
|
174
165
|
},
|
|
175
166
|
"dependencies": {
|
|
176
|
-
"@blockcast/fec-worker": "
|
|
177
|
-
"@blockcast/mmt-base": "
|
|
178
|
-
"@blockcast/mmt-fec": "
|
|
179
|
-
"@blockcast/mmt-manifest-verify": "
|
|
167
|
+
"@blockcast/fec-worker": "0.5.0-main.6f3380bce0c1",
|
|
168
|
+
"@blockcast/mmt-base": "0.5.0-main.6f3380bce0c1",
|
|
169
|
+
"@blockcast/mmt-fec": "0.5.0-main.6f3380bce0c1",
|
|
170
|
+
"@blockcast/mmt-manifest-verify": "0.5.0-main.6f3380bce0c1",
|
|
180
171
|
"@noble/curves": "^1.9.7",
|
|
181
172
|
"@noble/hashes": "^1.8.0",
|
|
182
173
|
"ajv": "^8.17.1",
|
package/src/cmcd-producer.ts
CHANGED
|
@@ -14,13 +14,18 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import type { FecTrackStats } from '@blockcast/fec-worker'
|
|
17
|
-
import type { ManifestVerificationStats } from '@blockcast/mmt-manifest-verify'
|
|
18
17
|
import type { FecFailClosedReason } from './fec-manager.js'
|
|
19
18
|
|
|
20
19
|
// ---------------------------------------------------------------------------
|
|
21
20
|
// Types
|
|
22
21
|
// ---------------------------------------------------------------------------
|
|
23
22
|
|
|
23
|
+
/** Source-auth counters for CMCD: records verified, and drops per reason. */
|
|
24
|
+
export interface ManifestVerificationStats {
|
|
25
|
+
verified: number
|
|
26
|
+
failures: Record<string, number>
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
/** Transport state snapshot, built by the player wiring layer from SocketPool. */
|
|
25
30
|
export interface TransportSnapshot {
|
|
26
31
|
transport: 'native' | 'amt' | 'moq'
|
package/src/fec-manager.ts
CHANGED
|
@@ -46,6 +46,7 @@ import {
|
|
|
46
46
|
type TrackKind,
|
|
47
47
|
} from './block-policy.js'
|
|
48
48
|
|
|
49
|
+
import { HeldLayerAdmission, heldLayerAnchorHorizon, type FecFailClosedReason } from './held-layer-admission.js'
|
|
49
50
|
import type { MmtpDeliveryProvenance } from './mfu-reassembler.js'
|
|
50
51
|
import type {
|
|
51
52
|
FecWorkerClient,
|
|
@@ -291,21 +292,7 @@ export interface FecRepairLayer {
|
|
|
291
292
|
repairSymbols: number
|
|
292
293
|
}
|
|
293
294
|
|
|
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
|
-
}
|
|
295
|
+
export type { FecFailClosedReason } from './held-layer-admission.js'
|
|
309
296
|
|
|
310
297
|
/** A {@link FecFailClosedReason} with the stream it closed, as reported to the fail-closed handler. */
|
|
311
298
|
export interface FecFailClosedEvent extends FecFailClosedReason {
|
|
@@ -313,26 +300,6 @@ export interface FecFailClosedEvent extends FecFailClosedReason {
|
|
|
313
300
|
catalogTrackName: string | undefined
|
|
314
301
|
}
|
|
315
302
|
|
|
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
|
|
334
|
-
}
|
|
335
|
-
|
|
336
303
|
interface ResolvedFECTrackConfig {
|
|
337
304
|
blockProfile?: FecBlockProfile
|
|
338
305
|
algorithm?: 'raptorq' | 'reed-solomon'
|
|
@@ -544,7 +511,7 @@ export class FECManager {
|
|
|
544
511
|
// symbols its repair group carries. Same lifecycle as #blockRepairRsIds.
|
|
545
512
|
#blockRsbLengths = new Map<string, number>()
|
|
546
513
|
/** fec-01 6.3.9 anchor state per stream key, one entry per held layer. */
|
|
547
|
-
#heldLayerStates = new Map<string,
|
|
514
|
+
#heldLayerStates = new Map<string, HeldLayerAdmission>()
|
|
548
515
|
/** Streams whose FEC failed closed at runtime (fec-01 6.3.9). */
|
|
549
516
|
#fecFailClosed = new Map<string, FecFailClosedReason>()
|
|
550
517
|
#onFecFailClosed: ((event: FecFailClosedEvent) => void) | null = null
|
|
@@ -630,6 +597,9 @@ export class FECManager {
|
|
|
630
597
|
// Worker recovery emits all K source symbols. Track recovery once per block
|
|
631
598
|
// while routing only ESI slots that were absent from the direct source path.
|
|
632
599
|
#workerRecoveredBlocks = new Set<string>()
|
|
600
|
+
// Worker-recovered blocks a recovered packet of which admission refused,
|
|
601
|
+
// until the decode's final symbol (7.2.7: the block is unrecovered).
|
|
602
|
+
#refusedRecoveries = new Set<string>()
|
|
633
603
|
|
|
634
604
|
// How the multicast leg delivers symbols (see MulticastSymbolDelivery). The
|
|
635
605
|
// provider declares it per transport join; absence keeps datagram semantics.
|
|
@@ -833,7 +803,14 @@ export class FECManager {
|
|
|
833
803
|
| null = null
|
|
834
804
|
|
|
835
805
|
// Worker-path callbacks — async recovery and stats from FecWorkerClient.
|
|
836
|
-
|
|
806
|
+
/**
|
|
807
|
+
* A recovered source symbol. Return false when admission refused the
|
|
808
|
+
* packet it carries (bc-provenance v2, draft-ramadan-moq-multicast-01
|
|
809
|
+
* 7.2.7): the block is then unrecovered and stays open to its FEC deadline.
|
|
810
|
+
*/
|
|
811
|
+
onBlockRecovered:
|
|
812
|
+
| ((sbn: number, packetId: number, data: ArrayBuffer, meta: FrameMeta, catalogTrackName?: string) => boolean | void)
|
|
813
|
+
| null = null
|
|
837
814
|
onFecStatsUpdate: ((packetId: number, stats: FecTrackStats) => void) | null = null
|
|
838
815
|
|
|
839
816
|
#encodeTrackName(catalogTrackName: string): string {
|
|
@@ -978,6 +955,7 @@ export class FECManager {
|
|
|
978
955
|
this.#completedBlocks.delete(record.key)
|
|
979
956
|
this.#cleanlyCompletedBlocks.delete(record.key)
|
|
980
957
|
this.#workerRecoveredBlocks.delete(record.key)
|
|
958
|
+
this.#refusedRecoveries.delete(record.key)
|
|
981
959
|
// The policy's terminal ledgers describe the same terminal state and
|
|
982
960
|
// retire with it: a failed block must never outlive its failure record
|
|
983
961
|
// as 'complete' (that would hide a loss from the release gate).
|
|
@@ -2534,6 +2512,7 @@ export class FECManager {
|
|
|
2534
2512
|
resetSet(this.#cleanlyCompletedBlocks)
|
|
2535
2513
|
resetSet(this.#repairRequestedBlocks)
|
|
2536
2514
|
resetSet(this.#workerRecoveredBlocks)
|
|
2515
|
+
resetSet(this.#refusedRecoveries)
|
|
2537
2516
|
resetSet(this.#startupAlignedPackets)
|
|
2538
2517
|
resetSet(this.#startupPartialBlocks)
|
|
2539
2518
|
resetSet(this.#startupRepairReadyPackets)
|
|
@@ -2668,6 +2647,7 @@ export class FECManager {
|
|
|
2668
2647
|
dropSet(this.#cleanlyCompletedBlocks)
|
|
2669
2648
|
dropSet(this.#repairRequestedBlocks)
|
|
2670
2649
|
dropSet(this.#workerRecoveredBlocks)
|
|
2650
|
+
dropSet(this.#refusedRecoveries)
|
|
2671
2651
|
dropSet(this.#startupAlignedPackets)
|
|
2672
2652
|
dropSet(this.#startupPartialBlocks)
|
|
2673
2653
|
dropSet(this.#startupRepairReadyPackets)
|
|
@@ -3023,6 +3003,18 @@ export class FECManager {
|
|
|
3023
3003
|
blockAnchorAtMs(sbn: number, packetId: number, catalogTrackName?: string): number | undefined {
|
|
3024
3004
|
return this.#blockAnchorsMs.get(this.#blockKey(sbn, packetId, catalogTrackName))
|
|
3025
3005
|
}
|
|
3006
|
+
/**
|
|
3007
|
+
* How long ago (ms) the oldest open block of the stream, one with an FEC
|
|
3008
|
+
* deadline, took its first accepted symbol; undefined with none open.
|
|
3009
|
+
*/
|
|
3010
|
+
oldestOpenBlockAgeMs(packetId: number, catalogTrackName: string): number | undefined {
|
|
3011
|
+
let oldest = Infinity
|
|
3012
|
+
for (const key of this.#activeBlocks.keys()) {
|
|
3013
|
+
if (!this.#belongsToStream(key, packetId, catalogTrackName)) continue
|
|
3014
|
+
oldest = Math.min(oldest, this.#blockAnchorsMs.get(key) ?? Infinity)
|
|
3015
|
+
}
|
|
3016
|
+
return oldest === Infinity ? undefined : performance.now() - oldest
|
|
3017
|
+
}
|
|
3026
3018
|
/** Absolute fail deadline of a still-open block, or undefined. */
|
|
3027
3019
|
blockDeadlineAtMs(sbn: number, packetId: number, catalogTrackName?: string): number | undefined {
|
|
3028
3020
|
return this.#activeBlockDeadlinesMs.get(this.#blockKey(sbn, packetId, catalogTrackName))
|
|
@@ -3687,22 +3679,6 @@ export class FECManager {
|
|
|
3687
3679
|
const blockKey = this.#blockKey(meta.sbn, packetId, recoveredCatalogTrackName)
|
|
3688
3680
|
const cleanlyCompleted = this.#cleanlyCompletedBlocks.has(blockKey)
|
|
3689
3681
|
if (!cleanlyCompleted) {
|
|
3690
|
-
if (!this.#workerRecoveredBlocks.has(blockKey)) {
|
|
3691
|
-
this.#traceLifecycle(
|
|
3692
|
-
'recovered',
|
|
3693
|
-
meta.sbn,
|
|
3694
|
-
packetId,
|
|
3695
|
-
recoveredCatalogTrackName,
|
|
3696
|
-
)
|
|
3697
|
-
this.#workerRecoveredBlocks.add(blockKey)
|
|
3698
|
-
this.#fecStats.blocksRecovered++
|
|
3699
|
-
this.#statsForPacket(packetId).blocksRecovered++
|
|
3700
|
-
if (this.#workerRecoveredBlocks.size > 1000) {
|
|
3701
|
-
dropOldest(this.#workerRecoveredBlocks, 500)
|
|
3702
|
-
}
|
|
3703
|
-
this.#noteBlockRepaired(blockKey, meta.sbn, packetId, recoveredCatalogTrackName)
|
|
3704
|
-
}
|
|
3705
|
-
|
|
3706
3682
|
// RaptorQ returns the full K-symbol block, not only erased symbols.
|
|
3707
3683
|
// The direct path already parsed every source ESI in #seenSymbols;
|
|
3708
3684
|
// routing those symbols again injects duplicate MFU fragments and can
|
|
@@ -3710,23 +3686,46 @@ export class FECManager {
|
|
|
3710
3686
|
const symbolKey = `${blockKey}:${esi}`
|
|
3711
3687
|
if (!this.#seenSymbols.has(symbolKey)) {
|
|
3712
3688
|
this.#seenSymbols.add(symbolKey)
|
|
3713
|
-
this.onBlockRecovered?.(
|
|
3689
|
+
const admitted = this.onBlockRecovered?.(
|
|
3714
3690
|
meta.sbn,
|
|
3715
3691
|
packetId,
|
|
3716
3692
|
data,
|
|
3717
3693
|
meta,
|
|
3718
3694
|
recoveredCatalogTrackName,
|
|
3719
3695
|
)
|
|
3696
|
+
if (admitted === false) {
|
|
3697
|
+
this.#refusedRecoveries.add(blockKey)
|
|
3698
|
+
if (this.#refusedRecoveries.size > 1000) dropOldest(this.#refusedRecoveries, 500)
|
|
3699
|
+
}
|
|
3720
3700
|
}
|
|
3721
3701
|
}
|
|
3722
3702
|
|
|
3723
3703
|
// The worker emits recovered source symbols in ESI order. Complete the
|
|
3724
3704
|
// block only after its final authored slot so assemblers receive every
|
|
3725
3705
|
// missing symbol before their completion callback flushes buffered media.
|
|
3706
|
+
// A decode one of whose recovered packets admission refused recovered
|
|
3707
|
+
// nothing (7.2.7): the block stays open and fails at its FEC deadline.
|
|
3708
|
+
const refused = esi >= meta.ssbLength! - 1 && this.#refusedRecoveries.delete(blockKey)
|
|
3726
3709
|
if (
|
|
3727
3710
|
esi >= meta.ssbLength! - 1 &&
|
|
3711
|
+
!refused &&
|
|
3728
3712
|
!this.#completedBlocks.has(blockKey)
|
|
3729
3713
|
) {
|
|
3714
|
+
if (!cleanlyCompleted && !this.#workerRecoveredBlocks.has(blockKey)) {
|
|
3715
|
+
this.#traceLifecycle(
|
|
3716
|
+
'recovered',
|
|
3717
|
+
meta.sbn,
|
|
3718
|
+
packetId,
|
|
3719
|
+
recoveredCatalogTrackName,
|
|
3720
|
+
)
|
|
3721
|
+
this.#workerRecoveredBlocks.add(blockKey)
|
|
3722
|
+
this.#fecStats.blocksRecovered++
|
|
3723
|
+
this.#statsForPacket(packetId).blocksRecovered++
|
|
3724
|
+
if (this.#workerRecoveredBlocks.size > 1000) {
|
|
3725
|
+
dropOldest(this.#workerRecoveredBlocks, 500)
|
|
3726
|
+
}
|
|
3727
|
+
this.#noteBlockRepaired(blockKey, meta.sbn, packetId, recoveredCatalogTrackName)
|
|
3728
|
+
}
|
|
3730
3729
|
this.cancelBlockTimeout(meta.sbn, packetId, recoveredCatalogTrackName)
|
|
3731
3730
|
if (recoveredCatalogTrackName === undefined) {
|
|
3732
3731
|
this.onBlockComplete?.(meta.sbn, packetId)
|
|
@@ -4106,77 +4105,26 @@ export class FECManager {
|
|
|
4106
4105
|
const config = this.#trackConfigs.get(packetId)
|
|
4107
4106
|
const layers = config?.repairLayers
|
|
4108
4107
|
if (layers === undefined || layers.length === 0) return true
|
|
4109
|
-
|
|
4110
|
-
|
|
4108
|
+
let admission = this.#heldLayerStates.get(streamKey)
|
|
4109
|
+
if (admission === undefined) {
|
|
4110
|
+
admission = new HeldLayerAdmission(layers, config!.heldLayers)
|
|
4111
|
+
this.#heldLayerStates.set(streamKey, admission)
|
|
4111
4112
|
}
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
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
|
-
}
|
|
4113
|
+
const verdict = admission.admit(
|
|
4114
|
+
repairTrackName,
|
|
4115
|
+
ssStart,
|
|
4116
|
+
rsbLength,
|
|
4117
|
+
this.#layerAnchorHorizon(packetId),
|
|
4118
|
+
this.#sourceFrontiers.get(streamKey)?.sbn,
|
|
4119
|
+
)
|
|
4120
|
+
if (verdict === 'discard') return false
|
|
4121
|
+
if (verdict !== undefined) {
|
|
4122
|
+
this.#fecFailClosed.set(streamKey, verdict)
|
|
4123
|
+
this.#onFecFailClosed?.({ ...verdict, packetId, catalogTrackName })
|
|
4124
|
+
console.warn(
|
|
4125
|
+
`[FECManager] FEC failed closed (fec-01 6.3.9) packetId=${packetId} track=${catalogTrackName ?? '-'}: ${JSON.stringify(verdict)}`,
|
|
4126
|
+
)
|
|
4127
|
+
return false
|
|
4180
4128
|
}
|
|
4181
4129
|
return true
|
|
4182
4130
|
}
|
|
@@ -4187,11 +4135,9 @@ export class FECManager {
|
|
|
4187
4135
|
* times K, capped at 2^30 so compared serials stay inside one half-window.
|
|
4188
4136
|
*/
|
|
4189
4137
|
#layerAnchorHorizon(packetId: number): number {
|
|
4190
|
-
const cap = 0x40000000
|
|
4191
4138
|
let blocks: number | undefined
|
|
4192
4139
|
try { blocks = this.isoRetentionBlocksForPacket(packetId) } catch { blocks = undefined }
|
|
4193
|
-
|
|
4194
|
-
return blocks === undefined || k <= 0 ? cap : Math.min(cap, blocks * k)
|
|
4140
|
+
return heldLayerAnchorHorizon(blocks, this.#trackConfigs.get(packetId)?.k ?? 0)
|
|
4195
4141
|
}
|
|
4196
4142
|
|
|
4197
4143
|
/**
|
|
@@ -4778,6 +4724,7 @@ export class FECManager {
|
|
|
4778
4724
|
this.#cleanlyCompletedBlocks.clear()
|
|
4779
4725
|
this.#repairRequestedBlocks.clear()
|
|
4780
4726
|
this.#workerRecoveredBlocks.clear()
|
|
4727
|
+
this.#refusedRecoveries.clear()
|
|
4781
4728
|
this.#syncDecoderBlockOwners.clear()
|
|
4782
4729
|
this.#startupAlignedPackets.clear()
|
|
4783
4730
|
this.#startupPartialBlocks.clear()
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fec-01 6.3.9 receiver check (held-layer anchored RSB_length), in one
|
|
3
|
+
* place. FECManager and MmtpFecSession both run their repair packets through
|
|
4
|
+
* HeldLayerAdmission; neither restates the rule.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { serial32Distance, serial32Precedes } from '@blockcast/mmt-base'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Why a source track's FEC failed closed at runtime (fec-01 6.3.9): a repair
|
|
11
|
+
* packet stated an RSB_length below a held layer's total B_i on that layer's
|
|
12
|
+
* own repair track (`below_own_track_total`), or at or after the anchor, the
|
|
13
|
+
* earliest block in SS_Start serial order whose repair carried >= B_i
|
|
14
|
+
* (`below_anchored_total`). Repair for the track is refused from then on.
|
|
15
|
+
*/
|
|
16
|
+
export interface FecFailClosedReason {
|
|
17
|
+
code: 'below_own_track_total' | 'below_anchored_total'
|
|
18
|
+
layer: number
|
|
19
|
+
total: number
|
|
20
|
+
rsbLength: number
|
|
21
|
+
ssStart: number
|
|
22
|
+
anchor?: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** One repair layer as the catalog states it: B_i = rsIdOffset + repairSymbols. */
|
|
26
|
+
export interface HeldLayerInput {
|
|
27
|
+
layer: number
|
|
28
|
+
repairTrackName: string
|
|
29
|
+
rsIdOffset: number
|
|
30
|
+
repairSymbols: number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface HeldLayerState {
|
|
34
|
+
layer: number
|
|
35
|
+
repairTrackName: string
|
|
36
|
+
total: number
|
|
37
|
+
/** Earliest (serial order) block start whose repair carried >= total. */
|
|
38
|
+
anchor?: number
|
|
39
|
+
/** Latest (serial order) block start whose repair carried < total. */
|
|
40
|
+
latestBelow?: number
|
|
41
|
+
/** RSB_length that latestBelow's repair carried, for the fail-closed reason. */
|
|
42
|
+
latestBelowRsb?: number
|
|
43
|
+
/** Newest block start seen; anchor and latestBelow are retired behind it. */
|
|
44
|
+
newest?: number
|
|
45
|
+
/**
|
|
46
|
+
* The anchor fell behind the horizon, so no block that can still arrive
|
|
47
|
+
* precedes it: every later packet must carry >= total. Its serial is no
|
|
48
|
+
* longer compared, so SS_Start wrapping past it cannot misorder it.
|
|
49
|
+
*/
|
|
50
|
+
settled?: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The largest horizon compared, so every compared serial stays in one half-window. */
|
|
54
|
+
const HORIZON_CAP = 0x40000000
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* How far (in SS_Start symbols) behind the newest block a 6.3.9 anchor or
|
|
58
|
+
* below-total block can still matter: the iso retention in blocks times K,
|
|
59
|
+
* capped at 2^30. Unknown inputs give the cap.
|
|
60
|
+
*/
|
|
61
|
+
export function heldLayerAnchorHorizon(retentionBlocks: number | undefined, k: number): number {
|
|
62
|
+
return retentionBlocks === undefined || k <= 0 ? HORIZON_CAP : Math.min(HORIZON_CAP, retentionBlocks * k)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* fec-01 6.3.9 anchored state for one FEC instance's held layers. For each
|
|
67
|
+
* held layer i with total B_i = O_i + P_i: the anchor is the earliest block,
|
|
68
|
+
* in SS_Start serial order, whose repair carried RSB_length >= B_i. The
|
|
69
|
+
* instance fails closed on (a) a packet on layer i's own repair track (i > 0)
|
|
70
|
+
* below B_i, or (b) any packet of the instance at or after the anchor below
|
|
71
|
+
* B_i. Blocks before the anchor (pre-append) stay valid at the previous total.
|
|
72
|
+
* The result is not latched here: the caller owns what failing closed means.
|
|
73
|
+
*/
|
|
74
|
+
export class HeldLayerAdmission {
|
|
75
|
+
readonly #layerNames: ReadonlySet<string>
|
|
76
|
+
readonly #states: HeldLayerState[]
|
|
77
|
+
|
|
78
|
+
constructor(layers: readonly HeldLayerInput[], heldLayers: readonly number[] = [0]) {
|
|
79
|
+
const held = new Set(heldLayers)
|
|
80
|
+
this.#layerNames = new Set(layers.map((l) => l.repairTrackName))
|
|
81
|
+
this.#states = layers
|
|
82
|
+
.filter((l) => held.has(l.layer))
|
|
83
|
+
.map((l) => ({ layer: l.layer, repairTrackName: l.repairTrackName, total: l.rsIdOffset + l.repairSymbols }))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Judges one repair packet, after the 4.5 discards and the size check and
|
|
88
|
+
* before it places a block. `repairTrackName` is the subscribed repair
|
|
89
|
+
* track, never inferred from RS_ID; without it only (b) runs. A packet on a
|
|
90
|
+
* repair track the catalog does not list is `'discard'` and anchors nothing.
|
|
91
|
+
* `sourceFrontier` is the newest source SS_ID, if any: a repair more than
|
|
92
|
+
* `horizon` past it is judged without moving the anchored state.
|
|
93
|
+
*
|
|
94
|
+
* @returns undefined to admit, `'discard'`, or the fail-closed reason.
|
|
95
|
+
*/
|
|
96
|
+
admit(
|
|
97
|
+
repairTrackName: string | undefined,
|
|
98
|
+
ssStart: number,
|
|
99
|
+
rsbLength: number,
|
|
100
|
+
horizon: number,
|
|
101
|
+
sourceFrontier?: number,
|
|
102
|
+
): FecFailClosedReason | 'discard' | undefined {
|
|
103
|
+
if (repairTrackName !== undefined && !this.#layerNames.has(repairTrackName)) return 'discard'
|
|
104
|
+
// A repair may run ahead of the media, but one more than `horizon` past the
|
|
105
|
+
// source frontier must not move the held-layer state: advancing `newest` on
|
|
106
|
+
// it would retire every real anchor and skip this check until traffic caught
|
|
107
|
+
// up. Such a repair is still judged below the total: it is on its own track,
|
|
108
|
+
// or after any anchor by definition. With no anchor yet it says nothing.
|
|
109
|
+
// It is still admitted: in iso the frontier only moves when a repair places
|
|
110
|
+
// held sources, so dropping it would stall recovery after a long outage.
|
|
111
|
+
// IsoBlockLocator.placeRepair may still refuse the same repair as `ahead`:
|
|
112
|
+
// it measures from `newest`, which held sources move, not from this frontier.
|
|
113
|
+
const farAhead =
|
|
114
|
+
sourceFrontier !== undefined &&
|
|
115
|
+
serial32Precedes(sourceFrontier, ssStart) &&
|
|
116
|
+
serial32Distance(sourceFrontier, ssStart) > horizon
|
|
117
|
+
for (const state of this.#states) {
|
|
118
|
+
let code: FecFailClosedReason['code'] | undefined
|
|
119
|
+
if (farAhead) {
|
|
120
|
+
if (rsbLength < state.total) {
|
|
121
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = 'below_own_track_total'
|
|
122
|
+
else if (state.anchor !== undefined || state.settled) code = 'below_anchored_total'
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
// Serials more than `horizon` behind the newest block are retired, so
|
|
126
|
+
// every serial still compared sits inside one half-window and SS_Start
|
|
127
|
+
// wrapping on a long-running stream cannot reorder them.
|
|
128
|
+
if (state.newest === undefined || serial32Precedes(state.newest, ssStart)) state.newest = ssStart
|
|
129
|
+
const stale = (s: number) => serial32Distance(s, state.newest!) > horizon
|
|
130
|
+
if (state.latestBelow !== undefined && stale(state.latestBelow)) {
|
|
131
|
+
delete state.latestBelow
|
|
132
|
+
delete state.latestBelowRsb
|
|
133
|
+
}
|
|
134
|
+
if (state.anchor !== undefined && stale(state.anchor)) state.settled = true
|
|
135
|
+
if (rsbLength < state.total) {
|
|
136
|
+
if (state.layer > 0 && repairTrackName === state.repairTrackName) code = 'below_own_track_total'
|
|
137
|
+
else if (stale(ssStart)) continue // past retention: undecodable, anchors nothing
|
|
138
|
+
else if (state.settled || (state.anchor !== undefined && !serial32Precedes(ssStart, state.anchor))) code = 'below_anchored_total'
|
|
139
|
+
else if (state.latestBelow === undefined || serial32Precedes(state.latestBelow, ssStart)) {
|
|
140
|
+
state.latestBelow = ssStart
|
|
141
|
+
state.latestBelowRsb = rsbLength
|
|
142
|
+
}
|
|
143
|
+
} else if (!state.settled && !stale(ssStart)) {
|
|
144
|
+
if (state.anchor === undefined || serial32Precedes(ssStart, state.anchor)) state.anchor = ssStart
|
|
145
|
+
if (state.latestBelow !== undefined && !serial32Precedes(state.latestBelow, state.anchor)) {
|
|
146
|
+
code = 'below_anchored_total'
|
|
147
|
+
ssStart = state.latestBelow
|
|
148
|
+
rsbLength = state.latestBelowRsb!
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (code !== undefined) {
|
|
153
|
+
return {
|
|
154
|
+
code, layer: state.layer, total: state.total, rsbLength, ssStart,
|
|
155
|
+
...(state.anchor === undefined ? {} : { anchor: state.anchor }),
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return undefined
|
|
160
|
+
}
|
|
161
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -39,15 +39,11 @@ export {
|
|
|
39
39
|
export { isCompleteFmp4DataUnit } from './fmp4-completion.js'
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
//
|
|
43
|
-
// from the eager index barrel
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
// "Failed to resolve module specifier". No browser player uses source-auth.)
|
|
48
|
-
// Consumers that need it import the dedicated subpath: '@blockcast/mmt-container/source-auth'.
|
|
49
|
-
// The same rule covers the @blockcast/mmt-manifest-verify surface (ManifestVerifier et al.):
|
|
50
|
-
// import it from that package (or the subpath above) directly, never from this barrel.
|
|
42
|
+
// The bc-provenance v2 surface (@blockcast/mmt-manifest-verify) is intentionally
|
|
43
|
+
// NOT re-exported from the eager index barrel: it imports @noble/curves and
|
|
44
|
+
// @noble/hashes, bare specifiers the moq-lib / shred / moqtail players (which
|
|
45
|
+
// load the barrel as raw ESM via an import map) cannot resolve. Import it from
|
|
46
|
+
// that package directly. The router's provenance hooks take it by type only.
|
|
51
47
|
|
|
52
48
|
// H.264/AVC + H.265/HEVC Codec Utilities
|
|
53
49
|
export {
|