@blockcast/mmt-container 0.1.0-main.c71423b8a4e4 → 0.1.0-main.ce3c8aeb7f68
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/dist/align.d.ts +6 -2
- package/dist/align.d.ts.map +1 -1
- package/dist/align.js.map +2 -2
- package/dist/audio-ring-buffer.js +23 -36
- package/dist/audio-ring-buffer.js.map +1 -1
- package/dist/browser-runtime.js +6865 -6485
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +3 -1
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +21 -2
- package/dist/carp-catalog.js.map +4 -4
- package/dist/catalog-fec-params.js +10 -0
- package/dist/catalog-fec-params.js.map +4 -4
- package/dist/cmaf-block-assembler.d.ts +42 -0
- package/dist/cmaf-block-assembler.d.ts.map +1 -1
- package/dist/cmaf-block-assembler.js +542 -535
- package/dist/cmaf-block-assembler.js.map +2 -2
- package/dist/cmaf-group-batcher.js +27 -46
- package/dist/cmaf-group-batcher.js.map +2 -2
- package/dist/cmcd-producer.js +45 -66
- package/dist/cmcd-producer.js.map +1 -1
- package/dist/fec-manager.d.ts +13 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +1151 -871
- package/dist/fec-manager.js.map +2 -2
- package/dist/fec-starvation-detector.js +25 -40
- package/dist/fec-starvation-detector.js.map +1 -1
- package/dist/fec-worker-setup.js +242 -225
- package/dist/fec-worker-setup.js.map +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +2 -2
- package/dist/iso-bmff-timing.js +63 -88
- package/dist/iso-bmff-timing.js.map +1 -1
- package/dist/loc.js +7 -4
- package/dist/loc.js.map +1 -1
- package/dist/manifest-auth-plan.js +292 -311
- package/dist/manifest-auth-plan.js.map +1 -1
- package/dist/media-router.d.ts +0 -99
- package/dist/media-router.d.ts.map +1 -1
- package/dist/media-router.js +270 -504
- package/dist/media-router.js.map +3 -3
- package/dist/mfu-reassembler.js +597 -607
- package/dist/mfu-reassembler.js.map +3 -3
- package/dist/mmtp-container-parser.d.ts +37 -0
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +1531 -1522
- package/dist/mmtp-container-parser.js.map +3 -3
- package/dist/mmtp-container-parser.no-modules.js +179 -102
- package/dist/mmtp-container-parser.no-modules.js.map +3 -3
- package/dist/mmtp-decode-pipeline.js +1641 -1651
- package/dist/mmtp-decode-pipeline.js.map +3 -3
- package/dist/mmtp-router.d.ts +34 -0
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +3676 -3390
- package/dist/mmtp-router.js.map +3 -3
- package/dist/mmtp-to-cmaf.d.ts +7 -1
- package/dist/mmtp-to-cmaf.d.ts.map +1 -1
- package/dist/mmtp-to-cmaf.js +109 -134
- package/dist/mmtp-to-cmaf.js.map +2 -2
- package/dist/multicast-input.d.ts +7 -35
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +21 -2
- package/dist/multicast-input.js.map +4 -4
- package/dist/multicast-manager.d.ts +10 -1
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +5584 -4961
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +7 -0
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +369 -421
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +53 -30
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.js +2096 -2097
- package/dist/no-modules.js.map +3 -3
- package/dist/sample-combiner.js +118 -139
- package/dist/sample-combiner.js.map +1 -1
- package/dist/signaling.js.map +2 -2
- package/dist/source-auth.js +353 -382
- package/dist/source-auth.js.map +1 -1
- package/dist/switching-set-alignment.js +14 -29
- package/dist/switching-set-alignment.js.map +1 -1
- package/dist/timestamp-codec.js +17 -11
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/track-pipeline-setup.js +105 -125
- package/dist/track-pipeline-setup.js.map +1 -1
- package/dist/track-pipeline.js +107 -127
- package/dist/track-pipeline.js.map +1 -1
- package/dist/track-session.d.ts +16 -0
- package/dist/track-session.d.ts.map +1 -1
- package/dist/track-session.js +230 -243
- package/dist/track-session.js.map +2 -2
- package/dist/transport-pool.js +24 -38
- package/dist/transport-pool.js.map +1 -1
- package/dist/wasm-mfu-reassembler.d.ts +6 -1
- package/dist/wasm-mfu-reassembler.d.ts.map +1 -1
- package/dist/wasm-mfu-reassembler.js +127 -144
- package/dist/wasm-mfu-reassembler.js.map +2 -2
- package/dist/wasm-mmtp-container-parser.js +1659 -1650
- package/dist/wasm-mmtp-container-parser.js.map +3 -3
- package/node_modules/@blockcast/fec-worker/README.md +5 -1
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.d.ts +8 -2
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.d.ts.map +1 -1
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.js +89 -16
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-client.js.map +1 -1
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts +48 -3
- package/node_modules/@blockcast/fec-worker/dist/fec-worker-types.d.ts.map +1 -1
- package/node_modules/@blockcast/fec-worker/dist/fec-worker.js +55 -8
- package/node_modules/@blockcast/fec-worker/dist/fec-worker.js.map +2 -2
- package/node_modules/@blockcast/fec-worker/dist/index.d.ts +1 -1
- package/node_modules/@blockcast/fec-worker/dist/index.d.ts.map +1 -1
- package/node_modules/@blockcast/fec-worker/dist/index.js.map +1 -1
- package/node_modules/@blockcast/fec-worker/src/fec-worker-client.ts +97 -17
- package/node_modules/@blockcast/fec-worker/src/fec-worker-types.ts +46 -2
- package/node_modules/@blockcast/fec-worker/src/fec-worker.ts +78 -10
- package/node_modules/@blockcast/fec-worker/src/index.ts +2 -0
- package/node_modules/@blockcast/mmt-base/README.md +1 -0
- package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +52 -0
- package/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -1
- package/node_modules/@blockcast/mmt-base/dist/mmtp.js +142 -37
- package/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -1
- package/node_modules/@blockcast/mmt-base/src/mmtp.ts +158 -37
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/README.md +1 -0
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts +52 -0
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.d.ts.map +1 -1
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js +142 -37
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/dist/mmtp.js.map +1 -1
- package/node_modules/@blockcast/mmt-fec/node_modules/@blockcast/mmt-base/src/mmtp.ts +158 -37
- package/package.json +7 -6
- package/schemas/catalog.schema.json +1 -1
- package/src/align.ts +6 -2
- package/src/carp-catalog.ts +13 -3
- package/src/cmaf-block-assembler.ts +90 -81
- package/src/fec-manager.ts +530 -146
- package/src/index.ts +2 -2
- package/src/media-router.ts +0 -397
- package/src/mmtp-container-parser.ts +97 -21
- package/src/mmtp-router.ts +302 -125
- package/src/mmtp-to-cmaf.ts +21 -7
- package/src/multicast-input.ts +23 -3
- package/src/multicast-manager.ts +83 -11
- package/src/multicast-transport.ts +56 -17
- package/src/track-session.ts +16 -0
- package/src/wasm-mfu-reassembler.ts +40 -24
- package/test-vectors/catalog/README.md +2 -0
- package/test-vectors/catalog/negative/multicast-packet-id-signaling.json +26 -0
- package/test-vectors/catalog-validation.json +11 -0
package/dist/fec-worker-setup.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var __typeError = (msg) => {
|
|
4
|
-
throw TypeError(msg);
|
|
5
|
-
};
|
|
6
3
|
var __esm = (fn, res) => function __init() {
|
|
7
4
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
8
5
|
};
|
|
@@ -10,19 +7,6 @@ var __export = (target, all) => {
|
|
|
10
7
|
for (var name in all)
|
|
11
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
9
|
};
|
|
13
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
14
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
15
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
16
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
17
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
18
|
-
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
19
|
-
set _(value) {
|
|
20
|
-
__privateSet(obj, member, value, setter);
|
|
21
|
-
},
|
|
22
|
-
get _() {
|
|
23
|
-
return __privateGet(obj, member, getter);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
10
|
|
|
27
11
|
// ../fec-worker/dist/fec-worker-client.js
|
|
28
12
|
function formatWorkerError(event) {
|
|
@@ -53,42 +37,53 @@ function formatWorkerMessageError(event) {
|
|
|
53
37
|
const detail = data == null ? "" : data instanceof Error ? `: ${data.message}` : `: ${Object.prototype.toString.call(data)}`;
|
|
54
38
|
return `Worker messageerror: failed to deserialize worker message${detail}`;
|
|
55
39
|
}
|
|
56
|
-
var
|
|
40
|
+
var FecWorkerClient;
|
|
57
41
|
var init_fec_worker_client = __esm({
|
|
58
42
|
"../fec-worker/dist/fec-worker-client.js"() {
|
|
59
43
|
"use strict";
|
|
60
44
|
FecWorkerClient = class {
|
|
45
|
+
#worker;
|
|
46
|
+
#onFrame = null;
|
|
47
|
+
#onSnapshot = null;
|
|
48
|
+
#onBlockUpdate = null;
|
|
49
|
+
#onGreenFill = null;
|
|
50
|
+
#onCleanupComplete = null;
|
|
51
|
+
#onError = null;
|
|
52
|
+
#cleanupInFlight = null;
|
|
53
|
+
#queuedCleanupSbns = /* @__PURE__ */ new Set();
|
|
54
|
+
#pendingResets = 0;
|
|
55
|
+
#resetFailed = false;
|
|
56
|
+
#disposed = false;
|
|
57
|
+
// Symbols fed during the current task, sent as one feedSymbols message
|
|
58
|
+
// when the task's microtasks run (BLO-36599). A packet stream delivers many
|
|
59
|
+
// symbols per task, and each postMessage is a structured-clone round trip
|
|
60
|
+
// on the page thread; the batch boundary is the task, not a size or timer.
|
|
61
|
+
#pendingSymbols = [];
|
|
62
|
+
#pendingTransfer = [];
|
|
63
|
+
#flushQueued = false;
|
|
64
|
+
// Batching starts only once the Worker announced it accepts feedSymbols.
|
|
65
|
+
#batchSymbols = false;
|
|
66
|
+
// The Worker posts blockUpdate events only to a client that subscribed,
|
|
67
|
+
// which this client does once a callback is registered and the Worker
|
|
68
|
+
// announced the command (BLO-36599).
|
|
69
|
+
#blockUpdatesAnnounced = false;
|
|
70
|
+
#blockUpdatesSubscribed = false;
|
|
61
71
|
/**
|
|
62
72
|
* Create a FecWorkerClient.
|
|
63
73
|
* @param workerOrUrl - Either a Worker instance (for testing) or a URL to create one
|
|
64
74
|
*/
|
|
65
75
|
constructor(workerOrUrl) {
|
|
66
|
-
__privateAdd(this, _FecWorkerClient_instances);
|
|
67
|
-
__privateAdd(this, _worker);
|
|
68
|
-
__privateAdd(this, _onFrame, null);
|
|
69
|
-
__privateAdd(this, _onSnapshot, null);
|
|
70
|
-
__privateAdd(this, _onBlockUpdate, null);
|
|
71
|
-
__privateAdd(this, _onGreenFill, null);
|
|
72
|
-
__privateAdd(this, _onCleanupComplete, null);
|
|
73
|
-
__privateAdd(this, _onError, null);
|
|
74
|
-
__privateAdd(this, _cleanupInFlight, null);
|
|
75
|
-
__privateAdd(this, _queuedCleanupSbns, /* @__PURE__ */ new Set());
|
|
76
|
-
__privateAdd(this, _pendingResets, 0);
|
|
77
|
-
__privateAdd(this, _resetFailed, false);
|
|
78
|
-
__privateAdd(this, _disposed, false);
|
|
79
76
|
if (workerOrUrl instanceof URL) {
|
|
80
|
-
|
|
77
|
+
this.#worker = new Worker(workerOrUrl, { type: "module" });
|
|
81
78
|
} else {
|
|
82
|
-
|
|
79
|
+
this.#worker = workerOrUrl;
|
|
83
80
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
(_a = __privateGet(this, _onError)) == null ? void 0 : _a.call(this, formatWorkerError(e), "worker-runtime");
|
|
81
|
+
this.#worker.onmessage = (e) => this.#handleEvent(e.data);
|
|
82
|
+
this.#worker.onerror = (e) => {
|
|
83
|
+
this.#onError?.(formatWorkerError(e), "worker-runtime");
|
|
88
84
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
(_a = __privateGet(this, _onError)) == null ? void 0 : _a.call(this, formatWorkerMessageError(e), "worker-message");
|
|
85
|
+
this.#worker.onmessageerror = (e) => {
|
|
86
|
+
this.#onError?.(formatWorkerMessageError(e), "worker-message");
|
|
92
87
|
};
|
|
93
88
|
}
|
|
94
89
|
/**
|
|
@@ -99,8 +94,9 @@ var init_fec_worker_client = __esm({
|
|
|
99
94
|
* altaWasmModule is structured-cloneable (NOT transferable — do not add to transfer list).
|
|
100
95
|
*/
|
|
101
96
|
configure(config, wasmModule, altaPublicKey, altaWasmModule) {
|
|
102
|
-
if (
|
|
97
|
+
if (this.#disposed)
|
|
103
98
|
throw new Error("[FecWorkerClient] disposed");
|
|
99
|
+
this.#flushSymbols();
|
|
104
100
|
const cmd = {
|
|
105
101
|
type: "configure",
|
|
106
102
|
config,
|
|
@@ -111,11 +107,12 @@ var init_fec_worker_client = __esm({
|
|
|
111
107
|
const transferList = [];
|
|
112
108
|
if (altaPublicKey)
|
|
113
109
|
transferList.push(altaPublicKey);
|
|
114
|
-
|
|
110
|
+
this.#worker.postMessage(cmd, transferList);
|
|
115
111
|
}
|
|
116
112
|
/**
|
|
117
113
|
* Feed a source symbol to the Worker. data ArrayBuffer is transferred (zero-copy).
|
|
118
|
-
* Caller must not access data after this call — it is
|
|
114
|
+
* Caller must not access data after this call — it is transferred with the
|
|
115
|
+
* task's symbol batch, before any later command of this client.
|
|
119
116
|
*
|
|
120
117
|
* Optional `alta` carries the detached ALTA authenticator bytes and the
|
|
121
118
|
* byte offset in `data` where the signed payload ends. The auth buffer is
|
|
@@ -123,18 +120,20 @@ var init_fec_worker_client = __esm({
|
|
|
123
120
|
* upstream (mmtp-router) to extract it from the wire packet.
|
|
124
121
|
*/
|
|
125
122
|
feedSource(ssId, data, ts, alta) {
|
|
126
|
-
if (
|
|
123
|
+
if (this.#disposed)
|
|
127
124
|
throw new Error("[FecWorkerClient] feedSource on a disposed client");
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
125
|
+
if (alta) {
|
|
126
|
+
this.#queueSymbol({
|
|
127
|
+
type: "feedSource",
|
|
128
|
+
ssId,
|
|
129
|
+
data,
|
|
130
|
+
ts,
|
|
131
|
+
altaAuth: alta.auth,
|
|
132
|
+
altaPayloadEnd: alta.payloadEnd
|
|
133
|
+
}, data, alta.auth);
|
|
134
|
+
} else {
|
|
135
|
+
this.#queueSymbol({ type: "feedSource", ssId, data, ts }, data);
|
|
136
|
+
}
|
|
138
137
|
}
|
|
139
138
|
/**
|
|
140
139
|
* Feed a repair symbol to the Worker. data ArrayBuffer is transferred (zero-copy).
|
|
@@ -146,24 +145,48 @@ var init_fec_worker_client = __esm({
|
|
|
146
145
|
* - rsId: repair symbol index within the block
|
|
147
146
|
*/
|
|
148
147
|
feedRepair(ssStart, ssbLength, rsId, data, ts) {
|
|
149
|
-
if (
|
|
148
|
+
if (this.#disposed)
|
|
150
149
|
throw new Error("[FecWorkerClient] feedRepair on a disposed client");
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
this.#queueSymbol({ type: "feedRepair", ssStart, ssbLength, rsId, data, ts }, data);
|
|
151
|
+
}
|
|
152
|
+
#queueSymbol(symbol, data, auth) {
|
|
153
|
+
if (!this.#batchSymbols) {
|
|
154
|
+
this.#worker.postMessage(symbol, auth ? [data, auth] : [data]);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.#pendingSymbols.push(symbol);
|
|
158
|
+
this.#pendingTransfer.push(data);
|
|
159
|
+
if (auth)
|
|
160
|
+
this.#pendingTransfer.push(auth);
|
|
161
|
+
if (this.#flushQueued)
|
|
162
|
+
return;
|
|
163
|
+
this.#flushQueued = true;
|
|
164
|
+
queueMicrotask(() => {
|
|
165
|
+
this.#flushQueued = false;
|
|
166
|
+
this.#flushSymbols();
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Send the symbols fed so far. Every other command calls this first, so a
|
|
171
|
+
* cleanup barrier, reset or signature still follows all earlier symbols.
|
|
172
|
+
*/
|
|
173
|
+
#flushSymbols() {
|
|
174
|
+
if (this.#pendingSymbols.length === 0 || this.#disposed)
|
|
175
|
+
return;
|
|
176
|
+
const symbols = this.#pendingSymbols;
|
|
177
|
+
const transfer = this.#pendingTransfer;
|
|
178
|
+
this.#pendingSymbols = [];
|
|
179
|
+
this.#pendingTransfer = [];
|
|
180
|
+
this.#worker.postMessage({ type: "feedSymbols", symbols }, transfer);
|
|
159
181
|
}
|
|
160
182
|
/**
|
|
161
183
|
* Submit relay block signature for verification. sig and hash are transferred.
|
|
162
184
|
*/
|
|
163
185
|
relayBlockSig(sbn, sig, hash) {
|
|
164
|
-
if (
|
|
186
|
+
if (this.#disposed)
|
|
165
187
|
throw new Error("[FecWorkerClient] relayBlockSig on a disposed client");
|
|
166
|
-
|
|
188
|
+
this.#flushSymbols();
|
|
189
|
+
this.#worker.postMessage({ type: "relayBlockSig", sbn, sig, hash }, [sig, hash]);
|
|
167
190
|
}
|
|
168
191
|
/**
|
|
169
192
|
* Trigger cleanup after a block's inactivity deadline.
|
|
@@ -172,49 +195,68 @@ var init_fec_worker_client = __esm({
|
|
|
172
195
|
* the next command without losing their individual acknowledgement identity.
|
|
173
196
|
*/
|
|
174
197
|
cleanup(currentSbn) {
|
|
175
|
-
if (
|
|
198
|
+
if (this.#disposed)
|
|
176
199
|
throw new Error("[FecWorkerClient] cleanup on a disposed client");
|
|
177
200
|
if (!Number.isInteger(currentSbn) || currentSbn < 0 || currentSbn > 4294967295) {
|
|
178
201
|
throw new Error("[FecWorkerClient] cleanup: SBN must be a uint32");
|
|
179
202
|
}
|
|
180
|
-
if (
|
|
181
|
-
|
|
203
|
+
if (this.#cleanupInFlight) {
|
|
204
|
+
this.#queuedCleanupSbns.add(currentSbn);
|
|
182
205
|
return;
|
|
183
206
|
}
|
|
184
|
-
|
|
207
|
+
this.#postCleanup(/* @__PURE__ */ new Set([currentSbn]));
|
|
185
208
|
}
|
|
186
209
|
/** Reset this track's decoder epoch while preserving Worker configuration. */
|
|
187
210
|
reset() {
|
|
188
|
-
if (
|
|
211
|
+
if (this.#disposed)
|
|
189
212
|
throw new Error("[FecWorkerClient] reset on a disposed client");
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
213
|
+
this.#flushSymbols();
|
|
214
|
+
this.#pendingResets++;
|
|
215
|
+
this.#cleanupInFlight = null;
|
|
216
|
+
this.#queuedCleanupSbns.clear();
|
|
217
|
+
this.#worker.postMessage({ type: "reset" });
|
|
218
|
+
}
|
|
219
|
+
#postCleanup(sbns) {
|
|
220
|
+
this.#flushSymbols();
|
|
221
|
+
this.#cleanupInFlight = sbns;
|
|
222
|
+
const orderedSbns = [...sbns].sort((a, b) => a - b);
|
|
223
|
+
this.#worker.postMessage({ type: "cleanup", sbns: orderedSbns });
|
|
194
224
|
}
|
|
195
225
|
/** Register callback for decoded/recovered frames (FEC-03). */
|
|
196
226
|
onFrame(cb) {
|
|
197
|
-
|
|
227
|
+
this.#onFrame = cb;
|
|
198
228
|
}
|
|
199
229
|
/** Register callback for periodic stats snapshots (FEC-04). */
|
|
200
230
|
onSnapshot(cb) {
|
|
201
|
-
|
|
231
|
+
this.#onSnapshot = cb;
|
|
202
232
|
}
|
|
203
|
-
/**
|
|
233
|
+
/**
|
|
234
|
+
* Register callback for individual block state changes. The Worker posts
|
|
235
|
+
* them only once asked, so registering subscribes (after the Worker
|
|
236
|
+
* announces `subscribeBlockUpdates`). An older Worker that does not
|
|
237
|
+
* announce it posts them unasked.
|
|
238
|
+
*/
|
|
204
239
|
onBlockUpdate(cb) {
|
|
205
|
-
|
|
240
|
+
this.#onBlockUpdate = cb;
|
|
241
|
+
this.#subscribeBlockUpdates();
|
|
242
|
+
}
|
|
243
|
+
#subscribeBlockUpdates() {
|
|
244
|
+
if (this.#disposed || this.#blockUpdatesSubscribed || !this.#blockUpdatesAnnounced || !this.#onBlockUpdate)
|
|
245
|
+
return;
|
|
246
|
+
this.#blockUpdatesSubscribed = true;
|
|
247
|
+
this.#worker.postMessage({ type: "subscribeBlockUpdates" });
|
|
206
248
|
}
|
|
207
249
|
/** Register callback for green-fill frames. */
|
|
208
250
|
onGreenFill(cb) {
|
|
209
|
-
|
|
251
|
+
this.#onGreenFill = cb;
|
|
210
252
|
}
|
|
211
253
|
/** Register callback fired after the Worker drains all commands queued before cleanup. */
|
|
212
254
|
onCleanupComplete(cb) {
|
|
213
|
-
|
|
255
|
+
this.#onCleanupComplete = cb;
|
|
214
256
|
}
|
|
215
257
|
/** Register callback for Worker errors. */
|
|
216
258
|
onError(cb) {
|
|
217
|
-
|
|
259
|
+
this.#onError = cb;
|
|
218
260
|
}
|
|
219
261
|
/**
|
|
220
262
|
* True once dispose() ran. A disposed client cannot decode, fill, or
|
|
@@ -223,84 +265,77 @@ var init_fec_worker_client = __esm({
|
|
|
223
265
|
* throws rather than pretend otherwise. Callers check this first.
|
|
224
266
|
*/
|
|
225
267
|
get disposed() {
|
|
226
|
-
return
|
|
268
|
+
return this.#disposed;
|
|
227
269
|
}
|
|
228
270
|
/**
|
|
229
271
|
* Dispose the Worker. Sends dispose command then terminates.
|
|
230
272
|
* Idempotent — safe to call multiple times.
|
|
231
273
|
*/
|
|
232
274
|
dispose() {
|
|
233
|
-
if (
|
|
275
|
+
if (this.#disposed)
|
|
234
276
|
return;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
_pendingResets = new WeakMap();
|
|
252
|
-
_resetFailed = new WeakMap();
|
|
253
|
-
_disposed = new WeakMap();
|
|
254
|
-
_FecWorkerClient_instances = new WeakSet();
|
|
255
|
-
postCleanup_fn = function(sbns) {
|
|
256
|
-
__privateSet(this, _cleanupInFlight, sbns);
|
|
257
|
-
const orderedSbns = [...sbns].sort((a, b) => a - b);
|
|
258
|
-
__privateGet(this, _worker).postMessage({ type: "cleanup", sbns: orderedSbns });
|
|
259
|
-
};
|
|
260
|
-
handleEvent_fn = function(event) {
|
|
261
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
262
|
-
if (event.type === "resetComplete") {
|
|
263
|
-
__privateSet(this, _pendingResets, Math.max(0, __privateGet(this, _pendingResets) - 1));
|
|
264
|
-
__privateSet(this, _resetFailed, false);
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
if (event.type === "error") {
|
|
268
|
-
if (event.code === "reset-failed") {
|
|
269
|
-
__privateSet(this, _pendingResets, Math.max(0, __privateGet(this, _pendingResets) - 1));
|
|
270
|
-
__privateSet(this, _resetFailed, true);
|
|
271
|
-
}
|
|
272
|
-
if (event.code)
|
|
273
|
-
(_a = __privateGet(this, _onError)) == null ? void 0 : _a.call(this, event.message, event.code);
|
|
274
|
-
else
|
|
275
|
-
(_b = __privateGet(this, _onError)) == null ? void 0 : _b.call(this, event.message);
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
if (__privateGet(this, _pendingResets) > 0 || __privateGet(this, _resetFailed))
|
|
279
|
-
return;
|
|
280
|
-
switch (event.type) {
|
|
281
|
-
case "frame":
|
|
282
|
-
(_c = __privateGet(this, _onFrame)) == null ? void 0 : _c.call(this, event.data, event.meta);
|
|
283
|
-
break;
|
|
284
|
-
case "snapshot":
|
|
285
|
-
(_d = __privateGet(this, _onSnapshot)) == null ? void 0 : _d.call(this, event.stats);
|
|
286
|
-
break;
|
|
287
|
-
case "blockUpdate":
|
|
288
|
-
(_e = __privateGet(this, _onBlockUpdate)) == null ? void 0 : _e.call(this, event.block);
|
|
289
|
-
break;
|
|
290
|
-
case "greenFill":
|
|
291
|
-
(_f = __privateGet(this, _onGreenFill)) == null ? void 0 : _f.call(this, event.sbn, event.data);
|
|
292
|
-
break;
|
|
293
|
-
case "cleanupComplete":
|
|
294
|
-
for (const sbn of event.sbns) {
|
|
295
|
-
(_g = __privateGet(this, _onCleanupComplete)) == null ? void 0 : _g.call(this, sbn);
|
|
277
|
+
this.#disposed = true;
|
|
278
|
+
this.#pendingSymbols = [];
|
|
279
|
+
this.#pendingTransfer = [];
|
|
280
|
+
this.#cleanupInFlight = null;
|
|
281
|
+
this.#queuedCleanupSbns.clear();
|
|
282
|
+
this.#worker.postMessage({ type: "dispose" });
|
|
283
|
+
this.#worker.terminate();
|
|
284
|
+
}
|
|
285
|
+
#handleEvent(event) {
|
|
286
|
+
if (event.type === "capabilities") {
|
|
287
|
+
if (Array.isArray(event.commands) && event.commands.includes("feedSymbols")) {
|
|
288
|
+
this.#batchSymbols = true;
|
|
289
|
+
}
|
|
290
|
+
if (Array.isArray(event.commands) && event.commands.includes("subscribeBlockUpdates")) {
|
|
291
|
+
this.#blockUpdatesAnnounced = true;
|
|
292
|
+
this.#subscribeBlockUpdates();
|
|
296
293
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (event.type === "resetComplete") {
|
|
297
|
+
this.#pendingResets = Math.max(0, this.#pendingResets - 1);
|
|
298
|
+
this.#resetFailed = false;
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (event.type === "error") {
|
|
302
|
+
if (event.code === "reset-failed") {
|
|
303
|
+
this.#pendingResets = Math.max(0, this.#pendingResets - 1);
|
|
304
|
+
this.#resetFailed = true;
|
|
302
305
|
}
|
|
303
|
-
|
|
306
|
+
if (event.code)
|
|
307
|
+
this.#onError?.(event.message, event.code);
|
|
308
|
+
else
|
|
309
|
+
this.#onError?.(event.message);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (this.#pendingResets > 0 || this.#resetFailed)
|
|
313
|
+
return;
|
|
314
|
+
switch (event.type) {
|
|
315
|
+
case "frame":
|
|
316
|
+
this.#onFrame?.(event.data, event.meta);
|
|
317
|
+
break;
|
|
318
|
+
case "snapshot":
|
|
319
|
+
this.#onSnapshot?.(event.stats);
|
|
320
|
+
break;
|
|
321
|
+
case "blockUpdate":
|
|
322
|
+
this.#onBlockUpdate?.(event.block);
|
|
323
|
+
break;
|
|
324
|
+
case "greenFill":
|
|
325
|
+
this.#onGreenFill?.(event.sbn, event.data);
|
|
326
|
+
break;
|
|
327
|
+
case "cleanupComplete":
|
|
328
|
+
for (const sbn of event.sbns) {
|
|
329
|
+
this.#onCleanupComplete?.(sbn);
|
|
330
|
+
}
|
|
331
|
+
this.#cleanupInFlight = null;
|
|
332
|
+
if (this.#queuedCleanupSbns.size > 0) {
|
|
333
|
+
const next = this.#queuedCleanupSbns;
|
|
334
|
+
this.#queuedCleanupSbns = /* @__PURE__ */ new Set();
|
|
335
|
+
this.#postCleanup(next);
|
|
336
|
+
}
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
304
339
|
}
|
|
305
340
|
};
|
|
306
341
|
}
|
|
@@ -323,12 +358,24 @@ function formatWorkerError2(event) {
|
|
|
323
358
|
parts.push(event.error.stack);
|
|
324
359
|
return parts.join(": ");
|
|
325
360
|
}
|
|
326
|
-
var DEFAULT_MAX_INFLIGHT,
|
|
361
|
+
var DEFAULT_MAX_INFLIGHT, ShredWorkerClient;
|
|
327
362
|
var init_shred_worker_client = __esm({
|
|
328
363
|
"../fec-worker/dist/shred-worker-client.js"() {
|
|
329
364
|
"use strict";
|
|
330
365
|
DEFAULT_MAX_INFLIGHT = 8192;
|
|
331
366
|
ShredWorkerClient = class {
|
|
367
|
+
#worker;
|
|
368
|
+
#onRecovered = null;
|
|
369
|
+
#onStats = null;
|
|
370
|
+
#onError = null;
|
|
371
|
+
#disposed = false;
|
|
372
|
+
/** feedShred in-flight backpressure accounting (see ShredWorkerClientOptions.maxInflight). */
|
|
373
|
+
#maxInflight;
|
|
374
|
+
#sent = 0;
|
|
375
|
+
// frames posted via feedShred (monotonic)
|
|
376
|
+
#processed = 0;
|
|
377
|
+
// worker-consumed total from the last stats heartbeat (monotonic)
|
|
378
|
+
#droppedBackpressure = 0;
|
|
332
379
|
// frames dropped by the in-flight guard (monotonic)
|
|
333
380
|
/**
|
|
334
381
|
* @param workerOrUrl - A URL (a Worker is created internally, `type: module`)
|
|
@@ -336,36 +383,17 @@ var init_shred_worker_client = __esm({
|
|
|
336
383
|
* @param opts - Optional {@link ShredWorkerClientOptions}.
|
|
337
384
|
*/
|
|
338
385
|
constructor(workerOrUrl, opts = {}) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
__privateAdd(this, _disposed2, false);
|
|
345
|
-
/** feedShred in-flight backpressure accounting (see ShredWorkerClientOptions.maxInflight). */
|
|
346
|
-
__privateAdd(this, _maxInflight);
|
|
347
|
-
__privateAdd(this, _sent, 0);
|
|
348
|
-
// frames posted via feedShred (monotonic)
|
|
349
|
-
__privateAdd(this, _processed, 0);
|
|
350
|
-
// worker-consumed total from the last stats heartbeat (monotonic)
|
|
351
|
-
__privateAdd(this, _droppedBackpressure, 0);
|
|
352
|
-
__privateSet(this, _maxInflight, opts.maxInflight ?? DEFAULT_MAX_INFLIGHT);
|
|
353
|
-
__privateSet(this, _worker2, workerOrUrl instanceof URL ? new Worker(workerOrUrl, { type: "module" }) : workerOrUrl);
|
|
354
|
-
__privateGet(this, _worker2).onmessage = (e) => __privateMethod(this, _ShredWorkerClient_instances, handleEvent_fn2).call(this, e.data);
|
|
355
|
-
__privateGet(this, _worker2).onerror = (e) => {
|
|
356
|
-
var _a;
|
|
357
|
-
return (_a = __privateGet(this, _onError2)) == null ? void 0 : _a.call(this, formatWorkerError2(e), "worker-runtime");
|
|
358
|
-
};
|
|
359
|
-
__privateGet(this, _worker2).onmessageerror = () => {
|
|
360
|
-
var _a;
|
|
361
|
-
return (_a = __privateGet(this, _onError2)) == null ? void 0 : _a.call(this, "failed to deserialize worker message", "worker-message");
|
|
362
|
-
};
|
|
386
|
+
this.#maxInflight = opts.maxInflight ?? DEFAULT_MAX_INFLIGHT;
|
|
387
|
+
this.#worker = workerOrUrl instanceof URL ? new Worker(workerOrUrl, { type: "module" }) : workerOrUrl;
|
|
388
|
+
this.#worker.onmessage = (e) => this.#handleEvent(e.data);
|
|
389
|
+
this.#worker.onerror = (e) => this.#onError?.(formatWorkerError2(e), "worker-runtime");
|
|
390
|
+
this.#worker.onmessageerror = () => this.#onError?.("failed to deserialize worker message", "worker-message");
|
|
363
391
|
}
|
|
364
392
|
/** Configure the decoder (WASM load + ShredFecBuffer construction happen in the worker). */
|
|
365
393
|
configure(config) {
|
|
366
|
-
if (
|
|
394
|
+
if (this.#disposed)
|
|
367
395
|
throw new Error("[ShredWorkerClient] disposed");
|
|
368
|
-
|
|
396
|
+
this.#post({ type: "configure", config });
|
|
369
397
|
}
|
|
370
398
|
/**
|
|
371
399
|
* Hand the worker a stream of raw shred frames to batch-drain. The stream is
|
|
@@ -373,9 +401,9 @@ var init_shred_worker_client = __esm({
|
|
|
373
401
|
* time; attaching a new one cancels the previous.
|
|
374
402
|
*/
|
|
375
403
|
attachStream(readable) {
|
|
376
|
-
if (
|
|
404
|
+
if (this.#disposed)
|
|
377
405
|
return;
|
|
378
|
-
|
|
406
|
+
this.#post({ type: "attachStream", readable }, [readable]);
|
|
379
407
|
}
|
|
380
408
|
/**
|
|
381
409
|
* Feed one already-demuxed raw shred frame. `frame` is transferred zero-copy;
|
|
@@ -388,32 +416,32 @@ var init_shred_worker_client = __esm({
|
|
|
388
416
|
* renderer-heap blow-up.
|
|
389
417
|
*/
|
|
390
418
|
feedShred(frame) {
|
|
391
|
-
if (
|
|
419
|
+
if (this.#disposed)
|
|
392
420
|
return;
|
|
393
|
-
if (
|
|
394
|
-
|
|
421
|
+
if (this.#maxInflight > 0 && this.#sent - this.#processed >= this.#maxInflight) {
|
|
422
|
+
this.#droppedBackpressure++;
|
|
395
423
|
return;
|
|
396
424
|
}
|
|
397
|
-
|
|
398
|
-
|
|
425
|
+
this.#sent++;
|
|
426
|
+
this.#post({ type: "feedShred", frame }, [frame]);
|
|
399
427
|
}
|
|
400
428
|
/** Explicitly drive loss recovery (in addition to the worker's internal timer). */
|
|
401
429
|
recoverAll(nowMs = Date.now()) {
|
|
402
|
-
if (
|
|
430
|
+
if (this.#disposed)
|
|
403
431
|
return;
|
|
404
|
-
|
|
432
|
+
this.#post({ type: "recoverAll", nowMs });
|
|
405
433
|
}
|
|
406
434
|
/** Register callback for recovered/completed FEC sets. `data` is a transferred buffer. */
|
|
407
435
|
onRecovered(cb) {
|
|
408
|
-
|
|
436
|
+
this.#onRecovered = cb;
|
|
409
437
|
}
|
|
410
438
|
/** Register callback for the coalesced stats heartbeat. */
|
|
411
439
|
onStats(cb) {
|
|
412
|
-
|
|
440
|
+
this.#onStats = cb;
|
|
413
441
|
}
|
|
414
442
|
/** Register callback for worker errors. */
|
|
415
443
|
onError(cb) {
|
|
416
|
-
|
|
444
|
+
this.#onError = cb;
|
|
417
445
|
}
|
|
418
446
|
/**
|
|
419
447
|
* Frames dropped by the in-flight backpressure guard since construction
|
|
@@ -421,56 +449,45 @@ var init_shred_worker_client = __esm({
|
|
|
421
449
|
* silent — a rising counter means the consumer can't keep pace with ingest.
|
|
422
450
|
*/
|
|
423
451
|
get droppedBackpressure() {
|
|
424
|
-
return
|
|
452
|
+
return this.#droppedBackpressure;
|
|
425
453
|
}
|
|
426
454
|
/**
|
|
427
455
|
* Frames posted via {@link feedShred} but not yet reported drained by the
|
|
428
456
|
* worker's last stats heartbeat (best-effort, heartbeat-granular; never < 0).
|
|
429
457
|
*/
|
|
430
458
|
get inflight() {
|
|
431
|
-
return Math.max(0,
|
|
459
|
+
return Math.max(0, this.#sent - this.#processed);
|
|
432
460
|
}
|
|
433
461
|
/** Dispose the worker. Idempotent. */
|
|
434
462
|
dispose() {
|
|
435
|
-
if (
|
|
463
|
+
if (this.#disposed)
|
|
436
464
|
return;
|
|
437
|
-
|
|
465
|
+
this.#disposed = true;
|
|
438
466
|
try {
|
|
439
|
-
|
|
467
|
+
this.#worker.postMessage({ type: "dispose" });
|
|
440
468
|
} catch {
|
|
441
469
|
}
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
break;
|
|
464
|
-
case "stats":
|
|
465
|
-
__privateSet(this, _processed, event.stats.shredsRx + event.stats.malformed + event.stats.versionMismatch);
|
|
466
|
-
(_b = __privateGet(this, _onStats)) == null ? void 0 : _b.call(this, event.stats);
|
|
467
|
-
break;
|
|
468
|
-
case "error":
|
|
469
|
-
if (event.code)
|
|
470
|
-
(_c = __privateGet(this, _onError2)) == null ? void 0 : _c.call(this, event.message, event.code);
|
|
471
|
-
else
|
|
472
|
-
(_d = __privateGet(this, _onError2)) == null ? void 0 : _d.call(this, event.message);
|
|
473
|
-
break;
|
|
470
|
+
this.#worker.terminate();
|
|
471
|
+
}
|
|
472
|
+
#post(cmd, transfer = []) {
|
|
473
|
+
this.#worker.postMessage(cmd, transfer);
|
|
474
|
+
}
|
|
475
|
+
#handleEvent(event) {
|
|
476
|
+
switch (event.type) {
|
|
477
|
+
case "recovered":
|
|
478
|
+
this.#onRecovered?.(event.data, event.meta);
|
|
479
|
+
break;
|
|
480
|
+
case "stats":
|
|
481
|
+
this.#processed = event.stats.shredsRx + event.stats.malformed + event.stats.versionMismatch;
|
|
482
|
+
this.#onStats?.(event.stats);
|
|
483
|
+
break;
|
|
484
|
+
case "error":
|
|
485
|
+
if (event.code)
|
|
486
|
+
this.#onError?.(event.message, event.code);
|
|
487
|
+
else
|
|
488
|
+
this.#onError?.(event.message);
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
474
491
|
}
|
|
475
492
|
};
|
|
476
493
|
}
|