@blockcast/mmt-container 0.4.0-main.bbd83cb48eff → 0.4.0-main.ce637cfaae36
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/browser-runtime.js +362 -11
- package/dist/browser-runtime.js.map +3 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +441 -11
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-fec-session.d.ts +117 -0
- package/dist/mmtp-fec-session.d.ts.map +1 -0
- package/dist/mmtp-fec-session.js +482 -0
- package/dist/mmtp-fec-session.js.map +7 -0
- package/dist/multicast-manager.d.ts +21 -2
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +35 -1
- package/dist/multicast-manager.js.map +2 -2
- package/dist/no-modules.d.ts +1 -0
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +393 -0
- package/dist/no-modules.js.map +3 -3
- package/dist/repair-fetch.d.ts +23 -1
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +35 -10
- package/dist/repair-fetch.js.map +2 -2
- package/package.json +5 -5
- package/src/index.ts +13 -0
- package/src/mmtp-fec-session.ts +430 -0
- package/src/multicast-manager.ts +80 -2
- package/src/no-modules.ts +1 -0
- package/src/repair-fetch.ts +79 -14
|
@@ -41,6 +41,7 @@ var BlockcastMmt = (() => {
|
|
|
41
41
|
FEC_INACTIVE_REASONS: () => FEC_INACTIVE_REASONS,
|
|
42
42
|
ManifestVerifier: () => ManifestVerifier,
|
|
43
43
|
MmtpContainerParser: () => MmtpContainerParser,
|
|
44
|
+
MmtpFecSession: () => MmtpFecSession,
|
|
44
45
|
MmtpToCmaf: () => MmtpToCmaf,
|
|
45
46
|
catalogDeclaresFec: () => catalogDeclaresFec,
|
|
46
47
|
catalogFecInterleaveMs: () => catalogFecInterleaveMs,
|
|
@@ -348,6 +349,54 @@ var BlockcastMmt = (() => {
|
|
|
348
349
|
ssId: (mmtpPacket[off] << 24 | mmtpPacket[off + 1] << 16 | mmtpPacket[off + 2] << 8 | mmtpPacket[off + 3]) >>> 0
|
|
349
350
|
};
|
|
350
351
|
}
|
|
352
|
+
var REPAIR_FEC_PID_SIZE = 13;
|
|
353
|
+
function readRepairFecPayloadIdFields(mmtpPacket, parsedHeader) {
|
|
354
|
+
let header;
|
|
355
|
+
if (parsedHeader) {
|
|
356
|
+
header = parsedHeader;
|
|
357
|
+
} else {
|
|
358
|
+
try {
|
|
359
|
+
header = parseMMTPHeader(mmtpPacket);
|
|
360
|
+
} catch {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (header.packetType !== PACKET_TYPE_REPAIR || header.fecType !== 2)
|
|
365
|
+
return null;
|
|
366
|
+
const off = header.headerLength;
|
|
367
|
+
if (mmtpPacket.length < off + REPAIR_FEC_PID_SIZE)
|
|
368
|
+
return null;
|
|
369
|
+
const ssStart = (mmtpPacket[off] << 24 | mmtpPacket[off + 1] << 16 | mmtpPacket[off + 2] << 8 | mmtpPacket[off + 3]) >>> 0;
|
|
370
|
+
const rsbLength = mmtpPacket[off + 4] << 16 | mmtpPacket[off + 5] << 8 | mmtpPacket[off + 6];
|
|
371
|
+
const rsId = mmtpPacket[off + 7] << 16 | mmtpPacket[off + 8] << 8 | mmtpPacket[off + 9];
|
|
372
|
+
const ssbLength = mmtpPacket[off + 10] << 16 | mmtpPacket[off + 11] << 8 | mmtpPacket[off + 12];
|
|
373
|
+
return {
|
|
374
|
+
packetId: header.packetId,
|
|
375
|
+
ssStart,
|
|
376
|
+
rsbLength,
|
|
377
|
+
rsId,
|
|
378
|
+
ssbLength,
|
|
379
|
+
dataOffset: off + REPAIR_FEC_PID_SIZE
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function parseMoqRepairFrameWithHeader(frame, header) {
|
|
383
|
+
return moqRepairFrameFrom(frame, readRepairFecPayloadIdFields(frame, header));
|
|
384
|
+
}
|
|
385
|
+
function moqRepairFrameFrom(frame, repairId) {
|
|
386
|
+
if (!repairId)
|
|
387
|
+
return null;
|
|
388
|
+
const symbolData = frame.subarray(repairId.dataOffset);
|
|
389
|
+
if (repairId.rsbLength === 0 || repairId.ssbLength === 0 || repairId.rsId >= repairId.rsbLength || symbolData.length === 0)
|
|
390
|
+
return null;
|
|
391
|
+
return {
|
|
392
|
+
packetId: repairId.packetId,
|
|
393
|
+
ssStart: repairId.ssStart,
|
|
394
|
+
rsbLength: repairId.rsbLength,
|
|
395
|
+
rsId: repairId.rsId,
|
|
396
|
+
ssbLength: repairId.ssbLength,
|
|
397
|
+
symbolData
|
|
398
|
+
};
|
|
399
|
+
}
|
|
351
400
|
|
|
352
401
|
// ../mmt-base/dist/ntp-short.js
|
|
353
402
|
var NTP_SHORT_BITS = 32;
|
|
@@ -356,6 +405,26 @@ var BlockcastMmt = (() => {
|
|
|
356
405
|
|
|
357
406
|
// ../mmt-base/dist/serial-number.js
|
|
358
407
|
var SERIAL32_SPAN = 4294967296;
|
|
408
|
+
var SERIAL32_HALF = 2147483648;
|
|
409
|
+
function assertUint32(value, name) {
|
|
410
|
+
if (!Number.isInteger(value) || value < 0 || value >= SERIAL32_SPAN) {
|
|
411
|
+
throw new RangeError(`${name} must be a uint32 (got ${value})`);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
function serial32Add(s, n) {
|
|
415
|
+
assertUint32(s, "s");
|
|
416
|
+
if (!Number.isInteger(n) || n <= -SERIAL32_HALF || n >= SERIAL32_HALF) {
|
|
417
|
+
throw new RangeError(`serial addend must lie in (-2^31, 2^31) (got ${n})`);
|
|
418
|
+
}
|
|
419
|
+
return (s + n + SERIAL32_SPAN) % SERIAL32_SPAN;
|
|
420
|
+
}
|
|
421
|
+
function serial32Distance(from, to) {
|
|
422
|
+
return to - from >>> 0;
|
|
423
|
+
}
|
|
424
|
+
function serial32Precedes(a, b) {
|
|
425
|
+
const distance = serial32Distance(a, b);
|
|
426
|
+
return distance !== 0 && distance < SERIAL32_HALF;
|
|
427
|
+
}
|
|
359
428
|
|
|
360
429
|
// ../mmt-base/dist/fec-block-profile.js
|
|
361
430
|
var FEC_BLOCK_PROFILES = Object.freeze([
|
|
@@ -372,6 +441,35 @@ var BlockcastMmt = (() => {
|
|
|
372
441
|
}
|
|
373
442
|
throw new Error(`${where} must be "iso-ssbg1-v1" (got ${JSON.stringify(value)})`);
|
|
374
443
|
}
|
|
444
|
+
var SSBG1_LENGTH_FIELD_BYTES = 2;
|
|
445
|
+
function ssbg1MaxPacketLength(symbolSize) {
|
|
446
|
+
return symbolSize - SSBG1_LENGTH_FIELD_BYTES;
|
|
447
|
+
}
|
|
448
|
+
function ssbg1FitsSymbol(packetLength, symbolSize) {
|
|
449
|
+
return Number.isSafeInteger(packetLength) && packetLength >= 0 && packetLength <= ssbg1MaxPacketLength(symbolSize) && packetLength <= 65535;
|
|
450
|
+
}
|
|
451
|
+
function trimSsbg1SourceSymbol(symbol) {
|
|
452
|
+
if (symbol.byteLength < SSBG1_LENGTH_FIELD_BYTES)
|
|
453
|
+
return null;
|
|
454
|
+
const length = symbol[0] << 8 | symbol[1];
|
|
455
|
+
const end = SSBG1_LENGTH_FIELD_BYTES + length;
|
|
456
|
+
if (end > symbol.byteLength)
|
|
457
|
+
return null;
|
|
458
|
+
for (let i = end; i < symbol.byteLength; i++) {
|
|
459
|
+
if (symbol[i] !== 0)
|
|
460
|
+
return null;
|
|
461
|
+
}
|
|
462
|
+
return symbol.subarray(SSBG1_LENGTH_FIELD_BYTES, end);
|
|
463
|
+
}
|
|
464
|
+
function isoBlockContains(ssStart, ssbLength, ssId) {
|
|
465
|
+
return serial32Distance(ssStart, ssId) < ssbLength;
|
|
466
|
+
}
|
|
467
|
+
function isoBlocksBehindLowerBound(a, b, kMax) {
|
|
468
|
+
if (!Number.isSafeInteger(kMax) || kMax <= 0) {
|
|
469
|
+
throw new Error(`iso-ssbg1-v1 block horizon needs a positive maximum K (got ${kMax})`);
|
|
470
|
+
}
|
|
471
|
+
return serial32Precedes(a, b) ? Math.floor(serial32Distance(a, b) / kMax) : 0;
|
|
472
|
+
}
|
|
375
473
|
|
|
376
474
|
// ../mmt-base/dist/catalog-fec-source.js
|
|
377
475
|
var ALL_ROLES = Object.freeze(["video", "audio"]);
|
|
@@ -7913,6 +8011,36 @@ var BlockcastMmt = (() => {
|
|
|
7913
8011
|
}
|
|
7914
8012
|
return Math.ceil(interleaveDepthMs * safetyFactor);
|
|
7915
8013
|
}
|
|
8014
|
+
function fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs) {
|
|
8015
|
+
if (!Number.isFinite(interleaveDepthMs) || !(interleaveDepthMs > 0)) {
|
|
8016
|
+
throw new Error(`[FEC] interleaveDepthMs must be a finite value > 0 (got ${interleaveDepthMs}ms). Fix encoder config.`);
|
|
8017
|
+
}
|
|
8018
|
+
if (!(reorderToleranceMs >= 0) || !Number.isFinite(reorderToleranceMs)) {
|
|
8019
|
+
throw new Error(`[FEC] reorderToleranceMs must be a finite value >= 0 (got ${reorderToleranceMs}ms). It is a catalog value (fec.reorderToleranceMs), not a local default.`);
|
|
8020
|
+
}
|
|
8021
|
+
return Math.ceil(interleaveDepthMs + reorderToleranceMs);
|
|
8022
|
+
}
|
|
8023
|
+
function deriveFecRetentionBlocks(deliveryWindowMs, interleaveDepthMs) {
|
|
8024
|
+
const blocks = tryDeriveFecRetentionBlocks(deliveryWindowMs, interleaveDepthMs);
|
|
8025
|
+
if (blocks !== void 0)
|
|
8026
|
+
return blocks;
|
|
8027
|
+
if (!Number.isFinite(interleaveDepthMs) || !(interleaveDepthMs > 0)) {
|
|
8028
|
+
throw new Error(`[FEC] interleaveDepthMs must be a finite value > 0 (got ${interleaveDepthMs}ms). Fix encoder config.`);
|
|
8029
|
+
}
|
|
8030
|
+
if (!Number.isFinite(deliveryWindowMs) || !(deliveryWindowMs > 0)) {
|
|
8031
|
+
throw new Error(`[FEC] deliveryWindowMs must be a finite value > 0 (got ${deliveryWindowMs}ms). It is derived from catalog geometry, not a local default.`);
|
|
8032
|
+
}
|
|
8033
|
+
throw new Error(`[FEC] retention of ${Math.ceil(deliveryWindowMs / interleaveDepthMs) + 1} blocks exceeds the 255 the decoder and the ISO/IEC 23008-1 AL-FEC signaling byte accept (deliveryWindowMs=${deliveryWindowMs}ms over interleaveDepthMs=${interleaveDepthMs}ms). Fix the catalog geometry: a span this short cannot carry a window this wide.`);
|
|
8034
|
+
}
|
|
8035
|
+
var MAX_FEC_RETENTION_BLOCKS = 255;
|
|
8036
|
+
function tryDeriveFecRetentionBlocks(deliveryWindowMs, interleaveDepthMs) {
|
|
8037
|
+
if (!Number.isFinite(interleaveDepthMs) || !(interleaveDepthMs > 0))
|
|
8038
|
+
return void 0;
|
|
8039
|
+
if (!Number.isFinite(deliveryWindowMs) || !(deliveryWindowMs > 0))
|
|
8040
|
+
return void 0;
|
|
8041
|
+
const blocks = Math.ceil(deliveryWindowMs / interleaveDepthMs) + 1;
|
|
8042
|
+
return blocks > MAX_FEC_RETENTION_BLOCKS ? void 0 : blocks;
|
|
8043
|
+
}
|
|
7916
8044
|
|
|
7917
8045
|
// ../fec/dist/repair-group.js
|
|
7918
8046
|
var WRAP_EPOCH_BITS = 30n;
|
|
@@ -7969,6 +8097,308 @@ var BlockcastMmt = (() => {
|
|
|
7969
8097
|
return INACTIVE["reliable-moq"];
|
|
7970
8098
|
}
|
|
7971
8099
|
|
|
8100
|
+
// src/mmtp-fec-session.ts
|
|
8101
|
+
var _decoder, _blocks, _settled, _have, _newest, _prunedAt, _repairPacketId, _stats3, _MmtpFecSession_instances, drop_fn2, noteNewest_fn, blockStartOf_fn, countHeld_fn, behindHorizon_fn, settle_fn, settleClean_fn, settleDecoded_fn, retireBehindHorizon_fn;
|
|
8102
|
+
var MmtpFecSession = class {
|
|
8103
|
+
/**
|
|
8104
|
+
* @throws when the catalog block lacks or misstates a field the session
|
|
8105
|
+
* needs: the block profile, K, T, `interleaveDepthMs` or
|
|
8106
|
+
* `reorderToleranceMs`. None is defaulted.
|
|
8107
|
+
*/
|
|
8108
|
+
constructor(config) {
|
|
8109
|
+
__privateAdd(this, _MmtpFecSession_instances);
|
|
8110
|
+
__privateAdd(this, _decoder);
|
|
8111
|
+
/** Blocks a repair has defined and that are not settled yet, by SS_Start. */
|
|
8112
|
+
__privateAdd(this, _blocks, /* @__PURE__ */ new Map());
|
|
8113
|
+
/** SS_Starts of settled blocks, so a later repair for one is refused. */
|
|
8114
|
+
__privateAdd(this, _settled, /* @__PURE__ */ new Set());
|
|
8115
|
+
/** SS_IDs whose packet the parser has: received, or recovered by the session. */
|
|
8116
|
+
__privateAdd(this, _have, /* @__PURE__ */ new Set());
|
|
8117
|
+
__privateAdd(this, _newest);
|
|
8118
|
+
/** The newest SS_ID when the remembered SS_IDs were last pruned. */
|
|
8119
|
+
__privateAdd(this, _prunedAt);
|
|
8120
|
+
__privateAdd(this, _repairPacketId);
|
|
8121
|
+
__privateAdd(this, _stats3, {
|
|
8122
|
+
sourceSymbols: 0,
|
|
8123
|
+
repairSymbols: 0,
|
|
8124
|
+
blocksClean: 0,
|
|
8125
|
+
blocksRecovered: 0,
|
|
8126
|
+
blocksFailed: 0,
|
|
8127
|
+
blocksReleased: 0,
|
|
8128
|
+
packetsRecovered: 0,
|
|
8129
|
+
packetsLost: 0,
|
|
8130
|
+
dropped: {}
|
|
8131
|
+
});
|
|
8132
|
+
const fec = config?.fec;
|
|
8133
|
+
if (!fec || typeof fec !== "object") {
|
|
8134
|
+
throw new Error("MmtpFecSession: the catalog fec block is required");
|
|
8135
|
+
}
|
|
8136
|
+
this.blockProfile = parseFecBlockProfile(fec.blockProfile, "fec.blockProfile");
|
|
8137
|
+
this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, "fec.sourceSymbols");
|
|
8138
|
+
this.symbolSize = requirePositiveInteger(fec.symbolSize, "fec.symbolSize");
|
|
8139
|
+
const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, "fec.interleaveDepthMs");
|
|
8140
|
+
const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, "fec.reorderToleranceMs");
|
|
8141
|
+
this.retentionBlocks = deriveFecRetentionBlocks(
|
|
8142
|
+
fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs),
|
|
8143
|
+
interleaveDepthMs
|
|
8144
|
+
);
|
|
8145
|
+
if (typeof config.Decoder !== "function") {
|
|
8146
|
+
throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
|
|
8147
|
+
}
|
|
8148
|
+
const decoder = new config.Decoder(this.retentionBlocks, this.blockProfile);
|
|
8149
|
+
try {
|
|
8150
|
+
decoder.configure_params(this.sourceSymbols, this.symbolSize);
|
|
8151
|
+
} catch (error) {
|
|
8152
|
+
decoder.free();
|
|
8153
|
+
throw error;
|
|
8154
|
+
}
|
|
8155
|
+
__privateSet(this, _decoder, decoder);
|
|
8156
|
+
}
|
|
8157
|
+
/** True once release() ran. */
|
|
8158
|
+
get released() {
|
|
8159
|
+
return __privateGet(this, _decoder) === null;
|
|
8160
|
+
}
|
|
8161
|
+
get stats() {
|
|
8162
|
+
return { ...__privateGet(this, _stats3), dropped: { ...__privateGet(this, _stats3).dropped } };
|
|
8163
|
+
}
|
|
8164
|
+
/**
|
|
8165
|
+
* Feeds one received source packet: the MMTP packet without its four-byte
|
|
8166
|
+
* Source FEC Payload ID, under the SS_ID that ID stated. This is what
|
|
8167
|
+
* MmtpContainerParser's onSourceSymbol() hands over.
|
|
8168
|
+
*
|
|
8169
|
+
* @returns the protected packets of this packet's block that it recovered,
|
|
8170
|
+
* in SS_ID order, for the caller to feed to its parser with
|
|
8171
|
+
* `{skipFecPayloadId: true, recovered: true}`. Usually empty.
|
|
8172
|
+
*/
|
|
8173
|
+
addSource(ssId, packet) {
|
|
8174
|
+
const decoder = __privateGet(this, _decoder);
|
|
8175
|
+
if (!decoder) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:released");
|
|
8176
|
+
if (!Number.isInteger(ssId) || ssId < 0 || ssId > 4294967295) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:bad-ss-id");
|
|
8177
|
+
if (!ssbg1FitsSymbol(packet.byteLength, this.symbolSize)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:exceeds-symbol");
|
|
8178
|
+
if (__privateGet(this, _have).has(ssId)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:duplicate");
|
|
8179
|
+
__privateGet(this, _have).add(ssId);
|
|
8180
|
+
__privateGet(this, _stats3).sourceSymbols++;
|
|
8181
|
+
__privateMethod(this, _MmtpFecSession_instances, noteNewest_fn).call(this, ssId);
|
|
8182
|
+
const start = __privateMethod(this, _MmtpFecSession_instances, blockStartOf_fn).call(this, ssId);
|
|
8183
|
+
const block = start === void 0 ? void 0 : __privateGet(this, _blocks).get(start);
|
|
8184
|
+
if (block) block.received++;
|
|
8185
|
+
let output;
|
|
8186
|
+
try {
|
|
8187
|
+
output = decoder.add_source(ssId, packet, 0);
|
|
8188
|
+
} catch {
|
|
8189
|
+
__privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:decoder-refused");
|
|
8190
|
+
output = void 0;
|
|
8191
|
+
}
|
|
8192
|
+
const recovered = [];
|
|
8193
|
+
if (start !== void 0 && block) {
|
|
8194
|
+
if (output) {
|
|
8195
|
+
recovered.push(...__privateMethod(this, _MmtpFecSession_instances, settleDecoded_fn).call(this, start, block, output));
|
|
8196
|
+
} else if (block.received >= block.ssbLength) {
|
|
8197
|
+
__privateMethod(this, _MmtpFecSession_instances, settleClean_fn).call(this, start);
|
|
8198
|
+
}
|
|
8199
|
+
}
|
|
8200
|
+
__privateMethod(this, _MmtpFecSession_instances, retireBehindHorizon_fn).call(this);
|
|
8201
|
+
return recovered;
|
|
8202
|
+
}
|
|
8203
|
+
/**
|
|
8204
|
+
* Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
|
|
8205
|
+
* 23008-1 C.5.3). A repair track carries one repair flow, so the first
|
|
8206
|
+
* repair packet fixes its packet ID and a packet of any other is refused.
|
|
8207
|
+
*
|
|
8208
|
+
* @returns the protected packets this repair symbol recovered, as for
|
|
8209
|
+
* addSource().
|
|
8210
|
+
*/
|
|
8211
|
+
addRepair(packet) {
|
|
8212
|
+
const decoder = __privateGet(this, _decoder);
|
|
8213
|
+
if (!decoder) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:released");
|
|
8214
|
+
let header;
|
|
8215
|
+
try {
|
|
8216
|
+
header = parseMMTPHeader(packet);
|
|
8217
|
+
} catch {
|
|
8218
|
+
return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:malformed");
|
|
8219
|
+
}
|
|
8220
|
+
const frame = parseMoqRepairFrameWithHeader(packet, header);
|
|
8221
|
+
if (!frame) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:malformed");
|
|
8222
|
+
if (__privateGet(this, _repairPacketId) === void 0) {
|
|
8223
|
+
__privateSet(this, _repairPacketId, frame.packetId);
|
|
8224
|
+
} else if (frame.packetId !== __privateGet(this, _repairPacketId)) {
|
|
8225
|
+
return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:foreign-packet-id");
|
|
8226
|
+
}
|
|
8227
|
+
if (frame.symbolData.byteLength !== this.symbolSize) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:symbol-size");
|
|
8228
|
+
if (frame.ssbLength > this.sourceSymbols) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:ssb-length");
|
|
8229
|
+
const start = frame.ssStart;
|
|
8230
|
+
let block = __privateGet(this, _blocks).get(start);
|
|
8231
|
+
if (block && block.ssbLength !== frame.ssbLength) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:conflicting-ssb-length");
|
|
8232
|
+
if (!block) {
|
|
8233
|
+
if (__privateGet(this, _settled).has(start)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:block-settled");
|
|
8234
|
+
if (__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, start)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:behind-horizon");
|
|
8235
|
+
block = { ssbLength: frame.ssbLength, received: __privateMethod(this, _MmtpFecSession_instances, countHeld_fn).call(this, start, frame.ssbLength) };
|
|
8236
|
+
__privateGet(this, _blocks).set(start, block);
|
|
8237
|
+
}
|
|
8238
|
+
__privateMethod(this, _MmtpFecSession_instances, noteNewest_fn).call(this, serial32Add(start, frame.ssbLength - 1));
|
|
8239
|
+
if (block.received >= block.ssbLength) {
|
|
8240
|
+
__privateMethod(this, _MmtpFecSession_instances, settleClean_fn).call(this, start);
|
|
8241
|
+
__privateMethod(this, _MmtpFecSession_instances, retireBehindHorizon_fn).call(this);
|
|
8242
|
+
return [];
|
|
8243
|
+
}
|
|
8244
|
+
let output;
|
|
8245
|
+
try {
|
|
8246
|
+
output = decoder.add_repair(start, frame.ssbLength, frame.rsId, frame.symbolData, 0);
|
|
8247
|
+
} catch {
|
|
8248
|
+
return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:decoder-refused");
|
|
8249
|
+
}
|
|
8250
|
+
__privateGet(this, _stats3).repairSymbols++;
|
|
8251
|
+
const recovered = output ? __privateMethod(this, _MmtpFecSession_instances, settleDecoded_fn).call(this, start, block, output) : [];
|
|
8252
|
+
__privateMethod(this, _MmtpFecSession_instances, retireBehindHorizon_fn).call(this);
|
|
8253
|
+
return recovered;
|
|
8254
|
+
}
|
|
8255
|
+
/**
|
|
8256
|
+
* Frees the decoder and every block. Blocks still unsettled are counted as
|
|
8257
|
+
* released, not failed: nothing proved them unrecoverable. Idempotent;
|
|
8258
|
+
* returns whether this call released anything.
|
|
8259
|
+
*/
|
|
8260
|
+
release() {
|
|
8261
|
+
const decoder = __privateGet(this, _decoder);
|
|
8262
|
+
if (!decoder) return false;
|
|
8263
|
+
__privateSet(this, _decoder, null);
|
|
8264
|
+
__privateGet(this, _stats3).blocksReleased += __privateGet(this, _blocks).size;
|
|
8265
|
+
__privateGet(this, _blocks).clear();
|
|
8266
|
+
__privateGet(this, _settled).clear();
|
|
8267
|
+
__privateGet(this, _have).clear();
|
|
8268
|
+
decoder.free();
|
|
8269
|
+
return true;
|
|
8270
|
+
}
|
|
8271
|
+
};
|
|
8272
|
+
_decoder = new WeakMap();
|
|
8273
|
+
_blocks = new WeakMap();
|
|
8274
|
+
_settled = new WeakMap();
|
|
8275
|
+
_have = new WeakMap();
|
|
8276
|
+
_newest = new WeakMap();
|
|
8277
|
+
_prunedAt = new WeakMap();
|
|
8278
|
+
_repairPacketId = new WeakMap();
|
|
8279
|
+
_stats3 = new WeakMap();
|
|
8280
|
+
_MmtpFecSession_instances = new WeakSet();
|
|
8281
|
+
drop_fn2 = function(reason) {
|
|
8282
|
+
__privateGet(this, _stats3).dropped[reason] = (__privateGet(this, _stats3).dropped[reason] ?? 0) + 1;
|
|
8283
|
+
return [];
|
|
8284
|
+
};
|
|
8285
|
+
noteNewest_fn = function(ssId) {
|
|
8286
|
+
if (__privateGet(this, _newest) === void 0 || serial32Precedes(__privateGet(this, _newest), ssId)) __privateSet(this, _newest, ssId);
|
|
8287
|
+
};
|
|
8288
|
+
blockStartOf_fn = function(ssId) {
|
|
8289
|
+
for (const [start, block] of __privateGet(this, _blocks)) {
|
|
8290
|
+
if (isoBlockContains(start, block.ssbLength, ssId)) return start;
|
|
8291
|
+
}
|
|
8292
|
+
return void 0;
|
|
8293
|
+
};
|
|
8294
|
+
countHeld_fn = function(start, ssbLength) {
|
|
8295
|
+
let held = 0;
|
|
8296
|
+
for (let i = 0; i < ssbLength; i++) {
|
|
8297
|
+
if (__privateGet(this, _have).has(serial32Add(start, i))) held++;
|
|
8298
|
+
}
|
|
8299
|
+
return held;
|
|
8300
|
+
};
|
|
8301
|
+
/** The decoder's own rule: more than its retention behind, counted from below. */
|
|
8302
|
+
behindHorizon_fn = function(start) {
|
|
8303
|
+
const newest = __privateGet(this, _newest);
|
|
8304
|
+
if (newest === void 0) return false;
|
|
8305
|
+
return isoBlocksBehindLowerBound(start, newest, this.sourceSymbols) > this.retentionBlocks;
|
|
8306
|
+
};
|
|
8307
|
+
settle_fn = function(start) {
|
|
8308
|
+
__privateGet(this, _blocks).delete(start);
|
|
8309
|
+
__privateGet(this, _settled).add(start);
|
|
8310
|
+
};
|
|
8311
|
+
settleClean_fn = function(start) {
|
|
8312
|
+
if (!__privateGet(this, _blocks).has(start)) return;
|
|
8313
|
+
__privateMethod(this, _MmtpFecSession_instances, settle_fn).call(this, start);
|
|
8314
|
+
__privateGet(this, _stats3).blocksClean++;
|
|
8315
|
+
try {
|
|
8316
|
+
__privateGet(this, _decoder)?.cleanup_blocks_detailed(Uint32Array.of(start));
|
|
8317
|
+
} catch {
|
|
8318
|
+
}
|
|
8319
|
+
};
|
|
8320
|
+
/**
|
|
8321
|
+
* The decoder returns a completed block as its K' ssbg_mode1 symbols,
|
|
8322
|
+
* concatenated: split by T, trim by each symbol's length field, and hand
|
|
8323
|
+
* back the packets the parser does not have yet.
|
|
8324
|
+
*/
|
|
8325
|
+
settleDecoded_fn = function(start, block, output) {
|
|
8326
|
+
__privateMethod(this, _MmtpFecSession_instances, settle_fn).call(this, start);
|
|
8327
|
+
if (output.byteLength !== block.ssbLength * this.symbolSize) {
|
|
8328
|
+
__privateGet(this, _stats3).blocksFailed++;
|
|
8329
|
+
__privateGet(this, _stats3).packetsLost += block.ssbLength - block.received;
|
|
8330
|
+
__privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "block:decoded-length");
|
|
8331
|
+
return [];
|
|
8332
|
+
}
|
|
8333
|
+
const recovered = [];
|
|
8334
|
+
let refused = 0;
|
|
8335
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
8336
|
+
const ssId = serial32Add(start, i);
|
|
8337
|
+
if (__privateGet(this, _have).has(ssId)) continue;
|
|
8338
|
+
const symbol = output.subarray(i * this.symbolSize, (i + 1) * this.symbolSize);
|
|
8339
|
+
const packet = trimSsbg1SourceSymbol(symbol);
|
|
8340
|
+
if (!packet) {
|
|
8341
|
+
refused++;
|
|
8342
|
+
continue;
|
|
8343
|
+
}
|
|
8344
|
+
__privateGet(this, _have).add(ssId);
|
|
8345
|
+
recovered.push(packet.slice());
|
|
8346
|
+
}
|
|
8347
|
+
if (refused > 0) {
|
|
8348
|
+
__privateGet(this, _stats3).blocksFailed++;
|
|
8349
|
+
__privateGet(this, _stats3).packetsLost += refused;
|
|
8350
|
+
__privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "block:bad-ssbg1-symbol");
|
|
8351
|
+
} else if (recovered.length === 0) {
|
|
8352
|
+
__privateGet(this, _stats3).blocksClean++;
|
|
8353
|
+
} else {
|
|
8354
|
+
__privateGet(this, _stats3).blocksRecovered++;
|
|
8355
|
+
}
|
|
8356
|
+
__privateGet(this, _stats3).packetsRecovered += recovered.length;
|
|
8357
|
+
return recovered;
|
|
8358
|
+
};
|
|
8359
|
+
/**
|
|
8360
|
+
* Retires every block, and every SS_ID the session remembers, that the
|
|
8361
|
+
* newest SS_ID has moved past the retention. An unsettled block retired
|
|
8362
|
+
* here is a failure: more of its sources were lost than its repair could
|
|
8363
|
+
* restore, or its repair never arrived.
|
|
8364
|
+
*/
|
|
8365
|
+
retireBehindHorizon_fn = function() {
|
|
8366
|
+
const decoder = __privateGet(this, _decoder);
|
|
8367
|
+
const newest = __privateGet(this, _newest);
|
|
8368
|
+
if (!decoder || newest === void 0) return;
|
|
8369
|
+
try {
|
|
8370
|
+
decoder.cleanup_by_ss_start(newest);
|
|
8371
|
+
} catch {
|
|
8372
|
+
}
|
|
8373
|
+
for (const [start, block] of __privateGet(this, _blocks)) {
|
|
8374
|
+
if (!__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, start)) continue;
|
|
8375
|
+
__privateMethod(this, _MmtpFecSession_instances, settle_fn).call(this, start);
|
|
8376
|
+
__privateGet(this, _stats3).blocksFailed++;
|
|
8377
|
+
__privateGet(this, _stats3).packetsLost += block.ssbLength - block.received;
|
|
8378
|
+
}
|
|
8379
|
+
const prunedAt = __privateGet(this, _prunedAt);
|
|
8380
|
+
if (prunedAt !== void 0 && serial32Distance(prunedAt, newest) < this.sourceSymbols) return;
|
|
8381
|
+
__privateSet(this, _prunedAt, newest);
|
|
8382
|
+
for (const ssId of __privateGet(this, _have)) {
|
|
8383
|
+
if (__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, ssId)) __privateGet(this, _have).delete(ssId);
|
|
8384
|
+
}
|
|
8385
|
+
for (const start of __privateGet(this, _settled)) {
|
|
8386
|
+
if (__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, start)) __privateGet(this, _settled).delete(start);
|
|
8387
|
+
}
|
|
8388
|
+
};
|
|
8389
|
+
function requirePositiveInteger(value, path) {
|
|
8390
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
8391
|
+
throw new Error(`MmtpFecSession: ${path} must be a positive integer (got ${String(value)})`);
|
|
8392
|
+
}
|
|
8393
|
+
return value;
|
|
8394
|
+
}
|
|
8395
|
+
function requireNumber(value, path) {
|
|
8396
|
+
if (typeof value !== "number") {
|
|
8397
|
+
throw new Error(`MmtpFecSession: ${path} is required (got ${String(value)}); it is never defaulted`);
|
|
8398
|
+
}
|
|
8399
|
+
return value;
|
|
8400
|
+
}
|
|
8401
|
+
|
|
7972
8402
|
// src/mmtp-to-cmaf.ts
|
|
7973
8403
|
function box(type, ...children2) {
|
|
7974
8404
|
let size = 8;
|
|
@@ -9242,7 +9672,7 @@ var BlockcastMmt = (() => {
|
|
|
9242
9672
|
return diff === 0;
|
|
9243
9673
|
};
|
|
9244
9674
|
var isPromiseLike = (value) => typeof value === "object" && value !== null && typeof value.then === "function";
|
|
9245
|
-
var _config, _verifySignature, _onFailure, _tracks2,
|
|
9675
|
+
var _config, _verifySignature, _onFailure, _tracks2, _stats4, _disposed2, _ManifestVerifier_instances, requireTrack_fn, group_fn, validateIdentity_fn, admitAgainstEntry_fn, rejectOrShadow_fn, resolvePending_fn, closeGroup_fn, finishGroupSignature_fn, verifyAcceptedSignature_fn, failGroup_fn, removePending_fn, quarantine_fn, enforceCap_fn, giveUpOnPending_fn, failOpenTrack_fn, failOpenGroup_fn, releaseAllQuarantine_fn, failure_fn;
|
|
9246
9676
|
var ManifestVerifier = class {
|
|
9247
9677
|
constructor(options) {
|
|
9248
9678
|
__privateAdd(this, _ManifestVerifier_instances);
|
|
@@ -9250,7 +9680,7 @@ var BlockcastMmt = (() => {
|
|
|
9250
9680
|
__privateAdd(this, _verifySignature);
|
|
9251
9681
|
__privateAdd(this, _onFailure);
|
|
9252
9682
|
__privateAdd(this, _tracks2, /* @__PURE__ */ new Map());
|
|
9253
|
-
__privateAdd(this,
|
|
9683
|
+
__privateAdd(this, _stats4, {
|
|
9254
9684
|
verified: 0,
|
|
9255
9685
|
failures: Object.fromEntries(FAILURE_REASONS.map((reason) => [reason, 0])),
|
|
9256
9686
|
quarantinedBytes: 0
|
|
@@ -9268,10 +9698,10 @@ var BlockcastMmt = (() => {
|
|
|
9268
9698
|
for (const track of __privateGet(this, _tracks2).values())
|
|
9269
9699
|
quarantined += track.quarantine.length;
|
|
9270
9700
|
return {
|
|
9271
|
-
verified: __privateGet(this,
|
|
9272
|
-
failures: { ...__privateGet(this,
|
|
9701
|
+
verified: __privateGet(this, _stats4).verified,
|
|
9702
|
+
failures: { ...__privateGet(this, _stats4).failures },
|
|
9273
9703
|
quarantined,
|
|
9274
|
-
quarantinedBytes: __privateGet(this,
|
|
9704
|
+
quarantinedBytes: __privateGet(this, _stats4).quarantinedBytes
|
|
9275
9705
|
};
|
|
9276
9706
|
}
|
|
9277
9707
|
setMode(mode) {
|
|
@@ -9406,7 +9836,7 @@ var BlockcastMmt = (() => {
|
|
|
9406
9836
|
_verifySignature = new WeakMap();
|
|
9407
9837
|
_onFailure = new WeakMap();
|
|
9408
9838
|
_tracks2 = new WeakMap();
|
|
9409
|
-
|
|
9839
|
+
_stats4 = new WeakMap();
|
|
9410
9840
|
_disposed2 = new WeakMap();
|
|
9411
9841
|
_ManifestVerifier_instances = new WeakSet();
|
|
9412
9842
|
requireTrack_fn = function(bindingId) {
|
|
@@ -9458,7 +9888,7 @@ var BlockcastMmt = (() => {
|
|
|
9458
9888
|
return { action: "stall", verified: false };
|
|
9459
9889
|
}
|
|
9460
9890
|
release();
|
|
9461
|
-
__privateGet(this,
|
|
9891
|
+
__privateGet(this, _stats4).verified++;
|
|
9462
9892
|
return { action: "play", verified: true };
|
|
9463
9893
|
};
|
|
9464
9894
|
rejectOrShadow_fn = function(identity, release, reason) {
|
|
@@ -9598,7 +10028,7 @@ var BlockcastMmt = (() => {
|
|
|
9598
10028
|
if (index >= 0)
|
|
9599
10029
|
track.quarantine.splice(index, 1);
|
|
9600
10030
|
track.quarantinedBytes -= pending.bytes;
|
|
9601
|
-
__privateGet(this,
|
|
10031
|
+
__privateGet(this, _stats4).quarantinedBytes -= pending.bytes;
|
|
9602
10032
|
};
|
|
9603
10033
|
quarantine_fn = function(track, group, pending) {
|
|
9604
10034
|
if (group.pending.has(pending.identity.objectId))
|
|
@@ -9606,7 +10036,7 @@ var BlockcastMmt = (() => {
|
|
|
9606
10036
|
group.pending.set(pending.identity.objectId, pending);
|
|
9607
10037
|
track.quarantine.push(pending);
|
|
9608
10038
|
track.quarantinedBytes += pending.bytes;
|
|
9609
|
-
__privateGet(this,
|
|
10039
|
+
__privateGet(this, _stats4).quarantinedBytes += pending.bytes;
|
|
9610
10040
|
__privateMethod(this, _ManifestVerifier_instances, enforceCap_fn).call(this, track);
|
|
9611
10041
|
return true;
|
|
9612
10042
|
};
|
|
@@ -9617,7 +10047,7 @@ var BlockcastMmt = (() => {
|
|
|
9617
10047
|
if (group)
|
|
9618
10048
|
group.pending.delete(pending.identity.objectId);
|
|
9619
10049
|
track.quarantinedBytes -= pending.bytes;
|
|
9620
|
-
__privateGet(this,
|
|
10050
|
+
__privateGet(this, _stats4).quarantinedBytes -= pending.bytes;
|
|
9621
10051
|
__privateMethod(this, _ManifestVerifier_instances, giveUpOnPending_fn).call(this, pending);
|
|
9622
10052
|
__privateMethod(this, _ManifestVerifier_instances, failure_fn).call(this, pending.identity, "manifestAbsent");
|
|
9623
10053
|
console.warn(`[ManifestVerifier] quarantine cap eviction track=${pending.identity.trackName} group=${pending.identity.groupId} object=${pending.identity.objectId} disposition=${__privateGet(this, _config).mode === "enforce" ? "drop" : "fail-open"}`);
|
|
@@ -9674,7 +10104,7 @@ var BlockcastMmt = (() => {
|
|
|
9674
10104
|
};
|
|
9675
10105
|
failure_fn = function(identity, reason) {
|
|
9676
10106
|
var _a;
|
|
9677
|
-
__privateGet(this,
|
|
10107
|
+
__privateGet(this, _stats4).failures[reason]++;
|
|
9678
10108
|
(_a = __privateGet(this, _onFailure)) == null ? void 0 : _a.call(this, {
|
|
9679
10109
|
trackName: identity.trackName,
|
|
9680
10110
|
...identity.bindingId === void 0 ? {} : { bindingId: identity.bindingId },
|