@blockcast/mmt-container 0.4.0 → 0.4.1-main.22841c1f0a2d
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 +37 -21
- 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 +2037 -881
- 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 +13 -1
- 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 +108 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +452 -66
- package/dist/fec-manager.js.map +4 -4
- 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/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 +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/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 +3677 -1213
- 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 +192 -0
- package/dist/mmtp-fec-session.d.ts.map +1 -0
- package/dist/mmtp-fec-session.js +640 -0
- package/dist/mmtp-fec-session.js.map +7 -0
- package/dist/mmtp-router.d.ts +69 -32
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +296 -192
- 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 +313 -124
- package/dist/multicast-auth-catalog.js.map +3 -3
- 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 +97 -11
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +1022 -527
- 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 +5 -3
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +3625 -1194
- 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/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 -18
- 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 +23 -1
- package/src/fec-manager.ts +366 -63
- package/src/fec-state.ts +11 -4
- package/src/fec-worker-setup.ts +30 -2
- package/src/held-layer-admission.ts +161 -0
- package/src/index.ts +32 -19
- package/src/iso-block-locator.ts +110 -7
- package/src/mmtp-container-parser.ts +75 -7
- package/src/mmtp-fec-session.ts +606 -0
- package/src/mmtp-router.ts +301 -240
- package/src/multicast-auth-catalog.ts +134 -238
- package/src/multicast-input.ts +148 -124
- package/src/multicast-manager.ts +271 -40
- package/src/multicast-transport.ts +17 -3
- package/src/no-modules.ts +8 -7
- 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/dist/manifest-auth-plan.d.ts +0 -30
- package/dist/manifest-auth-plan.d.ts.map +0 -1
- package/dist/manifest-auth-plan.js +0 -1266
- 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 -1209
- package/dist/source-auth.js.map +0 -7
- package/src/fec-codec.ts +0 -61
- package/src/manifest-auth-plan.ts +0 -107
- 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/src/fec-state.ts
CHANGED
|
@@ -13,7 +13,12 @@
|
|
|
13
13
|
// timers or elapsed time. The rules live here so the three players cannot
|
|
14
14
|
// disagree about precedence.
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
catalogFecDeclaresUnconfigurableInstance,
|
|
18
|
+
fecAlgorithmUnimplemented,
|
|
19
|
+
isFecBlockProfile,
|
|
20
|
+
isoBlockSpanUsable,
|
|
21
|
+
} from '@blockcast/mmt-base'
|
|
17
22
|
|
|
18
23
|
/** The optional elapsed-span rule lives in mmt-base beside the other catalog FEC rules. */
|
|
19
24
|
export { isoBlockSpanUsable }
|
|
@@ -103,7 +108,8 @@ function isPositiveSafeInteger(value: unknown): boolean {
|
|
|
103
108
|
* Whether one catalog `fec` block (a hang rendition's `fec` or an MSF/CMSF
|
|
104
109
|
* track's `fec`) declares an FEC instance a receiver can configure: source
|
|
105
110
|
* symbols per block (K) and a symbol size (T) are both positive integers, the
|
|
106
|
-
* algorithm is
|
|
111
|
+
* algorithm is neither `none` nor a token this receiver does not implement
|
|
112
|
+
* (`fecAlgorithmUnimplemented`, draft-ramadan-moq-fec-01 4), `blockProfile` names the implemented profile
|
|
107
113
|
* `iso-ssbg1-v1` (BLO-35597), and the block carries that profile's usable
|
|
108
114
|
* span field (`isoBlockSpanUsable`); zero/absence still permits in-band FEC. Total: it never throws, and answers false for
|
|
109
115
|
* any other value.
|
|
@@ -141,12 +147,13 @@ function isPositiveSafeInteger(value: unknown): boolean {
|
|
|
141
147
|
*/
|
|
142
148
|
export function catalogDeclaresFec(fec: unknown): boolean {
|
|
143
149
|
const block = recordOf(fec)
|
|
144
|
-
if (block === undefined || block['algorithm'] === 'none') return false
|
|
150
|
+
if (block === undefined || block['algorithm'] === 'none' || fecAlgorithmUnimplemented(block['algorithm'])) return false
|
|
145
151
|
return (
|
|
146
152
|
isPositiveSafeInteger(block['sourceSymbols']) &&
|
|
147
153
|
isPositiveSafeInteger(block['symbolSize']) &&
|
|
148
154
|
isFecBlockProfile(block['blockProfile']) &&
|
|
149
|
-
isoBlockSpanUsable(block)
|
|
155
|
+
isoBlockSpanUsable(block) &&
|
|
156
|
+
!catalogFecDeclaresUnconfigurableInstance(block)
|
|
150
157
|
)
|
|
151
158
|
}
|
|
152
159
|
|
package/src/fec-worker-setup.ts
CHANGED
|
@@ -16,10 +16,12 @@
|
|
|
16
16
|
import { parseFecBlockProfile, type FecBlockProfile } from '@blockcast/mmt-base'
|
|
17
17
|
import type { FecWorkerClient, FecTrackConfig } from '@blockcast/fec-worker'
|
|
18
18
|
import type { MulticastManager } from './multicast-manager.js'
|
|
19
|
+
import type { FecRepairLayer } from './fec-manager.js'
|
|
19
20
|
import {
|
|
20
21
|
deriveFecRetentionBlocks,
|
|
21
22
|
LOCAL_FEC_RETENTION_BLOCKS,
|
|
22
23
|
LOCAL_FEC_TIMEOUT_MS,
|
|
24
|
+
MAX_FEC_RETENTION_BLOCKS,
|
|
23
25
|
} from '@blockcast/mmt-fec'
|
|
24
26
|
import { computeFecDeliveryWindowMs } from './track-session.js'
|
|
25
27
|
|
|
@@ -47,6 +49,8 @@ export interface FecWorkerSetupOptions {
|
|
|
47
49
|
* Worker is created. Never defaulted, never inferred.
|
|
48
50
|
*/
|
|
49
51
|
fecBlockProfile: FecBlockProfile
|
|
52
|
+
/** The track's FEC scheme (`TrackFecParams.fecAlgorithm`). Defaults to RaptorQ. */
|
|
53
|
+
fecAlgorithm?: 'raptorq' | 'reed-solomon'
|
|
50
54
|
/**
|
|
51
55
|
* FEC K from catalog: the maximum SSB_length (K_max) of any block. Blocks
|
|
52
56
|
* are variable-length ssbg_mode1 blocks keyed by SS_Start, so K bounds
|
|
@@ -77,6 +81,13 @@ export interface FecWorkerSetupOptions {
|
|
|
77
81
|
mediaUnitDurationMs?: number
|
|
78
82
|
/** Optional repair track name (MoQ). Forwarded to FecTrackConfig. */
|
|
79
83
|
repairTrackName?: string
|
|
84
|
+
/**
|
|
85
|
+
* The catalog's base repair layers (`TrackFecParams.repairLayers`) and the
|
|
86
|
+
* layers this receiver holds (default `[0]`), for the fec-01 6.3.9 anchored
|
|
87
|
+
* RSB_length check. Absent layers: no check.
|
|
88
|
+
*/
|
|
89
|
+
fecRepairLayers?: readonly FecRepairLayer[]
|
|
90
|
+
heldRepairLayers?: readonly number[]
|
|
80
91
|
/** Audio sample rate (optional — audio tracks only). */
|
|
81
92
|
sampleRate?: number
|
|
82
93
|
/** Codec string (optional; "unknown" is acceptable for first setup). */
|
|
@@ -237,7 +248,7 @@ export async function setupFecWorkerForTrack(
|
|
|
237
248
|
trackType: opts.trackType,
|
|
238
249
|
framerate: opts.framerate,
|
|
239
250
|
sampleRate: opts.sampleRate,
|
|
240
|
-
algorithm: '
|
|
251
|
+
algorithm: opts.fecAlgorithm ?? 'raptorq',
|
|
241
252
|
blockProfile,
|
|
242
253
|
k: opts.fecK,
|
|
243
254
|
// P as this receiver joined it, not the catalog total: the worker snapshot
|
|
@@ -252,10 +263,10 @@ export async function setupFecWorkerForTrack(
|
|
|
252
263
|
relayBlockSigEnabled: false,
|
|
253
264
|
} as unknown as FecTrackConfig
|
|
254
265
|
|
|
255
|
-
client.configure(fecTrackConfig, rqWasm)
|
|
256
266
|
try {
|
|
257
267
|
opts.multicastManager.setFecWorker(opts.packetId, client, opts.trackType, {
|
|
258
268
|
blockProfile,
|
|
269
|
+
algorithm: opts.fecAlgorithm ?? 'raptorq',
|
|
259
270
|
k: opts.fecK,
|
|
260
271
|
symbolSize: opts.fecSymbolSize,
|
|
261
272
|
interleaveDepthMs: opts.fecInterleaveMs,
|
|
@@ -264,6 +275,8 @@ export async function setupFecWorkerForTrack(
|
|
|
264
275
|
// or classification.
|
|
265
276
|
...(hasCatalogTiming ? { fps: 1000 / opts.mediaUnitDurationMs! } : {}),
|
|
266
277
|
timeoutMs: deliveryWindowMs,
|
|
278
|
+
...(opts.fecRepairLayers ? { repairLayers: opts.fecRepairLayers } : {}),
|
|
279
|
+
...(opts.heldRepairLayers ? { heldLayers: opts.heldRepairLayers } : {}),
|
|
267
280
|
}, opts.trackName)
|
|
268
281
|
} catch (e) {
|
|
269
282
|
// The manager refused the registration (for example the stream still
|
|
@@ -276,6 +289,21 @@ export async function setupFecWorkerForTrack(
|
|
|
276
289
|
}
|
|
277
290
|
throw e
|
|
278
291
|
}
|
|
292
|
+
// The Worker retires a block `interleaveDepth` blocks behind the newest
|
|
293
|
+
// SS_ID it has seen, repair SS_Starts included, by the metric the manager's
|
|
294
|
+
// locator uses for its own horizon. Repairs ride their own group and can run
|
|
295
|
+
// blocks ahead of their media, so a shorter Worker horizon fails a block whose
|
|
296
|
+
// late sources the manager still waits for.
|
|
297
|
+
// ponytail: read once here; a keyframe cadence configured later widens only
|
|
298
|
+
// the manager's horizon (reconfigure the Worker if a player ever does that).
|
|
299
|
+
fecTrackConfig.interleaveDepth = Math.min(
|
|
300
|
+
MAX_FEC_RETENTION_BLOCKS,
|
|
301
|
+
Math.max(
|
|
302
|
+
interleaveDepthBlocks,
|
|
303
|
+
opts.multicastManager.fecManager.isoRetentionBlocksForPacket(opts.packetId) ?? 0,
|
|
304
|
+
),
|
|
305
|
+
)
|
|
306
|
+
client.configure(fecTrackConfig, rqWasm)
|
|
279
307
|
|
|
280
308
|
let disposed = false
|
|
281
309
|
return {
|
|
@@ -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 {
|
|
@@ -121,7 +117,7 @@ export {
|
|
|
121
117
|
} from './loc.js'
|
|
122
118
|
|
|
123
119
|
// CARP Catalog Extensions (draft-law-ramadan-moq-carp-reliability §3-4)
|
|
124
|
-
// + Track Timing (draft-ramadan-moq-mmt-
|
|
120
|
+
// + Track Timing (draft-ramadan-moq-mmt-01 §4.4.2)
|
|
125
121
|
export {
|
|
126
122
|
type FecAlgorithm,
|
|
127
123
|
type FecCatalogConfig,
|
|
@@ -173,7 +169,7 @@ export {
|
|
|
173
169
|
} from './delivery-catalog.js'
|
|
174
170
|
|
|
175
171
|
// Multicast input contract — validator + builder for publisher-emitted
|
|
176
|
-
// catalogs (draft-ramadan-moq-multicast-
|
|
172
|
+
// catalogs (draft-ramadan-moq-multicast-01 §4.1, BLO-3323 A.1).
|
|
177
173
|
// `multicastFromEnv` is the env-var helper used by FFmpeg and the
|
|
178
174
|
// cast bridge (BLO-3337).
|
|
179
175
|
export {
|
|
@@ -265,8 +261,12 @@ export {
|
|
|
265
261
|
type WasmFecDecoder,
|
|
266
262
|
type FecStats,
|
|
267
263
|
type MulticastSymbolDelivery,
|
|
264
|
+
type UndelimitedIsoLoss,
|
|
268
265
|
type FecBlockResolution,
|
|
269
266
|
type RepairVia,
|
|
267
|
+
type FecRepairLayer,
|
|
268
|
+
type FecFailClosedReason,
|
|
269
|
+
type FecFailClosedEvent,
|
|
270
270
|
} from './fec-manager.js'
|
|
271
271
|
|
|
272
272
|
// MMTP Router (packet processing + frame routing)
|
|
@@ -325,14 +325,6 @@ export {
|
|
|
325
325
|
type WasmMmtpParserConfig,
|
|
326
326
|
} from './wasm-mmtp-container-parser.js'
|
|
327
327
|
|
|
328
|
-
// FEC Codec (generic, algorithm-pluggable)
|
|
329
|
-
export {
|
|
330
|
-
type FecCodec,
|
|
331
|
-
NoneCodec,
|
|
332
|
-
ReedSolomonCodec,
|
|
333
|
-
createFecCodec,
|
|
334
|
-
} from './fec-codec.js'
|
|
335
|
-
|
|
336
328
|
// Multicast Transport (SSM join/socket/watchdog)
|
|
337
329
|
export {
|
|
338
330
|
MulticastTransport,
|
|
@@ -554,6 +546,7 @@ export {
|
|
|
554
546
|
catalogFecUnavailable,
|
|
555
547
|
catalogFecAvailable,
|
|
556
548
|
catalogFecDeclaresUnconfigurableInstance,
|
|
549
|
+
fecAlgorithmUnimplemented,
|
|
557
550
|
locateCatalogFecSource,
|
|
558
551
|
type CatalogFecRole,
|
|
559
552
|
type CatalogFecSource,
|
|
@@ -616,10 +609,26 @@ export {
|
|
|
616
609
|
type NoFecCounters,
|
|
617
610
|
} from "./fec-state.js";
|
|
618
611
|
|
|
612
|
+
// In-band AL-FEC for one MMTP asset over a MoQT subscription, for a player
|
|
613
|
+
// that owns its own parser (the Shaka MSF MMTP packaging).
|
|
614
|
+
export {
|
|
615
|
+
MmtpFecSession,
|
|
616
|
+
type MmtpFecSessionCatalogFec,
|
|
617
|
+
type MmtpFecSessionConfig,
|
|
618
|
+
type MmtpFecSessionDecoder,
|
|
619
|
+
type MmtpFecSessionDecoderConstructor,
|
|
620
|
+
type MmtpFecSessionMixedPathStats,
|
|
621
|
+
type MmtpFecSessionPath,
|
|
622
|
+
type MmtpFecSessionPathCounts,
|
|
623
|
+
type MmtpFecSessionStats,
|
|
624
|
+
} from "./mmtp-fec-session.js";
|
|
625
|
+
|
|
619
626
|
export {
|
|
620
627
|
catalogAmtNetworkSource,
|
|
628
|
+
catalogAtsc3NetworkSource,
|
|
621
629
|
DEFAULT_AMT_RELAY_PORT,
|
|
622
630
|
type AmtNetworkSource,
|
|
631
|
+
type Atsc3NetworkSource,
|
|
623
632
|
type CatalogNetworkSource,
|
|
624
633
|
} from "./catalog-network-source.js";
|
|
625
634
|
|
|
@@ -634,7 +643,11 @@ export {
|
|
|
634
643
|
type RepairFetchPriority,
|
|
635
644
|
type RepairFetchRequest,
|
|
636
645
|
type RepairFetchTransport,
|
|
646
|
+
type RepairRangeFetchRequest,
|
|
647
|
+
type RepairRangeFetchTransport,
|
|
648
|
+
type RepairDeadlineBound,
|
|
637
649
|
type RepairPriorityReason,
|
|
650
|
+
type RepairSendMeasurement,
|
|
638
651
|
type RepairSkipReason,
|
|
639
652
|
type RepairSubscribeCallback,
|
|
640
653
|
type WireRepairFetchOptions,
|
package/src/iso-block-locator.ts
CHANGED
|
@@ -51,9 +51,15 @@ export type IsoRepairPlacement<T> =
|
|
|
51
51
|
readonly placed: readonly IsoPlacedSource<T>[]
|
|
52
52
|
/** The repair-less span this repair closed in front of `block`, if any. */
|
|
53
53
|
readonly span?: { readonly block: IsoBlockRange; readonly placed: readonly IsoPlacedSource<T>[] }
|
|
54
|
+
/**
|
|
55
|
+
* With `deferIncompleteGaps`: the SS_IDs in front of `block` whose every
|
|
56
|
+
* repair was lost and some source too, kept as a pending hole instead of
|
|
57
|
+
* a span (see `closeHolesWithin`). `lostSsId` is the highest missing one.
|
|
58
|
+
*/
|
|
59
|
+
readonly hole?: { readonly block: IsoBlockRange; readonly lostSsId: number }
|
|
54
60
|
}
|
|
55
61
|
/** Not a block this stream can use; the repair symbol is dropped. */
|
|
56
|
-
| { readonly status: 'conflict' | 'overlap' | 'stale'; readonly reason: string }
|
|
62
|
+
| { readonly status: 'conflict' | 'overlap' | 'stale' | 'ahead'; readonly reason: string }
|
|
57
63
|
|
|
58
64
|
/**
|
|
59
65
|
* Retention: the locator is never without one. Every call that can grow it
|
|
@@ -79,6 +85,15 @@ export class IsoBlockLocator<T> {
|
|
|
79
85
|
#retentionBlocks: number
|
|
80
86
|
#heldEvicted = 0
|
|
81
87
|
#newest: number | undefined
|
|
88
|
+
/** Pending holes (see `deferIncompleteGaps`): unstated, sources still held. */
|
|
89
|
+
readonly #holes: IsoBlockRange[] = []
|
|
90
|
+
/**
|
|
91
|
+
* Keep a gap that is missing a source as a pending hole rather than a span,
|
|
92
|
+
* so a repair FETCHed for it (draft-ramadan-moq-fec §7.5) can still state
|
|
93
|
+
* its blocks. Set only while a range repair scheduler is wired; its owner
|
|
94
|
+
* must close every hole it is told about (`closeHolesWithin`).
|
|
95
|
+
*/
|
|
96
|
+
deferIncompleteGaps = false
|
|
82
97
|
|
|
83
98
|
/**
|
|
84
99
|
* @param kMax the catalog maximum K (`sourceSymbols`), the bound on SSB_length.
|
|
@@ -168,6 +183,16 @@ export class IsoBlockLocator<T> {
|
|
|
168
183
|
return null
|
|
169
184
|
}
|
|
170
185
|
|
|
186
|
+
/** Number of pending holes. */
|
|
187
|
+
get holeCount(): number {
|
|
188
|
+
return this.#holes.length
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** The stated block (never a span) ending exactly at `end`. */
|
|
192
|
+
blockEndingAt(end: number): IsoBlockRange | undefined {
|
|
193
|
+
return this.#blocks.find((block) => !block.span && isoBlockEnd(block.start, block.length) === end)
|
|
194
|
+
}
|
|
195
|
+
|
|
171
196
|
/** The known block or span starting exactly at `start`. */
|
|
172
197
|
blockAt(start: number): IsoBlockRange | undefined {
|
|
173
198
|
return this.#blocks.find((block) => block.start === start)
|
|
@@ -192,6 +217,10 @@ export class IsoBlockLocator<T> {
|
|
|
192
217
|
coversBetween(a: number, b: number): boolean {
|
|
193
218
|
if (this.#coverageEnd === undefined) return false
|
|
194
219
|
if (!serial32Precedes(a, b) || serial32Distance(a, b) <= 1) return true
|
|
220
|
+
// A pending hole may still be stated by a FETCHed repair.
|
|
221
|
+
const first = (a + 1) >>> 0
|
|
222
|
+
const count = serial32Distance(a, b) - 1
|
|
223
|
+
if (this.#holes.some((hole) => isoRangesOverlap(first, count, hole.start, hole.length))) return false
|
|
195
224
|
// The last SS_ID strictly before b must precede the coverage end.
|
|
196
225
|
return serial32Precedes((b - 1) >>> 0, this.#coverageEnd)
|
|
197
226
|
}
|
|
@@ -225,6 +254,15 @@ export class IsoBlockLocator<T> {
|
|
|
225
254
|
* known block (a different length, or an overlap with another block or a
|
|
226
255
|
* span) fails closed: the repair symbol is dropped and no block changes.
|
|
227
256
|
* A newly stated block retires behind its SS_Start (see the class note).
|
|
257
|
+
* A block so far past `newest` that stating it would retire the position
|
|
258
|
+
* `newest` is refused as `ahead`. When `newest` is a placed block's SS_Start
|
|
259
|
+
* this is slightly conservative (retirement measures that block from its
|
|
260
|
+
* last SS_ID), dropping up to one block-length of repairs past the horizon
|
|
261
|
+
* until a source moves `newest`. Placing it would turn everything
|
|
262
|
+
* between into a repair-less span and leave every real repair behind it
|
|
263
|
+
* `stale`. Sources move `newest` (`hold`, `observe`), so after a real outage
|
|
264
|
+
* the first source back brings the next repair inside the horizon; until one
|
|
265
|
+
* arrives, a stream's repairs alone cannot pass it.
|
|
228
266
|
*/
|
|
229
267
|
placeRepair(start: number, length: number): IsoRepairPlacement<T> {
|
|
230
268
|
if (!Number.isSafeInteger(length) || length <= 0 || length > this.#kMax) {
|
|
@@ -243,6 +281,23 @@ export class IsoBlockLocator<T> {
|
|
|
243
281
|
}
|
|
244
282
|
return { status: 'placed', block: known, placed: [] }
|
|
245
283
|
}
|
|
284
|
+
const pending = this.#holes.find((h) => isoBlockContains(h.start, h.length, start))
|
|
285
|
+
if (pending !== undefined) {
|
|
286
|
+
if (!isoBlockContains(pending.start, pending.length, serial32Add(start, length - 1))) {
|
|
287
|
+
return { status: 'overlap', reason: `repair block ${start}+${length} runs past pending hole ${pending.start}+${pending.length}` }
|
|
288
|
+
}
|
|
289
|
+
// A FETCHed repair stated a block inside a pending hole: split the hole round it.
|
|
290
|
+
this.#holes.splice(this.#holes.indexOf(pending), 1)
|
|
291
|
+
const before = serial32Distance(pending.start, start)
|
|
292
|
+
const afterStart = isoBlockEnd(start, length)
|
|
293
|
+
const after = pending.length - before - length
|
|
294
|
+
if (before > 0) this.#holes.push({ start: pending.start, length: before, span: false })
|
|
295
|
+
if (after > 0) this.#holes.push({ start: afterStart, length: after, span: false })
|
|
296
|
+
const block: IsoBlockRange = { start, length, span: false }
|
|
297
|
+
const placed = this.#claim(block)
|
|
298
|
+
this.#blocks.push(block)
|
|
299
|
+
return { status: 'placed', block, placed }
|
|
300
|
+
}
|
|
246
301
|
for (const block of this.#blocks) {
|
|
247
302
|
if (
|
|
248
303
|
isoBlockContains(block.start, block.length, start) ||
|
|
@@ -254,7 +309,11 @@ export class IsoBlockLocator<T> {
|
|
|
254
309
|
}
|
|
255
310
|
}
|
|
256
311
|
}
|
|
312
|
+
if (this.#newest !== undefined && isoBlocksBehindLowerBound(this.#newest, start, this.#kMax) > this.#retentionBlocks) {
|
|
313
|
+
return { status: 'ahead', reason: `repair block ${start}+${length} is past the retention horizon ahead of ${this.#newest}` }
|
|
314
|
+
}
|
|
257
315
|
let span: { block: IsoBlockRange; placed: IsoPlacedSource<T>[] } | undefined
|
|
316
|
+
let hole: { block: IsoBlockRange; lostSsId: number } | undefined
|
|
258
317
|
if (this.#coverageEnd === undefined) {
|
|
259
318
|
// Reception starts at the first stated block. Held sources before it
|
|
260
319
|
// are the tail of blocks that began before the join: their range is
|
|
@@ -266,24 +325,57 @@ export class IsoBlockLocator<T> {
|
|
|
266
325
|
} else if (serial32Precedes(start, this.#coverageEnd)) {
|
|
267
326
|
return { status: 'stale', reason: `repair block ${start}+${length} precedes known coverage` }
|
|
268
327
|
} else if (start !== this.#coverageEnd) {
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
span:
|
|
328
|
+
const gap = { start: this.#coverageEnd, length: serial32Distance(this.#coverageEnd, start) }
|
|
329
|
+
const lostSsId = this.deferIncompleteGaps ? this.#highestMissing(gap.start, gap.length) : undefined
|
|
330
|
+
if (lostSsId !== undefined) {
|
|
331
|
+
const holeBlock: IsoBlockRange = { ...gap, span: false }
|
|
332
|
+
this.#holes.push(holeBlock)
|
|
333
|
+
hole = { block: holeBlock, lostSsId }
|
|
334
|
+
} else {
|
|
335
|
+
const spanBlock: IsoBlockRange = { ...gap, span: true }
|
|
336
|
+
span = { block: spanBlock, placed: this.#claim(spanBlock) }
|
|
337
|
+
this.#blocks.push(spanBlock)
|
|
273
338
|
}
|
|
274
|
-
span = { block: spanBlock, placed: this.#claim(spanBlock) }
|
|
275
|
-
this.#blocks.push(spanBlock)
|
|
276
339
|
}
|
|
277
340
|
const block: IsoBlockRange = { start, length, span: false }
|
|
278
341
|
const placed = this.#claim(block)
|
|
279
342
|
this.#blocks.push(block)
|
|
280
343
|
this.#coverageEnd = isoBlockEnd(start, length)
|
|
281
344
|
this.retireBehind(start)
|
|
345
|
+
if (hole !== undefined) return { status: 'placed', block, placed, hole }
|
|
282
346
|
return span === undefined
|
|
283
347
|
? { status: 'placed', block, placed }
|
|
284
348
|
: { status: 'placed', block, placed, span }
|
|
285
349
|
}
|
|
286
350
|
|
|
351
|
+
/**
|
|
352
|
+
* Turn every pending hole inside `[start, start + length)` into a
|
|
353
|
+
* repair-less span, claiming its held sources: its range FETCH ended, so
|
|
354
|
+
* nothing more will state its blocks. Returns the spans, in SS_ID order.
|
|
355
|
+
*/
|
|
356
|
+
closeHolesWithin(start: number, length: number): { block: IsoBlockRange; placed: IsoPlacedSource<T>[] }[] {
|
|
357
|
+
const closed: { block: IsoBlockRange; placed: IsoPlacedSource<T>[] }[] = []
|
|
358
|
+
for (const hole of [...this.#holes]) {
|
|
359
|
+
if (!isoBlockContains(start, length, hole.start)) continue
|
|
360
|
+
this.#holes.splice(this.#holes.indexOf(hole), 1)
|
|
361
|
+
const spanBlock: IsoBlockRange = { start: hole.start, length: hole.length, span: true }
|
|
362
|
+
closed.push({ block: spanBlock, placed: this.#claim(spanBlock) })
|
|
363
|
+
this.#blocks.push(spanBlock)
|
|
364
|
+
}
|
|
365
|
+
return closed.sort((x, y) => serial32Distance(start, x.block.start) - serial32Distance(start, y.block.start))
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** The highest SS_ID in the range no source is held for, or undefined when all are. */
|
|
369
|
+
#highestMissing(start: number, length: number): number | undefined {
|
|
370
|
+
// Every position past the held count cannot all be held: bounded scan.
|
|
371
|
+
const steps = Math.min(length, this.#held.size + 1)
|
|
372
|
+
for (let i = 1; i <= steps; i++) {
|
|
373
|
+
const ssId = serial32Add(start, length - i)
|
|
374
|
+
if (!this.#held.has(ssId)) return ssId
|
|
375
|
+
}
|
|
376
|
+
return undefined
|
|
377
|
+
}
|
|
378
|
+
|
|
287
379
|
/**
|
|
288
380
|
* Retire every block and span whose last SS_ID, and every held source,
|
|
289
381
|
* lies more than `retentionBlocks` blocks behind `position`, with the shared
|
|
@@ -302,6 +394,11 @@ export class IsoBlockLocator<T> {
|
|
|
302
394
|
this.#blocks.splice(i, 1)
|
|
303
395
|
}
|
|
304
396
|
}
|
|
397
|
+
for (let i = this.#holes.length - 1; i >= 0; i--) {
|
|
398
|
+
const hole = this.#holes[i]!
|
|
399
|
+
const last = serial32Add(hole.start, hole.length - 1)
|
|
400
|
+
if (isoBlocksBehindLowerBound(last, position, this.#kMax) > horizon) this.#holes.splice(i, 1)
|
|
401
|
+
}
|
|
305
402
|
for (const ssId of [...this.#held.keys()]) {
|
|
306
403
|
if (isoBlocksBehindLowerBound(ssId, position, this.#kMax) > horizon) this.#held.delete(ssId)
|
|
307
404
|
}
|
|
@@ -311,6 +408,7 @@ export class IsoBlockLocator<T> {
|
|
|
311
408
|
/** Forget everything (publisher restart, track reset). */
|
|
312
409
|
reset(): void {
|
|
313
410
|
this.#blocks.length = 0
|
|
411
|
+
this.#holes.length = 0
|
|
314
412
|
this.#held.clear()
|
|
315
413
|
this.#coverageEnd = undefined
|
|
316
414
|
this.#newest = undefined
|
|
@@ -327,3 +425,8 @@ export class IsoBlockLocator<T> {
|
|
|
327
425
|
return placed
|
|
328
426
|
}
|
|
329
427
|
}
|
|
428
|
+
|
|
429
|
+
/** Whether `[aStart, aStart + aLength)` and `[bStart, bStart + bLength)` share an SS_ID. */
|
|
430
|
+
function isoRangesOverlap(aStart: number, aLength: number, bStart: number, bLength: number): boolean {
|
|
431
|
+
return serial32Distance(aStart, bStart) < aLength || serial32Distance(bStart, aStart) < bLength
|
|
432
|
+
}
|