@blockcast/mmt-container 0.4.0 → 0.4.1-main.cbe342dbdd9c
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 +1839 -692
- package/dist/browser-runtime.js.map +4 -4
- package/dist/carp-catalog.d.ts +76 -39
- package/dist/carp-catalog.d.ts.map +1 -1
- package/dist/carp-catalog.js +321 -205
- package/dist/carp-catalog.js.map +3 -3
- package/dist/catalog-fec-params.d.ts +12 -4
- package/dist/catalog-fec-params.d.ts.map +1 -1
- package/dist/catalog-fec-params.js +40 -17
- package/dist/catalog-fec-params.js.map +3 -3
- package/dist/catalog-network-source.d.ts +28 -7
- package/dist/catalog-network-source.d.ts.map +1 -1
- package/dist/catalog-network-source.js +21 -1
- package/dist/catalog-network-source.js.map +2 -2
- package/dist/catalog-validator.d.ts +4 -3
- package/dist/catalog-validator.d.ts.map +1 -1
- package/dist/catalog-validator.js +0 -29
- package/dist/catalog-validator.js.map +3 -3
- package/dist/cmcd-producer.d.ts +8 -0
- package/dist/cmcd-producer.d.ts.map +1 -1
- package/dist/cmcd-producer.js +14 -0
- package/dist/cmcd-producer.js.map +2 -2
- package/dist/delivery-catalog.js +98 -234
- package/dist/delivery-catalog.js.map +4 -4
- package/dist/fec-manager.d.ts +121 -1
- package/dist/fec-manager.d.ts.map +1 -1
- package/dist/fec-manager.js +421 -66
- package/dist/fec-manager.js.map +3 -3
- package/dist/fec-state.d.ts +2 -1
- package/dist/fec-state.d.ts.map +1 -1
- package/dist/fec-state.js +18 -3
- package/dist/fec-state.js.map +3 -3
- package/dist/fec-worker-setup.d.ts +10 -0
- package/dist/fec-worker-setup.d.ts.map +1 -1
- package/dist/fec-worker-setup.js +15 -4
- package/dist/fec-worker-setup.js.map +2 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +2 -2
- package/dist/iso-block-locator.d.ts +39 -1
- package/dist/iso-block-locator.d.ts.map +1 -1
- package/dist/iso-block-locator.js +109 -17
- package/dist/iso-block-locator.js.map +3 -3
- package/dist/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 +21 -13
- package/dist/mfu-reassembler.js.map +2 -2
- package/dist/mmtp-container-parser.d.ts.map +1 -1
- package/dist/mmtp-container-parser.js +93 -22
- package/dist/mmtp-container-parser.js.map +2 -2
- package/dist/mmtp-container-parser.no-modules.js +1137 -317
- package/dist/mmtp-container-parser.no-modules.js.map +4 -4
- package/dist/mmtp-decode-pipeline.js +93 -22
- package/dist/mmtp-decode-pipeline.js.map +2 -2
- package/dist/mmtp-fec-session.d.ts +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 +39 -6
- package/dist/mmtp-router.d.ts.map +1 -1
- package/dist/mmtp-router.js +184 -27
- package/dist/mmtp-router.js.map +2 -2
- package/dist/multicast-auth-catalog.d.ts +86 -92
- package/dist/multicast-auth-catalog.d.ts.map +1 -1
- package/dist/multicast-auth-catalog.js +347 -132
- package/dist/multicast-auth-catalog.js.map +4 -4
- package/dist/multicast-input.d.ts +31 -8
- package/dist/multicast-input.d.ts.map +1 -1
- package/dist/multicast-input.js +299 -35
- package/dist/multicast-input.js.map +3 -3
- package/dist/multicast-manager.d.ts +94 -5
- package/dist/multicast-manager.d.ts.map +1 -1
- package/dist/multicast-manager.js +877 -357
- package/dist/multicast-manager.js.map +4 -4
- package/dist/multicast-transport.d.ts +12 -2
- package/dist/multicast-transport.d.ts.map +1 -1
- package/dist/multicast-transport.js +108 -238
- package/dist/multicast-transport.js.map +4 -4
- package/dist/multicast-unwrap.js +21 -13
- package/dist/multicast-unwrap.js.map +2 -2
- package/dist/no-modules.d.ts +4 -1
- package/dist/no-modules.d.ts.map +1 -1
- package/dist/no-modules.js +1086 -301
- package/dist/no-modules.js.map +4 -4
- package/dist/phase14-catalog-override.d.ts +1 -1
- package/dist/phase14-catalog-override.d.ts.map +1 -1
- package/dist/phase14-catalog-override.js +2 -2
- package/dist/phase14-catalog-override.js.map +2 -2
- package/dist/repair-fetch.d.ts +81 -6
- package/dist/repair-fetch.d.ts.map +1 -1
- package/dist/repair-fetch.js +156 -31
- package/dist/repair-fetch.js.map +3 -3
- package/dist/repair-layers.d.ts +2 -0
- package/dist/repair-layers.d.ts.map +1 -1
- package/dist/repair-layers.js +19 -2
- package/dist/repair-layers.js.map +2 -2
- package/dist/sample-combiner.d.ts +7 -1
- package/dist/sample-combiner.d.ts.map +1 -1
- package/dist/sample-combiner.js +14 -2
- package/dist/sample-combiner.js.map +2 -2
- package/dist/signaling.d.ts +2 -2
- package/dist/signaling.d.ts.map +1 -1
- package/dist/signaling.js +3 -3
- package/dist/signaling.js.map +2 -2
- package/dist/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 +21 -13
- package/dist/timestamp-codec.js.map +2 -2
- package/dist/wasm-mfu-reassembler.js.map +1 -1
- package/dist/wasm-mmtp-container-parser.js +93 -22
- package/dist/wasm-mmtp-container-parser.js.map +2 -2
- package/package.json +6 -9
- package/schemas/catalog.schema.json +133 -38
- package/src/align.ts +52 -21
- package/src/carp-catalog.ts +188 -68
- package/src/catalog-fec-params.ts +28 -3
- package/src/catalog-network-source.ts +49 -7
- package/src/catalog-validator.ts +4 -11
- package/src/cmcd-producer.ts +17 -0
- package/src/fec-manager.ts +452 -63
- package/src/fec-state.ts +11 -4
- package/src/fec-worker-setup.ts +30 -2
- package/src/index.ts +27 -10
- package/src/iso-block-locator.ts +110 -7
- 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 +166 -7
- package/src/multicast-auth-catalog.ts +131 -238
- package/src/multicast-input.ts +148 -124
- package/src/multicast-manager.ts +267 -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 +71 -4
- package/test-vectors/catalog/negative/fec-block-profile-missing.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-retired.json +1 -1
- package/test-vectors/catalog/negative/fec-block-profile-unknown.json +1 -1
- package/test-vectors/catalog/negative/fec-iso-symbol-size-below-floor.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-iso-symbol-size-13.json +28 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-k-plus-p-over-255.json +39 -0
- package/test-vectors/catalog/negative/fec-reed-solomon-overlay-over-255.json +40 -0
- package/test-vectors/catalog/negative/fec-repair-overlay-source-symbols-zero.json +43 -0
- package/test-vectors/catalog/negative/fec-repair-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-source-symbols-zero.json +28 -0
- package/test-vectors/catalog/negative/fec-symbol-size-zero.json +28 -0
- package/test-vectors/catalog/negative/init-data-inline-without-data.json +22 -0
- package/test-vectors/catalog/negative/mmtp-mode-mpu.json +15 -0
- package/test-vectors/catalog/negative/multicast-amt-dns-without-relay.json +37 -0
- package/test-vectors/catalog/negative/multicast-amt-driad-with-relay.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-asm-missing-sender-address.json +77 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-first-epoch.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-duplicate-kid.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-auth-without-object-auth.json +38 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-auth.json +49 -0
- package/test-vectors/catalog/negative/multicast-auth-endpoint-missing-bandwidth.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-port-equals-port.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-manifest-timer-out-of-range.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-above-max.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-max-auth-delay-below-min.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-root-dotted-key.json +55 -0
- package/test-vectors/catalog/negative/multicast-auth-sender-address-on-ssm.json +57 -0
- package/test-vectors/catalog/negative/multicast-auth-version-1.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-3.json +56 -0
- package/test-vectors/catalog/negative/multicast-auth-version-missing.json +55 -0
- package/test-vectors/catalog/negative/multicast-endpoint-foreign-namespace-track.json +44 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-amt.json +38 -0
- package/test-vectors/catalog/negative/multicast-endpoint-protocol-atsc3.json +38 -0
- package/test-vectors/catalog/negative/presentation-anchor-unsafe.json +16 -0
- package/test-vectors/catalog/positive/fec-algorithm-unimplemented.json +29 -0
- package/test-vectors/catalog/positive/fec-iso-ssbg1.json +1 -1
- package/test-vectors/catalog/positive/fec-multicast.json +1 -1
- package/test-vectors/catalog/positive/fec-reed-solomon-layered.json +50 -0
- package/test-vectors/catalog/positive/mmt01-12-1-init-ref-anchor.json +29 -0
- package/test-vectors/catalog/positive/multicast-amt-discovery-omitted.json +37 -0
- package/test-vectors/catalog/positive/multicast-amt-dns-relay.json +38 -0
- package/test-vectors/catalog/positive/multicast-amt-manual-relay.json +3 -3
- package/test-vectors/catalog/{negative/multicast-endpoint-missing-protocol-and-source.json → positive/multicast-asm-unprotected.json} +10 -5
- package/test-vectors/catalog/positive/multicast-auth-asm-sender.json +78 -0
- package/test-vectors/catalog/positive/multicast-auth-rotation.json +39 -38
- package/test-vectors/catalog/positive/multicast-draft01-4-1-example.json +81 -0
- package/test-vectors/catalog/positive/multicast-draft01-7-2-6-example.json +70 -0
- package/test-vectors/catalog/positive/presentation-anchor-negative.json +27 -0
- package/test-vectors/catalog/section-codes.json +31 -1
- package/test-vectors/catalog-multicast-auth-v1.json +38 -20
- package/test-vectors/catalog-validation.json +101 -5
- package/test-vectors/catalog-validator-public-api.mjs +14 -9
- package/test-vectors/generate-bc-provenance-v2.mjs +252 -0
- package/dist/fec-codec.d.ts +0 -32
- package/dist/fec-codec.d.ts.map +0 -1
- package/dist/fec-codec.js +0 -47
- package/dist/fec-codec.js.map +0 -7
- package/src/fec-codec.ts +0 -61
|
@@ -41,14 +41,19 @@ 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,
|
|
46
|
+
catalogAmtNetworkSource: () => catalogAmtNetworkSource,
|
|
47
|
+
catalogAtsc3NetworkSource: () => catalogAtsc3NetworkSource,
|
|
45
48
|
catalogDeclaresFec: () => catalogDeclaresFec,
|
|
46
49
|
catalogFecInterleaveMs: () => catalogFecInterleaveMs,
|
|
47
|
-
computeFecTimeout: () => computeFecTimeout,
|
|
48
50
|
createManifestAuthPlan: () => createManifestAuthPlan,
|
|
49
51
|
createWasmMmtpContainerParser: () => createWasmMmtpContainerParser,
|
|
50
52
|
createWebCryptoEd25519Verifier: () => createWebCryptoEd25519Verifier,
|
|
51
53
|
datagramMfuReassembly: () => datagramMfuReassembly,
|
|
54
|
+
fecBlockBudgetMs: () => fecBlockBudgetMs,
|
|
55
|
+
fecBlockDeadlineMs: () => fecBlockDeadlineMs,
|
|
56
|
+
isFmp4InitSegment: () => isFmp4InitSegment,
|
|
52
57
|
manifestBindingId: () => manifestBindingId,
|
|
53
58
|
mmtpFrameReorderWindowFrames: () => mmtpFrameReorderWindowFrames,
|
|
54
59
|
reliableMoqMfuReassembly: () => reliableMoqMfuReassembly,
|
|
@@ -209,26 +214,30 @@ var BlockcastMmt = (() => {
|
|
|
209
214
|
const authLength = view2.getUint16(2, false);
|
|
210
215
|
return start + LEGACY_TRAILER_HEADER_SIZE + authLength === end;
|
|
211
216
|
}
|
|
212
|
-
function resolveDeclaredTrailers(payload, declaredEnd, fecType, options) {
|
|
217
|
+
function resolveDeclaredTrailers(payload, declaredEnd, fecType, options, rapFlag = false) {
|
|
213
218
|
if (declaredEnd > payload.length)
|
|
214
219
|
return null;
|
|
215
220
|
if (options?.skipFecId) {
|
|
216
|
-
return isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length) ? { hasFecId: false } : null;
|
|
221
|
+
return isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length) ? { hasFecId: false, hasOverlayFecId: false } : null;
|
|
217
222
|
}
|
|
223
|
+
const overlay = options?.overlayDeclared === true && rapFlag;
|
|
218
224
|
if (fecType === 1) {
|
|
219
|
-
const fecStart = payload.length -
|
|
225
|
+
const fecStart = payload.length - sourceFecTrailerSize(overlay);
|
|
220
226
|
if (fecStart < declaredEnd || !isEmptyOrExactLegacyTrailer(payload, declaredEnd, fecStart)) {
|
|
221
227
|
return null;
|
|
222
228
|
}
|
|
223
|
-
return { hasFecId: true };
|
|
229
|
+
return { hasFecId: true, hasOverlayFecId: overlay };
|
|
224
230
|
}
|
|
225
|
-
if (fecType !== 0)
|
|
231
|
+
if (fecType !== 0 || overlay)
|
|
226
232
|
return null;
|
|
227
233
|
if (isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length)) {
|
|
228
|
-
return { hasFecId: false };
|
|
234
|
+
return { hasFecId: false, hasOverlayFecId: false };
|
|
229
235
|
}
|
|
230
236
|
return null;
|
|
231
237
|
}
|
|
238
|
+
function sourceFecTrailerSize(overlay) {
|
|
239
|
+
return overlay ? 2 * SOURCE_FEC_PAYLOAD_ID_SIZE : SOURCE_FEC_PAYLOAD_ID_SIZE;
|
|
240
|
+
}
|
|
232
241
|
function planMfuExtraction(mmtpPacket, options, parsedHeader) {
|
|
233
242
|
if (mmtpPacket.length < MMTP_HEADER_SIZE + MPU_HEADER_SIZE) {
|
|
234
243
|
return {
|
|
@@ -281,15 +290,16 @@ var BlockcastMmt = (() => {
|
|
|
281
290
|
if ("rejection" in layoutResult)
|
|
282
291
|
return layoutResult;
|
|
283
292
|
const { layout } = layoutResult;
|
|
284
|
-
const trailerLayout = resolveDeclaredTrailers(payload, layout.dataEnd, header.fecType, options);
|
|
293
|
+
const trailerLayout = resolveDeclaredTrailers(payload, layout.dataEnd, header.fecType, options, header.rapFlag);
|
|
285
294
|
if (!trailerLayout) {
|
|
286
295
|
if (!options?.skipFecId && header.fecType === 1) {
|
|
287
296
|
const observed = payload.length - layout.dataEnd;
|
|
288
|
-
|
|
297
|
+
const expected = sourceFecTrailerSize(options?.overlayDeclared === true && header.rapFlag);
|
|
298
|
+
if (observed !== expected) {
|
|
289
299
|
return {
|
|
290
300
|
rejection: {
|
|
291
301
|
gate: "source-fec-payload-id-width-mismatch",
|
|
292
|
-
detail: `producer wrote a ${observed}-byte Source FEC Payload ID, ISO/IEC 23008-1 \xA7C.5.2 requires ${
|
|
302
|
+
detail: `producer wrote a ${observed}-byte Source FEC Payload ID, ISO/IEC 23008-1 \xA7C.5.2 requires ${expected} (payload=${payload.length}, declaredEnd=${layout.dataEnd})`
|
|
293
303
|
}
|
|
294
304
|
};
|
|
295
305
|
}
|
|
@@ -316,10 +326,13 @@ var BlockcastMmt = (() => {
|
|
|
316
326
|
const mfuDuHeader = mfuDuHeaderPresent && mpu.timedFlag === 1 ? parseTimedMfuDuHeader(payload, MPU_HEADER_SIZE) : null;
|
|
317
327
|
const itemId = mfuDuHeaderPresent && mpu.timedFlag === 0 ? new DataView(payload.buffer, payload.byteOffset + MPU_HEADER_SIZE, 4).getUint32(0, false) : null;
|
|
318
328
|
const data = payload.subarray(mfuOffset, dataEnd);
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
329
|
+
const trailerStart = mmtpPacket.length - sourceFecTrailerSize(trailerLayout.hasOverlayFecId);
|
|
330
|
+
const ssIdAt = (offset) => ({
|
|
331
|
+
ssId: new DataView(mmtpPacket.buffer, mmtpPacket.byteOffset + offset, 4).getUint32(0, false)
|
|
332
|
+
});
|
|
333
|
+
const fecPayloadId = trailerLayout.hasFecId ? ssIdAt(trailerStart) : null;
|
|
334
|
+
const overlayFecPayloadId = trailerLayout.hasOverlayFecId ? ssIdAt(trailerStart + SOURCE_FEC_PAYLOAD_ID_SIZE) : null;
|
|
335
|
+
return { header, mpu, fragmentType, data, mfuDuHeader, itemId, fecPayloadId, overlayFecPayloadId };
|
|
323
336
|
}
|
|
324
337
|
function sourceFecPayloadIdOf(mmtpPacket, header) {
|
|
325
338
|
if (mmtpPacket.length < MMTP_HEADER_SIZE + MPU_HEADER_SIZE)
|
|
@@ -340,6 +353,57 @@ var BlockcastMmt = (() => {
|
|
|
340
353
|
ssId: (mmtpPacket[off] << 24 | mmtpPacket[off + 1] << 16 | mmtpPacket[off + 2] << 8 | mmtpPacket[off + 3]) >>> 0
|
|
341
354
|
};
|
|
342
355
|
}
|
|
356
|
+
var REPAIR_FEC_PID_SIZE = 13;
|
|
357
|
+
function readRepairFecPayloadIdFields(mmtpPacket, parsedHeader) {
|
|
358
|
+
let header;
|
|
359
|
+
if (parsedHeader) {
|
|
360
|
+
header = parsedHeader;
|
|
361
|
+
} else {
|
|
362
|
+
try {
|
|
363
|
+
header = parseMMTPHeader(mmtpPacket);
|
|
364
|
+
} catch {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (header.packetType !== PACKET_TYPE_REPAIR || header.fecType !== 2)
|
|
369
|
+
return null;
|
|
370
|
+
const off = header.headerLength;
|
|
371
|
+
if (mmtpPacket.length < off + REPAIR_FEC_PID_SIZE)
|
|
372
|
+
return null;
|
|
373
|
+
const ssStart = (mmtpPacket[off] << 24 | mmtpPacket[off + 1] << 16 | mmtpPacket[off + 2] << 8 | mmtpPacket[off + 3]) >>> 0;
|
|
374
|
+
const rsbLength = mmtpPacket[off + 4] << 16 | mmtpPacket[off + 5] << 8 | mmtpPacket[off + 6];
|
|
375
|
+
const rsId = mmtpPacket[off + 7] << 16 | mmtpPacket[off + 8] << 8 | mmtpPacket[off + 9];
|
|
376
|
+
const ssbLength = mmtpPacket[off + 10] << 16 | mmtpPacket[off + 11] << 8 | mmtpPacket[off + 12];
|
|
377
|
+
return {
|
|
378
|
+
packetId: header.packetId,
|
|
379
|
+
ssStart,
|
|
380
|
+
rsbLength,
|
|
381
|
+
rsId,
|
|
382
|
+
ssbLength,
|
|
383
|
+
dataOffset: off + REPAIR_FEC_PID_SIZE
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function parseMoqRepairFrameWithHeader(frame, header) {
|
|
387
|
+
return moqRepairFrameFrom(frame, readRepairFecPayloadIdFields(frame, header));
|
|
388
|
+
}
|
|
389
|
+
function moqRepairFrameFrom(frame, repairId) {
|
|
390
|
+
if (!repairId)
|
|
391
|
+
return null;
|
|
392
|
+
const symbolData = frame.subarray(repairId.dataOffset);
|
|
393
|
+
if (repairId.rsbLength === 0 || repairId.ssbLength === 0 || repairId.rsId >= repairId.rsbLength || symbolData.length === 0)
|
|
394
|
+
return null;
|
|
395
|
+
return {
|
|
396
|
+
packetId: repairId.packetId,
|
|
397
|
+
ssStart: repairId.ssStart,
|
|
398
|
+
rsbLength: repairId.rsbLength,
|
|
399
|
+
rsId: repairId.rsId,
|
|
400
|
+
ssbLength: repairId.ssbLength,
|
|
401
|
+
symbolData
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ../mmt-base/dist/net-constants.js
|
|
406
|
+
var DEFAULT_AMT_RELAY_PORT = 2268;
|
|
343
407
|
|
|
344
408
|
// ../mmt-base/dist/ntp-short.js
|
|
345
409
|
var NTP_SHORT_BITS = 32;
|
|
@@ -348,6 +412,26 @@ var BlockcastMmt = (() => {
|
|
|
348
412
|
|
|
349
413
|
// ../mmt-base/dist/serial-number.js
|
|
350
414
|
var SERIAL32_SPAN = 4294967296;
|
|
415
|
+
var SERIAL32_HALF = 2147483648;
|
|
416
|
+
function assertUint32(value, name) {
|
|
417
|
+
if (!Number.isInteger(value) || value < 0 || value >= SERIAL32_SPAN) {
|
|
418
|
+
throw new RangeError(`${name} must be a uint32 (got ${value})`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
function serial32Add(s, n) {
|
|
422
|
+
assertUint32(s, "s");
|
|
423
|
+
if (!Number.isInteger(n) || n <= -SERIAL32_HALF || n >= SERIAL32_HALF) {
|
|
424
|
+
throw new RangeError(`serial addend must lie in (-2^31, 2^31) (got ${n})`);
|
|
425
|
+
}
|
|
426
|
+
return (s + n + SERIAL32_SPAN) % SERIAL32_SPAN;
|
|
427
|
+
}
|
|
428
|
+
function serial32Distance(from, to) {
|
|
429
|
+
return to - from >>> 0;
|
|
430
|
+
}
|
|
431
|
+
function serial32Precedes(a, b) {
|
|
432
|
+
const distance = serial32Distance(a, b);
|
|
433
|
+
return distance !== 0 && distance < SERIAL32_HALF;
|
|
434
|
+
}
|
|
351
435
|
|
|
352
436
|
// ../mmt-base/dist/fec-block-profile.js
|
|
353
437
|
var FEC_BLOCK_PROFILES = Object.freeze([
|
|
@@ -364,6 +448,35 @@ var BlockcastMmt = (() => {
|
|
|
364
448
|
}
|
|
365
449
|
throw new Error(`${where} must be "iso-ssbg1-v1" (got ${JSON.stringify(value)})`);
|
|
366
450
|
}
|
|
451
|
+
var SSBG1_LENGTH_FIELD_BYTES = 2;
|
|
452
|
+
function ssbg1MaxPacketLength(symbolSize) {
|
|
453
|
+
return symbolSize - SSBG1_LENGTH_FIELD_BYTES;
|
|
454
|
+
}
|
|
455
|
+
function ssbg1FitsSymbol(packetLength, symbolSize) {
|
|
456
|
+
return Number.isSafeInteger(packetLength) && packetLength >= 0 && packetLength <= ssbg1MaxPacketLength(symbolSize) && packetLength <= 65535;
|
|
457
|
+
}
|
|
458
|
+
function trimSsbg1SourceSymbol(symbol) {
|
|
459
|
+
if (symbol.byteLength < SSBG1_LENGTH_FIELD_BYTES)
|
|
460
|
+
return null;
|
|
461
|
+
const length = symbol[0] << 8 | symbol[1];
|
|
462
|
+
const end = SSBG1_LENGTH_FIELD_BYTES + length;
|
|
463
|
+
if (end > symbol.byteLength)
|
|
464
|
+
return null;
|
|
465
|
+
for (let i = end; i < symbol.byteLength; i++) {
|
|
466
|
+
if (symbol[i] !== 0)
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
return symbol.subarray(SSBG1_LENGTH_FIELD_BYTES, end);
|
|
470
|
+
}
|
|
471
|
+
function isoBlockContains(ssStart, ssbLength, ssId) {
|
|
472
|
+
return serial32Distance(ssStart, ssId) < ssbLength;
|
|
473
|
+
}
|
|
474
|
+
function isoBlocksBehindLowerBound(a, b, kMax) {
|
|
475
|
+
if (!Number.isSafeInteger(kMax) || kMax <= 0) {
|
|
476
|
+
throw new Error(`iso-ssbg1-v1 block horizon needs a positive maximum K (got ${kMax})`);
|
|
477
|
+
}
|
|
478
|
+
return serial32Precedes(a, b) ? Math.floor(serial32Distance(a, b) / kMax) : 0;
|
|
479
|
+
}
|
|
367
480
|
|
|
368
481
|
// ../mmt-base/dist/catalog-fec-source.js
|
|
369
482
|
var ALL_ROLES = Object.freeze(["video", "audio"]);
|
|
@@ -377,6 +490,269 @@ var BlockcastMmt = (() => {
|
|
|
377
490
|
const ms = block["interleaveDepthMs"];
|
|
378
491
|
return ms === void 0 || typeof ms === "number" && Number.isSafeInteger(ms) && ms >= 0;
|
|
379
492
|
}
|
|
493
|
+
function fecAlgorithmUnimplemented(algorithm) {
|
|
494
|
+
return typeof algorithm === "string" && algorithm !== "none" && algorithm !== "raptorq" && algorithm !== "reed-solomon";
|
|
495
|
+
}
|
|
496
|
+
function isPositiveSafeInteger(value) {
|
|
497
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
498
|
+
}
|
|
499
|
+
var ISO_SSBG1_MIN_SYMBOL_SIZE = 14;
|
|
500
|
+
function catalogFecDeclaresUnconfigurableInstance(fec) {
|
|
501
|
+
const block = recordOf(fec);
|
|
502
|
+
if (block === void 0 || block["algorithm"] === "none" || fecAlgorithmUnimplemented(block["algorithm"]))
|
|
503
|
+
return false;
|
|
504
|
+
if (!(isPositiveSafeInteger(block["sourceSymbols"]) && isPositiveSafeInteger(block["symbolSize"])))
|
|
505
|
+
return true;
|
|
506
|
+
return block["blockProfile"] === "iso-ssbg1-v1" && block["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// ../mmt-base/dist/multicast-catalog.js
|
|
510
|
+
var ED25519_PUBLIC_KEY_BASE64URL = /^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/;
|
|
511
|
+
var UINT32_MAX = 4294967295;
|
|
512
|
+
var AUTH_MEMBERS = /* @__PURE__ */ new Set(["scheme", "version", "sig", "keys", "minEpoch"]);
|
|
513
|
+
var KEY_MEMBERS = /* @__PURE__ */ new Set(["kid", "publicKey", "firstEpoch"]);
|
|
514
|
+
var ENDPOINT_AUTH_MEMBERS = /* @__PURE__ */ new Set([
|
|
515
|
+
"manifestPort",
|
|
516
|
+
"streamId",
|
|
517
|
+
"senderAddress",
|
|
518
|
+
"maxAuthDelayMs",
|
|
519
|
+
"manifestTimerMs",
|
|
520
|
+
"manifestTrack"
|
|
521
|
+
]);
|
|
522
|
+
function isObject(value) {
|
|
523
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
524
|
+
}
|
|
525
|
+
function isNonEmptyString(value) {
|
|
526
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
527
|
+
}
|
|
528
|
+
function isIntegerIn(value, min, max) {
|
|
529
|
+
return Number.isSafeInteger(value) && value >= min && value <= max;
|
|
530
|
+
}
|
|
531
|
+
function multicastEndpointSource(endpoint) {
|
|
532
|
+
if (!isObject(endpoint))
|
|
533
|
+
return void 0;
|
|
534
|
+
const sourceAddress = endpoint["sourceAddress"];
|
|
535
|
+
if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress))
|
|
536
|
+
return void 0;
|
|
537
|
+
const mode = sourceAddress === void 0 ? "asm" : "ssm";
|
|
538
|
+
const protocol = endpoint["protocol"];
|
|
539
|
+
if (protocol !== void 0 && protocol !== mode)
|
|
540
|
+
return void 0;
|
|
541
|
+
const auth = endpoint["auth"];
|
|
542
|
+
const senderAddress = isObject(auth) ? auth["senderAddress"] : void 0;
|
|
543
|
+
if (mode === "ssm")
|
|
544
|
+
return senderAddress === void 0 ? { mode, source: sourceAddress } : void 0;
|
|
545
|
+
if (auth === void 0)
|
|
546
|
+
return { mode };
|
|
547
|
+
return isNonEmptyString(senderAddress) ? { mode, source: senderAddress } : void 0;
|
|
548
|
+
}
|
|
549
|
+
function authIssues(auth) {
|
|
550
|
+
const base = "$.multicast.auth";
|
|
551
|
+
const issue = (path, message) => [
|
|
552
|
+
{ code: "multicast_auth", path: `${base}${path}`, message }
|
|
553
|
+
];
|
|
554
|
+
if (!isObject(auth))
|
|
555
|
+
return issue("", "auth must be an object");
|
|
556
|
+
const unknown = Object.keys(auth).filter((key) => !AUTH_MEMBERS.has(key));
|
|
557
|
+
if (unknown.length > 0) {
|
|
558
|
+
return issue("", `auth has unknown member(s) ${unknown.join(", ")}; draft -01 7.2.6 defines scheme, version, sig, keys and minEpoch`);
|
|
559
|
+
}
|
|
560
|
+
if (auth["scheme"] !== "bc-provenance")
|
|
561
|
+
return issue(".scheme", 'scheme must be "bc-provenance"');
|
|
562
|
+
if (auth["version"] !== 2)
|
|
563
|
+
return issue(".version", "version must be 2 (bc-provenance version 2, draft -01 7.2)");
|
|
564
|
+
if (auth["sig"] !== "ed25519")
|
|
565
|
+
return issue(".sig", 'sig must be "ed25519"');
|
|
566
|
+
const keys = auth["keys"];
|
|
567
|
+
if (!Array.isArray(keys) || keys.length < 1 || keys.length > 4) {
|
|
568
|
+
return issue(".keys", "keys must be an array of one to four {kid, publicKey, firstEpoch} objects");
|
|
569
|
+
}
|
|
570
|
+
const kids = /* @__PURE__ */ new Set();
|
|
571
|
+
const firstEpochs = /* @__PURE__ */ new Set();
|
|
572
|
+
for (let index = 0; index < keys.length; index++) {
|
|
573
|
+
const key = keys[index];
|
|
574
|
+
const at = `.keys[${index}]`;
|
|
575
|
+
if (!isObject(key) || Object.keys(key).some((member) => !KEY_MEMBERS.has(member))) {
|
|
576
|
+
return issue(at, "a key is exactly {kid, publicKey, firstEpoch}");
|
|
577
|
+
}
|
|
578
|
+
if (!isIntegerIn(key["kid"], 0, UINT32_MAX))
|
|
579
|
+
return issue(`${at}.kid`, "kid must be an unsigned 32-bit integer");
|
|
580
|
+
if (typeof key["publicKey"] !== "string" || !ED25519_PUBLIC_KEY_BASE64URL.test(key["publicKey"])) {
|
|
581
|
+
return issue(`${at}.publicKey`, "publicKey must be a 32-octet Ed25519 key in canonical unpadded base64url");
|
|
582
|
+
}
|
|
583
|
+
if (!isIntegerIn(key["firstEpoch"], 0, UINT32_MAX)) {
|
|
584
|
+
return issue(`${at}.firstEpoch`, "firstEpoch must be an unsigned 32-bit integer");
|
|
585
|
+
}
|
|
586
|
+
if (kids.has(key["kid"]))
|
|
587
|
+
return issue(`${at}.kid`, `kid ${key["kid"]} is repeated; the catalog holds no key set`);
|
|
588
|
+
if (firstEpochs.has(key["firstEpoch"])) {
|
|
589
|
+
return issue(`${at}.firstEpoch`, `firstEpoch ${key["firstEpoch"]} is repeated; the catalog holds no key set`);
|
|
590
|
+
}
|
|
591
|
+
kids.add(key["kid"]);
|
|
592
|
+
firstEpochs.add(key["firstEpoch"]);
|
|
593
|
+
}
|
|
594
|
+
if (!isIntegerIn(auth["minEpoch"], 0, UINT32_MAX)) {
|
|
595
|
+
return issue(".minEpoch", "minEpoch must be an unsigned 32-bit integer");
|
|
596
|
+
}
|
|
597
|
+
return [];
|
|
598
|
+
}
|
|
599
|
+
function endpointAuthIssue(endpoint, mode, at) {
|
|
600
|
+
const auth = endpoint["auth"];
|
|
601
|
+
if (!isObject(auth))
|
|
602
|
+
return { path: `${at}.auth`, message: "auth must be an object" };
|
|
603
|
+
const unknown = Object.keys(auth).filter((key) => !ENDPOINT_AUTH_MEMBERS.has(key));
|
|
604
|
+
if (unknown.length > 0)
|
|
605
|
+
return { path: `${at}.auth`, message: `auth has unknown member(s) ${unknown.join(", ")}` };
|
|
606
|
+
if (!isIntegerIn(auth["manifestPort"], 1, 65535)) {
|
|
607
|
+
return { path: `${at}.auth.manifestPort`, message: "manifestPort must be an integer from 1 to 65535" };
|
|
608
|
+
}
|
|
609
|
+
if (!isIntegerIn(auth["streamId"], 0, UINT32_MAX)) {
|
|
610
|
+
return { path: `${at}.auth.streamId`, message: "streamId must be an unsigned 32-bit integer" };
|
|
611
|
+
}
|
|
612
|
+
if (mode === "ssm" && auth["senderAddress"] !== void 0) {
|
|
613
|
+
return { path: `${at}.auth.senderAddress`, message: "senderAddress must not appear on an SSM endpoint; S is sourceAddress" };
|
|
614
|
+
}
|
|
615
|
+
if (mode === "asm" && !isNonEmptyString(auth["senderAddress"])) {
|
|
616
|
+
return { path: `${at}.auth.senderAddress`, message: "a protected ASM endpoint requires senderAddress" };
|
|
617
|
+
}
|
|
618
|
+
if (auth["maxAuthDelayMs"] !== void 0 && !isIntegerIn(auth["maxAuthDelayMs"], 50, 1e3)) {
|
|
619
|
+
return { path: `${at}.auth.maxAuthDelayMs`, message: "maxAuthDelayMs must be an integer from 50 to 1000" };
|
|
620
|
+
}
|
|
621
|
+
if (auth["manifestTimerMs"] !== void 0 && !isIntegerIn(auth["manifestTimerMs"], 1, Number.MAX_SAFE_INTEGER)) {
|
|
622
|
+
return { path: `${at}.auth.manifestTimerMs`, message: "manifestTimerMs must be an integer of at least 1" };
|
|
623
|
+
}
|
|
624
|
+
if (auth["manifestTrack"] !== void 0 && !isNonEmptyString(auth["manifestTrack"])) {
|
|
625
|
+
return { path: `${at}.auth.manifestTrack`, message: "manifestTrack must be a non-empty string" };
|
|
626
|
+
}
|
|
627
|
+
if (!isIntegerIn(endpoint["bandwidth"], 1, Number.MAX_SAFE_INTEGER)) {
|
|
628
|
+
return { path: `${at}.bandwidth`, message: "a protected endpoint requires bandwidth, which bounds the receiver's hold queues" };
|
|
629
|
+
}
|
|
630
|
+
return void 0;
|
|
631
|
+
}
|
|
632
|
+
var CATALOG_NAMESPACE = /* @__PURE__ */ Symbol.for("@blockcast/mmt-base/catalogNamespace");
|
|
633
|
+
function multicastCatalogIssues(catalog, options = {}) {
|
|
634
|
+
if (!isObject(catalog))
|
|
635
|
+
return [];
|
|
636
|
+
const issues = [];
|
|
637
|
+
if ("multicast.auth" in catalog) {
|
|
638
|
+
issues.push({
|
|
639
|
+
code: "multicast_auth",
|
|
640
|
+
path: '$["multicast.auth"]',
|
|
641
|
+
message: 'the root "multicast.auth" key is retired; declare auth as multicast.auth (draft -01 7.2.6)'
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
const multicast = catalog["multicast"];
|
|
645
|
+
if (!isObject(multicast))
|
|
646
|
+
return issues;
|
|
647
|
+
const protectedCatalog = multicast["auth"] !== void 0;
|
|
648
|
+
if (protectedCatalog)
|
|
649
|
+
issues.push(...authIssues(multicast["auth"]));
|
|
650
|
+
const endpoints = multicast["endpoints"];
|
|
651
|
+
if (!Array.isArray(endpoints))
|
|
652
|
+
return issues;
|
|
653
|
+
const tracks = Array.isArray(catalog["tracks"]) ? catalog["tracks"] : [];
|
|
654
|
+
const namespaceOf = /* @__PURE__ */ new Map();
|
|
655
|
+
for (const track of tracks) {
|
|
656
|
+
if (isObject(track) && typeof track["name"] === "string")
|
|
657
|
+
namespaceOf.set(track["name"], track["namespace"]);
|
|
658
|
+
}
|
|
659
|
+
const tagged = catalog[CATALOG_NAMESPACE];
|
|
660
|
+
let referenceNamespace = options.catalogNamespace ?? (typeof tagged === "string" ? tagged : void 0);
|
|
661
|
+
const sources = [];
|
|
662
|
+
for (let index = 0; index < endpoints.length; index++) {
|
|
663
|
+
const endpoint = endpoints[index];
|
|
664
|
+
const at = `$.multicast.endpoints[${index}]`;
|
|
665
|
+
const fail = (code, path, message) => {
|
|
666
|
+
issues.push({ code, path, message, endpointIndex: index });
|
|
667
|
+
};
|
|
668
|
+
sources.push(void 0);
|
|
669
|
+
if (!isObject(endpoint)) {
|
|
670
|
+
fail("multicast_endpoint", at, "endpoint must be an object");
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
const protocol = endpoint["protocol"];
|
|
674
|
+
if (protocol !== void 0 && protocol !== "ssm" && protocol !== "asm") {
|
|
675
|
+
fail("multicast_endpoint", `${at}.protocol`, `protocol must be "ssm" or "asm"; a bearer such as ${JSON.stringify(protocol)} is a networkSource entry (draft -01 4.2)`);
|
|
676
|
+
continue;
|
|
677
|
+
}
|
|
678
|
+
const hasAuth = endpoint["auth"] !== void 0;
|
|
679
|
+
if (protectedCatalog !== hasAuth) {
|
|
680
|
+
fail("multicast_endpoint_auth", `${at}.auth`, protectedCatalog ? "every endpoint requires auth when multicast carries auth; a receiver ignores this endpoint" : "auth names no key without multicast.auth; a receiver ignores this endpoint");
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
const sourceAddress = endpoint["sourceAddress"];
|
|
684
|
+
if (sourceAddress !== void 0 && !isNonEmptyString(sourceAddress)) {
|
|
685
|
+
fail("multicast_endpoint", `${at}.sourceAddress`, "sourceAddress must be a non-empty string");
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
const mode = sourceAddress === void 0 ? "asm" : "ssm";
|
|
689
|
+
if (protocol !== void 0 && protocol !== mode) {
|
|
690
|
+
fail("multicast_endpoint", `${at}.protocol`, `protocol ${JSON.stringify(protocol)} disagrees with sourceAddress, which selects ${mode}`);
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
if (!isIntegerIn(endpoint["port"], 1, 65535)) {
|
|
694
|
+
fail("multicast_endpoint", `${at}.port`, "port must be an integer from 1 to 65535");
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
if (hasAuth) {
|
|
698
|
+
const authIssue = endpointAuthIssue(endpoint, mode, at);
|
|
699
|
+
if (authIssue) {
|
|
700
|
+
fail("multicast_endpoint_auth", authIssue.path, authIssue.message);
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
sources[index] = multicastEndpointSource(endpoint);
|
|
705
|
+
const refs = Array.isArray(endpoint["tracks"]) ? endpoint["tracks"] : [];
|
|
706
|
+
for (let refIndex = 0; refIndex < refs.length; refIndex++) {
|
|
707
|
+
const ref = refs[refIndex];
|
|
708
|
+
const name = isObject(ref) ? ref["name"] : ref;
|
|
709
|
+
if (typeof name !== "string")
|
|
710
|
+
continue;
|
|
711
|
+
const namespace = namespaceOf.get(name);
|
|
712
|
+
if (typeof namespace !== "string")
|
|
713
|
+
continue;
|
|
714
|
+
referenceNamespace ?? (referenceNamespace = namespace);
|
|
715
|
+
if (namespace !== referenceNamespace) {
|
|
716
|
+
fail("multicast_track", `${at}.tracks[${refIndex}].name`, `track ${JSON.stringify(name)} declares namespace ${JSON.stringify(namespace)}, not the catalog track's ${JSON.stringify(referenceNamespace)}`);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
const tupleOf = (index) => {
|
|
721
|
+
const endpoint = endpoints[index];
|
|
722
|
+
const auth = endpoint["auth"];
|
|
723
|
+
return {
|
|
724
|
+
sg: JSON.stringify([sources[index].source ?? null, endpoint["groupAddress"]]),
|
|
725
|
+
port: endpoint["port"],
|
|
726
|
+
manifestPort: isObject(auth) ? auth["manifestPort"] : void 0
|
|
727
|
+
};
|
|
728
|
+
};
|
|
729
|
+
for (let index = 0; index < endpoints.length; index++) {
|
|
730
|
+
if (!sources[index])
|
|
731
|
+
continue;
|
|
732
|
+
const own = tupleOf(index);
|
|
733
|
+
const at = `$.multicast.endpoints[${index}]`;
|
|
734
|
+
if (own.manifestPort !== void 0 && own.manifestPort === own.port) {
|
|
735
|
+
issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: "manifestPort must differ from the endpoint's own port", endpointIndex: index });
|
|
736
|
+
continue;
|
|
737
|
+
}
|
|
738
|
+
for (let other = 0; other < endpoints.length; other++) {
|
|
739
|
+
if (other === index || !sources[other])
|
|
740
|
+
continue;
|
|
741
|
+
const peer = tupleOf(other);
|
|
742
|
+
if (peer.sg !== own.sg)
|
|
743
|
+
continue;
|
|
744
|
+
if (peer.port === own.port) {
|
|
745
|
+
issues.push({ code: "multicast_endpoint", path: `${at}.port`, message: `(S, G, port) is shared with endpoint ${other}; one endpoint object per multicast tuple`, endpointIndex: index });
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
if (own.manifestPort !== void 0 && (own.manifestPort === peer.port || own.manifestPort === peer.manifestPort)) {
|
|
749
|
+
issues.push({ code: "multicast_endpoint_auth", path: `${at}.auth.manifestPort`, message: `manifestPort is a port or manifestPort of endpoint ${other} on the same (S, G)`, endpointIndex: index });
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return issues;
|
|
755
|
+
}
|
|
380
756
|
|
|
381
757
|
// src/mfu-reassembler.ts
|
|
382
758
|
function fragmentProvenance(fragment) {
|
|
@@ -3220,8 +3596,14 @@ var BlockcastMmt = (() => {
|
|
|
3220
3596
|
/**
|
|
3221
3597
|
* Add one reassembled data unit. Returns the combined sample once every
|
|
3222
3598
|
* constituent data unit has arrived and totals the authored size.
|
|
3599
|
+
*
|
|
3600
|
+
* `sampleSize` is the authored size the host resolves for the sample as the
|
|
3601
|
+
* data unit completes. It stands in only when no size was registered, which
|
|
3602
|
+
* happens when the data unit's FI=0/FI=1 reached the reassembler without the
|
|
3603
|
+
* host's own FT=2 parse: an FEC-recovered first fragment completed by source
|
|
3604
|
+
* fragments, or one decoded before its source copy arrived.
|
|
3223
3605
|
*/
|
|
3224
|
-
addMfu(mfu) {
|
|
3606
|
+
addMfu(mfu, sampleSize) {
|
|
3225
3607
|
if (mfu.movieFragmentSequenceNumber === void 0 || mfu.sampleNumber === void 0) {
|
|
3226
3608
|
__privateGet(this, _stats).passthroughSamples++;
|
|
3227
3609
|
return fromPassthrough(mfu);
|
|
@@ -3237,7 +3619,7 @@ var BlockcastMmt = (() => {
|
|
|
3237
3619
|
return null;
|
|
3238
3620
|
}
|
|
3239
3621
|
const dataLen = mfu.data.byteLength;
|
|
3240
|
-
const authoredSize = __privateGet(this, _authoredSizes).get(key);
|
|
3622
|
+
const authoredSize = __privateGet(this, _authoredSizes).get(key) ?? sampleSize;
|
|
3241
3623
|
if (offset === 0 && !__privateGet(this, _pending).has(key)) {
|
|
3242
3624
|
const passesThrough = authoredSize === void 0 ? !__privateGet(this, _requireAuthoredSize) : dataLen === authoredSize;
|
|
3243
3625
|
if (passesThrough) {
|
|
@@ -3545,6 +3927,12 @@ var BlockcastMmt = (() => {
|
|
|
3545
3927
|
const out = c.addMfu(mfu(1, 9, 17, 5, [6, 7, 8, 9, 10], 1001n, false));
|
|
3546
3928
|
expect(out?.data).toEqual(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
|
|
3547
3929
|
});
|
|
3930
|
+
test("a size handed with the data unit completes a sample no head registered", () => {
|
|
3931
|
+
const c = combiner({ requireAuthoredSize: true });
|
|
3932
|
+
const out = c.addMfu(mfu(1, 9, 17, 0, [1, 2, 3, 4, 5], 1000n, true), 5);
|
|
3933
|
+
expect(out?.data).toEqual(new Uint8Array([1, 2, 3, 4, 5]));
|
|
3934
|
+
expect(c.addMfu(mfu(1, 9, 17, 0, [1, 2, 3, 4, 5], 1000n, true), 5)).toBeNull();
|
|
3935
|
+
});
|
|
3548
3936
|
test("duplicate offset is rejected", () => {
|
|
3549
3937
|
const c = combiner();
|
|
3550
3938
|
c.registerAuthoredSize(void 0, 1, 9, 17, 10);
|
|
@@ -5532,7 +5920,8 @@ var BlockcastMmt = (() => {
|
|
|
5532
5920
|
const type = String.fromCharCode(data[4], data[5], data[6], data[7]);
|
|
5533
5921
|
return FMPU_BOX_TYPES.has(type);
|
|
5534
5922
|
}
|
|
5535
|
-
var
|
|
5923
|
+
var MAX_AWAITING_TIMING_HEADS = 8;
|
|
5924
|
+
var _tracks, _defaultTrack, _reassembler, _sampleCombiners, _sampleCombinerOptions, _retiredSampleCombinerStats, _timingStreams, _maxPendingTimingSamples, _pendingTimingSamples, _reclaimedTimingSamples, _evictedTimingSamples, _rejectedMovieFragments, _sequencers, _fecGate, _fecSequencer, _reorderWindow, _reassemblyPolicy, _frameCb, _initCb, _sourceSymbolCb, _trackFrameCbs, _reorderStats, _reliableMoqStartupGate, _disposed, _replayingAwaitingTiming, _fedObjects, _reassemblerFragmentsFed, _reassemblerDataUnitsReturned, _feedOutcomes, _deferredFeedOutcomes, _lastOutcome, _lastOutcomeCount, _MmtpContainerParser_instances, streamKey_fn, sampleCombinerFor_fn, releaseTimingSlot_fn, dropSampleCombiner_fn, countOutcome_fn, countDeferredOutcome_fn, drop_fn, feedCounted_fn, feed_fn, emitCombinedSample_fn, passReliableMoqStartupGate_fn, timingResolver_fn, awaitTiming_fn, replayAwaitingTiming_fn, dropTimingStream_fn, validateReassemblyPolicy_fn, buildFrameMeta_fn, sequencerFor_fn, flushSequencers_fn, emitFrame_fn2, _MmtpContainerParser_static, scanForKeyframe_fn, scanLengthPrefixedHevcForKeyframe_fn, scanAnnexBForKeyframe_fn;
|
|
5536
5925
|
var _MmtpContainerParser = class _MmtpContainerParser {
|
|
5537
5926
|
constructor(config) {
|
|
5538
5927
|
__privateAdd(this, _MmtpContainerParser_instances);
|
|
@@ -5595,6 +5984,7 @@ var BlockcastMmt = (() => {
|
|
|
5595
5984
|
* reordering into the parser. */
|
|
5596
5985
|
__privateAdd(this, _reliableMoqStartupGate, /* @__PURE__ */ new Map());
|
|
5597
5986
|
__privateAdd(this, _disposed, false);
|
|
5987
|
+
__privateAdd(this, _replayingAwaitingTiming, false);
|
|
5598
5988
|
__privateAdd(this, _fedObjects, 0);
|
|
5599
5989
|
__privateAdd(this, _reassemblerFragmentsFed, 0);
|
|
5600
5990
|
__privateAdd(this, _reassemblerDataUnitsReturned, 0);
|
|
@@ -5853,6 +6243,12 @@ var BlockcastMmt = (() => {
|
|
|
5853
6243
|
for (const combiner of __privateGet(this, _sampleCombiners).values()) {
|
|
5854
6244
|
combiner.cleanupTimeouts(timeoutMs);
|
|
5855
6245
|
}
|
|
6246
|
+
const now = Date.now();
|
|
6247
|
+
for (const { awaitingTiming } of __privateGet(this, _timingStreams).values()) {
|
|
6248
|
+
while (awaitingTiming.length > 0 && now - awaitingTiming[0].arrivedAt > timeoutMs) {
|
|
6249
|
+
awaitingTiming.shift();
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
5856
6252
|
}
|
|
5857
6253
|
/**
|
|
5858
6254
|
* Phase 1 of two-phase parsing. Returns structured header info for FEC feeding.
|
|
@@ -6139,6 +6535,7 @@ var BlockcastMmt = (() => {
|
|
|
6139
6535
|
_reorderStats = new WeakMap();
|
|
6140
6536
|
_reliableMoqStartupGate = new WeakMap();
|
|
6141
6537
|
_disposed = new WeakMap();
|
|
6538
|
+
_replayingAwaitingTiming = new WeakMap();
|
|
6142
6539
|
_fedObjects = new WeakMap();
|
|
6143
6540
|
_reassemblerFragmentsFed = new WeakMap();
|
|
6144
6541
|
_reassemblerDataUnitsReturned = new WeakMap();
|
|
@@ -6219,7 +6616,8 @@ var BlockcastMmt = (() => {
|
|
|
6219
6616
|
* a single failure bucket. Returns null so call sites stay `return this.#drop(...)`.
|
|
6220
6617
|
*/
|
|
6221
6618
|
drop_fn = function(reason) {
|
|
6222
|
-
__privateMethod(this, _MmtpContainerParser_instances,
|
|
6619
|
+
if (__privateGet(this, _replayingAwaitingTiming)) __privateMethod(this, _MmtpContainerParser_instances, countDeferredOutcome_fn).call(this, reason);
|
|
6620
|
+
else __privateMethod(this, _MmtpContainerParser_instances, countOutcome_fn).call(this, `drop:${reason}`);
|
|
6223
6621
|
return null;
|
|
6224
6622
|
};
|
|
6225
6623
|
feedCounted_fn = function(packet, options, parsed) {
|
|
@@ -6248,7 +6646,7 @@ var BlockcastMmt = (() => {
|
|
|
6248
6646
|
byteLength: packet.byteLength
|
|
6249
6647
|
};
|
|
6250
6648
|
}
|
|
6251
|
-
if (info.fecPayloadId !== null && __privateGet(this, _sourceSymbolCb)) {
|
|
6649
|
+
if (info.fecPayloadId !== null && __privateGet(this, _sourceSymbolCb) && !__privateGet(this, _replayingAwaitingTiming)) {
|
|
6252
6650
|
const rawSymbol = packet.subarray(0, packet.length - 4);
|
|
6253
6651
|
try {
|
|
6254
6652
|
__privateGet(this, _sourceSymbolCb).call(this, info.packetId, info.fecPayloadId.ssId, rawSymbol);
|
|
@@ -6296,6 +6694,7 @@ var BlockcastMmt = (() => {
|
|
|
6296
6694
|
}
|
|
6297
6695
|
return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "fragment-timing-refused");
|
|
6298
6696
|
}
|
|
6697
|
+
__privateMethod(this, _MmtpContainerParser_instances, replayAwaitingTiming_fn).call(this, streamKey, resolver2);
|
|
6299
6698
|
return {
|
|
6300
6699
|
kind: "fragment",
|
|
6301
6700
|
packet: info,
|
|
@@ -6319,7 +6718,18 @@ var BlockcastMmt = (() => {
|
|
|
6319
6718
|
mfuDuHeader.movieFragmentSequenceNumber,
|
|
6320
6719
|
mfuDuHeader.sampleNumber
|
|
6321
6720
|
);
|
|
6322
|
-
if (!headTiming)
|
|
6721
|
+
if (!headTiming) {
|
|
6722
|
+
__privateMethod(this, _MmtpContainerParser_instances, awaitTiming_fn).call(this, streamKey, {
|
|
6723
|
+
packet,
|
|
6724
|
+
options,
|
|
6725
|
+
parsed,
|
|
6726
|
+
mpuSequenceNumber: mpu.mpuSequenceNumber,
|
|
6727
|
+
movieFragmentSequenceNumber: mfuDuHeader.movieFragmentSequenceNumber,
|
|
6728
|
+
sampleNumber: mfuDuHeader.sampleNumber,
|
|
6729
|
+
arrivedAt: Date.now()
|
|
6730
|
+
});
|
|
6731
|
+
return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "mfu-sample-timing-missing");
|
|
6732
|
+
}
|
|
6323
6733
|
const offset = mfuDuHeader.offset;
|
|
6324
6734
|
if (!Number.isSafeInteger(offset) || offset < 0 || offset >= headTiming.size)
|
|
6325
6735
|
return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "mfu-offset-out-of-range");
|
|
@@ -6389,16 +6799,17 @@ var BlockcastMmt = (() => {
|
|
|
6389
6799
|
const sampleNumber = assembled.sampleNumber;
|
|
6390
6800
|
if (movieFragmentSequenceNumber === void 0 || sampleNumber === void 0)
|
|
6391
6801
|
return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "assembled-identity-missing");
|
|
6392
|
-
|
|
6802
|
+
const assembledTiming = resolver.sampleTiming(
|
|
6393
6803
|
assembled.mpuSequenceNumber,
|
|
6394
6804
|
movieFragmentSequenceNumber,
|
|
6395
6805
|
sampleNumber
|
|
6396
|
-
)
|
|
6806
|
+
);
|
|
6807
|
+
if (!assembledTiming) return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "assembled-timing-missing");
|
|
6397
6808
|
if (assembled.mpuSequenceNumber !== mpu.mpuSequenceNumber)
|
|
6398
6809
|
return __privateMethod(this, _MmtpContainerParser_instances, drop_fn).call(this, "assembled-mpu-mismatch");
|
|
6399
6810
|
let combined;
|
|
6400
6811
|
try {
|
|
6401
|
-
combined = __privateMethod(this, _MmtpContainerParser_instances, sampleCombinerFor_fn).call(this, streamKey).addMfu(assembled);
|
|
6812
|
+
combined = __privateMethod(this, _MmtpContainerParser_instances, sampleCombinerFor_fn).call(this, streamKey).addMfu(assembled, assembledTiming.size);
|
|
6402
6813
|
} catch (error) {
|
|
6403
6814
|
if (!(error instanceof SampleCombineError)) throw error;
|
|
6404
6815
|
console.warn(
|
|
@@ -6492,9 +6903,37 @@ var BlockcastMmt = (() => {
|
|
|
6492
6903
|
if (existing) return existing.resolver;
|
|
6493
6904
|
if (!create) return null;
|
|
6494
6905
|
const resolver = new IsoBmffTimingResolver(__privateGet(this, _maxPendingTimingSamples));
|
|
6495
|
-
__privateGet(this, _timingStreams).set(streamKey, { packetId, resolver });
|
|
6906
|
+
__privateGet(this, _timingStreams).set(streamKey, { packetId, resolver, awaitingTiming: [] });
|
|
6496
6907
|
return resolver;
|
|
6497
6908
|
};
|
|
6909
|
+
awaitTiming_fn = function(streamKey, head) {
|
|
6910
|
+
const awaitingTiming = __privateGet(this, _timingStreams).get(streamKey)?.awaitingTiming;
|
|
6911
|
+
if (!awaitingTiming) return;
|
|
6912
|
+
awaitingTiming.push(head);
|
|
6913
|
+
if (awaitingTiming.length > MAX_AWAITING_TIMING_HEADS) awaitingTiming.shift();
|
|
6914
|
+
};
|
|
6915
|
+
/**
|
|
6916
|
+
* Feed again the heads whose timing the FT=1 just admitted declares. That
|
|
6917
|
+
* FT=1 can be an FEC recovery landing after its sample's FI=1, and neither
|
|
6918
|
+
* FEC path routes a source symbol that already arrived a second time.
|
|
6919
|
+
*/
|
|
6920
|
+
replayAwaitingTiming_fn = function(streamKey, resolver) {
|
|
6921
|
+
const state = __privateGet(this, _timingStreams).get(streamKey);
|
|
6922
|
+
if (!state || state.awaitingTiming.length === 0) return;
|
|
6923
|
+
const ready = state.awaitingTiming.filter((head) => resolver.sampleTiming(
|
|
6924
|
+
head.mpuSequenceNumber,
|
|
6925
|
+
head.movieFragmentSequenceNumber,
|
|
6926
|
+
head.sampleNumber
|
|
6927
|
+
));
|
|
6928
|
+
if (ready.length === 0) return;
|
|
6929
|
+
state.awaitingTiming = state.awaitingTiming.filter((head) => !ready.includes(head));
|
|
6930
|
+
__privateSet(this, _replayingAwaitingTiming, true);
|
|
6931
|
+
try {
|
|
6932
|
+
for (const head of ready) __privateMethod(this, _MmtpContainerParser_instances, feed_fn).call(this, head.packet, head.options, head.parsed);
|
|
6933
|
+
} finally {
|
|
6934
|
+
__privateSet(this, _replayingAwaitingTiming, false);
|
|
6935
|
+
}
|
|
6936
|
+
};
|
|
6498
6937
|
dropTimingStream_fn = function(streamKey) {
|
|
6499
6938
|
const state = __privateGet(this, _timingStreams).get(streamKey);
|
|
6500
6939
|
if (!state) return;
|
|
@@ -6996,197 +7435,6 @@ var BlockcastMmt = (() => {
|
|
|
6996
7435
|
});
|
|
6997
7436
|
}
|
|
6998
7437
|
|
|
6999
|
-
// src/multicast-auth-catalog.ts
|
|
7000
|
-
var RAW_ED25519_KEY_LENGTH = 32;
|
|
7001
|
-
var SOURCE_AUTH_SCOPE_LENGTH = 32;
|
|
7002
|
-
var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
7003
|
-
function encodeBase64Url(bytes) {
|
|
7004
|
-
let output = "";
|
|
7005
|
-
for (let i = 0; i < bytes.length; i += 3) {
|
|
7006
|
-
const b0 = bytes[i];
|
|
7007
|
-
const b1 = bytes[i + 1];
|
|
7008
|
-
const b2 = bytes[i + 2];
|
|
7009
|
-
output += BASE64URL_ALPHABET[b0 >> 2];
|
|
7010
|
-
output += BASE64URL_ALPHABET[(b0 & 3) << 4 | (b1 === void 0 ? 0 : b1 >> 4)];
|
|
7011
|
-
if (b1 === void 0) break;
|
|
7012
|
-
output += BASE64URL_ALPHABET[(b1 & 15) << 2 | (b2 === void 0 ? 0 : b2 >> 6)];
|
|
7013
|
-
if (b2 === void 0) break;
|
|
7014
|
-
output += BASE64URL_ALPHABET[b2 & 63];
|
|
7015
|
-
}
|
|
7016
|
-
return output;
|
|
7017
|
-
}
|
|
7018
|
-
var BASE64URL_DECODE_TABLE = (() => {
|
|
7019
|
-
const table = new Int8Array(128).fill(-1);
|
|
7020
|
-
for (let i = 0; i < BASE64URL_ALPHABET.length; i++) {
|
|
7021
|
-
table[BASE64URL_ALPHABET.charCodeAt(i)] = i;
|
|
7022
|
-
}
|
|
7023
|
-
return table;
|
|
7024
|
-
})();
|
|
7025
|
-
function decodeBase64Url(text) {
|
|
7026
|
-
if (text.length % 4 === 1) {
|
|
7027
|
-
throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text}"`);
|
|
7028
|
-
}
|
|
7029
|
-
const bytes = [];
|
|
7030
|
-
let buffer = 0;
|
|
7031
|
-
let bits = 0;
|
|
7032
|
-
for (let i = 0; i < text.length; i++) {
|
|
7033
|
-
const code = text.charCodeAt(i);
|
|
7034
|
-
const value = code < 128 ? BASE64URL_DECODE_TABLE[code] : -1;
|
|
7035
|
-
if (value === void 0 || value < 0) {
|
|
7036
|
-
throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text}"`);
|
|
7037
|
-
}
|
|
7038
|
-
buffer = buffer << 6 | value;
|
|
7039
|
-
bits += 6;
|
|
7040
|
-
if (bits >= 8) {
|
|
7041
|
-
bits -= 8;
|
|
7042
|
-
bytes.push(buffer >> bits & 255);
|
|
7043
|
-
}
|
|
7044
|
-
}
|
|
7045
|
-
const decoded = Uint8Array.from(bytes);
|
|
7046
|
-
if (encodeBase64Url(decoded) !== text) {
|
|
7047
|
-
throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text}"`);
|
|
7048
|
-
}
|
|
7049
|
-
return decoded;
|
|
7050
|
-
}
|
|
7051
|
-
function decodeAuthScope(authScope) {
|
|
7052
|
-
const bytes = decodeBase64Url(authScope);
|
|
7053
|
-
if (bytes.byteLength !== SOURCE_AUTH_SCOPE_LENGTH) {
|
|
7054
|
-
throw new Error(
|
|
7055
|
-
`[multicast-auth-catalog] authScope must decode to ${SOURCE_AUTH_SCOPE_LENGTH} raw bytes, got ${bytes.byteLength}`
|
|
7056
|
-
);
|
|
7057
|
-
}
|
|
7058
|
-
return bytes;
|
|
7059
|
-
}
|
|
7060
|
-
function decodeEd25519PublicKey(publicKey) {
|
|
7061
|
-
const bytes = decodeBase64Url(publicKey);
|
|
7062
|
-
if (bytes.byteLength !== RAW_ED25519_KEY_LENGTH) {
|
|
7063
|
-
throw new Error(
|
|
7064
|
-
`[multicast-auth-catalog] public key must decode to ${RAW_ED25519_KEY_LENGTH} raw bytes, got ${bytes.byteLength}`
|
|
7065
|
-
);
|
|
7066
|
-
}
|
|
7067
|
-
return bytes;
|
|
7068
|
-
}
|
|
7069
|
-
function isNonEmptyString(value) {
|
|
7070
|
-
return typeof value === "string" && value.length > 0;
|
|
7071
|
-
}
|
|
7072
|
-
function isValidAuthScopeField(value) {
|
|
7073
|
-
if (!isNonEmptyString(value)) return false;
|
|
7074
|
-
try {
|
|
7075
|
-
decodeAuthScope(value);
|
|
7076
|
-
return true;
|
|
7077
|
-
} catch {
|
|
7078
|
-
return false;
|
|
7079
|
-
}
|
|
7080
|
-
}
|
|
7081
|
-
function isValidPublicKeyField(value) {
|
|
7082
|
-
if (!isNonEmptyString(value)) return false;
|
|
7083
|
-
try {
|
|
7084
|
-
decodeEd25519PublicKey(value);
|
|
7085
|
-
return true;
|
|
7086
|
-
} catch {
|
|
7087
|
-
return false;
|
|
7088
|
-
}
|
|
7089
|
-
}
|
|
7090
|
-
function hasOnlyKeys(object, allowed) {
|
|
7091
|
-
const allowedKeys = new Set(allowed);
|
|
7092
|
-
return Object.keys(object).every((key) => allowedKeys.has(key));
|
|
7093
|
-
}
|
|
7094
|
-
function isMulticastAuthTrackConfig(obj) {
|
|
7095
|
-
if (typeof obj !== "object" || obj === null) return false;
|
|
7096
|
-
const o = obj;
|
|
7097
|
-
return hasOnlyKeys(o, ["mediaTrack", "manifestTrack", "authScope", "sourceSymbolFormat"]) && isNonEmptyString(o["mediaTrack"]) && isNonEmptyString(o["manifestTrack"]) && o["mediaTrack"] !== o["manifestTrack"] && isValidAuthScopeField(o["authScope"]) && isNonEmptyString(o["sourceSymbolFormat"]);
|
|
7098
|
-
}
|
|
7099
|
-
var VALID_COMPACTION = /* @__PURE__ */ new Set(["merkle", "none"]);
|
|
7100
|
-
var VALID_ENFORCEMENT = /* @__PURE__ */ new Set(["shadow", "enforce"]);
|
|
7101
|
-
function hasUniqueMulticastAuthTrackBindings(tracks) {
|
|
7102
|
-
const bindings = tracks.flatMap((track) => {
|
|
7103
|
-
if (typeof track !== "object" || track === null) return [];
|
|
7104
|
-
const value = track;
|
|
7105
|
-
if (typeof value["mediaTrack"] !== "string" || typeof value["sourceSymbolFormat"] !== "string") {
|
|
7106
|
-
return [];
|
|
7107
|
-
}
|
|
7108
|
-
return [JSON.stringify([value["mediaTrack"], value["sourceSymbolFormat"]])];
|
|
7109
|
-
});
|
|
7110
|
-
return new Set(bindings).size === bindings.length;
|
|
7111
|
-
}
|
|
7112
|
-
function isMulticastAuthConfig(obj) {
|
|
7113
|
-
if (typeof obj !== "object" || obj === null) return false;
|
|
7114
|
-
const o = obj;
|
|
7115
|
-
if (o["scheme"] !== "bc-provenance") return false;
|
|
7116
|
-
if (o["hash"] !== "blake3") return false;
|
|
7117
|
-
if (o["sig"] !== "ed25519") return false;
|
|
7118
|
-
if (!hasOnlyKeys(o, ["scheme", "hash", "sig", "publicKey", "keyId", "previousKey", "compaction", "enforcement", "tracks"])) return false;
|
|
7119
|
-
if (!isValidPublicKeyField(o["publicKey"])) return false;
|
|
7120
|
-
if (!isNonEmptyString(o["keyId"])) return false;
|
|
7121
|
-
if (o["previousKey"] !== void 0 && !isValidPublicKeyField(o["previousKey"])) return false;
|
|
7122
|
-
if (o["previousKey"] === o["publicKey"]) return false;
|
|
7123
|
-
if (typeof o["compaction"] !== "string" || !VALID_COMPACTION.has(o["compaction"])) return false;
|
|
7124
|
-
if (o["enforcement"] !== void 0) {
|
|
7125
|
-
if (typeof o["enforcement"] !== "string" || !VALID_ENFORCEMENT.has(o["enforcement"])) return false;
|
|
7126
|
-
}
|
|
7127
|
-
if (!Array.isArray(o["tracks"]) || o["tracks"].length === 0) return false;
|
|
7128
|
-
const tracks = o["tracks"];
|
|
7129
|
-
if (!tracks.every((t) => isMulticastAuthTrackConfig(t))) return false;
|
|
7130
|
-
const typedTracks = tracks;
|
|
7131
|
-
const scopes = typedTracks.map((t) => t.authScope);
|
|
7132
|
-
if (new Set(scopes).size !== scopes.length) return false;
|
|
7133
|
-
if (!hasUniqueMulticastAuthTrackBindings(typedTracks)) return false;
|
|
7134
|
-
const manifestTracks = typedTracks.map((t) => t.manifestTrack);
|
|
7135
|
-
if (new Set(manifestTracks).size !== manifestTracks.length) return false;
|
|
7136
|
-
return true;
|
|
7137
|
-
}
|
|
7138
|
-
function resolveMulticastAuthMode(playerMode, auth) {
|
|
7139
|
-
if (playerMode !== void 0) return playerMode;
|
|
7140
|
-
if (auth === void 0) return "off";
|
|
7141
|
-
return auth.enforcement ?? "shadow";
|
|
7142
|
-
}
|
|
7143
|
-
function resolveMulticastAuthCatalog(catalog, playerMode) {
|
|
7144
|
-
if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
|
|
7145
|
-
throw new Error("[multicast-auth-catalog] catalog must be an object");
|
|
7146
|
-
}
|
|
7147
|
-
const root = catalog;
|
|
7148
|
-
const rawAuth = root["multicast.auth"];
|
|
7149
|
-
if (rawAuth === void 0) {
|
|
7150
|
-
if (playerMode === "enforce") {
|
|
7151
|
-
throw new Error("[multicast-auth-catalog] player enforce mode requires multicast.auth");
|
|
7152
|
-
}
|
|
7153
|
-
return void 0;
|
|
7154
|
-
}
|
|
7155
|
-
if (!isMulticastAuthConfig(rawAuth)) {
|
|
7156
|
-
throw new Error("[multicast-auth-catalog] invalid multicast.auth v2 block");
|
|
7157
|
-
}
|
|
7158
|
-
const rawTracks = root["tracks"];
|
|
7159
|
-
if (!Array.isArray(rawTracks)) {
|
|
7160
|
-
throw new Error("[multicast-auth-catalog] catalog tracks must be an array");
|
|
7161
|
-
}
|
|
7162
|
-
const catalogTrackNames = new Set(
|
|
7163
|
-
rawTracks.flatMap(
|
|
7164
|
-
(track) => typeof track === "object" && track !== null && typeof track["name"] === "string" ? [track["name"]] : []
|
|
7165
|
-
)
|
|
7166
|
-
);
|
|
7167
|
-
for (const track of rawAuth.tracks) {
|
|
7168
|
-
if (!catalogTrackNames.has(track.mediaTrack)) {
|
|
7169
|
-
throw new Error(`[multicast-auth-catalog] unknown mediaTrack "${track.mediaTrack}"`);
|
|
7170
|
-
}
|
|
7171
|
-
if (!catalogTrackNames.has(track.manifestTrack)) {
|
|
7172
|
-
throw new Error(`[multicast-auth-catalog] unknown manifestTrack "${track.manifestTrack}"`);
|
|
7173
|
-
}
|
|
7174
|
-
}
|
|
7175
|
-
return {
|
|
7176
|
-
keyId: rawAuth.keyId,
|
|
7177
|
-
acceptedPublicKeys: [
|
|
7178
|
-
decodeEd25519PublicKey(rawAuth.publicKey),
|
|
7179
|
-
...rawAuth.previousKey === void 0 ? [] : [decodeEd25519PublicKey(rawAuth.previousKey)]
|
|
7180
|
-
],
|
|
7181
|
-
mode: resolveMulticastAuthMode(playerMode, rawAuth),
|
|
7182
|
-
compaction: rawAuth.compaction,
|
|
7183
|
-
tracks: rawAuth.tracks.map((track) => ({
|
|
7184
|
-
...track,
|
|
7185
|
-
authScope: decodeAuthScope(track.authScope)
|
|
7186
|
-
}))
|
|
7187
|
-
};
|
|
7188
|
-
}
|
|
7189
|
-
|
|
7190
7438
|
// src/repair-layers.ts
|
|
7191
7439
|
var REPAIR_PRIORITY_MIN = 192;
|
|
7192
7440
|
var REPAIR_PRIORITY_MAX = 255;
|
|
@@ -7194,6 +7442,7 @@ var BlockcastMmt = (() => {
|
|
|
7194
7442
|
var MAX_RAPTORQ_SOURCE_SYMBOLS = 56403;
|
|
7195
7443
|
var MAX_REPAIR_SYMBOLS = 16777215;
|
|
7196
7444
|
var MAX_ENCODING_SYMBOL_ID = 16777215;
|
|
7445
|
+
var MAX_REED_SOLOMON_BLOCK_SYMBOLS = 255;
|
|
7197
7446
|
var RepairContractError = class extends Error {
|
|
7198
7447
|
constructor(code, path, message) {
|
|
7199
7448
|
super(`[repair-layers:${code}] ${path}: ${message}`);
|
|
@@ -7376,11 +7625,12 @@ var BlockcastMmt = (() => {
|
|
|
7376
7625
|
if (layered && !positiveInteger(source.sourceSymbols)) {
|
|
7377
7626
|
fail("track_fec", `${source.path}.sourceSymbols`, "layered or overlay repair needs a positive integer sourceSymbols on the source");
|
|
7378
7627
|
}
|
|
7379
|
-
|
|
7628
|
+
const reedSolomon = source.algorithm === "reed-solomon";
|
|
7629
|
+
if (layered && source.algorithm !== "raptorq" && !reedSolomon) {
|
|
7380
7630
|
fail(
|
|
7381
7631
|
"track_fec",
|
|
7382
7632
|
`${source.path}.algorithm`,
|
|
7383
|
-
"repair layers and overlays are defined only for raptorq
|
|
7633
|
+
"repair layers and overlays are defined only for raptorq and reed-solomon (draft-ramadan-moq-fec-01 6.3.4 rule 7)"
|
|
7384
7634
|
);
|
|
7385
7635
|
}
|
|
7386
7636
|
let layerZeroPriority = DEFAULT_REPAIR_PRIORITY;
|
|
@@ -7439,6 +7689,13 @@ var BlockcastMmt = (() => {
|
|
|
7439
7689
|
`overlay sourceSymbols + repairSymbols - 1 exceeds the 24-bit ESI space (${MAX_ENCODING_SYMBOL_ID})`
|
|
7440
7690
|
);
|
|
7441
7691
|
}
|
|
7692
|
+
if (reedSolomon && sourceSymbols + repairSymbols > MAX_REED_SOLOMON_BLOCK_SYMBOLS) {
|
|
7693
|
+
fail(
|
|
7694
|
+
"track_fec_bounds",
|
|
7695
|
+
`${d.path}.repairSymbols`,
|
|
7696
|
+
`reed-solomon overlay sourceSymbols + repairSymbols exceeds ${MAX_REED_SOLOMON_BLOCK_SYMBOLS} (draft-ramadan-moq-fec-01 6.3.4 rule 12)`
|
|
7697
|
+
);
|
|
7698
|
+
}
|
|
7442
7699
|
overlays.push({ repairTrackName: d.name, scope: "keyframe", sourceSymbols, repairSymbols, priority: d.priority });
|
|
7443
7700
|
}
|
|
7444
7701
|
let offset = layerZeroSymbols;
|
|
@@ -7483,6 +7740,13 @@ var BlockcastMmt = (() => {
|
|
|
7483
7740
|
`sourceSymbols + total base repair symbols - 1 exceeds the 24-bit ESI space (${MAX_ENCODING_SYMBOL_ID})`
|
|
7484
7741
|
);
|
|
7485
7742
|
}
|
|
7743
|
+
if (reedSolomon && k + totalBaseRepairSymbols > MAX_REED_SOLOMON_BLOCK_SYMBOLS) {
|
|
7744
|
+
fail(
|
|
7745
|
+
"track_fec_bounds",
|
|
7746
|
+
`${source.path}.sourceSymbols`,
|
|
7747
|
+
`reed-solomon sourceSymbols + total base repair symbols exceeds ${MAX_REED_SOLOMON_BLOCK_SYMBOLS} (draft-ramadan-moq-fec-01 6.3.4 rule 12)`
|
|
7748
|
+
);
|
|
7749
|
+
}
|
|
7486
7750
|
return { sourceTrackName: source.name, baseLayers, overlays, totalBaseRepairSymbols };
|
|
7487
7751
|
}
|
|
7488
7752
|
|
|
@@ -7570,13 +7834,22 @@ var BlockcastMmt = (() => {
|
|
|
7570
7834
|
function catalogError(code, path, message) {
|
|
7571
7835
|
throw new CmsfCatalogValidationError(code, path, message);
|
|
7572
7836
|
}
|
|
7573
|
-
function
|
|
7837
|
+
function validateNetworkSourceRelays(sources, path) {
|
|
7838
|
+
if (!Array.isArray(sources)) return;
|
|
7839
|
+
sources.forEach((source, i) => {
|
|
7840
|
+
const s = source;
|
|
7841
|
+
if (s?.["type"] === "amt" && s["discovery"] === "driad" && s["relay"] !== void 0) {
|
|
7842
|
+
catalogError("multicast_network_source", `${path}[${i}].relay`, 'relay must be omitted with discovery "driad"');
|
|
7843
|
+
}
|
|
7844
|
+
});
|
|
7845
|
+
}
|
|
7846
|
+
function validateCmsfMmtpCatalog(value, options = {}) {
|
|
7574
7847
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
7575
7848
|
catalogError("catalog_object", "$", "catalog must be an object");
|
|
7576
7849
|
}
|
|
7577
7850
|
const catalog = value;
|
|
7578
7851
|
const rawVersion = catalog["version"];
|
|
7579
|
-
const normalizedVersion = typeof rawVersion === "string" ? Number.isFinite(Number(rawVersion)) ? Number(rawVersion) : rawVersion.startsWith("draft-ietf-moq-catalogformat") ? 1 : NaN : rawVersion;
|
|
7852
|
+
const normalizedVersion = typeof rawVersion === "string" ? Number.isFinite(Number(rawVersion)) ? Number(rawVersion) : rawVersion.startsWith("draft-ietf-moq-catalogformat") || rawVersion === "draft-01" ? 1 : NaN : rawVersion;
|
|
7580
7853
|
if (!Number.isInteger(normalizedVersion) || normalizedVersion <= 0) {
|
|
7581
7854
|
catalogError("catalog_version", "$.version", "version must be a positive integer or a recognized format tag");
|
|
7582
7855
|
}
|
|
@@ -7591,6 +7864,22 @@ var BlockcastMmt = (() => {
|
|
|
7591
7864
|
"commonTrackFields is retired; every track carries its own fields"
|
|
7592
7865
|
);
|
|
7593
7866
|
}
|
|
7867
|
+
const initDataList = catalog["initDataList"];
|
|
7868
|
+
if (initDataList !== void 0) {
|
|
7869
|
+
if (!Array.isArray(initDataList)) {
|
|
7870
|
+
catalogError("catalog_init_data_list", "$.initDataList", "initDataList must be an array");
|
|
7871
|
+
}
|
|
7872
|
+
initDataList.forEach((entry, i) => {
|
|
7873
|
+
const e = entry;
|
|
7874
|
+
const entryPath = `$.initDataList[${i}]`;
|
|
7875
|
+
if (typeof e !== "object" || e === null || Array.isArray(e) || typeof e["id"] !== "string" || e["id"].length === 0 || typeof e["type"] !== "string" || e["type"].length === 0) {
|
|
7876
|
+
catalogError("catalog_init_data_list", entryPath, "entry needs a non-empty string id and type");
|
|
7877
|
+
}
|
|
7878
|
+
if (e["type"] === "inline" && (typeof e["data"] !== "string" || e["data"].length === 0)) {
|
|
7879
|
+
catalogError("catalog_init_data_list", `${entryPath}.data`, 'an "inline" entry needs non-empty data');
|
|
7880
|
+
}
|
|
7881
|
+
});
|
|
7882
|
+
}
|
|
7594
7883
|
const tracks = catalog["tracks"];
|
|
7595
7884
|
const trackRecords = [];
|
|
7596
7885
|
const positiveInteger2 = (input) => Number.isSafeInteger(input) && input > 0;
|
|
@@ -7642,6 +7931,14 @@ var BlockcastMmt = (() => {
|
|
|
7642
7931
|
if (keyframeIntervalMs !== void 0 && !positiveNumber(keyframeIntervalMs) || keyframeIntervalTicks !== void 0 && !positiveInteger2(keyframeIntervalTicks)) {
|
|
7643
7932
|
catalogError("track_keyframe_interval", path, "keyframe interval fields must be positive numbers");
|
|
7644
7933
|
}
|
|
7934
|
+
const anchor = track["presentationAnchorTicks"];
|
|
7935
|
+
if (anchor !== void 0 && !Number.isSafeInteger(anchor)) {
|
|
7936
|
+
catalogError("track_presentation_anchor", `${path}.presentationAnchorTicks`, "must be a safe integer");
|
|
7937
|
+
}
|
|
7938
|
+
const initRef = track["initRef"];
|
|
7939
|
+
if (initRef !== void 0 && (typeof initRef !== "string" || initRef.length === 0)) {
|
|
7940
|
+
catalogError("track_init_ref", `${path}.initRef`, "must be a non-empty string");
|
|
7941
|
+
}
|
|
7645
7942
|
if (packaging === "fec-repair") {
|
|
7646
7943
|
rejectRepairTrackGeometry(path, track, catalogError);
|
|
7647
7944
|
validateRepairTrackFields(describeRepairTrack(name, path, track), catalogError);
|
|
@@ -7649,9 +7946,8 @@ var BlockcastMmt = (() => {
|
|
|
7649
7946
|
rejectRepairFieldsOnMediaTrack(path, track, catalogError);
|
|
7650
7947
|
}
|
|
7651
7948
|
if (packaging === "mmtp") {
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mpu or mfu");
|
|
7949
|
+
if (track["mmtpMode"] !== "mfu") {
|
|
7950
|
+
catalogError("track_mmtp_mode", `${path}.mmtpMode`, "must be mfu");
|
|
7655
7951
|
}
|
|
7656
7952
|
if (!positiveInteger2(timescale)) {
|
|
7657
7953
|
catalogError("track_timescale", `${path}.timescale`, "must be a positive integer");
|
|
@@ -7674,8 +7970,8 @@ var BlockcastMmt = (() => {
|
|
|
7674
7970
|
}
|
|
7675
7971
|
const config = fec;
|
|
7676
7972
|
const algorithm = config["algorithm"];
|
|
7677
|
-
if (
|
|
7678
|
-
catalogError("track_fec", `${path}.fec.algorithm`, "
|
|
7973
|
+
if (typeof algorithm !== "string" || algorithm.length === 0) {
|
|
7974
|
+
catalogError("track_fec", `${path}.fec.algorithm`, "must be a non-empty string");
|
|
7679
7975
|
}
|
|
7680
7976
|
if ("interleaveDepth" in config || "interleaveMs" in config) {
|
|
7681
7977
|
catalogError("track_fec", `${path}.fec`, "interleaveDepthMs is the only supported interleave field");
|
|
@@ -7704,6 +8000,9 @@ var BlockcastMmt = (() => {
|
|
|
7704
8000
|
}
|
|
7705
8001
|
}
|
|
7706
8002
|
readFecBlockProfile(config["blockProfile"], `${path}.fec.blockProfile`, algorithm !== "none", catalogError);
|
|
8003
|
+
if (algorithm !== "none" && config["symbolSize"] < ISO_SSBG1_MIN_SYMBOL_SIZE) {
|
|
8004
|
+
catalogError("track_fec", `${path}.fec.symbolSize`, "iso-ssbg1-v1 symbolSize must be at least 14");
|
|
8005
|
+
}
|
|
7707
8006
|
}
|
|
7708
8007
|
}
|
|
7709
8008
|
const repairDescriptors = trackRecords.flatMap(
|
|
@@ -7753,19 +8052,34 @@ var BlockcastMmt = (() => {
|
|
|
7753
8052
|
const timescale = BigInt(track["timescale"]);
|
|
7754
8053
|
const durationTicks = track["groupDurationTicks"];
|
|
7755
8054
|
const ticks = durationTicks !== void 0 ? BigInt(durationTicks) : BigInt(track["groupDurationMs"]) * timescale / 1000n;
|
|
7756
|
-
const
|
|
7757
|
-
|
|
7758
|
-
|
|
8055
|
+
const framerate = track["framerate"];
|
|
8056
|
+
const intraOnly = positiveNumber(framerate) && Math.abs(Number(ticks) * framerate - Number(timescale)) <= Number(timescale) * 1e-3;
|
|
8057
|
+
const members = switchingSets.get(altGroup) ?? [];
|
|
8058
|
+
members.push({ index, name: track["name"], ticks, timescale, intraOnly });
|
|
8059
|
+
switchingSets.set(altGroup, members);
|
|
8060
|
+
}
|
|
8061
|
+
for (const [altGroup, members] of switchingSets) {
|
|
8062
|
+
const anchor = members.find((member) => !member.intraOnly) ?? members[0];
|
|
8063
|
+
for (const member of members) {
|
|
8064
|
+
if (member === anchor || member.ticks * anchor.timescale === anchor.ticks * member.timescale) continue;
|
|
8065
|
+
const nests = member.intraOnly && !anchor.intraOnly && anchor.ticks * member.timescale % (member.ticks * anchor.timescale) === 0n;
|
|
8066
|
+
if (!nests) {
|
|
8067
|
+
catalogError("track_switching_set", `$.tracks[${member.index}]`, `group duration does not match ${JSON.stringify(anchor.name)} in altGroup ${altGroup}`);
|
|
8068
|
+
}
|
|
7759
8069
|
}
|
|
7760
|
-
if (!anchor) switchingSets.set(altGroup, { name: track["name"], ticks, timescale });
|
|
7761
8070
|
}
|
|
7762
8071
|
const multicast = catalog["multicast"];
|
|
7763
8072
|
if (typeof multicast === "object" && multicast !== null && !Array.isArray(multicast)) {
|
|
8073
|
+
validateNetworkSourceRelays(multicast["networkSource"], "$.multicast.networkSource");
|
|
7764
8074
|
const endpoints = multicast["endpoints"];
|
|
7765
8075
|
if (Array.isArray(endpoints)) {
|
|
7766
8076
|
for (let endpointIndex = 0; endpointIndex < endpoints.length; endpointIndex++) {
|
|
7767
8077
|
const endpoint = endpoints[endpointIndex];
|
|
7768
8078
|
if (typeof endpoint !== "object" || endpoint === null || Array.isArray(endpoint)) continue;
|
|
8079
|
+
validateNetworkSourceRelays(
|
|
8080
|
+
endpoint["networkSource"],
|
|
8081
|
+
`$.multicast.endpoints[${endpointIndex}].networkSource`
|
|
8082
|
+
);
|
|
7769
8083
|
if ("relayAddress" in endpoint) {
|
|
7770
8084
|
catalogError(
|
|
7771
8085
|
"multicast_relay_address",
|
|
@@ -7805,15 +8119,8 @@ var BlockcastMmt = (() => {
|
|
|
7805
8119
|
}
|
|
7806
8120
|
}
|
|
7807
8121
|
}
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
} catch (error) {
|
|
7811
|
-
catalogError(
|
|
7812
|
-
"multicast_auth",
|
|
7813
|
-
"$.multicast.auth",
|
|
7814
|
-
error instanceof Error ? error.message : "invalid multicast.auth v2 block"
|
|
7815
|
-
);
|
|
7816
|
-
}
|
|
8122
|
+
const [multicastIssue] = multicastCatalogIssues(catalog, options);
|
|
8123
|
+
if (multicastIssue) catalogError(multicastIssue.code, multicastIssue.path, multicastIssue.message);
|
|
7817
8124
|
validateArchive(catalog);
|
|
7818
8125
|
return catalog;
|
|
7819
8126
|
}
|
|
@@ -7823,14 +8130,42 @@ var BlockcastMmt = (() => {
|
|
|
7823
8130
|
const ms = fec?.interleaveDepthMs;
|
|
7824
8131
|
return typeof ms === "number" && Number.isSafeInteger(ms) && ms >= 0 ? ms : void 0;
|
|
7825
8132
|
}
|
|
7826
|
-
function
|
|
7827
|
-
|
|
8133
|
+
function fecBlockDeadlineMs(params) {
|
|
8134
|
+
const { firstAcceptedAtMs, interleaveDepthMs, reorderToleranceMs } = params;
|
|
8135
|
+
if (!Number.isFinite(firstAcceptedAtMs)) {
|
|
8136
|
+
throw new Error(`[FEC] firstAcceptedAtMs must be finite (got ${firstAcceptedAtMs}).`);
|
|
8137
|
+
}
|
|
8138
|
+
return firstAcceptedAtMs + fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs);
|
|
8139
|
+
}
|
|
8140
|
+
function fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs) {
|
|
8141
|
+
if (!Number.isFinite(interleaveDepthMs) || !(interleaveDepthMs > 0)) {
|
|
7828
8142
|
throw new Error(`[FEC] interleaveDepthMs must be a finite value > 0 (got ${interleaveDepthMs}ms). Fix encoder config.`);
|
|
7829
8143
|
}
|
|
7830
|
-
if (!
|
|
7831
|
-
throw new Error(`[FEC]
|
|
8144
|
+
if (!(reorderToleranceMs >= 0) || !Number.isFinite(reorderToleranceMs)) {
|
|
8145
|
+
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.`);
|
|
7832
8146
|
}
|
|
7833
|
-
return Math.ceil(interleaveDepthMs
|
|
8147
|
+
return Math.ceil(interleaveDepthMs + reorderToleranceMs);
|
|
8148
|
+
}
|
|
8149
|
+
function deriveFecRetentionBlocks(deliveryWindowMs, interleaveDepthMs) {
|
|
8150
|
+
const blocks = tryDeriveFecRetentionBlocks(deliveryWindowMs, interleaveDepthMs);
|
|
8151
|
+
if (blocks !== void 0)
|
|
8152
|
+
return blocks;
|
|
8153
|
+
if (!Number.isFinite(interleaveDepthMs) || !(interleaveDepthMs > 0)) {
|
|
8154
|
+
throw new Error(`[FEC] interleaveDepthMs must be a finite value > 0 (got ${interleaveDepthMs}ms). Fix encoder config.`);
|
|
8155
|
+
}
|
|
8156
|
+
if (!Number.isFinite(deliveryWindowMs) || !(deliveryWindowMs > 0)) {
|
|
8157
|
+
throw new Error(`[FEC] deliveryWindowMs must be a finite value > 0 (got ${deliveryWindowMs}ms). It is derived from catalog geometry, not a local default.`);
|
|
8158
|
+
}
|
|
8159
|
+
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.`);
|
|
8160
|
+
}
|
|
8161
|
+
var MAX_FEC_RETENTION_BLOCKS = 255;
|
|
8162
|
+
function tryDeriveFecRetentionBlocks(deliveryWindowMs, interleaveDepthMs) {
|
|
8163
|
+
if (!Number.isFinite(interleaveDepthMs) || !(interleaveDepthMs > 0))
|
|
8164
|
+
return void 0;
|
|
8165
|
+
if (!Number.isFinite(deliveryWindowMs) || !(deliveryWindowMs > 0))
|
|
8166
|
+
return void 0;
|
|
8167
|
+
const blocks = Math.ceil(deliveryWindowMs / interleaveDepthMs) + 1;
|
|
8168
|
+
return blocks > MAX_FEC_RETENTION_BLOCKS ? void 0 : blocks;
|
|
7834
8169
|
}
|
|
7835
8170
|
|
|
7836
8171
|
// ../fec/dist/repair-group.js
|
|
@@ -7854,13 +8189,13 @@ var BlockcastMmt = (() => {
|
|
|
7854
8189
|
function recordOf2(value) {
|
|
7855
8190
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
7856
8191
|
}
|
|
7857
|
-
function
|
|
8192
|
+
function isPositiveSafeInteger2(value) {
|
|
7858
8193
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
7859
8194
|
}
|
|
7860
8195
|
function catalogDeclaresFec(fec) {
|
|
7861
8196
|
const block = recordOf2(fec);
|
|
7862
|
-
if (block === void 0 || block["algorithm"] === "none") return false;
|
|
7863
|
-
return
|
|
8197
|
+
if (block === void 0 || block["algorithm"] === "none" || fecAlgorithmUnimplemented(block["algorithm"])) return false;
|
|
8198
|
+
return isPositiveSafeInteger2(block["sourceSymbols"]) && isPositiveSafeInteger2(block["symbolSize"]) && isFecBlockProfile(block["blockProfile"]) && isoBlockSpanUsable(block) && !catalogFecDeclaresUnconfigurableInstance(block);
|
|
7864
8199
|
}
|
|
7865
8200
|
function requireBoolean(value, field) {
|
|
7866
8201
|
if (typeof value !== "boolean") {
|
|
@@ -7888,6 +8223,395 @@ var BlockcastMmt = (() => {
|
|
|
7888
8223
|
return INACTIVE["reliable-moq"];
|
|
7889
8224
|
}
|
|
7890
8225
|
|
|
8226
|
+
// src/mmtp-fec-session.ts
|
|
8227
|
+
var PATH_BITS = { moq: 1, multicast: 2 };
|
|
8228
|
+
var MIXED_PATHS = PATH_BITS.moq | PATH_BITS.multicast;
|
|
8229
|
+
var _decoder, _blocks, _settled, _have, _newest, _prunedAt, _repairPacketId, _stats3, _MmtpFecSession_instances, drop_fn2, noteNewest_fn, blockStartOf_fn, countHeld_fn, noteMixed_fn, behindHorizon_fn, settle_fn, settleClean_fn, settleDecoded_fn, retireBehindHorizon_fn;
|
|
8230
|
+
var MmtpFecSession = class {
|
|
8231
|
+
/**
|
|
8232
|
+
* @throws when the catalog block lacks or misstates a field the session
|
|
8233
|
+
* needs: the block profile, K, T, `interleaveDepthMs` or
|
|
8234
|
+
* `reorderToleranceMs`. None is defaulted.
|
|
8235
|
+
*/
|
|
8236
|
+
constructor(config) {
|
|
8237
|
+
__privateAdd(this, _MmtpFecSession_instances);
|
|
8238
|
+
__privateAdd(this, _decoder);
|
|
8239
|
+
/** Blocks a repair has defined and that are not settled yet, by SS_Start. */
|
|
8240
|
+
__privateAdd(this, _blocks, /* @__PURE__ */ new Map());
|
|
8241
|
+
/** SS_Starts of settled blocks, so a later repair for one is refused. */
|
|
8242
|
+
__privateAdd(this, _settled, /* @__PURE__ */ new Set());
|
|
8243
|
+
/**
|
|
8244
|
+
* SS_IDs whose packet the parser has, with the PATH_BITS of the path it was
|
|
8245
|
+
* received on, or 0 for one the session recovered.
|
|
8246
|
+
*/
|
|
8247
|
+
__privateAdd(this, _have, /* @__PURE__ */ new Map());
|
|
8248
|
+
__privateAdd(this, _newest);
|
|
8249
|
+
/** The newest SS_ID when the remembered SS_IDs were last pruned. */
|
|
8250
|
+
__privateAdd(this, _prunedAt);
|
|
8251
|
+
__privateAdd(this, _repairPacketId);
|
|
8252
|
+
__privateAdd(this, _stats3, {
|
|
8253
|
+
sourceSymbols: 0,
|
|
8254
|
+
repairSymbols: 0,
|
|
8255
|
+
blocksClean: 0,
|
|
8256
|
+
blocksRecovered: 0,
|
|
8257
|
+
blocksFailed: 0,
|
|
8258
|
+
blocksReleased: 0,
|
|
8259
|
+
packetsRecovered: 0,
|
|
8260
|
+
packetsLost: 0,
|
|
8261
|
+
dropped: {},
|
|
8262
|
+
sourceSymbolsByPath: { moq: 0, multicast: 0 },
|
|
8263
|
+
repairSymbolsByPath: { moq: 0, multicast: 0 },
|
|
8264
|
+
mixedPath: { clean: 0, recovered: 0, failed: 0, released: 0 }
|
|
8265
|
+
});
|
|
8266
|
+
const fec = config?.fec;
|
|
8267
|
+
if (!fec || typeof fec !== "object") {
|
|
8268
|
+
throw new Error("MmtpFecSession: the catalog fec block is required");
|
|
8269
|
+
}
|
|
8270
|
+
this.blockProfile = parseFecBlockProfile(fec.blockProfile, "fec.blockProfile");
|
|
8271
|
+
if (fec.algorithm !== void 0 && fec.algorithm !== "raptorq" && fec.algorithm !== "reed-solomon") {
|
|
8272
|
+
throw new Error(`MmtpFecSession: fec.algorithm ${JSON.stringify(fec.algorithm)} is not implemented`);
|
|
8273
|
+
}
|
|
8274
|
+
this.algorithm = fec.algorithm === "reed-solomon" ? "reed-solomon" : "raptorq";
|
|
8275
|
+
this.sourceSymbols = requirePositiveInteger(fec.sourceSymbols, "fec.sourceSymbols");
|
|
8276
|
+
this.symbolSize = requirePositiveInteger(fec.symbolSize, "fec.symbolSize");
|
|
8277
|
+
const interleaveDepthMs = requireNumber(fec.interleaveDepthMs, "fec.interleaveDepthMs");
|
|
8278
|
+
const reorderToleranceMs = requireNumber(fec.reorderToleranceMs, "fec.reorderToleranceMs");
|
|
8279
|
+
this.retentionBlocks = deriveFecRetentionBlocks(
|
|
8280
|
+
fecBlockBudgetMs(interleaveDepthMs, reorderToleranceMs),
|
|
8281
|
+
interleaveDepthMs
|
|
8282
|
+
);
|
|
8283
|
+
if (typeof config.Decoder !== "function") {
|
|
8284
|
+
throw new Error("MmtpFecSession: a decoder constructor (wasm_bindgen.MmtFecDecoder) is required");
|
|
8285
|
+
}
|
|
8286
|
+
const decoder = new config.Decoder(this.retentionBlocks, this.blockProfile, this.algorithm);
|
|
8287
|
+
try {
|
|
8288
|
+
decoder.configure_params(this.sourceSymbols, this.symbolSize);
|
|
8289
|
+
} catch (error) {
|
|
8290
|
+
decoder.free();
|
|
8291
|
+
throw error;
|
|
8292
|
+
}
|
|
8293
|
+
__privateSet(this, _decoder, decoder);
|
|
8294
|
+
}
|
|
8295
|
+
/** True once release() ran. */
|
|
8296
|
+
get released() {
|
|
8297
|
+
return __privateGet(this, _decoder) === null;
|
|
8298
|
+
}
|
|
8299
|
+
get stats() {
|
|
8300
|
+
return {
|
|
8301
|
+
...__privateGet(this, _stats3),
|
|
8302
|
+
dropped: { ...__privateGet(this, _stats3).dropped },
|
|
8303
|
+
sourceSymbolsByPath: { ...__privateGet(this, _stats3).sourceSymbolsByPath },
|
|
8304
|
+
repairSymbolsByPath: { ...__privateGet(this, _stats3).repairSymbolsByPath },
|
|
8305
|
+
mixedPath: { ...__privateGet(this, _stats3).mixedPath }
|
|
8306
|
+
};
|
|
8307
|
+
}
|
|
8308
|
+
/**
|
|
8309
|
+
* Feeds one received source packet: the MMTP packet without its four-byte
|
|
8310
|
+
* Source FEC Payload ID, under the SS_ID that ID stated. This is what
|
|
8311
|
+
* MmtpContainerParser's onSourceSymbol() hands over. `path` is where it
|
|
8312
|
+
* was received; a caller that only subscribes over MoQT can leave it out.
|
|
8313
|
+
*
|
|
8314
|
+
* @returns the protected packets of this packet's block that it recovered,
|
|
8315
|
+
* in SS_ID order, for the caller to feed to its parser with
|
|
8316
|
+
* `{skipFecPayloadId: true, recovered: true}`. Usually empty.
|
|
8317
|
+
*/
|
|
8318
|
+
addSource(ssId, packet, path = "moq") {
|
|
8319
|
+
const decoder = __privateGet(this, _decoder);
|
|
8320
|
+
if (!decoder) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:released");
|
|
8321
|
+
const pathBit = PATH_BITS[path];
|
|
8322
|
+
if (!pathBit) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:unknown-path");
|
|
8323
|
+
if (!Number.isInteger(ssId) || ssId < 0 || ssId > 4294967295) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:bad-ss-id");
|
|
8324
|
+
if (!ssbg1FitsSymbol(packet.byteLength, this.symbolSize)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:exceeds-symbol");
|
|
8325
|
+
if (__privateGet(this, _have).has(ssId)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:duplicate");
|
|
8326
|
+
__privateGet(this, _have).set(ssId, pathBit);
|
|
8327
|
+
__privateGet(this, _stats3).sourceSymbols++;
|
|
8328
|
+
__privateGet(this, _stats3).sourceSymbolsByPath[path]++;
|
|
8329
|
+
__privateMethod(this, _MmtpFecSession_instances, noteNewest_fn).call(this, ssId);
|
|
8330
|
+
const start = __privateMethod(this, _MmtpFecSession_instances, blockStartOf_fn).call(this, ssId);
|
|
8331
|
+
const block = start === void 0 ? void 0 : __privateGet(this, _blocks).get(start);
|
|
8332
|
+
if (block) {
|
|
8333
|
+
block.received++;
|
|
8334
|
+
block.paths |= pathBit;
|
|
8335
|
+
}
|
|
8336
|
+
let output;
|
|
8337
|
+
try {
|
|
8338
|
+
output = decoder.add_source(ssId, packet, 0);
|
|
8339
|
+
} catch {
|
|
8340
|
+
__privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "source:decoder-refused");
|
|
8341
|
+
output = void 0;
|
|
8342
|
+
}
|
|
8343
|
+
const recovered = [];
|
|
8344
|
+
if (start !== void 0 && block) {
|
|
8345
|
+
if (output) {
|
|
8346
|
+
recovered.push(...__privateMethod(this, _MmtpFecSession_instances, settleDecoded_fn).call(this, start, block, output));
|
|
8347
|
+
} else if (block.received >= block.ssbLength) {
|
|
8348
|
+
__privateMethod(this, _MmtpFecSession_instances, settleClean_fn).call(this, start);
|
|
8349
|
+
}
|
|
8350
|
+
}
|
|
8351
|
+
__privateMethod(this, _MmtpFecSession_instances, retireBehindHorizon_fn).call(this);
|
|
8352
|
+
return recovered;
|
|
8353
|
+
}
|
|
8354
|
+
/**
|
|
8355
|
+
* Feeds one object of the repair track: a whole MMTP repair packet (ISO/IEC
|
|
8356
|
+
* 23008-1 C.5.3). A repair track carries one repair flow, so the first
|
|
8357
|
+
* repair packet fixes its packet ID and a packet of any other is refused.
|
|
8358
|
+
* `path` is where it was received, as for addSource().
|
|
8359
|
+
*
|
|
8360
|
+
* @returns the protected packets this repair symbol recovered, as for
|
|
8361
|
+
* addSource().
|
|
8362
|
+
*/
|
|
8363
|
+
addRepair(packet, path = "moq") {
|
|
8364
|
+
const decoder = __privateGet(this, _decoder);
|
|
8365
|
+
if (!decoder) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:released");
|
|
8366
|
+
const pathBit = PATH_BITS[path];
|
|
8367
|
+
if (!pathBit) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:unknown-path");
|
|
8368
|
+
let header;
|
|
8369
|
+
try {
|
|
8370
|
+
header = parseMMTPHeader(packet);
|
|
8371
|
+
} catch {
|
|
8372
|
+
return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:malformed");
|
|
8373
|
+
}
|
|
8374
|
+
const frame = parseMoqRepairFrameWithHeader(packet, header);
|
|
8375
|
+
if (!frame) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:malformed");
|
|
8376
|
+
if (__privateGet(this, _repairPacketId) === void 0) {
|
|
8377
|
+
__privateSet(this, _repairPacketId, frame.packetId);
|
|
8378
|
+
} else if (frame.packetId !== __privateGet(this, _repairPacketId)) {
|
|
8379
|
+
return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:foreign-packet-id");
|
|
8380
|
+
}
|
|
8381
|
+
if (frame.symbolData.byteLength !== this.symbolSize) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:symbol-size");
|
|
8382
|
+
if (frame.ssbLength > this.sourceSymbols) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:ssb-length");
|
|
8383
|
+
if (this.algorithm === "reed-solomon" && frame.ssbLength + frame.rsbLength > 255) {
|
|
8384
|
+
return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:rs-block-length");
|
|
8385
|
+
}
|
|
8386
|
+
const start = frame.ssStart;
|
|
8387
|
+
let block = __privateGet(this, _blocks).get(start);
|
|
8388
|
+
if (block && block.ssbLength !== frame.ssbLength) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:conflicting-ssb-length");
|
|
8389
|
+
if (block?.rsIds.has(frame.rsId)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:duplicate");
|
|
8390
|
+
if (!block) {
|
|
8391
|
+
if (__privateGet(this, _settled).has(start)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:block-settled");
|
|
8392
|
+
if (__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, start)) return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:behind-horizon");
|
|
8393
|
+
block = { ssbLength: frame.ssbLength, received: 0, paths: 0, rsIds: /* @__PURE__ */ new Set() };
|
|
8394
|
+
__privateMethod(this, _MmtpFecSession_instances, countHeld_fn).call(this, start, block);
|
|
8395
|
+
__privateGet(this, _blocks).set(start, block);
|
|
8396
|
+
}
|
|
8397
|
+
__privateMethod(this, _MmtpFecSession_instances, noteNewest_fn).call(this, serial32Add(start, frame.ssbLength - 1));
|
|
8398
|
+
if (block.received >= block.ssbLength) {
|
|
8399
|
+
__privateMethod(this, _MmtpFecSession_instances, settleClean_fn).call(this, start);
|
|
8400
|
+
__privateMethod(this, _MmtpFecSession_instances, retireBehindHorizon_fn).call(this);
|
|
8401
|
+
return [];
|
|
8402
|
+
}
|
|
8403
|
+
let output;
|
|
8404
|
+
try {
|
|
8405
|
+
output = decoder.add_repair(start, frame.ssbLength, frame.rsId, frame.symbolData, 0);
|
|
8406
|
+
} catch {
|
|
8407
|
+
return __privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "repair:decoder-refused");
|
|
8408
|
+
}
|
|
8409
|
+
block.rsIds.add(frame.rsId);
|
|
8410
|
+
__privateGet(this, _stats3).repairSymbols++;
|
|
8411
|
+
__privateGet(this, _stats3).repairSymbolsByPath[path]++;
|
|
8412
|
+
block.paths |= pathBit;
|
|
8413
|
+
const recovered = output ? __privateMethod(this, _MmtpFecSession_instances, settleDecoded_fn).call(this, start, block, output) : [];
|
|
8414
|
+
__privateMethod(this, _MmtpFecSession_instances, retireBehindHorizon_fn).call(this);
|
|
8415
|
+
return recovered;
|
|
8416
|
+
}
|
|
8417
|
+
/**
|
|
8418
|
+
* Frees the decoder and every block. Blocks still unsettled are counted as
|
|
8419
|
+
* released, not failed: nothing proved them unrecoverable. Idempotent;
|
|
8420
|
+
* returns whether this call released anything.
|
|
8421
|
+
*/
|
|
8422
|
+
release() {
|
|
8423
|
+
const decoder = __privateGet(this, _decoder);
|
|
8424
|
+
if (!decoder) return false;
|
|
8425
|
+
__privateSet(this, _decoder, null);
|
|
8426
|
+
__privateGet(this, _stats3).blocksReleased += __privateGet(this, _blocks).size;
|
|
8427
|
+
for (const block of __privateGet(this, _blocks).values()) __privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "released");
|
|
8428
|
+
__privateGet(this, _blocks).clear();
|
|
8429
|
+
__privateGet(this, _settled).clear();
|
|
8430
|
+
__privateGet(this, _have).clear();
|
|
8431
|
+
decoder.free();
|
|
8432
|
+
return true;
|
|
8433
|
+
}
|
|
8434
|
+
};
|
|
8435
|
+
_decoder = new WeakMap();
|
|
8436
|
+
_blocks = new WeakMap();
|
|
8437
|
+
_settled = new WeakMap();
|
|
8438
|
+
_have = new WeakMap();
|
|
8439
|
+
_newest = new WeakMap();
|
|
8440
|
+
_prunedAt = new WeakMap();
|
|
8441
|
+
_repairPacketId = new WeakMap();
|
|
8442
|
+
_stats3 = new WeakMap();
|
|
8443
|
+
_MmtpFecSession_instances = new WeakSet();
|
|
8444
|
+
drop_fn2 = function(reason) {
|
|
8445
|
+
__privateGet(this, _stats3).dropped[reason] = (__privateGet(this, _stats3).dropped[reason] ?? 0) + 1;
|
|
8446
|
+
return [];
|
|
8447
|
+
};
|
|
8448
|
+
noteNewest_fn = function(ssId) {
|
|
8449
|
+
if (__privateGet(this, _newest) === void 0 || serial32Precedes(__privateGet(this, _newest), ssId)) __privateSet(this, _newest, ssId);
|
|
8450
|
+
};
|
|
8451
|
+
blockStartOf_fn = function(ssId) {
|
|
8452
|
+
for (const [start, block] of __privateGet(this, _blocks)) {
|
|
8453
|
+
if (isoBlockContains(start, block.ssbLength, ssId)) return start;
|
|
8454
|
+
}
|
|
8455
|
+
return void 0;
|
|
8456
|
+
};
|
|
8457
|
+
/** Counts the sources of a new block the parser already has, and their paths. */
|
|
8458
|
+
countHeld_fn = function(start, block) {
|
|
8459
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
8460
|
+
const pathBit = __privateGet(this, _have).get(serial32Add(start, i));
|
|
8461
|
+
if (pathBit === void 0) continue;
|
|
8462
|
+
block.received++;
|
|
8463
|
+
block.paths |= pathBit;
|
|
8464
|
+
}
|
|
8465
|
+
};
|
|
8466
|
+
noteMixed_fn = function(block, outcome) {
|
|
8467
|
+
if ((block.paths & MIXED_PATHS) === MIXED_PATHS) __privateGet(this, _stats3).mixedPath[outcome]++;
|
|
8468
|
+
};
|
|
8469
|
+
/** The decoder's own rule: more than its retention behind, counted from below. */
|
|
8470
|
+
behindHorizon_fn = function(start) {
|
|
8471
|
+
const newest = __privateGet(this, _newest);
|
|
8472
|
+
if (newest === void 0) return false;
|
|
8473
|
+
return isoBlocksBehindLowerBound(start, newest, this.sourceSymbols) > this.retentionBlocks;
|
|
8474
|
+
};
|
|
8475
|
+
settle_fn = function(start) {
|
|
8476
|
+
__privateGet(this, _blocks).delete(start);
|
|
8477
|
+
__privateGet(this, _settled).add(start);
|
|
8478
|
+
};
|
|
8479
|
+
settleClean_fn = function(start) {
|
|
8480
|
+
const block = __privateGet(this, _blocks).get(start);
|
|
8481
|
+
if (!block) return;
|
|
8482
|
+
__privateMethod(this, _MmtpFecSession_instances, settle_fn).call(this, start);
|
|
8483
|
+
__privateGet(this, _stats3).blocksClean++;
|
|
8484
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "clean");
|
|
8485
|
+
try {
|
|
8486
|
+
__privateGet(this, _decoder)?.cleanup_blocks_detailed(Uint32Array.of(start));
|
|
8487
|
+
} catch {
|
|
8488
|
+
}
|
|
8489
|
+
};
|
|
8490
|
+
/**
|
|
8491
|
+
* The decoder returns a completed block as its K' ssbg_mode1 symbols,
|
|
8492
|
+
* concatenated: split by T, trim by each symbol's length field, and hand
|
|
8493
|
+
* back the packets the parser does not have yet.
|
|
8494
|
+
*/
|
|
8495
|
+
settleDecoded_fn = function(start, block, output) {
|
|
8496
|
+
__privateMethod(this, _MmtpFecSession_instances, settle_fn).call(this, start);
|
|
8497
|
+
if (output.byteLength !== block.ssbLength * this.symbolSize) {
|
|
8498
|
+
__privateGet(this, _stats3).blocksFailed++;
|
|
8499
|
+
__privateGet(this, _stats3).packetsLost += block.ssbLength - block.received;
|
|
8500
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "failed");
|
|
8501
|
+
__privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "block:decoded-length");
|
|
8502
|
+
return [];
|
|
8503
|
+
}
|
|
8504
|
+
const recovered = [];
|
|
8505
|
+
let refused = 0;
|
|
8506
|
+
for (let i = 0; i < block.ssbLength; i++) {
|
|
8507
|
+
const ssId = serial32Add(start, i);
|
|
8508
|
+
if (__privateGet(this, _have).has(ssId)) continue;
|
|
8509
|
+
const symbol = output.subarray(i * this.symbolSize, (i + 1) * this.symbolSize);
|
|
8510
|
+
const packet = trimSsbg1SourceSymbol(symbol);
|
|
8511
|
+
if (!packet) {
|
|
8512
|
+
refused++;
|
|
8513
|
+
continue;
|
|
8514
|
+
}
|
|
8515
|
+
__privateGet(this, _have).set(ssId, 0);
|
|
8516
|
+
recovered.push(packet.slice());
|
|
8517
|
+
}
|
|
8518
|
+
if (refused > 0) {
|
|
8519
|
+
__privateGet(this, _stats3).blocksFailed++;
|
|
8520
|
+
__privateGet(this, _stats3).packetsLost += refused;
|
|
8521
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "failed");
|
|
8522
|
+
__privateMethod(this, _MmtpFecSession_instances, drop_fn2).call(this, "block:bad-ssbg1-symbol");
|
|
8523
|
+
} else if (recovered.length === 0) {
|
|
8524
|
+
__privateGet(this, _stats3).blocksClean++;
|
|
8525
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "clean");
|
|
8526
|
+
} else {
|
|
8527
|
+
__privateGet(this, _stats3).blocksRecovered++;
|
|
8528
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "recovered");
|
|
8529
|
+
}
|
|
8530
|
+
__privateGet(this, _stats3).packetsRecovered += recovered.length;
|
|
8531
|
+
return recovered;
|
|
8532
|
+
};
|
|
8533
|
+
/**
|
|
8534
|
+
* Retires every block, and every SS_ID the session remembers, that the
|
|
8535
|
+
* newest SS_ID has moved past the retention. An unsettled block retired
|
|
8536
|
+
* here is a failure: more of its sources were lost than its repair could
|
|
8537
|
+
* restore, or its repair never arrived.
|
|
8538
|
+
*/
|
|
8539
|
+
retireBehindHorizon_fn = function() {
|
|
8540
|
+
const decoder = __privateGet(this, _decoder);
|
|
8541
|
+
const newest = __privateGet(this, _newest);
|
|
8542
|
+
if (!decoder || newest === void 0) return;
|
|
8543
|
+
try {
|
|
8544
|
+
decoder.cleanup_by_ss_start(newest);
|
|
8545
|
+
} catch {
|
|
8546
|
+
}
|
|
8547
|
+
for (const [start, block] of __privateGet(this, _blocks)) {
|
|
8548
|
+
if (!__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, start)) continue;
|
|
8549
|
+
__privateMethod(this, _MmtpFecSession_instances, settle_fn).call(this, start);
|
|
8550
|
+
__privateGet(this, _stats3).blocksFailed++;
|
|
8551
|
+
__privateGet(this, _stats3).packetsLost += block.ssbLength - block.received;
|
|
8552
|
+
__privateMethod(this, _MmtpFecSession_instances, noteMixed_fn).call(this, block, "failed");
|
|
8553
|
+
}
|
|
8554
|
+
const prunedAt = __privateGet(this, _prunedAt);
|
|
8555
|
+
if (prunedAt !== void 0 && serial32Distance(prunedAt, newest) < this.sourceSymbols) return;
|
|
8556
|
+
__privateSet(this, _prunedAt, newest);
|
|
8557
|
+
for (const ssId of __privateGet(this, _have).keys()) {
|
|
8558
|
+
if (__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, ssId)) __privateGet(this, _have).delete(ssId);
|
|
8559
|
+
}
|
|
8560
|
+
for (const start of __privateGet(this, _settled)) {
|
|
8561
|
+
if (__privateMethod(this, _MmtpFecSession_instances, behindHorizon_fn).call(this, start)) __privateGet(this, _settled).delete(start);
|
|
8562
|
+
}
|
|
8563
|
+
};
|
|
8564
|
+
function requirePositiveInteger(value, path) {
|
|
8565
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
8566
|
+
throw new Error(`MmtpFecSession: ${path} must be a positive integer (got ${String(value)})`);
|
|
8567
|
+
}
|
|
8568
|
+
return value;
|
|
8569
|
+
}
|
|
8570
|
+
function requireNumber(value, path) {
|
|
8571
|
+
if (typeof value !== "number") {
|
|
8572
|
+
throw new Error(`MmtpFecSession: ${path} is required (got ${String(value)}); it is never defaulted`);
|
|
8573
|
+
}
|
|
8574
|
+
return value;
|
|
8575
|
+
}
|
|
8576
|
+
|
|
8577
|
+
// src/catalog-network-source.ts
|
|
8578
|
+
function normalizePort(value) {
|
|
8579
|
+
const n = typeof value === "number" ? value : typeof value === "string" ? Number(value) : Number.NaN;
|
|
8580
|
+
return Number.isInteger(n) && n > 0 && n <= 65535 ? n : void 0;
|
|
8581
|
+
}
|
|
8582
|
+
function catalogAmtNetworkSource(networkSource) {
|
|
8583
|
+
const entries = Array.isArray(networkSource) ? networkSource : networkSource ? [networkSource] : [];
|
|
8584
|
+
for (const raw of entries) {
|
|
8585
|
+
if (!raw || typeof raw !== "object") continue;
|
|
8586
|
+
const ns = raw;
|
|
8587
|
+
if (ns.type !== "amt") continue;
|
|
8588
|
+
if (ns.discovery === "driad") continue;
|
|
8589
|
+
const relay = typeof ns.relay === "string" ? ns.relay.trim() : "";
|
|
8590
|
+
if (!relay) continue;
|
|
8591
|
+
return { relay, port: normalizePort(ns.port) ?? DEFAULT_AMT_RELAY_PORT };
|
|
8592
|
+
}
|
|
8593
|
+
return void 0;
|
|
8594
|
+
}
|
|
8595
|
+
function intIn(value, min, max) {
|
|
8596
|
+
return Number.isInteger(value) && value >= min && value <= max;
|
|
8597
|
+
}
|
|
8598
|
+
function catalogAtsc3NetworkSource(networkSource) {
|
|
8599
|
+
const entries = Array.isArray(networkSource) ? networkSource : networkSource ? [networkSource] : [];
|
|
8600
|
+
for (const raw of entries) {
|
|
8601
|
+
if (!raw || typeof raw !== "object") continue;
|
|
8602
|
+
const ns = raw;
|
|
8603
|
+
if (ns.type !== "atsc3" || !intIn(ns.frequency, 1, Number.MAX_SAFE_INTEGER)) continue;
|
|
8604
|
+
const slsUri = typeof ns.slsUri === "string" ? ns.slsUri.trim() : "";
|
|
8605
|
+
return {
|
|
8606
|
+
frequency: ns.frequency,
|
|
8607
|
+
...intIn(ns.plpId, 0, 63) ? { plpId: ns.plpId } : {},
|
|
8608
|
+
...intIn(ns.serviceId, 0, 65535) ? { serviceId: ns.serviceId } : {},
|
|
8609
|
+
...slsUri ? { slsUri } : {}
|
|
8610
|
+
};
|
|
8611
|
+
}
|
|
8612
|
+
return void 0;
|
|
8613
|
+
}
|
|
8614
|
+
|
|
7891
8615
|
// src/mmtp-to-cmaf.ts
|
|
7892
8616
|
function box(type, ...children2) {
|
|
7893
8617
|
let size = 8;
|
|
@@ -7930,8 +8654,8 @@ var BlockcastMmt = (() => {
|
|
|
7930
8654
|
}
|
|
7931
8655
|
var KEYFRAME_FLAGS = 33554432;
|
|
7932
8656
|
var DELTA_FLAGS = 16842752;
|
|
7933
|
-
var
|
|
7934
|
-
var MAX_TRACK_ID =
|
|
8657
|
+
var UINT32_MAX2 = 4294967295;
|
|
8658
|
+
var MAX_TRACK_ID = UINT32_MAX2 - 1;
|
|
7935
8659
|
var INT32_MIN = -2147483648;
|
|
7936
8660
|
var INT32_MAX = 2147483647;
|
|
7937
8661
|
function assertTrackId(trackId, label) {
|
|
@@ -7940,8 +8664,8 @@ var BlockcastMmt = (() => {
|
|
|
7940
8664
|
}
|
|
7941
8665
|
}
|
|
7942
8666
|
function assertTimescale(timescale, label) {
|
|
7943
|
-
if (!Number.isInteger(timescale) || timescale <= 0 || timescale >
|
|
7944
|
-
throw new RangeError(`${label} must be an integer in 1..${
|
|
8667
|
+
if (!Number.isInteger(timescale) || timescale <= 0 || timescale > UINT32_MAX2) {
|
|
8668
|
+
throw new RangeError(`${label} must be an integer in 1..${UINT32_MAX2}, got ${timescale}`);
|
|
7945
8669
|
}
|
|
7946
8670
|
}
|
|
7947
8671
|
function assertCompositionTimeOffsets(samples) {
|
|
@@ -9005,7 +9729,7 @@ var BlockcastMmt = (() => {
|
|
|
9005
9729
|
var SOURCE_AUTH_GROUP_CLOSE_LENGTH = 112;
|
|
9006
9730
|
var SOURCE_AUTH_MAX_OBJECTS_PER_GROUP = 4096;
|
|
9007
9731
|
var SOURCE_AUTH_MAX_TRUE_LENGTH = 16 * 1024 * 1024;
|
|
9008
|
-
var
|
|
9732
|
+
var SOURCE_AUTH_SCOPE_LENGTH = 32;
|
|
9009
9733
|
var SIGNATURE_DOMAIN = new TextEncoder().encode("blockcast-mmt-root-v1\0\0\0");
|
|
9010
9734
|
function requireBytes(name, value, length) {
|
|
9011
9735
|
if (value.byteLength !== length) {
|
|
@@ -9082,7 +9806,7 @@ var BlockcastMmt = (() => {
|
|
|
9082
9806
|
throw new Error(`objectCount must be between 1 and ${SOURCE_AUTH_MAX_OBJECTS_PER_GROUP}`);
|
|
9083
9807
|
}
|
|
9084
9808
|
requireU64("groupId", groupId);
|
|
9085
|
-
requireBytes("authScope", authScope,
|
|
9809
|
+
requireBytes("authScope", authScope, SOURCE_AUTH_SCOPE_LENGTH);
|
|
9086
9810
|
requireBytes("root", root, 32);
|
|
9087
9811
|
const preimage = new Uint8Array(100);
|
|
9088
9812
|
const view2 = new DataView(preimage.buffer);
|
|
@@ -9133,6 +9857,20 @@ var BlockcastMmt = (() => {
|
|
|
9133
9857
|
}
|
|
9134
9858
|
|
|
9135
9859
|
// ../mmt-manifest-verify/dist/verifier.js
|
|
9860
|
+
function manifestKeyFor(keys, epoch, kid) {
|
|
9861
|
+
if (new Set(keys.map((key) => key.kid)).size !== keys.length)
|
|
9862
|
+
return void 0;
|
|
9863
|
+
if (new Set(keys.map((key) => key.firstEpoch)).size !== keys.length)
|
|
9864
|
+
return void 0;
|
|
9865
|
+
let signer;
|
|
9866
|
+
for (const key of keys) {
|
|
9867
|
+
if (key.firstEpoch <= epoch && (signer === void 0 || key.firstEpoch > signer.firstEpoch))
|
|
9868
|
+
signer = key;
|
|
9869
|
+
}
|
|
9870
|
+
if (signer === void 0 || kid !== void 0 && signer.kid !== kid)
|
|
9871
|
+
return void 0;
|
|
9872
|
+
return signer.publicKey;
|
|
9873
|
+
}
|
|
9136
9874
|
function manifestBindingId(trackName, sourceSymbolFormat) {
|
|
9137
9875
|
return JSON.stringify([trackName, sourceSymbolFormat]);
|
|
9138
9876
|
}
|
|
@@ -9161,7 +9899,7 @@ var BlockcastMmt = (() => {
|
|
|
9161
9899
|
return diff === 0;
|
|
9162
9900
|
};
|
|
9163
9901
|
var isPromiseLike = (value) => typeof value === "object" && value !== null && typeof value.then === "function";
|
|
9164
|
-
var _config, _verifySignature, _onFailure, _tracks2,
|
|
9902
|
+
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;
|
|
9165
9903
|
var ManifestVerifier = class {
|
|
9166
9904
|
constructor(options) {
|
|
9167
9905
|
__privateAdd(this, _ManifestVerifier_instances);
|
|
@@ -9169,7 +9907,7 @@ var BlockcastMmt = (() => {
|
|
|
9169
9907
|
__privateAdd(this, _verifySignature);
|
|
9170
9908
|
__privateAdd(this, _onFailure);
|
|
9171
9909
|
__privateAdd(this, _tracks2, /* @__PURE__ */ new Map());
|
|
9172
|
-
__privateAdd(this,
|
|
9910
|
+
__privateAdd(this, _stats4, {
|
|
9173
9911
|
verified: 0,
|
|
9174
9912
|
failures: Object.fromEntries(FAILURE_REASONS.map((reason) => [reason, 0])),
|
|
9175
9913
|
quarantinedBytes: 0
|
|
@@ -9187,10 +9925,10 @@ var BlockcastMmt = (() => {
|
|
|
9187
9925
|
for (const track of __privateGet(this, _tracks2).values())
|
|
9188
9926
|
quarantined += track.quarantine.length;
|
|
9189
9927
|
return {
|
|
9190
|
-
verified: __privateGet(this,
|
|
9191
|
-
failures: { ...__privateGet(this,
|
|
9928
|
+
verified: __privateGet(this, _stats4).verified,
|
|
9929
|
+
failures: { ...__privateGet(this, _stats4).failures },
|
|
9192
9930
|
quarantined,
|
|
9193
|
-
quarantinedBytes: __privateGet(this,
|
|
9931
|
+
quarantinedBytes: __privateGet(this, _stats4).quarantinedBytes
|
|
9194
9932
|
};
|
|
9195
9933
|
}
|
|
9196
9934
|
setMode(mode) {
|
|
@@ -9211,11 +9949,12 @@ var BlockcastMmt = (() => {
|
|
|
9211
9949
|
}
|
|
9212
9950
|
if (context.authScope.byteLength !== 32)
|
|
9213
9951
|
throw new Error("manifest authScope must be 32 bytes");
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9952
|
+
for (const key of context.keys) {
|
|
9953
|
+
if (key.publicKey.byteLength !== 32)
|
|
9954
|
+
throw new Error("manifest keys must carry 32-byte public keys");
|
|
9955
|
+
}
|
|
9956
|
+
if (manifestKeyFor(context.keys, context.keyEpoch) === void 0) {
|
|
9957
|
+
throw new Error(`manifest keys hold no key set signing keyEpoch ${context.keyEpoch}`);
|
|
9219
9958
|
}
|
|
9220
9959
|
for (const [name, value] of Object.entries({
|
|
9221
9960
|
broadcastNamespaceId: context.broadcastNamespaceId,
|
|
@@ -9325,7 +10064,7 @@ var BlockcastMmt = (() => {
|
|
|
9325
10064
|
_verifySignature = new WeakMap();
|
|
9326
10065
|
_onFailure = new WeakMap();
|
|
9327
10066
|
_tracks2 = new WeakMap();
|
|
9328
|
-
|
|
10067
|
+
_stats4 = new WeakMap();
|
|
9329
10068
|
_disposed2 = new WeakMap();
|
|
9330
10069
|
_ManifestVerifier_instances = new WeakSet();
|
|
9331
10070
|
requireTrack_fn = function(bindingId) {
|
|
@@ -9377,7 +10116,7 @@ var BlockcastMmt = (() => {
|
|
|
9377
10116
|
return { action: "stall", verified: false };
|
|
9378
10117
|
}
|
|
9379
10118
|
release();
|
|
9380
|
-
__privateGet(this,
|
|
10119
|
+
__privateGet(this, _stats4).verified++;
|
|
9381
10120
|
return { action: "play", verified: true };
|
|
9382
10121
|
};
|
|
9383
10122
|
rejectOrShadow_fn = function(identity, release, reason) {
|
|
@@ -9468,7 +10207,7 @@ var BlockcastMmt = (() => {
|
|
|
9468
10207
|
}
|
|
9469
10208
|
};
|
|
9470
10209
|
verifyAcceptedSignature_fn = function(track, message, signature) {
|
|
9471
|
-
const keys = track.context.
|
|
10210
|
+
const keys = [manifestKeyFor(track.context.keys, track.context.keyEpoch)];
|
|
9472
10211
|
const pending = [];
|
|
9473
10212
|
let hadSynchronousError = false;
|
|
9474
10213
|
for (const key of keys) {
|
|
@@ -9517,7 +10256,7 @@ var BlockcastMmt = (() => {
|
|
|
9517
10256
|
if (index >= 0)
|
|
9518
10257
|
track.quarantine.splice(index, 1);
|
|
9519
10258
|
track.quarantinedBytes -= pending.bytes;
|
|
9520
|
-
__privateGet(this,
|
|
10259
|
+
__privateGet(this, _stats4).quarantinedBytes -= pending.bytes;
|
|
9521
10260
|
};
|
|
9522
10261
|
quarantine_fn = function(track, group, pending) {
|
|
9523
10262
|
if (group.pending.has(pending.identity.objectId))
|
|
@@ -9525,7 +10264,7 @@ var BlockcastMmt = (() => {
|
|
|
9525
10264
|
group.pending.set(pending.identity.objectId, pending);
|
|
9526
10265
|
track.quarantine.push(pending);
|
|
9527
10266
|
track.quarantinedBytes += pending.bytes;
|
|
9528
|
-
__privateGet(this,
|
|
10267
|
+
__privateGet(this, _stats4).quarantinedBytes += pending.bytes;
|
|
9529
10268
|
__privateMethod(this, _ManifestVerifier_instances, enforceCap_fn).call(this, track);
|
|
9530
10269
|
return true;
|
|
9531
10270
|
};
|
|
@@ -9536,7 +10275,7 @@ var BlockcastMmt = (() => {
|
|
|
9536
10275
|
if (group)
|
|
9537
10276
|
group.pending.delete(pending.identity.objectId);
|
|
9538
10277
|
track.quarantinedBytes -= pending.bytes;
|
|
9539
|
-
__privateGet(this,
|
|
10278
|
+
__privateGet(this, _stats4).quarantinedBytes -= pending.bytes;
|
|
9540
10279
|
__privateMethod(this, _ManifestVerifier_instances, giveUpOnPending_fn).call(this, pending);
|
|
9541
10280
|
__privateMethod(this, _ManifestVerifier_instances, failure_fn).call(this, pending.identity, "manifestAbsent");
|
|
9542
10281
|
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"}`);
|
|
@@ -9593,7 +10332,7 @@ var BlockcastMmt = (() => {
|
|
|
9593
10332
|
};
|
|
9594
10333
|
failure_fn = function(identity, reason) {
|
|
9595
10334
|
var _a;
|
|
9596
|
-
__privateGet(this,
|
|
10335
|
+
__privateGet(this, _stats4).failures[reason]++;
|
|
9597
10336
|
(_a = __privateGet(this, _onFailure)) == null ? void 0 : _a.call(this, {
|
|
9598
10337
|
trackName: identity.trackName,
|
|
9599
10338
|
...identity.bindingId === void 0 ? {} : { bindingId: identity.bindingId },
|
|
@@ -9603,59 +10342,140 @@ var BlockcastMmt = (() => {
|
|
|
9603
10342
|
});
|
|
9604
10343
|
};
|
|
9605
10344
|
|
|
9606
|
-
//
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
|
|
9625
|
-
|
|
9626
|
-
|
|
9627
|
-
|
|
9628
|
-
|
|
9629
|
-
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
|
|
10345
|
+
// ../mmt-manifest-verify/dist/bc-provenance-v2.js
|
|
10346
|
+
var BCPV2_HEADER_LENGTH = 68;
|
|
10347
|
+
var BCPV2_SIGNATURE_LENGTH = 64;
|
|
10348
|
+
var BCPV2_MIN_RECORD_LENGTH = BCPV2_HEADER_LENGTH + 32 + BCPV2_SIGNATURE_LENGTH;
|
|
10349
|
+
var text = new TextEncoder();
|
|
10350
|
+
var MAGIC = Uint8Array.from([77, 72, 77, 50]);
|
|
10351
|
+
var SIGNING_DOMAIN = text.encode("mcast-manifest-v2\0");
|
|
10352
|
+
|
|
10353
|
+
// src/multicast-auth-catalog.ts
|
|
10354
|
+
var RAW_ED25519_KEY_LENGTH = 32;
|
|
10355
|
+
var DEFAULT_MAX_AUTH_DELAY_MS = 200;
|
|
10356
|
+
var DEFAULT_MANIFEST_TIMER_MS = 20;
|
|
10357
|
+
var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
10358
|
+
function encodeBase64Url(bytes) {
|
|
10359
|
+
let output = "";
|
|
10360
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
10361
|
+
const b0 = bytes[i];
|
|
10362
|
+
const b1 = bytes[i + 1];
|
|
10363
|
+
const b2 = bytes[i + 2];
|
|
10364
|
+
output += BASE64URL_ALPHABET[b0 >> 2];
|
|
10365
|
+
output += BASE64URL_ALPHABET[(b0 & 3) << 4 | (b1 === void 0 ? 0 : b1 >> 4)];
|
|
10366
|
+
if (b1 === void 0) break;
|
|
10367
|
+
output += BASE64URL_ALPHABET[(b1 & 15) << 2 | (b2 === void 0 ? 0 : b2 >> 6)];
|
|
10368
|
+
if (b2 === void 0) break;
|
|
10369
|
+
output += BASE64URL_ALPHABET[b2 & 63];
|
|
10370
|
+
}
|
|
10371
|
+
return output;
|
|
10372
|
+
}
|
|
10373
|
+
var BASE64URL_DECODE_TABLE = (() => {
|
|
10374
|
+
const table = new Int8Array(128).fill(-1);
|
|
10375
|
+
for (let i = 0; i < BASE64URL_ALPHABET.length; i++) {
|
|
10376
|
+
table[BASE64URL_ALPHABET.charCodeAt(i)] = i;
|
|
10377
|
+
}
|
|
10378
|
+
return table;
|
|
10379
|
+
})();
|
|
10380
|
+
function decodeBase64Url(text2) {
|
|
10381
|
+
if (text2.length % 4 === 1) {
|
|
10382
|
+
throw new Error(`[multicast-auth-catalog] invalid unpadded base64url length for "${text2}"`);
|
|
10383
|
+
}
|
|
10384
|
+
const bytes = [];
|
|
10385
|
+
let buffer = 0;
|
|
10386
|
+
let bits = 0;
|
|
10387
|
+
for (let i = 0; i < text2.length; i++) {
|
|
10388
|
+
const code = text2.charCodeAt(i);
|
|
10389
|
+
const value = code < 128 ? BASE64URL_DECODE_TABLE[code] : -1;
|
|
10390
|
+
if (value === void 0 || value < 0) {
|
|
10391
|
+
throw new Error(`[multicast-auth-catalog] invalid base64url character in "${text2}"`);
|
|
10392
|
+
}
|
|
10393
|
+
buffer = buffer << 6 | value;
|
|
10394
|
+
bits += 6;
|
|
10395
|
+
if (bits >= 8) {
|
|
10396
|
+
bits -= 8;
|
|
10397
|
+
bytes.push(buffer >> bits & 255);
|
|
10398
|
+
}
|
|
10399
|
+
}
|
|
10400
|
+
const decoded = Uint8Array.from(bytes);
|
|
10401
|
+
if (encodeBase64Url(decoded) !== text2) {
|
|
10402
|
+
throw new Error(`[multicast-auth-catalog] non-canonical base64url encoding "${text2}"`);
|
|
10403
|
+
}
|
|
10404
|
+
return decoded;
|
|
10405
|
+
}
|
|
10406
|
+
function decodeEd25519PublicKey(publicKey) {
|
|
10407
|
+
const bytes = decodeBase64Url(publicKey);
|
|
10408
|
+
if (bytes.byteLength !== RAW_ED25519_KEY_LENGTH) {
|
|
10409
|
+
throw new Error(
|
|
10410
|
+
`[multicast-auth-catalog] public key must decode to ${RAW_ED25519_KEY_LENGTH} raw bytes, got ${bytes.byteLength}`
|
|
10411
|
+
);
|
|
10412
|
+
}
|
|
10413
|
+
return bytes;
|
|
10414
|
+
}
|
|
10415
|
+
function resolveMulticastAuthCatalog(catalog, options = {}) {
|
|
10416
|
+
if (typeof catalog !== "object" || catalog === null || Array.isArray(catalog)) {
|
|
10417
|
+
throw new Error("[multicast-auth-catalog] catalog must be an object");
|
|
10418
|
+
}
|
|
10419
|
+
const issues = multicastCatalogIssues(catalog, options);
|
|
10420
|
+
const fatal = issues.find((issue) => issue.endpointIndex === void 0);
|
|
10421
|
+
if (fatal) throw new Error(`[multicast-auth-catalog] ${fatal.path}: ${fatal.message}`);
|
|
10422
|
+
const multicast = catalog["multicast"];
|
|
10423
|
+
const auth = multicast?.["auth"];
|
|
10424
|
+
if (auth === void 0) {
|
|
10425
|
+
if (options.requireAuth) {
|
|
10426
|
+
throw new Error("[multicast-auth-catalog] authentication is pinned but the catalog declares no multicast.auth");
|
|
10427
|
+
}
|
|
10428
|
+
return void 0;
|
|
10429
|
+
}
|
|
10430
|
+
const ignored = new Set(issues.map((issue) => issue.endpointIndex));
|
|
10431
|
+
const endpoints = multicast["endpoints"] ?? [];
|
|
10432
|
+
const flows = [];
|
|
10433
|
+
endpoints.forEach((endpoint, endpointIndex) => {
|
|
10434
|
+
if (ignored.has(endpointIndex)) return;
|
|
10435
|
+
const flowAuth = endpoint["auth"];
|
|
10436
|
+
flows.push({
|
|
10437
|
+
endpointIndex,
|
|
10438
|
+
source: endpoint["sourceAddress"] ?? flowAuth.senderAddress,
|
|
10439
|
+
groupAddress: endpoint["groupAddress"],
|
|
10440
|
+
port: endpoint["port"],
|
|
10441
|
+
bandwidth: endpoint["bandwidth"],
|
|
10442
|
+
manifestPort: flowAuth.manifestPort,
|
|
10443
|
+
streamId: flowAuth.streamId,
|
|
10444
|
+
maxAuthDelayMs: flowAuth.maxAuthDelayMs ?? DEFAULT_MAX_AUTH_DELAY_MS,
|
|
10445
|
+
manifestTimerMs: flowAuth.manifestTimerMs ?? DEFAULT_MANIFEST_TIMER_MS,
|
|
10446
|
+
...flowAuth.manifestTrack === void 0 ? {} : { manifestTrack: flowAuth.manifestTrack },
|
|
10447
|
+
tracks: (endpoint["tracks"] ?? []).map(({ name, packetId }) => ({
|
|
10448
|
+
name,
|
|
10449
|
+
packetId
|
|
10450
|
+
}))
|
|
9635
10451
|
});
|
|
9636
|
-
byManifestTrack.set(binding.manifestTrack, planned);
|
|
9637
|
-
return planned;
|
|
9638
10452
|
});
|
|
9639
|
-
let disposed = false;
|
|
9640
10453
|
return {
|
|
9641
|
-
|
|
9642
|
-
|
|
9643
|
-
|
|
10454
|
+
keys: auth.keys.map((key) => ({ kid: key.kid, publicKey: decodeEd25519PublicKey(key.publicKey), firstEpoch: key.firstEpoch })).sort((a, b) => a.firstEpoch - b.firstEpoch),
|
|
10455
|
+
minEpoch: auth.minEpoch,
|
|
10456
|
+
flows
|
|
10457
|
+
};
|
|
10458
|
+
}
|
|
10459
|
+
function multicastAuthKeyFor(resolved, kid, epoch) {
|
|
10460
|
+
return manifestKeyFor(resolved.keys, epoch, kid);
|
|
10461
|
+
}
|
|
10462
|
+
|
|
10463
|
+
// src/manifest-auth-plan.ts
|
|
10464
|
+
function createManifestAuthPlan(catalog, options = {}) {
|
|
10465
|
+
const resolved = resolveMulticastAuthCatalog(catalog, options);
|
|
10466
|
+
if (!resolved) return void 0;
|
|
10467
|
+
const byManifestTrack = /* @__PURE__ */ new Map();
|
|
10468
|
+
for (const flow of resolved.flows) {
|
|
10469
|
+
if (flow.manifestTrack !== void 0) byManifestTrack.set(flow.manifestTrack, flow);
|
|
10470
|
+
}
|
|
10471
|
+
return {
|
|
10472
|
+
keys: resolved.keys,
|
|
10473
|
+
minEpoch: resolved.minEpoch,
|
|
10474
|
+
flows: resolved.flows,
|
|
9644
10475
|
manifestTracks: [...byManifestTrack.keys()],
|
|
9645
|
-
|
|
9646
|
-
|
|
9647
|
-
|
|
9648
|
-
},
|
|
9649
|
-
ingestManifestPayload(manifestTrack, payload) {
|
|
9650
|
-
const binding = byManifestTrack.get(manifestTrack);
|
|
9651
|
-
if (!binding) throw new Error(`unknown manifest subscription track ${manifestTrack}`);
|
|
9652
|
-
verifier.ingestManifestFrame(binding.bindingId, payload);
|
|
9653
|
-
},
|
|
9654
|
-
dispose() {
|
|
9655
|
-
if (disposed) return;
|
|
9656
|
-
disposed = true;
|
|
9657
|
-
verifier.dispose();
|
|
9658
|
-
}
|
|
10476
|
+
keyFor: (kid, epoch) => multicastAuthKeyFor(resolved, kid, epoch),
|
|
10477
|
+
flowForManifestPort: (source, groupAddress, manifestPort) => resolved.flows.find((flow) => flow.source === source && flow.groupAddress === groupAddress && flow.manifestPort === manifestPort),
|
|
10478
|
+
flowForManifestTrack: (manifestTrack) => byManifestTrack.get(manifestTrack)
|
|
9659
10479
|
};
|
|
9660
10480
|
}
|
|
9661
10481
|
return __toCommonJS(no_modules_exports);
|