@blockcast/mmt-container 0.4.0-main.bb90ce9247fa → 0.4.0-main.bbdfdbf39ded
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -20
- package/dist/align.d.ts +24 -18
- package/dist/align.d.ts.map +1 -1
- package/dist/align.js +23 -4
- package/dist/align.js.map +2 -2
- package/dist/browser-runtime.js +1721 -705
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +72 -34
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +309 -204
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +15 -4
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +137 -50
- package/dist/catalog-fec-params.js.map +4 -4
- package/dist/catalog-network-source.d.ts +24 -2
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js +24 -1
- package/dist/catalog-network-source.js.map +3 -3
- 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/delivery-catalog.js +100 -230
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.d.ts +64 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +275 -62
- package/dist/fec-manager.js.map +4 -4
- package/dist/fec-state.d.ts +5 -3
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +34 -12
- package/dist/fec-state.js.map +4 -4
- package/dist/fec-worker-setup.d.ts +2 -0
- package/dist/fec-worker-setup.d.ts.map +1 -1
- package/dist/fec-worker-setup.js +15 -3
- package/dist/fec-worker-setup.js.map +3 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -8
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +29 -0
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +100 -17
- package/dist/iso-block-locator.js.map +4 -4
- package/dist/manifest-auth-plan.d.ts +26 -25
- package/dist/manifest-auth-plan.d.ts.map +1 -1
- package/dist/manifest-auth-plan.js +331 -1171
- package/dist/manifest-auth-plan.js.map +4 -4
- package/dist/mfu-reassembler.js +24 -13
- package/dist/mfu-reassembler.js.map +3 -3
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +96 -22
- package/dist/mmtp-container-parser.js.map +3 -3
- package/dist/mmtp-container-parser.no-modules.js +1138 -325
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +96 -22
- package/dist/mmtp-decode-pipeline.js.map +3 -3
- package/dist/mmtp-fec-session.d.ts +159 -0
- package/dist/mmtp-fec-session.d.ts.map +1 -0
- package/dist/mmtp-fec-session.js +531 -0
- package/dist/mmtp-fec-session.js.map +7 -0
- package/dist/mmtp-router.d.ts +31 -5
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +168 -22
- package/dist/mmtp-router.js.map +3 -3
- package/dist/multicast-auth-catalog.d.ts +86 -92
- package/dist/multicast-auth-catalog.d.ts.map +1 -1
- package/dist/multicast-auth-catalog.js +347 -132
- package/dist/multicast-auth-catalog.js.map +4 -4
- package/dist/multicast-input.d.ts +28 -6
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +293 -28
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +89 -5
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +730 -356
- 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 +111 -235
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +24 -13
- package/dist/multicast-unwrap.js.map +3 -3
- package/dist/no-modules.d.ts +4 -1
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +1087 -309
- 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 +159 -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 +22 -2
- package/dist/repair-layers.js.map +3 -3
- 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 +6 -3
- package/dist/signaling.js.map +3 -3
- package/dist/source-auth.js +2710 -7
- package/dist/source-auth.js.map +4 -4
- package/dist/switching-set-alignment.d.ts +1 -1
- package/dist/switching-set-alignment.js.map +1 -1
- package/dist/timestamp-codec.js +24 -13
- package/dist/timestamp-codec.js.map +3 -3
- package/dist/wasm-mfu-reassembler.js +3 -0
- package/dist/wasm-mfu-reassembler.js.map +3 -3
- package/dist/wasm-mmtp-container-parser.js +96 -22
- package/dist/wasm-mmtp-container-parser.js.map +3 -3
- package/package.json +6 -9
- package/schemas/catalog.schema.json +124 -37
- package/src/align.ts +52 -21
- package/src/carp-catalog.ts +163 -61
- package/src/catalog-fec-params.ts +66 -20
- package/src/catalog-network-source.ts +45 -2
- package/src/catalog-validator.ts +4 -11
- package/src/fec-manager.ts +239 -63
- package/src/fec-state.ts +14 -12
- package/src/fec-worker-setup.ts +20 -2
- package/src/index.ts +29 -10
- package/src/iso-block-locator.ts +97 -6
- package/src/manifest-auth-plan.ts +39 -91
- package/src/mmtp-container-parser.ts +75 -7
- package/src/mmtp-fec-session.ts +533 -0
- package/src/mmtp-router.ts +133 -5
- package/src/multicast-auth-catalog.ts +131 -238
- package/src/multicast-input.ts +119 -61
- package/src/multicast-manager.ts +258 -21
- package/src/multicast-transport.ts +17 -3
- package/src/no-modules.ts +7 -1
- package/src/phase14-catalog-override.ts +3 -3
- package/src/repair-fetch.ts +283 -39
- package/src/repair-layers.ts +22 -2
- package/src/sample-combiner.ts +15 -2
- package/src/signaling.ts +2 -2
- package/src/switching-set-alignment.ts +1 -1
- package/test-vectors/align.json +108 -32
- package/test-vectors/bc-provenance-v2.json +1526 -0
- package/test-vectors/catalog/README.md +65 -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-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 +2 -2
- 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 +30 -1
- package/test-vectors/catalog-multicast-auth-v1.json +38 -20
- package/test-vectors/catalog-validation.json +101 -5
- package/test-vectors/catalog-validator-public-api.mjs +14 -9
- package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
- package/dist/fec-codec.d.ts +0 -32
- package/dist/fec-codec.d.ts.map +0 -1
- package/dist/fec-codec.js +0 -47
- package/dist/fec-codec.js.map +0 -7
- package/src/fec-codec.ts +0 -61
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-band AL-FEC for one MMTP asset received over a MoQT subscription: the
|
|
3
|
+
* asset's source packets on its own track, its repair packets on the repair
|
|
4
|
+
* track the catalog names (`fec.repairTrack`). The same asset's packets can also
|
|
5
|
+
* arrive on the multicast group (native SSM or AMT) carrying it: the caller
|
|
6
|
+
* states each symbol's path, and a block fed on both -- multicast source
|
|
7
|
+
* symbols repaired from the MoQT repair track, say -- is counted as mixed-path
|
|
8
|
+
* under `stats.mixedPath`, never inferred. Built for a player that owns
|
|
9
|
+
* its own MMTP parser and wants nothing else of the multicast stack
|
|
10
|
+
* (MulticastManager, MmtpRouter, FECManager): the Shaka MSF MMTP packaging.
|
|
11
|
+
*
|
|
12
|
+
* The session is clock-free, like the reliable-MoQ reassembly policy it sits
|
|
13
|
+
* beside. A block is settled only by wire evidence: clean once every source
|
|
14
|
+
* the repair's SSB_length states has arrived, recovered when the decoder
|
|
15
|
+
* completes it, failed once the newest SS_ID has moved it past the decoder's
|
|
16
|
+
* retention. No timer and no arrival time decides a block's fate, so a repair
|
|
17
|
+
* that is merely late on its own subscription is never counted as a loss.
|
|
18
|
+
* The retention is derived from the catalog's `fecBlockBudgetMs`, and a
|
|
19
|
+
* catalog missing either input throws rather than defaulting.
|
|
20
|
+
*
|
|
21
|
+
* Every repair packet that cannot be used is counted under the reason it was
|
|
22
|
+
* refused, and every block ends under exactly one outcome, so a stream whose
|
|
23
|
+
* FEC is doing nothing can be told apart from one with nothing to repair.
|
|
24
|
+
*/
|
|
25
|
+
import { type FecBlockProfile } from '@blockcast/mmt-base';
|
|
26
|
+
/** The mmt-wasm `MmtFecDecoder` members the session drives. */
|
|
27
|
+
export interface MmtpFecSessionDecoder {
|
|
28
|
+
configure_params(k: number, symbolSize: number): void;
|
|
29
|
+
add_source(ssId: number, data: Uint8Array, timestamp: number): Uint8Array | null | undefined;
|
|
30
|
+
add_repair(ssStart: number, ssbLength: number, rsId: number, data: Uint8Array, timestamp: number): Uint8Array | null | undefined;
|
|
31
|
+
cleanup_by_ss_start(current: number): Uint32Array;
|
|
32
|
+
cleanup_blocks_detailed(ssStarts: Uint32Array): unknown;
|
|
33
|
+
free(): void;
|
|
34
|
+
}
|
|
35
|
+
/** `wasm_bindgen.MmtFecDecoder`, or a constructor of the same shape. */
|
|
36
|
+
export type MmtpFecSessionDecoderConstructor = new (interleaveDepth: number, blockProfile: string, algorithm?: string) => MmtpFecSessionDecoder;
|
|
37
|
+
/** The catalog `fec` fields the session reads. */
|
|
38
|
+
export interface MmtpFecSessionCatalogFec {
|
|
39
|
+
/** `raptorq` (the default when absent) or `reed-solomon`. */
|
|
40
|
+
algorithm?: unknown;
|
|
41
|
+
blockProfile?: unknown;
|
|
42
|
+
sourceSymbols?: unknown;
|
|
43
|
+
symbolSize?: unknown;
|
|
44
|
+
interleaveDepthMs?: unknown;
|
|
45
|
+
reorderToleranceMs?: unknown;
|
|
46
|
+
}
|
|
47
|
+
export interface MmtpFecSessionConfig {
|
|
48
|
+
/** The source track's catalog `fec` block. */
|
|
49
|
+
fec: MmtpFecSessionCatalogFec;
|
|
50
|
+
/** Builds the RaptorQ decoder, normally `wasm_bindgen.MmtFecDecoder`. */
|
|
51
|
+
Decoder: MmtpFecSessionDecoderConstructor;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The path a symbol arrived on: its MoQT subscription, or the multicast
|
|
55
|
+
* group (native SSM or AMT) carrying the same asset. The caller states it;
|
|
56
|
+
* the session never infers it.
|
|
57
|
+
*/
|
|
58
|
+
export type MmtpFecSessionPath = 'moq' | 'multicast';
|
|
59
|
+
/** A count per path. */
|
|
60
|
+
export interface MmtpFecSessionPathCounts {
|
|
61
|
+
moq: number;
|
|
62
|
+
multicast: number;
|
|
63
|
+
}
|
|
64
|
+
/** How the settled blocks that were fed on both paths ended. */
|
|
65
|
+
export interface MmtpFecSessionMixedPathStats {
|
|
66
|
+
clean: number;
|
|
67
|
+
recovered: number;
|
|
68
|
+
failed: number;
|
|
69
|
+
released: number;
|
|
70
|
+
}
|
|
71
|
+
/** How the session's blocks and packets ended so far. */
|
|
72
|
+
export interface MmtpFecSessionStats {
|
|
73
|
+
/** Source symbols fed, counting each SS_ID once. */
|
|
74
|
+
sourceSymbols: number;
|
|
75
|
+
/** Repair symbols accepted for decoding. */
|
|
76
|
+
repairSymbols: number;
|
|
77
|
+
/** Blocks whose every source arrived. */
|
|
78
|
+
blocksClean: number;
|
|
79
|
+
/** Blocks with loss that the decoder completed. */
|
|
80
|
+
blocksRecovered: number;
|
|
81
|
+
/** Blocks with loss the decoder could not complete before retiring them. */
|
|
82
|
+
blocksFailed: number;
|
|
83
|
+
/** Blocks still unsettled when the session was released. */
|
|
84
|
+
blocksReleased: number;
|
|
85
|
+
/** Source packets the session recovered and handed back. */
|
|
86
|
+
packetsRecovered: number;
|
|
87
|
+
/** Source packets of failed blocks that never arrived and were not recovered. */
|
|
88
|
+
packetsLost: number;
|
|
89
|
+
/**
|
|
90
|
+
* Packets the session could not use, keyed by reason. Two reasons are not
|
|
91
|
+
* loss and belong in no loss tally. `repair:block-settled` counts the
|
|
92
|
+
* repair symbols of a block that had already settled, which on a healthy
|
|
93
|
+
* stream is every repair symbol of a block after the first.
|
|
94
|
+
* `source:decoder-refused` counts source packets the decoder threw on:
|
|
95
|
+
* they were delivered to the parser, only unprotected.
|
|
96
|
+
*/
|
|
97
|
+
dropped: Record<string, number>;
|
|
98
|
+
/** `sourceSymbols`, by the path each arrived on. */
|
|
99
|
+
sourceSymbolsByPath: MmtpFecSessionPathCounts;
|
|
100
|
+
/** `repairSymbols`, by the path each arrived on. */
|
|
101
|
+
repairSymbolsByPath: MmtpFecSessionPathCounts;
|
|
102
|
+
/**
|
|
103
|
+
* Blocks whose symbols the session used arrived on both paths -- for
|
|
104
|
+
* instance multicast source symbols and MoQT repair -- by how each ended.
|
|
105
|
+
* Each is also counted under its outcome above. A symbol the session
|
|
106
|
+
* refused, and a repair that arrived after its block was already clean,
|
|
107
|
+
* contributed nothing to its block and do not make it mixed.
|
|
108
|
+
*/
|
|
109
|
+
mixedPath: MmtpFecSessionMixedPathStats;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* One asset's in-band FEC state. See the file comment.
|
|
113
|
+
*/
|
|
114
|
+
export declare class MmtpFecSession {
|
|
115
|
+
#private;
|
|
116
|
+
readonly blockProfile: FecBlockProfile;
|
|
117
|
+
readonly algorithm: 'raptorq' | 'reed-solomon';
|
|
118
|
+
readonly sourceSymbols: number;
|
|
119
|
+
readonly symbolSize: number;
|
|
120
|
+
/** The decoder's retention, in blocks, derived from the catalog budget. */
|
|
121
|
+
readonly retentionBlocks: number;
|
|
122
|
+
/**
|
|
123
|
+
* @throws when the catalog block lacks or misstates a field the session
|
|
124
|
+
* needs: the block profile, K, T, `interleaveDepthMs` or
|
|
125
|
+
* `reorderToleranceMs`. None is defaulted.
|
|
126
|
+
*/
|
|
127
|
+
constructor(config: MmtpFecSessionConfig);
|
|
128
|
+
/** True once release() ran. */
|
|
129
|
+
get released(): boolean;
|
|
130
|
+
get stats(): MmtpFecSessionStats;
|
|
131
|
+
/**
|
|
132
|
+
* Feeds one received source packet: the MMTP packet without its four-byte
|
|
133
|
+
* Source FEC Payload ID, under the SS_ID that ID stated. This is what
|
|
134
|
+
* MmtpContainerParser's onSourceSymbol() hands over. `path` is where it
|
|
135
|
+
* was received; a caller that only subscribes over MoQT can leave it out.
|
|
136
|
+
*
|
|
137
|
+
* @returns the protected packets of this packet's block that it recovered,
|
|
138
|
+
* in SS_ID order, for the caller to feed to its parser with
|
|
139
|
+
* `{skipFecPayloadId: true, recovered: true}`. Usually empty.
|
|
140
|
+
*/
|
|
141
|
+
addSource(ssId: number, packet: Uint8Array, path?: MmtpFecSessionPath): Uint8Array[];
|
|
142
|
+
/**
|
|
143
|
+
* Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
|
|
144
|
+
* 23008-1 C.5.3). A repair track carries one repair flow, so the first
|
|
145
|
+
* repair packet fixes its packet ID and a packet of any other is refused.
|
|
146
|
+
* `path` is where it was received, as for addSource().
|
|
147
|
+
*
|
|
148
|
+
* @returns the protected packets this repair symbol recovered, as for
|
|
149
|
+
* addSource().
|
|
150
|
+
*/
|
|
151
|
+
addRepair(packet: Uint8Array, path?: MmtpFecSessionPath): Uint8Array[];
|
|
152
|
+
/**
|
|
153
|
+
* Frees the decoder and every block. Blocks still unsettled are counted as
|
|
154
|
+
* released, not failed: nothing proved them unrecoverable. Idempotent;
|
|
155
|
+
* returns whether this call released anything.
|
|
156
|
+
*/
|
|
157
|
+
release(): boolean;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=mmtp-fec-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mmtp-fec-session.d.ts","sourceRoot":"","sources":["../src/mmtp-fec-session.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
// ../mmt-base/dist/mmtp.js
|
|
2
|
+
var MMTP_HEADER_SIZE = 12;
|
|
3
|
+
var MPU_HEADER_SIZE = 8;
|
|
4
|
+
var MPU_LENGTH_FIELD_SIZE = 2;
|
|
5
|
+
var MPU_HEADER_REMAINDER_SIZE = MPU_HEADER_SIZE - MPU_LENGTH_FIELD_SIZE;
|
|
6
|
+
var PACKET_TYPE_REPAIR = 3;
|
|
7
|
+
function parseMMTPHeader(buffer) {
|
|
8
|
+
if (buffer.length < MMTP_HEADER_SIZE) {
|
|
9
|
+
throw new Error(`MMTP packet too small: ${buffer.length} bytes`);
|
|
10
|
+
}
|
|
11
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
12
|
+
const version = buffer[0] >> 6 & 3;
|
|
13
|
+
if (version !== 0) {
|
|
14
|
+
throw new Error(`Unsupported MMTP version: ${version}`);
|
|
15
|
+
}
|
|
16
|
+
const fecType = buffer[0] >> 3 & 3;
|
|
17
|
+
const packetCounterFlag = (buffer[0] & 32) !== 0;
|
|
18
|
+
const extensionFlag = (buffer[0] & 2) !== 0;
|
|
19
|
+
const rapFlag = (buffer[0] & 1) === 1;
|
|
20
|
+
const packetType = buffer[1] & 63;
|
|
21
|
+
let offset = 2;
|
|
22
|
+
const packetId = view.getUint16(offset, false);
|
|
23
|
+
offset += 2;
|
|
24
|
+
const timestamp = BigInt(view.getUint32(offset, false));
|
|
25
|
+
offset += 4;
|
|
26
|
+
const sequenceNumber = view.getUint32(offset, false);
|
|
27
|
+
offset += 4;
|
|
28
|
+
let packetCounter;
|
|
29
|
+
if (packetCounterFlag) {
|
|
30
|
+
if (offset + 4 > buffer.length)
|
|
31
|
+
throw new Error("MMTP packet truncated in packet_counter");
|
|
32
|
+
packetCounter = view.getUint32(offset, false);
|
|
33
|
+
offset += 4;
|
|
34
|
+
}
|
|
35
|
+
let extension;
|
|
36
|
+
if (extensionFlag) {
|
|
37
|
+
if (offset + 4 > buffer.length)
|
|
38
|
+
throw new Error("MMTP packet truncated in header extension");
|
|
39
|
+
const type = view.getUint16(offset, false);
|
|
40
|
+
const length = view.getUint16(offset + 2, false);
|
|
41
|
+
offset += 4;
|
|
42
|
+
if (offset + length > buffer.length)
|
|
43
|
+
throw new Error("MMTP packet truncated in header extension value");
|
|
44
|
+
extension = { type, data: buffer.subarray(offset, offset + length) };
|
|
45
|
+
offset += length;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
version,
|
|
49
|
+
packetType,
|
|
50
|
+
packetId,
|
|
51
|
+
timestamp,
|
|
52
|
+
sequenceNumber,
|
|
53
|
+
payloadLength: buffer.length - offset,
|
|
54
|
+
fecType,
|
|
55
|
+
packetCounterFlag,
|
|
56
|
+
packetCounter,
|
|
57
|
+
extensionFlag,
|
|
58
|
+
extension,
|
|
59
|
+
headerLength: offset,
|
|
60
|
+
rapFlag
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
var REPAIR_FEC_PID_SIZE = 13;
|
|
64
|
+
function readRepairFecPayloadIdFields(mmtpPacket, parsedHeader) {
|
|
65
|
+
let header;
|
|
66
|
+
if (parsedHeader) {
|
|
67
|
+
header = parsedHeader;
|
|
68
|
+
} else {
|
|
69
|
+
try {
|
|
70
|
+
header = parseMMTPHeader(mmtpPacket);
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (header.packetType !== PACKET_TYPE_REPAIR || header.fecType !== 2)
|
|
76
|
+
return null;
|
|
77
|
+
const off = header.headerLength;
|
|
78
|
+
if (mmtpPacket.length < off + REPAIR_FEC_PID_SIZE)
|
|
79
|
+
return null;
|
|
80
|
+
const ssStart = (mmtpPacket[off] << 24 | mmtpPacket[off + 1] << 16 | mmtpPacket[off + 2] << 8 | mmtpPacket[off + 3]) >>> 0;
|
|
81
|
+
const rsbLength = mmtpPacket[off + 4] << 16 | mmtpPacket[off + 5] << 8 | mmtpPacket[off + 6];
|
|
82
|
+
const rsId = mmtpPacket[off + 7] << 16 | mmtpPacket[off + 8] << 8 | mmtpPacket[off + 9];
|
|
83
|
+
const ssbLength = mmtpPacket[off + 10] << 16 | mmtpPacket[off + 11] << 8 | mmtpPacket[off + 12];
|
|
84
|
+
return {
|
|
85
|
+
packetId: header.packetId,
|
|
86
|
+
ssStart,
|
|
87
|
+
rsbLength,
|
|
88
|
+
rsId,
|
|
89
|
+
ssbLength,
|
|
90
|
+
dataOffset: off + REPAIR_FEC_PID_SIZE
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function parseMoqRepairFrameWithHeader(frame, header) {
|
|
94
|
+
return moqRepairFrameFrom(frame, readRepairFecPayloadIdFields(frame, header));
|
|
95
|
+
}
|
|
96
|
+
function moqRepairFrameFrom(frame, repairId) {
|
|
97
|
+
if (!repairId)
|
|
98
|
+
return null;
|
|
99
|
+
const symbolData = frame.subarray(repairId.dataOffset);
|
|
100
|
+
if (repairId.rsbLength === 0 || repairId.ssbLength === 0 || repairId.rsId >= repairId.rsbLength || symbolData.length === 0)
|
|
101
|
+
return null;
|
|
102
|
+
return {
|
|
103
|
+
packetId: repairId.packetId,
|
|
104
|
+
ssStart: repairId.ssStart,
|
|
105
|
+
rsbLength: repairId.rsbLength,
|
|
106
|
+
rsId: repairId.rsId,
|
|
107
|
+
ssbLength: repairId.ssbLength,
|
|
108
|
+
symbolData
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ../mmt-base/dist/ntp-short.js
|
|
113
|
+
var NTP_SHORT_BITS = 32;
|
|
114
|
+
var NTP_SHORT_MODULUS = 2 ** NTP_SHORT_BITS;
|
|
115
|
+
var NTP_SHORT_HALF_RANGE = 2 ** (NTP_SHORT_BITS - 1);
|
|
116
|
+
|
|
117
|
+
// ../mmt-base/dist/serial-number.js
|
|
118
|
+
var SERIAL32_SPAN = 4294967296;
|
|
119
|
+
var SERIAL32_HALF = 2147483648;
|
|
120
|
+
function assertUint32(value, name) {
|
|
121
|
+
if (!Number.isInteger(value) || value < 0 || value >= SERIAL32_SPAN) {
|
|
122
|
+
throw new RangeError(`${name} must be a uint32 (got ${value})`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function serial32Add(s, n) {
|
|
126
|
+
assertUint32(s, "s");
|
|
127
|
+
if (!Number.isInteger(n) || n <= -SERIAL32_HALF || n >= SERIAL32_HALF) {
|
|
128
|
+
throw new RangeError(`serial addend must lie in (-2^31, 2^31) (got ${n})`);
|
|
129
|
+
}
|
|
130
|
+
return (s + n + SERIAL32_SPAN) % SERIAL32_SPAN;
|
|
131
|
+
}
|
|
132
|
+
function serial32Distance(from, to) {
|
|
133
|
+
return to - from >>> 0;
|
|
134
|
+
}
|
|
135
|
+
function serial32Precedes(a, b) {
|
|
136
|
+
const distance = serial32Distance(a, b);
|
|
137
|
+
return distance !== 0 && distance < SERIAL32_HALF;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ../mmt-base/dist/fec-block-profile.js
|
|
141
|
+
var FEC_BLOCK_PROFILES = Object.freeze([
|
|
142
|
+
"iso-ssbg1-v1"
|
|
143
|
+
]);
|
|
144
|
+
function isFecBlockProfile(value) {
|
|
145
|
+
return value === "iso-ssbg1-v1";
|
|
146
|
+
}
|
|
147
|
+
function parseFecBlockProfile(value, where) {
|
|
148
|
+
if (isFecBlockProfile(value))
|
|
149
|
+
return value;
|
|
150
|
+
if (value === void 0) {
|
|
151
|
+
throw new Error(`${where} is required: name the FEC block profile ("iso-ssbg1-v1")`);
|
|
152
|
+
}
|
|
153
|
+
throw new Error(`${where} must be "iso-ssbg1-v1" (got ${JSON.stringify(value)})`);
|
|
154
|
+
}
|
|
155
|
+
var SSBG1_LENGTH_FIELD_BYTES = 2;
|
|
156
|
+
function ssbg1MaxPacketLength(symbolSize) {
|
|
157
|
+
return symbolSize - SSBG1_LENGTH_FIELD_BYTES;
|
|
158
|
+
}
|
|
159
|
+
function ssbg1FitsSymbol(packetLength, symbolSize) {
|
|
160
|
+
return Number.isSafeInteger(packetLength) && packetLength >= 0 && packetLength <= ssbg1MaxPacketLength(symbolSize) && packetLength <= 65535;
|
|
161
|
+
}
|
|
162
|
+
function trimSsbg1SourceSymbol(symbol) {
|
|
163
|
+
if (symbol.byteLength < SSBG1_LENGTH_FIELD_BYTES)
|
|
164
|
+
return null;
|
|
165
|
+
const length = symbol[0] << 8 | symbol[1];
|
|
166
|
+
const end = SSBG1_LENGTH_FIELD_BYTES + length;
|
|
167
|
+
if (end > symbol.byteLength)
|
|
168
|
+
return null;
|
|
169
|
+
for (let i = end; i < symbol.byteLength; i++) {
|
|
170
|
+
if (symbol[i] !== 0)
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
return symbol.subarray(SSBG1_LENGTH_FIELD_BYTES, end);
|
|
174
|
+
}
|
|
175
|
+
function isoBlockContains(ssStart, ssbLength, ssId) {
|
|
176
|
+
return serial32Distance(ssStart, ssId) < ssbLength;
|
|
177
|
+
}
|
|
178
|
+
function isoBlocksBehindLowerBound(a, b, kMax) {
|
|
179
|
+
if (!Number.isSafeInteger(kMax) || kMax <= 0) {
|
|
180
|
+
throw new Error(`iso-ssbg1-v1 block horizon needs a positive maximum K (got ${kMax})`);
|
|
181
|
+
}
|
|
182
|
+
return serial32Precedes(a, b) ? Math.floor(serial32Distance(a, b) / kMax) : 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// ../mmt-base/dist/catalog-fec-source.js
|
|
186
|
+
var ALL_ROLES = Object.freeze(["video", "audio"]);
|
|
187
|
+
|
|
188
|
+
// src/mmtp-fec-session.ts
|
|
189
|
+
import { deriveFecRetentionBlocks, fecBlockBudgetMs } from "@blockcast/mmt-fec";
|
|
190
|
+
var PATH_BITS = { moq: 1, multicast: 2 };
|
|
191
|
+
var MIXED_PATHS = PATH_BITS.moq | PATH_BITS.multicast;
|
|
192
|
+
var MmtpFecSession = class {
|
|
193
|
+
#decoder;
|
|
194
|
+
/** Blocks a repair has defined and that are not settled yet, by SS_Start. */
|
|
195
|
+
#blocks = /* @__PURE__ */ new Map();
|
|
196
|
+
/** SS_Starts of settled blocks, so a later repair for one is refused. */
|
|
197
|
+
#settled = /* @__PURE__ */ new Set();
|
|
198
|
+
/**
|
|
199
|
+
* SS_IDs whose packet the parser has, with the PATH_BITS of the path it was
|
|
200
|
+
* received on, or 0 for one the session recovered.
|
|
201
|
+
*/
|
|
202
|
+
#have = /* @__PURE__ */ new Map();
|
|
203
|
+
#newest;
|
|
204
|
+
/** The newest SS_ID when the remembered SS_IDs were last pruned. */
|
|
205
|
+
#prunedAt;
|
|
206
|
+
#repairPacketId;
|
|
207
|
+
#stats = {
|
|
208
|
+
sourceSymbols: 0,
|
|
209
|
+
repairSymbols: 0,
|
|
210
|
+
blocksClean: 0,
|
|
211
|
+
blocksRecovered: 0,
|
|
212
|
+
blocksFailed: 0,
|
|
213
|
+
blocksReleased: 0,
|
|
214
|
+
packetsRecovered: 0,
|
|
215
|
+
packetsLost: 0,
|
|
216
|
+
dropped: {},
|
|
217
|
+
sourceSymbolsByPath: { moq: 0, multicast: 0 },
|
|
218
|
+
repairSymbolsByPath: { moq: 0, multicast: 0 },
|
|
219
|
+
mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 }
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* @throws when the catalog block lacks or misstates a field the session
|
|
223
|
+
* needs: the block profile, K, T, `interleaveDepthMs` or
|
|
224
|
+
* `reorderToleranceMs`. None is defaulted.
|
|
225
|
+
*/
|
|
226
|
+
constructor(config) {
|
|
227
|
+
const fec = config?.fec;
|
|
228
|
+
if (!fec || typeof fec !== "object") {
|
|
229
|
+
throw new Error("MmtpFecSession: the catalog fec block is required");
|
|
230
|
+
}
|
|
231
|
+
this.blockProfile = parseFecBlockProfile(fec.blockProfile, "fec.blockProfile");
|
|
232
|
+
if (fec.algorithm !== void 0 && fec.algorithm !== "raptorq" && fec.algorithm !== "reed-solomon") {
|
|
233
|
+
throw new Error(`MmtpFecSession: fec.algorithm ${JSON.stringify(fec.algorithm)} is not implemented`);
|
|
234
|
+
}
|
|
235
|
+
this.algorithm = fec.algorithm === "reed-solomon" ? "reed-solomon" : "raptorq";
|
|
236
|
+
this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, "fec.sourceSymbols");
|
|
237
|
+
this.symbolSize = requirePositiveInteger(fec.symbolSize, "fec.symbolSize");
|
|
238
|
+
const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, "fec.interleaveDepthMs");
|
|
239
|
+
const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, "fec.reorderToleranceMs");
|
|
240
|
+
this.retentionBlocks = deriveFecRetentionBlocks(
|
|
241
|
+
fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs),
|
|
242
|
+
interleaveDepthMs
|
|
243
|
+
);
|
|
244
|
+
if (typeof config.Decoder !== "function") {
|
|
245
|
+
throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
|
|
246
|
+
}
|
|
247
|
+
const decoder = new config.Decoder(this.retentionBlocks, this.blockProfile, this.algorithm);
|
|
248
|
+
try {
|
|
249
|
+
decoder.configure_params(this.sourceSymbols, this.symbolSize);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
decoder.free();
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
this.#decoder = decoder;
|
|
255
|
+
}
|
|
256
|
+
/** True once release() ran. */
|
|
257
|
+
get released() {
|
|
258
|
+
return this.#decoder === null;
|
|
259
|
+
}
|
|
260
|
+
get stats() {
|
|
261
|
+
return {
|
|
262
|
+
...this.#stats,
|
|
263
|
+
dropped: { ...this.#stats.dropped },
|
|
264
|
+
sourceSymbolsByPath: { ...this.#stats.sourceSymbolsByPath },
|
|
265
|
+
repairSymbolsByPath: { ...this.#stats.repairSymbolsByPath },
|
|
266
|
+
mixedPath: { ...this.#stats.mixedPath }
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Feeds one received source packet: the MMTP packet without its four-byte
|
|
271
|
+
* Source FEC Payload ID, under the SS_ID that ID stated. This is what
|
|
272
|
+
* MmtpContainerParser's onSourceSymbol() hands over. `path` is where it
|
|
273
|
+
* was received; a caller that only subscribes over MoQT can leave it out.
|
|
274
|
+
*
|
|
275
|
+
* @returns the protected packets of this packet's block that it recovered,
|
|
276
|
+
* in SS_ID order, for the caller to feed to its parser with
|
|
277
|
+
* `{skipFecPayloadId: true, recovered: true}`. Usually empty.
|
|
278
|
+
*/
|
|
279
|
+
addSource(ssId, packet, path = "moq") {
|
|
280
|
+
const decoder = this.#decoder;
|
|
281
|
+
if (!decoder) return this.#drop("source:released");
|
|
282
|
+
const pathBit = PATH_BITS[path];
|
|
283
|
+
if (!pathBit) return this.#drop("source:unknown-path");
|
|
284
|
+
if (!Number.isInteger(ssId) || ssId < 0 || ssId > 4294967295) return this.#drop("source:bad-ss-id");
|
|
285
|
+
if (!ssbg1FitsSymbol(packet.byteLength, this.symbolSize)) return this.#drop("source:exceeds-symbol");
|
|
286
|
+
if (this.#have.has(ssId)) return this.#drop("source:duplicate");
|
|
287
|
+
this.#have.set(ssId, pathBit);
|
|
288
|
+
this.#stats.sourceSymbols++;
|
|
289
|
+
this.#stats.sourceSymbolsByPath[path]++;
|
|
290
|
+
this.#noteNewest(ssId);
|
|
291
|
+
const start = this.#blockStartOf(ssId);
|
|
292
|
+
const block = start === void 0 ? void 0 : this.#blocks.get(start);
|
|
293
|
+
if (block) {
|
|
294
|
+
block.received++;
|
|
295
|
+
block.paths |= pathBit;
|
|
296
|
+
}
|
|
297
|
+
let output;
|
|
298
|
+
try {
|
|
299
|
+
output = decoder.add_source(ssId, packet, 0);
|
|
300
|
+
} catch {
|
|
301
|
+
this.#drop("source:decoder-refused");
|
|
302
|
+
output = void 0;
|
|
303
|
+
}
|
|
304
|
+
const recovered = [];
|
|
305
|
+
if (start !== void 0 && block) {
|
|
306
|
+
if (output) {
|
|
307
|
+
recovered.push(...this.#settleDecoded(start, block, output));
|
|
308
|
+
} else if (block.received >= block.ssbLength) {
|
|
309
|
+
this.#settleClean(start);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
this.#retireBehindHorizon();
|
|
313
|
+
return recovered;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
|
|
317
|
+
* 23008-1 C.5.3). A repair track carries one repair flow, so the first
|
|
318
|
+
* repair packet fixes its packet ID and a packet of any other is refused.
|
|
319
|
+
* `path` is where it was received, as for addSource().
|
|
320
|
+
*
|
|
321
|
+
* @returns the protected packets this repair symbol recovered, as for
|
|
322
|
+
* addSource().
|
|
323
|
+
*/
|
|
324
|
+
addRepair(packet, path = "moq") {
|
|
325
|
+
const decoder = this.#decoder;
|
|
326
|
+
if (!decoder) return this.#drop("repair:released");
|
|
327
|
+
const pathBit = PATH_BITS[path];
|
|
328
|
+
if (!pathBit) return this.#drop("repair:unknown-path");
|
|
329
|
+
let header;
|
|
330
|
+
try {
|
|
331
|
+
header = parseMMTPHeader(packet);
|
|
332
|
+
} catch {
|
|
333
|
+
return this.#drop("repair:malformed");
|
|
334
|
+
}
|
|
335
|
+
const frame = parseMoqRepairFrameWithHeader(packet, header);
|
|
336
|
+
if (!frame) return this.#drop("repair:malformed");
|
|
337
|
+
if (this.#repairPacketId === void 0) {
|
|
338
|
+
this.#repairPacketId = frame.packetId;
|
|
339
|
+
} else if (frame.packetId !== this.#repairPacketId) {
|
|
340
|
+
return this.#drop("repair:foreign-packet-id");
|
|
341
|
+
}
|
|
342
|
+
if (frame.symbolData.byteLength !== this.symbolSize) return this.#drop("repair:symbol-size");
|
|
343
|
+
if (frame.ssbLength > this.sourceSymbols) return this.#drop("repair:ssb-length");
|
|
344
|
+
if (this.algorithm === "reed-solomon" && frame.ssbLength + frame.rsbLength > 255) {
|
|
345
|
+
return this.#drop("repair:rs-block-length");
|
|
346
|
+
}
|
|
347
|
+
const start = frame.ssStart;
|
|
348
|
+
let block = this.#blocks.get(start);
|
|
349
|
+
if (block && block.ssbLength !== frame.ssbLength) return this.#drop("repair:conflicting-ssb-length");
|
|
350
|
+
if (block?.rsIds.has(frame.rsId)) return this.#drop("repair:duplicate");
|
|
351
|
+
if (!block) {
|
|
352
|
+
if (this.#settled.has(start)) return this.#drop("repair:block-settled");
|
|
353
|
+
if (this.#behindHorizon(start)) return this.#drop("repair:behind-horizon");
|
|
354
|
+
block = { ssbLength: frame.ssbLength, received: 0, paths: 0, rsIds: /* @__PURE__ */ new Set() };
|
|
355
|
+
this.#countHeld(start, block);
|
|
356
|
+
this.#blocks.set(start, block);
|
|
357
|
+
}
|
|
358
|
+
this.#noteNewest(serial32Add(start, frame.ssbLength - 1));
|
|
359
|
+
if (block.received >= block.ssbLength) {
|
|
360
|
+
this.#settleClean(start);
|
|
361
|
+
this.#retireBehindHorizon();
|
|
362
|
+
return [];
|
|
363
|
+
}
|
|
364
|
+
let output;
|
|
365
|
+
try {
|
|
366
|
+
output = decoder.add_repair(start, frame.ssbLength, frame.rsId, frame.symbolData, 0);
|
|
367
|
+
} catch {
|
|
368
|
+
return this.#drop("repair:decoder-refused");
|
|
369
|
+
}
|
|
370
|
+
block.rsIds.add(frame.rsId);
|
|
371
|
+
this.#stats.repairSymbols++;
|
|
372
|
+
this.#stats.repairSymbolsByPath[path]++;
|
|
373
|
+
block.paths |= pathBit;
|
|
374
|
+
const recovered = output ? this.#settleDecoded(start, block, output) : [];
|
|
375
|
+
this.#retireBehindHorizon();
|
|
376
|
+
return recovered;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Frees the decoder and every block. Blocks still unsettled are counted as
|
|
380
|
+
* released, not failed: nothing proved them unrecoverable. Idempotent;
|
|
381
|
+
* returns whether this call released anything.
|
|
382
|
+
*/
|
|
383
|
+
release() {
|
|
384
|
+
const decoder = this.#decoder;
|
|
385
|
+
if (!decoder) return false;
|
|
386
|
+
this.#decoder = null;
|
|
387
|
+
this.#stats.blocksReleased += this.#blocks.size;
|
|
388
|
+
for (const block of this.#blocks.values()) this.#noteMixed(block, "released");
|
|
389
|
+
this.#blocks.clear();
|
|
390
|
+
this.#settled.clear();
|
|
391
|
+
this.#have.clear();
|
|
392
|
+
decoder.free();
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
#drop(reason) {
|
|
396
|
+
this.#stats.dropped[reason] = (this.#stats.dropped[reason] ?? 0) + 1;
|
|
397
|
+
return [];
|
|
398
|
+
}
|
|
399
|
+
#noteNewest(ssId) {
|
|
400
|
+
if (this.#newest === void 0 || serial32Precedes(this.#newest, ssId)) this.#newest = ssId;
|
|
401
|
+
}
|
|
402
|
+
#blockStartOf(ssId) {
|
|
403
|
+
for (const [start, block] of this.#blocks) {
|
|
404
|
+
if (isoBlockContains(start, block.ssbLength, ssId)) return start;
|
|
405
|
+
}
|
|
406
|
+
return void 0;
|
|
407
|
+
}
|
|
408
|
+
/** Counts the sources of a new block the parser already has, and their paths. */
|
|
409
|
+
#countHeld(start, block) {
|
|
410
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
411
|
+
const pathBit = this.#have.get(serial32Add(start, i));
|
|
412
|
+
if (pathBit === void 0) continue;
|
|
413
|
+
block.received++;
|
|
414
|
+
block.paths |= pathBit;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
#noteMixed(block, outcome) {
|
|
418
|
+
if ((block.paths & MIXED_PATHS) === MIXED_PATHS) this.#stats.mixedPath[outcome]++;
|
|
419
|
+
}
|
|
420
|
+
/** The decoder's own rule: more than its retention behind, counted from below. */
|
|
421
|
+
#behindHorizon(start) {
|
|
422
|
+
const newest = this.#newest;
|
|
423
|
+
if (newest === void 0) return false;
|
|
424
|
+
return isoBlocksBehindLowerBound(start, newest, this.sourceSymbols) > this.retentionBlocks;
|
|
425
|
+
}
|
|
426
|
+
#settle(start) {
|
|
427
|
+
this.#blocks.delete(start);
|
|
428
|
+
this.#settled.add(start);
|
|
429
|
+
}
|
|
430
|
+
#settleClean(start) {
|
|
431
|
+
const block = this.#blocks.get(start);
|
|
432
|
+
if (!block) return;
|
|
433
|
+
this.#settle(start);
|
|
434
|
+
this.#stats.blocksClean++;
|
|
435
|
+
this.#noteMixed(block, "clean");
|
|
436
|
+
try {
|
|
437
|
+
this.#decoder?.cleanup_blocks_detailed(Uint32Array.of(start));
|
|
438
|
+
} catch {
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* The decoder returns a completed block as its K' ssbg_mode1 symbols,
|
|
443
|
+
* concatenated: split by T, trim by each symbol's length field, and hand
|
|
444
|
+
* back the packets the parser does not have yet.
|
|
445
|
+
*/
|
|
446
|
+
#settleDecoded(start, block, output) {
|
|
447
|
+
this.#settle(start);
|
|
448
|
+
if (output.byteLength !== block.ssbLength * this.symbolSize) {
|
|
449
|
+
this.#stats.blocksFailed++;
|
|
450
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
451
|
+
this.#noteMixed(block, "failed");
|
|
452
|
+
this.#drop("block:decoded-length");
|
|
453
|
+
return [];
|
|
454
|
+
}
|
|
455
|
+
const recovered = [];
|
|
456
|
+
let refused = 0;
|
|
457
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
458
|
+
const ssId = serial32Add(start, i);
|
|
459
|
+
if (this.#have.has(ssId)) continue;
|
|
460
|
+
const symbol = output.subarray(i * this.symbolSize, (i + 1) * this.symbolSize);
|
|
461
|
+
const packet = trimSsbg1SourceSymbol(symbol);
|
|
462
|
+
if (!packet) {
|
|
463
|
+
refused++;
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
this.#have.set(ssId, 0);
|
|
467
|
+
recovered.push(packet.slice());
|
|
468
|
+
}
|
|
469
|
+
if (refused > 0) {
|
|
470
|
+
this.#stats.blocksFailed++;
|
|
471
|
+
this.#stats.packetsLost += refused;
|
|
472
|
+
this.#noteMixed(block, "failed");
|
|
473
|
+
this.#drop("block:bad-ssbg1-symbol");
|
|
474
|
+
} else if (recovered.length === 0) {
|
|
475
|
+
this.#stats.blocksClean++;
|
|
476
|
+
this.#noteMixed(block, "clean");
|
|
477
|
+
} else {
|
|
478
|
+
this.#stats.blocksRecovered++;
|
|
479
|
+
this.#noteMixed(block, "recovered");
|
|
480
|
+
}
|
|
481
|
+
this.#stats.packetsRecovered += recovered.length;
|
|
482
|
+
return recovered;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Retires every block, and every SS_ID the session remembers, that the
|
|
486
|
+
* newest SS_ID has moved past the retention. An unsettled block retired
|
|
487
|
+
* here is a failure: more of its sources were lost than its repair could
|
|
488
|
+
* restore, or its repair never arrived.
|
|
489
|
+
*/
|
|
490
|
+
#retireBehindHorizon() {
|
|
491
|
+
const decoder = this.#decoder;
|
|
492
|
+
const newest = this.#newest;
|
|
493
|
+
if (!decoder || newest === void 0) return;
|
|
494
|
+
try {
|
|
495
|
+
decoder.cleanup_by_ss_start(newest);
|
|
496
|
+
} catch {
|
|
497
|
+
}
|
|
498
|
+
for (const [start, block] of this.#blocks) {
|
|
499
|
+
if (!this.#behindHorizon(start)) continue;
|
|
500
|
+
this.#settle(start);
|
|
501
|
+
this.#stats.blocksFailed++;
|
|
502
|
+
this.#stats.packetsLost += block.ssbLength - block.received;
|
|
503
|
+
this.#noteMixed(block, "failed");
|
|
504
|
+
}
|
|
505
|
+
const prunedAt = this.#prunedAt;
|
|
506
|
+
if (prunedAt !== void 0 && serial32Distance(prunedAt, newest) < this.sourceSymbols) return;
|
|
507
|
+
this.#prunedAt = newest;
|
|
508
|
+
for (const ssId of this.#have.keys()) {
|
|
509
|
+
if (this.#behindHorizon(ssId)) this.#have.delete(ssId);
|
|
510
|
+
}
|
|
511
|
+
for (const start of this.#settled) {
|
|
512
|
+
if (this.#behindHorizon(start)) this.#settled.delete(start);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
function requirePositiveInteger(value, path) {
|
|
517
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
518
|
+
throw new Error(`MmtpFecSession: ${path} must be a positive integer (got ${String(value)})`);
|
|
519
|
+
}
|
|
520
|
+
return value;
|
|
521
|
+
}
|
|
522
|
+
function requireNumber(value, path) {
|
|
523
|
+
if (typeof value !== "number") {
|
|
524
|
+
throw new Error(`MmtpFecSession: ${path} is required (got ${String(value)}); it is never defaulted`);
|
|
525
|
+
}
|
|
526
|
+
return value;
|
|
527
|
+
}
|
|
528
|
+
export {
|
|
529
|
+
MmtpFecSession
|
|
530
|
+
};
|
|
531
|
+
//# sourceMappingURL=mmtp-fec-session.js.map
|